Skip to content

Commit

Permalink
add tests verifying #471 and #259
Browse files Browse the repository at this point in the history
  • Loading branch information
biojppm committed Jan 20, 2025
1 parent be5f038 commit 9789e47
Showing 1 changed file with 78 additions and 0 deletions.
78 changes: 78 additions & 0 deletions test/test_scalar_null.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,84 @@ TEST(issue480, deserialize_empty_key)
});
}


//-----------------------------------------------------------------------------

TEST(empty_scalar, issue471_val)
{
csubstr flow = R"({
a: ,
b:
})";
csubstr blck = R"(
a:
b:
)";
for(csubstr yaml : {flow, blck})
{
test_check_emit_check(yaml, [](Tree const& t){
EXPECT_TRUE(t[0].val_is_null());
EXPECT_TRUE(t[1].val_is_null());
ExpectError::check_error(&t, [&] { std::string s; t["a"] >> s; });
ExpectError::check_error(&t, [&] { int s; t["a"] >> s; });
ExpectError::check_error(&t, [&] { float s; t["a"] >> s; });
});
}
}
TEST(empty_scalar, issue471_key)
{
csubstr flow = R"({
: a,
: b
})";
csubstr blck = R"(
: a
: b
)";
for(csubstr yaml : {flow, blck})
{
test_check_emit_check(yaml, [](Tree const& t){
EXPECT_TRUE(t[0].key_is_null());
EXPECT_TRUE(t[1].key_is_null());
ExpectError::check_error(&t, [&] { std::string s; t["a"] >> key(s); });
ExpectError::check_error(&t, [&] { int s; t["a"] >> key(s); });
ExpectError::check_error(&t, [&] { float s; t["a"] >> key(s); });
});
}
}

TEST(empty_scalar, issue259)
{
csubstr yaml = R"(
{
? explicit key1 : explicit value,
? explicit key2 : , # Explicit empty
? explicit key3, # Empty value
simple key1 : explicit value,
simple key2 : , # Explicit empty
simple key3, # Empty value
}
)";
test_check_emit_check(yaml, [](Tree const& t){
EXPECT_EQ(t["explicit key1"].key(), "explicit key1");
EXPECT_EQ(t["explicit key1"].val(), "explicit value");
EXPECT_EQ(t["explicit key2"].key(), "explicit key2");
EXPECT_EQ(t["explicit key2"].val(), "");
EXPECT_TRUE(t["explicit key2"].val_is_null());
EXPECT_EQ(t["explicit key3"].key(), "explicit key3");
EXPECT_EQ(t["explicit key3"].val(), "");
EXPECT_TRUE(t["explicit key3"].val_is_null());
EXPECT_EQ(t["simple key1"].key(), "simple key1");
EXPECT_EQ(t["simple key1"].val(), "explicit value");
EXPECT_EQ(t["simple key2"].key(), "simple key2");
EXPECT_EQ(t["simple key2"].val(), "");
EXPECT_TRUE(t["simple key2"].val_is_null());
EXPECT_EQ(t["simple key3"].key(), "simple key3");
EXPECT_EQ(t["simple key3"].val(), "");
EXPECT_TRUE(t["simple key3"].val_is_null());
});
}

}


Expand Down

0 comments on commit 9789e47

Please sign in to comment.