diff --git a/internal/filter/filter_test.go b/internal/filter/filter_test.go index 97df452fb..0aedaeb71 100644 --- a/internal/filter/filter_test.go +++ b/internal/filter/filter_test.go @@ -244,6 +244,7 @@ var filterListTests = []struct { path string match bool }{ + {[]string{}, "/foo/bar/test.go", false}, {[]string{"*.go"}, "/foo/bar/test.go", true}, {[]string{"*.c"}, "/foo/bar/test.go", false}, {[]string{"*.go", "*.c"}, "/foo/bar/test.go", true}, @@ -279,6 +280,38 @@ func ExampleList() { // match: true } +func TestInvalidStrs(t *testing.T) { + _, err := filter.Match("test", "") + if err == nil { + t.Error("Match accepted invalid path") + } + + _, err = filter.ChildMatch("test", "") + if err == nil { + t.Error("ChildMatch accepted invalid path") + } + + patterns := []string{"test"} + _, _, err = filter.List(patterns, "") + if err == nil { + t.Error("List accepted invalid path") + } +} + +func TestInvalidPattern(t *testing.T) { + patterns := []string{"test/["} + _, _, err := filter.List(patterns, "test/example") + if err == nil { + t.Error("List accepted invalid pattern") + } + + patterns = []string{"test/**/["} + _, _, err = filter.List(patterns, "test/example") + if err == nil { + t.Error("List accepted invalid pattern") + } +} + func extractTestLines(t testing.TB) (lines []string) { f, err := os.Open("testdata/libreoffice.txt.bz2") if err != nil {