Refactor unit tests to use more convenient doctest assertion macros (#3393)

* Add missing check

* Refactor assertions in unit-algorithms.cpp

* Refactor assertions in unit-bson.cpp

* Refactor assertions in unit-cbor.cpp

* Refactor assertions in unit-class_const_iterator.cpp

* Refactor assertions in unit-class_iterator.cpp

* Refactor assertions in unit-class_parser.cpp

* Refactor assertions in unit-constructor1.cpp

* Refactor assertions in unit-convenience.cpp

* Refactor assertions in unit-conversions.cpp

* Refactor assertions in unit-deserialization.cpp

* Refactor assertions in unit-element_access1.cpp

* Refactor assertions in unit-element_access2.cpp

* Refactor assertions in unit-iterators1.cpp

* Refactor assertions in unit-iterators2.cpp

* Refactor assertions in unit-json_patch.cpp

* Refactor assertions in unit-json_pointer.cpp

* Refactor assertions in unit-modifiers.cpp

* Refactor assertions in unit-msgpack.cpp

* Refactor assertions in unit-reference_access.cpp

* Refactor assertions in unit-regression1.cpp

* Refactor assertions in unit-serialization.cpp

* Refactor assertions in unit-ubjson.cpp

* Refactor assertions in unit-unicode1.cpp

* Apply formatting
This commit is contained in:
Krzysiek Karbowiak
2022-03-24 15:55:35 +01:00
committed by GitHub
parent ad103e5b45
commit ce35256825
23 changed files with 1239 additions and 2374 deletions

View File

@@ -94,43 +94,27 @@ TEST_CASE("value conversion")
SECTION("exception in case of a non-object type")
{
CHECK_THROWS_AS(json(json::value_t::null).get<json::object_t>(),
json::type_error&);
CHECK_THROWS_AS(json(json::value_t::array).get<json::object_t>(),
json::type_error&);
CHECK_THROWS_AS(json(json::value_t::string).get<json::object_t>(),
json::type_error&);
CHECK_THROWS_AS(json(json::value_t::boolean).get<json::object_t>(),
json::type_error&);
CHECK_THROWS_AS(json(json::value_t::number_integer).get<json::object_t>(),
json::type_error&);
CHECK_THROWS_AS(
json(json::value_t::number_unsigned).get<json::object_t>(),
json::type_error&);
CHECK_THROWS_AS(json(json::value_t::number_float).get<json::object_t>(),
json::type_error&);
CHECK_THROWS_WITH(
CHECK_THROWS_WITH_AS(
json(json::value_t::null).get<json::object_t>(),
"[json.exception.type_error.302] type must be object, but is null");
CHECK_THROWS_WITH(
"[json.exception.type_error.302] type must be object, but is null", json::type_error&);
CHECK_THROWS_WITH_AS(
json(json::value_t::array).get<json::object_t>(),
"[json.exception.type_error.302] type must be object, but is array");
CHECK_THROWS_WITH(
"[json.exception.type_error.302] type must be object, but is array", json::type_error&);
CHECK_THROWS_WITH_AS(
json(json::value_t::string).get<json::object_t>(),
"[json.exception.type_error.302] type must be object, but is string");
CHECK_THROWS_WITH(json(json::value_t::boolean).get<json::object_t>(),
"[json.exception.type_error.302] type must be object, "
"but is boolean");
CHECK_THROWS_WITH(
"[json.exception.type_error.302] type must be object, but is string", json::type_error&);
CHECK_THROWS_WITH_AS(json(json::value_t::boolean).get<json::object_t>(),
"[json.exception.type_error.302] type must be object, "
"but is boolean", json::type_error&);
CHECK_THROWS_WITH_AS(
json(json::value_t::number_integer).get<json::object_t>(),
"[json.exception.type_error.302] type must be object, but is number");
CHECK_THROWS_WITH(
"[json.exception.type_error.302] type must be object, but is number", json::type_error&);
CHECK_THROWS_WITH_AS(
json(json::value_t::number_unsigned).get<json::object_t>(),
"[json.exception.type_error.302] type must be object, but is number");
CHECK_THROWS_WITH(
"[json.exception.type_error.302] type must be object, but is number", json::type_error&);
CHECK_THROWS_WITH_AS(
json(json::value_t::number_float).get<json::object_t>(),
"[json.exception.type_error.302] type must be object, but is number");
"[json.exception.type_error.302] type must be object, but is number", json::type_error&);
}
}
@@ -248,11 +232,9 @@ TEST_CASE("value conversion")
std::forward_list<json> a = j.get<std::forward_list<json>>();
CHECK(json(a) == j);
CHECK_THROWS_AS(json(json::value_t::null).get<std::forward_list<json>>(),
json::type_error&);
CHECK_THROWS_WITH(
CHECK_THROWS_WITH_AS(
json(json::value_t::null).get<std::forward_list<json>>(),
"[json.exception.type_error.302] type must be array, but is null");
"[json.exception.type_error.302] type must be array, but is null", json::type_error&);
}
SECTION("std::vector<json>")
@@ -260,11 +242,9 @@ TEST_CASE("value conversion")
std::vector<json> a = j.get<std::vector<json>>();
CHECK(json(a) == j);
CHECK_THROWS_AS(json(json::value_t::null).get<std::vector<json>>(),
json::type_error&);
CHECK_THROWS_WITH(
CHECK_THROWS_WITH_AS(
json(json::value_t::null).get<std::vector<json>>(),
"[json.exception.type_error.302] type must be array, but is null");
"[json.exception.type_error.302] type must be array, but is null", json::type_error&);
#if !defined(JSON_NOEXCEPTION)
SECTION("reserve is called on containers that supports it")
@@ -299,45 +279,30 @@ TEST_CASE("value conversion")
SECTION("exception in case of a non-array type")
{
CHECK_THROWS_AS(json(json::value_t::null).get<json::array_t>(),
json::type_error&);
CHECK_THROWS_AS(json(json::value_t::object).get<json::array_t>(),
json::type_error&);
CHECK_THROWS_AS(json(json::value_t::string).get<json::array_t>(),
json::type_error&);
CHECK_THROWS_AS(json(json::value_t::boolean).get<json::array_t>(),
json::type_error&);
CHECK_THROWS_AS(json(json::value_t::number_integer).get<json::array_t>(),
json::type_error&);
CHECK_THROWS_AS(json(json::value_t::number_unsigned).get<json::array_t>(),
json::type_error&);
CHECK_THROWS_AS(json(json::value_t::number_float).get<json::array_t>(),
json::type_error&);
CHECK_THROWS_WITH(
CHECK_THROWS_WITH_AS(
json(json::value_t::object).get<std::vector<int>>(),
"[json.exception.type_error.302] type must be array, but is object");
CHECK_THROWS_WITH(
"[json.exception.type_error.302] type must be array, but is object", json::type_error&);
CHECK_THROWS_WITH_AS(
json(json::value_t::null).get<json::array_t>(),
"[json.exception.type_error.302] type must be array, but is null");
CHECK_THROWS_WITH(
"[json.exception.type_error.302] type must be array, but is null", json::type_error&);
CHECK_THROWS_WITH_AS(
json(json::value_t::object).get<json::array_t>(),
"[json.exception.type_error.302] type must be array, but is object");
CHECK_THROWS_WITH(
"[json.exception.type_error.302] type must be array, but is object", json::type_error&);
CHECK_THROWS_WITH_AS(
json(json::value_t::string).get<json::array_t>(),
"[json.exception.type_error.302] type must be array, but is string");
CHECK_THROWS_WITH(
"[json.exception.type_error.302] type must be array, but is string", json::type_error&);
CHECK_THROWS_WITH_AS(
json(json::value_t::boolean).get<json::array_t>(),
"[json.exception.type_error.302] type must be array, but is boolean");
CHECK_THROWS_WITH(
"[json.exception.type_error.302] type must be array, but is boolean", json::type_error&);
CHECK_THROWS_WITH_AS(
json(json::value_t::number_integer).get<json::array_t>(),
"[json.exception.type_error.302] type must be array, but is number");
CHECK_THROWS_WITH(
"[json.exception.type_error.302] type must be array, but is number", json::type_error&);
CHECK_THROWS_WITH_AS(
json(json::value_t::number_unsigned).get<json::array_t>(),
"[json.exception.type_error.302] type must be array, but is number");
CHECK_THROWS_WITH(
"[json.exception.type_error.302] type must be array, but is number", json::type_error&);
CHECK_THROWS_WITH_AS(
json(json::value_t::number_float).get<json::array_t>(),
"[json.exception.type_error.302] type must be array, but is number");
"[json.exception.type_error.302] type must be array, but is number", json::type_error&);
}
}
@@ -465,70 +430,46 @@ TEST_CASE("value conversion")
SECTION("exception in case of a non-string type")
{
CHECK_THROWS_AS(json(json::value_t::null).get<json::string_t>(),
json::type_error&);
CHECK_THROWS_AS(json(json::value_t::object).get<json::string_t>(),
json::type_error&);
CHECK_THROWS_AS(json(json::value_t::array).get<json::string_t>(),
json::type_error&);
CHECK_THROWS_AS(json(json::value_t::boolean).get<json::string_t>(),
json::type_error&);
CHECK_THROWS_AS(json(json::value_t::number_integer).get<json::string_t>(),
json::type_error&);
CHECK_THROWS_AS(
json(json::value_t::number_unsigned).get<json::string_t>(),
json::type_error&);
CHECK_THROWS_AS(json(json::value_t::number_float).get<json::string_t>(),
json::type_error&);
CHECK_THROWS_WITH(
CHECK_THROWS_WITH_AS(
json(json::value_t::null).get<json::string_t>(),
"[json.exception.type_error.302] type must be string, but is null");
CHECK_THROWS_WITH(
"[json.exception.type_error.302] type must be string, but is null", json::type_error&);
CHECK_THROWS_WITH_AS(
json(json::value_t::object).get<json::string_t>(),
"[json.exception.type_error.302] type must be string, but is object");
CHECK_THROWS_WITH(
"[json.exception.type_error.302] type must be string, but is object", json::type_error&);
CHECK_THROWS_WITH_AS(
json(json::value_t::array).get<json::string_t>(),
"[json.exception.type_error.302] type must be string, but is array");
CHECK_THROWS_WITH(json(json::value_t::boolean).get<json::string_t>(),
"[json.exception.type_error.302] type must be string, "
"but is boolean");
CHECK_THROWS_WITH(
"[json.exception.type_error.302] type must be string, but is array", json::type_error&);
CHECK_THROWS_WITH_AS(json(json::value_t::boolean).get<json::string_t>(),
"[json.exception.type_error.302] type must be string, "
"but is boolean", json::type_error&);
CHECK_THROWS_WITH_AS(
json(json::value_t::number_integer).get<json::string_t>(),
"[json.exception.type_error.302] type must be string, but is number");
CHECK_THROWS_WITH(
"[json.exception.type_error.302] type must be string, but is number", json::type_error&);
CHECK_THROWS_WITH_AS(
json(json::value_t::number_unsigned).get<json::string_t>(),
"[json.exception.type_error.302] type must be string, but is number");
CHECK_THROWS_WITH(
"[json.exception.type_error.302] type must be string, but is number", json::type_error&);
CHECK_THROWS_WITH_AS(
json(json::value_t::number_float).get<json::string_t>(),
"[json.exception.type_error.302] type must be string, but is number");
"[json.exception.type_error.302] type must be string, but is number", json::type_error&);
}
#if defined(JSON_HAS_CPP_17)
SECTION("exception in case of a non-string type using string_view")
{
CHECK_THROWS_AS(json(json::value_t::null).get<std::string_view>(), json::type_error&);
CHECK_THROWS_AS(json(json::value_t::object).get<std::string_view>(), json::type_error&);
CHECK_THROWS_AS(json(json::value_t::array).get<std::string_view>(), json::type_error&);
CHECK_THROWS_AS(json(json::value_t::boolean).get<std::string_view>(), json::type_error&);
CHECK_THROWS_AS(json(json::value_t::number_integer).get<std::string_view>(), json::type_error&);
CHECK_THROWS_AS(json(json::value_t::number_unsigned).get<std::string_view>(), json::type_error&);
CHECK_THROWS_AS(json(json::value_t::number_float).get<std::string_view>(), json::type_error&);
CHECK_THROWS_WITH(json(json::value_t::null).get<std::string_view>(),
"[json.exception.type_error.302] type must be string, but is null");
CHECK_THROWS_WITH(json(json::value_t::object).get<std::string_view>(),
"[json.exception.type_error.302] type must be string, but is object");
CHECK_THROWS_WITH(json(json::value_t::array).get<std::string_view>(),
"[json.exception.type_error.302] type must be string, but is array");
CHECK_THROWS_WITH(json(json::value_t::boolean).get<std::string_view>(),
"[json.exception.type_error.302] type must be string, but is boolean");
CHECK_THROWS_WITH(json(json::value_t::number_integer).get<std::string_view>(),
"[json.exception.type_error.302] type must be string, but is number");
CHECK_THROWS_WITH(json(json::value_t::number_unsigned).get<std::string_view>(),
"[json.exception.type_error.302] type must be string, but is number");
CHECK_THROWS_WITH(json(json::value_t::number_float).get<std::string_view>(),
"[json.exception.type_error.302] type must be string, but is number");
CHECK_THROWS_WITH_AS(json(json::value_t::null).get<std::string_view>(),
"[json.exception.type_error.302] type must be string, but is null", json::type_error&);
CHECK_THROWS_WITH_AS(json(json::value_t::object).get<std::string_view>(),
"[json.exception.type_error.302] type must be string, but is object", json::type_error&);
CHECK_THROWS_WITH_AS(json(json::value_t::array).get<std::string_view>(),
"[json.exception.type_error.302] type must be string, but is array", json::type_error&);
CHECK_THROWS_WITH_AS(json(json::value_t::boolean).get<std::string_view>(),
"[json.exception.type_error.302] type must be string, but is boolean", json::type_error&);
CHECK_THROWS_WITH_AS(json(json::value_t::number_integer).get<std::string_view>(),
"[json.exception.type_error.302] type must be string, but is number", json::type_error&);
CHECK_THROWS_WITH_AS(json(json::value_t::number_unsigned).get<std::string_view>(),
"[json.exception.type_error.302] type must be string, but is number", json::type_error&);
CHECK_THROWS_WITH_AS(json(json::value_t::number_float).get<std::string_view>(),
"[json.exception.type_error.302] type must be string, but is number", json::type_error&);
}
#endif
}
@@ -570,29 +511,20 @@ TEST_CASE("value conversion")
auto n2 = j.get<std::nullptr_t>();
CHECK(n2 == n);
CHECK_THROWS_AS(json(json::value_t::string).get<std::nullptr_t>(), json::type_error&);
CHECK_THROWS_AS(json(json::value_t::object).get<std::nullptr_t>(), json::type_error&);
CHECK_THROWS_AS(json(json::value_t::array).get<std::nullptr_t>(), json::type_error&);
CHECK_THROWS_AS(json(json::value_t::boolean).get<std::nullptr_t>(), json::type_error&);
CHECK_THROWS_AS(json(json::value_t::number_integer).get<std::nullptr_t>(), json::type_error&);
CHECK_THROWS_AS(json(json::value_t::number_unsigned).get<std::nullptr_t>(), json::type_error&);
CHECK_THROWS_AS(json(json::value_t::number_float).get<std::nullptr_t>(), json::type_error&);
CHECK_THROWS_WITH(json(json::value_t::string).get<std::nullptr_t>(),
"[json.exception.type_error.302] type must be null, but is string");
CHECK_THROWS_WITH(json(json::value_t::object).get<std::nullptr_t>(),
"[json.exception.type_error.302] type must be null, but is object");
CHECK_THROWS_WITH(json(json::value_t::array).get<std::nullptr_t>(),
"[json.exception.type_error.302] type must be null, but is array");
CHECK_THROWS_WITH(json(json::value_t::boolean).get<std::nullptr_t>(),
"[json.exception.type_error.302] type must be null, but is boolean");
CHECK_THROWS_WITH(json(json::value_t::number_integer).get<std::nullptr_t>(),
"[json.exception.type_error.302] type must be null, but is number");
CHECK_THROWS_WITH(json(json::value_t::number_unsigned).get<std::nullptr_t>(),
"[json.exception.type_error.302] type must be null, but is number");
CHECK_THROWS_WITH(json(json::value_t::number_float).get<std::nullptr_t>(),
"[json.exception.type_error.302] type must be null, but is number");
CHECK_THROWS_WITH_AS(json(json::value_t::string).get<std::nullptr_t>(),
"[json.exception.type_error.302] type must be null, but is string", json::type_error&);
CHECK_THROWS_WITH_AS(json(json::value_t::object).get<std::nullptr_t>(),
"[json.exception.type_error.302] type must be null, but is object", json::type_error&);
CHECK_THROWS_WITH_AS(json(json::value_t::array).get<std::nullptr_t>(),
"[json.exception.type_error.302] type must be null, but is array", json::type_error&);
CHECK_THROWS_WITH_AS(json(json::value_t::boolean).get<std::nullptr_t>(),
"[json.exception.type_error.302] type must be null, but is boolean", json::type_error&);
CHECK_THROWS_WITH_AS(json(json::value_t::number_integer).get<std::nullptr_t>(),
"[json.exception.type_error.302] type must be null, but is number", json::type_error&);
CHECK_THROWS_WITH_AS(json(json::value_t::number_unsigned).get<std::nullptr_t>(),
"[json.exception.type_error.302] type must be null, but is number", json::type_error&);
CHECK_THROWS_WITH_AS(json(json::value_t::number_float).get<std::nullptr_t>(),
"[json.exception.type_error.302] type must be null, but is number", json::type_error&);
}
#if JSON_USE_IMPLICIT_CONVERSIONS
@@ -648,49 +580,33 @@ TEST_CASE("value conversion")
SECTION("exception in case of a non-number type")
{
CHECK_THROWS_AS(json(json::value_t::null).get<json::boolean_t>(),
json::type_error&);
CHECK_THROWS_AS(json(json::value_t::object).get<json::boolean_t>(),
json::type_error&);
CHECK_THROWS_AS(json(json::value_t::array).get<json::boolean_t>(),
json::type_error&);
CHECK_THROWS_AS(json(json::value_t::string).get<json::boolean_t>(),
json::type_error&);
CHECK_THROWS_AS(json(json::value_t::string).get<uint8_t>(),
json::type_error&);
CHECK_THROWS_AS(
json(json::value_t::number_integer).get<json::boolean_t>(),
json::type_error&);
CHECK_THROWS_AS(
json(json::value_t::number_unsigned).get<json::boolean_t>(),
json::type_error&);
CHECK_THROWS_AS(json(json::value_t::number_float).get<json::boolean_t>(),
json::type_error&);
CHECK_THROWS_WITH(
CHECK_THROWS_WITH_AS(
json(json::value_t::null).get<json::boolean_t>(),
"[json.exception.type_error.302] type must be boolean, but is null");
CHECK_THROWS_WITH(json(json::value_t::object).get<json::boolean_t>(),
"[json.exception.type_error.302] type must be boolean, "
"but is object");
CHECK_THROWS_WITH(
"[json.exception.type_error.302] type must be boolean, but is null", json::type_error&);
CHECK_THROWS_WITH_AS(json(json::value_t::object).get<json::boolean_t>(),
"[json.exception.type_error.302] type must be boolean, "
"but is object", json::type_error&);
CHECK_THROWS_WITH_AS(
json(json::value_t::array).get<json::boolean_t>(),
"[json.exception.type_error.302] type must be boolean, but is array");
CHECK_THROWS_WITH(json(json::value_t::string).get<json::boolean_t>(),
"[json.exception.type_error.302] type must be boolean, "
"but is string");
CHECK_THROWS_WITH(
"[json.exception.type_error.302] type must be boolean, but is array", json::type_error&);
CHECK_THROWS_WITH_AS(json(json::value_t::string).get<json::boolean_t>(),
"[json.exception.type_error.302] type must be boolean, "
"but is string", json::type_error&);
CHECK_THROWS_WITH_AS(
json(json::value_t::number_integer).get<json::boolean_t>(),
"[json.exception.type_error.302] type must be boolean, but is "
"number");
CHECK_THROWS_WITH(
"number", json::type_error&);
CHECK_THROWS_WITH_AS(
json(json::value_t::number_unsigned).get<json::boolean_t>(),
"[json.exception.type_error.302] type must be boolean, but is "
"number");
CHECK_THROWS_WITH(
"number", json::type_error&);
CHECK_THROWS_WITH_AS(
json(json::value_t::number_float).get<json::boolean_t>(),
"[json.exception.type_error.302] type must be boolean, but is "
"number");
"number", json::type_error&);
}
}
@@ -927,34 +843,22 @@ TEST_CASE("value conversion")
SECTION("exception in case of a non-number type")
{
CHECK_THROWS_AS(json(json::value_t::null).get<json::number_integer_t>(),
json::type_error&);
CHECK_THROWS_AS(json(json::value_t::object).get<json::number_integer_t>(),
json::type_error&);
CHECK_THROWS_AS(json(json::value_t::array).get<json::number_integer_t>(),
json::type_error&);
CHECK_THROWS_AS(json(json::value_t::string).get<json::number_integer_t>(),
json::type_error&);
CHECK_THROWS_AS(
json(json::value_t::boolean).get<json::number_integer_t>(),
json::type_error&);
CHECK_THROWS_WITH(
CHECK_THROWS_WITH_AS(
json(json::value_t::null).get<json::number_integer_t>(),
"[json.exception.type_error.302] type must be number, but is null");
CHECK_THROWS_WITH(
"[json.exception.type_error.302] type must be number, but is null", json::type_error&);
CHECK_THROWS_WITH_AS(
json(json::value_t::object).get<json::number_integer_t>(),
"[json.exception.type_error.302] type must be number, but is object");
CHECK_THROWS_WITH(
"[json.exception.type_error.302] type must be number, but is object", json::type_error&);
CHECK_THROWS_WITH_AS(
json(json::value_t::array).get<json::number_integer_t>(),
"[json.exception.type_error.302] type must be number, but is array");
CHECK_THROWS_WITH(
"[json.exception.type_error.302] type must be number, but is array", json::type_error&);
CHECK_THROWS_WITH_AS(
json(json::value_t::string).get<json::number_integer_t>(),
"[json.exception.type_error.302] type must be number, but is string");
CHECK_THROWS_WITH(
"[json.exception.type_error.302] type must be number, but is string", json::type_error&);
CHECK_THROWS_WITH_AS(
json(json::value_t::boolean).get<json::number_integer_t>(),
"[json.exception.type_error.302] type must be number, but is "
"boolean");
"boolean", json::type_error&);
CHECK_NOTHROW(
json(json::value_t::number_float).get<json::number_integer_t>());
@@ -1202,33 +1106,22 @@ TEST_CASE("value conversion")
SECTION("exception in case of a non-string type")
{
CHECK_THROWS_AS(json(json::value_t::null).get<json::number_float_t>(),
json::type_error&);
CHECK_THROWS_AS(json(json::value_t::object).get<json::number_float_t>(),
json::type_error&);
CHECK_THROWS_AS(json(json::value_t::array).get<json::number_float_t>(),
json::type_error&);
CHECK_THROWS_AS(json(json::value_t::string).get<json::number_float_t>(),
json::type_error&);
CHECK_THROWS_AS(json(json::value_t::boolean).get<json::number_float_t>(),
json::type_error&);
CHECK_THROWS_WITH(
CHECK_THROWS_WITH_AS(
json(json::value_t::null).get<json::number_float_t>(),
"[json.exception.type_error.302] type must be number, but is null");
CHECK_THROWS_WITH(
"[json.exception.type_error.302] type must be number, but is null", json::type_error&);
CHECK_THROWS_WITH_AS(
json(json::value_t::object).get<json::number_float_t>(),
"[json.exception.type_error.302] type must be number, but is object");
CHECK_THROWS_WITH(
"[json.exception.type_error.302] type must be number, but is object", json::type_error&);
CHECK_THROWS_WITH_AS(
json(json::value_t::array).get<json::number_float_t>(),
"[json.exception.type_error.302] type must be number, but is array");
CHECK_THROWS_WITH(
"[json.exception.type_error.302] type must be number, but is array", json::type_error&);
CHECK_THROWS_WITH_AS(
json(json::value_t::string).get<json::number_float_t>(),
"[json.exception.type_error.302] type must be number, but is string");
CHECK_THROWS_WITH(
"[json.exception.type_error.302] type must be number, but is string", json::type_error&);
CHECK_THROWS_WITH_AS(
json(json::value_t::boolean).get<json::number_float_t>(),
"[json.exception.type_error.302] type must be number, but is "
"boolean");
"boolean", json::type_error&);
CHECK_NOTHROW(
json(json::value_t::number_integer).get<json::number_float_t>());
@@ -1443,11 +1336,9 @@ TEST_CASE("value conversion")
SECTION("exception in case of a non-object type")
{
CHECK_THROWS_AS((json().get<std::map<std::string, int>>()),
json::type_error&);
CHECK_THROWS_WITH(
CHECK_THROWS_WITH_AS(
(json().get<std::map<std::string, int>>()),
"[json.exception.type_error.302] type must be object, but is null");
"[json.exception.type_error.302] type must be object, but is null", json::type_error&);
}
}
@@ -1488,9 +1379,8 @@ TEST_CASE("value conversion")
SECTION("std::array is larger than JSON")
{
std::array<int, 6> arr6 = {{1, 2, 3, 4, 5, 6}};
CHECK_THROWS_AS(j1.get_to(arr6), json::out_of_range&);
CHECK_THROWS_WITH(j1.get_to(arr6), "[json.exception.out_of_range.401] "
"array index 4 is out of range");
CHECK_THROWS_WITH_AS(j1.get_to(arr6), "[json.exception.out_of_range.401] "
"array index 4 is out of range", json::out_of_range&);
}
SECTION("std::array is smaller than JSON")
@@ -1557,14 +1447,12 @@ TEST_CASE("value conversion")
json j7 = {0, 1, 2, 3};
json j8 = 2;
CHECK_THROWS_AS((j7.get<std::map<int, int>>()), json::type_error&);
CHECK_THROWS_AS((j8.get<std::map<int, int>>()), json::type_error&);
CHECK_THROWS_WITH((j7.get<std::map<int, int>>()),
"[json.exception.type_error.302] type must be array, "
"but is number");
CHECK_THROWS_WITH((j8.get<std::map<int, int>>()),
"[json.exception.type_error.302] type must be array, "
"but is number");
CHECK_THROWS_WITH_AS((j7.get<std::map<int, int>>()),
"[json.exception.type_error.302] type must be array, "
"but is number", json::type_error&);
CHECK_THROWS_WITH_AS((j8.get<std::map<int, int>>()),
"[json.exception.type_error.302] type must be array, "
"but is number", json::type_error&);
SECTION("superfluous entries")
{
@@ -1584,14 +1472,12 @@ TEST_CASE("value conversion")
json j7 = {0, 1, 2, 3};
json j8 = 2;
CHECK_THROWS_AS((j7.get<std::unordered_map<int, int>>()), json::type_error&);
CHECK_THROWS_AS((j8.get<std::unordered_map<int, int>>()), json::type_error&);
CHECK_THROWS_WITH((j7.get<std::unordered_map<int, int>>()),
"[json.exception.type_error.302] type must be array, "
"but is number");
CHECK_THROWS_WITH((j8.get<std::unordered_map<int, int>>()),
"[json.exception.type_error.302] type must be array, "
"but is number");
CHECK_THROWS_WITH_AS((j7.get<std::unordered_map<int, int>>()),
"[json.exception.type_error.302] type must be array, "
"but is number", json::type_error&);
CHECK_THROWS_WITH_AS((j8.get<std::unordered_map<int, int>>()),
"[json.exception.type_error.302] type must be array, "
"but is number", json::type_error&);
SECTION("superfluous entries")
{
@@ -1603,32 +1489,26 @@ TEST_CASE("value conversion")
SECTION("exception in case of a non-object type")
{
CHECK_THROWS_AS((json().get<std::list<int>>()), json::type_error&);
CHECK_THROWS_AS((json().get<std::vector<int>>()), json::type_error&);
CHECK_THROWS_AS((json().get<std::vector<json>>()), json::type_error&);
CHECK_THROWS_AS((json().get<std::list<json>>()), json::type_error&);
CHECK_THROWS_AS((json().get<std::valarray<int>>()), json::type_error&);
// does type really must be an array? or it rather must not be null?
// that's what I thought when other test like this one broke
CHECK_THROWS_WITH(
CHECK_THROWS_WITH_AS(
(json().get<std::list<int>>()),
"[json.exception.type_error.302] type must be array, but is null");
CHECK_THROWS_WITH(
"[json.exception.type_error.302] type must be array, but is null", json::type_error&);
CHECK_THROWS_WITH_AS(
(json().get<std::vector<int>>()),
"[json.exception.type_error.302] type must be array, but is null");
CHECK_THROWS_WITH(
"[json.exception.type_error.302] type must be array, but is null", json::type_error&);
CHECK_THROWS_WITH_AS(
(json().get<std::vector<json>>()),
"[json.exception.type_error.302] type must be array, but is null");
CHECK_THROWS_WITH(
"[json.exception.type_error.302] type must be array, but is null", json::type_error&);
CHECK_THROWS_WITH_AS(
(json().get<std::list<json>>()),
"[json.exception.type_error.302] type must be array, but is null");
CHECK_THROWS_WITH(
"[json.exception.type_error.302] type must be array, but is null", json::type_error&);
CHECK_THROWS_WITH_AS(
(json().get<std::valarray<int>>()),
"[json.exception.type_error.302] type must be array, but is null");
CHECK_THROWS_WITH(
"[json.exception.type_error.302] type must be array, but is null", json::type_error&);
CHECK_THROWS_WITH_AS(
(json().get<std::map<int, int>>()),
"[json.exception.type_error.302] type must be array, but is null");
"[json.exception.type_error.302] type must be array, but is null", json::type_error&);
}
}
}