Skip to content
quarry Artifact [24822dc841]
Login

Artifact [24822dc841]

Artifact 24822dc841d5434c16f5b729b0da4d3aa006f70b336c877223c48dfef2468fa6:


package index

import "testing"

// The Docs index lists tree documents and wiki pages as one list, so
// the "docs" scope must find both. Kind "doc" alone holds tree files
// only, which left every listed wiki page unreachable from its own
// header box.
func TestDocsScopeSpansTreeDocumentsAndWikiPages(t *testing.T) {
	ix := openIndex(t)
	if err := ix.ReplaceTree("v1", []TreeText{
		{Path: "NOTES.md", Body: "probe notes", Doc: true},
		{Path: "src/probe.c", Body: "probe source"},
	}); err != nil {
		t.Fatal(err)
	}
	if _, err := ix.w.Exec(`INSERT INTO search_doc (hash, kind, ref, label, text)
		VALUES ('w1', 'wiki', 'HookProbe', 'HookProbe', 'a probe page'),
		       ('t1', 'ticket', 'tkt', 'a ticket', 'probe ticket')`); err != nil {
		t.Fatal(err)
	}

	for name, search := range map[string]func(string) ([]SearchResult, error){
		"Search":      func(k string) ([]SearchResult, error) { return ix.Search("probe", k, 10) },
		"SearchBrief": func(k string) ([]SearchResult, error) { return ix.SearchBrief("probe", k, 10) },
		"SearchAny":   func(k string) ([]SearchResult, error) { return ix.SearchAny([]string{"probe"}, k, 10) },
	} {
		got, err := search("docs")
		if err != nil {
			t.Fatalf("FAIL: %s: %v", name, err)
		}
		kinds := map[string]bool{}
		for _, r := range got {
			kinds[r.Kind] = true
		}
		if len(got) != 2 || !kinds["doc"] || !kinds["wiki"] {
			t.Errorf("FAIL: %s docs scope found %v, want exactly one doc and one wiki", name, got)
		}
	}
	n, err := ix.SearchCount("probe", "docs")
	if err != nil || n != 2 {
		t.Errorf("FAIL: SearchCount docs = %d, %v, want 2", n, err)
	}
	// A single kind is unchanged: "doc" must not start matching wiki pages.
	if got, _ := ix.Search("probe", "doc", 10); len(got) != 1 || got[0].Kind != "doc" {
		t.Errorf("FAIL: kind doc found %v, want only the tree document", got)
	}
}