From 38db3274cb60e9420d4810d983a8004f8ca32bb9 Mon Sep 17 00:00:00 2001 From: dota17 Date: Mon, 29 Jun 2020 10:28:57 +0800 Subject: [PATCH] update the code and test cases --- src/emitter.cpp | 9 ++++----- test/integration/emitter_test.cpp | 18 +++++++++++++----- 2 files changed, 17 insertions(+), 10 deletions(-) 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.