diff --git a/src/emitter.cpp b/src/emitter.cpp index 6ab1dd1..0eeaf2d 100644 --- a/src/emitter.cpp +++ b/src/emitter.cpp @@ -775,8 +775,7 @@ const char* Emitter::ComputeFullBoolName(bool b) const { } const char* Emitter::ComputeNullName() const { - const EMITTER_MANIP nullFmt = m_pState->GetNullFormat(); - switch (nullFmt) { + switch (m_pState->GetNullFormat()) { case LowerNull: return "null"; case UpperNull: @@ -784,8 +783,9 @@ const char* Emitter::ComputeNullName() const { case CamelNull: return "Null"; case TildeNull: - default: return "~"; + default: // fallthrough + break; } } @@ -912,8 +912,7 @@ Emitter& Emitter::Write(const _Null& /*null*/) { PrepareNode(EmitterNodeType::Scalar); - const char* name = ComputeNullName(); - m_stream << name; + m_stream << ComputeNullName(); StartedScalar(); diff --git a/test/integration/emitter_test.cpp b/test/integration/emitter_test.cpp index b0c75ac..04adadf 100644 --- a/test/integration/emitter_test.cpp +++ b/test/integration/emitter_test.cpp @@ -1048,7 +1048,7 @@ TEST_F(EmitterTest, BoolFormatting) { } TEST_F(EmitterTest, GlobalNullFormatting) { - out << BeginSeq; + out << Flow << BeginSeq; out.SetNullFormat(LowerNull); out << Null; out.SetNullFormat(UpperNull); @@ -1058,24 +1058,32 @@ TEST_F(EmitterTest, GlobalNullFormatting) { out.SetNullFormat(TildeNull); out << Null; out << EndSeq; - ExpectEmit("- null\n- NULL\n- Null\n- ~"); + ExpectEmit("[null, NULL, Null, ~]"); } TEST_F(EmitterTest, NullFormatting) { - out << BeginSeq; + out << Flow << BeginSeq; out << LowerNull << Null; out << UpperNull << Null; out << CamelNull << Null; out << TildeNull << Null; out << EndSeq; - ExpectEmit("- null\n- NULL\n- Null\n- ~"); + ExpectEmit("[null, NULL, Null, ~]"); } TEST_F(EmitterTest, NullFormattingOnNode) { Node n(Load("null")); + out << Flow << BeginSeq; + out.SetNullFormat(LowerNull); + out << n; out.SetNullFormat(UpperNull); out << n; - ExpectEmit("NULL"); + out.SetNullFormat(CamelNull); + out << n; + out.SetNullFormat(TildeNull); + out << n; + out << EndSeq; + ExpectEmit("[null, NULL, Null, ~]"); } // TODO: Fix this test.