From 498a8df74305a4df94bf1b50edba568c3639a4ef Mon Sep 17 00:00:00 2001 From: Jesse Donat Date: Thu, 5 May 2016 16:57:46 -0500 Subject: [PATCH] Adds any_of / every_of tests --- any_of_test.go | 50 ++++++++++++++++++++++++++++++++++++++++++++++++ every_of_test.go | 50 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 100 insertions(+) create mode 100644 any_of_test.go create mode 100644 every_of_test.go diff --git a/any_of_test.go b/any_of_test.go new file mode 100644 index 0000000..76b5d85 --- /dev/null +++ b/any_of_test.go @@ -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) + } + } +} diff --git a/every_of_test.go b/every_of_test.go new file mode 100644 index 0000000..c914187 --- /dev/null +++ b/every_of_test.go @@ -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) + } + } +}