From c67d701ad81da65a576efd3341634f8cd3892c9b Mon Sep 17 00:00:00 2001 From: Alejandro-FA <61871580+Alejandro-FA@users.noreply.github.com> Date: Thu, 25 Jan 2024 18:19:15 +0100 Subject: [PATCH] Fix indentation of empty sequences and add test --- src/emitter.cpp | 3 ++- test/integration/emitter_test.cpp | 11 +++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/emitter.cpp b/src/emitter.cpp index 4d48307..2a2262d 100644 --- a/src/emitter.cpp +++ b/src/emitter.cpp @@ -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 { diff --git a/test/integration/emitter_test.cpp b/test/integration/emitter_test.cpp index b277d57..e3464a6 100644 --- a/test/integration/emitter_test.cpp +++ b/test/integration/emitter_test.cpp @@ -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;