Repository navigation
Expand file tree
/
Copy pathassertions_methods.go
More file actions
400 lines (343 loc) · 12 KB
/
Copy pathassertions_methods.go
File metadata and controls
400 lines (343 loc) · 12 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
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
package assert
import "reflect"
// Nil asserts that the given is a nil value
func (as *Assertions) Nil(give any, fmtAndArgs ...any) *Assertions {
as.t.Helper()
as.ok = Nil(as.t, give, fmtAndArgs...)
return as
}
// NotNil asserts that the given is a not nil value
func (as *Assertions) NotNil(val any, fmtAndArgs ...any) *Assertions {
as.t.Helper()
as.ok = NotNil(as.t, val, fmtAndArgs...)
return as
}
// True check, please see True()
func (as *Assertions) True(give bool, fmtAndArgs ...any) *Assertions {
as.t.Helper()
as.ok = True(as.t, give, fmtAndArgs...)
return as
}
// False check, please see False()
func (as *Assertions) False(give bool, fmtAndArgs ...any) *Assertions {
as.t.Helper()
as.ok = False(as.t, give, fmtAndArgs...)
return as
}
// Empty check, please see Empty()
func (as *Assertions) Empty(give any, fmtAndArgs ...any) *Assertions {
as.t.Helper()
as.ok = Empty(as.t, give, fmtAndArgs...)
return as
}
// NotEmpty check, please see NotEmpty()
func (as *Assertions) NotEmpty(give any, fmtAndArgs ...any) *Assertions {
as.t.Helper()
as.ok = NotEmpty(as.t, give, fmtAndArgs...)
return as
}
// Zero check, please see Zero()
func (as *Assertions) Zero(give any, fmtAndArgs ...any) *Assertions {
as.t.Helper()
as.ok = Zero(as.t, give, fmtAndArgs...)
return as
}
// NotZero check, please see NotZero()
func (as *Assertions) NotZero(give any, fmtAndArgs ...any) *Assertions {
as.t.Helper()
as.ok = NotZero(as.t, give, fmtAndArgs...)
return as
}
// Panics check, please see Panics()
func (as *Assertions) Panics(fn PanicRunFunc, fmtAndArgs ...any) *Assertions {
as.t.Helper()
as.ok = Panics(as.t, fn, fmtAndArgs...)
return as
}
// NotPanics check, please see NotPanics()
func (as *Assertions) NotPanics(fn PanicRunFunc, fmtAndArgs ...any) *Assertions {
as.t.Helper()
as.ok = NotPanics(as.t, fn, fmtAndArgs...)
return as
}
// PanicsMsg check, please see PanicsMsg()
func (as *Assertions) PanicsMsg(fn PanicRunFunc, wantVal any, fmtAndArgs ...any) *Assertions {
as.t.Helper()
as.ok = PanicsMsg(as.t, fn, wantVal, fmtAndArgs...)
return as
}
// PanicsErrMsg check, please see PanicsErrMsg()
func (as *Assertions) PanicsErrMsg(fn PanicRunFunc, errMsg string, fmtAndArgs ...any) *Assertions {
as.t.Helper()
as.ok = PanicsErrMsg(as.t, fn, errMsg, fmtAndArgs...)
return as
}
// Contains asserts that the given data(string,slice,map) should contain element
func (as *Assertions) Contains(src, elem any, fmtAndArgs ...any) *Assertions {
as.t.Helper()
as.ok = Contains(as.t, src, elem, fmtAndArgs...)
return as
}
// NotContains asserts that the given data(string,slice,map) should not contain element
func (as *Assertions) NotContains(src, elem any, fmtAndArgs ...any) *Assertions {
as.t.Helper()
as.ok = NotContains(as.t, src, elem, fmtAndArgs...)
return as
}
// ContainsKey asserts that the given map is contains key
func (as *Assertions) ContainsKey(mp, key any, fmtAndArgs ...any) *Assertions {
as.t.Helper()
as.ok = ContainsKey(as.t, mp, key, fmtAndArgs...)
return as
}
// NotContainsKey asserts that the given map is not contains key
func (as *Assertions) NotContainsKey(mp, key any, fmtAndArgs ...any) *Assertions {
as.t.Helper()
as.ok = NotContainsKey(as.t, mp, key, fmtAndArgs...)
return as
}
// ContainsKeys asserts that the map is contains all given keys
func (as *Assertions) ContainsKeys(mp any, keys any, fmtAndArgs ...any) *Assertions {
as.t.Helper()
as.ok = ContainsKeys(as.t, mp, keys, fmtAndArgs...)
return as
}
// NotContainsKeys asserts that the map is not contains all given keys
func (as *Assertions) NotContainsKeys(mp any, keys any, fmtAndArgs ...any) *Assertions {
as.t.Helper()
as.ok = NotContainsKeys(as.t, mp, keys, fmtAndArgs...)
return as
}
// ContainsElems asserts that the given list should contain sub elements
func (as *Assertions) ContainsElems(list any, sub any, fmtAndArgs ...any) *Assertions {
as.t.Helper()
as.ok = ContainsElemsAny(as.t, list, sub, fmtAndArgs...)
return as
}
// StrContains asserts that the given strings is contains sub-string
func (as *Assertions) StrContains(s, sub string, fmtAndArgs ...any) *Assertions {
as.t.Helper()
as.ok = StrContains(as.t, s, sub, fmtAndArgs...)
return as
}
// StrNotContains asserts that the given strings is not contains sub-string
func (as *Assertions) StrNotContains(s, sub string, fmtAndArgs ...any) *Assertions {
as.t.Helper()
as.ok = StrNotContains(as.t, s, sub, fmtAndArgs...)
return as
}
// StrContainsAll asserts that the given strings is contains all sub-strings
func (as *Assertions) StrContainsAll(s string, subs []string, fmtAndArgs ...any) *Assertions {
as.t.Helper()
as.ok = StrContainsAll(as.t, s, subs, fmtAndArgs...)
return as
}
// StrCount asserts that the given strings contains substring count
func (as *Assertions) StrCount(s, sub string, count int, fmtAndArgs ...any) *Assertions {
as.t.Helper()
as.ok = StrCount(as.t, s, sub, count, fmtAndArgs...)
return as
}
// NoErr asserts that the given is a nil error
func (as *Assertions) NoErr(err error, fmtAndArgs ...any) *Assertions {
as.t.Helper()
as.ok = NoErr(as.t, err, fmtAndArgs...)
return as
}
// NoError asserts that the given is a nil error
func (as *Assertions) NoError(err error, fmtAndArgs ...any) *Assertions {
as.t.Helper()
as.ok = NoErr(as.t, err, fmtAndArgs...)
return as
}
// Err asserts that the given is a not nil error
func (as *Assertions) Err(err error, fmtAndArgs ...any) *Assertions {
as.t.Helper()
as.ok = Err(as.t, err, fmtAndArgs...)
return as
}
// Error asserts that the given is a not nil error
func (as *Assertions) Error(err error, fmtAndArgs ...any) *Assertions {
as.t.Helper()
as.ok = Err(as.t, err, fmtAndArgs...)
return as
}
// ErrIs asserts that the given error is equals wantErr
func (as *Assertions) ErrIs(err, wantErr error, fmtAndArgs ...any) *Assertions {
as.t.Helper()
as.ok = ErrIs(as.t, err, wantErr, fmtAndArgs...)
return as
}
// ErrMsg asserts that the given is a not nil error and error message equals wantMsg
func (as *Assertions) ErrMsg(err error, errMsg string, fmtAndArgs ...any) *Assertions {
as.t.Helper()
as.ok = ErrMsg(as.t, err, errMsg, fmtAndArgs...)
return as
}
// ErrSubMsg asserts that the given is a not nil error and the error message contains subMsg
func (as *Assertions) ErrSubMsg(err error, subMsg string, fmtAndArgs ...any) *Assertions {
as.t.Helper()
as.ok = ErrSubMsg(as.t, err, subMsg, fmtAndArgs...)
return as
}
// ErrMsgContains asserts that the given is a not nil error and error message contains subMsg
func (as *Assertions) ErrMsgContains(err error, subMsg string, fmtAndArgs ...any) *Assertions {
as.t.Helper()
as.ok = ErrMsgContains(as.t, err, subMsg, fmtAndArgs...)
return as
}
// ErrHasMsg asserts that the given is a not nil error and the error message contains subMsg
func (as *Assertions) ErrHasMsg(err error, subMsg string, fmtAndArgs ...any) *Assertions {
as.t.Helper()
as.ok = ErrHasMsg(as.t, err, subMsg, fmtAndArgs...)
return as
}
// FileExists asserts that the given file exists
func (as *Assertions) FileExists(filePath string, fmtAndArgs ...any) *Assertions {
as.t.Helper()
as.ok = FileExists(as.t, filePath, fmtAndArgs...)
return as
}
// FileNotExists asserts that the given file not exists
func (as *Assertions) FileNotExists(filePath string, fmtAndArgs ...any) *Assertions {
as.t.Helper()
as.ok = FileNotExists(as.t, filePath, fmtAndArgs...)
return as
}
// DirExists asserts that the given dir exists
func (as *Assertions) DirExists(dirPath string, fmtAndArgs ...any) *Assertions {
as.t.Helper()
as.ok = DirExists(as.t, dirPath, fmtAndArgs...)
return as
}
// DirNotExists asserts that the given dir not exists
func (as *Assertions) DirNotExists(dirPath string, fmtAndArgs ...any) *Assertions {
as.t.Helper()
as.ok = DirNotExists(as.t, dirPath, fmtAndArgs...)
return as
}
// Len assert given length is equals to wantLn
func (as *Assertions) Len(give any, wantLn int, fmtAndArgs ...any) *Assertions {
as.t.Helper()
as.ok = Len(as.t, give, wantLn, fmtAndArgs...)
return as
}
// LenGt assert given length is greater than to minLn
func (as *Assertions) LenGt(give any, minLn int, fmtAndArgs ...any) *Assertions {
as.t.Helper()
as.ok = LenGt(as.t, give, minLn, fmtAndArgs...)
return as
}
// Eq asserts that the want should equal to the given
func (as *Assertions) Eq(want, give any, fmtAndArgs ...any) *Assertions {
as.t.Helper()
as.ok = Eq(as.t, want, give, fmtAndArgs...)
return as
}
// Equal asserts that the want should equal to the given
//
// Alias of Eq()
func (as *Assertions) Equal(want, give any, fmtAndArgs ...any) *Assertions {
as.t.Helper()
as.ok = Eq(as.t, want, give, fmtAndArgs...)
return as
}
// Neq asserts that the want should not be equal to the given.
// alias of NotEq()
func (as *Assertions) Neq(want, give any, fmtAndArgs ...any) *Assertions {
as.t.Helper()
as.ok = Neq(as.t, want, give, fmtAndArgs...)
return as
}
// NotEq asserts that the want should not be equal to the given
func (as *Assertions) NotEq(want, give any, fmtAndArgs ...any) *Assertions {
as.t.Helper()
as.ok = NotEq(as.t, want, give, fmtAndArgs...)
return as
}
// NotEqual asserts that the want should not be equal to the given
//
// Alias of NotEq()
func (as *Assertions) NotEqual(want, give any, fmtAndArgs ...any) *Assertions {
as.t.Helper()
as.ok = NotEq(as.t, want, give, fmtAndArgs...)
return as
}
// Lt asserts that the give(intX) should not be less than max
func (as *Assertions) Lt(give, max any, fmtAndArgs ...any) *Assertions {
as.t.Helper()
as.ok = Lt(as.t, give, max, fmtAndArgs...)
return as
}
// Lte asserts that the give(intX) should not be less than or equal to max
func (as *Assertions) Lte(give, max any, fmtAndArgs ...any) *Assertions {
as.t.Helper()
as.ok = Lte(as.t, give, max, fmtAndArgs...)
return as
}
// Gt asserts that the give(intX) should not be greater than min
func (as *Assertions) Gt(give, min any, fmtAndArgs ...any) *Assertions {
as.t.Helper()
as.ok = Gt(as.t, give, min, fmtAndArgs...)
return as
}
// Gte asserts that the give(intX) should not be greater than or equal to min
func (as *Assertions) Gte(give, min any, fmtAndArgs ...any) *Assertions {
as.t.Helper()
as.ok = Gte(as.t, give, min, fmtAndArgs...)
return as
}
// EqInt asserts that the want should equal to the given intX
func (as *Assertions) EqInt(want, give any, fmtAndArgs ...any) *Assertions {
as.t.Helper()
as.ok = EqInt(as.t, want, give, fmtAndArgs...)
return as
}
// EqFloat asserts that the want should equal to the given float with delta
func (as *Assertions) EqFloat(want, give any, delta float64, fmtAndArgs ...any) *Assertions {
as.t.Helper()
as.ok = EqFloat(as.t, want, give, delta, fmtAndArgs...)
return as
}
// InDelta asserts that two floating-point values differ within a certain range
func (as *Assertions) InDelta(want, give any, delta float64, fmtAndArgs ...any) *Assertions {
as.t.Helper()
as.ok = InDelta(as.t, want, give, delta, fmtAndArgs...)
return as
}
// IsType type equals assert
func (as *Assertions) IsType(wantType, give any, fmtAndArgs ...any) *Assertions {
as.t.Helper()
as.ok = IsType(as.t, wantType, give, fmtAndArgs...)
return as
}
// IsKind asserts that the given data reflect.Kind equals
func (as *Assertions) IsKind(wantKind reflect.Kind, give any, fmtAndArgs ...any) *Assertions {
as.t.Helper()
as.ok = IsKind(as.t, wantKind, give, fmtAndArgs...)
return as
}
// Same asserts that two pointers reference the same object
func (as *Assertions) Same(wanted, actual any, fmtAndArgs ...any) *Assertions {
as.t.Helper()
as.ok = Same(as.t, wanted, actual, fmtAndArgs...)
return as
}
// NotSame asserts that two pointers do not reference the same object
func (as *Assertions) NotSame(want, actual any, fmtAndArgs ...any) *Assertions {
as.t.Helper()
as.ok = NotSame(as.t, want, actual, fmtAndArgs...)
return as
}
// Fail reports a failure through
func (as *Assertions) Fail(failMsg string, fmtAndArgs ...any) *Assertions {
as.t.Helper()
as.ok = Fail(as.t, failMsg, fmtAndArgs...)
return as
}
// FailNow fails test
func (as *Assertions) FailNow(failMsg string, fmtAndArgs ...any) *Assertions {
as.t.Helper()
as.ok = FailNow(as.t, failMsg, fmtAndArgs...)
return as
}