filter: explicitly test separate ListWithChild function

This commit is contained in:
Michael Eischer 2020-10-07 20:12:38 +02:00
parent bcc3bddcf4
commit 54a124de3b

View file

@ -240,21 +240,22 @@ func ExampleMatch_wildcards() {
} }
var filterListTests = []struct { var filterListTests = []struct {
patterns []string patterns []string
path string path string
match bool match bool
childMatch bool
}{ }{
{[]string{}, "/foo/bar/test.go", false}, {[]string{}, "/foo/bar/test.go", false, false},
{[]string{"*.go"}, "/foo/bar/test.go", true}, {[]string{"*.go"}, "/foo/bar/test.go", true, true},
{[]string{"*.c"}, "/foo/bar/test.go", false}, {[]string{"*.c"}, "/foo/bar/test.go", false, true},
{[]string{"*.go", "*.c"}, "/foo/bar/test.go", true}, {[]string{"*.go", "*.c"}, "/foo/bar/test.go", true, true},
{[]string{"*"}, "/foo/bar/test.go", true}, {[]string{"*"}, "/foo/bar/test.go", true, true},
{[]string{"x"}, "/foo/bar/test.go", false}, {[]string{"x"}, "/foo/bar/test.go", false, true},
{[]string{"?"}, "/foo/bar/test.go", false}, {[]string{"?"}, "/foo/bar/test.go", false, true},
{[]string{"?", "x"}, "/foo/bar/x", true}, {[]string{"?", "x"}, "/foo/bar/x", true, true},
{[]string{"/*/*/bar/test.*"}, "/foo/bar/test.go", false}, {[]string{"/*/*/bar/test.*"}, "/foo/bar/test.go", false, false},
{[]string{"/*/*/bar/test.*", "*.go"}, "/foo/bar/test.go", true}, {[]string{"/*/*/bar/test.*", "*.go"}, "/foo/bar/test.go", true, true},
{[]string{"", "*.c"}, "/foo/bar/test.go", false}, {[]string{"", "*.c"}, "/foo/bar/test.go", false, true},
} }
func TestList(t *testing.T) { func TestList(t *testing.T) {
@ -268,9 +269,21 @@ func TestList(t *testing.T) {
} }
if match != test.match { if match != test.match {
t.Errorf("test %d: filter.MatchList(%q, %q): expected %v, got %v", t.Errorf("test %d: filter.List(%q, %q): expected %v, got %v",
i, test.patterns, test.path, test.match, match) i, test.patterns, test.path, test.match, match)
} }
match, childMatch, err := filter.ListWithChild(patterns, test.path)
if err != nil {
t.Errorf("test %d failed: expected no error for patterns %q, but error returned: %v",
i, test.patterns, err)
continue
}
if match != test.match || childMatch != test.childMatch {
t.Errorf("test %d: filter.ListWithChild(%q, %q): expected %v, %v, got %v, %v",
i, test.patterns, test.path, test.match, test.childMatch, match, childMatch)
}
} }
} }