Skip to content

Commit 29dce03

Browse files
committed
bignum tests
1 parent d6a112c commit 29dce03

File tree

3 files changed

+40
-7
lines changed

3 files changed

+40
-7
lines changed

CHANGELOG.md

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,28 @@
1313
`basic_csv_parser` `basic_csv_reader` and `basic_csv_cursor` that take an `err_handler` argument have been deprecated
1414
and will be removed in a future release. Use the `allow_trailing_comma` and `allow_comments`
1515
options instead.
16+
1617
- The functors `strict_json_parsing` and `allow_trailing_commas have been deprecated and
1718
will be removed in a future release. Use the `allow_trailing_comma` and `allow_comments`
1819
options instead.
1920

21+
- The json_parser option `lossless_bignum`, when **false**, now applies to integer values as well as floating point values.
22+
23+
- `basic_json::is_bignum` function has been changed to return `true` if the value
24+
is any string value tagged as `bigint`, `bigdec`, `float128`, or `bigfloat`
25+
(previously only `bigint`.)
26+
2027
- Enhancements
2128

22-
- Git Discussion #594: Supports `boost::optional` with built-in reflection traits
29+
- Git Discussions #594: Updated reflection traits to supports `boost::optional`
2330

24-
- Git Discussion #651: Improve `decode_json` error messages
31+
- Git Discussions #651: Improved `decode_json` error messages
2532

2633
- Git PR #647: Allow user configuration of **JSONCONS_HAS_STD_FROM_CHARS**
2734

28-
- Added an `indent_char` property to `basic_json_options` that supports tab indents
35+
- Git Discussions #654: Added an `indent_char` property to `basic_json_options` that supports tab indents
36+
37+
- Git Discussions #660: Added reflection traits for read/write of enum values as integers.
2938

3039
- Fixed bug:
3140

doc/ref/corelib/basic_json_options.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ neginf_to_str|Substitute string with `negative infinity`, if enabled|Sets a stri
2222
nan_to_num| |Sets a number replacement for `NaN` when writing JSON|Unenabled|
2323
inf_to_num| |Sets a number replacement for `Infinity` when writing JSON|Unenabled|
2424
neginf_to_num| |Sets a number replacement for `Negative Infinity` when writing JSON|Unenabled|
25-
max_nesting_depth|Maximum nesting depth allowed when parsing JSON|Maximum nesting depth allowed when serializing JSON|1024|
25+
max_nesting_depth|Maximum nesting depth allowed when parsing JSON|Maximum nesting depth allowed when serializing JSON|**1024**|
2626
lossless_bignum|When parsing floating point values, and value is out-of-range, produces a string with tag `semantic_tag::bigdec` if **true**, otherwise produces +- infinity.| |**true**|(since 1.4.0)</br>(until 1.5.0)
27-
lossless_bignum|When parsing an integer value, and value is out-of-range, produces a string with tag `semantic_tag::bigint` if **true**, otherwise parses as double. When parsing floating point values, and value is out-of-range, produces a string with tag `semantic_tag::bigdec` if **true**, otherwise produces +- **infinity**.| |**true**|(since 1.5.0)
27+
lossless_bignum|When parsing an integer value, and value is out-of-range, produces a string with tag `semantic_tag::bigint` if **true**, otherwise parses as double. When parsing floating point values, and value is out-of-range, produces a string with tag `semantic_tag::bigdec` if **true**, otherwise produces `+- infinity`.| |**true**|(since 1.5.0)
2828
lossless_number|If **true**, reads numbers with exponents and fractional parts as strings with tag `semantic_tag::bigdec`.| |**false**|
2929
allow_comments|If 'true', allow (and ignore) comments when parsing JSON| |**true**|(since 1.3.0)
30-
allow_trailing_comma|If 'true', an extra comma at the end of a list of JSON values in an object or array is allowed (and ignored)| |false|(since 1.3.0)
30+
allow_trailing_comma|If 'true', an extra comma at the end of a list of JSON values in an object or array is allowed (and ignored)| |**false**|(since 1.3.0)
3131
err_handler|Defines an [error handler](err_handler.md) for parsing JSON.| |`default_json_parsing`|(since 0.171.0, deprecated in 1.5.0)
3232
indent_size| |The indent size|4|
3333
indent_char| |The indent character, e.g. '\t'|' '| (since 1.5)

test/corelib/src/json_options_tests.cpp

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -696,7 +696,7 @@ TEST_CASE("json_options lossless_bignum")
696696
j.dump(buffer);
697697
CHECK(expected == buffer);
698698
}
699-
SECTION("positive bignum")
699+
SECTION("negative bignum")
700700
{
701701
std::string str = R"({"a":-123456789012345678901234567890})";
702702
std::string expected = R"({"a":-1.2345678901234568e+29})";
@@ -707,5 +707,29 @@ TEST_CASE("json_options lossless_bignum")
707707
j.dump(buffer);
708708
CHECK(expected == buffer);
709709
}
710+
SECTION("+inf")
711+
{
712+
std::string str = R"({"a":1e999})";
713+
std::string expected = R"({"a":null})";
714+
auto options = jsoncons::json_options{}
715+
.lossless_bignum(false);
716+
auto j = jsoncons::json::parse(str, options);
717+
CHECK(HUGE_VAL == j["a"].as<double>());
718+
std::string buffer;
719+
j.dump(buffer);
720+
CHECK(expected == buffer);
721+
}
722+
SECTION("-inf")
723+
{
724+
std::string str = R"({"a":-1e999})";
725+
std::string expected = R"({"a":null})";
726+
auto options = jsoncons::json_options{}
727+
.lossless_bignum(false);
728+
auto j = jsoncons::json::parse(str, options);
729+
CHECK(-HUGE_VAL == j["a"].as<double>());
730+
std::string buffer;
731+
j.dump(buffer);
732+
CHECK(expected == buffer);
733+
}
710734
}
711735

0 commit comments

Comments
 (0)