From 4ae48e988c8c84c138d688eba40bfc869f4be907 Mon Sep 17 00:00:00 2001 From: Zachary Becker Date: Sun, 15 Oct 2023 17:45:52 -0500 Subject: [PATCH] Combine switch cases, difference wrapped in if statement --- assert/assertions.go | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/assert/assertions.go b/assert/assertions.go index 4d669d734..1e55fbf54 100644 --- a/assert/assertions.go +++ b/assert/assertions.go @@ -114,20 +114,13 @@ func copyExportedFields(expected interface{}) interface{} { result.Elem().Set(reflect.ValueOf(unexportedRemoved)) return result.Interface() - case reflect.Array: - result := reflect.New(reflect.ArrayOf(expectedValue.Len(), expectedType.Elem())).Elem() - for i := 0; i < expectedValue.Len(); i++ { - index := expectedValue.Index(i) - if isNil(index) { - continue - } - unexportedRemoved := copyExportedFields(index.Interface()) - result.Index(i).Set(reflect.ValueOf(unexportedRemoved)) + case reflect.Array, reflect.Slice: + var result reflect.Value + if expectedKind == reflect.Array { + result = reflect.New(reflect.ArrayOf(expectedValue.Len(), expectedType.Elem())).Elem() + } else { + result = reflect.MakeSlice(expectedType, expectedValue.Len(), expectedValue.Len()) } - return result.Interface() - - case reflect.Slice: - result := reflect.MakeSlice(expectedType, expectedValue.Len(), expectedValue.Len()) for i := 0; i < expectedValue.Len(); i++ { index := expectedValue.Index(i) if isNil(index) {