assertion_forward.go 34 KB

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