assertion_format.go

  1/*
  2* CODE GENERATED AUTOMATICALLY WITH github.com/stretchr/testify/_codegen
  3* THIS FILE MUST NOT BE EDITED BY HAND
  4 */
  5
  6package assert
  7
  8import (
  9	http "net/http"
 10	url "net/url"
 11	time "time"
 12)
 13
 14// Conditionf uses a Comparison to assert a complex condition.
 15func Conditionf(t TestingT, comp Comparison, msg string, args ...interface{}) bool {
 16	if h, ok := t.(tHelper); ok {
 17		h.Helper()
 18	}
 19	return Condition(t, comp, append([]interface{}{msg}, args...)...)
 20}
 21
 22// Containsf asserts that the specified string, list(array, slice...) or map contains the
 23// specified substring or element.
 24//
 25//    assert.Containsf(t, "Hello World", "World", "error message %s", "formatted")
 26//    assert.Containsf(t, ["Hello", "World"], "World", "error message %s", "formatted")
 27//    assert.Containsf(t, {"Hello": "World"}, "Hello", "error message %s", "formatted")
 28func Containsf(t TestingT, s interface{}, contains interface{}, msg string, args ...interface{}) bool {
 29	if h, ok := t.(tHelper); ok {
 30		h.Helper()
 31	}
 32	return Contains(t, s, contains, append([]interface{}{msg}, args...)...)
 33}
 34
 35// DirExistsf checks whether a directory exists in the given path. It also fails if the path is a file rather a directory or there is an error checking whether it exists.
 36func DirExistsf(t TestingT, path string, msg string, args ...interface{}) bool {
 37	if h, ok := t.(tHelper); ok {
 38		h.Helper()
 39	}
 40	return DirExists(t, path, append([]interface{}{msg}, args...)...)
 41}
 42
 43// ElementsMatchf asserts that the specified listA(array, slice...) is equal to specified
 44// listB(array, slice...) ignoring the order of the elements. If there are duplicate elements,
 45// the number of appearances of each of them in both lists should match.
 46//
 47// assert.ElementsMatchf(t, [1, 3, 2, 3], [1, 3, 3, 2], "error message %s", "formatted")
 48func ElementsMatchf(t TestingT, listA interface{}, listB interface{}, msg string, args ...interface{}) bool {
 49	if h, ok := t.(tHelper); ok {
 50		h.Helper()
 51	}
 52	return ElementsMatch(t, listA, listB, append([]interface{}{msg}, args...)...)
 53}
 54
 55// Emptyf asserts that the specified object is empty.  I.e. nil, "", false, 0 or either
 56// a slice or a channel with len == 0.
 57//
 58//  assert.Emptyf(t, obj, "error message %s", "formatted")
 59func Emptyf(t TestingT, object interface{}, msg string, args ...interface{}) bool {
 60	if h, ok := t.(tHelper); ok {
 61		h.Helper()
 62	}
 63	return Empty(t, object, append([]interface{}{msg}, args...)...)
 64}
 65
 66// Equalf asserts that two objects are equal.
 67//
 68//    assert.Equalf(t, 123, 123, "error message %s", "formatted")
 69//
 70// Pointer variable equality is determined based on the equality of the
 71// referenced values (as opposed to the memory addresses). Function equality
 72// cannot be determined and will always fail.
 73func Equalf(t TestingT, expected interface{}, actual interface{}, msg string, args ...interface{}) bool {
 74	if h, ok := t.(tHelper); ok {
 75		h.Helper()
 76	}
 77	return Equal(t, expected, actual, append([]interface{}{msg}, args...)...)
 78}
 79
 80// EqualErrorf asserts that a function returned an error (i.e. not `nil`)
 81// and that it is equal to the provided error.
 82//
 83//   actualObj, err := SomeFunction()
 84//   assert.EqualErrorf(t, err,  expectedErrorString, "error message %s", "formatted")
 85func EqualErrorf(t TestingT, theError error, errString string, msg string, args ...interface{}) bool {
 86	if h, ok := t.(tHelper); ok {
 87		h.Helper()
 88	}
 89	return EqualError(t, theError, errString, append([]interface{}{msg}, args...)...)
 90}
 91
 92// EqualValuesf asserts that two objects are equal or convertable to the same types
 93// and equal.
 94//
 95//    assert.EqualValuesf(t, uint32(123, "error message %s", "formatted"), int32(123))
 96func EqualValuesf(t TestingT, expected interface{}, actual interface{}, msg string, args ...interface{}) bool {
 97	if h, ok := t.(tHelper); ok {
 98		h.Helper()
 99	}
100	return EqualValues(t, expected, actual, append([]interface{}{msg}, args...)...)
101}
102
103// Errorf asserts that a function returned an error (i.e. not `nil`).
104//
105//   actualObj, err := SomeFunction()
106//   if assert.Errorf(t, err, "error message %s", "formatted") {
107// 	   assert.Equal(t, expectedErrorf, err)
108//   }
109func Errorf(t TestingT, err error, msg string, args ...interface{}) bool {
110	if h, ok := t.(tHelper); ok {
111		h.Helper()
112	}
113	return Error(t, err, append([]interface{}{msg}, args...)...)
114}
115
116// Exactlyf asserts that two objects are equal in value and type.
117//
118//    assert.Exactlyf(t, int32(123, "error message %s", "formatted"), int64(123))
119func Exactlyf(t TestingT, expected interface{}, actual interface{}, msg string, args ...interface{}) bool {
120	if h, ok := t.(tHelper); ok {
121		h.Helper()
122	}
123	return Exactly(t, expected, actual, append([]interface{}{msg}, args...)...)
124}
125
126// Failf reports a failure through
127func Failf(t TestingT, failureMessage string, msg string, args ...interface{}) bool {
128	if h, ok := t.(tHelper); ok {
129		h.Helper()
130	}
131	return Fail(t, failureMessage, append([]interface{}{msg}, args...)...)
132}
133
134// FailNowf fails test
135func FailNowf(t TestingT, failureMessage string, msg string, args ...interface{}) bool {
136	if h, ok := t.(tHelper); ok {
137		h.Helper()
138	}
139	return FailNow(t, failureMessage, append([]interface{}{msg}, args...)...)
140}
141
142// Falsef asserts that the specified value is false.
143//
144//    assert.Falsef(t, myBool, "error message %s", "formatted")
145func Falsef(t TestingT, value bool, msg string, args ...interface{}) bool {
146	if h, ok := t.(tHelper); ok {
147		h.Helper()
148	}
149	return False(t, value, append([]interface{}{msg}, args...)...)
150}
151
152// FileExistsf checks whether a file exists in the given path. It also fails if the path points to a directory or there is an error when trying to check the file.
153func FileExistsf(t TestingT, path string, msg string, args ...interface{}) bool {
154	if h, ok := t.(tHelper); ok {
155		h.Helper()
156	}
157	return FileExists(t, path, append([]interface{}{msg}, args...)...)
158}
159
160// HTTPBodyContainsf asserts that a specified handler returns a
161// body that contains a string.
162//
163//  assert.HTTPBodyContainsf(t, myHandler, "GET", "www.google.com", nil, "I'm Feeling Lucky", "error message %s", "formatted")
164//
165// Returns whether the assertion was successful (true) or not (false).
166func HTTPBodyContainsf(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, str interface{}, msg string, args ...interface{}) bool {
167	if h, ok := t.(tHelper); ok {
168		h.Helper()
169	}
170	return HTTPBodyContains(t, handler, method, url, values, str, append([]interface{}{msg}, args...)...)
171}
172
173// HTTPBodyNotContainsf asserts that a specified handler returns a
174// body that does not contain a string.
175//
176//  assert.HTTPBodyNotContainsf(t, myHandler, "GET", "www.google.com", nil, "I'm Feeling Lucky", "error message %s", "formatted")
177//
178// Returns whether the assertion was successful (true) or not (false).
179func HTTPBodyNotContainsf(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, str interface{}, msg string, args ...interface{}) bool {
180	if h, ok := t.(tHelper); ok {
181		h.Helper()
182	}
183	return HTTPBodyNotContains(t, handler, method, url, values, str, append([]interface{}{msg}, args...)...)
184}
185
186// HTTPErrorf asserts that a specified handler returns an error status code.
187//
188//  assert.HTTPErrorf(t, myHandler, "POST", "/a/b/c", url.Values{"a": []string{"b", "c"}}
189//
190// Returns whether the assertion was successful (true, "error message %s", "formatted") or not (false).
191func HTTPErrorf(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, msg string, args ...interface{}) bool {
192	if h, ok := t.(tHelper); ok {
193		h.Helper()
194	}
195	return HTTPError(t, handler, method, url, values, append([]interface{}{msg}, args...)...)
196}
197
198// HTTPRedirectf asserts that a specified handler returns a redirect status code.
199//
200//  assert.HTTPRedirectf(t, myHandler, "GET", "/a/b/c", url.Values{"a": []string{"b", "c"}}
201//
202// Returns whether the assertion was successful (true, "error message %s", "formatted") or not (false).
203func HTTPRedirectf(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, msg string, args ...interface{}) bool {
204	if h, ok := t.(tHelper); ok {
205		h.Helper()
206	}
207	return HTTPRedirect(t, handler, method, url, values, append([]interface{}{msg}, args...)...)
208}
209
210// HTTPSuccessf asserts that a specified handler returns a success status code.
211//
212//  assert.HTTPSuccessf(t, myHandler, "POST", "http://www.google.com", nil, "error message %s", "formatted")
213//
214// Returns whether the assertion was successful (true) or not (false).
215func HTTPSuccessf(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, msg string, args ...interface{}) bool {
216	if h, ok := t.(tHelper); ok {
217		h.Helper()
218	}
219	return HTTPSuccess(t, handler, method, url, values, append([]interface{}{msg}, args...)...)
220}
221
222// Implementsf asserts that an object is implemented by the specified interface.
223//
224//    assert.Implementsf(t, (*MyInterface, "error message %s", "formatted")(nil), new(MyObject))
225func Implementsf(t TestingT, interfaceObject interface{}, object interface{}, msg string, args ...interface{}) bool {
226	if h, ok := t.(tHelper); ok {
227		h.Helper()
228	}
229	return Implements(t, interfaceObject, object, append([]interface{}{msg}, args...)...)
230}
231
232// InDeltaf asserts that the two numerals are within delta of each other.
233//
234// 	 assert.InDeltaf(t, math.Pi, (22 / 7.0, "error message %s", "formatted"), 0.01)
235func InDeltaf(t TestingT, expected interface{}, actual interface{}, delta float64, msg string, args ...interface{}) bool {
236	if h, ok := t.(tHelper); ok {
237		h.Helper()
238	}
239	return InDelta(t, expected, actual, delta, append([]interface{}{msg}, args...)...)
240}
241
242// InDeltaMapValuesf is the same as InDelta, but it compares all values between two maps. Both maps must have exactly the same keys.
243func InDeltaMapValuesf(t TestingT, expected interface{}, actual interface{}, delta float64, msg string, args ...interface{}) bool {
244	if h, ok := t.(tHelper); ok {
245		h.Helper()
246	}
247	return InDeltaMapValues(t, expected, actual, delta, append([]interface{}{msg}, args...)...)
248}
249
250// InDeltaSlicef is the same as InDelta, except it compares two slices.
251func InDeltaSlicef(t TestingT, expected interface{}, actual interface{}, delta float64, msg string, args ...interface{}) bool {
252	if h, ok := t.(tHelper); ok {
253		h.Helper()
254	}
255	return InDeltaSlice(t, expected, actual, delta, append([]interface{}{msg}, args...)...)
256}
257
258// InEpsilonf asserts that expected and actual have a relative error less than epsilon
259func InEpsilonf(t TestingT, expected interface{}, actual interface{}, epsilon float64, msg string, args ...interface{}) bool {
260	if h, ok := t.(tHelper); ok {
261		h.Helper()
262	}
263	return InEpsilon(t, expected, actual, epsilon, append([]interface{}{msg}, args...)...)
264}
265
266// InEpsilonSlicef is the same as InEpsilon, except it compares each value from two slices.
267func InEpsilonSlicef(t TestingT, expected interface{}, actual interface{}, epsilon float64, msg string, args ...interface{}) bool {
268	if h, ok := t.(tHelper); ok {
269		h.Helper()
270	}
271	return InEpsilonSlice(t, expected, actual, epsilon, append([]interface{}{msg}, args...)...)
272}
273
274// IsTypef asserts that the specified objects are of the same type.
275func IsTypef(t TestingT, expectedType interface{}, object interface{}, msg string, args ...interface{}) bool {
276	if h, ok := t.(tHelper); ok {
277		h.Helper()
278	}
279	return IsType(t, expectedType, object, append([]interface{}{msg}, args...)...)
280}
281
282// JSONEqf asserts that two JSON strings are equivalent.
283//
284//  assert.JSONEqf(t, `{"hello": "world", "foo": "bar"}`, `{"foo": "bar", "hello": "world"}`, "error message %s", "formatted")
285func JSONEqf(t TestingT, expected string, actual string, msg string, args ...interface{}) bool {
286	if h, ok := t.(tHelper); ok {
287		h.Helper()
288	}
289	return JSONEq(t, expected, actual, append([]interface{}{msg}, args...)...)
290}
291
292// Lenf asserts that the specified object has specific length.
293// Lenf also fails if the object has a type that len() not accept.
294//
295//    assert.Lenf(t, mySlice, 3, "error message %s", "formatted")
296func Lenf(t TestingT, object interface{}, length int, msg string, args ...interface{}) bool {
297	if h, ok := t.(tHelper); ok {
298		h.Helper()
299	}
300	return Len(t, object, length, append([]interface{}{msg}, args...)...)
301}
302
303// Nilf asserts that the specified object is nil.
304//
305//    assert.Nilf(t, err, "error message %s", "formatted")
306func Nilf(t TestingT, object interface{}, msg string, args ...interface{}) bool {
307	if h, ok := t.(tHelper); ok {
308		h.Helper()
309	}
310	return Nil(t, object, append([]interface{}{msg}, args...)...)
311}
312
313// NoErrorf asserts that a function returned no error (i.e. `nil`).
314//
315//   actualObj, err := SomeFunction()
316//   if assert.NoErrorf(t, err, "error message %s", "formatted") {
317// 	   assert.Equal(t, expectedObj, actualObj)
318//   }
319func NoErrorf(t TestingT, err error, msg string, args ...interface{}) bool {
320	if h, ok := t.(tHelper); ok {
321		h.Helper()
322	}
323	return NoError(t, err, append([]interface{}{msg}, args...)...)
324}
325
326// NotContainsf asserts that the specified string, list(array, slice...) or map does NOT contain the
327// specified substring or element.
328//
329//    assert.NotContainsf(t, "Hello World", "Earth", "error message %s", "formatted")
330//    assert.NotContainsf(t, ["Hello", "World"], "Earth", "error message %s", "formatted")
331//    assert.NotContainsf(t, {"Hello": "World"}, "Earth", "error message %s", "formatted")
332func NotContainsf(t TestingT, s interface{}, contains interface{}, msg string, args ...interface{}) bool {
333	if h, ok := t.(tHelper); ok {
334		h.Helper()
335	}
336	return NotContains(t, s, contains, append([]interface{}{msg}, args...)...)
337}
338
339// NotEmptyf asserts that the specified object is NOT empty.  I.e. not nil, "", false, 0 or either
340// a slice or a channel with len == 0.
341//
342//  if assert.NotEmptyf(t, obj, "error message %s", "formatted") {
343//    assert.Equal(t, "two", obj[1])
344//  }
345func NotEmptyf(t TestingT, object interface{}, msg string, args ...interface{}) bool {
346	if h, ok := t.(tHelper); ok {
347		h.Helper()
348	}
349	return NotEmpty(t, object, append([]interface{}{msg}, args...)...)
350}
351
352// NotEqualf asserts that the specified values are NOT equal.
353//
354//    assert.NotEqualf(t, obj1, obj2, "error message %s", "formatted")
355//
356// Pointer variable equality is determined based on the equality of the
357// referenced values (as opposed to the memory addresses).
358func NotEqualf(t TestingT, expected interface{}, actual interface{}, msg string, args ...interface{}) bool {
359	if h, ok := t.(tHelper); ok {
360		h.Helper()
361	}
362	return NotEqual(t, expected, actual, append([]interface{}{msg}, args...)...)
363}
364
365// NotNilf asserts that the specified object is not nil.
366//
367//    assert.NotNilf(t, err, "error message %s", "formatted")
368func NotNilf(t TestingT, object interface{}, msg string, args ...interface{}) bool {
369	if h, ok := t.(tHelper); ok {
370		h.Helper()
371	}
372	return NotNil(t, object, append([]interface{}{msg}, args...)...)
373}
374
375// NotPanicsf asserts that the code inside the specified PanicTestFunc does NOT panic.
376//
377//   assert.NotPanicsf(t, func(){ RemainCalm() }, "error message %s", "formatted")
378func NotPanicsf(t TestingT, f PanicTestFunc, msg string, args ...interface{}) bool {
379	if h, ok := t.(tHelper); ok {
380		h.Helper()
381	}
382	return NotPanics(t, f, append([]interface{}{msg}, args...)...)
383}
384
385// NotRegexpf asserts that a specified regexp does not match a string.
386//
387//  assert.NotRegexpf(t, regexp.MustCompile("starts", "error message %s", "formatted"), "it's starting")
388//  assert.NotRegexpf(t, "^start", "it's not starting", "error message %s", "formatted")
389func NotRegexpf(t TestingT, rx interface{}, str interface{}, msg string, args ...interface{}) bool {
390	if h, ok := t.(tHelper); ok {
391		h.Helper()
392	}
393	return NotRegexp(t, rx, str, append([]interface{}{msg}, args...)...)
394}
395
396// NotSubsetf asserts that the specified list(array, slice...) contains not all
397// elements given in the specified subset(array, slice...).
398//
399//    assert.NotSubsetf(t, [1, 3, 4], [1, 2], "But [1, 3, 4] does not contain [1, 2]", "error message %s", "formatted")
400func NotSubsetf(t TestingT, list interface{}, subset interface{}, msg string, args ...interface{}) bool {
401	if h, ok := t.(tHelper); ok {
402		h.Helper()
403	}
404	return NotSubset(t, list, subset, append([]interface{}{msg}, args...)...)
405}
406
407// NotZerof asserts that i is not the zero value for its type.
408func NotZerof(t TestingT, i interface{}, msg string, args ...interface{}) bool {
409	if h, ok := t.(tHelper); ok {
410		h.Helper()
411	}
412	return NotZero(t, i, append([]interface{}{msg}, args...)...)
413}
414
415// Panicsf asserts that the code inside the specified PanicTestFunc panics.
416//
417//   assert.Panicsf(t, func(){ GoCrazy() }, "error message %s", "formatted")
418func Panicsf(t TestingT, f PanicTestFunc, msg string, args ...interface{}) bool {
419	if h, ok := t.(tHelper); ok {
420		h.Helper()
421	}
422	return Panics(t, f, append([]interface{}{msg}, args...)...)
423}
424
425// PanicsWithValuef asserts that the code inside the specified PanicTestFunc panics, and that
426// the recovered panic value equals the expected panic value.
427//
428//   assert.PanicsWithValuef(t, "crazy error", func(){ GoCrazy() }, "error message %s", "formatted")
429func PanicsWithValuef(t TestingT, expected interface{}, f PanicTestFunc, msg string, args ...interface{}) bool {
430	if h, ok := t.(tHelper); ok {
431		h.Helper()
432	}
433	return PanicsWithValue(t, expected, f, append([]interface{}{msg}, args...)...)
434}
435
436// Regexpf asserts that a specified regexp matches a string.
437//
438//  assert.Regexpf(t, regexp.MustCompile("start", "error message %s", "formatted"), "it's starting")
439//  assert.Regexpf(t, "start...$", "it's not starting", "error message %s", "formatted")
440func Regexpf(t TestingT, rx interface{}, str interface{}, msg string, args ...interface{}) bool {
441	if h, ok := t.(tHelper); ok {
442		h.Helper()
443	}
444	return Regexp(t, rx, str, append([]interface{}{msg}, args...)...)
445}
446
447// Subsetf asserts that the specified list(array, slice...) contains all
448// elements given in the specified subset(array, slice...).
449//
450//    assert.Subsetf(t, [1, 2, 3], [1, 2], "But [1, 2, 3] does contain [1, 2]", "error message %s", "formatted")
451func Subsetf(t TestingT, list interface{}, subset interface{}, msg string, args ...interface{}) bool {
452	if h, ok := t.(tHelper); ok {
453		h.Helper()
454	}
455	return Subset(t, list, subset, append([]interface{}{msg}, args...)...)
456}
457
458// Truef asserts that the specified value is true.
459//
460//    assert.Truef(t, myBool, "error message %s", "formatted")
461func Truef(t TestingT, value bool, msg string, args ...interface{}) bool {
462	if h, ok := t.(tHelper); ok {
463		h.Helper()
464	}
465	return True(t, value, append([]interface{}{msg}, args...)...)
466}
467
468// WithinDurationf asserts that the two times are within duration delta of each other.
469//
470//   assert.WithinDurationf(t, time.Now(), time.Now(), 10*time.Second, "error message %s", "formatted")
471func WithinDurationf(t TestingT, expected time.Time, actual time.Time, delta time.Duration, msg string, args ...interface{}) bool {
472	if h, ok := t.(tHelper); ok {
473		h.Helper()
474	}
475	return WithinDuration(t, expected, actual, delta, append([]interface{}{msg}, args...)...)
476}
477
478// Zerof asserts that i is the zero value for its type.
479func Zerof(t TestingT, i interface{}, msg string, args ...interface{}) bool {
480	if h, ok := t.(tHelper); ok {
481		h.Helper()
482	}
483	return Zero(t, i, append([]interface{}{msg}, args...)...)
484}