Skip to content

Commit

Permalink
tag_null (jbeder#897)
Browse files Browse the repository at this point in the history
  • Loading branch information
dota17 authored Jun 17, 2020
1 parent 72fe73a commit 5a9ab17
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
11 changes: 6 additions & 5 deletions src/singledocparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
13 changes: 12 additions & 1 deletion test/integration/load_node_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string>(), "null");
}

TEST(NodeTest, LoadQuotedNull) {
Node node = Load("\"null\"");
EXPECT_EQ(node.as<std::string>(), "null");
}

TEST(NodeTest, LoadTagWithParenthesis) {
Node node = Load("!Complex(Tag) foo");
EXPECT_EQ(node.Tag(), "!Complex(Tag)");
Expand Down

0 comments on commit 5a9ab17

Please sign in to comment.