This commit is contained in:
s.kamardin 2016-01-12 14:13:56 +03:00
parent f2255c18f5
commit df67a5925f
4 changed files with 39 additions and 5 deletions

View File

@ -49,12 +49,10 @@ func optimize(matcher match.Matcher) match.Matcher {
if leftNil && rightSuffix {
return match.PrefixSuffix{Prefix: r.Str, Suffix: rs.Suffix}
// return match.EveryOf{match.Matchers{match.Prefix{r.Str}, rs}}
}
if rightNil && leftPrefix {
return match.PrefixSuffix{Prefix: lp.Prefix, Suffix: r.Str}
// return match.EveryOf{match.Matchers{lp, match.Suffix{r.Str}}}
}
return m

View File

@ -277,8 +277,7 @@ func TestCompiler(t *testing.T) {
result: match.Prefix{"abc"},
},
{
ast: pattern(&nodeText{text: "abc"}, &nodeAny{}, &nodeText{text: "def"}),
// result: match.EveryOf{match.Matchers{match.Prefix{"abc"}, match.Suffix{"def"}}},
ast: pattern(&nodeText{text: "abc"}, &nodeAny{}, &nodeText{text: "def"}),
result: match.PrefixSuffix{"abc", "def"},
},
{

View File

@ -42,7 +42,7 @@ func TestCompilePattern(t *testing.T) {
exp match.Matcher
}{
// {
// pattern: "{*,def}ghi",
// pattern: "{*,def,abc[a-z]*}ghi",
// exp: match.Raw{"t"},
// },
} {

37
match/any_test.go Normal file
View File

@ -0,0 +1,37 @@
package match
import (
"reflect"
"testing"
)
func TestAnyIndex(t *testing.T) {
for id, test := range []struct {
sep string
fixture string
index int
segments []int
}{
{
".",
"abc",
0,
[]int{0, 1, 2, 3},
},
{
".",
"abc.def",
0,
[]int{0, 1, 2, 3},
},
} {
p := Any{test.sep}
index, segments := p.Index(test.fixture)
if index != test.index {
t.Errorf("#%d unexpected index: exp: %d, act: %d", id, test.index, index)
}
if !reflect.DeepEqual(segments, test.segments) {
t.Errorf("#%d unexpected segments: exp: %v, act: %v", id, test.segments, segments)
}
}
}