1
0

assertion_format.go 17 KB

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