mirror of
https://github.com/nlohmann/json.git
synced 2024-11-23 22:19:02 +08:00
Skip enum tests when JSON_DisableEnumSerialization=ON (#4504)
Some checks failed
Code scanning - action / CodeQL-Build (push) Has been cancelled
macOS / macos-12 (13.1) (push) Has been cancelled
macOS / macos-12 (13.2.1) (push) Has been cancelled
macOS / macos-12 (13.3.1) (push) Has been cancelled
macOS / macos-12 (13.4.1) (push) Has been cancelled
macOS / macos-12 (14.0) (push) Has been cancelled
macOS / macos-12 (14.0.1) (push) Has been cancelled
macOS / macos-12 (14.1) (push) Has been cancelled
macOS / macos-13 (14.2) (push) Has been cancelled
macOS / macos-13 (14.3) (push) Has been cancelled
macOS / macos-13 (14.3.1) (push) Has been cancelled
macOS / macos-13 (15.0.1) (push) Has been cancelled
macOS / macos-13 (15.1) (push) Has been cancelled
macOS / macos-13 (15.2) (push) Has been cancelled
macOS / macos-14 (15.3) (push) Has been cancelled
macOS / macos-14 (15.4) (push) Has been cancelled
macOS / macos-15 (16.0) (push) Has been cancelled
macOS / macos-15 (16.1) (push) Has been cancelled
macOS / xcode_standards (11) (push) Has been cancelled
macOS / xcode_standards (14) (push) Has been cancelled
macOS / xcode_standards (17) (push) Has been cancelled
macOS / xcode_standards (20) (push) Has been cancelled
macOS / xcode_standards (23) (push) Has been cancelled
Ubuntu / ci_test_clang (push) Has been cancelled
Ubuntu / ci_test_gcc (push) Has been cancelled
Ubuntu / ci_static_analysis (ci_cppcheck) (push) Has been cancelled
Ubuntu / ci_static_analysis (ci_infer) (push) Has been cancelled
Ubuntu / ci_static_analysis (ci_single_binaries) (push) Has been cancelled
Ubuntu / ci_static_analysis (ci_test_amalgamation) (push) Has been cancelled
Ubuntu / ci_static_analysis (ci_test_single_header) (push) Has been cancelled
Ubuntu / ci_static_analysis (ci_test_valgrind) (push) Has been cancelled
Ubuntu / ci_static_analysis_ubuntu (ci_cpplint) (push) Has been cancelled
Ubuntu / ci_static_analysis_ubuntu (ci_non_git_tests) (push) Has been cancelled
Ubuntu / ci_static_analysis_ubuntu (ci_offline_testdata) (push) Has been cancelled
Ubuntu / ci_static_analysis_ubuntu (ci_reproducible_tests) (push) Has been cancelled
Ubuntu / ci_static_analysis_clang (ci_clang_analyze) (push) Has been cancelled
Ubuntu / ci_static_analysis_clang (ci_clang_tidy) (push) Has been cancelled
Ubuntu / ci_static_analysis_clang (ci_test_clang_sanitizer) (push) Has been cancelled
Ubuntu / ci_cmake_options (ci_cmake_flags) (push) Has been cancelled
Ubuntu / ci_cmake_options (ci_test_diagnostics) (push) Has been cancelled
Ubuntu / ci_cmake_options (ci_test_legacycomparison) (push) Has been cancelled
Ubuntu / ci_cmake_options (ci_test_noexceptions) (push) Has been cancelled
Ubuntu / ci_cmake_options (ci_test_noglobaludls) (push) Has been cancelled
Ubuntu / ci_cmake_options (ci_test_noimplicitconversions) (push) Has been cancelled
Ubuntu / ci_test_coverage (push) Has been cancelled
Ubuntu / ci_test_compilers_gcc_old (4.8) (push) Has been cancelled
Ubuntu / ci_test_compilers_gcc_old (4.9) (push) Has been cancelled
Ubuntu / ci_test_compilers_gcc_old (5) (push) Has been cancelled
Ubuntu / ci_test_compilers_gcc_old (6) (push) Has been cancelled
Ubuntu / ci_test_compilers_gcc (10) (push) Has been cancelled
Ubuntu / ci_test_compilers_gcc (11) (push) Has been cancelled
Ubuntu / ci_test_compilers_gcc (12) (push) Has been cancelled
Ubuntu / ci_test_compilers_gcc (13) (push) Has been cancelled
Ubuntu / ci_test_compilers_gcc (14) (push) Has been cancelled
Ubuntu / ci_test_compilers_gcc (7) (push) Has been cancelled
Ubuntu / ci_test_compilers_gcc (8) (push) Has been cancelled
Ubuntu / ci_test_compilers_gcc (9) (push) Has been cancelled
Ubuntu / ci_test_compilers_gcc (latest) (push) Has been cancelled
Ubuntu / ci_test_compilers_clang (10) (push) Has been cancelled
Ubuntu / ci_test_compilers_clang (11) (push) Has been cancelled
Ubuntu / ci_test_compilers_clang (12) (push) Has been cancelled
Ubuntu / ci_test_compilers_clang (13) (push) Has been cancelled
Ubuntu / ci_test_compilers_clang (14) (push) Has been cancelled
Ubuntu / ci_test_compilers_clang (15-bullseye) (push) Has been cancelled
Ubuntu / ci_test_compilers_clang (16) (push) Has been cancelled
Ubuntu / ci_test_compilers_clang (17) (push) Has been cancelled
Ubuntu / ci_test_compilers_clang (18) (push) Has been cancelled
Ubuntu / ci_test_compilers_clang (19) (push) Has been cancelled
Ubuntu / ci_test_compilers_clang (3.5) (push) Has been cancelled
Ubuntu / ci_test_compilers_clang (3.6) (push) Has been cancelled
Ubuntu / ci_test_compilers_clang (3.7) (push) Has been cancelled
Ubuntu / ci_test_compilers_clang (3.8) (push) Has been cancelled
Ubuntu / ci_test_compilers_clang (3.9) (push) Has been cancelled
Ubuntu / ci_test_compilers_clang (4) (push) Has been cancelled
Ubuntu / ci_test_compilers_clang (5) (push) Has been cancelled
Ubuntu / ci_test_compilers_clang (6) (push) Has been cancelled
Ubuntu / ci_test_compilers_clang (7) (push) Has been cancelled
Ubuntu / ci_test_compilers_clang (8) (push) Has been cancelled
Ubuntu / ci_test_compilers_clang (9) (push) Has been cancelled
Ubuntu / ci_test_compilers_clang (latest) (push) Has been cancelled
Ubuntu / ci_test_compilers (g++-4.8) (push) Has been cancelled
Ubuntu / ci_test_standards_gcc (11) (push) Has been cancelled
Ubuntu / ci_test_standards_gcc (14) (push) Has been cancelled
Ubuntu / ci_test_standards_gcc (17) (push) Has been cancelled
Ubuntu / ci_test_standards_gcc (20) (push) Has been cancelled
Ubuntu / ci_test_standards_gcc (23) (push) Has been cancelled
Ubuntu / ci_test_standards_clang (11, libcxx) (push) Has been cancelled
Ubuntu / ci_test_standards_clang (11, libstdcxx) (push) Has been cancelled
Ubuntu / ci_test_standards_clang (14, libcxx) (push) Has been cancelled
Ubuntu / ci_test_standards_clang (14, libstdcxx) (push) Has been cancelled
Ubuntu / ci_test_standards_clang (17, libcxx) (push) Has been cancelled
Ubuntu / ci_test_standards_clang (17, libstdcxx) (push) Has been cancelled
Ubuntu / ci_test_standards_clang (20, libcxx) (push) Has been cancelled
Ubuntu / ci_test_standards_clang (20, libstdcxx) (push) Has been cancelled
Ubuntu / ci_test_standards_clang (23, libcxx) (push) Has been cancelled
Ubuntu / ci_test_standards_clang (23, libstdcxx) (push) Has been cancelled
Ubuntu / ci_cuda_example (push) Has been cancelled
Ubuntu / ci_icpc (push) Has been cancelled
Ubuntu / ci_reuse_compliance (push) Has been cancelled
Ubuntu / ci_test_documentation (ci_test_api_documentation) (push) Has been cancelled
Ubuntu / ci_test_documentation (ci_test_examples) (push) Has been cancelled
Windows / mingw (x64) (push) Has been cancelled
Windows / mingw (x86) (push) Has been cancelled
Windows / msvc2019 (Win32, Debug) (push) Has been cancelled
Windows / msvc2019 (Win32, Release) (push) Has been cancelled
Windows / msvc2019 (x64, Debug) (push) Has been cancelled
Windows / msvc2019 (x64, Release) (push) Has been cancelled
Windows / msvc2019_latest (push) Has been cancelled
Windows / msvc2022 (Win32, Debug) (push) Has been cancelled
Windows / msvc2022 (Win32, Release) (push) Has been cancelled
Windows / msvc2022 (x64, Debug) (push) Has been cancelled
Windows / msvc2022 (x64, Release) (push) Has been cancelled
Windows / msvc2022_latest (push) Has been cancelled
Windows / clang (11) (push) Has been cancelled
Windows / clang (12) (push) Has been cancelled
Windows / clang (13) (push) Has been cancelled
Windows / clang (14) (push) Has been cancelled
Windows / clang (15) (push) Has been cancelled
Windows / clang-cl-11 (Win32) (push) Has been cancelled
Windows / clang-cl-11 (x64) (push) Has been cancelled
Some checks failed
Code scanning - action / CodeQL-Build (push) Has been cancelled
macOS / macos-12 (13.1) (push) Has been cancelled
macOS / macos-12 (13.2.1) (push) Has been cancelled
macOS / macos-12 (13.3.1) (push) Has been cancelled
macOS / macos-12 (13.4.1) (push) Has been cancelled
macOS / macos-12 (14.0) (push) Has been cancelled
macOS / macos-12 (14.0.1) (push) Has been cancelled
macOS / macos-12 (14.1) (push) Has been cancelled
macOS / macos-13 (14.2) (push) Has been cancelled
macOS / macos-13 (14.3) (push) Has been cancelled
macOS / macos-13 (14.3.1) (push) Has been cancelled
macOS / macos-13 (15.0.1) (push) Has been cancelled
macOS / macos-13 (15.1) (push) Has been cancelled
macOS / macos-13 (15.2) (push) Has been cancelled
macOS / macos-14 (15.3) (push) Has been cancelled
macOS / macos-14 (15.4) (push) Has been cancelled
macOS / macos-15 (16.0) (push) Has been cancelled
macOS / macos-15 (16.1) (push) Has been cancelled
macOS / xcode_standards (11) (push) Has been cancelled
macOS / xcode_standards (14) (push) Has been cancelled
macOS / xcode_standards (17) (push) Has been cancelled
macOS / xcode_standards (20) (push) Has been cancelled
macOS / xcode_standards (23) (push) Has been cancelled
Ubuntu / ci_test_clang (push) Has been cancelled
Ubuntu / ci_test_gcc (push) Has been cancelled
Ubuntu / ci_static_analysis (ci_cppcheck) (push) Has been cancelled
Ubuntu / ci_static_analysis (ci_infer) (push) Has been cancelled
Ubuntu / ci_static_analysis (ci_single_binaries) (push) Has been cancelled
Ubuntu / ci_static_analysis (ci_test_amalgamation) (push) Has been cancelled
Ubuntu / ci_static_analysis (ci_test_single_header) (push) Has been cancelled
Ubuntu / ci_static_analysis (ci_test_valgrind) (push) Has been cancelled
Ubuntu / ci_static_analysis_ubuntu (ci_cpplint) (push) Has been cancelled
Ubuntu / ci_static_analysis_ubuntu (ci_non_git_tests) (push) Has been cancelled
Ubuntu / ci_static_analysis_ubuntu (ci_offline_testdata) (push) Has been cancelled
Ubuntu / ci_static_analysis_ubuntu (ci_reproducible_tests) (push) Has been cancelled
Ubuntu / ci_static_analysis_clang (ci_clang_analyze) (push) Has been cancelled
Ubuntu / ci_static_analysis_clang (ci_clang_tidy) (push) Has been cancelled
Ubuntu / ci_static_analysis_clang (ci_test_clang_sanitizer) (push) Has been cancelled
Ubuntu / ci_cmake_options (ci_cmake_flags) (push) Has been cancelled
Ubuntu / ci_cmake_options (ci_test_diagnostics) (push) Has been cancelled
Ubuntu / ci_cmake_options (ci_test_legacycomparison) (push) Has been cancelled
Ubuntu / ci_cmake_options (ci_test_noexceptions) (push) Has been cancelled
Ubuntu / ci_cmake_options (ci_test_noglobaludls) (push) Has been cancelled
Ubuntu / ci_cmake_options (ci_test_noimplicitconversions) (push) Has been cancelled
Ubuntu / ci_test_coverage (push) Has been cancelled
Ubuntu / ci_test_compilers_gcc_old (4.8) (push) Has been cancelled
Ubuntu / ci_test_compilers_gcc_old (4.9) (push) Has been cancelled
Ubuntu / ci_test_compilers_gcc_old (5) (push) Has been cancelled
Ubuntu / ci_test_compilers_gcc_old (6) (push) Has been cancelled
Ubuntu / ci_test_compilers_gcc (10) (push) Has been cancelled
Ubuntu / ci_test_compilers_gcc (11) (push) Has been cancelled
Ubuntu / ci_test_compilers_gcc (12) (push) Has been cancelled
Ubuntu / ci_test_compilers_gcc (13) (push) Has been cancelled
Ubuntu / ci_test_compilers_gcc (14) (push) Has been cancelled
Ubuntu / ci_test_compilers_gcc (7) (push) Has been cancelled
Ubuntu / ci_test_compilers_gcc (8) (push) Has been cancelled
Ubuntu / ci_test_compilers_gcc (9) (push) Has been cancelled
Ubuntu / ci_test_compilers_gcc (latest) (push) Has been cancelled
Ubuntu / ci_test_compilers_clang (10) (push) Has been cancelled
Ubuntu / ci_test_compilers_clang (11) (push) Has been cancelled
Ubuntu / ci_test_compilers_clang (12) (push) Has been cancelled
Ubuntu / ci_test_compilers_clang (13) (push) Has been cancelled
Ubuntu / ci_test_compilers_clang (14) (push) Has been cancelled
Ubuntu / ci_test_compilers_clang (15-bullseye) (push) Has been cancelled
Ubuntu / ci_test_compilers_clang (16) (push) Has been cancelled
Ubuntu / ci_test_compilers_clang (17) (push) Has been cancelled
Ubuntu / ci_test_compilers_clang (18) (push) Has been cancelled
Ubuntu / ci_test_compilers_clang (19) (push) Has been cancelled
Ubuntu / ci_test_compilers_clang (3.5) (push) Has been cancelled
Ubuntu / ci_test_compilers_clang (3.6) (push) Has been cancelled
Ubuntu / ci_test_compilers_clang (3.7) (push) Has been cancelled
Ubuntu / ci_test_compilers_clang (3.8) (push) Has been cancelled
Ubuntu / ci_test_compilers_clang (3.9) (push) Has been cancelled
Ubuntu / ci_test_compilers_clang (4) (push) Has been cancelled
Ubuntu / ci_test_compilers_clang (5) (push) Has been cancelled
Ubuntu / ci_test_compilers_clang (6) (push) Has been cancelled
Ubuntu / ci_test_compilers_clang (7) (push) Has been cancelled
Ubuntu / ci_test_compilers_clang (8) (push) Has been cancelled
Ubuntu / ci_test_compilers_clang (9) (push) Has been cancelled
Ubuntu / ci_test_compilers_clang (latest) (push) Has been cancelled
Ubuntu / ci_test_compilers (g++-4.8) (push) Has been cancelled
Ubuntu / ci_test_standards_gcc (11) (push) Has been cancelled
Ubuntu / ci_test_standards_gcc (14) (push) Has been cancelled
Ubuntu / ci_test_standards_gcc (17) (push) Has been cancelled
Ubuntu / ci_test_standards_gcc (20) (push) Has been cancelled
Ubuntu / ci_test_standards_gcc (23) (push) Has been cancelled
Ubuntu / ci_test_standards_clang (11, libcxx) (push) Has been cancelled
Ubuntu / ci_test_standards_clang (11, libstdcxx) (push) Has been cancelled
Ubuntu / ci_test_standards_clang (14, libcxx) (push) Has been cancelled
Ubuntu / ci_test_standards_clang (14, libstdcxx) (push) Has been cancelled
Ubuntu / ci_test_standards_clang (17, libcxx) (push) Has been cancelled
Ubuntu / ci_test_standards_clang (17, libstdcxx) (push) Has been cancelled
Ubuntu / ci_test_standards_clang (20, libcxx) (push) Has been cancelled
Ubuntu / ci_test_standards_clang (20, libstdcxx) (push) Has been cancelled
Ubuntu / ci_test_standards_clang (23, libcxx) (push) Has been cancelled
Ubuntu / ci_test_standards_clang (23, libstdcxx) (push) Has been cancelled
Ubuntu / ci_cuda_example (push) Has been cancelled
Ubuntu / ci_icpc (push) Has been cancelled
Ubuntu / ci_reuse_compliance (push) Has been cancelled
Ubuntu / ci_test_documentation (ci_test_api_documentation) (push) Has been cancelled
Ubuntu / ci_test_documentation (ci_test_examples) (push) Has been cancelled
Windows / mingw (x64) (push) Has been cancelled
Windows / mingw (x86) (push) Has been cancelled
Windows / msvc2019 (Win32, Debug) (push) Has been cancelled
Windows / msvc2019 (Win32, Release) (push) Has been cancelled
Windows / msvc2019 (x64, Debug) (push) Has been cancelled
Windows / msvc2019 (x64, Release) (push) Has been cancelled
Windows / msvc2019_latest (push) Has been cancelled
Windows / msvc2022 (Win32, Debug) (push) Has been cancelled
Windows / msvc2022 (Win32, Release) (push) Has been cancelled
Windows / msvc2022 (x64, Debug) (push) Has been cancelled
Windows / msvc2022 (x64, Release) (push) Has been cancelled
Windows / msvc2022_latest (push) Has been cancelled
Windows / clang (11) (push) Has been cancelled
Windows / clang (12) (push) Has been cancelled
Windows / clang (13) (push) Has been cancelled
Windows / clang (14) (push) Has been cancelled
Windows / clang (15) (push) Has been cancelled
Windows / clang-cl-11 (Win32) (push) Has been cancelled
Windows / clang-cl-11 (x64) (push) Has been cancelled
* ✅ skip enum tests when JSON_DisableEnumSerialization=ON * ✅ skip enum tests when JSON_DisableEnumSerialization=ON
This commit is contained in:
parent
f9f8c07792
commit
a97041a98f
@ -40,7 +40,7 @@ endif()
|
|||||||
option(JSON_BuildTests "Build the unit tests when BUILD_TESTING is enabled." ${JSON_BuildTests_INIT})
|
option(JSON_BuildTests "Build the unit tests when BUILD_TESTING is enabled." ${JSON_BuildTests_INIT})
|
||||||
option(JSON_CI "Enable CI build targets." OFF)
|
option(JSON_CI "Enable CI build targets." OFF)
|
||||||
option(JSON_Diagnostics "Use extended diagnostic messages." OFF)
|
option(JSON_Diagnostics "Use extended diagnostic messages." OFF)
|
||||||
option(JSON_GlobalUDLs "Place use-defined string literals in the global namespace." ON)
|
option(JSON_GlobalUDLs "Place user-defined string literals in the global namespace." ON)
|
||||||
option(JSON_ImplicitConversions "Enable implicit conversions." ON)
|
option(JSON_ImplicitConversions "Enable implicit conversions." ON)
|
||||||
option(JSON_DisableEnumSerialization "Disable default integer enum serialization." OFF)
|
option(JSON_DisableEnumSerialization "Disable default integer enum serialization." OFF)
|
||||||
option(JSON_LegacyDiscardedValueComparison "Enable legacy discarded value comparison." OFF)
|
option(JSON_LegacyDiscardedValueComparison "Enable legacy discarded value comparison." OFF)
|
||||||
@ -96,6 +96,10 @@ if (JSON_Diagnostics)
|
|||||||
message(STATUS "Diagnostics enabled")
|
message(STATUS "Diagnostics enabled")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
if (NOT JSON_GlobalUDLs)
|
||||||
|
message(STATUS "User-defined string literals are not put in the global namespace")
|
||||||
|
endif()
|
||||||
|
|
||||||
if (JSON_SystemInclude)
|
if (JSON_SystemInclude)
|
||||||
set(NLOHMANN_JSON_SYSTEM_INCLUDE "SYSTEM")
|
set(NLOHMANN_JSON_SYSTEM_INCLUDE "SYSTEM")
|
||||||
endif()
|
endif()
|
||||||
|
@ -16,6 +16,11 @@
|
|||||||
|
|
||||||
#include "doctest_compatibility.h"
|
#include "doctest_compatibility.h"
|
||||||
|
|
||||||
|
// skip tests if JSON_DisableEnumSerialization=ON (#4384)
|
||||||
|
#if defined(JSON_DISABLE_ENUM_SERIALIZATION) && (JSON_DISABLE_ENUM_SERIALIZATION == 1)
|
||||||
|
#define SKIP_TESTS_FOR_ENUM_SERIALIZATION
|
||||||
|
#endif
|
||||||
|
|
||||||
#define JSON_TESTS_PRIVATE
|
#define JSON_TESTS_PRIVATE
|
||||||
#include <nlohmann/json.hpp>
|
#include <nlohmann/json.hpp>
|
||||||
using nlohmann::json;
|
using nlohmann::json;
|
||||||
@ -1284,6 +1289,7 @@ TEST_CASE("value conversion")
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef SKIP_TESTS_FOR_ENUM_SERIALIZATION
|
||||||
SECTION("get an enum")
|
SECTION("get an enum")
|
||||||
{
|
{
|
||||||
enum c_enum { value_1, value_2 };
|
enum c_enum { value_1, value_2 };
|
||||||
@ -1292,6 +1298,7 @@ TEST_CASE("value conversion")
|
|||||||
CHECK(json(value_1).get<c_enum>() == value_1);
|
CHECK(json(value_1).get<c_enum>() == value_1);
|
||||||
CHECK(json(cpp_enum::value_1).get<cpp_enum>() == cpp_enum::value_1);
|
CHECK(json(cpp_enum::value_1).get<cpp_enum>() == cpp_enum::value_1);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
SECTION("more involved conversions")
|
SECTION("more involved conversions")
|
||||||
{
|
{
|
||||||
|
@ -12,6 +12,11 @@
|
|||||||
DOCTEST_GCC_SUPPRESS_WARNING_PUSH
|
DOCTEST_GCC_SUPPRESS_WARNING_PUSH
|
||||||
DOCTEST_GCC_SUPPRESS_WARNING("-Wnoexcept")
|
DOCTEST_GCC_SUPPRESS_WARNING("-Wnoexcept")
|
||||||
|
|
||||||
|
// skip tests if JSON_DisableEnumSerialization=ON (#4384)
|
||||||
|
#if defined(JSON_DISABLE_ENUM_SERIALIZATION) && (JSON_DISABLE_ENUM_SERIALIZATION == 1)
|
||||||
|
#define SKIP_TESTS_FOR_ENUM_SERIALIZATION
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <nlohmann/json.hpp>
|
#include <nlohmann/json.hpp>
|
||||||
|
|
||||||
using nlohmann::json;
|
using nlohmann::json;
|
||||||
@ -36,11 +41,15 @@ static_assert(noexcept(json{}), "");
|
|||||||
static_assert(noexcept(nlohmann::to_json(std::declval<json&>(), 2)), "");
|
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&>(), 2.5)), "");
|
||||||
static_assert(noexcept(nlohmann::to_json(std::declval<json&>(), true)), "");
|
static_assert(noexcept(nlohmann::to_json(std::declval<json&>(), true)), "");
|
||||||
|
#ifndef SKIP_TESTS_FOR_ENUM_SERIALIZATION
|
||||||
static_assert(noexcept(nlohmann::to_json(std::declval<json&>(), test {})), "");
|
static_assert(noexcept(nlohmann::to_json(std::declval<json&>(), test {})), "");
|
||||||
|
#endif
|
||||||
static_assert(noexcept(nlohmann::to_json(std::declval<json&>(), pod {})), "");
|
static_assert(noexcept(nlohmann::to_json(std::declval<json&>(), pod {})), "");
|
||||||
static_assert(!noexcept(nlohmann::to_json(std::declval<json&>(), pod_bis{})), "");
|
static_assert(!noexcept(nlohmann::to_json(std::declval<json&>(), pod_bis{})), "");
|
||||||
static_assert(noexcept(json(2)), "");
|
static_assert(noexcept(json(2)), "");
|
||||||
|
#ifndef SKIP_TESTS_FOR_ENUM_SERIALIZATION
|
||||||
static_assert(noexcept(json(test {})), "");
|
static_assert(noexcept(json(test {})), "");
|
||||||
|
#endif
|
||||||
static_assert(noexcept(json(pod {})), "");
|
static_assert(noexcept(json(pod {})), "");
|
||||||
static_assert(noexcept(std::declval<json>().get<pod>()), "");
|
static_assert(noexcept(std::declval<json>().get<pod>()), "");
|
||||||
static_assert(!noexcept(std::declval<json>().get<pod_bis>()), "");
|
static_assert(!noexcept(std::declval<json>().get<pod_bis>()), "");
|
||||||
|
@ -11,6 +11,11 @@
|
|||||||
// for some reason including this after the json header leads to linker errors with VS 2017...
|
// for some reason including this after the json header leads to linker errors with VS 2017...
|
||||||
#include <locale>
|
#include <locale>
|
||||||
|
|
||||||
|
// skip tests if JSON_DisableEnumSerialization=ON (#4384)
|
||||||
|
#if defined(JSON_DISABLE_ENUM_SERIALIZATION) && (JSON_DISABLE_ENUM_SERIALIZATION == 1)
|
||||||
|
#define SKIP_TESTS_FOR_ENUM_SERIALIZATION
|
||||||
|
#endif
|
||||||
|
|
||||||
#define JSON_TESTS_PRIVATE
|
#define JSON_TESTS_PRIVATE
|
||||||
#include <nlohmann/json.hpp>
|
#include <nlohmann/json.hpp>
|
||||||
using nlohmann::json;
|
using nlohmann::json;
|
||||||
@ -169,6 +174,7 @@ TEST_CASE("regression tests 1")
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef SKIP_TESTS_FOR_ENUM_SERIALIZATION
|
||||||
SECTION("pull request #71 - handle enum type")
|
SECTION("pull request #71 - handle enum type")
|
||||||
{
|
{
|
||||||
enum { t = 0, u = 102};
|
enum { t = 0, u = 102};
|
||||||
@ -191,6 +197,7 @@ TEST_CASE("regression tests 1")
|
|||||||
{"game_type", t}
|
{"game_type", t}
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
SECTION("issue #76 - dump() / parse() not idempotent")
|
SECTION("issue #76 - dump() / parse() not idempotent")
|
||||||
{
|
{
|
||||||
|
@ -12,6 +12,11 @@
|
|||||||
DOCTEST_GCC_SUPPRESS_WARNING_PUSH
|
DOCTEST_GCC_SUPPRESS_WARNING_PUSH
|
||||||
DOCTEST_GCC_SUPPRESS_WARNING("-Wnoexcept")
|
DOCTEST_GCC_SUPPRESS_WARNING("-Wnoexcept")
|
||||||
|
|
||||||
|
// skip tests if JSON_DisableEnumSerialization=ON (#4384)
|
||||||
|
#if defined(JSON_DISABLE_ENUM_SERIALIZATION) && (JSON_DISABLE_ENUM_SERIALIZATION == 1)
|
||||||
|
#define SKIP_TESTS_FOR_ENUM_SERIALIZATION
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <nlohmann/json.hpp>
|
#include <nlohmann/json.hpp>
|
||||||
using nlohmann::json;
|
using nlohmann::json;
|
||||||
#ifdef JSON_TEST_NO_GLOBAL_UDLS
|
#ifdef JSON_TEST_NO_GLOBAL_UDLS
|
||||||
@ -132,7 +137,11 @@ static void to_json(nlohmann::json& j, const contact& c)
|
|||||||
|
|
||||||
static void to_json(nlohmann::json& j, const contact_book& cb)
|
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}};
|
j = json{{"name", cb.m_book_name},
|
||||||
|
#ifndef SKIP_TESTS_FOR_ENUM_SERIALIZATION
|
||||||
|
{"id", cb.m_book_id},
|
||||||
|
#endif
|
||||||
|
{"contacts", cb.m_contacts}};
|
||||||
}
|
}
|
||||||
|
|
||||||
// operators
|
// operators
|
||||||
@ -222,7 +231,9 @@ static void from_json(const nlohmann::json& j, contact& c)
|
|||||||
static void from_json(const nlohmann::json& j, contact_book& cb)
|
static void from_json(const nlohmann::json& j, contact_book& cb)
|
||||||
{
|
{
|
||||||
cb.m_book_name = j["name"].get<name>();
|
cb.m_book_name = j["name"].get<name>();
|
||||||
|
#ifndef SKIP_TESTS_FOR_ENUM_SERIALIZATION
|
||||||
cb.m_book_id = j["id"].get<book_id>();
|
cb.m_book_id = j["id"].get<book_id>();
|
||||||
|
#endif
|
||||||
cb.m_contacts = j["contacts"].get<std::vector<contact>>();
|
cb.m_contacts = j["contacts"].get<std::vector<contact>>();
|
||||||
}
|
}
|
||||||
} // namespace udt
|
} // namespace udt
|
||||||
@ -253,14 +264,22 @@ TEST_CASE("basic usage" * doctest::test_suite("udt"))
|
|||||||
CHECK(json("Paris") == json(addr));
|
CHECK(json("Paris") == json(addr));
|
||||||
CHECK(json(cpp_programmer) ==
|
CHECK(json(cpp_programmer) ==
|
||||||
R"({"person" : {"age":23, "name":"theo", "country":"France"}, "address":"Paris"})"_json);
|
R"({"person" : {"age":23, "name":"theo", "country":"France"}, "address":"Paris"})"_json);
|
||||||
|
#ifndef SKIP_TESTS_FOR_ENUM_SERIALIZATION
|
||||||
CHECK(json(large_id) == json(static_cast<std::uint64_t>(1) << 63));
|
CHECK(json(large_id) == json(static_cast<std::uint64_t>(1) << 63));
|
||||||
CHECK(json(large_id) > 0u);
|
CHECK(json(large_id) > 0u);
|
||||||
CHECK(to_string(json(large_id)) == "9223372036854775808");
|
CHECK(to_string(json(large_id)) == "9223372036854775808");
|
||||||
CHECK(json(large_id).is_number_unsigned());
|
CHECK(json(large_id).is_number_unsigned());
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef SKIP_TESTS_FOR_ENUM_SERIALIZATION
|
||||||
CHECK(
|
CHECK(
|
||||||
json(book) ==
|
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);
|
R"({"name":"C++", "id":42, "contacts" : [{"person" : {"age":23, "name":"theo", "country":"France"}, "address":"Paris"}, {"person" : {"age":42, "country":"中华人民共和国", "name":"王芳"}, "address":"Paris"}]})"_json);
|
||||||
|
#else
|
||||||
|
CHECK(
|
||||||
|
json(book) ==
|
||||||
|
R"({"name":"C++", "contacts" : [{"person" : {"age":23, "name":"theo", "country":"France"}, "address":"Paris"}, {"person" : {"age":42, "country":"中华人民共和国", "name":"王芳"}, "address":"Paris"}]})"_json);
|
||||||
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -272,7 +291,9 @@ TEST_CASE("basic usage" * doctest::test_suite("udt"))
|
|||||||
{
|
{
|
||||||
const auto parsed_book = big_json.get<udt::contact_book>();
|
const auto parsed_book = big_json.get<udt::contact_book>();
|
||||||
const auto book_name = big_json["name"].get<udt::name>();
|
const auto book_name = big_json["name"].get<udt::name>();
|
||||||
|
#ifndef SKIP_TESTS_FOR_ENUM_SERIALIZATION
|
||||||
const auto book_id = big_json["id"].get<udt::book_id>();
|
const auto book_id = big_json["id"].get<udt::book_id>();
|
||||||
|
#endif
|
||||||
const auto contacts =
|
const auto contacts =
|
||||||
big_json["contacts"].get<std::vector<udt::contact>>();
|
big_json["contacts"].get<std::vector<udt::contact>>();
|
||||||
const auto contact_json = big_json["contacts"].at(0);
|
const auto contact_json = big_json["contacts"].at(0);
|
||||||
@ -292,8 +313,10 @@ TEST_CASE("basic usage" * doctest::test_suite("udt"))
|
|||||||
CHECK(contact == cpp_programmer);
|
CHECK(contact == cpp_programmer);
|
||||||
CHECK(contacts == book.m_contacts);
|
CHECK(contacts == book.m_contacts);
|
||||||
CHECK(book_name == udt::name{"C++"});
|
CHECK(book_name == udt::name{"C++"});
|
||||||
|
#ifndef SKIP_TESTS_FOR_ENUM_SERIALIZATION
|
||||||
CHECK(book_id == book.m_book_id);
|
CHECK(book_id == book.m_book_id);
|
||||||
CHECK(book == parsed_book);
|
CHECK(book == parsed_book);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("via explicit calls to get_to")
|
SECTION("via explicit calls to get_to")
|
||||||
@ -314,7 +337,9 @@ TEST_CASE("basic usage" * doctest::test_suite("udt"))
|
|||||||
{
|
{
|
||||||
const udt::contact_book parsed_book = big_json;
|
const udt::contact_book parsed_book = big_json;
|
||||||
const udt::name book_name = big_json["name"];
|
const udt::name book_name = big_json["name"];
|
||||||
|
#ifndef SKIP_TESTS_FOR_ENUM_SERIALIZATION
|
||||||
const udt::book_id book_id = big_json["id"];
|
const udt::book_id book_id = big_json["id"];
|
||||||
|
#endif
|
||||||
const std::vector<udt::contact> contacts = big_json["contacts"];
|
const std::vector<udt::contact> contacts = big_json["contacts"];
|
||||||
const auto contact_json = big_json["contacts"].at(0);
|
const auto contact_json = big_json["contacts"].at(0);
|
||||||
const udt::contact contact = contact_json;
|
const udt::contact contact = contact_json;
|
||||||
@ -332,8 +357,10 @@ TEST_CASE("basic usage" * doctest::test_suite("udt"))
|
|||||||
CHECK(contact == cpp_programmer);
|
CHECK(contact == cpp_programmer);
|
||||||
CHECK(contacts == book.m_contacts);
|
CHECK(contacts == book.m_contacts);
|
||||||
CHECK(book_name == udt::name{"C++"});
|
CHECK(book_name == udt::name{"C++"});
|
||||||
|
#ifndef SKIP_TESTS_FOR_ENUM_SERIALIZATION
|
||||||
CHECK(book_id == static_cast<udt::book_id>(42u));
|
CHECK(book_id == static_cast<udt::book_id>(42u));
|
||||||
CHECK(book == parsed_book);
|
CHECK(book == parsed_book);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user