From 3b16057ffaaed250cf207233f9238392ea0245ee Mon Sep 17 00:00:00 2001 From: Krzysiek Karbowiak Date: Fri, 1 Apr 2022 14:38:17 +0200 Subject: [PATCH] Refactor unit tests to use more convenient doctest assertion macros (Part 2) (#3405) * Refactor assertion and adjust expected error message * Refactor assertion and adjust expected error message * Refactor assertion and remove redundant local variable * Refactor assertion and remove redundant local variable * Rename local variable * Apply formatting --- test/src/unit-regression1.cpp | 30 +++++++++--------------------- 1 file changed, 9 insertions(+), 21 deletions(-) diff --git a/test/src/unit-regression1.cpp b/test/src/unit-regression1.cpp index a83be81b8..e6dfaa1c5 100644 --- a/test/src/unit-regression1.cpp +++ b/test/src/unit-regression1.cpp @@ -770,9 +770,8 @@ TEST_CASE("regression tests 1") std::stringstream ss; ss << " "; json j; - CHECK_THROWS_AS(ss >> j, json::parse_error&); - CHECK_THROWS_WITH(ss >> j, - "[json.exception.parse_error.101] parse error at line 1, column 1: syntax error while parsing value - unexpected end of input; expected '[', '{', or a literal"); + CHECK_THROWS_WITH_AS(ss >> j, + "[json.exception.parse_error.101] parse error at line 1, column 4: syntax error while parsing value - unexpected end of input; expected '[', '{', or a literal", json::parse_error&); } SECTION("one value") @@ -794,9 +793,8 @@ TEST_CASE("regression tests 1") CHECK_NOTHROW(ss >> j); CHECK(j == 222); - CHECK_THROWS_AS(ss >> j, json::parse_error&); - CHECK_THROWS_WITH(ss >> j, - "[json.exception.parse_error.101] parse error at line 1, column 1: syntax error while parsing value - unexpected end of input; expected '[', '{', or a literal"); + CHECK_THROWS_WITH_AS(ss >> j, + "[json.exception.parse_error.101] parse error at line 2, column 1: syntax error while parsing value - unexpected end of input; expected '[', '{', or a literal", json::parse_error&); } SECTION("whitespace + one value") @@ -1413,24 +1411,14 @@ TEST_CASE("regression tests 1") auto p1 = R"([{"op": "move", "from": "/one/two/three", "path": "/a/b/c"}])"_json; - CHECK_THROWS_AS(model.patch(p1), json::out_of_range&); + CHECK_THROWS_WITH_AS(model.patch(p1), + "[json.exception.out_of_range.403] key 'a' not found", json::out_of_range&); - auto p2 = R"([{"op": "move", + auto p2 = R"([{"op": "copy", "from": "/one/two/three", "path": "/a/b/c"}])"_json; - CHECK_THROWS_WITH(model.patch(p2), - "[json.exception.out_of_range.403] key 'a' not found"); - - auto p3 = R"([{"op": "copy", - "from": "/one/two/three", - "path": "/a/b/c"}])"_json; - CHECK_THROWS_AS(model.patch(p3), json::out_of_range&); - - auto p4 = R"([{"op": "copy", - "from": "/one/two/three", - "path": "/a/b/c"}])"_json; - CHECK_THROWS_WITH(model.patch(p4), - "[json.exception.out_of_range.403] key 'a' not found"); + CHECK_THROWS_WITH_AS(model.patch(p2), + "[json.exception.out_of_range.403] key 'a' not found", json::out_of_range&); } SECTION("issue #961 - incorrect parsing of indefinite length CBOR strings")