mirror of
https://github.com/nlohmann/json.git
synced 2026-02-17 09:03:58 +00:00
Extend type_name() to invalid type (#4786)
* ✅ add regression test Signed-off-by: Niels Lohmann <mail@nlohmann.me> * 💚 fix build Signed-off-by: Niels Lohmann <mail@nlohmann.me> * 📝 add comment Signed-off-by: Niels Lohmann <mail@nlohmann.me> --------- Signed-off-by: Niels Lohmann <mail@nlohmann.me>
This commit is contained in:
@@ -1080,6 +1080,20 @@ TEST_CASE("regression tests 2")
|
||||
CHECK(t4.port.has_value());
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !defined(_MSVC_LANG)
|
||||
// MSVC returns garbage on invalid enum values, so this test is excluded
|
||||
// there.
|
||||
SECTION("issue #4762 - json exception 302 with unhelpful explanation : type must be number, but is number")
|
||||
{
|
||||
// In #4762, the main issue was that a json object with an invalid type
|
||||
// returned "number" as type_name(), because this was the default case.
|
||||
// This test makes sure we now return "invalid" instead.
|
||||
json j;
|
||||
j.m_data.m_type = static_cast<json::value_t>(100); // NOLINT(clang-analyzer-optin.core.EnumCastOutOfRange)
|
||||
CHECK(j.type_name() == "invalid");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
DOCTEST_CLANG_SUPPRESS_WARNING_POP
|
||||
|
||||
Reference in New Issue
Block a user