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

Add the support to parsing a null value as `std::string`.

Fixes #590.
parent 4571e817
......@@ -110,6 +110,8 @@ struct as_if<std::string, S> {
const Node& node;
std::string operator()(const S& fallback) const {
if (node.Type() == NodeType::Null)
return "null";
if (node.Type() != NodeType::Scalar)
return fallback;
return node.Scalar();
......@@ -138,6 +140,8 @@ struct as_if<std::string, void> {
const Node& node;
std::string operator()() const {
if (node.Type() == NodeType::Null)
return "null";
if (node.Type() != NodeType::Scalar)
throw TypedBadConversion<std::string>(node.Mark());
return node.Scalar();
......
......@@ -314,6 +314,8 @@ TEST(NodeTest, IncorrectFlow) {
TEST(NodeTest, LoadTildeAsNull) {
Node node = Load("~");
ASSERT_TRUE(node.IsNull());
EXPECT_EQ(node.as<std::string>(), "null");
EXPECT_EQ(node.as<std::string>("~"), "null");
}
TEST(NodeTest, LoadNullWithStrTag) {
......
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