Unverified Commit 5a9ab177 authored by Chen's avatar Chen Committed by GitHub
Browse files

tag_null (#897)

parent 72fe73a1
...@@ -90,16 +90,17 @@ void SingleDocParser::HandleNode(EventHandler& eventHandler) { ...@@ -90,16 +90,17 @@ void SingleDocParser::HandleNode(EventHandler& eventHandler) {
const Token& token = m_scanner.peek(); 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); eventHandler.OnNull(mark, anchor);
m_scanner.pop(); m_scanner.pop();
return; 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 // now split based on what kind of node we should be
switch (token.type) { switch (token.type) {
case Token::PLAIN_SCALAR: case Token::PLAIN_SCALAR:
......
...@@ -269,7 +269,18 @@ TEST(NodeTest, LoadTildeAsNull) { ...@@ -269,7 +269,18 @@ TEST(NodeTest, LoadTildeAsNull) {
Node node = Load("~"); Node node = Load("~");
ASSERT_TRUE(node.IsNull()); 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<std::string>(), "null");
}
TEST(NodeTest, LoadQuotedNull) {
Node node = Load("\"null\"");
EXPECT_EQ(node.as<std::string>(), "null");
}
TEST(NodeTest, LoadTagWithParenthesis) { TEST(NodeTest, LoadTagWithParenthesis) {
Node node = Load("!Complex(Tag) foo"); Node node = Load("!Complex(Tag) foo");
EXPECT_EQ(node.Tag(), "!Complex(Tag)"); EXPECT_EQ(node.Tag(), "!Complex(Tag)");
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment