You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

387 lines
14 KiB

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