-
Notifications
You must be signed in to change notification settings - Fork 3
/
regexes_test.go
44 lines (40 loc) · 975 Bytes
/
regexes_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
package porto
import (
"regexp"
"testing"
"github.com/stretchr/testify/assert"
)
func TestGetRegexpList(t *testing.T) {
tests := []struct {
name string
regexps string
expected []*regexp.Regexp
err string
}{
{
name: "single regex",
regexps: "^.*pb.go$",
expected: []*regexp.Regexp{regexp.MustCompile("^.*pb.go$")},
},
{
name: "failing regex",
regexps: "^.*pb.go$,*$$",
err: "failed to compile regex \"*$$\": error parsing regexp: missing argument to repetition operator: `*`",
},
{
name: "multiple regexes",
regexps: "^.*pb.go$,^tools.go$",
expected: []*regexp.Regexp{regexp.MustCompile("^.*pb.go$"), regexp.MustCompile("^tools.go$")},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
actual, err := GetRegexpList(tt.regexps)
if err != nil || tt.err != "" {
assert.EqualError(t, err, tt.err)
} else {
assert.Equal(t, tt.expected, actual)
}
})
}
}