From 93fd4aa6f6694bd6464acb36de5fac158301ef53 Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Mon, 28 Sep 2026 20:37:04 +0200 Subject: [PATCH] Build the enum-keyed map test object instead of parsing it ci_test_diagnostic_positions failed in unit-enum_keyed_maps_default.cpp: with JSON_DIAGNOSTIC_POSITIONS, a parsed value adds its byte range to the exception message ("(bytes 0-7) type must be array, but is object"), so the exact-message checks did not match. Build the object in memory, like unit-custom-array-type.cpp does. Signed-off-by: Niels Lohmann --- tests/src/unit-enum_keyed_maps_default.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tests/src/unit-enum_keyed_maps_default.cpp b/tests/src/unit-enum_keyed_maps_default.cpp index 899a0a0fb..5638b37e1 100644 --- a/tests/src/unit-enum_keyed_maps_default.cpp +++ b/tests/src/unit-enum_keyed_maps_default.cpp @@ -122,11 +122,14 @@ TEST_CASE("maps with enum keys") SECTION("objects are only read for enum keys") { + // built rather than parsed, so that the messages do not gain a byte + // range with JSON_DIAGNOSTIC_POSITIONS + const json j = {{"1", 2}}; int_map im; int_umap ium; - CHECK_THROWS_WITH_AS(json::parse(R"({"1":2})").get_to(im), + CHECK_THROWS_WITH_AS(j.get_to(im), "[json.exception.type_error.302] type must be array, but is object", json::type_error&); - CHECK_THROWS_WITH_AS(json::parse(R"({"1":2})").get_to(ium), + CHECK_THROWS_WITH_AS(j.get_to(ium), "[json.exception.type_error.302] type must be array, but is object", json::type_error&); }