package index
import (
"strings"
"testing"
)
// A brief search is the same search without the snippets: the same
// documents in the same order, so a list that shows only names can skip
// the cost of cutting them.
func TestSearchBriefFindsWhatSearchFinds(t *testing.T) {
ix := openIndex(t)
var tree []TreeText
for i, path := range []string{"a.c", "b.c", "c.c", "d.c", "e.c", "f.c"} {
tree = append(tree, TreeText{Path: path,
Body: strings.Repeat("widget ", i+1) + strings.Repeat("filler text ", 50*(i+1))})
}
tree = append(tree, TreeText{Path: "none.c", Body: "nothing to see"})
if err := ix.ReplaceTree("v1", tree); err != nil {
t.Fatal(err)
}
full, err := ix.Search("widget", "", 4)
if err != nil {
t.Fatal(err)
}
brief, err := ix.SearchBrief("widget", "", 4)
if err != nil {
t.Fatal(err)
}
if len(full) != 4 || len(brief) != len(full) {
t.Fatalf("full %d rows, brief %d, want 4 each", len(full), len(brief))
}
for i := range full {
if brief[i].Kind != full[i].Kind || brief[i].Ref != full[i].Ref || brief[i].Rank != full[i].Rank {
t.Errorf("row %d: brief %s/%s, full %s/%s", i, brief[i].Kind, brief[i].Ref, full[i].Kind, full[i].Ref)
}
if full[i].Snippet == "" {
t.Errorf("row %d: full search has no snippet", i)
}
if brief[i].Snippet != "" {
t.Errorf("row %d: brief search cut a snippet", i)
}
}
}