fix issue743: handle the empty content of flow sep/map correctly during emitting. (#921)

* fix issue743: handle the empty content of flow sep/map correctly during emitting.

* handle the empty Tag/Anchor properly.

* delete comment
This commit is contained in:
Chen
2020-07-24 20:28:40 +08:00
committed by GitHub
parent 11917babc7
commit 1c9abc8fa4
3 changed files with 89 additions and 2 deletions

View File

@@ -138,6 +138,56 @@ TEST_F(EmitterTest, EmptyFlowSeq) {
ExpectEmit("[]");
}
TEST_F(EmitterTest, EmptyBlockSeqWithBegunContent) {
out << BeginSeq;
out << BeginSeq << Comment("comment") << EndSeq;
out << BeginSeq << Newline << EndSeq;
out << EndSeq;
ExpectEmit(R"(-
# comment
[]
-
[])");
}
TEST_F(EmitterTest, EmptyBlockMapWithBegunContent) {
out << BeginSeq;
out << BeginMap << Comment("comment") << EndMap;
out << BeginMap << Newline << EndMap;
out << EndSeq;
ExpectEmit(R"(- # comment
{}
-
{})");
}
TEST_F(EmitterTest, EmptyFlowSeqWithBegunContent) {
out << Flow;
out << BeginSeq;
out << BeginSeq << Comment("comment") << EndSeq;
out << BeginSeq << Newline << EndSeq;
out << EndSeq;
ExpectEmit(R"([[ # comment
], [
]])");
}
TEST_F(EmitterTest, EmptyFlowMapWithBegunContent) {
out << Flow;
out << BeginSeq;
out << BeginMap << Comment("comment") << EndMap;
out << BeginMap << Newline << EndMap;
out << EndSeq;
ExpectEmit(R"([{ # comment
}, {
}])");
}
TEST_F(EmitterTest, NestedBlockSeq) {
out << BeginSeq;
out << "item 1";
@@ -1553,6 +1603,26 @@ TEST_F(EmitterErrorTest, BadLocalTag) {
ExpectEmitError("invalid tag");
}
TEST_F(EmitterErrorTest, BadTagAndTag) {
out << VerbatimTag("!far") << VerbatimTag("!foo") << "bar";
ExpectEmitError(ErrorMsg::INVALID_TAG);
}
TEST_F(EmitterErrorTest, BadAnchorAndAnchor) {
out << Anchor("far") << Anchor("foo") << "bar";
ExpectEmitError(ErrorMsg::INVALID_ANCHOR);
}
TEST_F(EmitterErrorTest, BadEmptyAnchorOnGroup) {
out << BeginSeq << "bar" << Anchor("foo") << EndSeq;
ExpectEmitError(ErrorMsg::INVALID_ANCHOR);
}
TEST_F(EmitterErrorTest, BadEmptyTagOnGroup) {
out << BeginSeq << "bar" << VerbatimTag("!foo") << EndSeq;
ExpectEmitError(ErrorMsg::INVALID_TAG);
}
TEST_F(EmitterErrorTest, ExtraEndSeq) {
out << BeginSeq;
out << "Hello";