mirror of
https://github.com/nlohmann/json.git
synced 2026-02-26 21:36:27 +00:00
🔨 added user-defined exceptions 303-304
This commit is contained in:
@@ -76,77 +76,77 @@ TEST_CASE("element access 1")
|
||||
{
|
||||
json j_nonarray(json::value_t::null);
|
||||
const json j_nonarray_const(j_nonarray);
|
||||
CHECK_THROWS_AS(j_nonarray.at(0), std::domain_error);
|
||||
CHECK_THROWS_AS(j_nonarray_const.at(0), std::domain_error);
|
||||
CHECK_THROWS_AS(j_nonarray.at(0), json::type_error);
|
||||
CHECK_THROWS_AS(j_nonarray_const.at(0), json::type_error);
|
||||
|
||||
CHECK_THROWS_WITH(j_nonarray.at(0), "cannot use at() with null");
|
||||
CHECK_THROWS_WITH(j_nonarray_const.at(0), "cannot use at() with null");
|
||||
CHECK_THROWS_WITH(j_nonarray.at(0), "[json.exception.type_error.304] cannot use at() with null");
|
||||
CHECK_THROWS_WITH(j_nonarray_const.at(0), "[json.exception.type_error.304] cannot use at() with null");
|
||||
}
|
||||
|
||||
SECTION("boolean")
|
||||
{
|
||||
json j_nonarray(json::value_t::boolean);
|
||||
const json j_nonarray_const(j_nonarray);
|
||||
CHECK_THROWS_AS(j_nonarray.at(0), std::domain_error);
|
||||
CHECK_THROWS_AS(j_nonarray_const.at(0), std::domain_error);
|
||||
CHECK_THROWS_AS(j_nonarray.at(0), json::type_error);
|
||||
CHECK_THROWS_AS(j_nonarray_const.at(0), json::type_error);
|
||||
|
||||
CHECK_THROWS_WITH(j_nonarray.at(0), "cannot use at() with boolean");
|
||||
CHECK_THROWS_WITH(j_nonarray_const.at(0), "cannot use at() with boolean");
|
||||
CHECK_THROWS_WITH(j_nonarray.at(0), "[json.exception.type_error.304] cannot use at() with boolean");
|
||||
CHECK_THROWS_WITH(j_nonarray_const.at(0), "[json.exception.type_error.304] cannot use at() with boolean");
|
||||
}
|
||||
|
||||
SECTION("string")
|
||||
{
|
||||
json j_nonarray(json::value_t::string);
|
||||
const json j_nonarray_const(j_nonarray);
|
||||
CHECK_THROWS_AS(j_nonarray.at(0), std::domain_error);
|
||||
CHECK_THROWS_AS(j_nonarray_const.at(0), std::domain_error);
|
||||
CHECK_THROWS_AS(j_nonarray.at(0), json::type_error);
|
||||
CHECK_THROWS_AS(j_nonarray_const.at(0), json::type_error);
|
||||
|
||||
CHECK_THROWS_WITH(j_nonarray.at(0), "cannot use at() with string");
|
||||
CHECK_THROWS_WITH(j_nonarray_const.at(0), "cannot use at() with string");
|
||||
CHECK_THROWS_WITH(j_nonarray.at(0), "[json.exception.type_error.304] cannot use at() with string");
|
||||
CHECK_THROWS_WITH(j_nonarray_const.at(0), "[json.exception.type_error.304] cannot use at() with string");
|
||||
}
|
||||
|
||||
SECTION("object")
|
||||
{
|
||||
json j_nonarray(json::value_t::object);
|
||||
const json j_nonarray_const(j_nonarray);
|
||||
CHECK_THROWS_AS(j_nonarray.at(0), std::domain_error);
|
||||
CHECK_THROWS_AS(j_nonarray_const.at(0), std::domain_error);
|
||||
CHECK_THROWS_AS(j_nonarray.at(0), json::type_error);
|
||||
CHECK_THROWS_AS(j_nonarray_const.at(0), json::type_error);
|
||||
|
||||
CHECK_THROWS_WITH(j_nonarray.at(0), "cannot use at() with object");
|
||||
CHECK_THROWS_WITH(j_nonarray_const.at(0), "cannot use at() with object");
|
||||
CHECK_THROWS_WITH(j_nonarray.at(0), "[json.exception.type_error.304] cannot use at() with object");
|
||||
CHECK_THROWS_WITH(j_nonarray_const.at(0), "[json.exception.type_error.304] cannot use at() with object");
|
||||
}
|
||||
|
||||
SECTION("number (integer)")
|
||||
{
|
||||
json j_nonarray(json::value_t::number_integer);
|
||||
const json j_nonarray_const(j_nonarray);
|
||||
CHECK_THROWS_AS(j_nonarray.at(0), std::domain_error);
|
||||
CHECK_THROWS_AS(j_nonarray_const.at(0), std::domain_error);
|
||||
CHECK_THROWS_AS(j_nonarray.at(0), json::type_error);
|
||||
CHECK_THROWS_AS(j_nonarray_const.at(0), json::type_error);
|
||||
|
||||
CHECK_THROWS_WITH(j_nonarray.at(0), "cannot use at() with number");
|
||||
CHECK_THROWS_WITH(j_nonarray_const.at(0), "cannot use at() with number");
|
||||
CHECK_THROWS_WITH(j_nonarray.at(0), "[json.exception.type_error.304] cannot use at() with number");
|
||||
CHECK_THROWS_WITH(j_nonarray_const.at(0), "[json.exception.type_error.304] cannot use at() with number");
|
||||
}
|
||||
|
||||
SECTION("number (unsigned)")
|
||||
{
|
||||
json j_nonarray(json::value_t::number_unsigned);
|
||||
const json j_nonarray_const(j_nonarray);
|
||||
CHECK_THROWS_AS(j_nonarray.at(0), std::domain_error);
|
||||
CHECK_THROWS_AS(j_nonarray_const.at(0), std::domain_error);
|
||||
CHECK_THROWS_AS(j_nonarray.at(0), json::type_error);
|
||||
CHECK_THROWS_AS(j_nonarray_const.at(0), json::type_error);
|
||||
|
||||
CHECK_THROWS_WITH(j_nonarray.at(0), "cannot use at() with number");
|
||||
CHECK_THROWS_WITH(j_nonarray_const.at(0), "cannot use at() with number");
|
||||
CHECK_THROWS_WITH(j_nonarray.at(0), "[json.exception.type_error.304] cannot use at() with number");
|
||||
CHECK_THROWS_WITH(j_nonarray_const.at(0), "[json.exception.type_error.304] cannot use at() with number");
|
||||
}
|
||||
|
||||
SECTION("number (floating-point)")
|
||||
{
|
||||
json j_nonarray(json::value_t::number_float);
|
||||
const json j_nonarray_const(j_nonarray);
|
||||
CHECK_THROWS_AS(j_nonarray.at(0), std::domain_error);
|
||||
CHECK_THROWS_AS(j_nonarray_const.at(0), std::domain_error);
|
||||
CHECK_THROWS_AS(j_nonarray.at(0), json::type_error);
|
||||
CHECK_THROWS_AS(j_nonarray_const.at(0), json::type_error);
|
||||
|
||||
CHECK_THROWS_WITH(j_nonarray.at(0), "cannot use at() with number");
|
||||
CHECK_THROWS_WITH(j_nonarray_const.at(0), "cannot use at() with number");
|
||||
CHECK_THROWS_WITH(j_nonarray.at(0), "[json.exception.type_error.304] cannot use at() with number");
|
||||
CHECK_THROWS_WITH(j_nonarray_const.at(0), "[json.exception.type_error.304] cannot use at() with number");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user