Skip to content

Commit

Permalink
some fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
EfesX committed Jun 1, 2024
1 parent b1b47b8 commit d56a564
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 18 deletions.
4 changes: 2 additions & 2 deletions tests/src/unit-conversions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1263,7 +1263,7 @@ TEST_CASE("value conversion")
}
#endif

#if JSON_DISABLE_ENUM_SERIALIZATION != 0
#if JSON_DISABLE_ENUM_SERIALIZATION
SECTION("get an enum")
{
enum c_enum { value_1, value_2 };
Expand All @@ -1272,7 +1272,7 @@ TEST_CASE("value conversion")
CHECK(json(value_1).get<c_enum>() == value_1);
CHECK(json(cpp_enum::value_1).get<cpp_enum>() == cpp_enum::value_1);
}
#endif
#endif // JSON_DISABLE_ENUM_SERIALIZATION

SECTION("more involved conversions")
{
Expand Down
4 changes: 2 additions & 2 deletions tests/src/unit-noexcept.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ static_assert(noexcept(std::declval<json>().get<pod>()), "");
static_assert(!noexcept(std::declval<json>().get<pod_bis>()), "");
static_assert(noexcept(json(pod{})), "");

#if JSON_DISABLE_ENUM_SERIALIZATION != 0
#if JSON_DISABLE_ENUM_SERIALIZATION
static_assert(noexcept(nlohmann::to_json(std::declval<json&>(), test{})), "");
static_assert(noexcept(json(test{})), "");
#endif
#endif // JSON_DISABLE_ENUM_SERIALIZATION
} // namespace

TEST_CASE("noexcept")
Expand Down
4 changes: 2 additions & 2 deletions tests/src/unit-regression1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ TEST_CASE("regression tests 1")
}
}

#if JSON_DISABLE_ENUM_SERIALIZATION != 0
#if JSON_DISABLE_ENUM_SERIALIZATION
SECTION("pull request #71 - handle enum type")
{
enum { t = 0, u = 102};
Expand All @@ -192,7 +192,7 @@ TEST_CASE("regression tests 1")
{"game_type", t}
}));
}
#endif
#endif // JSON_DISABLE_ENUM_SERIALIZATION

SECTION("issue #76 - dump() / parse() not idempotent")
{
Expand Down
24 changes: 12 additions & 12 deletions tests/src/unit-udt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,12 @@ static void to_json(nlohmann::json& j, const contact& c)
j = json{{"person", c.m_person}, {"address", c.m_address}};
}

#if JSON_DISABLE_ENUM_SERIALIZATION != 0
#if JSON_DISABLE_ENUM_SERIALIZATION
static void to_json(nlohmann::json& j, const contact_book& cb)
{
j = json{{"name", cb.m_book_name}, {"id", cb.m_book_id}, {"contacts", cb.m_contacts}};
}
#endif
#endif // JSON_DISABLE_ENUM_SERIALIZATION

// operators
static bool operator==(age lhs, age rhs)
Expand Down Expand Up @@ -221,14 +221,14 @@ static void from_json(const nlohmann::json& j, contact& c)
c.m_address = j["address"].get<address>();
}

#if JSON_DISABLE_ENUM_SERIALIZATION != 0
#if JSON_DISABLE_ENUM_SERIALIZATION
static void from_json(const nlohmann::json& j, contact_book& cb)
{
cb.m_book_name = j["name"].get<name>();
cb.m_book_id = j["id"].get<book_id>();
cb.m_contacts = j["contacts"].get<std::vector<contact>>();
}
#endif
#endif // JSON_DISABLE_ENUM_SERIALIZATION
} // namespace udt

TEST_CASE("basic usage" * doctest::test_suite("udt"))
Expand Down Expand Up @@ -257,7 +257,7 @@ TEST_CASE("basic usage" * doctest::test_suite("udt"))
CHECK(json("Paris") == json(addr));
CHECK(json(cpp_programmer) ==
R"({"person" : {"age":23, "name":"theo", "country":"France"}, "address":"Paris"})"_json);
#if JSON_DISABLE_ENUM_SERIALIZATION != 0
#if JSON_DISABLE_ENUM_SERIALIZATION
CHECK(json(large_id) == json(static_cast<std::uint64_t>(1) << 63));
CHECK(json(large_id) > 0u);
CHECK(to_string(json(large_id)) == "9223372036854775808");
Expand All @@ -266,7 +266,7 @@ TEST_CASE("basic usage" * doctest::test_suite("udt"))
CHECK(
json(book) ==
R"({"name":"C++", "id":42, "contacts" : [{"person" : {"age":23, "name":"theo", "country":"France"}, "address":"Paris"}, {"person" : {"age":42, "country":"中华人民共和国", "name":"王芳"}, "address":"Paris"}]})"_json);
#endif
#endif // JSON_DISABLE_ENUM_SERIALIZATION
}

SECTION("conversion from json via free-functions")
Expand All @@ -275,11 +275,11 @@ TEST_CASE("basic usage" * doctest::test_suite("udt"))
R"({"name":"C++", "id":42, "contacts" : [{"person" : {"age":23, "name":"theo", "country":"France"}, "address":"Paris"}, {"person" : {"age":42, "country":"中华人民共和国", "name":"王芳"}, "address":"Paris"}]})"_json;
SECTION("via explicit calls to get")
{
#if JSON_DISABLE_ENUM_SERIALIZATION != 0
#if JSON_DISABLE_ENUM_SERIALIZATION
const auto parsed_book = big_json.get<udt::contact_book>();
const auto book_name = big_json["name"].get<udt::name>();
const auto book_id = big_json["id"].get<udt::book_id>();
#endif
#endif // JSON_DISABLE_ENUM_SERIALIZATION
const auto contacts =
big_json["contacts"].get<std::vector<udt::contact>>();
const auto contact_json = big_json["contacts"].at(0);
Expand All @@ -298,11 +298,11 @@ TEST_CASE("basic usage" * doctest::test_suite("udt"))
CHECK(person == sfinae_addict);
CHECK(contact == cpp_programmer);
CHECK(contacts == book.m_contacts);
#if JSON_DISABLE_ENUM_SERIALIZATION != 0
#if JSON_DISABLE_ENUM_SERIALIZATION
CHECK(book_name == udt::name{"C++"});
CHECK(book_id == book.m_book_id);
CHECK(book == parsed_book);
#endif
#endif // JSON_DISABLE_ENUM_SERIALIZATION
}

SECTION("via explicit calls to get_to")
Expand All @@ -317,7 +317,7 @@ TEST_CASE("basic usage" * doctest::test_suite("udt"))
person_json["name"].get_to(name).m_val = "new name";
CHECK(name.m_val == "new name");
}
#if JSON_DISABLE_ENUM_SERIALIZATION != 0
#if JSON_DISABLE_ENUM_SERIALIZATION
#if JSON_USE_IMPLICIT_CONVERSIONS
SECTION("implicit conversions")
{
Expand Down Expand Up @@ -347,7 +347,7 @@ TEST_CASE("basic usage" * doctest::test_suite("udt"))
CHECK(book == parsed_book);
}
#endif
#endif
#endif // JSON_DISABLE_ENUM_SERIALIZATION
}
}

Expand Down

0 comments on commit d56a564

Please sign in to comment.