GitRoot

craft your forge, build your project, grow your community freely
 1// SPDX-FileCopyrightText: 2025 Romain Maneschi <romain@gitroot.dev>
 2//
 3// SPDX-License-Identifier: MIT
 4
 5package glob
 6
 7import (
 8	"testing"
 9)
10
11type data struct {
12	pattern     string
13	filepath    []string
14	shouldMatch bool
15}
16
17func TestDoubleStar(t *testing.T) {
18	d := []data{
19		{pattern: "**/*.md", filepath: []string{"submodule.md", "src/app/module/submodule.md"}, shouldMatch: true},
20		{pattern: "**/*.md", filepath: []string{"src/app/module/submodule.go"}, shouldMatch: false},
21		{pattern: "**/*.md|**/*.go", filepath: []string{"submodule.md", "src/app/module/submodule.go"}, shouldMatch: true},
22		{pattern: "**/*.go|!**/*.md", filepath: []string{"submodule.go"}, shouldMatch: true},
23		{pattern: "**/*|!**/*.md", filepath: []string{"submodule.md"}, shouldMatch: false},
24	}
25
26	for _, i := range d {
27		g, _ := NewGlob(i.pattern)
28		for _, f := range i.filepath {
29			match := g.Match(f)
30			if i.shouldMatch && !match {
31				t.Fatalf("%s should be compatible with %s", i.pattern, f)
32			} else if !i.shouldMatch && match {
33				t.Fatalf("%s should not be compatible with %s", i.pattern, f)
34			}
35		}
36	}
37}