Skip to content

Commit

Permalink
Combine switch cases, difference wrapped in if statement
Browse files Browse the repository at this point in the history
  • Loading branch information
zrbecker authored and dolmen committed Oct 15, 2023
1 parent 2f7efa2 commit 4ae48e9
Showing 1 changed file with 6 additions and 13 deletions.
19 changes: 6 additions & 13 deletions assert/assertions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 4ae48e9

Please sign in to comment.