github.com/v2pro/plz@v0.0.0-20221028024117-e5f9aec5b631/test/testify/assert/assertion_format.go (about) 1 /* 2 * CODE GENERATED AUTOMATICALLY WITH github.com/stretchr/testify/_codegen 3 * THIS FILE MUST NOT BE EDITED BY HAND 4 */ 5 6 package assert 7 8 import ( 9 http "net/http" 10 url "net/url" 11 time "time" 12 ) 13 14 // Conditionf uses a Comparison to assert a complex condition. 15 func Conditionf(t TestingT, comp Comparison, msg string, args ...interface{}) bool { 16 return Condition(t, comp, append([]interface{}{msg}, args...)...) 17 } 18 19 // Containsf asserts that the specified string, list(array, slice...) or map contains the 20 // specified substring or element. 21 // 22 // assert.Containsf(t, "Hello World", "World", "error message %s", "formatted") 23 // assert.Containsf(t, ["Hello", "World"], "World", "error message %s", "formatted") 24 // assert.Containsf(t, {"Hello": "World"}, "Hello", "error message %s", "formatted") 25 func Containsf(t TestingT, s interface{}, contains interface{}, msg string, args ...interface{}) bool { 26 return Contains(t, s, contains, append([]interface{}{msg}, args...)...) 27 } 28 29 // DirExistsf checks whether a directory exists in the given path. It also fails if the path is a file rather a directory or there is an error checking whether it exists. 30 func DirExistsf(t TestingT, path string, msg string, args ...interface{}) bool { 31 return DirExists(t, path, append([]interface{}{msg}, args...)...) 32 } 33 34 // ElementsMatchf asserts that the specified listA(array, slice...) is equal to specified 35 // listB(array, slice...) ignoring the order of the elements. If there are duplicate elements, 36 // the number of appearances of each of them in both lists should match. 37 // 38 // assert.ElementsMatchf(t, [1, 3, 2, 3], [1, 3, 3, 2], "error message %s", "formatted")) 39 func ElementsMatchf(t TestingT, listA interface{}, listB interface{}, msg string, args ...interface{}) bool { 40 return ElementsMatch(t, listA, listB, append([]interface{}{msg}, args...)...) 41 } 42 43 // Emptyf asserts that the specified object is empty. I.e. nil, "", false, 0 or either 44 // a slice or a channel with len == 0. 45 // 46 // assert.Emptyf(t, obj, "error message %s", "formatted") 47 func Emptyf(t TestingT, object interface{}, msg string, args ...interface{}) bool { 48 return Empty(t, object, append([]interface{}{msg}, args...)...) 49 } 50 51 // Equalf asserts that two objects are equal. 52 // 53 // assert.Equalf(t, 123, 123, "error message %s", "formatted") 54 // 55 // Pointer variable equality is determined based on the equality of the 56 // referenced values (as opposed to the memory addresses). Function equality 57 // cannot be determined and will always fail. 58 func Equalf(t TestingT, expected interface{}, actual interface{}, msg string, args ...interface{}) bool { 59 return Equal(t, expected, actual, append([]interface{}{msg}, args...)...) 60 } 61 62 // EqualErrorf asserts that a function returned an error (i.e. not `nil`) 63 // and that it is equal to the provided error. 64 // 65 // actualObj, err := SomeFunction() 66 // assert.EqualErrorf(t, err, expectedErrorString, "error message %s", "formatted") 67 func EqualErrorf(t TestingT, theError error, errString string, msg string, args ...interface{}) bool { 68 return EqualError(t, theError, errString, append([]interface{}{msg}, args...)...) 69 } 70 71 // EqualValuesf asserts that two objects are equal or convertable to the same types 72 // and equal. 73 // 74 // assert.EqualValuesf(t, uint32(123, "error message %s", "formatted"), int32(123)) 75 func EqualValuesf(t TestingT, expected interface{}, actual interface{}, msg string, args ...interface{}) bool { 76 return EqualValues(t, expected, actual, append([]interface{}{msg}, args...)...) 77 } 78 79 // Errorf asserts that a function returned an error (i.e. not `nil`). 80 // 81 // actualObj, err := SomeFunction() 82 // if assert.Errorf(t, err, "error message %s", "formatted") { 83 // assert.Equal(t, expectedErrorf, err) 84 // } 85 func Errorf(t TestingT, err error, msg string, args ...interface{}) bool { 86 return Error(t, err, append([]interface{}{msg}, args...)...) 87 } 88 89 // Exactlyf asserts that two objects are equal in value and type. 90 // 91 // assert.Exactlyf(t, int32(123, "error message %s", "formatted"), int64(123)) 92 func Exactlyf(t TestingT, expected interface{}, actual interface{}, msg string, args ...interface{}) bool { 93 return Exactly(t, expected, actual, append([]interface{}{msg}, args...)...) 94 } 95 96 // Failf reports a failure through 97 func Failf(t TestingT, failureMessage string, msg string, args ...interface{}) bool { 98 return Fail(t, failureMessage, append([]interface{}{msg}, args...)...) 99 } 100 101 // FailNowf fails test 102 func FailNowf(t TestingT, failureMessage string, msg string, args ...interface{}) bool { 103 return FailNow(t, failureMessage, append([]interface{}{msg}, args...)...) 104 } 105 106 // Falsef asserts that the specified value is false. 107 // 108 // assert.Falsef(t, myBool, "error message %s", "formatted") 109 func Falsef(t TestingT, value bool, msg string, args ...interface{}) bool { 110 return False(t, value, append([]interface{}{msg}, args...)...) 111 } 112 113 // FileExistsf checks whether a file exists in the given path. It also fails if the path points to a directory or there is an error when trying to check the file. 114 func FileExistsf(t TestingT, path string, msg string, args ...interface{}) bool { 115 return FileExists(t, path, append([]interface{}{msg}, args...)...) 116 } 117 118 // HTTPBodyContainsf asserts that a specified handler returns a 119 // body that contains a string. 120 // 121 // assert.HTTPBodyContainsf(t, myHandler, "www.google.com", nil, "I'm Feeling Lucky", "error message %s", "formatted") 122 // 123 // Returns whether the assertion was successful (true) or not (false). 124 func HTTPBodyContainsf(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, str interface{}, msg string, args ...interface{}) bool { 125 return HTTPBodyContains(t, handler, method, url, values, str, append([]interface{}{msg}, args...)...) 126 } 127 128 // HTTPBodyNotContainsf asserts that a specified handler returns a 129 // body that does not contain a string. 130 // 131 // assert.HTTPBodyNotContainsf(t, myHandler, "www.google.com", nil, "I'm Feeling Lucky", "error message %s", "formatted") 132 // 133 // Returns whether the assertion was successful (true) or not (false). 134 func HTTPBodyNotContainsf(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, str interface{}, msg string, args ...interface{}) bool { 135 return HTTPBodyNotContains(t, handler, method, url, values, str, append([]interface{}{msg}, args...)...) 136 } 137 138 // HTTPErrorf asserts that a specified handler returns an error status code. 139 // 140 // assert.HTTPErrorf(t, myHandler, "POST", "/a/b/c", url.Values{"a": []string{"b", "c"}} 141 // 142 // Returns whether the assertion was successful (true, "error message %s", "formatted") or not (false). 143 func HTTPErrorf(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, msg string, args ...interface{}) bool { 144 return HTTPError(t, handler, method, url, values, append([]interface{}{msg}, args...)...) 145 } 146 147 // HTTPRedirectf asserts that a specified handler returns a redirect status code. 148 // 149 // assert.HTTPRedirectf(t, myHandler, "GET", "/a/b/c", url.Values{"a": []string{"b", "c"}} 150 // 151 // Returns whether the assertion was successful (true, "error message %s", "formatted") or not (false). 152 func HTTPRedirectf(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, msg string, args ...interface{}) bool { 153 return HTTPRedirect(t, handler, method, url, values, append([]interface{}{msg}, args...)...) 154 } 155 156 // HTTPSuccessf asserts that a specified handler returns a success status code. 157 // 158 // assert.HTTPSuccessf(t, myHandler, "POST", "http://www.google.com", nil, "error message %s", "formatted") 159 // 160 // Returns whether the assertion was successful (true) or not (false). 161 func HTTPSuccessf(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, msg string, args ...interface{}) bool { 162 return HTTPSuccess(t, handler, method, url, values, append([]interface{}{msg}, args...)...) 163 } 164 165 // Implementsf asserts that an object is implemented by the specified interface. 166 // 167 // assert.Implementsf(t, (*MyInterface, "error message %s", "formatted")(nil), new(MyObject)) 168 func Implementsf(t TestingT, interfaceObject interface{}, object interface{}, msg string, args ...interface{}) bool { 169 return Implements(t, interfaceObject, object, append([]interface{}{msg}, args...)...) 170 } 171 172 // InDeltaf asserts that the two numerals are within delta of each other. 173 // 174 // assert.InDeltaf(t, math.Pi, (22 / 7.0, "error message %s", "formatted"), 0.01) 175 func InDeltaf(t TestingT, expected interface{}, actual interface{}, delta float64, msg string, args ...interface{}) bool { 176 return InDelta(t, expected, actual, delta, append([]interface{}{msg}, args...)...) 177 } 178 179 // InDeltaMapValuesf is the same as InDelta, but it compares all values between two maps. Both maps must have exactly the same keys. 180 func InDeltaMapValuesf(t TestingT, expected interface{}, actual interface{}, delta float64, msg string, args ...interface{}) bool { 181 return InDeltaMapValues(t, expected, actual, delta, append([]interface{}{msg}, args...)...) 182 } 183 184 // InDeltaSlicef is the same as InDelta, except it compares two slices. 185 func InDeltaSlicef(t TestingT, expected interface{}, actual interface{}, delta float64, msg string, args ...interface{}) bool { 186 return InDeltaSlice(t, expected, actual, delta, append([]interface{}{msg}, args...)...) 187 } 188 189 // InEpsilonf asserts that expected and actual have a relative error less than epsilon 190 func InEpsilonf(t TestingT, expected interface{}, actual interface{}, epsilon float64, msg string, args ...interface{}) bool { 191 return InEpsilon(t, expected, actual, epsilon, append([]interface{}{msg}, args...)...) 192 } 193 194 // InEpsilonSlicef is the same as InEpsilon, except it compares each value from two slices. 195 func InEpsilonSlicef(t TestingT, expected interface{}, actual interface{}, epsilon float64, msg string, args ...interface{}) bool { 196 return InEpsilonSlice(t, expected, actual, epsilon, append([]interface{}{msg}, args...)...) 197 } 198 199 // IsTypef asserts that the specified objects are of the same type. 200 func IsTypef(t TestingT, expectedType interface{}, object interface{}, msg string, args ...interface{}) bool { 201 return IsType(t, expectedType, object, append([]interface{}{msg}, args...)...) 202 } 203 204 // JSONEqf asserts that two JSON strings are equivalent. 205 // 206 // assert.JSONEqf(t, `{"hello": "world", "foo": "bar"}`, `{"foo": "bar", "hello": "world"}`, "error message %s", "formatted") 207 func JSONEqf(t TestingT, expected string, actual string, msg string, args ...interface{}) bool { 208 return JSONEq(t, expected, actual, append([]interface{}{msg}, args...)...) 209 } 210 211 // Lenf asserts that the specified object has specific length. 212 // Lenf also fails if the object has a type that len() not accept. 213 // 214 // assert.Lenf(t, mySlice, 3, "error message %s", "formatted") 215 func Lenf(t TestingT, object interface{}, length int, msg string, args ...interface{}) bool { 216 return Len(t, object, length, append([]interface{}{msg}, args...)...) 217 } 218 219 // Nilf asserts that the specified object is nil. 220 // 221 // assert.Nilf(t, err, "error message %s", "formatted") 222 func Nilf(t TestingT, object interface{}, msg string, args ...interface{}) bool { 223 return Nil(t, object, append([]interface{}{msg}, args...)...) 224 } 225 226 // NoErrorf asserts that a function returned no error (i.e. `nil`). 227 // 228 // actualObj, err := SomeFunction() 229 // if assert.NoErrorf(t, err, "error message %s", "formatted") { 230 // assert.Equal(t, expectedObj, actualObj) 231 // } 232 func NoErrorf(t TestingT, err error, msg string, args ...interface{}) bool { 233 return NoError(t, err, append([]interface{}{msg}, args...)...) 234 } 235 236 // NotContainsf asserts that the specified string, list(array, slice...) or map does NOT contain the 237 // specified substring or element. 238 // 239 // assert.NotContainsf(t, "Hello World", "Earth", "error message %s", "formatted") 240 // assert.NotContainsf(t, ["Hello", "World"], "Earth", "error message %s", "formatted") 241 // assert.NotContainsf(t, {"Hello": "World"}, "Earth", "error message %s", "formatted") 242 func NotContainsf(t TestingT, s interface{}, contains interface{}, msg string, args ...interface{}) bool { 243 return NotContains(t, s, contains, append([]interface{}{msg}, args...)...) 244 } 245 246 // NotEmptyf asserts that the specified object is NOT empty. I.e. not nil, "", false, 0 or either 247 // a slice or a channel with len == 0. 248 // 249 // if assert.NotEmptyf(t, obj, "error message %s", "formatted") { 250 // assert.Equal(t, "two", obj[1]) 251 // } 252 func NotEmptyf(t TestingT, object interface{}, msg string, args ...interface{}) bool { 253 return NotEmpty(t, object, append([]interface{}{msg}, args...)...) 254 } 255 256 // NotEqualf asserts that the specified values are NOT equal. 257 // 258 // assert.NotEqualf(t, obj1, obj2, "error message %s", "formatted") 259 // 260 // Pointer variable equality is determined based on the equality of the 261 // referenced values (as opposed to the memory addresses). 262 func NotEqualf(t TestingT, expected interface{}, actual interface{}, msg string, args ...interface{}) bool { 263 return NotEqual(t, expected, actual, append([]interface{}{msg}, args...)...) 264 } 265 266 // NotNilf asserts that the specified object is not nil. 267 // 268 // assert.NotNilf(t, err, "error message %s", "formatted") 269 func NotNilf(t TestingT, object interface{}, msg string, args ...interface{}) bool { 270 return NotNil(t, object, append([]interface{}{msg}, args...)...) 271 } 272 273 // NotPanicsf asserts that the code inside the specified PanicTestFunc does NOT panic. 274 // 275 // assert.NotPanicsf(t, func(){ RemainCalm() }, "error message %s", "formatted") 276 func NotPanicsf(t TestingT, f PanicTestFunc, msg string, args ...interface{}) bool { 277 return NotPanics(t, f, append([]interface{}{msg}, args...)...) 278 } 279 280 // NotRegexpf asserts that a specified regexp does not match a string. 281 // 282 // assert.NotRegexpf(t, regexp.MustCompile("starts", "error message %s", "formatted"), "it's starting") 283 // assert.NotRegexpf(t, "^start", "it's not starting", "error message %s", "formatted") 284 func NotRegexpf(t TestingT, rx interface{}, str interface{}, msg string, args ...interface{}) bool { 285 return NotRegexp(t, rx, str, append([]interface{}{msg}, args...)...) 286 } 287 288 // NotSubsetf asserts that the specified list(array, slice...) contains not all 289 // elements given in the specified subset(array, slice...). 290 // 291 // assert.NotSubsetf(t, [1, 3, 4], [1, 2], "But [1, 3, 4] does not contain [1, 2]", "error message %s", "formatted") 292 func NotSubsetf(t TestingT, list interface{}, subset interface{}, msg string, args ...interface{}) bool { 293 return NotSubset(t, list, subset, append([]interface{}{msg}, args...)...) 294 } 295 296 // NotZerof asserts that i is not the zero value for its type. 297 func NotZerof(t TestingT, i interface{}, msg string, args ...interface{}) bool { 298 return NotZero(t, i, append([]interface{}{msg}, args...)...) 299 } 300 301 // Panicsf asserts that the code inside the specified PanicTestFunc panics. 302 // 303 // assert.Panicsf(t, func(){ GoCrazy() }, "error message %s", "formatted") 304 func Panicsf(t TestingT, f PanicTestFunc, msg string, args ...interface{}) bool { 305 return Panics(t, f, append([]interface{}{msg}, args...)...) 306 } 307 308 // PanicsWithValuef asserts that the code inside the specified PanicTestFunc panics, and that 309 // the recovered panic value equals the expected panic value. 310 // 311 // assert.PanicsWithValuef(t, "crazy error", func(){ GoCrazy() }, "error message %s", "formatted") 312 func PanicsWithValuef(t TestingT, expected interface{}, f PanicTestFunc, msg string, args ...interface{}) bool { 313 return PanicsWithValue(t, expected, f, append([]interface{}{msg}, args...)...) 314 } 315 316 // Regexpf asserts that a specified regexp matches a string. 317 // 318 // assert.Regexpf(t, regexp.MustCompile("start", "error message %s", "formatted"), "it's starting") 319 // assert.Regexpf(t, "start...$", "it's not starting", "error message %s", "formatted") 320 func Regexpf(t TestingT, rx interface{}, str interface{}, msg string, args ...interface{}) bool { 321 return Regexp(t, rx, str, append([]interface{}{msg}, args...)...) 322 } 323 324 // Subsetf asserts that the specified list(array, slice...) contains all 325 // elements given in the specified subset(array, slice...). 326 // 327 // assert.Subsetf(t, [1, 2, 3], [1, 2], "But [1, 2, 3] does contain [1, 2]", "error message %s", "formatted") 328 func Subsetf(t TestingT, list interface{}, subset interface{}, msg string, args ...interface{}) bool { 329 return Subset(t, list, subset, append([]interface{}{msg}, args...)...) 330 } 331 332 // Truef asserts that the specified value is true. 333 // 334 // assert.Truef(t, myBool, "error message %s", "formatted") 335 func Truef(t TestingT, value bool, msg string, args ...interface{}) bool { 336 return True(t, value, append([]interface{}{msg}, args...)...) 337 } 338 339 // WithinDurationf asserts that the two times are within duration delta of each other. 340 // 341 // assert.WithinDurationf(t, time.Now(), time.Now(), 10*time.Second, "error message %s", "formatted") 342 func WithinDurationf(t TestingT, expected time.Time, actual time.Time, delta time.Duration, msg string, args ...interface{}) bool { 343 return WithinDuration(t, expected, actual, delta, append([]interface{}{msg}, args...)...) 344 } 345 346 // Zerof asserts that i is the zero value for its type. 347 func Zerof(t TestingT, i interface{}, msg string, args ...interface{}) bool { 348 return Zero(t, i, append([]interface{}{msg}, args...)...) 349 }