From ca24fae3b6044e5f30f190528de3021a3c1e8ec6 Mon Sep 17 00:00:00 2001 From: Harald Nordgren Date: Sat, 22 Apr 2023 09:30:02 +0200 Subject: [PATCH] Handle multiple values --- assert/assertions.go | 5 +++-- assert/assertions_test.go | 17 ++++++++++------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/assert/assertions.go b/assert/assertions.go index b589dc7d3..8b2ae04b5 100644 --- a/assert/assertions.go +++ b/assert/assertions.go @@ -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()) } diff --git a/assert/assertions_test.go b/assert/assertions_test.go index 3dd4ed0d2..b8863931c 100644 --- a/assert/assertions_test.go +++ b/assert/assertions_test.go @@ -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 { @@ -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 {