package gutenberg import ( "strings" "testing" ) func TestStripBoilerplate(t *testing.T) { input := `The Project Gutenberg eBook of Test Book *** START OF THE PROJECT GUTENBERG EBOOK TEST BOOK *** This is the actual content of the book. It has multiple lines. And some more content here. *** END OF THE PROJECT GUTENBERG EBOOK TEST BOOK *** End of the Project Gutenberg EBook of Test Book Blah blah license info.` result := StripBoilerplate(input) if strings.Contains(result, "Project Gutenberg") { t.Error("boilerplate not fully stripped") } if !strings.Contains(result, "actual content") { t.Error("body content was stripped") } if !strings.Contains(result, "multiple lines") { t.Error("body content was stripped") } if strings.Contains(result, "license info") { t.Error("footer not stripped") } } func TestStripBoilerplateNoMarkers(t *testing.T) { input := "This is plain text without any Gutenberg markers." result := StripBoilerplate(input) if result != input { t.Error("text without markers should be returned unchanged") } } func TestStripBoilerplateCaseInsensitive(t *testing.T) { input := `header stuff *** start of THE PROJECT GUTENBERG EBOOK *** body content *** END of THE PROJECT GUTENBERG EBOOK *** footer` result := StripBoilerplate(input) if !strings.Contains(result, "body content") { t.Error("case-insensitive matching failed") } } func TestBookIDsFromCatalog(t *testing.T) { input := strings.NewReader(`# Comment 1 2 3 # Another comment 5 not-a-number 10 `) ids, err := BookIDsFromCatalog(input) if err != nil { t.Fatal(err) } if len(ids) != 5 { t.Errorf("got %d IDs, want 5", len(ids)) } expected := []int{1, 2, 3, 5, 10} for i, want := range expected { if ids[i] != want { t.Errorf("ids[%d] = %d, want %d", i, ids[i], want) } } }