🔨 added user-defined exceptions 401-402

This commit is contained in:
Niels Lohmann 2017-03-05 22:56:39 +01:00
parent 491c9780a7
commit 60da36aee2
No known key found for this signature in database
GPG key ID: 7F3CEA63AE251B69
5 changed files with 75 additions and 60 deletions

View file

@ -63,11 +63,13 @@ TEST_CASE("element access 1")
SECTION("access outside bounds")
{
CHECK_THROWS_AS(j.at(8), std::out_of_range);
CHECK_THROWS_AS(j_const.at(8), std::out_of_range);
CHECK_THROWS_AS(j.at(8), json::out_of_range);
CHECK_THROWS_AS(j_const.at(8), json::out_of_range);
CHECK_THROWS_WITH(j.at(8), "array index 8 is out of range");
CHECK_THROWS_WITH(j_const.at(8), "array index 8 is out of range");
CHECK_THROWS_WITH(j.at(8),
"[json.exception.out_of_range.401] array index 8 is out of range");
CHECK_THROWS_WITH(j_const.at(8),
"[json.exception.out_of_range.401] array index 8 is out of range");
}
SECTION("access on non-array type")
@ -311,8 +313,9 @@ TEST_CASE("element access 1")
}
{
json jarray = {1, 1u, true, nullptr, "string", 42.23, json::object(), {1, 2, 3}};
CHECK_THROWS_AS(jarray.erase(8), std::out_of_range);
CHECK_THROWS_WITH(jarray.erase(8), "array index 8 is out of range");
CHECK_THROWS_AS(jarray.erase(8), json::out_of_range);
CHECK_THROWS_WITH(jarray.erase(8),
"[json.exception.out_of_range.401] array index 8 is out of range");
}
}

View file

@ -741,8 +741,9 @@ TEST_CASE("JSON patch")
{
json j = {1, 2};
json patch = {{{"op", "add"}, {"path", "/4"}, {"value", 4}}};
CHECK_THROWS_AS(j.patch(patch), std::out_of_range);
CHECK_THROWS_WITH(j.patch(patch), "array index 4 is out of range");
CHECK_THROWS_AS(j.patch(patch), json::out_of_range);
CHECK_THROWS_WITH(j.patch(patch),
"[json.exception.out_of_range.401] array index 4 is out of range");
}
}
@ -770,8 +771,9 @@ TEST_CASE("JSON patch")
{
json j = {1, 2, 3};
json patch = {{{"op", "remove"}, {"path", "/17"}}};
CHECK_THROWS_AS(j.patch(patch), std::out_of_range);
CHECK_THROWS_WITH(j.patch(patch), "array index 17 is out of range");
CHECK_THROWS_AS(j.patch(patch), json::out_of_range);
CHECK_THROWS_WITH(j.patch(patch),
"[json.exception.out_of_range.401] array index 17 is out of range");
}
SECTION("nonexisting target location (object)")
@ -824,8 +826,9 @@ TEST_CASE("JSON patch")
{
json j = {1, 2, 3};
json patch = {{{"op", "replace"}, {"path", "/17"}, {"value", 19}}};
CHECK_THROWS_AS(j.patch(patch), std::out_of_range);
CHECK_THROWS_WITH(j.patch(patch), "array index 17 is out of range");
CHECK_THROWS_AS(j.patch(patch), json::out_of_range);
CHECK_THROWS_WITH(j.patch(patch),
"[json.exception.out_of_range.401] array index 17 is out of range");
}
SECTION("nonexisting target location (object)")
@ -879,8 +882,9 @@ TEST_CASE("JSON patch")
{
json j = {1, 2, 3};
json patch = {{{"op", "move"}, {"path", "/0"}, {"from", "/5"}}};
CHECK_THROWS_AS(j.patch(patch), std::out_of_range);
CHECK_THROWS_WITH(j.patch(patch), "array index 5 is out of range");
CHECK_THROWS_AS(j.patch(patch), json::out_of_range);
CHECK_THROWS_WITH(j.patch(patch),
"[json.exception.out_of_range.401] array index 5 is out of range");
}
SECTION("nonexisting from location (object)")
@ -934,8 +938,9 @@ TEST_CASE("JSON patch")
{
json j = {1, 2, 3};
json patch = {{{"op", "copy"}, {"path", "/0"}, {"from", "/5"}}};
CHECK_THROWS_AS(j.patch(patch), std::out_of_range);
CHECK_THROWS_WITH(j.patch(patch), "array index 5 is out of range");
CHECK_THROWS_AS(j.patch(patch), json::out_of_range);
CHECK_THROWS_WITH(j.patch(patch),
"[json.exception.out_of_range.401] array index 5 is out of range");
}
SECTION("nonexisting from location (object)")

View file

@ -271,14 +271,17 @@ 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], std::out_of_range);
CHECK_THROWS_WITH(j_const["/-"_json_pointer], "array index '-' (3) is 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");
// error when using "-" with at
CHECK_THROWS_AS(j.at("/-"_json_pointer), std::out_of_range);
CHECK_THROWS_WITH(j.at("/-"_json_pointer), "array index '-' (7) is out of range");
CHECK_THROWS_AS(j_const.at("/-"_json_pointer), std::out_of_range);
CHECK_THROWS_WITH(j_const.at("/-"_json_pointer), "array index '-' (3) is 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_WITH(j_const.at("/-"_json_pointer),
"[json.exception.out_of_range.402] array index '-' (3) is out of range");
}
SECTION("const access")
@ -291,18 +294,22 @@ TEST_CASE("JSON pointers")
CHECK(j["/2"_json_pointer] == j[2]);
// assign to nonexisting index
CHECK_THROWS_AS(j.at("/3"_json_pointer), std::out_of_range);
CHECK_THROWS_WITH(j.at("/3"_json_pointer), "array index 3 is 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");
// assign to nonexisting index (with gap)
CHECK_THROWS_AS(j.at("/5"_json_pointer), std::out_of_range);
CHECK_THROWS_WITH(j.at("/5"_json_pointer), "array index 5 is 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");
// assign to "-"
CHECK_THROWS_AS(j["/-"_json_pointer], std::out_of_range);
CHECK_THROWS_WITH(j["/-"_json_pointer], "array index '-' (3) is out of range");
CHECK_THROWS_AS(j.at("/-"_json_pointer), std::out_of_range);
CHECK_THROWS_WITH(j.at("/-"_json_pointer), "array index '-' (3) is 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_WITH(j.at("/-"_json_pointer),
"[json.exception.out_of_range.402] array index '-' (3) is out of range");
}
}