Build the update()/merge_patch() diagnostics test values instead of parsing them
Parsed values carry byte positions under JSON_DIAGNOSTIC_POSITIONS, which the expected messages do not include. Signed-off-by: Niels Lohmann <mail@nlohmann.me>
This commit is contained in:
1 parent
3395089b5f
commit
6f971ae520
1 file changed
+10
-10
@@ -368,25 +368,25 @@ TEST_CASE("Better diagnostics past the descent bound of update() and merge_patch
|
|||||||
// Both merge objects nested more than detail::recursion_depth_limit()
|
// Both merge objects nested more than detail::recursion_depth_limit()
|
||||||
// (128) levels deep without recursing; the values they add or replace
|
// (128) levels deep without recursing; the values they add or replace
|
||||||
// there must still know their parents.
|
// there must still know their parents.
|
||||||
|
// The values are built rather than parsed, so that the expected messages
|
||||||
|
// carry no byte positions under JSON_DIAGNOSTIC_POSITIONS.
|
||||||
const std::size_t depth = 200;
|
const std::size_t depth = 200;
|
||||||
std::string target_text;
|
json target = {{"x", 1}};
|
||||||
std::string patch_text;
|
json patch = {{"y", 2}};
|
||||||
std::string path;
|
std::string path;
|
||||||
for (std::size_t i = 0; i < depth; ++i)
|
for (std::size_t i = 0; i < depth; ++i)
|
||||||
{
|
{
|
||||||
target_text += "{\"a\":";
|
target = json{{"a", std::move(target)}};
|
||||||
patch_text += "{\"a\":";
|
patch = json{{"a", std::move(patch)}};
|
||||||
path += "/a";
|
path += "/a";
|
||||||
}
|
}
|
||||||
target_text += "{\"x\":1}" + std::string(depth, '}');
|
|
||||||
patch_text += "{\"y\":2}" + std::string(depth, '}');
|
|
||||||
const std::string expected_x = "[json.exception.type_error.304] (" + path + "/x) cannot use at() with number";
|
const std::string expected_x = "[json.exception.type_error.304] (" + path + "/x) cannot use at() with number";
|
||||||
const std::string expected_y = "[json.exception.type_error.304] (" + path + "/y) cannot use at() with number";
|
const std::string expected_y = "[json.exception.type_error.304] (" + path + "/y) cannot use at() with number";
|
||||||
|
|
||||||
SECTION("update()")
|
SECTION("update()")
|
||||||
{
|
{
|
||||||
json j = json::parse(target_text);
|
json j = target;
|
||||||
j.update(json::parse(patch_text), true);
|
j.update(patch, true);
|
||||||
|
|
||||||
// walk down through const references, which leave m_parent alone
|
// walk down through const references, which leave m_parent alone
|
||||||
const json* p = &j;
|
const json* p = &j;
|
||||||
@@ -400,8 +400,8 @@ TEST_CASE("Better diagnostics past the descent bound of update() and merge_patch
|
|||||||
|
|
||||||
SECTION("merge_patch()")
|
SECTION("merge_patch()")
|
||||||
{
|
{
|
||||||
json j = json::parse(target_text);
|
json j = target;
|
||||||
j.merge_patch(json::parse(patch_text));
|
j.merge_patch(patch);
|
||||||
|
|
||||||
const json* p = &j;
|
const json* p = &j;
|
||||||
for (std::size_t i = 0; i < depth; ++i)
|
for (std::size_t i = 0; i < depth; ++i)
|
||||||
|
|||||||
Reference in new issue
Block a user