Skip to content

Commit

Permalink
Merge pull request #1537 from stretchr/fix-time-equal
Browse files Browse the repository at this point in the history
Revert "assert: ObjectsAreEqual: use time.Equal for time.Time type"
  • Loading branch information
brackendawson committed Feb 19, 2024
2 parents 14ffa90 + 7b3de08 commit fef12e7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 19 deletions.
29 changes: 12 additions & 17 deletions assert/assertions.go
Expand Up @@ -59,25 +59,20 @@ func ObjectsAreEqual(expected, actual interface{}) bool {
if expected == nil || actual == nil {
return expected == actual
}
switch exp := expected.(type) {
case []byte:
act, ok := actual.([]byte)
if !ok {
return false
}
if exp == nil || act == nil {
return exp == nil && act == nil
}
return bytes.Equal(exp, act)
case time.Time:
act, ok := actual.(time.Time)
if !ok {
return false
}
return exp.Equal(act)
default:

exp, ok := expected.([]byte)
if !ok {
return reflect.DeepEqual(expected, actual)
}

act, ok := actual.([]byte)
if !ok {
return false
}
if exp == nil || act == nil {
return exp == nil && act == nil
}
return bytes.Equal(exp, act)
}

// copyExportedFields iterates downward through nested data structures and creates a copy
Expand Down
4 changes: 2 additions & 2 deletions assert/assertions_test.go
Expand Up @@ -148,8 +148,8 @@ func TestObjectsAreEqualValues(t *testing.T) {
{uint32(10), int32(10), true},
{0, nil, false},
{nil, 0, false},
{now, now.In(time.Local), true}, // should be time zone independent
{int(270), int8(14), false}, // should handle overflow/underflow
{now, now.In(time.Local), false}, // should not be time zone independent
{int(270), int8(14), false}, // should handle overflow/underflow
{int8(14), int(270), false},
{[]int{270, 270}, []int8{14, 14}, false},
{complex128(1e+100 + 1e+100i), complex64(complex(math.Inf(0), math.Inf(0))), false},
Expand Down

0 comments on commit fef12e7

Please sign in to comment.