@@ -5,6 +5,58 @@ import (
5
5
"testing"
6
6
)
7
7
8
+ // ContainsString tests whether the string contains the substring or not, and it set the result to
9
+ // fail if the string does not contains the substring.
10
+ //
11
+ // ContainsString(t, "Hello world", "") // success
12
+ // ContainsString(t, "Hello world", "Hello") // success
13
+ // ContainsString(t, "Hello world", "world") // success
14
+ // ContainsString(t, "Hello world", "hello") // fail
15
+ func ContainsString (t * testing.T , str , substr string , message ... any ) error {
16
+ t .Helper ()
17
+
18
+ return tryContainsString (t , false , str , substr , message ... )
19
+ }
20
+
21
+ // ContainsStringNow tests whether the string contains the substring or not, and it will terminate the
22
+ // execution if the string does not contains the substring.
23
+ //
24
+ // ContainsStringNow(t, "Hello world", "") // success
25
+ // ContainsStringNow(t, "Hello world", "Hello") // success
26
+ // ContainsStringNow(t, "Hello world", "world") // success
27
+ // ContainsStringNow(t, "Hello world", "hello") // fail and stop the execution
28
+ // // never runs
29
+ func ContainsStringNow (t * testing.T , str , substr string , message ... any ) error {
30
+ t .Helper ()
31
+
32
+ return tryContainsString (t , true , str , substr , message ... )
33
+ }
34
+
35
+ // NotContainsString tests whether the string contains the substring or not, and it set the result
36
+ // to fail if the string contains the substring.
37
+ //
38
+ // NotContainsString(t, "Hello world", "") // fail
39
+ // NotContainsString(t, "Hello world", "Hello") // fail
40
+ // NotContainsString(t, "Hello world", "world") // fail
41
+ // NotContainsString(t, "Hello world", "hello") // success
42
+ func NotContainsString (t * testing.T , str , substr string , message ... any ) error {
43
+ t .Helper ()
44
+
45
+ return tryNotContainsString (t , false , str , substr , message ... )
46
+ }
47
+
48
+ // NotContainsStringNow tests whether the string contains the substring or not, and it will terminate the
49
+ // execution if the string does not contains the substring.
50
+ //
51
+ // NotContainsStringNow(t, "Hello world", "hello") // success
52
+ // NotContainsStringNow(t, "Hello world", "Hello") // fail and stop the execution
53
+ // // never runs
54
+ func NotContainsStringNow (t * testing.T , str , substr string , message ... any ) error {
55
+ t .Helper ()
56
+
57
+ return tryNotContainsString (t , true , str , substr , message ... )
58
+ }
59
+
8
60
// DeepEqual tests the deep equality between actual and expect parameters. It'll set the result to
9
61
// fail if they are not deeply equal, and it doesn't stop the execution.
10
62
//
@@ -114,6 +166,110 @@ func NotEqualNow(t *testing.T, actual, expect any, message ...any) error {
114
166
return tryNotEqual (t , true , actual , expect , message ... )
115
167
}
116
168
169
+ // HasPrefixString tests whether the string has the prefix string or not, and it set the result to
170
+ // fail if the string does not have the prefix string.
171
+ //
172
+ // HasPrefixString(t, "Hello world", "") // success
173
+ // HasPrefixString(t, "Hello world", "Hello") // success
174
+ // HasPrefixString(t, "Hello world", "world") // fail
175
+ // HasPrefixString(t, "Hello world", "hello") // fail
176
+ func HasPrefixString (t * testing.T , str , prefix string , message ... any ) error {
177
+ t .Helper ()
178
+
179
+ return tryHasPrefixString (t , false , str , prefix , message ... )
180
+ }
181
+
182
+ // HasPrefixStringNow tests whether the string has the prefix string or not, and it will terminate
183
+ // the execution if the string does not have the prefix string.
184
+ //
185
+ // HasPrefixStringNow(t, "Hello world", "") // success
186
+ // HasPrefixStringNow(t, "Hello world", "Hello") // success
187
+ // HasPrefixStringNow(t, "Hello world", "hello") // fail and stop the execution
188
+ // // never runs
189
+ func HasPrefixStringNow (t * testing.T , str , prefix string , message ... any ) error {
190
+ t .Helper ()
191
+
192
+ return tryHasPrefixString (t , true , str , prefix , message ... )
193
+ }
194
+
195
+ // NotHasPrefixString tests whether the string has the prefix string or not, and it set the result
196
+ // to fail if the string have the prefix string.
197
+ //
198
+ // NotHasPrefixString(t, "Hello world", "hello") // success
199
+ // NotHasPrefixString(t, "Hello world", "world") // success
200
+ // NotHasPrefixString(t, "Hello world", "") // fail
201
+ // NotHasPrefixString(t, "Hello world", "Hello") // fail
202
+ func NotHasPrefixString (t * testing.T , str , prefix string , message ... any ) error {
203
+ t .Helper ()
204
+
205
+ return tryNotHasPrefixString (t , false , str , prefix , message ... )
206
+ }
207
+
208
+ // NotHasPrefixStringNow tests whether the string has the prefix string or not, and it will
209
+ // terminate the execution if the string have the prefix string.
210
+ //
211
+ // NotHasPrefixStringNow(t, "Hello world", "hello") // success
212
+ // NotHasPrefixStringNow(t, "Hello world", "world") // success
213
+ // NotHasPrefixStringNow(t, "Hello world", "Hello") // fail and stop the execution
214
+ // // never runs
215
+ func NotHasPrefixStringNow (t * testing.T , str , prefix string , message ... any ) error {
216
+ t .Helper ()
217
+
218
+ return tryNotHasPrefixString (t , true , str , prefix , message ... )
219
+ }
220
+
221
+ // HasSuffixString tests whether the string has the suffix string or not, and it set the result to
222
+ // fail if the string does not have the suffix string.
223
+ //
224
+ // HasSuffixString(t, "Hello world", "") // success
225
+ // HasSuffixString(t, "Hello world", "world") // success
226
+ // HasSuffixString(t, "Hello world", "World") // fail
227
+ // HasSuffixString(t, "Hello world", "hello") // fail
228
+ func HasSuffixString (t * testing.T , str , suffix string , message ... any ) error {
229
+ t .Helper ()
230
+
231
+ return tryHasSuffixString (t , false , str , suffix , message ... )
232
+ }
233
+
234
+ // HasSuffixStringNow tests whether the string has the suffix string or not, and it will terminate
235
+ // the execution if the string does not have the suffix string.
236
+ //
237
+ // HasSuffixStringNow(t, "Hello world", "") // success
238
+ // HasSuffixStringNow(t, "Hello world", "world") // success
239
+ // HasSuffixStringNow(t, "Hello world", "World") // fail and stop the execution
240
+ // // never runs
241
+ func HasSuffixStringNow (t * testing.T , str , suffix string , message ... any ) error {
242
+ t .Helper ()
243
+
244
+ return tryHasSuffixString (t , true , str , suffix , message ... )
245
+ }
246
+
247
+ // NotHasSuffixString tests whether the string has the suffix string or not, and it set the result
248
+ // to fail if the string have the suffix string.
249
+ //
250
+ // NotHasSuffixString(t, "Hello world", "Hello") // success
251
+ // NotHasSuffixString(t, "Hello world", "World") // success
252
+ // NotHasSuffixString(t, "Hello world", "") // fail
253
+ // NotHasSuffixString(t, "Hello world", "world") // fail
254
+ func NotHasSuffixString (t * testing.T , str , suffix string , message ... any ) error {
255
+ t .Helper ()
256
+
257
+ return tryNotHasSuffixString (t , false , str , suffix , message ... )
258
+ }
259
+
260
+ // NotHasSuffixStringNow tests whether the string has the suffix string or not, and it will
261
+ // terminate the execution if the string have the suffix string.
262
+ //
263
+ // NotHasSuffixStringNow(t, "Hello world", "hello") // success
264
+ // NotHasSuffixStringNow(t, "Hello world", "World") // success
265
+ // NotHasSuffixStringNow(t, "Hello world", "world") // fail and stop the execution
266
+ // // never runs
267
+ func NotHasSuffixStringNow (t * testing.T , str , suffix string , message ... any ) error {
268
+ t .Helper ()
269
+
270
+ return tryNotHasSuffixString (t , true , str , suffix , message ... )
271
+ }
272
+
117
273
// Match tests whether the string matches the regular expression or not.
118
274
//
119
275
// pattern := regexp.MustCompile(`^https?:\/\/`)
0 commit comments