-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
assert: handle array case in copyExportedFields #1404 #1436
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -109,7 +109,19 @@ func copyExportedFields(expected interface{}) interface{} { | |||||
result.Elem().Set(reflect.ValueOf(unexportedRemoved)) | ||||||
return result.Interface() | ||||||
|
||||||
case reflect.Array, reflect.Slice: | ||||||
case reflect.Array: | ||||||
result := reflect.New(expectedType).Elem() | ||||||
for i := 0; i < expectedValue.Len(); i++ { | ||||||
index := expectedValue.Index(i) | ||||||
if isNil(index.Interface()) { | ||||||
continue | ||||||
} | ||||||
unexportedRemoved := copyExportedFields(index.Interface()) | ||||||
result.Index(i).Set(reflect.ValueOf(unexportedRemoved)) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
} | ||||||
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) | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -184,6 +184,11 @@ type S6 struct { | |
unexported string | ||
} | ||
|
||
type S7 struct { | ||
Exported Nested | ||
unexported Nested | ||
} | ||
|
||
func TestObjectsExportedFieldsAreEqual(t *testing.T) { | ||
|
||
intValue := 1 | ||
|
@@ -402,6 +407,72 @@ func TestEqualExportedValues(t *testing.T) { | |
+ Exported: (int) 2, | ||
notExported: (interface {}) <nil>`, | ||
}, | ||
{ | ||
value1: S7{ | ||
Nested{[2]int{1, 2}, [2]int{1, 2}}, | ||
Nested{[2]int{1, 2}, [2]int{3, 4}}, | ||
}, | ||
value2: S7{ | ||
Nested{[3]int{1, 2, 3}, [2]int{3, 4}}, | ||
Nested{[2]int{5, 6}, [2]int{7, 8}}, | ||
}, | ||
expectedEqual: false, | ||
expectedFail: ` | ||
Diff: | ||
--- Expected | ||
+++ Actual | ||
@@ -2,5 +2,6 @@ | ||
Exported: (assert.Nested) { | ||
- Exported: ([2]int) (len=2) { | ||
+ Exported: ([3]int) (len=3) { | ||
(int) 1, | ||
- (int) 2 | ||
+ (int) 2, | ||
+ (int) 3 | ||
},`, | ||
}, | ||
{ | ||
value1: S7{ | ||
Nested{[2]int{1, 2}, [2]int{1, 2}}, | ||
Nested{[2]int{1, 2}, [2]int{3, 4}}, | ||
}, | ||
value2: S7{ | ||
Nested{[2]int{1, 3}, [2]int{3, 4}}, | ||
Nested{[2]int{5, 6}, [2]int{7, 8}}, | ||
}, | ||
expectedEqual: false, | ||
expectedFail: ` | ||
Diff: | ||
--- Expected | ||
+++ Actual | ||
@@ -4,3 +4,3 @@ | ||
(int) 1, | ||
- (int) 2 | ||
+ (int) 3 | ||
},`, | ||
}, | ||
{ | ||
value1: S7{ | ||
Nested{[2]interface{}{nil, 2}, [2]int{1, 2}}, | ||
Nested{[2]int{1, 2}, [2]int{3, 4}}, | ||
}, | ||
value2: S7{ | ||
Nested{[2]interface{}{nil, 2}, [2]int{3, 4}}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As |
||
Nested{[2]int{5, 6}, [2]int{7, 8}}, | ||
}, | ||
expectedEqual: true, | ||
}, | ||
{ | ||
value1: S7{ | ||
Nested{[2]int{1, 2}, [2]int{1, 2}}, | ||
Nested{[2]int{1, 2}, [2]int{3, 4}}, | ||
}, | ||
value2: S7{ | ||
Nested{[2]int{1, 2}, [2]int{3, 4}}, | ||
Nested{[2]int{5, 6}, [2]int{7, 8}}, | ||
}, | ||
expectedEqual: true, | ||
}, | ||
} | ||
|
||
for _, c := range cases { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This case is not covered by the test suite.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
I added one more test for nil-value, but it failed. I fixed it by passing an actual
interface{}
to the isNil function.