diff --git a/compiler.go b/compiler.go index 67aecc5..3b79c95 100644 --- a/compiler.go +++ b/compiler.go @@ -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 diff --git a/compiler_test.go b/compiler_test.go index 5e919cc..94e8101 100644 --- a/compiler_test.go +++ b/compiler_test.go @@ -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"}, }, { diff --git a/glob_test.go b/glob_test.go index 473c62f..1228a2b 100644 --- a/glob_test.go +++ b/glob_test.go @@ -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"}, // }, } { diff --git a/match/any_test.go b/match/any_test.go new file mode 100644 index 0000000..e526b83 --- /dev/null +++ b/match/any_test.go @@ -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) + } + } +}