-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathstring_matcher_test.go
More file actions
54 lines (46 loc) · 823 Bytes
/
string_matcher_test.go
File metadata and controls
54 lines (46 loc) · 823 Bytes
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
package gomatch
import (
"testing"
"github.com/stretchr/testify/assert"
)
var stringMatcherTests = []struct {
desc string
v interface{}
ok bool
errMsg string
}{
{
"Should match string",
"some valid string",
true,
"",
},
{
"Should not match number",
1234,
false,
"expected string",
},
{
"Should not match slice",
[]interface{}{"a", "b"},
false,
"expected string",
},
}
func TestStringMatcher(t *testing.T) {
pattern := "@pattern@"
for _, tt := range stringMatcherTests {
m := NewStringMatcher(pattern)
assert.True(t, m.CanMatch(pattern), "expected to support pattern")
t.Logf(tt.desc)
ok, err := m.Match(pattern, tt.v)
if tt.ok {
assert.True(t, ok)
assert.Nil(t, err)
} else {
assert.False(t, ok)
assert.EqualError(t, err, tt.errMsg)
}
}
}