From c8b8907dd4064e04d91ba2a7959bc737bcb95720 Mon Sep 17 00:00:00 2001 From: Krzysiek Karbowiak Date: Thu, 17 Mar 2022 10:43:43 +0100 Subject: [PATCH] Refactor assertions in unit-reference_access.cpp --- test/src/unit-reference_access.cpp | 203 +++++++++++------------------ 1 file changed, 77 insertions(+), 126 deletions(-) diff --git a/test/src/unit-reference_access.cpp b/test/src/unit-reference_access.cpp index 1342d479d..52199d798 100644 --- a/test/src/unit-reference_access.cpp +++ b/test/src/unit-reference_access.cpp @@ -65,24 +65,18 @@ TEST_CASE("reference access") // check if mismatching references throw correctly CHECK_NOTHROW(value.get_ref()); - CHECK_THROWS_AS(value.get_ref(), json::type_error&); - CHECK_THROWS_WITH(value.get_ref(), - "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is object"); - CHECK_THROWS_AS(value.get_ref(), json::type_error&); - CHECK_THROWS_WITH(value.get_ref(), - "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is object"); - CHECK_THROWS_AS(value.get_ref(), json::type_error&); - CHECK_THROWS_WITH(value.get_ref(), - "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is object"); - CHECK_THROWS_AS(value.get_ref(), json::type_error&); - CHECK_THROWS_WITH(value.get_ref(), - "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is object"); - CHECK_THROWS_AS(value.get_ref(), json::type_error&); - CHECK_THROWS_WITH(value.get_ref(), - "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is object"); - CHECK_THROWS_AS(value.get_ref(), json::type_error&); - CHECK_THROWS_WITH(value.get_ref(), - "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is object"); + CHECK_THROWS_WITH_AS(value.get_ref(), + "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is object", json::type_error&); + CHECK_THROWS_WITH_AS(value.get_ref(), + "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is object", json::type_error&); + CHECK_THROWS_WITH_AS(value.get_ref(), + "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is object", json::type_error&); + CHECK_THROWS_WITH_AS(value.get_ref(), + "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is object", json::type_error&); + CHECK_THROWS_WITH_AS(value.get_ref(), + "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is object", json::type_error&); + CHECK_THROWS_WITH_AS(value.get_ref(), + "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is object", json::type_error&); } SECTION("const reference access to const object_t") @@ -114,25 +108,19 @@ TEST_CASE("reference access") CHECK(p2 == value.get()); // check if mismatching references throw correctly - CHECK_THROWS_AS(value.get_ref(), json::type_error&); - CHECK_THROWS_WITH(value.get_ref(), - "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is array"); + CHECK_THROWS_WITH_AS(value.get_ref(), + "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is array", json::type_error&); CHECK_NOTHROW(value.get_ref()); - CHECK_THROWS_AS(value.get_ref(), json::type_error&); - CHECK_THROWS_WITH(value.get_ref(), - "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is array"); - CHECK_THROWS_AS(value.get_ref(), json::type_error&); - CHECK_THROWS_WITH(value.get_ref(), - "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is array"); - CHECK_THROWS_AS(value.get_ref(), json::type_error&); - CHECK_THROWS_WITH(value.get_ref(), - "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is array"); - CHECK_THROWS_AS(value.get_ref(), json::type_error&); - CHECK_THROWS_WITH(value.get_ref(), - "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is array"); - CHECK_THROWS_AS(value.get_ref(), json::type_error&); - CHECK_THROWS_WITH(value.get_ref(), - "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is array"); + CHECK_THROWS_WITH_AS(value.get_ref(), + "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is array", json::type_error&); + CHECK_THROWS_WITH_AS(value.get_ref(), + "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is array", json::type_error&); + CHECK_THROWS_WITH_AS(value.get_ref(), + "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is array", json::type_error&); + CHECK_THROWS_WITH_AS(value.get_ref(), + "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is array", json::type_error&); + CHECK_THROWS_WITH_AS(value.get_ref(), + "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is array", json::type_error&); } SECTION("reference access to string_t") @@ -150,25 +138,19 @@ TEST_CASE("reference access") CHECK(p2 == value.get()); // check if mismatching references throw correctly - CHECK_THROWS_AS(value.get_ref(), json::type_error&); - CHECK_THROWS_WITH(value.get_ref(), - "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is string"); - CHECK_THROWS_AS(value.get_ref(), json::type_error&); - CHECK_THROWS_WITH(value.get_ref(), - "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is string"); + CHECK_THROWS_WITH_AS(value.get_ref(), + "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is string", json::type_error&); + CHECK_THROWS_WITH_AS(value.get_ref(), + "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is string", json::type_error&); CHECK_NOTHROW(value.get_ref()); - CHECK_THROWS_AS(value.get_ref(), json::type_error&); - CHECK_THROWS_WITH(value.get_ref(), - "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is string"); - CHECK_THROWS_AS(value.get_ref(), json::type_error&); - CHECK_THROWS_WITH(value.get_ref(), - "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is string"); - CHECK_THROWS_AS(value.get_ref(), json::type_error&); - CHECK_THROWS_WITH(value.get_ref(), - "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is string"); - CHECK_THROWS_AS(value.get_ref(), json::type_error&); - CHECK_THROWS_WITH(value.get_ref(), - "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is string"); + CHECK_THROWS_WITH_AS(value.get_ref(), + "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is string", json::type_error&); + CHECK_THROWS_WITH_AS(value.get_ref(), + "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is string", json::type_error&); + CHECK_THROWS_WITH_AS(value.get_ref(), + "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is string", json::type_error&); + CHECK_THROWS_WITH_AS(value.get_ref(), + "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is string", json::type_error&); } SECTION("reference access to boolean_t") @@ -186,25 +168,19 @@ TEST_CASE("reference access") CHECK(p2 == value.get()); // check if mismatching references throw correctly - CHECK_THROWS_AS(value.get_ref(), json::type_error&); - CHECK_THROWS_WITH(value.get_ref(), - "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is boolean"); - CHECK_THROWS_AS(value.get_ref(), json::type_error&); - CHECK_THROWS_WITH(value.get_ref(), - "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is boolean"); - CHECK_THROWS_AS(value.get_ref(), json::type_error&); - CHECK_THROWS_WITH(value.get_ref(), - "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is boolean"); + CHECK_THROWS_WITH_AS(value.get_ref(), + "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is boolean", json::type_error&); + CHECK_THROWS_WITH_AS(value.get_ref(), + "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is boolean", json::type_error&); + CHECK_THROWS_WITH_AS(value.get_ref(), + "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is boolean", json::type_error&); CHECK_NOTHROW(value.get_ref()); - CHECK_THROWS_AS(value.get_ref(), json::type_error&); - CHECK_THROWS_WITH(value.get_ref(), - "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is boolean"); - CHECK_THROWS_AS(value.get_ref(), json::type_error&); - CHECK_THROWS_WITH(value.get_ref(), - "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is boolean"); - CHECK_THROWS_AS(value.get_ref(), json::type_error&); - CHECK_THROWS_WITH(value.get_ref(), - "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is boolean"); + CHECK_THROWS_WITH_AS(value.get_ref(), + "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is boolean", json::type_error&); + CHECK_THROWS_WITH_AS(value.get_ref(), + "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is boolean", json::type_error&); + CHECK_THROWS_WITH_AS(value.get_ref(), + "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is boolean", json::type_error&); } SECTION("reference access to number_integer_t") @@ -222,25 +198,19 @@ TEST_CASE("reference access") CHECK(p2 == value.get()); // check if mismatching references throw correctly - CHECK_THROWS_AS(value.get_ref(), json::type_error&); - CHECK_THROWS_WITH(value.get_ref(), - "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number"); - CHECK_THROWS_AS(value.get_ref(), json::type_error&); - CHECK_THROWS_WITH(value.get_ref(), - "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number"); - CHECK_THROWS_AS(value.get_ref(), json::type_error&); - CHECK_THROWS_WITH(value.get_ref(), - "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number"); - CHECK_THROWS_AS(value.get_ref(), json::type_error&); - CHECK_THROWS_WITH(value.get_ref(), - "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number"); + CHECK_THROWS_WITH_AS(value.get_ref(), + "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number", json::type_error&); + CHECK_THROWS_WITH_AS(value.get_ref(), + "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number", json::type_error&); + CHECK_THROWS_WITH_AS(value.get_ref(), + "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number", json::type_error&); + CHECK_THROWS_WITH_AS(value.get_ref(), + "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number", json::type_error&); CHECK_NOTHROW(value.get_ref()); - CHECK_THROWS_AS(value.get_ref(), json::type_error&); - CHECK_THROWS_WITH(value.get_ref(), - "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number"); - CHECK_THROWS_AS(value.get_ref(), json::type_error&); - CHECK_THROWS_WITH(value.get_ref(), - "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number"); + CHECK_THROWS_WITH_AS(value.get_ref(), + "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number", json::type_error&); + CHECK_THROWS_WITH_AS(value.get_ref(), + "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number", json::type_error&); } SECTION("reference access to number_unsigned_t") @@ -258,25 +228,18 @@ TEST_CASE("reference access") CHECK(p2 == value.get()); // check if mismatching references throw correctly - CHECK_THROWS_AS(value.get_ref(), json::type_error&); - CHECK_THROWS_WITH(value.get_ref(), - "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number"); - CHECK_THROWS_AS(value.get_ref(), json::type_error&); - CHECK_THROWS_WITH(value.get_ref(), - "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number"); - CHECK_THROWS_AS(value.get_ref(), json::type_error&); - CHECK_THROWS_WITH(value.get_ref(), - "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number"); - CHECK_THROWS_AS(value.get_ref(), json::type_error&); - CHECK_THROWS_WITH(value.get_ref(), - "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number"); - //CHECK_THROWS_AS(value.get_ref(), json::type_error&); - //CHECK_THROWS_WITH(value.get_ref(), - // "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number"); + CHECK_THROWS_WITH_AS(value.get_ref(), + "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number", json::type_error&); + CHECK_THROWS_WITH_AS(value.get_ref(), + "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number", json::type_error&); + CHECK_THROWS_WITH_AS(value.get_ref(), + "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number", json::type_error&); + CHECK_THROWS_WITH_AS(value.get_ref(), + "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number", json::type_error&); + //CHECK_THROWS_WITH_AS(value.get_ref(), + // "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number", json::type_error&); CHECK_NOTHROW(value.get_ref()); - CHECK_THROWS_AS(value.get_ref(), json::type_error&); - CHECK_THROWS_WITH(value.get_ref(), - "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number"); + CHECK_THROWS_WITH_AS(value.get_ref(), "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number", json::type_error&); } SECTION("reference access to number_float_t") @@ -294,24 +257,12 @@ TEST_CASE("reference access") CHECK(p2 == value.get()); // check if mismatching references throw correctly - CHECK_THROWS_AS(value.get_ref(), json::type_error&); - CHECK_THROWS_WITH(value.get_ref(), - "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number"); - CHECK_THROWS_AS(value.get_ref(), json::type_error&); - CHECK_THROWS_WITH(value.get_ref(), - "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number"); - CHECK_THROWS_AS(value.get_ref(), json::type_error&); - CHECK_THROWS_WITH(value.get_ref(), - "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number"); - CHECK_THROWS_AS(value.get_ref(), json::type_error&); - CHECK_THROWS_WITH(value.get_ref(), - "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number"); - CHECK_THROWS_AS(value.get_ref(), json::type_error&); - CHECK_THROWS_WITH(value.get_ref(), - "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number"); - CHECK_THROWS_AS(value.get_ref(), json::type_error&); - CHECK_THROWS_WITH(value.get_ref(), - "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number"); + CHECK_THROWS_WITH_AS(value.get_ref(), "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number", json::type_error&); + CHECK_THROWS_WITH_AS(value.get_ref(), "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number", json::type_error&); + CHECK_THROWS_WITH_AS(value.get_ref(), "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number", json::type_error&); + CHECK_THROWS_WITH_AS(value.get_ref(), "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number", json::type_error&); + CHECK_THROWS_WITH_AS(value.get_ref(), "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number", json::type_error&); + CHECK_THROWS_WITH_AS(value.get_ref(), "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number", json::type_error&); CHECK_NOTHROW(value.get_ref()); } }