...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package namespace
16
17 import (
18 "bytes"
19 "testing"
20 )
21
22 func TestPrefixInterval(t *testing.T) {
23 tests := []struct {
24 pfx string
25 key []byte
26 end []byte
27
28 wKey []byte
29 wEnd []byte
30 }{
31
32 {
33 pfx: "pfx/",
34 key: []byte("a"),
35
36 wKey: []byte("pfx/a"),
37 },
38
39 {
40 pfx: "pfx/",
41 key: []byte("abc"),
42 end: []byte("def"),
43
44 wKey: []byte("pfx/abc"),
45 wEnd: []byte("pfx/def"),
46 },
47
48 {
49 pfx: "pfx/",
50 key: []byte("abc"),
51 end: []byte{0},
52
53 wKey: []byte("pfx/abc"),
54 wEnd: []byte("pfx0"),
55 },
56
57 {
58 pfx: "\xff\xff",
59 key: []byte("abc"),
60 end: []byte{0},
61
62 wKey: []byte("\xff\xffabc"),
63 wEnd: []byte{0},
64 },
65 }
66 for i, tt := range tests {
67 pfxKey, pfxEnd := prefixInterval(tt.pfx, tt.key, tt.end)
68 if !bytes.Equal(pfxKey, tt.wKey) {
69 t.Errorf("#%d: expected key=%q, got key=%q", i, tt.wKey, pfxKey)
70 }
71 if !bytes.Equal(pfxEnd, tt.wEnd) {
72 t.Errorf("#%d: expected end=%q, got end=%q", i, tt.wEnd, pfxEnd)
73 }
74 }
75 }
76
View as plain text