mirror of
https://github.com/nlohmann/json.git
synced 2024-11-23 22:19:02 +08:00
🎨 use Clang-Format
This commit is contained in:
parent
286f0c7647
commit
af3f87e84e
@ -46,7 +46,7 @@ BreakStringLiterals: false
|
||||
ColumnLimit: 160
|
||||
CompactNamespaces: false
|
||||
ConstructorInitializerIndentWidth: 2
|
||||
Cpp11BracedListStyle: true
|
||||
Cpp11BracedListStyle: false
|
||||
PointerAlignment: Left
|
||||
FixNamespaceComments: true
|
||||
#IndentCaseBlocks: false
|
||||
@ -92,3 +92,6 @@ IncludeCategories:
|
||||
Priority: 3
|
||||
- Regex: '.*'
|
||||
Priority: 4
|
||||
|
||||
Macros:
|
||||
- JSON_PRIVATE_UNLESS_TESTED=private
|
||||
|
16
.github/workflows/ubuntu.yml
vendored
16
.github/workflows/ubuntu.yml
vendored
@ -43,10 +43,20 @@ jobs:
|
||||
|
||||
ci_static_analysis:
|
||||
runs-on: ubuntu-latest
|
||||
container: silkeh/clang:dev
|
||||
container: ghcr.io/nlohmann/json-ci:v2.4.0
|
||||
strategy:
|
||||
matrix:
|
||||
target: [ci_cppcheck, ci_test_valgrind, ci_test_amalgamation, ci_test_single_header, ci_single_binaries, ci_infer]
|
||||
target: [ci_cppcheck, ci_test_valgrind, ci_test_single_header, ci_single_binaries, ci_infer]
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: Run CMake
|
||||
run: cmake -S . -B build -DJSON_CI=On
|
||||
- name: Build
|
||||
run: cmake --build build --target ${{ matrix.target }}
|
||||
|
||||
ci_test_amalgamation:
|
||||
runs-on: ubuntu-latest
|
||||
container: silkeh/clang:dev
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: Get latest CMake and ninja
|
||||
@ -54,7 +64,7 @@ jobs:
|
||||
- name: Run CMake
|
||||
run: cmake -S . -B build -DJSON_CI=On
|
||||
- name: Build
|
||||
run: cmake --build build --target ${{ matrix.target }}
|
||||
run: cmake --build build --target ci_test_amalgamation
|
||||
|
||||
ci_static_analysis_ubuntu:
|
||||
runs-on: ubuntu-latest
|
||||
|
@ -51,8 +51,8 @@ class exception : public std::exception
|
||||
JSON_HEDLEY_NON_NULL(3)
|
||||
exception(int id_, const char* what_arg)
|
||||
: id(id_)
|
||||
, m(what_arg)
|
||||
{} // NOLINT(bugprone-throw-keyword-missing)
|
||||
, m(what_arg) // NOLINT(bugprone-throw-keyword-missing)
|
||||
{}
|
||||
|
||||
static std::string name(const std::string& ename, int id_)
|
||||
{
|
||||
|
@ -341,10 +341,10 @@ class binary_reader
|
||||
default: // anything else not supported (yet)
|
||||
{
|
||||
std::array<char, 3> cr{ {} };
|
||||
static_cast<void>((std::snprintf)(cr.data(),
|
||||
static_cast<void>((std::snprintf)(cr.data(), // NOLINT(cppcoreguidelines-pro-type-vararg,hicpp-vararg)
|
||||
cr.size(),
|
||||
"%.2hhX",
|
||||
static_cast<unsigned char>(element_type))); // NOLINT(cppcoreguidelines-pro-type-vararg,hicpp-vararg)
|
||||
static_cast<unsigned char>(element_type)));
|
||||
const std::string cr_str{ cr.data() };
|
||||
return sax->parse_error(element_type_parse_position,
|
||||
cr_str,
|
||||
|
@ -1454,8 +1454,8 @@ scan_number_done:
|
||||
{
|
||||
// escape control characters
|
||||
std::array<char, 9> cs{ {} };
|
||||
static_cast<void>((
|
||||
std::snprintf)(cs.data(), cs.size(), "<U+%.4X>", static_cast<unsigned char>(c))); // NOLINT(cppcoreguidelines-pro-type-vararg,hicpp-vararg)
|
||||
static_cast<void>(( // NOLINT(cppcoreguidelines-pro-type-vararg,hicpp-vararg)
|
||||
std::snprintf)(cs.data(), cs.size(), "<U+%.4X>", static_cast<unsigned char>(c)));
|
||||
result += cs.data();
|
||||
}
|
||||
else
|
||||
@ -1549,7 +1549,8 @@ scan_number_done:
|
||||
case 't':
|
||||
{
|
||||
std::array<char_type, 4> true_literal = {
|
||||
{static_cast<char_type>('t'), static_cast<char_type>('r'), static_cast<char_type>('u'), static_cast<char_type>('e')}};
|
||||
{ static_cast<char_type>('t'), static_cast<char_type>('r'), static_cast<char_type>('u'), static_cast<char_type>('e') }
|
||||
};
|
||||
return scan_literal(true_literal.data(), true_literal.size(), token_type::literal_true);
|
||||
}
|
||||
case 'f':
|
||||
@ -1564,7 +1565,8 @@ scan_number_done:
|
||||
case 'n':
|
||||
{
|
||||
std::array<char_type, 4> null_literal = {
|
||||
{static_cast<char_type>('n'), static_cast<char_type>('u'), static_cast<char_type>('l'), static_cast<char_type>('l')}};
|
||||
{ static_cast<char_type>('n'), static_cast<char_type>('u'), static_cast<char_type>('l'), static_cast<char_type>('l') }
|
||||
};
|
||||
return scan_literal(null_literal.data(), null_literal.size(), token_type::literal_null);
|
||||
}
|
||||
|
||||
|
@ -196,8 +196,7 @@ class iter_impl // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
|
||||
@brief set the iterator to the first value
|
||||
@pre The iterator is initialized; i.e. `m_object != nullptr`.
|
||||
*/
|
||||
void
|
||||
set_begin() noexcept
|
||||
void set_begin() noexcept
|
||||
{
|
||||
JSON_ASSERT(m_object != nullptr);
|
||||
|
||||
|
@ -242,7 +242,8 @@ class json_pointer
|
||||
return static_cast<size_type>(res);
|
||||
}
|
||||
|
||||
JSON_PRIVATE_UNLESS_TESTED : json_pointer top() const
|
||||
JSON_PRIVATE_UNLESS_TESTED :
|
||||
json_pointer top() const
|
||||
{
|
||||
if (JSON_HEDLEY_UNLIKELY(empty()))
|
||||
{
|
||||
|
@ -1579,17 +1579,8 @@ class binary_writer
|
||||
*/
|
||||
bool write_bjdata_ndarray(const typename BasicJsonType::object_t& value, const bool use_count, const bool use_type)
|
||||
{
|
||||
std::map<string_t, CharType> bjdtype = {{"uint8", 'U'},
|
||||
{"int8", 'i'},
|
||||
{"uint16", 'u'},
|
||||
{"int16", 'I'},
|
||||
{"uint32", 'm'},
|
||||
{"int32", 'l'},
|
||||
{"uint64", 'M'},
|
||||
{"int64", 'L'},
|
||||
{"single", 'd'},
|
||||
{"double", 'D'},
|
||||
{"char", 'C'}};
|
||||
std::map<string_t, CharType> bjdtype = { { "uint8", 'U' }, { "int8", 'i' }, { "uint16", 'u' }, { "int16", 'I' }, { "uint32", 'm' }, { "int32", 'l' },
|
||||
{ "uint64", 'M' }, { "int64", 'L' }, { "single", 'd' }, { "double", 'D' }, { "char", 'C' } };
|
||||
|
||||
string_t key = "_ArrayType_";
|
||||
auto it = bjdtype.find(static_cast<string_t>(value.at(key)));
|
||||
|
@ -379,8 +379,7 @@ class serializer
|
||||
|
||||
@complexity Linear in the length of string @a s.
|
||||
*/
|
||||
void
|
||||
dump_escaped(const string_t& s, const bool ensure_ascii)
|
||||
void dump_escaped(const string_t& s, const bool ensure_ascii)
|
||||
{
|
||||
std::uint32_t codepoint{};
|
||||
std::uint8_t state = UTF8_ACCEPT;
|
||||
@ -707,16 +706,19 @@ class serializer
|
||||
void dump_integer(NumberType x)
|
||||
{
|
||||
static constexpr std::array<std::array<char, 2>, 100> digits_to_99{ {
|
||||
{{'0', '0'}}, {{'0', '1'}}, {{'0', '2'}}, {{'0', '3'}}, {{'0', '4'}}, {{'0', '5'}}, {{'0', '6'}}, {{'0', '7'}}, {{'0', '8'}}, {{'0', '9'}},
|
||||
{{'1', '0'}}, {{'1', '1'}}, {{'1', '2'}}, {{'1', '3'}}, {{'1', '4'}}, {{'1', '5'}}, {{'1', '6'}}, {{'1', '7'}}, {{'1', '8'}}, {{'1', '9'}},
|
||||
{{'2', '0'}}, {{'2', '1'}}, {{'2', '2'}}, {{'2', '3'}}, {{'2', '4'}}, {{'2', '5'}}, {{'2', '6'}}, {{'2', '7'}}, {{'2', '8'}}, {{'2', '9'}},
|
||||
{{'3', '0'}}, {{'3', '1'}}, {{'3', '2'}}, {{'3', '3'}}, {{'3', '4'}}, {{'3', '5'}}, {{'3', '6'}}, {{'3', '7'}}, {{'3', '8'}}, {{'3', '9'}},
|
||||
{{'4', '0'}}, {{'4', '1'}}, {{'4', '2'}}, {{'4', '3'}}, {{'4', '4'}}, {{'4', '5'}}, {{'4', '6'}}, {{'4', '7'}}, {{'4', '8'}}, {{'4', '9'}},
|
||||
{{'5', '0'}}, {{'5', '1'}}, {{'5', '2'}}, {{'5', '3'}}, {{'5', '4'}}, {{'5', '5'}}, {{'5', '6'}}, {{'5', '7'}}, {{'5', '8'}}, {{'5', '9'}},
|
||||
{{'6', '0'}}, {{'6', '1'}}, {{'6', '2'}}, {{'6', '3'}}, {{'6', '4'}}, {{'6', '5'}}, {{'6', '6'}}, {{'6', '7'}}, {{'6', '8'}}, {{'6', '9'}},
|
||||
{{'7', '0'}}, {{'7', '1'}}, {{'7', '2'}}, {{'7', '3'}}, {{'7', '4'}}, {{'7', '5'}}, {{'7', '6'}}, {{'7', '7'}}, {{'7', '8'}}, {{'7', '9'}},
|
||||
{{'8', '0'}}, {{'8', '1'}}, {{'8', '2'}}, {{'8', '3'}}, {{'8', '4'}}, {{'8', '5'}}, {{'8', '6'}}, {{'8', '7'}}, {{'8', '8'}}, {{'8', '9'}},
|
||||
{{'9', '0'}}, {{'9', '1'}}, {{'9', '2'}}, {{'9', '3'}}, {{'9', '4'}}, {{'9', '5'}}, {{'9', '6'}}, {{'9', '7'}}, {{'9', '8'}}, {{'9', '9'}},
|
||||
{ { '0', '0' } }, { { '0', '1' } }, { { '0', '2' } }, { { '0', '3' } }, { { '0', '4' } }, { { '0', '5' } }, { { '0', '6' } }, { { '0', '7' } },
|
||||
{ { '0', '8' } }, { { '0', '9' } }, { { '1', '0' } }, { { '1', '1' } }, { { '1', '2' } }, { { '1', '3' } }, { { '1', '4' } }, { { '1', '5' } },
|
||||
{ { '1', '6' } }, { { '1', '7' } }, { { '1', '8' } }, { { '1', '9' } }, { { '2', '0' } }, { { '2', '1' } }, { { '2', '2' } }, { { '2', '3' } },
|
||||
{ { '2', '4' } }, { { '2', '5' } }, { { '2', '6' } }, { { '2', '7' } }, { { '2', '8' } }, { { '2', '9' } }, { { '3', '0' } }, { { '3', '1' } },
|
||||
{ { '3', '2' } }, { { '3', '3' } }, { { '3', '4' } }, { { '3', '5' } }, { { '3', '6' } }, { { '3', '7' } }, { { '3', '8' } }, { { '3', '9' } },
|
||||
{ { '4', '0' } }, { { '4', '1' } }, { { '4', '2' } }, { { '4', '3' } }, { { '4', '4' } }, { { '4', '5' } }, { { '4', '6' } }, { { '4', '7' } },
|
||||
{ { '4', '8' } }, { { '4', '9' } }, { { '5', '0' } }, { { '5', '1' } }, { { '5', '2' } }, { { '5', '3' } }, { { '5', '4' } }, { { '5', '5' } },
|
||||
{ { '5', '6' } }, { { '5', '7' } }, { { '5', '8' } }, { { '5', '9' } }, { { '6', '0' } }, { { '6', '1' } }, { { '6', '2' } }, { { '6', '3' } },
|
||||
{ { '6', '4' } }, { { '6', '5' } }, { { '6', '6' } }, { { '6', '7' } }, { { '6', '8' } }, { { '6', '9' } }, { { '7', '0' } }, { { '7', '1' } },
|
||||
{ { '7', '2' } }, { { '7', '3' } }, { { '7', '4' } }, { { '7', '5' } }, { { '7', '6' } }, { { '7', '7' } }, { { '7', '8' } }, { { '7', '9' } },
|
||||
{ { '8', '0' } }, { { '8', '1' } }, { { '8', '2' } }, { { '8', '3' } }, { { '8', '4' } }, { { '8', '5' } }, { { '8', '6' } }, { { '8', '7' } },
|
||||
{ { '8', '8' } }, { { '8', '9' } }, { { '9', '0' } }, { { '9', '1' } }, { { '9', '2' } }, { { '9', '3' } }, { { '9', '4' } }, { { '9', '5' } },
|
||||
{ { '9', '6' } }, { { '9', '7' } }, { { '9', '8' } }, { { '9', '9' } },
|
||||
} };
|
||||
|
||||
// special case for "0"
|
||||
|
@ -155,7 +155,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spe
|
||||
template<typename CharType>
|
||||
using binary_writer = ::nlohmann::detail::binary_writer<basic_json, CharType>;
|
||||
|
||||
JSON_PRIVATE_UNLESS_TESTED : using serializer = ::nlohmann::detail::serializer<basic_json>;
|
||||
JSON_PRIVATE_UNLESS_TESTED :
|
||||
using serializer = ::nlohmann::detail::serializer<basic_json>;
|
||||
|
||||
public:
|
||||
using value_t = detail::value_t;
|
||||
@ -3604,8 +3605,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spe
|
||||
// - any operand is discarded
|
||||
// in legacy mode, discarded values are considered ordered if
|
||||
// an operation is computed as an odd number of inverses of others
|
||||
static bool
|
||||
compares_unordered(const_reference lhs, const_reference rhs, bool inverse = false) noexcept
|
||||
static bool compares_unordered(const_reference lhs, const_reference rhs, bool inverse = false) noexcept
|
||||
{
|
||||
if ((lhs.is_number_float() && std::isnan(lhs.m_data.m_value.number_float) && rhs.is_number()) ||
|
||||
(rhs.is_number_float() && std::isnan(rhs.m_data.m_value.number_float) && lhs.is_number()))
|
||||
|
@ -213,6 +213,7 @@ NLOHMANN_JSON_NAMESPACE_END
|
||||
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#include <utility> // declval, pair
|
||||
// #include <nlohmann/detail/meta/detected.hpp>
|
||||
// __ _____ _____ _____
|
||||
// __| | __| | | | JSON for Modern C++
|
||||
@ -2024,8 +2025,6 @@ JSON_HEDLEY_DIAGNOSTIC_POP
|
||||
|
||||
#endif /* !defined(JSON_HEDLEY_VERSION) || (JSON_HEDLEY_VERSION < X) */
|
||||
|
||||
#include <utility> // declval, pair
|
||||
|
||||
// This file contains all internal macro definitions (except those affecting ABI)
|
||||
// You MUST include macro_unscope.hpp at the end of json.hpp to undef all of them
|
||||
|
||||
@ -7444,8 +7443,8 @@ class exception : public std::exception
|
||||
JSON_HEDLEY_NON_NULL(3)
|
||||
exception(int id_, const char* what_arg)
|
||||
: id(id_)
|
||||
, m(what_arg)
|
||||
{} // NOLINT(bugprone-throw-keyword-missing)
|
||||
, m(what_arg) // NOLINT(bugprone-throw-keyword-missing)
|
||||
{}
|
||||
|
||||
static std::string name(const std::string& ename, int id_)
|
||||
{
|
||||
@ -11845,8 +11844,8 @@ scan_number_done:
|
||||
{
|
||||
// escape control characters
|
||||
std::array<char, 9> cs{ {} };
|
||||
static_cast<void>((
|
||||
std::snprintf)(cs.data(), cs.size(), "<U+%.4X>", static_cast<unsigned char>(c))); // NOLINT(cppcoreguidelines-pro-type-vararg,hicpp-vararg)
|
||||
static_cast<void>(( // NOLINT(cppcoreguidelines-pro-type-vararg,hicpp-vararg)
|
||||
std::snprintf)(cs.data(), cs.size(), "<U+%.4X>", static_cast<unsigned char>(c)));
|
||||
result += cs.data();
|
||||
}
|
||||
else
|
||||
@ -11940,7 +11939,8 @@ scan_number_done:
|
||||
case 't':
|
||||
{
|
||||
std::array<char_type, 4> true_literal = {
|
||||
{static_cast<char_type>('t'), static_cast<char_type>('r'), static_cast<char_type>('u'), static_cast<char_type>('e')}};
|
||||
{ static_cast<char_type>('t'), static_cast<char_type>('r'), static_cast<char_type>('u'), static_cast<char_type>('e') }
|
||||
};
|
||||
return scan_literal(true_literal.data(), true_literal.size(), token_type::literal_true);
|
||||
}
|
||||
case 'f':
|
||||
@ -11955,7 +11955,8 @@ scan_number_done:
|
||||
case 'n':
|
||||
{
|
||||
std::array<char_type, 4> null_literal = {
|
||||
{static_cast<char_type>('n'), static_cast<char_type>('u'), static_cast<char_type>('l'), static_cast<char_type>('l')}};
|
||||
{ static_cast<char_type>('n'), static_cast<char_type>('u'), static_cast<char_type>('l'), static_cast<char_type>('l') }
|
||||
};
|
||||
return scan_literal(null_literal.data(), null_literal.size(), token_type::literal_null);
|
||||
}
|
||||
|
||||
@ -12471,10 +12472,10 @@ class binary_reader
|
||||
default: // anything else not supported (yet)
|
||||
{
|
||||
std::array<char, 3> cr{ {} };
|
||||
static_cast<void>((std::snprintf)(cr.data(),
|
||||
static_cast<void>((std::snprintf)(cr.data(), // NOLINT(cppcoreguidelines-pro-type-vararg,hicpp-vararg)
|
||||
cr.size(),
|
||||
"%.2hhX",
|
||||
static_cast<unsigned char>(element_type))); // NOLINT(cppcoreguidelines-pro-type-vararg,hicpp-vararg)
|
||||
static_cast<unsigned char>(element_type)));
|
||||
const std::string cr_str{ cr.data() };
|
||||
return sax->parse_error(element_type_parse_position,
|
||||
cr_str,
|
||||
@ -16111,8 +16112,7 @@ class iter_impl // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
|
||||
@brief set the iterator to the first value
|
||||
@pre The iterator is initialized; i.e. `m_object != nullptr`.
|
||||
*/
|
||||
void
|
||||
set_begin() noexcept
|
||||
void set_begin() noexcept
|
||||
{
|
||||
JSON_ASSERT(m_object != nullptr);
|
||||
|
||||
@ -17090,7 +17090,8 @@ class json_pointer
|
||||
return static_cast<size_type>(res);
|
||||
}
|
||||
|
||||
JSON_PRIVATE_UNLESS_TESTED : json_pointer top() const
|
||||
JSON_PRIVATE_UNLESS_TESTED :
|
||||
json_pointer top() const
|
||||
{
|
||||
if (JSON_HEDLEY_UNLIKELY(empty()))
|
||||
{
|
||||
@ -19618,17 +19619,8 @@ class binary_writer
|
||||
*/
|
||||
bool write_bjdata_ndarray(const typename BasicJsonType::object_t& value, const bool use_count, const bool use_type)
|
||||
{
|
||||
std::map<string_t, CharType> bjdtype = {{"uint8", 'U'},
|
||||
{"int8", 'i'},
|
||||
{"uint16", 'u'},
|
||||
{"int16", 'I'},
|
||||
{"uint32", 'm'},
|
||||
{"int32", 'l'},
|
||||
{"uint64", 'M'},
|
||||
{"int64", 'L'},
|
||||
{"single", 'd'},
|
||||
{"double", 'D'},
|
||||
{"char", 'C'}};
|
||||
std::map<string_t, CharType> bjdtype = { { "uint8", 'U' }, { "int8", 'i' }, { "uint16", 'u' }, { "int16", 'I' }, { "uint32", 'm' }, { "int32", 'l' },
|
||||
{ "uint64", 'M' }, { "int64", 'L' }, { "single", 'd' }, { "double", 'D' }, { "char", 'C' } };
|
||||
|
||||
string_t key = "_ArrayType_";
|
||||
auto it = bjdtype.find(static_cast<string_t>(value.at(key)));
|
||||
@ -21272,8 +21264,7 @@ class serializer
|
||||
|
||||
@complexity Linear in the length of string @a s.
|
||||
*/
|
||||
void
|
||||
dump_escaped(const string_t& s, const bool ensure_ascii)
|
||||
void dump_escaped(const string_t& s, const bool ensure_ascii)
|
||||
{
|
||||
std::uint32_t codepoint{};
|
||||
std::uint8_t state = UTF8_ACCEPT;
|
||||
@ -21600,16 +21591,19 @@ class serializer
|
||||
void dump_integer(NumberType x)
|
||||
{
|
||||
static constexpr std::array<std::array<char, 2>, 100> digits_to_99{ {
|
||||
{{'0', '0'}}, {{'0', '1'}}, {{'0', '2'}}, {{'0', '3'}}, {{'0', '4'}}, {{'0', '5'}}, {{'0', '6'}}, {{'0', '7'}}, {{'0', '8'}}, {{'0', '9'}},
|
||||
{{'1', '0'}}, {{'1', '1'}}, {{'1', '2'}}, {{'1', '3'}}, {{'1', '4'}}, {{'1', '5'}}, {{'1', '6'}}, {{'1', '7'}}, {{'1', '8'}}, {{'1', '9'}},
|
||||
{{'2', '0'}}, {{'2', '1'}}, {{'2', '2'}}, {{'2', '3'}}, {{'2', '4'}}, {{'2', '5'}}, {{'2', '6'}}, {{'2', '7'}}, {{'2', '8'}}, {{'2', '9'}},
|
||||
{{'3', '0'}}, {{'3', '1'}}, {{'3', '2'}}, {{'3', '3'}}, {{'3', '4'}}, {{'3', '5'}}, {{'3', '6'}}, {{'3', '7'}}, {{'3', '8'}}, {{'3', '9'}},
|
||||
{{'4', '0'}}, {{'4', '1'}}, {{'4', '2'}}, {{'4', '3'}}, {{'4', '4'}}, {{'4', '5'}}, {{'4', '6'}}, {{'4', '7'}}, {{'4', '8'}}, {{'4', '9'}},
|
||||
{{'5', '0'}}, {{'5', '1'}}, {{'5', '2'}}, {{'5', '3'}}, {{'5', '4'}}, {{'5', '5'}}, {{'5', '6'}}, {{'5', '7'}}, {{'5', '8'}}, {{'5', '9'}},
|
||||
{{'6', '0'}}, {{'6', '1'}}, {{'6', '2'}}, {{'6', '3'}}, {{'6', '4'}}, {{'6', '5'}}, {{'6', '6'}}, {{'6', '7'}}, {{'6', '8'}}, {{'6', '9'}},
|
||||
{{'7', '0'}}, {{'7', '1'}}, {{'7', '2'}}, {{'7', '3'}}, {{'7', '4'}}, {{'7', '5'}}, {{'7', '6'}}, {{'7', '7'}}, {{'7', '8'}}, {{'7', '9'}},
|
||||
{{'8', '0'}}, {{'8', '1'}}, {{'8', '2'}}, {{'8', '3'}}, {{'8', '4'}}, {{'8', '5'}}, {{'8', '6'}}, {{'8', '7'}}, {{'8', '8'}}, {{'8', '9'}},
|
||||
{{'9', '0'}}, {{'9', '1'}}, {{'9', '2'}}, {{'9', '3'}}, {{'9', '4'}}, {{'9', '5'}}, {{'9', '6'}}, {{'9', '7'}}, {{'9', '8'}}, {{'9', '9'}},
|
||||
{ { '0', '0' } }, { { '0', '1' } }, { { '0', '2' } }, { { '0', '3' } }, { { '0', '4' } }, { { '0', '5' } }, { { '0', '6' } }, { { '0', '7' } },
|
||||
{ { '0', '8' } }, { { '0', '9' } }, { { '1', '0' } }, { { '1', '1' } }, { { '1', '2' } }, { { '1', '3' } }, { { '1', '4' } }, { { '1', '5' } },
|
||||
{ { '1', '6' } }, { { '1', '7' } }, { { '1', '8' } }, { { '1', '9' } }, { { '2', '0' } }, { { '2', '1' } }, { { '2', '2' } }, { { '2', '3' } },
|
||||
{ { '2', '4' } }, { { '2', '5' } }, { { '2', '6' } }, { { '2', '7' } }, { { '2', '8' } }, { { '2', '9' } }, { { '3', '0' } }, { { '3', '1' } },
|
||||
{ { '3', '2' } }, { { '3', '3' } }, { { '3', '4' } }, { { '3', '5' } }, { { '3', '6' } }, { { '3', '7' } }, { { '3', '8' } }, { { '3', '9' } },
|
||||
{ { '4', '0' } }, { { '4', '1' } }, { { '4', '2' } }, { { '4', '3' } }, { { '4', '4' } }, { { '4', '5' } }, { { '4', '6' } }, { { '4', '7' } },
|
||||
{ { '4', '8' } }, { { '4', '9' } }, { { '5', '0' } }, { { '5', '1' } }, { { '5', '2' } }, { { '5', '3' } }, { { '5', '4' } }, { { '5', '5' } },
|
||||
{ { '5', '6' } }, { { '5', '7' } }, { { '5', '8' } }, { { '5', '9' } }, { { '6', '0' } }, { { '6', '1' } }, { { '6', '2' } }, { { '6', '3' } },
|
||||
{ { '6', '4' } }, { { '6', '5' } }, { { '6', '6' } }, { { '6', '7' } }, { { '6', '8' } }, { { '6', '9' } }, { { '7', '0' } }, { { '7', '1' } },
|
||||
{ { '7', '2' } }, { { '7', '3' } }, { { '7', '4' } }, { { '7', '5' } }, { { '7', '6' } }, { { '7', '7' } }, { { '7', '8' } }, { { '7', '9' } },
|
||||
{ { '8', '0' } }, { { '8', '1' } }, { { '8', '2' } }, { { '8', '3' } }, { { '8', '4' } }, { { '8', '5' } }, { { '8', '6' } }, { { '8', '7' } },
|
||||
{ { '8', '8' } }, { { '8', '9' } }, { { '9', '0' } }, { { '9', '1' } }, { { '9', '2' } }, { { '9', '3' } }, { { '9', '4' } }, { { '9', '5' } },
|
||||
{ { '9', '6' } }, { { '9', '7' } }, { { '9', '8' } }, { { '9', '9' } },
|
||||
} };
|
||||
|
||||
// special case for "0"
|
||||
@ -22336,7 +22330,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spe
|
||||
template<typename CharType>
|
||||
using binary_writer = ::nlohmann::detail::binary_writer<basic_json, CharType>;
|
||||
|
||||
JSON_PRIVATE_UNLESS_TESTED : using serializer = ::nlohmann::detail::serializer<basic_json>;
|
||||
JSON_PRIVATE_UNLESS_TESTED :
|
||||
using serializer = ::nlohmann::detail::serializer<basic_json>;
|
||||
|
||||
public:
|
||||
using value_t = detail::value_t;
|
||||
@ -25785,8 +25780,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spe
|
||||
// - any operand is discarded
|
||||
// in legacy mode, discarded values are considered ordered if
|
||||
// an operation is computed as an odd number of inverses of others
|
||||
static bool
|
||||
compares_unordered(const_reference lhs, const_reference rhs, bool inverse = false) noexcept
|
||||
static bool compares_unordered(const_reference lhs, const_reference rhs, bool inverse = false) noexcept
|
||||
{
|
||||
if ((lhs.is_number_float() && std::isnan(lhs.m_data.m_value.number_float) && rhs.is_number()) ||
|
||||
(rhs.is_number_float() && std::isnan(rhs.m_data.m_value.number_float) && lhs.is_number()))
|
||||
|
@ -24,8 +24,6 @@
|
||||
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
|
||||
|
||||
// This file contains all macro definitions affecting or depending on the ABI
|
||||
|
||||
#ifndef JSON_SKIP_LIBRARY_VERSION_CHECK
|
||||
@ -103,7 +101,6 @@
|
||||
} // namespace nlohmann
|
||||
#endif
|
||||
|
||||
|
||||
/*!
|
||||
@brief namespace for Niels Lohmann
|
||||
@see https://github.com/nlohmann
|
||||
|
@ -334,12 +334,7 @@ TEST_CASE("BJData")
|
||||
SECTION("-2147483648..-32769 (int32)")
|
||||
{
|
||||
std::vector<int32_t> const numbers{
|
||||
-32769,
|
||||
-100000,
|
||||
-1000000,
|
||||
-10000000,
|
||||
-100000000,
|
||||
-1000000000,
|
||||
-32769, -100000, -1000000, -10000000, -100000000, -1000000000,
|
||||
-2147483647 - 1, // https://stackoverflow.com/a/29356002/266378
|
||||
};
|
||||
for (const auto i : numbers)
|
||||
@ -2422,9 +2417,12 @@ TEST_CASE("BJData")
|
||||
CHECK(json::from_bjdata(v_l) == json({ { "_ArrayData_", { 1, 2, 3, 4, 5, 6 } }, { "_ArraySize_", { 2, 3 } }, { "_ArrayType_", "int32" } }));
|
||||
CHECK(json::from_bjdata(v_M) == json({ { "_ArrayData_", { 1, 2, 3, 4, 5, 6 } }, { "_ArraySize_", { 2, 3 } }, { "_ArrayType_", "uint64" } }));
|
||||
CHECK(json::from_bjdata(v_L) == json({ { "_ArrayData_", { 1, 2, 3, 4, 5, 6 } }, { "_ArraySize_", { 2, 3 } }, { "_ArrayType_", "int64" } }));
|
||||
CHECK(json::from_bjdata(v_d) == json({{"_ArrayData_", {1.f, 2.f, 3.f, 4.f, 5.f, 6.f}}, {"_ArraySize_", {2, 3}}, {"_ArrayType_", "single"}}));
|
||||
CHECK(json::from_bjdata(v_D) == json({{"_ArrayData_", {1., 2., 3., 4., 5., 6.}}, {"_ArraySize_", {2, 3}}, {"_ArrayType_", "double"}}));
|
||||
CHECK(json::from_bjdata(v_C) == json({{"_ArrayData_", {'a', 'b', 'c', 'd', 'e', 'f'}}, {"_ArraySize_", {2, 3}}, {"_ArrayType_", "char"}}));
|
||||
CHECK(json::from_bjdata(v_d) ==
|
||||
json({ { "_ArrayData_", { 1.f, 2.f, 3.f, 4.f, 5.f, 6.f } }, { "_ArraySize_", { 2, 3 } }, { "_ArrayType_", "single" } }));
|
||||
CHECK(json::from_bjdata(v_D) ==
|
||||
json({ { "_ArrayData_", { 1., 2., 3., 4., 5., 6. } }, { "_ArraySize_", { 2, 3 } }, { "_ArrayType_", "double" } }));
|
||||
CHECK(json::from_bjdata(v_C) ==
|
||||
json({ { "_ArrayData_", { 'a', 'b', 'c', 'd', 'e', 'f' } }, { "_ArraySize_", { 2, 3 } }, { "_ArrayType_", "char" } }));
|
||||
|
||||
// roundtrip: output should be optimized
|
||||
CHECK(json::to_bjdata(json::from_bjdata(v_e), true, true) == v_e);
|
||||
@ -3314,8 +3312,9 @@ TEST_CASE("Universal Binary JSON Specification Examples 1")
|
||||
SECTION("Boolean Types")
|
||||
{
|
||||
json const j = { { "authorized", true }, { "verified", false } };
|
||||
std::vector<uint8_t> v = {'{', 'i', 10, 'a', 'u', 't', 'h', 'o', 'r', 'i', 'z', 'e', 'd',
|
||||
'T', 'i', 8, 'v', 'e', 'r', 'i', 'f', 'i', 'e', 'd', 'F', '}'};
|
||||
std::vector<uint8_t> v = {
|
||||
'{', 'i', 10, 'a', 'u', 't', 'h', 'o', 'r', 'i', 'z', 'e', 'd', 'T', 'i', 8, 'v', 'e', 'r', 'i', 'f', 'i', 'e', 'd', 'F', '}'
|
||||
};
|
||||
CHECK(json::to_bjdata(j) == v);
|
||||
CHECK(json::from_bjdata(v) == j);
|
||||
}
|
||||
|
@ -131,17 +131,10 @@ TEST_CASE("BSON")
|
||||
json const j = { { "entry", true } };
|
||||
|
||||
std::vector<std::uint8_t> const expected = {
|
||||
0x0D,
|
||||
0x00,
|
||||
0x00,
|
||||
0x0D, 0x00, 0x00,
|
||||
0x00, // size (little endian)
|
||||
0x08, // entry: boolean
|
||||
'e',
|
||||
'n',
|
||||
't',
|
||||
'r',
|
||||
'y',
|
||||
'\x00',
|
||||
'e', 'n', 't', 'r', 'y', '\x00',
|
||||
0x01, // value = true
|
||||
0x00 // end marker
|
||||
};
|
||||
@ -159,17 +152,10 @@ TEST_CASE("BSON")
|
||||
json const j = { { "entry", false } };
|
||||
|
||||
std::vector<std::uint8_t> const expected = {
|
||||
0x0D,
|
||||
0x00,
|
||||
0x00,
|
||||
0x0D, 0x00, 0x00,
|
||||
0x00, // size (little endian)
|
||||
0x08, // entry: boolean
|
||||
'e',
|
||||
'n',
|
||||
't',
|
||||
'r',
|
||||
'y',
|
||||
'\x00',
|
||||
'e', 'n', 't', 'r', 'y', '\x00',
|
||||
0x00, // value = false
|
||||
0x00 // end marker
|
||||
};
|
||||
@ -227,17 +213,10 @@ TEST_CASE("BSON")
|
||||
json const j = { { "entry", nullptr } };
|
||||
|
||||
std::vector<std::uint8_t> const expected = {
|
||||
0x0C,
|
||||
0x00,
|
||||
0x00,
|
||||
0x0C, 0x00, 0x00,
|
||||
0x00, // size (little endian)
|
||||
0x0A, /// entry: null
|
||||
'e',
|
||||
'n',
|
||||
't',
|
||||
'r',
|
||||
'y',
|
||||
'\x00',
|
||||
'e', 'n', 't', 'r', 'y', '\x00',
|
||||
0x00 // end marker
|
||||
};
|
||||
|
||||
@ -254,21 +233,10 @@ TEST_CASE("BSON")
|
||||
json const j = { { "entry", std::int32_t{ 0x12345678 } } };
|
||||
|
||||
std::vector<std::uint8_t> const expected = {
|
||||
0x10,
|
||||
0x00,
|
||||
0x00,
|
||||
0x10, 0x00, 0x00,
|
||||
0x00, // size (little endian)
|
||||
0x10, /// entry: int32
|
||||
'e',
|
||||
'n',
|
||||
't',
|
||||
'r',
|
||||
'y',
|
||||
'\x00',
|
||||
0x78,
|
||||
0x56,
|
||||
0x34,
|
||||
0x12,
|
||||
'e', 'n', 't', 'r', 'y', '\x00', 0x78, 0x56, 0x34, 0x12,
|
||||
0x00 // end marker
|
||||
};
|
||||
|
||||
@ -305,21 +273,10 @@ TEST_CASE("BSON")
|
||||
json const j = { { "entry", std::int32_t{ -1 } } };
|
||||
|
||||
std::vector<std::uint8_t> const expected = {
|
||||
0x10,
|
||||
0x00,
|
||||
0x00,
|
||||
0x10, 0x00, 0x00,
|
||||
0x00, // size (little endian)
|
||||
0x10, /// entry: int32
|
||||
'e',
|
||||
'n',
|
||||
't',
|
||||
'r',
|
||||
'y',
|
||||
'\x00',
|
||||
0xFF,
|
||||
0xFF,
|
||||
0xFF,
|
||||
0xFF,
|
||||
'e', 'n', 't', 'r', 'y', '\x00', 0xFF, 0xFF, 0xFF, 0xFF,
|
||||
0x00 // end marker
|
||||
};
|
||||
|
||||
@ -336,21 +293,10 @@ TEST_CASE("BSON")
|
||||
json const j = { { "entry", std::int64_t{ -1 } } };
|
||||
|
||||
std::vector<std::uint8_t> const expected = {
|
||||
0x10,
|
||||
0x00,
|
||||
0x00,
|
||||
0x10, 0x00, 0x00,
|
||||
0x00, // size (little endian)
|
||||
0x10, /// entry: int32
|
||||
'e',
|
||||
'n',
|
||||
't',
|
||||
'r',
|
||||
'y',
|
||||
'\x00',
|
||||
0xFF,
|
||||
0xFF,
|
||||
0xFF,
|
||||
0xFF,
|
||||
'e', 'n', 't', 'r', 'y', '\x00', 0xFF, 0xFF, 0xFF, 0xFF,
|
||||
0x00 // end marker
|
||||
};
|
||||
|
||||
@ -388,21 +334,10 @@ TEST_CASE("BSON")
|
||||
json const j = { { "entry", std::uint64_t{ 0x42 } } };
|
||||
|
||||
std::vector<std::uint8_t> const expected = {
|
||||
0x10,
|
||||
0x00,
|
||||
0x00,
|
||||
0x10, 0x00, 0x00,
|
||||
0x00, // size (little endian)
|
||||
0x10, /// entry: int32
|
||||
'e',
|
||||
'n',
|
||||
't',
|
||||
'r',
|
||||
'y',
|
||||
'\x00',
|
||||
0x42,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
'e', 'n', 't', 'r', 'y', '\x00', 0x42, 0x00, 0x00, 0x00,
|
||||
0x00 // end marker
|
||||
};
|
||||
|
||||
@ -895,13 +830,10 @@ TEST_CASE("Incomplete BSON Input")
|
||||
SECTION("Incomplete BSON Input 1")
|
||||
{
|
||||
std::vector<std::uint8_t> const incomplete_bson = {
|
||||
0x0D,
|
||||
0x00,
|
||||
0x00,
|
||||
0x0D, 0x00, 0x00,
|
||||
0x00, // size (little endian)
|
||||
0x08, // entry: boolean
|
||||
'e',
|
||||
'n',
|
||||
'e', 'n',
|
||||
't' // unexpected EOF
|
||||
};
|
||||
|
||||
@ -919,9 +851,7 @@ TEST_CASE("Incomplete BSON Input")
|
||||
SECTION("Incomplete BSON Input 2")
|
||||
{
|
||||
std::vector<std::uint8_t> const incomplete_bson = {
|
||||
0x0D,
|
||||
0x00,
|
||||
0x00,
|
||||
0x0D, 0x00, 0x00,
|
||||
0x00, // size (little endian)
|
||||
0x08, // entry: boolean, unexpected EOF
|
||||
};
|
||||
@ -1024,17 +954,10 @@ TEST_CASE("Negative size of binary value")
|
||||
TEST_CASE("Unsupported BSON input")
|
||||
{
|
||||
std::vector<std::uint8_t> const bson = {
|
||||
0x0C,
|
||||
0x00,
|
||||
0x00,
|
||||
0x0C, 0x00, 0x00,
|
||||
0x00, // size (little endian)
|
||||
0xFF, // entry type: Min key (not supported yet)
|
||||
'e',
|
||||
'n',
|
||||
't',
|
||||
'r',
|
||||
'y',
|
||||
'\x00',
|
||||
'e', 'n', 't', 'r', 'y', '\x00',
|
||||
0x00 // end marker
|
||||
};
|
||||
|
||||
|
@ -236,13 +236,7 @@ TEST_CASE("CBOR")
|
||||
SECTION("-4294967296..-65537")
|
||||
{
|
||||
const std::vector<int64_t> numbers{
|
||||
-65537,
|
||||
-100000,
|
||||
-1000000,
|
||||
-10000000,
|
||||
-100000000,
|
||||
-1000000000,
|
||||
-4294967296,
|
||||
-65537, -100000, -1000000, -10000000, -100000000, -1000000000, -4294967296,
|
||||
};
|
||||
for (const auto i : numbers)
|
||||
{
|
||||
@ -2015,7 +2009,8 @@ TEST_CASE("CBOR roundtrips" * doctest::skip())
|
||||
exclude_packed.insert(TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_duplicated_key.json");
|
||||
exclude_packed.insert(TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_long_strings.json");
|
||||
|
||||
for (const std::string filename : {TEST_DATA_DIRECTORY "/json_nlohmann_tests/all_unicode.json",
|
||||
for (const std::string filename :
|
||||
{ TEST_DATA_DIRECTORY "/json_nlohmann_tests/all_unicode.json",
|
||||
TEST_DATA_DIRECTORY "/json.org/1.json",
|
||||
TEST_DATA_DIRECTORY "/json.org/2.json",
|
||||
TEST_DATA_DIRECTORY "/json.org/3.json",
|
||||
@ -2328,7 +2323,8 @@ TEST_CASE("all CBOR first bytes")
|
||||
|
||||
/// break cannot be the first byte
|
||||
|
||||
0xff};
|
||||
0xff
|
||||
};
|
||||
|
||||
for (auto i = 0; i < 256; ++i)
|
||||
{
|
||||
|
@ -87,16 +87,10 @@ TEST_CASE("lexicographical comparison operators")
|
||||
|
||||
SECTION("types")
|
||||
{
|
||||
std::vector<json::value_t> j_types = {json::value_t::null,
|
||||
json::value_t::boolean,
|
||||
json::value_t::number_integer,
|
||||
json::value_t::number_unsigned,
|
||||
json::value_t::number_float,
|
||||
json::value_t::object,
|
||||
json::value_t::array,
|
||||
json::value_t::string,
|
||||
json::value_t::binary,
|
||||
json::value_t::discarded};
|
||||
std::vector<json::value_t> j_types = {
|
||||
json::value_t::null, json::value_t::boolean, json::value_t::number_integer, json::value_t::number_unsigned, json::value_t::number_float,
|
||||
json::value_t::object, json::value_t::array, json::value_t::string, json::value_t::binary, json::value_t::discarded
|
||||
};
|
||||
|
||||
std::vector<std::vector<bool>> expected_lt = {
|
||||
//0 1 2 3 4 5 6 7 8 9
|
||||
|
@ -140,12 +140,14 @@ TEST_CASE("constructors")
|
||||
SECTION("create an object (implicit)")
|
||||
{
|
||||
// reference object
|
||||
json::object_t const o_reference{{"a", json(1)}, {"b", json(1u)}, {"c", json(2.2)}, {"d", json(false)}, {"e", json("string")}, {"f", json()}};
|
||||
json::object_t const o_reference{ { "a", json(1) }, { "b", json(1u) }, { "c", json(2.2) },
|
||||
{ "d", json(false) }, { "e", json("string") }, { "f", json() } };
|
||||
json const j_reference(o_reference);
|
||||
|
||||
SECTION("std::map<json::string_t, json>")
|
||||
{
|
||||
std::map<json::string_t, json> const o{{"a", json(1)}, {"b", json(1u)}, {"c", json(2.2)}, {"d", json(false)}, {"e", json("string")}, {"f", json()}};
|
||||
std::map<json::string_t, json> const o{ { "a", json(1) }, { "b", json(1u) }, { "c", json(2.2) },
|
||||
{ "d", json(false) }, { "e", json("string") }, { "f", json() } };
|
||||
json const j(o);
|
||||
CHECK(j.type() == json::value_t::object);
|
||||
CHECK(j == j_reference);
|
||||
@ -165,7 +167,8 @@ TEST_CASE("constructors")
|
||||
|
||||
SECTION("std::map<const char*, json>")
|
||||
{
|
||||
std::map<const char*, json> const o{{"a", json(1)}, {"b", json(1u)}, {"c", json(2.2)}, {"d", json(false)}, {"e", json("string")}, {"f", json()}};
|
||||
std::map<const char*, json> const o{ { "a", json(1) }, { "b", json(1u) }, { "c", json(2.2) },
|
||||
{ "d", json(false) }, { "e", json("string") }, { "f", json() } };
|
||||
json const j(o);
|
||||
CHECK(j.type() == json::value_t::object);
|
||||
CHECK(j == j_reference);
|
||||
@ -173,12 +176,8 @@ TEST_CASE("constructors")
|
||||
|
||||
SECTION("std::multimap<json::string_t, json>")
|
||||
{
|
||||
std::multimap<json::string_t, json> const o{{"a", json(1)},
|
||||
{"b", json(1u)},
|
||||
{"c", json(2.2)},
|
||||
{"d", json(false)},
|
||||
{"e", json("string")},
|
||||
{"f", json()}};
|
||||
std::multimap<json::string_t, json> const o{ { "a", json(1) }, { "b", json(1u) }, { "c", json(2.2) },
|
||||
{ "d", json(false) }, { "e", json("string") }, { "f", json() } };
|
||||
json const j(o);
|
||||
CHECK(j.type() == json::value_t::object);
|
||||
CHECK(j == j_reference);
|
||||
@ -186,12 +185,8 @@ TEST_CASE("constructors")
|
||||
|
||||
SECTION("std::unordered_map<json::string_t, json>")
|
||||
{
|
||||
std::unordered_map<json::string_t, json> const o{{"a", json(1)},
|
||||
{"b", json(1u)},
|
||||
{"c", json(2.2)},
|
||||
{"d", json(false)},
|
||||
{"e", json("string")},
|
||||
{"f", json()}};
|
||||
std::unordered_map<json::string_t, json> const o{ { "a", json(1) }, { "b", json(1u) }, { "c", json(2.2) },
|
||||
{ "d", json(false) }, { "e", json("string") }, { "f", json() } };
|
||||
json const j(o);
|
||||
CHECK(j.type() == json::value_t::object);
|
||||
CHECK(j == j_reference);
|
||||
@ -199,12 +194,8 @@ TEST_CASE("constructors")
|
||||
|
||||
SECTION("std::unordered_multimap<json::string_t, json>")
|
||||
{
|
||||
std::unordered_multimap<json::string_t, json> const o{{"a", json(1)},
|
||||
{"b", json(1u)},
|
||||
{"c", json(2.2)},
|
||||
{"d", json(false)},
|
||||
{"e", json("string")},
|
||||
{"f", json()}};
|
||||
std::unordered_multimap<json::string_t, json> const o{ { "a", json(1) }, { "b", json(1u) }, { "c", json(2.2) },
|
||||
{ "d", json(false) }, { "e", json("string") }, { "f", json() } };
|
||||
json const j(o);
|
||||
CHECK(j.type() == json::value_t::object);
|
||||
CHECK(j == j_reference);
|
||||
|
@ -36,8 +36,8 @@ TEST_CASE("value conversion")
|
||||
{
|
||||
SECTION("get an object (explicit)")
|
||||
{
|
||||
const json::object_t o_reference =
|
||||
{{"object", json::object()}, {"array", {1, 2, 3, 4}}, {"number", 42}, {"boolean", false}, {"null", nullptr}, {"string", "Hello world"}};
|
||||
const json::object_t o_reference = { { "object", json::object() }, { "array", { 1, 2, 3, 4 } }, { "number", 42 },
|
||||
{ "boolean", false }, { "null", nullptr }, { "string", "Hello world" } };
|
||||
json j(o_reference);
|
||||
|
||||
SECTION("json::object_t")
|
||||
@ -99,8 +99,8 @@ TEST_CASE("value conversion")
|
||||
|
||||
SECTION("get an object (explicit, get_to)")
|
||||
{
|
||||
const json::object_t o_reference =
|
||||
{{"object", json::object()}, {"array", {1, 2, 3, 4}}, {"number", 42}, {"boolean", false}, {"null", nullptr}, {"string", "Hello world"}};
|
||||
const json::object_t o_reference = { { "object", json::object() }, { "array", { 1, 2, 3, 4 } }, { "number", 42 },
|
||||
{ "boolean", false }, { "null", nullptr }, { "string", "Hello world" } };
|
||||
json j(o_reference);
|
||||
|
||||
SECTION("json::object_t")
|
||||
@ -142,8 +142,8 @@ TEST_CASE("value conversion")
|
||||
#if JSON_USE_IMPLICIT_CONVERSIONS
|
||||
SECTION("get an object (implicit)")
|
||||
{
|
||||
const json::object_t o_reference =
|
||||
{{"object", json::object()}, {"array", {1, 2, 3, 4}}, {"number", 42}, {"boolean", false}, {"null", nullptr}, {"string", "Hello world"}};
|
||||
const json::object_t o_reference = { { "object", json::object() }, { "array", { 1, 2, 3, 4 } }, { "number", 42 },
|
||||
{ "boolean", false }, { "null", nullptr }, { "string", "Hello world" } };
|
||||
json j(o_reference);
|
||||
|
||||
SECTION("json::object_t")
|
||||
|
@ -1089,10 +1089,14 @@ TEST_CASE("deserialization")
|
||||
|
||||
json::sax_parse(s, &exit_after_start_object);
|
||||
CHECK(exit_after_start_object.events.size() == 8);
|
||||
CHECK(
|
||||
exit_after_start_object.events ==
|
||||
std::vector<std::string>(
|
||||
{"start_array()", "number_unsigned(1)", "start_array()", "string(string)", "number_float(43.12)", "end_array()", "null()", "start_object()"}));
|
||||
CHECK(exit_after_start_object.events == std::vector<std::string>({ "start_array()",
|
||||
"number_unsigned(1)",
|
||||
"start_array()",
|
||||
"string(string)",
|
||||
"number_float(43.12)",
|
||||
"end_array()",
|
||||
"null()",
|
||||
"start_object()" }));
|
||||
|
||||
json::sax_parse(s, &exit_after_key);
|
||||
CHECK(exit_after_key.events.size() == 9);
|
||||
@ -1182,8 +1186,9 @@ TEST_CASE_TEMPLATE("deserialization of different character types (ASCII)",
|
||||
TEST_CASE_TEMPLATE("deserialization of different character types (UTF-8)", T, char, unsigned char, std::uint8_t)
|
||||
{
|
||||
// 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), '"'};
|
||||
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), '"'
|
||||
};
|
||||
CHECK(json::parse(v).dump(-1, ' ', true) == "\"\\u2b50\\ufe0f\"");
|
||||
CHECK(json::accept(v));
|
||||
|
||||
|
@ -21,14 +21,8 @@ TEST_CASE_TEMPLATE("element access 2", Json, nlohmann::json, nlohmann::ordered_j
|
||||
{
|
||||
SECTION("object")
|
||||
{
|
||||
Json j = {{"integer", 1},
|
||||
{"unsigned", 1u},
|
||||
{"floating", 42.23},
|
||||
{"null", nullptr},
|
||||
{"string", "hello world"},
|
||||
{"boolean", true},
|
||||
{"object", Json::object()},
|
||||
{"array", {1, 2, 3}}};
|
||||
Json j = { { "integer", 1 }, { "unsigned", 1u }, { "floating", 42.23 }, { "null", nullptr }, { "string", "hello world" },
|
||||
{ "boolean", true }, { "object", Json::object() }, { "array", { 1, 2, 3 } } };
|
||||
const Json j_const = j;
|
||||
|
||||
SECTION("access specified element with bounds checking")
|
||||
@ -1651,22 +1645,10 @@ TEST_CASE_TEMPLATE("element access 2 (throwing tests)", Json, nlohmann::json, nl
|
||||
{
|
||||
SECTION("object")
|
||||
{
|
||||
Json j = {{"integer", 1},
|
||||
{"unsigned", 1u},
|
||||
{"floating", 42.23},
|
||||
{"null", nullptr},
|
||||
{"string", "hello world"},
|
||||
{"boolean", true},
|
||||
{"object", Json::object()},
|
||||
{"array", {1, 2, 3}}};
|
||||
const Json j_const = {{"integer", 1},
|
||||
{"unsigned", 1u},
|
||||
{"floating", 42.23},
|
||||
{"null", nullptr},
|
||||
{"string", "hello world"},
|
||||
{"boolean", true},
|
||||
{"object", Json::object()},
|
||||
{"array", {1, 2, 3}}};
|
||||
Json j = { { "integer", 1 }, { "unsigned", 1u }, { "floating", 42.23 }, { "null", nullptr }, { "string", "hello world" },
|
||||
{ "boolean", true }, { "object", Json::object() }, { "array", { 1, 2, 3 } } };
|
||||
const Json j_const = { { "integer", 1 }, { "unsigned", 1u }, { "floating", 42.23 }, { "null", nullptr }, { "string", "hello world" },
|
||||
{ "boolean", true }, { "object", Json::object() }, { "array", { 1, 2, 3 } } };
|
||||
|
||||
SECTION("access specified element with default value")
|
||||
{
|
||||
|
@ -202,7 +202,8 @@ TEST_CASE("object inspection")
|
||||
|
||||
SECTION("serialization")
|
||||
{
|
||||
json const j{{"object", json::object()}, {"array", {1, 2, 3, 4}}, {"number", 42}, {"boolean", false}, {"null", nullptr}, {"string", "Hello world"}};
|
||||
json const j{ { "object", json::object() }, { "array", { 1, 2, 3, 4 } }, { "number", 42 },
|
||||
{ "boolean", false }, { "null", nullptr }, { "string", "Hello world" } };
|
||||
|
||||
SECTION("no indent / indent=-1")
|
||||
{
|
||||
|
@ -403,7 +403,8 @@ TEST_CASE("JSON pointers")
|
||||
{ "nothing", nullptr },
|
||||
{ "answer", { { "everything", 42 } } },
|
||||
{ "list", { 1, 0, 2 } },
|
||||
{"object", {{"currency", "USD"}, {"value", 42.99}, {"", "empty string"}, {"/", "slash"}, {"~", "tilde"}, {"~1", "tilde1"}}}};
|
||||
{ "object",
|
||||
{ { "currency", "USD" }, { "value", 42.99 }, { "", "empty string" }, { "/", "slash" }, { "~", "tilde" }, { "~1", "tilde1" } } } };
|
||||
|
||||
json j_flatten = { { "/pi", 3.141 },
|
||||
{ "/happy", true },
|
||||
@ -435,7 +436,9 @@ TEST_CASE("JSON pointers")
|
||||
"[json.exception.type_error.315] (/~11) values in object must be primitive",
|
||||
json::type_error&);
|
||||
#else
|
||||
CHECK_THROWS_WITH_AS(json({{"/1", {1, 2, 3}}}).unflatten(), "[json.exception.type_error.315] values in object must be primitive", json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(json({ { "/1", { 1, 2, 3 } } }).unflatten(),
|
||||
"[json.exception.type_error.315] values in object must be primitive",
|
||||
json::type_error&);
|
||||
#endif
|
||||
|
||||
// error for conflicting values
|
||||
@ -503,7 +506,8 @@ TEST_CASE("JSON pointers")
|
||||
{ "nothing", nullptr },
|
||||
{ "answer", { { "everything", 42 } } },
|
||||
{ "list", { 1, 0, 2 } },
|
||||
{"object", {{"currency", "USD"}, {"value", 42.99}, {"", "empty string"}, {"/", "slash"}, {"~", "tilde"}, {"~1", "tilde1"}}}};
|
||||
{ "object",
|
||||
{ { "currency", "USD" }, { "value", 42.99 }, { "", "empty string" }, { "/", "slash" }, { "~", "tilde" }, { "~1", "tilde1" } } } };
|
||||
|
||||
// empty json_pointer returns the root JSON-object
|
||||
auto ptr = ""_json_pointer;
|
||||
@ -562,7 +566,8 @@ TEST_CASE("JSON pointers")
|
||||
{ "nothing", nullptr },
|
||||
{ "answer", { { "everything", 42 } } },
|
||||
{ "list", { 1, 0, 2 } },
|
||||
{"object", {{"currency", "USD"}, {"value", 42.99}, {"", "empty string"}, {"/", "slash"}, {"~", "tilde"}, {"~1", "tilde1"}}}};
|
||||
{ "object",
|
||||
{ { "currency", "USD" }, { "value", 42.99 }, { "", "empty string" }, { "/", "slash" }, { "~", "tilde" }, { "~1", "tilde1" } } } };
|
||||
|
||||
// empty json_pointer returns the root JSON-object
|
||||
auto ptr = ""_json_pointer;
|
||||
|
@ -459,11 +459,7 @@ TEST_CASE("MessagePack")
|
||||
SECTION("-32769..-2147483648")
|
||||
{
|
||||
std::vector<int32_t> const numbers{
|
||||
-32769,
|
||||
-65536,
|
||||
-77777,
|
||||
-1048576,
|
||||
-2147483648LL,
|
||||
-32769, -65536, -77777, -1048576, -2147483648LL,
|
||||
};
|
||||
for (auto i : numbers)
|
||||
{
|
||||
|
@ -1377,8 +1377,8 @@ TEST_CASE("regression tests 1")
|
||||
|
||||
SECTION("issue #838 - incorrect parse error with binary data in keys")
|
||||
{
|
||||
std::array<uint8_t, 28> key1 = {
|
||||
{103, 92, 117, 48, 48, 48, 55, 92, 114, 215, 126, 214, 95, 92, 34, 174, 40, 71, 38, 174, 40, 71, 38, 223, 134, 247, 127, 0}};
|
||||
std::array<uint8_t, 28> key1 = { { 103, 92, 117, 48, 48, 48, 55, 92, 114, 215, 126, 214, 95, 92,
|
||||
34, 174, 40, 71, 38, 174, 40, 71, 38, 223, 134, 247, 127, 0 } };
|
||||
std::string const key1_str(reinterpret_cast<char*>(key1.data()));
|
||||
json const j = key1_str;
|
||||
CHECK_THROWS_WITH_AS(j.dump(), "[json.exception.type_error.316] invalid UTF-8 byte at index 10: 0x7E", json::type_error&);
|
||||
|
@ -504,11 +504,12 @@ TEST_CASE("regression tests 2")
|
||||
SECTION("test case in issue #1445")
|
||||
{
|
||||
nlohmann::json dump_test;
|
||||
const std::array<int, 108> data = {{109, 108, 103, 125, -122, -53, 115, 18, 3, 0, 102, 19, 1, 15, -110, 13, -3, -1, -81, 32, 2, 0,
|
||||
0, 0, 0, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -80, 2, 0, 0,
|
||||
96, -118, 46, -116, 46, 109, -84, -87, 108, 14, 109, -24, -83, 13, -18, -51, -83, -52, -115, 14, 6, 32,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 64, 3, 0, 0, 0, 35, -74, -73, 55, 57, -128,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 33, 0, 0, 0, -96, -54, -28, -26}};
|
||||
const std::array<int, 108> data = {
|
||||
{ 109, 108, 103, 125, -122, -53, 115, 18, 3, 0, 102, 19, 1, 15, -110, 13, -3, -1, -81, 32, 2, 0, 0, 0, 0, 0, 0,
|
||||
0, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -80, 2, 0, 0, 96, -118, 46, -116, 46, 109, -84, -87, 108, 14,
|
||||
109, -24, -83, 13, -18, -51, -83, -52, -115, 14, 6, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 64, 3, 0, 0,
|
||||
0, 35, -74, -73, 55, 57, -128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 33, 0, 0, 0, -96, -54, -28, -26 }
|
||||
};
|
||||
std::string s;
|
||||
for (const int i : data)
|
||||
{
|
||||
@ -605,8 +606,8 @@ TEST_CASE("regression tests 2")
|
||||
|
||||
SECTION("issue #2067 - cannot serialize binary data to text JSON")
|
||||
{
|
||||
const std::array<unsigned char, 23> data = {
|
||||
{0x81, 0xA4, 0x64, 0x61, 0x74, 0x61, 0xC4, 0x0F, 0x33, 0x30, 0x30, 0x32, 0x33, 0x34, 0x30, 0x31, 0x30, 0x37, 0x30, 0x35, 0x30, 0x31, 0x30}};
|
||||
const std::array<unsigned char, 23> data = { { 0x81, 0xA4, 0x64, 0x61, 0x74, 0x61, 0xC4, 0x0F, 0x33, 0x30, 0x30, 0x32,
|
||||
0x33, 0x34, 0x30, 0x31, 0x30, 0x37, 0x30, 0x35, 0x30, 0x31, 0x30 } };
|
||||
const json j = json::from_msgpack(data.data(), data.size());
|
||||
CHECK_NOTHROW(j.dump(4, // Indent
|
||||
' ', // Indent char
|
||||
|
@ -964,7 +964,8 @@ TEST_CASE("nst's JSONTestSuite (2)")
|
||||
|
||||
SECTION("n")
|
||||
{
|
||||
for (const auto* filename : {TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_array_1_true_without_comma.json",
|
||||
for (const auto* filename :
|
||||
{ TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_array_1_true_without_comma.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_array_a_invalid_utf8.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_array_colon_instead_of_comma.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_array_comma_after_close.json",
|
||||
|
@ -2144,7 +2144,9 @@ TEST_CASE("Universal Binary JSON Specification Examples 1")
|
||||
|
||||
SECTION("Numeric Types")
|
||||
{
|
||||
json const j = {{"int8", 16}, {"uint8", 255}, {"int16", 32767}, {"int32", 2147483647}, {"int64", 9223372036854775807}, {"float64", 113243.7863123}};
|
||||
json const j = {
|
||||
{ "int8", 16 }, { "uint8", 255 }, { "int16", 32767 }, { "int32", 2147483647 }, { "int64", 9223372036854775807 }, { "float64", 113243.7863123 }
|
||||
};
|
||||
std::vector<uint8_t> const v = { '{', 'i', 7, 'f', 'l', 'o', 'a', 't', '6', '4', 'D', 0x40, 0xfb, 0xa5, 0xbc, 0x94, 0xbc, 0x34, 0xcf,
|
||||
'i', 5, 'i', 'n', 't', '1', '6', 'I', 0x7f, 0xff, 'i', 5, 'i', 'n', 't', '3', '2', 'l', 0x7f,
|
||||
0xff, 0xff, 0xff, 'i', 5, 'i', 'n', 't', '6', '4', 'L', 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
|
||||
|
@ -199,7 +199,9 @@ template<typename BasicJsonType>
|
||||
static void from_json(const BasicJsonType& j, country& c)
|
||||
{
|
||||
const auto str = j.template get<std::string>();
|
||||
const std::map<std::string, country> m = {{"中华人民共和国", country::china}, {"France", country::france}, {"Российская Федерация", country::russia}};
|
||||
const std::map<std::string, country> m = { { "中华人民共和国", country::china },
|
||||
{ "France", country::france },
|
||||
{ "Российская Федерация", country::russia } };
|
||||
|
||||
const auto it = m.find(str);
|
||||
// TODO(nlohmann) test exceptions
|
||||
|
Loading…
Reference in New Issue
Block a user