From 07cbbc548a5ec57eb9eda729a7abd60e699e2531 Mon Sep 17 00:00:00 2001 From: Florian Albrechtskirchinger Date: Fri, 5 Aug 2022 17:20:49 +0200 Subject: [PATCH] Add type_traits unit test --- tests/src/unit-type_traits.cpp | 56 ++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 tests/src/unit-type_traits.cpp diff --git a/tests/src/unit-type_traits.cpp b/tests/src/unit-type_traits.cpp new file mode 100644 index 000000000..3be8e98a9 --- /dev/null +++ b/tests/src/unit-type_traits.cpp @@ -0,0 +1,56 @@ +// __ _____ _____ _____ +// __| | __| | | | JSON for Modern C++ (supporting code) +// | | |__ | | | | | | version 3.11.1 +// |_____|_____|_____|_|___| https://github.com/nlohmann/json +// +// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann +// SPDX-License-Identifier: MIT + +#include "doctest_compatibility.h" + +#if JSON_TEST_USING_MULTIPLE_HEADERS + #include +#else + #include +#endif + +TEST_CASE("type traits") +{ + SECTION("is_c_string") + { + using nlohmann::detail::is_c_string; + using nlohmann::detail::is_c_string_uncvref; + + SECTION("char *") + { + CHECK(is_c_string::value); + CHECK(is_c_string::value); + CHECK(is_c_string::value); + CHECK(is_c_string::value); + + CHECK_FALSE(is_c_string::value); + CHECK_FALSE(is_c_string::value); + CHECK_FALSE(is_c_string::value); + CHECK_FALSE(is_c_string::value); + + CHECK(is_c_string_uncvref::value); + CHECK(is_c_string_uncvref::value); + CHECK(is_c_string_uncvref::value); + CHECK(is_c_string_uncvref::value); + } + + SECTION("char[]") + { + // NOLINTBEGIN(hicpp-avoid-c-arrays,modernize-avoid-c-arrays,cppcoreguidelines-avoid-c-arrays) + CHECK(is_c_string::value); + CHECK(is_c_string::value); + + CHECK_FALSE(is_c_string::value); + CHECK_FALSE(is_c_string::value); + + CHECK(is_c_string_uncvref::value); + CHECK(is_c_string_uncvref::value); + // NOLINTEND(hicpp-avoid-c-arrays,modernize-avoid-c-arrays,cppcoreguidelines-avoid-c-arrays) + } + } +}