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

Function EqualExportedValues

internal/testify/assert/assertions.go:610–649  ·  view source on GitHub ↗

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

608// assert.EqualExportedValues(t, S{1, 2}, S{1, 3}) => true
609// assert.EqualExportedValues(t, S{1, 2}, S{2, 3}) => false
610func EqualExportedValues(t TestingT, expected, actual interface{}, msgAndArgs ...interface{}) bool {
611 if h, ok := t.(tHelper); ok {
612 h.Helper()
613 }
614
615 aType := reflect.TypeOf(expected)
616 bType := reflect.TypeOf(actual)
617
618 if aType != bType {
619 return Fail(t, fmt.Sprintf("Types expected to match exactly\n\t%v != %v", aType, bType), msgAndArgs...)
620 }
621
622 if aType.Kind() == reflect.Ptr {
623 aType = aType.Elem()
624 }
625 if bType.Kind() == reflect.Ptr {
626 bType = bType.Elem()
627 }
628
629 if aType.Kind() != reflect.Struct {
630 return Fail(t, fmt.Sprintf("Types expected to both be struct or pointer to struct \n\t%v != %v", aType.Kind(), reflect.Struct), msgAndArgs...)
631 }
632
633 if bType.Kind() != reflect.Struct {
634 return Fail(t, fmt.Sprintf("Types expected to both be struct or pointer to struct \n\t%v != %v", bType.Kind(), reflect.Struct), msgAndArgs...)
635 }
636
637 expected = copyExportedFields(expected)
638 actual = copyExportedFields(actual)
639
640 if !ObjectsAreEqualValues(expected, actual) {
641 diff := diff(expected, actual)
642 expected, actual = formatUnequalValues(expected, actual)
643 return Fail(t, fmt.Sprintf("Not equal (comparing only exported fields): \n"+
644 "expected: %s\n"+
645 "actual : %s%s", expected, actual, diff), msgAndArgs...)
646 }
647
648 return true
649}
650
651// Exactly asserts that two objects are equal in value and type.
652//

Callers 4

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

Calls 8

copyExportedFieldsFunction · 0.85
ObjectsAreEqualValuesFunction · 0.85
diffFunction · 0.85
formatUnequalValuesFunction · 0.85
SprintfMethod · 0.80
ElemMethod · 0.80
FailFunction · 0.70
HelperMethod · 0.45

Tested by 1

TestEqualExportedValuesFunction · 0.56

Used in the wild real call sites across dependent graphs

searching dependent graphs…