-
Notifications
You must be signed in to change notification settings - Fork 42
/
strings_test.go
111 lines (101 loc) · 2.3 KB
/
strings_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
101
102
103
104
105
106
107
108
109
110
111
package exp
import "testing"
var m = Map{
"foo": "bar",
"bar": "baz",
"baz": "booyah",
}
func TestMatch(t *testing.T) {
for key, value := range map[string]string{
"foo": "bar",
"bar": "baz",
"baz": "booyah",
} {
if !Match(key, value).Eval(m) {
t.Errorf("Match(%q, %q) should evaluate to true", key, value)
}
}
}
func TestMatchAny(t *testing.T) {
for key, values := range map[string][]string{
"foo": {"bar", "zzz"},
"bar": {"zzz", "baz"},
} {
if !MatchAny(key, values...).Eval(m) {
t.Errorf("MatchAny(%q, %q) should evaluate to true", key, values)
}
}
}
func TestContains(t *testing.T) {
for key, substr := range map[string][]string{
"foo": {"ar", "ba", "bar"},
"bar": {"ba", "az", "baz"},
} {
for _, s := range substr {
if !Contains(key, s).Eval(m) {
t.Errorf("Contains(%q, %q) should evaluate to true", key, s)
}
}
}
}
func TestContainsAny(t *testing.T) {
for key, chars := range map[string][]string{
"foo": {"abc", "abr", "rtu"},
"bar": {"ab", "zax", "wea"},
"baz": {"oq", "ya", "ha"},
} {
for _, c := range chars {
if !ContainsAny(key, c).Eval(m) {
t.Errorf("ContainsAny(%q, %q) should evaluate to true", key, c)
}
}
}
}
func TestContainsRune(t *testing.T) {
for key, runes := range map[string][]rune{
"foo": {'b', 'a', 'r'},
"bar": {'b', 'a', 'z'},
"baz": {'b', 'o', 'y', 'a', 'h'},
} {
for _, r := range runes {
if !ContainsRune(key, r).Eval(m) {
t.Errorf("ContainsRune(%q, %q) should evaluate to true", key, r)
}
}
}
}
func TestLen(t *testing.T) {
for key, length := range map[string]int{
"foo": 3,
"bar": 3,
"baz": 6,
} {
if !Len(key, length).Eval(m) {
t.Errorf("Len(%q, %d) should evaluate to true", key, length)
}
}
}
func TestCount(t *testing.T) {
for key, tests := range map[string]map[string]int{
"foo": {"b": 1, "a": 1, "r": 1},
"bar": {"b": 1, "a": 1, "z": 1},
"baz": {"b": 1, "o": 2, "y": 1},
} {
for sep, length := range tests {
if !Count(key, sep, length).Eval(m) {
t.Errorf("Count(%q, %q, %d) should evaluate to true", key, sep, length)
}
}
}
}
func TestEqualFold(t *testing.T) {
for key, fold := range map[string]string{
"foo": "Bar",
"bar": "Baz",
"baz": "BooYah",
} {
if !EqualFold(key, fold).Eval(m) {
t.Errorf("EqualFold(%q, %q) should evaluate to true", key, fold)
}
}
}