Skip to content

Commit

Permalink
Handle multiple values
Browse files Browse the repository at this point in the history
  • Loading branch information
HaraldNordgren committed Apr 22, 2023
1 parent fe1ef96 commit ca24fae
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
5 changes: 3 additions & 2 deletions assert/assertions.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,10 @@ func ObjectsExportedFieldsAreEqual(expected, actual interface{}) bool {
equal = ObjectsExportedFieldsAreEqual(expectedField.Interface(), actualField.Interface())
case reflect.Ptr:
if expectedField.IsNil() || actualField.IsNil() {
return expectedField == actualField
equal = ObjectsAreEqualValues(expectedField.Elem(), actualField.Elem())
} else {
equal = ObjectsExportedFieldsAreEqual(expectedField.Elem().Interface(), actualField.Elem().Interface())
}
equal = ObjectsExportedFieldsAreEqual(expectedField.Elem().Interface(), actualField.Elem().Interface())
default:
equal = ObjectsAreEqualValues(expectedField.Interface(), actualField.Interface())
}
Expand Down
17 changes: 10 additions & 7 deletions assert/assertions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,9 @@ func TestObjectsExportedFieldsAreEqual(t *testing.T) {
foo interface{}
}

type S3 struct {
ExportedPointer *Nested
type SP struct {
Exported1 *Nested
Exported2 *Nested
}

cases := []struct {
Expand All @@ -184,11 +185,13 @@ func TestObjectsExportedFieldsAreEqual(t *testing.T) {
{S{1, Nested{2, 3}, 4, Nested{5, 6}}, S{1, Nested{"a", 3}, 4, Nested{5, 6}}, false},
{S{1, Nested{2, 3}, 4, Nested{5, 6}}, S2{1}, false},
{1, S{1, Nested{2, 3}, 4, Nested{5, 6}}, false},
{S3{&Nested{2, 3}}, S3{&Nested{2, 3}}, true},
{S3{&Nested{2, 3}}, S3{&Nested{2, 4}}, true},
{S3{&Nested{2, 3}}, S3{&Nested{"a", 3}}, false},
{S3{&Nested{2, 3}}, S3{}, false},
{S3{}, S3{}, true},
{SP{&Nested{1, 2}, &Nested{3, 4}}, SP{&Nested{1, 2}, &Nested{3, 4}}, true},
{SP{nil, &Nested{3, 4}}, SP{nil, &Nested{3, 4}}, true},
{SP{&Nested{1, 2}, &Nested{3, 4}}, SP{&Nested{1, 2}, &Nested{3, "b"}}, true},
{SP{&Nested{1, 2}, &Nested{3, 4}}, SP{&Nested{1, "a"}, &Nested{3, "b"}}, true},
{SP{&Nested{1, 2}, &Nested{3, 4}}, SP{&Nested{"a", 2}, &Nested{3, 4}}, false},
{SP{&Nested{1, 2}, &Nested{3, 4}}, SP{}, false},
{SP{}, SP{}, true},
}

for _, c := range cases {
Expand Down

0 comments on commit ca24fae

Please # to comment.