assert: handle array case in copyExportedFields #1404#1436
Closed
qerdcv wants to merge 1 commit intostretchr:masterfrom
qerdcv:bugfix/1404/assert-array
Closed
assert: handle array case in copyExportedFields #1404#1436qerdcv wants to merge 1 commit intostretchr:masterfrom qerdcv:bugfix/1404/assert-array
qerdcv wants to merge 1 commit intostretchr:masterfrom
qerdcv:bugfix/1404/assert-array
Conversation
Contributor
Author
|
Сheck it please, when you have time and inspiration |
dolmen
requested changes
Jul 31, 2023
| for i := 0; i < expectedValue.Len(); i++ { | ||
| index := expectedValue.Index(i) | ||
| if isNil(index) { | ||
| continue |
Collaborator
There was a problem hiding this comment.
This case is not covered by the test suite.
Contributor
Author
There was a problem hiding this comment.
Thanks!
I added one more test for nil-value, but it failed. I fixed it by passing an actual interface{} to the isNil function.
dolmen
requested changes
Aug 8, 2023
| continue | ||
| } | ||
| unexportedRemoved := copyExportedFields(index.Interface()) | ||
| result.Index(i).Set(reflect.ValueOf(unexportedRemoved)) |
Collaborator
There was a problem hiding this comment.
Suggested change
| result.Index(i).Set(reflect.ValueOf(unexportedRemoved)) | |
| index.Set(reflect.ValueOf(unexportedRemoved)) |
| Nested{[2]int{1, 2}, [2]int{3, 4}}, | ||
| }, | ||
| value2: S7{ | ||
| Nested{[2]interface{}{nil, 2}, [2]int{3, 4}}, |
Collaborator
There was a problem hiding this comment.
As nil is a special value which means anything matches, it would be better to use a concrete value here. Or better: add more test cases to validate that anything matches, not just that nil matches anything.
Collaborator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implemented reflect.Array handling in the copyExportedFields to prevent panic when trying to make a slice from an array
Changes
Creating new array and filling it with exported values following the example from reflect.Slice.
I've decide to copy paste some code from the reflect.Slice case to make the code more readable, straightforward and avoid mutating the existing case for reflect.Slice
Motivation
Fixing a bug described in the issue #1404
Related issues
#1404