Skip to content

Commit 1ee798c

Browse files
alexandeardolmen
authored andcommitted
Remove canConvert because Go 1.16 is dropped from support
1 parent 882382d commit 1ee798c

File tree

5 files changed

+17
-216
lines changed

5 files changed

+17
-216
lines changed

assert/assertion_compare.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ func compare(obj1, obj2 interface{}, kind reflect.Kind) (CompareType, bool) {
308308
case reflect.Struct:
309309
{
310310
// All structs enter here. We're not interested in most types.
311-
if !canConvert(obj1Value, timeType) {
311+
if !obj1Value.CanConvert(timeType) {
312312
break
313313
}
314314

@@ -328,7 +328,7 @@ func compare(obj1, obj2 interface{}, kind reflect.Kind) (CompareType, bool) {
328328
case reflect.Slice:
329329
{
330330
// We only care about the []byte type.
331-
if !canConvert(obj1Value, bytesType) {
331+
if !obj1Value.CanConvert(bytesType) {
332332
break
333333
}
334334

assert/assertion_compare_can_convert.go

Lines changed: 0 additions & 16 deletions
This file was deleted.

assert/assertion_compare_go1.17_test.go

Lines changed: 0 additions & 182 deletions
This file was deleted.

assert/assertion_compare_legacy.go

Lines changed: 0 additions & 16 deletions
This file was deleted.

assert/assertion_compare_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"reflect"
77
"runtime"
88
"testing"
9+
"time"
910
)
1011

1112
func TestCompare(t *testing.T) {
@@ -22,6 +23,8 @@ func TestCompare(t *testing.T) {
2223
type customFloat32 float32
2324
type customFloat64 float64
2425
type customString string
26+
type customTime time.Time
27+
type customBytes []byte
2528
for _, currCase := range []struct {
2629
less interface{}
2730
greater interface{}
@@ -52,6 +55,10 @@ func TestCompare(t *testing.T) {
5255
{less: customFloat32(1.23), greater: customFloat32(2.23), cType: "float32"},
5356
{less: float64(1.23), greater: float64(2.34), cType: "float64"},
5457
{less: customFloat64(1.23), greater: customFloat64(2.34), cType: "float64"},
58+
{less: time.Now(), greater: time.Now().Add(time.Hour), cType: "time.Time"},
59+
{less: customTime(time.Now()), greater: customTime(time.Now().Add(time.Hour)), cType: "time.Time"},
60+
{less: []byte{1, 1}, greater: []byte{1, 2}, cType: "[]byte"},
61+
{less: customBytes([]byte{1, 1}), greater: customBytes([]byte{1, 2}), cType: "[]byte"},
5562
} {
5663
resLess, isComparable := compare(currCase.less, currCase.greater, reflect.ValueOf(currCase.less).Kind())
5764
if !isComparable {
@@ -148,6 +155,8 @@ func TestGreater(t *testing.T) {
148155
{less: uint64(1), greater: uint64(2), msg: `"1" is not greater than "2"`},
149156
{less: float32(1.23), greater: float32(2.34), msg: `"1.23" is not greater than "2.34"`},
150157
{less: float64(1.23), greater: float64(2.34), msg: `"1.23" is not greater than "2.34"`},
158+
{less: []byte{1, 1}, greater: []byte{1, 2}, msg: `"[1 1]" is not greater than "[1 2]"`},
159+
{less: time.Time{}, greater: time.Time{}.Add(time.Hour), msg: `"0001-01-01 00:00:00 +0000 UTC" is not greater than "0001-01-01 01:00:00 +0000 UTC"`},
151160
} {
152161
out := &outputT{buf: bytes.NewBuffer(nil)}
153162
False(t, Greater(out, currCase.less, currCase.greater))
@@ -189,6 +198,8 @@ func TestGreaterOrEqual(t *testing.T) {
189198
{less: uint64(1), greater: uint64(2), msg: `"1" is not greater than or equal to "2"`},
190199
{less: float32(1.23), greater: float32(2.34), msg: `"1.23" is not greater than or equal to "2.34"`},
191200
{less: float64(1.23), greater: float64(2.34), msg: `"1.23" is not greater than or equal to "2.34"`},
201+
{less: []byte{1, 1}, greater: []byte{1, 2}, msg: `"[1 1]" is not greater than or equal to "[1 2]"`},
202+
{less: time.Time{}, greater: time.Time{}.Add(time.Hour), msg: `"0001-01-01 00:00:00 +0000 UTC" is not greater than or equal to "0001-01-01 01:00:00 +0000 UTC"`},
192203
} {
193204
out := &outputT{buf: bytes.NewBuffer(nil)}
194205
False(t, GreaterOrEqual(out, currCase.less, currCase.greater))
@@ -230,6 +241,8 @@ func TestLess(t *testing.T) {
230241
{less: uint64(1), greater: uint64(2), msg: `"2" is not less than "1"`},
231242
{less: float32(1.23), greater: float32(2.34), msg: `"2.34" is not less than "1.23"`},
232243
{less: float64(1.23), greater: float64(2.34), msg: `"2.34" is not less than "1.23"`},
244+
{less: []byte{1, 1}, greater: []byte{1, 2}, msg: `"[1 2]" is not less than "[1 1]"`},
245+
{less: time.Time{}, greater: time.Time{}.Add(time.Hour), msg: `"0001-01-01 01:00:00 +0000 UTC" is not less than "0001-01-01 00:00:00 +0000 UTC"`},
233246
} {
234247
out := &outputT{buf: bytes.NewBuffer(nil)}
235248
False(t, Less(out, currCase.greater, currCase.less))
@@ -271,6 +284,8 @@ func TestLessOrEqual(t *testing.T) {
271284
{less: uint64(1), greater: uint64(2), msg: `"2" is not less than or equal to "1"`},
272285
{less: float32(1.23), greater: float32(2.34), msg: `"2.34" is not less than or equal to "1.23"`},
273286
{less: float64(1.23), greater: float64(2.34), msg: `"2.34" is not less than or equal to "1.23"`},
287+
{less: []byte{1, 1}, greater: []byte{1, 2}, msg: `"[1 2]" is not less than or equal to "[1 1]"`},
288+
{less: time.Time{}, greater: time.Time{}.Add(time.Hour), msg: `"0001-01-01 01:00:00 +0000 UTC" is not less than or equal to "0001-01-01 00:00:00 +0000 UTC"`},
274289
} {
275290
out := &outputT{buf: bytes.NewBuffer(nil)}
276291
False(t, LessOrEqual(out, currCase.greater, currCase.less))

0 commit comments

Comments
 (0)