Skip to content

Commit 6b59125

Browse files
authored
test: add tests for glob matching (#319)
This helps demonstrate how our globbing works.
1 parent 2510126 commit 6b59125

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

format/glob_test.go

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package format_test
2+
3+
import (
4+
"testing"
5+
6+
"git.numtide.com/numtide/treefmt/format"
7+
8+
"github.com/gobwas/glob"
9+
"github.com/stretchr/testify/require"
10+
)
11+
12+
func TestGlobs(t *testing.T) {
13+
r := require.New(t)
14+
15+
var (
16+
globs []glob.Glob
17+
err error
18+
)
19+
20+
// File extension
21+
globs, err = format.CompileGlobs([]string{"*.txt"})
22+
r.NoError(err)
23+
r.True(format.PathMatches("test/foo/bar.txt", globs))
24+
r.False(format.PathMatches("test/foo/bar.txtz", globs))
25+
r.False(format.PathMatches("test/foo/bar.flob", globs))
26+
27+
// Prefix matching
28+
globs, err = format.CompileGlobs([]string{"test/*"})
29+
r.NoError(err)
30+
r.True(format.PathMatches("test/bar.txt", globs))
31+
r.True(format.PathMatches("test/foo/bar.txt", globs))
32+
r.False(format.PathMatches("/test/foo/bar.txt", globs))
33+
34+
// Exact matches
35+
// File extension
36+
globs, err = format.CompileGlobs([]string{"LICENSE"})
37+
r.NoError(err)
38+
r.True(format.PathMatches("LICENSE", globs))
39+
r.False(format.PathMatches("test/LICENSE", globs))
40+
r.False(format.PathMatches("LICENSE.txt", globs))
41+
}

nix/treefmt.nix

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
global.excludes = [
2727
"LICENSE"
2828
# let's not mess with the test folder
29-
"test/**"
29+
"test/*"
3030
# unsupported extensions
3131
"*.{gif,png,svg,tape,mts,lock,mod,sum,toml,env,envrc,gitignore}"
3232
];

0 commit comments

Comments
 (0)