-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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 int/float conversion to bool #2893
Conversation
This is a breaking change, which would affect everyone using bools. Can you add tests for this change? |
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.
One comment. Can you also fix the empty string -> bool conversion?
Reviewed 1 of 1 files at r1, 1 of 1 files at r2.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @srfrog and @gitlw)
types/conversion_test.go, line 218 at r2 (raw file):
{in: Val{Tid: StringID, Value: []byte("False")}, out: Val{Tid: BoolID, Value: false}}, {in: Val{Tid: StringID, Value: []byte("srfrog")}, fail: true}, {in: Val{Tid: StringID, Value: []byte("")}, fail: true},
Shouldn't this be false? Empty string is the default in string. False is the default in bool.
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.
Reviewable status: 0 of 2 files reviewed, 1 unresolved discussion (waiting on @manishrjain and @gitlw)
types/conversion_test.go, line 218 at r2 (raw file):
Previously, manishrjain (Manish R Jain) wrote…
Shouldn't this be false? Empty string is the default in string. False is the default in bool.
Done.
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.
Try to make tests go in one line.
Reviewable status: 0 of 2 files reviewed, 1 unresolved discussion (waiting on @manishrjain)
* fix conversion from int/float to bool to make zero equal to false * added tests for int/float -> bool conversion * change convert empty string to boolean false * update test to account for empty string to bool false * added truthy value test * added falsy value test * simplified tests and added more cases * refactor tests for legibility and support * empty binary should be false * compacted tests a bit except when failure cases are expected * fixed typo
This PR changes the logic in
Convert
to set int/float zero values asfalse
when converting to bool. All other values will betrue
. Before this change, an int/float value of one (1) would convert tofalse
bool.Old behavior:
New behavior:
This change is