-
Notifications
You must be signed in to change notification settings - Fork 0
/
regex_test.go
59 lines (51 loc) · 1.29 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
package matchers_test
import (
"fmt"
"testing"
matchers "github.com/Storytel/gomock-matchers/v2"
"github.com/stretchr/testify/assert"
)
func TestRegexpMatcher(t *testing.T) {
testCases := []struct {
pattern string
value interface{}
matches bool
}{
{"^something .*", "something good", true},
{"^something .*", "that's something good", false},
{"^[0-9][1-5]a?$", "42a", true},
{".*", 12, false},
}
for i, testCase := range testCases {
t.Run(fmt.Sprintf("Test #%d", i), func(t *testing.T) {
assert := assert.New(t)
m := matchers.Regexp(testCase.pattern)
assert.Equal(testCase.matches, m.Matches(testCase.value))
})
}
}
func TestRegexpMatcherCompileError(t *testing.T) {
defer func() {
if r := recover(); r == nil {
t.Errorf("invalid regexp did not panic")
}
}()
_ = matchers.Regexp("^(abc$")
}
func TestRegexpMatcherString(t *testing.T) {
testCases := []struct {
pattern string
str string
}{
{"^[a-z]$", "matches pattern /^[a-z]$/"},
{"asdf", "matches pattern /asdf/"},
{"something[[:space:]]", "matches pattern /something[[:space:]]/"},
}
for i, testCase := range testCases {
t.Run(fmt.Sprintf("Test #%d", i), func(t *testing.T) {
assert := assert.New(t)
m := matchers.Regexp(testCase.pattern)
assert.Equal(testCase.str, m.String())
})
}
}