[test] re #216: add tests reproducing

This commit is contained in:
Joao Paulo Magalhaes
2022-02-14 01:33:44 +01:00
parent 9c6fc2800b
commit fba1afdab1
3 changed files with 46 additions and 1 deletions

View File

@@ -154,6 +154,7 @@ As part of the [new feature to track source locations](https://github.com/biojpp
foo4 : bar
```
- Ensure container keys preserve quote flags when the key is quoted ([PR#210](https://github.com/biojppm/rapidyaml/pulls/210)).
- Ensure scalars beginning with `%` are emitted with quotes (([PR#216](https://github.com/biojppm/rapidyaml/pulls/216)).
- Fix [#203](https://github.com/biojppm/rapidyaml/issues/203): when parsing, do not convert `null` or `~` to null scalar strings. Now the scalar strings contain the verbatim contents of the original scalar; to query whether a scalar value is null, use `Tree::key_is_null()/val_is_null()` and `NodeRef::key_is_null()/val_is_null()` which return true if it is empty or any of the unquoted strings `~`, `null`, `Null`, or `NULL`. ([PR#207](https://github.com/biojppm/rapidyaml/pulls/207)):
- Fix [#205](https://github.com/biojppm/rapidyaml/issues/205): fix parsing of escaped characters in double-quoted strings: `"\\\"\n\r\t\<TAB>\/\<SPC>\0\b\f\a\v\e\_\N\L\P"` ([PR#207](https://github.com/biojppm/rapidyaml/pulls/207)).
- Fix [#204](https://github.com/biojppm/rapidyaml/issues/204): add decoding of unicode codepoints `\x` `\u` `\U` in double-quoted scalars:
@@ -224,3 +225,4 @@ As part of the [new feature to track source locations](https://github.com/biojpp
- @fargies
- @Xeonacid
- @aviktorov
- @xTVaser

View File

@@ -371,6 +371,28 @@ TEST(emit, existing_map_node)
}
}
TEST(emit, percent_is_quoted)
{
Tree ti = parse_in_arena("{}");
ASSERT_TRUE(ti.rootref().is_map());
ti["%ROOT"] = "%VAL";
ti["%ROOT2"] |= SEQ;
ti["%ROOT2"][0] = "%VAL";
ti["%ROOT2"][1] = "%VAL";
std::string yaml = emitrs<std::string>(ti);
test_check_emit_check(to_csubstr(yaml), [](Tree const &t){
ASSERT_TRUE(t.rootref().is_map());
ASSERT_TRUE(t.rootref().has_child("%ROOT"));
ASSERT_TRUE(t.rootref().has_child("%ROOT2"));
ASSERT_EQ(t["%ROOT2"].num_children(), 2u);
EXPECT_TRUE(t["%ROOT"].is_key_quoted());
EXPECT_TRUE(t["%ROOT"].is_val_quoted());
EXPECT_TRUE(t["%ROOT2"].is_key_quoted());
EXPECT_TRUE(t["%ROOT2"][0].is_val_quoted());
EXPECT_TRUE(t["%ROOT2"][1].is_val_quoted());
});
}
//-------------------------------------------
// this is needed to use the test case library

View File

@@ -3,7 +3,7 @@
namespace c4 {
namespace yml {
TEST(double_quoted, test_suite_KSS4)
TEST(single_quoted, test_suite_KSS4)
{
csubstr yaml = R"(
---
@@ -114,6 +114,27 @@ tie-fighter: '|\-*-/|'
});
}
TEST(single_quoted, quotes_are_preserved)
{
csubstr yaml = R"(
'%ROOT': '%VAL'
'%ROOT2':
- '%VAL'
- '%VAL'
)";
test_check_emit_check(yaml, [](Tree const &t){
ASSERT_TRUE(t.rootref().is_map());
ASSERT_TRUE(t.rootref().has_child("%ROOT"));
ASSERT_TRUE(t.rootref().has_child("%ROOT2"));
ASSERT_EQ(t["%ROOT2"].num_children(), 2u);
EXPECT_TRUE(t["%ROOT"].is_key_quoted());
EXPECT_TRUE(t["%ROOT"].is_val_quoted());
EXPECT_TRUE(t["%ROOT2"].is_key_quoted());
EXPECT_TRUE(t["%ROOT2"][0].is_val_quoted());
EXPECT_TRUE(t["%ROOT2"][1].is_val_quoted());
});
}
//-----------------------------------------------------------------------------