Merge commit 'a28dbbf733e264fe214ac6167dd7c33d296e6474' into dev
This commit is contained in:
2
external/json/tests/abi/config/config.hpp
vendored
2
external/json/tests/abi/config/config.hpp
vendored
@@ -3,7 +3,7 @@
|
||||
// | | |__ | | | | | | version 3.11.3
|
||||
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
//
|
||||
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-FileCopyrightText: 2013 - 2024 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#pragma once
|
||||
|
||||
2
external/json/tests/abi/config/custom.cpp
vendored
2
external/json/tests/abi/config/custom.cpp
vendored
@@ -3,7 +3,7 @@
|
||||
// | | |__ | | | | | | version 3.11.3
|
||||
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
//
|
||||
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-FileCopyrightText: 2013 - 2024 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#include "doctest_compatibility.h"
|
||||
|
||||
6
external/json/tests/abi/config/default.cpp
vendored
6
external/json/tests/abi/config/default.cpp
vendored
@@ -3,7 +3,7 @@
|
||||
// | | |__ | | | | | | version 3.11.3
|
||||
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
//
|
||||
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-FileCopyrightText: 2013 - 2024 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#include "doctest_compatibility.h"
|
||||
@@ -24,6 +24,10 @@ TEST_CASE("default namespace")
|
||||
expected += "_diag";
|
||||
#endif
|
||||
|
||||
#if JSON_DIAGNOSTIC_POSITIONS
|
||||
expected += "_dp";
|
||||
#endif
|
||||
|
||||
#if JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON
|
||||
expected += "_ldvcmp";
|
||||
#endif
|
||||
|
||||
6
external/json/tests/abi/config/noversion.cpp
vendored
6
external/json/tests/abi/config/noversion.cpp
vendored
@@ -3,7 +3,7 @@
|
||||
// | | |__ | | | | | | version 3.11.3
|
||||
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
//
|
||||
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-FileCopyrightText: 2013 - 2024 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#include "doctest_compatibility.h"
|
||||
@@ -25,6 +25,10 @@ TEST_CASE("default namespace without version component")
|
||||
expected += "_diag";
|
||||
#endif
|
||||
|
||||
#if JSON_DIAGNOSTIC_POSITIONS
|
||||
expected += "_dp";
|
||||
#endif
|
||||
|
||||
#if JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON
|
||||
expected += "_ldvcmp";
|
||||
#endif
|
||||
|
||||
2
external/json/tests/abi/diag/diag.cpp
vendored
2
external/json/tests/abi/diag/diag.cpp
vendored
@@ -3,7 +3,7 @@
|
||||
// | | |__ | | | | | | version 3.11.3
|
||||
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
//
|
||||
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-FileCopyrightText: 2013 - 2024 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#include "doctest_compatibility.h"
|
||||
|
||||
2
external/json/tests/abi/diag/diag.hpp
vendored
2
external/json/tests/abi/diag/diag.hpp
vendored
@@ -3,7 +3,7 @@
|
||||
// | | |__ | | | | | | version 3.11.3
|
||||
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
//
|
||||
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-FileCopyrightText: 2013 - 2024 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#pragma once
|
||||
|
||||
2
external/json/tests/abi/diag/diag_off.cpp
vendored
2
external/json/tests/abi/diag/diag_off.cpp
vendored
@@ -3,7 +3,7 @@
|
||||
// | | |__ | | | | | | version 3.11.3
|
||||
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
//
|
||||
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-FileCopyrightText: 2013 - 2024 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#undef JSON_DIAGNOSTICS
|
||||
|
||||
2
external/json/tests/abi/diag/diag_on.cpp
vendored
2
external/json/tests/abi/diag/diag_on.cpp
vendored
@@ -3,7 +3,7 @@
|
||||
// | | |__ | | | | | | version 3.11.3
|
||||
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
//
|
||||
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-FileCopyrightText: 2013 - 2024 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#undef JSON_DIAGNOSTICS
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
// | | |__ | | | | | | version 3.11.3
|
||||
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
//
|
||||
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-FileCopyrightText: 2013 - 2024 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#include "doctest_compatibility.h"
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
// | | |__ | | | | | | version 3.11.3
|
||||
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
//
|
||||
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-FileCopyrightText: 2013 - 2024 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#include "doctest_compatibility.h"
|
||||
|
||||
3
external/json/tests/abi/main.cpp
vendored
3
external/json/tests/abi/main.cpp
vendored
@@ -3,8 +3,7 @@
|
||||
// | | |__ | | | | | | version 3.11.3
|
||||
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
//
|
||||
// Copyright (c) 2013-2022 Niels Lohmann <http://nlohmann.me>.
|
||||
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-FileCopyrightText: 2013 - 2024 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
// | | |__ | | | | | | version 3.11.3
|
||||
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
//
|
||||
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-FileCopyrightText: 2013 - 2024 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#include <benchmark/benchmark.h>
|
||||
@@ -140,6 +140,46 @@ BENCHMARK_CAPTURE(ToCbor, signed_ints, TEST_DATA_DIRECTORY "/regression/si
|
||||
BENCHMARK_CAPTURE(ToCbor, unsigned_ints, TEST_DATA_DIRECTORY "/regression/unsigned_ints.json");
|
||||
BENCHMARK_CAPTURE(ToCbor, small_signed_ints, TEST_DATA_DIRECTORY "/regression/small_signed_ints.json");
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// Parse Msgpack
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static void FromMsgpack(benchmark::State& state, const char* filename)
|
||||
{
|
||||
std::ifstream f(filename);
|
||||
std::string str((std::istreambuf_iterator<char>(f)), std::istreambuf_iterator<char>());
|
||||
auto bytes = json::to_msgpack(json::parse(str));
|
||||
std::ofstream o("test.msgpack");
|
||||
o.write((char*)bytes.data(), bytes.size());
|
||||
o.flush();
|
||||
o.close();
|
||||
for (auto _ : state)
|
||||
{
|
||||
state.PauseTiming();
|
||||
auto* j = new json();
|
||||
auto file = fopen("test.msgpack", "rb");
|
||||
state.ResumeTiming();
|
||||
|
||||
*j = json::from_msgpack(file);
|
||||
|
||||
state.PauseTiming();
|
||||
fclose(file);
|
||||
delete j;
|
||||
state.ResumeTiming();
|
||||
}
|
||||
|
||||
state.SetBytesProcessed(state.iterations() * bytes.size());
|
||||
}
|
||||
|
||||
BENCHMARK_CAPTURE(FromMsgpack, jeopardy, TEST_DATA_DIRECTORY "/jeopardy/jeopardy.json");
|
||||
BENCHMARK_CAPTURE(FromMsgpack, canada, TEST_DATA_DIRECTORY "/nativejson-benchmark/canada.json");
|
||||
BENCHMARK_CAPTURE(FromMsgpack, citm_catalog, TEST_DATA_DIRECTORY "/nativejson-benchmark/citm_catalog.json");
|
||||
BENCHMARK_CAPTURE(FromMsgpack, twitter, TEST_DATA_DIRECTORY "/nativejson-benchmark/twitter.json");
|
||||
BENCHMARK_CAPTURE(FromMsgpack, floats, TEST_DATA_DIRECTORY "/regression/floats.json");
|
||||
BENCHMARK_CAPTURE(FromMsgpack, signed_ints, TEST_DATA_DIRECTORY "/regression/signed_ints.json");
|
||||
BENCHMARK_CAPTURE(FromMsgpack, unsigned_ints, TEST_DATA_DIRECTORY "/regression/unsigned_ints.json");
|
||||
BENCHMARK_CAPTURE(FromMsgpack, small_signed_ints, TEST_DATA_DIRECTORY "/regression/small_signed_ints.json");
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// serialize binary CBOR
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
// | | |__ | | | | | | version 3.11.3
|
||||
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
//
|
||||
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-FileCopyrightText: 2013 - 2024 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
// | | |__ | | | | | | version 3.11.3
|
||||
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
//
|
||||
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-FileCopyrightText: 2013 - 2024 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
// | | |__ | | | | | | version 3.11.3
|
||||
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
//
|
||||
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-FileCopyrightText: 2013 - 2024 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
// | | |__ | | | | | | version 3.11.3
|
||||
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
//
|
||||
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-FileCopyrightText: 2013 - 2024 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
// | | |__ | | | | | | version 3.11.3
|
||||
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
//
|
||||
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-FileCopyrightText: 2013 - 2024 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
// | | |__ | | | | | | version 3.11.3
|
||||
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
//
|
||||
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-FileCopyrightText: 2013 - 2024 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#include "Bar.hpp"
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
// | | |__ | | | | | | version 3.11.3
|
||||
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
//
|
||||
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-FileCopyrightText: 2013 - 2024 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
// | | |__ | | | | | | version 3.11.3
|
||||
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
//
|
||||
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-FileCopyrightText: 2013 - 2024 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#include "Foo.hpp"
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
// | | |__ | | | | | | version 3.11.3
|
||||
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
//
|
||||
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-FileCopyrightText: 2013 - 2024 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#pragma once
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
// | | |__ | | | | | | version 3.11.3
|
||||
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
//
|
||||
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-FileCopyrightText: 2013 - 2024 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
// | | |__ | | | | | | version 3.11.3
|
||||
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
//
|
||||
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-FileCopyrightText: 2013 - 2024 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
// | | |__ | | | | | | version 3.11.3
|
||||
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
//
|
||||
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-FileCopyrightText: 2013 - 2024 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
/*
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
// | | |__ | | | | | | version 3.11.3
|
||||
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
//
|
||||
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-FileCopyrightText: 2013 - 2024 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
/*
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
// | | |__ | | | | | | version 3.11.3
|
||||
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
//
|
||||
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-FileCopyrightText: 2013 - 2024 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
/*
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
// | | |__ | | | | | | version 3.11.3
|
||||
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
//
|
||||
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-FileCopyrightText: 2013 - 2024 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
/*
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
// | | |__ | | | | | | version 3.11.3
|
||||
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
//
|
||||
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-FileCopyrightText: 2013 - 2024 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
/*
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
// | | |__ | | | | | | version 3.11.3
|
||||
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
//
|
||||
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-FileCopyrightText: 2013 - 2024 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
/*
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
// | | |__ | | | | | | version 3.11.3
|
||||
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
//
|
||||
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-FileCopyrightText: 2013 - 2024 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
/*
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
// | | |__ | | | | | | version 3.11.3
|
||||
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
//
|
||||
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-FileCopyrightText: 2013 - 2024 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#pragma once
|
||||
|
||||
2
external/json/tests/src/test_utils.hpp
vendored
2
external/json/tests/src/test_utils.hpp
vendored
@@ -3,7 +3,7 @@
|
||||
// | | |__ | | | | | | version 3.11.3
|
||||
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
//
|
||||
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-FileCopyrightText: 2013 - 2024 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#pragma once
|
||||
|
||||
4
external/json/tests/src/unit-32bit.cpp
vendored
4
external/json/tests/src/unit-32bit.cpp
vendored
@@ -3,7 +3,7 @@
|
||||
// | | |__ | | | | | | version 3.11.3
|
||||
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
//
|
||||
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-FileCopyrightText: 2013 - 2024 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#include "doctest_compatibility.h"
|
||||
@@ -23,7 +23,7 @@ struct trait_test_arg
|
||||
static constexpr bool max_in_range = MaxInRange;
|
||||
};
|
||||
|
||||
TEST_CASE_TEMPLATE_DEFINE("value_in_range_of trait", T, value_in_range_of_test)
|
||||
TEST_CASE_TEMPLATE_DEFINE("value_in_range_of trait", T, value_in_range_of_test) // NOLINT(readability-math-missing-parentheses)
|
||||
{
|
||||
using nlohmann::detail::value_in_range_of;
|
||||
|
||||
|
||||
2
external/json/tests/src/unit-algorithms.cpp
vendored
2
external/json/tests/src/unit-algorithms.cpp
vendored
@@ -3,7 +3,7 @@
|
||||
// | | |__ | | | | | | version 3.11.3
|
||||
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
//
|
||||
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-FileCopyrightText: 2013 - 2024 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#include "doctest_compatibility.h"
|
||||
|
||||
2
external/json/tests/src/unit-allocator.cpp
vendored
2
external/json/tests/src/unit-allocator.cpp
vendored
@@ -3,7 +3,7 @@
|
||||
// | | |__ | | | | | | version 3.11.3
|
||||
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
//
|
||||
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-FileCopyrightText: 2013 - 2024 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#include "doctest_compatibility.h"
|
||||
|
||||
56
external/json/tests/src/unit-alt-string.cpp
vendored
56
external/json/tests/src/unit-alt-string.cpp
vendored
@@ -3,7 +3,7 @@
|
||||
// | | |__ | | | | | | version 3.11.3
|
||||
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
//
|
||||
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-FileCopyrightText: 2013 - 2024 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-FileCopyrightText: 2018 Vitaliy Manushkin <agri@akamo.info>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
@@ -16,8 +16,8 @@
|
||||
|
||||
/* forward declarations */
|
||||
class alt_string;
|
||||
bool operator<(const char* op1, const alt_string& op2) noexcept;
|
||||
void int_to_string(alt_string& target, std::size_t value);
|
||||
bool operator<(const char* op1, const alt_string& op2) noexcept; // NOLINT(misc-use-internal-linkage)
|
||||
void int_to_string(alt_string& target, std::size_t value); // NOLINT(misc-use-internal-linkage)
|
||||
|
||||
/*
|
||||
* This is virtually a string class.
|
||||
@@ -28,17 +28,28 @@ class alt_string
|
||||
public:
|
||||
using value_type = std::string::value_type;
|
||||
|
||||
static constexpr auto npos = static_cast<std::size_t>(-1);
|
||||
static constexpr auto npos = (std::numeric_limits<std::size_t>::max)();
|
||||
|
||||
alt_string(const char* str): str_impl(str) {}
|
||||
alt_string(const char* str, std::size_t count): str_impl(str, count) {}
|
||||
alt_string(size_t count, char chr): str_impl(count, chr) {}
|
||||
alt_string() = default;
|
||||
|
||||
template <typename...TParams>
|
||||
alt_string& append(TParams&& ...params)
|
||||
alt_string& append(char ch)
|
||||
{
|
||||
str_impl.append(std::forward<TParams>(params)...);
|
||||
str_impl.push_back(ch);
|
||||
return *this;
|
||||
}
|
||||
|
||||
alt_string& append(const alt_string& str)
|
||||
{
|
||||
str_impl.append(str.str_impl);
|
||||
return *this;
|
||||
}
|
||||
|
||||
alt_string& append(const char* s, std::size_t length)
|
||||
{
|
||||
str_impl.append(s, length);
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -157,8 +168,13 @@ class alt_string
|
||||
return *this;
|
||||
}
|
||||
|
||||
void reserve( std::size_t new_cap = 0 )
|
||||
{
|
||||
str_impl.reserve(new_cap);
|
||||
}
|
||||
|
||||
private:
|
||||
std::string str_impl {};
|
||||
std::string str_impl {}; // NOLINT(readability-redundant-member-init)
|
||||
|
||||
friend bool operator<(const char* /*op1*/, const alt_string& /*op2*/) noexcept;
|
||||
};
|
||||
@@ -319,4 +335,28 @@ TEST_CASE("alternative string type")
|
||||
CHECK(j.at(alt_json::json_pointer("/foo/0")) == j["foo"][0]);
|
||||
CHECK(j.at(alt_json::json_pointer("/foo/1")) == j["foo"][1]);
|
||||
}
|
||||
|
||||
SECTION("patch")
|
||||
{
|
||||
alt_json const patch1 = alt_json::parse(R"([{ "op": "add", "path": "/a/b", "value": [ "foo", "bar" ] }])");
|
||||
alt_json const doc1 = alt_json::parse(R"({ "a": { "foo": 1 } })");
|
||||
|
||||
CHECK_NOTHROW(doc1.patch(patch1));
|
||||
alt_json doc1_ans = alt_json::parse(R"(
|
||||
{
|
||||
"a": {
|
||||
"foo": 1,
|
||||
"b": [ "foo", "bar" ]
|
||||
}
|
||||
}
|
||||
)");
|
||||
CHECK(doc1.patch(patch1) == doc1_ans);
|
||||
}
|
||||
|
||||
SECTION("diff")
|
||||
{
|
||||
alt_json const j1 = {"foo", "bar", "baz"};
|
||||
alt_json const j2 = {"foo", "bam"};
|
||||
CHECK(alt_json::diff(j1, j2).dump() == "[{\"op\":\"replace\",\"path\":\"/1\",\"value\":\"bam\"},{\"op\":\"remove\",\"path\":\"/2\"}]");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
// | | |__ | | | | | | version 3.11.3
|
||||
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
//
|
||||
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-FileCopyrightText: 2013 - 2024 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#include "doctest_compatibility.h"
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
// | | |__ | | | | | | version 3.11.3
|
||||
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
//
|
||||
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-FileCopyrightText: 2013 - 2024 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#include "doctest_compatibility.h"
|
||||
|
||||
26
external/json/tests/src/unit-bjdata.cpp
vendored
26
external/json/tests/src/unit-bjdata.cpp
vendored
@@ -3,7 +3,7 @@
|
||||
// | | |__ | | | | | | version 3.11.3
|
||||
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
//
|
||||
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-FileCopyrightText: 2013 - 2024 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#include "doctest_compatibility.h"
|
||||
@@ -109,7 +109,7 @@ struct trait_test_arg
|
||||
static constexpr bool max_in_range = MaxInRange;
|
||||
};
|
||||
|
||||
TEST_CASE_TEMPLATE_DEFINE("value_in_range_of trait", T, value_in_range_of_test)
|
||||
TEST_CASE_TEMPLATE_DEFINE("value_in_range_of trait", T, value_in_range_of_test) // NOLINT(readability-math-missing-parentheses)
|
||||
{
|
||||
using nlohmann::detail::value_in_range_of;
|
||||
|
||||
@@ -339,13 +339,13 @@ TEST_CASE("BJData")
|
||||
std::vector<int32_t> const numbers
|
||||
{
|
||||
-32769,
|
||||
-100000,
|
||||
-1000000,
|
||||
-10000000,
|
||||
-100000000,
|
||||
-1000000000,
|
||||
-2147483647 - 1, // https://stackoverflow.com/a/29356002/266378
|
||||
};
|
||||
-100000,
|
||||
-1000000,
|
||||
-10000000,
|
||||
-100000000,
|
||||
-1000000000,
|
||||
-2147483647 - 1, // https://stackoverflow.com/a/29356002/266378
|
||||
};
|
||||
for (const auto i : numbers)
|
||||
{
|
||||
CAPTURE(i)
|
||||
@@ -573,7 +573,7 @@ TEST_CASE("BJData")
|
||||
|
||||
// check individual bytes
|
||||
CHECK(result[0] == 'I');
|
||||
auto const restored = static_cast<uint16_t>(static_cast<uint8_t>(result[2]) * 256 + static_cast<uint8_t>(result[1]));
|
||||
auto const restored = static_cast<uint16_t>((static_cast<uint8_t>(result[2]) * 256) + static_cast<uint8_t>(result[1]));
|
||||
CHECK(restored == i);
|
||||
|
||||
// roundtrip
|
||||
@@ -613,7 +613,7 @@ TEST_CASE("BJData")
|
||||
|
||||
// check individual bytes
|
||||
CHECK(result[0] == 'u');
|
||||
auto const restored = static_cast<uint16_t>(static_cast<uint8_t>(result[2]) * 256 + static_cast<uint8_t>(result[1]));
|
||||
auto const restored = static_cast<uint16_t>((static_cast<uint8_t>(result[2]) * 256) + static_cast<uint8_t>(result[1]));
|
||||
CHECK(restored == i);
|
||||
|
||||
// roundtrip
|
||||
@@ -905,7 +905,7 @@ TEST_CASE("BJData")
|
||||
|
||||
// check individual bytes
|
||||
CHECK(result[0] == 'I');
|
||||
auto const restored = static_cast<uint16_t>(static_cast<uint8_t>(result[2]) * 256 + static_cast<uint8_t>(result[1]));
|
||||
auto const restored = static_cast<uint16_t>((static_cast<uint8_t>(result[2]) * 256) + static_cast<uint8_t>(result[1]));
|
||||
CHECK(restored == i);
|
||||
|
||||
// roundtrip
|
||||
@@ -944,7 +944,7 @@ TEST_CASE("BJData")
|
||||
|
||||
// check individual bytes
|
||||
CHECK(result[0] == 'u');
|
||||
auto const restored = static_cast<uint16_t>(static_cast<uint8_t>(result[2]) * 256 + static_cast<uint8_t>(result[1]));
|
||||
auto const restored = static_cast<uint16_t>((static_cast<uint8_t>(result[2]) * 256) + static_cast<uint8_t>(result[1]));
|
||||
CHECK(restored == i);
|
||||
|
||||
// roundtrip
|
||||
|
||||
4
external/json/tests/src/unit-bson.cpp
vendored
4
external/json/tests/src/unit-bson.cpp
vendored
@@ -3,7 +3,7 @@
|
||||
// | | |__ | | | | | | version 3.11.3
|
||||
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
//
|
||||
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-FileCopyrightText: 2013 - 2024 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#include "doctest_compatibility.h"
|
||||
@@ -621,7 +621,7 @@ TEST_CASE("BSON input/output_adapters")
|
||||
{
|
||||
SECTION("std::ostringstream")
|
||||
{
|
||||
std::basic_ostringstream<std::uint8_t> ss;
|
||||
std::basic_ostringstream<char> ss;
|
||||
json::to_bson(json_representation, ss);
|
||||
json j3 = json::from_bson(ss.str());
|
||||
CHECK(json_representation == j3);
|
||||
|
||||
@@ -3,8 +3,7 @@
|
||||
// | | |__ | | | | | | version 3.11.3
|
||||
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
//
|
||||
// Copyright (c) 2013-2022 Niels Lohmann <http://nlohmann.me>.
|
||||
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-FileCopyrightText: 2013 - 2024 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#include "doctest_compatibility.h"
|
||||
|
||||
3
external/json/tests/src/unit-capacity.cpp
vendored
3
external/json/tests/src/unit-capacity.cpp
vendored
@@ -3,8 +3,7 @@
|
||||
// | | |__ | | | | | | version 3.11.3
|
||||
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
//
|
||||
// Copyright (c) 2013-2022 Niels Lohmann <http://nlohmann.me>.
|
||||
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-FileCopyrightText: 2013 - 2024 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#include "doctest_compatibility.h"
|
||||
|
||||
29
external/json/tests/src/unit-cbor.cpp
vendored
29
external/json/tests/src/unit-cbor.cpp
vendored
@@ -3,7 +3,7 @@
|
||||
// | | |__ | | | | | | version 3.11.3
|
||||
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
//
|
||||
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-FileCopyrightText: 2013 - 2024 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#include "doctest_compatibility.h"
|
||||
@@ -14,7 +14,6 @@ using nlohmann::json;
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
#include <limits>
|
||||
#include <set>
|
||||
#include "make_test_data_available.hpp"
|
||||
@@ -241,13 +240,13 @@ TEST_CASE("CBOR")
|
||||
const std::vector<int64_t> numbers
|
||||
{
|
||||
-65537,
|
||||
-100000,
|
||||
-1000000,
|
||||
-10000000,
|
||||
-100000000,
|
||||
-1000000000,
|
||||
-4294967296,
|
||||
};
|
||||
-100000,
|
||||
-1000000,
|
||||
-10000000,
|
||||
-100000000,
|
||||
-1000000000,
|
||||
-4294967296,
|
||||
};
|
||||
for (const auto i : numbers)
|
||||
{
|
||||
CAPTURE(i)
|
||||
@@ -317,7 +316,7 @@ TEST_CASE("CBOR")
|
||||
|
||||
// check individual bytes
|
||||
CHECK(result[0] == 0x39);
|
||||
const auto restored = static_cast<uint16_t>(static_cast<uint8_t>(result[1]) * 256 + static_cast<uint8_t>(result[2]));
|
||||
const auto restored = static_cast<uint16_t>((static_cast<uint8_t>(result[1]) * 256) + static_cast<uint8_t>(result[2]));
|
||||
CHECK(restored == positive);
|
||||
CHECK(-1 - restored == i);
|
||||
|
||||
@@ -505,7 +504,7 @@ TEST_CASE("CBOR")
|
||||
|
||||
// check individual bytes
|
||||
CHECK(result[0] == 0x19);
|
||||
const auto restored = static_cast<uint16_t>(static_cast<uint8_t>(result[1]) * 256 + static_cast<uint8_t>(result[2]));
|
||||
const auto restored = static_cast<uint16_t>((static_cast<uint8_t>(result[1]) * 256) + static_cast<uint8_t>(result[2]));
|
||||
CHECK(restored == i);
|
||||
|
||||
// roundtrip
|
||||
@@ -744,7 +743,7 @@ TEST_CASE("CBOR")
|
||||
|
||||
// check individual bytes
|
||||
CHECK(result[0] == 0x19);
|
||||
const auto restored = static_cast<uint16_t>(static_cast<uint8_t>(result[1]) * 256 + static_cast<uint8_t>(result[2]));
|
||||
const auto restored = static_cast<uint16_t>((static_cast<uint8_t>(result[1]) * 256) + static_cast<uint8_t>(result[2]));
|
||||
CHECK(restored == i);
|
||||
|
||||
// roundtrip
|
||||
@@ -990,7 +989,7 @@ TEST_CASE("CBOR")
|
||||
{
|
||||
0xfa, 0xff, 0x7f, 0xff, 0xff
|
||||
};
|
||||
// the same with lowest float
|
||||
// the same with the lowest float
|
||||
const auto result = json::to_cbor(j);
|
||||
CHECK(result == expected);
|
||||
// roundtrip
|
||||
@@ -1632,7 +1631,7 @@ TEST_CASE("CBOR")
|
||||
};
|
||||
|
||||
json j;
|
||||
auto cbp = nlohmann::detail::json_sax_dom_callback_parser<json>(j, callback, true);
|
||||
auto cbp = nlohmann::detail::json_sax_dom_callback_parser<json, nlohmann::detail::string_input_adapter_type>(j, callback, true);
|
||||
CHECK(json::sax_parse(input, &cbp, json::input_format_t::cbor));
|
||||
CHECK(j.at("foo").is_binary());
|
||||
CHECK(binary_seen);
|
||||
@@ -1881,7 +1880,7 @@ TEST_CASE("single CBOR roundtrip")
|
||||
{
|
||||
SECTION("std::ostringstream")
|
||||
{
|
||||
std::basic_ostringstream<std::uint8_t> ss;
|
||||
std::basic_ostringstream<char> ss;
|
||||
json::to_cbor(j1, ss);
|
||||
json j3 = json::from_cbor(ss.str());
|
||||
CHECK(j1 == j3);
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
// | | |__ | | | | | | version 3.11.3
|
||||
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
//
|
||||
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-FileCopyrightText: 2013 - 2024 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#include "doctest_compatibility.h"
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
// | | |__ | | | | | | version 3.11.3
|
||||
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
//
|
||||
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-FileCopyrightText: 2013 - 2024 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#include "doctest_compatibility.h"
|
||||
|
||||
4
external/json/tests/src/unit-class_lexer.cpp
vendored
4
external/json/tests/src/unit-class_lexer.cpp
vendored
@@ -3,7 +3,7 @@
|
||||
// | | |__ | | | | | | version 3.11.3
|
||||
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
//
|
||||
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-FileCopyrightText: 2013 - 2024 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#include "doctest_compatibility.h"
|
||||
@@ -23,7 +23,7 @@ json::lexer::token_type scan_string(const char* s, const bool ignore_comments)
|
||||
}
|
||||
} // namespace
|
||||
|
||||
std::string get_error_message(const char* s, bool ignore_comments = false);
|
||||
std::string get_error_message(const char* s, bool ignore_comments = false); // NOLINT(misc-use-internal-linkage)
|
||||
std::string get_error_message(const char* s, const bool ignore_comments)
|
||||
{
|
||||
auto ia = nlohmann::detail::input_adapter(s);
|
||||
|
||||
12
external/json/tests/src/unit-class_parser.cpp
vendored
12
external/json/tests/src/unit-class_parser.cpp
vendored
@@ -3,7 +3,7 @@
|
||||
// | | |__ | | | | | | version 3.11.3
|
||||
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
//
|
||||
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-FileCopyrightText: 2013 - 2024 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#include "doctest_compatibility.h"
|
||||
@@ -75,7 +75,7 @@ class SaxEventLogger
|
||||
|
||||
bool start_object(std::size_t elements)
|
||||
{
|
||||
if (elements == static_cast<std::size_t>(-1))
|
||||
if (elements == (std::numeric_limits<std::size_t>::max)())
|
||||
{
|
||||
events.emplace_back("start_object()");
|
||||
}
|
||||
@@ -100,7 +100,7 @@ class SaxEventLogger
|
||||
|
||||
bool start_array(std::size_t elements)
|
||||
{
|
||||
if (elements == static_cast<std::size_t>(-1))
|
||||
if (elements == (std::numeric_limits<std::size_t>::max)())
|
||||
{
|
||||
events.emplace_back("start_array()");
|
||||
}
|
||||
@@ -124,7 +124,7 @@ class SaxEventLogger
|
||||
return false;
|
||||
}
|
||||
|
||||
std::vector<std::string> events {};
|
||||
std::vector<std::string> events {}; // NOLINT(readability-redundant-member-init)
|
||||
bool errored = false;
|
||||
};
|
||||
|
||||
@@ -219,7 +219,7 @@ json parser_helper(const std::string& s)
|
||||
CHECK(j_nothrow == j);
|
||||
|
||||
json j_sax;
|
||||
nlohmann::detail::json_sax_dom_parser<json> sdp(j_sax);
|
||||
nlohmann::detail::json_sax_dom_parser<json, nlohmann::detail::string_input_adapter_type> sdp(j_sax);
|
||||
json::sax_parse(s, &sdp);
|
||||
CHECK(j_sax == j);
|
||||
|
||||
@@ -828,7 +828,7 @@ TEST_CASE("parser class")
|
||||
// for ranges in range of IEEE 754-2008 binary64 (double precision)
|
||||
// this does not accommodate 64 bit integers without loss of accuracy.
|
||||
// As 64 bit integers are now widely used in software, it is desirable
|
||||
// to expand support to to the full 64 bit (signed and unsigned) range
|
||||
// to expand support to the full 64 bit (signed and unsigned) range
|
||||
// i.e. -(2**63) -> (2**64)-1.
|
||||
|
||||
// -(2**63) ** Note: compilers see negative literals as negated positive numbers (hence the -1))
|
||||
|
||||
1957
external/json/tests/src/unit-class_parser_diagnostic_positions.cpp
vendored
Normal file
1957
external/json/tests/src/unit-class_parser_diagnostic_positions.cpp
vendored
Normal file
File diff suppressed because it is too large
Load Diff
2
external/json/tests/src/unit-comparison.cpp
vendored
2
external/json/tests/src/unit-comparison.cpp
vendored
@@ -3,7 +3,7 @@
|
||||
// | | |__ | | | | | | version 3.11.3
|
||||
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
//
|
||||
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-FileCopyrightText: 2013 - 2024 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
// cmake/test.cmake selects the C++ standard versions with which to build a
|
||||
|
||||
3
external/json/tests/src/unit-concepts.cpp
vendored
3
external/json/tests/src/unit-concepts.cpp
vendored
@@ -3,7 +3,7 @@
|
||||
// | | |__ | | | | | | version 3.11.3
|
||||
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
//
|
||||
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-FileCopyrightText: 2013 - 2024 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#include "doctest_compatibility.h"
|
||||
@@ -20,7 +20,6 @@ TEST_CASE("concepts")
|
||||
// a, b: values of type X: json
|
||||
|
||||
// TABLE 96 - Container Requirements
|
||||
|
||||
// X::value_type must return T
|
||||
CHECK((std::is_same<json::value_type, json>::value));
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
// | | |__ | | | | | | version 3.11.3
|
||||
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
//
|
||||
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-FileCopyrightText: 2013 - 2024 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#include "doctest_compatibility.h"
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
// | | |__ | | | | | | version 3.11.3
|
||||
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
//
|
||||
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-FileCopyrightText: 2013 - 2024 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#include "doctest_compatibility.h"
|
||||
|
||||
6
external/json/tests/src/unit-convenience.cpp
vendored
6
external/json/tests/src/unit-convenience.cpp
vendored
@@ -3,7 +3,7 @@
|
||||
// | | |__ | | | | | | version 3.11.3
|
||||
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
//
|
||||
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-FileCopyrightText: 2013 - 2024 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#include "doctest_compatibility.h"
|
||||
@@ -55,7 +55,7 @@ struct alt_string_iter
|
||||
return *this;
|
||||
}
|
||||
|
||||
std::string impl{};
|
||||
std::string impl{}; // NOLINT(readability-redundant-member-init)
|
||||
};
|
||||
|
||||
struct alt_string_data
|
||||
@@ -91,7 +91,7 @@ struct alt_string_data
|
||||
return *this;
|
||||
}
|
||||
|
||||
std::string impl{};
|
||||
std::string impl{}; // NOLINT(readability-redundant-member-init)
|
||||
};
|
||||
|
||||
void check_escaped(const char* original, const char* escaped = "", bool ensure_ascii = false);
|
||||
|
||||
164
external/json/tests/src/unit-conversions.cpp
vendored
164
external/json/tests/src/unit-conversions.cpp
vendored
@@ -3,8 +3,7 @@
|
||||
// | | |__ | | | | | | version 3.11.3
|
||||
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
//
|
||||
// Copyright (c) 2013-2022 Niels Lohmann <http://nlohmann.me>.
|
||||
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-FileCopyrightText: 2013 - 2024 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
// cmake/test.cmake selects the C++ standard versions with which to build a
|
||||
@@ -16,6 +15,11 @@
|
||||
|
||||
#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
|
||||
#include <nlohmann/json.hpp>
|
||||
using nlohmann::json;
|
||||
@@ -32,6 +36,25 @@ using nlohmann::json;
|
||||
DOCTEST_CLANG_SUPPRESS_WARNING_PUSH
|
||||
DOCTEST_CLANG_SUPPRESS_WARNING("-Wexit-time-destructors")
|
||||
|
||||
#if (defined(__cplusplus) && __cplusplus >= 201703L) || (defined(_HAS_CXX17) && _HAS_CXX17 == 1) // fix for issue #464
|
||||
#define JSON_HAS_CPP_17
|
||||
#define JSON_HAS_CPP_14
|
||||
#elif (defined(__cplusplus) && __cplusplus >= 201402L) || (defined(_HAS_CXX14) && _HAS_CXX14 == 1)
|
||||
#define JSON_HAS_CPP_14
|
||||
#endif
|
||||
|
||||
#ifdef JSON_HAS_CPP_17
|
||||
#if __has_include(<optional>)
|
||||
#include <optional>
|
||||
#elif __has_include(<experimental/optional>)
|
||||
#include <experimental/optional>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(JSON_HAS_CPP_17)
|
||||
#include <string_view>
|
||||
#endif
|
||||
|
||||
TEST_CASE("value conversion")
|
||||
{
|
||||
SECTION("get an object (explicit)")
|
||||
@@ -153,6 +176,7 @@ TEST_CASE("value conversion")
|
||||
}
|
||||
|
||||
#if JSON_USE_IMPLICIT_CONVERSIONS
|
||||
|
||||
SECTION("get an object (implicit)")
|
||||
{
|
||||
const json::object_t o_reference = {{"object", json::object()},
|
||||
@@ -344,6 +368,68 @@ TEST_CASE("value conversion")
|
||||
CHECK(std::equal(std::begin(nbs), std::end(nbs), std::begin(nbs2)));
|
||||
}
|
||||
|
||||
SECTION("built-in arrays: 2D")
|
||||
{
|
||||
const int nbs[][3] = {{0, 1, 2}, {3, 4, 5}}; // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays)
|
||||
int nbs2[][3] = {{0, 0, 0}, {0, 0, 0}}; // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays)
|
||||
|
||||
const json j2 = nbs;
|
||||
j2.get_to(nbs2);
|
||||
CHECK(std::equal(std::begin(nbs[0]), std::end(nbs[1]), std::begin(nbs2[0])));
|
||||
}
|
||||
|
||||
SECTION("built-in arrays: 3D")
|
||||
{
|
||||
// NOLINTBEGIN(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays)
|
||||
const int nbs[][2][3] = {\
|
||||
{{0, 1, 2}, {3, 4, 5}}, \
|
||||
{{10, 11, 12}, {13, 14, 15}}\
|
||||
};
|
||||
int nbs2[][2][3] = {\
|
||||
{{0, 0, 0}, {0, 0, 0}}, \
|
||||
{{0, 0, 0}, {0, 0, 0}}\
|
||||
};
|
||||
// NOLINTEND(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays)
|
||||
|
||||
const json j2 = nbs;
|
||||
j2.get_to(nbs2);
|
||||
CHECK(std::equal(std::begin(nbs[0][0]), std::end(nbs[1][1]), std::begin(nbs2[0][0])));
|
||||
}
|
||||
|
||||
SECTION("built-in arrays: 4D")
|
||||
{
|
||||
// NOLINTBEGIN(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays)
|
||||
const int nbs[][2][2][3] = {\
|
||||
{
|
||||
\
|
||||
{{0, 1, 2}, {3, 4, 5}}, \
|
||||
{{10, 11, 12}, {13, 14, 15}}\
|
||||
}, \
|
||||
{
|
||||
\
|
||||
{{20, 21, 22}, {23, 24, 25}}, \
|
||||
{{30, 31, 32}, {33, 34, 35}}\
|
||||
}\
|
||||
};
|
||||
int nbs2[][2][2][3] = {\
|
||||
{
|
||||
\
|
||||
{{0, 0, 0}, {0, 0, 0}}, \
|
||||
{{0, 0, 0}, {0, 0, 0}}\
|
||||
}, \
|
||||
{
|
||||
\
|
||||
{{0, 0, 0}, {0, 0, 0}}, \
|
||||
{{0, 0, 0}, {0, 0, 0}}\
|
||||
}\
|
||||
};
|
||||
// NOLINTEND(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays)
|
||||
|
||||
const json j2 = nbs;
|
||||
j2.get_to(nbs2);
|
||||
CHECK(std::equal(std::begin(nbs[0][0][0]), std::end(nbs[1][1][1]), std::begin(nbs2[0][0][0])));
|
||||
}
|
||||
|
||||
SECTION("std::deque<json>")
|
||||
{
|
||||
std::deque<json> a{"previous", "value"};
|
||||
@@ -1164,7 +1250,7 @@ TEST_CASE("value conversion")
|
||||
|
||||
SECTION("non-const")
|
||||
{
|
||||
const json j_const = j;
|
||||
const json j_const = j; // NOLINT(performance-unnecessary-copy-initialization)
|
||||
const auto& b = j_const.get_binary();
|
||||
CHECK(*json(b).m_data.m_value.binary == *j.m_data.m_value.binary);
|
||||
}
|
||||
@@ -1263,6 +1349,7 @@ TEST_CASE("value conversion")
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef SKIP_TESTS_FOR_ENUM_SERIALIZATION
|
||||
SECTION("get an enum")
|
||||
{
|
||||
enum c_enum { value_1, value_2 };
|
||||
@@ -1271,6 +1358,7 @@ TEST_CASE("value conversion")
|
||||
CHECK(json(value_1).get<c_enum>() == value_1);
|
||||
CHECK(json(cpp_enum::value_1).get<cpp_enum>() == cpp_enum::value_1);
|
||||
}
|
||||
#endif
|
||||
|
||||
SECTION("more involved conversions")
|
||||
{
|
||||
@@ -1513,7 +1601,7 @@ NLOHMANN_JSON_SERIALIZE_ENUM(cards,
|
||||
{cards::karo, "karo"}
|
||||
})
|
||||
|
||||
enum TaskState
|
||||
enum TaskState // NOLINT(cert-int09-c,readability-enum-initial-value)
|
||||
{
|
||||
TS_STOPPED,
|
||||
TS_RUNNING,
|
||||
@@ -1569,4 +1657,72 @@ TEST_CASE("JSON to enum mapping")
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef JSON_HAS_CPP_17
|
||||
#ifndef JSON_USE_IMPLICIT_CONVERSIONS
|
||||
TEST_CASE("std::optional")
|
||||
{
|
||||
SECTION("null")
|
||||
{
|
||||
json j_null;
|
||||
std::optional<std::string> opt_null;
|
||||
|
||||
CHECK(json(opt_null) == j_null);
|
||||
CHECK(j_null.get<std::optional<std::string>>() == std::nullopt);
|
||||
}
|
||||
|
||||
SECTION("string")
|
||||
{
|
||||
json j_string = "string";
|
||||
std::optional<std::string> opt_string = "string";
|
||||
|
||||
CHECK(json(opt_string) == j_string);
|
||||
CHECK(std::optional<std::string>(j_string) == opt_string);
|
||||
}
|
||||
|
||||
SECTION("bool")
|
||||
{
|
||||
json j_bool = true;
|
||||
std::optional<bool> opt_bool = true;
|
||||
|
||||
CHECK(json(opt_bool) == j_bool);
|
||||
CHECK(std::optional<bool>(j_bool) == opt_bool);
|
||||
}
|
||||
|
||||
SECTION("number")
|
||||
{
|
||||
json j_number = 1;
|
||||
std::optional<int> opt_int = 1;
|
||||
|
||||
CHECK(json(opt_int) == j_number);
|
||||
CHECK(j_number.get<std::optional<int>>() == opt_int);
|
||||
}
|
||||
|
||||
SECTION("array")
|
||||
{
|
||||
json j_array = {1, 2, nullptr};
|
||||
std::vector<std::optional<int>> opt_array = {{1, 2, std::nullopt}};
|
||||
|
||||
CHECK(json(opt_array) == j_array);
|
||||
CHECK(j_array.get<std::vector<std::optional<int>>>() == opt_array);
|
||||
}
|
||||
|
||||
SECTION("object")
|
||||
{
|
||||
json j_object = {{"one", 1}, {"two", 2}, {"zero", nullptr}};
|
||||
std::map<std::string, std::optional<int>> opt_object {{"one", 1}, {"two", 2}, {"zero", std::nullopt}};
|
||||
|
||||
CHECK(json(opt_object) == j_object);
|
||||
CHECK(std::map<std::string, std::optional<int>>(j_object) == opt_object);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef JSON_HAS_CPP_17
|
||||
#undef JSON_HAS_CPP_17
|
||||
#endif
|
||||
|
||||
#ifdef JSON_HAS_CPP_14
|
||||
#undef JSON_HAS_CPP_14
|
||||
#endif
|
||||
DOCTEST_CLANG_SUPPRESS_WARNING_POP
|
||||
|
||||
@@ -3,8 +3,7 @@
|
||||
// | | |__ | | | | | | version 3.11.3
|
||||
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
//
|
||||
// Copyright (c) 2013-2019 Niels Lohmann <http://nlohmann.me>.
|
||||
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-FileCopyrightText: 2013 - 2024 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#include <set>
|
||||
@@ -283,8 +282,8 @@ TEST_CASE("JSON Visit Node")
|
||||
};
|
||||
|
||||
json.visit(
|
||||
[&](const json_with_visitor_t::json_pointer & p,
|
||||
const json_with_visitor_t& j)
|
||||
[&](const json_with_visitor_t::json_pointer & p,
|
||||
const json_with_visitor_t& j)
|
||||
{
|
||||
std::stringstream str;
|
||||
str << p.to_string() << " - " ;
|
||||
@@ -331,6 +330,6 @@ TEST_CASE("JSON Visit Node")
|
||||
CHECK(expected.count(str.str()) == 1);
|
||||
expected.erase(str.str());
|
||||
}
|
||||
);
|
||||
);
|
||||
CHECK(expected.empty());
|
||||
}
|
||||
|
||||
44
external/json/tests/src/unit-deserialization.cpp
vendored
44
external/json/tests/src/unit-deserialization.cpp
vendored
@@ -3,8 +3,7 @@
|
||||
// | | |__ | | | | | | version 3.11.3
|
||||
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
//
|
||||
// Copyright (c) 2013-2022 Niels Lohmann <http://nlohmann.me>.
|
||||
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-FileCopyrightText: 2013 - 2024 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#include "doctest_compatibility.h"
|
||||
@@ -77,7 +76,7 @@ struct SaxEventLogger : public nlohmann::json_sax<json>
|
||||
|
||||
bool start_object(std::size_t elements) override
|
||||
{
|
||||
if (elements == static_cast<std::size_t>(-1))
|
||||
if (elements == (std::numeric_limits<std::size_t>::max)())
|
||||
{
|
||||
events.emplace_back("start_object()");
|
||||
}
|
||||
@@ -102,7 +101,7 @@ struct SaxEventLogger : public nlohmann::json_sax<json>
|
||||
|
||||
bool start_array(std::size_t elements) override
|
||||
{
|
||||
if (elements == static_cast<std::size_t>(-1))
|
||||
if (elements == (std::numeric_limits<std::size_t>::max)())
|
||||
{
|
||||
events.emplace_back("start_array()");
|
||||
}
|
||||
@@ -125,14 +124,14 @@ struct SaxEventLogger : public nlohmann::json_sax<json>
|
||||
return false;
|
||||
}
|
||||
|
||||
std::vector<std::string> events {};
|
||||
std::vector<std::string> events {}; // NOLINT(readability-redundant-member-init)
|
||||
};
|
||||
|
||||
struct SaxEventLoggerExitAfterStartObject : public SaxEventLogger
|
||||
{
|
||||
bool start_object(std::size_t elements) override
|
||||
{
|
||||
if (elements == static_cast<std::size_t>(-1))
|
||||
if (elements == (std::numeric_limits<std::size_t>::max)())
|
||||
{
|
||||
events.emplace_back("start_object()");
|
||||
}
|
||||
@@ -157,7 +156,7 @@ struct SaxEventLoggerExitAfterStartArray : public SaxEventLogger
|
||||
{
|
||||
bool start_array(std::size_t elements) override
|
||||
{
|
||||
if (elements == static_cast<std::size_t>(-1))
|
||||
if (elements == (std::numeric_limits<std::size_t>::max)())
|
||||
{
|
||||
events.emplace_back("start_array()");
|
||||
}
|
||||
@@ -360,6 +359,10 @@ TEST_CASE("deserialization")
|
||||
"start_object()", "key(one)", "number_unsigned(1)",
|
||||
"end_object()", "parse_error(29)"
|
||||
}));
|
||||
|
||||
const char* string = nullptr;
|
||||
CHECK_THROWS_WITH_AS(_ = json::parse(string), "[json.exception.parse_error.101] parse error: attempting to parse an empty input; check that your input string or stream contains the expected JSON", json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(_ = json::parse(nullptr), "[json.exception.parse_error.101] parse error: attempting to parse an empty input; check that your input string or stream contains the expected JSON", json::parse_error&);
|
||||
}
|
||||
|
||||
SECTION("operator<<")
|
||||
@@ -583,7 +586,7 @@ TEST_CASE("deserialization")
|
||||
auto first = str.begin();
|
||||
auto last = str.end();
|
||||
json j;
|
||||
json_sax_dom_parser<json> sax(j, true);
|
||||
json_sax_dom_parser<json, nlohmann::detail::string_input_adapter_type> sax(j, true);
|
||||
|
||||
CHECK(json::sax_parse(proxy(first), proxy(last), &sax,
|
||||
input_format_t::json, false));
|
||||
@@ -1131,13 +1134,15 @@ TEST_CASE("deserialization")
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE_TEMPLATE("deserialization of different character types (ASCII)", T,
|
||||
char, unsigned char, signed char,
|
||||
wchar_t,
|
||||
char16_t, char32_t,
|
||||
std::uint8_t, std::int8_t,
|
||||
std::int16_t, std::uint16_t,
|
||||
std::int32_t, std::uint32_t)
|
||||
// select the types to test - char8_t is only available in C++20
|
||||
#define TYPE_LIST(...) __VA_ARGS__
|
||||
#ifdef JSON_HAS_CPP_20
|
||||
#define ASCII_TYPES TYPE_LIST(char, wchar_t, char16_t, char32_t, char8_t)
|
||||
#else
|
||||
#define ASCII_TYPES TYPE_LIST(char, wchar_t, char16_t, char32_t)
|
||||
#endif
|
||||
|
||||
TEST_CASE_TEMPLATE("deserialization of different character types (ASCII)", T, ASCII_TYPES) // NOLINT(readability-math-missing-parentheses)
|
||||
{
|
||||
std::vector<T> const v = {'t', 'r', 'u', 'e'};
|
||||
CHECK(json::parse(v) == json(true));
|
||||
@@ -1149,8 +1154,7 @@ TEST_CASE_TEMPLATE("deserialization of different character types (ASCII)", T,
|
||||
CHECK(l.events == std::vector<std::string>({"boolean(true)"}));
|
||||
}
|
||||
|
||||
TEST_CASE_TEMPLATE("deserialization of different character types (UTF-8)", T,
|
||||
char, unsigned char, std::uint8_t)
|
||||
TEST_CASE_TEMPLATE("deserialization of different character types (UTF-8)", T, char, unsigned char, std::uint8_t) // NOLINT(readability-math-missing-parentheses)
|
||||
{
|
||||
// a star emoji
|
||||
std::vector<T> const v = {'"', static_cast<T>(0xe2u), static_cast<T>(0xadu), static_cast<T>(0x90u), static_cast<T>(0xefu), static_cast<T>(0xb8u), static_cast<T>(0x8fu), '"'};
|
||||
@@ -1162,8 +1166,7 @@ TEST_CASE_TEMPLATE("deserialization of different character types (UTF-8)", T,
|
||||
CHECK(l.events.size() == 1);
|
||||
}
|
||||
|
||||
TEST_CASE_TEMPLATE("deserialization of different character types (UTF-16)", T,
|
||||
char16_t, std::uint16_t)
|
||||
TEST_CASE_TEMPLATE("deserialization of different character types (UTF-16)", T, char16_t) // NOLINT(readability-math-missing-parentheses)
|
||||
{
|
||||
// a star emoji
|
||||
std::vector<T> const v = {static_cast<T>('"'), static_cast<T>(0x2b50), static_cast<T>(0xfe0f), static_cast<T>('"')};
|
||||
@@ -1175,8 +1178,7 @@ TEST_CASE_TEMPLATE("deserialization of different character types (UTF-16)", T,
|
||||
CHECK(l.events.size() == 1);
|
||||
}
|
||||
|
||||
TEST_CASE_TEMPLATE("deserialization of different character types (UTF-32)", T,
|
||||
char32_t, std::uint32_t)
|
||||
TEST_CASE_TEMPLATE("deserialization of different character types (UTF-32)", T, char32_t) // NOLINT(readability-math-missing-parentheses)
|
||||
{
|
||||
// a star emoji
|
||||
std::vector<T> const v = {static_cast<T>('"'), static_cast<T>(0x2b50), static_cast<T>(0xfe0f), static_cast<T>('"')};
|
||||
|
||||
23
external/json/tests/src/unit-diagnostics.cpp
vendored
23
external/json/tests/src/unit-diagnostics.cpp
vendored
@@ -3,8 +3,7 @@
|
||||
// | | |__ | | | | | | version 3.11.3
|
||||
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
//
|
||||
// Copyright (c) 2013-2022 Niels Lohmann <http://nlohmann.me>.
|
||||
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-FileCopyrightText: 2013 - 2024 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#include "doctest_compatibility.h"
|
||||
@@ -243,4 +242,24 @@ TEST_CASE("Regression tests for extended diagnostics")
|
||||
json const j_arr_copy = j_arr;
|
||||
}
|
||||
}
|
||||
|
||||
SECTION("Regression test for issue #3915 - JSON_DIAGNOSTICS trigger assertion")
|
||||
{
|
||||
json j = json::object();
|
||||
j["root"] = "root_str";
|
||||
|
||||
json jj = json::object();
|
||||
jj["child"] = json::object();
|
||||
|
||||
// If do not push anything in object, then no assert will be produced
|
||||
jj["child"]["prop1"] = "prop1_value";
|
||||
|
||||
// Push all properties of child in parent
|
||||
j.insert(jj.at("child").begin(), jj.at("child").end());
|
||||
|
||||
// Here assert is generated when construct new json
|
||||
const json k(j);
|
||||
|
||||
CHECK(k.dump() == "{\"prop1\":\"prop1_value\",\"root\":\"root_str\"}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,8 +3,7 @@
|
||||
// | | |__ | | | | | | version 3.11.3
|
||||
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
//
|
||||
// Copyright (c) 2013-2022 Niels Lohmann <http://nlohmann.me>.
|
||||
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-FileCopyrightText: 2013 - 2024 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#include "doctest_compatibility.h"
|
||||
@@ -20,10 +19,10 @@ using json = nlohmann::json;
|
||||
// for #2824
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
|
||||
class sax_no_exception : public nlohmann::detail::json_sax_dom_parser<json>
|
||||
class sax_no_exception : public nlohmann::detail::json_sax_dom_parser<json, nlohmann::detail::string_input_adapter_type>
|
||||
{
|
||||
public:
|
||||
explicit sax_no_exception(json& j) : nlohmann::detail::json_sax_dom_parser<json>(j, false) {}
|
||||
explicit sax_no_exception(json& j) : nlohmann::detail::json_sax_dom_parser<json, nlohmann::detail::string_input_adapter_type>(j, false) {}
|
||||
|
||||
static bool parse_error(std::size_t /*position*/, const std::string& /*last_token*/, const json::exception& ex)
|
||||
{
|
||||
|
||||
31
external/json/tests/src/unit-element_access1.cpp
vendored
31
external/json/tests/src/unit-element_access1.cpp
vendored
@@ -3,8 +3,7 @@
|
||||
// | | |__ | | | | | | version 3.11.3
|
||||
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
//
|
||||
// Copyright (c) 2013-2022 Niels Lohmann <http://nlohmann.me>.
|
||||
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-FileCopyrightText: 2013 - 2024 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#include "doctest_compatibility.h"
|
||||
@@ -55,7 +54,7 @@ TEST_CASE("element access 1")
|
||||
SECTION("null")
|
||||
{
|
||||
json j_nonarray(json::value_t::null);
|
||||
const json j_nonarray_const(j_nonarray);
|
||||
const json j_nonarray_const(j_nonarray); // NOLINT(performance-unnecessary-copy-initialization)
|
||||
|
||||
CHECK_THROWS_WITH_AS(j_nonarray.at(0), "[json.exception.type_error.304] cannot use at() with null", json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonarray_const.at(0), "[json.exception.type_error.304] cannot use at() with null", json::type_error&);
|
||||
@@ -64,7 +63,7 @@ TEST_CASE("element access 1")
|
||||
SECTION("boolean")
|
||||
{
|
||||
json j_nonarray(json::value_t::boolean);
|
||||
const json j_nonarray_const(j_nonarray);
|
||||
const json j_nonarray_const(j_nonarray); // NOLINT(performance-unnecessary-copy-initialization)
|
||||
|
||||
CHECK_THROWS_WITH_AS(j_nonarray.at(0), "[json.exception.type_error.304] cannot use at() with boolean", json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonarray_const.at(0), "[json.exception.type_error.304] cannot use at() with boolean", json::type_error&);
|
||||
@@ -73,7 +72,7 @@ TEST_CASE("element access 1")
|
||||
SECTION("string")
|
||||
{
|
||||
json j_nonarray(json::value_t::string);
|
||||
const json j_nonarray_const(j_nonarray);
|
||||
const json j_nonarray_const(j_nonarray); // NOLINT(performance-unnecessary-copy-initialization)
|
||||
|
||||
CHECK_THROWS_WITH_AS(j_nonarray.at(0), "[json.exception.type_error.304] cannot use at() with string", json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonarray_const.at(0), "[json.exception.type_error.304] cannot use at() with string", json::type_error&);
|
||||
@@ -82,7 +81,7 @@ TEST_CASE("element access 1")
|
||||
SECTION("object")
|
||||
{
|
||||
json j_nonarray(json::value_t::object);
|
||||
const json j_nonarray_const(j_nonarray);
|
||||
const json j_nonarray_const(j_nonarray); // NOLINT(performance-unnecessary-copy-initialization)
|
||||
|
||||
CHECK_THROWS_WITH_AS(j_nonarray.at(0), "[json.exception.type_error.304] cannot use at() with object", json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonarray_const.at(0), "[json.exception.type_error.304] cannot use at() with object", json::type_error&);
|
||||
@@ -91,7 +90,7 @@ TEST_CASE("element access 1")
|
||||
SECTION("number (integer)")
|
||||
{
|
||||
json j_nonarray(json::value_t::number_integer);
|
||||
const json j_nonarray_const(j_nonarray);
|
||||
const json j_nonarray_const(j_nonarray); // NOLINT(performance-unnecessary-copy-initialization)
|
||||
|
||||
CHECK_THROWS_WITH_AS(j_nonarray.at(0), "[json.exception.type_error.304] cannot use at() with number", json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonarray_const.at(0), "[json.exception.type_error.304] cannot use at() with number", json::type_error&);
|
||||
@@ -100,7 +99,7 @@ TEST_CASE("element access 1")
|
||||
SECTION("number (unsigned)")
|
||||
{
|
||||
json j_nonarray(json::value_t::number_unsigned);
|
||||
const json j_nonarray_const(j_nonarray);
|
||||
const json j_nonarray_const(j_nonarray); // NOLINT(performance-unnecessary-copy-initialization)
|
||||
|
||||
CHECK_THROWS_WITH_AS(j_nonarray.at(0), "[json.exception.type_error.304] cannot use at() with number", json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonarray_const.at(0), "[json.exception.type_error.304] cannot use at() with number", json::type_error&);
|
||||
@@ -109,7 +108,7 @@ TEST_CASE("element access 1")
|
||||
SECTION("number (floating-point)")
|
||||
{
|
||||
json j_nonarray(json::value_t::number_float);
|
||||
const json j_nonarray_const(j_nonarray);
|
||||
const json j_nonarray_const(j_nonarray); // NOLINT(performance-unnecessary-copy-initialization)
|
||||
|
||||
CHECK_THROWS_WITH_AS(j_nonarray.at(0), "[json.exception.type_error.304] cannot use at() with number", json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonarray_const.at(0), "[json.exception.type_error.304] cannot use at() with number", json::type_error&);
|
||||
@@ -155,7 +154,7 @@ TEST_CASE("element access 1")
|
||||
SECTION("standard tests")
|
||||
{
|
||||
json j_nonarray(json::value_t::null);
|
||||
const json j_nonarray_const(j_nonarray);
|
||||
const json j_nonarray_const(j_nonarray); // NOLINT(performance-unnecessary-copy-initialization)
|
||||
CHECK_NOTHROW(j_nonarray[0]);
|
||||
CHECK_THROWS_WITH_AS(j_nonarray_const[0], "[json.exception.type_error.305] cannot use operator[] with a numeric argument with null", json::type_error&);
|
||||
}
|
||||
@@ -171,7 +170,7 @@ TEST_CASE("element access 1")
|
||||
SECTION("boolean")
|
||||
{
|
||||
json j_nonarray(json::value_t::boolean);
|
||||
const json j_nonarray_const(j_nonarray);
|
||||
const json j_nonarray_const(j_nonarray); // NOLINT(performance-unnecessary-copy-initialization)
|
||||
CHECK_THROWS_WITH_AS(j_nonarray[0], "[json.exception.type_error.305] cannot use operator[] with a numeric argument with boolean", json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonarray_const[0], "[json.exception.type_error.305] cannot use operator[] with a numeric argument with boolean", json::type_error&);
|
||||
}
|
||||
@@ -179,7 +178,7 @@ TEST_CASE("element access 1")
|
||||
SECTION("string")
|
||||
{
|
||||
json j_nonarray(json::value_t::string);
|
||||
const json j_nonarray_const(j_nonarray);
|
||||
const json j_nonarray_const(j_nonarray); // NOLINT(performance-unnecessary-copy-initialization)
|
||||
CHECK_THROWS_WITH_AS(j_nonarray[0], "[json.exception.type_error.305] cannot use operator[] with a numeric argument with string", json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonarray_const[0], "[json.exception.type_error.305] cannot use operator[] with a numeric argument with string", json::type_error&);
|
||||
}
|
||||
@@ -187,7 +186,7 @@ TEST_CASE("element access 1")
|
||||
SECTION("object")
|
||||
{
|
||||
json j_nonarray(json::value_t::object);
|
||||
const json j_nonarray_const(j_nonarray);
|
||||
const json j_nonarray_const(j_nonarray); // NOLINT(performance-unnecessary-copy-initialization)
|
||||
CHECK_THROWS_WITH_AS(j_nonarray[0], "[json.exception.type_error.305] cannot use operator[] with a numeric argument with object", json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonarray_const[0], "[json.exception.type_error.305] cannot use operator[] with a numeric argument with object", json::type_error&);
|
||||
}
|
||||
@@ -195,7 +194,7 @@ TEST_CASE("element access 1")
|
||||
SECTION("number (integer)")
|
||||
{
|
||||
json j_nonarray(json::value_t::number_integer);
|
||||
const json j_nonarray_const(j_nonarray);
|
||||
const json j_nonarray_const(j_nonarray); // NOLINT(performance-unnecessary-copy-initialization)
|
||||
CHECK_THROWS_WITH_AS(j_nonarray[0], "[json.exception.type_error.305] cannot use operator[] with a numeric argument with number", json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonarray_const[0], "[json.exception.type_error.305] cannot use operator[] with a numeric argument with number", json::type_error&);
|
||||
}
|
||||
@@ -203,7 +202,7 @@ TEST_CASE("element access 1")
|
||||
SECTION("number (unsigned)")
|
||||
{
|
||||
json j_nonarray(json::value_t::number_unsigned);
|
||||
const json j_nonarray_const(j_nonarray);
|
||||
const json j_nonarray_const(j_nonarray); // NOLINT(performance-unnecessary-copy-initialization)
|
||||
CHECK_THROWS_WITH_AS(j_nonarray[0], "[json.exception.type_error.305] cannot use operator[] with a numeric argument with number", json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonarray_const[0], "[json.exception.type_error.305] cannot use operator[] with a numeric argument with number", json::type_error&);
|
||||
}
|
||||
@@ -211,7 +210,7 @@ TEST_CASE("element access 1")
|
||||
SECTION("number (floating-point)")
|
||||
{
|
||||
json j_nonarray(json::value_t::number_float);
|
||||
const json j_nonarray_const(j_nonarray);
|
||||
const json j_nonarray_const(j_nonarray); // NOLINT(performance-unnecessary-copy-initialization)
|
||||
CHECK_THROWS_WITH_AS(j_nonarray[0], "[json.exception.type_error.305] cannot use operator[] with a numeric argument with number", json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonarray_const[0], "[json.exception.type_error.305] cannot use operator[] with a numeric argument with number", json::type_error&);
|
||||
}
|
||||
|
||||
23
external/json/tests/src/unit-element_access2.cpp
vendored
23
external/json/tests/src/unit-element_access2.cpp
vendored
@@ -3,8 +3,7 @@
|
||||
// | | |__ | | | | | | version 3.11.3
|
||||
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
//
|
||||
// Copyright (c) 2013-2022 Niels Lohmann <http://nlohmann.me>.
|
||||
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-FileCopyrightText: 2013 - 2024 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#include "doctest_compatibility.h"
|
||||
@@ -17,7 +16,7 @@
|
||||
// build test with C++14
|
||||
// JSON_HAS_CPP_14
|
||||
|
||||
TEST_CASE_TEMPLATE("element access 2", Json, nlohmann::json, nlohmann::ordered_json)
|
||||
TEST_CASE_TEMPLATE("element access 2", Json, nlohmann::json, nlohmann::ordered_json) // NOLINT(readability-math-missing-parentheses)
|
||||
{
|
||||
SECTION("object")
|
||||
{
|
||||
@@ -83,7 +82,7 @@ TEST_CASE_TEMPLATE("element access 2", Json, nlohmann::json, nlohmann::ordered_j
|
||||
SECTION("null")
|
||||
{
|
||||
Json j_nonobject(Json::value_t::null);
|
||||
const Json j_nonobject_const(j_nonobject);
|
||||
const Json j_nonobject_const(j_nonobject); // NOLINT(performance-unnecessary-copy-initialization)
|
||||
CHECK_THROWS_WITH_AS(j_nonobject.at("foo"), "[json.exception.type_error.304] cannot use at() with null", typename Json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonobject_const.at("foo"), "[json.exception.type_error.304] cannot use at() with null", typename Json::type_error&);
|
||||
|
||||
@@ -96,7 +95,7 @@ TEST_CASE_TEMPLATE("element access 2", Json, nlohmann::json, nlohmann::ordered_j
|
||||
SECTION("boolean")
|
||||
{
|
||||
Json j_nonobject(Json::value_t::boolean);
|
||||
const Json j_nonobject_const(j_nonobject);
|
||||
const Json j_nonobject_const(j_nonobject); // NOLINT(performance-unnecessary-copy-initialization)
|
||||
CHECK_THROWS_WITH_AS(j_nonobject.at("foo"), "[json.exception.type_error.304] cannot use at() with boolean", typename Json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonobject_const.at("foo"), "[json.exception.type_error.304] cannot use at() with boolean", typename Json::type_error&);
|
||||
|
||||
@@ -109,7 +108,7 @@ TEST_CASE_TEMPLATE("element access 2", Json, nlohmann::json, nlohmann::ordered_j
|
||||
SECTION("string")
|
||||
{
|
||||
Json j_nonobject(Json::value_t::string);
|
||||
const Json j_nonobject_const(j_nonobject);
|
||||
const Json j_nonobject_const(j_nonobject); // NOLINT(performance-unnecessary-copy-initialization)
|
||||
CHECK_THROWS_WITH_AS(j_nonobject.at("foo"), "[json.exception.type_error.304] cannot use at() with string", typename Json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonobject_const.at("foo"), "[json.exception.type_error.304] cannot use at() with string", typename Json::type_error&);
|
||||
|
||||
@@ -122,7 +121,7 @@ TEST_CASE_TEMPLATE("element access 2", Json, nlohmann::json, nlohmann::ordered_j
|
||||
SECTION("array")
|
||||
{
|
||||
Json j_nonobject(Json::value_t::array);
|
||||
const Json j_nonobject_const(j_nonobject);
|
||||
const Json j_nonobject_const(j_nonobject); // NOLINT(performance-unnecessary-copy-initialization)
|
||||
CHECK_THROWS_WITH_AS(j_nonobject.at("foo"), "[json.exception.type_error.304] cannot use at() with array", typename Json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonobject_const.at("foo"), "[json.exception.type_error.304] cannot use at() with array", typename Json::type_error&);
|
||||
|
||||
@@ -135,7 +134,7 @@ TEST_CASE_TEMPLATE("element access 2", Json, nlohmann::json, nlohmann::ordered_j
|
||||
SECTION("number (integer)")
|
||||
{
|
||||
Json j_nonobject(Json::value_t::number_integer);
|
||||
const Json j_nonobject_const(j_nonobject);
|
||||
const Json j_nonobject_const(j_nonobject); // NOLINT(performance-unnecessary-copy-initialization)
|
||||
CHECK_THROWS_WITH_AS(j_nonobject.at("foo"), "[json.exception.type_error.304] cannot use at() with number", typename Json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonobject_const.at("foo"), "[json.exception.type_error.304] cannot use at() with number", typename Json::type_error&);
|
||||
|
||||
@@ -148,7 +147,7 @@ TEST_CASE_TEMPLATE("element access 2", Json, nlohmann::json, nlohmann::ordered_j
|
||||
SECTION("number (unsigned)")
|
||||
{
|
||||
Json j_nonobject(Json::value_t::number_unsigned);
|
||||
const Json j_nonobject_const(j_nonobject);
|
||||
const Json j_nonobject_const(j_nonobject); // NOLINT(performance-unnecessary-copy-initialization)
|
||||
CHECK_THROWS_WITH_AS(j_nonobject.at("foo"), "[json.exception.type_error.304] cannot use at() with number", typename Json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonobject_const.at("foo"), "[json.exception.type_error.304] cannot use at() with number", typename Json::type_error&);
|
||||
|
||||
@@ -161,7 +160,7 @@ TEST_CASE_TEMPLATE("element access 2", Json, nlohmann::json, nlohmann::ordered_j
|
||||
SECTION("number (floating-point)")
|
||||
{
|
||||
Json j_nonobject(Json::value_t::number_float);
|
||||
const Json j_nonobject_const(j_nonobject);
|
||||
const Json j_nonobject_const(j_nonobject); // NOLINT(performance-unnecessary-copy-initialization)
|
||||
CHECK_THROWS_WITH_AS(j_nonobject.at("foo"), "[json.exception.type_error.304] cannot use at() with number", typename Json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonobject_const.at("foo"), "[json.exception.type_error.304] cannot use at() with number", typename Json::type_error&);
|
||||
|
||||
@@ -1456,7 +1455,7 @@ TEST_CASE_TEMPLATE("element access 2", Json, nlohmann::json, nlohmann::ordered_j
|
||||
}
|
||||
|
||||
#if !defined(JSON_NOEXCEPTION)
|
||||
TEST_CASE_TEMPLATE("element access 2 (throwing tests)", Json, nlohmann::json, nlohmann::ordered_json)
|
||||
TEST_CASE_TEMPLATE("element access 2 (throwing tests)", Json, nlohmann::json, nlohmann::ordered_json) // NOLINT(readability-math-missing-parentheses)
|
||||
{
|
||||
SECTION("object")
|
||||
{
|
||||
@@ -1492,7 +1491,7 @@ TEST_CASE_TEMPLATE("element access 2 (throwing tests)", Json, nlohmann::json, nl
|
||||
#endif
|
||||
|
||||
// TODO(falbrechtskirchinger) merge with the other test case; clean up
|
||||
TEST_CASE_TEMPLATE("element access 2 (additional value() tests)", Json, nlohmann::json, nlohmann::ordered_json)
|
||||
TEST_CASE_TEMPLATE("element access 2 (additional value() tests)", Json, nlohmann::json, nlohmann::ordered_json) // NOLINT(readability-math-missing-parentheses)
|
||||
{
|
||||
using string_t = typename Json::string_t;
|
||||
using number_integer_t = typename Json::number_integer_t;
|
||||
|
||||
2
external/json/tests/src/unit-hash.cpp
vendored
2
external/json/tests/src/unit-hash.cpp
vendored
@@ -3,7 +3,7 @@
|
||||
// | | |__ | | | | | | version 3.11.3
|
||||
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
//
|
||||
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-FileCopyrightText: 2013 - 2024 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#include "doctest_compatibility.h"
|
||||
|
||||
2
external/json/tests/src/unit-inspection.cpp
vendored
2
external/json/tests/src/unit-inspection.cpp
vendored
@@ -3,7 +3,7 @@
|
||||
// | | |__ | | | | | | version 3.11.3
|
||||
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
//
|
||||
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-FileCopyrightText: 2013 - 2024 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#include "doctest_compatibility.h"
|
||||
|
||||
2
external/json/tests/src/unit-items.cpp
vendored
2
external/json/tests/src/unit-items.cpp
vendored
@@ -3,7 +3,7 @@
|
||||
// | | |__ | | | | | | version 3.11.3
|
||||
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
//
|
||||
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-FileCopyrightText: 2013 - 2024 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#include "doctest_compatibility.h"
|
||||
|
||||
2
external/json/tests/src/unit-iterators1.cpp
vendored
2
external/json/tests/src/unit-iterators1.cpp
vendored
@@ -3,7 +3,7 @@
|
||||
// | | |__ | | | | | | version 3.11.3
|
||||
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
//
|
||||
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-FileCopyrightText: 2013 - 2024 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#include "doctest_compatibility.h"
|
||||
|
||||
2
external/json/tests/src/unit-iterators2.cpp
vendored
2
external/json/tests/src/unit-iterators2.cpp
vendored
@@ -3,7 +3,7 @@
|
||||
// | | |__ | | | | | | version 3.11.3
|
||||
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
//
|
||||
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-FileCopyrightText: 2013 - 2024 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
// cmake/test.cmake selects the C++ standard versions with which to build a
|
||||
|
||||
35
external/json/tests/src/unit-iterators3.cpp
vendored
Normal file
35
external/json/tests/src/unit-iterators3.cpp
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
// __ _____ _____ _____
|
||||
// __| | __| | | | JSON for Modern C++ (supporting code)
|
||||
// | | |__ | | | | | | version 3.11.3
|
||||
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
//
|
||||
// SPDX-FileCopyrightText: 2013 - 2024 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#include "doctest_compatibility.h"
|
||||
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
using nlohmann::json;
|
||||
|
||||
#if (defined(__cplusplus) && __cplusplus >= 201402L) || (defined(_HAS_CXX14) && _HAS_CXX14 == 1)
|
||||
#define JSON_HAS_CPP_14
|
||||
#endif
|
||||
|
||||
#ifdef JSON_HAS_CPP_14
|
||||
TEST_CASE_TEMPLATE("checking forward-iterators", T, // NOLINT(readability-math-missing-parentheses)
|
||||
std::vector<int>, std::string, nlohmann::json)
|
||||
{
|
||||
auto it1 = typename T::iterator{};
|
||||
auto it2 = typename T::iterator{};
|
||||
CHECK(it1 == it2);
|
||||
CHECK(it1 <= it2);
|
||||
CHECK(it1 >= it2);
|
||||
CHECK_FALSE(it1 != it2);
|
||||
CHECK_FALSE(it1 < it2);
|
||||
CHECK_FALSE(it1 > it2);
|
||||
}
|
||||
#endif
|
||||
4
external/json/tests/src/unit-json_patch.cpp
vendored
4
external/json/tests/src/unit-json_patch.cpp
vendored
@@ -3,7 +3,7 @@
|
||||
// | | |__ | | | | | | version 3.11.3
|
||||
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
//
|
||||
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-FileCopyrightText: 2013 - 2024 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#include "doctest_compatibility.h"
|
||||
@@ -1305,7 +1305,7 @@ TEST_CASE("JSON patch")
|
||||
const auto& doc = test["doc"];
|
||||
const auto& patch = test["patch"];
|
||||
|
||||
if (test.count("error") == 0)
|
||||
if (test.count("error") == 0) // NOLINT(readability-container-contains)
|
||||
{
|
||||
// if an expected value is given, use it; use doc otherwise
|
||||
const auto& expected = test.value("expected", doc);
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
// | | |__ | | | | | | version 3.11.3
|
||||
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
//
|
||||
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-FileCopyrightText: 2013 - 2024 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#include "doctest_compatibility.h"
|
||||
|
||||
2
external/json/tests/src/unit-large_json.cpp
vendored
2
external/json/tests/src/unit-large_json.cpp
vendored
@@ -3,7 +3,7 @@
|
||||
// | | |__ | | | | | | version 3.11.3
|
||||
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
//
|
||||
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-FileCopyrightText: 2013 - 2024 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#include "doctest_compatibility.h"
|
||||
|
||||
161
external/json/tests/src/unit-locale-cpp.cpp
vendored
Normal file
161
external/json/tests/src/unit-locale-cpp.cpp
vendored
Normal file
@@ -0,0 +1,161 @@
|
||||
// __ _____ _____ _____
|
||||
// __| | __| | | | JSON for Modern C++ (supporting code)
|
||||
// | | |__ | | | | | | version 3.11.3
|
||||
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
//
|
||||
// SPDX-FileCopyrightText: 2013 - 2024 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#include "doctest_compatibility.h"
|
||||
|
||||
#define JSON_TESTS_PRIVATE
|
||||
#include <nlohmann/json.hpp>
|
||||
using nlohmann::json;
|
||||
|
||||
#include <clocale>
|
||||
|
||||
struct ParserImpl final: public nlohmann::json_sax<json>
|
||||
{
|
||||
bool null() override
|
||||
{
|
||||
return true;
|
||||
}
|
||||
bool boolean(bool /*val*/) override
|
||||
{
|
||||
return true;
|
||||
}
|
||||
bool number_integer(json::number_integer_t /*val*/) override
|
||||
{
|
||||
return true;
|
||||
}
|
||||
bool number_unsigned(json::number_unsigned_t /*val*/) override
|
||||
{
|
||||
return true;
|
||||
}
|
||||
bool number_float(json::number_float_t /*val*/, const json::string_t& s) override
|
||||
{
|
||||
float_string_copy = s;
|
||||
return true;
|
||||
}
|
||||
bool string(json::string_t& /*val*/) override
|
||||
{
|
||||
return true;
|
||||
}
|
||||
bool binary(json::binary_t& /*val*/) override
|
||||
{
|
||||
return true;
|
||||
}
|
||||
bool start_object(std::size_t /*val*/) override
|
||||
{
|
||||
return true;
|
||||
}
|
||||
bool key(json::string_t& /*val*/) override
|
||||
{
|
||||
return true;
|
||||
}
|
||||
bool end_object() override
|
||||
{
|
||||
return true;
|
||||
}
|
||||
bool start_array(std::size_t /*val*/) override
|
||||
{
|
||||
return true;
|
||||
}
|
||||
bool end_array() override
|
||||
{
|
||||
return true;
|
||||
}
|
||||
bool parse_error(std::size_t /*val*/, const std::string& /*val*/, const nlohmann::detail::exception& /*val*/) override
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
~ParserImpl() override;
|
||||
|
||||
ParserImpl()
|
||||
: float_string_copy("not set")
|
||||
{}
|
||||
|
||||
ParserImpl(const ParserImpl& other)
|
||||
: float_string_copy(other.float_string_copy)
|
||||
{}
|
||||
|
||||
ParserImpl(ParserImpl&& other) noexcept
|
||||
: float_string_copy(std::move(other.float_string_copy))
|
||||
{}
|
||||
|
||||
ParserImpl& operator=(const ParserImpl& other)
|
||||
{
|
||||
if (this != &other)
|
||||
{
|
||||
float_string_copy = other.float_string_copy;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
ParserImpl& operator=(ParserImpl&& other) noexcept
|
||||
{
|
||||
if (this != &other)
|
||||
{
|
||||
float_string_copy = std::move(other.float_string_copy);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
json::string_t float_string_copy;
|
||||
};
|
||||
|
||||
ParserImpl::~ParserImpl() = default;
|
||||
|
||||
TEST_CASE("locale-dependent test (LC_NUMERIC=C)")
|
||||
{
|
||||
WARN_MESSAGE(std::setlocale(LC_NUMERIC, "C") != nullptr, "could not set locale");
|
||||
|
||||
SECTION("check if locale is properly set")
|
||||
{
|
||||
std::array<char, 6> buffer = {};
|
||||
CHECK(std::snprintf(buffer.data(), buffer.size(), "%.2f", 12.34) == 5); // NOLINT(cppcoreguidelines-pro-type-vararg,hicpp-vararg)
|
||||
CHECK(std::string(buffer.data()) == "12.34");
|
||||
}
|
||||
|
||||
SECTION("parsing")
|
||||
{
|
||||
CHECK(json::parse("12.34").dump() == "12.34");
|
||||
}
|
||||
|
||||
SECTION("SAX parsing")
|
||||
{
|
||||
ParserImpl sax {};
|
||||
json::sax_parse( "12.34", &sax );
|
||||
CHECK(sax.float_string_copy == "12.34");
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("locale-dependent test (LC_NUMERIC=de_DE)")
|
||||
{
|
||||
if (std::setlocale(LC_NUMERIC, "de_DE") != nullptr)
|
||||
{
|
||||
SECTION("check if locale is properly set")
|
||||
{
|
||||
std::array<char, 6> buffer = {};
|
||||
CHECK(std::snprintf(buffer.data(), buffer.size(), "%.2f", 12.34) == 5); // NOLINT(cppcoreguidelines-pro-type-vararg,hicpp-vararg)
|
||||
CHECK(std::string(buffer.data()) == "12,34");
|
||||
}
|
||||
|
||||
SECTION("parsing")
|
||||
{
|
||||
CHECK(json::parse("12.34").dump() == "12.34");
|
||||
}
|
||||
|
||||
SECTION("SAX parsing")
|
||||
{
|
||||
ParserImpl sax{};
|
||||
json::sax_parse("12.34", &sax);
|
||||
CHECK(sax.float_string_copy == "12.34");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
MESSAGE("locale de_DE is not usable");
|
||||
}
|
||||
}
|
||||
2
external/json/tests/src/unit-merge_patch.cpp
vendored
2
external/json/tests/src/unit-merge_patch.cpp
vendored
@@ -3,7 +3,7 @@
|
||||
// | | |__ | | | | | | version 3.11.3
|
||||
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
//
|
||||
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-FileCopyrightText: 2013 - 2024 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#include "doctest_compatibility.h"
|
||||
|
||||
2
external/json/tests/src/unit-meta.cpp
vendored
2
external/json/tests/src/unit-meta.cpp
vendored
@@ -3,7 +3,7 @@
|
||||
// | | |__ | | | | | | version 3.11.3
|
||||
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
//
|
||||
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-FileCopyrightText: 2013 - 2024 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#include "doctest_compatibility.h"
|
||||
|
||||
3
external/json/tests/src/unit-modifiers.cpp
vendored
3
external/json/tests/src/unit-modifiers.cpp
vendored
@@ -3,8 +3,7 @@
|
||||
// | | |__ | | | | | | version 3.11.3
|
||||
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
//
|
||||
// Copyright (c) 2013-2022 Niels Lohmann <http://nlohmann.me>.
|
||||
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-FileCopyrightText: 2013 - 2024 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#include "doctest_compatibility.h"
|
||||
|
||||
34
external/json/tests/src/unit-msgpack.cpp
vendored
34
external/json/tests/src/unit-msgpack.cpp
vendored
@@ -3,7 +3,7 @@
|
||||
// | | |__ | | | | | | version 3.11.3
|
||||
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
//
|
||||
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-FileCopyrightText: 2013 - 2024 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#include "doctest_compatibility.h"
|
||||
@@ -281,7 +281,7 @@ TEST_CASE("MessagePack")
|
||||
|
||||
// check individual bytes
|
||||
CHECK(result[0] == 0xcd);
|
||||
auto const restored = static_cast<uint16_t>(static_cast<uint8_t>(result[1]) * 256 + static_cast<uint8_t>(result[2]));
|
||||
auto const restored = static_cast<uint16_t>((static_cast<uint8_t>(result[1]) * 256) + static_cast<uint8_t>(result[2]));
|
||||
CHECK(restored == i);
|
||||
|
||||
// roundtrip
|
||||
@@ -479,11 +479,11 @@ TEST_CASE("MessagePack")
|
||||
std::vector<int32_t> const numbers
|
||||
{
|
||||
-32769,
|
||||
-65536,
|
||||
-77777,
|
||||
-1048576,
|
||||
-2147483648LL,
|
||||
};
|
||||
-65536,
|
||||
-77777,
|
||||
-1048576,
|
||||
-2147483648LL,
|
||||
};
|
||||
for (auto i : numbers)
|
||||
{
|
||||
CAPTURE(i)
|
||||
@@ -671,7 +671,7 @@ TEST_CASE("MessagePack")
|
||||
|
||||
// check individual bytes
|
||||
CHECK(result[0] == 0xcd);
|
||||
auto const restored = static_cast<uint16_t>(static_cast<uint8_t>(result[1]) * 256 + static_cast<uint8_t>(result[2]));
|
||||
auto const restored = static_cast<uint16_t>((static_cast<uint8_t>(result[1]) * 256) + static_cast<uint8_t>(result[2]));
|
||||
CHECK(restored == i);
|
||||
|
||||
// roundtrip
|
||||
@@ -1508,6 +1508,22 @@ TEST_CASE("MessagePack")
|
||||
CHECK(json::from_msgpack(std::vector<uint8_t>({0xc4}), true, false).is_discarded());
|
||||
}
|
||||
|
||||
SECTION("unexpected end inside int with stream")
|
||||
{
|
||||
json _;
|
||||
const std::string data = {static_cast<char>(0xd2u), static_cast<char>(0x12u), static_cast<char>(0x34u), static_cast<char>(0x56u)};
|
||||
CHECK_THROWS_WITH_AS(_ = json::from_msgpack(std::istringstream(data, std::ios::binary)),
|
||||
"[json.exception.parse_error.110] parse error at byte 5: syntax error while parsing MessagePack number: unexpected end of input", json::parse_error&);
|
||||
}
|
||||
SECTION("misuse wchar for binary")
|
||||
{
|
||||
json _;
|
||||
// creates 0xd2 after UTF-8 decoding, triggers get_elements in wide_string_input_adapter for code coverage
|
||||
const std::u32string data = {static_cast<char32_t>(0x0280)};
|
||||
CHECK_THROWS_WITH_AS(_ = json::from_msgpack(data),
|
||||
"[json.exception.parse_error.112] parse error at byte 1: wide string type cannot be interpreted as binary data", json::parse_error&);
|
||||
}
|
||||
|
||||
SECTION("unsupported bytes")
|
||||
{
|
||||
SECTION("concrete examples")
|
||||
@@ -1604,7 +1620,7 @@ TEST_CASE("single MessagePack roundtrip")
|
||||
{
|
||||
SECTION("std::ostringstream")
|
||||
{
|
||||
std::basic_ostringstream<std::uint8_t> ss;
|
||||
std::basic_ostringstream<char> ss;
|
||||
json::to_msgpack(j1, ss);
|
||||
json j3 = json::from_msgpack(ss.str());
|
||||
CHECK(j1 == j3);
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
// | | |__ | | | | | | version 3.11.3
|
||||
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
//
|
||||
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-FileCopyrightText: 2013 - 2024 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#include "doctest_compatibility.h"
|
||||
|
||||
19
external/json/tests/src/unit-noexcept.cpp
vendored
19
external/json/tests/src/unit-noexcept.cpp
vendored
@@ -3,7 +3,7 @@
|
||||
// | | |__ | | | | | | version 3.11.3
|
||||
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
//
|
||||
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-FileCopyrightText: 2013 - 2024 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#include "doctest_compatibility.h"
|
||||
@@ -12,6 +12,11 @@
|
||||
DOCTEST_GCC_SUPPRESS_WARNING_PUSH
|
||||
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>
|
||||
|
||||
using nlohmann::json;
|
||||
@@ -36,12 +41,16 @@ static_assert(noexcept(json{}), "");
|
||||
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&>(), true)), "");
|
||||
static_assert(noexcept(nlohmann::to_json(std::declval<json&>(), test{})), "");
|
||||
static_assert(noexcept(nlohmann::to_json(std::declval<json&>(), pod{})), "");
|
||||
#ifndef SKIP_TESTS_FOR_ENUM_SERIALIZATION
|
||||
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_bis{})), "");
|
||||
static_assert(noexcept(json(2)), "");
|
||||
static_assert(noexcept(json(test{})), "");
|
||||
static_assert(noexcept(json(pod{})), "");
|
||||
#ifndef SKIP_TESTS_FOR_ENUM_SERIALIZATION
|
||||
static_assert(noexcept(json(test {})), "");
|
||||
#endif
|
||||
static_assert(noexcept(json(pod {})), "");
|
||||
static_assert(noexcept(std::declval<json>().get<pod>()), "");
|
||||
static_assert(!noexcept(std::declval<json>().get<pod_bis>()), "");
|
||||
static_assert(noexcept(json(pod{})), "");
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
// | | |__ | | | | | | version 3.11.3
|
||||
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
//
|
||||
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-FileCopyrightText: 2013 - 2024 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#include "doctest_compatibility.h"
|
||||
|
||||
2
external/json/tests/src/unit-ordered_map.cpp
vendored
2
external/json/tests/src/unit-ordered_map.cpp
vendored
@@ -3,7 +3,7 @@
|
||||
// | | |__ | | | | | | version 3.11.3
|
||||
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
//
|
||||
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-FileCopyrightText: 2013 - 2024 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#include "doctest_compatibility.h"
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
// | | |__ | | | | | | version 3.11.3
|
||||
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
//
|
||||
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-FileCopyrightText: 2013 - 2024 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#include "doctest_compatibility.h"
|
||||
@@ -326,7 +326,7 @@ TEST_CASE("pointer access")
|
||||
CHECK(value.get_ptr<json::array_t*>() == nullptr);
|
||||
CHECK(value.get_ptr<json::string_t*>() == nullptr);
|
||||
CHECK(value.get_ptr<json::boolean_t*>() == nullptr);
|
||||
CHECK(value.get_ptr<json::number_integer_t*>() != nullptr);
|
||||
CHECK(value.get_ptr<json::number_integer_t*>() == nullptr);
|
||||
CHECK(value.get_ptr<json::number_unsigned_t*>() != nullptr);
|
||||
CHECK(value.get_ptr<json::number_float_t*>() == nullptr);
|
||||
CHECK(value.get_ptr<json::binary_t*>() == nullptr);
|
||||
@@ -355,7 +355,7 @@ TEST_CASE("pointer access")
|
||||
CHECK(value.get_ptr<const json::array_t*>() == nullptr);
|
||||
CHECK(value.get_ptr<const json::string_t*>() == nullptr);
|
||||
CHECK(value.get_ptr<const json::boolean_t*>() == nullptr);
|
||||
CHECK(value.get_ptr<const json::number_integer_t*>() != nullptr);
|
||||
CHECK(value.get_ptr<const json::number_integer_t*>() == nullptr);
|
||||
CHECK(value.get_ptr<const json::number_unsigned_t*>() != nullptr);
|
||||
CHECK(value.get_ptr<const json::number_float_t*>() == nullptr);
|
||||
CHECK(value.get_ptr<const json::binary_t*>() == nullptr);
|
||||
|
||||
12
external/json/tests/src/unit-readme.cpp
vendored
12
external/json/tests/src/unit-readme.cpp
vendored
@@ -3,7 +3,7 @@
|
||||
// | | |__ | | | | | | version 3.11.3
|
||||
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
//
|
||||
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-FileCopyrightText: 2013 - 2024 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#include "doctest_compatibility.h"
|
||||
@@ -115,7 +115,7 @@ TEST_CASE("README" * doctest::skip())
|
||||
auto j3 = json::parse(R"({"happy": true, "pi": 3.141})");
|
||||
|
||||
// explicit conversion to string
|
||||
std::string const s = j.dump(); // {\"happy\":true,\"pi\":3.141}
|
||||
std::string const s = j.dump(); // NOLINT(bugprone-unused-local-non-trivial-variable) // {\"happy\":true,\"pi\":3.141}
|
||||
|
||||
// serialization with pretty printing
|
||||
// pass in the amount of spaces to indent
|
||||
@@ -152,7 +152,7 @@ TEST_CASE("README" * doctest::skip())
|
||||
}
|
||||
|
||||
// getter/setter
|
||||
const auto tmp = j[0].get<std::string>();
|
||||
const auto tmp = j[0].get<std::string>(); // NOLINT(bugprone-unused-local-non-trivial-variable)
|
||||
j[1] = 42;
|
||||
bool foo{j.at(2)};
|
||||
CHECK(foo == true);
|
||||
@@ -171,7 +171,7 @@ TEST_CASE("README" * doctest::skip())
|
||||
|
||||
// find an entry
|
||||
CHECK(o.find("foo") != o.end());
|
||||
if (o.find("foo") != o.end())
|
||||
if (o.find("foo") != o.end()) // NOLINT(readability-container-contains)
|
||||
{
|
||||
// there is an entry with key "foo"
|
||||
}
|
||||
@@ -237,7 +237,7 @@ TEST_CASE("README" * doctest::skip())
|
||||
// strings
|
||||
std::string const s1 = "Hello, world!";
|
||||
json const js = s1;
|
||||
auto s2 = js.get<std::string>();
|
||||
auto s2 = js.get<std::string>(); // NOLINT(bugprone-unused-local-non-trivial-variable)
|
||||
|
||||
// Booleans
|
||||
bool const b1 = true;
|
||||
@@ -253,7 +253,7 @@ TEST_CASE("README" * doctest::skip())
|
||||
|
||||
// etc.
|
||||
|
||||
std::string const vs = js.get<std::string>();
|
||||
std::string const vs = js.get<std::string>(); // NOLINT(bugprone-unused-local-non-trivial-variable)
|
||||
bool vb = jb.get<bool>();
|
||||
CHECK(vb == true);
|
||||
int vi = jn.get<int>();
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
// | | |__ | | | | | | version 3.11.3
|
||||
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
//
|
||||
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-FileCopyrightText: 2013 - 2024 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#include "doctest_compatibility.h"
|
||||
@@ -215,8 +215,8 @@ TEST_CASE("reference access")
|
||||
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number", json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(value.get_ref<json::boolean_t&>(),
|
||||
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number", json::type_error&);
|
||||
//CHECK_THROWS_WITH_AS(value.get_ref<json::number_integer_t&>(),
|
||||
// "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number", json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(value.get_ref<json::number_integer_t&>(),
|
||||
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number", json::type_error&);
|
||||
CHECK_NOTHROW(value.get_ref<json::number_unsigned_t&>());
|
||||
CHECK_THROWS_WITH_AS(value.get_ref<json::number_float_t&>(), "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number", json::type_error&);
|
||||
}
|
||||
|
||||
25
external/json/tests/src/unit-regression1.cpp
vendored
25
external/json/tests/src/unit-regression1.cpp
vendored
@@ -3,7 +3,7 @@
|
||||
// | | |__ | | | | | | version 3.11.3
|
||||
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
//
|
||||
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-FileCopyrightText: 2013 - 2024 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#include "doctest_compatibility.h"
|
||||
@@ -11,6 +11,11 @@
|
||||
// for some reason including this after the json header leads to linker errors with VS 2017...
|
||||
#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
|
||||
#include <nlohmann/json.hpp>
|
||||
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")
|
||||
{
|
||||
enum { t = 0, u = 102};
|
||||
@@ -191,6 +197,7 @@ TEST_CASE("regression tests 1")
|
||||
{"game_type", t}
|
||||
}));
|
||||
}
|
||||
#endif
|
||||
|
||||
SECTION("issue #76 - dump() / parse() not idempotent")
|
||||
{
|
||||
@@ -1328,10 +1335,10 @@ TEST_CASE("regression tests 1")
|
||||
{
|
||||
std::ifstream is;
|
||||
is.exceptions(
|
||||
is.exceptions()
|
||||
| std::ios_base::failbit
|
||||
| std::ios_base::badbit
|
||||
); // handle different exceptions as 'file not found', 'permission denied'
|
||||
is.exceptions()
|
||||
| std::ios_base::failbit
|
||||
| std::ios_base::badbit
|
||||
); // handle different exceptions as 'file not found', 'permission denied'
|
||||
|
||||
is.open(TEST_DATA_DIRECTORY "/regression/working_file.json");
|
||||
json _;
|
||||
@@ -1341,10 +1348,10 @@ TEST_CASE("regression tests 1")
|
||||
{
|
||||
std::ifstream is;
|
||||
is.exceptions(
|
||||
is.exceptions()
|
||||
| std::ios_base::failbit
|
||||
| std::ios_base::badbit
|
||||
); // handle different exceptions as 'file not found', 'permission denied'
|
||||
is.exceptions()
|
||||
| std::ios_base::failbit
|
||||
| std::ios_base::badbit
|
||||
); // handle different exceptions as 'file not found', 'permission denied'
|
||||
|
||||
is.open(TEST_DATA_DIRECTORY "/json_nlohmann_tests/all_unicode.json.cbor",
|
||||
std::ios_base::in | std::ios_base::binary);
|
||||
|
||||
91
external/json/tests/src/unit-regression2.cpp
vendored
91
external/json/tests/src/unit-regression2.cpp
vendored
@@ -3,7 +3,7 @@
|
||||
// | | |__ | | | | | | version 3.11.3
|
||||
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
//
|
||||
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-FileCopyrightText: 2013 - 2024 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
// cmake/test.cmake selects the C++ standard versions with which to build a
|
||||
@@ -90,18 +90,18 @@ struct Data
|
||||
: a(std::move(a_))
|
||||
, b(std::move(b_))
|
||||
{}
|
||||
std::string a{};
|
||||
std::string b{};
|
||||
std::string a{}; // NOLINT(readability-redundant-member-init)
|
||||
std::string b{}; // NOLINT(readability-redundant-member-init)
|
||||
};
|
||||
|
||||
void from_json(const json& j, Data& data);
|
||||
void from_json(const json& j, Data& data); // NOLINT(misc-use-internal-linkage)
|
||||
void from_json(const json& j, Data& data)
|
||||
{
|
||||
j["a"].get_to(data.a);
|
||||
j["b"].get_to(data.b);
|
||||
}
|
||||
|
||||
bool operator==(Data const& lhs, Data const& rhs);
|
||||
bool operator==(Data const& lhs, Data const& rhs); // NOLINT(misc-use-internal-linkage)
|
||||
bool operator==(Data const& lhs, Data const& rhs)
|
||||
{
|
||||
return lhs.a == rhs.a && lhs.b == rhs.b;
|
||||
@@ -162,11 +162,11 @@ struct adl_serializer<NonDefaultConstructible>
|
||||
// for #2824
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
|
||||
class sax_no_exception : public nlohmann::detail::json_sax_dom_parser<json>
|
||||
class sax_no_exception : public nlohmann::detail::json_sax_dom_parser<json, nlohmann::detail::string_input_adapter_type>
|
||||
{
|
||||
public:
|
||||
explicit sax_no_exception(json& j)
|
||||
: nlohmann::detail::json_sax_dom_parser<json>(j, false)
|
||||
: nlohmann::detail::json_sax_dom_parser<json, nlohmann::detail::string_input_adapter_type>(j, false)
|
||||
{}
|
||||
|
||||
static bool parse_error(std::size_t /*position*/, const std::string& /*last_token*/, const json::exception& ex)
|
||||
@@ -218,10 +218,10 @@ class Foo
|
||||
class FooBar
|
||||
{
|
||||
public:
|
||||
Foo foo{};
|
||||
Foo foo{}; // NOLINT(readability-redundant-member-init)
|
||||
};
|
||||
|
||||
inline void from_json(const nlohmann::json& j, FooBar& fb)
|
||||
inline void from_json(const nlohmann::json& j, FooBar& fb) // NOLINT(misc-use-internal-linkage)
|
||||
{
|
||||
j.at("value").get_to(fb.foo.value);
|
||||
}
|
||||
@@ -233,23 +233,80 @@ inline void from_json(const nlohmann::json& j, FooBar& fb)
|
||||
struct for_3171_base // NOLINT(cppcoreguidelines-special-member-functions)
|
||||
{
|
||||
for_3171_base(const std::string& /*unused*/ = {}) {}
|
||||
virtual ~for_3171_base() = default;
|
||||
virtual ~for_3171_base();
|
||||
|
||||
for_3171_base(const for_3171_base& other) // NOLINT(hicpp-use-equals-default,modernize-use-equals-default)
|
||||
: str(other.str)
|
||||
{}
|
||||
|
||||
for_3171_base& operator=(const for_3171_base& other)
|
||||
{
|
||||
if (this != &other)
|
||||
{
|
||||
str = other.str;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
for_3171_base(for_3171_base&& other) noexcept
|
||||
: str(std::move(other.str))
|
||||
{}
|
||||
|
||||
for_3171_base& operator=(for_3171_base&& other) noexcept
|
||||
{
|
||||
if (this != &other)
|
||||
{
|
||||
str = std::move(other.str);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
virtual void _from_json(const json& j)
|
||||
{
|
||||
j.at("str").get_to(str);
|
||||
}
|
||||
|
||||
std::string str{};
|
||||
std::string str{}; // NOLINT(readability-redundant-member-init)
|
||||
};
|
||||
|
||||
for_3171_base::~for_3171_base() = default;
|
||||
|
||||
struct for_3171_derived : public for_3171_base
|
||||
{
|
||||
for_3171_derived() = default;
|
||||
~for_3171_derived() override;
|
||||
explicit for_3171_derived(const std::string& /*unused*/) { }
|
||||
|
||||
for_3171_derived(const for_3171_derived& other) // NOLINT(hicpp-use-equals-default,modernize-use-equals-default)
|
||||
: for_3171_base(other)
|
||||
{}
|
||||
|
||||
for_3171_derived& operator=(const for_3171_derived& other)
|
||||
{
|
||||
if (this != &other)
|
||||
{
|
||||
for_3171_base::operator=(other); // Call base class assignment operator
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
for_3171_derived(for_3171_derived&& other) noexcept
|
||||
: for_3171_base(std::move(other))
|
||||
{}
|
||||
|
||||
for_3171_derived& operator=(for_3171_derived&& other) noexcept
|
||||
{
|
||||
if (this != &other)
|
||||
{
|
||||
for_3171_base::operator=(std::move(other)); // Call base class move assignment operator
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
|
||||
inline void from_json(const json& j, for_3171_base& tb)
|
||||
for_3171_derived::~for_3171_derived() = default;
|
||||
|
||||
inline void from_json(const json& j, for_3171_base& tb) // NOLINT(misc-use-internal-linkage)
|
||||
{
|
||||
tb._from_json(j);
|
||||
}
|
||||
@@ -264,7 +321,7 @@ struct for_3312
|
||||
std::string name;
|
||||
};
|
||||
|
||||
inline void from_json(const json& j, for_3312& obj)
|
||||
inline void from_json(const json& j, for_3312& obj) // NOLINT(misc-use-internal-linkage)
|
||||
{
|
||||
j.at("name").get_to(obj.name);
|
||||
}
|
||||
@@ -622,8 +679,8 @@ TEST_CASE("regression tests 2")
|
||||
// see https://github.com/nlohmann/json/pull/2181#issuecomment-653326060
|
||||
const json j{{"x", "test"}};
|
||||
const std::string defval = "default value";
|
||||
auto val = j.value("x", defval);
|
||||
auto val2 = j.value("y", defval);
|
||||
auto val = j.value("x", defval); // NOLINT(bugprone-unused-local-non-trivial-variable)
|
||||
auto val2 = j.value("y", defval); // NOLINT(bugprone-unused-local-non-trivial-variable)
|
||||
}
|
||||
|
||||
SECTION("issue #2293 - eof doesn't cause parsing to stop")
|
||||
@@ -675,6 +732,7 @@ TEST_CASE("regression tests 2")
|
||||
}
|
||||
|
||||
#ifdef JSON_HAS_CPP_20
|
||||
#ifndef _LIBCPP_VERSION // see https://github.com/nlohmann/json/issues/4490
|
||||
#if __has_include(<span>)
|
||||
SECTION("issue #2546 - parsing containers of std::byte")
|
||||
{
|
||||
@@ -684,6 +742,7 @@ TEST_CASE("regression tests 2")
|
||||
CHECK(j.dump() == "\"Hello, world!\"");
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
SECTION("issue #2574 - Deserialization to std::array, std::pair, and std::tuple with non-default constructable types fails")
|
||||
@@ -866,7 +925,7 @@ TEST_CASE("regression tests 2")
|
||||
CHECK(j.dump() == "[1,4]");
|
||||
}
|
||||
|
||||
SECTION("issue #3343 - json and ordered_json are not interchangable")
|
||||
SECTION("issue #3343 - json and ordered_json are not interchangeable")
|
||||
{
|
||||
json::object_t jobj({ { "product", "one" } });
|
||||
ordered_json::object_t ojobj({{"product", "one"}});
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
// | | |__ | | | | | | version 3.11.3
|
||||
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
//
|
||||
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-FileCopyrightText: 2013 - 2024 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#include "doctest_compatibility.h"
|
||||
@@ -165,7 +165,7 @@ TEST_CASE("serialization")
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE_TEMPLATE("serialization for extreme integer values", T, int32_t, uint32_t, int64_t, uint64_t)
|
||||
TEST_CASE_TEMPLATE("serialization for extreme integer values", T, int32_t, uint32_t, int64_t, uint64_t) // NOLINT(readability-math-missing-parentheses)
|
||||
{
|
||||
SECTION("minimum")
|
||||
{
|
||||
|
||||
6
external/json/tests/src/unit-testsuites.cpp
vendored
6
external/json/tests/src/unit-testsuites.cpp
vendored
@@ -3,7 +3,7 @@
|
||||
// | | |__ | | | | | | version 3.11.3
|
||||
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
//
|
||||
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-FileCopyrightText: 2013 - 2024 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#include "doctest_compatibility.h"
|
||||
@@ -163,7 +163,7 @@ TEST_CASE("compliance tests from nativejson-benchmark")
|
||||
TEST_DOUBLE("[2.2250738585072012e-308]",
|
||||
2.2250738585072014e-308);
|
||||
|
||||
// More closer to normal/subnormal boundary
|
||||
// Closer to normal/subnormal boundary
|
||||
// boundary = 2^-1022 - 2^-1075 = 2.225073858507201136057409796709131975934819546351645648... ¡Á 10^-308
|
||||
TEST_DOUBLE("[2.22507385850720113605740979670913197593481954635164564e-308]",
|
||||
2.2250738585072009e-308);
|
||||
@@ -312,7 +312,7 @@ TEST_CASE("test suite from json-test-suite")
|
||||
{
|
||||
SECTION("read all sample.json")
|
||||
{
|
||||
// read a file with all unicode characters stored as single-character
|
||||
// read a file with all Unicode characters stored as single-character
|
||||
// strings in a JSON array
|
||||
std::ifstream f(TEST_DATA_DIRECTORY "/json_testsuite/sample.json");
|
||||
json j;
|
||||
|
||||
2
external/json/tests/src/unit-to_chars.cpp
vendored
2
external/json/tests/src/unit-to_chars.cpp
vendored
@@ -3,7 +3,7 @@
|
||||
// | | |__ | | | | | | version 3.11.3
|
||||
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
//
|
||||
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-FileCopyrightText: 2013 - 2024 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
// XXX:
|
||||
|
||||
2
external/json/tests/src/unit-type_traits.cpp
vendored
2
external/json/tests/src/unit-type_traits.cpp
vendored
@@ -3,7 +3,7 @@
|
||||
// | | |__ | | | | | | version 3.11.3
|
||||
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
//
|
||||
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-FileCopyrightText: 2013 - 2024 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#include "doctest_compatibility.h"
|
||||
|
||||
10
external/json/tests/src/unit-ubjson.cpp
vendored
10
external/json/tests/src/unit-ubjson.cpp
vendored
@@ -3,7 +3,7 @@
|
||||
// | | |__ | | | | | | version 3.11.3
|
||||
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
//
|
||||
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-FileCopyrightText: 2013 - 2024 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#include "doctest_compatibility.h"
|
||||
@@ -450,7 +450,7 @@ TEST_CASE("UBJSON")
|
||||
|
||||
// check individual bytes
|
||||
CHECK(result[0] == 'I');
|
||||
auto const restored = static_cast<uint16_t>(static_cast<uint8_t>(result[1]) * 256 + static_cast<uint8_t>(result[2]));
|
||||
auto const restored = static_cast<uint16_t>((static_cast<uint8_t>(result[1]) * 256) + static_cast<uint8_t>(result[2]));
|
||||
CHECK(restored == i);
|
||||
|
||||
// roundtrip
|
||||
@@ -655,7 +655,7 @@ TEST_CASE("UBJSON")
|
||||
|
||||
// check individual bytes
|
||||
CHECK(result[0] == 'I');
|
||||
auto const restored = static_cast<uint16_t>(static_cast<uint8_t>(result[1]) * 256 + static_cast<uint8_t>(result[2]));
|
||||
auto const restored = static_cast<uint16_t>((static_cast<uint8_t>(result[1]) * 256) + static_cast<uint8_t>(result[2]));
|
||||
CHECK(restored == i);
|
||||
|
||||
// roundtrip
|
||||
@@ -1617,7 +1617,7 @@ TEST_CASE("UBJSON")
|
||||
CHECK_THROWS_AS(_ = json::from_ubjson(v_ubjson), json::out_of_range&);
|
||||
|
||||
json j;
|
||||
nlohmann::detail::json_sax_dom_callback_parser<json> scp(j, [](int /*unused*/, json::parse_event_t /*unused*/, const json& /*unused*/) noexcept
|
||||
nlohmann::detail::json_sax_dom_callback_parser<json, decltype(nlohmann::detail::input_adapter(v_ubjson))> scp(j, [](int /*unused*/, json::parse_event_t /*unused*/, const json& /*unused*/) noexcept
|
||||
{
|
||||
return true;
|
||||
});
|
||||
@@ -1631,7 +1631,7 @@ TEST_CASE("UBJSON")
|
||||
CHECK_THROWS_AS(_ = json::from_ubjson(v_ubjson), json::out_of_range&);
|
||||
|
||||
json j;
|
||||
nlohmann::detail::json_sax_dom_callback_parser<json> scp(j, [](int /*unused*/, json::parse_event_t /*unused*/, const json& /*unused*/) noexcept
|
||||
nlohmann::detail::json_sax_dom_callback_parser<json, decltype(nlohmann::detail::input_adapter(v_ubjson))> scp(j, [](int /*unused*/, json::parse_event_t /*unused*/, const json& /*unused*/) noexcept
|
||||
{
|
||||
return true;
|
||||
});
|
||||
|
||||
2
external/json/tests/src/unit-udl.cpp
vendored
2
external/json/tests/src/unit-udl.cpp
vendored
@@ -3,7 +3,7 @@
|
||||
// | | |__ | | | | | | version 3.11.3
|
||||
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
//
|
||||
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-FileCopyrightText: 2013 - 2024 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#include "doctest_compatibility.h"
|
||||
|
||||
72
external/json/tests/src/unit-udt.cpp
vendored
72
external/json/tests/src/unit-udt.cpp
vendored
@@ -3,7 +3,7 @@
|
||||
// | | |__ | | | | | | version 3.11.3
|
||||
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
//
|
||||
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-FileCopyrightText: 2013 - 2024 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#include "doctest_compatibility.h"
|
||||
@@ -12,6 +12,11 @@
|
||||
DOCTEST_GCC_SUPPRESS_WARNING_PUSH
|
||||
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>
|
||||
using nlohmann::json;
|
||||
#ifdef JSON_TEST_NO_GLOBAL_UDLS
|
||||
@@ -52,27 +57,30 @@ struct address
|
||||
|
||||
struct person
|
||||
{
|
||||
age m_age{};
|
||||
name m_name{};
|
||||
country m_country{};
|
||||
age m_age{}; // NOLINT(readability-redundant-member-init)
|
||||
name m_name{}; // NOLINT(readability-redundant-member-init)
|
||||
country m_country{}; // NOLINT(readability-redundant-member-init)
|
||||
person() = default;
|
||||
person(const age& a, name n, const country& c) : m_age(a), m_name(std::move(n)), m_country(c) {}
|
||||
};
|
||||
|
||||
struct contact
|
||||
{
|
||||
person m_person{};
|
||||
address m_address{};
|
||||
person m_person{}; // NOLINT(readability-redundant-member-init)
|
||||
address m_address{}; // NOLINT(readability-redundant-member-init)
|
||||
contact() = default;
|
||||
contact(person p, address a) : m_person(std::move(p)), m_address(std::move(a)) {}
|
||||
};
|
||||
|
||||
enum class book_id : std::uint64_t;
|
||||
|
||||
struct contact_book
|
||||
{
|
||||
name m_book_name{};
|
||||
std::vector<contact> m_contacts{};
|
||||
name m_book_name{}; // NOLINT(readability-redundant-member-init)
|
||||
book_id m_book_id{};
|
||||
std::vector<contact> m_contacts{}; // NOLINT(readability-redundant-member-init)
|
||||
contact_book() = default;
|
||||
contact_book(name n, std::vector<contact> c) : m_book_name(std::move(n)), m_contacts(std::move(c)) {}
|
||||
contact_book(name n, book_id i, std::vector<contact> c) : m_book_name(std::move(n)), m_book_id(i), m_contacts(std::move(c)) {}
|
||||
};
|
||||
} // namespace udt
|
||||
|
||||
@@ -129,7 +137,11 @@ static void to_json(nlohmann::json& j, const contact& c)
|
||||
|
||||
static void to_json(nlohmann::json& j, const contact_book& cb)
|
||||
{
|
||||
j = json{{"name", cb.m_book_name}, {"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
|
||||
@@ -161,8 +173,8 @@ static bool operator==(const contact& lhs, const contact& rhs)
|
||||
|
||||
static bool operator==(const contact_book& lhs, const contact_book& rhs)
|
||||
{
|
||||
return std::tie(lhs.m_book_name, lhs.m_contacts) ==
|
||||
std::tie(rhs.m_book_name, rhs.m_contacts);
|
||||
return std::tie(lhs.m_book_name, lhs.m_book_id, lhs.m_contacts) ==
|
||||
std::tie(rhs.m_book_name, rhs.m_book_id, rhs.m_contacts);
|
||||
}
|
||||
} // namespace udt
|
||||
|
||||
@@ -219,6 +231,9 @@ static void from_json(const nlohmann::json& j, contact& c)
|
||||
static void from_json(const nlohmann::json& j, contact_book& cb)
|
||||
{
|
||||
cb.m_book_name = j["name"].get<name>();
|
||||
#ifndef SKIP_TESTS_FOR_ENUM_SERIALIZATION
|
||||
cb.m_book_id = j["id"].get<book_id>();
|
||||
#endif
|
||||
cb.m_contacts = j["contacts"].get<std::vector<contact>>();
|
||||
}
|
||||
} // namespace udt
|
||||
@@ -237,7 +252,8 @@ TEST_CASE("basic usage" * doctest::test_suite("udt"))
|
||||
const udt::person senior_programmer{{42}, {"王芳"}, udt::country::china};
|
||||
const udt::address addr{"Paris"};
|
||||
const udt::contact cpp_programmer{sfinae_addict, addr};
|
||||
const udt::contact_book book{{"C++"}, {cpp_programmer, {senior_programmer, addr}}};
|
||||
const udt::book_id large_id{static_cast<udt::book_id>(static_cast<std::uint64_t>(1) << 63)}; // verify large unsigned enums are handled correctly
|
||||
const udt::contact_book book{{"C++"}, static_cast<udt::book_id>(42u), {cpp_programmer, {senior_programmer, addr}}};
|
||||
|
||||
SECTION("conversion to json via free-functions")
|
||||
{
|
||||
@@ -248,21 +264,36 @@ TEST_CASE("basic usage" * doctest::test_suite("udt"))
|
||||
CHECK(json("Paris") == json(addr));
|
||||
CHECK(json(cpp_programmer) ==
|
||||
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) > 0u);
|
||||
CHECK(to_string(json(large_id)) == "9223372036854775808");
|
||||
CHECK(json(large_id).is_number_unsigned());
|
||||
#endif
|
||||
|
||||
#ifndef SKIP_TESTS_FOR_ENUM_SERIALIZATION
|
||||
CHECK(
|
||||
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);
|
||||
#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
|
||||
|
||||
}
|
||||
|
||||
SECTION("conversion from json via free-functions")
|
||||
{
|
||||
const auto big_json =
|
||||
R"({"name":"C++", "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;
|
||||
SECTION("via explicit calls to get")
|
||||
{
|
||||
const auto parsed_book = big_json.get<udt::contact_book>();
|
||||
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>();
|
||||
#endif
|
||||
const auto contacts =
|
||||
big_json["contacts"].get<std::vector<udt::contact>>();
|
||||
const auto contact_json = big_json["contacts"].at(0);
|
||||
@@ -282,7 +313,10 @@ TEST_CASE("basic usage" * doctest::test_suite("udt"))
|
||||
CHECK(contact == cpp_programmer);
|
||||
CHECK(contacts == book.m_contacts);
|
||||
CHECK(book_name == udt::name{"C++"});
|
||||
#ifndef SKIP_TESTS_FOR_ENUM_SERIALIZATION
|
||||
CHECK(book_id == book.m_book_id);
|
||||
CHECK(book == parsed_book);
|
||||
#endif
|
||||
}
|
||||
|
||||
SECTION("via explicit calls to get_to")
|
||||
@@ -303,6 +337,9 @@ TEST_CASE("basic usage" * doctest::test_suite("udt"))
|
||||
{
|
||||
const udt::contact_book parsed_book = big_json;
|
||||
const udt::name book_name = big_json["name"];
|
||||
#ifndef SKIP_TESTS_FOR_ENUM_SERIALIZATION
|
||||
const udt::book_id book_id = big_json["id"];
|
||||
#endif
|
||||
const std::vector<udt::contact> contacts = big_json["contacts"];
|
||||
const auto contact_json = big_json["contacts"].at(0);
|
||||
const udt::contact contact = contact_json;
|
||||
@@ -320,7 +357,10 @@ TEST_CASE("basic usage" * doctest::test_suite("udt"))
|
||||
CHECK(contact == cpp_programmer);
|
||||
CHECK(contacts == book.m_contacts);
|
||||
CHECK(book_name == udt::name{"C++"});
|
||||
#ifndef SKIP_TESTS_FOR_ENUM_SERIALIZATION
|
||||
CHECK(book_id == static_cast<udt::book_id>(42u));
|
||||
CHECK(book == parsed_book);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -330,7 +370,7 @@ namespace udt
|
||||
{
|
||||
struct legacy_type
|
||||
{
|
||||
std::string number{};
|
||||
std::string number{}; // NOLINT(readability-redundant-member-init)
|
||||
legacy_type() = default;
|
||||
legacy_type(std::string n) : number(std::move(n)) {}
|
||||
};
|
||||
@@ -603,7 +643,7 @@ struct small_pod
|
||||
|
||||
struct non_pod
|
||||
{
|
||||
std::string s{};
|
||||
std::string s{}; // NOLINT(readability-redundant-member-init)
|
||||
non_pod() = default;
|
||||
non_pod(std::string S) : s(std::move(S)) {}
|
||||
};
|
||||
|
||||
260
external/json/tests/src/unit-udt_macro.cpp
vendored
260
external/json/tests/src/unit-udt_macro.cpp
vendored
@@ -3,7 +3,7 @@
|
||||
// | | |__ | | | | | | version 3.11.3
|
||||
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
//
|
||||
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-FileCopyrightText: 2013 - 2024 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#include <string>
|
||||
@@ -18,7 +18,7 @@ namespace persons
|
||||
class person_with_private_data
|
||||
{
|
||||
private:
|
||||
std::string name{};
|
||||
std::string name{}; // NOLINT(readability-redundant-member-init)
|
||||
int age = 0;
|
||||
json metadata = nullptr;
|
||||
|
||||
@@ -38,10 +38,30 @@ class person_with_private_data
|
||||
NLOHMANN_DEFINE_TYPE_INTRUSIVE(person_with_private_data, age, name, metadata)
|
||||
};
|
||||
|
||||
class derived_person_with_private_data : public person_with_private_data
|
||||
{
|
||||
private:
|
||||
std::string hair_color{"blue"};
|
||||
|
||||
public:
|
||||
bool operator==(const derived_person_with_private_data& rhs) const
|
||||
{
|
||||
return person_with_private_data::operator==(rhs) && hair_color == rhs.hair_color;
|
||||
}
|
||||
|
||||
derived_person_with_private_data() = default;
|
||||
derived_person_with_private_data(std::string name_, int age_, json metadata_, std::string hair_color_)
|
||||
: person_with_private_data(std::move(name_), age_, std::move(metadata_))
|
||||
, hair_color(std::move(hair_color_))
|
||||
{}
|
||||
|
||||
NLOHMANN_DEFINE_DERIVED_TYPE_INTRUSIVE(derived_person_with_private_data, person_with_private_data, hair_color)
|
||||
};
|
||||
|
||||
class person_with_private_data_2
|
||||
{
|
||||
private:
|
||||
std::string name{};
|
||||
std::string name{}; // NOLINT(readability-redundant-member-init)
|
||||
int age = 0;
|
||||
json metadata = nullptr;
|
||||
|
||||
@@ -74,10 +94,35 @@ class person_with_private_data_2
|
||||
NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(person_with_private_data_2, age, name, metadata)
|
||||
};
|
||||
|
||||
class derived_person_with_private_data_2 : public person_with_private_data_2
|
||||
{
|
||||
private:
|
||||
std::string hair_color{"blue"};
|
||||
|
||||
public:
|
||||
bool operator==(const derived_person_with_private_data_2& rhs) const
|
||||
{
|
||||
return person_with_private_data_2::operator==(rhs) && hair_color == rhs.hair_color;
|
||||
}
|
||||
|
||||
derived_person_with_private_data_2() = default;
|
||||
derived_person_with_private_data_2(std::string name_, int age_, json metadata_, std::string hair_color_)
|
||||
: person_with_private_data_2(std::move(name_), age_, std::move(metadata_))
|
||||
, hair_color(std::move(hair_color_))
|
||||
{}
|
||||
|
||||
std::string getHairColor() const
|
||||
{
|
||||
return hair_color;
|
||||
}
|
||||
|
||||
NLOHMANN_DEFINE_DERIVED_TYPE_INTRUSIVE_WITH_DEFAULT(derived_person_with_private_data_2, person_with_private_data_2, hair_color)
|
||||
};
|
||||
|
||||
class person_without_private_data_1
|
||||
{
|
||||
public:
|
||||
std::string name{};
|
||||
std::string name{}; // NOLINT(readability-redundant-member-init)
|
||||
int age = 0;
|
||||
json metadata = nullptr;
|
||||
|
||||
@@ -96,10 +141,30 @@ class person_without_private_data_1
|
||||
NLOHMANN_DEFINE_TYPE_INTRUSIVE(person_without_private_data_1, age, name, metadata)
|
||||
};
|
||||
|
||||
class derived_person_without_private_data_1 : public person_without_private_data_1
|
||||
{
|
||||
public:
|
||||
std::string hair_color{"blue"};
|
||||
|
||||
public:
|
||||
bool operator==(const derived_person_without_private_data_1& rhs) const
|
||||
{
|
||||
return person_without_private_data_1::operator==(rhs) && hair_color == rhs.hair_color;
|
||||
}
|
||||
|
||||
derived_person_without_private_data_1() = default;
|
||||
derived_person_without_private_data_1(std::string name_, int age_, json metadata_, std::string hair_color_)
|
||||
: person_without_private_data_1(std::move(name_), age_, std::move(metadata_))
|
||||
, hair_color(std::move(hair_color_))
|
||||
{}
|
||||
|
||||
NLOHMANN_DEFINE_DERIVED_TYPE_INTRUSIVE(derived_person_without_private_data_1, person_without_private_data_1, hair_color)
|
||||
};
|
||||
|
||||
class person_without_private_data_2
|
||||
{
|
||||
public:
|
||||
std::string name{};
|
||||
std::string name{}; // NOLINT(readability-redundant-member-init)
|
||||
int age = 0;
|
||||
json metadata = nullptr;
|
||||
|
||||
@@ -118,10 +183,30 @@ class person_without_private_data_2
|
||||
|
||||
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(person_without_private_data_2, age, name, metadata)
|
||||
|
||||
class derived_person_without_private_data_2 : public person_without_private_data_2
|
||||
{
|
||||
public:
|
||||
std::string hair_color{"blue"};
|
||||
|
||||
public:
|
||||
bool operator==(const derived_person_without_private_data_2& rhs) const
|
||||
{
|
||||
return person_without_private_data_2::operator==(rhs) && hair_color == rhs.hair_color;
|
||||
}
|
||||
|
||||
derived_person_without_private_data_2() = default;
|
||||
derived_person_without_private_data_2(std::string name_, int age_, json metadata_, std::string hair_color_)
|
||||
: person_without_private_data_2(std::move(name_), age_, std::move(metadata_))
|
||||
, hair_color(std::move(hair_color_))
|
||||
{}
|
||||
};
|
||||
|
||||
NLOHMANN_DEFINE_DERIVED_TYPE_NON_INTRUSIVE(derived_person_without_private_data_2, person_without_private_data_2, hair_color)
|
||||
|
||||
class person_without_private_data_3
|
||||
{
|
||||
public:
|
||||
std::string name{};
|
||||
std::string name{}; // NOLINT(readability-redundant-member-init)
|
||||
int age = 0;
|
||||
json metadata = nullptr;
|
||||
|
||||
@@ -153,6 +238,31 @@ class person_without_private_data_3
|
||||
|
||||
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(person_without_private_data_3, age, name, metadata)
|
||||
|
||||
class derived_person_without_private_data_3 : public person_without_private_data_3
|
||||
{
|
||||
public:
|
||||
std::string hair_color{"blue"};
|
||||
|
||||
public:
|
||||
bool operator==(const derived_person_without_private_data_3& rhs) const
|
||||
{
|
||||
return person_without_private_data_3::operator==(rhs) && hair_color == rhs.hair_color;
|
||||
}
|
||||
|
||||
derived_person_without_private_data_3() = default;
|
||||
derived_person_without_private_data_3(std::string name_, int age_, json metadata_, std::string hair_color_)
|
||||
: person_without_private_data_3(std::move(name_), age_, std::move(metadata_))
|
||||
, hair_color(std::move(hair_color_))
|
||||
{}
|
||||
|
||||
std::string getHairColor() const
|
||||
{
|
||||
return hair_color;
|
||||
}
|
||||
};
|
||||
|
||||
NLOHMANN_DEFINE_DERIVED_TYPE_NON_INTRUSIVE_WITH_DEFAULT(derived_person_without_private_data_3, person_without_private_data_3, hair_color)
|
||||
|
||||
class person_with_private_alphabet
|
||||
{
|
||||
public:
|
||||
@@ -216,6 +326,19 @@ class person_with_private_alphabet
|
||||
NLOHMANN_DEFINE_TYPE_INTRUSIVE(person_with_private_alphabet, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z)
|
||||
};
|
||||
|
||||
class derived_person_with_private_alphabet : public person_with_private_alphabet
|
||||
{
|
||||
public:
|
||||
bool operator==(const derived_person_with_private_alphabet& other) const
|
||||
{
|
||||
return person_with_private_alphabet::operator==(other) && schwa == other.schwa;
|
||||
}
|
||||
|
||||
private:
|
||||
int schwa = 0;
|
||||
NLOHMANN_DEFINE_DERIVED_TYPE_INTRUSIVE(derived_person_with_private_alphabet, person_with_private_alphabet, schwa)
|
||||
};
|
||||
|
||||
class person_with_public_alphabet
|
||||
{
|
||||
public:
|
||||
@@ -317,9 +440,35 @@ class person_without_default_constructor_2
|
||||
|
||||
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_ONLY_SERIALIZE(person_without_default_constructor_2, name, age)
|
||||
|
||||
class derived_person_only_serialize_public : public person_without_default_constructor_1
|
||||
{
|
||||
public:
|
||||
std::string hair_color;
|
||||
|
||||
derived_person_only_serialize_public(std::string name_, int age_, std::string hair_color_)
|
||||
: person_without_default_constructor_1(std::move(name_), age_)
|
||||
, hair_color(std::move(hair_color_))
|
||||
{}
|
||||
};
|
||||
|
||||
NLOHMANN_DEFINE_DERIVED_TYPE_NON_INTRUSIVE_ONLY_SERIALIZE(derived_person_only_serialize_public, person_without_default_constructor_1, hair_color)
|
||||
|
||||
class derived_person_only_serialize_private : person_without_default_constructor_1
|
||||
{
|
||||
private:
|
||||
std::string hair_color;
|
||||
public:
|
||||
derived_person_only_serialize_private(std::string name_, int age_, std::string hair_color_)
|
||||
: person_without_default_constructor_1(std::move(name_), age_)
|
||||
, hair_color(std::move(hair_color_))
|
||||
{}
|
||||
|
||||
NLOHMANN_DEFINE_DERIVED_TYPE_INTRUSIVE_ONLY_SERIALIZE(derived_person_only_serialize_private, person_without_default_constructor_1, hair_color)
|
||||
};
|
||||
|
||||
} // namespace persons
|
||||
|
||||
TEST_CASE_TEMPLATE("Serialization/deserialization via NLOHMANN_DEFINE_TYPE_INTRUSIVE and NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE", T,
|
||||
TEST_CASE_TEMPLATE("Serialization/deserialization via NLOHMANN_DEFINE_TYPE_INTRUSIVE and NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE", T, // NOLINT(readability-math-missing-parentheses)
|
||||
persons::person_with_private_data,
|
||||
persons::person_without_private_data_1,
|
||||
persons::person_without_private_data_2)
|
||||
@@ -345,7 +494,33 @@ TEST_CASE_TEMPLATE("Serialization/deserialization via NLOHMANN_DEFINE_TYPE_INTRU
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE_TEMPLATE("Serialization/deserialization via NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT and NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT", T,
|
||||
TEST_CASE_TEMPLATE("Serialization/deserialization via NLOHMANN_DEFINE_DERIVED_TYPE_INTRUSIVE and NLOHMANN_DEFINE_DERIVED_TYPE_NON_INTRUSIVE", T, // NOLINT(readability-math-missing-parentheses)
|
||||
persons::derived_person_with_private_data,
|
||||
persons::derived_person_without_private_data_1,
|
||||
persons::derived_person_without_private_data_2)
|
||||
{
|
||||
SECTION("person")
|
||||
{
|
||||
// serialization
|
||||
T p1("Erik", 1, {{"haircuts", 2}}, "red");
|
||||
CHECK(json(p1).dump() == "{\"age\":1,\"hair_color\":\"red\",\"metadata\":{\"haircuts\":2},\"name\":\"Erik\"}");
|
||||
|
||||
// deserialization
|
||||
auto p2 = json(p1).get<T>();
|
||||
CHECK(p2 == p1);
|
||||
|
||||
// roundtrip
|
||||
CHECK(T(json(p1)) == p1);
|
||||
CHECK(json(T(json(p1))) == json(p1));
|
||||
|
||||
// check exception in case of missing field
|
||||
json j = json(p1);
|
||||
j.erase("age");
|
||||
CHECK_THROWS_WITH_AS(j.get<T>(), "[json.exception.out_of_range.403] key 'age' not found", json::out_of_range);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE_TEMPLATE("Serialization/deserialization via NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT and NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT", T, // NOLINT(readability-math-missing-parentheses)
|
||||
persons::person_with_private_data_2,
|
||||
persons::person_without_private_data_3)
|
||||
{
|
||||
@@ -376,10 +551,53 @@ TEST_CASE_TEMPLATE("Serialization/deserialization via NLOHMANN_DEFINE_TYPE_INTRU
|
||||
CHECK(p3.getName() == "");
|
||||
CHECK(p3.getAge() == 0);
|
||||
CHECK(p3.getMetadata() == nullptr);
|
||||
|
||||
// check default value in case of empty json
|
||||
const json j4;
|
||||
T p4 = j4.get<T>();
|
||||
CHECK(p4.getName() == "");
|
||||
CHECK(p4.getAge() == 0);
|
||||
CHECK(p4.getMetadata() == nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE_TEMPLATE("Serialization/deserialization of classes with 26 public/private member variables via NLOHMANN_DEFINE_TYPE_INTRUSIVE and NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE", T,
|
||||
TEST_CASE_TEMPLATE("Serialization/deserialization via NLOHMANN_DEFINE_DERIVED_TYPE_INTRUSIVE_WITH_DEFAULT and NLOHMANN_DEFINE_DERIVED_TYPE_NON_INTRUSIVE_WITH_DEFAULT", T, // NOLINT(readability-math-missing-parentheses)
|
||||
persons::derived_person_with_private_data_2,
|
||||
persons::derived_person_without_private_data_3)
|
||||
{
|
||||
SECTION("derived person with default values")
|
||||
{
|
||||
// serialization of default constructed object
|
||||
T p0;
|
||||
CHECK(json(p0).dump() == "{\"age\":0,\"hair_color\":\"blue\",\"metadata\":null,\"name\":\"\"}");
|
||||
|
||||
// serialization
|
||||
T p1("Erik", 1, {{"haircuts", 2}}, "red");
|
||||
CHECK(json(p1).dump() == "{\"age\":1,\"hair_color\":\"red\",\"metadata\":{\"haircuts\":2},\"name\":\"Erik\"}");
|
||||
|
||||
// deserialization
|
||||
auto p2 = json(p1).get<T>();
|
||||
CHECK(p2 == p1);
|
||||
|
||||
// roundtrip
|
||||
CHECK(T(json(p1)) == p1);
|
||||
CHECK(json(T(json(p1))) == json(p1));
|
||||
|
||||
// check default value in case of missing field
|
||||
json j = json(p1);
|
||||
j.erase("name");
|
||||
j.erase("age");
|
||||
j.erase("metadata");
|
||||
j.erase("hair_color");
|
||||
T p3 = j.get<T>();
|
||||
CHECK(p3.getName() == "");
|
||||
CHECK(p3.getAge() == 0);
|
||||
CHECK(p3.getMetadata() == nullptr);
|
||||
CHECK(p3.getHairColor() == "blue");
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE_TEMPLATE("Serialization/deserialization of classes with 26 public/private member variables via NLOHMANN_DEFINE_TYPE_INTRUSIVE and NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE", T, // NOLINT(readability-math-missing-parentheses)
|
||||
persons::person_with_private_alphabet,
|
||||
persons::person_with_public_alphabet)
|
||||
{
|
||||
@@ -451,7 +669,7 @@ TEST_CASE_TEMPLATE("Serialization/deserialization of classes with 26 public/priv
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE_TEMPLATE("Serialization of non-default-constructible classes via NLOHMANN_DEFINE_TYPE_INTRUSIVE_ONLY_SERIALIZE and NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_ONLY_SERIALIZE", T,
|
||||
TEST_CASE_TEMPLATE("Serialization of non-default-constructible classes via NLOHMANN_DEFINE_TYPE_INTRUSIVE_ONLY_SERIALIZE and NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_ONLY_SERIALIZE", T, // NOLINT(readability-math-missing-parentheses)
|
||||
persons::person_without_default_constructor_1,
|
||||
persons::person_without_default_constructor_2)
|
||||
{
|
||||
@@ -472,3 +690,25 @@ TEST_CASE_TEMPLATE("Serialization of non-default-constructible classes via NLOHM
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE_TEMPLATE("Serialization of non-default-constructible classes via NLOHMANN_DEFINE_DERIVED_TYPE_INTRUSIVE_ONLY_SERIALIZE and NLOHMANN_DEFINE_DERIVED_TYPE_NON_INTRUSIVE_ONLY_SERIALIZE", T, // NOLINT(readability-math-missing-parentheses)
|
||||
persons::derived_person_only_serialize_public,
|
||||
persons::derived_person_only_serialize_private)
|
||||
{
|
||||
SECTION("derived person only serialize")
|
||||
{
|
||||
{
|
||||
// serialization of a single object
|
||||
T person{"Erik", 1, "brown"};
|
||||
CHECK(json(person).dump() == "{\"age\":1,\"hair_color\":\"brown\",\"name\":\"Erik\"}");
|
||||
|
||||
// serialization of a container with objects
|
||||
std::vector<T> const two_persons
|
||||
{
|
||||
{"Erik", 1, "brown"},
|
||||
{"Kyle", 2, "black"}
|
||||
};
|
||||
CHECK(json(two_persons).dump() == "[{\"age\":1,\"hair_color\":\"brown\",\"name\":\"Erik\"},{\"age\":2,\"hair_color\":\"black\",\"name\":\"Kyle\"}]");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
4
external/json/tests/src/unit-unicode1.cpp
vendored
4
external/json/tests/src/unit-unicode1.cpp
vendored
@@ -3,7 +3,7 @@
|
||||
// | | |__ | | | | | | version 3.11.3
|
||||
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
//
|
||||
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-FileCopyrightText: 2013 - 2024 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#include "doctest_compatibility.h"
|
||||
@@ -155,7 +155,7 @@ TEST_CASE("Unicode (1/5)" * doctest::skip())
|
||||
|
||||
SECTION("read all unicode characters")
|
||||
{
|
||||
// read a file with all unicode characters stored as single-character
|
||||
// read a file with all Unicode characters stored as single-character
|
||||
// strings in a JSON array
|
||||
std::ifstream f(TEST_DATA_DIRECTORY "/json_nlohmann_tests/all_unicode.json");
|
||||
json j;
|
||||
|
||||
2
external/json/tests/src/unit-unicode2.cpp
vendored
2
external/json/tests/src/unit-unicode2.cpp
vendored
@@ -3,7 +3,7 @@
|
||||
// | | |__ | | | | | | version 3.11.3
|
||||
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
//
|
||||
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-FileCopyrightText: 2013 - 2024 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#include "doctest_compatibility.h"
|
||||
|
||||
2
external/json/tests/src/unit-unicode3.cpp
vendored
2
external/json/tests/src/unit-unicode3.cpp
vendored
@@ -3,7 +3,7 @@
|
||||
// | | |__ | | | | | | version 3.11.3
|
||||
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
//
|
||||
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-FileCopyrightText: 2013 - 2024 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#include "doctest_compatibility.h"
|
||||
|
||||
2
external/json/tests/src/unit-unicode4.cpp
vendored
2
external/json/tests/src/unit-unicode4.cpp
vendored
@@ -3,7 +3,7 @@
|
||||
// | | |__ | | | | | | version 3.11.3
|
||||
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
//
|
||||
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-FileCopyrightText: 2013 - 2024 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#include "doctest_compatibility.h"
|
||||
|
||||
2
external/json/tests/src/unit-unicode5.cpp
vendored
2
external/json/tests/src/unit-unicode5.cpp
vendored
@@ -3,7 +3,7 @@
|
||||
// | | |__ | | | | | | version 3.11.3
|
||||
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
//
|
||||
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-FileCopyrightText: 2013 - 2024 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#include "doctest_compatibility.h"
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
// | | |__ | | | | | | version 3.11.3
|
||||
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
//
|
||||
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-FileCopyrightText: 2013 - 2024 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#include "doctest_compatibility.h"
|
||||
|
||||
2
external/json/tests/src/unit-windows_h.cpp
vendored
2
external/json/tests/src/unit-windows_h.cpp
vendored
@@ -3,7 +3,7 @@
|
||||
// | | |__ | | | | | | version 3.11.3
|
||||
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
//
|
||||
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-FileCopyrightText: 2013 - 2024 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#include "doctest_compatibility.h"
|
||||
|
||||
2
external/json/tests/src/unit-wstring.cpp
vendored
2
external/json/tests/src/unit-wstring.cpp
vendored
@@ -3,7 +3,7 @@
|
||||
// | | |__ | | | | | | version 3.11.3
|
||||
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
//
|
||||
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-FileCopyrightText: 2013 - 2024 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#include "doctest_compatibility.h"
|
||||
|
||||
2
external/json/tests/src/unit.cpp
vendored
2
external/json/tests/src/unit.cpp
vendored
@@ -3,7 +3,7 @@
|
||||
// | | |__ | | | | | | version 3.11.3
|
||||
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
//
|
||||
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-FileCopyrightText: 2013 - 2024 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
|
||||
|
||||
Reference in New Issue
Block a user