2
0

assertion_forward.go 60 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673
  1. // Code generated with github.com/stretchr/testify/_codegen; DO NOT EDIT.
  2. package assert
  3. import (
  4. http "net/http"
  5. url "net/url"
  6. time "time"
  7. )
  8. // Condition uses a Comparison to assert a complex condition.
  9. func (a *Assertions) Condition(comp Comparison, msgAndArgs ...interface{}) bool {
  10. if h, ok := a.t.(tHelper); ok {
  11. h.Helper()
  12. }
  13. return Condition(a.t, comp, msgAndArgs...)
  14. }
  15. // Conditionf uses a Comparison to assert a complex condition.
  16. func (a *Assertions) Conditionf(comp Comparison, msg string, args ...interface{}) bool {
  17. if h, ok := a.t.(tHelper); ok {
  18. h.Helper()
  19. }
  20. return Conditionf(a.t, comp, msg, args...)
  21. }
  22. // Contains asserts that the specified string, list(array, slice...) or map contains the
  23. // specified substring or element.
  24. //
  25. // a.Contains("Hello World", "World")
  26. // a.Contains(["Hello", "World"], "World")
  27. // a.Contains({"Hello": "World"}, "Hello")
  28. func (a *Assertions) Contains(s interface{}, contains interface{}, msgAndArgs ...interface{}) bool {
  29. if h, ok := a.t.(tHelper); ok {
  30. h.Helper()
  31. }
  32. return Contains(a.t, s, contains, msgAndArgs...)
  33. }
  34. // Containsf asserts that the specified string, list(array, slice...) or map contains the
  35. // specified substring or element.
  36. //
  37. // a.Containsf("Hello World", "World", "error message %s", "formatted")
  38. // a.Containsf(["Hello", "World"], "World", "error message %s", "formatted")
  39. // a.Containsf({"Hello": "World"}, "Hello", "error message %s", "formatted")
  40. func (a *Assertions) Containsf(s interface{}, contains interface{}, msg string, args ...interface{}) bool {
  41. if h, ok := a.t.(tHelper); ok {
  42. h.Helper()
  43. }
  44. return Containsf(a.t, s, contains, msg, args...)
  45. }
  46. // DirExists checks whether a directory exists in the given path. It also fails
  47. // if the path is a file rather a directory or there is an error checking whether it exists.
  48. func (a *Assertions) DirExists(path string, msgAndArgs ...interface{}) bool {
  49. if h, ok := a.t.(tHelper); ok {
  50. h.Helper()
  51. }
  52. return DirExists(a.t, path, msgAndArgs...)
  53. }
  54. // DirExistsf checks whether a directory exists in the given path. It also fails
  55. // if the path is a file rather a directory or there is an error checking whether it exists.
  56. func (a *Assertions) DirExistsf(path string, msg string, args ...interface{}) bool {
  57. if h, ok := a.t.(tHelper); ok {
  58. h.Helper()
  59. }
  60. return DirExistsf(a.t, path, msg, args...)
  61. }
  62. // ElementsMatch asserts that the specified listA(array, slice...) is equal to specified
  63. // listB(array, slice...) ignoring the order of the elements. If there are duplicate elements,
  64. // the number of appearances of each of them in both lists should match.
  65. //
  66. // a.ElementsMatch([1, 3, 2, 3], [1, 3, 3, 2])
  67. func (a *Assertions) ElementsMatch(listA interface{}, listB interface{}, msgAndArgs ...interface{}) bool {
  68. if h, ok := a.t.(tHelper); ok {
  69. h.Helper()
  70. }
  71. return ElementsMatch(a.t, listA, listB, msgAndArgs...)
  72. }
  73. // ElementsMatchf asserts that the specified listA(array, slice...) is equal to specified
  74. // listB(array, slice...) ignoring the order of the elements. If there are duplicate elements,
  75. // the number of appearances of each of them in both lists should match.
  76. //
  77. // a.ElementsMatchf([1, 3, 2, 3], [1, 3, 3, 2], "error message %s", "formatted")
  78. func (a *Assertions) ElementsMatchf(listA interface{}, listB interface{}, msg string, args ...interface{}) bool {
  79. if h, ok := a.t.(tHelper); ok {
  80. h.Helper()
  81. }
  82. return ElementsMatchf(a.t, listA, listB, msg, args...)
  83. }
  84. // Empty asserts that the specified object is empty. I.e. nil, "", false, 0 or either
  85. // a slice or a channel with len == 0.
  86. //
  87. // a.Empty(obj)
  88. func (a *Assertions) Empty(object interface{}, msgAndArgs ...interface{}) bool {
  89. if h, ok := a.t.(tHelper); ok {
  90. h.Helper()
  91. }
  92. return Empty(a.t, object, msgAndArgs...)
  93. }
  94. // Emptyf asserts that the specified object is empty. I.e. nil, "", false, 0 or either
  95. // a slice or a channel with len == 0.
  96. //
  97. // a.Emptyf(obj, "error message %s", "formatted")
  98. func (a *Assertions) Emptyf(object interface{}, msg string, args ...interface{}) bool {
  99. if h, ok := a.t.(tHelper); ok {
  100. h.Helper()
  101. }
  102. return Emptyf(a.t, object, msg, args...)
  103. }
  104. // Equal asserts that two objects are equal.
  105. //
  106. // a.Equal(123, 123)
  107. //
  108. // Pointer variable equality is determined based on the equality of the
  109. // referenced values (as opposed to the memory addresses). Function equality
  110. // cannot be determined and will always fail.
  111. func (a *Assertions) Equal(expected interface{}, actual interface{}, msgAndArgs ...interface{}) bool {
  112. if h, ok := a.t.(tHelper); ok {
  113. h.Helper()
  114. }
  115. return Equal(a.t, expected, actual, msgAndArgs...)
  116. }
  117. // EqualError asserts that a function returned an error (i.e. not `nil`)
  118. // and that it is equal to the provided error.
  119. //
  120. // actualObj, err := SomeFunction()
  121. // a.EqualError(err, expectedErrorString)
  122. func (a *Assertions) EqualError(theError error, errString string, msgAndArgs ...interface{}) bool {
  123. if h, ok := a.t.(tHelper); ok {
  124. h.Helper()
  125. }
  126. return EqualError(a.t, theError, errString, msgAndArgs...)
  127. }
  128. // EqualErrorf asserts that a function returned an error (i.e. not `nil`)
  129. // and that it is equal to the provided error.
  130. //
  131. // actualObj, err := SomeFunction()
  132. // a.EqualErrorf(err, expectedErrorString, "error message %s", "formatted")
  133. func (a *Assertions) EqualErrorf(theError error, errString string, msg string, args ...interface{}) bool {
  134. if h, ok := a.t.(tHelper); ok {
  135. h.Helper()
  136. }
  137. return EqualErrorf(a.t, theError, errString, msg, args...)
  138. }
  139. // EqualExportedValues asserts that the types of two objects are equal and their public
  140. // fields are also equal. This is useful for comparing structs that have private fields
  141. // that could potentially differ.
  142. //
  143. // type S struct {
  144. // Exported int
  145. // notExported int
  146. // }
  147. // a.EqualExportedValues(S{1, 2}, S{1, 3}) => true
  148. // a.EqualExportedValues(S{1, 2}, S{2, 3}) => false
  149. func (a *Assertions) EqualExportedValues(expected interface{}, actual interface{}, msgAndArgs ...interface{}) bool {
  150. if h, ok := a.t.(tHelper); ok {
  151. h.Helper()
  152. }
  153. return EqualExportedValues(a.t, expected, actual, msgAndArgs...)
  154. }
  155. // EqualExportedValuesf asserts that the types of two objects are equal and their public
  156. // fields are also equal. This is useful for comparing structs that have private fields
  157. // that could potentially differ.
  158. //
  159. // type S struct {
  160. // Exported int
  161. // notExported int
  162. // }
  163. // a.EqualExportedValuesf(S{1, 2}, S{1, 3}, "error message %s", "formatted") => true
  164. // a.EqualExportedValuesf(S{1, 2}, S{2, 3}, "error message %s", "formatted") => false
  165. func (a *Assertions) EqualExportedValuesf(expected interface{}, actual interface{}, msg string, args ...interface{}) bool {
  166. if h, ok := a.t.(tHelper); ok {
  167. h.Helper()
  168. }
  169. return EqualExportedValuesf(a.t, expected, actual, msg, args...)
  170. }
  171. // EqualValues asserts that two objects are equal or convertible to the larger
  172. // type and equal.
  173. //
  174. // a.EqualValues(uint32(123), int32(123))
  175. func (a *Assertions) EqualValues(expected interface{}, actual interface{}, msgAndArgs ...interface{}) bool {
  176. if h, ok := a.t.(tHelper); ok {
  177. h.Helper()
  178. }
  179. return EqualValues(a.t, expected, actual, msgAndArgs...)
  180. }
  181. // EqualValuesf asserts that two objects are equal or convertible to the larger
  182. // type and equal.
  183. //
  184. // a.EqualValuesf(uint32(123), int32(123), "error message %s", "formatted")
  185. func (a *Assertions) EqualValuesf(expected interface{}, actual interface{}, msg string, args ...interface{}) bool {
  186. if h, ok := a.t.(tHelper); ok {
  187. h.Helper()
  188. }
  189. return EqualValuesf(a.t, expected, actual, msg, args...)
  190. }
  191. // Equalf asserts that two objects are equal.
  192. //
  193. // a.Equalf(123, 123, "error message %s", "formatted")
  194. //
  195. // Pointer variable equality is determined based on the equality of the
  196. // referenced values (as opposed to the memory addresses). Function equality
  197. // cannot be determined and will always fail.
  198. func (a *Assertions) Equalf(expected interface{}, actual interface{}, msg string, args ...interface{}) bool {
  199. if h, ok := a.t.(tHelper); ok {
  200. h.Helper()
  201. }
  202. return Equalf(a.t, expected, actual, msg, args...)
  203. }
  204. // Error asserts that a function returned an error (i.e. not `nil`).
  205. //
  206. // actualObj, err := SomeFunction()
  207. // if a.Error(err) {
  208. // assert.Equal(t, expectedError, err)
  209. // }
  210. func (a *Assertions) Error(err error, msgAndArgs ...interface{}) bool {
  211. if h, ok := a.t.(tHelper); ok {
  212. h.Helper()
  213. }
  214. return Error(a.t, err, msgAndArgs...)
  215. }
  216. // ErrorAs asserts that at least one of the errors in err's chain matches target, and if so, sets target to that error value.
  217. // This is a wrapper for errors.As.
  218. func (a *Assertions) ErrorAs(err error, target interface{}, msgAndArgs ...interface{}) bool {
  219. if h, ok := a.t.(tHelper); ok {
  220. h.Helper()
  221. }
  222. return ErrorAs(a.t, err, target, msgAndArgs...)
  223. }
  224. // ErrorAsf asserts that at least one of the errors in err's chain matches target, and if so, sets target to that error value.
  225. // This is a wrapper for errors.As.
  226. func (a *Assertions) ErrorAsf(err error, target interface{}, msg string, args ...interface{}) bool {
  227. if h, ok := a.t.(tHelper); ok {
  228. h.Helper()
  229. }
  230. return ErrorAsf(a.t, err, target, msg, args...)
  231. }
  232. // ErrorContains asserts that a function returned an error (i.e. not `nil`)
  233. // and that the error contains the specified substring.
  234. //
  235. // actualObj, err := SomeFunction()
  236. // a.ErrorContains(err, expectedErrorSubString)
  237. func (a *Assertions) ErrorContains(theError error, contains string, msgAndArgs ...interface{}) bool {
  238. if h, ok := a.t.(tHelper); ok {
  239. h.Helper()
  240. }
  241. return ErrorContains(a.t, theError, contains, msgAndArgs...)
  242. }
  243. // ErrorContainsf asserts that a function returned an error (i.e. not `nil`)
  244. // and that the error contains the specified substring.
  245. //
  246. // actualObj, err := SomeFunction()
  247. // a.ErrorContainsf(err, expectedErrorSubString, "error message %s", "formatted")
  248. func (a *Assertions) ErrorContainsf(theError error, contains string, msg string, args ...interface{}) bool {
  249. if h, ok := a.t.(tHelper); ok {
  250. h.Helper()
  251. }
  252. return ErrorContainsf(a.t, theError, contains, msg, args...)
  253. }
  254. // ErrorIs asserts that at least one of the errors in err's chain matches target.
  255. // This is a wrapper for errors.Is.
  256. func (a *Assertions) ErrorIs(err error, target error, msgAndArgs ...interface{}) bool {
  257. if h, ok := a.t.(tHelper); ok {
  258. h.Helper()
  259. }
  260. return ErrorIs(a.t, err, target, msgAndArgs...)
  261. }
  262. // ErrorIsf asserts that at least one of the errors in err's chain matches target.
  263. // This is a wrapper for errors.Is.
  264. func (a *Assertions) ErrorIsf(err error, target error, msg string, args ...interface{}) bool {
  265. if h, ok := a.t.(tHelper); ok {
  266. h.Helper()
  267. }
  268. return ErrorIsf(a.t, err, target, msg, args...)
  269. }
  270. // Errorf asserts that a function returned an error (i.e. not `nil`).
  271. //
  272. // actualObj, err := SomeFunction()
  273. // if a.Errorf(err, "error message %s", "formatted") {
  274. // assert.Equal(t, expectedErrorf, err)
  275. // }
  276. func (a *Assertions) Errorf(err error, msg string, args ...interface{}) bool {
  277. if h, ok := a.t.(tHelper); ok {
  278. h.Helper()
  279. }
  280. return Errorf(a.t, err, msg, args...)
  281. }
  282. // Eventually asserts that given condition will be met in waitFor time,
  283. // periodically checking target function each tick.
  284. //
  285. // a.Eventually(func() bool { return true; }, time.Second, 10*time.Millisecond)
  286. func (a *Assertions) Eventually(condition func() bool, waitFor time.Duration, tick time.Duration, msgAndArgs ...interface{}) bool {
  287. if h, ok := a.t.(tHelper); ok {
  288. h.Helper()
  289. }
  290. return Eventually(a.t, condition, waitFor, tick, msgAndArgs...)
  291. }
  292. // EventuallyWithT asserts that given condition will be met in waitFor time,
  293. // periodically checking target function each tick. In contrast to Eventually,
  294. // it supplies a CollectT to the condition function, so that the condition
  295. // function can use the CollectT to call other assertions.
  296. // The condition is considered "met" if no errors are raised in a tick.
  297. // The supplied CollectT collects all errors from one tick (if there are any).
  298. // If the condition is not met before waitFor, the collected errors of
  299. // the last tick are copied to t.
  300. //
  301. // externalValue := false
  302. // go func() {
  303. // time.Sleep(8*time.Second)
  304. // externalValue = true
  305. // }()
  306. // a.EventuallyWithT(func(c *assert.CollectT) {
  307. // // add assertions as needed; any assertion failure will fail the current tick
  308. // assert.True(c, externalValue, "expected 'externalValue' to be true")
  309. // }, 10*time.Second, 1*time.Second, "external state has not changed to 'true'; still false")
  310. func (a *Assertions) EventuallyWithT(condition func(collect *CollectT), waitFor time.Duration, tick time.Duration, msgAndArgs ...interface{}) bool {
  311. if h, ok := a.t.(tHelper); ok {
  312. h.Helper()
  313. }
  314. return EventuallyWithT(a.t, condition, waitFor, tick, msgAndArgs...)
  315. }
  316. // EventuallyWithTf asserts that given condition will be met in waitFor time,
  317. // periodically checking target function each tick. In contrast to Eventually,
  318. // it supplies a CollectT to the condition function, so that the condition
  319. // function can use the CollectT to call other assertions.
  320. // The condition is considered "met" if no errors are raised in a tick.
  321. // The supplied CollectT collects all errors from one tick (if there are any).
  322. // If the condition is not met before waitFor, the collected errors of
  323. // the last tick are copied to t.
  324. //
  325. // externalValue := false
  326. // go func() {
  327. // time.Sleep(8*time.Second)
  328. // externalValue = true
  329. // }()
  330. // a.EventuallyWithTf(func(c *assert.CollectT, "error message %s", "formatted") {
  331. // // add assertions as needed; any assertion failure will fail the current tick
  332. // assert.True(c, externalValue, "expected 'externalValue' to be true")
  333. // }, 10*time.Second, 1*time.Second, "external state has not changed to 'true'; still false")
  334. func (a *Assertions) EventuallyWithTf(condition func(collect *CollectT), waitFor time.Duration, tick time.Duration, msg string, args ...interface{}) bool {
  335. if h, ok := a.t.(tHelper); ok {
  336. h.Helper()
  337. }
  338. return EventuallyWithTf(a.t, condition, waitFor, tick, msg, args...)
  339. }
  340. // Eventuallyf asserts that given condition will be met in waitFor time,
  341. // periodically checking target function each tick.
  342. //
  343. // a.Eventuallyf(func() bool { return true; }, time.Second, 10*time.Millisecond, "error message %s", "formatted")
  344. func (a *Assertions) Eventuallyf(condition func() bool, waitFor time.Duration, tick time.Duration, msg string, args ...interface{}) bool {
  345. if h, ok := a.t.(tHelper); ok {
  346. h.Helper()
  347. }
  348. return Eventuallyf(a.t, condition, waitFor, tick, msg, args...)
  349. }
  350. // Exactly asserts that two objects are equal in value and type.
  351. //
  352. // a.Exactly(int32(123), int64(123))
  353. func (a *Assertions) Exactly(expected interface{}, actual interface{}, msgAndArgs ...interface{}) bool {
  354. if h, ok := a.t.(tHelper); ok {
  355. h.Helper()
  356. }
  357. return Exactly(a.t, expected, actual, msgAndArgs...)
  358. }
  359. // Exactlyf asserts that two objects are equal in value and type.
  360. //
  361. // a.Exactlyf(int32(123), int64(123), "error message %s", "formatted")
  362. func (a *Assertions) Exactlyf(expected interface{}, actual interface{}, msg string, args ...interface{}) bool {
  363. if h, ok := a.t.(tHelper); ok {
  364. h.Helper()
  365. }
  366. return Exactlyf(a.t, expected, actual, msg, args...)
  367. }
  368. // Fail reports a failure through
  369. func (a *Assertions) Fail(failureMessage string, msgAndArgs ...interface{}) bool {
  370. if h, ok := a.t.(tHelper); ok {
  371. h.Helper()
  372. }
  373. return Fail(a.t, failureMessage, msgAndArgs...)
  374. }
  375. // FailNow fails test
  376. func (a *Assertions) FailNow(failureMessage string, msgAndArgs ...interface{}) bool {
  377. if h, ok := a.t.(tHelper); ok {
  378. h.Helper()
  379. }
  380. return FailNow(a.t, failureMessage, msgAndArgs...)
  381. }
  382. // FailNowf fails test
  383. func (a *Assertions) FailNowf(failureMessage string, msg string, args ...interface{}) bool {
  384. if h, ok := a.t.(tHelper); ok {
  385. h.Helper()
  386. }
  387. return FailNowf(a.t, failureMessage, msg, args...)
  388. }
  389. // Failf reports a failure through
  390. func (a *Assertions) Failf(failureMessage string, msg string, args ...interface{}) bool {
  391. if h, ok := a.t.(tHelper); ok {
  392. h.Helper()
  393. }
  394. return Failf(a.t, failureMessage, msg, args...)
  395. }
  396. // False asserts that the specified value is false.
  397. //
  398. // a.False(myBool)
  399. func (a *Assertions) False(value bool, msgAndArgs ...interface{}) bool {
  400. if h, ok := a.t.(tHelper); ok {
  401. h.Helper()
  402. }
  403. return False(a.t, value, msgAndArgs...)
  404. }
  405. // Falsef asserts that the specified value is false.
  406. //
  407. // a.Falsef(myBool, "error message %s", "formatted")
  408. func (a *Assertions) Falsef(value bool, msg string, args ...interface{}) bool {
  409. if h, ok := a.t.(tHelper); ok {
  410. h.Helper()
  411. }
  412. return Falsef(a.t, value, msg, args...)
  413. }
  414. // FileExists checks whether a file exists in the given path. It also fails if
  415. // the path points to a directory or there is an error when trying to check the file.
  416. func (a *Assertions) FileExists(path string, msgAndArgs ...interface{}) bool {
  417. if h, ok := a.t.(tHelper); ok {
  418. h.Helper()
  419. }
  420. return FileExists(a.t, path, msgAndArgs...)
  421. }
  422. // FileExistsf checks whether a file exists in the given path. It also fails if
  423. // the path points to a directory or there is an error when trying to check the file.
  424. func (a *Assertions) FileExistsf(path string, msg string, args ...interface{}) bool {
  425. if h, ok := a.t.(tHelper); ok {
  426. h.Helper()
  427. }
  428. return FileExistsf(a.t, path, msg, args...)
  429. }
  430. // Greater asserts that the first element is greater than the second
  431. //
  432. // a.Greater(2, 1)
  433. // a.Greater(float64(2), float64(1))
  434. // a.Greater("b", "a")
  435. func (a *Assertions) Greater(e1 interface{}, e2 interface{}, msgAndArgs ...interface{}) bool {
  436. if h, ok := a.t.(tHelper); ok {
  437. h.Helper()
  438. }
  439. return Greater(a.t, e1, e2, msgAndArgs...)
  440. }
  441. // GreaterOrEqual asserts that the first element is greater than or equal to the second
  442. //
  443. // a.GreaterOrEqual(2, 1)
  444. // a.GreaterOrEqual(2, 2)
  445. // a.GreaterOrEqual("b", "a")
  446. // a.GreaterOrEqual("b", "b")
  447. func (a *Assertions) GreaterOrEqual(e1 interface{}, e2 interface{}, msgAndArgs ...interface{}) bool {
  448. if h, ok := a.t.(tHelper); ok {
  449. h.Helper()
  450. }
  451. return GreaterOrEqual(a.t, e1, e2, msgAndArgs...)
  452. }
  453. // GreaterOrEqualf asserts that the first element is greater than or equal to the second
  454. //
  455. // a.GreaterOrEqualf(2, 1, "error message %s", "formatted")
  456. // a.GreaterOrEqualf(2, 2, "error message %s", "formatted")
  457. // a.GreaterOrEqualf("b", "a", "error message %s", "formatted")
  458. // a.GreaterOrEqualf("b", "b", "error message %s", "formatted")
  459. func (a *Assertions) GreaterOrEqualf(e1 interface{}, e2 interface{}, msg string, args ...interface{}) bool {
  460. if h, ok := a.t.(tHelper); ok {
  461. h.Helper()
  462. }
  463. return GreaterOrEqualf(a.t, e1, e2, msg, args...)
  464. }
  465. // Greaterf asserts that the first element is greater than the second
  466. //
  467. // a.Greaterf(2, 1, "error message %s", "formatted")
  468. // a.Greaterf(float64(2), float64(1), "error message %s", "formatted")
  469. // a.Greaterf("b", "a", "error message %s", "formatted")
  470. func (a *Assertions) Greaterf(e1 interface{}, e2 interface{}, msg string, args ...interface{}) bool {
  471. if h, ok := a.t.(tHelper); ok {
  472. h.Helper()
  473. }
  474. return Greaterf(a.t, e1, e2, msg, args...)
  475. }
  476. // HTTPBodyContains asserts that a specified handler returns a
  477. // body that contains a string.
  478. //
  479. // a.HTTPBodyContains(myHandler, "GET", "www.google.com", nil, "I'm Feeling Lucky")
  480. //
  481. // Returns whether the assertion was successful (true) or not (false).
  482. func (a *Assertions) HTTPBodyContains(handler http.HandlerFunc, method string, url string, values url.Values, str interface{}, msgAndArgs ...interface{}) bool {
  483. if h, ok := a.t.(tHelper); ok {
  484. h.Helper()
  485. }
  486. return HTTPBodyContains(a.t, handler, method, url, values, str, msgAndArgs...)
  487. }
  488. // HTTPBodyContainsf asserts that a specified handler returns a
  489. // body that contains a string.
  490. //
  491. // a.HTTPBodyContainsf(myHandler, "GET", "www.google.com", nil, "I'm Feeling Lucky", "error message %s", "formatted")
  492. //
  493. // Returns whether the assertion was successful (true) or not (false).
  494. func (a *Assertions) HTTPBodyContainsf(handler http.HandlerFunc, method string, url string, values url.Values, str interface{}, msg string, args ...interface{}) bool {
  495. if h, ok := a.t.(tHelper); ok {
  496. h.Helper()
  497. }
  498. return HTTPBodyContainsf(a.t, handler, method, url, values, str, msg, args...)
  499. }
  500. // HTTPBodyNotContains asserts that a specified handler returns a
  501. // body that does not contain a string.
  502. //
  503. // a.HTTPBodyNotContains(myHandler, "GET", "www.google.com", nil, "I'm Feeling Lucky")
  504. //
  505. // Returns whether the assertion was successful (true) or not (false).
  506. func (a *Assertions) HTTPBodyNotContains(handler http.HandlerFunc, method string, url string, values url.Values, str interface{}, msgAndArgs ...interface{}) bool {
  507. if h, ok := a.t.(tHelper); ok {
  508. h.Helper()
  509. }
  510. return HTTPBodyNotContains(a.t, handler, method, url, values, str, msgAndArgs...)
  511. }
  512. // HTTPBodyNotContainsf asserts that a specified handler returns a
  513. // body that does not contain a string.
  514. //
  515. // a.HTTPBodyNotContainsf(myHandler, "GET", "www.google.com", nil, "I'm Feeling Lucky", "error message %s", "formatted")
  516. //
  517. // Returns whether the assertion was successful (true) or not (false).
  518. func (a *Assertions) HTTPBodyNotContainsf(handler http.HandlerFunc, method string, url string, values url.Values, str interface{}, msg string, args ...interface{}) bool {
  519. if h, ok := a.t.(tHelper); ok {
  520. h.Helper()
  521. }
  522. return HTTPBodyNotContainsf(a.t, handler, method, url, values, str, msg, args...)
  523. }
  524. // HTTPError asserts that a specified handler returns an error status code.
  525. //
  526. // a.HTTPError(myHandler, "POST", "/a/b/c", url.Values{"a": []string{"b", "c"}}
  527. //
  528. // Returns whether the assertion was successful (true) or not (false).
  529. func (a *Assertions) HTTPError(handler http.HandlerFunc, method string, url string, values url.Values, msgAndArgs ...interface{}) bool {
  530. if h, ok := a.t.(tHelper); ok {
  531. h.Helper()
  532. }
  533. return HTTPError(a.t, handler, method, url, values, msgAndArgs...)
  534. }
  535. // HTTPErrorf asserts that a specified handler returns an error status code.
  536. //
  537. // a.HTTPErrorf(myHandler, "POST", "/a/b/c", url.Values{"a": []string{"b", "c"}}
  538. //
  539. // Returns whether the assertion was successful (true) or not (false).
  540. func (a *Assertions) HTTPErrorf(handler http.HandlerFunc, method string, url string, values url.Values, msg string, args ...interface{}) bool {
  541. if h, ok := a.t.(tHelper); ok {
  542. h.Helper()
  543. }
  544. return HTTPErrorf(a.t, handler, method, url, values, msg, args...)
  545. }
  546. // HTTPRedirect asserts that a specified handler returns a redirect status code.
  547. //
  548. // a.HTTPRedirect(myHandler, "GET", "/a/b/c", url.Values{"a": []string{"b", "c"}}
  549. //
  550. // Returns whether the assertion was successful (true) or not (false).
  551. func (a *Assertions) HTTPRedirect(handler http.HandlerFunc, method string, url string, values url.Values, msgAndArgs ...interface{}) bool {
  552. if h, ok := a.t.(tHelper); ok {
  553. h.Helper()
  554. }
  555. return HTTPRedirect(a.t, handler, method, url, values, msgAndArgs...)
  556. }
  557. // HTTPRedirectf asserts that a specified handler returns a redirect status code.
  558. //
  559. // a.HTTPRedirectf(myHandler, "GET", "/a/b/c", url.Values{"a": []string{"b", "c"}}
  560. //
  561. // Returns whether the assertion was successful (true) or not (false).
  562. func (a *Assertions) HTTPRedirectf(handler http.HandlerFunc, method string, url string, values url.Values, msg string, args ...interface{}) bool {
  563. if h, ok := a.t.(tHelper); ok {
  564. h.Helper()
  565. }
  566. return HTTPRedirectf(a.t, handler, method, url, values, msg, args...)
  567. }
  568. // HTTPStatusCode asserts that a specified handler returns a specified status code.
  569. //
  570. // a.HTTPStatusCode(myHandler, "GET", "/notImplemented", nil, 501)
  571. //
  572. // Returns whether the assertion was successful (true) or not (false).
  573. func (a *Assertions) HTTPStatusCode(handler http.HandlerFunc, method string, url string, values url.Values, statuscode int, msgAndArgs ...interface{}) bool {
  574. if h, ok := a.t.(tHelper); ok {
  575. h.Helper()
  576. }
  577. return HTTPStatusCode(a.t, handler, method, url, values, statuscode, msgAndArgs...)
  578. }
  579. // HTTPStatusCodef asserts that a specified handler returns a specified status code.
  580. //
  581. // a.HTTPStatusCodef(myHandler, "GET", "/notImplemented", nil, 501, "error message %s", "formatted")
  582. //
  583. // Returns whether the assertion was successful (true) or not (false).
  584. func (a *Assertions) HTTPStatusCodef(handler http.HandlerFunc, method string, url string, values url.Values, statuscode int, msg string, args ...interface{}) bool {
  585. if h, ok := a.t.(tHelper); ok {
  586. h.Helper()
  587. }
  588. return HTTPStatusCodef(a.t, handler, method, url, values, statuscode, msg, args...)
  589. }
  590. // HTTPSuccess asserts that a specified handler returns a success status code.
  591. //
  592. // a.HTTPSuccess(myHandler, "POST", "http://www.google.com", nil)
  593. //
  594. // Returns whether the assertion was successful (true) or not (false).
  595. func (a *Assertions) HTTPSuccess(handler http.HandlerFunc, method string, url string, values url.Values, msgAndArgs ...interface{}) bool {
  596. if h, ok := a.t.(tHelper); ok {
  597. h.Helper()
  598. }
  599. return HTTPSuccess(a.t, handler, method, url, values, msgAndArgs...)
  600. }
  601. // HTTPSuccessf asserts that a specified handler returns a success status code.
  602. //
  603. // a.HTTPSuccessf(myHandler, "POST", "http://www.google.com", nil, "error message %s", "formatted")
  604. //
  605. // Returns whether the assertion was successful (true) or not (false).
  606. func (a *Assertions) HTTPSuccessf(handler http.HandlerFunc, method string, url string, values url.Values, msg string, args ...interface{}) bool {
  607. if h, ok := a.t.(tHelper); ok {
  608. h.Helper()
  609. }
  610. return HTTPSuccessf(a.t, handler, method, url, values, msg, args...)
  611. }
  612. // Implements asserts that an object is implemented by the specified interface.
  613. //
  614. // a.Implements((*MyInterface)(nil), new(MyObject))
  615. func (a *Assertions) Implements(interfaceObject interface{}, object interface{}, msgAndArgs ...interface{}) bool {
  616. if h, ok := a.t.(tHelper); ok {
  617. h.Helper()
  618. }
  619. return Implements(a.t, interfaceObject, object, msgAndArgs...)
  620. }
  621. // Implementsf asserts that an object is implemented by the specified interface.
  622. //
  623. // a.Implementsf((*MyInterface)(nil), new(MyObject), "error message %s", "formatted")
  624. func (a *Assertions) Implementsf(interfaceObject interface{}, object interface{}, msg string, args ...interface{}) bool {
  625. if h, ok := a.t.(tHelper); ok {
  626. h.Helper()
  627. }
  628. return Implementsf(a.t, interfaceObject, object, msg, args...)
  629. }
  630. // InDelta asserts that the two numerals are within delta of each other.
  631. //
  632. // a.InDelta(math.Pi, 22/7.0, 0.01)
  633. func (a *Assertions) InDelta(expected interface{}, actual interface{}, delta float64, msgAndArgs ...interface{}) bool {
  634. if h, ok := a.t.(tHelper); ok {
  635. h.Helper()
  636. }
  637. return InDelta(a.t, expected, actual, delta, msgAndArgs...)
  638. }
  639. // InDeltaMapValues is the same as InDelta, but it compares all values between two maps. Both maps must have exactly the same keys.
  640. func (a *Assertions) InDeltaMapValues(expected interface{}, actual interface{}, delta float64, msgAndArgs ...interface{}) bool {
  641. if h, ok := a.t.(tHelper); ok {
  642. h.Helper()
  643. }
  644. return InDeltaMapValues(a.t, expected, actual, delta, msgAndArgs...)
  645. }
  646. // InDeltaMapValuesf is the same as InDelta, but it compares all values between two maps. Both maps must have exactly the same keys.
  647. func (a *Assertions) InDeltaMapValuesf(expected interface{}, actual interface{}, delta float64, msg string, args ...interface{}) bool {
  648. if h, ok := a.t.(tHelper); ok {
  649. h.Helper()
  650. }
  651. return InDeltaMapValuesf(a.t, expected, actual, delta, msg, args...)
  652. }
  653. // InDeltaSlice is the same as InDelta, except it compares two slices.
  654. func (a *Assertions) InDeltaSlice(expected interface{}, actual interface{}, delta float64, msgAndArgs ...interface{}) bool {
  655. if h, ok := a.t.(tHelper); ok {
  656. h.Helper()
  657. }
  658. return InDeltaSlice(a.t, expected, actual, delta, msgAndArgs...)
  659. }
  660. // InDeltaSlicef is the same as InDelta, except it compares two slices.
  661. func (a *Assertions) InDeltaSlicef(expected interface{}, actual interface{}, delta float64, msg string, args ...interface{}) bool {
  662. if h, ok := a.t.(tHelper); ok {
  663. h.Helper()
  664. }
  665. return InDeltaSlicef(a.t, expected, actual, delta, msg, args...)
  666. }
  667. // InDeltaf asserts that the two numerals are within delta of each other.
  668. //
  669. // a.InDeltaf(math.Pi, 22/7.0, 0.01, "error message %s", "formatted")
  670. func (a *Assertions) InDeltaf(expected interface{}, actual interface{}, delta float64, msg string, args ...interface{}) bool {
  671. if h, ok := a.t.(tHelper); ok {
  672. h.Helper()
  673. }
  674. return InDeltaf(a.t, expected, actual, delta, msg, args...)
  675. }
  676. // InEpsilon asserts that expected and actual have a relative error less than epsilon
  677. func (a *Assertions) InEpsilon(expected interface{}, actual interface{}, epsilon float64, msgAndArgs ...interface{}) bool {
  678. if h, ok := a.t.(tHelper); ok {
  679. h.Helper()
  680. }
  681. return InEpsilon(a.t, expected, actual, epsilon, msgAndArgs...)
  682. }
  683. // InEpsilonSlice is the same as InEpsilon, except it compares each value from two slices.
  684. func (a *Assertions) InEpsilonSlice(expected interface{}, actual interface{}, epsilon float64, msgAndArgs ...interface{}) bool {
  685. if h, ok := a.t.(tHelper); ok {
  686. h.Helper()
  687. }
  688. return InEpsilonSlice(a.t, expected, actual, epsilon, msgAndArgs...)
  689. }
  690. // InEpsilonSlicef is the same as InEpsilon, except it compares each value from two slices.
  691. func (a *Assertions) InEpsilonSlicef(expected interface{}, actual interface{}, epsilon float64, msg string, args ...interface{}) bool {
  692. if h, ok := a.t.(tHelper); ok {
  693. h.Helper()
  694. }
  695. return InEpsilonSlicef(a.t, expected, actual, epsilon, msg, args...)
  696. }
  697. // InEpsilonf asserts that expected and actual have a relative error less than epsilon
  698. func (a *Assertions) InEpsilonf(expected interface{}, actual interface{}, epsilon float64, msg string, args ...interface{}) bool {
  699. if h, ok := a.t.(tHelper); ok {
  700. h.Helper()
  701. }
  702. return InEpsilonf(a.t, expected, actual, epsilon, msg, args...)
  703. }
  704. // IsDecreasing asserts that the collection is decreasing
  705. //
  706. // a.IsDecreasing([]int{2, 1, 0})
  707. // a.IsDecreasing([]float{2, 1})
  708. // a.IsDecreasing([]string{"b", "a"})
  709. func (a *Assertions) IsDecreasing(object interface{}, msgAndArgs ...interface{}) bool {
  710. if h, ok := a.t.(tHelper); ok {
  711. h.Helper()
  712. }
  713. return IsDecreasing(a.t, object, msgAndArgs...)
  714. }
  715. // IsDecreasingf asserts that the collection is decreasing
  716. //
  717. // a.IsDecreasingf([]int{2, 1, 0}, "error message %s", "formatted")
  718. // a.IsDecreasingf([]float{2, 1}, "error message %s", "formatted")
  719. // a.IsDecreasingf([]string{"b", "a"}, "error message %s", "formatted")
  720. func (a *Assertions) IsDecreasingf(object interface{}, msg string, args ...interface{}) bool {
  721. if h, ok := a.t.(tHelper); ok {
  722. h.Helper()
  723. }
  724. return IsDecreasingf(a.t, object, msg, args...)
  725. }
  726. // IsIncreasing asserts that the collection is increasing
  727. //
  728. // a.IsIncreasing([]int{1, 2, 3})
  729. // a.IsIncreasing([]float{1, 2})
  730. // a.IsIncreasing([]string{"a", "b"})
  731. func (a *Assertions) IsIncreasing(object interface{}, msgAndArgs ...interface{}) bool {
  732. if h, ok := a.t.(tHelper); ok {
  733. h.Helper()
  734. }
  735. return IsIncreasing(a.t, object, msgAndArgs...)
  736. }
  737. // IsIncreasingf asserts that the collection is increasing
  738. //
  739. // a.IsIncreasingf([]int{1, 2, 3}, "error message %s", "formatted")
  740. // a.IsIncreasingf([]float{1, 2}, "error message %s", "formatted")
  741. // a.IsIncreasingf([]string{"a", "b"}, "error message %s", "formatted")
  742. func (a *Assertions) IsIncreasingf(object interface{}, msg string, args ...interface{}) bool {
  743. if h, ok := a.t.(tHelper); ok {
  744. h.Helper()
  745. }
  746. return IsIncreasingf(a.t, object, msg, args...)
  747. }
  748. // IsNonDecreasing asserts that the collection is not decreasing
  749. //
  750. // a.IsNonDecreasing([]int{1, 1, 2})
  751. // a.IsNonDecreasing([]float{1, 2})
  752. // a.IsNonDecreasing([]string{"a", "b"})
  753. func (a *Assertions) IsNonDecreasing(object interface{}, msgAndArgs ...interface{}) bool {
  754. if h, ok := a.t.(tHelper); ok {
  755. h.Helper()
  756. }
  757. return IsNonDecreasing(a.t, object, msgAndArgs...)
  758. }
  759. // IsNonDecreasingf asserts that the collection is not decreasing
  760. //
  761. // a.IsNonDecreasingf([]int{1, 1, 2}, "error message %s", "formatted")
  762. // a.IsNonDecreasingf([]float{1, 2}, "error message %s", "formatted")
  763. // a.IsNonDecreasingf([]string{"a", "b"}, "error message %s", "formatted")
  764. func (a *Assertions) IsNonDecreasingf(object interface{}, msg string, args ...interface{}) bool {
  765. if h, ok := a.t.(tHelper); ok {
  766. h.Helper()
  767. }
  768. return IsNonDecreasingf(a.t, object, msg, args...)
  769. }
  770. // IsNonIncreasing asserts that the collection is not increasing
  771. //
  772. // a.IsNonIncreasing([]int{2, 1, 1})
  773. // a.IsNonIncreasing([]float{2, 1})
  774. // a.IsNonIncreasing([]string{"b", "a"})
  775. func (a *Assertions) IsNonIncreasing(object interface{}, msgAndArgs ...interface{}) bool {
  776. if h, ok := a.t.(tHelper); ok {
  777. h.Helper()
  778. }
  779. return IsNonIncreasing(a.t, object, msgAndArgs...)
  780. }
  781. // IsNonIncreasingf asserts that the collection is not increasing
  782. //
  783. // a.IsNonIncreasingf([]int{2, 1, 1}, "error message %s", "formatted")
  784. // a.IsNonIncreasingf([]float{2, 1}, "error message %s", "formatted")
  785. // a.IsNonIncreasingf([]string{"b", "a"}, "error message %s", "formatted")
  786. func (a *Assertions) IsNonIncreasingf(object interface{}, msg string, args ...interface{}) bool {
  787. if h, ok := a.t.(tHelper); ok {
  788. h.Helper()
  789. }
  790. return IsNonIncreasingf(a.t, object, msg, args...)
  791. }
  792. // IsType asserts that the specified objects are of the same type.
  793. func (a *Assertions) IsType(expectedType interface{}, object interface{}, msgAndArgs ...interface{}) bool {
  794. if h, ok := a.t.(tHelper); ok {
  795. h.Helper()
  796. }
  797. return IsType(a.t, expectedType, object, msgAndArgs...)
  798. }
  799. // IsTypef asserts that the specified objects are of the same type.
  800. func (a *Assertions) IsTypef(expectedType interface{}, object interface{}, msg string, args ...interface{}) bool {
  801. if h, ok := a.t.(tHelper); ok {
  802. h.Helper()
  803. }
  804. return IsTypef(a.t, expectedType, object, msg, args...)
  805. }
  806. // JSONEq asserts that two JSON strings are equivalent.
  807. //
  808. // a.JSONEq(`{"hello": "world", "foo": "bar"}`, `{"foo": "bar", "hello": "world"}`)
  809. func (a *Assertions) JSONEq(expected string, actual string, msgAndArgs ...interface{}) bool {
  810. if h, ok := a.t.(tHelper); ok {
  811. h.Helper()
  812. }
  813. return JSONEq(a.t, expected, actual, msgAndArgs...)
  814. }
  815. // JSONEqf asserts that two JSON strings are equivalent.
  816. //
  817. // a.JSONEqf(`{"hello": "world", "foo": "bar"}`, `{"foo": "bar", "hello": "world"}`, "error message %s", "formatted")
  818. func (a *Assertions) JSONEqf(expected string, actual string, msg string, args ...interface{}) bool {
  819. if h, ok := a.t.(tHelper); ok {
  820. h.Helper()
  821. }
  822. return JSONEqf(a.t, expected, actual, msg, args...)
  823. }
  824. // Len asserts that the specified object has specific length.
  825. // Len also fails if the object has a type that len() not accept.
  826. //
  827. // a.Len(mySlice, 3)
  828. func (a *Assertions) Len(object interface{}, length int, msgAndArgs ...interface{}) bool {
  829. if h, ok := a.t.(tHelper); ok {
  830. h.Helper()
  831. }
  832. return Len(a.t, object, length, msgAndArgs...)
  833. }
  834. // Lenf asserts that the specified object has specific length.
  835. // Lenf also fails if the object has a type that len() not accept.
  836. //
  837. // a.Lenf(mySlice, 3, "error message %s", "formatted")
  838. func (a *Assertions) Lenf(object interface{}, length int, msg string, args ...interface{}) bool {
  839. if h, ok := a.t.(tHelper); ok {
  840. h.Helper()
  841. }
  842. return Lenf(a.t, object, length, msg, args...)
  843. }
  844. // Less asserts that the first element is less than the second
  845. //
  846. // a.Less(1, 2)
  847. // a.Less(float64(1), float64(2))
  848. // a.Less("a", "b")
  849. func (a *Assertions) Less(e1 interface{}, e2 interface{}, msgAndArgs ...interface{}) bool {
  850. if h, ok := a.t.(tHelper); ok {
  851. h.Helper()
  852. }
  853. return Less(a.t, e1, e2, msgAndArgs...)
  854. }
  855. // LessOrEqual asserts that the first element is less than or equal to the second
  856. //
  857. // a.LessOrEqual(1, 2)
  858. // a.LessOrEqual(2, 2)
  859. // a.LessOrEqual("a", "b")
  860. // a.LessOrEqual("b", "b")
  861. func (a *Assertions) LessOrEqual(e1 interface{}, e2 interface{}, msgAndArgs ...interface{}) bool {
  862. if h, ok := a.t.(tHelper); ok {
  863. h.Helper()
  864. }
  865. return LessOrEqual(a.t, e1, e2, msgAndArgs...)
  866. }
  867. // LessOrEqualf asserts that the first element is less than or equal to the second
  868. //
  869. // a.LessOrEqualf(1, 2, "error message %s", "formatted")
  870. // a.LessOrEqualf(2, 2, "error message %s", "formatted")
  871. // a.LessOrEqualf("a", "b", "error message %s", "formatted")
  872. // a.LessOrEqualf("b", "b", "error message %s", "formatted")
  873. func (a *Assertions) LessOrEqualf(e1 interface{}, e2 interface{}, msg string, args ...interface{}) bool {
  874. if h, ok := a.t.(tHelper); ok {
  875. h.Helper()
  876. }
  877. return LessOrEqualf(a.t, e1, e2, msg, args...)
  878. }
  879. // Lessf asserts that the first element is less than the second
  880. //
  881. // a.Lessf(1, 2, "error message %s", "formatted")
  882. // a.Lessf(float64(1), float64(2), "error message %s", "formatted")
  883. // a.Lessf("a", "b", "error message %s", "formatted")
  884. func (a *Assertions) Lessf(e1 interface{}, e2 interface{}, msg string, args ...interface{}) bool {
  885. if h, ok := a.t.(tHelper); ok {
  886. h.Helper()
  887. }
  888. return Lessf(a.t, e1, e2, msg, args...)
  889. }
  890. // Negative asserts that the specified element is negative
  891. //
  892. // a.Negative(-1)
  893. // a.Negative(-1.23)
  894. func (a *Assertions) Negative(e interface{}, msgAndArgs ...interface{}) bool {
  895. if h, ok := a.t.(tHelper); ok {
  896. h.Helper()
  897. }
  898. return Negative(a.t, e, msgAndArgs...)
  899. }
  900. // Negativef asserts that the specified element is negative
  901. //
  902. // a.Negativef(-1, "error message %s", "formatted")
  903. // a.Negativef(-1.23, "error message %s", "formatted")
  904. func (a *Assertions) Negativef(e interface{}, msg string, args ...interface{}) bool {
  905. if h, ok := a.t.(tHelper); ok {
  906. h.Helper()
  907. }
  908. return Negativef(a.t, e, msg, args...)
  909. }
  910. // Never asserts that the given condition doesn't satisfy in waitFor time,
  911. // periodically checking the target function each tick.
  912. //
  913. // a.Never(func() bool { return false; }, time.Second, 10*time.Millisecond)
  914. func (a *Assertions) Never(condition func() bool, waitFor time.Duration, tick time.Duration, msgAndArgs ...interface{}) bool {
  915. if h, ok := a.t.(tHelper); ok {
  916. h.Helper()
  917. }
  918. return Never(a.t, condition, waitFor, tick, msgAndArgs...)
  919. }
  920. // Neverf asserts that the given condition doesn't satisfy in waitFor time,
  921. // periodically checking the target function each tick.
  922. //
  923. // a.Neverf(func() bool { return false; }, time.Second, 10*time.Millisecond, "error message %s", "formatted")
  924. func (a *Assertions) Neverf(condition func() bool, waitFor time.Duration, tick time.Duration, msg string, args ...interface{}) bool {
  925. if h, ok := a.t.(tHelper); ok {
  926. h.Helper()
  927. }
  928. return Neverf(a.t, condition, waitFor, tick, msg, args...)
  929. }
  930. // Nil asserts that the specified object is nil.
  931. //
  932. // a.Nil(err)
  933. func (a *Assertions) Nil(object interface{}, msgAndArgs ...interface{}) bool {
  934. if h, ok := a.t.(tHelper); ok {
  935. h.Helper()
  936. }
  937. return Nil(a.t, object, msgAndArgs...)
  938. }
  939. // Nilf asserts that the specified object is nil.
  940. //
  941. // a.Nilf(err, "error message %s", "formatted")
  942. func (a *Assertions) Nilf(object interface{}, msg string, args ...interface{}) bool {
  943. if h, ok := a.t.(tHelper); ok {
  944. h.Helper()
  945. }
  946. return Nilf(a.t, object, msg, args...)
  947. }
  948. // NoDirExists checks whether a directory does not exist in the given path.
  949. // It fails if the path points to an existing _directory_ only.
  950. func (a *Assertions) NoDirExists(path string, msgAndArgs ...interface{}) bool {
  951. if h, ok := a.t.(tHelper); ok {
  952. h.Helper()
  953. }
  954. return NoDirExists(a.t, path, msgAndArgs...)
  955. }
  956. // NoDirExistsf checks whether a directory does not exist in the given path.
  957. // It fails if the path points to an existing _directory_ only.
  958. func (a *Assertions) NoDirExistsf(path string, msg string, args ...interface{}) bool {
  959. if h, ok := a.t.(tHelper); ok {
  960. h.Helper()
  961. }
  962. return NoDirExistsf(a.t, path, msg, args...)
  963. }
  964. // NoError asserts that a function returned no error (i.e. `nil`).
  965. //
  966. // actualObj, err := SomeFunction()
  967. // if a.NoError(err) {
  968. // assert.Equal(t, expectedObj, actualObj)
  969. // }
  970. func (a *Assertions) NoError(err error, msgAndArgs ...interface{}) bool {
  971. if h, ok := a.t.(tHelper); ok {
  972. h.Helper()
  973. }
  974. return NoError(a.t, err, msgAndArgs...)
  975. }
  976. // NoErrorf asserts that a function returned no error (i.e. `nil`).
  977. //
  978. // actualObj, err := SomeFunction()
  979. // if a.NoErrorf(err, "error message %s", "formatted") {
  980. // assert.Equal(t, expectedObj, actualObj)
  981. // }
  982. func (a *Assertions) NoErrorf(err error, msg string, args ...interface{}) bool {
  983. if h, ok := a.t.(tHelper); ok {
  984. h.Helper()
  985. }
  986. return NoErrorf(a.t, err, msg, args...)
  987. }
  988. // NoFileExists checks whether a file does not exist in a given path. It fails
  989. // if the path points to an existing _file_ only.
  990. func (a *Assertions) NoFileExists(path string, msgAndArgs ...interface{}) bool {
  991. if h, ok := a.t.(tHelper); ok {
  992. h.Helper()
  993. }
  994. return NoFileExists(a.t, path, msgAndArgs...)
  995. }
  996. // NoFileExistsf checks whether a file does not exist in a given path. It fails
  997. // if the path points to an existing _file_ only.
  998. func (a *Assertions) NoFileExistsf(path string, msg string, args ...interface{}) bool {
  999. if h, ok := a.t.(tHelper); ok {
  1000. h.Helper()
  1001. }
  1002. return NoFileExistsf(a.t, path, msg, args...)
  1003. }
  1004. // NotContains asserts that the specified string, list(array, slice...) or map does NOT contain the
  1005. // specified substring or element.
  1006. //
  1007. // a.NotContains("Hello World", "Earth")
  1008. // a.NotContains(["Hello", "World"], "Earth")
  1009. // a.NotContains({"Hello": "World"}, "Earth")
  1010. func (a *Assertions) NotContains(s interface{}, contains interface{}, msgAndArgs ...interface{}) bool {
  1011. if h, ok := a.t.(tHelper); ok {
  1012. h.Helper()
  1013. }
  1014. return NotContains(a.t, s, contains, msgAndArgs...)
  1015. }
  1016. // NotContainsf asserts that the specified string, list(array, slice...) or map does NOT contain the
  1017. // specified substring or element.
  1018. //
  1019. // a.NotContainsf("Hello World", "Earth", "error message %s", "formatted")
  1020. // a.NotContainsf(["Hello", "World"], "Earth", "error message %s", "formatted")
  1021. // a.NotContainsf({"Hello": "World"}, "Earth", "error message %s", "formatted")
  1022. func (a *Assertions) NotContainsf(s interface{}, contains interface{}, msg string, args ...interface{}) bool {
  1023. if h, ok := a.t.(tHelper); ok {
  1024. h.Helper()
  1025. }
  1026. return NotContainsf(a.t, s, contains, msg, args...)
  1027. }
  1028. // NotElementsMatch asserts that the specified listA(array, slice...) is NOT equal to specified
  1029. // listB(array, slice...) ignoring the order of the elements. If there are duplicate elements,
  1030. // the number of appearances of each of them in both lists should not match.
  1031. // This is an inverse of ElementsMatch.
  1032. //
  1033. // a.NotElementsMatch([1, 1, 2, 3], [1, 1, 2, 3]) -> false
  1034. //
  1035. // a.NotElementsMatch([1, 1, 2, 3], [1, 2, 3]) -> true
  1036. //
  1037. // a.NotElementsMatch([1, 2, 3], [1, 2, 4]) -> true
  1038. func (a *Assertions) NotElementsMatch(listA interface{}, listB interface{}, msgAndArgs ...interface{}) bool {
  1039. if h, ok := a.t.(tHelper); ok {
  1040. h.Helper()
  1041. }
  1042. return NotElementsMatch(a.t, listA, listB, msgAndArgs...)
  1043. }
  1044. // NotElementsMatchf asserts that the specified listA(array, slice...) is NOT equal to specified
  1045. // listB(array, slice...) ignoring the order of the elements. If there are duplicate elements,
  1046. // the number of appearances of each of them in both lists should not match.
  1047. // This is an inverse of ElementsMatch.
  1048. //
  1049. // a.NotElementsMatchf([1, 1, 2, 3], [1, 1, 2, 3], "error message %s", "formatted") -> false
  1050. //
  1051. // a.NotElementsMatchf([1, 1, 2, 3], [1, 2, 3], "error message %s", "formatted") -> true
  1052. //
  1053. // a.NotElementsMatchf([1, 2, 3], [1, 2, 4], "error message %s", "formatted") -> true
  1054. func (a *Assertions) NotElementsMatchf(listA interface{}, listB interface{}, msg string, args ...interface{}) bool {
  1055. if h, ok := a.t.(tHelper); ok {
  1056. h.Helper()
  1057. }
  1058. return NotElementsMatchf(a.t, listA, listB, msg, args...)
  1059. }
  1060. // NotEmpty asserts that the specified object is NOT empty. I.e. not nil, "", false, 0 or either
  1061. // a slice or a channel with len == 0.
  1062. //
  1063. // if a.NotEmpty(obj) {
  1064. // assert.Equal(t, "two", obj[1])
  1065. // }
  1066. func (a *Assertions) NotEmpty(object interface{}, msgAndArgs ...interface{}) bool {
  1067. if h, ok := a.t.(tHelper); ok {
  1068. h.Helper()
  1069. }
  1070. return NotEmpty(a.t, object, msgAndArgs...)
  1071. }
  1072. // NotEmptyf asserts that the specified object is NOT empty. I.e. not nil, "", false, 0 or either
  1073. // a slice or a channel with len == 0.
  1074. //
  1075. // if a.NotEmptyf(obj, "error message %s", "formatted") {
  1076. // assert.Equal(t, "two", obj[1])
  1077. // }
  1078. func (a *Assertions) NotEmptyf(object interface{}, msg string, args ...interface{}) bool {
  1079. if h, ok := a.t.(tHelper); ok {
  1080. h.Helper()
  1081. }
  1082. return NotEmptyf(a.t, object, msg, args...)
  1083. }
  1084. // NotEqual asserts that the specified values are NOT equal.
  1085. //
  1086. // a.NotEqual(obj1, obj2)
  1087. //
  1088. // Pointer variable equality is determined based on the equality of the
  1089. // referenced values (as opposed to the memory addresses).
  1090. func (a *Assertions) NotEqual(expected interface{}, actual interface{}, msgAndArgs ...interface{}) bool {
  1091. if h, ok := a.t.(tHelper); ok {
  1092. h.Helper()
  1093. }
  1094. return NotEqual(a.t, expected, actual, msgAndArgs...)
  1095. }
  1096. // NotEqualValues asserts that two objects are not equal even when converted to the same type
  1097. //
  1098. // a.NotEqualValues(obj1, obj2)
  1099. func (a *Assertions) NotEqualValues(expected interface{}, actual interface{}, msgAndArgs ...interface{}) bool {
  1100. if h, ok := a.t.(tHelper); ok {
  1101. h.Helper()
  1102. }
  1103. return NotEqualValues(a.t, expected, actual, msgAndArgs...)
  1104. }
  1105. // NotEqualValuesf asserts that two objects are not equal even when converted to the same type
  1106. //
  1107. // a.NotEqualValuesf(obj1, obj2, "error message %s", "formatted")
  1108. func (a *Assertions) NotEqualValuesf(expected interface{}, actual interface{}, msg string, args ...interface{}) bool {
  1109. if h, ok := a.t.(tHelper); ok {
  1110. h.Helper()
  1111. }
  1112. return NotEqualValuesf(a.t, expected, actual, msg, args...)
  1113. }
  1114. // NotEqualf asserts that the specified values are NOT equal.
  1115. //
  1116. // a.NotEqualf(obj1, obj2, "error message %s", "formatted")
  1117. //
  1118. // Pointer variable equality is determined based on the equality of the
  1119. // referenced values (as opposed to the memory addresses).
  1120. func (a *Assertions) NotEqualf(expected interface{}, actual interface{}, msg string, args ...interface{}) bool {
  1121. if h, ok := a.t.(tHelper); ok {
  1122. h.Helper()
  1123. }
  1124. return NotEqualf(a.t, expected, actual, msg, args...)
  1125. }
  1126. // NotErrorAs asserts that none of the errors in err's chain matches target,
  1127. // but if so, sets target to that error value.
  1128. func (a *Assertions) NotErrorAs(err error, target interface{}, msgAndArgs ...interface{}) bool {
  1129. if h, ok := a.t.(tHelper); ok {
  1130. h.Helper()
  1131. }
  1132. return NotErrorAs(a.t, err, target, msgAndArgs...)
  1133. }
  1134. // NotErrorAsf asserts that none of the errors in err's chain matches target,
  1135. // but if so, sets target to that error value.
  1136. func (a *Assertions) NotErrorAsf(err error, target interface{}, msg string, args ...interface{}) bool {
  1137. if h, ok := a.t.(tHelper); ok {
  1138. h.Helper()
  1139. }
  1140. return NotErrorAsf(a.t, err, target, msg, args...)
  1141. }
  1142. // NotErrorIs asserts that none of the errors in err's chain matches target.
  1143. // This is a wrapper for errors.Is.
  1144. func (a *Assertions) NotErrorIs(err error, target error, msgAndArgs ...interface{}) bool {
  1145. if h, ok := a.t.(tHelper); ok {
  1146. h.Helper()
  1147. }
  1148. return NotErrorIs(a.t, err, target, msgAndArgs...)
  1149. }
  1150. // NotErrorIsf asserts that none of the errors in err's chain matches target.
  1151. // This is a wrapper for errors.Is.
  1152. func (a *Assertions) NotErrorIsf(err error, target error, msg string, args ...interface{}) bool {
  1153. if h, ok := a.t.(tHelper); ok {
  1154. h.Helper()
  1155. }
  1156. return NotErrorIsf(a.t, err, target, msg, args...)
  1157. }
  1158. // NotImplements asserts that an object does not implement the specified interface.
  1159. //
  1160. // a.NotImplements((*MyInterface)(nil), new(MyObject))
  1161. func (a *Assertions) NotImplements(interfaceObject interface{}, object interface{}, msgAndArgs ...interface{}) bool {
  1162. if h, ok := a.t.(tHelper); ok {
  1163. h.Helper()
  1164. }
  1165. return NotImplements(a.t, interfaceObject, object, msgAndArgs...)
  1166. }
  1167. // NotImplementsf asserts that an object does not implement the specified interface.
  1168. //
  1169. // a.NotImplementsf((*MyInterface)(nil), new(MyObject), "error message %s", "formatted")
  1170. func (a *Assertions) NotImplementsf(interfaceObject interface{}, object interface{}, msg string, args ...interface{}) bool {
  1171. if h, ok := a.t.(tHelper); ok {
  1172. h.Helper()
  1173. }
  1174. return NotImplementsf(a.t, interfaceObject, object, msg, args...)
  1175. }
  1176. // NotNil asserts that the specified object is not nil.
  1177. //
  1178. // a.NotNil(err)
  1179. func (a *Assertions) NotNil(object interface{}, msgAndArgs ...interface{}) bool {
  1180. if h, ok := a.t.(tHelper); ok {
  1181. h.Helper()
  1182. }
  1183. return NotNil(a.t, object, msgAndArgs...)
  1184. }
  1185. // NotNilf asserts that the specified object is not nil.
  1186. //
  1187. // a.NotNilf(err, "error message %s", "formatted")
  1188. func (a *Assertions) NotNilf(object interface{}, msg string, args ...interface{}) bool {
  1189. if h, ok := a.t.(tHelper); ok {
  1190. h.Helper()
  1191. }
  1192. return NotNilf(a.t, object, msg, args...)
  1193. }
  1194. // NotPanics asserts that the code inside the specified PanicTestFunc does NOT panic.
  1195. //
  1196. // a.NotPanics(func(){ RemainCalm() })
  1197. func (a *Assertions) NotPanics(f PanicTestFunc, msgAndArgs ...interface{}) bool {
  1198. if h, ok := a.t.(tHelper); ok {
  1199. h.Helper()
  1200. }
  1201. return NotPanics(a.t, f, msgAndArgs...)
  1202. }
  1203. // NotPanicsf asserts that the code inside the specified PanicTestFunc does NOT panic.
  1204. //
  1205. // a.NotPanicsf(func(){ RemainCalm() }, "error message %s", "formatted")
  1206. func (a *Assertions) NotPanicsf(f PanicTestFunc, msg string, args ...interface{}) bool {
  1207. if h, ok := a.t.(tHelper); ok {
  1208. h.Helper()
  1209. }
  1210. return NotPanicsf(a.t, f, msg, args...)
  1211. }
  1212. // NotRegexp asserts that a specified regexp does not match a string.
  1213. //
  1214. // a.NotRegexp(regexp.MustCompile("starts"), "it's starting")
  1215. // a.NotRegexp("^start", "it's not starting")
  1216. func (a *Assertions) NotRegexp(rx interface{}, str interface{}, msgAndArgs ...interface{}) bool {
  1217. if h, ok := a.t.(tHelper); ok {
  1218. h.Helper()
  1219. }
  1220. return NotRegexp(a.t, rx, str, msgAndArgs...)
  1221. }
  1222. // NotRegexpf asserts that a specified regexp does not match a string.
  1223. //
  1224. // a.NotRegexpf(regexp.MustCompile("starts"), "it's starting", "error message %s", "formatted")
  1225. // a.NotRegexpf("^start", "it's not starting", "error message %s", "formatted")
  1226. func (a *Assertions) NotRegexpf(rx interface{}, str interface{}, msg string, args ...interface{}) bool {
  1227. if h, ok := a.t.(tHelper); ok {
  1228. h.Helper()
  1229. }
  1230. return NotRegexpf(a.t, rx, str, msg, args...)
  1231. }
  1232. // NotSame asserts that two pointers do not reference the same object.
  1233. //
  1234. // a.NotSame(ptr1, ptr2)
  1235. //
  1236. // Both arguments must be pointer variables. Pointer variable sameness is
  1237. // determined based on the equality of both type and value.
  1238. func (a *Assertions) NotSame(expected interface{}, actual interface{}, msgAndArgs ...interface{}) bool {
  1239. if h, ok := a.t.(tHelper); ok {
  1240. h.Helper()
  1241. }
  1242. return NotSame(a.t, expected, actual, msgAndArgs...)
  1243. }
  1244. // NotSamef asserts that two pointers do not reference the same object.
  1245. //
  1246. // a.NotSamef(ptr1, ptr2, "error message %s", "formatted")
  1247. //
  1248. // Both arguments must be pointer variables. Pointer variable sameness is
  1249. // determined based on the equality of both type and value.
  1250. func (a *Assertions) NotSamef(expected interface{}, actual interface{}, msg string, args ...interface{}) bool {
  1251. if h, ok := a.t.(tHelper); ok {
  1252. h.Helper()
  1253. }
  1254. return NotSamef(a.t, expected, actual, msg, args...)
  1255. }
  1256. // NotSubset asserts that the specified list(array, slice...) or map does NOT
  1257. // contain all elements given in the specified subset list(array, slice...) or
  1258. // map.
  1259. //
  1260. // a.NotSubset([1, 3, 4], [1, 2])
  1261. // a.NotSubset({"x": 1, "y": 2}, {"z": 3})
  1262. func (a *Assertions) NotSubset(list interface{}, subset interface{}, msgAndArgs ...interface{}) bool {
  1263. if h, ok := a.t.(tHelper); ok {
  1264. h.Helper()
  1265. }
  1266. return NotSubset(a.t, list, subset, msgAndArgs...)
  1267. }
  1268. // NotSubsetf asserts that the specified list(array, slice...) or map does NOT
  1269. // contain all elements given in the specified subset list(array, slice...) or
  1270. // map.
  1271. //
  1272. // a.NotSubsetf([1, 3, 4], [1, 2], "error message %s", "formatted")
  1273. // a.NotSubsetf({"x": 1, "y": 2}, {"z": 3}, "error message %s", "formatted")
  1274. func (a *Assertions) NotSubsetf(list interface{}, subset interface{}, msg string, args ...interface{}) bool {
  1275. if h, ok := a.t.(tHelper); ok {
  1276. h.Helper()
  1277. }
  1278. return NotSubsetf(a.t, list, subset, msg, args...)
  1279. }
  1280. // NotZero asserts that i is not the zero value for its type.
  1281. func (a *Assertions) NotZero(i interface{}, msgAndArgs ...interface{}) bool {
  1282. if h, ok := a.t.(tHelper); ok {
  1283. h.Helper()
  1284. }
  1285. return NotZero(a.t, i, msgAndArgs...)
  1286. }
  1287. // NotZerof asserts that i is not the zero value for its type.
  1288. func (a *Assertions) NotZerof(i interface{}, msg string, args ...interface{}) bool {
  1289. if h, ok := a.t.(tHelper); ok {
  1290. h.Helper()
  1291. }
  1292. return NotZerof(a.t, i, msg, args...)
  1293. }
  1294. // Panics asserts that the code inside the specified PanicTestFunc panics.
  1295. //
  1296. // a.Panics(func(){ GoCrazy() })
  1297. func (a *Assertions) Panics(f PanicTestFunc, msgAndArgs ...interface{}) bool {
  1298. if h, ok := a.t.(tHelper); ok {
  1299. h.Helper()
  1300. }
  1301. return Panics(a.t, f, msgAndArgs...)
  1302. }
  1303. // PanicsWithError asserts that the code inside the specified PanicTestFunc
  1304. // panics, and that the recovered panic value is an error that satisfies the
  1305. // EqualError comparison.
  1306. //
  1307. // a.PanicsWithError("crazy error", func(){ GoCrazy() })
  1308. func (a *Assertions) PanicsWithError(errString string, f PanicTestFunc, msgAndArgs ...interface{}) bool {
  1309. if h, ok := a.t.(tHelper); ok {
  1310. h.Helper()
  1311. }
  1312. return PanicsWithError(a.t, errString, f, msgAndArgs...)
  1313. }
  1314. // PanicsWithErrorf asserts that the code inside the specified PanicTestFunc
  1315. // panics, and that the recovered panic value is an error that satisfies the
  1316. // EqualError comparison.
  1317. //
  1318. // a.PanicsWithErrorf("crazy error", func(){ GoCrazy() }, "error message %s", "formatted")
  1319. func (a *Assertions) PanicsWithErrorf(errString string, f PanicTestFunc, msg string, args ...interface{}) bool {
  1320. if h, ok := a.t.(tHelper); ok {
  1321. h.Helper()
  1322. }
  1323. return PanicsWithErrorf(a.t, errString, f, msg, args...)
  1324. }
  1325. // PanicsWithValue asserts that the code inside the specified PanicTestFunc panics, and that
  1326. // the recovered panic value equals the expected panic value.
  1327. //
  1328. // a.PanicsWithValue("crazy error", func(){ GoCrazy() })
  1329. func (a *Assertions) PanicsWithValue(expected interface{}, f PanicTestFunc, msgAndArgs ...interface{}) bool {
  1330. if h, ok := a.t.(tHelper); ok {
  1331. h.Helper()
  1332. }
  1333. return PanicsWithValue(a.t, expected, f, msgAndArgs...)
  1334. }
  1335. // PanicsWithValuef asserts that the code inside the specified PanicTestFunc panics, and that
  1336. // the recovered panic value equals the expected panic value.
  1337. //
  1338. // a.PanicsWithValuef("crazy error", func(){ GoCrazy() }, "error message %s", "formatted")
  1339. func (a *Assertions) PanicsWithValuef(expected interface{}, f PanicTestFunc, msg string, args ...interface{}) bool {
  1340. if h, ok := a.t.(tHelper); ok {
  1341. h.Helper()
  1342. }
  1343. return PanicsWithValuef(a.t, expected, f, msg, args...)
  1344. }
  1345. // Panicsf asserts that the code inside the specified PanicTestFunc panics.
  1346. //
  1347. // a.Panicsf(func(){ GoCrazy() }, "error message %s", "formatted")
  1348. func (a *Assertions) Panicsf(f PanicTestFunc, msg string, args ...interface{}) bool {
  1349. if h, ok := a.t.(tHelper); ok {
  1350. h.Helper()
  1351. }
  1352. return Panicsf(a.t, f, msg, args...)
  1353. }
  1354. // Positive asserts that the specified element is positive
  1355. //
  1356. // a.Positive(1)
  1357. // a.Positive(1.23)
  1358. func (a *Assertions) Positive(e interface{}, msgAndArgs ...interface{}) bool {
  1359. if h, ok := a.t.(tHelper); ok {
  1360. h.Helper()
  1361. }
  1362. return Positive(a.t, e, msgAndArgs...)
  1363. }
  1364. // Positivef asserts that the specified element is positive
  1365. //
  1366. // a.Positivef(1, "error message %s", "formatted")
  1367. // a.Positivef(1.23, "error message %s", "formatted")
  1368. func (a *Assertions) Positivef(e interface{}, msg string, args ...interface{}) bool {
  1369. if h, ok := a.t.(tHelper); ok {
  1370. h.Helper()
  1371. }
  1372. return Positivef(a.t, e, msg, args...)
  1373. }
  1374. // Regexp asserts that a specified regexp matches a string.
  1375. //
  1376. // a.Regexp(regexp.MustCompile("start"), "it's starting")
  1377. // a.Regexp("start...$", "it's not starting")
  1378. func (a *Assertions) Regexp(rx interface{}, str interface{}, msgAndArgs ...interface{}) bool {
  1379. if h, ok := a.t.(tHelper); ok {
  1380. h.Helper()
  1381. }
  1382. return Regexp(a.t, rx, str, msgAndArgs...)
  1383. }
  1384. // Regexpf asserts that a specified regexp matches a string.
  1385. //
  1386. // a.Regexpf(regexp.MustCompile("start"), "it's starting", "error message %s", "formatted")
  1387. // a.Regexpf("start...$", "it's not starting", "error message %s", "formatted")
  1388. func (a *Assertions) Regexpf(rx interface{}, str interface{}, msg string, args ...interface{}) bool {
  1389. if h, ok := a.t.(tHelper); ok {
  1390. h.Helper()
  1391. }
  1392. return Regexpf(a.t, rx, str, msg, args...)
  1393. }
  1394. // Same asserts that two pointers reference the same object.
  1395. //
  1396. // a.Same(ptr1, ptr2)
  1397. //
  1398. // Both arguments must be pointer variables. Pointer variable sameness is
  1399. // determined based on the equality of both type and value.
  1400. func (a *Assertions) Same(expected interface{}, actual interface{}, msgAndArgs ...interface{}) bool {
  1401. if h, ok := a.t.(tHelper); ok {
  1402. h.Helper()
  1403. }
  1404. return Same(a.t, expected, actual, msgAndArgs...)
  1405. }
  1406. // Samef asserts that two pointers reference the same object.
  1407. //
  1408. // a.Samef(ptr1, ptr2, "error message %s", "formatted")
  1409. //
  1410. // Both arguments must be pointer variables. Pointer variable sameness is
  1411. // determined based on the equality of both type and value.
  1412. func (a *Assertions) Samef(expected interface{}, actual interface{}, msg string, args ...interface{}) bool {
  1413. if h, ok := a.t.(tHelper); ok {
  1414. h.Helper()
  1415. }
  1416. return Samef(a.t, expected, actual, msg, args...)
  1417. }
  1418. // Subset asserts that the specified list(array, slice...) or map contains all
  1419. // elements given in the specified subset list(array, slice...) or map.
  1420. //
  1421. // a.Subset([1, 2, 3], [1, 2])
  1422. // a.Subset({"x": 1, "y": 2}, {"x": 1})
  1423. func (a *Assertions) Subset(list interface{}, subset interface{}, msgAndArgs ...interface{}) bool {
  1424. if h, ok := a.t.(tHelper); ok {
  1425. h.Helper()
  1426. }
  1427. return Subset(a.t, list, subset, msgAndArgs...)
  1428. }
  1429. // Subsetf asserts that the specified list(array, slice...) or map contains all
  1430. // elements given in the specified subset list(array, slice...) or map.
  1431. //
  1432. // a.Subsetf([1, 2, 3], [1, 2], "error message %s", "formatted")
  1433. // a.Subsetf({"x": 1, "y": 2}, {"x": 1}, "error message %s", "formatted")
  1434. func (a *Assertions) Subsetf(list interface{}, subset interface{}, msg string, args ...interface{}) bool {
  1435. if h, ok := a.t.(tHelper); ok {
  1436. h.Helper()
  1437. }
  1438. return Subsetf(a.t, list, subset, msg, args...)
  1439. }
  1440. // True asserts that the specified value is true.
  1441. //
  1442. // a.True(myBool)
  1443. func (a *Assertions) True(value bool, msgAndArgs ...interface{}) bool {
  1444. if h, ok := a.t.(tHelper); ok {
  1445. h.Helper()
  1446. }
  1447. return True(a.t, value, msgAndArgs...)
  1448. }
  1449. // Truef asserts that the specified value is true.
  1450. //
  1451. // a.Truef(myBool, "error message %s", "formatted")
  1452. func (a *Assertions) Truef(value bool, msg string, args ...interface{}) bool {
  1453. if h, ok := a.t.(tHelper); ok {
  1454. h.Helper()
  1455. }
  1456. return Truef(a.t, value, msg, args...)
  1457. }
  1458. // WithinDuration asserts that the two times are within duration delta of each other.
  1459. //
  1460. // a.WithinDuration(time.Now(), time.Now(), 10*time.Second)
  1461. func (a *Assertions) WithinDuration(expected time.Time, actual time.Time, delta time.Duration, msgAndArgs ...interface{}) bool {
  1462. if h, ok := a.t.(tHelper); ok {
  1463. h.Helper()
  1464. }
  1465. return WithinDuration(a.t, expected, actual, delta, msgAndArgs...)
  1466. }
  1467. // WithinDurationf asserts that the two times are within duration delta of each other.
  1468. //
  1469. // a.WithinDurationf(time.Now(), time.Now(), 10*time.Second, "error message %s", "formatted")
  1470. func (a *Assertions) WithinDurationf(expected time.Time, actual time.Time, delta time.Duration, msg string, args ...interface{}) bool {
  1471. if h, ok := a.t.(tHelper); ok {
  1472. h.Helper()
  1473. }
  1474. return WithinDurationf(a.t, expected, actual, delta, msg, args...)
  1475. }
  1476. // WithinRange asserts that a time is within a time range (inclusive).
  1477. //
  1478. // a.WithinRange(time.Now(), time.Now().Add(-time.Second), time.Now().Add(time.Second))
  1479. func (a *Assertions) WithinRange(actual time.Time, start time.Time, end time.Time, msgAndArgs ...interface{}) bool {
  1480. if h, ok := a.t.(tHelper); ok {
  1481. h.Helper()
  1482. }
  1483. return WithinRange(a.t, actual, start, end, msgAndArgs...)
  1484. }
  1485. // WithinRangef asserts that a time is within a time range (inclusive).
  1486. //
  1487. // a.WithinRangef(time.Now(), time.Now().Add(-time.Second), time.Now().Add(time.Second), "error message %s", "formatted")
  1488. func (a *Assertions) WithinRangef(actual time.Time, start time.Time, end time.Time, msg string, args ...interface{}) bool {
  1489. if h, ok := a.t.(tHelper); ok {
  1490. h.Helper()
  1491. }
  1492. return WithinRangef(a.t, actual, start, end, msg, args...)
  1493. }
  1494. // YAMLEq asserts that two YAML strings are equivalent.
  1495. func (a *Assertions) YAMLEq(expected string, actual string, msgAndArgs ...interface{}) bool {
  1496. if h, ok := a.t.(tHelper); ok {
  1497. h.Helper()
  1498. }
  1499. return YAMLEq(a.t, expected, actual, msgAndArgs...)
  1500. }
  1501. // YAMLEqf asserts that two YAML strings are equivalent.
  1502. func (a *Assertions) YAMLEqf(expected string, actual string, msg string, args ...interface{}) bool {
  1503. if h, ok := a.t.(tHelper); ok {
  1504. h.Helper()
  1505. }
  1506. return YAMLEqf(a.t, expected, actual, msg, args...)
  1507. }
  1508. // Zero asserts that i is the zero value for its type.
  1509. func (a *Assertions) Zero(i interface{}, msgAndArgs ...interface{}) bool {
  1510. if h, ok := a.t.(tHelper); ok {
  1511. h.Helper()
  1512. }
  1513. return Zero(a.t, i, msgAndArgs...)
  1514. }
  1515. // Zerof asserts that i is the zero value for its type.
  1516. func (a *Assertions) Zerof(i interface{}, msg string, args ...interface{}) bool {
  1517. if h, ok := a.t.(tHelper); ok {
  1518. h.Helper()
  1519. }
  1520. return Zerof(a.t, i, msg, args...)
  1521. }