assertion_forward.go 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  1. /*
  2. * CODE GENERATED AUTOMATICALLY WITH github.com/stretchr/testify/_codegen
  3. * THIS FILE MUST NOT BE EDITED BY HAND
  4. */
  5. package assert
  6. import (
  7. http "net/http"
  8. url "net/url"
  9. time "time"
  10. )
  11. // Condition uses a Comparison to assert a complex condition.
  12. func (a *Assertions) Condition(comp Comparison, msgAndArgs ...interface{}) bool {
  13. return Condition(a.t, comp, msgAndArgs...)
  14. }
  15. // Contains asserts that the specified string, list(array, slice...) or map contains the
  16. // specified substring or element.
  17. //
  18. // a.Contains("Hello World", "World", "But 'Hello World' does contain 'World'")
  19. // a.Contains(["Hello", "World"], "World", "But ["Hello", "World"] does contain 'World'")
  20. // a.Contains({"Hello": "World"}, "Hello", "But {'Hello': 'World'} does contain 'Hello'")
  21. //
  22. // Returns whether the assertion was successful (true) or not (false).
  23. func (a *Assertions) Contains(s interface{}, contains interface{}, msgAndArgs ...interface{}) bool {
  24. return Contains(a.t, s, contains, msgAndArgs...)
  25. }
  26. // Empty asserts that the specified object is empty. I.e. nil, "", false, 0 or either
  27. // a slice or a channel with len == 0.
  28. //
  29. // a.Empty(obj)
  30. //
  31. // Returns whether the assertion was successful (true) or not (false).
  32. func (a *Assertions) Empty(object interface{}, msgAndArgs ...interface{}) bool {
  33. return Empty(a.t, object, msgAndArgs...)
  34. }
  35. // Equal asserts that two objects are equal.
  36. //
  37. // a.Equal(123, 123, "123 and 123 should be equal")
  38. //
  39. // Returns whether the assertion was successful (true) or not (false).
  40. //
  41. // Pointer variable equality is determined based on the equality of the
  42. // referenced values (as opposed to the memory addresses).
  43. func (a *Assertions) Equal(expected interface{}, actual interface{}, msgAndArgs ...interface{}) bool {
  44. return Equal(a.t, expected, actual, msgAndArgs...)
  45. }
  46. // EqualError asserts that a function returned an error (i.e. not `nil`)
  47. // and that it is equal to the provided error.
  48. //
  49. // actualObj, err := SomeFunction()
  50. // a.EqualError(err, expectedErrorString, "An error was expected")
  51. //
  52. // Returns whether the assertion was successful (true) or not (false).
  53. func (a *Assertions) EqualError(theError error, errString string, msgAndArgs ...interface{}) bool {
  54. return EqualError(a.t, theError, errString, msgAndArgs...)
  55. }
  56. // EqualValues asserts that two objects are equal or convertable to the same types
  57. // and equal.
  58. //
  59. // a.EqualValues(uint32(123), int32(123), "123 and 123 should be equal")
  60. //
  61. // Returns whether the assertion was successful (true) or not (false).
  62. func (a *Assertions) EqualValues(expected interface{}, actual interface{}, msgAndArgs ...interface{}) bool {
  63. return EqualValues(a.t, expected, actual, msgAndArgs...)
  64. }
  65. // Error asserts that a function returned an error (i.e. not `nil`).
  66. //
  67. // actualObj, err := SomeFunction()
  68. // if a.Error(err, "An error was expected") {
  69. // assert.Equal(t, err, expectedError)
  70. // }
  71. //
  72. // Returns whether the assertion was successful (true) or not (false).
  73. func (a *Assertions) Error(err error, msgAndArgs ...interface{}) bool {
  74. return Error(a.t, err, msgAndArgs...)
  75. }
  76. // Exactly asserts that two objects are equal is value and type.
  77. //
  78. // a.Exactly(int32(123), int64(123), "123 and 123 should NOT be equal")
  79. //
  80. // Returns whether the assertion was successful (true) or not (false).
  81. func (a *Assertions) Exactly(expected interface{}, actual interface{}, msgAndArgs ...interface{}) bool {
  82. return Exactly(a.t, expected, actual, msgAndArgs...)
  83. }
  84. // Fail reports a failure through
  85. func (a *Assertions) Fail(failureMessage string, msgAndArgs ...interface{}) bool {
  86. return Fail(a.t, failureMessage, msgAndArgs...)
  87. }
  88. // FailNow fails test
  89. func (a *Assertions) FailNow(failureMessage string, msgAndArgs ...interface{}) bool {
  90. return FailNow(a.t, failureMessage, msgAndArgs...)
  91. }
  92. // False asserts that the specified value is false.
  93. //
  94. // a.False(myBool, "myBool should be false")
  95. //
  96. // Returns whether the assertion was successful (true) or not (false).
  97. func (a *Assertions) False(value bool, msgAndArgs ...interface{}) bool {
  98. return False(a.t, value, msgAndArgs...)
  99. }
  100. // HTTPBodyContains asserts that a specified handler returns a
  101. // body that contains a string.
  102. //
  103. // a.HTTPBodyContains(myHandler, "www.google.com", nil, "I'm Feeling Lucky")
  104. //
  105. // Returns whether the assertion was successful (true) or not (false).
  106. func (a *Assertions) HTTPBodyContains(handler http.HandlerFunc, method string, url string, values url.Values, str interface{}) bool {
  107. return HTTPBodyContains(a.t, handler, method, url, values, str)
  108. }
  109. // HTTPBodyNotContains asserts that a specified handler returns a
  110. // body that does not contain a string.
  111. //
  112. // a.HTTPBodyNotContains(myHandler, "www.google.com", nil, "I'm Feeling Lucky")
  113. //
  114. // Returns whether the assertion was successful (true) or not (false).
  115. func (a *Assertions) HTTPBodyNotContains(handler http.HandlerFunc, method string, url string, values url.Values, str interface{}) bool {
  116. return HTTPBodyNotContains(a.t, handler, method, url, values, str)
  117. }
  118. // HTTPError asserts that a specified handler returns an error status code.
  119. //
  120. // a.HTTPError(myHandler, "POST", "/a/b/c", url.Values{"a": []string{"b", "c"}}
  121. //
  122. // Returns whether the assertion was successful (true) or not (false).
  123. func (a *Assertions) HTTPError(handler http.HandlerFunc, method string, url string, values url.Values) bool {
  124. return HTTPError(a.t, handler, method, url, values)
  125. }
  126. // HTTPRedirect asserts that a specified handler returns a redirect status code.
  127. //
  128. // a.HTTPRedirect(myHandler, "GET", "/a/b/c", url.Values{"a": []string{"b", "c"}}
  129. //
  130. // Returns whether the assertion was successful (true) or not (false).
  131. func (a *Assertions) HTTPRedirect(handler http.HandlerFunc, method string, url string, values url.Values) bool {
  132. return HTTPRedirect(a.t, handler, method, url, values)
  133. }
  134. // HTTPSuccess asserts that a specified handler returns a success status code.
  135. //
  136. // a.HTTPSuccess(myHandler, "POST", "http://www.google.com", nil)
  137. //
  138. // Returns whether the assertion was successful (true) or not (false).
  139. func (a *Assertions) HTTPSuccess(handler http.HandlerFunc, method string, url string, values url.Values) bool {
  140. return HTTPSuccess(a.t, handler, method, url, values)
  141. }
  142. // Implements asserts that an object is implemented by the specified interface.
  143. //
  144. // a.Implements((*MyInterface)(nil), new(MyObject), "MyObject")
  145. func (a *Assertions) Implements(interfaceObject interface{}, object interface{}, msgAndArgs ...interface{}) bool {
  146. return Implements(a.t, interfaceObject, object, msgAndArgs...)
  147. }
  148. // InDelta asserts that the two numerals are within delta of each other.
  149. //
  150. // a.InDelta(math.Pi, (22 / 7.0), 0.01)
  151. //
  152. // Returns whether the assertion was successful (true) or not (false).
  153. func (a *Assertions) InDelta(expected interface{}, actual interface{}, delta float64, msgAndArgs ...interface{}) bool {
  154. return InDelta(a.t, expected, actual, delta, msgAndArgs...)
  155. }
  156. // InDeltaSlice is the same as InDelta, except it compares two slices.
  157. func (a *Assertions) InDeltaSlice(expected interface{}, actual interface{}, delta float64, msgAndArgs ...interface{}) bool {
  158. return InDeltaSlice(a.t, expected, actual, delta, msgAndArgs...)
  159. }
  160. // InEpsilon asserts that expected and actual have a relative error less than epsilon
  161. //
  162. // Returns whether the assertion was successful (true) or not (false).
  163. func (a *Assertions) InEpsilon(expected interface{}, actual interface{}, epsilon float64, msgAndArgs ...interface{}) bool {
  164. return InEpsilon(a.t, expected, actual, epsilon, msgAndArgs...)
  165. }
  166. // InEpsilonSlice is the same as InEpsilon, except it compares each value from two slices.
  167. func (a *Assertions) InEpsilonSlice(expected interface{}, actual interface{}, epsilon float64, msgAndArgs ...interface{}) bool {
  168. return InEpsilonSlice(a.t, expected, actual, epsilon, msgAndArgs...)
  169. }
  170. // IsType asserts that the specified objects are of the same type.
  171. func (a *Assertions) IsType(expectedType interface{}, object interface{}, msgAndArgs ...interface{}) bool {
  172. return IsType(a.t, expectedType, object, msgAndArgs...)
  173. }
  174. // JSONEq asserts that two JSON strings are equivalent.
  175. //
  176. // a.JSONEq(`{"hello": "world", "foo": "bar"}`, `{"foo": "bar", "hello": "world"}`)
  177. //
  178. // Returns whether the assertion was successful (true) or not (false).
  179. func (a *Assertions) JSONEq(expected string, actual string, msgAndArgs ...interface{}) bool {
  180. return JSONEq(a.t, expected, actual, msgAndArgs...)
  181. }
  182. // Len asserts that the specified object has specific length.
  183. // Len also fails if the object has a type that len() not accept.
  184. //
  185. // a.Len(mySlice, 3, "The size of slice is not 3")
  186. //
  187. // Returns whether the assertion was successful (true) or not (false).
  188. func (a *Assertions) Len(object interface{}, length int, msgAndArgs ...interface{}) bool {
  189. return Len(a.t, object, length, msgAndArgs...)
  190. }
  191. // Nil asserts that the specified object is nil.
  192. //
  193. // a.Nil(err, "err should be nothing")
  194. //
  195. // Returns whether the assertion was successful (true) or not (false).
  196. func (a *Assertions) Nil(object interface{}, msgAndArgs ...interface{}) bool {
  197. return Nil(a.t, object, msgAndArgs...)
  198. }
  199. // NoError asserts that a function returned no error (i.e. `nil`).
  200. //
  201. // actualObj, err := SomeFunction()
  202. // if a.NoError(err) {
  203. // assert.Equal(t, actualObj, expectedObj)
  204. // }
  205. //
  206. // Returns whether the assertion was successful (true) or not (false).
  207. func (a *Assertions) NoError(err error, msgAndArgs ...interface{}) bool {
  208. return NoError(a.t, err, msgAndArgs...)
  209. }
  210. // NotContains asserts that the specified string, list(array, slice...) or map does NOT contain the
  211. // specified substring or element.
  212. //
  213. // a.NotContains("Hello World", "Earth", "But 'Hello World' does NOT contain 'Earth'")
  214. // a.NotContains(["Hello", "World"], "Earth", "But ['Hello', 'World'] does NOT contain 'Earth'")
  215. // a.NotContains({"Hello": "World"}, "Earth", "But {'Hello': 'World'} does NOT contain 'Earth'")
  216. //
  217. // Returns whether the assertion was successful (true) or not (false).
  218. func (a *Assertions) NotContains(s interface{}, contains interface{}, msgAndArgs ...interface{}) bool {
  219. return NotContains(a.t, s, contains, msgAndArgs...)
  220. }
  221. // NotEmpty asserts that the specified object is NOT empty. I.e. not nil, "", false, 0 or either
  222. // a slice or a channel with len == 0.
  223. //
  224. // if a.NotEmpty(obj) {
  225. // assert.Equal(t, "two", obj[1])
  226. // }
  227. //
  228. // Returns whether the assertion was successful (true) or not (false).
  229. func (a *Assertions) NotEmpty(object interface{}, msgAndArgs ...interface{}) bool {
  230. return NotEmpty(a.t, object, msgAndArgs...)
  231. }
  232. // NotEqual asserts that the specified values are NOT equal.
  233. //
  234. // a.NotEqual(obj1, obj2, "two objects shouldn't be equal")
  235. //
  236. // Returns whether the assertion was successful (true) or not (false).
  237. //
  238. // Pointer variable equality is determined based on the equality of the
  239. // referenced values (as opposed to the memory addresses).
  240. func (a *Assertions) NotEqual(expected interface{}, actual interface{}, msgAndArgs ...interface{}) bool {
  241. return NotEqual(a.t, expected, actual, msgAndArgs...)
  242. }
  243. // NotNil asserts that the specified object is not nil.
  244. //
  245. // a.NotNil(err, "err should be something")
  246. //
  247. // Returns whether the assertion was successful (true) or not (false).
  248. func (a *Assertions) NotNil(object interface{}, msgAndArgs ...interface{}) bool {
  249. return NotNil(a.t, object, msgAndArgs...)
  250. }
  251. // NotPanics asserts that the code inside the specified PanicTestFunc does NOT panic.
  252. //
  253. // a.NotPanics(func(){
  254. // RemainCalm()
  255. // }, "Calling RemainCalm() should NOT panic")
  256. //
  257. // Returns whether the assertion was successful (true) or not (false).
  258. func (a *Assertions) NotPanics(f PanicTestFunc, msgAndArgs ...interface{}) bool {
  259. return NotPanics(a.t, f, msgAndArgs...)
  260. }
  261. // NotRegexp asserts that a specified regexp does not match a string.
  262. //
  263. // a.NotRegexp(regexp.MustCompile("starts"), "it's starting")
  264. // a.NotRegexp("^start", "it's not starting")
  265. //
  266. // Returns whether the assertion was successful (true) or not (false).
  267. func (a *Assertions) NotRegexp(rx interface{}, str interface{}, msgAndArgs ...interface{}) bool {
  268. return NotRegexp(a.t, rx, str, msgAndArgs...)
  269. }
  270. // NotZero asserts that i is not the zero value for its type and returns the truth.
  271. func (a *Assertions) NotZero(i interface{}, msgAndArgs ...interface{}) bool {
  272. return NotZero(a.t, i, msgAndArgs...)
  273. }
  274. // Panics asserts that the code inside the specified PanicTestFunc panics.
  275. //
  276. // a.Panics(func(){
  277. // GoCrazy()
  278. // }, "Calling GoCrazy() should panic")
  279. //
  280. // Returns whether the assertion was successful (true) or not (false).
  281. func (a *Assertions) Panics(f PanicTestFunc, msgAndArgs ...interface{}) bool {
  282. return Panics(a.t, f, msgAndArgs...)
  283. }
  284. // Regexp asserts that a specified regexp matches a string.
  285. //
  286. // a.Regexp(regexp.MustCompile("start"), "it's starting")
  287. // a.Regexp("start...$", "it's not starting")
  288. //
  289. // Returns whether the assertion was successful (true) or not (false).
  290. func (a *Assertions) Regexp(rx interface{}, str interface{}, msgAndArgs ...interface{}) bool {
  291. return Regexp(a.t, rx, str, msgAndArgs...)
  292. }
  293. // True asserts that the specified value is true.
  294. //
  295. // a.True(myBool, "myBool should be true")
  296. //
  297. // Returns whether the assertion was successful (true) or not (false).
  298. func (a *Assertions) True(value bool, msgAndArgs ...interface{}) bool {
  299. return True(a.t, value, msgAndArgs...)
  300. }
  301. // WithinDuration asserts that the two times are within duration delta of each other.
  302. //
  303. // a.WithinDuration(time.Now(), time.Now(), 10*time.Second, "The difference should not be more than 10s")
  304. //
  305. // Returns whether the assertion was successful (true) or not (false).
  306. func (a *Assertions) WithinDuration(expected time.Time, actual time.Time, delta time.Duration, msgAndArgs ...interface{}) bool {
  307. return WithinDuration(a.t, expected, actual, delta, msgAndArgs...)
  308. }
  309. // Zero asserts that i is the zero value for its type and returns the truth.
  310. func (a *Assertions) Zero(i interface{}, msgAndArgs ...interface{}) bool {
  311. return Zero(a.t, i, msgAndArgs...)
  312. }