From 4e630ec62457fe14df0fd372d822d196ac973bc8 Mon Sep 17 00:00:00 2001 From: Svyatoslav Kryukov Date: Tue, 18 May 2021 14:58:08 +0300 Subject: [PATCH] Case-insensitive glob --- cmd/run.go | 4 ++-- cmd/run_test.go | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 cmd/run_test.go diff --git a/cmd/run.go b/cmd/run.go index d4d6b851..4b4697bb 100644 --- a/cmd/run.go +++ b/cmd/run.go @@ -546,11 +546,11 @@ func FilterGlob(vs []string, matcher string) []string { return vs } - g := glob.MustCompile(matcher) + g := glob.MustCompile(strings.ToLower(matcher)) vsf := make([]string, 0) for _, v := range vs { - if res := g.Match(v); res { + if res := g.Match(strings.ToLower(v)); res { vsf = append(vsf, v) } } diff --git a/cmd/run_test.go b/cmd/run_test.go new file mode 100644 index 00000000..099c5a57 --- /dev/null +++ b/cmd/run_test.go @@ -0,0 +1,16 @@ +package cmd + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestFilterGlob(t *testing.T) { + files := []string{"path/to/file.jpg", "path/to/file.png", "path/to/file.go", "path/to/another-file.JPG"} + pattern := "*.{jpg,PNG}" + result := FilterGlob(files, pattern) + + expected := []string{"path/to/file.jpg", "path/to/file.png", "path/to/another-file.JPG"} + assert.ElementsMatch(t, expected, result) +}