🚧 move to Catch2

This commit is contained in:
Niels Lohmann 2021-12-31 18:07:54 +01:00
parent 1a41dbe4a7
commit 3fedcbb46f
No known key found for this signature in database
GPG Key ID: 7F3CEA63AE251B69
22 changed files with 358 additions and 350 deletions

View File

@ -62,7 +62,7 @@ TEST_CASE("bad_alloc")
bad_allocator>; bad_allocator>;
// creating an object should throw // creating an object should throw
CHECK_THROWS_AS(bad_json(bad_json::value_t::object), std::bad_alloc&); CHECK_THROWS_AS(bad_json(bad_json::value_t::object), std::bad_alloc);
} }
} }
@ -152,7 +152,7 @@ TEST_CASE("controlled bad_alloc")
auto t = my_json::value_t::object; auto t = my_json::value_t::object;
CHECK_NOTHROW(my_allocator_clean_up(my_json::json_value(t).object)); CHECK_NOTHROW(my_allocator_clean_up(my_json::json_value(t).object));
next_construct_fails = true; next_construct_fails = true;
CHECK_THROWS_AS(my_json::json_value(t), std::bad_alloc&); CHECK_THROWS_AS(my_json::json_value(t), std::bad_alloc);
next_construct_fails = false; next_construct_fails = false;
} }
SECTION("array") SECTION("array")
@ -161,7 +161,7 @@ TEST_CASE("controlled bad_alloc")
auto t = my_json::value_t::array; auto t = my_json::value_t::array;
CHECK_NOTHROW(my_allocator_clean_up(my_json::json_value(t).array)); CHECK_NOTHROW(my_allocator_clean_up(my_json::json_value(t).array));
next_construct_fails = true; next_construct_fails = true;
CHECK_THROWS_AS(my_json::json_value(t), std::bad_alloc&); CHECK_THROWS_AS(my_json::json_value(t), std::bad_alloc);
next_construct_fails = false; next_construct_fails = false;
} }
SECTION("string") SECTION("string")
@ -170,7 +170,7 @@ TEST_CASE("controlled bad_alloc")
auto t = my_json::value_t::string; auto t = my_json::value_t::string;
CHECK_NOTHROW(my_allocator_clean_up(my_json::json_value(t).string)); CHECK_NOTHROW(my_allocator_clean_up(my_json::json_value(t).string));
next_construct_fails = true; next_construct_fails = true;
CHECK_THROWS_AS(my_json::json_value(t), std::bad_alloc&); CHECK_THROWS_AS(my_json::json_value(t), std::bad_alloc);
next_construct_fails = false; next_construct_fails = false;
} }
} }
@ -181,7 +181,7 @@ TEST_CASE("controlled bad_alloc")
my_json::string_t v("foo"); my_json::string_t v("foo");
CHECK_NOTHROW(my_allocator_clean_up(my_json::json_value(v).string)); CHECK_NOTHROW(my_allocator_clean_up(my_json::json_value(v).string));
next_construct_fails = true; next_construct_fails = true;
CHECK_THROWS_AS(my_json::json_value(v), std::bad_alloc&); CHECK_THROWS_AS(my_json::json_value(v), std::bad_alloc);
next_construct_fails = false; next_construct_fails = false;
} }
} }
@ -194,7 +194,7 @@ TEST_CASE("controlled bad_alloc")
std::map<std::string, std::string> v {{"foo", "bar"}}; std::map<std::string, std::string> v {{"foo", "bar"}};
CHECK_NOTHROW(my_json(v)); CHECK_NOTHROW(my_json(v));
next_construct_fails = true; next_construct_fails = true;
CHECK_THROWS_AS(my_json(v), std::bad_alloc&); CHECK_THROWS_AS(my_json(v), std::bad_alloc);
next_construct_fails = false; next_construct_fails = false;
} }
@ -204,7 +204,7 @@ TEST_CASE("controlled bad_alloc")
std::vector<std::string> v {"foo", "bar", "baz"}; std::vector<std::string> v {"foo", "bar", "baz"};
CHECK_NOTHROW(my_json(v)); CHECK_NOTHROW(my_json(v));
next_construct_fails = true; next_construct_fails = true;
CHECK_THROWS_AS(my_json(v), std::bad_alloc&); CHECK_THROWS_AS(my_json(v), std::bad_alloc);
next_construct_fails = false; next_construct_fails = false;
} }
@ -213,7 +213,7 @@ TEST_CASE("controlled bad_alloc")
next_construct_fails = false; next_construct_fails = false;
CHECK_NOTHROW(my_json("foo")); CHECK_NOTHROW(my_json("foo"));
next_construct_fails = true; next_construct_fails = true;
CHECK_THROWS_AS(my_json("foo"), std::bad_alloc&); CHECK_THROWS_AS(my_json("foo"), std::bad_alloc);
next_construct_fails = false; next_construct_fails = false;
} }
@ -223,7 +223,7 @@ TEST_CASE("controlled bad_alloc")
std::string s("foo"); std::string s("foo");
CHECK_NOTHROW(my_json(s)); CHECK_NOTHROW(my_json(s));
next_construct_fails = true; next_construct_fails = true;
CHECK_THROWS_AS(my_json(s), std::bad_alloc&); CHECK_THROWS_AS(my_json(s), std::bad_alloc);
next_construct_fails = false; next_construct_fails = false;
} }
} }

View File

@ -922,7 +922,7 @@ TEST_CASE("BSON numerical data")
for (auto i : numbers) for (auto i : numbers)
{ {
CAPTURE(i) CAPTURE(i);
json j = json j =
{ {
@ -994,7 +994,7 @@ TEST_CASE("BSON numerical data")
for (auto i : numbers) for (auto i : numbers)
{ {
CAPTURE(i) CAPTURE(i);
json j = json j =
{ {
@ -1047,7 +1047,7 @@ TEST_CASE("BSON numerical data")
for (auto i : numbers) for (auto i : numbers)
{ {
CAPTURE(i) CAPTURE(i);
json j = json j =
{ {
@ -1109,7 +1109,7 @@ TEST_CASE("BSON numerical data")
for (auto i : numbers) for (auto i : numbers)
{ {
CAPTURE(i) CAPTURE(i);
json j = json j =
{ {
@ -1164,7 +1164,7 @@ TEST_CASE("BSON numerical data")
for (auto i : numbers) for (auto i : numbers)
{ {
CAPTURE(i) CAPTURE(i);
json j = json j =
{ {
@ -1214,7 +1214,7 @@ TEST_CASE("BSON numerical data")
for (auto i : numbers) for (auto i : numbers)
{ {
CAPTURE(i) CAPTURE(i);
json j = json j =
{ {
@ -1242,7 +1242,7 @@ TEST_CASE("BSON numerical data")
#if JSON_DIAGNOSTICS #if JSON_DIAGNOSTICS
CHECK_THROWS_WITH_STD_STR(json::to_bson(j), "[json.exception.out_of_range.407] (/entry) integer number " + std::to_string(i) + " cannot be represented by BSON as it does not fit int64"); CHECK_THROWS_WITH_STD_STR(json::to_bson(j), "[json.exception.out_of_range.407] (/entry) integer number " + std::to_string(i) + " cannot be represented by BSON as it does not fit int64");
#else #else
CHECK_THROWS_WITH_STD_STR(json::to_bson(j), "[json.exception.out_of_range.407] integer number " + std::to_string(i) + " cannot be represented by BSON as it does not fit int64"); CHECK_THROWS_WITH(json::to_bson(j), "[json.exception.out_of_range.407] integer number " + std::to_string(i) + " cannot be represented by BSON as it does not fit int64");
#endif #endif
} }
} }
@ -1251,7 +1251,7 @@ TEST_CASE("BSON numerical data")
} }
} }
TEST_CASE("BSON roundtrips" * doctest::skip()) TEST_CASE("BSON roundtrips", "[.]")
{ {
SECTION("reference files") SECTION("reference files")
{ {
@ -1264,10 +1264,10 @@ TEST_CASE("BSON roundtrips" * doctest::skip())
TEST_DATA_DIRECTORY "/json.org/5.json" TEST_DATA_DIRECTORY "/json.org/5.json"
}) })
{ {
CAPTURE(filename) CAPTURE(filename);
SECTION(filename + ": std::vector<std::uint8_t>")
{ {
INFO_WITH_TEMP(filename + ": std::vector<std::uint8_t>");
// parse JSON file // parse JSON file
std::ifstream f_json(filename); std::ifstream f_json(filename);
json j1 = json::parse(f_json); json j1 = json::parse(f_json);
@ -1281,8 +1281,8 @@ TEST_CASE("BSON roundtrips" * doctest::skip())
CHECK(j1 == j2); CHECK(j1 == j2);
} }
SECTION(filename + ": std::ifstream")
{ {
INFO_WITH_TEMP(filename + ": std::ifstream");
// parse JSON file // parse JSON file
std::ifstream f_json(filename); std::ifstream f_json(filename);
json j1 = json::parse(f_json); json j1 = json::parse(f_json);
@ -1296,8 +1296,8 @@ TEST_CASE("BSON roundtrips" * doctest::skip())
CHECK(j1 == j2); CHECK(j1 == j2);
} }
SECTION(filename + ": uint8_t* and size")
{ {
INFO_WITH_TEMP(filename + ": uint8_t* and size");
// parse JSON file // parse JSON file
std::ifstream f_json(filename); std::ifstream f_json(filename);
json j1 = json::parse(f_json); json j1 = json::parse(f_json);
@ -1311,8 +1311,8 @@ TEST_CASE("BSON roundtrips" * doctest::skip())
CHECK(j1 == j2); CHECK(j1 == j2);
} }
SECTION(filename + ": output to output adapters")
{ {
INFO_WITH_TEMP(filename + ": output to output adapters");
// parse JSON file // parse JSON file
std::ifstream f_json(filename); std::ifstream f_json(filename);
json j1 = json::parse(f_json); json j1 = json::parse(f_json);
@ -1320,8 +1320,8 @@ TEST_CASE("BSON roundtrips" * doctest::skip())
// parse BSON file // parse BSON file
auto packed = utils::read_binary_file(filename + ".bson"); auto packed = utils::read_binary_file(filename + ".bson");
SECTION(filename + ": output adapters: std::vector<std::uint8_t>")
{ {
INFO_WITH_TEMP(filename + ": output adapters: std::vector<std::uint8_t>");
std::vector<std::uint8_t> vec; std::vector<std::uint8_t> vec;
json::to_bson(j1, vec); json::to_bson(j1, vec);

View File

@ -132,7 +132,7 @@ TEST_CASE("iterator class")
{ {
json j(json::value_t::null); json j(json::value_t::null);
json::iterator it = j.begin(); json::iterator it = j.begin();
CHECK_THROWS_AS(*it, json::invalid_iterator&); CHECK_THROWS_AS(*it, json::invalid_iterator);
CHECK_THROWS_WITH(*it, "[json.exception.invalid_iterator.214] cannot get value"); CHECK_THROWS_WITH(*it, "[json.exception.invalid_iterator.214] cannot get value");
} }
@ -142,7 +142,7 @@ TEST_CASE("iterator class")
json::iterator it = j.begin(); json::iterator it = j.begin();
CHECK(*it == json(17)); CHECK(*it == json(17));
it = j.end(); it = j.end();
CHECK_THROWS_AS(*it, json::invalid_iterator&); CHECK_THROWS_AS(*it, json::invalid_iterator);
CHECK_THROWS_WITH(*it, "[json.exception.invalid_iterator.214] cannot get value"); CHECK_THROWS_WITH(*it, "[json.exception.invalid_iterator.214] cannot get value");
} }
@ -167,7 +167,7 @@ TEST_CASE("iterator class")
{ {
json j(json::value_t::null); json j(json::value_t::null);
json::iterator it = j.begin(); json::iterator it = j.begin();
CHECK_THROWS_AS(std::string(it->type_name()), json::invalid_iterator&); CHECK_THROWS_AS(std::string(it->type_name()), json::invalid_iterator);
CHECK_THROWS_WITH(std::string(it->type_name()), "[json.exception.invalid_iterator.214] cannot get value"); CHECK_THROWS_WITH(std::string(it->type_name()), "[json.exception.invalid_iterator.214] cannot get value");
} }
@ -177,7 +177,7 @@ TEST_CASE("iterator class")
json::iterator it = j.begin(); json::iterator it = j.begin();
CHECK(std::string(it->type_name()) == "number"); CHECK(std::string(it->type_name()) == "number");
it = j.end(); it = j.end();
CHECK_THROWS_AS(std::string(it->type_name()), json::invalid_iterator&); CHECK_THROWS_AS(std::string(it->type_name()), json::invalid_iterator);
CHECK_THROWS_WITH(std::string(it->type_name()), "[json.exception.invalid_iterator.214] cannot get value"); CHECK_THROWS_WITH(std::string(it->type_name()), "[json.exception.invalid_iterator.214] cannot get value");
} }

View File

@ -1172,7 +1172,7 @@ TEST_CASE("parser class")
// only check error message if c is not a control character // only check error message if c is not a control character
if (c > 0x1f) if (c > 0x1f)
{ {
CHECK_THROWS_WITH_STD_STR(parser_helper(s), CHECK_THROWS_WITH(parser_helper(s),
"[json.exception.parse_error.101] parse error at line 1, column 3: syntax error while parsing value - invalid string: forbidden character after backslash; last read: '\"\\" + std::string(1, static_cast<char>(c)) + "'"); "[json.exception.parse_error.101] parse error at line 1, column 3: syntax error while parsing value - invalid string: forbidden character after backslash; last read: '\"\\" + std::string(1, static_cast<char>(c)) + "'");
} }
break; break;
@ -1232,50 +1232,50 @@ TEST_CASE("parser class")
if (valid(c)) if (valid(c))
{ {
CAPTURE(s1) CAPTURE(s1);
CHECK_NOTHROW(parser_helper(s1)); CHECK_NOTHROW(parser_helper(s1));
CAPTURE(s2) CAPTURE(s2);
CHECK_NOTHROW(parser_helper(s2)); CHECK_NOTHROW(parser_helper(s2));
CAPTURE(s3) CAPTURE(s3);
CHECK_NOTHROW(parser_helper(s3)); CHECK_NOTHROW(parser_helper(s3));
CAPTURE(s4) CAPTURE(s4);
CHECK_NOTHROW(parser_helper(s4)); CHECK_NOTHROW(parser_helper(s4));
} }
else else
{ {
CAPTURE(s1) CAPTURE(s1);
CHECK_THROWS_AS(parser_helper(s1), json::parse_error); CHECK_THROWS_AS(parser_helper(s1), json::parse_error);
// only check error message if c is not a control character // only check error message if c is not a control character
if (c > 0x1f) if (c > 0x1f)
{ {
CHECK_THROWS_WITH_STD_STR(parser_helper(s1), CHECK_THROWS_WITH(parser_helper(s1),
"[json.exception.parse_error.101] parse error at line 1, column 7: syntax error while parsing value - invalid string: '\\u' must be followed by 4 hex digits; last read: '" + s1.substr(0, 7) + "'"); "[json.exception.parse_error.101] parse error at line 1, column 7: syntax error while parsing value - invalid string: '\\u' must be followed by 4 hex digits; last read: '" + s1.substr(0, 7) + "'");
} }
CAPTURE(s2) CAPTURE(s2);
CHECK_THROWS_AS(parser_helper(s2), json::parse_error); CHECK_THROWS_AS(parser_helper(s2), json::parse_error);
// only check error message if c is not a control character // only check error message if c is not a control character
if (c > 0x1f) if (c > 0x1f)
{ {
CHECK_THROWS_WITH_STD_STR(parser_helper(s2), CHECK_THROWS_WITH(parser_helper(s2),
"[json.exception.parse_error.101] parse error at line 1, column 6: syntax error while parsing value - invalid string: '\\u' must be followed by 4 hex digits; last read: '" + s2.substr(0, 6) + "'"); "[json.exception.parse_error.101] parse error at line 1, column 6: syntax error while parsing value - invalid string: '\\u' must be followed by 4 hex digits; last read: '" + s2.substr(0, 6) + "'");
} }
CAPTURE(s3) CAPTURE(s3);
CHECK_THROWS_AS(parser_helper(s3), json::parse_error); CHECK_THROWS_AS(parser_helper(s3), json::parse_error);
// only check error message if c is not a control character // only check error message if c is not a control character
if (c > 0x1f) if (c > 0x1f)
{ {
CHECK_THROWS_WITH_STD_STR(parser_helper(s3), CHECK_THROWS_WITH(parser_helper(s3),
"[json.exception.parse_error.101] parse error at line 1, column 5: syntax error while parsing value - invalid string: '\\u' must be followed by 4 hex digits; last read: '" + s3.substr(0, 5) + "'"); "[json.exception.parse_error.101] parse error at line 1, column 5: syntax error while parsing value - invalid string: '\\u' must be followed by 4 hex digits; last read: '" + s3.substr(0, 5) + "'");
} }
CAPTURE(s4) CAPTURE(s4);
CHECK_THROWS_AS(parser_helper(s4), json::parse_error); CHECK_THROWS_AS(parser_helper(s4), json::parse_error);
// only check error message if c is not a control character // only check error message if c is not a control character
if (c > 0x1f) if (c > 0x1f)
{ {
CHECK_THROWS_WITH_STD_STR(parser_helper(s4), CHECK_THROWS_WITH(parser_helper(s4),
"[json.exception.parse_error.101] parse error at line 1, column 4: syntax error while parsing value - invalid string: '\\u' must be followed by 4 hex digits; last read: '" + s4.substr(0, 4) + "'"); "[json.exception.parse_error.101] parse error at line 1, column 4: syntax error while parsing value - invalid string: '\\u' must be followed by 4 hex digits; last read: '" + s4.substr(0, 4) + "'");
} }
} }
@ -1452,27 +1452,27 @@ TEST_CASE("parser class")
if (valid(c)) if (valid(c))
{ {
CAPTURE(s1) CAPTURE(s1);
CHECK(json::parser(nlohmann::detail::input_adapter(s1)).accept()); CHECK(json::parser(nlohmann::detail::input_adapter(s1)).accept());
CAPTURE(s2) CAPTURE(s2);
CHECK(json::parser(nlohmann::detail::input_adapter(s2)).accept()); CHECK(json::parser(nlohmann::detail::input_adapter(s2)).accept());
CAPTURE(s3) CAPTURE(s3);
CHECK(json::parser(nlohmann::detail::input_adapter(s3)).accept()); CHECK(json::parser(nlohmann::detail::input_adapter(s3)).accept());
CAPTURE(s4) CAPTURE(s4);
CHECK(json::parser(nlohmann::detail::input_adapter(s4)).accept()); CHECK(json::parser(nlohmann::detail::input_adapter(s4)).accept());
} }
else else
{ {
CAPTURE(s1) CAPTURE(s1);
CHECK(json::parser(nlohmann::detail::input_adapter(s1)).accept() == false); CHECK(json::parser(nlohmann::detail::input_adapter(s1)).accept() == false);
CAPTURE(s2) CAPTURE(s2);
CHECK(json::parser(nlohmann::detail::input_adapter(s2)).accept() == false); CHECK(json::parser(nlohmann::detail::input_adapter(s2)).accept() == false);
CAPTURE(s3) CAPTURE(s3);
CHECK(json::parser(nlohmann::detail::input_adapter(s3)).accept() == false); CHECK(json::parser(nlohmann::detail::input_adapter(s3)).accept() == false);
CAPTURE(s4) CAPTURE(s4);
CHECK(json::parser(nlohmann::detail::input_adapter(s4)).accept() == false); CHECK(json::parser(nlohmann::detail::input_adapter(s4)).accept() == false);
} }
} }

View File

@ -305,11 +305,11 @@ TEST_CASE("constructors")
{ {
json j{1}; json j{1};
CHECK_THROWS_AS((j.get<std::pair<int, int>>()), json::out_of_range&); CHECK_THROWS_AS((j.get<std::pair<int, int>>()), json::out_of_range);
CHECK_THROWS_WITH((j.get<std::pair<int, int>>()), "[json.exception.out_of_range.401] array index 1 is out of range"); CHECK_THROWS_WITH((j.get<std::pair<int, int>>()), "[json.exception.out_of_range.401] array index 1 is out of range");
CHECK_THROWS_AS((j.get<std::tuple<int, int>>()), json::out_of_range&); CHECK_THROWS_AS((j.get<std::tuple<int, int>>()), json::out_of_range);
CHECK_THROWS_WITH((j.get<std::tuple<int, int>>()), "[json.exception.out_of_range.401] array index 1 is out of range"); CHECK_THROWS_WITH((j.get<std::tuple<int, int>>()), "[json.exception.out_of_range.401] array index 1 is out of range");
CHECK_THROWS_AS((j.get<std::array<int, 3>>()), json::out_of_range&); CHECK_THROWS_AS((j.get<std::array<int, 3>>()), json::out_of_range);
CHECK_THROWS_WITH((j.get<std::array<int, 3>>()), "[json.exception.out_of_range.401] array index 1 is out of range"); CHECK_THROWS_WITH((j.get<std::array<int, 3>>()), "[json.exception.out_of_range.401] array index 1 is out of range");
} }
@ -878,7 +878,7 @@ TEST_CASE("constructors")
float n = 42.23f; float n = 42.23f;
json j(n); json j(n);
CHECK(j.type() == json::value_t::number_float); CHECK(j.type() == json::value_t::number_float);
CHECK(j.m_value.number_float == Approx(j_reference.m_value.number_float)); CHECK(j.m_value.number_float == Catch::Approx(j_reference.m_value.number_float));
} }
SECTION("double") SECTION("double")
@ -886,7 +886,7 @@ TEST_CASE("constructors")
double n = 42.23; double n = 42.23;
json j(n); json j(n);
CHECK(j.type() == json::value_t::number_float); CHECK(j.type() == json::value_t::number_float);
CHECK(j.m_value.number_float == Approx(j_reference.m_value.number_float)); CHECK(j.m_value.number_float == Catch::Approx(j_reference.m_value.number_float));
} }
SECTION("long double") SECTION("long double")
@ -894,28 +894,28 @@ TEST_CASE("constructors")
long double n = 42.23L; long double n = 42.23L;
json j(n); json j(n);
CHECK(j.type() == json::value_t::number_float); CHECK(j.type() == json::value_t::number_float);
CHECK(j.m_value.number_float == Approx(j_reference.m_value.number_float)); CHECK(j.m_value.number_float == Catch::Approx(j_reference.m_value.number_float));
} }
SECTION("floating-point literal without suffix") SECTION("floating-point literal without suffix")
{ {
json j(42.23); json j(42.23);
CHECK(j.type() == json::value_t::number_float); CHECK(j.type() == json::value_t::number_float);
CHECK(j.m_value.number_float == Approx(j_reference.m_value.number_float)); CHECK(j.m_value.number_float == Catch::Approx(j_reference.m_value.number_float));
} }
SECTION("integer literal with f suffix") SECTION("integer literal with f suffix")
{ {
json j(42.23f); json j(42.23f);
CHECK(j.type() == json::value_t::number_float); CHECK(j.type() == json::value_t::number_float);
CHECK(j.m_value.number_float == Approx(j_reference.m_value.number_float)); CHECK(j.m_value.number_float == Catch::Approx(j_reference.m_value.number_float));
} }
SECTION("integer literal with l suffix") SECTION("integer literal with l suffix")
{ {
json j(42.23L); json j(42.23L);
CHECK(j.type() == json::value_t::number_float); CHECK(j.type() == json::value_t::number_float);
CHECK(j.m_value.number_float == Approx(j_reference.m_value.number_float)); CHECK(j.m_value.number_float == Catch::Approx(j_reference.m_value.number_float));
} }
} }
@ -1092,7 +1092,7 @@ TEST_CASE("constructors")
{ {
json _; json _;
CHECK_THROWS_AS(_ = json::object({ {"one", 1}, {"two", 1u}, {"three", 2.2}, {"four", false}, 13 }), CHECK_THROWS_AS(_ = json::object({ {"one", 1}, {"two", 1u}, {"three", 2.2}, {"four", false}, 13 }),
json::type_error&); json::type_error);
CHECK_THROWS_WITH(_ = json::object({ {"one", 1}, {"two", 1u}, {"three", 2.2}, {"four", false}, 13 }), CHECK_THROWS_WITH(_ = json::object({ {"one", 1}, {"two", 1u}, {"three", 2.2}, {"four", false}, 13 }),
"[json.exception.type_error.301] cannot create object from initializer list"); "[json.exception.type_error.301] cannot create object from initializer list");
} }
@ -1340,16 +1340,16 @@ TEST_CASE("constructors")
{ {
json jobject = {{"a", "a"}, {"b", 1}, {"c", 17u}, {"d", false}, {"e", true}}; json jobject = {{"a", "a"}, {"b", 1}, {"c", 17u}, {"d", false}, {"e", true}};
json jobject2 = {{"a", "a"}, {"b", 1}, {"c", 17u}}; json jobject2 = {{"a", "a"}, {"b", 1}, {"c", 17u}};
CHECK_THROWS_AS(json(jobject.begin(), jobject2.end()), json::invalid_iterator&); CHECK_THROWS_AS(json(jobject.begin(), jobject2.end()), json::invalid_iterator);
CHECK_THROWS_AS(json(jobject2.begin(), jobject.end()), json::invalid_iterator&); CHECK_THROWS_AS(json(jobject2.begin(), jobject.end()), json::invalid_iterator);
CHECK_THROWS_WITH(json(jobject.begin(), jobject2.end()), "[json.exception.invalid_iterator.201] iterators are not compatible"); CHECK_THROWS_WITH(json(jobject.begin(), jobject2.end()), "[json.exception.invalid_iterator.201] iterators are not compatible");
CHECK_THROWS_WITH(json(jobject2.begin(), jobject.end()), "[json.exception.invalid_iterator.201] iterators are not compatible"); CHECK_THROWS_WITH(json(jobject2.begin(), jobject.end()), "[json.exception.invalid_iterator.201] iterators are not compatible");
} }
{ {
json jobject = {{"a", "a"}, {"b", 1}, {"c", 17u}, {"d", false}, {"e", true}}; json jobject = {{"a", "a"}, {"b", 1}, {"c", 17u}, {"d", false}, {"e", true}};
json jobject2 = {{"a", "a"}, {"b", 1}, {"c", 17u}}; json jobject2 = {{"a", "a"}, {"b", 1}, {"c", 17u}};
CHECK_THROWS_AS(json(jobject.cbegin(), jobject2.cend()), json::invalid_iterator&); CHECK_THROWS_AS(json(jobject.cbegin(), jobject2.cend()), json::invalid_iterator);
CHECK_THROWS_AS(json(jobject2.cbegin(), jobject.cend()), json::invalid_iterator&); CHECK_THROWS_AS(json(jobject2.cbegin(), jobject.cend()), json::invalid_iterator);
CHECK_THROWS_WITH(json(jobject.cbegin(), jobject2.cend()), "[json.exception.invalid_iterator.201] iterators are not compatible"); CHECK_THROWS_WITH(json(jobject.cbegin(), jobject2.cend()), "[json.exception.invalid_iterator.201] iterators are not compatible");
CHECK_THROWS_WITH(json(jobject2.cbegin(), jobject.cend()), "[json.exception.invalid_iterator.201] iterators are not compatible"); CHECK_THROWS_WITH(json(jobject2.cbegin(), jobject.cend()), "[json.exception.invalid_iterator.201] iterators are not compatible");
} }
@ -1405,16 +1405,16 @@ TEST_CASE("constructors")
{ {
json jarray = {1, 2, 3, 4}; json jarray = {1, 2, 3, 4};
json jarray2 = {2, 3, 4, 5}; json jarray2 = {2, 3, 4, 5};
CHECK_THROWS_AS(json(jarray.begin(), jarray2.end()), json::invalid_iterator&); CHECK_THROWS_AS(json(jarray.begin(), jarray2.end()), json::invalid_iterator);
CHECK_THROWS_AS(json(jarray2.begin(), jarray.end()), json::invalid_iterator&); CHECK_THROWS_AS(json(jarray2.begin(), jarray.end()), json::invalid_iterator);
CHECK_THROWS_WITH(json(jarray.begin(), jarray2.end()), "[json.exception.invalid_iterator.201] iterators are not compatible"); CHECK_THROWS_WITH(json(jarray.begin(), jarray2.end()), "[json.exception.invalid_iterator.201] iterators are not compatible");
CHECK_THROWS_WITH(json(jarray2.begin(), jarray.end()), "[json.exception.invalid_iterator.201] iterators are not compatible"); CHECK_THROWS_WITH(json(jarray2.begin(), jarray.end()), "[json.exception.invalid_iterator.201] iterators are not compatible");
} }
{ {
json jarray = {1, 2, 3, 4}; json jarray = {1, 2, 3, 4};
json jarray2 = {2, 3, 4, 5}; json jarray2 = {2, 3, 4, 5};
CHECK_THROWS_AS(json(jarray.cbegin(), jarray2.cend()), json::invalid_iterator&); CHECK_THROWS_AS(json(jarray.cbegin(), jarray2.cend()), json::invalid_iterator);
CHECK_THROWS_AS(json(jarray2.cbegin(), jarray.cend()), json::invalid_iterator&); CHECK_THROWS_AS(json(jarray2.cbegin(), jarray.cend()), json::invalid_iterator);
CHECK_THROWS_WITH(json(jarray.cbegin(), jarray2.cend()), "[json.exception.invalid_iterator.201] iterators are not compatible"); CHECK_THROWS_WITH(json(jarray.cbegin(), jarray2.cend()), "[json.exception.invalid_iterator.201] iterators are not compatible");
CHECK_THROWS_WITH(json(jarray2.cbegin(), jarray.cend()), "[json.exception.invalid_iterator.201] iterators are not compatible"); CHECK_THROWS_WITH(json(jarray2.cbegin(), jarray.cend()), "[json.exception.invalid_iterator.201] iterators are not compatible");
} }
@ -1429,13 +1429,13 @@ TEST_CASE("constructors")
{ {
{ {
json j; json j;
CHECK_THROWS_AS(json(j.begin(), j.end()), json::invalid_iterator&); CHECK_THROWS_AS(json(j.begin(), j.end()), json::invalid_iterator);
CHECK_THROWS_WITH(json(j.begin(), j.end()), CHECK_THROWS_WITH(json(j.begin(), j.end()),
"[json.exception.invalid_iterator.206] cannot construct with iterators from null"); "[json.exception.invalid_iterator.206] cannot construct with iterators from null");
} }
{ {
json j; json j;
CHECK_THROWS_AS(json(j.cbegin(), j.cend()), json::invalid_iterator&); CHECK_THROWS_AS(json(j.cbegin(), j.cend()), json::invalid_iterator);
CHECK_THROWS_WITH(json(j.cbegin(), j.cend()), CHECK_THROWS_WITH(json(j.cbegin(), j.cend()),
"[json.exception.invalid_iterator.206] cannot construct with iterators from null"); "[json.exception.invalid_iterator.206] cannot construct with iterators from null");
} }
@ -1532,15 +1532,15 @@ TEST_CASE("constructors")
{ {
{ {
json j = "foo"; json j = "foo";
CHECK_THROWS_AS(json(j.end(), j.end()), json::invalid_iterator&); CHECK_THROWS_AS(json(j.end(), j.end()), json::invalid_iterator);
CHECK_THROWS_AS(json(j.begin(), j.begin()), json::invalid_iterator&); CHECK_THROWS_AS(json(j.begin(), j.begin()), json::invalid_iterator);
CHECK_THROWS_WITH(json(j.end(), j.end()), "[json.exception.invalid_iterator.204] iterators out of range"); CHECK_THROWS_WITH(json(j.end(), j.end()), "[json.exception.invalid_iterator.204] iterators out of range");
CHECK_THROWS_WITH(json(j.begin(), j.begin()), "[json.exception.invalid_iterator.204] iterators out of range"); CHECK_THROWS_WITH(json(j.begin(), j.begin()), "[json.exception.invalid_iterator.204] iterators out of range");
} }
{ {
json j = "bar"; json j = "bar";
CHECK_THROWS_AS(json(j.cend(), j.cend()), json::invalid_iterator&); CHECK_THROWS_AS(json(j.cend(), j.cend()), json::invalid_iterator);
CHECK_THROWS_AS(json(j.cbegin(), j.cbegin()), json::invalid_iterator&); CHECK_THROWS_AS(json(j.cbegin(), j.cbegin()), json::invalid_iterator);
CHECK_THROWS_WITH(json(j.cend(), j.cend()), "[json.exception.invalid_iterator.204] iterators out of range"); CHECK_THROWS_WITH(json(j.cend(), j.cend()), "[json.exception.invalid_iterator.204] iterators out of range");
CHECK_THROWS_WITH(json(j.cbegin(), j.cbegin()), "[json.exception.invalid_iterator.204] iterators out of range"); CHECK_THROWS_WITH(json(j.cbegin(), j.cbegin()), "[json.exception.invalid_iterator.204] iterators out of range");
} }
@ -1550,15 +1550,15 @@ TEST_CASE("constructors")
{ {
{ {
json j = false; json j = false;
CHECK_THROWS_AS(json(j.end(), j.end()), json::invalid_iterator&); CHECK_THROWS_AS(json(j.end(), j.end()), json::invalid_iterator);
CHECK_THROWS_AS(json(j.begin(), j.begin()), json::invalid_iterator&); CHECK_THROWS_AS(json(j.begin(), j.begin()), json::invalid_iterator);
CHECK_THROWS_WITH(json(j.end(), j.end()), "[json.exception.invalid_iterator.204] iterators out of range"); CHECK_THROWS_WITH(json(j.end(), j.end()), "[json.exception.invalid_iterator.204] iterators out of range");
CHECK_THROWS_WITH(json(j.begin(), j.begin()), "[json.exception.invalid_iterator.204] iterators out of range"); CHECK_THROWS_WITH(json(j.begin(), j.begin()), "[json.exception.invalid_iterator.204] iterators out of range");
} }
{ {
json j = true; json j = true;
CHECK_THROWS_AS(json(j.cend(), j.cend()), json::invalid_iterator&); CHECK_THROWS_AS(json(j.cend(), j.cend()), json::invalid_iterator);
CHECK_THROWS_AS(json(j.cbegin(), j.cbegin()), json::invalid_iterator&); CHECK_THROWS_AS(json(j.cbegin(), j.cbegin()), json::invalid_iterator);
CHECK_THROWS_WITH(json(j.cend(), j.cend()), "[json.exception.invalid_iterator.204] iterators out of range"); CHECK_THROWS_WITH(json(j.cend(), j.cend()), "[json.exception.invalid_iterator.204] iterators out of range");
CHECK_THROWS_WITH(json(j.cbegin(), j.cbegin()), "[json.exception.invalid_iterator.204] iterators out of range"); CHECK_THROWS_WITH(json(j.cbegin(), j.cbegin()), "[json.exception.invalid_iterator.204] iterators out of range");
} }
@ -1568,15 +1568,15 @@ TEST_CASE("constructors")
{ {
{ {
json j = 17; json j = 17;
CHECK_THROWS_AS(json(j.end(), j.end()), json::invalid_iterator&); CHECK_THROWS_AS(json(j.end(), j.end()), json::invalid_iterator);
CHECK_THROWS_AS(json(j.begin(), j.begin()), json::invalid_iterator&); CHECK_THROWS_AS(json(j.begin(), j.begin()), json::invalid_iterator);
CHECK_THROWS_WITH(json(j.end(), j.end()), "[json.exception.invalid_iterator.204] iterators out of range"); CHECK_THROWS_WITH(json(j.end(), j.end()), "[json.exception.invalid_iterator.204] iterators out of range");
CHECK_THROWS_WITH(json(j.begin(), j.begin()), "[json.exception.invalid_iterator.204] iterators out of range"); CHECK_THROWS_WITH(json(j.begin(), j.begin()), "[json.exception.invalid_iterator.204] iterators out of range");
} }
{ {
json j = 17; json j = 17;
CHECK_THROWS_AS(json(j.cend(), j.cend()), json::invalid_iterator&); CHECK_THROWS_AS(json(j.cend(), j.cend()), json::invalid_iterator);
CHECK_THROWS_AS(json(j.cbegin(), j.cbegin()), json::invalid_iterator&); CHECK_THROWS_AS(json(j.cbegin(), j.cbegin()), json::invalid_iterator);
CHECK_THROWS_WITH(json(j.cend(), j.cend()), "[json.exception.invalid_iterator.204] iterators out of range"); CHECK_THROWS_WITH(json(j.cend(), j.cend()), "[json.exception.invalid_iterator.204] iterators out of range");
CHECK_THROWS_WITH(json(j.cbegin(), j.cbegin()), "[json.exception.invalid_iterator.204] iterators out of range"); CHECK_THROWS_WITH(json(j.cbegin(), j.cbegin()), "[json.exception.invalid_iterator.204] iterators out of range");
} }
@ -1586,15 +1586,15 @@ TEST_CASE("constructors")
{ {
{ {
json j = 17u; json j = 17u;
CHECK_THROWS_AS(json(j.end(), j.end()), json::invalid_iterator&); CHECK_THROWS_AS(json(j.end(), j.end()), json::invalid_iterator);
CHECK_THROWS_AS(json(j.begin(), j.begin()), json::invalid_iterator&); CHECK_THROWS_AS(json(j.begin(), j.begin()), json::invalid_iterator);
CHECK_THROWS_WITH(json(j.end(), j.end()), "[json.exception.invalid_iterator.204] iterators out of range"); CHECK_THROWS_WITH(json(j.end(), j.end()), "[json.exception.invalid_iterator.204] iterators out of range");
CHECK_THROWS_WITH(json(j.begin(), j.begin()), "[json.exception.invalid_iterator.204] iterators out of range"); CHECK_THROWS_WITH(json(j.begin(), j.begin()), "[json.exception.invalid_iterator.204] iterators out of range");
} }
{ {
json j = 17u; json j = 17u;
CHECK_THROWS_AS(json(j.cend(), j.cend()), json::invalid_iterator&); CHECK_THROWS_AS(json(j.cend(), j.cend()), json::invalid_iterator);
CHECK_THROWS_AS(json(j.cbegin(), j.cbegin()), json::invalid_iterator&); CHECK_THROWS_AS(json(j.cbegin(), j.cbegin()), json::invalid_iterator);
CHECK_THROWS_WITH(json(j.cend(), j.cend()), "[json.exception.invalid_iterator.204] iterators out of range"); CHECK_THROWS_WITH(json(j.cend(), j.cend()), "[json.exception.invalid_iterator.204] iterators out of range");
CHECK_THROWS_WITH(json(j.cbegin(), j.cbegin()), "[json.exception.invalid_iterator.204] iterators out of range"); CHECK_THROWS_WITH(json(j.cbegin(), j.cbegin()), "[json.exception.invalid_iterator.204] iterators out of range");
} }
@ -1604,15 +1604,15 @@ TEST_CASE("constructors")
{ {
{ {
json j = 23.42; json j = 23.42;
CHECK_THROWS_AS(json(j.end(), j.end()), json::invalid_iterator&); CHECK_THROWS_AS(json(j.end(), j.end()), json::invalid_iterator);
CHECK_THROWS_AS(json(j.begin(), j.begin()), json::invalid_iterator&); CHECK_THROWS_AS(json(j.begin(), j.begin()), json::invalid_iterator);
CHECK_THROWS_WITH(json(j.end(), j.end()), "[json.exception.invalid_iterator.204] iterators out of range"); CHECK_THROWS_WITH(json(j.end(), j.end()), "[json.exception.invalid_iterator.204] iterators out of range");
CHECK_THROWS_WITH(json(j.begin(), j.begin()), "[json.exception.invalid_iterator.204] iterators out of range"); CHECK_THROWS_WITH(json(j.begin(), j.begin()), "[json.exception.invalid_iterator.204] iterators out of range");
} }
{ {
json j = 23.42; json j = 23.42;
CHECK_THROWS_AS(json(j.cend(), j.cend()), json::invalid_iterator&); CHECK_THROWS_AS(json(j.cend(), j.cend()), json::invalid_iterator);
CHECK_THROWS_AS(json(j.cbegin(), j.cbegin()), json::invalid_iterator&); CHECK_THROWS_AS(json(j.cbegin(), j.cbegin()), json::invalid_iterator);
CHECK_THROWS_WITH(json(j.cend(), j.cend()), "[json.exception.invalid_iterator.204] iterators out of range"); CHECK_THROWS_WITH(json(j.cend(), j.cend()), "[json.exception.invalid_iterator.204] iterators out of range");
CHECK_THROWS_WITH(json(j.cbegin(), j.cbegin()), "[json.exception.invalid_iterator.204] iterators out of range"); CHECK_THROWS_WITH(json(j.cbegin(), j.cbegin()), "[json.exception.invalid_iterator.204] iterators out of range");
} }

View File

@ -106,11 +106,11 @@ TEST_CASE("convenience functions")
check_escaped("\x1f", "\\u001f"); check_escaped("\x1f", "\\u001f");
// invalid UTF-8 characters // invalid UTF-8 characters
CHECK_THROWS_AS(check_escaped("ä\xA9ü"), json::type_error&); CHECK_THROWS_AS(check_escaped("ä\xA9ü"), json::type_error);
CHECK_THROWS_WITH(check_escaped("ä\xA9ü"), CHECK_THROWS_WITH(check_escaped("ä\xA9ü"),
"[json.exception.type_error.316] invalid UTF-8 byte at index 2: 0xA9"); "[json.exception.type_error.316] invalid UTF-8 byte at index 2: 0xA9");
CHECK_THROWS_AS(check_escaped("\xC2"), json::type_error&); CHECK_THROWS_AS(check_escaped("\xC2"), json::type_error);
CHECK_THROWS_WITH(check_escaped("\xC2"), CHECK_THROWS_WITH(check_escaped("\xC2"),
"[json.exception.type_error.316] incomplete UTF-8 string; last byte: 0xC2"); "[json.exception.type_error.316] incomplete UTF-8 string; last byte: 0xC2");
} }

View File

@ -1192,19 +1192,19 @@ TEST_CASE("value conversion")
SECTION("number_float_t") SECTION("number_float_t")
{ {
auto n = j.get<json::number_float_t>(); auto n = j.get<json::number_float_t>();
CHECK(json(n).m_value.number_float == Approx(j.m_value.number_float)); CHECK(json(n).m_value.number_float == Catch::Approx(j.m_value.number_float));
} }
SECTION("float") SECTION("float")
{ {
auto n = j.get<float>(); auto n = j.get<float>();
CHECK(json(n).m_value.number_float == Approx(j.m_value.number_float)); CHECK(json(n).m_value.number_float == Catch::Approx(j.m_value.number_float));
} }
SECTION("double") SECTION("double")
{ {
auto n = j.get<double>(); auto n = j.get<double>();
CHECK(json(n).m_value.number_float == Approx(j.m_value.number_float)); CHECK(json(n).m_value.number_float == Catch::Approx(j.m_value.number_float));
} }
SECTION("exception in case of a non-string type") SECTION("exception in case of a non-string type")
@ -1253,19 +1253,19 @@ TEST_CASE("value conversion")
SECTION("number_float_t") SECTION("number_float_t")
{ {
json::number_float_t n = j; json::number_float_t n = j;
CHECK(json(n).m_value.number_float == Approx(j.m_value.number_float)); CHECK(json(n).m_value.number_float == Catch::Approx(j.m_value.number_float));
} }
SECTION("float") SECTION("float")
{ {
float n = j; float n = j;
CHECK(json(n).m_value.number_float == Approx(j.m_value.number_float)); CHECK(json(n).m_value.number_float == Catch::Approx(j.m_value.number_float));
} }
SECTION("double") SECTION("double")
{ {
double n = j; double n = j;
CHECK(json(n).m_value.number_float == Approx(j.m_value.number_float)); CHECK(json(n).m_value.number_float == Catch::Approx(j.m_value.number_float));
} }
} }
#endif #endif

View File

@ -44,7 +44,8 @@ TEST_CASE("Better diagnostics")
{ {
json j = 1; json j = 1;
std::string s; std::string s;
CHECK_THROWS_WITH_AS(s = j.get<std::string>(), "[json.exception.type_error.302] type must be string, but is number", json::type_error); CHECK_THROWS_WITH(s = j.get<std::string>(), "[json.exception.type_error.302] type must be string, but is number");
CHECK_THROWS_AS(s = j.get<std::string>(), json::type_error);
} }
SECTION("invalid type") SECTION("invalid type")
@ -52,35 +53,40 @@ TEST_CASE("Better diagnostics")
json j; json j;
j["a"]["b"]["c"] = 1; j["a"]["b"]["c"] = 1;
std::string s; std::string s;
CHECK_THROWS_WITH_AS(s = j["a"]["b"]["c"].get<std::string>(), "[json.exception.type_error.302] (/a/b/c) type must be string, but is number", json::type_error); CHECK_THROWS_WITH(s = j["a"]["b"]["c"].get<std::string>(), "[json.exception.type_error.302] (/a/b/c) type must be string, but is number");
CHECK_THROWS_AS(s = j["a"]["b"]["c"].get<std::string>(), json::type_error);
} }
SECTION("missing key") SECTION("missing key")
{ {
json j; json j;
j["object"]["object"] = true; j["object"]["object"] = true;
CHECK_THROWS_WITH_AS(j["object"].at("not_found"), "[json.exception.out_of_range.403] (/object) key 'not_found' not found", json::out_of_range); CHECK_THROWS_WITH(j["object"].at("not_found"), "[json.exception.out_of_range.403] (/object) key 'not_found' not found");
CHECK_THROWS_AS(j["object"].at("not_found"), json::out_of_range);
} }
SECTION("array index out of range") SECTION("array index out of range")
{ {
json j; json j;
j["array"][4] = true; j["array"][4] = true;
CHECK_THROWS_WITH_AS(j["array"].at(5), "[json.exception.out_of_range.401] (/array) array index 5 is out of range", json::out_of_range); CHECK_THROWS_WITH(j["array"].at(5), "[json.exception.out_of_range.401] (/array) array index 5 is out of range");
CHECK_THROWS_AS(j["array"].at(5), json::out_of_range);
} }
SECTION("array index at wrong type") SECTION("array index at wrong type")
{ {
json j; json j;
j["array"][4] = true; j["array"][4] = true;
CHECK_THROWS_WITH_AS(j["array"][4][5], "[json.exception.type_error.305] (/array/4) cannot use operator[] with a numeric argument with boolean", json::type_error); CHECK_THROWS_WITH(j["array"][4][5], "[json.exception.type_error.305] (/array/4) cannot use operator[] with a numeric argument with boolean");
CHECK_THROWS_AS(j["array"][4][5], json::type_error);
} }
SECTION("wrong iterator") SECTION("wrong iterator")
{ {
json j; json j;
j["array"] = json::array(); j["array"] = json::array();
CHECK_THROWS_WITH_AS(j["array"].erase(j.begin()), "[json.exception.invalid_iterator.202] (/array) iterator does not fit current value", json::invalid_iterator); CHECK_THROWS_WITH(j["array"].erase(j.begin()), "[json.exception.invalid_iterator.202] (/array) iterator does not fit current value");
CHECK_THROWS_AS(j["array"].erase(j.begin()), json::invalid_iterator);
} }
SECTION("JSON Pointer escaping") SECTION("JSON Pointer escaping")
@ -88,13 +94,15 @@ TEST_CASE("Better diagnostics")
json j; json j;
j["a/b"]["m~n"] = 1; j["a/b"]["m~n"] = 1;
std::string s; std::string s;
CHECK_THROWS_WITH_AS(s = j["a/b"]["m~n"].get<std::string>(), "[json.exception.type_error.302] (/a~1b/m~0n) type must be string, but is number", json::type_error); CHECK_THROWS_WITH(s = j["a/b"]["m~n"].get<std::string>(), "[json.exception.type_error.302] (/a~1b/m~0n) type must be string, but is number");
CHECK_THROWS_AS(s = j["a/b"]["m~n"].get<std::string>(), json::type_error);
} }
SECTION("Parse error") SECTION("Parse error")
{ {
json _; json _;
CHECK_THROWS_WITH_AS(_ = json::parse(""), "[json.exception.parse_error.101] parse error at line 1, column 1: syntax error while parsing value - unexpected end of input; expected '[', '{', or a literal", json::parse_error); CHECK_THROWS_WITH(_ = json::parse(""), "[json.exception.parse_error.101] parse error at line 1, column 1: syntax error while parsing value - unexpected end of input; expected '[', '{', or a literal");
CHECK_THROWS_AS(_ = json::parse(""), json::parse_error);
} }
SECTION("Wrong type in update()") SECTION("Wrong type in update()")

View File

@ -69,4 +69,4 @@ TEST_CASE("Tests with disabled exceptions")
} }
} }
DOCTEST_GCC_SUPPRESS_WARNING_POP //DOCTEST_GCC_SUPPRESS_WARNING_POP

View File

@ -40,10 +40,10 @@ using nlohmann::json;
#endif #endif
// This test suite uses range for loops where values are copied. This is inefficient in usual code, but required to achieve 100% coverage. // This test suite uses range for loops where values are copied. This is inefficient in usual code, but required to achieve 100% coverage.
DOCTEST_GCC_SUPPRESS_WARNING_PUSH //DOCTEST_GCC_SUPPRESS_WARNING_PUSH
DOCTEST_GCC_SUPPRESS_WARNING("-Wrange-loop-construct") //DOCTEST_GCC_SUPPRESS_WARNING("-Wrange-loop-construct")
DOCTEST_CLANG_SUPPRESS_WARNING_PUSH //DOCTEST_CLANG_SUPPRESS_WARNING_PUSH
DOCTEST_CLANG_SUPPRESS_WARNING("-Wrange-loop-construct") //DOCTEST_CLANG_SUPPRESS_WARNING("-Wrange-loop-construct")
TEST_CASE("iterator_wrapper") TEST_CASE("iterator_wrapper")
{ {
@ -1463,5 +1463,5 @@ TEST_CASE("items()")
#undef JSON_HAS_CPP_14 #undef JSON_HAS_CPP_14
#endif #endif
DOCTEST_GCC_SUPPRESS_WARNING_POP //DOCTEST_GCC_SUPPRESS_WARNING_POP
DOCTEST_CLANG_SUPPRESS_WARNING_POP //DOCTEST_CLANG_SUPPRESS_WARNING_POP

View File

@ -344,9 +344,9 @@ TEST_CASE("JSON patch")
// check that evaluation throws // check that evaluation throws
CHECK_THROWS_AS(doc.patch(patch), json::other_error); CHECK_THROWS_AS(doc.patch(patch), json::other_error);
#if JSON_DIAGNOSTICS #if JSON_DIAGNOSTICS
CHECK_THROWS_WITH_STD_STR(doc.patch(patch), "[json.exception.other_error.501] (/0) unsuccessful: " + patch[0].dump()); CHECK_THROWS_WITH(doc.patch(patch), "[json.exception.other_error.501] (/0) unsuccessful: " + patch[0].dump());
#else #else
CHECK_THROWS_WITH_STD_STR(doc.patch(patch), "[json.exception.other_error.501] unsuccessful: " + patch[0].dump()); CHECK_THROWS_WITH(doc.patch(patch), "[json.exception.other_error.501] unsuccessful: " + patch[0].dump());
#endif #endif
} }
@ -489,9 +489,9 @@ TEST_CASE("JSON patch")
// check that evaluation throws // check that evaluation throws
CHECK_THROWS_AS(doc.patch(patch), json::other_error); CHECK_THROWS_AS(doc.patch(patch), json::other_error);
#if JSON_DIAGNOSTICS #if JSON_DIAGNOSTICS
CHECK_THROWS_WITH_STD_STR(doc.patch(patch), "[json.exception.other_error.501] (/0) unsuccessful: " + patch[0].dump()); CHECK_THROWS_WITH(doc.patch(patch), "[json.exception.other_error.501] (/0) unsuccessful: " + patch[0].dump());
#else #else
CHECK_THROWS_WITH_STD_STR(doc.patch(patch), "[json.exception.other_error.501] unsuccessful: " + patch[0].dump()); CHECK_THROWS_WITH(doc.patch(patch), "[json.exception.other_error.501] unsuccessful: " + patch[0].dump());
#endif #endif
} }
@ -1261,9 +1261,9 @@ TEST_CASE("JSON patch")
// the test will fail // the test will fail
CHECK_THROWS_AS(doc.patch(patch), json::other_error); CHECK_THROWS_AS(doc.patch(patch), json::other_error);
#if JSON_DIAGNOSTICS #if JSON_DIAGNOSTICS
CHECK_THROWS_WITH_STD_STR(doc.patch(patch), "[json.exception.other_error.501] (/0) unsuccessful: " + patch[0].dump()); CHECK_THROWS_WITH(doc.patch(patch), "[json.exception.other_error.501] (/0) unsuccessful: " + patch[0].dump());
#else #else
CHECK_THROWS_WITH_STD_STR(doc.patch(patch), "[json.exception.other_error.501] unsuccessful: " + patch[0].dump()); CHECK_THROWS_WITH(doc.patch(patch), "[json.exception.other_error.501] unsuccessful: " + patch[0].dump());
#endif #endif
} }
} }
@ -1345,13 +1345,13 @@ TEST_CASE("JSON patch")
TEST_DATA_DIRECTORY "/json-patch-tests/tests.json" TEST_DATA_DIRECTORY "/json-patch-tests/tests.json"
}) })
{ {
CAPTURE(filename) CAPTURE(filename);
std::ifstream f(filename); std::ifstream f(filename);
json suite = json::parse(f); json suite = json::parse(f);
for (const auto& test : suite) for (const auto& test : suite)
{ {
INFO_WITH_TEMP(test.value("comment", "")); CAPTURE(test.value("comment", ""));
// skip tests marked as disabled // skip tests marked as disabled
if (test.value("disabled", false)) if (test.value("disabled", false))

View File

@ -37,23 +37,23 @@ TEST_CASE("JSON pointers")
{ {
SECTION("errors") SECTION("errors")
{ {
CHECK_THROWS_AS(json::json_pointer("foo"), json::parse_error&); CHECK_THROWS_AS(json::json_pointer("foo"), json::parse_error);
CHECK_THROWS_WITH(json::json_pointer("foo"), CHECK_THROWS_WITH(json::json_pointer("foo"),
"[json.exception.parse_error.107] parse error at byte 1: JSON pointer must be empty or begin with '/' - was: 'foo'"); "[json.exception.parse_error.107] parse error at byte 1: JSON pointer must be empty or begin with '/' - was: 'foo'");
CHECK_THROWS_AS(json::json_pointer("/~~"), json::parse_error&); CHECK_THROWS_AS(json::json_pointer("/~~"), json::parse_error);
CHECK_THROWS_WITH(json::json_pointer("/~~"), CHECK_THROWS_WITH(json::json_pointer("/~~"),
"[json.exception.parse_error.108] parse error: escape character '~' must be followed with '0' or '1'"); "[json.exception.parse_error.108] parse error: escape character '~' must be followed with '0' or '1'");
CHECK_THROWS_AS(json::json_pointer("/~"), json::parse_error&); CHECK_THROWS_AS(json::json_pointer("/~"), json::parse_error);
CHECK_THROWS_WITH(json::json_pointer("/~"), CHECK_THROWS_WITH(json::json_pointer("/~"),
"[json.exception.parse_error.108] parse error: escape character '~' must be followed with '0' or '1'"); "[json.exception.parse_error.108] parse error: escape character '~' must be followed with '0' or '1'");
json::json_pointer p; json::json_pointer p;
CHECK_THROWS_AS(p.top(), json::out_of_range&); CHECK_THROWS_AS(p.top(), json::out_of_range);
CHECK_THROWS_WITH(p.top(), CHECK_THROWS_WITH(p.top(),
"[json.exception.out_of_range.405] JSON pointer has no parent"); "[json.exception.out_of_range.405] JSON pointer has no parent");
CHECK_THROWS_AS(p.pop_back(), json::out_of_range&); CHECK_THROWS_AS(p.pop_back(), json::out_of_range);
CHECK_THROWS_WITH(p.pop_back(), CHECK_THROWS_WITH(p.pop_back(),
"[json.exception.out_of_range.405] JSON pointer has no parent"); "[json.exception.out_of_range.405] JSON pointer has no parent");
@ -61,7 +61,7 @@ TEST_CASE("JSON pointers")
{ {
json v = {1, 2, 3, 4}; json v = {1, 2, 3, 4};
json::json_pointer ptr("/10e"); json::json_pointer ptr("/10e");
CHECK_THROWS_AS(v[ptr], json::out_of_range&); CHECK_THROWS_AS(v[ptr], json::out_of_range);
CHECK_THROWS_WITH(v[ptr], CHECK_THROWS_WITH(v[ptr],
"[json.exception.out_of_range.404] unresolved reference token '10e'"); "[json.exception.out_of_range.404] unresolved reference token '10e'");
} }
@ -165,10 +165,10 @@ TEST_CASE("JSON pointers")
// unresolved access // unresolved access
json j_primitive = 1; json j_primitive = 1;
CHECK_THROWS_AS(j_primitive["/foo"_json_pointer], json::out_of_range&); CHECK_THROWS_AS(j_primitive["/foo"_json_pointer], json::out_of_range);
CHECK_THROWS_WITH(j_primitive["/foo"_json_pointer], CHECK_THROWS_WITH(j_primitive["/foo"_json_pointer],
"[json.exception.out_of_range.404] unresolved reference token 'foo'"); "[json.exception.out_of_range.404] unresolved reference token 'foo'");
CHECK_THROWS_AS(j_primitive.at("/foo"_json_pointer), json::out_of_range&); CHECK_THROWS_AS(j_primitive.at("/foo"_json_pointer), json::out_of_range);
CHECK_THROWS_WITH(j_primitive.at("/foo"_json_pointer), CHECK_THROWS_WITH(j_primitive.at("/foo"_json_pointer),
"[json.exception.out_of_range.404] unresolved reference token 'foo'"); "[json.exception.out_of_range.404] unresolved reference token 'foo'");
CHECK(!j_primitive.contains(json::json_pointer("/foo"))); CHECK(!j_primitive.contains(json::json_pointer("/foo")));
@ -229,16 +229,16 @@ TEST_CASE("JSON pointers")
CHECK(j[json::json_pointer("/m~0n")] == j["m~n"]); CHECK(j[json::json_pointer("/m~0n")] == j["m~n"]);
// unescaped access // unescaped access
CHECK_THROWS_AS(j.at(json::json_pointer("/a/b")), json::out_of_range&); CHECK_THROWS_AS(j.at(json::json_pointer("/a/b")), json::out_of_range);
CHECK_THROWS_WITH(j.at(json::json_pointer("/a/b")), CHECK_THROWS_WITH(j.at(json::json_pointer("/a/b")),
"[json.exception.out_of_range.403] key 'a' not found"); "[json.exception.out_of_range.403] key 'a' not found");
// unresolved access // unresolved access
const json j_primitive = 1; const json j_primitive = 1;
CHECK_THROWS_AS(j_primitive["/foo"_json_pointer], json::out_of_range&); CHECK_THROWS_AS(j_primitive["/foo"_json_pointer], json::out_of_range);
CHECK_THROWS_WITH(j_primitive["/foo"_json_pointer], CHECK_THROWS_WITH(j_primitive["/foo"_json_pointer],
"[json.exception.out_of_range.404] unresolved reference token 'foo'"); "[json.exception.out_of_range.404] unresolved reference token 'foo'");
CHECK_THROWS_AS(j_primitive.at("/foo"_json_pointer), json::out_of_range&); CHECK_THROWS_AS(j_primitive.at("/foo"_json_pointer), json::out_of_range);
CHECK_THROWS_WITH(j_primitive.at("/foo"_json_pointer), CHECK_THROWS_WITH(j_primitive.at("/foo"_json_pointer),
"[json.exception.out_of_range.404] unresolved reference token 'foo'"); "[json.exception.out_of_range.404] unresolved reference token 'foo'");
} }
@ -300,16 +300,16 @@ TEST_CASE("JSON pointers")
CHECK(j == json({1, 13, 3, 33, nullptr, 55})); CHECK(j == json({1, 13, 3, 33, nullptr, 55}));
// error with leading 0 // error with leading 0
CHECK_THROWS_AS(j["/01"_json_pointer], json::parse_error&); CHECK_THROWS_AS(j["/01"_json_pointer], json::parse_error);
CHECK_THROWS_WITH(j["/01"_json_pointer], CHECK_THROWS_WITH(j["/01"_json_pointer],
"[json.exception.parse_error.106] parse error: array index '01' must not begin with '0'"); "[json.exception.parse_error.106] parse error: array index '01' must not begin with '0'");
CHECK_THROWS_AS(j_const["/01"_json_pointer], json::parse_error&); CHECK_THROWS_AS(j_const["/01"_json_pointer], json::parse_error);
CHECK_THROWS_WITH(j_const["/01"_json_pointer], CHECK_THROWS_WITH(j_const["/01"_json_pointer],
"[json.exception.parse_error.106] parse error: array index '01' must not begin with '0'"); "[json.exception.parse_error.106] parse error: array index '01' must not begin with '0'");
CHECK_THROWS_AS(j.at("/01"_json_pointer), json::parse_error&); CHECK_THROWS_AS(j.at("/01"_json_pointer), json::parse_error);
CHECK_THROWS_WITH(j.at("/01"_json_pointer), CHECK_THROWS_WITH(j.at("/01"_json_pointer),
"[json.exception.parse_error.106] parse error: array index '01' must not begin with '0'"); "[json.exception.parse_error.106] parse error: array index '01' must not begin with '0'");
CHECK_THROWS_AS(j_const.at("/01"_json_pointer), json::parse_error&); CHECK_THROWS_AS(j_const.at("/01"_json_pointer), json::parse_error);
CHECK_THROWS_WITH(j_const.at("/01"_json_pointer), CHECK_THROWS_WITH(j_const.at("/01"_json_pointer),
"[json.exception.parse_error.106] parse error: array index '01' must not begin with '0'"); "[json.exception.parse_error.106] parse error: array index '01' must not begin with '0'");
@ -319,31 +319,31 @@ TEST_CASE("JSON pointers")
CHECK(!j_const.contains("/01"_json_pointer)); CHECK(!j_const.contains("/01"_json_pointer));
// error with incorrect numbers // error with incorrect numbers
CHECK_THROWS_AS(j["/one"_json_pointer] = 1, json::parse_error&); CHECK_THROWS_AS(j["/one"_json_pointer] = 1, json::parse_error);
CHECK_THROWS_WITH(j["/one"_json_pointer] = 1, CHECK_THROWS_WITH(j["/one"_json_pointer] = 1,
"[json.exception.parse_error.109] parse error: array index 'one' is not a number"); "[json.exception.parse_error.109] parse error: array index 'one' is not a number");
CHECK_THROWS_AS(j_const["/one"_json_pointer] == 1, json::parse_error&); CHECK_THROWS_AS(j_const["/one"_json_pointer] == 1, json::parse_error);
CHECK_THROWS_WITH(j_const["/one"_json_pointer] == 1, CHECK_THROWS_WITH(j_const["/one"_json_pointer] == 1,
"[json.exception.parse_error.109] parse error: array index 'one' is not a number"); "[json.exception.parse_error.109] parse error: array index 'one' is not a number");
CHECK_THROWS_AS(j.at("/one"_json_pointer) = 1, json::parse_error&); CHECK_THROWS_AS(j.at("/one"_json_pointer) = 1, json::parse_error);
CHECK_THROWS_WITH(j.at("/one"_json_pointer) = 1, CHECK_THROWS_WITH(j.at("/one"_json_pointer) = 1,
"[json.exception.parse_error.109] parse error: array index 'one' is not a number"); "[json.exception.parse_error.109] parse error: array index 'one' is not a number");
CHECK_THROWS_AS(j_const.at("/one"_json_pointer) == 1, json::parse_error&); CHECK_THROWS_AS(j_const.at("/one"_json_pointer) == 1, json::parse_error);
CHECK_THROWS_WITH(j_const.at("/one"_json_pointer) == 1, CHECK_THROWS_WITH(j_const.at("/one"_json_pointer) == 1,
"[json.exception.parse_error.109] parse error: array index 'one' is not a number"); "[json.exception.parse_error.109] parse error: array index 'one' is not a number");
CHECK_THROWS_AS(j["/+1"_json_pointer] = 1, json::parse_error&); CHECK_THROWS_AS(j["/+1"_json_pointer] = 1, json::parse_error);
CHECK_THROWS_WITH(j["/+1"_json_pointer] = 1, CHECK_THROWS_WITH(j["/+1"_json_pointer] = 1,
"[json.exception.parse_error.109] parse error: array index '+1' is not a number"); "[json.exception.parse_error.109] parse error: array index '+1' is not a number");
CHECK_THROWS_AS(j_const["/+1"_json_pointer] == 1, json::parse_error&); CHECK_THROWS_AS(j_const["/+1"_json_pointer] == 1, json::parse_error);
CHECK_THROWS_WITH(j_const["/+1"_json_pointer] == 1, CHECK_THROWS_WITH(j_const["/+1"_json_pointer] == 1,
"[json.exception.parse_error.109] parse error: array index '+1' is not a number"); "[json.exception.parse_error.109] parse error: array index '+1' is not a number");
CHECK_THROWS_AS(j["/1+1"_json_pointer] = 1, json::out_of_range&); CHECK_THROWS_AS(j["/1+1"_json_pointer] = 1, json::out_of_range);
CHECK_THROWS_WITH(j["/1+1"_json_pointer] = 1, CHECK_THROWS_WITH(j["/1+1"_json_pointer] = 1,
"[json.exception.out_of_range.404] unresolved reference token '1+1'"); "[json.exception.out_of_range.404] unresolved reference token '1+1'");
CHECK_THROWS_AS(j_const["/1+1"_json_pointer] == 1, json::out_of_range&); CHECK_THROWS_AS(j_const["/1+1"_json_pointer] == 1, json::out_of_range);
CHECK_THROWS_WITH(j_const["/1+1"_json_pointer] == 1, CHECK_THROWS_WITH(j_const["/1+1"_json_pointer] == 1,
"[json.exception.out_of_range.404] unresolved reference token '1+1'"); "[json.exception.out_of_range.404] unresolved reference token '1+1'");
@ -352,9 +352,9 @@ TEST_CASE("JSON pointers")
json::json_pointer jp(std::string("/") + too_large_index); json::json_pointer jp(std::string("/") + too_large_index);
std::string throw_msg = std::string("[json.exception.out_of_range.404] unresolved reference token '") + too_large_index + "'"; std::string throw_msg = std::string("[json.exception.out_of_range.404] unresolved reference token '") + too_large_index + "'";
CHECK_THROWS_AS(j[jp] = 1, json::out_of_range&); CHECK_THROWS_AS(j[jp] = 1, json::out_of_range);
CHECK_THROWS_WITH(j[jp] = 1, throw_msg.c_str()); CHECK_THROWS_WITH(j[jp] = 1, throw_msg.c_str());
CHECK_THROWS_AS(j_const[jp] == 1, json::out_of_range&); CHECK_THROWS_AS(j_const[jp] == 1, json::out_of_range);
CHECK_THROWS_WITH(j_const[jp] == 1, throw_msg.c_str()); CHECK_THROWS_WITH(j_const[jp] == 1, throw_msg.c_str());
} }
@ -369,18 +369,18 @@ TEST_CASE("JSON pointers")
json::json_pointer jp(std::string("/") + too_large_index); json::json_pointer jp(std::string("/") + too_large_index);
std::string throw_msg = std::string("[json.exception.out_of_range.410] array index ") + too_large_index + " exceeds size_type"; std::string throw_msg = std::string("[json.exception.out_of_range.410] array index ") + too_large_index + " exceeds size_type";
CHECK_THROWS_AS(j[jp] = 1, json::out_of_range&); CHECK_THROWS_AS(j[jp] = 1, json::out_of_range);
CHECK_THROWS_WITH(j[jp] = 1, throw_msg.c_str()); CHECK_THROWS_WITH(j[jp] = 1, throw_msg.c_str());
CHECK_THROWS_AS(j_const[jp] == 1, json::out_of_range&); CHECK_THROWS_AS(j_const[jp] == 1, json::out_of_range);
CHECK_THROWS_WITH(j_const[jp] == 1, throw_msg.c_str()); CHECK_THROWS_WITH(j_const[jp] == 1, throw_msg.c_str());
} }
DOCTEST_MSVC_SUPPRESS_WARNING_POP DOCTEST_MSVC_SUPPRESS_WARNING_POP
CHECK_THROWS_AS(j.at("/one"_json_pointer) = 1, json::parse_error&); CHECK_THROWS_AS(j.at("/one"_json_pointer) = 1, json::parse_error);
CHECK_THROWS_WITH(j.at("/one"_json_pointer) = 1, CHECK_THROWS_WITH(j.at("/one"_json_pointer) = 1,
"[json.exception.parse_error.109] parse error: array index 'one' is not a number"); "[json.exception.parse_error.109] parse error: array index 'one' is not a number");
CHECK_THROWS_AS(j_const.at("/one"_json_pointer) == 1, json::parse_error&); CHECK_THROWS_AS(j_const.at("/one"_json_pointer) == 1, json::parse_error);
CHECK_THROWS_WITH(j_const.at("/one"_json_pointer) == 1, CHECK_THROWS_WITH(j_const.at("/one"_json_pointer) == 1,
"[json.exception.parse_error.109] parse error: array index 'one' is not a number"); "[json.exception.parse_error.109] parse error: array index 'one' is not a number");
@ -389,7 +389,7 @@ TEST_CASE("JSON pointers")
CHECK(!j_const.contains("/one"_json_pointer)); CHECK(!j_const.contains("/one"_json_pointer));
CHECK(!j_const.contains("/one"_json_pointer)); CHECK(!j_const.contains("/one"_json_pointer));
CHECK_THROWS_AS(json({{"/list/0", 1}, {"/list/1", 2}, {"/list/three", 3}}).unflatten(), json::parse_error&); CHECK_THROWS_AS(json({{"/list/0", 1}, {"/list/1", 2}, {"/list/three", 3}}).unflatten(), json::parse_error);
CHECK_THROWS_WITH(json({{"/list/0", 1}, {"/list/1", 2}, {"/list/three", 3}}).unflatten(), CHECK_THROWS_WITH(json({{"/list/0", 1}, {"/list/1", 2}, {"/list/three", 3}}).unflatten(),
"[json.exception.parse_error.109] parse error: array index 'three' is not a number"); "[json.exception.parse_error.109] parse error: array index 'three' is not a number");
@ -398,16 +398,16 @@ TEST_CASE("JSON pointers")
CHECK(j == json({1, 13, 3, 33, nullptr, 55, 99})); CHECK(j == json({1, 13, 3, 33, nullptr, 55, 99}));
// error when using "-" in const object // error when using "-" in const object
CHECK_THROWS_AS(j_const["/-"_json_pointer], json::out_of_range&); CHECK_THROWS_AS(j_const["/-"_json_pointer], json::out_of_range);
CHECK_THROWS_WITH(j_const["/-"_json_pointer], CHECK_THROWS_WITH(j_const["/-"_json_pointer],
"[json.exception.out_of_range.402] array index '-' (3) is out of range"); "[json.exception.out_of_range.402] array index '-' (3) is out of range");
CHECK(!j_const.contains("/-"_json_pointer)); CHECK(!j_const.contains("/-"_json_pointer));
// error when using "-" with at // error when using "-" with at
CHECK_THROWS_AS(j.at("/-"_json_pointer), json::out_of_range&); CHECK_THROWS_AS(j.at("/-"_json_pointer), json::out_of_range);
CHECK_THROWS_WITH(j.at("/-"_json_pointer), CHECK_THROWS_WITH(j.at("/-"_json_pointer),
"[json.exception.out_of_range.402] array index '-' (7) is out of range"); "[json.exception.out_of_range.402] array index '-' (7) is out of range");
CHECK_THROWS_AS(j_const.at("/-"_json_pointer), json::out_of_range&); CHECK_THROWS_AS(j_const.at("/-"_json_pointer), json::out_of_range);
CHECK_THROWS_WITH(j_const.at("/-"_json_pointer), CHECK_THROWS_WITH(j_const.at("/-"_json_pointer),
"[json.exception.out_of_range.402] array index '-' (3) is out of range"); "[json.exception.out_of_range.402] array index '-' (3) is out of range");
CHECK(!j_const.contains("/-"_json_pointer)); CHECK(!j_const.contains("/-"_json_pointer));
@ -423,22 +423,22 @@ TEST_CASE("JSON pointers")
CHECK(j["/2"_json_pointer] == j[2]); CHECK(j["/2"_json_pointer] == j[2]);
// assign to nonexisting index // assign to nonexisting index
CHECK_THROWS_AS(j.at("/3"_json_pointer), json::out_of_range&); CHECK_THROWS_AS(j.at("/3"_json_pointer), json::out_of_range);
CHECK_THROWS_WITH(j.at("/3"_json_pointer), CHECK_THROWS_WITH(j.at("/3"_json_pointer),
"[json.exception.out_of_range.401] array index 3 is out of range"); "[json.exception.out_of_range.401] array index 3 is out of range");
CHECK(!j.contains("/3"_json_pointer)); CHECK(!j.contains("/3"_json_pointer));
// assign to nonexisting index (with gap) // assign to nonexisting index (with gap)
CHECK_THROWS_AS(j.at("/5"_json_pointer), json::out_of_range&); CHECK_THROWS_AS(j.at("/5"_json_pointer), json::out_of_range);
CHECK_THROWS_WITH(j.at("/5"_json_pointer), CHECK_THROWS_WITH(j.at("/5"_json_pointer),
"[json.exception.out_of_range.401] array index 5 is out of range"); "[json.exception.out_of_range.401] array index 5 is out of range");
CHECK(!j.contains("/5"_json_pointer)); CHECK(!j.contains("/5"_json_pointer));
// assign to "-" // assign to "-"
CHECK_THROWS_AS(j["/-"_json_pointer], json::out_of_range&); CHECK_THROWS_AS(j["/-"_json_pointer], json::out_of_range);
CHECK_THROWS_WITH(j["/-"_json_pointer], CHECK_THROWS_WITH(j["/-"_json_pointer],
"[json.exception.out_of_range.402] array index '-' (3) is out of range"); "[json.exception.out_of_range.402] array index '-' (3) is out of range");
CHECK_THROWS_AS(j.at("/-"_json_pointer), json::out_of_range&); CHECK_THROWS_AS(j.at("/-"_json_pointer), json::out_of_range);
CHECK_THROWS_WITH(j.at("/-"_json_pointer), CHECK_THROWS_WITH(j.at("/-"_json_pointer),
"[json.exception.out_of_range.402] array index '-' (3) is out of range"); "[json.exception.out_of_range.402] array index '-' (3) is out of range");
CHECK(!j.contains("/-"_json_pointer)); CHECK(!j.contains("/-"_json_pointer));
@ -496,12 +496,12 @@ TEST_CASE("JSON pointers")
CHECK(j_flatten.unflatten() == j); CHECK(j_flatten.unflatten() == j);
// error for nonobjects // error for nonobjects
CHECK_THROWS_AS(json(1).unflatten(), json::type_error&); CHECK_THROWS_AS(json(1).unflatten(), json::type_error);
CHECK_THROWS_WITH(json(1).unflatten(), CHECK_THROWS_WITH(json(1).unflatten(),
"[json.exception.type_error.314] only objects can be unflattened"); "[json.exception.type_error.314] only objects can be unflattened");
// error for nonprimitve values // error for nonprimitve values
CHECK_THROWS_AS(json({{"/1", {1, 2, 3}}}).unflatten(), json::type_error&); CHECK_THROWS_AS(json({{"/1", {1, 2, 3}}}).unflatten(), json::type_error);
#if JSON_DIAGNOSTICS #if JSON_DIAGNOSTICS
CHECK_THROWS_WITH(json({{"/1", {1, 2, 3}}}).unflatten(), "[json.exception.type_error.315] (/~11) values in object must be primitive"); CHECK_THROWS_WITH(json({{"/1", {1, 2, 3}}}).unflatten(), "[json.exception.type_error.315] (/~11) values in object must be primitive");
#else #else
@ -510,7 +510,7 @@ TEST_CASE("JSON pointers")
// error for conflicting values // error for conflicting values
json j_error = {{"", 42}, {"/foo", 17}}; json j_error = {{"", 42}, {"/foo", 17}};
CHECK_THROWS_AS(j_error.unflatten(), json::type_error&); CHECK_THROWS_AS(j_error.unflatten(), json::type_error);
CHECK_THROWS_WITH(j_error.unflatten(), CHECK_THROWS_WITH(j_error.unflatten(),
"[json.exception.type_error.313] invalid value to unflatten"); "[json.exception.type_error.313] invalid value to unflatten");

View File

@ -176,7 +176,7 @@ TEST_CASE("MessagePack")
{ {
for (auto i = -32; i <= -1; ++i) for (auto i = -32; i <= -1; ++i)
{ {
CAPTURE(i) CAPTURE(i);
// create JSON value with integer number // create JSON value with integer number
json j = i; json j = i;
@ -206,7 +206,7 @@ TEST_CASE("MessagePack")
{ {
for (size_t i = 0; i <= 127; ++i) for (size_t i = 0; i <= 127; ++i)
{ {
CAPTURE(i) CAPTURE(i);
// create JSON value with integer number // create JSON value with integer number
json j = -1; json j = -1;
@ -237,7 +237,7 @@ TEST_CASE("MessagePack")
{ {
for (size_t i = 128; i <= 255; ++i) for (size_t i = 128; i <= 255; ++i)
{ {
CAPTURE(i) CAPTURE(i);
// create JSON value with integer number // create JSON value with integer number
json j = -1; json j = -1;
@ -271,7 +271,7 @@ TEST_CASE("MessagePack")
{ {
for (size_t i = 256; i <= 65535; ++i) for (size_t i = 256; i <= 65535; ++i)
{ {
CAPTURE(i) CAPTURE(i);
// create JSON value with integer number // create JSON value with integer number
json j = -1; json j = -1;
@ -309,7 +309,7 @@ TEST_CASE("MessagePack")
65536u, 77777u, 1048576u, 4294967295u 65536u, 77777u, 1048576u, 4294967295u
}) })
{ {
CAPTURE(i) CAPTURE(i);
// create JSON value with integer number // create JSON value with integer number
json j = -1; json j = -1;
@ -352,7 +352,7 @@ TEST_CASE("MessagePack")
4294967296LU, 9223372036854775807LU 4294967296LU, 9223372036854775807LU
}) })
{ {
CAPTURE(i) CAPTURE(i);
// create JSON value with integer number // create JSON value with integer number
json j = -1; json j = -1;
@ -400,7 +400,7 @@ TEST_CASE("MessagePack")
{ {
for (auto i = -128; i <= -33; ++i) for (auto i = -128; i <= -33; ++i)
{ {
CAPTURE(i) CAPTURE(i);
// create JSON value with integer number // create JSON value with integer number
json j = i; json j = i;
@ -448,7 +448,7 @@ TEST_CASE("MessagePack")
{ {
for (int16_t i = -32768; i <= static_cast<std::int16_t>(-129); ++i) for (int16_t i = -32768; i <= static_cast<std::int16_t>(-129); ++i)
{ {
CAPTURE(i) CAPTURE(i);
// create JSON value with integer number // create JSON value with integer number
json j = i; json j = i;
@ -488,7 +488,7 @@ TEST_CASE("MessagePack")
numbers.push_back(-2147483648LL); numbers.push_back(-2147483648LL);
for (auto i : numbers) for (auto i : numbers)
{ {
CAPTURE(i) CAPTURE(i);
// create JSON value with integer number // create JSON value with integer number
json j = i; json j = i;
@ -530,7 +530,7 @@ TEST_CASE("MessagePack")
numbers.push_back(-2147483649LL); numbers.push_back(-2147483649LL);
for (auto i : numbers) for (auto i : numbers)
{ {
CAPTURE(i) CAPTURE(i);
// create JSON value with unsigned integer number // create JSON value with unsigned integer number
json j = i; json j = i;
@ -580,7 +580,7 @@ TEST_CASE("MessagePack")
{ {
for (size_t i = 0; i <= 127; ++i) for (size_t i = 0; i <= 127; ++i)
{ {
CAPTURE(i) CAPTURE(i);
// create JSON value with unsigned integer number // create JSON value with unsigned integer number
json j = i; json j = i;
@ -610,7 +610,7 @@ TEST_CASE("MessagePack")
{ {
for (size_t i = 128; i <= 255; ++i) for (size_t i = 128; i <= 255; ++i)
{ {
CAPTURE(i) CAPTURE(i);
// create JSON value with unsigned integer number // create JSON value with unsigned integer number
json j = i; json j = i;
@ -643,7 +643,7 @@ TEST_CASE("MessagePack")
{ {
for (size_t i = 256; i <= 65535; ++i) for (size_t i = 256; i <= 65535; ++i)
{ {
CAPTURE(i) CAPTURE(i);
// create JSON value with unsigned integer number // create JSON value with unsigned integer number
json j = i; json j = i;
@ -680,7 +680,7 @@ TEST_CASE("MessagePack")
65536u, 77777u, 1048576u, 4294967295u 65536u, 77777u, 1048576u, 4294967295u
}) })
{ {
CAPTURE(i) CAPTURE(i);
// create JSON value with unsigned integer number // create JSON value with unsigned integer number
json j = i; json j = i;
@ -722,7 +722,7 @@ TEST_CASE("MessagePack")
4294967296LU, 18446744073709551615LU 4294967296LU, 18446744073709551615LU
}) })
{ {
CAPTURE(i) CAPTURE(i);
// create JSON value with unsigned integer number // create JSON value with unsigned integer number
json j = i; json j = i;
@ -836,7 +836,7 @@ TEST_CASE("MessagePack")
for (size_t N = 0; N < first_bytes.size(); ++N) for (size_t N = 0; N < first_bytes.size(); ++N)
{ {
CAPTURE(N) CAPTURE(N);
// create JSON value with string containing of N * 'x' // create JSON value with string containing of N * 'x'
const auto s = std::string(N, 'x'); const auto s = std::string(N, 'x');
@ -873,7 +873,7 @@ TEST_CASE("MessagePack")
{ {
for (size_t N = 32; N <= 255; ++N) for (size_t N = 32; N <= 255; ++N)
{ {
CAPTURE(N) CAPTURE(N);
// create JSON value with string containing of N * 'x' // create JSON value with string containing of N * 'x'
const auto s = std::string(N, 'x'); const auto s = std::string(N, 'x');
@ -908,7 +908,7 @@ TEST_CASE("MessagePack")
256u, 999u, 1025u, 3333u, 2048u, 65535u 256u, 999u, 1025u, 3333u, 2048u, 65535u
}) })
{ {
CAPTURE(N) CAPTURE(N);
// create JSON value with string containing of N * 'x' // create JSON value with string containing of N * 'x'
const auto s = std::string(N, 'x'); const auto s = std::string(N, 'x');
@ -941,7 +941,7 @@ TEST_CASE("MessagePack")
65536u, 77777u, 1048576u 65536u, 77777u, 1048576u
}) })
{ {
CAPTURE(N) CAPTURE(N);
// create JSON value with string containing of N * 'x' // create JSON value with string containing of N * 'x'
const auto s = std::string(N, 'x'); const auto s = std::string(N, 'x');
@ -1050,7 +1050,7 @@ TEST_CASE("MessagePack")
CHECK(result.size() == expected.size()); CHECK(result.size() == expected.size());
for (size_t i = 0; i < expected.size(); ++i) for (size_t i = 0; i < expected.size(); ++i)
{ {
CAPTURE(i) CAPTURE(i);
CHECK(result[i] == expected[i]); CHECK(result[i] == expected[i]);
} }
@ -1163,7 +1163,7 @@ TEST_CASE("MessagePack")
{ {
for (size_t N = 0; N <= 0xFF; ++N) for (size_t N = 0; N <= 0xFF; ++N)
{ {
CAPTURE(N) CAPTURE(N);
// create JSON value with byte array containing of N * 'x' // create JSON value with byte array containing of N * 'x'
const auto s = std::vector<uint8_t>(N, 'x'); const auto s = std::vector<uint8_t>(N, 'x');
@ -1238,7 +1238,7 @@ TEST_CASE("MessagePack")
256u, 999u, 1025u, 3333u, 2048u, 65535u 256u, 999u, 1025u, 3333u, 2048u, 65535u
}) })
{ {
CAPTURE(N) CAPTURE(N);
// create JSON value with string containing of N * 'x' // create JSON value with string containing of N * 'x'
const auto s = std::vector<uint8_t>(N, 'x'); const auto s = std::vector<uint8_t>(N, 'x');
@ -1274,7 +1274,7 @@ TEST_CASE("MessagePack")
65536u, 77777u, 1048576u 65536u, 77777u, 1048576u
}) })
{ {
CAPTURE(N) CAPTURE(N);
// create JSON value with string containing of N * 'x' // create JSON value with string containing of N * 'x'
const auto s = std::vector<uint8_t>(N, 'x'); const auto s = std::vector<uint8_t>(N, 'x');
@ -1312,7 +1312,7 @@ TEST_CASE("MessagePack")
{ {
for (std::size_t N = 0; N <= 0xFF; ++N) for (std::size_t N = 0; N <= 0xFF; ++N)
{ {
CAPTURE(N) CAPTURE(N);
// create JSON value with byte array containing of N * 'x' // create JSON value with byte array containing of N * 'x'
const auto s = std::vector<uint8_t>(N, 'x'); const auto s = std::vector<uint8_t>(N, 'x');
@ -1350,7 +1350,7 @@ TEST_CASE("MessagePack")
256u, 999u, 1025u, 3333u, 2048u, 65535u 256u, 999u, 1025u, 3333u, 2048u, 65535u
}) })
{ {
CAPTURE(N) CAPTURE(N);
// create JSON value with string containing of N * 'x' // create JSON value with string containing of N * 'x'
const auto s = std::vector<std::uint8_t>(N, 'x'); const auto s = std::vector<std::uint8_t>(N, 'x');
@ -1383,7 +1383,7 @@ TEST_CASE("MessagePack")
65536u, 77777u, 1048576u 65536u, 77777u, 1048576u
}) })
{ {
CAPTURE(N) CAPTURE(N);
// create JSON value with string containing of N * 'x' // create JSON value with string containing of N * 'x'
const auto s = std::vector<std::uint8_t>(N, 'x'); const auto s = std::vector<std::uint8_t>(N, 'x');
@ -1417,7 +1417,7 @@ TEST_CASE("MessagePack")
{ {
auto given = std::vector<uint8_t>({0xca, 0x41, 0xc8, 0x00, 0x01}); auto given = std::vector<uint8_t>({0xca, 0x41, 0xc8, 0x00, 0x01});
json j = json::from_msgpack(given); json j = json::from_msgpack(given);
CHECK(j.get<double>() == Approx(25.0000019073486)); CHECK(j.get<double>() == Catch::Approx(25.0000019073486));
} }
SECTION("errors") SECTION("errors")
@ -1812,10 +1812,10 @@ TEST_CASE("MessagePack roundtrips" * doctest::skip())
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_structure_whitespace_array.json" TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_structure_whitespace_array.json"
}) })
{ {
CAPTURE(filename) CAPTURE(filename);
SECTION(filename + ": std::vector<uint8_t>")
{ {
INFO_WITH_TEMP(filename + ": std::vector<uint8_t>");
// parse JSON file // parse JSON file
std::ifstream f_json(filename); std::ifstream f_json(filename);
json j1 = json::parse(f_json); json j1 = json::parse(f_json);
@ -1829,8 +1829,8 @@ TEST_CASE("MessagePack roundtrips" * doctest::skip())
CHECK(j1 == j2); CHECK(j1 == j2);
} }
SECTION(filename + ": std::ifstream")
{ {
INFO_WITH_TEMP(filename + ": std::ifstream");
// parse JSON file // parse JSON file
std::ifstream f_json(filename); std::ifstream f_json(filename);
json j1 = json::parse(f_json); json j1 = json::parse(f_json);
@ -1844,8 +1844,8 @@ TEST_CASE("MessagePack roundtrips" * doctest::skip())
CHECK(j1 == j2); CHECK(j1 == j2);
} }
SECTION(filename + ": uint8_t* and size")
{ {
INFO_WITH_TEMP(filename + ": uint8_t* and size");
// parse JSON file // parse JSON file
std::ifstream f_json(filename); std::ifstream f_json(filename);
json j1 = json::parse(f_json); json j1 = json::parse(f_json);
@ -1859,8 +1859,8 @@ TEST_CASE("MessagePack roundtrips" * doctest::skip())
CHECK(j1 == j2); CHECK(j1 == j2);
} }
SECTION(filename + ": output to output adapters")
{ {
INFO_WITH_TEMP(filename + ": output to output adapters");
// parse JSON file // parse JSON file
std::ifstream f_json(filename); std::ifstream f_json(filename);
json j1 = json::parse(f_json); json j1 = json::parse(f_json);
@ -1870,8 +1870,8 @@ TEST_CASE("MessagePack roundtrips" * doctest::skip())
if (exclude_packed.count(filename) == 0u) if (exclude_packed.count(filename) == 0u)
{ {
SECTION(filename + ": output adapters: std::vector<uint8_t>")
{ {
INFO_WITH_TEMP(filename + ": output adapters: std::vector<uint8_t>");
std::vector<uint8_t> vec; std::vector<uint8_t> vec;
json::to_msgpack(j1, vec); json::to_msgpack(j1, vec);
CHECK(vec == packed); CHECK(vec == packed);

View File

@ -100,4 +100,4 @@ TEST_CASE("runtime checks")
} }
} }
DOCTEST_GCC_SUPPRESS_WARNING_POP //DOCTEST_GCC_SUPPRESS_WARNING_POP

View File

@ -390,15 +390,15 @@ TEST_CASE("pointer access")
// check if pointers are returned correctly // check if pointers are returned correctly
test_type* p1 = value.get_ptr<test_type*>(); test_type* p1 = value.get_ptr<test_type*>();
CHECK(p1 == value.get_ptr<test_type*>()); CHECK(p1 == value.get_ptr<test_type*>());
CHECK(*p1 == Approx(value.get<test_type>())); CHECK(*p1 == Catch::Approx(value.get<test_type>()));
const test_type* p2 = value.get_ptr<const test_type*>(); const test_type* p2 = value.get_ptr<const test_type*>();
CHECK(p2 == value.get_ptr<const test_type*>()); CHECK(p2 == value.get_ptr<const test_type*>());
CHECK(*p2 == Approx(value.get<test_type>())); CHECK(*p2 == Catch::Approx(value.get<test_type>()));
const test_type* const p3 = value.get_ptr<const test_type* const>(); const test_type* const p3 = value.get_ptr<const test_type* const>();
CHECK(p3 == value.get_ptr<const test_type* const>()); CHECK(p3 == value.get_ptr<const test_type* const>());
CHECK(*p3 == Approx(value.get<test_type>())); CHECK(*p3 == Catch::Approx(value.get<test_type>()));
// check if null pointers are returned correctly // check if null pointers are returned correctly
CHECK(value.get_ptr<json::object_t*>() == nullptr); CHECK(value.get_ptr<json::object_t*>() == nullptr);
@ -419,15 +419,15 @@ TEST_CASE("pointer access")
// check if pointers are returned correctly // check if pointers are returned correctly
test_type* p1 = value.get_ptr<test_type*>(); test_type* p1 = value.get_ptr<test_type*>();
CHECK(p1 == value.get_ptr<test_type*>()); CHECK(p1 == value.get_ptr<test_type*>());
CHECK(*p1 == Approx(value.get<test_type>())); CHECK(*p1 == Catch::Approx(value.get<test_type>()));
const test_type* p2 = value.get_ptr<const test_type*>(); const test_type* p2 = value.get_ptr<const test_type*>();
CHECK(p2 == value.get_ptr<const test_type*>()); CHECK(p2 == value.get_ptr<const test_type*>());
CHECK(*p2 == Approx(value.get<test_type>())); CHECK(*p2 == Catch::Approx(value.get<test_type>()));
const test_type* const p3 = value.get_ptr<const test_type* const>(); const test_type* const p3 = value.get_ptr<const test_type* const>();
CHECK(p3 == value.get_ptr<const test_type* const>()); CHECK(p3 == value.get_ptr<const test_type* const>());
CHECK(*p3 == Approx(value.get<test_type>())); CHECK(*p3 == Catch::Approx(value.get<test_type>()));
// check if null pointers are returned correctly // check if null pointers are returned correctly
CHECK(value.get_ptr<const json::object_t*>() == nullptr); CHECK(value.get_ptr<const json::object_t*>() == nullptr);

View File

@ -43,10 +43,10 @@ using nlohmann::json;
#include <iomanip> #include <iomanip>
// local variable is initialized but not referenced // local variable is initialized but not referenced
DOCTEST_MSVC_SUPPRESS_WARNING_PUSH //DOCTEST_MSVC_SUPPRESS_WARNING_PUSH
DOCTEST_MSVC_SUPPRESS_WARNING(4189) //DOCTEST_MSVC_SUPPRESS_WARNING(4189)
TEST_CASE("README" * doctest::skip()) TEST_CASE("README", "[.]")
{ {
{ {
// redirect std::cout for the README file // redirect std::cout for the README file
@ -320,4 +320,4 @@ TEST_CASE("README" * doctest::skip())
} }
} }
DOCTEST_MSVC_SUPPRESS_WARNING_POP //DOCTEST_MSVC_SUPPRESS_WARNING_POP

View File

@ -264,7 +264,7 @@ TEST_CASE("regression tests 1")
int number{j["Number"]}; int number{j["Number"]};
CHECK(number == 100); CHECK(number == 100);
float foo{j["Foo"]}; float foo{j["Foo"]};
CHECK(static_cast<double>(foo) == Approx(42.42)); CHECK(static_cast<double>(foo) == Catch::Approx(42.42));
} }
SECTION("issue #89 - nonstandard integer type") SECTION("issue #89 - nonstandard integer type")
@ -645,7 +645,7 @@ TEST_CASE("regression tests 1")
TEST_DATA_DIRECTORY "/regression/working_file.json" TEST_DATA_DIRECTORY "/regression/working_file.json"
}) })
{ {
CAPTURE(filename) CAPTURE(filename);
json j; json j;
std::ifstream f(filename); std::ifstream f(filename);
CHECK_NOTHROW(f >> j); CHECK_NOTHROW(f >> j);
@ -662,7 +662,7 @@ TEST_CASE("regression tests 1")
TEST_DATA_DIRECTORY "/regression/small_signed_ints.json" TEST_DATA_DIRECTORY "/regression/small_signed_ints.json"
}) })
{ {
CAPTURE(filename) CAPTURE(filename);
json j; json j;
std::ifstream f(filename); std::ifstream f(filename);
CHECK_NOTHROW(f >> j); CHECK_NOTHROW(f >> j);
@ -679,7 +679,7 @@ TEST_CASE("regression tests 1")
SECTION("issue #329 - serialized value not always can be parsed") SECTION("issue #329 - serialized value not always can be parsed")
{ {
json _; json _;
CHECK_THROWS_AS(_ = json::parse("22e2222"), json::out_of_range&); CHECK_THROWS_AS(_ = json::parse("22e2222"), json::out_of_range);
CHECK_THROWS_WITH(_ = json::parse("22e2222"), CHECK_THROWS_WITH(_ = json::parse("22e2222"),
"[json.exception.out_of_range.406] number overflow parsing '22e2222'"); "[json.exception.out_of_range.406] number overflow parsing '22e2222'");
} }
@ -688,7 +688,7 @@ TEST_CASE("regression tests 1")
{ {
auto check_roundtrip = [](double number) auto check_roundtrip = [](double number)
{ {
CAPTURE(number) CAPTURE(number);
json j = number; json j = number;
CHECK(j.is_number_float()); CHECK(j.is_number_float());
@ -746,7 +746,7 @@ TEST_CASE("regression tests 1")
{ {
std::ifstream f("file_not_found.json"); std::ifstream f("file_not_found.json");
json _; json _;
CHECK_THROWS_AS(_ = json::parse(f), json::parse_error&); CHECK_THROWS_AS(_ = json::parse(f), json::parse_error);
CHECK_THROWS_WITH(_ = json::parse(f), "[json.exception.parse_error.101] parse error at line 1, column 1: syntax error while parsing value - unexpected end of input; expected '[', '{', or a literal"); CHECK_THROWS_WITH(_ = json::parse(f), "[json.exception.parse_error.101] parse error at line 1, column 1: syntax error while parsing value - unexpected end of input; expected '[', '{', or a literal");
} }
@ -761,7 +761,7 @@ TEST_CASE("regression tests 1")
// ss is not at EOF; this yielded an error before the fix // ss is not at EOF; this yielded an error before the fix
// (threw basic_string::append). No, it should just throw // (threw basic_string::append). No, it should just throw
// a parse error because of the EOF. // a parse error because of the EOF.
CHECK_THROWS_AS(ss >> j, json::parse_error&); CHECK_THROWS_AS(ss >> j, json::parse_error);
CHECK_THROWS_WITH(ss >> j, CHECK_THROWS_WITH(ss >> j,
"[json.exception.parse_error.101] parse error at line 1, column 1: syntax error while parsing value - unexpected end of input; expected '[', '{', or a literal"); "[json.exception.parse_error.101] parse error at line 1, column 1: syntax error while parsing value - unexpected end of input; expected '[', '{', or a literal");
} }
@ -772,7 +772,7 @@ TEST_CASE("regression tests 1")
{ {
std::stringstream ss; std::stringstream ss;
json j; json j;
CHECK_THROWS_AS(ss >> j, json::parse_error&); CHECK_THROWS_AS(ss >> j, json::parse_error);
CHECK_THROWS_WITH(ss >> j, CHECK_THROWS_WITH(ss >> j,
"[json.exception.parse_error.101] parse error at line 1, column 1: syntax error while parsing value - unexpected end of input; expected '[', '{', or a literal"); "[json.exception.parse_error.101] parse error at line 1, column 1: syntax error while parsing value - unexpected end of input; expected '[', '{', or a literal");
} }
@ -782,7 +782,7 @@ TEST_CASE("regression tests 1")
std::stringstream ss; std::stringstream ss;
ss << " "; ss << " ";
json j; json j;
CHECK_THROWS_AS(ss >> j, json::parse_error&); CHECK_THROWS_AS(ss >> j, json::parse_error);
CHECK_THROWS_WITH(ss >> j, CHECK_THROWS_WITH(ss >> j,
"[json.exception.parse_error.101] parse error at line 1, column 1: syntax error while parsing value - unexpected end of input; expected '[', '{', or a literal"); "[json.exception.parse_error.101] parse error at line 1, column 1: syntax error while parsing value - unexpected end of input; expected '[', '{', or a literal");
} }
@ -795,7 +795,7 @@ TEST_CASE("regression tests 1")
CHECK_NOTHROW(ss >> j); CHECK_NOTHROW(ss >> j);
CHECK(j == 111); CHECK(j == 111);
CHECK_THROWS_AS(ss >> j, json::parse_error&); CHECK_THROWS_AS(ss >> j, json::parse_error);
CHECK_THROWS_WITH(ss >> j, CHECK_THROWS_WITH(ss >> j,
"[json.exception.parse_error.101] parse error at line 1, column 1: syntax error while parsing value - unexpected end of input; expected '[', '{', or a literal"); "[json.exception.parse_error.101] parse error at line 1, column 1: syntax error while parsing value - unexpected end of input; expected '[', '{', or a literal");
} }
@ -808,7 +808,7 @@ TEST_CASE("regression tests 1")
CHECK_NOTHROW(ss >> j); CHECK_NOTHROW(ss >> j);
CHECK(j == 222); CHECK(j == 222);
CHECK_THROWS_AS(ss >> j, json::parse_error&); CHECK_THROWS_AS(ss >> j, json::parse_error);
CHECK_THROWS_WITH(ss >> j, CHECK_THROWS_WITH(ss >> j,
"[json.exception.parse_error.101] parse error at line 1, column 1: syntax error while parsing value - unexpected end of input; expected '[', '{', or a literal"); "[json.exception.parse_error.101] parse error at line 1, column 1: syntax error while parsing value - unexpected end of input; expected '[', '{', or a literal");
} }
@ -821,7 +821,7 @@ TEST_CASE("regression tests 1")
CHECK_NOTHROW(ss >> j); CHECK_NOTHROW(ss >> j);
CHECK(j == 333); CHECK(j == 333);
CHECK_THROWS_AS(ss >> j, json::parse_error&); CHECK_THROWS_AS(ss >> j, json::parse_error);
CHECK_THROWS_WITH(ss >> j, CHECK_THROWS_WITH(ss >> j,
"[json.exception.parse_error.101] parse error at line 1, column 1: syntax error while parsing value - unexpected end of input; expected '[', '{', or a literal"); "[json.exception.parse_error.101] parse error at line 1, column 1: syntax error while parsing value - unexpected end of input; expected '[', '{', or a literal");
} }
@ -838,7 +838,7 @@ TEST_CASE("regression tests 1")
CHECK_NOTHROW(ss >> j); CHECK_NOTHROW(ss >> j);
CHECK(j == 333); CHECK(j == 333);
CHECK_THROWS_AS(ss >> j, json::parse_error&); CHECK_THROWS_AS(ss >> j, json::parse_error);
CHECK_THROWS_WITH(ss >> j, CHECK_THROWS_WITH(ss >> j,
"[json.exception.parse_error.101] parse error at line 1, column 1: syntax error while parsing value - unexpected end of input; expected '[', '{', or a literal"); "[json.exception.parse_error.101] parse error at line 1, column 1: syntax error while parsing value - unexpected end of input; expected '[', '{', or a literal");
} }
@ -857,7 +857,7 @@ TEST_CASE("regression tests 1")
CHECK_NOTHROW(ss >> j); CHECK_NOTHROW(ss >> j);
CHECK(j == ""); CHECK(j == "");
CHECK_THROWS_AS(ss >> j, json::parse_error&); CHECK_THROWS_AS(ss >> j, json::parse_error);
CHECK_THROWS_WITH(ss >> j, CHECK_THROWS_WITH(ss >> j,
"[json.exception.parse_error.101] parse error at line 1, column 1: syntax error while parsing value - unexpected end of input; expected '[', '{', or a literal"); "[json.exception.parse_error.101] parse error at line 1, column 1: syntax error while parsing value - unexpected end of input; expected '[', '{', or a literal");
} }
@ -872,7 +872,7 @@ TEST_CASE("regression tests 1")
CHECK_NOTHROW(ss >> j); CHECK_NOTHROW(ss >> j);
CHECK(j == json({{"three", 3}})); CHECK(j == json({{"three", 3}}));
CHECK_THROWS_AS(ss >> j, json::parse_error&); CHECK_THROWS_AS(ss >> j, json::parse_error);
CHECK_THROWS_WITH(ss >> j, CHECK_THROWS_WITH(ss >> j,
"[json.exception.parse_error.101] parse error at line 1, column 1: syntax error while parsing value - unexpected end of input; expected '[', '{', or a literal"); "[json.exception.parse_error.101] parse error at line 1, column 1: syntax error while parsing value - unexpected end of input; expected '[', '{', or a literal");
} }
@ -892,7 +892,7 @@ TEST_CASE("regression tests 1")
size_t i = 0; size_t i = 0;
while (stream.peek() != EOF) while (stream.peek() != EOF)
{ {
CAPTURE(i) CAPTURE(i);
CHECK_NOTHROW(stream >> val); CHECK_NOTHROW(stream >> val);
CHECK(i < 2); CHECK(i < 2);
@ -943,7 +943,7 @@ TEST_CASE("regression tests 1")
// original test case // original test case
std::vector<uint8_t> vec {0x65, 0xf5, 0x0a, 0x48, 0x21}; std::vector<uint8_t> vec {0x65, 0xf5, 0x0a, 0x48, 0x21};
json _; json _;
CHECK_THROWS_AS(_ = json::from_cbor(vec), json::parse_error&); CHECK_THROWS_AS(_ = json::from_cbor(vec), json::parse_error);
CHECK_THROWS_WITH(_ = json::from_cbor(vec), CHECK_THROWS_WITH(_ = json::from_cbor(vec),
"[json.exception.parse_error.110] parse error at byte 6: syntax error while parsing CBOR string: unexpected end of input"); "[json.exception.parse_error.110] parse error at byte 6: syntax error while parsing CBOR string: unexpected end of input");
} }
@ -954,31 +954,31 @@ TEST_CASE("regression tests 1")
// original test case: incomplete float64 // original test case: incomplete float64
std::vector<uint8_t> vec1 {0xcb, 0x8f, 0x0a}; std::vector<uint8_t> vec1 {0xcb, 0x8f, 0x0a};
CHECK_THROWS_AS(_ = json::from_msgpack(vec1), json::parse_error&); CHECK_THROWS_AS(_ = json::from_msgpack(vec1), json::parse_error);
CHECK_THROWS_WITH(_ = json::from_msgpack(vec1), CHECK_THROWS_WITH(_ = json::from_msgpack(vec1),
"[json.exception.parse_error.110] parse error at byte 4: syntax error while parsing MessagePack number: unexpected end of input"); "[json.exception.parse_error.110] parse error at byte 4: syntax error while parsing MessagePack number: unexpected end of input");
// related test case: incomplete float32 // related test case: incomplete float32
std::vector<uint8_t> vec2 {0xca, 0x8f, 0x0a}; std::vector<uint8_t> vec2 {0xca, 0x8f, 0x0a};
CHECK_THROWS_AS(_ = json::from_msgpack(vec2), json::parse_error&); CHECK_THROWS_AS(_ = json::from_msgpack(vec2), json::parse_error);
CHECK_THROWS_WITH(_ = json::from_msgpack(vec2), CHECK_THROWS_WITH(_ = json::from_msgpack(vec2),
"[json.exception.parse_error.110] parse error at byte 4: syntax error while parsing MessagePack number: unexpected end of input"); "[json.exception.parse_error.110] parse error at byte 4: syntax error while parsing MessagePack number: unexpected end of input");
// related test case: incomplete Half-Precision Float (CBOR) // related test case: incomplete Half-Precision Float (CBOR)
std::vector<uint8_t> vec3 {0xf9, 0x8f}; std::vector<uint8_t> vec3 {0xf9, 0x8f};
CHECK_THROWS_AS(_ = json::from_cbor(vec3), json::parse_error&); CHECK_THROWS_AS(_ = json::from_cbor(vec3), json::parse_error);
CHECK_THROWS_WITH(_ = json::from_cbor(vec3), CHECK_THROWS_WITH(_ = json::from_cbor(vec3),
"[json.exception.parse_error.110] parse error at byte 3: syntax error while parsing CBOR number: unexpected end of input"); "[json.exception.parse_error.110] parse error at byte 3: syntax error while parsing CBOR number: unexpected end of input");
// related test case: incomplete Single-Precision Float (CBOR) // related test case: incomplete Single-Precision Float (CBOR)
std::vector<uint8_t> vec4 {0xfa, 0x8f, 0x0a}; std::vector<uint8_t> vec4 {0xfa, 0x8f, 0x0a};
CHECK_THROWS_AS(_ = json::from_cbor(vec4), json::parse_error&); CHECK_THROWS_AS(_ = json::from_cbor(vec4), json::parse_error);
CHECK_THROWS_WITH(_ = json::from_cbor(vec4), CHECK_THROWS_WITH(_ = json::from_cbor(vec4),
"[json.exception.parse_error.110] parse error at byte 4: syntax error while parsing CBOR number: unexpected end of input"); "[json.exception.parse_error.110] parse error at byte 4: syntax error while parsing CBOR number: unexpected end of input");
// related test case: incomplete Double-Precision Float (CBOR) // related test case: incomplete Double-Precision Float (CBOR)
std::vector<uint8_t> vec5 {0xfb, 0x8f, 0x0a}; std::vector<uint8_t> vec5 {0xfb, 0x8f, 0x0a};
CHECK_THROWS_AS(_ = json::from_cbor(vec5), json::parse_error&); CHECK_THROWS_AS(_ = json::from_cbor(vec5), json::parse_error);
CHECK_THROWS_WITH(_ = json::from_cbor(vec5), CHECK_THROWS_WITH(_ = json::from_cbor(vec5),
"[json.exception.parse_error.110] parse error at byte 4: syntax error while parsing CBOR number: unexpected end of input"); "[json.exception.parse_error.110] parse error at byte 4: syntax error while parsing CBOR number: unexpected end of input");
} }
@ -989,7 +989,7 @@ TEST_CASE("regression tests 1")
// original test case // original test case
std::vector<uint8_t> vec1 {0x87}; std::vector<uint8_t> vec1 {0x87};
CHECK_THROWS_AS(_ = json::from_msgpack(vec1), json::parse_error&); CHECK_THROWS_AS(_ = json::from_msgpack(vec1), json::parse_error);
CHECK_THROWS_WITH(_ = json::from_msgpack(vec1), CHECK_THROWS_WITH(_ = json::from_msgpack(vec1),
"[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing MessagePack string: unexpected end of input"); "[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing MessagePack string: unexpected end of input");
@ -1003,7 +1003,7 @@ TEST_CASE("regression tests 1")
}) })
{ {
std::vector<uint8_t> vec(1, static_cast<uint8_t>(b)); std::vector<uint8_t> vec(1, static_cast<uint8_t>(b));
CHECK_THROWS_AS(_ = json::from_msgpack(vec), json::parse_error&); CHECK_THROWS_AS(_ = json::from_msgpack(vec), json::parse_error);
} }
// more test cases for CBOR // more test cases for CBOR
@ -1018,15 +1018,15 @@ TEST_CASE("regression tests 1")
}) })
{ {
std::vector<uint8_t> vec(1, static_cast<uint8_t>(b)); std::vector<uint8_t> vec(1, static_cast<uint8_t>(b));
CHECK_THROWS_AS(_ = json::from_cbor(vec), json::parse_error&); CHECK_THROWS_AS(_ = json::from_cbor(vec), json::parse_error);
} }
// special case: empty input // special case: empty input
std::vector<uint8_t> vec2; std::vector<uint8_t> vec2;
CHECK_THROWS_AS(_ = json::from_cbor(vec2), json::parse_error&); CHECK_THROWS_AS(_ = json::from_cbor(vec2), json::parse_error);
CHECK_THROWS_WITH(_ = json::from_cbor(vec2), CHECK_THROWS_WITH(_ = json::from_cbor(vec2),
"[json.exception.parse_error.110] parse error at byte 1: syntax error while parsing CBOR value: unexpected end of input"); "[json.exception.parse_error.110] parse error at byte 1: syntax error while parsing CBOR value: unexpected end of input");
CHECK_THROWS_AS(_ = json::from_msgpack(vec2), json::parse_error&); CHECK_THROWS_AS(_ = json::from_msgpack(vec2), json::parse_error);
CHECK_THROWS_WITH(_ = json::from_msgpack(vec2), CHECK_THROWS_WITH(_ = json::from_msgpack(vec2),
"[json.exception.parse_error.110] parse error at byte 1: syntax error while parsing MessagePack value: unexpected end of input"); "[json.exception.parse_error.110] parse error at byte 1: syntax error while parsing MessagePack value: unexpected end of input");
} }
@ -1037,19 +1037,19 @@ TEST_CASE("regression tests 1")
// original test case: empty UTF-8 string (indefinite length) // original test case: empty UTF-8 string (indefinite length)
std::vector<uint8_t> vec1 {0x7f}; std::vector<uint8_t> vec1 {0x7f};
CHECK_THROWS_AS(_ = json::from_cbor(vec1), json::parse_error&); CHECK_THROWS_AS(_ = json::from_cbor(vec1), json::parse_error);
CHECK_THROWS_WITH(_ = json::from_cbor(vec1), CHECK_THROWS_WITH(_ = json::from_cbor(vec1),
"[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing CBOR string: unexpected end of input"); "[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing CBOR string: unexpected end of input");
// related test case: empty array (indefinite length) // related test case: empty array (indefinite length)
std::vector<uint8_t> vec2 {0x9f}; std::vector<uint8_t> vec2 {0x9f};
CHECK_THROWS_AS(_ = json::from_cbor(vec2), json::parse_error&); CHECK_THROWS_AS(_ = json::from_cbor(vec2), json::parse_error);
CHECK_THROWS_WITH(_ = json::from_cbor(vec2), CHECK_THROWS_WITH(_ = json::from_cbor(vec2),
"[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing CBOR value: unexpected end of input"); "[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing CBOR value: unexpected end of input");
// related test case: empty map (indefinite length) // related test case: empty map (indefinite length)
std::vector<uint8_t> vec3 {0xbf}; std::vector<uint8_t> vec3 {0xbf};
CHECK_THROWS_AS(_ = json::from_cbor(vec3), json::parse_error&); CHECK_THROWS_AS(_ = json::from_cbor(vec3), json::parse_error);
CHECK_THROWS_WITH(_ = json::from_cbor(vec3), CHECK_THROWS_WITH(_ = json::from_cbor(vec3),
"[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing CBOR string: unexpected end of input"); "[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing CBOR string: unexpected end of input");
} }
@ -1079,25 +1079,25 @@ TEST_CASE("regression tests 1")
}; };
json _; json _;
CHECK_THROWS_AS(_ = json::from_cbor(vec), json::parse_error&); CHECK_THROWS_AS(_ = json::from_cbor(vec), json::parse_error);
CHECK_THROWS_WITH(_ = json::from_cbor(vec), CHECK_THROWS_WITH(_ = json::from_cbor(vec),
"[json.exception.parse_error.113] parse error at byte 2: syntax error while parsing CBOR string: expected length specification (0x60-0x7B) or indefinite string type (0x7F); last byte: 0x98"); "[json.exception.parse_error.113] parse error at byte 2: syntax error while parsing CBOR string: expected length specification (0x60-0x7B) or indefinite string type (0x7F); last byte: 0x98");
// related test case: nonempty UTF-8 string (indefinite length) // related test case: nonempty UTF-8 string (indefinite length)
std::vector<uint8_t> vec1 {0x7f, 0x61, 0x61}; std::vector<uint8_t> vec1 {0x7f, 0x61, 0x61};
CHECK_THROWS_AS(_ = json::from_cbor(vec1), json::parse_error&); CHECK_THROWS_AS(_ = json::from_cbor(vec1), json::parse_error);
CHECK_THROWS_WITH(_ = json::from_cbor(vec1), CHECK_THROWS_WITH(_ = json::from_cbor(vec1),
"[json.exception.parse_error.110] parse error at byte 4: syntax error while parsing CBOR string: unexpected end of input"); "[json.exception.parse_error.110] parse error at byte 4: syntax error while parsing CBOR string: unexpected end of input");
// related test case: nonempty array (indefinite length) // related test case: nonempty array (indefinite length)
std::vector<uint8_t> vec2 {0x9f, 0x01}; std::vector<uint8_t> vec2 {0x9f, 0x01};
CHECK_THROWS_AS(_ = json::from_cbor(vec2), json::parse_error&); CHECK_THROWS_AS(_ = json::from_cbor(vec2), json::parse_error);
CHECK_THROWS_WITH(_ = json::from_cbor(vec2), CHECK_THROWS_WITH(_ = json::from_cbor(vec2),
"[json.exception.parse_error.110] parse error at byte 3: syntax error while parsing CBOR value: unexpected end of input"); "[json.exception.parse_error.110] parse error at byte 3: syntax error while parsing CBOR value: unexpected end of input");
// related test case: nonempty map (indefinite length) // related test case: nonempty map (indefinite length)
std::vector<uint8_t> vec3 {0xbf, 0x61, 0x61, 0x01}; std::vector<uint8_t> vec3 {0xbf, 0x61, 0x61, 0x01};
CHECK_THROWS_AS(_ = json::from_cbor(vec3), json::parse_error&); CHECK_THROWS_AS(_ = json::from_cbor(vec3), json::parse_error);
CHECK_THROWS_WITH(_ = json::from_cbor(vec3), CHECK_THROWS_WITH(_ = json::from_cbor(vec3),
"[json.exception.parse_error.110] parse error at byte 5: syntax error while parsing CBOR string: unexpected end of input"); "[json.exception.parse_error.110] parse error at byte 5: syntax error while parsing CBOR string: unexpected end of input");
} }
@ -1134,7 +1134,7 @@ TEST_CASE("regression tests 1")
}; };
json _; json _;
CHECK_THROWS_AS(_ = json::from_cbor(vec1), json::parse_error&); CHECK_THROWS_AS(_ = json::from_cbor(vec1), json::parse_error);
CHECK_THROWS_WITH(_ = json::from_cbor(vec1), CHECK_THROWS_WITH(_ = json::from_cbor(vec1),
"[json.exception.parse_error.113] parse error at byte 13: syntax error while parsing CBOR string: expected length specification (0x60-0x7B) or indefinite string type (0x7F); last byte: 0xB4"); "[json.exception.parse_error.113] parse error at byte 13: syntax error while parsing CBOR string: expected length specification (0x60-0x7B) or indefinite string type (0x7F); last byte: 0xB4");
@ -1148,7 +1148,7 @@ TEST_CASE("regression tests 1")
0x96, 0x96, 0xb4, 0xb4, 0xfa, 0x94, 0x94, 0x61, 0x96, 0x96, 0xb4, 0xb4, 0xfa, 0x94, 0x94, 0x61,
0x61, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61, 0xfb 0x61, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61, 0xfb
}; };
CHECK_THROWS_AS(_ = json::from_cbor(vec2), json::parse_error&); CHECK_THROWS_AS(_ = json::from_cbor(vec2), json::parse_error);
CHECK_THROWS_WITH(_ = json::from_cbor(vec2), CHECK_THROWS_WITH(_ = json::from_cbor(vec2),
"[json.exception.parse_error.113] parse error at byte 13: syntax error while parsing CBOR string: expected length specification (0x60-0x7B) or indefinite string type (0x7F); last byte: 0xB4"); "[json.exception.parse_error.113] parse error at byte 13: syntax error while parsing CBOR string: expected length specification (0x60-0x7B) or indefinite string type (0x7F); last byte: 0xB4");
} }
@ -1157,7 +1157,7 @@ TEST_CASE("regression tests 1")
{ {
std::vector<uint8_t> vec = {'-', '0', '1', '2', '2', '7', '4'}; std::vector<uint8_t> vec = {'-', '0', '1', '2', '2', '7', '4'};
json _; json _;
CHECK_THROWS_AS(_ = json::parse(vec), json::parse_error&); CHECK_THROWS_AS(_ = json::parse(vec), json::parse_error);
} }
SECTION("issue #454 - doubles are printed as integers") SECTION("issue #454 - doubles are printed as integers")
@ -1200,9 +1200,9 @@ TEST_CASE("regression tests 1")
}; };
CHECK_NOTHROW(create(j_array)); CHECK_NOTHROW(create(j_array));
CHECK_THROWS_AS(create(j_number), json::type_error&); CHECK_THROWS_AS(create(j_number), json::type_error);
CHECK_THROWS_WITH(create(j_number), "[json.exception.type_error.302] type must be array, but is number"); CHECK_THROWS_WITH(create(j_number), "[json.exception.type_error.302] type must be array, but is number");
CHECK_THROWS_AS(create(j_null), json::type_error&); CHECK_THROWS_AS(create(j_null), json::type_error);
CHECK_THROWS_WITH(create(j_null), "[json.exception.type_error.302] type must be array, but is null"); CHECK_THROWS_WITH(create(j_null), "[json.exception.type_error.302] type must be array, but is null");
} }
@ -1214,9 +1214,9 @@ TEST_CASE("regression tests 1")
}; };
CHECK_NOTHROW(create(j_array)); CHECK_NOTHROW(create(j_array));
CHECK_THROWS_AS(create(j_number), json::type_error&); CHECK_THROWS_AS(create(j_number), json::type_error);
CHECK_THROWS_WITH(create(j_number), "[json.exception.type_error.302] type must be array, but is number"); CHECK_THROWS_WITH(create(j_number), "[json.exception.type_error.302] type must be array, but is number");
CHECK_THROWS_AS(create(j_null), json::type_error&); CHECK_THROWS_AS(create(j_null), json::type_error);
CHECK_THROWS_WITH(create(j_null), "[json.exception.type_error.302] type must be array, but is null"); CHECK_THROWS_WITH(create(j_null), "[json.exception.type_error.302] type must be array, but is null");
} }
@ -1228,9 +1228,9 @@ TEST_CASE("regression tests 1")
}; };
CHECK_NOTHROW(create(j_array)); CHECK_NOTHROW(create(j_array));
CHECK_THROWS_AS(create(j_number), json::type_error&); CHECK_THROWS_AS(create(j_number), json::type_error);
CHECK_THROWS_WITH(create(j_number), "[json.exception.type_error.302] type must be array, but is number"); CHECK_THROWS_WITH(create(j_number), "[json.exception.type_error.302] type must be array, but is number");
CHECK_THROWS_AS(create(j_null), json::type_error&); CHECK_THROWS_AS(create(j_null), json::type_error);
CHECK_THROWS_WITH(create(j_null), "[json.exception.type_error.302] type must be array, but is null"); CHECK_THROWS_WITH(create(j_null), "[json.exception.type_error.302] type must be array, but is null");
} }
} }
@ -1311,7 +1311,7 @@ TEST_CASE("regression tests 1")
{ {
json _; json _;
std::vector<uint8_t> vec = {'"', '\\', '"', 'X', '"', '"'}; std::vector<uint8_t> vec = {'"', '\\', '"', 'X', '"', '"'};
CHECK_THROWS_AS(_ = json::parse(vec), json::parse_error&); CHECK_THROWS_AS(_ = json::parse(vec), json::parse_error);
} }
#if JSON_USE_IMPLICIT_CONVERSIONS #if JSON_USE_IMPLICIT_CONVERSIONS
@ -1380,7 +1380,7 @@ TEST_CASE("regression tests 1")
CHECK(v[i] == j[i]); CHECK(v[i] == j[i]);
} }
CHECK_THROWS_AS(json().get<std::valarray<double>>(), json::type_error&); CHECK_THROWS_AS(json().get<std::valarray<double>>(), json::type_error);
CHECK_THROWS_WITH(json().get<std::valarray<double>>(), CHECK_THROWS_WITH(json().get<std::valarray<double>>(),
"[json.exception.type_error.302] type must be array, but is null"); "[json.exception.type_error.302] type must be array, but is null");
} }
@ -1452,7 +1452,7 @@ TEST_CASE("regression tests 1")
std::array<uint8_t, 28> key1 = {{ 103, 92, 117, 48, 48, 48, 55, 92, 114, 215, 126, 214, 95, 92, 34, 174, 40, 71, 38, 174, 40, 71, 38, 223, 134, 247, 127, 0 }}; std::array<uint8_t, 28> key1 = {{ 103, 92, 117, 48, 48, 48, 55, 92, 114, 215, 126, 214, 95, 92, 34, 174, 40, 71, 38, 174, 40, 71, 38, 223, 134, 247, 127, 0 }};
std::string key1_str(reinterpret_cast<char*>(key1.data())); std::string key1_str(reinterpret_cast<char*>(key1.data()));
json j = key1_str; json j = key1_str;
CHECK_THROWS_AS(j.dump(), json::type_error&); CHECK_THROWS_AS(j.dump(), json::type_error);
CHECK_THROWS_WITH(j.dump(), "[json.exception.type_error.316] invalid UTF-8 byte at index 10: 0x7E"); CHECK_THROWS_WITH(j.dump(), "[json.exception.type_error.316] invalid UTF-8 byte at index 10: 0x7E");
} }
@ -1480,7 +1480,7 @@ TEST_CASE("regression tests 1")
auto p1 = R"([{"op": "move", auto p1 = R"([{"op": "move",
"from": "/one/two/three", "from": "/one/two/three",
"path": "/a/b/c"}])"_json; "path": "/a/b/c"}])"_json;
CHECK_THROWS_AS(model.patch(p1), json::out_of_range&); CHECK_THROWS_AS(model.patch(p1), json::out_of_range);
auto p2 = R"([{"op": "move", auto p2 = R"([{"op": "move",
"from": "/one/two/three", "from": "/one/two/three",
@ -1491,7 +1491,7 @@ TEST_CASE("regression tests 1")
auto p3 = R"([{"op": "copy", auto p3 = R"([{"op": "copy",
"from": "/one/two/three", "from": "/one/two/three",
"path": "/a/b/c"}])"_json; "path": "/a/b/c"}])"_json;
CHECK_THROWS_AS(model.patch(p3), json::out_of_range&); CHECK_THROWS_AS(model.patch(p3), json::out_of_range);
auto p4 = R"([{"op": "copy", auto p4 = R"([{"op": "copy",
"from": "/one/two/three", "from": "/one/two/three",
@ -1519,12 +1519,12 @@ TEST_CASE("regression tests 1")
{ {
json _; json _;
std::vector<uint8_t> v_ubjson = {'[', '$', 'Z', '#', 'L', 0x78, 0x28, 0x00, 0x68, 0x28, 0x69, 0x69, 0x17}; std::vector<uint8_t> v_ubjson = {'[', '$', 'Z', '#', 'L', 0x78, 0x28, 0x00, 0x68, 0x28, 0x69, 0x69, 0x17};
CHECK_THROWS_AS(_ = json::from_ubjson(v_ubjson), json::out_of_range&); CHECK_THROWS_AS(_ = json::from_ubjson(v_ubjson), json::out_of_range);
//CHECK_THROWS_WITH(json::from_ubjson(v_ubjson), //CHECK_THROWS_WITH(json::from_ubjson(v_ubjson),
// "[json.exception.out_of_range.408] excessive array size: 8658170730974374167"); // "[json.exception.out_of_range.408] excessive array size: 8658170730974374167");
v_ubjson[0] = '{'; v_ubjson[0] = '{';
CHECK_THROWS_AS(_ = json::from_ubjson(v_ubjson), json::out_of_range&); CHECK_THROWS_AS(_ = json::from_ubjson(v_ubjson), json::out_of_range);
//CHECK_THROWS_WITH(json::from_ubjson(v_ubjson), //CHECK_THROWS_WITH(json::from_ubjson(v_ubjson),
// "[json.exception.out_of_range.408] excessive object size: 8658170730974374167"); // "[json.exception.out_of_range.408] excessive object size: 8658170730974374167");
} }
@ -1588,7 +1588,7 @@ TEST_CASE("regression tests, exceptions dependent")
json j; json j;
s >> j; s >> j;
s >> j; s >> j;
CHECK_THROWS_AS(s >> j, json::parse_error const&); CHECK_THROWS_AS(s >> j, json::parse_error const);
CHECK(s.eof()); CHECK(s.eof());
} }
} }

View File

@ -190,18 +190,18 @@ TEST_CASE("serialization")
} }
} }
TEST_CASE_TEMPLATE("serialization for extreme integer values", T, int32_t, uint32_t, int64_t, uint64_t) TEMPLATE_TEST_CASE("serialization for extreme integer values", "", int32_t, uint32_t, int64_t, uint64_t)
{ {
SECTION("minimum") SECTION("minimum")
{ {
constexpr auto minimum = (std::numeric_limits<T>::min)(); constexpr auto minimum = (std::numeric_limits<TestType>::min)();
json j = minimum; json j = minimum;
CHECK(j.dump() == std::to_string(minimum)); CHECK(j.dump() == std::to_string(minimum));
} }
SECTION("maximum") SECTION("maximum")
{ {
constexpr auto maximum = (std::numeric_limits<T>::max)(); constexpr auto maximum = (std::numeric_limits<TestType>::max)();
json j = maximum; json j = maximum;
CHECK(j.dump() == std::to_string(maximum)); CHECK(j.dump() == std::to_string(maximum));
} }

View File

@ -131,7 +131,7 @@ TEST_CASE("compliance tests from nativejson-benchmark")
{ {
CAPTURE(json_string); CAPTURE(json_string);
CAPTURE(expected); CAPTURE(expected);
CHECK(json::parse(json_string)[0].get<double>() == Approx(expected)); CHECK(json::parse(json_string)[0].get<double>() == Catch::Approx(expected));
}; };
TEST_DOUBLE("[0.0]", 0.0); TEST_DOUBLE("[0.0]", 0.0);
@ -261,8 +261,8 @@ TEST_CASE("compliance tests from nativejson-benchmark")
{ {
auto TEST_STRING = [](const std::string & json_string, const std::string & expected) auto TEST_STRING = [](const std::string & json_string, const std::string & expected)
{ {
CAPTURE(json_string) CAPTURE(json_string);
CAPTURE(expected) CAPTURE(expected);
CHECK(json::parse(json_string)[0].get<std::string>() == expected); CHECK(json::parse(json_string)[0].get<std::string>() == expected);
}; };
@ -317,12 +317,12 @@ TEST_CASE("compliance tests from nativejson-benchmark")
//TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip32.json" // same as roundtrip31 //TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip32.json" // same as roundtrip31
}) })
{ {
CAPTURE(filename) CAPTURE(filename);
std::ifstream f(filename); std::ifstream f(filename);
std::string json_string( (std::istreambuf_iterator<char>(f) ), std::string json_string( (std::istreambuf_iterator<char>(f) ),
(std::istreambuf_iterator<char>()) ); (std::istreambuf_iterator<char>()) );
CAPTURE(json_string) CAPTURE(json_string);
json j = json::parse(json_string); json j = json::parse(json_string);
CHECK(j.dump() == json_string); CHECK(j.dump() == json_string);
} }
@ -597,7 +597,7 @@ TEST_CASE("nst's JSONTestSuite")
} }
) )
{ {
CAPTURE(filename) CAPTURE(filename);
std::ifstream f(filename); std::ifstream f(filename);
json j; json j;
CHECK_NOTHROW(f >> j); CHECK_NOTHROW(f >> j);
@ -806,7 +806,7 @@ TEST_CASE("nst's JSONTestSuite")
} }
) )
{ {
CAPTURE(filename) CAPTURE(filename);
std::ifstream f(filename); std::ifstream f(filename);
json _; json _;
CHECK_THROWS_AS(_ = json::parse(f), json::parse_error); CHECK_THROWS_AS(_ = json::parse(f), json::parse_error);
@ -839,7 +839,7 @@ TEST_CASE("nst's JSONTestSuite")
} }
) )
{ {
CAPTURE(filename) CAPTURE(filename);
std::ifstream f(filename); std::ifstream f(filename);
json j; json j;
CHECK_NOTHROW(f >> j); CHECK_NOTHROW(f >> j);
@ -862,7 +862,7 @@ TEST_CASE("nst's JSONTestSuite")
} }
) )
{ {
CAPTURE(filename) CAPTURE(filename);
std::ifstream f(filename); std::ifstream f(filename);
json j; json j;
CHECK_NOTHROW(f >> j); CHECK_NOTHROW(f >> j);
@ -882,7 +882,7 @@ TEST_CASE("nst's JSONTestSuite")
} }
) )
{ {
CAPTURE(filename) CAPTURE(filename);
std::ifstream f(filename); std::ifstream f(filename);
json j; json j;
CHECK_THROWS_AS(f >> j, json::out_of_range); CHECK_THROWS_AS(f >> j, json::out_of_range);
@ -909,7 +909,7 @@ TEST_CASE("nst's JSONTestSuite")
} }
) )
{ {
CAPTURE(filename) CAPTURE(filename);
std::ifstream f(filename); std::ifstream f(filename);
json j; json j;
CHECK_THROWS_AS(f >> j, json::parse_error); CHECK_THROWS_AS(f >> j, json::parse_error);
@ -1024,7 +1024,7 @@ TEST_CASE("nst's JSONTestSuite (2)")
} }
) )
{ {
CAPTURE(filename) CAPTURE(filename);
std::ifstream f(filename); std::ifstream f(filename);
json _; json _;
CHECK_NOTHROW(_ = json::parse(f)); CHECK_NOTHROW(_ = json::parse(f));
@ -1226,7 +1226,7 @@ TEST_CASE("nst's JSONTestSuite (2)")
} }
) )
{ {
CAPTURE(filename) CAPTURE(filename);
std::ifstream f(filename); std::ifstream f(filename);
json _; json _;
CHECK_THROWS_AS(_ = json::parse(f), json::parse_error); CHECK_THROWS_AS(_ = json::parse(f), json::parse_error);
@ -1244,7 +1244,7 @@ TEST_CASE("nst's JSONTestSuite (2)")
} }
) )
{ {
CAPTURE(filename) CAPTURE(filename);
std::ifstream f(filename); std::ifstream f(filename);
CHECK(!json::accept(f)); CHECK(!json::accept(f));
} }
@ -1292,7 +1292,7 @@ TEST_CASE("nst's JSONTestSuite (2)")
} }
) )
{ {
CAPTURE(filename) CAPTURE(filename);
std::ifstream f(filename); std::ifstream f(filename);
json _; json _;
CHECK_NOTHROW(_ = json::parse(f)); CHECK_NOTHROW(_ = json::parse(f));
@ -1404,7 +1404,7 @@ TEST_CASE("Big List of Naughty Strings")
} }
// check roundtrip // check roundtrip
CAPTURE(line) CAPTURE(line);
json j = json::parse(line); json j = json::parse(line);
CHECK(j.dump() == line); CHECK(j.dump() == line);
} }

View File

@ -187,7 +187,7 @@ TEST_CASE("UBJSON")
numbers.push_back(-2147483649LL); numbers.push_back(-2147483649LL);
for (auto i : numbers) for (auto i : numbers)
{ {
CAPTURE(i) CAPTURE(i);
// create JSON value with integer number // create JSON value with integer number
json j = i; json j = i;
@ -242,7 +242,7 @@ TEST_CASE("UBJSON")
numbers.push_back(-2147483647 - 1); // https://stackoverflow.com/a/29356002/266378 numbers.push_back(-2147483647 - 1); // https://stackoverflow.com/a/29356002/266378
for (auto i : numbers) for (auto i : numbers)
{ {
CAPTURE(i) CAPTURE(i);
// create JSON value with integer number // create JSON value with integer number
json j = i; json j = i;
@ -281,7 +281,7 @@ TEST_CASE("UBJSON")
{ {
for (int32_t i = -32768; i <= -129; ++i) for (int32_t i = -32768; i <= -129; ++i)
{ {
CAPTURE(i) CAPTURE(i);
// create JSON value with integer number // create JSON value with integer number
json j = i; json j = i;
@ -335,7 +335,7 @@ TEST_CASE("UBJSON")
{ {
for (auto i = -128; i <= -1; ++i) for (auto i = -128; i <= -1; ++i)
{ {
CAPTURE(i) CAPTURE(i);
// create JSON value with integer number // create JSON value with integer number
json j = i; json j = i;
@ -367,7 +367,7 @@ TEST_CASE("UBJSON")
{ {
for (size_t i = 0; i <= 127; ++i) for (size_t i = 0; i <= 127; ++i)
{ {
CAPTURE(i) CAPTURE(i);
// create JSON value with integer number // create JSON value with integer number
json j = -1; json j = -1;
@ -400,7 +400,7 @@ TEST_CASE("UBJSON")
{ {
for (size_t i = 128; i <= 255; ++i) for (size_t i = 128; i <= 255; ++i)
{ {
CAPTURE(i) CAPTURE(i);
// create JSON value with integer number // create JSON value with integer number
json j = -1; json j = -1;
@ -433,7 +433,7 @@ TEST_CASE("UBJSON")
{ {
for (size_t i = 256; i <= 32767; ++i) for (size_t i = 256; i <= 32767; ++i)
{ {
CAPTURE(i) CAPTURE(i);
// create JSON value with integer number // create JSON value with integer number
json j = -1; json j = -1;
@ -471,7 +471,7 @@ TEST_CASE("UBJSON")
65536u, 77777u, 1048576u 65536u, 77777u, 1048576u
}) })
{ {
CAPTURE(i) CAPTURE(i);
// create JSON value with integer number // create JSON value with integer number
json j = -1; json j = -1;
@ -512,7 +512,7 @@ TEST_CASE("UBJSON")
std::vector<uint64_t> v = {2147483648ul, 9223372036854775807ul}; std::vector<uint64_t> v = {2147483648ul, 9223372036854775807ul};
for (uint64_t i : v) for (uint64_t i : v)
{ {
CAPTURE(i) CAPTURE(i);
// create JSON value with integer number // create JSON value with integer number
json j = -1; json j = -1;
@ -563,7 +563,7 @@ TEST_CASE("UBJSON")
{ {
for (size_t i = 0; i <= 127; ++i) for (size_t i = 0; i <= 127; ++i)
{ {
CAPTURE(i) CAPTURE(i);
// create JSON value with unsigned integer number // create JSON value with unsigned integer number
json j = i; json j = i;
@ -596,7 +596,7 @@ TEST_CASE("UBJSON")
{ {
for (size_t i = 128; i <= 255; ++i) for (size_t i = 128; i <= 255; ++i)
{ {
CAPTURE(i) CAPTURE(i);
// create JSON value with unsigned integer number // create JSON value with unsigned integer number
json j = i; json j = i;
@ -629,7 +629,7 @@ TEST_CASE("UBJSON")
{ {
for (size_t i = 256; i <= 32767; ++i) for (size_t i = 256; i <= 32767; ++i)
{ {
CAPTURE(i) CAPTURE(i);
// create JSON value with unsigned integer number // create JSON value with unsigned integer number
json j = i; json j = i;
@ -666,7 +666,7 @@ TEST_CASE("UBJSON")
65536u, 77777u, 1048576u 65536u, 77777u, 1048576u
}) })
{ {
CAPTURE(i) CAPTURE(i);
// create JSON value with unsigned integer number // create JSON value with unsigned integer number
json j = i; json j = i;
@ -706,7 +706,7 @@ TEST_CASE("UBJSON")
std::vector<uint64_t> v = {2147483648ul, 9223372036854775807ul}; std::vector<uint64_t> v = {2147483648ul, 9223372036854775807ul};
for (uint64_t i : v) for (uint64_t i : v)
{ {
CAPTURE(i) CAPTURE(i);
// create JSON value with integer number // create JSON value with integer number
json j = i; json j = i;
@ -837,7 +837,7 @@ TEST_CASE("UBJSON")
{ {
for (size_t N = 0; N <= 127; ++N) for (size_t N = 0; N <= 127; ++N)
{ {
CAPTURE(N) CAPTURE(N);
// create JSON value with string containing of N * 'x' // create JSON value with string containing of N * 'x'
const auto s = std::string(N, 'x'); const auto s = std::string(N, 'x');
@ -873,7 +873,7 @@ TEST_CASE("UBJSON")
{ {
for (size_t N = 128; N <= 255; ++N) for (size_t N = 128; N <= 255; ++N)
{ {
CAPTURE(N) CAPTURE(N);
// create JSON value with string containing of N * 'x' // create JSON value with string containing of N * 'x'
const auto s = std::string(N, 'x'); const auto s = std::string(N, 'x');
@ -909,7 +909,7 @@ TEST_CASE("UBJSON")
256u, 999u, 1025u, 3333u, 2048u, 32767u 256u, 999u, 1025u, 3333u, 2048u, 32767u
}) })
{ {
CAPTURE(N) CAPTURE(N);
// create JSON value with string containing of N * 'x' // create JSON value with string containing of N * 'x'
const auto s = std::string(N, 'x'); const auto s = std::string(N, 'x');
@ -943,7 +943,7 @@ TEST_CASE("UBJSON")
65536u, 77777u, 1048576u 65536u, 77777u, 1048576u
}) })
{ {
CAPTURE(N) CAPTURE(N);
// create JSON value with string containing of N * 'x' // create JSON value with string containing of N * 'x'
const auto s = std::string(N, 'x'); const auto s = std::string(N, 'x');
@ -979,7 +979,7 @@ TEST_CASE("UBJSON")
{ {
for (std::size_t N = 0; N <= 127; ++N) for (std::size_t N = 0; N <= 127; ++N)
{ {
CAPTURE(N) CAPTURE(N);
// create JSON value with byte array containing of N * 'x' // create JSON value with byte array containing of N * 'x'
const auto s = std::vector<std::uint8_t>(N, 'x'); const auto s = std::vector<std::uint8_t>(N, 'x');
@ -1030,7 +1030,7 @@ TEST_CASE("UBJSON")
{ {
for (std::size_t N = 128; N <= 255; ++N) for (std::size_t N = 128; N <= 255; ++N)
{ {
CAPTURE(N) CAPTURE(N);
// create JSON value with byte array containing of N * 'x' // create JSON value with byte array containing of N * 'x'
const auto s = std::vector<std::uint8_t>(N, 'x'); const auto s = std::vector<std::uint8_t>(N, 'x');
@ -1070,7 +1070,7 @@ TEST_CASE("UBJSON")
256u, 999u, 1025u, 3333u, 2048u, 32767u 256u, 999u, 1025u, 3333u, 2048u, 32767u
}) })
{ {
CAPTURE(N) CAPTURE(N);
// create JSON value with byte array containing of N * 'x' // create JSON value with byte array containing of N * 'x'
const auto s = std::vector<std::uint8_t>(N, 'x'); const auto s = std::vector<std::uint8_t>(N, 'x');
@ -1107,7 +1107,7 @@ TEST_CASE("UBJSON")
32768u, 77777u, 1048576u 32768u, 77777u, 1048576u
}) })
{ {
CAPTURE(N) CAPTURE(N);
// create JSON value with byte array containing of N * 'x' // create JSON value with byte array containing of N * 'x'
const auto s = std::vector<std::uint8_t>(N, 'x'); const auto s = std::vector<std::uint8_t>(N, 'x');
@ -1595,7 +1595,7 @@ TEST_CASE("UBJSON")
SECTION("strict mode") SECTION("strict mode")
{ {
json _; json _;
CHECK_THROWS_AS(_ = json::from_ubjson(vec), json::parse_error&); CHECK_THROWS_AS(_ = json::from_ubjson(vec), json::parse_error);
CHECK_THROWS_WITH(_ = json::from_ubjson(vec), CHECK_THROWS_WITH(_ = json::from_ubjson(vec),
"[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing UBJSON value: expected end of input; last byte: 0x5A"); "[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing UBJSON value: expected end of input; last byte: 0x5A");
} }
@ -1607,28 +1607,28 @@ TEST_CASE("UBJSON")
{ {
std::vector<uint8_t> v_ubjson = {'[', '$', 'Z', '#', 'L', 0x78, 0x28, 0x00, 0x68, 0x28, 0x69, 0x69, 0x17}; std::vector<uint8_t> v_ubjson = {'[', '$', 'Z', '#', 'L', 0x78, 0x28, 0x00, 0x68, 0x28, 0x69, 0x69, 0x17};
json _; json _;
CHECK_THROWS_AS(_ = json::from_ubjson(v_ubjson), json::out_of_range&); CHECK_THROWS_AS(_ = json::from_ubjson(v_ubjson), json::out_of_range);
json j; json j;
nlohmann::detail::json_sax_dom_callback_parser<json> scp(j, [](int /*unused*/, json::parse_event_t /*unused*/, const json& /*unused*/) nlohmann::detail::json_sax_dom_callback_parser<json> scp(j, [](int /*unused*/, json::parse_event_t /*unused*/, const json& /*unused*/)
{ {
return true; return true;
}); });
CHECK_THROWS_AS(_ = json::sax_parse(v_ubjson, &scp, json::input_format_t::ubjson), json::out_of_range&); CHECK_THROWS_AS(_ = json::sax_parse(v_ubjson, &scp, json::input_format_t::ubjson), json::out_of_range);
} }
SECTION("object") SECTION("object")
{ {
std::vector<uint8_t> v_ubjson = {'{', '$', 'Z', '#', 'L', 0x78, 0x28, 0x00, 0x68, 0x28, 0x69, 0x69, 0x17}; std::vector<uint8_t> v_ubjson = {'{', '$', 'Z', '#', 'L', 0x78, 0x28, 0x00, 0x68, 0x28, 0x69, 0x69, 0x17};
json _; json _;
CHECK_THROWS_AS(_ = json::from_ubjson(v_ubjson), json::out_of_range&); CHECK_THROWS_AS(_ = json::from_ubjson(v_ubjson), json::out_of_range);
json j; json j;
nlohmann::detail::json_sax_dom_callback_parser<json> scp(j, [](int /*unused*/, json::parse_event_t /*unused*/, const json& /*unused*/) nlohmann::detail::json_sax_dom_callback_parser<json> scp(j, [](int /*unused*/, json::parse_event_t /*unused*/, const json& /*unused*/)
{ {
return true; return true;
}); });
CHECK_THROWS_AS(_ = json::sax_parse(v_ubjson, &scp, json::input_format_t::ubjson), json::out_of_range&); CHECK_THROWS_AS(_ = json::sax_parse(v_ubjson, &scp, json::input_format_t::ubjson), json::out_of_range);
} }
} }
} }
@ -1820,7 +1820,7 @@ TEST_CASE("UBJSON")
SECTION("empty byte vector") SECTION("empty byte vector")
{ {
json _; json _;
CHECK_THROWS_AS(_ = json::from_ubjson(std::vector<uint8_t>()), json::parse_error&); CHECK_THROWS_AS(_ = json::from_ubjson(std::vector<uint8_t>()), json::parse_error);
CHECK_THROWS_WITH(_ = json::from_ubjson(std::vector<uint8_t>()), CHECK_THROWS_WITH(_ = json::from_ubjson(std::vector<uint8_t>()),
"[json.exception.parse_error.110] parse error at byte 1: syntax error while parsing UBJSON value: unexpected end of input"); "[json.exception.parse_error.110] parse error at byte 1: syntax error while parsing UBJSON value: unexpected end of input");
} }
@ -1831,7 +1831,7 @@ TEST_CASE("UBJSON")
{ {
std::vector<uint8_t> v = {'C'}; std::vector<uint8_t> v = {'C'};
json _; json _;
CHECK_THROWS_AS(_ = json::from_ubjson(v), json::parse_error&); CHECK_THROWS_AS(_ = json::from_ubjson(v), json::parse_error);
CHECK_THROWS_WITH(_ = json::from_ubjson(v), "[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing UBJSON char: unexpected end of input"); CHECK_THROWS_WITH(_ = json::from_ubjson(v), "[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing UBJSON char: unexpected end of input");
} }
@ -1839,7 +1839,7 @@ TEST_CASE("UBJSON")
{ {
std::vector<uint8_t> v = {'C', 130}; std::vector<uint8_t> v = {'C', 130};
json _; json _;
CHECK_THROWS_AS(_ = json::from_ubjson(v), json::parse_error&); CHECK_THROWS_AS(_ = json::from_ubjson(v), json::parse_error);
CHECK_THROWS_WITH(_ = json::from_ubjson(v), "[json.exception.parse_error.113] parse error at byte 2: syntax error while parsing UBJSON char: byte after 'C' must be in range 0x00..0x7F; last byte: 0x82"); CHECK_THROWS_WITH(_ = json::from_ubjson(v), "[json.exception.parse_error.113] parse error at byte 2: syntax error while parsing UBJSON char: byte after 'C' must be in range 0x00..0x7F; last byte: 0x82");
} }
} }
@ -1850,7 +1850,7 @@ TEST_CASE("UBJSON")
{ {
std::vector<uint8_t> v = {'S'}; std::vector<uint8_t> v = {'S'};
json _; json _;
CHECK_THROWS_AS(_ = json::from_ubjson(v), json::parse_error&); CHECK_THROWS_AS(_ = json::from_ubjson(v), json::parse_error);
CHECK_THROWS_WITH(_ = json::from_ubjson(v), "[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing UBJSON value: unexpected end of input"); CHECK_THROWS_WITH(_ = json::from_ubjson(v), "[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing UBJSON value: unexpected end of input");
} }
@ -1858,7 +1858,7 @@ TEST_CASE("UBJSON")
{ {
std::vector<uint8_t> v = {'S', '1', 'a'}; std::vector<uint8_t> v = {'S', '1', 'a'};
json _; json _;
CHECK_THROWS_AS(_ = json::from_ubjson(v), json::parse_error&); CHECK_THROWS_AS(_ = json::from_ubjson(v), json::parse_error);
CHECK_THROWS_WITH(_ = json::from_ubjson(v), "[json.exception.parse_error.113] parse error at byte 2: syntax error while parsing UBJSON string: expected length type specification (U, i, I, l, L); last byte: 0x31"); CHECK_THROWS_WITH(_ = json::from_ubjson(v), "[json.exception.parse_error.113] parse error at byte 2: syntax error while parsing UBJSON string: expected length type specification (U, i, I, l, L); last byte: 0x31");
} }
} }
@ -1869,7 +1869,7 @@ TEST_CASE("UBJSON")
{ {
std::vector<uint8_t> v = {'[', '$', 'i', 2}; std::vector<uint8_t> v = {'[', '$', 'i', 2};
json _; json _;
CHECK_THROWS_AS(_ = json::from_ubjson(v), json::parse_error&); CHECK_THROWS_AS(_ = json::from_ubjson(v), json::parse_error);
CHECK_THROWS_WITH(_ = json::from_ubjson(v), "[json.exception.parse_error.112] parse error at byte 4: syntax error while parsing UBJSON size: expected '#' after type information; last byte: 0x02"); CHECK_THROWS_WITH(_ = json::from_ubjson(v), "[json.exception.parse_error.112] parse error at byte 4: syntax error while parsing UBJSON size: expected '#' after type information; last byte: 0x02");
} }
} }
@ -1878,17 +1878,17 @@ TEST_CASE("UBJSON")
{ {
std::vector<uint8_t> vS = {'S'}; std::vector<uint8_t> vS = {'S'};
json _; json _;
CHECK_THROWS_AS(_ = json::from_ubjson(vS), json::parse_error&); CHECK_THROWS_AS(_ = json::from_ubjson(vS), json::parse_error);
CHECK_THROWS_WITH(_ = json::from_ubjson(vS), "[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing UBJSON value: unexpected end of input"); CHECK_THROWS_WITH(_ = json::from_ubjson(vS), "[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing UBJSON value: unexpected end of input");
CHECK(json::from_ubjson(vS, true, false).is_discarded()); CHECK(json::from_ubjson(vS, true, false).is_discarded());
std::vector<uint8_t> v = {'S', 'i', '2', 'a'}; std::vector<uint8_t> v = {'S', 'i', '2', 'a'};
CHECK_THROWS_AS(_ = json::from_ubjson(v), json::parse_error&); CHECK_THROWS_AS(_ = json::from_ubjson(v), json::parse_error);
CHECK_THROWS_WITH(_ = json::from_ubjson(v), "[json.exception.parse_error.110] parse error at byte 5: syntax error while parsing UBJSON string: unexpected end of input"); CHECK_THROWS_WITH(_ = json::from_ubjson(v), "[json.exception.parse_error.110] parse error at byte 5: syntax error while parsing UBJSON string: unexpected end of input");
CHECK(json::from_ubjson(v, true, false).is_discarded()); CHECK(json::from_ubjson(v, true, false).is_discarded());
std::vector<uint8_t> vC = {'C'}; std::vector<uint8_t> vC = {'C'};
CHECK_THROWS_AS(_ = json::from_ubjson(vC), json::parse_error&); CHECK_THROWS_AS(_ = json::from_ubjson(vC), json::parse_error);
CHECK_THROWS_WITH(_ = json::from_ubjson(vC), "[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing UBJSON char: unexpected end of input"); CHECK_THROWS_WITH(_ = json::from_ubjson(vC), "[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing UBJSON char: unexpected end of input");
CHECK(json::from_ubjson(vC, true, false).is_discarded()); CHECK(json::from_ubjson(vC, true, false).is_discarded());
} }
@ -1897,32 +1897,32 @@ TEST_CASE("UBJSON")
{ {
std::vector<uint8_t> vU = {'[', '#', 'U'}; std::vector<uint8_t> vU = {'[', '#', 'U'};
json _; json _;
CHECK_THROWS_AS(_ = json::from_ubjson(vU), json::parse_error&); CHECK_THROWS_AS(_ = json::from_ubjson(vU), json::parse_error);
CHECK_THROWS_WITH(_ = json::from_ubjson(vU), "[json.exception.parse_error.110] parse error at byte 4: syntax error while parsing UBJSON number: unexpected end of input"); CHECK_THROWS_WITH(_ = json::from_ubjson(vU), "[json.exception.parse_error.110] parse error at byte 4: syntax error while parsing UBJSON number: unexpected end of input");
CHECK(json::from_ubjson(vU, true, false).is_discarded()); CHECK(json::from_ubjson(vU, true, false).is_discarded());
std::vector<uint8_t> vi = {'[', '#', 'i'}; std::vector<uint8_t> vi = {'[', '#', 'i'};
CHECK_THROWS_AS(_ = json::from_ubjson(vi), json::parse_error&); CHECK_THROWS_AS(_ = json::from_ubjson(vi), json::parse_error);
CHECK_THROWS_WITH(_ = json::from_ubjson(vi), "[json.exception.parse_error.110] parse error at byte 4: syntax error while parsing UBJSON number: unexpected end of input"); CHECK_THROWS_WITH(_ = json::from_ubjson(vi), "[json.exception.parse_error.110] parse error at byte 4: syntax error while parsing UBJSON number: unexpected end of input");
CHECK(json::from_ubjson(vi, true, false).is_discarded()); CHECK(json::from_ubjson(vi, true, false).is_discarded());
std::vector<uint8_t> vI = {'[', '#', 'I'}; std::vector<uint8_t> vI = {'[', '#', 'I'};
CHECK_THROWS_AS(_ = json::from_ubjson(vI), json::parse_error&); CHECK_THROWS_AS(_ = json::from_ubjson(vI), json::parse_error);
CHECK_THROWS_WITH(_ = json::from_ubjson(vI), "[json.exception.parse_error.110] parse error at byte 4: syntax error while parsing UBJSON number: unexpected end of input"); CHECK_THROWS_WITH(_ = json::from_ubjson(vI), "[json.exception.parse_error.110] parse error at byte 4: syntax error while parsing UBJSON number: unexpected end of input");
CHECK(json::from_ubjson(vI, true, false).is_discarded()); CHECK(json::from_ubjson(vI, true, false).is_discarded());
std::vector<uint8_t> vl = {'[', '#', 'l'}; std::vector<uint8_t> vl = {'[', '#', 'l'};
CHECK_THROWS_AS(_ = json::from_ubjson(vl), json::parse_error&); CHECK_THROWS_AS(_ = json::from_ubjson(vl), json::parse_error);
CHECK_THROWS_WITH(_ = json::from_ubjson(vl), "[json.exception.parse_error.110] parse error at byte 4: syntax error while parsing UBJSON number: unexpected end of input"); CHECK_THROWS_WITH(_ = json::from_ubjson(vl), "[json.exception.parse_error.110] parse error at byte 4: syntax error while parsing UBJSON number: unexpected end of input");
CHECK(json::from_ubjson(vl, true, false).is_discarded()); CHECK(json::from_ubjson(vl, true, false).is_discarded());
std::vector<uint8_t> vL = {'[', '#', 'L'}; std::vector<uint8_t> vL = {'[', '#', 'L'};
CHECK_THROWS_AS(_ = json::from_ubjson(vL), json::parse_error&); CHECK_THROWS_AS(_ = json::from_ubjson(vL), json::parse_error);
CHECK_THROWS_WITH(_ = json::from_ubjson(vL), "[json.exception.parse_error.110] parse error at byte 4: syntax error while parsing UBJSON number: unexpected end of input"); CHECK_THROWS_WITH(_ = json::from_ubjson(vL), "[json.exception.parse_error.110] parse error at byte 4: syntax error while parsing UBJSON number: unexpected end of input");
CHECK(json::from_ubjson(vL, true, false).is_discarded()); CHECK(json::from_ubjson(vL, true, false).is_discarded());
std::vector<uint8_t> v0 = {'[', '#', 'T', ']'}; std::vector<uint8_t> v0 = {'[', '#', 'T', ']'};
CHECK_THROWS_AS(_ = json::from_ubjson(v0), json::parse_error&); CHECK_THROWS_AS(_ = json::from_ubjson(v0), json::parse_error);
CHECK_THROWS_WITH(_ = json::from_ubjson(v0), "[json.exception.parse_error.113] parse error at byte 3: syntax error while parsing UBJSON size: expected length type specification (U, i, I, l, L) after '#'; last byte: 0x54"); CHECK_THROWS_WITH(_ = json::from_ubjson(v0), "[json.exception.parse_error.113] parse error at byte 3: syntax error while parsing UBJSON size: expected length type specification (U, i, I, l, L) after '#'; last byte: 0x54");
CHECK(json::from_ubjson(v0, true, false).is_discarded()); CHECK(json::from_ubjson(v0, true, false).is_discarded());
} }
@ -1931,17 +1931,17 @@ TEST_CASE("UBJSON")
{ {
std::vector<uint8_t> v0 = {'[', '$'}; std::vector<uint8_t> v0 = {'[', '$'};
json _; json _;
CHECK_THROWS_AS(_ = json::from_ubjson(v0), json::parse_error&); CHECK_THROWS_AS(_ = json::from_ubjson(v0), json::parse_error);
CHECK_THROWS_WITH(_ = json::from_ubjson(v0), "[json.exception.parse_error.110] parse error at byte 3: syntax error while parsing UBJSON type: unexpected end of input"); CHECK_THROWS_WITH(_ = json::from_ubjson(v0), "[json.exception.parse_error.110] parse error at byte 3: syntax error while parsing UBJSON type: unexpected end of input");
CHECK(json::from_ubjson(v0, true, false).is_discarded()); CHECK(json::from_ubjson(v0, true, false).is_discarded());
std::vector<uint8_t> vi = {'[', '$', '#'}; std::vector<uint8_t> vi = {'[', '$', '#'};
CHECK_THROWS_AS(_ = json::from_ubjson(vi), json::parse_error&); CHECK_THROWS_AS(_ = json::from_ubjson(vi), json::parse_error);
CHECK_THROWS_WITH(_ = json::from_ubjson(vi), "[json.exception.parse_error.110] parse error at byte 4: syntax error while parsing UBJSON value: unexpected end of input"); CHECK_THROWS_WITH(_ = json::from_ubjson(vi), "[json.exception.parse_error.110] parse error at byte 4: syntax error while parsing UBJSON value: unexpected end of input");
CHECK(json::from_ubjson(vi, true, false).is_discarded()); CHECK(json::from_ubjson(vi, true, false).is_discarded());
std::vector<uint8_t> vT = {'[', '$', 'T'}; std::vector<uint8_t> vT = {'[', '$', 'T'};
CHECK_THROWS_AS(_ = json::from_ubjson(vT), json::parse_error&); CHECK_THROWS_AS(_ = json::from_ubjson(vT), json::parse_error);
CHECK_THROWS_WITH(_ = json::from_ubjson(vT), "[json.exception.parse_error.110] parse error at byte 4: syntax error while parsing UBJSON value: unexpected end of input"); CHECK_THROWS_WITH(_ = json::from_ubjson(vT), "[json.exception.parse_error.110] parse error at byte 4: syntax error while parsing UBJSON value: unexpected end of input");
CHECK(json::from_ubjson(vT, true, false).is_discarded()); CHECK(json::from_ubjson(vT, true, false).is_discarded());
} }
@ -1950,17 +1950,17 @@ TEST_CASE("UBJSON")
{ {
std::vector<uint8_t> vST = {'[', '$', 'i', '#', 'i', 2, 1}; std::vector<uint8_t> vST = {'[', '$', 'i', '#', 'i', 2, 1};
json _; json _;
CHECK_THROWS_AS(_ = json::from_ubjson(vST), json::parse_error&); CHECK_THROWS_AS(_ = json::from_ubjson(vST), json::parse_error);
CHECK_THROWS_WITH(_ = json::from_ubjson(vST), "[json.exception.parse_error.110] parse error at byte 8: syntax error while parsing UBJSON number: unexpected end of input"); CHECK_THROWS_WITH(_ = json::from_ubjson(vST), "[json.exception.parse_error.110] parse error at byte 8: syntax error while parsing UBJSON number: unexpected end of input");
CHECK(json::from_ubjson(vST, true, false).is_discarded()); CHECK(json::from_ubjson(vST, true, false).is_discarded());
std::vector<uint8_t> vS = {'[', '#', 'i', 2, 'i', 1}; std::vector<uint8_t> vS = {'[', '#', 'i', 2, 'i', 1};
CHECK_THROWS_AS(_ = json::from_ubjson(vS), json::parse_error&); CHECK_THROWS_AS(_ = json::from_ubjson(vS), json::parse_error);
CHECK_THROWS_WITH(_ = json::from_ubjson(vS), "[json.exception.parse_error.110] parse error at byte 7: syntax error while parsing UBJSON value: unexpected end of input"); CHECK_THROWS_WITH(_ = json::from_ubjson(vS), "[json.exception.parse_error.110] parse error at byte 7: syntax error while parsing UBJSON value: unexpected end of input");
CHECK(json::from_ubjson(vS, true, false).is_discarded()); CHECK(json::from_ubjson(vS, true, false).is_discarded());
std::vector<uint8_t> v = {'[', 'i', 2, 'i', 1}; std::vector<uint8_t> v = {'[', 'i', 2, 'i', 1};
CHECK_THROWS_AS(_ = json::from_ubjson(v), json::parse_error&); CHECK_THROWS_AS(_ = json::from_ubjson(v), json::parse_error);
CHECK_THROWS_WITH(_ = json::from_ubjson(v), "[json.exception.parse_error.110] parse error at byte 6: syntax error while parsing UBJSON value: unexpected end of input"); CHECK_THROWS_WITH(_ = json::from_ubjson(v), "[json.exception.parse_error.110] parse error at byte 6: syntax error while parsing UBJSON value: unexpected end of input");
CHECK(json::from_ubjson(v, true, false).is_discarded()); CHECK(json::from_ubjson(v, true, false).is_discarded());
} }
@ -1969,42 +1969,42 @@ TEST_CASE("UBJSON")
{ {
std::vector<uint8_t> vST = {'{', '$', 'i', '#', 'i', 2, 'i', 1, 'a', 1}; std::vector<uint8_t> vST = {'{', '$', 'i', '#', 'i', 2, 'i', 1, 'a', 1};
json _; json _;
CHECK_THROWS_AS(_ = json::from_ubjson(vST), json::parse_error&); CHECK_THROWS_AS(_ = json::from_ubjson(vST), json::parse_error);
CHECK_THROWS_WITH(_ = json::from_ubjson(vST), "[json.exception.parse_error.110] parse error at byte 11: syntax error while parsing UBJSON value: unexpected end of input"); CHECK_THROWS_WITH(_ = json::from_ubjson(vST), "[json.exception.parse_error.110] parse error at byte 11: syntax error while parsing UBJSON value: unexpected end of input");
CHECK(json::from_ubjson(vST, true, false).is_discarded()); CHECK(json::from_ubjson(vST, true, false).is_discarded());
std::vector<uint8_t> vT = {'{', '$', 'i', 'i', 1, 'a', 1}; std::vector<uint8_t> vT = {'{', '$', 'i', 'i', 1, 'a', 1};
CHECK_THROWS_AS(_ = json::from_ubjson(vT), json::parse_error&); CHECK_THROWS_AS(_ = json::from_ubjson(vT), json::parse_error);
CHECK_THROWS_WITH(_ = json::from_ubjson(vT), "[json.exception.parse_error.112] parse error at byte 4: syntax error while parsing UBJSON size: expected '#' after type information; last byte: 0x69"); CHECK_THROWS_WITH(_ = json::from_ubjson(vT), "[json.exception.parse_error.112] parse error at byte 4: syntax error while parsing UBJSON size: expected '#' after type information; last byte: 0x69");
CHECK(json::from_ubjson(vT, true, false).is_discarded()); CHECK(json::from_ubjson(vT, true, false).is_discarded());
std::vector<uint8_t> vS = {'{', '#', 'i', 2, 'i', 1, 'a', 'i', 1}; std::vector<uint8_t> vS = {'{', '#', 'i', 2, 'i', 1, 'a', 'i', 1};
CHECK_THROWS_AS(_ = json::from_ubjson(vS), json::parse_error&); CHECK_THROWS_AS(_ = json::from_ubjson(vS), json::parse_error);
CHECK_THROWS_WITH(_ = json::from_ubjson(vS), "[json.exception.parse_error.110] parse error at byte 10: syntax error while parsing UBJSON value: unexpected end of input"); CHECK_THROWS_WITH(_ = json::from_ubjson(vS), "[json.exception.parse_error.110] parse error at byte 10: syntax error while parsing UBJSON value: unexpected end of input");
CHECK(json::from_ubjson(vS, true, false).is_discarded()); CHECK(json::from_ubjson(vS, true, false).is_discarded());
std::vector<uint8_t> v = {'{', 'i', 1, 'a', 'i', 1}; std::vector<uint8_t> v = {'{', 'i', 1, 'a', 'i', 1};
CHECK_THROWS_AS(_ = json::from_ubjson(v), json::parse_error&); CHECK_THROWS_AS(_ = json::from_ubjson(v), json::parse_error);
CHECK_THROWS_WITH(_ = json::from_ubjson(v), "[json.exception.parse_error.110] parse error at byte 7: syntax error while parsing UBJSON value: unexpected end of input"); CHECK_THROWS_WITH(_ = json::from_ubjson(v), "[json.exception.parse_error.110] parse error at byte 7: syntax error while parsing UBJSON value: unexpected end of input");
CHECK(json::from_ubjson(v, true, false).is_discarded()); CHECK(json::from_ubjson(v, true, false).is_discarded());
std::vector<uint8_t> v2 = {'{', 'i', 1, 'a', 'i', 1, 'i'}; std::vector<uint8_t> v2 = {'{', 'i', 1, 'a', 'i', 1, 'i'};
CHECK_THROWS_AS(_ = json::from_ubjson(v2), json::parse_error&); CHECK_THROWS_AS(_ = json::from_ubjson(v2), json::parse_error);
CHECK_THROWS_WITH(_ = json::from_ubjson(v2), "[json.exception.parse_error.110] parse error at byte 8: syntax error while parsing UBJSON number: unexpected end of input"); CHECK_THROWS_WITH(_ = json::from_ubjson(v2), "[json.exception.parse_error.110] parse error at byte 8: syntax error while parsing UBJSON number: unexpected end of input");
CHECK(json::from_ubjson(v2, true, false).is_discarded()); CHECK(json::from_ubjson(v2, true, false).is_discarded());
std::vector<uint8_t> v3 = {'{', 'i', 1, 'a'}; std::vector<uint8_t> v3 = {'{', 'i', 1, 'a'};
CHECK_THROWS_AS(_ = json::from_ubjson(v3), json::parse_error&); CHECK_THROWS_AS(_ = json::from_ubjson(v3), json::parse_error);
CHECK_THROWS_WITH(_ = json::from_ubjson(v3), "[json.exception.parse_error.110] parse error at byte 5: syntax error while parsing UBJSON value: unexpected end of input"); CHECK_THROWS_WITH(_ = json::from_ubjson(v3), "[json.exception.parse_error.110] parse error at byte 5: syntax error while parsing UBJSON value: unexpected end of input");
CHECK(json::from_ubjson(v3, true, false).is_discarded()); CHECK(json::from_ubjson(v3, true, false).is_discarded());
std::vector<uint8_t> vST1 = {'{', '$', 'd', '#', 'i', 2, 'i', 1, 'a'}; std::vector<uint8_t> vST1 = {'{', '$', 'd', '#', 'i', 2, 'i', 1, 'a'};
CHECK_THROWS_AS(_ = json::from_ubjson(vST1), json::parse_error&); CHECK_THROWS_AS(_ = json::from_ubjson(vST1), json::parse_error);
CHECK_THROWS_WITH(_ = json::from_ubjson(vST1), "[json.exception.parse_error.110] parse error at byte 10: syntax error while parsing UBJSON number: unexpected end of input"); CHECK_THROWS_WITH(_ = json::from_ubjson(vST1), "[json.exception.parse_error.110] parse error at byte 10: syntax error while parsing UBJSON number: unexpected end of input");
CHECK(json::from_ubjson(vST1, true, false).is_discarded()); CHECK(json::from_ubjson(vST1, true, false).is_discarded());
std::vector<uint8_t> vST2 = {'{', '#', 'i', 2, 'i', 1, 'a'}; std::vector<uint8_t> vST2 = {'{', '#', 'i', 2, 'i', 1, 'a'};
CHECK_THROWS_AS(_ = json::from_ubjson(vST2), json::parse_error&); CHECK_THROWS_AS(_ = json::from_ubjson(vST2), json::parse_error);
CHECK_THROWS_WITH(_ = json::from_ubjson(vST2), "[json.exception.parse_error.110] parse error at byte 8: syntax error while parsing UBJSON value: unexpected end of input"); CHECK_THROWS_WITH(_ = json::from_ubjson(vST2), "[json.exception.parse_error.110] parse error at byte 8: syntax error while parsing UBJSON value: unexpected end of input");
CHECK(json::from_ubjson(vST2, true, false).is_discarded()); CHECK(json::from_ubjson(vST2, true, false).is_discarded());
} }
@ -2502,7 +2502,7 @@ TEST_CASE("UBJSON roundtrips" * doctest::skip())
TEST_DATA_DIRECTORY "/json_tests/pass3.json" TEST_DATA_DIRECTORY "/json_tests/pass3.json"
}) })
{ {
CAPTURE(filename) CAPTURE(filename);
{ {
INFO_WITH_TEMP(filename + ": std::vector<uint8_t>"); INFO_WITH_TEMP(filename + ": std::vector<uint8_t>");

View File

@ -242,7 +242,7 @@ static void from_json(const nlohmann::json& j, contact_book& cb)
} }
} // namespace udt } // namespace udt
TEST_CASE("basic usage" * doctest::test_suite("udt")) TEST_CASE("basic usage", "[udt]")
{ {
// a bit narcissistic maybe :) ? // a bit narcissistic maybe :) ?
@ -400,7 +400,7 @@ struct adl_serializer<udt::legacy_type>
}; };
} // namespace nlohmann } // namespace nlohmann
TEST_CASE("adl_serializer specialization" * doctest::test_suite("udt")) TEST_CASE("adl_serializer specialization", "[udt]")
{ {
SECTION("partial specialization") SECTION("partial specialization")
{ {
@ -476,7 +476,7 @@ struct adl_serializer<std::vector<float>>
}; };
} // namespace nlohmann } // namespace nlohmann
TEST_CASE("even supported types can be specialized" * doctest::test_suite("udt")) TEST_CASE("even supported types can be specialized", "[udt]")
{ {
json j = std::vector<float> {1.0, 2.0, 3.0}; json j = std::vector<float> {1.0, 2.0, 3.0};
CHECK(j.dump() == R"("hijacked!")"); CHECK(j.dump() == R"("hijacked!")");
@ -515,7 +515,7 @@ struct adl_serializer<std::unique_ptr<T>>
}; };
} // namespace nlohmann } // namespace nlohmann
TEST_CASE("Non-copyable types" * doctest::test_suite("udt")) TEST_CASE("Non-copyable types", "[udt]")
{ {
SECTION("to_json") SECTION("to_json")
{ {
@ -656,7 +656,7 @@ static std::ostream& operator<<(std::ostream& os, small_pod l)
} }
} // namespace udt } // namespace udt
TEST_CASE("custom serializer for pods" * doctest::test_suite("udt")) TEST_CASE("custom serializer for pods", "[udt]")
{ {
using custom_json = using custom_json =
nlohmann::basic_json<std::map, std::vector, std::string, bool, nlohmann::basic_json<std::map, std::vector, std::string, bool,
@ -696,7 +696,7 @@ struct another_adl_serializer
} }
}; };
TEST_CASE("custom serializer that does adl by default" * doctest::test_suite("udt")) TEST_CASE("custom serializer that does adl by default", "[udt]")
{ {
auto me = udt::person{{23}, {"theo"}, udt::country::france}; auto me = udt::person{{23}, {"theo"}, udt::country::france};
@ -808,7 +808,7 @@ template <typename T>
struct is_constructible_patched<T, decltype(void(json(std::declval<T>())))> : std::true_type {}; struct is_constructible_patched<T, decltype(void(json(std::declval<T>())))> : std::true_type {};
} // namespace } // namespace
TEST_CASE("an incomplete type does not trigger a compiler error in non-evaluated context" * doctest::test_suite("udt")) TEST_CASE("an incomplete type does not trigger a compiler error in non-evaluated context", "[udt]")
{ {
static_assert(!is_constructible_patched<json, incomplete>::value, ""); static_assert(!is_constructible_patched<json, incomplete>::value, "");
} }

View File

@ -257,71 +257,71 @@ TEMPLATE_TEST_CASE("Serialization/deserialization via NLOHMANN_DEFINE_TYPE_INTRU
} }
} }
TEST_CASE_TEMPLATE("Serialization/deserialization of classes with 26 public/private member variables via NLOHMANN_DEFINE_TYPE_INTRUSIVE and NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE", T, TEMPLATE_TEST_CASE("Serialization/deserialization of classes with 26 public/private member variables via NLOHMANN_DEFINE_TYPE_INTRUSIVE and NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE", "",
persons::person_with_private_alphabet, persons::person_with_private_alphabet,
persons::person_with_public_alphabet) persons::person_with_public_alphabet)
{ {
SECTION("alphabet") SECTION("alphabet")
{ {
{ {
T obj1; TestType obj1;
nlohmann::json j = obj1; //via json object nlohmann::json j = obj1; //via json object
T obj2; TestType obj2;
j.get_to(obj2); j.get_to(obj2);
bool ok = (obj1 == obj2); bool ok = (obj1 == obj2);
CHECK(ok); CHECK(ok);
} }
{ {
T obj1; TestType obj1;
nlohmann::json j1 = obj1; //via json string nlohmann::json j1 = obj1; //via json string
std::string s = j1.dump(); std::string s = j1.dump();
nlohmann::json j2 = nlohmann::json::parse(s); nlohmann::json j2 = nlohmann::json::parse(s);
T obj2; TestType obj2;
j2.get_to(obj2); j2.get_to(obj2);
bool ok = (obj1 == obj2); bool ok = (obj1 == obj2);
CHECK(ok); CHECK(ok);
} }
{ {
T obj1; TestType obj1;
nlohmann::json j1 = obj1; //via msgpack nlohmann::json j1 = obj1; //via msgpack
std::vector<uint8_t> buf = nlohmann::json::to_msgpack(j1); std::vector<uint8_t> buf = nlohmann::json::to_msgpack(j1);
nlohmann::json j2 = nlohmann::json::from_msgpack(buf); nlohmann::json j2 = nlohmann::json::from_msgpack(buf);
T obj2; TestType obj2;
j2.get_to(obj2); j2.get_to(obj2);
bool ok = (obj1 == obj2); bool ok = (obj1 == obj2);
CHECK(ok); CHECK(ok);
} }
{ {
T obj1; TestType obj1;
nlohmann::json j1 = obj1; //via bson nlohmann::json j1 = obj1; //via bson
std::vector<uint8_t> buf = nlohmann::json::to_bson(j1); std::vector<uint8_t> buf = nlohmann::json::to_bson(j1);
nlohmann::json j2 = nlohmann::json::from_bson(buf); nlohmann::json j2 = nlohmann::json::from_bson(buf);
T obj2; TestType obj2;
j2.get_to(obj2); j2.get_to(obj2);
bool ok = (obj1 == obj2); bool ok = (obj1 == obj2);
CHECK(ok); CHECK(ok);
} }
{ {
T obj1; TestType obj1;
nlohmann::json j1 = obj1; //via cbor nlohmann::json j1 = obj1; //via cbor
std::vector<uint8_t> buf = nlohmann::json::to_cbor(j1); std::vector<uint8_t> buf = nlohmann::json::to_cbor(j1);
nlohmann::json j2 = nlohmann::json::from_cbor(buf); nlohmann::json j2 = nlohmann::json::from_cbor(buf);
T obj2; TestType obj2;
j2.get_to(obj2); j2.get_to(obj2);
bool ok = (obj1 == obj2); bool ok = (obj1 == obj2);
CHECK(ok); CHECK(ok);
} }
{ {
T obj1; TestType obj1;
nlohmann::json j1 = obj1; //via ubjson nlohmann::json j1 = obj1; //via ubjson
std::vector<uint8_t> buf = nlohmann::json::to_ubjson(j1); std::vector<uint8_t> buf = nlohmann::json::to_ubjson(j1);
nlohmann::json j2 = nlohmann::json::from_ubjson(buf); nlohmann::json j2 = nlohmann::json::from_ubjson(buf);
T obj2; TestType obj2;
j2.get_to(obj2); j2.get_to(obj2);
bool ok = (obj1 == obj2); bool ok = (obj1 == obj2);
CHECK(ok); CHECK(ok);