fix tests

This commit is contained in:
gobwas 2019-03-12 22:15:41 +03:00
parent cd9e75ee86
commit bcbbef0a8d
3 changed files with 9 additions and 9 deletions

View File

@ -54,7 +54,7 @@ func main() {
for _, c := range strings.Split(*sep, ",") { for _, c := range strings.Split(*sep, ",") {
r, w := utf8.DecodeRuneInString(c) r, w := utf8.DecodeRuneInString(c)
if len(c) > w { if len(c) > w {
fmt.Println("only single charactered separators are allowed: %+q", c) fmt.Printf("only single charactered separators are allowed: %+q\n", c)
os.Exit(1) os.Exit(1)
} }
separators = append(separators, r) separators = append(separators, r)

View File

@ -113,7 +113,7 @@ func TestCompiler(t *testing.T) {
match.NewSingle(separators), match.NewSingle(separators),
}), }),
match.NewAny(separators), match.NewAny(separators),
nil, match.Nothing{},
), ),
}, },
{ {
@ -129,13 +129,13 @@ func TestCompiler(t *testing.T) {
sep: separators, sep: separators,
exp: match.NewTree( exp: match.NewTree(
match.NewText("/"), match.NewText("/"),
nil, match.Nothing{},
match.NewTree( match.NewTree(
match.MustIndexedAnyOf( match.MustIndexedAnyOf(
match.NewText("z"), match.NewText("z"),
match.NewText("ab"), match.NewText("ab"),
), ),
nil, match.Nothing{},
match.NewSuper(), match.NewSuper(),
), ),
), ),
@ -156,7 +156,7 @@ func TestCompiler(t *testing.T) {
match.NewSingle(separators), match.NewSingle(separators),
}), }),
match.NewSuper(), match.NewSuper(),
nil, match.Nothing{},
), ),
}, },
{ {
@ -273,7 +273,7 @@ func TestCompiler(t *testing.T) {
), ),
exp: match.NewTree( exp: match.NewTree(
match.NewText("abc"), match.NewText("abc"),
nil, match.Nothing{},
match.NewAnyOf( match.NewAnyOf(
match.NewSingle(nil), match.NewSingle(nil),
match.NewList([]rune{'d', 'e', 'f'}, false), match.NewList([]rune{'d', 'e', 'f'}, false),
@ -293,7 +293,7 @@ func TestCompiler(t *testing.T) {
match.NewRange('a', 'z', false), match.NewRange('a', 'z', false),
match.NewRange('a', 'x', true), match.NewRange('a', 'x', true),
}), }),
nil, match.Nothing{},
match.NewSuper(), match.NewSuper(),
), ),
}, },

View File

@ -40,8 +40,8 @@ func Optimize(m Matcher) (opt Matcher) {
} }
var ( var (
leftNil = v.left == nil leftNil = v.left == nil || v.left == Nothing{}
rightNil = v.right == nil rightNil = v.right == nil || v.right == Nothing{}
) )
if leftNil && rightNil { if leftNil && rightNil {
return NewText(txt.s) return NewText(txt.s)