assertion_format.go 19 KB

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