package memoriatest import ( "net/http" "regexp" "strings" "testing" ) func TestStoreThenFind(t *testing.T) { h := newApp(t) if rec := store(t, h, "Q3 board pack", "## Revenue\n\nJune revenue was 1,350,000 across all regions.\n\n## Costs\n\nHosting fell after the migration."); rec.Code != http.StatusSeeOther { t.Fatalf("store: status %d, want 303", rec.Code) } body := get(t, h, "/?q=june+revenue").Body.String() if !strings.Contains(body, "Q3 board pack") { t.Errorf("search does not show the document title:\n%s", body) } if !strings.Contains(body, "Revenue") { t.Error("search result carries no heading trail") } if !strings.Contains(body, "") { t.Error("search result carries no highlight") } } // The list must distinguish "nothing matched" from "nothing indexed". // Conflating them is the plausible-empty-list failure. func TestNoMatchSaysTheCorpusIsNotEmpty(t *testing.T) { h := newApp(t) store(t, h, "Notes", strings.Repeat("hosting migration notes. ", 20)) body := get(t, h, "/?q=xylophone").Body.String() // One quiet line (shared chrome §4), not "0 results" over a callout. if !strings.Contains(body, "No matches for “xylophone”.") { t.Errorf("no-match page does not say nothing matched:\n%s", body) } // The count is on the same page, in the footer, and it is not zero — // so a reader can tell an absent answer from an empty index. if !regexp.MustCompile(`[1-9][0-9]* passages? indexed`).MatchString(body) { t.Error("no-match page does not say how much is indexed, so a reader " + "cannot tell an absent answer from an empty index") } } // Stored text is untrusted. A document containing markup must not // execute in a search result or on the document page. func TestStoredMarkupIsEscaped(t *testing.T) { h := newApp(t) const nasty = `` store(t, h, "Payload "+nasty, "## Heading "+nasty+"\n\nA passage containing "+nasty+" inline and revenue too.") for _, target := range []string{"/?q=revenue", "/documents/1"} { body := get(t, h, target).Body.String() if strings.Contains(body, "