Skip to content

Commit c3672b7

Browse files
committed
Replace all uses of 'interface{}' with 'any' in the internal/ packages.
1 parent 056ba3c commit c3672b7

30 files changed

+317
-317
lines changed

internal/assert/assertion_compare.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ var (
4343
bytesType = reflect.TypeOf([]byte{})
4444
)
4545

46-
func compare(obj1, obj2 interface{}, kind reflect.Kind) (CompareType, bool) {
46+
func compare(obj1, obj2 any, kind reflect.Kind) (CompareType, bool) {
4747
obj1Value := reflect.ValueOf(obj1)
4848
obj2Value := reflect.ValueOf(obj2)
4949

@@ -361,7 +361,7 @@ func compare(obj1, obj2 interface{}, kind reflect.Kind) (CompareType, bool) {
361361
// assert.Greater(t, 2, 1)
362362
// assert.Greater(t, float64(2), float64(1))
363363
// assert.Greater(t, "b", "a")
364-
func Greater(t TestingT, e1 interface{}, e2 interface{}, msgAndArgs ...interface{}) bool {
364+
func Greater(t TestingT, e1 any, e2 any, msgAndArgs ...any) bool {
365365
if h, ok := t.(tHelper); ok {
366366
h.Helper()
367367
}
@@ -374,7 +374,7 @@ func Greater(t TestingT, e1 interface{}, e2 interface{}, msgAndArgs ...interface
374374
// assert.GreaterOrEqual(t, 2, 2)
375375
// assert.GreaterOrEqual(t, "b", "a")
376376
// assert.GreaterOrEqual(t, "b", "b")
377-
func GreaterOrEqual(t TestingT, e1 interface{}, e2 interface{}, msgAndArgs ...interface{}) bool {
377+
func GreaterOrEqual(t TestingT, e1 any, e2 any, msgAndArgs ...any) bool {
378378
if h, ok := t.(tHelper); ok {
379379
h.Helper()
380380
}
@@ -386,7 +386,7 @@ func GreaterOrEqual(t TestingT, e1 interface{}, e2 interface{}, msgAndArgs ...in
386386
// assert.Less(t, 1, 2)
387387
// assert.Less(t, float64(1), float64(2))
388388
// assert.Less(t, "a", "b")
389-
func Less(t TestingT, e1 interface{}, e2 interface{}, msgAndArgs ...interface{}) bool {
389+
func Less(t TestingT, e1 any, e2 any, msgAndArgs ...any) bool {
390390
if h, ok := t.(tHelper); ok {
391391
h.Helper()
392392
}
@@ -399,7 +399,7 @@ func Less(t TestingT, e1 interface{}, e2 interface{}, msgAndArgs ...interface{})
399399
// assert.LessOrEqual(t, 2, 2)
400400
// assert.LessOrEqual(t, "a", "b")
401401
// assert.LessOrEqual(t, "b", "b")
402-
func LessOrEqual(t TestingT, e1 interface{}, e2 interface{}, msgAndArgs ...interface{}) bool {
402+
func LessOrEqual(t TestingT, e1 any, e2 any, msgAndArgs ...any) bool {
403403
if h, ok := t.(tHelper); ok {
404404
h.Helper()
405405
}
@@ -410,7 +410,7 @@ func LessOrEqual(t TestingT, e1 interface{}, e2 interface{}, msgAndArgs ...inter
410410
//
411411
// assert.Positive(t, 1)
412412
// assert.Positive(t, 1.23)
413-
func Positive(t TestingT, e interface{}, msgAndArgs ...interface{}) bool {
413+
func Positive(t TestingT, e any, msgAndArgs ...any) bool {
414414
if h, ok := t.(tHelper); ok {
415415
h.Helper()
416416
}
@@ -422,15 +422,15 @@ func Positive(t TestingT, e interface{}, msgAndArgs ...interface{}) bool {
422422
//
423423
// assert.Negative(t, -1)
424424
// assert.Negative(t, -1.23)
425-
func Negative(t TestingT, e interface{}, msgAndArgs ...interface{}) bool {
425+
func Negative(t TestingT, e any, msgAndArgs ...any) bool {
426426
if h, ok := t.(tHelper); ok {
427427
h.Helper()
428428
}
429429
zero := reflect.Zero(reflect.TypeOf(e))
430430
return compareTwoValues(t, e, zero.Interface(), []CompareType{compareLess}, "\"%v\" is not negative", msgAndArgs...)
431431
}
432432

433-
func compareTwoValues(t TestingT, e1 interface{}, e2 interface{}, allowedComparesResults []CompareType, failMessage string, msgAndArgs ...interface{}) bool {
433+
func compareTwoValues(t TestingT, e1 any, e2 any, allowedComparesResults []CompareType, failMessage string, msgAndArgs ...any) bool {
434434
if h, ok := t.(tHelper); ok {
435435
h.Helper()
436436
}

internal/assert/assertion_compare_go1.17_test.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ func TestCompare17(t *testing.T) {
2020
type customTime time.Time
2121
type customBytes []byte
2222
for _, currCase := range []struct {
23-
less interface{}
24-
greater interface{}
23+
less any
24+
greater any
2525
cType string
2626
}{
2727
{less: time.Now(), greater: time.Now().Add(time.Hour), cType: "time.Time"},
@@ -76,8 +76,8 @@ func TestGreater17(t *testing.T) {
7676

7777
// Check error report
7878
for _, currCase := range []struct {
79-
less interface{}
80-
greater interface{}
79+
less any
80+
greater any
8181
msg string
8282
}{
8383
{less: []byte{1, 1}, greater: []byte{1, 2}, msg: `"[1 1]" is not greater than "[1 2]"`},
@@ -107,8 +107,8 @@ func TestGreaterOrEqual17(t *testing.T) {
107107

108108
// Check error report
109109
for _, currCase := range []struct {
110-
less interface{}
111-
greater interface{}
110+
less any
111+
greater any
112112
msg string
113113
}{
114114
{less: []byte{1, 1}, greater: []byte{1, 2}, msg: `"[1 1]" is not greater than or equal to "[1 2]"`},
@@ -138,8 +138,8 @@ func TestLess17(t *testing.T) {
138138

139139
// Check error report
140140
for _, currCase := range []struct {
141-
less interface{}
142-
greater interface{}
141+
less any
142+
greater any
143143
msg string
144144
}{
145145
{less: []byte{1, 1}, greater: []byte{1, 2}, msg: `"[1 2]" is not less than "[1 1]"`},
@@ -169,8 +169,8 @@ func TestLessOrEqual17(t *testing.T) {
169169

170170
// Check error report
171171
for _, currCase := range []struct {
172-
less interface{}
173-
greater interface{}
172+
less any
173+
greater any
174174
msg string
175175
}{
176176
{less: []byte{1, 1}, greater: []byte{1, 2}, msg: `"[1 2]" is not less than or equal to "[1 1]"`},

internal/assert/assertion_compare_test.go

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ func TestCompare(t *testing.T) {
2929
type customFloat64 float64
3030
type customString string
3131
for _, currCase := range []struct {
32-
less interface{}
33-
greater interface{}
32+
less any
33+
greater any
3434
cType string
3535
}{
3636
{less: customString("a"), greater: customString("b"), cType: "string"},
@@ -95,7 +95,7 @@ type outputT struct {
9595
}
9696

9797
// Implements TestingT
98-
func (t *outputT) Errorf(format string, args ...interface{}) {
98+
func (t *outputT) Errorf(format string, args ...any) {
9999
s := fmt.Sprintf(format, args...)
100100
t.buf.WriteString(s)
101101
}
@@ -138,8 +138,8 @@ func TestGreater(t *testing.T) {
138138

139139
// Check error report
140140
for _, currCase := range []struct {
141-
less interface{}
142-
greater interface{}
141+
less any
142+
greater any
143143
msg string
144144
}{
145145
{less: "a", greater: "b", msg: `"a" is not greater than "b"`},
@@ -179,8 +179,8 @@ func TestGreaterOrEqual(t *testing.T) {
179179

180180
// Check error report
181181
for _, currCase := range []struct {
182-
less interface{}
183-
greater interface{}
182+
less any
183+
greater any
184184
msg string
185185
}{
186186
{less: "a", greater: "b", msg: `"a" is not greater than or equal to "b"`},
@@ -220,8 +220,8 @@ func TestLess(t *testing.T) {
220220

221221
// Check error report
222222
for _, currCase := range []struct {
223-
less interface{}
224-
greater interface{}
223+
less any
224+
greater any
225225
msg string
226226
}{
227227
{less: "a", greater: "b", msg: `"b" is not less than "a"`},
@@ -261,8 +261,8 @@ func TestLessOrEqual(t *testing.T) {
261261

262262
// Check error report
263263
for _, currCase := range []struct {
264-
less interface{}
265-
greater interface{}
264+
less any
265+
greater any
266266
msg string
267267
}{
268268
{less: "a", greater: "b", msg: `"b" is not less than or equal to "a"`},
@@ -306,7 +306,7 @@ func TestPositive(t *testing.T) {
306306

307307
// Check error report
308308
for _, currCase := range []struct {
309-
e interface{}
309+
e any
310310
msg string
311311
}{
312312
{e: int(-1), msg: `"-1" is not positive`},
@@ -345,7 +345,7 @@ func TestNegative(t *testing.T) {
345345

346346
// Check error report
347347
for _, currCase := range []struct {
348-
e interface{}
348+
e any
349349
msg string
350350
}{
351351
{e: int(1), msg: `"1" is not negative`},
@@ -367,8 +367,8 @@ func Test_compareTwoValuesDifferentValuesTypes(t *testing.T) {
367367
mockT := new(testing.T)
368368

369369
for _, currCase := range []struct {
370-
v1 interface{}
371-
v2 interface{}
370+
v1 any
371+
v2 any
372372
compareResult bool
373373
}{
374374
{v1: 123, v2: "abc"},
@@ -388,8 +388,8 @@ func Test_compareTwoValuesNotComparableValues(t *testing.T) {
388388
}
389389

390390
for _, currCase := range []struct {
391-
v1 interface{}
392-
v2 interface{}
391+
v1 any
392+
v2 any
393393
}{
394394
{v1: CompareStruct{}, v2: CompareStruct{}},
395395
{v1: map[string]int{}, v2: map[string]int{}},
@@ -404,8 +404,8 @@ func Test_compareTwoValuesCorrectCompareResult(t *testing.T) {
404404
mockT := new(testing.T)
405405

406406
for _, currCase := range []struct {
407-
v1 interface{}
408-
v2 interface{}
407+
v1 any
408+
v2 any
409409
compareTypes []CompareType
410410
}{
411411
{v1: 1, v2: 2, compareTypes: []CompareType{compareLess}},
@@ -437,7 +437,7 @@ func Test_containsValue(t *testing.T) {
437437
}
438438

439439
func TestComparingMsgAndArgsForwarding(t *testing.T) {
440-
msgAndArgs := []interface{}{"format %s %x", "this", 0xc001}
440+
msgAndArgs := []any{"format %s %x", "this", 0xc001}
441441
expectedOutput := "format this c001\n"
442442
funcs := []func(t TestingT){
443443
func(t TestingT) { Greater(t, 1, 2, msgAndArgs...) },

0 commit comments

Comments
 (0)