mirror of
https://github.com/nlohmann/json.git
synced 2026-03-19 15:35:59 +00:00
- If an overflow occurs during parsing a number from a JSON text, an exception (std::out_of_range for the moment, to be replaced by a user-defined exception #244) is thrown so that the overflow is detected early and roundtripping is guaranteed. - NaN and INF floating-point values can be stored in a JSON value and are not replaced by null. That is, the basic_json class behaves like double in this regard (no exception occurs). However, NaN and INF are serialized to “null”. - Adjusted test cases appropriately.
This commit is contained in:
@@ -33,6 +33,7 @@ SOFTWARE.
|
||||
using nlohmann::json;
|
||||
|
||||
#include <fstream>
|
||||
#include <cmath>
|
||||
|
||||
TEST_CASE("CBOR")
|
||||
{
|
||||
@@ -744,13 +745,17 @@ TEST_CASE("CBOR")
|
||||
SECTION("infinity")
|
||||
{
|
||||
json j = json::from_cbor(std::vector<uint8_t>({0xf9, 0x7c, 0x00}));
|
||||
CHECK(j == nullptr);
|
||||
json::number_float_t d = j;
|
||||
CHECK(not std::isfinite(d));
|
||||
CHECK(j.dump() == "null");
|
||||
}
|
||||
|
||||
SECTION("NaN")
|
||||
{
|
||||
json j = json::from_cbor(std::vector<uint8_t>({0xf9, 0x7c, 0x01}));
|
||||
CHECK(j == nullptr);
|
||||
json::number_float_t d = j;
|
||||
CHECK(std::isnan(d));
|
||||
CHECK(j.dump() == "null");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1344,7 +1349,7 @@ TEST_CASE("CBOR roundtrips", "[hide]")
|
||||
"test/data/nst_json_testsuite/test_parsing/y_number_after_space.json",
|
||||
"test/data/nst_json_testsuite/test_parsing/y_number_double_close_to_zero.json",
|
||||
"test/data/nst_json_testsuite/test_parsing/y_number_double_huge_neg_exp.json",
|
||||
"test/data/nst_json_testsuite/test_parsing/y_number_huge_exp.json",
|
||||
//"test/data/nst_json_testsuite/test_parsing/y_number_huge_exp.json",
|
||||
"test/data/nst_json_testsuite/test_parsing/y_number_int_with_exp.json",
|
||||
"test/data/nst_json_testsuite/test_parsing/y_number_minus_zero.json",
|
||||
"test/data/nst_json_testsuite/test_parsing/y_number_negative_int.json",
|
||||
@@ -1356,9 +1361,9 @@ TEST_CASE("CBOR roundtrips", "[hide]")
|
||||
"test/data/nst_json_testsuite/test_parsing/y_number_real_exponent.json",
|
||||
"test/data/nst_json_testsuite/test_parsing/y_number_real_fraction_exponent.json",
|
||||
"test/data/nst_json_testsuite/test_parsing/y_number_real_neg_exp.json",
|
||||
"test/data/nst_json_testsuite/test_parsing/y_number_real_neg_overflow.json",
|
||||
//"test/data/nst_json_testsuite/test_parsing/y_number_real_neg_overflow.json",
|
||||
"test/data/nst_json_testsuite/test_parsing/y_number_real_pos_exponent.json",
|
||||
"test/data/nst_json_testsuite/test_parsing/y_number_real_pos_overflow.json",
|
||||
//"test/data/nst_json_testsuite/test_parsing/y_number_real_pos_overflow.json",
|
||||
"test/data/nst_json_testsuite/test_parsing/y_number_real_underflow.json",
|
||||
"test/data/nst_json_testsuite/test_parsing/y_number_simple_int.json",
|
||||
"test/data/nst_json_testsuite/test_parsing/y_number_simple_real.json",
|
||||
|
||||
Reference in New Issue
Block a user