Refactor assertions in unit-reference_access.cpp

This commit is contained in:
Krzysiek Karbowiak 2022-03-17 10:43:43 +01:00
parent 3b1bdf4571
commit c8b8907dd4

View File

@ -65,24 +65,18 @@ TEST_CASE("reference access")
// check if mismatching references throw correctly // check if mismatching references throw correctly
CHECK_NOTHROW(value.get_ref<json::object_t&>()); CHECK_NOTHROW(value.get_ref<json::object_t&>());
CHECK_THROWS_AS(value.get_ref<json::array_t&>(), json::type_error&); CHECK_THROWS_WITH_AS(value.get_ref<json::array_t&>(),
CHECK_THROWS_WITH(value.get_ref<json::array_t&>(), "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is object", json::type_error&);
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is object"); CHECK_THROWS_WITH_AS(value.get_ref<json::string_t&>(),
CHECK_THROWS_AS(value.get_ref<json::string_t&>(), json::type_error&); "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is object", json::type_error&);
CHECK_THROWS_WITH(value.get_ref<json::string_t&>(), CHECK_THROWS_WITH_AS(value.get_ref<json::boolean_t&>(),
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is object"); "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is object", json::type_error&);
CHECK_THROWS_AS(value.get_ref<json::boolean_t&>(), json::type_error&); CHECK_THROWS_WITH_AS(value.get_ref<json::number_integer_t&>(),
CHECK_THROWS_WITH(value.get_ref<json::boolean_t&>(), "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is object", json::type_error&);
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is object"); CHECK_THROWS_WITH_AS(value.get_ref<json::number_unsigned_t&>(),
CHECK_THROWS_AS(value.get_ref<json::number_integer_t&>(), json::type_error&); "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is object", json::type_error&);
CHECK_THROWS_WITH(value.get_ref<json::number_integer_t&>(), CHECK_THROWS_WITH_AS(value.get_ref<json::number_float_t&>(),
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is object"); "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is object", json::type_error&);
CHECK_THROWS_AS(value.get_ref<json::number_unsigned_t&>(), json::type_error&);
CHECK_THROWS_WITH(value.get_ref<json::number_unsigned_t&>(),
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is object");
CHECK_THROWS_AS(value.get_ref<json::number_float_t&>(), json::type_error&);
CHECK_THROWS_WITH(value.get_ref<json::number_float_t&>(),
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is object");
} }
SECTION("const reference access to const object_t") SECTION("const reference access to const object_t")
@ -114,25 +108,19 @@ TEST_CASE("reference access")
CHECK(p2 == value.get<test_type>()); CHECK(p2 == value.get<test_type>());
// check if mismatching references throw correctly // check if mismatching references throw correctly
CHECK_THROWS_AS(value.get_ref<json::object_t&>(), json::type_error&); CHECK_THROWS_WITH_AS(value.get_ref<json::object_t&>(),
CHECK_THROWS_WITH(value.get_ref<json::object_t&>(), "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is array", json::type_error&);
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is array");
CHECK_NOTHROW(value.get_ref<json::array_t&>()); CHECK_NOTHROW(value.get_ref<json::array_t&>());
CHECK_THROWS_AS(value.get_ref<json::string_t&>(), json::type_error&); CHECK_THROWS_WITH_AS(value.get_ref<json::string_t&>(),
CHECK_THROWS_WITH(value.get_ref<json::string_t&>(), "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is array", json::type_error&);
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is array"); CHECK_THROWS_WITH_AS(value.get_ref<json::boolean_t&>(),
CHECK_THROWS_AS(value.get_ref<json::boolean_t&>(), json::type_error&); "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is array", json::type_error&);
CHECK_THROWS_WITH(value.get_ref<json::boolean_t&>(), CHECK_THROWS_WITH_AS(value.get_ref<json::number_integer_t&>(),
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is array"); "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is array", json::type_error&);
CHECK_THROWS_AS(value.get_ref<json::number_integer_t&>(), json::type_error&); CHECK_THROWS_WITH_AS(value.get_ref<json::number_unsigned_t&>(),
CHECK_THROWS_WITH(value.get_ref<json::number_integer_t&>(), "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is array", json::type_error&);
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is array"); CHECK_THROWS_WITH_AS(value.get_ref<json::number_float_t&>(),
CHECK_THROWS_AS(value.get_ref<json::number_unsigned_t&>(), json::type_error&); "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is array", json::type_error&);
CHECK_THROWS_WITH(value.get_ref<json::number_unsigned_t&>(),
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is array");
CHECK_THROWS_AS(value.get_ref<json::number_float_t&>(), json::type_error&);
CHECK_THROWS_WITH(value.get_ref<json::number_float_t&>(),
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is array");
} }
SECTION("reference access to string_t") SECTION("reference access to string_t")
@ -150,25 +138,19 @@ TEST_CASE("reference access")
CHECK(p2 == value.get<test_type>()); CHECK(p2 == value.get<test_type>());
// check if mismatching references throw correctly // check if mismatching references throw correctly
CHECK_THROWS_AS(value.get_ref<json::object_t&>(), json::type_error&); CHECK_THROWS_WITH_AS(value.get_ref<json::object_t&>(),
CHECK_THROWS_WITH(value.get_ref<json::object_t&>(), "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is string", json::type_error&);
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is string"); CHECK_THROWS_WITH_AS(value.get_ref<json::array_t&>(),
CHECK_THROWS_AS(value.get_ref<json::array_t&>(), json::type_error&); "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is string", json::type_error&);
CHECK_THROWS_WITH(value.get_ref<json::array_t&>(),
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is string");
CHECK_NOTHROW(value.get_ref<json::string_t&>()); CHECK_NOTHROW(value.get_ref<json::string_t&>());
CHECK_THROWS_AS(value.get_ref<json::boolean_t&>(), json::type_error&); CHECK_THROWS_WITH_AS(value.get_ref<json::boolean_t&>(),
CHECK_THROWS_WITH(value.get_ref<json::boolean_t&>(), "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is string", json::type_error&);
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is string"); CHECK_THROWS_WITH_AS(value.get_ref<json::number_integer_t&>(),
CHECK_THROWS_AS(value.get_ref<json::number_integer_t&>(), json::type_error&); "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is string", json::type_error&);
CHECK_THROWS_WITH(value.get_ref<json::number_integer_t&>(), CHECK_THROWS_WITH_AS(value.get_ref<json::number_unsigned_t&>(),
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is string"); "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is string", json::type_error&);
CHECK_THROWS_AS(value.get_ref<json::number_unsigned_t&>(), json::type_error&); CHECK_THROWS_WITH_AS(value.get_ref<json::number_float_t&>(),
CHECK_THROWS_WITH(value.get_ref<json::number_unsigned_t&>(), "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is string", json::type_error&);
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is string");
CHECK_THROWS_AS(value.get_ref<json::number_float_t&>(), json::type_error&);
CHECK_THROWS_WITH(value.get_ref<json::number_float_t&>(),
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is string");
} }
SECTION("reference access to boolean_t") SECTION("reference access to boolean_t")
@ -186,25 +168,19 @@ TEST_CASE("reference access")
CHECK(p2 == value.get<test_type>()); CHECK(p2 == value.get<test_type>());
// check if mismatching references throw correctly // check if mismatching references throw correctly
CHECK_THROWS_AS(value.get_ref<json::object_t&>(), json::type_error&); CHECK_THROWS_WITH_AS(value.get_ref<json::object_t&>(),
CHECK_THROWS_WITH(value.get_ref<json::object_t&>(), "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is boolean", json::type_error&);
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is boolean"); CHECK_THROWS_WITH_AS(value.get_ref<json::array_t&>(),
CHECK_THROWS_AS(value.get_ref<json::array_t&>(), json::type_error&); "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is boolean", json::type_error&);
CHECK_THROWS_WITH(value.get_ref<json::array_t&>(), CHECK_THROWS_WITH_AS(value.get_ref<json::string_t&>(),
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is boolean"); "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is boolean", json::type_error&);
CHECK_THROWS_AS(value.get_ref<json::string_t&>(), json::type_error&);
CHECK_THROWS_WITH(value.get_ref<json::string_t&>(),
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is boolean");
CHECK_NOTHROW(value.get_ref<json::boolean_t&>()); CHECK_NOTHROW(value.get_ref<json::boolean_t&>());
CHECK_THROWS_AS(value.get_ref<json::number_integer_t&>(), json::type_error&); CHECK_THROWS_WITH_AS(value.get_ref<json::number_integer_t&>(),
CHECK_THROWS_WITH(value.get_ref<json::number_integer_t&>(), "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is boolean", json::type_error&);
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is boolean"); CHECK_THROWS_WITH_AS(value.get_ref<json::number_unsigned_t&>(),
CHECK_THROWS_AS(value.get_ref<json::number_unsigned_t&>(), json::type_error&); "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is boolean", json::type_error&);
CHECK_THROWS_WITH(value.get_ref<json::number_unsigned_t&>(), CHECK_THROWS_WITH_AS(value.get_ref<json::number_float_t&>(),
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is boolean"); "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is boolean", json::type_error&);
CHECK_THROWS_AS(value.get_ref<json::number_float_t&>(), json::type_error&);
CHECK_THROWS_WITH(value.get_ref<json::number_float_t&>(),
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is boolean");
} }
SECTION("reference access to number_integer_t") SECTION("reference access to number_integer_t")
@ -222,25 +198,19 @@ TEST_CASE("reference access")
CHECK(p2 == value.get<test_type>()); CHECK(p2 == value.get<test_type>());
// check if mismatching references throw correctly // check if mismatching references throw correctly
CHECK_THROWS_AS(value.get_ref<json::object_t&>(), json::type_error&); CHECK_THROWS_WITH_AS(value.get_ref<json::object_t&>(),
CHECK_THROWS_WITH(value.get_ref<json::object_t&>(), "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number", json::type_error&);
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number"); CHECK_THROWS_WITH_AS(value.get_ref<json::array_t&>(),
CHECK_THROWS_AS(value.get_ref<json::array_t&>(), json::type_error&); "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number", json::type_error&);
CHECK_THROWS_WITH(value.get_ref<json::array_t&>(), CHECK_THROWS_WITH_AS(value.get_ref<json::string_t&>(),
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number"); "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number", json::type_error&);
CHECK_THROWS_AS(value.get_ref<json::string_t&>(), json::type_error&); CHECK_THROWS_WITH_AS(value.get_ref<json::boolean_t&>(),
CHECK_THROWS_WITH(value.get_ref<json::string_t&>(), "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number", json::type_error&);
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number");
CHECK_THROWS_AS(value.get_ref<json::boolean_t&>(), json::type_error&);
CHECK_THROWS_WITH(value.get_ref<json::boolean_t&>(),
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number");
CHECK_NOTHROW(value.get_ref<json::number_integer_t&>()); CHECK_NOTHROW(value.get_ref<json::number_integer_t&>());
CHECK_THROWS_AS(value.get_ref<json::number_unsigned_t&>(), json::type_error&); CHECK_THROWS_WITH_AS(value.get_ref<json::number_unsigned_t&>(),
CHECK_THROWS_WITH(value.get_ref<json::number_unsigned_t&>(), "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number", json::type_error&);
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number"); CHECK_THROWS_WITH_AS(value.get_ref<json::number_float_t&>(),
CHECK_THROWS_AS(value.get_ref<json::number_float_t&>(), json::type_error&); "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number", json::type_error&);
CHECK_THROWS_WITH(value.get_ref<json::number_float_t&>(),
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number");
} }
SECTION("reference access to number_unsigned_t") SECTION("reference access to number_unsigned_t")
@ -258,25 +228,18 @@ TEST_CASE("reference access")
CHECK(p2 == value.get<test_type>()); CHECK(p2 == value.get<test_type>());
// check if mismatching references throw correctly // check if mismatching references throw correctly
CHECK_THROWS_AS(value.get_ref<json::object_t&>(), json::type_error&); CHECK_THROWS_WITH_AS(value.get_ref<json::object_t&>(),
CHECK_THROWS_WITH(value.get_ref<json::object_t&>(), "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number", json::type_error&);
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number"); CHECK_THROWS_WITH_AS(value.get_ref<json::array_t&>(),
CHECK_THROWS_AS(value.get_ref<json::array_t&>(), json::type_error&); "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number", json::type_error&);
CHECK_THROWS_WITH(value.get_ref<json::array_t&>(), CHECK_THROWS_WITH_AS(value.get_ref<json::string_t&>(),
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number"); "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number", json::type_error&);
CHECK_THROWS_AS(value.get_ref<json::string_t&>(), json::type_error&); CHECK_THROWS_WITH_AS(value.get_ref<json::boolean_t&>(),
CHECK_THROWS_WITH(value.get_ref<json::string_t&>(), "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number", json::type_error&);
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number"); //CHECK_THROWS_WITH_AS(value.get_ref<json::number_integer_t&>(),
CHECK_THROWS_AS(value.get_ref<json::boolean_t&>(), json::type_error&); // "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number", json::type_error&);
CHECK_THROWS_WITH(value.get_ref<json::boolean_t&>(),
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number");
//CHECK_THROWS_AS(value.get_ref<json::number_integer_t&>(), json::type_error&);
//CHECK_THROWS_WITH(value.get_ref<json::number_integer_t&>(),
// "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number");
CHECK_NOTHROW(value.get_ref<json::number_unsigned_t&>()); CHECK_NOTHROW(value.get_ref<json::number_unsigned_t&>());
CHECK_THROWS_AS(value.get_ref<json::number_float_t&>(), json::type_error&); CHECK_THROWS_WITH_AS(value.get_ref<json::number_float_t&>(), "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number", json::type_error&);
CHECK_THROWS_WITH(value.get_ref<json::number_float_t&>(),
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number");
} }
SECTION("reference access to number_float_t") SECTION("reference access to number_float_t")
@ -294,24 +257,12 @@ TEST_CASE("reference access")
CHECK(p2 == value.get<test_type>()); CHECK(p2 == value.get<test_type>());
// check if mismatching references throw correctly // check if mismatching references throw correctly
CHECK_THROWS_AS(value.get_ref<json::object_t&>(), json::type_error&); CHECK_THROWS_WITH_AS(value.get_ref<json::object_t&>(), "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number", json::type_error&);
CHECK_THROWS_WITH(value.get_ref<json::object_t&>(), CHECK_THROWS_WITH_AS(value.get_ref<json::array_t&>(), "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number", json::type_error&);
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number"); CHECK_THROWS_WITH_AS(value.get_ref<json::string_t&>(), "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number", json::type_error&);
CHECK_THROWS_AS(value.get_ref<json::array_t&>(), json::type_error&); CHECK_THROWS_WITH_AS(value.get_ref<json::boolean_t&>(), "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number", json::type_error&);
CHECK_THROWS_WITH(value.get_ref<json::array_t&>(), CHECK_THROWS_WITH_AS(value.get_ref<json::number_integer_t&>(), "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number", json::type_error&);
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number"); CHECK_THROWS_WITH_AS(value.get_ref<json::number_unsigned_t&>(), "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number", json::type_error&);
CHECK_THROWS_AS(value.get_ref<json::string_t&>(), json::type_error&);
CHECK_THROWS_WITH(value.get_ref<json::string_t&>(),
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number");
CHECK_THROWS_AS(value.get_ref<json::boolean_t&>(), json::type_error&);
CHECK_THROWS_WITH(value.get_ref<json::boolean_t&>(),
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number");
CHECK_THROWS_AS(value.get_ref<json::number_integer_t&>(), json::type_error&);
CHECK_THROWS_WITH(value.get_ref<json::number_integer_t&>(),
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number");
CHECK_THROWS_AS(value.get_ref<json::number_unsigned_t&>(), json::type_error&);
CHECK_THROWS_WITH(value.get_ref<json::number_unsigned_t&>(),
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number");
CHECK_NOTHROW(value.get_ref<json::number_float_t&>()); CHECK_NOTHROW(value.get_ref<json::number_float_t&>());
} }
} }