MCPcopy
hub / github.com/expr-lang/expr / ObjectsAreEqualValues

Function ObjectsAreEqualValues

internal/testify/assert/assertions.go:162–194  ·  view source on GitHub ↗

ObjectsAreEqualValues gets whether two objects are equal, or if their values are equal.

(expected, actual interface{})

Source from the content-addressed store, hash-verified

160// ObjectsAreEqualValues gets whether two objects are equal, or if their
161// values are equal.
162func ObjectsAreEqualValues(expected, actual interface{}) bool {
163 if ObjectsAreEqual(expected, actual) {
164 return true
165 }
166
167 expectedValue := reflect.ValueOf(expected)
168 actualValue := reflect.ValueOf(actual)
169 if !expectedValue.IsValid() || !actualValue.IsValid() {
170 return false
171 }
172
173 expectedType := expectedValue.Type()
174 actualType := actualValue.Type()
175 if !expectedType.ConvertibleTo(actualType) {
176 return false
177 }
178
179 if !isNumericType(expectedType) || !isNumericType(actualType) {
180 // Attempt comparison after type conversion
181 return reflect.DeepEqual(
182 expectedValue.Convert(actualType).Interface(), actual,
183 )
184 }
185
186 // If BOTH values are numeric, there are chances of false positives due
187 // to overflow or underflow. So, we need to make sure to always convert
188 // the smaller type to a larger type before comparing.
189 if expectedType.Size() >= actualType.Size() {
190 return actualValue.Convert(expectedType).Interface() == expected
191 }
192
193 return expectedValue.Convert(actualType).Interface() == actual
194}
195
196// isNumericType returns true if the type is one of:
197// int, int8, int16, int32, int64, uint, uint8, uint16, uint32, uint64,

Callers 6

TestCopyExportedFieldsFunction · 0.85
EqualValuesFunction · 0.85
EqualExportedValuesFunction · 0.85
NotEqualValuesFunction · 0.85

Calls 4

ObjectsAreEqualFunction · 0.85
isNumericTypeFunction · 0.85
SizeMethod · 0.80
TypeMethod · 0.65

Tested by 2

TestCopyExportedFieldsFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…