testify icon indicating copy to clipboard operation
testify copied to clipboard

ObjectsAreEqual: improve list/map support

Open harryzcy opened this issue 4 years ago • 2 comments

Summary

Function ObjectsAreEqual now compares two objects of type array/slice/map by iterating over each element. When two objects contain the same value but have different types, the function will now return true.

Changes

  • The function ObjectsAreEqualValues in assertion.go is changed.
  • Two helper functions listsAreEqualValues and mapsAreEqualValues are added.
  • Tests are added accordingly.

Motivation

Currently, assert.EqualValues would fail when two objects are of type array/slice/map and contain values of different types.

// assert would fail
assert.EqualValues(t, []interface{}{1}, []interface{}{int64(1)})

But, assert.EqualValues should always compare objects by value. So the above code should idealy pass.

Related issues

Closes #1057

harryzcy avatar Mar 01 '21 19:03 harryzcy

Hi @harryzcy,

Thanks for your fix. Do you have any idea when this fix will be released?

joselitofilho avatar Mar 04 '24 00:03 joselitofilho

Hi @harryzcy,

Thanks for your fix. Do you have any idea when this fix will be released?

No, I don't know when maintainers will review them.

harryzcy avatar Mar 04 '24 01:03 harryzcy