Skip to content
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

Improve bool parsing as XML can support also 0/1 value as bool #88

Merged
merged 10 commits into from
Mar 11, 2019

Conversation

punkstarman
Copy link
Collaborator

Continuation of #51

@punkstarman punkstarman self-assigned this Jan 17, 2019
@punkstarman
Copy link
Collaborator Author

In #51 a test was requested to complete the feature.

I added a test that deserializes 0 and 1 as boolean. I don't feel that a round-trip test is useful. This is because the de(ser(x)) round-trip pair is the easiest to test and most useful, but in this case serialization isn't changed.

test_parse_ok(&[
("<bla>true</bla>", true),
("<bla>false</bla>", false),
("<bla> true </bla>", true),
("<bla> false </bla>", false),
("<bla>1</bla>", true),
("<bla>0</bla>", false),
]);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you also add a test for the error case please?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ping on this one too.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I see, it was fixed. Nvm.

src/de/mod.rs Outdated
match s.as_str() {
"true" | "1" => visitor.visit_bool(true),
"false" | "0" => visitor.visit_bool(false),
_ => Err(ErrorKind::UnexpectedToken(
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe better to use Error::unknown_variant or Error::invalid_value here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@RReverser, are you suggesting creating a new ErrorKind?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missed this. No, I meant using Serde's own method.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I chose Error::invalid_value.

@RReverser
Copy link
Owner

(approved; as a reminder, please clean up history a bit before merging)

@punkstarman punkstarman merged commit e6bf15a into RReverser:master Mar 11, 2019
@punkstarman punkstarman deleted the feature/boolean-01 branch March 11, 2019 15:21
punkstarman added a commit that referenced this pull request Jul 29, 2020
Improve bool parsing as XML can support also 0/1 value as bool
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants