From ea72ffe0a3598a1e4a19f0f6e7a5b603e77f5ba6 Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Sun, 4 Oct 2026 18:10:17 +0200 Subject: [PATCH] Add tests for the with_*_t member alias templates Check with std::is_same that each with_*_t alias produces the expected basic_json type, and that with_string_t keeps nlohmann::ordered_map as the object type when used on ordered_json. Co-authored-by: Raphael Grimm <1005058+barcode@users.noreply.github.com> Signed-off-by: Niels Lohmann --- tests/src/unit-udt.cpp | 63 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/tests/src/unit-udt.cpp b/tests/src/unit-udt.cpp index 11d4940f4..f5d0ffc1e 100644 --- a/tests/src/unit-udt.cpp +++ b/tests/src/unit-udt.cpp @@ -23,6 +23,7 @@ using nlohmann::json; using namespace nlohmann::literals; // NOLINT(google-build-using-namespace) #endif +#include #include #include #include @@ -733,6 +734,68 @@ TEST_CASE("custom serializer that does adl by default" * doctest::test_suite("ud CHECK(me == cj.get()); } +TEST_CASE("with_*_t aliases" * doctest::test_suite("udt")) +{ + // a custom base class used to check with_base_class_t + struct custom_base_class {}; + + CHECK(std::is_same, + nlohmann::basic_json>>::value); + + CHECK(std::is_same, + nlohmann::basic_json>>::value); + + CHECK(std::is_same, + nlohmann::basic_json>>::value); + + CHECK(std::is_same, + nlohmann::basic_json>>::value); + + CHECK(std::is_same, + nlohmann::basic_json>>::value); + + CHECK(std::is_same, + nlohmann::basic_json>>::value); + + CHECK(std::is_same, + nlohmann::basic_json>>::value); + + CHECK(std::is_same, + nlohmann::basic_json>>::value); + + CHECK(std::is_same>, + nlohmann::basic_json>>::value); + + CHECK(std::is_same, + nlohmann::basic_json, custom_base_class>>::value); + + // with_string_t on ordered_json must keep ordered_map as the object type + CHECK(std::is_same, + nlohmann::basic_json>>::value); +} + TEST_CASE("different basic_json types conversions") { SECTION("null")