Refactor assertions in unit-conversions.cpp
This commit is contained in:
parent
2b37ebb059
commit
8140466217
@ -101,43 +101,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 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");
|
||||
CHECK_THROWS_WITH(
|
||||
"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&);
|
||||
}
|
||||
}
|
||||
|
||||
@ -255,11 +239,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>")
|
||||
@ -267,11 +249,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")
|
||||
@ -306,45 +286,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&);
|
||||
}
|
||||
}
|
||||
|
||||
@ -472,70 +437,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 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");
|
||||
CHECK_THROWS_WITH(
|
||||
"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
|
||||
}
|
||||
@ -577,29 +518,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
|
||||
@ -655,49 +587,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 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");
|
||||
CHECK_THROWS_WITH(
|
||||
"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 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");
|
||||
CHECK_THROWS_WITH(
|
||||
"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&);
|
||||
}
|
||||
}
|
||||
|
||||
@ -934,34 +850,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>());
|
||||
@ -1209,33 +1113,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>());
|
||||
@ -1450,11 +1343,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&);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1495,9 +1386,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")
|
||||
@ -1564,14 +1454,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>>()),
|
||||
CHECK_THROWS_WITH_AS((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>>()),
|
||||
"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");
|
||||
"but is number", json::type_error&);
|
||||
|
||||
SECTION("superfluous entries")
|
||||
{
|
||||
@ -1591,14 +1479,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>>()),
|
||||
CHECK_THROWS_WITH_AS((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>>()),
|
||||
"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");
|
||||
"but is number", json::type_error&);
|
||||
|
||||
SECTION("superfluous entries")
|
||||
{
|
||||
@ -1610,32 +1496,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&);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user