1/* 2* CODE GENERATED AUTOMATICALLY WITH github.com/stretchr/testify/_codegen 3* THIS FILE MUST NOT BE EDITED BY HAND 4 */ 5 6package require 7 8import ( 9 assert "github.com/stretchr/testify/assert" 10 http "net/http" 11 url "net/url" 12 time "time" 13) 14 15// Condition uses a Comparison to assert a complex condition. 16func (a *Assertions) Condition(comp assert.Comparison, msgAndArgs ...interface{}) { 17 if h, ok := a.t.(tHelper); ok { 18 h.Helper() 19 } 20 Condition(a.t, comp, msgAndArgs...) 21} 22 23// Conditionf uses a Comparison to assert a complex condition. 24func (a *Assertions) Conditionf(comp assert.Comparison, msg string, args ...interface{}) { 25 if h, ok := a.t.(tHelper); ok { 26 h.Helper() 27 } 28 Conditionf(a.t, comp, msg, args...) 29} 30 31// Contains asserts that the specified string, list(array, slice...) or map contains the 32// specified substring or element. 33// 34// a.Contains("Hello World", "World") 35// a.Contains(["Hello", "World"], "World") 36// a.Contains({"Hello": "World"}, "Hello") 37func (a *Assertions) Contains(s interface{}, contains interface{}, msgAndArgs ...interface{}) { 38 if h, ok := a.t.(tHelper); ok { 39 h.Helper() 40 } 41 Contains(a.t, s, contains, msgAndArgs...) 42} 43 44// Containsf asserts that the specified string, list(array, slice...) or map contains the 45// specified substring or element. 46// 47// a.Containsf("Hello World", "World", "error message %s", "formatted") 48// a.Containsf(["Hello", "World"], "World", "error message %s", "formatted") 49// a.Containsf({"Hello": "World"}, "Hello", "error message %s", "formatted") 50func (a *Assertions) Containsf(s interface{}, contains interface{}, msg string, args ...interface{}) { 51 if h, ok := a.t.(tHelper); ok { 52 h.Helper() 53 } 54 Containsf(a.t, s, contains, msg, args...) 55} 56 57// DirExists 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. 58func (a *Assertions) DirExists(path string, msgAndArgs ...interface{}) { 59 if h, ok := a.t.(tHelper); ok { 60 h.Helper() 61 } 62 DirExists(a.t, path, msgAndArgs...) 63} 64 65// 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. 66func (a *Assertions) DirExistsf(path string, msg string, args ...interface{}) { 67 if h, ok := a.t.(tHelper); ok { 68 h.Helper() 69 } 70 DirExistsf(a.t, path, msg, args...) 71} 72 73// ElementsMatch asserts that the specified listA(array, slice...) is equal to specified 74// listB(array, slice...) ignoring the order of the elements. If there are duplicate elements, 75// the number of appearances of each of them in both lists should match. 76// 77// a.ElementsMatch([1, 3, 2, 3], [1, 3, 3, 2]) 78func (a *Assertions) ElementsMatch(listA interface{}, listB interface{}, msgAndArgs ...interface{}) { 79 if h, ok := a.t.(tHelper); ok { 80 h.Helper() 81 } 82 ElementsMatch(a.t, listA, listB, msgAndArgs...) 83} 84 85// ElementsMatchf asserts that the specified listA(array, slice...) is equal to specified 86// listB(array, slice...) ignoring the order of the elements. If there are duplicate elements, 87// the number of appearances of each of them in both lists should match. 88// 89// a.ElementsMatchf([1, 3, 2, 3], [1, 3, 3, 2], "error message %s", "formatted") 90func (a *Assertions) ElementsMatchf(listA interface{}, listB interface{}, msg string, args ...interface{}) { 91 if h, ok := a.t.(tHelper); ok { 92 h.Helper() 93 } 94 ElementsMatchf(a.t, listA, listB, msg, args...) 95} 96 97// Empty asserts that the specified object is empty. I.e. nil, "", false, 0 or either 98// a slice or a channel with len == 0. 99// 100// a.Empty(obj) 101func (a *Assertions) Empty(object interface{}, msgAndArgs ...interface{}) { 102 if h, ok := a.t.(tHelper); ok { 103 h.Helper() 104 } 105 Empty(a.t, object, msgAndArgs...) 106} 107 108// Emptyf asserts that the specified object is empty. I.e. nil, "", false, 0 or either 109// a slice or a channel with len == 0. 110// 111// a.Emptyf(obj, "error message %s", "formatted") 112func (a *Assertions) Emptyf(object interface{}, msg string, args ...interface{}) { 113 if h, ok := a.t.(tHelper); ok { 114 h.Helper() 115 } 116 Emptyf(a.t, object, msg, args...) 117} 118 119// Equal asserts that two objects are equal. 120// 121// a.Equal(123, 123) 122// 123// Pointer variable equality is determined based on the equality of the 124// referenced values (as opposed to the memory addresses). Function equality 125// cannot be determined and will always fail. 126func (a *Assertions) Equal(expected interface{}, actual interface{}, msgAndArgs ...interface{}) { 127 if h, ok := a.t.(tHelper); ok { 128 h.Helper() 129 } 130 Equal(a.t, expected, actual, msgAndArgs...) 131} 132 133// EqualError asserts that a function returned an error (i.e. not `nil`) 134// and that it is equal to the provided error. 135// 136// actualObj, err := SomeFunction() 137// a.EqualError(err, expectedErrorString) 138func (a *Assertions) EqualError(theError error, errString string, msgAndArgs ...interface{}) { 139 if h, ok := a.t.(tHelper); ok { 140 h.Helper() 141 } 142 EqualError(a.t, theError, errString, msgAndArgs...) 143} 144 145// EqualErrorf asserts that a function returned an error (i.e. not `nil`) 146// and that it is equal to the provided error. 147// 148// actualObj, err := SomeFunction() 149// a.EqualErrorf(err, expectedErrorString, "error message %s", "formatted") 150func (a *Assertions) EqualErrorf(theError error, errString string, msg string, args ...interface{}) { 151 if h, ok := a.t.(tHelper); ok { 152 h.Helper() 153 } 154 EqualErrorf(a.t, theError, errString, msg, args...) 155} 156 157// EqualValues asserts that two objects are equal or convertable to the same types 158// and equal. 159// 160// a.EqualValues(uint32(123), int32(123)) 161func (a *Assertions) EqualValues(expected interface{}, actual interface{}, msgAndArgs ...interface{}) { 162 if h, ok := a.t.(tHelper); ok { 163 h.Helper() 164 } 165 EqualValues(a.t, expected, actual, msgAndArgs...) 166} 167 168// EqualValuesf asserts that two objects are equal or convertable to the same types 169// and equal. 170// 171// a.EqualValuesf(uint32(123, "error message %s", "formatted"), int32(123)) 172func (a *Assertions) EqualValuesf(expected interface{}, actual interface{}, msg string, args ...interface{}) { 173 if h, ok := a.t.(tHelper); ok { 174 h.Helper() 175 } 176 EqualValuesf(a.t, expected, actual, msg, args...) 177} 178 179// Equalf asserts that two objects are equal. 180// 181// a.Equalf(123, 123, "error message %s", "formatted") 182// 183// Pointer variable equality is determined based on the equality of the 184// referenced values (as opposed to the memory addresses). Function equality 185// cannot be determined and will always fail. 186func (a *Assertions) Equalf(expected interface{}, actual interface{}, msg string, args ...interface{}) { 187 if h, ok := a.t.(tHelper); ok { 188 h.Helper() 189 } 190 Equalf(a.t, expected, actual, msg, args...) 191} 192 193// Error asserts that a function returned an error (i.e. not `nil`). 194// 195// actualObj, err := SomeFunction() 196// if a.Error(err) { 197// assert.Equal(t, expectedError, err) 198// } 199func (a *Assertions) Error(err error, msgAndArgs ...interface{}) { 200 if h, ok := a.t.(tHelper); ok { 201 h.Helper() 202 } 203 Error(a.t, err, msgAndArgs...) 204} 205 206// Errorf asserts that a function returned an error (i.e. not `nil`). 207// 208// actualObj, err := SomeFunction() 209// if a.Errorf(err, "error message %s", "formatted") { 210// assert.Equal(t, expectedErrorf, err) 211// } 212func (a *Assertions) Errorf(err error, msg string, args ...interface{}) { 213 if h, ok := a.t.(tHelper); ok { 214 h.Helper() 215 } 216 Errorf(a.t, err, msg, args...) 217} 218 219// Exactly asserts that two objects are equal in value and type. 220// 221// a.Exactly(int32(123), int64(123)) 222func (a *Assertions) Exactly(expected interface{}, actual interface{}, msgAndArgs ...interface{}) { 223 if h, ok := a.t.(tHelper); ok { 224 h.Helper() 225 } 226 Exactly(a.t, expected, actual, msgAndArgs...) 227} 228 229// Exactlyf asserts that two objects are equal in value and type. 230// 231// a.Exactlyf(int32(123, "error message %s", "formatted"), int64(123)) 232func (a *Assertions) Exactlyf(expected interface{}, actual interface{}, msg string, args ...interface{}) { 233 if h, ok := a.t.(tHelper); ok { 234 h.Helper() 235 } 236 Exactlyf(a.t, expected, actual, msg, args...) 237} 238 239// Fail reports a failure through 240func (a *Assertions) Fail(failureMessage string, msgAndArgs ...interface{}) { 241 if h, ok := a.t.(tHelper); ok { 242 h.Helper() 243 } 244 Fail(a.t, failureMessage, msgAndArgs...) 245} 246 247// FailNow fails test 248func (a *Assertions) FailNow(failureMessage string, msgAndArgs ...interface{}) { 249 if h, ok := a.t.(tHelper); ok { 250 h.Helper() 251 } 252 FailNow(a.t, failureMessage, msgAndArgs...) 253} 254 255// FailNowf fails test 256func (a *Assertions) FailNowf(failureMessage string, msg string, args ...interface{}) { 257 if h, ok := a.t.(tHelper); ok { 258 h.Helper() 259 } 260 FailNowf(a.t, failureMessage, msg, args...) 261} 262 263// Failf reports a failure through 264func (a *Assertions) Failf(failureMessage string, msg string, args ...interface{}) { 265 if h, ok := a.t.(tHelper); ok { 266 h.Helper() 267 } 268 Failf(a.t, failureMessage, msg, args...) 269} 270 271// False asserts that the specified value is false. 272// 273// a.False(myBool) 274func (a *Assertions) False(value bool, msgAndArgs ...interface{}) { 275 if h, ok := a.t.(tHelper); ok { 276 h.Helper() 277 } 278 False(a.t, value, msgAndArgs...) 279} 280 281// Falsef asserts that the specified value is false. 282// 283// a.Falsef(myBool, "error message %s", "formatted") 284func (a *Assertions) Falsef(value bool, msg string, args ...interface{}) { 285 if h, ok := a.t.(tHelper); ok { 286 h.Helper() 287 } 288 Falsef(a.t, value, msg, args...) 289} 290 291// FileExists 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. 292func (a *Assertions) FileExists(path string, msgAndArgs ...interface{}) { 293 if h, ok := a.t.(tHelper); ok { 294 h.Helper() 295 } 296 FileExists(a.t, path, msgAndArgs...) 297} 298 299// 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. 300func (a *Assertions) FileExistsf(path string, msg string, args ...interface{}) { 301 if h, ok := a.t.(tHelper); ok { 302 h.Helper() 303 } 304 FileExistsf(a.t, path, msg, args...) 305} 306 307// HTTPBodyContains asserts that a specified handler returns a 308// body that contains a string. 309// 310// a.HTTPBodyContains(myHandler, "GET", "www.google.com", nil, "I'm Feeling Lucky") 311// 312// Returns whether the assertion was successful (true) or not (false). 313func (a *Assertions) HTTPBodyContains(handler http.HandlerFunc, method string, url string, values url.Values, str interface{}, msgAndArgs ...interface{}) { 314 if h, ok := a.t.(tHelper); ok { 315 h.Helper() 316 } 317 HTTPBodyContains(a.t, handler, method, url, values, str, msgAndArgs...) 318} 319 320// HTTPBodyContainsf asserts that a specified handler returns a 321// body that contains a string. 322// 323// a.HTTPBodyContainsf(myHandler, "GET", "www.google.com", nil, "I'm Feeling Lucky", "error message %s", "formatted") 324// 325// Returns whether the assertion was successful (true) or not (false). 326func (a *Assertions) HTTPBodyContainsf(handler http.HandlerFunc, method string, url string, values url.Values, str interface{}, msg string, args ...interface{}) { 327 if h, ok := a.t.(tHelper); ok { 328 h.Helper() 329 } 330 HTTPBodyContainsf(a.t, handler, method, url, values, str, msg, args...) 331} 332 333// HTTPBodyNotContains asserts that a specified handler returns a 334// body that does not contain a string. 335// 336// a.HTTPBodyNotContains(myHandler, "GET", "www.google.com", nil, "I'm Feeling Lucky") 337// 338// Returns whether the assertion was successful (true) or not (false). 339func (a *Assertions) HTTPBodyNotContains(handler http.HandlerFunc, method string, url string, values url.Values, str interface{}, msgAndArgs ...interface{}) { 340 if h, ok := a.t.(tHelper); ok { 341 h.Helper() 342 } 343 HTTPBodyNotContains(a.t, handler, method, url, values, str, msgAndArgs...) 344} 345 346// HTTPBodyNotContainsf asserts that a specified handler returns a 347// body that does not contain a string. 348// 349// a.HTTPBodyNotContainsf(myHandler, "GET", "www.google.com", nil, "I'm Feeling Lucky", "error message %s", "formatted") 350// 351// Returns whether the assertion was successful (true) or not (false). 352func (a *Assertions) HTTPBodyNotContainsf(handler http.HandlerFunc, method string, url string, values url.Values, str interface{}, msg string, args ...interface{}) { 353 if h, ok := a.t.(tHelper); ok { 354 h.Helper() 355 } 356 HTTPBodyNotContainsf(a.t, handler, method, url, values, str, msg, args...) 357} 358 359// HTTPError asserts that a specified handler returns an error status code. 360// 361// a.HTTPError(myHandler, "POST", "/a/b/c", url.Values{"a": []string{"b", "c"}} 362// 363// Returns whether the assertion was successful (true) or not (false). 364func (a *Assertions) HTTPError(handler http.HandlerFunc, method string, url string, values url.Values, msgAndArgs ...interface{}) { 365 if h, ok := a.t.(tHelper); ok { 366 h.Helper() 367 } 368 HTTPError(a.t, handler, method, url, values, msgAndArgs...) 369} 370 371// HTTPErrorf asserts that a specified handler returns an error status code. 372// 373// a.HTTPErrorf(myHandler, "POST", "/a/b/c", url.Values{"a": []string{"b", "c"}} 374// 375// Returns whether the assertion was successful (true, "error message %s", "formatted") or not (false). 376func (a *Assertions) HTTPErrorf(handler http.HandlerFunc, method string, url string, values url.Values, msg string, args ...interface{}) { 377 if h, ok := a.t.(tHelper); ok { 378 h.Helper() 379 } 380 HTTPErrorf(a.t, handler, method, url, values, msg, args...) 381} 382 383// HTTPRedirect asserts that a specified handler returns a redirect status code. 384// 385// a.HTTPRedirect(myHandler, "GET", "/a/b/c", url.Values{"a": []string{"b", "c"}} 386// 387// Returns whether the assertion was successful (true) or not (false). 388func (a *Assertions) HTTPRedirect(handler http.HandlerFunc, method string, url string, values url.Values, msgAndArgs ...interface{}) { 389 if h, ok := a.t.(tHelper); ok { 390 h.Helper() 391 } 392 HTTPRedirect(a.t, handler, method, url, values, msgAndArgs...) 393} 394 395// HTTPRedirectf asserts that a specified handler returns a redirect status code. 396// 397// a.HTTPRedirectf(myHandler, "GET", "/a/b/c", url.Values{"a": []string{"b", "c"}} 398// 399// Returns whether the assertion was successful (true, "error message %s", "formatted") or not (false). 400func (a *Assertions) HTTPRedirectf(handler http.HandlerFunc, method string, url string, values url.Values, msg string, args ...interface{}) { 401 if h, ok := a.t.(tHelper); ok { 402 h.Helper() 403 } 404 HTTPRedirectf(a.t, handler, method, url, values, msg, args...) 405} 406 407// HTTPSuccess asserts that a specified handler returns a success status code. 408// 409// a.HTTPSuccess(myHandler, "POST", "http://www.google.com", nil) 410// 411// Returns whether the assertion was successful (true) or not (false). 412func (a *Assertions) HTTPSuccess(handler http.HandlerFunc, method string, url string, values url.Values, msgAndArgs ...interface{}) { 413 if h, ok := a.t.(tHelper); ok { 414 h.Helper() 415 } 416 HTTPSuccess(a.t, handler, method, url, values, msgAndArgs...) 417} 418 419// HTTPSuccessf asserts that a specified handler returns a success status code. 420// 421// a.HTTPSuccessf(myHandler, "POST", "http://www.google.com", nil, "error message %s", "formatted") 422// 423// Returns whether the assertion was successful (true) or not (false). 424func (a *Assertions) HTTPSuccessf(handler http.HandlerFunc, method string, url string, values url.Values, msg string, args ...interface{}) { 425 if h, ok := a.t.(tHelper); ok { 426 h.Helper() 427 } 428 HTTPSuccessf(a.t, handler, method, url, values, msg, args...) 429} 430 431// Implements asserts that an object is implemented by the specified interface. 432// 433// a.Implements((*MyInterface)(nil), new(MyObject)) 434func (a *Assertions) Implements(interfaceObject interface{}, object interface{}, msgAndArgs ...interface{}) { 435 if h, ok := a.t.(tHelper); ok { 436 h.Helper() 437 } 438 Implements(a.t, interfaceObject, object, msgAndArgs...) 439} 440 441// Implementsf asserts that an object is implemented by the specified interface. 442// 443// a.Implementsf((*MyInterface, "error message %s", "formatted")(nil), new(MyObject)) 444func (a *Assertions) Implementsf(interfaceObject interface{}, object interface{}, msg string, args ...interface{}) { 445 if h, ok := a.t.(tHelper); ok { 446 h.Helper() 447 } 448 Implementsf(a.t, interfaceObject, object, msg, args...) 449} 450 451// InDelta asserts that the two numerals are within delta of each other. 452// 453// a.InDelta(math.Pi, (22 / 7.0), 0.01) 454func (a *Assertions) InDelta(expected interface{}, actual interface{}, delta float64, msgAndArgs ...interface{}) { 455 if h, ok := a.t.(tHelper); ok { 456 h.Helper() 457 } 458 InDelta(a.t, expected, actual, delta, msgAndArgs...) 459} 460 461// InDeltaMapValues is the same as InDelta, but it compares all values between two maps. Both maps must have exactly the same keys. 462func (a *Assertions) InDeltaMapValues(expected interface{}, actual interface{}, delta float64, msgAndArgs ...interface{}) { 463 if h, ok := a.t.(tHelper); ok { 464 h.Helper() 465 } 466 InDeltaMapValues(a.t, expected, actual, delta, msgAndArgs...) 467} 468 469// InDeltaMapValuesf is the same as InDelta, but it compares all values between two maps. Both maps must have exactly the same keys. 470func (a *Assertions) InDeltaMapValuesf(expected interface{}, actual interface{}, delta float64, msg string, args ...interface{}) { 471 if h, ok := a.t.(tHelper); ok { 472 h.Helper() 473 } 474 InDeltaMapValuesf(a.t, expected, actual, delta, msg, args...) 475} 476 477// InDeltaSlice is the same as InDelta, except it compares two slices. 478func (a *Assertions) InDeltaSlice(expected interface{}, actual interface{}, delta float64, msgAndArgs ...interface{}) { 479 if h, ok := a.t.(tHelper); ok { 480 h.Helper() 481 } 482 InDeltaSlice(a.t, expected, actual, delta, msgAndArgs...) 483} 484 485// InDeltaSlicef is the same as InDelta, except it compares two slices. 486func (a *Assertions) InDeltaSlicef(expected interface{}, actual interface{}, delta float64, msg string, args ...interface{}) { 487 if h, ok := a.t.(tHelper); ok { 488 h.Helper() 489 } 490 InDeltaSlicef(a.t, expected, actual, delta, msg, args...) 491} 492 493// InDeltaf asserts that the two numerals are within delta of each other. 494// 495// a.InDeltaf(math.Pi, (22 / 7.0, "error message %s", "formatted"), 0.01) 496func (a *Assertions) InDeltaf(expected interface{}, actual interface{}, delta float64, msg string, args ...interface{}) { 497 if h, ok := a.t.(tHelper); ok { 498 h.Helper() 499 } 500 InDeltaf(a.t, expected, actual, delta, msg, args...) 501} 502 503// InEpsilon asserts that expected and actual have a relative error less than epsilon 504func (a *Assertions) InEpsilon(expected interface{}, actual interface{}, epsilon float64, msgAndArgs ...interface{}) { 505 if h, ok := a.t.(tHelper); ok { 506 h.Helper() 507 } 508 InEpsilon(a.t, expected, actual, epsilon, msgAndArgs...) 509} 510 511// InEpsilonSlice is the same as InEpsilon, except it compares each value from two slices. 512func (a *Assertions) InEpsilonSlice(expected interface{}, actual interface{}, epsilon float64, msgAndArgs ...interface{}) { 513 if h, ok := a.t.(tHelper); ok { 514 h.Helper() 515 } 516 InEpsilonSlice(a.t, expected, actual, epsilon, msgAndArgs...) 517} 518 519// InEpsilonSlicef is the same as InEpsilon, except it compares each value from two slices. 520func (a *Assertions) InEpsilonSlicef(expected interface{}, actual interface{}, epsilon float64, msg string, args ...interface{}) { 521 if h, ok := a.t.(tHelper); ok { 522 h.Helper() 523 } 524 InEpsilonSlicef(a.t, expected, actual, epsilon, msg, args...) 525} 526 527// InEpsilonf asserts that expected and actual have a relative error less than epsilon 528func (a *Assertions) InEpsilonf(expected interface{}, actual interface{}, epsilon float64, msg string, args ...interface{}) { 529 if h, ok := a.t.(tHelper); ok { 530 h.Helper() 531 } 532 InEpsilonf(a.t, expected, actual, epsilon, msg, args...) 533} 534 535// IsType asserts that the specified objects are of the same type. 536func (a *Assertions) IsType(expectedType interface{}, object interface{}, msgAndArgs ...interface{}) { 537 if h, ok := a.t.(tHelper); ok { 538 h.Helper() 539 } 540 IsType(a.t, expectedType, object, msgAndArgs...) 541} 542 543// IsTypef asserts that the specified objects are of the same type. 544func (a *Assertions) IsTypef(expectedType interface{}, object interface{}, msg string, args ...interface{}) { 545 if h, ok := a.t.(tHelper); ok { 546 h.Helper() 547 } 548 IsTypef(a.t, expectedType, object, msg, args...) 549} 550 551// JSONEq asserts that two JSON strings are equivalent. 552// 553// a.JSONEq(`{"hello": "world", "foo": "bar"}`, `{"foo": "bar", "hello": "world"}`) 554func (a *Assertions) JSONEq(expected string, actual string, msgAndArgs ...interface{}) { 555 if h, ok := a.t.(tHelper); ok { 556 h.Helper() 557 } 558 JSONEq(a.t, expected, actual, msgAndArgs...) 559} 560 561// JSONEqf asserts that two JSON strings are equivalent. 562// 563// a.JSONEqf(`{"hello": "world", "foo": "bar"}`, `{"foo": "bar", "hello": "world"}`, "error message %s", "formatted") 564func (a *Assertions) JSONEqf(expected string, actual string, msg string, args ...interface{}) { 565 if h, ok := a.t.(tHelper); ok { 566 h.Helper() 567 } 568 JSONEqf(a.t, expected, actual, msg, args...) 569} 570 571// Len asserts that the specified object has specific length. 572// Len also fails if the object has a type that len() not accept. 573// 574// a.Len(mySlice, 3) 575func (a *Assertions) Len(object interface{}, length int, msgAndArgs ...interface{}) { 576 if h, ok := a.t.(tHelper); ok { 577 h.Helper() 578 } 579 Len(a.t, object, length, msgAndArgs...) 580} 581 582// Lenf asserts that the specified object has specific length. 583// Lenf also fails if the object has a type that len() not accept. 584// 585// a.Lenf(mySlice, 3, "error message %s", "formatted") 586func (a *Assertions) Lenf(object interface{}, length int, msg string, args ...interface{}) { 587 if h, ok := a.t.(tHelper); ok { 588 h.Helper() 589 } 590 Lenf(a.t, object, length, msg, args...) 591} 592 593// Nil asserts that the specified object is nil. 594// 595// a.Nil(err) 596func (a *Assertions) Nil(object interface{}, msgAndArgs ...interface{}) { 597 if h, ok := a.t.(tHelper); ok { 598 h.Helper() 599 } 600 Nil(a.t, object, msgAndArgs...) 601} 602 603// Nilf asserts that the specified object is nil. 604// 605// a.Nilf(err, "error message %s", "formatted") 606func (a *Assertions) Nilf(object interface{}, msg string, args ...interface{}) { 607 if h, ok := a.t.(tHelper); ok { 608 h.Helper() 609 } 610 Nilf(a.t, object, msg, args...) 611} 612 613// NoError asserts that a function returned no error (i.e. `nil`). 614// 615// actualObj, err := SomeFunction() 616// if a.NoError(err) { 617// assert.Equal(t, expectedObj, actualObj) 618// } 619func (a *Assertions) NoError(err error, msgAndArgs ...interface{}) { 620 if h, ok := a.t.(tHelper); ok { 621 h.Helper() 622 } 623 NoError(a.t, err, msgAndArgs...) 624} 625 626// NoErrorf asserts that a function returned no error (i.e. `nil`). 627// 628// actualObj, err := SomeFunction() 629// if a.NoErrorf(err, "error message %s", "formatted") { 630// assert.Equal(t, expectedObj, actualObj) 631// } 632func (a *Assertions) NoErrorf(err error, msg string, args ...interface{}) { 633 if h, ok := a.t.(tHelper); ok { 634 h.Helper() 635 } 636 NoErrorf(a.t, err, msg, args...) 637} 638 639// NotContains asserts that the specified string, list(array, slice...) or map does NOT contain the 640// specified substring or element. 641// 642// a.NotContains("Hello World", "Earth") 643// a.NotContains(["Hello", "World"], "Earth") 644// a.NotContains({"Hello": "World"}, "Earth") 645func (a *Assertions) NotContains(s interface{}, contains interface{}, msgAndArgs ...interface{}) { 646 if h, ok := a.t.(tHelper); ok { 647 h.Helper() 648 } 649 NotContains(a.t, s, contains, msgAndArgs...) 650} 651 652// NotContainsf asserts that the specified string, list(array, slice...) or map does NOT contain the 653// specified substring or element. 654// 655// a.NotContainsf("Hello World", "Earth", "error message %s", "formatted") 656// a.NotContainsf(["Hello", "World"], "Earth", "error message %s", "formatted") 657// a.NotContainsf({"Hello": "World"}, "Earth", "error message %s", "formatted") 658func (a *Assertions) NotContainsf(s interface{}, contains interface{}, msg string, args ...interface{}) { 659 if h, ok := a.t.(tHelper); ok { 660 h.Helper() 661 } 662 NotContainsf(a.t, s, contains, msg, args...) 663} 664 665// NotEmpty asserts that the specified object is NOT empty. I.e. not nil, "", false, 0 or either 666// a slice or a channel with len == 0. 667// 668// if a.NotEmpty(obj) { 669// assert.Equal(t, "two", obj[1]) 670// } 671func (a *Assertions) NotEmpty(object interface{}, msgAndArgs ...interface{}) { 672 if h, ok := a.t.(tHelper); ok { 673 h.Helper() 674 } 675 NotEmpty(a.t, object, msgAndArgs...) 676} 677 678// NotEmptyf asserts that the specified object is NOT empty. I.e. not nil, "", false, 0 or either 679// a slice or a channel with len == 0. 680// 681// if a.NotEmptyf(obj, "error message %s", "formatted") { 682// assert.Equal(t, "two", obj[1]) 683// } 684func (a *Assertions) NotEmptyf(object interface{}, msg string, args ...interface{}) { 685 if h, ok := a.t.(tHelper); ok { 686 h.Helper() 687 } 688 NotEmptyf(a.t, object, msg, args...) 689} 690 691// NotEqual asserts that the specified values are NOT equal. 692// 693// a.NotEqual(obj1, obj2) 694// 695// Pointer variable equality is determined based on the equality of the 696// referenced values (as opposed to the memory addresses). 697func (a *Assertions) NotEqual(expected interface{}, actual interface{}, msgAndArgs ...interface{}) { 698 if h, ok := a.t.(tHelper); ok { 699 h.Helper() 700 } 701 NotEqual(a.t, expected, actual, msgAndArgs...) 702} 703 704// NotEqualf asserts that the specified values are NOT equal. 705// 706// a.NotEqualf(obj1, obj2, "error message %s", "formatted") 707// 708// Pointer variable equality is determined based on the equality of the 709// referenced values (as opposed to the memory addresses). 710func (a *Assertions) NotEqualf(expected interface{}, actual interface{}, msg string, args ...interface{}) { 711 if h, ok := a.t.(tHelper); ok { 712 h.Helper() 713 } 714 NotEqualf(a.t, expected, actual, msg, args...) 715} 716 717// NotNil asserts that the specified object is not nil. 718// 719// a.NotNil(err) 720func (a *Assertions) NotNil(object interface{}, msgAndArgs ...interface{}) { 721 if h, ok := a.t.(tHelper); ok { 722 h.Helper() 723 } 724 NotNil(a.t, object, msgAndArgs...) 725} 726 727// NotNilf asserts that the specified object is not nil. 728// 729// a.NotNilf(err, "error message %s", "formatted") 730func (a *Assertions) NotNilf(object interface{}, msg string, args ...interface{}) { 731 if h, ok := a.t.(tHelper); ok { 732 h.Helper() 733 } 734 NotNilf(a.t, object, msg, args...) 735} 736 737// NotPanics asserts that the code inside the specified PanicTestFunc does NOT panic. 738// 739// a.NotPanics(func(){ RemainCalm() }) 740func (a *Assertions) NotPanics(f assert.PanicTestFunc, msgAndArgs ...interface{}) { 741 if h, ok := a.t.(tHelper); ok { 742 h.Helper() 743 } 744 NotPanics(a.t, f, msgAndArgs...) 745} 746 747// NotPanicsf asserts that the code inside the specified PanicTestFunc does NOT panic. 748// 749// a.NotPanicsf(func(){ RemainCalm() }, "error message %s", "formatted") 750func (a *Assertions) NotPanicsf(f assert.PanicTestFunc, msg string, args ...interface{}) { 751 if h, ok := a.t.(tHelper); ok { 752 h.Helper() 753 } 754 NotPanicsf(a.t, f, msg, args...) 755} 756 757// NotRegexp asserts that a specified regexp does not match a string. 758// 759// a.NotRegexp(regexp.MustCompile("starts"), "it's starting") 760// a.NotRegexp("^start", "it's not starting") 761func (a *Assertions) NotRegexp(rx interface{}, str interface{}, msgAndArgs ...interface{}) { 762 if h, ok := a.t.(tHelper); ok { 763 h.Helper() 764 } 765 NotRegexp(a.t, rx, str, msgAndArgs...) 766} 767 768// NotRegexpf asserts that a specified regexp does not match a string. 769// 770// a.NotRegexpf(regexp.MustCompile("starts", "error message %s", "formatted"), "it's starting") 771// a.NotRegexpf("^start", "it's not starting", "error message %s", "formatted") 772func (a *Assertions) NotRegexpf(rx interface{}, str interface{}, msg string, args ...interface{}) { 773 if h, ok := a.t.(tHelper); ok { 774 h.Helper() 775 } 776 NotRegexpf(a.t, rx, str, msg, args...) 777} 778 779// NotSubset asserts that the specified list(array, slice...) contains not all 780// elements given in the specified subset(array, slice...). 781// 782// a.NotSubset([1, 3, 4], [1, 2], "But [1, 3, 4] does not contain [1, 2]") 783func (a *Assertions) NotSubset(list interface{}, subset interface{}, msgAndArgs ...interface{}) { 784 if h, ok := a.t.(tHelper); ok { 785 h.Helper() 786 } 787 NotSubset(a.t, list, subset, msgAndArgs...) 788} 789 790// NotSubsetf asserts that the specified list(array, slice...) contains not all 791// elements given in the specified subset(array, slice...). 792// 793// a.NotSubsetf([1, 3, 4], [1, 2], "But [1, 3, 4] does not contain [1, 2]", "error message %s", "formatted") 794func (a *Assertions) NotSubsetf(list interface{}, subset interface{}, msg string, args ...interface{}) { 795 if h, ok := a.t.(tHelper); ok { 796 h.Helper() 797 } 798 NotSubsetf(a.t, list, subset, msg, args...) 799} 800 801// NotZero asserts that i is not the zero value for its type. 802func (a *Assertions) NotZero(i interface{}, msgAndArgs ...interface{}) { 803 if h, ok := a.t.(tHelper); ok { 804 h.Helper() 805 } 806 NotZero(a.t, i, msgAndArgs...) 807} 808 809// NotZerof asserts that i is not the zero value for its type. 810func (a *Assertions) NotZerof(i interface{}, msg string, args ...interface{}) { 811 if h, ok := a.t.(tHelper); ok { 812 h.Helper() 813 } 814 NotZerof(a.t, i, msg, args...) 815} 816 817// Panics asserts that the code inside the specified PanicTestFunc panics. 818// 819// a.Panics(func(){ GoCrazy() }) 820func (a *Assertions) Panics(f assert.PanicTestFunc, msgAndArgs ...interface{}) { 821 if h, ok := a.t.(tHelper); ok { 822 h.Helper() 823 } 824 Panics(a.t, f, msgAndArgs...) 825} 826 827// PanicsWithValue asserts that the code inside the specified PanicTestFunc panics, and that 828// the recovered panic value equals the expected panic value. 829// 830// a.PanicsWithValue("crazy error", func(){ GoCrazy() }) 831func (a *Assertions) PanicsWithValue(expected interface{}, f assert.PanicTestFunc, msgAndArgs ...interface{}) { 832 if h, ok := a.t.(tHelper); ok { 833 h.Helper() 834 } 835 PanicsWithValue(a.t, expected, f, msgAndArgs...) 836} 837 838// PanicsWithValuef asserts that the code inside the specified PanicTestFunc panics, and that 839// the recovered panic value equals the expected panic value. 840// 841// a.PanicsWithValuef("crazy error", func(){ GoCrazy() }, "error message %s", "formatted") 842func (a *Assertions) PanicsWithValuef(expected interface{}, f assert.PanicTestFunc, msg string, args ...interface{}) { 843 if h, ok := a.t.(tHelper); ok { 844 h.Helper() 845 } 846 PanicsWithValuef(a.t, expected, f, msg, args...) 847} 848 849// Panicsf asserts that the code inside the specified PanicTestFunc panics. 850// 851// a.Panicsf(func(){ GoCrazy() }, "error message %s", "formatted") 852func (a *Assertions) Panicsf(f assert.PanicTestFunc, msg string, args ...interface{}) { 853 if h, ok := a.t.(tHelper); ok { 854 h.Helper() 855 } 856 Panicsf(a.t, f, msg, args...) 857} 858 859// Regexp asserts that a specified regexp matches a string. 860// 861// a.Regexp(regexp.MustCompile("start"), "it's starting") 862// a.Regexp("start...$", "it's not starting") 863func (a *Assertions) Regexp(rx interface{}, str interface{}, msgAndArgs ...interface{}) { 864 if h, ok := a.t.(tHelper); ok { 865 h.Helper() 866 } 867 Regexp(a.t, rx, str, msgAndArgs...) 868} 869 870// Regexpf asserts that a specified regexp matches a string. 871// 872// a.Regexpf(regexp.MustCompile("start", "error message %s", "formatted"), "it's starting") 873// a.Regexpf("start...$", "it's not starting", "error message %s", "formatted") 874func (a *Assertions) Regexpf(rx interface{}, str interface{}, msg string, args ...interface{}) { 875 if h, ok := a.t.(tHelper); ok { 876 h.Helper() 877 } 878 Regexpf(a.t, rx, str, msg, args...) 879} 880 881// Subset asserts that the specified list(array, slice...) contains all 882// elements given in the specified subset(array, slice...). 883// 884// a.Subset([1, 2, 3], [1, 2], "But [1, 2, 3] does contain [1, 2]") 885func (a *Assertions) Subset(list interface{}, subset interface{}, msgAndArgs ...interface{}) { 886 if h, ok := a.t.(tHelper); ok { 887 h.Helper() 888 } 889 Subset(a.t, list, subset, msgAndArgs...) 890} 891 892// Subsetf asserts that the specified list(array, slice...) contains all 893// elements given in the specified subset(array, slice...). 894// 895// a.Subsetf([1, 2, 3], [1, 2], "But [1, 2, 3] does contain [1, 2]", "error message %s", "formatted") 896func (a *Assertions) Subsetf(list interface{}, subset interface{}, msg string, args ...interface{}) { 897 if h, ok := a.t.(tHelper); ok { 898 h.Helper() 899 } 900 Subsetf(a.t, list, subset, msg, args...) 901} 902 903// True asserts that the specified value is true. 904// 905// a.True(myBool) 906func (a *Assertions) True(value bool, msgAndArgs ...interface{}) { 907 if h, ok := a.t.(tHelper); ok { 908 h.Helper() 909 } 910 True(a.t, value, msgAndArgs...) 911} 912 913// Truef asserts that the specified value is true. 914// 915// a.Truef(myBool, "error message %s", "formatted") 916func (a *Assertions) Truef(value bool, msg string, args ...interface{}) { 917 if h, ok := a.t.(tHelper); ok { 918 h.Helper() 919 } 920 Truef(a.t, value, msg, args...) 921} 922 923// WithinDuration asserts that the two times are within duration delta of each other. 924// 925// a.WithinDuration(time.Now(), time.Now(), 10*time.Second) 926func (a *Assertions) WithinDuration(expected time.Time, actual time.Time, delta time.Duration, msgAndArgs ...interface{}) { 927 if h, ok := a.t.(tHelper); ok { 928 h.Helper() 929 } 930 WithinDuration(a.t, expected, actual, delta, msgAndArgs...) 931} 932 933// WithinDurationf asserts that the two times are within duration delta of each other. 934// 935// a.WithinDurationf(time.Now(), time.Now(), 10*time.Second, "error message %s", "formatted") 936func (a *Assertions) WithinDurationf(expected time.Time, actual time.Time, delta time.Duration, msg string, args ...interface{}) { 937 if h, ok := a.t.(tHelper); ok { 938 h.Helper() 939 } 940 WithinDurationf(a.t, expected, actual, delta, msg, args...) 941} 942 943// Zero asserts that i is the zero value for its type. 944func (a *Assertions) Zero(i interface{}, msgAndArgs ...interface{}) { 945 if h, ok := a.t.(tHelper); ok { 946 h.Helper() 947 } 948 Zero(a.t, i, msgAndArgs...) 949} 950 951// Zerof asserts that i is the zero value for its type. 952func (a *Assertions) Zerof(i interface{}, msg string, args ...interface{}) { 953 if h, ok := a.t.(tHelper); ok { 954 h.Helper() 955 } 956 Zerof(a.t, i, msg, args...) 957} 958