-
Notifications
You must be signed in to change notification settings - Fork 15.4k
[MsgPack] Use JSON schema boolean resolution rules #170561
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
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 |
|---|---|---|
|
|
@@ -420,3 +420,77 @@ TEST(MsgPackDocument, TestInputYAMLMap) { | |
| ASSERT_EQ(SS.getKind(), Type::String); | ||
| ASSERT_EQ(SS.getString(), "2"); | ||
| } | ||
|
|
||
| TEST(MsgPackDocument, TestInputYAMLBoolean) { | ||
| Document Doc; | ||
| auto GetFirst = [](Document &Doc) { return Doc.getRoot().getArray()[0]; }; | ||
| auto ToYAML = [](Document &Doc) { | ||
| std::string S; | ||
| raw_string_ostream OS(S); | ||
| Doc.toYAML(OS); | ||
| return S; | ||
| }; | ||
|
|
||
| bool Ok; | ||
|
|
||
| Ok = Doc.fromYAML("- n\n"); | ||
| ASSERT_TRUE(Ok); | ||
| ASSERT_EQ(GetFirst(Doc).getKind(), Type::String); | ||
| ASSERT_EQ(GetFirst(Doc).getString(), "n"); | ||
| ASSERT_EQ(ToYAML(Doc), "---\n- n\n...\n"); | ||
|
|
||
| Ok = Doc.fromYAML("- y\n"); | ||
| ASSERT_TRUE(Ok); | ||
| ASSERT_EQ(GetFirst(Doc).getKind(), Type::String); | ||
| ASSERT_EQ(GetFirst(Doc).getString(), "y"); | ||
| ASSERT_EQ(ToYAML(Doc), "---\n- y\n...\n"); | ||
|
|
||
| Ok = Doc.fromYAML("- no\n"); | ||
| ASSERT_TRUE(Ok); | ||
| ASSERT_EQ(GetFirst(Doc).getKind(), Type::String); | ||
| ASSERT_EQ(GetFirst(Doc).getString(), "no"); | ||
| ASSERT_EQ(ToYAML(Doc), "---\n- no\n...\n"); | ||
|
|
||
| Ok = Doc.fromYAML("- yes\n"); | ||
| ASSERT_TRUE(Ok); | ||
| ASSERT_EQ(GetFirst(Doc).getKind(), Type::String); | ||
| ASSERT_EQ(GetFirst(Doc).getString(), "yes"); | ||
| ASSERT_EQ(ToYAML(Doc), "---\n- yes\n...\n"); | ||
|
|
||
| Ok = Doc.fromYAML("- false\n"); | ||
| ASSERT_TRUE(Ok); | ||
| ASSERT_EQ(GetFirst(Doc).getKind(), Type::Boolean); | ||
| ASSERT_EQ(GetFirst(Doc).getBool(), false); | ||
| ASSERT_EQ(ToYAML(Doc), "---\n- false\n...\n"); | ||
|
|
||
| Ok = Doc.fromYAML("- true\n"); | ||
| ASSERT_TRUE(Ok); | ||
| ASSERT_EQ(GetFirst(Doc).getKind(), Type::Boolean); | ||
| ASSERT_EQ(GetFirst(Doc).getBool(), true); | ||
| ASSERT_EQ(ToYAML(Doc), "---\n- true\n...\n"); | ||
|
|
||
| Ok = Doc.fromYAML("- !str false\n"); | ||
| ASSERT_TRUE(Ok); | ||
| ASSERT_EQ(GetFirst(Doc).getKind(), Type::String); | ||
| ASSERT_EQ(GetFirst(Doc).getString(), "false"); | ||
| ASSERT_EQ(ToYAML(Doc), "---\n- !str 'false'\n...\n"); | ||
|
|
||
| Ok = Doc.fromYAML("- !str true\n"); | ||
| ASSERT_TRUE(Ok); | ||
| ASSERT_EQ(GetFirst(Doc).getKind(), Type::String); | ||
| ASSERT_EQ(GetFirst(Doc).getString(), "true"); | ||
| ASSERT_EQ(ToYAML(Doc), "---\n- !str 'true'\n...\n"); | ||
|
|
||
| // FIXME: A fix for these requires changes in YAMLParser/YAMLTraits. | ||
|
Contributor
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. Can you explain in more detail what fix is required?
Contributor
Author
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. It requires a change in YAMLParser/YAMLTraits directly and I wanted to avoid the fallout. If we would rather not have a half measure like this I can spend some time trying to understand the YAML issue more directly. Edit: to answer your first question more directly, the YAML spec(s) are complicated and I didn't want to wade into that swamp. I believe the change as-is at least works towards conforming to the JSON schema for bools, and I don't see how it can make the situation worse in this regard, but it is not a complete solution. |
||
| Ok = Doc.fromYAML("- \"false\"\n"); | ||
| ASSERT_TRUE(Ok); | ||
| ASSERT_EQ(GetFirst(Doc).getKind(), Type::Boolean); | ||
| ASSERT_EQ(GetFirst(Doc).getBool(), false); | ||
| ASSERT_EQ(ToYAML(Doc), "---\n- false\n...\n"); | ||
|
|
||
| Ok = Doc.fromYAML("- \"true\"\n"); | ||
| ASSERT_TRUE(Ok); | ||
| ASSERT_EQ(GetFirst(Doc).getKind(), Type::Boolean); | ||
| ASSERT_EQ(GetFirst(Doc).getBool(), true); | ||
| ASSERT_EQ(ToYAML(Doc), "---\n- true\n...\n"); | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.