♻️ move diagnostic code in header

This commit is contained in:
Niels Lohmann
2021-01-09 19:21:18 +01:00
parent 43cd5c8a4d
commit e160749003
13 changed files with 748 additions and 548 deletions

View File

@@ -692,7 +692,11 @@ TEST_CASE("JSON patch")
json patch = {"op", "add", "path", "", "value", 1};
CHECK_THROWS_AS(j.patch(patch), json::parse_error&);
CHECK_THROWS_WITH(j.patch(patch),
#if JSON_DIAGNOSTICS
"[json.exception.parse_error.104] parse error: (/0) JSON patch must be an array of objects");
#else
"[json.exception.parse_error.104] parse error: JSON patch must be an array of objects");
#endif
}
SECTION("missing 'op'")
@@ -701,7 +705,11 @@ TEST_CASE("JSON patch")
json patch = {{{"foo", "bar"}}};
CHECK_THROWS_AS(j.patch(patch), json::parse_error&);
CHECK_THROWS_WITH(j.patch(patch),
#if JSON_DIAGNOSTICS
"[json.exception.parse_error.105] parse error: (/0) operation must have member 'op'");
#else
"[json.exception.parse_error.105] parse error: operation must have member 'op'");
#endif
}
SECTION("non-string 'op'")
@@ -710,7 +718,11 @@ TEST_CASE("JSON patch")
json patch = {{{"op", 1}}};
CHECK_THROWS_AS(j.patch(patch), json::parse_error&);
CHECK_THROWS_WITH(j.patch(patch),
#if JSON_DIAGNOSTICS
"[json.exception.parse_error.105] parse error: (/0) operation must have string member 'op'");
#else
"[json.exception.parse_error.105] parse error: operation must have string member 'op'");
#endif
}
SECTION("invalid operation")
@@ -719,7 +731,11 @@ TEST_CASE("JSON patch")
json patch = {{{"op", "foo"}, {"path", ""}}};
CHECK_THROWS_AS(j.patch(patch), json::parse_error&);
CHECK_THROWS_WITH(j.patch(patch),
#if JSON_DIAGNOSTICS
"[json.exception.parse_error.105] parse error: (/0) operation value 'foo' is invalid");
#else
"[json.exception.parse_error.105] parse error: operation value 'foo' is invalid");
#endif
}
}
@@ -731,7 +747,11 @@ TEST_CASE("JSON patch")
json patch = {{{"op", "add"}}};
CHECK_THROWS_AS(j.patch(patch), json::parse_error&);
CHECK_THROWS_WITH(j.patch(patch),
#if JSON_DIAGNOSTICS
"[json.exception.parse_error.105] parse error: (/0) operation 'add' must have member 'path'");
#else
"[json.exception.parse_error.105] parse error: operation 'add' must have member 'path'");
#endif
}
SECTION("non-string 'path'")
@@ -740,7 +760,11 @@ TEST_CASE("JSON patch")
json patch = {{{"op", "add"}, {"path", 1}}};
CHECK_THROWS_AS(j.patch(patch), json::parse_error&);
CHECK_THROWS_WITH(j.patch(patch),
#if JSON_DIAGNOSTICS
"[json.exception.parse_error.105] parse error: (/0) operation 'add' must have string member 'path'");
#else
"[json.exception.parse_error.105] parse error: operation 'add' must have string member 'path'");
#endif
}
SECTION("missing 'value'")
@@ -749,7 +773,11 @@ TEST_CASE("JSON patch")
json patch = {{{"op", "add"}, {"path", ""}}};
CHECK_THROWS_AS(j.patch(patch), json::parse_error&);
CHECK_THROWS_WITH(j.patch(patch),
#if JSON_DIAGNOSTICS
"[json.exception.parse_error.105] parse error: (/0) operation 'add' must have member 'value'");
#else
"[json.exception.parse_error.105] parse error: operation 'add' must have member 'value'");
#endif
}
SECTION("invalid array index")
@@ -770,7 +798,11 @@ TEST_CASE("JSON patch")
json patch = {{{"op", "remove"}}};
CHECK_THROWS_AS(j.patch(patch), json::parse_error&);
CHECK_THROWS_WITH(j.patch(patch),
#if JSON_DIAGNOSTICS
"[json.exception.parse_error.105] parse error: (/0) operation 'remove' must have member 'path'");
#else
"[json.exception.parse_error.105] parse error: operation 'remove' must have member 'path'");
#endif
}
SECTION("non-string 'path'")
@@ -779,7 +811,11 @@ TEST_CASE("JSON patch")
json patch = {{{"op", "remove"}, {"path", 1}}};
CHECK_THROWS_AS(j.patch(patch), json::parse_error&);
CHECK_THROWS_WITH(j.patch(patch),
#if JSON_DIAGNOSTICS
"[json.exception.parse_error.105] parse error: (/0) operation 'remove' must have string member 'path'");
#else
"[json.exception.parse_error.105] parse error: operation 'remove' must have string member 'path'");
#endif
}
SECTION("nonexisting target location (array)")
@@ -818,7 +854,11 @@ TEST_CASE("JSON patch")
json patch = {{{"op", "replace"}}};
CHECK_THROWS_AS(j.patch(patch), json::parse_error&);
CHECK_THROWS_WITH(j.patch(patch),
#if JSON_DIAGNOSTICS
"[json.exception.parse_error.105] parse error: (/0) operation 'replace' must have member 'path'");
#else
"[json.exception.parse_error.105] parse error: operation 'replace' must have member 'path'");
#endif
}
SECTION("non-string 'path'")
@@ -827,7 +867,11 @@ TEST_CASE("JSON patch")
json patch = {{{"op", "replace"}, {"path", 1}}};
CHECK_THROWS_AS(j.patch(patch), json::parse_error&);
CHECK_THROWS_WITH(j.patch(patch),
#if JSON_DIAGNOSTICS
"[json.exception.parse_error.105] parse error: (/0) operation 'replace' must have string member 'path'");
#else
"[json.exception.parse_error.105] parse error: operation 'replace' must have string member 'path'");
#endif
}
SECTION("missing 'value'")
@@ -836,7 +880,11 @@ TEST_CASE("JSON patch")
json patch = {{{"op", "replace"}, {"path", ""}}};
CHECK_THROWS_AS(j.patch(patch), json::parse_error&);
CHECK_THROWS_WITH(j.patch(patch),
#if JSON_DIAGNOSTICS
"[json.exception.parse_error.105] parse error: (/0) operation 'replace' must have member 'value'");
#else
"[json.exception.parse_error.105] parse error: operation 'replace' must have member 'value'");
#endif
}
SECTION("nonexisting target location (array)")
@@ -866,7 +914,12 @@ TEST_CASE("JSON patch")
json patch = {{{"op", "move"}}};
CHECK_THROWS_AS(j.patch(patch), json::parse_error&);
CHECK_THROWS_WITH(j.patch(patch),
"[json.exception.parse_error.105] parse error: operation 'move' must have member 'path'");
#if JSON_DIAGNOSTICS
"[json.exception.parse_error.105] parse error: (/0) operation 'move' must have member 'path'"
#else
"[json.exception.parse_error.105] parse error: operation 'move' must have member 'path'"
#endif
);
}
SECTION("non-string 'path'")
@@ -875,7 +928,11 @@ TEST_CASE("JSON patch")
json patch = {{{"op", "move"}, {"path", 1}}};
CHECK_THROWS_AS(j.patch(patch), json::parse_error&);
CHECK_THROWS_WITH(j.patch(patch),
#if JSON_DIAGNOSTICS
"[json.exception.parse_error.105] parse error: (/0) operation 'move' must have string member 'path'");
#else
"[json.exception.parse_error.105] parse error: operation 'move' must have string member 'path'");
#endif
}
SECTION("missing 'from'")
@@ -884,7 +941,11 @@ TEST_CASE("JSON patch")
json patch = {{{"op", "move"}, {"path", ""}}};
CHECK_THROWS_AS(j.patch(patch), json::parse_error&);
CHECK_THROWS_WITH(j.patch(patch),
#if JSON_DIAGNOSTICS
"[json.exception.parse_error.105] parse error: (/0) operation 'move' must have member 'from'");
#else
"[json.exception.parse_error.105] parse error: operation 'move' must have member 'from'");
#endif
}
SECTION("non-string 'from'")
@@ -893,7 +954,11 @@ TEST_CASE("JSON patch")
json patch = {{{"op", "move"}, {"path", ""}, {"from", 1}}};
CHECK_THROWS_AS(j.patch(patch), json::parse_error&);
CHECK_THROWS_WITH(j.patch(patch),
#if JSON_DIAGNOSTICS
"[json.exception.parse_error.105] parse error: (/0) operation 'move' must have string member 'from'");
#else
"[json.exception.parse_error.105] parse error: operation 'move' must have string member 'from'");
#endif
}
SECTION("nonexisting from location (array)")
@@ -923,7 +988,11 @@ TEST_CASE("JSON patch")
json patch = {{{"op", "copy"}}};
CHECK_THROWS_AS(j.patch(patch), json::parse_error&);
CHECK_THROWS_WITH(j.patch(patch),
#if JSON_DIAGNOSTICS
"[json.exception.parse_error.105] parse error: (/0) operation 'copy' must have member 'path'");
#else
"[json.exception.parse_error.105] parse error: operation 'copy' must have member 'path'");
#endif
}
SECTION("non-string 'path'")
@@ -932,7 +1001,11 @@ TEST_CASE("JSON patch")
json patch = {{{"op", "copy"}, {"path", 1}}};
CHECK_THROWS_AS(j.patch(patch), json::parse_error&);
CHECK_THROWS_WITH(j.patch(patch),
#if JSON_DIAGNOSTICS
"[json.exception.parse_error.105] parse error: (/0) operation 'copy' must have string member 'path'");
#else
"[json.exception.parse_error.105] parse error: operation 'copy' must have string member 'path'");
#endif
}
SECTION("missing 'from'")
@@ -941,7 +1014,11 @@ TEST_CASE("JSON patch")
json patch = {{{"op", "copy"}, {"path", ""}}};
CHECK_THROWS_AS(j.patch(patch), json::parse_error&);
CHECK_THROWS_WITH(j.patch(patch),
#if JSON_DIAGNOSTICS
"[json.exception.parse_error.105] parse error: (/0) operation 'copy' must have member 'from'");
#else
"[json.exception.parse_error.105] parse error: operation 'copy' must have member 'from'");
#endif
}
SECTION("non-string 'from'")
@@ -950,7 +1027,11 @@ TEST_CASE("JSON patch")
json patch = {{{"op", "copy"}, {"path", ""}, {"from", 1}}};
CHECK_THROWS_AS(j.patch(patch), json::parse_error&);
CHECK_THROWS_WITH(j.patch(patch),
#if JSON_DIAGNOSTICS
"[json.exception.parse_error.105] parse error: (/0) operation 'copy' must have string member 'from'");
#else
"[json.exception.parse_error.105] parse error: operation 'copy' must have string member 'from'");
#endif
}
SECTION("nonexisting from location (array)")
@@ -980,7 +1061,11 @@ TEST_CASE("JSON patch")
json patch = {{{"op", "test"}}};
CHECK_THROWS_AS(j.patch(patch), json::parse_error&);
CHECK_THROWS_WITH(j.patch(patch),
#if JSON_DIAGNOSTICS
"[json.exception.parse_error.105] parse error: (/0) operation 'test' must have member 'path'");
#else
"[json.exception.parse_error.105] parse error: operation 'test' must have member 'path'");
#endif
}
SECTION("non-string 'path'")
@@ -989,7 +1074,11 @@ TEST_CASE("JSON patch")
json patch = {{{"op", "test"}, {"path", 1}}};
CHECK_THROWS_AS(j.patch(patch), json::parse_error&);
CHECK_THROWS_WITH(j.patch(patch),
#if JSON_DIAGNOSTICS
"[json.exception.parse_error.105] parse error: (/0) operation 'test' must have string member 'path'");
#else
"[json.exception.parse_error.105] parse error: operation 'test' must have string member 'path'");
#endif
}
SECTION("missing 'value'")
@@ -998,7 +1087,11 @@ TEST_CASE("JSON patch")
json patch = {{{"op", "test"}, {"path", ""}}};
CHECK_THROWS_AS(j.patch(patch), json::parse_error&);
CHECK_THROWS_WITH(j.patch(patch),
#if JSON_DIAGNOSTICS
"[json.exception.parse_error.105] parse error: (/0) operation 'test' must have member 'value'");
#else
"[json.exception.parse_error.105] parse error: operation 'test' must have member 'value'");
#endif
}
}
}