Bugfix: construct redirect URLs using net/url
[debiancodesearch.git] / index / read_test.go
blob4a75c3a6f472f2a34f2785ce30b1e32266ad931e
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.
5 package index
7 import (
8 "io/ioutil"
9 "os"
10 "testing"
13 var postFiles = map[string]string{
14 "file0": "",
15 "file1": "Google Code Search",
16 "file2": "Google Code Project Hosting",
17 "file3": "Google Web Search",
20 func tri(x, y, z byte) uint32 {
21 return uint32(x)<<16 | uint32(y)<<8 | uint32(z)
24 func TestTrivialPosting(t *testing.T) {
25 f, _ := ioutil.TempFile("", "index-test")
26 defer os.Remove(f.Name())
27 out := f.Name()
28 buildIndex(out, nil, postFiles)
29 ix := Open(out)
30 if l := ix.PostingList(tri('S', 'e', 'a')); !equalList(l, []uint32{1, 3}) {
31 t.Errorf("PostingList(Sea) = %v, want [1 3]", l)
33 if l := ix.PostingList(tri('G', 'o', 'o')); !equalList(l, []uint32{1, 2, 3}) {
34 t.Errorf("PostingList(Goo) = %v, want [1 2 3]", l)
36 if l := ix.PostingAnd(ix.PostingList(tri('S', 'e', 'a')), tri('G', 'o', 'o')); !equalList(l, []uint32{1, 3}) {
37 t.Errorf("PostingList(Sea&Goo) = %v, want [1 3]", l)
39 if l := ix.PostingAnd(ix.PostingList(tri('G', 'o', 'o')), tri('S', 'e', 'a')); !equalList(l, []uint32{1, 3}) {
40 t.Errorf("PostingList(Goo&Sea) = %v, want [1 3]", l)
42 if l := ix.PostingOr(ix.PostingList(tri('S', 'e', 'a')), tri('G', 'o', 'o')); !equalList(l, []uint32{1, 2, 3}) {
43 t.Errorf("PostingList(Sea|Goo) = %v, want [1 2 3]", l)
45 if l := ix.PostingOr(ix.PostingList(tri('G', 'o', 'o')), tri('S', 'e', 'a')); !equalList(l, []uint32{1, 2, 3}) {
46 t.Errorf("PostingList(Goo|Sea) = %v, want [1 2 3]", l)
50 func equalList(x, y []uint32) bool {
51 if len(x) != len(y) {
52 return false
54 for i, xi := range x {
55 if xi != y[i] {
56 return false
59 return true