🚧 move to Catch2
This commit is contained in:
parent
1a41dbe4a7
commit
3fedcbb46f
@ -62,7 +62,7 @@ TEST_CASE("bad_alloc")
|
||||
bad_allocator>;
|
||||
|
||||
// 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;
|
||||
CHECK_NOTHROW(my_allocator_clean_up(my_json::json_value(t).object));
|
||||
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;
|
||||
}
|
||||
SECTION("array")
|
||||
@ -161,7 +161,7 @@ TEST_CASE("controlled bad_alloc")
|
||||
auto t = my_json::value_t::array;
|
||||
CHECK_NOTHROW(my_allocator_clean_up(my_json::json_value(t).array));
|
||||
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;
|
||||
}
|
||||
SECTION("string")
|
||||
@ -170,7 +170,7 @@ TEST_CASE("controlled bad_alloc")
|
||||
auto t = my_json::value_t::string;
|
||||
CHECK_NOTHROW(my_allocator_clean_up(my_json::json_value(t).string));
|
||||
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;
|
||||
}
|
||||
}
|
||||
@ -181,7 +181,7 @@ TEST_CASE("controlled bad_alloc")
|
||||
my_json::string_t v("foo");
|
||||
CHECK_NOTHROW(my_allocator_clean_up(my_json::json_value(v).string));
|
||||
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;
|
||||
}
|
||||
}
|
||||
@ -194,7 +194,7 @@ TEST_CASE("controlled bad_alloc")
|
||||
std::map<std::string, std::string> v {{"foo", "bar"}};
|
||||
CHECK_NOTHROW(my_json(v));
|
||||
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;
|
||||
}
|
||||
|
||||
@ -204,7 +204,7 @@ TEST_CASE("controlled bad_alloc")
|
||||
std::vector<std::string> v {"foo", "bar", "baz"};
|
||||
CHECK_NOTHROW(my_json(v));
|
||||
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;
|
||||
}
|
||||
|
||||
@ -213,7 +213,7 @@ TEST_CASE("controlled bad_alloc")
|
||||
next_construct_fails = false;
|
||||
CHECK_NOTHROW(my_json("foo"));
|
||||
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;
|
||||
}
|
||||
|
||||
@ -223,7 +223,7 @@ TEST_CASE("controlled bad_alloc")
|
||||
std::string s("foo");
|
||||
CHECK_NOTHROW(my_json(s));
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@ -922,7 +922,7 @@ TEST_CASE("BSON numerical data")
|
||||
for (auto i : numbers)
|
||||
{
|
||||
|
||||
CAPTURE(i)
|
||||
CAPTURE(i);
|
||||
|
||||
json j =
|
||||
{
|
||||
@ -994,7 +994,7 @@ TEST_CASE("BSON numerical data")
|
||||
for (auto i : numbers)
|
||||
{
|
||||
|
||||
CAPTURE(i)
|
||||
CAPTURE(i);
|
||||
|
||||
json j =
|
||||
{
|
||||
@ -1047,7 +1047,7 @@ TEST_CASE("BSON numerical data")
|
||||
for (auto i : numbers)
|
||||
{
|
||||
|
||||
CAPTURE(i)
|
||||
CAPTURE(i);
|
||||
|
||||
json j =
|
||||
{
|
||||
@ -1109,7 +1109,7 @@ TEST_CASE("BSON numerical data")
|
||||
for (auto i : numbers)
|
||||
{
|
||||
|
||||
CAPTURE(i)
|
||||
CAPTURE(i);
|
||||
|
||||
json j =
|
||||
{
|
||||
@ -1164,7 +1164,7 @@ TEST_CASE("BSON numerical data")
|
||||
for (auto i : numbers)
|
||||
{
|
||||
|
||||
CAPTURE(i)
|
||||
CAPTURE(i);
|
||||
|
||||
json j =
|
||||
{
|
||||
@ -1214,7 +1214,7 @@ TEST_CASE("BSON numerical data")
|
||||
for (auto i : numbers)
|
||||
{
|
||||
|
||||
CAPTURE(i)
|
||||
CAPTURE(i);
|
||||
|
||||
json j =
|
||||
{
|
||||
@ -1242,7 +1242,7 @@ TEST_CASE("BSON numerical data")
|
||||
#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");
|
||||
#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
|
||||
}
|
||||
}
|
||||
@ -1251,7 +1251,7 @@ TEST_CASE("BSON numerical data")
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("BSON roundtrips" * doctest::skip())
|
||||
TEST_CASE("BSON roundtrips", "[.]")
|
||||
{
|
||||
SECTION("reference files")
|
||||
{
|
||||
@ -1264,10 +1264,10 @@ TEST_CASE("BSON roundtrips" * doctest::skip())
|
||||
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
|
||||
std::ifstream f_json(filename);
|
||||
json j1 = json::parse(f_json);
|
||||
@ -1281,8 +1281,8 @@ TEST_CASE("BSON roundtrips" * doctest::skip())
|
||||
CHECK(j1 == j2);
|
||||
}
|
||||
|
||||
SECTION(filename + ": std::ifstream")
|
||||
{
|
||||
INFO_WITH_TEMP(filename + ": std::ifstream");
|
||||
// parse JSON file
|
||||
std::ifstream f_json(filename);
|
||||
json j1 = json::parse(f_json);
|
||||
@ -1296,8 +1296,8 @@ TEST_CASE("BSON roundtrips" * doctest::skip())
|
||||
CHECK(j1 == j2);
|
||||
}
|
||||
|
||||
SECTION(filename + ": uint8_t* and size")
|
||||
{
|
||||
INFO_WITH_TEMP(filename + ": uint8_t* and size");
|
||||
// parse JSON file
|
||||
std::ifstream f_json(filename);
|
||||
json j1 = json::parse(f_json);
|
||||
@ -1311,8 +1311,8 @@ TEST_CASE("BSON roundtrips" * doctest::skip())
|
||||
CHECK(j1 == j2);
|
||||
}
|
||||
|
||||
SECTION(filename + ": output to output adapters")
|
||||
{
|
||||
INFO_WITH_TEMP(filename + ": output to output adapters");
|
||||
// parse JSON file
|
||||
std::ifstream f_json(filename);
|
||||
json j1 = json::parse(f_json);
|
||||
@ -1320,8 +1320,8 @@ TEST_CASE("BSON roundtrips" * doctest::skip())
|
||||
// parse BSON file
|
||||
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;
|
||||
json::to_bson(j1, vec);
|
||||
|
||||
|
||||
@ -132,7 +132,7 @@ TEST_CASE("iterator class")
|
||||
{
|
||||
json j(json::value_t::null);
|
||||
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");
|
||||
}
|
||||
|
||||
@ -142,7 +142,7 @@ TEST_CASE("iterator class")
|
||||
json::iterator it = j.begin();
|
||||
CHECK(*it == json(17));
|
||||
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");
|
||||
}
|
||||
|
||||
@ -167,7 +167,7 @@ TEST_CASE("iterator class")
|
||||
{
|
||||
json j(json::value_t::null);
|
||||
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");
|
||||
}
|
||||
|
||||
@ -177,7 +177,7 @@ TEST_CASE("iterator class")
|
||||
json::iterator it = j.begin();
|
||||
CHECK(std::string(it->type_name()) == "number");
|
||||
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");
|
||||
}
|
||||
|
||||
|
||||
@ -1172,7 +1172,7 @@ TEST_CASE("parser class")
|
||||
// only check error message if c is not a control character
|
||||
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)) + "'");
|
||||
}
|
||||
break;
|
||||
@ -1232,50 +1232,50 @@ TEST_CASE("parser class")
|
||||
|
||||
if (valid(c))
|
||||
{
|
||||
CAPTURE(s1)
|
||||
CAPTURE(s1);
|
||||
CHECK_NOTHROW(parser_helper(s1));
|
||||
CAPTURE(s2)
|
||||
CAPTURE(s2);
|
||||
CHECK_NOTHROW(parser_helper(s2));
|
||||
CAPTURE(s3)
|
||||
CAPTURE(s3);
|
||||
CHECK_NOTHROW(parser_helper(s3));
|
||||
CAPTURE(s4)
|
||||
CAPTURE(s4);
|
||||
CHECK_NOTHROW(parser_helper(s4));
|
||||
}
|
||||
else
|
||||
{
|
||||
CAPTURE(s1)
|
||||
CAPTURE(s1);
|
||||
CHECK_THROWS_AS(parser_helper(s1), json::parse_error);
|
||||
// only check error message if c is not a control character
|
||||
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) + "'");
|
||||
}
|
||||
|
||||
CAPTURE(s2)
|
||||
CAPTURE(s2);
|
||||
CHECK_THROWS_AS(parser_helper(s2), json::parse_error);
|
||||
// only check error message if c is not a control character
|
||||
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) + "'");
|
||||
}
|
||||
|
||||
CAPTURE(s3)
|
||||
CAPTURE(s3);
|
||||
CHECK_THROWS_AS(parser_helper(s3), json::parse_error);
|
||||
// only check error message if c is not a control character
|
||||
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) + "'");
|
||||
}
|
||||
|
||||
CAPTURE(s4)
|
||||
CAPTURE(s4);
|
||||
CHECK_THROWS_AS(parser_helper(s4), json::parse_error);
|
||||
// only check error message if c is not a control character
|
||||
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) + "'");
|
||||
}
|
||||
}
|
||||
@ -1452,27 +1452,27 @@ TEST_CASE("parser class")
|
||||
|
||||
if (valid(c))
|
||||
{
|
||||
CAPTURE(s1)
|
||||
CAPTURE(s1);
|
||||
CHECK(json::parser(nlohmann::detail::input_adapter(s1)).accept());
|
||||
CAPTURE(s2)
|
||||
CAPTURE(s2);
|
||||
CHECK(json::parser(nlohmann::detail::input_adapter(s2)).accept());
|
||||
CAPTURE(s3)
|
||||
CAPTURE(s3);
|
||||
CHECK(json::parser(nlohmann::detail::input_adapter(s3)).accept());
|
||||
CAPTURE(s4)
|
||||
CAPTURE(s4);
|
||||
CHECK(json::parser(nlohmann::detail::input_adapter(s4)).accept());
|
||||
}
|
||||
else
|
||||
{
|
||||
CAPTURE(s1)
|
||||
CAPTURE(s1);
|
||||
CHECK(json::parser(nlohmann::detail::input_adapter(s1)).accept() == false);
|
||||
|
||||
CAPTURE(s2)
|
||||
CAPTURE(s2);
|
||||
CHECK(json::parser(nlohmann::detail::input_adapter(s2)).accept() == false);
|
||||
|
||||
CAPTURE(s3)
|
||||
CAPTURE(s3);
|
||||
CHECK(json::parser(nlohmann::detail::input_adapter(s3)).accept() == false);
|
||||
|
||||
CAPTURE(s4)
|
||||
CAPTURE(s4);
|
||||
CHECK(json::parser(nlohmann::detail::input_adapter(s4)).accept() == false);
|
||||
}
|
||||
}
|
||||
|
||||
@ -305,11 +305,11 @@ TEST_CASE("constructors")
|
||||
{
|
||||
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_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_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");
|
||||
}
|
||||
|
||||
@ -878,7 +878,7 @@ TEST_CASE("constructors")
|
||||
float n = 42.23f;
|
||||
json j(n);
|
||||
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")
|
||||
@ -886,7 +886,7 @@ TEST_CASE("constructors")
|
||||
double n = 42.23;
|
||||
json j(n);
|
||||
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")
|
||||
@ -894,28 +894,28 @@ TEST_CASE("constructors")
|
||||
long double n = 42.23L;
|
||||
json j(n);
|
||||
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")
|
||||
{
|
||||
json j(42.23);
|
||||
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")
|
||||
{
|
||||
json j(42.23f);
|
||||
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")
|
||||
{
|
||||
json j(42.23L);
|
||||
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 _;
|
||||
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 }),
|
||||
"[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 jobject2 = {{"a", "a"}, {"b", 1}, {"c", 17u}};
|
||||
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(jobject.begin(), jobject2.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(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 jobject2 = {{"a", "a"}, {"b", 1}, {"c", 17u}};
|
||||
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(jobject.cbegin(), jobject2.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(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 jarray2 = {2, 3, 4, 5};
|
||||
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(jarray.begin(), jarray2.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(jarray2.begin(), jarray.end()), "[json.exception.invalid_iterator.201] iterators are not compatible");
|
||||
}
|
||||
{
|
||||
json jarray = {1, 2, 3, 4};
|
||||
json jarray2 = {2, 3, 4, 5};
|
||||
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(jarray.cbegin(), jarray2.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(jarray2.cbegin(), jarray.cend()), "[json.exception.invalid_iterator.201] iterators are not compatible");
|
||||
}
|
||||
@ -1429,13 +1429,13 @@ TEST_CASE("constructors")
|
||||
{
|
||||
{
|
||||
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()),
|
||||
"[json.exception.invalid_iterator.206] cannot construct with iterators from null");
|
||||
}
|
||||
{
|
||||
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()),
|
||||
"[json.exception.invalid_iterator.206] cannot construct with iterators from null");
|
||||
}
|
||||
@ -1532,15 +1532,15 @@ TEST_CASE("constructors")
|
||||
{
|
||||
{
|
||||
json j = "foo";
|
||||
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.end(), j.end()), 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.begin(), j.begin()), "[json.exception.invalid_iterator.204] iterators out of range");
|
||||
}
|
||||
{
|
||||
json j = "bar";
|
||||
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.cend(), j.cend()), 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.cbegin(), j.cbegin()), "[json.exception.invalid_iterator.204] iterators out of range");
|
||||
}
|
||||
@ -1550,15 +1550,15 @@ TEST_CASE("constructors")
|
||||
{
|
||||
{
|
||||
json j = false;
|
||||
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.end(), j.end()), 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.begin(), j.begin()), "[json.exception.invalid_iterator.204] iterators out of range");
|
||||
}
|
||||
{
|
||||
json j = true;
|
||||
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.cend(), j.cend()), 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.cbegin(), j.cbegin()), "[json.exception.invalid_iterator.204] iterators out of range");
|
||||
}
|
||||
@ -1568,15 +1568,15 @@ TEST_CASE("constructors")
|
||||
{
|
||||
{
|
||||
json j = 17;
|
||||
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.end(), j.end()), 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.begin(), j.begin()), "[json.exception.invalid_iterator.204] iterators out of range");
|
||||
}
|
||||
{
|
||||
json j = 17;
|
||||
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.cend(), j.cend()), 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.cbegin(), j.cbegin()), "[json.exception.invalid_iterator.204] iterators out of range");
|
||||
}
|
||||
@ -1586,15 +1586,15 @@ TEST_CASE("constructors")
|
||||
{
|
||||
{
|
||||
json j = 17u;
|
||||
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.end(), j.end()), 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.begin(), j.begin()), "[json.exception.invalid_iterator.204] iterators out of range");
|
||||
}
|
||||
{
|
||||
json j = 17u;
|
||||
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.cend(), j.cend()), 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.cbegin(), j.cbegin()), "[json.exception.invalid_iterator.204] iterators out of range");
|
||||
}
|
||||
@ -1604,15 +1604,15 @@ TEST_CASE("constructors")
|
||||
{
|
||||
{
|
||||
json j = 23.42;
|
||||
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.end(), j.end()), 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.begin(), j.begin()), "[json.exception.invalid_iterator.204] iterators out of range");
|
||||
}
|
||||
{
|
||||
json j = 23.42;
|
||||
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.cend(), j.cend()), 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.cbegin(), j.cbegin()), "[json.exception.invalid_iterator.204] iterators out of range");
|
||||
}
|
||||
|
||||
@ -106,11 +106,11 @@ TEST_CASE("convenience functions")
|
||||
check_escaped("\x1f", "\\u001f");
|
||||
|
||||
// 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ü"),
|
||||
"[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"),
|
||||
"[json.exception.type_error.316] incomplete UTF-8 string; last byte: 0xC2");
|
||||
}
|
||||
|
||||
@ -1192,19 +1192,19 @@ TEST_CASE("value conversion")
|
||||
SECTION("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")
|
||||
{
|
||||
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")
|
||||
{
|
||||
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")
|
||||
@ -1253,19 +1253,19 @@ TEST_CASE("value conversion")
|
||||
SECTION("number_float_t")
|
||||
{
|
||||
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")
|
||||
{
|
||||
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")
|
||||
{
|
||||
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
|
||||
|
||||
@ -44,7 +44,8 @@ TEST_CASE("Better diagnostics")
|
||||
{
|
||||
json j = 1;
|
||||
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")
|
||||
@ -52,35 +53,40 @@ TEST_CASE("Better diagnostics")
|
||||
json j;
|
||||
j["a"]["b"]["c"] = 1;
|
||||
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")
|
||||
{
|
||||
json j;
|
||||
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")
|
||||
{
|
||||
json j;
|
||||
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")
|
||||
{
|
||||
json j;
|
||||
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")
|
||||
{
|
||||
json j;
|
||||
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")
|
||||
@ -88,13 +94,15 @@ TEST_CASE("Better diagnostics")
|
||||
json j;
|
||||
j["a/b"]["m~n"] = 1;
|
||||
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")
|
||||
{
|
||||
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()")
|
||||
|
||||
@ -69,4 +69,4 @@ TEST_CASE("Tests with disabled exceptions")
|
||||
}
|
||||
}
|
||||
|
||||
DOCTEST_GCC_SUPPRESS_WARNING_POP
|
||||
//DOCTEST_GCC_SUPPRESS_WARNING_POP
|
||||
|
||||
@ -40,10 +40,10 @@ using nlohmann::json;
|
||||
#endif
|
||||
|
||||
// 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("-Wrange-loop-construct")
|
||||
DOCTEST_CLANG_SUPPRESS_WARNING_PUSH
|
||||
DOCTEST_CLANG_SUPPRESS_WARNING("-Wrange-loop-construct")
|
||||
//DOCTEST_GCC_SUPPRESS_WARNING_PUSH
|
||||
//DOCTEST_GCC_SUPPRESS_WARNING("-Wrange-loop-construct")
|
||||
//DOCTEST_CLANG_SUPPRESS_WARNING_PUSH
|
||||
//DOCTEST_CLANG_SUPPRESS_WARNING("-Wrange-loop-construct")
|
||||
|
||||
TEST_CASE("iterator_wrapper")
|
||||
{
|
||||
@ -1463,5 +1463,5 @@ TEST_CASE("items()")
|
||||
#undef JSON_HAS_CPP_14
|
||||
#endif
|
||||
|
||||
DOCTEST_GCC_SUPPRESS_WARNING_POP
|
||||
DOCTEST_CLANG_SUPPRESS_WARNING_POP
|
||||
//DOCTEST_GCC_SUPPRESS_WARNING_POP
|
||||
//DOCTEST_CLANG_SUPPRESS_WARNING_POP
|
||||
|
||||
@ -344,9 +344,9 @@ TEST_CASE("JSON patch")
|
||||
// check that evaluation throws
|
||||
CHECK_THROWS_AS(doc.patch(patch), json::other_error);
|
||||
#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
|
||||
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
|
||||
}
|
||||
|
||||
@ -489,9 +489,9 @@ TEST_CASE("JSON patch")
|
||||
// check that evaluation throws
|
||||
CHECK_THROWS_AS(doc.patch(patch), json::other_error);
|
||||
#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
|
||||
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
|
||||
}
|
||||
|
||||
@ -1261,9 +1261,9 @@ TEST_CASE("JSON patch")
|
||||
// the test will fail
|
||||
CHECK_THROWS_AS(doc.patch(patch), json::other_error);
|
||||
#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
|
||||
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
|
||||
}
|
||||
}
|
||||
@ -1345,13 +1345,13 @@ TEST_CASE("JSON patch")
|
||||
TEST_DATA_DIRECTORY "/json-patch-tests/tests.json"
|
||||
})
|
||||
{
|
||||
CAPTURE(filename)
|
||||
CAPTURE(filename);
|
||||
std::ifstream f(filename);
|
||||
json suite = json::parse(f);
|
||||
|
||||
for (const auto& test : suite)
|
||||
{
|
||||
INFO_WITH_TEMP(test.value("comment", ""));
|
||||
CAPTURE(test.value("comment", ""));
|
||||
|
||||
// skip tests marked as disabled
|
||||
if (test.value("disabled", false))
|
||||
|
||||
@ -37,23 +37,23 @@ TEST_CASE("JSON pointers")
|
||||
{
|
||||
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"),
|
||||
"[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("/~~"),
|
||||
"[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("/~"),
|
||||
"[json.exception.parse_error.108] parse error: escape character '~' must be followed with '0' or '1'");
|
||||
|
||||
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(),
|
||||
"[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(),
|
||||
"[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::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],
|
||||
"[json.exception.out_of_range.404] unresolved reference token '10e'");
|
||||
}
|
||||
@ -165,10 +165,10 @@ TEST_CASE("JSON pointers")
|
||||
|
||||
// unresolved access
|
||||
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],
|
||||
"[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),
|
||||
"[json.exception.out_of_range.404] unresolved reference token '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"]);
|
||||
|
||||
// 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")),
|
||||
"[json.exception.out_of_range.403] key 'a' not found");
|
||||
|
||||
// unresolved access
|
||||
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],
|
||||
"[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),
|
||||
"[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}));
|
||||
|
||||
// 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],
|
||||
"[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],
|
||||
"[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),
|
||||
"[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),
|
||||
"[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));
|
||||
|
||||
// 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,
|
||||
"[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,
|
||||
"[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,
|
||||
"[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,
|
||||
"[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,
|
||||
"[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,
|
||||
"[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,
|
||||
"[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,
|
||||
"[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);
|
||||
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_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());
|
||||
}
|
||||
|
||||
@ -369,18 +369,18 @@ TEST_CASE("JSON pointers")
|
||||
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";
|
||||
|
||||
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_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());
|
||||
}
|
||||
|
||||
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,
|
||||
"[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,
|
||||
"[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_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(),
|
||||
"[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}));
|
||||
|
||||
// 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],
|
||||
"[json.exception.out_of_range.402] array index '-' (3) is out of range");
|
||||
CHECK(!j_const.contains("/-"_json_pointer));
|
||||
|
||||
// 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),
|
||||
"[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),
|
||||
"[json.exception.out_of_range.402] array index '-' (3) is out of range");
|
||||
CHECK(!j_const.contains("/-"_json_pointer));
|
||||
@ -423,22 +423,22 @@ TEST_CASE("JSON pointers")
|
||||
CHECK(j["/2"_json_pointer] == j[2]);
|
||||
|
||||
// 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),
|
||||
"[json.exception.out_of_range.401] array index 3 is out of range");
|
||||
CHECK(!j.contains("/3"_json_pointer));
|
||||
|
||||
// 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),
|
||||
"[json.exception.out_of_range.401] array index 5 is out of range");
|
||||
CHECK(!j.contains("/5"_json_pointer));
|
||||
|
||||
// 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],
|
||||
"[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),
|
||||
"[json.exception.out_of_range.402] array index '-' (3) is out of range");
|
||||
CHECK(!j.contains("/-"_json_pointer));
|
||||
@ -496,12 +496,12 @@ TEST_CASE("JSON pointers")
|
||||
CHECK(j_flatten.unflatten() == j);
|
||||
|
||||
// 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(),
|
||||
"[json.exception.type_error.314] only objects can be unflattened");
|
||||
|
||||
// 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
|
||||
CHECK_THROWS_WITH(json({{"/1", {1, 2, 3}}}).unflatten(), "[json.exception.type_error.315] (/~11) values in object must be primitive");
|
||||
#else
|
||||
@ -510,7 +510,7 @@ TEST_CASE("JSON pointers")
|
||||
|
||||
// error for conflicting values
|
||||
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(),
|
||||
"[json.exception.type_error.313] invalid value to unflatten");
|
||||
|
||||
|
||||
@ -176,7 +176,7 @@ TEST_CASE("MessagePack")
|
||||
{
|
||||
for (auto i = -32; i <= -1; ++i)
|
||||
{
|
||||
CAPTURE(i)
|
||||
CAPTURE(i);
|
||||
|
||||
// create JSON value with integer number
|
||||
json j = i;
|
||||
@ -206,7 +206,7 @@ TEST_CASE("MessagePack")
|
||||
{
|
||||
for (size_t i = 0; i <= 127; ++i)
|
||||
{
|
||||
CAPTURE(i)
|
||||
CAPTURE(i);
|
||||
|
||||
// create JSON value with integer number
|
||||
json j = -1;
|
||||
@ -237,7 +237,7 @@ TEST_CASE("MessagePack")
|
||||
{
|
||||
for (size_t i = 128; i <= 255; ++i)
|
||||
{
|
||||
CAPTURE(i)
|
||||
CAPTURE(i);
|
||||
|
||||
// create JSON value with integer number
|
||||
json j = -1;
|
||||
@ -271,7 +271,7 @@ TEST_CASE("MessagePack")
|
||||
{
|
||||
for (size_t i = 256; i <= 65535; ++i)
|
||||
{
|
||||
CAPTURE(i)
|
||||
CAPTURE(i);
|
||||
|
||||
// create JSON value with integer number
|
||||
json j = -1;
|
||||
@ -309,7 +309,7 @@ TEST_CASE("MessagePack")
|
||||
65536u, 77777u, 1048576u, 4294967295u
|
||||
})
|
||||
{
|
||||
CAPTURE(i)
|
||||
CAPTURE(i);
|
||||
|
||||
// create JSON value with integer number
|
||||
json j = -1;
|
||||
@ -352,7 +352,7 @@ TEST_CASE("MessagePack")
|
||||
4294967296LU, 9223372036854775807LU
|
||||
})
|
||||
{
|
||||
CAPTURE(i)
|
||||
CAPTURE(i);
|
||||
|
||||
// create JSON value with integer number
|
||||
json j = -1;
|
||||
@ -400,7 +400,7 @@ TEST_CASE("MessagePack")
|
||||
{
|
||||
for (auto i = -128; i <= -33; ++i)
|
||||
{
|
||||
CAPTURE(i)
|
||||
CAPTURE(i);
|
||||
|
||||
// create JSON value with integer number
|
||||
json j = i;
|
||||
@ -448,7 +448,7 @@ TEST_CASE("MessagePack")
|
||||
{
|
||||
for (int16_t i = -32768; i <= static_cast<std::int16_t>(-129); ++i)
|
||||
{
|
||||
CAPTURE(i)
|
||||
CAPTURE(i);
|
||||
|
||||
// create JSON value with integer number
|
||||
json j = i;
|
||||
@ -488,7 +488,7 @@ TEST_CASE("MessagePack")
|
||||
numbers.push_back(-2147483648LL);
|
||||
for (auto i : numbers)
|
||||
{
|
||||
CAPTURE(i)
|
||||
CAPTURE(i);
|
||||
|
||||
// create JSON value with integer number
|
||||
json j = i;
|
||||
@ -530,7 +530,7 @@ TEST_CASE("MessagePack")
|
||||
numbers.push_back(-2147483649LL);
|
||||
for (auto i : numbers)
|
||||
{
|
||||
CAPTURE(i)
|
||||
CAPTURE(i);
|
||||
|
||||
// create JSON value with unsigned integer number
|
||||
json j = i;
|
||||
@ -580,7 +580,7 @@ TEST_CASE("MessagePack")
|
||||
{
|
||||
for (size_t i = 0; i <= 127; ++i)
|
||||
{
|
||||
CAPTURE(i)
|
||||
CAPTURE(i);
|
||||
|
||||
// create JSON value with unsigned integer number
|
||||
json j = i;
|
||||
@ -610,7 +610,7 @@ TEST_CASE("MessagePack")
|
||||
{
|
||||
for (size_t i = 128; i <= 255; ++i)
|
||||
{
|
||||
CAPTURE(i)
|
||||
CAPTURE(i);
|
||||
|
||||
// create JSON value with unsigned integer number
|
||||
json j = i;
|
||||
@ -643,7 +643,7 @@ TEST_CASE("MessagePack")
|
||||
{
|
||||
for (size_t i = 256; i <= 65535; ++i)
|
||||
{
|
||||
CAPTURE(i)
|
||||
CAPTURE(i);
|
||||
|
||||
// create JSON value with unsigned integer number
|
||||
json j = i;
|
||||
@ -680,7 +680,7 @@ TEST_CASE("MessagePack")
|
||||
65536u, 77777u, 1048576u, 4294967295u
|
||||
})
|
||||
{
|
||||
CAPTURE(i)
|
||||
CAPTURE(i);
|
||||
|
||||
// create JSON value with unsigned integer number
|
||||
json j = i;
|
||||
@ -722,7 +722,7 @@ TEST_CASE("MessagePack")
|
||||
4294967296LU, 18446744073709551615LU
|
||||
})
|
||||
{
|
||||
CAPTURE(i)
|
||||
CAPTURE(i);
|
||||
|
||||
// create JSON value with unsigned integer number
|
||||
json j = i;
|
||||
@ -836,7 +836,7 @@ TEST_CASE("MessagePack")
|
||||
|
||||
for (size_t N = 0; N < first_bytes.size(); ++N)
|
||||
{
|
||||
CAPTURE(N)
|
||||
CAPTURE(N);
|
||||
|
||||
// create JSON value with string containing of N * 'x'
|
||||
const auto s = std::string(N, 'x');
|
||||
@ -873,7 +873,7 @@ TEST_CASE("MessagePack")
|
||||
{
|
||||
for (size_t N = 32; N <= 255; ++N)
|
||||
{
|
||||
CAPTURE(N)
|
||||
CAPTURE(N);
|
||||
|
||||
// create JSON value with string containing of N * 'x'
|
||||
const auto s = std::string(N, 'x');
|
||||
@ -908,7 +908,7 @@ TEST_CASE("MessagePack")
|
||||
256u, 999u, 1025u, 3333u, 2048u, 65535u
|
||||
})
|
||||
{
|
||||
CAPTURE(N)
|
||||
CAPTURE(N);
|
||||
|
||||
// create JSON value with string containing of N * 'x'
|
||||
const auto s = std::string(N, 'x');
|
||||
@ -941,7 +941,7 @@ TEST_CASE("MessagePack")
|
||||
65536u, 77777u, 1048576u
|
||||
})
|
||||
{
|
||||
CAPTURE(N)
|
||||
CAPTURE(N);
|
||||
|
||||
// create JSON value with string containing of N * 'x'
|
||||
const auto s = std::string(N, 'x');
|
||||
@ -1050,7 +1050,7 @@ TEST_CASE("MessagePack")
|
||||
CHECK(result.size() == expected.size());
|
||||
for (size_t i = 0; i < expected.size(); ++i)
|
||||
{
|
||||
CAPTURE(i)
|
||||
CAPTURE(i);
|
||||
CHECK(result[i] == expected[i]);
|
||||
}
|
||||
|
||||
@ -1163,7 +1163,7 @@ TEST_CASE("MessagePack")
|
||||
{
|
||||
for (size_t N = 0; N <= 0xFF; ++N)
|
||||
{
|
||||
CAPTURE(N)
|
||||
CAPTURE(N);
|
||||
|
||||
// create JSON value with byte array containing of N * 'x'
|
||||
const auto s = std::vector<uint8_t>(N, 'x');
|
||||
@ -1238,7 +1238,7 @@ TEST_CASE("MessagePack")
|
||||
256u, 999u, 1025u, 3333u, 2048u, 65535u
|
||||
})
|
||||
{
|
||||
CAPTURE(N)
|
||||
CAPTURE(N);
|
||||
|
||||
// create JSON value with string containing of N * 'x'
|
||||
const auto s = std::vector<uint8_t>(N, 'x');
|
||||
@ -1274,7 +1274,7 @@ TEST_CASE("MessagePack")
|
||||
65536u, 77777u, 1048576u
|
||||
})
|
||||
{
|
||||
CAPTURE(N)
|
||||
CAPTURE(N);
|
||||
|
||||
// create JSON value with string containing of 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)
|
||||
{
|
||||
CAPTURE(N)
|
||||
CAPTURE(N);
|
||||
|
||||
// create JSON value with byte array containing of N * 'x'
|
||||
const auto s = std::vector<uint8_t>(N, 'x');
|
||||
@ -1350,7 +1350,7 @@ TEST_CASE("MessagePack")
|
||||
256u, 999u, 1025u, 3333u, 2048u, 65535u
|
||||
})
|
||||
{
|
||||
CAPTURE(N)
|
||||
CAPTURE(N);
|
||||
|
||||
// create JSON value with string containing of N * 'x'
|
||||
const auto s = std::vector<std::uint8_t>(N, 'x');
|
||||
@ -1383,7 +1383,7 @@ TEST_CASE("MessagePack")
|
||||
65536u, 77777u, 1048576u
|
||||
})
|
||||
{
|
||||
CAPTURE(N)
|
||||
CAPTURE(N);
|
||||
|
||||
// create JSON value with string containing of 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});
|
||||
json j = json::from_msgpack(given);
|
||||
CHECK(j.get<double>() == Approx(25.0000019073486));
|
||||
CHECK(j.get<double>() == Catch::Approx(25.0000019073486));
|
||||
}
|
||||
|
||||
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"
|
||||
})
|
||||
{
|
||||
CAPTURE(filename)
|
||||
CAPTURE(filename);
|
||||
|
||||
SECTION(filename + ": std::vector<uint8_t>")
|
||||
{
|
||||
INFO_WITH_TEMP(filename + ": std::vector<uint8_t>");
|
||||
// parse JSON file
|
||||
std::ifstream f_json(filename);
|
||||
json j1 = json::parse(f_json);
|
||||
@ -1829,8 +1829,8 @@ TEST_CASE("MessagePack roundtrips" * doctest::skip())
|
||||
CHECK(j1 == j2);
|
||||
}
|
||||
|
||||
SECTION(filename + ": std::ifstream")
|
||||
{
|
||||
INFO_WITH_TEMP(filename + ": std::ifstream");
|
||||
// parse JSON file
|
||||
std::ifstream f_json(filename);
|
||||
json j1 = json::parse(f_json);
|
||||
@ -1844,8 +1844,8 @@ TEST_CASE("MessagePack roundtrips" * doctest::skip())
|
||||
CHECK(j1 == j2);
|
||||
}
|
||||
|
||||
SECTION(filename + ": uint8_t* and size")
|
||||
{
|
||||
INFO_WITH_TEMP(filename + ": uint8_t* and size");
|
||||
// parse JSON file
|
||||
std::ifstream f_json(filename);
|
||||
json j1 = json::parse(f_json);
|
||||
@ -1859,8 +1859,8 @@ TEST_CASE("MessagePack roundtrips" * doctest::skip())
|
||||
CHECK(j1 == j2);
|
||||
}
|
||||
|
||||
SECTION(filename + ": output to output adapters")
|
||||
{
|
||||
INFO_WITH_TEMP(filename + ": output to output adapters");
|
||||
// parse JSON file
|
||||
std::ifstream f_json(filename);
|
||||
json j1 = json::parse(f_json);
|
||||
@ -1870,8 +1870,8 @@ TEST_CASE("MessagePack roundtrips" * doctest::skip())
|
||||
|
||||
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;
|
||||
json::to_msgpack(j1, vec);
|
||||
CHECK(vec == packed);
|
||||
|
||||
@ -100,4 +100,4 @@ TEST_CASE("runtime checks")
|
||||
}
|
||||
}
|
||||
|
||||
DOCTEST_GCC_SUPPRESS_WARNING_POP
|
||||
//DOCTEST_GCC_SUPPRESS_WARNING_POP
|
||||
|
||||
@ -390,15 +390,15 @@ TEST_CASE("pointer access")
|
||||
// check if pointers are returned correctly
|
||||
test_type* 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*>();
|
||||
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>();
|
||||
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(value.get_ptr<json::object_t*>() == nullptr);
|
||||
@ -419,15 +419,15 @@ TEST_CASE("pointer access")
|
||||
// check if pointers are returned correctly
|
||||
test_type* 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*>();
|
||||
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>();
|
||||
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(value.get_ptr<const json::object_t*>() == nullptr);
|
||||
|
||||
@ -43,10 +43,10 @@ using nlohmann::json;
|
||||
#include <iomanip>
|
||||
|
||||
// local variable is initialized but not referenced
|
||||
DOCTEST_MSVC_SUPPRESS_WARNING_PUSH
|
||||
DOCTEST_MSVC_SUPPRESS_WARNING(4189)
|
||||
//DOCTEST_MSVC_SUPPRESS_WARNING_PUSH
|
||||
//DOCTEST_MSVC_SUPPRESS_WARNING(4189)
|
||||
|
||||
TEST_CASE("README" * doctest::skip())
|
||||
TEST_CASE("README", "[.]")
|
||||
{
|
||||
{
|
||||
// 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
|
||||
|
||||
@ -264,7 +264,7 @@ TEST_CASE("regression tests 1")
|
||||
int number{j["Number"]};
|
||||
CHECK(number == 100);
|
||||
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")
|
||||
@ -645,7 +645,7 @@ TEST_CASE("regression tests 1")
|
||||
TEST_DATA_DIRECTORY "/regression/working_file.json"
|
||||
})
|
||||
{
|
||||
CAPTURE(filename)
|
||||
CAPTURE(filename);
|
||||
json j;
|
||||
std::ifstream f(filename);
|
||||
CHECK_NOTHROW(f >> j);
|
||||
@ -662,7 +662,7 @@ TEST_CASE("regression tests 1")
|
||||
TEST_DATA_DIRECTORY "/regression/small_signed_ints.json"
|
||||
})
|
||||
{
|
||||
CAPTURE(filename)
|
||||
CAPTURE(filename);
|
||||
json j;
|
||||
std::ifstream f(filename);
|
||||
CHECK_NOTHROW(f >> j);
|
||||
@ -679,7 +679,7 @@ TEST_CASE("regression tests 1")
|
||||
SECTION("issue #329 - serialized value not always can be parsed")
|
||||
{
|
||||
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"),
|
||||
"[json.exception.out_of_range.406] number overflow parsing '22e2222'");
|
||||
}
|
||||
@ -688,7 +688,7 @@ TEST_CASE("regression tests 1")
|
||||
{
|
||||
auto check_roundtrip = [](double number)
|
||||
{
|
||||
CAPTURE(number)
|
||||
CAPTURE(number);
|
||||
|
||||
json j = number;
|
||||
CHECK(j.is_number_float());
|
||||
@ -746,7 +746,7 @@ TEST_CASE("regression tests 1")
|
||||
{
|
||||
std::ifstream f("file_not_found.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");
|
||||
}
|
||||
|
||||
@ -761,7 +761,7 @@ TEST_CASE("regression tests 1")
|
||||
// ss is not at EOF; this yielded an error before the fix
|
||||
// (threw basic_string::append). No, it should just throw
|
||||
// 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,
|
||||
"[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;
|
||||
json j;
|
||||
CHECK_THROWS_AS(ss >> j, json::parse_error&);
|
||||
CHECK_THROWS_AS(ss >> j, json::parse_error);
|
||||
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");
|
||||
}
|
||||
@ -782,7 +782,7 @@ TEST_CASE("regression tests 1")
|
||||
std::stringstream ss;
|
||||
ss << " ";
|
||||
json j;
|
||||
CHECK_THROWS_AS(ss >> j, json::parse_error&);
|
||||
CHECK_THROWS_AS(ss >> j, json::parse_error);
|
||||
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");
|
||||
}
|
||||
@ -795,7 +795,7 @@ TEST_CASE("regression tests 1")
|
||||
CHECK_NOTHROW(ss >> j);
|
||||
CHECK(j == 111);
|
||||
|
||||
CHECK_THROWS_AS(ss >> j, json::parse_error&);
|
||||
CHECK_THROWS_AS(ss >> j, json::parse_error);
|
||||
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");
|
||||
}
|
||||
@ -808,7 +808,7 @@ TEST_CASE("regression tests 1")
|
||||
CHECK_NOTHROW(ss >> j);
|
||||
CHECK(j == 222);
|
||||
|
||||
CHECK_THROWS_AS(ss >> j, json::parse_error&);
|
||||
CHECK_THROWS_AS(ss >> j, json::parse_error);
|
||||
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");
|
||||
}
|
||||
@ -821,7 +821,7 @@ TEST_CASE("regression tests 1")
|
||||
CHECK_NOTHROW(ss >> j);
|
||||
CHECK(j == 333);
|
||||
|
||||
CHECK_THROWS_AS(ss >> j, json::parse_error&);
|
||||
CHECK_THROWS_AS(ss >> j, json::parse_error);
|
||||
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");
|
||||
}
|
||||
@ -838,7 +838,7 @@ TEST_CASE("regression tests 1")
|
||||
CHECK_NOTHROW(ss >> j);
|
||||
CHECK(j == 333);
|
||||
|
||||
CHECK_THROWS_AS(ss >> j, json::parse_error&);
|
||||
CHECK_THROWS_AS(ss >> j, json::parse_error);
|
||||
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");
|
||||
}
|
||||
@ -857,7 +857,7 @@ TEST_CASE("regression tests 1")
|
||||
CHECK_NOTHROW(ss >> j);
|
||||
CHECK(j == "");
|
||||
|
||||
CHECK_THROWS_AS(ss >> j, json::parse_error&);
|
||||
CHECK_THROWS_AS(ss >> j, json::parse_error);
|
||||
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");
|
||||
}
|
||||
@ -872,7 +872,7 @@ TEST_CASE("regression tests 1")
|
||||
CHECK_NOTHROW(ss >> j);
|
||||
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,
|
||||
"[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;
|
||||
while (stream.peek() != EOF)
|
||||
{
|
||||
CAPTURE(i)
|
||||
CAPTURE(i);
|
||||
CHECK_NOTHROW(stream >> val);
|
||||
|
||||
CHECK(i < 2);
|
||||
@ -943,7 +943,7 @@ TEST_CASE("regression tests 1")
|
||||
// original test case
|
||||
std::vector<uint8_t> vec {0x65, 0xf5, 0x0a, 0x48, 0x21};
|
||||
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),
|
||||
"[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
|
||||
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),
|
||||
"[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
|
||||
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),
|
||||
"[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)
|
||||
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),
|
||||
"[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)
|
||||
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),
|
||||
"[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)
|
||||
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),
|
||||
"[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
|
||||
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),
|
||||
"[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));
|
||||
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
|
||||
@ -1018,15 +1018,15 @@ TEST_CASE("regression tests 1")
|
||||
})
|
||||
{
|
||||
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
|
||||
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),
|
||||
"[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),
|
||||
"[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)
|
||||
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),
|
||||
"[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)
|
||||
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),
|
||||
"[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)
|
||||
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),
|
||||
"[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 _;
|
||||
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),
|
||||
"[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)
|
||||
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),
|
||||
"[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)
|
||||
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),
|
||||
"[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)
|
||||
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),
|
||||
"[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 _;
|
||||
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),
|
||||
"[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,
|
||||
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),
|
||||
"[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'};
|
||||
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")
|
||||
@ -1200,9 +1200,9 @@ TEST_CASE("regression tests 1")
|
||||
};
|
||||
|
||||
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_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");
|
||||
}
|
||||
|
||||
@ -1214,9 +1214,9 @@ TEST_CASE("regression tests 1")
|
||||
};
|
||||
|
||||
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_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");
|
||||
}
|
||||
|
||||
@ -1228,9 +1228,9 @@ TEST_CASE("regression tests 1")
|
||||
};
|
||||
|
||||
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_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");
|
||||
}
|
||||
}
|
||||
@ -1311,7 +1311,7 @@ TEST_CASE("regression tests 1")
|
||||
{
|
||||
json _;
|
||||
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
|
||||
@ -1380,7 +1380,7 @@ TEST_CASE("regression tests 1")
|
||||
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>>(),
|
||||
"[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::string key1_str(reinterpret_cast<char*>(key1.data()));
|
||||
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");
|
||||
}
|
||||
|
||||
@ -1480,7 +1480,7 @@ TEST_CASE("regression tests 1")
|
||||
auto p1 = R"([{"op": "move",
|
||||
"from": "/one/two/three",
|
||||
"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",
|
||||
"from": "/one/two/three",
|
||||
@ -1491,7 +1491,7 @@ TEST_CASE("regression tests 1")
|
||||
auto p3 = R"([{"op": "copy",
|
||||
"from": "/one/two/three",
|
||||
"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",
|
||||
"from": "/one/two/three",
|
||||
@ -1519,12 +1519,12 @@ TEST_CASE("regression tests 1")
|
||||
{
|
||||
json _;
|
||||
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),
|
||||
// "[json.exception.out_of_range.408] excessive array size: 8658170730974374167");
|
||||
|
||||
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),
|
||||
// "[json.exception.out_of_range.408] excessive object size: 8658170730974374167");
|
||||
}
|
||||
@ -1588,7 +1588,7 @@ TEST_CASE("regression tests, exceptions dependent")
|
||||
json 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());
|
||||
}
|
||||
}
|
||||
|
||||
@ -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")
|
||||
{
|
||||
constexpr auto minimum = (std::numeric_limits<T>::min)();
|
||||
constexpr auto minimum = (std::numeric_limits<TestType>::min)();
|
||||
json j = minimum;
|
||||
CHECK(j.dump() == std::to_string(minimum));
|
||||
}
|
||||
|
||||
SECTION("maximum")
|
||||
{
|
||||
constexpr auto maximum = (std::numeric_limits<T>::max)();
|
||||
constexpr auto maximum = (std::numeric_limits<TestType>::max)();
|
||||
json j = maximum;
|
||||
CHECK(j.dump() == std::to_string(maximum));
|
||||
}
|
||||
|
||||
@ -131,7 +131,7 @@ TEST_CASE("compliance tests from nativejson-benchmark")
|
||||
{
|
||||
CAPTURE(json_string);
|
||||
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);
|
||||
@ -261,8 +261,8 @@ TEST_CASE("compliance tests from nativejson-benchmark")
|
||||
{
|
||||
auto TEST_STRING = [](const std::string & json_string, const std::string & expected)
|
||||
{
|
||||
CAPTURE(json_string)
|
||||
CAPTURE(expected)
|
||||
CAPTURE(json_string);
|
||||
CAPTURE(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
|
||||
})
|
||||
{
|
||||
CAPTURE(filename)
|
||||
CAPTURE(filename);
|
||||
std::ifstream f(filename);
|
||||
std::string json_string( (std::istreambuf_iterator<char>(f) ),
|
||||
(std::istreambuf_iterator<char>()) );
|
||||
|
||||
CAPTURE(json_string)
|
||||
CAPTURE(json_string);
|
||||
json j = json::parse(json_string);
|
||||
CHECK(j.dump() == json_string);
|
||||
}
|
||||
@ -597,7 +597,7 @@ TEST_CASE("nst's JSONTestSuite")
|
||||
}
|
||||
)
|
||||
{
|
||||
CAPTURE(filename)
|
||||
CAPTURE(filename);
|
||||
std::ifstream f(filename);
|
||||
json j;
|
||||
CHECK_NOTHROW(f >> j);
|
||||
@ -806,7 +806,7 @@ TEST_CASE("nst's JSONTestSuite")
|
||||
}
|
||||
)
|
||||
{
|
||||
CAPTURE(filename)
|
||||
CAPTURE(filename);
|
||||
std::ifstream f(filename);
|
||||
json _;
|
||||
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);
|
||||
json j;
|
||||
CHECK_NOTHROW(f >> j);
|
||||
@ -862,7 +862,7 @@ TEST_CASE("nst's JSONTestSuite")
|
||||
}
|
||||
)
|
||||
{
|
||||
CAPTURE(filename)
|
||||
CAPTURE(filename);
|
||||
std::ifstream f(filename);
|
||||
json j;
|
||||
CHECK_NOTHROW(f >> j);
|
||||
@ -882,7 +882,7 @@ TEST_CASE("nst's JSONTestSuite")
|
||||
}
|
||||
)
|
||||
{
|
||||
CAPTURE(filename)
|
||||
CAPTURE(filename);
|
||||
std::ifstream f(filename);
|
||||
json j;
|
||||
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);
|
||||
json j;
|
||||
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);
|
||||
json _;
|
||||
CHECK_NOTHROW(_ = json::parse(f));
|
||||
@ -1226,7 +1226,7 @@ TEST_CASE("nst's JSONTestSuite (2)")
|
||||
}
|
||||
)
|
||||
{
|
||||
CAPTURE(filename)
|
||||
CAPTURE(filename);
|
||||
std::ifstream f(filename);
|
||||
json _;
|
||||
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);
|
||||
CHECK(!json::accept(f));
|
||||
}
|
||||
@ -1292,7 +1292,7 @@ TEST_CASE("nst's JSONTestSuite (2)")
|
||||
}
|
||||
)
|
||||
{
|
||||
CAPTURE(filename)
|
||||
CAPTURE(filename);
|
||||
std::ifstream f(filename);
|
||||
json _;
|
||||
CHECK_NOTHROW(_ = json::parse(f));
|
||||
@ -1404,7 +1404,7 @@ TEST_CASE("Big List of Naughty Strings")
|
||||
}
|
||||
|
||||
// check roundtrip
|
||||
CAPTURE(line)
|
||||
CAPTURE(line);
|
||||
json j = json::parse(line);
|
||||
CHECK(j.dump() == line);
|
||||
}
|
||||
|
||||
@ -187,7 +187,7 @@ TEST_CASE("UBJSON")
|
||||
numbers.push_back(-2147483649LL);
|
||||
for (auto i : numbers)
|
||||
{
|
||||
CAPTURE(i)
|
||||
CAPTURE(i);
|
||||
|
||||
// create JSON value with integer number
|
||||
json j = i;
|
||||
@ -242,7 +242,7 @@ TEST_CASE("UBJSON")
|
||||
numbers.push_back(-2147483647 - 1); // https://stackoverflow.com/a/29356002/266378
|
||||
for (auto i : numbers)
|
||||
{
|
||||
CAPTURE(i)
|
||||
CAPTURE(i);
|
||||
|
||||
// create JSON value with integer number
|
||||
json j = i;
|
||||
@ -281,7 +281,7 @@ TEST_CASE("UBJSON")
|
||||
{
|
||||
for (int32_t i = -32768; i <= -129; ++i)
|
||||
{
|
||||
CAPTURE(i)
|
||||
CAPTURE(i);
|
||||
|
||||
// create JSON value with integer number
|
||||
json j = i;
|
||||
@ -335,7 +335,7 @@ TEST_CASE("UBJSON")
|
||||
{
|
||||
for (auto i = -128; i <= -1; ++i)
|
||||
{
|
||||
CAPTURE(i)
|
||||
CAPTURE(i);
|
||||
|
||||
// create JSON value with integer number
|
||||
json j = i;
|
||||
@ -367,7 +367,7 @@ TEST_CASE("UBJSON")
|
||||
{
|
||||
for (size_t i = 0; i <= 127; ++i)
|
||||
{
|
||||
CAPTURE(i)
|
||||
CAPTURE(i);
|
||||
|
||||
// create JSON value with integer number
|
||||
json j = -1;
|
||||
@ -400,7 +400,7 @@ TEST_CASE("UBJSON")
|
||||
{
|
||||
for (size_t i = 128; i <= 255; ++i)
|
||||
{
|
||||
CAPTURE(i)
|
||||
CAPTURE(i);
|
||||
|
||||
// create JSON value with integer number
|
||||
json j = -1;
|
||||
@ -433,7 +433,7 @@ TEST_CASE("UBJSON")
|
||||
{
|
||||
for (size_t i = 256; i <= 32767; ++i)
|
||||
{
|
||||
CAPTURE(i)
|
||||
CAPTURE(i);
|
||||
|
||||
// create JSON value with integer number
|
||||
json j = -1;
|
||||
@ -471,7 +471,7 @@ TEST_CASE("UBJSON")
|
||||
65536u, 77777u, 1048576u
|
||||
})
|
||||
{
|
||||
CAPTURE(i)
|
||||
CAPTURE(i);
|
||||
|
||||
// create JSON value with integer number
|
||||
json j = -1;
|
||||
@ -512,7 +512,7 @@ TEST_CASE("UBJSON")
|
||||
std::vector<uint64_t> v = {2147483648ul, 9223372036854775807ul};
|
||||
for (uint64_t i : v)
|
||||
{
|
||||
CAPTURE(i)
|
||||
CAPTURE(i);
|
||||
|
||||
// create JSON value with integer number
|
||||
json j = -1;
|
||||
@ -563,7 +563,7 @@ TEST_CASE("UBJSON")
|
||||
{
|
||||
for (size_t i = 0; i <= 127; ++i)
|
||||
{
|
||||
CAPTURE(i)
|
||||
CAPTURE(i);
|
||||
|
||||
// create JSON value with unsigned integer number
|
||||
json j = i;
|
||||
@ -596,7 +596,7 @@ TEST_CASE("UBJSON")
|
||||
{
|
||||
for (size_t i = 128; i <= 255; ++i)
|
||||
{
|
||||
CAPTURE(i)
|
||||
CAPTURE(i);
|
||||
|
||||
// create JSON value with unsigned integer number
|
||||
json j = i;
|
||||
@ -629,7 +629,7 @@ TEST_CASE("UBJSON")
|
||||
{
|
||||
for (size_t i = 256; i <= 32767; ++i)
|
||||
{
|
||||
CAPTURE(i)
|
||||
CAPTURE(i);
|
||||
|
||||
// create JSON value with unsigned integer number
|
||||
json j = i;
|
||||
@ -666,7 +666,7 @@ TEST_CASE("UBJSON")
|
||||
65536u, 77777u, 1048576u
|
||||
})
|
||||
{
|
||||
CAPTURE(i)
|
||||
CAPTURE(i);
|
||||
|
||||
// create JSON value with unsigned integer number
|
||||
json j = i;
|
||||
@ -706,7 +706,7 @@ TEST_CASE("UBJSON")
|
||||
std::vector<uint64_t> v = {2147483648ul, 9223372036854775807ul};
|
||||
for (uint64_t i : v)
|
||||
{
|
||||
CAPTURE(i)
|
||||
CAPTURE(i);
|
||||
|
||||
// create JSON value with integer number
|
||||
json j = i;
|
||||
@ -837,7 +837,7 @@ TEST_CASE("UBJSON")
|
||||
{
|
||||
for (size_t N = 0; N <= 127; ++N)
|
||||
{
|
||||
CAPTURE(N)
|
||||
CAPTURE(N);
|
||||
|
||||
// create JSON value with string containing of N * 'x'
|
||||
const auto s = std::string(N, 'x');
|
||||
@ -873,7 +873,7 @@ TEST_CASE("UBJSON")
|
||||
{
|
||||
for (size_t N = 128; N <= 255; ++N)
|
||||
{
|
||||
CAPTURE(N)
|
||||
CAPTURE(N);
|
||||
|
||||
// create JSON value with string containing of N * 'x'
|
||||
const auto s = std::string(N, 'x');
|
||||
@ -909,7 +909,7 @@ TEST_CASE("UBJSON")
|
||||
256u, 999u, 1025u, 3333u, 2048u, 32767u
|
||||
})
|
||||
{
|
||||
CAPTURE(N)
|
||||
CAPTURE(N);
|
||||
|
||||
// create JSON value with string containing of N * 'x'
|
||||
const auto s = std::string(N, 'x');
|
||||
@ -943,7 +943,7 @@ TEST_CASE("UBJSON")
|
||||
65536u, 77777u, 1048576u
|
||||
})
|
||||
{
|
||||
CAPTURE(N)
|
||||
CAPTURE(N);
|
||||
|
||||
// create JSON value with string containing of 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)
|
||||
{
|
||||
CAPTURE(N)
|
||||
CAPTURE(N);
|
||||
|
||||
// create JSON value with byte array containing of 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)
|
||||
{
|
||||
CAPTURE(N)
|
||||
CAPTURE(N);
|
||||
|
||||
// create JSON value with byte array containing of 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
|
||||
})
|
||||
{
|
||||
CAPTURE(N)
|
||||
CAPTURE(N);
|
||||
|
||||
// create JSON value with byte array containing of N * 'x'
|
||||
const auto s = std::vector<std::uint8_t>(N, 'x');
|
||||
@ -1107,7 +1107,7 @@ TEST_CASE("UBJSON")
|
||||
32768u, 77777u, 1048576u
|
||||
})
|
||||
{
|
||||
CAPTURE(N)
|
||||
CAPTURE(N);
|
||||
|
||||
// create JSON value with byte array containing of N * 'x'
|
||||
const auto s = std::vector<std::uint8_t>(N, 'x');
|
||||
@ -1595,7 +1595,7 @@ TEST_CASE("UBJSON")
|
||||
SECTION("strict mode")
|
||||
{
|
||||
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),
|
||||
"[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};
|
||||
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;
|
||||
nlohmann::detail::json_sax_dom_callback_parser<json> scp(j, [](int /*unused*/, json::parse_event_t /*unused*/, const json& /*unused*/)
|
||||
{
|
||||
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")
|
||||
{
|
||||
std::vector<uint8_t> v_ubjson = {'{', '$', 'Z', '#', 'L', 0x78, 0x28, 0x00, 0x68, 0x28, 0x69, 0x69, 0x17};
|
||||
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;
|
||||
nlohmann::detail::json_sax_dom_callback_parser<json> scp(j, [](int /*unused*/, json::parse_event_t /*unused*/, const json& /*unused*/)
|
||||
{
|
||||
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")
|
||||
{
|
||||
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>()),
|
||||
"[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'};
|
||||
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");
|
||||
}
|
||||
|
||||
@ -1839,7 +1839,7 @@ TEST_CASE("UBJSON")
|
||||
{
|
||||
std::vector<uint8_t> v = {'C', 130};
|
||||
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");
|
||||
}
|
||||
}
|
||||
@ -1850,7 +1850,7 @@ TEST_CASE("UBJSON")
|
||||
{
|
||||
std::vector<uint8_t> v = {'S'};
|
||||
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");
|
||||
}
|
||||
|
||||
@ -1858,7 +1858,7 @@ TEST_CASE("UBJSON")
|
||||
{
|
||||
std::vector<uint8_t> v = {'S', '1', 'a'};
|
||||
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");
|
||||
}
|
||||
}
|
||||
@ -1869,7 +1869,7 @@ TEST_CASE("UBJSON")
|
||||
{
|
||||
std::vector<uint8_t> v = {'[', '$', 'i', 2};
|
||||
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");
|
||||
}
|
||||
}
|
||||
@ -1878,17 +1878,17 @@ TEST_CASE("UBJSON")
|
||||
{
|
||||
std::vector<uint8_t> vS = {'S'};
|
||||
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(json::from_ubjson(vS, true, false).is_discarded());
|
||||
|
||||
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(json::from_ubjson(v, true, false).is_discarded());
|
||||
|
||||
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(json::from_ubjson(vC, true, false).is_discarded());
|
||||
}
|
||||
@ -1897,32 +1897,32 @@ TEST_CASE("UBJSON")
|
||||
{
|
||||
std::vector<uint8_t> vU = {'[', '#', 'U'};
|
||||
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(json::from_ubjson(vU, true, false).is_discarded());
|
||||
|
||||
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(json::from_ubjson(vi, true, false).is_discarded());
|
||||
|
||||
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(json::from_ubjson(vI, true, false).is_discarded());
|
||||
|
||||
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(json::from_ubjson(vl, true, false).is_discarded());
|
||||
|
||||
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(json::from_ubjson(vL, true, false).is_discarded());
|
||||
|
||||
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(json::from_ubjson(v0, true, false).is_discarded());
|
||||
}
|
||||
@ -1931,17 +1931,17 @@ TEST_CASE("UBJSON")
|
||||
{
|
||||
std::vector<uint8_t> v0 = {'[', '$'};
|
||||
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(json::from_ubjson(v0, true, false).is_discarded());
|
||||
|
||||
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(json::from_ubjson(vi, true, false).is_discarded());
|
||||
|
||||
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(json::from_ubjson(vT, true, false).is_discarded());
|
||||
}
|
||||
@ -1950,17 +1950,17 @@ TEST_CASE("UBJSON")
|
||||
{
|
||||
std::vector<uint8_t> vST = {'[', '$', 'i', '#', 'i', 2, 1};
|
||||
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(json::from_ubjson(vST, true, false).is_discarded());
|
||||
|
||||
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(json::from_ubjson(vS, true, false).is_discarded());
|
||||
|
||||
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(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};
|
||||
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(json::from_ubjson(vST, true, false).is_discarded());
|
||||
|
||||
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(json::from_ubjson(vT, true, false).is_discarded());
|
||||
|
||||
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(json::from_ubjson(vS, true, false).is_discarded());
|
||||
|
||||
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(json::from_ubjson(v, true, false).is_discarded());
|
||||
|
||||
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(json::from_ubjson(v2, true, false).is_discarded());
|
||||
|
||||
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(json::from_ubjson(v3, true, false).is_discarded());
|
||||
|
||||
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(json::from_ubjson(vST1, true, false).is_discarded());
|
||||
|
||||
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(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"
|
||||
})
|
||||
{
|
||||
CAPTURE(filename)
|
||||
CAPTURE(filename);
|
||||
|
||||
{
|
||||
INFO_WITH_TEMP(filename + ": std::vector<uint8_t>");
|
||||
|
||||
@ -242,7 +242,7 @@ static void from_json(const nlohmann::json& j, contact_book& cb)
|
||||
}
|
||||
} // namespace udt
|
||||
|
||||
TEST_CASE("basic usage" * doctest::test_suite("udt"))
|
||||
TEST_CASE("basic usage", "[udt]")
|
||||
{
|
||||
|
||||
// a bit narcissistic maybe :) ?
|
||||
@ -400,7 +400,7 @@ struct adl_serializer<udt::legacy_type>
|
||||
};
|
||||
} // namespace nlohmann
|
||||
|
||||
TEST_CASE("adl_serializer specialization" * doctest::test_suite("udt"))
|
||||
TEST_CASE("adl_serializer specialization", "[udt]")
|
||||
{
|
||||
SECTION("partial specialization")
|
||||
{
|
||||
@ -476,7 +476,7 @@ struct adl_serializer<std::vector<float>>
|
||||
};
|
||||
} // 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};
|
||||
CHECK(j.dump() == R"("hijacked!")");
|
||||
@ -515,7 +515,7 @@ struct adl_serializer<std::unique_ptr<T>>
|
||||
};
|
||||
} // namespace nlohmann
|
||||
|
||||
TEST_CASE("Non-copyable types" * doctest::test_suite("udt"))
|
||||
TEST_CASE("Non-copyable types", "[udt]")
|
||||
{
|
||||
SECTION("to_json")
|
||||
{
|
||||
@ -656,7 +656,7 @@ static std::ostream& operator<<(std::ostream& os, small_pod l)
|
||||
}
|
||||
} // namespace udt
|
||||
|
||||
TEST_CASE("custom serializer for pods" * doctest::test_suite("udt"))
|
||||
TEST_CASE("custom serializer for pods", "[udt]")
|
||||
{
|
||||
using custom_json =
|
||||
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};
|
||||
|
||||
@ -808,7 +808,7 @@ template <typename T>
|
||||
struct is_constructible_patched<T, decltype(void(json(std::declval<T>())))> : std::true_type {};
|
||||
} // 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, "");
|
||||
}
|
||||
|
||||
@ -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_public_alphabet)
|
||||
{
|
||||
SECTION("alphabet")
|
||||
{
|
||||
{
|
||||
T obj1;
|
||||
TestType obj1;
|
||||
nlohmann::json j = obj1; //via json object
|
||||
T obj2;
|
||||
TestType obj2;
|
||||
j.get_to(obj2);
|
||||
bool ok = (obj1 == obj2);
|
||||
CHECK(ok);
|
||||
}
|
||||
|
||||
{
|
||||
T obj1;
|
||||
TestType obj1;
|
||||
nlohmann::json j1 = obj1; //via json string
|
||||
std::string s = j1.dump();
|
||||
nlohmann::json j2 = nlohmann::json::parse(s);
|
||||
T obj2;
|
||||
TestType obj2;
|
||||
j2.get_to(obj2);
|
||||
bool ok = (obj1 == obj2);
|
||||
CHECK(ok);
|
||||
}
|
||||
|
||||
{
|
||||
T obj1;
|
||||
TestType obj1;
|
||||
nlohmann::json j1 = obj1; //via msgpack
|
||||
std::vector<uint8_t> buf = nlohmann::json::to_msgpack(j1);
|
||||
nlohmann::json j2 = nlohmann::json::from_msgpack(buf);
|
||||
T obj2;
|
||||
TestType obj2;
|
||||
j2.get_to(obj2);
|
||||
bool ok = (obj1 == obj2);
|
||||
CHECK(ok);
|
||||
}
|
||||
|
||||
{
|
||||
T obj1;
|
||||
TestType obj1;
|
||||
nlohmann::json j1 = obj1; //via bson
|
||||
std::vector<uint8_t> buf = nlohmann::json::to_bson(j1);
|
||||
nlohmann::json j2 = nlohmann::json::from_bson(buf);
|
||||
T obj2;
|
||||
TestType obj2;
|
||||
j2.get_to(obj2);
|
||||
bool ok = (obj1 == obj2);
|
||||
CHECK(ok);
|
||||
}
|
||||
|
||||
{
|
||||
T obj1;
|
||||
TestType obj1;
|
||||
nlohmann::json j1 = obj1; //via cbor
|
||||
std::vector<uint8_t> buf = nlohmann::json::to_cbor(j1);
|
||||
nlohmann::json j2 = nlohmann::json::from_cbor(buf);
|
||||
T obj2;
|
||||
TestType obj2;
|
||||
j2.get_to(obj2);
|
||||
bool ok = (obj1 == obj2);
|
||||
CHECK(ok);
|
||||
}
|
||||
|
||||
{
|
||||
T obj1;
|
||||
TestType obj1;
|
||||
nlohmann::json j1 = obj1; //via ubjson
|
||||
std::vector<uint8_t> buf = nlohmann::json::to_ubjson(j1);
|
||||
nlohmann::json j2 = nlohmann::json::from_ubjson(buf);
|
||||
T obj2;
|
||||
TestType obj2;
|
||||
j2.get_to(obj2);
|
||||
bool ok = (obj1 == obj2);
|
||||
CHECK(ok);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user