mirror of
https://github.com/numtide/treefmt.git
synced 2024-10-03 20:18:11 +03:00
test: add tests for glob matching (#319)
This helps demonstrate how our globbing works.
This commit is contained in:
parent
251012657a
commit
6b591255b1
41
format/glob_test.go
Normal file
41
format/glob_test.go
Normal file
@ -0,0 +1,41 @@
|
||||
package format_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"git.numtide.com/numtide/treefmt/format"
|
||||
|
||||
"github.com/gobwas/glob"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestGlobs(t *testing.T) {
|
||||
r := require.New(t)
|
||||
|
||||
var (
|
||||
globs []glob.Glob
|
||||
err error
|
||||
)
|
||||
|
||||
// File extension
|
||||
globs, err = format.CompileGlobs([]string{"*.txt"})
|
||||
r.NoError(err)
|
||||
r.True(format.PathMatches("test/foo/bar.txt", globs))
|
||||
r.False(format.PathMatches("test/foo/bar.txtz", globs))
|
||||
r.False(format.PathMatches("test/foo/bar.flob", globs))
|
||||
|
||||
// Prefix matching
|
||||
globs, err = format.CompileGlobs([]string{"test/*"})
|
||||
r.NoError(err)
|
||||
r.True(format.PathMatches("test/bar.txt", globs))
|
||||
r.True(format.PathMatches("test/foo/bar.txt", globs))
|
||||
r.False(format.PathMatches("/test/foo/bar.txt", globs))
|
||||
|
||||
// Exact matches
|
||||
// File extension
|
||||
globs, err = format.CompileGlobs([]string{"LICENSE"})
|
||||
r.NoError(err)
|
||||
r.True(format.PathMatches("LICENSE", globs))
|
||||
r.False(format.PathMatches("test/LICENSE", globs))
|
||||
r.False(format.PathMatches("LICENSE.txt", globs))
|
||||
}
|
@ -26,7 +26,7 @@
|
||||
global.excludes = [
|
||||
"LICENSE"
|
||||
# let's not mess with the test folder
|
||||
"test/**"
|
||||
"test/*"
|
||||
# unsupported extensions
|
||||
"*.{gif,png,svg,tape,mts,lock,mod,sum,toml,env,envrc,gitignore}"
|
||||
];
|
||||
|
Loading…
Reference in New Issue
Block a user