Skip to content

Commit

Permalink
Include property nodes in the long key check (#1140)
Browse files Browse the repository at this point in the history
  • Loading branch information
zenno-leaky-bucket authored Oct 4, 2022
1 parent 4ae4cb7 commit 1b50109
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/emitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,8 @@ void Emitter::BlockMapPrepareNode(EmitterNodeType::value child) {
if (m_pState->GetMapKeyFormat() == LongKey)
m_pState->SetLongKey();
if (child == EmitterNodeType::BlockSeq ||
child == EmitterNodeType::BlockMap)
child == EmitterNodeType::BlockMap ||
child == EmitterNodeType::Property)
m_pState->SetLongKey();

if (m_pState->CurGroupLongKey())
Expand Down
34 changes: 33 additions & 1 deletion test/integration/emitter_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,38 @@ TEST_F(EmitterTest, BlockMapAsKey) {
ExpectEmit("? key: value\n next key: next value\n: total value");
}

TEST_F(EmitterTest, TaggedBlockMapAsKey) {
out << BeginMap;
out << Key;
out << LocalTag("innerMap");
out << BeginMap;
out << Key << "key" << Value << "value";
out << EndMap;
out << Value;
out << "outerValue";
out << EndMap;

ExpectEmit(R"(? !innerMap
key: value
: outerValue)");
}

TEST_F(EmitterTest, TaggedBlockListAsKey) {
out << BeginMap;
out << Key;
out << LocalTag("innerList");
out << BeginSeq;
out << "listItem";
out << EndSeq;
out << Value;
out << "outerValue";
out << EndMap;

ExpectEmit(R"(? !innerList
- listItem
: outerValue)");
}

TEST_F(EmitterTest, AliasAndAnchor) {
out << BeginSeq;
out << Anchor("fred");
Expand Down Expand Up @@ -520,7 +552,7 @@ TEST_F(EmitterTest, VerbatimTagInBlockMap) {
out << Value << VerbatimTag("!waz") << "baz";
out << EndMap;

ExpectEmit("!<!foo> bar: !<!waz> baz");
ExpectEmit("? !<!foo> bar\n: !<!waz> baz");
}

TEST_F(EmitterTest, VerbatimTagInFlowMap) {
Expand Down

0 comments on commit 1b50109

Please sign in to comment.