-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathglobset_test.go
100 lines (90 loc) · 3.04 KB
/
globset_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package ohmyglob
import (
"strings"
"testing"
"github.com/stretchr/testify/assert"
)
func TestGlobSet_MatchString(t *testing.T) {
patterns := []string{
"foo/*/baz",
"!foo/notme/baz",
"!foo/butyesme/baz",
"foo/butyesme/baz",
"!foo/notme/baz",
"!foo/*/baz/foo/**",
}
set, err := CompileGlobSet(patterns, DefaultOptions)
assert.NoError(t, err)
match := "foo/baz/baz"
assert.True(t, set.MatchString(match), "(%s) should match %s", set.String(), match)
match = "foo/notme/baz"
assert.False(t, set.MatchString(match), "(%s) should not match %s", set.String(), match)
match = "foo/butyesme/baz"
assert.True(t, set.MatchString(match), "(%s) should match %s", set.String(), match)
match = "foo/boop/baz/foo/bar/baz"
assert.False(t, set.MatchString(match), "(%s) should not match %s", set.String(), match)
}
func TestGlobSet_Match(t *testing.T) {
patterns := []string{
"foo/*/baz",
"!foo/notme/baz",
"!foo/butyesme/baz",
"foo/butyesme/baz",
"!foo/notme/baz",
"!foo/*/baz/foo/**",
}
set, err := CompileGlobSet(patterns, DefaultOptions)
assert.NoError(t, err)
match := []byte("foo/baz/baz")
assert.True(t, set.Match(match), "(%s) should match %s", set.String(), match)
match = []byte("foo/notme/baz")
assert.False(t, set.Match(match), "(%s) should not match %s", set.String(), match)
match = []byte("foo/butyesme/baz")
assert.True(t, set.Match(match), "(%s) should match %s", set.String(), match)
match = []byte("foo/boop/baz/foo/bar/baz")
assert.False(t, set.Match(match), "(%s) should not match %s", set.String(), match)
}
func TestGlobSet_MatchReader(t *testing.T) {
patterns := []string{
"foo/*/baz",
"!foo/notme/baz",
"!foo/butyesme/baz",
"foo/butyesme/baz",
"!foo/notme/baz",
"!foo/*/baz/foo/**",
}
set, err := CompileGlobSet(patterns, DefaultOptions)
assert.NoError(t, err)
match := "foo/baz/baz"
matchReader := strings.NewReader(match)
assert.True(t, set.MatchReader(matchReader), "(%s) should match %s", set.String(), match)
match = "foo/notme/baz"
matchReader = strings.NewReader(match)
assert.False(t, set.MatchReader(matchReader), "(%s) should not match %s", set.String(), match)
match = "foo/butyesme/baz"
matchReader = strings.NewReader(match)
assert.True(t, set.MatchReader(matchReader), "(%s) should match %s", set.String(), match)
match = "foo/boop/baz/foo/bar/baz"
matchReader = strings.NewReader(match)
assert.False(t, set.MatchReader(matchReader), "(%s) should not match %s", set.String(), match)
}
func TestGlobSet_AllMatchingGlobs(t *testing.T) {
patterns := []string{
"foo/**/baz",
"!foo/notme/baz",
"!foo/butyesme/baz",
"foo/butyesme/baz",
"!foo/notme/baz",
"!foo/*/baz/foo/**",
}
set, err := CompileGlobSet(patterns, DefaultOptions)
assert.NoError(t, err)
match := []byte("foo/notme/baz")
assert.Len(t, set.AllMatchingGlobs(match), 3)
match = []byte("foo/butyesme/baz")
assert.Len(t, set.AllMatchingGlobs(match), 3)
match = []byte("foo/yes/baz/foo/123")
assert.Len(t, set.AllMatchingGlobs(match), 1)
match = []byte("foo/yes/baz/foo/123/baz")
assert.Len(t, set.AllMatchingGlobs(match), 2)
}