From 5a9ab177bad9665ac5eb8f5b12435052123b5b6f Mon Sep 17 00:00:00 2001 From: Chen Date: Thu, 18 Jun 2020 01:49:09 +0800 Subject: [PATCH] tag_null (#897) --- src/singledocparser.cpp | 11 ++++++----- test/integration/load_node_test.cpp | 13 ++++++++++++- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/singledocparser.cpp b/src/singledocparser.cpp index 5e00515..4bbea76 100644 --- a/src/singledocparser.cpp +++ b/src/singledocparser.cpp @@ -90,16 +90,17 @@ void SingleDocParser::HandleNode(EventHandler& eventHandler) { const Token& token = m_scanner.peek(); - if (token.type == Token::PLAIN_SCALAR && IsNullString(token.value)) { + // add non-specific tags + if (tag.empty()) + tag = (token.type == Token::NON_PLAIN_SCALAR ? "!" : "?"); + + if (token.type == Token::PLAIN_SCALAR + && tag.compare("?") == 0 && IsNullString(token.value)) { eventHandler.OnNull(mark, anchor); m_scanner.pop(); return; } - // add non-specific tags - if (tag.empty()) - tag = (token.type == Token::NON_PLAIN_SCALAR ? "!" : "?"); - // now split based on what kind of node we should be switch (token.type) { case Token::PLAIN_SCALAR: diff --git a/test/integration/load_node_test.cpp b/test/integration/load_node_test.cpp index 33d50b9..b28cd37 100644 --- a/test/integration/load_node_test.cpp +++ b/test/integration/load_node_test.cpp @@ -269,7 +269,18 @@ TEST(NodeTest, LoadTildeAsNull) { Node node = Load("~"); ASSERT_TRUE(node.IsNull()); } - + +TEST(NodeTest, LoadNullWithStrTag) { + Node node = Load("!!str null"); + EXPECT_EQ(node.Tag(), "tag:yaml.org,2002:str"); + EXPECT_EQ(node.as(), "null"); +} + +TEST(NodeTest, LoadQuotedNull) { + Node node = Load("\"null\""); + EXPECT_EQ(node.as(), "null"); +} + TEST(NodeTest, LoadTagWithParenthesis) { Node node = Load("!Complex(Tag) foo"); EXPECT_EQ(node.Tag(), "!Complex(Tag)");