assertion_forward.go 57 KB

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