Adds any_of / every_of tests

This commit is contained in:
Jesse Donat 2016-05-05 16:57:46 -05:00
parent 62800bb501
commit 498a8df743
2 changed files with 100 additions and 0 deletions

50
any_of_test.go Normal file
View File

@ -0,0 +1,50 @@
package glob
import "testing"
func TestAnyOfMatch(t *testing.T) {
for id, test := range []struct {
globs Globs
fixture string
match bool
}{
{
Globs{},
"abcd",
false,
},
{
Globs{
MustCompile("a*"),
MustCompile("ab*"),
MustCompile("abc*"),
},
"abcd",
true,
},
{
Globs{
MustCompile("xa*"),
MustCompile("xab*"),
MustCompile("xabc*"),
},
"abcd",
false,
},
{
Globs{
MustCompile("xa*"),
MustCompile("xab*"),
MustCompile("abc*"),
},
"abcd",
true,
},
} {
anyOf := NewAnyOf(test.globs...)
match := anyOf.Match(test.fixture)
if match != test.match {
t.Errorf("#%d unexpected index: exp: %t, act: %t", id, test.match, match)
}
}
}

50
every_of_test.go Normal file
View File

@ -0,0 +1,50 @@
package glob
import "testing"
func TestEveryOfMatch(t *testing.T) {
for id, test := range []struct {
globs Globs
fixture string
match bool
}{
{
Globs{},
"abcd",
true,
},
{
Globs{
MustCompile("a*"),
MustCompile("ab*"),
MustCompile("abc*"),
},
"abcd",
true,
},
{
Globs{
MustCompile("a*"),
MustCompile("axb*"),
MustCompile("abc*"),
},
"abcd",
false,
},
{
Globs{
MustCompile("a*"),
MustCompile("ab*"),
MustCompile("abcx*"),
},
"abcd",
false,
},
} {
everyOf := NewEveryOf(test.globs...)
match := everyOf.Match(test.fixture)
if match != test.match {
t.Errorf("#%d unexpected index: exp: %t, act: %t", id, test.match, match)
}
}
}