mirror of
https://github.com/soheilhy/cmux.git
synced 2024-11-11 04:01:53 +08:00
36 lines
708 B
Go
36 lines
708 B
Go
|
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")
|
||
|
}
|