-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathregex_test.go
70 lines (65 loc) · 1.15 KB
/
regex_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
package rbac
import (
"fmt"
"testing"
"github.com/stretchr/testify/assert"
)
func TestRegexMatch(t *testing.T) {
cases := map[string]map[string]bool{
"": {
"": true,
"alpha": true,
"beta": true,
"charlie": true,
},
".*": {
"": true,
"alpha": true,
"beta": true,
"charlie": true,
},
"alpha": {
"": false,
"alpha": true,
"beta": false,
"charlie": false,
},
"^a.*$": {
"": false,
"alpha": true,
"beta": false,
"charlie": false,
},
"^.*a$": {
"": false,
"alpha": true,
"beta": true,
"charlie": false,
},
"a": {
"": false,
"alpha": true,
"beta": true,
"charlie": true,
},
"delta": {
"": false,
"alpha": false,
"beta": false,
"charlie": false,
},
}
for pattern, inputs := range cases {
matcher := RegexMatch(pattern)
for input, expected := range inputs {
name := fmt.Sprintf("%s/%s", pattern, input)
t.Run(name, func(t *testing.T) {
result, err := matcher(input)
if err != nil {
t.Fatal(err)
}
assert.Equal(t, expected, result)
})
}
}
}