MCPcopy
hub / github.com/stretchr/testify / EqualExportedValues

Function EqualExportedValues

assert/assertions.go:660–684  ·  assert/assertions.go::EqualExportedValues

EqualExportedValues asserts that the types of two objects are equal and their public fields are also equal. This is useful for comparing structs that have private fields that could potentially differ. type S struct { Exported int notExported int } assert.EqualExportedValues(t, S{1

(t TestingT, expected, actual interface{}, msgAndArgs ...interface{})

Source from the content-addressed store, hash-verified

658// assert.EqualExportedValues(t, S{1, 2}, S{1, 3}) => true
659// assert.EqualExportedValues(t, S{1, 2}, S{2, 3}) => false
660func EqualExportedValues(t TestingT, expected, actual interface{}, msgAndArgs ...interface{}) bool {
661 if h, ok := t.(tHelper); ok {
662 h.Helper()
663 }
664
665 aType := reflect.TypeOf(expected)
666 bType := reflect.TypeOf(actual)
667
668 if aType != bType {
669 return Fail(t, fmt.Sprintf("Types expected to match exactly\n\t%v != %v", aType, bType), msgAndArgs...)
670 }
671
672 expected = copyExportedFields(expected)
673 actual = copyExportedFields(actual)
674
675 if !ObjectsAreEqualValues(expected, actual) {
676 diff := diff(expected, actual)
677 expected, actual = formatUnequalValues(expected, actual)
678 return Fail(t, fmt.Sprintf("Not equal (comparing only exported fields): \n"+
679 "expected: %s\n"+
680 "actual : %s%s", expected, actual, diff), msgAndArgs...)
681 }
682
683 return true
684}
685
686// Exactly asserts that two objects are equal in value and type.
687//

Callers 4

EqualExportedValuesFunction · 0.92
EqualExportedValuesfFunction · 0.70
TestEqualExportedValuesFunction · 0.70
EqualExportedValuesMethod · 0.70

Calls 6

copyExportedFieldsFunction · 0.85
ObjectsAreEqualValuesFunction · 0.85
formatUnequalValuesFunction · 0.85
FailFunction · 0.70
diffFunction · 0.70
HelperMethod · 0.65

Tested by 1

TestEqualExportedValuesFunction · 0.56