Moved test for #1647 regression to regressions file.

This commit is contained in:
Anthony VH 2019-11-04 20:45:24 +01:00
parent ddda67a096
commit ec9647ae63
2 changed files with 38 additions and 25 deletions

View File

@ -1537,31 +1537,6 @@ NLOHMANN_JSON_SERIALIZE_ENUM(TaskState,
{TS_COMPLETED, "completed"},
})
namespace
{
// Helper struct to test whether compile error does not trigger upon
// conversion of an enum in the presence of non-member operator== for
// user-defined type with "non default" from_json function (#1647).
struct NonDefaultFromJsonStruct { };
inline bool operator== (NonDefaultFromJsonStruct const& lhs, NonDefaultFromJsonStruct const& rhs)
{
return true;
}
}
namespace nlohmann
{
template <>
struct adl_serializer<NonDefaultFromJsonStruct>
{
static NonDefaultFromJsonStruct from_json (json const& j)
{
return {};
}
};
}
TEST_CASE("JSON to enum mapping")
{
SECTION("enum class")

View File

@ -159,6 +159,38 @@ bool operator==(Data const& lhs, Data const& rhs)
using float_json = nlohmann::basic_json<std::map, std::vector, std::string, bool, std::int64_t, std::uint64_t, float>;
/////////////////////////////////////////////////////////////////////
// for #1647
/////////////////////////////////////////////////////////////////////
namespace
{
struct NonDefaultFromJsonStruct { };
inline bool operator== (NonDefaultFromJsonStruct const& lhs, NonDefaultFromJsonStruct const& rhs)
{
return true;
}
enum class for_1647 { one, two };
NLOHMANN_JSON_SERIALIZE_ENUM(for_1647,
{
{for_1647::one, "one"},
{for_1647::two, "two"},
})
}
namespace nlohmann
{
template <>
struct adl_serializer<NonDefaultFromJsonStruct>
{
static NonDefaultFromJsonStruct from_json (json const& j)
{
return {};
}
};
}
TEST_CASE("regression tests")
{
@ -1820,6 +1852,12 @@ TEST_CASE("regression tests")
CHECK(j.contains(jptr1));
CHECK(j.contains(jptr2));
}
SECTION("issue #1647 - compile error when deserializing enum if both non-default from_json and non-member operator== exists for other type")
{
auto val = nlohmann::json("one").get<for_1647>();
CHECK(val == for_1647::one);
}
}
#if not defined(JSON_NOEXCEPTION)