require_forward.go 33 KB

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