...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package cmux
16
17 import (
18 "strings"
19 "testing"
20 )
21
22 func testPTree(t *testing.T, strs ...string) {
23 pt := newPatriciaTreeString(strs...)
24 for _, s := range strs {
25 if !pt.match(strings.NewReader(s)) {
26 t.Errorf("%s is not matched by %s", s, s)
27 }
28
29 if !pt.matchPrefix(strings.NewReader(s + s)) {
30 t.Errorf("%s is not matched as a prefix by %s", s+s, s)
31 }
32
33 if pt.match(strings.NewReader(s + s)) {
34 t.Errorf("%s matches %s", s+s, s)
35 }
36
37
38
39 pt.matchPrefix(strings.NewReader(s[:len(s)-1]))
40 pt.match(strings.NewReader(s[:len(s)-1]))
41 pt.matchPrefix(strings.NewReader(s + "$"))
42 pt.match(strings.NewReader(s + "$"))
43 }
44 }
45
46 func TestPatriciaOnePrefix(t *testing.T) {
47 testPTree(t, "prefix")
48 }
49
50 func TestPatriciaNonOverlapping(t *testing.T) {
51 testPTree(t, "foo", "bar", "dummy")
52 }
53
54 func TestPatriciaOverlapping(t *testing.T) {
55 testPTree(t, "foo", "far", "farther", "boo", "ba", "bar")
56 }
57
View as plain text