mirror of https://github.com/stretchr/testify.git
Fix bug where array is treated as slice in EqualExportedValues
parent
ce5c2b684b
commit
2f7efa2451
|
@ -114,7 +114,19 @@ func copyExportedFields(expected interface{}) interface{} {
|
||||||
result.Elem().Set(reflect.ValueOf(unexportedRemoved))
|
result.Elem().Set(reflect.ValueOf(unexportedRemoved))
|
||||||
return result.Interface()
|
return result.Interface()
|
||||||
|
|
||||||
case reflect.Array, reflect.Slice:
|
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))
|
||||||
|
}
|
||||||
|
return result.Interface()
|
||||||
|
|
||||||
|
case reflect.Slice:
|
||||||
result := reflect.MakeSlice(expectedType, expectedValue.Len(), expectedValue.Len())
|
result := reflect.MakeSlice(expectedType, expectedValue.Len(), expectedValue.Len())
|
||||||
for i := 0; i < expectedValue.Len(); i++ {
|
for i := 0; i < expectedValue.Len(); i++ {
|
||||||
index := expectedValue.Index(i)
|
index := expectedValue.Index(i)
|
||||||
|
|
|
@ -408,6 +408,11 @@ func TestEqualExportedValues(t *testing.T) {
|
||||||
+ Exported: (int) 2,
|
+ Exported: (int) 2,
|
||||||
notExported: (interface {}) <nil>`,
|
notExported: (interface {}) <nil>`,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
value1: S{[2]int{1, 2}, Nested{2, 3}, 4, Nested{5, 6}},
|
||||||
|
value2: S{[2]int{1, 2}, Nested{2, nil}, nil, Nested{}},
|
||||||
|
expectedEqual: true,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, c := range cases {
|
for _, c := range cases {
|
||||||
|
|
Loading…
Reference in New Issue