2016-01-08 20:14:31 +03:00
|
|
|
package match
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestBTree(t *testing.T) {
|
|
|
|
for id, test := range []struct {
|
|
|
|
tree BTree
|
|
|
|
str string
|
|
|
|
exp bool
|
|
|
|
}{
|
|
|
|
{
|
2016-01-15 19:50:12 +03:00
|
|
|
NewBTree(NewText("abc"), Super{}, Super{}),
|
2016-01-08 20:14:31 +03:00
|
|
|
"abc",
|
|
|
|
true,
|
|
|
|
},
|
|
|
|
{
|
2016-01-15 19:50:12 +03:00
|
|
|
NewBTree(NewText("a"), Single{}, Single{}),
|
2016-01-08 20:14:31 +03:00
|
|
|
"aaa",
|
|
|
|
true,
|
|
|
|
},
|
|
|
|
{
|
2016-01-15 19:50:12 +03:00
|
|
|
NewBTree(NewText("b"), Single{}, nil),
|
2016-01-08 20:14:31 +03:00
|
|
|
"bbb",
|
|
|
|
false,
|
|
|
|
},
|
|
|
|
{
|
2016-01-15 19:50:12 +03:00
|
|
|
NewBTree(
|
|
|
|
NewText("c"),
|
|
|
|
NewBTree(
|
|
|
|
Single{},
|
|
|
|
Super{},
|
|
|
|
nil,
|
|
|
|
),
|
|
|
|
nil,
|
|
|
|
),
|
2016-01-08 20:14:31 +03:00
|
|
|
"abc",
|
|
|
|
true,
|
|
|
|
},
|
|
|
|
} {
|
|
|
|
act := test.tree.Match(test.str)
|
|
|
|
if act != test.exp {
|
|
|
|
t.Errorf("#%d match %q error: act: %t; exp: %t", id, test.str, act, test.exp)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|