assertion_format.go 19 KB

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