-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstring_test.go
More file actions
246 lines (212 loc) · 7.83 KB
/
Copy pathstring_test.go
File metadata and controls
246 lines (212 loc) · 7.83 KB
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
package assert
import (
"regexp"
"testing"
)
func TestStringContainsAndNotContains(t *testing.T) {
a := New(t)
mockA := New(new(testing.T))
testStringContainsAndNotContains(a, mockA, "", "", true)
testStringContainsAndNotContains(a, mockA, "Hello world", "", true)
testStringContainsAndNotContains(a, mockA, "Hello world", "Hello", true)
testStringContainsAndNotContains(a, mockA, "Hello world", "hello", false)
testStringContainsAndNotContains(a, mockA, "", "Hello", false)
testStringContainsAndNotContains(a, mockA, "", "world", false)
testStringContainsAndNotContains(a, mockA, "Hello world", "world", true)
testStringContainsAndNotContains(a, mockA, "Hello world", "o w", true)
}
func testStringContainsAndNotContains(
a, mockA *Assertion,
str, substr string,
isContains bool,
) {
a.T.Helper()
// ContainsString
testAssertionFunction(a, "ContainsString", func() error {
return ContainsString(mockA.T, str, substr)
}, isContains)
testAssertionFunction(a, "Assertion.ContainsString", func() error {
return mockA.ContainsString(str, substr)
}, isContains)
// NotContainsString
testAssertionFunction(a, "NotContainsString", func() error {
return NotContainsString(mockA.T, str, substr)
}, !isContains)
testAssertionFunction(a, "Assertion.NotContainsString", func() error {
return mockA.NotContainsString(str, substr)
}, !isContains)
// ContainsStringNow
testAssertionNowFunction(a, "ContainsStringNow", func() {
ContainsStringNow(mockA.T, str, substr)
}, !isContains)
testAssertionNowFunction(a, "Assertion.ContainsStringNow", func() {
mockA.ContainsStringNow(str, substr)
}, !isContains)
// NotContainsStringNow
testAssertionNowFunction(a, "NotContainsStringNow", func() {
NotContainsStringNow(mockA.T, str, substr)
}, isContains)
testAssertionNowFunction(a, "Assertion.NotContainsStringNow", func() {
mockA.NotContainsStringNow(str, substr)
}, isContains)
}
func TestStringHasPrefixAndNotHasPrefix(t *testing.T) {
a := New(t)
mockA := New(new(testing.T))
testStringHasPrefixAndNotHasPrefix(a, mockA, "", "", true)
testStringHasPrefixAndNotHasPrefix(a, mockA, "Hello world", "", true)
testStringHasPrefixAndNotHasPrefix(a, mockA, "Hello world", "Hello", true)
testStringHasPrefixAndNotHasPrefix(a, mockA, "Hello world", "hello", false)
testStringHasPrefixAndNotHasPrefix(a, mockA, "", "Hello", false)
testStringHasPrefixAndNotHasPrefix(a, mockA, "", "world", false)
testStringHasPrefixAndNotHasPrefix(a, mockA, "Hello world", "world", false)
}
func testStringHasPrefixAndNotHasPrefix(
a, mockA *Assertion,
str, prefix string,
isHasPrefix bool,
) {
a.T.Helper()
// HasPrefixString
testAssertionFunction(a, "HasPrefixString", func() error {
return HasPrefixString(mockA.T, str, prefix)
}, isHasPrefix)
testAssertionFunction(a, "Assertion.HasPrefixString", func() error {
return mockA.HasPrefixString(str, prefix)
}, isHasPrefix)
// NotHasPrefixString
testAssertionFunction(a, "NotHasPrefixString", func() error {
return NotHasPrefixString(mockA.T, str, prefix)
}, !isHasPrefix)
testAssertionFunction(a, "Assertion.NotHasPrefixString", func() error {
return mockA.NotHasPrefixString(str, prefix)
}, !isHasPrefix)
// HasPrefixStringNow
testAssertionNowFunction(a, "HasPrefixStringNow", func() {
HasPrefixStringNow(mockA.T, str, prefix)
}, !isHasPrefix)
testAssertionNowFunction(a, "Assertion.HasPrefixStringNow", func() {
mockA.HasPrefixStringNow(str, prefix)
}, !isHasPrefix)
// NotHasPrefixStringNow
testAssertionNowFunction(a, "NotHasPrefixStringNow", func() {
NotHasPrefixStringNow(mockA.T, str, prefix)
}, isHasPrefix)
testAssertionNowFunction(a, "Assertion.NotHasPrefixStringNow", func() {
mockA.NotHasPrefixStringNow(str, prefix)
}, isHasPrefix)
}
func TestStringHasSuffixAndNotHasSuffix(t *testing.T) {
a := New(t)
mockA := New(new(testing.T))
testStringHasSuffixAndNotHasSuffix(a, mockA, "", "", true)
testStringHasSuffixAndNotHasSuffix(a, mockA, "Hello world", "", true)
testStringHasSuffixAndNotHasSuffix(a, mockA, "Hello world", "Hello", false)
testStringHasSuffixAndNotHasSuffix(a, mockA, "Hello world", "hello", false)
testStringHasSuffixAndNotHasSuffix(a, mockA, "", "Hello", false)
testStringHasSuffixAndNotHasSuffix(a, mockA, "", "world", false)
testStringHasSuffixAndNotHasSuffix(a, mockA, "Hello world", "world", true)
}
func testStringHasSuffixAndNotHasSuffix(
a, mockA *Assertion,
str, suffix string,
isHasSuffix bool,
) {
a.T.Helper()
// HasSuffixString
testAssertionFunction(a, "HasSuffixString", func() error {
return HasSuffixString(mockA.T, str, suffix)
}, isHasSuffix)
testAssertionFunction(a, "Assertion.HasSuffixString", func() error {
return mockA.HasSuffixString(str, suffix)
}, isHasSuffix)
// NotHasSuffixString
testAssertionFunction(a, "NotHasSuffixString", func() error {
return NotHasSuffixString(mockA.T, str, suffix)
}, !isHasSuffix)
testAssertionFunction(a, "Assertion.NotHasSuffixString", func() error {
return mockA.NotHasSuffixString(str, suffix)
}, !isHasSuffix)
// HasSuffixStringNow
testAssertionNowFunction(a, "HasSuffixStringNow", func() {
HasSuffixStringNow(mockA.T, str, suffix)
}, !isHasSuffix)
testAssertionNowFunction(a, "Assertion.HasSuffixStringNow", func() {
mockA.HasSuffixStringNow(str, suffix)
}, !isHasSuffix)
// NotHasSuffixStringNow
testAssertionNowFunction(a, "NotHasSuffixStringNow", func() {
NotHasSuffixStringNow(mockA.T, str, suffix)
}, isHasSuffix)
testAssertionNowFunction(a, "Assertion.NotHasSuffixStringNow", func() {
mockA.NotHasSuffixStringNow(str, suffix)
}, isHasSuffix)
}
func TestMatchAndNotMatch(t *testing.T) {
a := New(t)
mockA := New(new(testing.T))
testMatchAndNotMatch(a, mockA, "Hello", `.+`, true)
testMatchAndNotMatch(a, mockA, "", `.+`, false)
testMatchAndNotMatch(a, mockA, "Hello", `^H`, true)
testMatchAndNotMatch(a, mockA, "hello", `^H`, false)
}
func testMatchAndNotMatch(a, mockA *Assertion, val string, pattern string, isMatch bool) {
a.T.Helper()
regPattern := regexp.MustCompile(pattern)
// MatchString
testAssertionFunction(a, "MatchString", func() error {
return MatchString(mockA.T, val, pattern)
}, isMatch)
testAssertionFunction(a, "Assertion.MatchString", func() error {
return mockA.MatchString(val, pattern)
}, isMatch)
// NotMatchString
testAssertionFunction(a, "NotMatchString", func() error {
return NotMatchString(mockA.T, val, pattern)
}, !isMatch)
testAssertionFunction(a, "Assertion.NotMatchString", func() error {
return mockA.NotMatchString(val, pattern)
}, !isMatch)
// MatchStringNow
testAssertionNowFunction(a, "MatchStringNow", func() {
MatchStringNow(mockA.T, val, pattern)
}, !isMatch)
testAssertionNowFunction(a, "Assertion.MatchStringNow", func() {
mockA.MatchStringNow(val, pattern)
}, !isMatch)
// NotMatchStringNow
testAssertionNowFunction(a, "NotMatchStringNow", func() {
NotMatchStringNow(mockA.T, val, pattern)
}, isMatch)
testAssertionNowFunction(a, "Assertion.NotMatchStringNow", func() {
mockA.NotMatchStringNow(val, pattern)
}, isMatch)
// Match
testAssertionFunction(a, "Match", func() error {
return Match(mockA.T, val, regPattern)
}, isMatch)
testAssertionFunction(a, "Assertion.Match", func() error {
return mockA.Match(val, regPattern)
}, isMatch)
// NotMatch
testAssertionFunction(a, "NotMatch", func() error {
return NotMatch(mockA.T, val, regPattern)
}, !isMatch)
testAssertionFunction(a, "Assertion.NotMatch", func() error {
return mockA.NotMatch(val, regPattern)
}, !isMatch)
// MatchNow
testAssertionNowFunction(a, "MatchNow", func() {
MatchNow(mockA.T, val, regPattern)
}, !isMatch)
testAssertionNowFunction(a, "Assertion.MatchNow", func() {
mockA.MatchNow(val, regPattern)
}, !isMatch)
// NotMatchNow
testAssertionNowFunction(a, "NotMatchNow", func() {
NotMatchNow(mockA.T, val, regPattern)
}, isMatch)
testAssertionNowFunction(a, "Assertion.NotMatchNow", func() {
mockA.NotMatchNow(val, regPattern)
}, isMatch)
}