handle the empty Tag/Anchor properly.

This commit is contained in:
dota17 2020-07-22 17:31:04 +08:00
parent 2f3938e9fe
commit 683c4d8517
2 changed files with 30 additions and 18 deletions

View File

@ -160,6 +160,12 @@ void EmitterState::EndedGroup(GroupType::value type) {
return SetError(ErrorMsg::UNEXPECTED_END_MAP);
}
// if have the unhandled Tag/Anchor, set the error message
if (m_hasTag)
SetError(ErrorMsg::INVALID_TAG);
if (m_hasAnchor)
SetError(ErrorMsg::INVALID_ANCHOR);
// get rid of the current group
{
std::unique_ptr<Group> pFinishedGroup = std::move(m_groups.back());

View File

@ -142,8 +142,6 @@ TEST_F(EmitterTest, EmptyBlockSeqWithBegunContent) {
out << BeginSeq;
out << BeginSeq << Comment("comment") << EndSeq;
out << BeginSeq << Newline << EndSeq;
out << BeginSeq << Anchor("test") << EndSeq;
out << BeginSeq << VerbatimTag("foo") << EndSeq;
out << EndSeq;
ExpectEmit(R"(-
@ -151,27 +149,19 @@ TEST_F(EmitterTest, EmptyBlockSeqWithBegunContent) {
[]
-
[]
-
- &test[]
-
- !<foo>[])");
[])");
}
TEST_F(EmitterTest, EmptyBlockMapWithBegunContent) {
out << BeginSeq;
out << BeginMap << Comment("comment") << EndMap;
out << BeginMap << Newline << EndMap;
out << BeginMap << Anchor("test") << EndMap;
out << BeginMap << VerbatimTag("foo") << EndMap;
out << EndSeq;
ExpectEmit(R"(- # comment
{}
-
{}
- &test{}
- !<foo>{})");
{})");
}
TEST_F(EmitterTest, EmptyFlowSeqWithBegunContent) {
@ -179,13 +169,11 @@ TEST_F(EmitterTest, EmptyFlowSeqWithBegunContent) {
out << BeginSeq;
out << BeginSeq << Comment("comment") << EndSeq;
out << BeginSeq << Newline << EndSeq;
out << BeginSeq << Anchor("test") << EndSeq;
out << BeginSeq << VerbatimTag("foo") << EndSeq;
out << EndSeq;
ExpectEmit(R"([[ # comment
], [
], [&test], [!<foo>]])");
]])");
}
TEST_F(EmitterTest, EmptyFlowMapWithBegunContent) {
@ -193,13 +181,11 @@ TEST_F(EmitterTest, EmptyFlowMapWithBegunContent) {
out << BeginSeq;
out << BeginMap << Comment("comment") << EndMap;
out << BeginMap << Newline << EndMap;
out << BeginMap << Anchor("test") << EndMap;
out << BeginMap << VerbatimTag("foo") << EndMap;
out << EndSeq;
ExpectEmit(R"([{ # comment
}, {
}, {&test}, {!<foo>}])");
}])");
}
TEST_F(EmitterTest, NestedBlockSeq) {
@ -1574,6 +1560,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";