diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 52d46f618..3b3727085 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -445,8 +445,7 @@ json_test_add_test_for(src/unit-stream-bulk-scan.cpp # with other values of JSON_UBJSON_VALUELESS_ELEMENTS_PER_BYTE: 1 (the smallest), # 1000000 (so large that the budget cannot be reached), and the largest value of # a 64-bit integer (which saturates the limit already at the first byte, and is -# clamped to the largest std::size_t where that has 32 bits). The file does not -# mention JSON_HAS_CPP_, so only C++11 is built unless the standards are forced +# clamped to the largest std::size_t where that has 32 bits) json_test_set_test_options(test-ubjson_valueless_rate_1 COMPILE_DEFINITIONS JSON_UBJSON_VALUELESS_ELEMENTS_PER_BYTE=1 ) diff --git a/tests/src/unit-allocator.cpp b/tests/src/unit-allocator.cpp index 73693347f..7bebe8a81 100644 --- a/tests/src/unit-allocator.cpp +++ b/tests/src/unit-allocator.cpp @@ -6,6 +6,13 @@ // SPDX-FileCopyrightText: 2013-2026 Niels Lohmann // SPDX-License-Identifier: MIT +// cmake/test.cmake selects the C++ standard versions with which to build a +// unit test based on the presence of JSON_HAS_CPP_ macros. +// When using macros that are only defined for particular versions of the standard +// (e.g., JSON_HAS_FILESYSTEM for C++17 and up), please mention the corresponding +// version macro in a comment close by, like this: +// JSON_HAS_CPP_ (do not remove; see note at top of file) + #include "doctest_compatibility.h" #define JSON_TESTS_PRIVATE @@ -15,6 +22,7 @@ using nlohmann::json; #include #include #include +// JSON_HAS_CPP_20 (do not remove; see note at top of file) #if JSON_HAS_RANGES #include #endif diff --git a/tests/src/unit-class_parser.cpp b/tests/src/unit-class_parser.cpp index b015a87d0..c1a86ca5f 100644 --- a/tests/src/unit-class_parser.cpp +++ b/tests/src/unit-class_parser.cpp @@ -6,6 +6,13 @@ // SPDX-FileCopyrightText: 2013-2026 Niels Lohmann // SPDX-License-Identifier: MIT +// cmake/test.cmake selects the C++ standard versions with which to build a +// unit test based on the presence of JSON_HAS_CPP_ macros. +// When using macros that are only defined for particular versions of the standard +// (e.g., JSON_HAS_FILESYSTEM for C++17 and up), please mention the corresponding +// version macro in a comment close by, like this: +// JSON_HAS_CPP_ (do not remove; see note at top of file) + #include "doctest_compatibility.h" // capture whether JSON_STRICT_NUL_HANDLING was enabled on the command line @@ -517,6 +524,7 @@ TEST_CASE("parser class") CHECK(json::accept(u"[1]")); CHECK(json::parse(U"[1]") == json({1})); CHECK(json::accept(U"[1]")); + // JSON_HAS_CPP_20 (do not remove; see note at top of file) #if defined(__cpp_char8_t) CHECK(json::parse(u8"[1]") == json({1})); CHECK(json::accept(u8"[1]")); @@ -2502,7 +2510,7 @@ TEST_CASE("text of float tokens") std::vector result; std::copy_if(events.begin(), events.end(), std::back_inserter(result), [](const std::string & e) { - return e.compare(0, 13, "number_float(") == 0; + return e.compare(0, 13, "number_float(") == 0; // NOLINT(modernize-use-starts-ends-with): C++11 }); return result; }; @@ -3103,7 +3111,7 @@ TEST_CASE("object keys are delivered decoded and validated") std::vector keys; for (const auto& e : l.events) { - if (e.compare(0, 4, "key(") == 0) + if (e.compare(0, 4, "key(") == 0) // NOLINT(modernize-use-starts-ends-with): C++11 { keys.push_back(e.substr(4, e.size() - 5)); } diff --git a/tests/src/unit-custom-number-types.cpp b/tests/src/unit-custom-number-types.cpp index 58353d67e..7b0f05985 100644 --- a/tests/src/unit-custom-number-types.cpp +++ b/tests/src/unit-custom-number-types.cpp @@ -6,6 +6,13 @@ // SPDX-FileCopyrightText: 2013-2026 Niels Lohmann // SPDX-License-Identifier: MIT +// cmake/test.cmake selects the C++ standard versions with which to build a +// unit test based on the presence of JSON_HAS_CPP_ macros. +// When using macros that are only defined for particular versions of the standard +// (e.g., JSON_HAS_FILESYSTEM for C++17 and up), please mention the corresponding +// version macro in a comment close by, like this: +// JSON_HAS_CPP_ (do not remove; see note at top of file) + #include "doctest_compatibility.h" #include @@ -17,6 +24,7 @@ #include #include +// JSON_HAS_CPP_20 (do not remove; see note at top of file) #if JSON_HAS_THREE_WAY_COMPARISON #include #endif diff --git a/tests/src/unit-json_view_builder.cpp b/tests/src/unit-json_view_builder.cpp index fed2b7a19..60b7661af 100644 --- a/tests/src/unit-json_view_builder.cpp +++ b/tests/src/unit-json_view_builder.cpp @@ -6,6 +6,13 @@ // SPDX-FileCopyrightText: 2013-2026 Niels Lohmann // SPDX-License-Identifier: MIT +// cmake/test.cmake selects the C++ standard versions with which to build a +// unit test based on the presence of JSON_HAS_CPP_ macros. +// When using macros that are only defined for particular versions of the standard +// (e.g., JSON_HAS_FILESYSTEM for C++17 and up), please mention the corresponding +// version macro in a comment close by, like this: +// JSON_HAS_CPP_ (do not remove; see note at top of file) + #include "doctest_compatibility.h" #include @@ -272,6 +279,7 @@ struct generator TEST_CASE("json_view string_ref") { // std::string_view in C++17, a stand-in with the same members before + // JSON_HAS_CPP_17 (do not remove; see note at top of file) using nlohmann::detail::view::string_ref; const std::string text = "abc"; const string_ref r(text); @@ -945,7 +953,7 @@ TEST_CASE("json_view document_data::holds() (the debug check of read())") SECTION("current edit buffer") { - d->edits.reset(new document_data::edit_state()); // NOLINT(cppcoreguidelines-owning-memory) + d->edits.reset(new document_data::edit_state()); // NOLINT(cppcoreguidelines-owning-memory,modernize-make-unique) CHECK(!d->holds(other.data(), other.size())); d->edits->texts.emplace_back(new char[16]); // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays,cppcoreguidelines-owning-memory) d->edits->text_cap = 16; diff --git a/tests/src/unit-recursion_depth_limit.cpp b/tests/src/unit-recursion_depth_limit.cpp index 2869a7241..0757d42f1 100644 --- a/tests/src/unit-recursion_depth_limit.cpp +++ b/tests/src/unit-recursion_depth_limit.cpp @@ -6,6 +6,13 @@ // SPDX-FileCopyrightText: 2013-2026 Niels Lohmann // SPDX-License-Identifier: MIT +// cmake/test.cmake selects the C++ standard versions with which to build a +// unit test based on the presence of JSON_HAS_CPP_ macros. +// When using macros that are only defined for particular versions of the standard +// (e.g., JSON_HAS_FILESYSTEM for C++17 and up), please mention the corresponding +// version macro in a comment close by, like this: +// JSON_HAS_CPP_ (do not remove; see note at top of file) + #include "doctest_compatibility.h" #include @@ -348,6 +355,7 @@ static_assert(nlohmann::detail::recursion_depth_limit_is_char_or_bool::value, "wchar_t is refused"); static_assert(nlohmann::detail::recursion_depth_limit_is_char_or_bool::value, "char16_t is refused"); static_assert(nlohmann::detail::recursion_depth_limit_is_char_or_bool::value, "char32_t is refused"); +// JSON_HAS_CPP_20 (do not remove; see note at top of file) #if defined(__cpp_char8_t) static_assert(nlohmann::detail::recursion_depth_limit_is_char_or_bool::value, "char8_t is refused"); #endif diff --git a/tests/src/unit-to_json-rvalue.cpp b/tests/src/unit-to_json-rvalue.cpp index 4aabda5a1..7d27cf0c0 100644 --- a/tests/src/unit-to_json-rvalue.cpp +++ b/tests/src/unit-to_json-rvalue.cpp @@ -6,6 +6,13 @@ // SPDX-FileCopyrightText: 2013-2026 Niels Lohmann // SPDX-License-Identifier: MIT +// cmake/test.cmake selects the C++ standard versions with which to build a +// unit test based on the presence of JSON_HAS_CPP_ macros. +// When using macros that are only defined for particular versions of the standard +// (e.g., JSON_HAS_FILESYSTEM for C++17 and up), please mention the corresponding +// version macro in a comment close by, like this: +// JSON_HAS_CPP_ (do not remove; see note at top of file) + #include "doctest_compatibility.h" #include @@ -23,6 +30,7 @@ using nlohmann::json; #include #include +// JSON_HAS_CPP_17 (do not remove; see note at top of file) #if (defined(__cplusplus) && __cplusplus >= 201703L) || (defined(_HAS_CXX17) && _HAS_CXX17 == 1) #if __has_include() #include @@ -244,6 +252,7 @@ TEST_CASE("to_json from rvalue containers") SECTION("std::filesystem::path rvalue is still a string") { CHECK(json(std::filesystem::path("a/b")) == json("a/b")); + // JSON_HAS_CPP_20 (do not remove; see note at top of file) #ifdef __cpp_lib_char8_t CHECK(json(std::u8string(u8"a/b")) == json("a/b")); #endif diff --git a/tests/src/unit-ubjson_valueless.cpp b/tests/src/unit-ubjson_valueless.cpp index 5a6afdab9..2ceb3f99b 100644 --- a/tests/src/unit-ubjson_valueless.cpp +++ b/tests/src/unit-ubjson_valueless.cpp @@ -6,6 +6,13 @@ // SPDX-FileCopyrightText: 2013-2026 Niels Lohmann // SPDX-License-Identifier: MIT +// cmake/test.cmake selects the C++ standard versions with which to build a +// unit test based on the presence of JSON_HAS_CPP_ macros. +// When using macros that are only defined for particular versions of the standard +// (e.g., JSON_HAS_FILESYSTEM for C++17 and up), please mention the corresponding +// version macro in a comment close by, like this: +// JSON_HAS_CPP_ (do not remove; see note at top of file) + // The budget for the elements of the UBJSON containers of a valueless type // ('Z', 'T', 'F') of a whole input: 1048576 plus // JSON_UBJSON_VALUELESS_ELEMENTS_PER_BYTE for every byte read (see @@ -92,6 +99,7 @@ static_assert(nlohmann::detail::valueless_elements_rate_is_char_or_bool::value, "wchar_t is refused"); static_assert(nlohmann::detail::valueless_elements_rate_is_char_or_bool::value, "char16_t is refused"); static_assert(nlohmann::detail::valueless_elements_rate_is_char_or_bool::value, "char32_t is refused"); +// JSON_HAS_CPP_20 (do not remove; see note at top of file) #if defined(__cpp_char8_t) static_assert(nlohmann::detail::valueless_elements_rate_is_char_or_bool::value, "char8_t is refused"); #endif