Skip to content

Commit

Permalink
Fix indentation of empty sequences and add test
Browse files Browse the repository at this point in the history
  • Loading branch information
Alejandro-FA authored and jbeder committed Jan 26, 2024
1 parent 9eb1142 commit c67d701
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/emitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,8 @@ void Emitter::EmitEndSeq() {
if (m_pState->CurGroupFlowType() == FlowType::Flow) {
if (m_stream.comment())
m_stream << "\n";
m_stream << IndentTo(m_pState->CurIndent());
if (originalType == FlowType::Block || m_pState->HasBegunNode())
m_stream << IndentTo(m_pState->CurIndent());
if (originalType == FlowType::Block) {
m_stream << "[";
} else {
Expand Down
11 changes: 11 additions & 0 deletions test/integration/emitter_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,17 @@ TEST_F(EmitterTest, EmptyFlowSeqWithBegunContent) {
]])");
}

TEST_F(EmitterTest, EmptyFlowSeqInMap) {
out << BeginMap;
out << Key << Flow << BeginSeq << EndSeq;
out << Value << 1;
out << Key << 2;
out << Value << Flow << BeginSeq << EndSeq;
out << EndMap;

ExpectEmit("[]: 1\n2: []");
}

TEST_F(EmitterTest, EmptyFlowMapWithBegunContent) {
out << Flow;
out << BeginSeq;
Expand Down

0 comments on commit c67d701

Please sign in to comment.