返回 DeepSeek-Reasonix
globset_test.go
根目录 / internal / fileutil / globset_test.go
1 package fileutil
2
3 import "testing"
4
5 func TestGlobSetIncludeExcludeDoublestar(t *testing.T) {
6 set, err := NewGlobSet([]string{"**/*.{go,ts}"}, []string{"**/vendor/**", "**/*.test.ts"})
7 if err != nil {
8 t.Fatalf("NewGlobSet: %v", err)
9 }
10 tests := map[string]bool{
11 "main.go": true,
12 "src/app.ts": true,
13 "src/app.test.ts": false,
14 "vendor/pkg/generated.go": false,
15 "README.md": false,
16 }
17 for path, want := range tests {
18 if got := set.Match(path); got != want {
19 t.Fatalf("Match(%q) = %v, want %v", path, got, want)
20 }
21 }
22 }
23
24 func TestGlobSetEmptyIncludeMeansAllExceptExcluded(t *testing.T) {
25 set, err := NewGlobSet(nil, []string{"**/*.tmp"})
26 if err != nil {
27 t.Fatalf("NewGlobSet: %v", err)
28 }
29 if !set.Match("src/app.go") {
30 t.Fatal("empty include should match ordinary file")
31 }
32 if set.Match("scratch.tmp") {
33 t.Fatal("exclude pattern should remove tmp file")
34 }
35 }
36
37 func TestMatchSlashGlobMatchesRootWithRecursivePrefix(t *testing.T) {
38 if !MatchSlashGlob("main.go", "**/*.go") {
39 t.Fatal("**/*.go should match root-level main.go")
40 }
41 }
42
42 lines GO