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 TestConcat(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 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())
52 buildIndex(out1
, mergePaths1
, mergeFiles1
)
53 buildIndex(out2
, mergePaths2
, mergeFiles2
)
55 Concat(out3
, out1
, out2
)
61 nameof
:= func(ix
*Index
) string {
73 checkFiles
:= func(ix
*Index
, l
...string) {
75 if n
:= ix
.Name(uint32(i
)); n
!= s
{
76 t
.Errorf("%s: Name(%d) = %s, want %s", nameof(ix
), i
, n
, s
)
81 checkFiles(ix1
, "/a/x", "/a/y", "/b/xx", "/b/xy", "/c/ab", "/c/de")
82 checkFiles(ix2
, "/cc", "/d/www", "/d/xz", "/d/yy")
84 checkFiles(ix3
, "/a/x", "/a/y", "/b/xx", "/b/xy", "/c/ab", "/c/de", "/cc", "/d/www", "/d/xz", "/d/yy")
86 check
:= func(ix
*Index
, trig
string, l
...uint32) {
87 l1
:= ix
.PostingList(tri(trig
[0], trig
[1], trig
[2]))
88 if !equalList(l1
, l
) {
89 t
.Errorf("PostingList(%s, %s) = %v, want %v", nameof(ix
), trig
, l1
, l
)
93 check(ix1
, "wor", 0, 1)
94 check(ix1
, "now", 2, 5)
95 check(ix1
, "all", 3, 4)
97 check(ix2
, "now", 2, 3)
99 check(ix3
, "all", 3, 4)
100 check(ix3
, "wor", 0, 1, 7)
101 check(ix3
, "now", 2, 5, 8, 9)
102 check(ix3
, "pot", 4, 6, 9)