assert: allow comparing time.Time · stretchr/testify@087b655

@@ -6,6 +6,7 @@ import (

66

"reflect"

77

"runtime"

88

"testing"

9+

"time"

910

)

10111112

func TestCompare(t *testing.T) {

@@ -22,6 +23,7 @@ func TestCompare(t *testing.T) {

2223

type customFloat32 float32

2324

type customFloat64 float64

2425

type customString string

26+

type customTime time.Time

2527

for _, currCase := range []struct {

2628

less interface{}

2729

greater interface{}

@@ -52,14 +54,17 @@ func TestCompare(t *testing.T) {

5254

{less: customFloat32(1.23), greater: customFloat32(2.23), cType: "float32"},

5355

{less: float64(1.23), greater: float64(2.34), cType: "float64"},

5456

{less: customFloat64(1.23), greater: customFloat64(2.34), cType: "float64"},

57+

{less: time.Now(), greater: time.Now().Add(time.Hour), cType: "time.Time"},

58+

{less: customTime(time.Now()), greater: customTime(time.Now().Add(time.Hour)), cType: "time.Time"},

5559

} {

5660

resLess, isComparable := compare(currCase.less, currCase.greater, reflect.ValueOf(currCase.less).Kind())

5761

if !isComparable {

5862

t.Error("object should be comparable for type " + currCase.cType)

5963

}

60646165

if resLess != compareLess {

62-

t.Errorf("object less should be less than greater for type " + currCase.cType)

66+

t.Errorf("object less (%v) should be less than greater (%v) for type "+currCase.cType,

67+

currCase.less, currCase.greater)

6368

}

64696570

resGreater, isComparable := compare(currCase.greater, currCase.less, reflect.ValueOf(currCase.less).Kind())