package book import "testing" func TestBody(t *testing.T) { c := NewChapterFromURL("https://books.lapw.at/", []*ScrapeConfig{NewScrapeConfig()}) got := c.Body() want := "\n\n \n Books\n \n \n \n \n \n \n \n\n \n \n\n\n\n \n\n\n\n\n\n\n \n \n
\n \"John\n

Books

\n

\n
\n \n
\n
\n
\n \n
\n

Books

\n \n \n\n\n\n
\n\n
\n \n\n" if got != want { t.Errorf("got %v, wanted %v", got, want) } } func TestName(t *testing.T) { c := NewChapterFromURL("https://books.lapw.at/", []*ScrapeConfig{NewScrapeConfig()}) got := c.Name() want := "Books" if got != want { t.Errorf("got %v, wanted %v", got, want) } } func TestAuthor(t *testing.T) { c := NewChapterFromURL("https://books.lapw.at/", []*ScrapeConfig{NewScrapeConfig()}) got := c.Author() want := "John Doe" if got != want { t.Errorf("got %v, wanted %v", got, want) } } func TestContent(t *testing.T) { c := NewChapterFromURL("https://books.lapw.at/", []*ScrapeConfig{NewScrapeConfig()}) got := c.Content() want := "
\n \n
\n \n \n\n
\n \n\n
" if got != want { t.Errorf("got %v, wanted %v", got, want) } } func TestContentImagesOnly(t *testing.T) { config := NewScrapeConfig() config.imagesOnly = true c := NewChapterFromURL("https://books.lapw.at/posts/adam-wiggins-the-twelve-factor-app/", []*ScrapeConfig{config}) got := c.Content() want := "\"One\"A\"Code\"Scale" if got != want { t.Errorf("got %v, wanted %v", got, want) } } func TestSubChapters(t *testing.T) { c := NewChapterFromURL("https://books.lapw.at/", []*ScrapeConfig{NewScrapeConfig(), NewScrapeConfig()}) got := len(c.SubChapters()) want := 2 if got != want { t.Errorf("got %v, wanted %v", got, want) } } func TestSubChaptersSelector(t *testing.T) { c := NewChapterFromURL("https://12factor.net/", []*ScrapeConfig{{"section.concrete > article > h2 > a", -1, true, false}, NewScrapeConfig()}) got := len(c.SubChapters()) want := 12 if got != want { t.Errorf("got %v, wanted %v", got, want) } } func TestSubChaptersLimit(t *testing.T) { config := NewScrapeConfig() config.limit = 1 c := NewChapterFromURL("https://books.lapw.at/", []*ScrapeConfig{config, NewScrapeConfig()}) got := len(c.SubChapters()) want := 1 if got != want { t.Errorf("got %v, wanted %v", got, want) } } func TestSubChaptersLimitOver(t *testing.T) { config := NewScrapeConfig() config.limit = 3 c := NewChapterFromURL("https://books.lapw.at/", []*ScrapeConfig{config, NewScrapeConfig()}) got := len(c.SubChapters()) want := 2 if got != want { t.Errorf("got %v, wanted %v", got, want) } } func TestNotInclude(t *testing.T) { config := NewScrapeConfig() config.include = false c := NewChapterFromURL("https://books.lapw.at/", []*ScrapeConfig{config}) got := c.Content() want := "" if got != want { t.Errorf("got %v, wanted %v", got, want) } }