Skip to content

Commit

Permalink
[fix] json emitter: ensure quoting version string scalars
Browse files Browse the repository at this point in the history
re #292
  • Loading branch information
biojppm committed Aug 30, 2022
1 parent f020b03 commit 6303191
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 5 deletions.
3 changes: 2 additions & 1 deletion changelog/0.5.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@
:barbar: b # was ok
:barbarbar: c # was ol
```
- Fix [#246](https://github.com/biojppm/rapidyaml/issues/246): add missing `#define` for the include guard of the amalgamated header.
- Fix [#253](https://github.com/biojppm/rapidyaml/issues/253): double-quoted emitter should encode carriage-return `\r` to preserve roundtrip equivalence:
```yaml
Tree tree;
Expand All @@ -83,6 +82,7 @@
EXPECT_EQ(tree2["s"].val(), tree["s"].val());
```
- Fix [#297](https://github.com/biojppm/rapidyaml/issues/297) ([PR#298](https://github.com/biojppm/rapidyaml/pull/298)): JSON emitter should escape control characters.
- Fix [#292](https://github.com/biojppm/rapidyaml/issues/292) ([PR#299](https://github.com/biojppm/rapidyaml/pull/299)): JSON emitter should quote version string scalars like `0.1.2`.
- Fix [#274](https://github.com/biojppm/rapidyaml/issues/274) ([PR#296](https://github.com/biojppm/rapidyaml/pull/296)): Lists with unindented items and trailing empty values parse incorrectly:
```yaml
foo:
Expand All @@ -106,4 +106,5 @@
=VAL :foo
=VAL :bar
```
- Fix [#246](https://github.com/biojppm/rapidyaml/issues/246): add missing `#define` for the include guard of the amalgamated header.
- Fix [cmake#8](https://github.com/biojppm/cmake/issues/8): `SOVERSION` missing from shared libraries.
18 changes: 15 additions & 3 deletions samples/quickstart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1211,23 +1211,35 @@ void sample_substr()
CHECK(ryml::csubstr("-1234)asdkjh").first_real_span() == "-1234");
CHECK(ryml::csubstr("-1234gasdkjh").first_real_span() == "");
CHECK(ryml::csubstr("1.234 asdkjh").first_real_span() == "1.234");
CHECK(ryml::csubstr("1.234e5 asdkjh").first_real_span() == "1.234e5");
CHECK(ryml::csubstr("1.234e+5 asdkjh").first_real_span() == "1.234e+5");
CHECK(ryml::csubstr("1.234e-5 asdkjh").first_real_span() == "1.234e-5");
CHECK(ryml::csubstr("1.234 asdkjh").first_real_span() == "1.234");
CHECK(ryml::csubstr("1.234e5 asdkjh").first_real_span() == "1.234e5");
CHECK(ryml::csubstr("1.234e+5 asdkjh").first_real_span() == "1.234e+5");
CHECK(ryml::csubstr("1.234e-5 asdkjh").first_real_span() == "1.234e-5");
CHECK(ryml::csubstr("-1.234 asdkjh").first_real_span() == "-1.234");
CHECK(ryml::csubstr("-1.234e5 asdkjh").first_real_span() == "-1.234e5");
CHECK(ryml::csubstr("-1.234e+5 asdkjh").first_real_span() == "-1.234e+5");
CHECK(ryml::csubstr("-1.234e-5 asdkjh").first_real_span() == "-1.234e-5");
// hexadecimal real numbers
CHECK(ryml::csubstr("0x1.e8480p+19 asdkjh").first_real_span() == "0x1.e8480p+19");
CHECK(ryml::csubstr("0x1.e8480p-19 asdkjh").first_real_span() == "0x1.e8480p-19");
CHECK(ryml::csubstr("-0x1.e8480p+19 asdkjh").first_real_span() == "-0x1.e8480p+19");
CHECK(ryml::csubstr("-0x1.e8480p-19 asdkjh").first_real_span() == "-0x1.e8480p-19");
CHECK(ryml::csubstr("+0x1.e8480p+19 asdkjh").first_real_span() == "+0x1.e8480p+19");
CHECK(ryml::csubstr("+0x1.e8480p-19 asdkjh").first_real_span() == "+0x1.e8480p-19");
// binary real numbers
CHECK(ryml::csubstr("0b101.011p+19 asdkjh").first_real_span() == "0b101.011p+19");
CHECK(ryml::csubstr("0b101.011p-19 asdkjh").first_real_span() == "0b101.011p-19");
CHECK(ryml::csubstr("-0b101.011p+19 asdkjh").first_real_span() == "-0b101.011p+19");
CHECK(ryml::csubstr("-0b101.011p-19 asdkjh").first_real_span() == "-0b101.011p-19");
CHECK(ryml::csubstr("+0b101.011p+19 asdkjh").first_real_span() == "+0b101.011p+19");
CHECK(ryml::csubstr("+0b101.011p-19 asdkjh").first_real_span() == "+0b101.011p-19");
// octal real numbers
CHECK(ryml::csubstr("0o173.045p+19 asdkjh").first_real_span() == "0o173.045p+19");
CHECK(ryml::csubstr("0o173.045p-19 asdkjh").first_real_span() == "0o173.045p-19");
CHECK(ryml::csubstr("-0o173.045p+19 asdkjh").first_real_span() == "-0o173.045p+19");
CHECK(ryml::csubstr("-0o173.045p-19 asdkjh").first_real_span() == "-0o173.045p-19");
CHECK(ryml::csubstr("+0o173.045p+19 asdkjh").first_real_span() == "+0o173.045p+19");
CHECK(ryml::csubstr("+0o173.045p-19 asdkjh").first_real_span() == "+0o173.045p-19");
}
// see also is_number()

Expand Down
9 changes: 9 additions & 0 deletions test/test_json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,15 @@ broken_value: '0.30.2'
)");
}

TEST(emit_json, issue292)
{
EXPECT_FALSE(csubstr("0.1.0").is_number());
Tree t = parse_in_arena("{}");
t["james"] = "1.2.3";
auto s = emitrs_json<std::string>(t);
EXPECT_EQ(s, "{\"james\": \"1.2.3\"}");
}

TEST(emit_json, issue297)
{
char yml_buf[] = R"(
Expand Down

0 comments on commit 6303191

Please sign in to comment.