Skip to content

Commit c67d701

Browse files
Alejandro-FAjbeder
authored andcommitted
Fix indentation of empty sequences and add test
1 parent 9eb1142 commit c67d701

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/emitter.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,8 @@ void Emitter::EmitEndSeq() {
213213
if (m_pState->CurGroupFlowType() == FlowType::Flow) {
214214
if (m_stream.comment())
215215
m_stream << "\n";
216-
m_stream << IndentTo(m_pState->CurIndent());
216+
if (originalType == FlowType::Block || m_pState->HasBegunNode())
217+
m_stream << IndentTo(m_pState->CurIndent());
217218
if (originalType == FlowType::Block) {
218219
m_stream << "[";
219220
} else {

test/integration/emitter_test.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,17 @@ TEST_F(EmitterTest, EmptyFlowSeqWithBegunContent) {
176176
]])");
177177
}
178178

179+
TEST_F(EmitterTest, EmptyFlowSeqInMap) {
180+
out << BeginMap;
181+
out << Key << Flow << BeginSeq << EndSeq;
182+
out << Value << 1;
183+
out << Key << 2;
184+
out << Value << Flow << BeginSeq << EndSeq;
185+
out << EndMap;
186+
187+
ExpectEmit("[]: 1\n2: []");
188+
}
189+
179190
TEST_F(EmitterTest, EmptyFlowMapWithBegunContent) {
180191
out << Flow;
181192
out << BeginSeq;

0 commit comments

Comments
 (0)