-
Notifications
You must be signed in to change notification settings - Fork 2.1k
feat/fix: support literal and single-quoted style for YAML::Binary emitting #1447
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
Changes from all commits
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 |
|---|---|---|
|
|
@@ -1191,6 +1191,34 @@ TEST_F(EmitterTest, EmptyBinary) { | |
| ExpectEmit("!!binary \"\""); | ||
| } | ||
|
|
||
| TEST_F(EmitterTest, BinaryStyles) { | ||
| Binary binary(reinterpret_cast<const unsigned char*>("Hello, World!"), 13); | ||
| out << BeginMap; | ||
| out << Key << "auto"; | ||
| out << Value << Auto << binary; | ||
| out << Key << "single"; | ||
| out << Value << SingleQuoted << binary; | ||
| out << Key << "double"; | ||
| out << Value << DoubleQuoted << binary; | ||
| out << Key << "literal"; | ||
| out << Value << Literal << binary; | ||
| out << Key << "literal_empty"; | ||
| out << Value << Literal << Binary(reinterpret_cast<const unsigned char*>(""), 0); | ||
| out << Key << "literal_indented"; | ||
| out << Value << Literal << Indent(8) << binary; | ||
| ExpectEmit( | ||
| "auto: !!binary \"SGVsbG8sIFdvcmxkIQ==\"\n" | ||
| "single: !!binary \'SGVsbG8sIFdvcmxkIQ==\'\n" | ||
| "double: !!binary \"SGVsbG8sIFdvcmxkIQ==\"\n" | ||
| "literal: !!binary |-\n" | ||
| " SGVsbG8sIFdvcmxkIQ==\n" | ||
| "literal_empty: !!binary |-\n" | ||
| "\n" | ||
| "literal_indented: !!binary |-\n" | ||
| " SGVsbG8sIFdvcmxkIQ==" | ||
| ); | ||
| } | ||
|
|
||
| TEST_F(EmitterTest, ColonAtEndOfScalar) { | ||
| out << "a:"; | ||
| ExpectEmit("\"a:\""); | ||
|
|
@@ -1468,8 +1496,8 @@ TEST_F(EmitterTest, Infinity) { | |
| out << YAML::EndMap; | ||
|
|
||
| ExpectEmit( | ||
| "foo: .inf\n" | ||
| "bar: .inf"); | ||
| "foo: .inf\n" | ||
| "bar: .inf"); | ||
|
Comment on lines
+1499
to
+1500
Collaborator
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. Could you explain why the indentation of these change?
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. This may be caused by clang-format. Previously this case used tab for indentation and the formatter changed it to spaces.
Collaborator
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.
Ah yes! than just leave the fix in. I just noticed other PRs have the same change. |
||
| } | ||
|
|
||
| TEST_F(EmitterTest, NegInfinity) { | ||
|
|
@@ -1481,8 +1509,8 @@ TEST_F(EmitterTest, NegInfinity) { | |
| out << YAML::EndMap; | ||
|
|
||
| ExpectEmit( | ||
| "foo: -.inf\n" | ||
| "bar: -.inf"); | ||
| "foo: -.inf\n" | ||
| "bar: -.inf"); | ||
| } | ||
|
|
||
| TEST_F(EmitterTest, NaN) { | ||
|
|
@@ -1494,8 +1522,8 @@ TEST_F(EmitterTest, NaN) { | |
| out << YAML::EndMap; | ||
|
|
||
| ExpectEmit( | ||
| "foo: .nan\n" | ||
| "bar: .nan"); | ||
| "foo: .nan\n" | ||
| "bar: .nan"); | ||
| } | ||
|
|
||
| TEST_F(EmitterTest, ComplexFlowSeqEmbeddingAMapWithNewLine) { | ||
|
|
||
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.
Could you add some comment for this block, what actually is happening?
Why do you format create a format string for "a"?
And why is there a case for
case StringFormat::Plainthat is commented out?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.
About "a":
Just like Emitter::Write for
const char*, we should use ComputeStringFormat to generate StringFormat. And I also thought it necessary to offer functions like WriteSingleQuotedBinary and WriteLiteralBinary in Utils and call them, rather than directly generating base64 and calling Utils functions for strings. However, ComputeStringFormat indeed requires a string, but the base64 string is not generated in Emitter::Write! If we encode twice, it may cost double the time with long binary.In fact ComputeStringFormat returns the same value for any non-empty base64 string and
a, so I just passedafor all non-empty Binary.Maybe adding a
ComputeBinaryFormatwill look better?About
Plain:Previously, without any options, the strFormat remains
Plainby default but emits double-quoted style for Binary. Some long-existing tests are also based on this. Changing the default behavior may also influence some downstream projects. So I left it unchanged (still double-quoted).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.
Best appreciation to you!