package monkeyd import ( "strings" "testing" ) // chapterFixture mirrors the real page shape: words split between markup and // CSS :before rules, HTML entities, spacer paragraphs and an ad script // inside the content container. const chapterFixture = `
1
Nghe trưởng tử noi.
Một và di.
1
" repeats the chapter label and would print twice. func TestParseChapterDropsRepeatedTitle(t *testing.T) { ch, err := ParseChapter([]byte(chapterFixture), ChapterRef{Label: "1", URL: "http://x/1.html"}) if err != nil { t.Fatalf("ParseChapter: %v", err) } if ch.Paragraphs[0] == "1" { t.Error("repeated chapter label was kept as a paragraph") } } // gatedChapterFixture mirrors how most chapters are served: a visible sponsor // block (div.actcl) stands in for the body, while the real text sits in a // sibling div.actac hidden with display:none and revealed by the site's // JavaScript. A source watermark and prev/next navigation bracket the prose. const gatedChapterFixture = `mo ung dung Shopee, sau do quay tro lai de doc!
CLICK
hi
`), ChapterRef{URL: "http://x/1.html"}); err == nil { t.Fatal("want an error when the content container is absent") } } func TestChapterHeading(t *testing.T) { for _, tc := range []struct{ label, want string }{ {"14", "Chương 14"}, {"Chương 12", "Chương 12"}, {"", "Chương"}, } { ch := &Chapter{Label: tc.label} if got := ch.Heading(); got != tc.want { t.Errorf("Heading(%q) = %q, want %q", tc.label, got, tc.want) } } }