2
0
mirror of https://github.com/soheilhy/cmux.git synced 2024-11-10 11:41:52 +08:00
cmux/patricia_test.go

36 lines
708 B
Go
Raw Normal View History

2015-07-30 01:45:57 +08:00
package cmux
import (
"strings"
"testing"
)
func testPTree(t *testing.T, strs ...string) {
pt := newPatriciaTreeString(strs...)
for _, s := range strs {
if !pt.match(strings.NewReader(s)) {
t.Errorf("%s is not matched by %s", s, s)
}
if !pt.matchPrefix(strings.NewReader(s + s)) {
t.Errorf("%s is not matched as a prefix by %s", s+s, s)
}
if pt.match(strings.NewReader(s + s)) {
t.Errorf("%s matches %s", s+s, s)
}
}
}
func TestPatriciaOnePrefix(t *testing.T) {
testPTree(t, "prefix")
}
func TestPatriciaNonOverlapping(t *testing.T) {
testPTree(t, "foo", "bar", "dummy")
}
func TestPatriciaOverlapping(t *testing.T) {
testPTree(t, "foo", "far", "farther", "boo", "bar")
}