From abd3c275d1960afef9d4caa9ef3186c60ae5ebd8 Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Sat, 24 Oct 2026 15:37:05 +0200 Subject: [PATCH] Expect the element path in the std::array type-error tests with JSON_DIAGNOSTICS Signed-off-by: Niels Lohmann --- tests/src/unit-constructor1.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/tests/src/unit-constructor1.cpp b/tests/src/unit-constructor1.cpp index 4d29ff4d3..96a64e721 100644 --- a/tests/src/unit-constructor1.cpp +++ b/tests/src/unit-constructor1.cpp @@ -361,13 +361,23 @@ TEST_CASE("constructors") CHECK_THROWS_WITH_AS((j.get>()), "[json.exception.out_of_range.401] array index 1 is out of range", json::out_of_range&); CHECK_THROWS_WITH_AS((j.get>()), "[json.exception.out_of_range.401] array index 1 is out of range", json::out_of_range&); CHECK_THROWS_WITH_AS((j.get>()), "[json.exception.out_of_range.401] array index 1 is out of range", json::out_of_range&); +#if JSON_DIAGNOSTICS + // the exception names the element that has the wrong type + CHECK_THROWS_WITH_AS((j.get>()), "[json.exception.type_error.302] (/0) type must be string, but is number", json::type_error&); +#else CHECK_THROWS_WITH_AS((j.get>()), "[json.exception.type_error.302] type must be string, but is number", json::type_error&); +#endif // the elements are converted in order, so a type error comes before a missing element json const j2{1, "two"}; - CHECK_THROWS_WITH_AS((j2.get>()), "[json.exception.type_error.302] type must be number, but is string", json::type_error&); std::array a{{0, 0, 0}}; +#if JSON_DIAGNOSTICS + CHECK_THROWS_WITH_AS((j2.get>()), "[json.exception.type_error.302] (/1) type must be number, but is string", json::type_error&); + CHECK_THROWS_WITH_AS(j2.get_to(a), "[json.exception.type_error.302] (/1) type must be number, but is string", json::type_error&); +#else + CHECK_THROWS_WITH_AS((j2.get>()), "[json.exception.type_error.302] type must be number, but is string", json::type_error&); CHECK_THROWS_WITH_AS(j2.get_to(a), "[json.exception.type_error.302] type must be number, but is string", json::type_error&); +#endif CHECK_THROWS_WITH_AS(j.get_to(a), "[json.exception.out_of_range.401] array index 1 is out of range", json::out_of_range&); #if !defined(JSON_NOEXCEPTION) // without exceptions, the get_to calls in CHECK_THROWS_WITH_AS do not run CHECK(a[0] == 1);