1 // Copyright 2011 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
13 func TestConcatN(t
*testing
.T
) {
14 var mergePaths1
= []string{
20 var mergePaths2
= []string{
25 var mergeFiles1
= map[string]string{
26 "/a/x": "hello world",
27 "/a/y": "goodbye world",
28 "/b/xx": "now is the time",
29 "/b/xy": "for all good men",
30 "/c/ab": "give me all the potatoes",
31 "/c/de": "or give me death now",
34 var mergeFiles2
= map[string]string{
35 "/cc": "come to the aid of his potatoes",
36 "/d/www": "world wide indeed",
37 "/d/xz": "no, not now",
38 "/d/yy": "first potatoes, now liberty?",
41 var mergeFiles3
= map[string]string{
42 "/latest": "ZZZ makes the snoring rabbit",
43 "/latest2": "aaa makes the snoring armadillo",
46 f1
, _
:= ioutil
.TempFile("", "index-test")
47 f2
, _
:= ioutil
.TempFile("", "index-test")
48 f3
, _
:= ioutil
.TempFile("", "index-test")
49 f4
, _
:= ioutil
.TempFile("", "index-test")
50 defer os
.Remove(f1
.Name())
51 defer os
.Remove(f2
.Name())
52 defer os
.Remove(f4
.Name())
59 buildIndex(out1
, mergePaths1
, mergeFiles1
)
60 buildIndex(out2
, mergePaths2
, mergeFiles2
)
61 buildIndex(out3
, []string{}, mergeFiles3
)
63 ConcatN(out4
, out1
, out2
, out3
)
70 nameof
:= func(ix
*Index
) string {
84 checkFiles
:= func(ix
*Index
, l
...string) {
86 if n
:= ix
.Name(uint32(i
)); n
!= s
{
87 t
.Errorf("%s: Name(%d) = %s, want %s", nameof(ix
), i
, n
, s
)
92 checkFiles(ix1
, "/a/x", "/a/y", "/b/xx", "/b/xy", "/c/ab", "/c/de")
93 checkFiles(ix2
, "/cc", "/d/www", "/d/xz", "/d/yy")
94 checkFiles(ix3
, "/latest")
96 checkFiles(ix4
, "/a/x", "/a/y", "/b/xx", "/b/xy", "/c/ab", "/c/de", "/cc", "/d/www", "/d/xz", "/d/yy", "/latest")
98 check
:= func(ix
*Index
, trig
string, l
...uint32) {
99 l1
:= ix
.PostingList(tri(trig
[0], trig
[1], trig
[2]))
100 if !equalList(l1
, l
) {
101 t
.Errorf("PostingList(%s, %s) = %v, want %v", nameof(ix
), trig
, l1
, l
)
105 check(ix1
, "wor", 0, 1)
106 check(ix1
, "now", 2, 5)
107 check(ix1
, "all", 3, 4)
109 check(ix2
, "now", 2, 3)
114 check(ix4
, "all", 3, 4)
115 check(ix4
, "wor", 0, 1, 7)
116 check(ix4
, "now", 2, 5, 8, 9)
117 check(ix4
, "pot", 4, 6, 9)
118 check(ix4
, "ZZZ", 10)
119 check(ix4
, "aaa", 11)