Skip to content

Commit

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

#if JSON_DISABLE_ENUM_SERIALIZATION != 0
SECTION("get an enum")
{
enum c_enum { value_1, value_2 };
Expand All @@ -1271,6 +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

SECTION("more involved conversions")
{
Expand Down
7 changes: 5 additions & 2 deletions tests/src/unit-noexcept.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,18 @@ static_assert(noexcept(json{}), "");
static_assert(noexcept(nlohmann::to_json(std::declval<json&>(), 2)), "");
static_assert(noexcept(nlohmann::to_json(std::declval<json&>(), 2.5)), "");
static_assert(noexcept(nlohmann::to_json(std::declval<json&>(), true)), "");
static_assert(noexcept(nlohmann::to_json(std::declval<json&>(), test{})), "");
static_assert(noexcept(nlohmann::to_json(std::declval<json&>(), pod{})), "");
static_assert(!noexcept(nlohmann::to_json(std::declval<json&>(), pod_bis{})), "");
static_assert(noexcept(json(2)), "");
static_assert(noexcept(json(test{})), "");
static_assert(noexcept(json(pod{})), "");
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
static_assert(noexcept(nlohmann::to_json(std::declval<json&>(), test{})), "");
static_assert(noexcept(json(test{})), "");
#endif
} // namespace

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

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

SECTION("issue #76 - dump() / parse() not idempotent")
{
Expand Down
16 changes: 14 additions & 2 deletions tests/src/unit-udt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +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
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

// operators
static bool operator==(age lhs, age rhs)
Expand Down Expand Up @@ -219,12 +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
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
} // namespace udt

TEST_CASE("basic usage" * doctest::test_suite("udt"))
Expand Down Expand Up @@ -253,6 +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
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 @@ -261,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
}

SECTION("conversion from json via free-functions")
Expand All @@ -270,9 +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
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
const auto contacts =
big_json["contacts"].get<std::vector<udt::contact>>();
const auto contact_json = big_json["contacts"].at(0);
Expand All @@ -291,9 +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
CHECK(book_name == udt::name{"C++"});
CHECK(book_id == book.m_book_id);
CHECK(book == parsed_book);
#endif
}

SECTION("via explicit calls to get_to")
Expand All @@ -308,11 +317,13 @@ 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_USE_IMPLICIT_CONVERSIONS
SECTION("implicit conversions")
{

const udt::contact_book parsed_book = big_json;

const udt::name book_name = big_json["name"];
const udt::book_id book_id = big_json["id"];
const std::vector<udt::contact> contacts = big_json["contacts"];
Expand All @@ -335,6 +346,7 @@ TEST_CASE("basic usage" * doctest::test_suite("udt"))
CHECK(book_id == static_cast<udt::book_id>(42u));
CHECK(book == parsed_book);
}
#endif
#endif
}
}
Expand Down

0 comments on commit b1b47b8

Please sign in to comment.