Dump the entire json library in

This commit is contained in:
jordan4ibanez
2023-11-26 01:31:01 -05:00
parent 8f54e69d33
commit 650ccf9844
1077 changed files with 173944 additions and 0 deletions

View File

@ -0,0 +1,30 @@
# common build settings
add_library(abi_compat_common INTERFACE)
target_compile_definitions(abi_compat_common INTERFACE
DOCTEST_CONFIG_SUPER_FAST_ASSERTS
JSON_TEST_KEEP_MACROS)
target_compile_features(abi_compat_common INTERFACE cxx_std_11)
target_compile_options(abi_compat_common INTERFACE
$<$<CXX_COMPILER_ID:MSVC>:/EHsc;$<$<CONFIG:Release>:/Od>>
# MSVC: Force to always compile with W4
$<$<CXX_COMPILER_ID:MSVC>:/W4>
# https://github.com/nlohmann/json/pull/3229
$<$<CXX_COMPILER_ID:Intel>:-diag-disable=2196>
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wno-deprecated;-Wno-float-equal>
$<$<CXX_COMPILER_ID:GNU>:-Wno-deprecated-declarations>
$<$<CXX_COMPILER_ID:Intel>:-diag-disable=1786>)
target_include_directories(abi_compat_common SYSTEM INTERFACE
../thirdparty/doctest
include)
target_link_libraries(abi_compat_common INTERFACE ${NLOHMANN_JSON_TARGET_NAME})
# shared main()
add_library(abi_compat_main STATIC main.cpp)
target_link_libraries(abi_compat_main PUBLIC abi_compat_common)
# add individual tests
add_subdirectory(config)
add_subdirectory(diag)
add_subdirectory(inline_ns)

View File

@ -0,0 +1,22 @@
# test the different options to change the namespace
# test default namespace
add_executable(abi_config_default default.cpp)
target_link_libraries(abi_config_default PRIVATE abi_compat_main)
add_test(
NAME test-abi_config_default
COMMAND abi_config_default ${DOCTEST_TEST_FILTER})
# test no version namespace
add_executable(abi_config_noversion noversion.cpp)
target_link_libraries(abi_config_noversion PRIVATE abi_compat_main)
add_test(
NAME test-abi_config_noversion
COMMAND abi_config_noversion ${DOCTEST_TEST_FILTER})
# test custom namespace
add_executable(abi_config_custom custom.cpp)
target_link_libraries(abi_config_custom PRIVATE abi_compat_main)
add_test(
NAME test-abi_config_custom
COMMAND abi_config_custom ${DOCTEST_TEST_FILTER})

View File

@ -0,0 +1,35 @@
// __ _____ _____ _____
// __| | __| | | | JSON for Modern C++ (supporting code)
// | | |__ | | | | | | version 3.11.2
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
//
// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me>
// SPDX-License-Identifier: MIT
#pragma once
#include "doctest.h"
#include <iostream>
#include <regex>
#include <string>
#define STRINGIZE_EX(x) #x
#define STRINGIZE(x) STRINGIZE_EX(x)
template<typename T>
std::string namespace_name(std::string ns, T* /*unused*/ = nullptr) // NOLINT(performance-unnecessary-value-param)
{
#if DOCTEST_MSVC && !DOCTEST_CLANG
ns = __FUNCSIG__;
#elif !DOCTEST_CLANG
ns = __PRETTY_FUNCTION__;
#endif
std::smatch m;
// extract the true namespace name from the function signature
CAPTURE(ns);
CHECK(std::regex_search(ns, m, std::regex("nlohmann(::[a-zA-Z0-9_]+)*::basic_json")));
return m.str();
}

View File

@ -0,0 +1,33 @@
// __ _____ _____ _____
// __| | __| | | | JSON for Modern C++ (supporting code)
// | | |__ | | | | | | version 3.11.2
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
//
// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me>
// SPDX-License-Identifier: MIT
#include "doctest_compatibility.h"
#include "config.hpp"
// define custom namespace
#define NLOHMANN_JSON_NAMESPACE nlohmann // this line may be omitted
#define NLOHMANN_JSON_NAMESPACE_BEGIN namespace nlohmann {
#define NLOHMANN_JSON_NAMESPACE_END }
#include <nlohmann/json_fwd.hpp>
TEST_CASE("custom namespace")
{
// GCC 4.8 fails with regex_error
#if !DOCTEST_GCC || DOCTEST_GCC >= DOCTEST_COMPILER(4, 9, 0)
SECTION("namespace matches expectation")
{
std::string expected = "nlohmann::basic_json";
// fallback for Clang
const std::string ns{STRINGIZE(NLOHMANN_JSON_NAMESPACE) "::basic_json"};
CHECK(namespace_name<nlohmann::json>(ns) == expected);
}
#endif
}

View File

@ -0,0 +1,41 @@
// __ _____ _____ _____
// __| | __| | | | JSON for Modern C++ (supporting code)
// | | |__ | | | | | | version 3.11.2
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
//
// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me>
// SPDX-License-Identifier: MIT
#include "doctest_compatibility.h"
#include "config.hpp"
#include <nlohmann/json_fwd.hpp>
TEST_CASE("default namespace")
{
// GCC 4.8 fails with regex_error
#if !DOCTEST_GCC || DOCTEST_GCC >= DOCTEST_COMPILER(4, 9, 0)
SECTION("namespace matches expectation")
{
std::string expected = "nlohmann::json_abi";
#if JSON_DIAGNOSTICS
expected += "_diag";
#endif
#if JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON
expected += "_ldvcmp";
#endif
expected += "_v" STRINGIZE(NLOHMANN_JSON_VERSION_MAJOR);
expected += "_" STRINGIZE(NLOHMANN_JSON_VERSION_MINOR);
expected += "_" STRINGIZE(NLOHMANN_JSON_VERSION_PATCH) "::basic_json";
// fallback for Clang
const std::string ns{STRINGIZE(NLOHMANN_JSON_NAMESPACE) "::basic_json"};
CHECK(namespace_name<nlohmann::json>(ns) == expected);
}
#endif
}

View File

@ -0,0 +1,40 @@
// __ _____ _____ _____
// __| | __| | | | JSON for Modern C++ (supporting code)
// | | |__ | | | | | | version 3.11.2
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
//
// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me>
// SPDX-License-Identifier: MIT
#include "doctest_compatibility.h"
#include "config.hpp"
#define NLOHMANN_JSON_NAMESPACE_NO_VERSION 1
#include <nlohmann/json_fwd.hpp>
TEST_CASE("default namespace without version component")
{
// GCC 4.8 fails with regex_error
#if !DOCTEST_GCC || DOCTEST_GCC >= DOCTEST_COMPILER(4, 9, 0)
SECTION("namespace matches expectation")
{
std::string expected = "nlohmann::json_abi";
#if JSON_DIAGNOSTICS
expected += "_diag";
#endif
#if JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON
expected += "_ldvcmp";
#endif
expected += "::basic_json";
// fallback for Clang
const std::string ns{STRINGIZE(NLOHMANN_JSON_NAMESPACE) "::basic_json"};
CHECK(namespace_name<nlohmann::json>(ns) == expected);
}
#endif
}

View File

@ -0,0 +1,19 @@
# test linking library built with different JSON_DIAGNOSTICS setting
# into the same executable
# compile code using JSON_DIAGNOSTICS=1
add_library(abi_compat_diag_on STATIC diag_on.cpp)
target_link_libraries(abi_compat_diag_on PUBLIC abi_compat_common)
# compile code using JSON_DIAGNOSTICS=0
add_library(abi_compat_diag_off STATIC diag_off.cpp)
target_link_libraries(abi_compat_diag_off PUBLIC abi_compat_common)
# build test executable and add test
add_executable(abi_compat_diag diag.cpp)
target_link_libraries(abi_compat_diag PRIVATE
abi_compat_main abi_compat_diag_on abi_compat_diag_off)
add_test(
NAME test-abi_compat_diag
COMMAND abi_compat_diag ${DOCTEST_TEST_FILTER})

View File

@ -0,0 +1,29 @@
// __ _____ _____ _____
// __| | __| | | | JSON for Modern C++ (supporting code)
// | | |__ | | | | | | version 3.11.2
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
//
// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me>
// SPDX-License-Identifier: MIT
#include "doctest_compatibility.h"
#include "diag.hpp"
TEST_CASE("ABI compatible diagnostics")
{
SECTION("basic_json size")
{
// basic_json with diagnostics is larger because of added data members
CHECK(json_sizeof_diag_on() == json_sizeof_diag_on_explicit());
CHECK(json_sizeof_diag_off() == json_sizeof_diag_off_explicit());
CHECK(json_sizeof_diag_on() > json_sizeof_diag_off());
}
SECTION("basic_json at")
{
// accessing a nonexistent key throws different exception with diagnostics
CHECK_THROWS_WITH(json_at_diag_on(), "[json.exception.out_of_range.403] (/foo) key 'bar' not found");
CHECK_THROWS_WITH(json_at_diag_off(), "[json.exception.out_of_range.403] key 'bar' not found");
}
}

View File

@ -0,0 +1,20 @@
// __ _____ _____ _____
// __| | __| | | | JSON for Modern C++ (supporting code)
// | | |__ | | | | | | version 3.11.2
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
//
// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me>
// SPDX-License-Identifier: MIT
#pragma once
#include <cstddef>
std::size_t json_sizeof_diag_on();
std::size_t json_sizeof_diag_on_explicit();
std::size_t json_sizeof_diag_off();
std::size_t json_sizeof_diag_off_explicit();
void json_at_diag_on();
void json_at_diag_off();

View File

@ -0,0 +1,30 @@
// __ _____ _____ _____
// __| | __| | | | JSON for Modern C++ (supporting code)
// | | |__ | | | | | | version 3.11.2
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
//
// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me>
// SPDX-License-Identifier: MIT
#undef JSON_DIAGNOSTICS
#define JSON_DIAGNOSTICS 0
#include <nlohmann/json.hpp>
#include "diag.hpp"
std::size_t json_sizeof_diag_off()
{
return sizeof(nlohmann::json);
}
std::size_t json_sizeof_diag_off_explicit()
{
return sizeof(::NLOHMANN_JSON_NAMESPACE::json);
}
void json_at_diag_off()
{
using nlohmann::json;
json j = json{{"foo", json::object()}};
j.at(json::json_pointer("/foo/bar"));
}

View File

@ -0,0 +1,30 @@
// __ _____ _____ _____
// __| | __| | | | JSON for Modern C++ (supporting code)
// | | |__ | | | | | | version 3.11.2
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
//
// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me>
// SPDX-License-Identifier: MIT
#undef JSON_DIAGNOSTICS
#define JSON_DIAGNOSTICS 1
#include <nlohmann/json.hpp>
#include "diag.hpp"
std::size_t json_sizeof_diag_on()
{
return sizeof(nlohmann::json);
}
std::size_t json_sizeof_diag_on_explicit()
{
return sizeof(::NLOHMANN_JSON_NAMESPACE::json);
}
void json_at_diag_on()
{
using nlohmann::json;
json j = json{{"foo", json::object()}};
j.at(json::json_pointer("/foo/bar"));
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,12 @@
# test linking an old library version without an inline namespace
# with the current library using an inline namespace into the same executable
# build test executable and add test
add_executable(abi_compat_inline_ns
use_v3_10_5.cpp
use_current.cpp)
target_link_libraries(abi_compat_inline_ns PRIVATE abi_compat_main)
add_test(
NAME test-abi_compat_inline_ns
COMMAND abi_compat_inline_ns ${DOCTEST_TEST_FILTER})

View File

@ -0,0 +1,36 @@
// __ _____ _____ _____
// __| | __| | | | JSON for Modern C++ (supporting code)
// | | |__ | | | | | | version 3.11.2
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
//
// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me>
// SPDX-License-Identifier: MIT
#include "doctest_compatibility.h"
#include <nlohmann/json.hpp>
TEST_CASE("use current library with inline namespace")
{
SECTION("implicitly")
{
using nlohmann::json;
using nlohmann::ordered_json;
json j;
// In v3.10.5 mixing json_pointers of different basic_json types
// results in implicit string conversion
j[ordered_json::json_pointer("/root")] = json::object();
CHECK(j.dump() == "{\"root\":{}}");
}
SECTION("explicitly")
{
using NLOHMANN_JSON_NAMESPACE::json;
using NLOHMANN_JSON_NAMESPACE::ordered_json;
json j;
j[ordered_json::json_pointer("/root")] = json::object();
CHECK(j.dump() == "{\"root\":{}}");
}
}

View File

@ -0,0 +1,22 @@
// __ _____ _____ _____
// __| | __| | | | JSON for Modern C++ (supporting code)
// | | |__ | | | | | | version 3.11.2
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
//
// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me>
// SPDX-License-Identifier: MIT
#include "doctest_compatibility.h"
#include <nlohmann/json_v3_10_5.hpp>
using nlohmann::json;
using nlohmann::ordered_json;
TEST_CASE("use library v3.10.5 without inline namespace")
{
json j;
j[ordered_json::json_pointer("/root")] = json::object();
// In v3.10.5 mixing json_pointers of different basic_json types
// results in implicit string conversion
CHECK(j.dump() == "{\"/root\":{}}");
}

View File

@ -0,0 +1,11 @@
// __ _____ _____ _____
// __| | __| | | | JSON for Modern C++ (supporting code)
// | | |__ | | | | | | version 3.11.2
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
//
// Copyright (c) 2013-2022 Niels Lohmann <http://nlohmann.me>.
// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me>
// SPDX-License-Identifier: MIT
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
#include "doctest_compatibility.h"