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-14 21:32:02 +03:00
|
|
|
BTree{Value: Text{"abc"}, Left: Super{}, Right: Super{}},
|
2016-01-08 20:14:31 +03:00
|
|
|
"abc",
|
|
|
|
true,
|
|
|
|
},
|
|
|
|
{
|
2016-01-14 21:32:02 +03:00
|
|
|
BTree{Value: Text{"a"}, Left: Single{}, Right: Single{}},
|
2016-01-08 20:14:31 +03:00
|
|
|
"aaa",
|
|
|
|
true,
|
|
|
|
},
|
|
|
|
{
|
2016-01-14 21:32:02 +03:00
|
|
|
BTree{Value: Text{"b"}, Left: Single{}},
|
2016-01-08 20:14:31 +03:00
|
|
|
"bbb",
|
|
|
|
false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
BTree{
|
|
|
|
Left: BTree{
|
|
|
|
Left: Super{},
|
|
|
|
Value: Single{},
|
|
|
|
},
|
2016-01-14 21:32:02 +03:00
|
|
|
Value: Text{"c"},
|
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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|