MCPcopy
hub / github.com/google/codesearch / TestMerge

Function TestMerge

index/merge_test.go:40–102  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

38}
39
40func TestMerge(t *testing.T) {
41 f1, _ := ioutil.TempFile("", "index-test")
42 f2, _ := ioutil.TempFile("", "index-test")
43 f3, _ := ioutil.TempFile("", "index-test")
44 defer os.Remove(f1.Name())
45 defer os.Remove(f2.Name())
46 defer os.Remove(f3.Name())
47
48 out1 := f1.Name()
49 out2 := f2.Name()
50 out3 := f3.Name()
51
52 buildIndex(out1, mergePaths1, mergeFiles1)
53 buildIndex(out2, mergePaths2, mergeFiles2)
54
55 Merge(out3, out1, out2)
56
57 ix1 := Open(out1)
58 ix2 := Open(out2)
59 ix3 := Open(out3)
60
61 nameof := func(ix *Index) string {
62 switch {
63 case ix == ix1:
64 return "ix1"
65 case ix == ix2:
66 return "ix2"
67 case ix == ix3:
68 return "ix3"
69 }
70 return "???"
71 }
72
73 checkFiles := func(ix *Index, l ...string) {
74 for i, s := range l {
75 if n := ix.Name(uint32(i)); n != s {
76 t.Errorf("%s: Name(%d) = %s, want %s", nameof(ix), i, n, s)
77 }
78 }
79 }
80
81 checkFiles(ix1, "/a/x", "/a/y", "/b/xx", "/b/xy", "/c/ab", "/c/de")
82 checkFiles(ix2, "/b/www", "/b/xx", "/b/yy", "/cc")
83 checkFiles(ix3, "/a/x", "/a/y", "/b/www", "/b/xx", "/b/yy", "/c/ab", "/c/de", "/cc")
84
85 check := func(ix *Index, trig string, l ...uint32) {
86 l1 := ix.PostingList(tri(trig[0], trig[1], trig[2]))
87 if !equalList(l1, l) {
88 t.Errorf("PostingList(%s, %s) = %v, want %v", nameof(ix), trig, l1, l)
89 }
90 }
91
92 check(ix1, "wor", 0, 1)
93 check(ix1, "now", 2, 5)
94 check(ix1, "all", 3, 4)
95
96 check(ix2, "now", 1, 2)
97

Callers

nothing calls this directly

Calls 7

buildIndexFunction · 0.85
MergeFunction · 0.85
OpenFunction · 0.85
triFunction · 0.85
equalListFunction · 0.85
NameMethod · 0.80
PostingListMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…