1
0
mirror of https://github.com/nlohmann/json synced 2024-11-27 14:20:07 +00:00

🚨 fix warning

This commit is contained in:
Niels Lohmann 2024-04-15 22:50:47 +02:00
parent 3c282210d6
commit fd968125e8
No known key found for this signature in database
GPG Key ID: 7F3CEA63AE251B69
3 changed files with 14 additions and 0 deletions

View File

@ -39,7 +39,12 @@ TEST_CASE("Better diagnostics")
{
json j;
j["object"]["object"] = true;
#if defined(JSON_HAS_CPP_17)
CHECK_THROWS_WITH_AS(j["object"].at("not_found"), "[json.exception.out_of_range.403] (/object) key not found (key is an rvalue and cannot be shown)", json::out_of_range);
#else
CHECK_THROWS_WITH_AS(j["object"].at("not_found"), "[json.exception.out_of_range.403] (/object) key 'not_found' not found", json::out_of_range);
#endif
}
SECTION("array index out of range")

View File

@ -69,8 +69,13 @@ TEST_CASE_TEMPLATE("element access 2", Json, nlohmann::json, nlohmann::ordered_j
SECTION("access outside bounds")
{
#if defined(JSON_HAS_CPP_17)
CHECK_THROWS_WITH_AS(j.at("foo"), "[json.exception.out_of_range.403] key not found (key is an rvalue and cannot be shown)", typename Json::out_of_range&);
CHECK_THROWS_WITH_AS(j_const.at("foo"), "[json.exception.out_of_range.403] key not found (key is an rvalue and cannot be shown)", typename Json::out_of_range&);
#else
CHECK_THROWS_WITH_AS(j.at("foo"), "[json.exception.out_of_range.403] key 'foo' not found", typename Json::out_of_range&);
CHECK_THROWS_WITH_AS(j_const.at("foo"), "[json.exception.out_of_range.403] key 'foo' not found", typename Json::out_of_range&);
#endif
#ifdef JSON_HAS_CPP_17
CHECK_THROWS_WITH_AS(j.at(std::string_view("foo")), "[json.exception.out_of_range.403] key not found (key is an rvalue and cannot be shown)", typename Json::out_of_range&);

View File

@ -341,7 +341,11 @@ TEST_CASE_TEMPLATE("Serialization/deserialization via NLOHMANN_DEFINE_TYPE_INTRU
// check exception in case of missing field
json j = json(p1);
j.erase("age");
#if defined(JSON_HAS_CPP_17)
CHECK_THROWS_WITH_AS(j.get<T>(), "[json.exception.out_of_range.403] key not found (key is an rvalue and cannot be shown)", json::out_of_range);
#else
CHECK_THROWS_WITH_AS(j.get<T>(), "[json.exception.out_of_range.403] key 'age' not found", json::out_of_range);
#endif
}
}