diff --git a/test/src/unit-element_access2.cpp b/test/src/unit-element_access2.cpp index 670458cd2..f28e26743 100644 --- a/test/src/unit-element_access2.cpp +++ b/test/src/unit-element_access2.cpp @@ -64,12 +64,8 @@ TEST_CASE("element access 2") SECTION("access outside bounds") { - CHECK_THROWS_AS(j.at("foo"), json::out_of_range&); - CHECK_THROWS_AS(j_const.at("foo"), json::out_of_range&); - CHECK_THROWS_WITH(j.at("foo"), - "[json.exception.out_of_range.403] key 'foo' not found"); - CHECK_THROWS_WITH(j_const.at("foo"), - "[json.exception.out_of_range.403] key 'foo' not found"); + CHECK_THROWS_WITH_AS(j.at("foo"), "[json.exception.out_of_range.403] key 'foo' not found", json::out_of_range&); + CHECK_THROWS_WITH_AS(j_const.at("foo"), "[json.exception.out_of_range.403] key 'foo' not found", json::out_of_range&); } SECTION("access on non-object type") @@ -78,70 +74,56 @@ TEST_CASE("element access 2") { json j_nonobject(json::value_t::null); const json j_nonobject_const(j_nonobject); - CHECK_THROWS_AS(j_nonobject.at("foo"), json::type_error&); - CHECK_THROWS_AS(j_nonobject_const.at("foo"), json::type_error&); - CHECK_THROWS_WITH(j_nonobject.at("foo"), "[json.exception.type_error.304] cannot use at() with null"); - CHECK_THROWS_WITH(j_nonobject_const.at("foo"), "[json.exception.type_error.304] cannot use at() with null"); + CHECK_THROWS_WITH_AS(j_nonobject.at("foo"), "[json.exception.type_error.304] cannot use at() with null", json::type_error&); + CHECK_THROWS_WITH_AS(j_nonobject_const.at("foo"), "[json.exception.type_error.304] cannot use at() with null", json::type_error&); } SECTION("boolean") { json j_nonobject(json::value_t::boolean); const json j_nonobject_const(j_nonobject); - CHECK_THROWS_AS(j_nonobject.at("foo"), json::type_error&); - CHECK_THROWS_AS(j_nonobject_const.at("foo"), json::type_error&); - CHECK_THROWS_WITH(j_nonobject.at("foo"), "[json.exception.type_error.304] cannot use at() with boolean"); - CHECK_THROWS_WITH(j_nonobject_const.at("foo"), "[json.exception.type_error.304] cannot use at() with boolean"); + CHECK_THROWS_WITH_AS(j_nonobject.at("foo"), "[json.exception.type_error.304] cannot use at() with boolean", json::type_error&); + CHECK_THROWS_WITH_AS(j_nonobject_const.at("foo"), "[json.exception.type_error.304] cannot use at() with boolean", json::type_error&); } SECTION("string") { json j_nonobject(json::value_t::string); const json j_nonobject_const(j_nonobject); - CHECK_THROWS_AS(j_nonobject.at("foo"), json::type_error&); - CHECK_THROWS_AS(j_nonobject_const.at("foo"), json::type_error&); - CHECK_THROWS_WITH(j_nonobject.at("foo"), "[json.exception.type_error.304] cannot use at() with string"); - CHECK_THROWS_WITH(j_nonobject_const.at("foo"), "[json.exception.type_error.304] cannot use at() with string"); + CHECK_THROWS_WITH_AS(j_nonobject.at("foo"), "[json.exception.type_error.304] cannot use at() with string", json::type_error&); + CHECK_THROWS_WITH_AS(j_nonobject_const.at("foo"), "[json.exception.type_error.304] cannot use at() with string", json::type_error&); } SECTION("array") { json j_nonobject(json::value_t::array); const json j_nonobject_const(j_nonobject); - CHECK_THROWS_AS(j_nonobject.at("foo"), json::type_error&); - CHECK_THROWS_AS(j_nonobject_const.at("foo"), json::type_error&); - CHECK_THROWS_WITH(j_nonobject.at("foo"), "[json.exception.type_error.304] cannot use at() with array"); - CHECK_THROWS_WITH(j_nonobject_const.at("foo"), "[json.exception.type_error.304] cannot use at() with array"); + CHECK_THROWS_WITH_AS(j_nonobject.at("foo"), "[json.exception.type_error.304] cannot use at() with array", json::type_error&); + CHECK_THROWS_WITH_AS(j_nonobject_const.at("foo"), "[json.exception.type_error.304] cannot use at() with array", json::type_error&); } SECTION("number (integer)") { json j_nonobject(json::value_t::number_integer); const json j_nonobject_const(j_nonobject); - CHECK_THROWS_AS(j_nonobject.at("foo"), json::type_error&); - CHECK_THROWS_AS(j_nonobject_const.at("foo"), json::type_error&); - CHECK_THROWS_WITH(j_nonobject.at("foo"), "[json.exception.type_error.304] cannot use at() with number"); - CHECK_THROWS_WITH(j_nonobject_const.at("foo"), "[json.exception.type_error.304] cannot use at() with number"); + CHECK_THROWS_WITH_AS(j_nonobject.at("foo"), "[json.exception.type_error.304] cannot use at() with number", json::type_error&); + CHECK_THROWS_WITH_AS(j_nonobject_const.at("foo"), "[json.exception.type_error.304] cannot use at() with number", json::type_error&); } SECTION("number (unsigned)") { json j_nonobject(json::value_t::number_unsigned); const json j_nonobject_const(j_nonobject); - CHECK_THROWS_AS(j_nonobject.at("foo"), json::type_error&); - CHECK_THROWS_AS(j_nonobject_const.at("foo"), json::type_error&); - CHECK_THROWS_WITH(j_nonobject.at("foo"), "[json.exception.type_error.304] cannot use at() with number"); - CHECK_THROWS_WITH(j_nonobject_const.at("foo"), "[json.exception.type_error.304] cannot use at() with number"); + CHECK_THROWS_WITH_AS(j_nonobject.at("foo"), "[json.exception.type_error.304] cannot use at() with number", json::type_error&); + CHECK_THROWS_WITH_AS(j_nonobject_const.at("foo"), "[json.exception.type_error.304] cannot use at() with number", json::type_error&); } SECTION("number (floating-point)") { json j_nonobject(json::value_t::number_float); const json j_nonobject_const(j_nonobject); - CHECK_THROWS_AS(j_nonobject.at("foo"), json::type_error&); - CHECK_THROWS_AS(j_nonobject_const.at("foo"), json::type_error&); - CHECK_THROWS_WITH(j_nonobject.at("foo"), "[json.exception.type_error.304] cannot use at() with number"); - CHECK_THROWS_WITH(j_nonobject_const.at("foo"), "[json.exception.type_error.304] cannot use at() with number"); + CHECK_THROWS_WITH_AS(j_nonobject.at("foo"), "[json.exception.type_error.304] cannot use at() with number", json::type_error&); + CHECK_THROWS_WITH_AS(j_nonobject_const.at("foo"), "[json.exception.type_error.304] cannot use at() with number", json::type_error&); } } } @@ -203,84 +185,56 @@ TEST_CASE("element access 2") { json j_nonobject(json::value_t::null); const json j_nonobject_const(json::value_t::null); - CHECK_THROWS_AS(j_nonobject.value("foo", 1), json::type_error&); - CHECK_THROWS_AS(j_nonobject_const.value("foo", 1), json::type_error&); - CHECK_THROWS_WITH(j_nonobject.value("foo", 1), - "[json.exception.type_error.306] cannot use value() with null"); - CHECK_THROWS_WITH(j_nonobject_const.value("foo", 1), - "[json.exception.type_error.306] cannot use value() with null"); + CHECK_THROWS_WITH_AS(j_nonobject.value("foo", 1), "[json.exception.type_error.306] cannot use value() with null", json::type_error&); + CHECK_THROWS_WITH_AS(j_nonobject_const.value("foo", 1), "[json.exception.type_error.306] cannot use value() with null", json::type_error&); } SECTION("boolean") { json j_nonobject(json::value_t::boolean); const json j_nonobject_const(json::value_t::boolean); - CHECK_THROWS_AS(j_nonobject.value("foo", 1), json::type_error&); - CHECK_THROWS_AS(j_nonobject_const.value("foo", 1), json::type_error&); - CHECK_THROWS_WITH(j_nonobject.value("foo", 1), - "[json.exception.type_error.306] cannot use value() with boolean"); - CHECK_THROWS_WITH(j_nonobject_const.value("foo", 1), - "[json.exception.type_error.306] cannot use value() with boolean"); + CHECK_THROWS_WITH_AS(j_nonobject.value("foo", 1), "[json.exception.type_error.306] cannot use value() with boolean", json::type_error&); + CHECK_THROWS_WITH_AS(j_nonobject_const.value("foo", 1), "[json.exception.type_error.306] cannot use value() with boolean", json::type_error&); } SECTION("string") { json j_nonobject(json::value_t::string); const json j_nonobject_const(json::value_t::string); - CHECK_THROWS_AS(j_nonobject.value("foo", 1), json::type_error&); - CHECK_THROWS_AS(j_nonobject_const.value("foo", 1), json::type_error&); - CHECK_THROWS_WITH(j_nonobject.value("foo", 1), - "[json.exception.type_error.306] cannot use value() with string"); - CHECK_THROWS_WITH(j_nonobject_const.value("foo", 1), - "[json.exception.type_error.306] cannot use value() with string"); + CHECK_THROWS_WITH_AS(j_nonobject.value("foo", 1), "[json.exception.type_error.306] cannot use value() with string", json::type_error&); + CHECK_THROWS_WITH_AS(j_nonobject_const.value("foo", 1), "[json.exception.type_error.306] cannot use value() with string", json::type_error&); } SECTION("array") { json j_nonobject(json::value_t::array); const json j_nonobject_const(json::value_t::array); - CHECK_THROWS_AS(j_nonobject.value("foo", 1), json::type_error&); - CHECK_THROWS_AS(j_nonobject_const.value("foo", 1), json::type_error&); - CHECK_THROWS_WITH(j_nonobject.value("foo", 1), - "[json.exception.type_error.306] cannot use value() with array"); - CHECK_THROWS_WITH(j_nonobject_const.value("foo", 1), - "[json.exception.type_error.306] cannot use value() with array"); + CHECK_THROWS_WITH_AS(j_nonobject.value("foo", 1), "[json.exception.type_error.306] cannot use value() with array", json::type_error&); + CHECK_THROWS_WITH_AS(j_nonobject_const.value("foo", 1), "[json.exception.type_error.306] cannot use value() with array", json::type_error&); } SECTION("number (integer)") { json j_nonobject(json::value_t::number_integer); const json j_nonobject_const(json::value_t::number_integer); - CHECK_THROWS_AS(j_nonobject.value("foo", 1), json::type_error&); - CHECK_THROWS_AS(j_nonobject_const.value("foo", 1), json::type_error&); - CHECK_THROWS_WITH(j_nonobject.value("foo", 1), - "[json.exception.type_error.306] cannot use value() with number"); - CHECK_THROWS_WITH(j_nonobject_const.value("foo", 1), - "[json.exception.type_error.306] cannot use value() with number"); + CHECK_THROWS_WITH_AS(j_nonobject.value("foo", 1), "[json.exception.type_error.306] cannot use value() with number", json::type_error&); + CHECK_THROWS_WITH_AS(j_nonobject_const.value("foo", 1), "[json.exception.type_error.306] cannot use value() with number", json::type_error&); } SECTION("number (unsigned)") { json j_nonobject(json::value_t::number_unsigned); const json j_nonobject_const(json::value_t::number_unsigned); - CHECK_THROWS_AS(j_nonobject.value("foo", 1), json::type_error&); - CHECK_THROWS_AS(j_nonobject_const.value("foo", 1), json::type_error&); - CHECK_THROWS_WITH(j_nonobject.value("foo", 1), - "[json.exception.type_error.306] cannot use value() with number"); - CHECK_THROWS_WITH(j_nonobject_const.value("foo", 1), - "[json.exception.type_error.306] cannot use value() with number"); + CHECK_THROWS_WITH_AS(j_nonobject.value("foo", 1), "[json.exception.type_error.306] cannot use value() with number", json::type_error&); + CHECK_THROWS_WITH_AS(j_nonobject_const.value("foo", 1), "[json.exception.type_error.306] cannot use value() with number", json::type_error&); } SECTION("number (floating-point)") { json j_nonobject(json::value_t::number_float); const json j_nonobject_const(json::value_t::number_float); - CHECK_THROWS_AS(j_nonobject.value("foo", 1), json::type_error&); - CHECK_THROWS_AS(j_nonobject_const.value("foo", 1), json::type_error&); - CHECK_THROWS_WITH(j_nonobject.value("foo", 1), - "[json.exception.type_error.306] cannot use value() with number"); - CHECK_THROWS_WITH(j_nonobject_const.value("foo", 1), - "[json.exception.type_error.306] cannot use value() with number"); + CHECK_THROWS_WITH_AS(j_nonobject.value("foo", 1), "[json.exception.type_error.306] cannot use value() with number", json::type_error&); + CHECK_THROWS_WITH_AS(j_nonobject_const.value("foo", 1), "[json.exception.type_error.306] cannot use value() with number", json::type_error&); } } } @@ -321,84 +275,56 @@ TEST_CASE("element access 2") { json j_nonobject(json::value_t::null); const json j_nonobject_const(json::value_t::null); - CHECK_THROWS_AS(j_nonobject.value("/foo"_json_pointer, 1), json::type_error&); - CHECK_THROWS_AS(j_nonobject_const.value("/foo"_json_pointer, 1), json::type_error&); - CHECK_THROWS_WITH(j_nonobject.value("/foo"_json_pointer, 1), - "[json.exception.type_error.306] cannot use value() with null"); - CHECK_THROWS_WITH(j_nonobject_const.value("/foo"_json_pointer, 1), - "[json.exception.type_error.306] cannot use value() with null"); + CHECK_THROWS_WITH_AS(j_nonobject.value("/foo"_json_pointer, 1), "[json.exception.type_error.306] cannot use value() with null", json::type_error&); + CHECK_THROWS_WITH_AS(j_nonobject_const.value("/foo"_json_pointer, 1), "[json.exception.type_error.306] cannot use value() with null", json::type_error&); } SECTION("boolean") { json j_nonobject(json::value_t::boolean); const json j_nonobject_const(json::value_t::boolean); - CHECK_THROWS_AS(j_nonobject.value("/foo"_json_pointer, 1), json::type_error&); - CHECK_THROWS_AS(j_nonobject_const.value("/foo"_json_pointer, 1), json::type_error&); - CHECK_THROWS_WITH(j_nonobject.value("/foo"_json_pointer, 1), - "[json.exception.type_error.306] cannot use value() with boolean"); - CHECK_THROWS_WITH(j_nonobject_const.value("/foo"_json_pointer, 1), - "[json.exception.type_error.306] cannot use value() with boolean"); + CHECK_THROWS_WITH_AS(j_nonobject.value("/foo"_json_pointer, 1), "[json.exception.type_error.306] cannot use value() with boolean", json::type_error&); + CHECK_THROWS_WITH_AS(j_nonobject_const.value("/foo"_json_pointer, 1), "[json.exception.type_error.306] cannot use value() with boolean", json::type_error&); } SECTION("string") { json j_nonobject(json::value_t::string); const json j_nonobject_const(json::value_t::string); - CHECK_THROWS_AS(j_nonobject.value("/foo"_json_pointer, 1), json::type_error&); - CHECK_THROWS_AS(j_nonobject_const.value("/foo"_json_pointer, 1), json::type_error&); - CHECK_THROWS_WITH(j_nonobject.value("/foo"_json_pointer, 1), - "[json.exception.type_error.306] cannot use value() with string"); - CHECK_THROWS_WITH(j_nonobject_const.value("/foo"_json_pointer, 1), - "[json.exception.type_error.306] cannot use value() with string"); + CHECK_THROWS_WITH_AS(j_nonobject.value("/foo"_json_pointer, 1), "[json.exception.type_error.306] cannot use value() with string", json::type_error&); + CHECK_THROWS_WITH_AS(j_nonobject_const.value("/foo"_json_pointer, 1), "[json.exception.type_error.306] cannot use value() with string", json::type_error&); } SECTION("array") { json j_nonobject(json::value_t::array); const json j_nonobject_const(json::value_t::array); - CHECK_THROWS_AS(j_nonobject.value("/foo"_json_pointer, 1), json::type_error&); - CHECK_THROWS_AS(j_nonobject_const.value("/foo"_json_pointer, 1), json::type_error&); - CHECK_THROWS_WITH(j_nonobject.value("/foo"_json_pointer, 1), - "[json.exception.type_error.306] cannot use value() with array"); - CHECK_THROWS_WITH(j_nonobject_const.value("/foo"_json_pointer, 1), - "[json.exception.type_error.306] cannot use value() with array"); + CHECK_THROWS_WITH_AS(j_nonobject.value("/foo"_json_pointer, 1), "[json.exception.type_error.306] cannot use value() with array", json::type_error&); + CHECK_THROWS_WITH_AS(j_nonobject_const.value("/foo"_json_pointer, 1), "[json.exception.type_error.306] cannot use value() with array", json::type_error&); } SECTION("number (integer)") { json j_nonobject(json::value_t::number_integer); const json j_nonobject_const(json::value_t::number_integer); - CHECK_THROWS_AS(j_nonobject.value("/foo"_json_pointer, 1), json::type_error&); - CHECK_THROWS_AS(j_nonobject_const.value("/foo"_json_pointer, 1), json::type_error&); - CHECK_THROWS_WITH(j_nonobject.value("/foo"_json_pointer, 1), - "[json.exception.type_error.306] cannot use value() with number"); - CHECK_THROWS_WITH(j_nonobject_const.value("/foo"_json_pointer, 1), - "[json.exception.type_error.306] cannot use value() with number"); + CHECK_THROWS_WITH_AS(j_nonobject.value("/foo"_json_pointer, 1), "[json.exception.type_error.306] cannot use value() with number", json::type_error&); + CHECK_THROWS_WITH_AS(j_nonobject_const.value("/foo"_json_pointer, 1), "[json.exception.type_error.306] cannot use value() with number", json::type_error&); } SECTION("number (unsigned)") { json j_nonobject(json::value_t::number_unsigned); const json j_nonobject_const(json::value_t::number_unsigned); - CHECK_THROWS_AS(j_nonobject.value("/foo"_json_pointer, 1), json::type_error&); - CHECK_THROWS_AS(j_nonobject_const.value("/foo"_json_pointer, 1), json::type_error&); - CHECK_THROWS_WITH(j_nonobject.value("/foo"_json_pointer, 1), - "[json.exception.type_error.306] cannot use value() with number"); - CHECK_THROWS_WITH(j_nonobject_const.value("/foo"_json_pointer, 1), - "[json.exception.type_error.306] cannot use value() with number"); + CHECK_THROWS_WITH_AS(j_nonobject.value("/foo"_json_pointer, 1), "[json.exception.type_error.306] cannot use value() with number", json::type_error&); + CHECK_THROWS_WITH_AS(j_nonobject_const.value("/foo"_json_pointer, 1), "[json.exception.type_error.306] cannot use value() with number", json::type_error&); } SECTION("number (floating-point)") { json j_nonobject(json::value_t::number_float); const json j_nonobject_const(json::value_t::number_float); - CHECK_THROWS_AS(j_nonobject.value("/foo"_json_pointer, 1), json::type_error&); - CHECK_THROWS_AS(j_nonobject_const.value("/foo"_json_pointer, 1), json::type_error&); - CHECK_THROWS_WITH(j_nonobject.value("/foo"_json_pointer, 1), - "[json.exception.type_error.306] cannot use value() with number"); - CHECK_THROWS_WITH(j_nonobject_const.value("/foo"_json_pointer, 1), - "[json.exception.type_error.306] cannot use value() with number"); + CHECK_THROWS_WITH_AS(j_nonobject.value("/foo"_json_pointer, 1), "[json.exception.type_error.306] cannot use value() with number", json::type_error&); + CHECK_THROWS_WITH_AS(j_nonobject_const.value("/foo"_json_pointer, 1), "[json.exception.type_error.306] cannot use value() with number", json::type_error&); } } } @@ -473,118 +399,91 @@ TEST_CASE("element access 2") const json j_const_nonobject(j_nonobject); CHECK_NOTHROW(j_nonobject["foo"]); CHECK_NOTHROW(j_nonobject2[json::object_t::key_type("foo")]); - CHECK_THROWS_AS(j_const_nonobject["foo"], json::type_error&); - CHECK_THROWS_AS(j_const_nonobject[json::object_t::key_type("foo")], json::type_error&); - CHECK_THROWS_WITH(j_const_nonobject["foo"], "[json.exception.type_error.305] cannot use operator[] with a string argument with null"); - CHECK_THROWS_WITH(j_const_nonobject[json::object_t::key_type("foo")], - "[json.exception.type_error.305] cannot use operator[] with a string argument with null"); + CHECK_THROWS_WITH_AS(j_const_nonobject["foo"], "[json.exception.type_error.305] cannot use operator[] with a string argument with null", json::type_error&); + CHECK_THROWS_WITH_AS(j_const_nonobject[json::object_t::key_type("foo")], "[json.exception.type_error.305] cannot use operator[] with a string argument with null", json::type_error&); } SECTION("boolean") { json j_nonobject(json::value_t::boolean); const json j_const_nonobject(j_nonobject); - CHECK_THROWS_AS(j_nonobject["foo"], json::type_error&); - CHECK_THROWS_AS(j_nonobject[json::object_t::key_type("foo")], json::type_error&); - CHECK_THROWS_AS(j_const_nonobject["foo"], json::type_error&); - CHECK_THROWS_AS(j_const_nonobject[json::object_t::key_type("foo")], json::type_error&); - CHECK_THROWS_WITH(j_nonobject["foo"], - "[json.exception.type_error.305] cannot use operator[] with a string argument with boolean"); - CHECK_THROWS_WITH(j_nonobject[json::object_t::key_type("foo")], - "[json.exception.type_error.305] cannot use operator[] with a string argument with boolean"); - CHECK_THROWS_WITH(j_const_nonobject["foo"], - "[json.exception.type_error.305] cannot use operator[] with a string argument with boolean"); - CHECK_THROWS_WITH(j_const_nonobject[json::object_t::key_type("foo")], - "[json.exception.type_error.305] cannot use operator[] with a string argument with boolean"); + CHECK_THROWS_WITH_AS(j_nonobject["foo"], + "[json.exception.type_error.305] cannot use operator[] with a string argument with boolean", json::type_error&); + CHECK_THROWS_WITH_AS(j_nonobject[json::object_t::key_type("foo")], + "[json.exception.type_error.305] cannot use operator[] with a string argument with boolean", json::type_error&); + CHECK_THROWS_WITH_AS(j_const_nonobject["foo"], + "[json.exception.type_error.305] cannot use operator[] with a string argument with boolean", json::type_error&); + CHECK_THROWS_WITH_AS(j_const_nonobject[json::object_t::key_type("foo")], + "[json.exception.type_error.305] cannot use operator[] with a string argument with boolean", json::type_error&); } SECTION("string") { json j_nonobject(json::value_t::string); const json j_const_nonobject(j_nonobject); - CHECK_THROWS_AS(j_nonobject["foo"], json::type_error&); - CHECK_THROWS_AS(j_nonobject[json::object_t::key_type("foo")], json::type_error&); - CHECK_THROWS_AS(j_const_nonobject["foo"], json::type_error&); - CHECK_THROWS_AS(j_const_nonobject[json::object_t::key_type("foo")], json::type_error&); - CHECK_THROWS_WITH(j_nonobject["foo"], - "[json.exception.type_error.305] cannot use operator[] with a string argument with string"); - CHECK_THROWS_WITH(j_nonobject[json::object_t::key_type("foo")], - "[json.exception.type_error.305] cannot use operator[] with a string argument with string"); - CHECK_THROWS_WITH(j_const_nonobject["foo"], - "[json.exception.type_error.305] cannot use operator[] with a string argument with string"); - CHECK_THROWS_WITH(j_const_nonobject[json::object_t::key_type("foo")], - "[json.exception.type_error.305] cannot use operator[] with a string argument with string"); + CHECK_THROWS_WITH_AS(j_nonobject["foo"], + "[json.exception.type_error.305] cannot use operator[] with a string argument with string", json::type_error&); + CHECK_THROWS_WITH_AS(j_nonobject[json::object_t::key_type("foo")], + "[json.exception.type_error.305] cannot use operator[] with a string argument with string", json::type_error&); + CHECK_THROWS_WITH_AS(j_const_nonobject["foo"], + "[json.exception.type_error.305] cannot use operator[] with a string argument with string", json::type_error&); + CHECK_THROWS_WITH_AS(j_const_nonobject[json::object_t::key_type("foo")], + "[json.exception.type_error.305] cannot use operator[] with a string argument with string", json::type_error&); } SECTION("array") { json j_nonobject(json::value_t::array); const json j_const_nonobject(j_nonobject); - CHECK_THROWS_AS(j_nonobject["foo"], json::type_error&); - CHECK_THROWS_AS(j_nonobject[json::object_t::key_type("foo")], json::type_error&); - CHECK_THROWS_AS(j_const_nonobject["foo"], json::type_error&); - CHECK_THROWS_AS(j_const_nonobject[json::object_t::key_type("foo")], json::type_error&); - CHECK_THROWS_WITH(j_nonobject["foo"], - "[json.exception.type_error.305] cannot use operator[] with a string argument with array"); - CHECK_THROWS_WITH(j_nonobject[json::object_t::key_type("foo")], "[json.exception.type_error.305] cannot use operator[] with a string argument with array"); - CHECK_THROWS_WITH(j_const_nonobject["foo"], - "[json.exception.type_error.305] cannot use operator[] with a string argument with array"); - CHECK_THROWS_WITH(j_const_nonobject[json::object_t::key_type("foo")], - "[json.exception.type_error.305] cannot use operator[] with a string argument with array"); + CHECK_THROWS_WITH_AS(j_nonobject["foo"], + "[json.exception.type_error.305] cannot use operator[] with a string argument with array", json::type_error&); + CHECK_THROWS_WITH_AS(j_nonobject[json::object_t::key_type("foo")], "[json.exception.type_error.305] cannot use operator[] with a string argument with array", json::type_error&); + CHECK_THROWS_WITH_AS(j_const_nonobject["foo"], + "[json.exception.type_error.305] cannot use operator[] with a string argument with array", json::type_error&); + CHECK_THROWS_WITH_AS(j_const_nonobject[json::object_t::key_type("foo")], + "[json.exception.type_error.305] cannot use operator[] with a string argument with array", json::type_error&); } SECTION("number (integer)") { json j_nonobject(json::value_t::number_integer); const json j_const_nonobject(j_nonobject); - CHECK_THROWS_AS(j_nonobject["foo"], json::type_error&); - CHECK_THROWS_AS(j_nonobject[json::object_t::key_type("foo")], json::type_error&); - CHECK_THROWS_AS(j_const_nonobject["foo"], json::type_error&); - CHECK_THROWS_AS(j_const_nonobject[json::object_t::key_type("foo")], json::type_error&); - CHECK_THROWS_WITH(j_nonobject["foo"], - "[json.exception.type_error.305] cannot use operator[] with a string argument with number"); - CHECK_THROWS_WITH(j_nonobject[json::object_t::key_type("foo")], - "[json.exception.type_error.305] cannot use operator[] with a string argument with number"); - CHECK_THROWS_WITH(j_const_nonobject["foo"], - "[json.exception.type_error.305] cannot use operator[] with a string argument with number"); - CHECK_THROWS_WITH(j_const_nonobject[json::object_t::key_type("foo")], - "[json.exception.type_error.305] cannot use operator[] with a string argument with number"); + CHECK_THROWS_WITH_AS(j_nonobject["foo"], + "[json.exception.type_error.305] cannot use operator[] with a string argument with number", json::type_error&); + CHECK_THROWS_WITH_AS(j_nonobject[json::object_t::key_type("foo")], + "[json.exception.type_error.305] cannot use operator[] with a string argument with number", json::type_error&); + CHECK_THROWS_WITH_AS(j_const_nonobject["foo"], + "[json.exception.type_error.305] cannot use operator[] with a string argument with number", json::type_error&); + CHECK_THROWS_WITH_AS(j_const_nonobject[json::object_t::key_type("foo")], + "[json.exception.type_error.305] cannot use operator[] with a string argument with number", json::type_error&); } SECTION("number (unsigned)") { json j_nonobject(json::value_t::number_unsigned); const json j_const_nonobject(j_nonobject); - CHECK_THROWS_AS(j_nonobject["foo"], json::type_error&); - CHECK_THROWS_AS(j_nonobject[json::object_t::key_type("foo")], json::type_error&); - CHECK_THROWS_AS(j_const_nonobject["foo"], json::type_error&); - CHECK_THROWS_AS(j_const_nonobject[json::object_t::key_type("foo")], json::type_error&); - CHECK_THROWS_WITH(j_nonobject["foo"], - "[json.exception.type_error.305] cannot use operator[] with a string argument with number"); - CHECK_THROWS_WITH(j_nonobject[json::object_t::key_type("foo")], - "[json.exception.type_error.305] cannot use operator[] with a string argument with number"); - CHECK_THROWS_WITH(j_const_nonobject["foo"], - "[json.exception.type_error.305] cannot use operator[] with a string argument with number"); - CHECK_THROWS_WITH(j_const_nonobject[json::object_t::key_type("foo")], - "[json.exception.type_error.305] cannot use operator[] with a string argument with number"); + CHECK_THROWS_WITH_AS(j_nonobject["foo"], + "[json.exception.type_error.305] cannot use operator[] with a string argument with number", json::type_error&); + CHECK_THROWS_WITH_AS(j_nonobject[json::object_t::key_type("foo")], + "[json.exception.type_error.305] cannot use operator[] with a string argument with number", json::type_error&); + CHECK_THROWS_WITH_AS(j_const_nonobject["foo"], + "[json.exception.type_error.305] cannot use operator[] with a string argument with number", json::type_error&); + CHECK_THROWS_WITH_AS(j_const_nonobject[json::object_t::key_type("foo")], + "[json.exception.type_error.305] cannot use operator[] with a string argument with number", json::type_error&); } SECTION("number (floating-point)") { json j_nonobject(json::value_t::number_float); const json j_const_nonobject(j_nonobject); - CHECK_THROWS_AS(j_nonobject["foo"], json::type_error&); - CHECK_THROWS_AS(j_nonobject[json::object_t::key_type("foo")], json::type_error&); - CHECK_THROWS_AS(j_const_nonobject["foo"], json::type_error&); - CHECK_THROWS_AS(j_const_nonobject[json::object_t::key_type("foo")], json::type_error&); - CHECK_THROWS_WITH(j_nonobject["foo"], - "[json.exception.type_error.305] cannot use operator[] with a string argument with number"); - CHECK_THROWS_WITH(j_nonobject[json::object_t::key_type("foo")], - "[json.exception.type_error.305] cannot use operator[] with a string argument with number"); - CHECK_THROWS_WITH(j_const_nonobject["foo"], - "[json.exception.type_error.305] cannot use operator[] with a string argument with number"); - CHECK_THROWS_WITH(j_const_nonobject[json::object_t::key_type("foo")], - "[json.exception.type_error.305] cannot use operator[] with a string argument with number"); + CHECK_THROWS_WITH_AS(j_nonobject["foo"], + "[json.exception.type_error.305] cannot use operator[] with a string argument with number", json::type_error&); + CHECK_THROWS_WITH_AS(j_nonobject[json::object_t::key_type("foo")], + "[json.exception.type_error.305] cannot use operator[] with a string argument with number", json::type_error&); + CHECK_THROWS_WITH_AS(j_const_nonobject["foo"], + "[json.exception.type_error.305] cannot use operator[] with a string argument with number", json::type_error&); + CHECK_THROWS_WITH_AS(j_const_nonobject[json::object_t::key_type("foo")], + "[json.exception.type_error.305] cannot use operator[] with a string argument with number", json::type_error&); } } } @@ -723,34 +622,26 @@ TEST_CASE("element access 2") { json jobject = {{"a", "a"}, {"b", 1}, {"c", 17u}, {"d", false}, {"e", true}}; json jobject2 = {{"a", "a"}, {"b", 1}, {"c", 17u}}; - CHECK_THROWS_AS(jobject.erase(jobject2.begin()), json::invalid_iterator&); - CHECK_THROWS_AS(jobject.erase(jobject.begin(), jobject2.end()), json::invalid_iterator&); - CHECK_THROWS_AS(jobject.erase(jobject2.begin(), jobject.end()), json::invalid_iterator&); - CHECK_THROWS_AS(jobject.erase(jobject2.begin(), jobject2.end()), json::invalid_iterator&); - CHECK_THROWS_WITH(jobject.erase(jobject2.begin()), - "[json.exception.invalid_iterator.202] iterator does not fit current value"); - CHECK_THROWS_WITH(jobject.erase(jobject.begin(), jobject2.end()), - "[json.exception.invalid_iterator.203] iterators do not fit current value"); - CHECK_THROWS_WITH(jobject.erase(jobject2.begin(), jobject.end()), - "[json.exception.invalid_iterator.203] iterators do not fit current value"); - CHECK_THROWS_WITH(jobject.erase(jobject2.begin(), jobject2.end()), - "[json.exception.invalid_iterator.203] iterators do not fit current value"); + CHECK_THROWS_WITH_AS(jobject.erase(jobject2.begin()), + "[json.exception.invalid_iterator.202] iterator does not fit current value", json::invalid_iterator&); + CHECK_THROWS_WITH_AS(jobject.erase(jobject.begin(), jobject2.end()), + "[json.exception.invalid_iterator.203] iterators do not fit current value", json::invalid_iterator&); + CHECK_THROWS_WITH_AS(jobject.erase(jobject2.begin(), jobject.end()), + "[json.exception.invalid_iterator.203] iterators do not fit current value", json::invalid_iterator&); + CHECK_THROWS_WITH_AS(jobject.erase(jobject2.begin(), jobject2.end()), + "[json.exception.invalid_iterator.203] iterators do not fit current value", json::invalid_iterator&); } { json jobject = {{"a", "a"}, {"b", 1}, {"c", 17u}, {"d", false}, {"e", true}}; json jobject2 = {{"a", "a"}, {"b", 1}, {"c", 17u}}; - CHECK_THROWS_AS(jobject.erase(jobject2.cbegin()), json::invalid_iterator&); - CHECK_THROWS_AS(jobject.erase(jobject.cbegin(), jobject2.cend()), json::invalid_iterator&); - CHECK_THROWS_AS(jobject.erase(jobject2.cbegin(), jobject.cend()), json::invalid_iterator&); - CHECK_THROWS_AS(jobject.erase(jobject2.cbegin(), jobject2.cend()), json::invalid_iterator&); - CHECK_THROWS_WITH(jobject.erase(jobject2.cbegin()), - "[json.exception.invalid_iterator.202] iterator does not fit current value"); - CHECK_THROWS_WITH(jobject.erase(jobject.cbegin(), jobject2.cend()), - "[json.exception.invalid_iterator.203] iterators do not fit current value"); - CHECK_THROWS_WITH(jobject.erase(jobject2.cbegin(), jobject.cend()), - "[json.exception.invalid_iterator.203] iterators do not fit current value"); - CHECK_THROWS_WITH(jobject.erase(jobject2.cbegin(), jobject2.cend()), - "[json.exception.invalid_iterator.203] iterators do not fit current value"); + CHECK_THROWS_WITH_AS(jobject.erase(jobject2.cbegin()), + "[json.exception.invalid_iterator.202] iterator does not fit current value", json::invalid_iterator&); + CHECK_THROWS_WITH_AS(jobject.erase(jobject.cbegin(), jobject2.cend()), + "[json.exception.invalid_iterator.203] iterators do not fit current value", json::invalid_iterator&); + CHECK_THROWS_WITH_AS(jobject.erase(jobject2.cbegin(), jobject.cend()), + "[json.exception.invalid_iterator.203] iterators do not fit current value", json::invalid_iterator&); + CHECK_THROWS_WITH_AS(jobject.erase(jobject2.cbegin(), jobject2.cend()), + "[json.exception.invalid_iterator.203] iterators do not fit current value", json::invalid_iterator&); } } } @@ -760,49 +651,37 @@ TEST_CASE("element access 2") SECTION("null") { json j_nonobject(json::value_t::null); - CHECK_THROWS_AS(j_nonobject.erase("foo"), json::type_error&); - CHECK_THROWS_WITH(j_nonobject.erase("foo"), - "[json.exception.type_error.307] cannot use erase() with null"); + CHECK_THROWS_WITH_AS(j_nonobject.erase("foo"), "[json.exception.type_error.307] cannot use erase() with null", json::type_error&); } SECTION("boolean") { json j_nonobject(json::value_t::boolean); - CHECK_THROWS_AS(j_nonobject.erase("foo"), json::type_error&); - CHECK_THROWS_WITH(j_nonobject.erase("foo"), - "[json.exception.type_error.307] cannot use erase() with boolean"); + CHECK_THROWS_WITH_AS(j_nonobject.erase("foo"), "[json.exception.type_error.307] cannot use erase() with boolean", json::type_error&); } SECTION("string") { json j_nonobject(json::value_t::string); - CHECK_THROWS_AS(j_nonobject.erase("foo"), json::type_error&); - CHECK_THROWS_WITH(j_nonobject.erase("foo"), - "[json.exception.type_error.307] cannot use erase() with string"); + CHECK_THROWS_WITH_AS(j_nonobject.erase("foo"), "[json.exception.type_error.307] cannot use erase() with string", json::type_error&); } SECTION("array") { json j_nonobject(json::value_t::array); - CHECK_THROWS_AS(j_nonobject.erase("foo"), json::type_error&); - CHECK_THROWS_WITH(j_nonobject.erase("foo"), - "[json.exception.type_error.307] cannot use erase() with array"); + CHECK_THROWS_WITH_AS(j_nonobject.erase("foo"), "[json.exception.type_error.307] cannot use erase() with array", json::type_error&); } SECTION("number (integer)") { json j_nonobject(json::value_t::number_integer); - CHECK_THROWS_AS(j_nonobject.erase("foo"), json::type_error&); - CHECK_THROWS_WITH(j_nonobject.erase("foo"), - "[json.exception.type_error.307] cannot use erase() with number"); + CHECK_THROWS_WITH_AS(j_nonobject.erase("foo"), "[json.exception.type_error.307] cannot use erase() with number", json::type_error&); } SECTION("number (floating-point)") { json j_nonobject(json::value_t::number_float); - CHECK_THROWS_AS(j_nonobject.erase("foo"), json::type_error&); - CHECK_THROWS_WITH(j_nonobject.erase("foo"), - "[json.exception.type_error.307] cannot use erase() with number"); + CHECK_THROWS_WITH_AS(j_nonobject.erase("foo"), "[json.exception.type_error.307] cannot use erase() with number", json::type_error&); } } }