-
Notifications
You must be signed in to change notification settings - Fork 61
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
Fix EncOption/DecOption unset fields on mode regurgitation. #480
Merged
fxamacker
merged 1 commit into
fxamacker:master
from
benluddy:options-mode-options-roundtrip-fix
Feb 4, 2024
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3623,6 +3623,23 @@ func TestEncModeInvalidBigIntConvertMode(t *testing.T) { | |
} | ||
} | ||
|
||
func TestEncOptionsTagsForbidden(t *testing.T) { | ||
// It's not valid to set both TagsMd and TimeTag to a non-zero value in the same EncOptions, | ||
// so this exercises the options-mode-options roundtrip for non-zero TagsMd. | ||
opts1 := EncOptions{ | ||
TagsMd: TagsForbidden, | ||
} | ||
em, err := opts1.EncMode() | ||
if err != nil { | ||
t.Errorf("EncMode() returned an error %v", err) | ||
} else { | ||
opts2 := em.EncOptions() | ||
if !reflect.DeepEqual(opts1, opts2) { | ||
t.Errorf("EncOptions->EncMode->EncOptions returned different values: %#v, %#v", opts1, opts2) | ||
} | ||
} | ||
} | ||
|
||
func TestEncOptions(t *testing.T) { | ||
opts1 := EncOptions{ | ||
Sort: SortBytewiseLexical, | ||
|
@@ -3633,16 +3650,33 @@ func TestEncOptions(t *testing.T) { | |
Time: TimeRFC3339Nano, | ||
TimeTag: EncTagRequired, | ||
IndefLength: IndefLengthForbidden, | ||
NilContainers: NilContainerAsNull, | ||
NilContainers: NilContainerAsEmpty, | ||
TagsMd: TagsAllowed, | ||
OmitEmpty: OmitEmptyGoValue, | ||
String: StringToByteString, | ||
FieldName: FieldNameToByteString, | ||
} | ||
ov := reflect.ValueOf(opts1) | ||
for i := 0; i < ov.NumField(); i++ { | ||
fv := ov.Field(i) | ||
if fv.IsZero() { | ||
fn := ov.Type().Field(i).Name | ||
if fn == "TagsMd" { | ||
// Roundtripping non-zero values for TagsMd is tested separately | ||
// since the non-zero value (TagsForbidden) is incompatible with the | ||
// non-zero value for other options (e.g. TimeTag). | ||
Comment on lines
+3665
to
+3667
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. Thank you for adding this detailed comment! 👍 |
||
continue | ||
} | ||
t.Errorf("options field %q is unset or set to the zero value for its type", fn) | ||
} | ||
} | ||
em, err := opts1.EncMode() | ||
if err != nil { | ||
t.Errorf("EncMode() returned an error %v", err) | ||
} else { | ||
opts2 := em.EncOptions() | ||
if !reflect.DeepEqual(opts1, opts2) { | ||
t.Errorf("EncOptions->EncMode->EncOptions returned different values: %v, %v", opts1, opts2) | ||
t.Errorf("EncOptions->EncMode->EncOptions returned different values: %#v, %#v", opts1, opts2) | ||
} | ||
} | ||
} | ||
|
Oops, something went wrong.
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.
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.
Thank you for checking for zero value option programmatically! 👍