MCPcopy Create free account
hub / github.com/JordanCoin/codemap / TestMatchesPattern

Function TestMatchesPattern

scanner/walker_test.go:571–605  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

569}
570
571func TestMatchesPattern(t *testing.T) {
572 tests := []struct {
573 name string
574 relPath string
575 pattern string
576 want bool
577 }{
578 {name: "glob broad filename match", relPath: "src/service_test.go", pattern: "*test*", want: true},
579 {name: "glob filename match", relPath: "src/user_test.go", pattern: "*_test.go", want: true},
580 {name: "glob path match", relPath: "assets/icons/logo.svg", pattern: "assets/*/*.svg", want: true},
581 {name: "extension with dot", relPath: "assets/logo.png", pattern: ".png", want: true},
582 {name: "extension without dot", relPath: "assets/logo.PNG", pattern: "png", want: true},
583 {name: "directory component mixed case path", relPath: "App/Fonts/Roboto.ttf", pattern: "Fonts", want: true},
584 {name: "directory component", relPath: "src/Fonts/Inter.ttf", pattern: "Fonts", want: true},
585 {name: "exact directory path", relPath: "Fonts", pattern: "Fonts", want: true},
586 {name: "exact directory name", relPath: "dist", pattern: "dist", want: true},
587 {name: "no vendor match", relPath: "src/main.go", pattern: "vendor", want: false},
588 {name: "no match", relPath: "src/main.go", pattern: "images", want: false},
589 }
590
591 for _, tt := range tests {
592 t.Run(tt.name, func(t *testing.T) {
593 relPath := filepath.ToSlash(filepath.FromSlash(tt.relPath))
594 pattern := tt.pattern
595 if strings.Contains(pattern, "/") {
596 pattern = filepath.ToSlash(filepath.FromSlash(pattern))
597 }
598
599 got := matchesPattern(relPath, pattern)
600 if got != tt.want {
601 t.Fatalf("matchesPattern(%q, %q): want %v, got %v", relPath, pattern, tt.want, got)
602 }
603 })
604 }
605}
606
607func TestShouldIncludeFile(t *testing.T) {
608 tests := []struct {

Callers

nothing calls this directly

Calls 1

matchesPatternFunction · 0.85

Tested by

no test coverage detected