Skip to content

Commit dc1948b

Browse files
committed
Use type alias
1 parent cb954e7 commit dc1948b

File tree

1 file changed

+53
-53
lines changed

1 file changed

+53
-53
lines changed

‎assert/assertions.go

Lines changed: 53 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ type ErrorAssertionFunc func(TestingT, error, ...interface{}) bool
4747

4848
// PanicAssertionFunc is a common function prototype when validating a panic value. Can be useful
4949
// for table driven tests.
50-
type PanicAssertionFunc func(t TestingT, f PanicTestFunc, msgAndArgs ...interface{}) bool
50+
type PanicAssertionFunc = func(t TestingT, f PanicTestFunc, msgAndArgs ...interface{}) bool
5151

5252
// Comparison is a custom function that returns true on success and false on failure
5353
type Comparison func() (success bool)
@@ -275,7 +275,7 @@ type labeledContent struct {
275275

276276
// labeledOutput returns a string consisting of the provided labeledContent. Each labeled output is appended in the following manner:
277277
//
278-
// \t{{label}}:{{align_spaces}}\t{{content}}\n
278+
// \t{{label}}:{{align_spaces}}\t{{content}}\n
279279
//
280280
// The initial carriage return is required to undo/erase any padding added by testing.T.Errorf. The "\t{{label}}:" is for the label.
281281
// If a label is shorter than the longest label provided, padding spaces are added to make all the labels match in length. Once this
@@ -298,7 +298,7 @@ func labeledOutput(content ...labeledContent) string {
298298

299299
// Implements asserts that an object is implemented by the specified interface.
300300
//
301-
// assert.Implements(t, (*MyInterface)(nil), new(MyObject))
301+
// assert.Implements(t, (*MyInterface)(nil), new(MyObject))
302302
func Implements(t TestingT, interfaceObject interface{}, object interface{}, msgAndArgs ...interface{}) bool {
303303
if h, ok := t.(tHelper); ok {
304304
h.Helper()
@@ -330,7 +330,7 @@ func IsType(t TestingT, expectedType interface{}, object interface{}, msgAndArgs
330330

331331
// Equal asserts that two objects are equal.
332332
//
333-
// assert.Equal(t, 123, 123)
333+
// assert.Equal(t, 123, 123)
334334
//
335335
// Pointer variable equality is determined based on the equality of the
336336
// referenced values (as opposed to the memory addresses). Function equality
@@ -371,7 +371,7 @@ func validateEqualArgs(expected, actual interface{}) error {
371371

372372
// Same asserts that two pointers reference the same object.
373373
//
374-
// assert.Same(t, ptr1, ptr2)
374+
// assert.Same(t, ptr1, ptr2)
375375
//
376376
// Both arguments must be pointer variables. Pointer variable sameness is
377377
// determined based on the equality of both type and value.
@@ -391,7 +391,7 @@ func Same(t TestingT, expected, actual interface{}, msgAndArgs ...interface{}) b
391391

392392
// NotSame asserts that two pointers do not reference the same object.
393393
//
394-
// assert.NotSame(t, ptr1, ptr2)
394+
// assert.NotSame(t, ptr1, ptr2)
395395
//
396396
// Both arguments must be pointer variables. Pointer variable sameness is
397397
// determined based on the equality of both type and value.
@@ -459,7 +459,7 @@ func truncatingFormat(data interface{}) string {
459459
// EqualValues asserts that two objects are equal or convertable to the same types
460460
// and equal.
461461
//
462-
// assert.EqualValues(t, uint32(123), int32(123))
462+
// assert.EqualValues(t, uint32(123), int32(123))
463463
func EqualValues(t TestingT, expected, actual interface{}, msgAndArgs ...interface{}) bool {
464464
if h, ok := t.(tHelper); ok {
465465
h.Helper()
@@ -479,7 +479,7 @@ func EqualValues(t TestingT, expected, actual interface{}, msgAndArgs ...interfa
479479

480480
// Exactly asserts that two objects are equal in value and type.
481481
//
482-
// assert.Exactly(t, int32(123), int64(123))
482+
// assert.Exactly(t, int32(123), int64(123))
483483
func Exactly(t TestingT, expected, actual interface{}, msgAndArgs ...interface{}) bool {
484484
if h, ok := t.(tHelper); ok {
485485
h.Helper()
@@ -498,7 +498,7 @@ func Exactly(t TestingT, expected, actual interface{}, msgAndArgs ...interface{}
498498

499499
// NotNil asserts that the specified object is not nil.
500500
//
501-
// assert.NotNil(t, err)
501+
// assert.NotNil(t, err)
502502
func NotNil(t TestingT, object interface{}, msgAndArgs ...interface{}) bool {
503503
if !isNil(object) {
504504
return true
@@ -544,7 +544,7 @@ func isNil(object interface{}) bool {
544544

545545
// Nil asserts that the specified object is nil.
546546
//
547-
// assert.Nil(t, err)
547+
// assert.Nil(t, err)
548548
func Nil(t TestingT, object interface{}, msgAndArgs ...interface{}) bool {
549549
if isNil(object) {
550550
return true
@@ -587,7 +587,7 @@ func isEmpty(object interface{}) bool {
587587
// Empty asserts that the specified object is empty. I.e. nil, "", false, 0 or either
588588
// a slice or a channel with len == 0.
589589
//
590-
// assert.Empty(t, obj)
590+
// assert.Empty(t, obj)
591591
func Empty(t TestingT, object interface{}, msgAndArgs ...interface{}) bool {
592592
pass := isEmpty(object)
593593
if !pass {
@@ -604,9 +604,9 @@ func Empty(t TestingT, object interface{}, msgAndArgs ...interface{}) bool {
604604
// NotEmpty asserts that the specified object is NOT empty. I.e. not nil, "", false, 0 or either
605605
// a slice or a channel with len == 0.
606606
//
607-
// if assert.NotEmpty(t, obj) {
608-
// assert.Equal(t, "two", obj[1])
609-
// }
607+
// if assert.NotEmpty(t, obj) {
608+
// assert.Equal(t, "two", obj[1])
609+
// }
610610
func NotEmpty(t TestingT, object interface{}, msgAndArgs ...interface{}) bool {
611611
pass := !isEmpty(object)
612612
if !pass {
@@ -635,7 +635,7 @@ func getLen(x interface{}) (ok bool, length int) {
635635
// Len asserts that the specified object has specific length.
636636
// Len also fails if the object has a type that len() not accept.
637637
//
638-
// assert.Len(t, mySlice, 3)
638+
// assert.Len(t, mySlice, 3)
639639
func Len(t TestingT, object interface{}, length int, msgAndArgs ...interface{}) bool {
640640
if h, ok := t.(tHelper); ok {
641641
h.Helper()
@@ -653,7 +653,7 @@ func Len(t TestingT, object interface{}, length int, msgAndArgs ...interface{})
653653

654654
// True asserts that the specified value is true.
655655
//
656-
// assert.True(t, myBool)
656+
// assert.True(t, myBool)
657657
func True(t TestingT, value bool, msgAndArgs ...interface{}) bool {
658658
if !value {
659659
if h, ok := t.(tHelper); ok {
@@ -668,7 +668,7 @@ func True(t TestingT, value bool, msgAndArgs ...interface{}) bool {
668668

669669
// False asserts that the specified value is false.
670670
//
671-
// assert.False(t, myBool)
671+
// assert.False(t, myBool)
672672
func False(t TestingT, value bool, msgAndArgs ...interface{}) bool {
673673
if value {
674674
if h, ok := t.(tHelper); ok {
@@ -683,7 +683,7 @@ func False(t TestingT, value bool, msgAndArgs ...interface{}) bool {
683683

684684
// NotEqual asserts that the specified values are NOT equal.
685685
//
686-
// assert.NotEqual(t, obj1, obj2)
686+
// assert.NotEqual(t, obj1, obj2)
687687
//
688688
// Pointer variable equality is determined based on the equality of the
689689
// referenced values (as opposed to the memory addresses).
@@ -706,7 +706,7 @@ func NotEqual(t TestingT, expected, actual interface{}, msgAndArgs ...interface{
706706

707707
// NotEqualValues asserts that two objects are not equal even when converted to the same type
708708
//
709-
// assert.NotEqualValues(t, obj1, obj2)
709+
// assert.NotEqualValues(t, obj1, obj2)
710710
func NotEqualValues(t TestingT, expected, actual interface{}, msgAndArgs ...interface{}) bool {
711711
if h, ok := t.(tHelper); ok {
712712
h.Helper()
@@ -765,9 +765,9 @@ func containsElement(list interface{}, element interface{}) (ok, found bool) {
765765
// Contains asserts that the specified string, list(array, slice...) or map contains the
766766
// specified substring or element.
767767
//
768-
// assert.Contains(t, "Hello World", "World")
769-
// assert.Contains(t, ["Hello", "World"], "World")
770-
// assert.Contains(t, {"Hello": "World"}, "Hello")
768+
// assert.Contains(t, "Hello World", "World")
769+
// assert.Contains(t, ["Hello", "World"], "World")
770+
// assert.Contains(t, {"Hello": "World"}, "Hello")
771771
func Contains(t TestingT, s, contains interface{}, msgAndArgs ...interface{}) bool {
772772
if h, ok := t.(tHelper); ok {
773773
h.Helper()
@@ -788,9 +788,9 @@ func Contains(t TestingT, s, contains interface{}, msgAndArgs ...interface{}) bo
788788
// NotContains asserts that the specified string, list(array, slice...) or map does NOT contain the
789789
// specified substring or element.
790790
//
791-
// assert.NotContains(t, "Hello World", "Earth")
792-
// assert.NotContains(t, ["Hello", "World"], "Earth")
793-
// assert.NotContains(t, {"Hello": "World"}, "Earth")
791+
// assert.NotContains(t, "Hello World", "Earth")
792+
// assert.NotContains(t, ["Hello", "World"], "Earth")
793+
// assert.NotContains(t, {"Hello": "World"}, "Earth")
794794
func NotContains(t TestingT, s, contains interface{}, msgAndArgs ...interface{}) bool {
795795
if h, ok := t.(tHelper); ok {
796796
h.Helper()
@@ -811,7 +811,7 @@ func NotContains(t TestingT, s, contains interface{}, msgAndArgs ...interface{})
811811
// Subset asserts that the specified list(array, slice...) contains all
812812
// elements given in the specified subset(array, slice...).
813813
//
814-
// assert.Subset(t, [1, 2, 3], [1, 2], "But [1, 2, 3] does contain [1, 2]")
814+
// assert.Subset(t, [1, 2, 3], [1, 2], "But [1, 2, 3] does contain [1, 2]")
815815
func Subset(t TestingT, list, subset interface{}, msgAndArgs ...interface{}) (ok bool) {
816816
if h, ok := t.(tHelper); ok {
817817
h.Helper()
@@ -872,7 +872,7 @@ func Subset(t TestingT, list, subset interface{}, msgAndArgs ...interface{}) (ok
872872
// NotSubset asserts that the specified list(array, slice...) contains not all
873873
// elements given in the specified subset(array, slice...).
874874
//
875-
// assert.NotSubset(t, [1, 3, 4], [1, 2], "But [1, 3, 4] does not contain [1, 2]")
875+
// assert.NotSubset(t, [1, 3, 4], [1, 2], "But [1, 3, 4] does not contain [1, 2]")
876876
func NotSubset(t TestingT, list, subset interface{}, msgAndArgs ...interface{}) (ok bool) {
877877
if h, ok := t.(tHelper); ok {
878878
h.Helper()
@@ -1062,7 +1062,7 @@ func didPanic(f PanicTestFunc) (didPanic bool, message interface{}, stack string
10621062

10631063
// Panics asserts that the code inside the specified PanicTestFunc panics.
10641064
//
1065-
// assert.Panics(t, func(){ GoCrazy() })
1065+
// assert.Panics(t, func(){ GoCrazy() })
10661066
func Panics(t TestingT, f PanicTestFunc, msgAndArgs ...interface{}) bool {
10671067
if h, ok := t.(tHelper); ok {
10681068
h.Helper()
@@ -1078,7 +1078,7 @@ func Panics(t TestingT, f PanicTestFunc, msgAndArgs ...interface{}) bool {
10781078
// PanicsWithValue asserts that the code inside the specified PanicTestFunc panics, and that
10791079
// the recovered panic value equals the expected panic value.
10801080
//
1081-
// assert.PanicsWithValue(t, "crazy error", func(){ GoCrazy() })
1081+
// assert.PanicsWithValue(t, "crazy error", func(){ GoCrazy() })
10821082
func PanicsWithValue(t TestingT, expected interface{}, f PanicTestFunc, msgAndArgs ...interface{}) bool {
10831083
if h, ok := t.(tHelper); ok {
10841084
h.Helper()
@@ -1099,7 +1099,7 @@ func PanicsWithValue(t TestingT, expected interface{}, f PanicTestFunc, msgAndAr
10991099
// panics, and that the recovered panic value is an error that satisfies the
11001100
// EqualError comparison.
11011101
//
1102-
// assert.PanicsWithError(t, "crazy error", func(){ GoCrazy() })
1102+
// assert.PanicsWithError(t, "crazy error", func(){ GoCrazy() })
11031103
func PanicsWithError(t TestingT, errString string, f PanicTestFunc, msgAndArgs ...interface{}) bool {
11041104
if h, ok := t.(tHelper); ok {
11051105
h.Helper()
@@ -1119,7 +1119,7 @@ func PanicsWithError(t TestingT, errString string, f PanicTestFunc, msgAndArgs .
11191119

11201120
// NotPanics asserts that the code inside the specified PanicTestFunc does NOT panic.
11211121
//
1122-
// assert.NotPanics(t, func(){ RemainCalm() })
1122+
// assert.NotPanics(t, func(){ RemainCalm() })
11231123
func NotPanics(t TestingT, f PanicTestFunc, msgAndArgs ...interface{}) bool {
11241124
if h, ok := t.(tHelper); ok {
11251125
h.Helper()
@@ -1134,7 +1134,7 @@ func NotPanics(t TestingT, f PanicTestFunc, msgAndArgs ...interface{}) bool {
11341134

11351135
// WithinDuration asserts that the two times are within duration delta of each other.
11361136
//
1137-
// assert.WithinDuration(t, time.Now(), time.Now(), 10*time.Second)
1137+
// assert.WithinDuration(t, time.Now(), time.Now(), 10*time.Second)
11381138
func WithinDuration(t TestingT, expected, actual time.Time, delta time.Duration, msgAndArgs ...interface{}) bool {
11391139
if h, ok := t.(tHelper); ok {
11401140
h.Helper()
@@ -1150,7 +1150,7 @@ func WithinDuration(t TestingT, expected, actual time.Time, delta time.Duration,
11501150

11511151
// WithinRange asserts that a time is within a time range (inclusive).
11521152
//
1153-
// assert.WithinRange(t, time.Now(), time.Now().Add(-time.Second), time.Now().Add(time.Second))
1153+
// assert.WithinRange(t, time.Now(), time.Now().Add(-time.Second), time.Now().Add(time.Second))
11541154
func WithinRange(t TestingT, actual, start, end time.Time, msgAndArgs ...interface{}) bool {
11551155
if h, ok := t.(tHelper); ok {
11561156
h.Helper()
@@ -1209,7 +1209,7 @@ func toFloat(x interface{}) (float64, bool) {
12091209

12101210
// InDelta asserts that the two numerals are within delta of each other.
12111211
//
1212-
// assert.InDelta(t, math.Pi, 22/7.0, 0.01)
1212+
// assert.InDelta(t, math.Pi, 22/7.0, 0.01)
12131213
func InDelta(t TestingT, expected, actual interface{}, delta float64, msgAndArgs ...interface{}) bool {
12141214
if h, ok := t.(tHelper); ok {
12151215
h.Helper()
@@ -1382,10 +1382,10 @@ func InEpsilonSlice(t TestingT, expected, actual interface{}, epsilon float64, m
13821382

13831383
// NoError asserts that a function returned no error (i.e. `nil`).
13841384
//
1385-
// actualObj, err := SomeFunction()
1386-
// if assert.NoError(t, err) {
1387-
// assert.Equal(t, expectedObj, actualObj)
1388-
// }
1385+
// actualObj, err := SomeFunction()
1386+
// if assert.NoError(t, err) {
1387+
// assert.Equal(t, expectedObj, actualObj)
1388+
// }
13891389
func NoError(t TestingT, err error, msgAndArgs ...interface{}) bool {
13901390
if err != nil {
13911391
if h, ok := t.(tHelper); ok {
@@ -1399,10 +1399,10 @@ func NoError(t TestingT, err error, msgAndArgs ...interface{}) bool {
13991399

14001400
// Error asserts that a function returned an error (i.e. not `nil`).
14011401
//
1402-
// actualObj, err := SomeFunction()
1403-
// if assert.Error(t, err) {
1404-
// assert.Equal(t, expectedError, err)
1405-
// }
1402+
// actualObj, err := SomeFunction()
1403+
// if assert.Error(t, err) {
1404+
// assert.Equal(t, expectedError, err)
1405+
// }
14061406
func Error(t TestingT, err error, msgAndArgs ...interface{}) bool {
14071407
if err == nil {
14081408
if h, ok := t.(tHelper); ok {
@@ -1417,8 +1417,8 @@ func Error(t TestingT, err error, msgAndArgs ...interface{}) bool {
14171417
// EqualError asserts that a function returned an error (i.e. not `nil`)
14181418
// and that it is equal to the provided error.
14191419
//
1420-
// actualObj, err := SomeFunction()
1421-
// assert.EqualError(t, err, expectedErrorString)
1420+
// actualObj, err := SomeFunction()
1421+
// assert.EqualError(t, err, expectedErrorString)
14221422
func EqualError(t TestingT, theError error, errString string, msgAndArgs ...interface{}) bool {
14231423
if h, ok := t.(tHelper); ok {
14241424
h.Helper()
@@ -1440,8 +1440,8 @@ func EqualError(t TestingT, theError error, errString string, msgAndArgs ...inte
14401440
// ErrorContains asserts that a function returned an error (i.e. not `nil`)
14411441
// and that the error contains the specified substring.
14421442
//
1443-
// actualObj, err := SomeFunction()
1444-
// assert.ErrorContains(t, err, expectedErrorSubString)
1443+
// actualObj, err := SomeFunction()
1444+
// assert.ErrorContains(t, err, expectedErrorSubString)
14451445
func ErrorContains(t TestingT, theError error, contains string, msgAndArgs ...interface{}) bool {
14461446
if h, ok := t.(tHelper); ok {
14471447
h.Helper()
@@ -1474,8 +1474,8 @@ func matchRegexp(rx interface{}, str interface{}) bool {
14741474

14751475
// Regexp asserts that a specified regexp matches a string.
14761476
//
1477-
// assert.Regexp(t, regexp.MustCompile("start"), "it's starting")
1478-
// assert.Regexp(t, "start...$", "it's not starting")
1477+
// assert.Regexp(t, regexp.MustCompile("start"), "it's starting")
1478+
// assert.Regexp(t, "start...$", "it's not starting")
14791479
func Regexp(t TestingT, rx interface{}, str interface{}, msgAndArgs ...interface{}) bool {
14801480
if h, ok := t.(tHelper); ok {
14811481
h.Helper()
@@ -1492,8 +1492,8 @@ func Regexp(t TestingT, rx interface{}, str interface{}, msgAndArgs ...interface
14921492

14931493
// NotRegexp asserts that a specified regexp does not match a string.
14941494
//
1495-
// assert.NotRegexp(t, regexp.MustCompile("starts"), "it's starting")
1496-
// assert.NotRegexp(t, "^start", "it's not starting")
1495+
// assert.NotRegexp(t, regexp.MustCompile("starts"), "it's starting")
1496+
// assert.NotRegexp(t, "^start", "it's not starting")
14971497
func NotRegexp(t TestingT, rx interface{}, str interface{}, msgAndArgs ...interface{}) bool {
14981498
if h, ok := t.(tHelper); ok {
14991499
h.Helper()
@@ -1605,7 +1605,7 @@ func NoDirExists(t TestingT, path string, msgAndArgs ...interface{}) bool {
16051605

16061606
// JSONEq asserts that two JSON strings are equivalent.
16071607
//
1608-
// assert.JSONEq(t, `{"hello": "world", "foo": "bar"}`, `{"foo": "bar", "hello": "world"}`)
1608+
// assert.JSONEq(t, `{"hello": "world", "foo": "bar"}`, `{"foo": "bar", "hello": "world"}`)
16091609
func JSONEq(t TestingT, expected string, actual string, msgAndArgs ...interface{}) bool {
16101610
if h, ok := t.(tHelper); ok {
16111611
h.Helper()
@@ -1728,7 +1728,7 @@ type tHelper interface {
17281728
// Eventually asserts that given condition will be met in waitFor time,
17291729
// periodically checking target function each tick.
17301730
//
1731-
// assert.Eventually(t, func() bool { return true; }, time.Second, 10*time.Millisecond)
1731+
// assert.Eventually(t, func() bool { return true; }, time.Second, 10*time.Millisecond)
17321732
func Eventually(t TestingT, condition func() bool, waitFor time.Duration, tick time.Duration, msgAndArgs ...interface{}) bool {
17331733
if h, ok := t.(tHelper); ok {
17341734
h.Helper()
@@ -1761,7 +1761,7 @@ func Eventually(t TestingT, condition func() bool, waitFor time.Duration, tick t
17611761
// Never asserts that the given condition doesn't satisfy in waitFor time,
17621762
// periodically checking the target function each tick.
17631763
//
1764-
// assert.Never(t, func() bool { return false; }, time.Second, 10*time.Millisecond)
1764+
// assert.Never(t, func() bool { return false; }, time.Second, 10*time.Millisecond)
17651765
func Never(t TestingT, condition func() bool, waitFor time.Duration, tick time.Duration, msgAndArgs ...interface{}) bool {
17661766
if h, ok := t.(tHelper); ok {
17671767
h.Helper()

0 commit comments

Comments
 (0)