From 04cf358f3cf360afe24b0df7cceb90ec439a6ee4 Mon Sep 17 00:00:00 2001 From: makki_d Date: Thu, 8 Dec 2022 17:18:50 +0000 Subject: [PATCH] match by stripping the prefix './' --- arelo.go | 9 +++++++++ arelo_watcher_test.go => arelo_test.go | 24 ++++++++++++++++++++++++ 2 files changed, 33 insertions(+) rename arelo_watcher_test.go => arelo_test.go (76%) diff --git a/arelo.go b/arelo.go index dca342b..f16a402 100644 --- a/arelo.go +++ b/arelo.go @@ -212,6 +212,15 @@ func matchPatterns(t string, pats []string) (bool, error) { if m { return true, nil } + if strings.HasPrefix(t, "./") { + m, err = doublestar.Match(p, t[2:]) + if err != nil { + return false, xerrors.Errorf("match(%v, %v): %w", p, t[2:], err) + } + if m { + return true, nil + } + } } return false, nil } diff --git a/arelo_watcher_test.go b/arelo_test.go similarity index 76% rename from arelo_watcher_test.go rename to arelo_test.go index 717ad4c..c643d1b 100644 --- a/arelo_watcher_test.go +++ b/arelo_test.go @@ -84,3 +84,27 @@ func clearChan(c <-chan string, ce <-chan error) { func touchFile(file string) { os.WriteFile(file, []byte("a"), 0644) } + +func TestMatchPatterns(t *testing.T) { + tests := []struct { + t, pat string + wants bool + }{ + {"ab/cd/efg", "**/efg", true}, + {"ab/cd/efg", "*/efg", false}, + {"./abc.efg", "**/*.efg", true}, + {"./abc.efg", "*.efg", true}, + {"./.abc", "**/.*", true}, + {"./.abc", ".*", true}, + } + + for _, test := range tests { + r, err := matchPatterns(test.t, []string{test.pat}) + if err != nil { + t.Fatalf("matchPatterns(%v, {%v}): %v", test.t, test.pat, err) + } + if r != test.wants { + t.Fatalf("matchPatterns(%v, {%v}) = %v wants %v", test.t, test.pat, r, test.wants) + } + } +}