From df67a5925fc96ea90cad3eb168dc343486b7be7b Mon Sep 17 00:00:00 2001 From: "s.kamardin" Date: Tue, 12 Jan 2016 14:13:56 +0300 Subject: [PATCH] tests --- compiler.go | 2 -- compiler_test.go | 3 +-- glob_test.go | 2 +- match/any_test.go | 37 +++++++++++++++++++++++++++++++++++++ 4 files changed, 39 insertions(+), 5 deletions(-) create mode 100644 match/any_test.go 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) + } + } +}