Skip to content

Commit

Permalink
🚨 fix warning
Browse files Browse the repository at this point in the history
  • Loading branch information
nlohmann committed Apr 15, 2024
1 parent 3c28221 commit fd96812
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
5 changes: 5 additions & 0 deletions tests/src/unit-diagnostics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
5 changes: 5 additions & 0 deletions tests/src/unit-element_access2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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&);
Expand Down
4 changes: 4 additions & 0 deletions tests/src/unit-udt_macro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down

0 comments on commit fd96812

Please sign in to comment.