Skip to content

Commit

Permalink
match by stripping the prefix './'
Browse files Browse the repository at this point in the history
  • Loading branch information
makiuchi-d committed Dec 8, 2022
1 parent d6350a8 commit 04cf358
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
9 changes: 9 additions & 0 deletions arelo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
24 changes: 24 additions & 0 deletions arelo_watcher_test.go → arelo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}

0 comments on commit 04cf358

Please sign in to comment.