Skip to content
This repository has been archived by the owner on Mar 14, 2020. It is now read-only.

Commit

Permalink
Merge pull request #4 from C2FO/equals
Browse files Browse the repository at this point in the history
Merge Equal and EqualValues together
  • Loading branch information
TechnotronicOz committed Aug 27, 2015
2 parents 3e467a3 + 711031b commit fba9636
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 16 deletions.
22 changes: 6 additions & 16 deletions assert/assertions.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,14 +236,16 @@ func IsType(t TestingT, expectedType interface{}, object interface{}, msgAndArgs
return true
}

// Equal asserts that two objects are equal.
// Equal asserts that two objects are equal or convertable to the same types and equal.
//
// assert.Equal(t, 123, 123, "123 and 123 should be equal")
// assert.Equal(t, uint32(123), int32(123), "123 and 123 should be equal")
//
// Returns whether the assertion was successful (true) or not (false).
func Equal(t TestingT, expected, actual interface{}, msgAndArgs ...interface{}) bool {

if !ObjectsAreEqual(expected, actual) {
// still calls ObjectsAreEqual
if !ObjectsAreEqualValues(expected, actual) {
return Fail(t, fmt.Sprintf("Not equal: %#v (expected)\n"+
" != %#v (actual)", expected, actual), msgAndArgs...)
}
Expand All @@ -252,21 +254,9 @@ func Equal(t TestingT, expected, actual interface{}, msgAndArgs ...interface{})

}

// EqualValues asserts that two objects are equal or convertable to the same types
// and equal.
//
// assert.EqualValues(t, uint32(123), int32(123), "123 and 123 should be equal")
//
// Returns whether the assertion was successful (true) or not (false).
// Deprecated, use .Equal instead
func EqualValues(t TestingT, expected, actual interface{}, msgAndArgs ...interface{}) bool {

if !ObjectsAreEqualValues(expected, actual) {
return Fail(t, fmt.Sprintf("Not equal: %#v (expected)\n"+
" != %#v (actual)", expected, actual), msgAndArgs...)
}

return true

return Equal(t, expected, actual, msgAndArgs...)
}

// Exactly asserts that two objects are equal is value and type.
Expand Down
6 changes: 6 additions & 0 deletions assert/assertions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,12 @@ func TestEqual(t *testing.T) {
if !Equal(mockT, uint64(123), uint64(123)) {
t.Error("Equal should return true")
}
if !Equal(mockT, uint32(1), int32(1)) {
t.Error("Equal should return true")
}
if !Equal(mockT, int64(1001), uint32(1001)) {
t.Error("Equal should return true")
}

}

Expand Down

0 comments on commit fba9636

Please sign in to comment.