forked from mirror/glob
tests
This commit is contained in:
parent
f2255c18f5
commit
df67a5925f
|
@ -49,12 +49,10 @@ func optimize(matcher match.Matcher) match.Matcher {
|
||||||
|
|
||||||
if leftNil && rightSuffix {
|
if leftNil && rightSuffix {
|
||||||
return match.PrefixSuffix{Prefix: r.Str, Suffix: rs.Suffix}
|
return match.PrefixSuffix{Prefix: r.Str, Suffix: rs.Suffix}
|
||||||
// return match.EveryOf{match.Matchers{match.Prefix{r.Str}, rs}}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if rightNil && leftPrefix {
|
if rightNil && leftPrefix {
|
||||||
return match.PrefixSuffix{Prefix: lp.Prefix, Suffix: r.Str}
|
return match.PrefixSuffix{Prefix: lp.Prefix, Suffix: r.Str}
|
||||||
// return match.EveryOf{match.Matchers{lp, match.Suffix{r.Str}}}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return m
|
return m
|
||||||
|
|
|
@ -277,8 +277,7 @@ func TestCompiler(t *testing.T) {
|
||||||
result: match.Prefix{"abc"},
|
result: match.Prefix{"abc"},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
ast: pattern(&nodeText{text: "abc"}, &nodeAny{}, &nodeText{text: "def"}),
|
ast: pattern(&nodeText{text: "abc"}, &nodeAny{}, &nodeText{text: "def"}),
|
||||||
// result: match.EveryOf{match.Matchers{match.Prefix{"abc"}, match.Suffix{"def"}}},
|
|
||||||
result: match.PrefixSuffix{"abc", "def"},
|
result: match.PrefixSuffix{"abc", "def"},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
|
@ -42,7 +42,7 @@ func TestCompilePattern(t *testing.T) {
|
||||||
exp match.Matcher
|
exp match.Matcher
|
||||||
}{
|
}{
|
||||||
// {
|
// {
|
||||||
// pattern: "{*,def}ghi",
|
// pattern: "{*,def,abc[a-z]*}ghi",
|
||||||
// exp: match.Raw{"t"},
|
// exp: match.Raw{"t"},
|
||||||
// },
|
// },
|
||||||
} {
|
} {
|
||||||
|
|
|
@ -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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue