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.

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