🎨 use Clang-Format

This commit is contained in:
Niels Lohmann 2023-11-29 21:46:01 +01:00
parent 286f0c7647
commit af3f87e84e
No known key found for this signature in database
GPG Key ID: 7F3CEA63AE251B69
77 changed files with 4290 additions and 4393 deletions

View File

@ -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

View File

@ -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

View File

@ -252,7 +252,7 @@ template<typename BasicJsonType, typename T, std::size_t... Idx>
std::array<T, sizeof...(Idx)>
from_json_inplace_array_impl(BasicJsonType&& j, identity_tag<std::array<T, sizeof...(Idx)>> /*unused*/, index_sequence<Idx...> /*unused*/)
{
return {{std::forward<BasicJsonType>(j).at(Idx).template get<T>()...}};
return { { std::forward<BasicJsonType>(j).at(Idx).template get<T>()... } };
}
template<typename BasicJsonType, typename T, std::size_t N>
@ -353,7 +353,7 @@ std::tuple<Args...> from_json_tuple_impl_base(BasicJsonType&& j, index_sequence<
template<typename BasicJsonType, class A1, class A2>
std::pair<A1, A2> from_json_tuple_impl(BasicJsonType&& j, identity_tag<std::pair<A1, A2>> /*unused*/, priority_tag<0> /*unused*/)
{
return {std::forward<BasicJsonType>(j).at(0).template get<A1>(), std::forward<BasicJsonType>(j).at(1).template get<A2>()};
return { std::forward<BasicJsonType>(j).at(0).template get<A1>(), std::forward<BasicJsonType>(j).at(1).template get<A2>() };
}
template<typename BasicJsonType, typename A1, typename A2>

View File

@ -75,7 +75,7 @@ struct diyfp // f * 2^e
JSON_ASSERT(x.e == y.e);
JSON_ASSERT(x.f >= y.f);
return {x.f - y.f, x.e};
return { x.f - y.f, x.e };
}
/*!
@ -136,11 +136,11 @@ struct diyfp // f * 2^e
// Effectively we only need to add the highest bit in p_lo to p_hi (and
// Q_hi + 1 does not overflow).
Q += std::uint64_t{1} << (64u - 32u - 1u); // round, ties up
Q += std::uint64_t{ 1 } << (64u - 32u - 1u); // round, ties up
const std::uint64_t h = p3 + p2_hi + p1_hi + (Q >> 32u);
return {h, x.e + y.e + 64};
return { h, x.e + y.e + 64 };
}
/*!
@ -171,7 +171,7 @@ struct diyfp // f * 2^e
JSON_ASSERT(delta >= 0);
JSON_ASSERT(((x.f << delta) >> delta) == x.f);
return {x.f << delta, target_exponent};
return { x.f << delta, target_exponent };
}
};
@ -206,7 +206,7 @@ boundaries compute_boundaries(FloatType value)
constexpr int kPrecision = std::numeric_limits<FloatType>::digits; // = p (includes the hidden bit)
constexpr int kBias = std::numeric_limits<FloatType>::max_exponent - 1 + (kPrecision - 1);
constexpr int kMinExp = 1 - kBias;
constexpr std::uint64_t kHiddenBit = std::uint64_t{1} << (kPrecision - 1); // = 2^(p-1)
constexpr std::uint64_t kHiddenBit = std::uint64_t{ 1 } << (kPrecision - 1); // = 2^(p-1)
using bits_type = typename std::conditional<kPrecision == 24, std::uint32_t, std::uint64_t>::type;
@ -249,7 +249,7 @@ boundaries compute_boundaries(FloatType value)
// Determine w- = m- such that e_(w-) = e_(w+).
const diyfp w_minus = diyfp::normalize_to(m_minus, w_plus.e);
return {diyfp::normalize(v), w_minus, w_plus};
return { diyfp::normalize(v), w_minus, w_plus };
}
// Given normalized diyfp w, Grisu needs to find a (normalized) cached
@ -379,28 +379,28 @@ inline cached_power get_cached_power_for_binary_exponent(int e)
constexpr int kCachedPowersMinDecExp = -300;
constexpr int kCachedPowersDecStep = 8;
static constexpr std::array<cached_power, 79> kCachedPowers = {{
{0xAB70FE17C79AC6CA, -1060, -300}, {0xFF77B1FCBEBCDC4F, -1034, -292}, {0xBE5691EF416BD60C, -1007, -284}, {0x8DD01FAD907FFC3C, -980, -276},
{0xD3515C2831559A83, -954, -268}, {0x9D71AC8FADA6C9B5, -927, -260}, {0xEA9C227723EE8BCB, -901, -252}, {0xAECC49914078536D, -874, -244},
{0x823C12795DB6CE57, -847, -236}, {0xC21094364DFB5637, -821, -228}, {0x9096EA6F3848984F, -794, -220}, {0xD77485CB25823AC7, -768, -212},
{0xA086CFCD97BF97F4, -741, -204}, {0xEF340A98172AACE5, -715, -196}, {0xB23867FB2A35B28E, -688, -188}, {0x84C8D4DFD2C63F3B, -661, -180},
{0xC5DD44271AD3CDBA, -635, -172}, {0x936B9FCEBB25C996, -608, -164}, {0xDBAC6C247D62A584, -582, -156}, {0xA3AB66580D5FDAF6, -555, -148},
{0xF3E2F893DEC3F126, -529, -140}, {0xB5B5ADA8AAFF80B8, -502, -132}, {0x87625F056C7C4A8B, -475, -124}, {0xC9BCFF6034C13053, -449, -116},
{0x964E858C91BA2655, -422, -108}, {0xDFF9772470297EBD, -396, -100}, {0xA6DFBD9FB8E5B88F, -369, -92}, {0xF8A95FCF88747D94, -343, -84},
{0xB94470938FA89BCF, -316, -76}, {0x8A08F0F8BF0F156B, -289, -68}, {0xCDB02555653131B6, -263, -60}, {0x993FE2C6D07B7FAC, -236, -52},
{0xE45C10C42A2B3B06, -210, -44}, {0xAA242499697392D3, -183, -36}, {0xFD87B5F28300CA0E, -157, -28}, {0xBCE5086492111AEB, -130, -20},
{0x8CBCCC096F5088CC, -103, -12}, {0xD1B71758E219652C, -77, -4}, {0x9C40000000000000, -50, 4}, {0xE8D4A51000000000, -24, 12},
{0xAD78EBC5AC620000, 3, 20}, {0x813F3978F8940984, 30, 28}, {0xC097CE7BC90715B3, 56, 36}, {0x8F7E32CE7BEA5C70, 83, 44},
{0xD5D238A4ABE98068, 109, 52}, {0x9F4F2726179A2245, 136, 60}, {0xED63A231D4C4FB27, 162, 68}, {0xB0DE65388CC8ADA8, 189, 76},
{0x83C7088E1AAB65DB, 216, 84}, {0xC45D1DF942711D9A, 242, 92}, {0x924D692CA61BE758, 269, 100}, {0xDA01EE641A708DEA, 295, 108},
{0xA26DA3999AEF774A, 322, 116}, {0xF209787BB47D6B85, 348, 124}, {0xB454E4A179DD1877, 375, 132}, {0x865B86925B9BC5C2, 402, 140},
{0xC83553C5C8965D3D, 428, 148}, {0x952AB45CFA97A0B3, 455, 156}, {0xDE469FBD99A05FE3, 481, 164}, {0xA59BC234DB398C25, 508, 172},
{0xF6C69A72A3989F5C, 534, 180}, {0xB7DCBF5354E9BECE, 561, 188}, {0x88FCF317F22241E2, 588, 196}, {0xCC20CE9BD35C78A5, 614, 204},
{0x98165AF37B2153DF, 641, 212}, {0xE2A0B5DC971F303A, 667, 220}, {0xA8D9D1535CE3B396, 694, 228}, {0xFB9B7CD9A4A7443C, 720, 236},
{0xBB764C4CA7A44410, 747, 244}, {0x8BAB8EEFB6409C1A, 774, 252}, {0xD01FEF10A657842C, 800, 260}, {0x9B10A4E5E9913129, 827, 268},
{0xE7109BFBA19C0C9D, 853, 276}, {0xAC2820D9623BF429, 880, 284}, {0x80444B5E7AA7CF85, 907, 292}, {0xBF21E44003ACDD2D, 933, 300},
{0x8E679C2F5E44FF8F, 960, 308}, {0xD433179D9C8CB841, 986, 316}, {0x9E19DB92B4E31BA9, 1013, 324},
}};
static constexpr std::array<cached_power, 79> kCachedPowers = { {
{ 0xAB70FE17C79AC6CA, -1060, -300 }, { 0xFF77B1FCBEBCDC4F, -1034, -292 }, { 0xBE5691EF416BD60C, -1007, -284 }, { 0x8DD01FAD907FFC3C, -980, -276 },
{ 0xD3515C2831559A83, -954, -268 }, { 0x9D71AC8FADA6C9B5, -927, -260 }, { 0xEA9C227723EE8BCB, -901, -252 }, { 0xAECC49914078536D, -874, -244 },
{ 0x823C12795DB6CE57, -847, -236 }, { 0xC21094364DFB5637, -821, -228 }, { 0x9096EA6F3848984F, -794, -220 }, { 0xD77485CB25823AC7, -768, -212 },
{ 0xA086CFCD97BF97F4, -741, -204 }, { 0xEF340A98172AACE5, -715, -196 }, { 0xB23867FB2A35B28E, -688, -188 }, { 0x84C8D4DFD2C63F3B, -661, -180 },
{ 0xC5DD44271AD3CDBA, -635, -172 }, { 0x936B9FCEBB25C996, -608, -164 }, { 0xDBAC6C247D62A584, -582, -156 }, { 0xA3AB66580D5FDAF6, -555, -148 },
{ 0xF3E2F893DEC3F126, -529, -140 }, { 0xB5B5ADA8AAFF80B8, -502, -132 }, { 0x87625F056C7C4A8B, -475, -124 }, { 0xC9BCFF6034C13053, -449, -116 },
{ 0x964E858C91BA2655, -422, -108 }, { 0xDFF9772470297EBD, -396, -100 }, { 0xA6DFBD9FB8E5B88F, -369, -92 }, { 0xF8A95FCF88747D94, -343, -84 },
{ 0xB94470938FA89BCF, -316, -76 }, { 0x8A08F0F8BF0F156B, -289, -68 }, { 0xCDB02555653131B6, -263, -60 }, { 0x993FE2C6D07B7FAC, -236, -52 },
{ 0xE45C10C42A2B3B06, -210, -44 }, { 0xAA242499697392D3, -183, -36 }, { 0xFD87B5F28300CA0E, -157, -28 }, { 0xBCE5086492111AEB, -130, -20 },
{ 0x8CBCCC096F5088CC, -103, -12 }, { 0xD1B71758E219652C, -77, -4 }, { 0x9C40000000000000, -50, 4 }, { 0xE8D4A51000000000, -24, 12 },
{ 0xAD78EBC5AC620000, 3, 20 }, { 0x813F3978F8940984, 30, 28 }, { 0xC097CE7BC90715B3, 56, 36 }, { 0x8F7E32CE7BEA5C70, 83, 44 },
{ 0xD5D238A4ABE98068, 109, 52 }, { 0x9F4F2726179A2245, 136, 60 }, { 0xED63A231D4C4FB27, 162, 68 }, { 0xB0DE65388CC8ADA8, 189, 76 },
{ 0x83C7088E1AAB65DB, 216, 84 }, { 0xC45D1DF942711D9A, 242, 92 }, { 0x924D692CA61BE758, 269, 100 }, { 0xDA01EE641A708DEA, 295, 108 },
{ 0xA26DA3999AEF774A, 322, 116 }, { 0xF209787BB47D6B85, 348, 124 }, { 0xB454E4A179DD1877, 375, 132 }, { 0x865B86925B9BC5C2, 402, 140 },
{ 0xC83553C5C8965D3D, 428, 148 }, { 0x952AB45CFA97A0B3, 455, 156 }, { 0xDE469FBD99A05FE3, 481, 164 }, { 0xA59BC234DB398C25, 508, 172 },
{ 0xF6C69A72A3989F5C, 534, 180 }, { 0xB7DCBF5354E9BECE, 561, 188 }, { 0x88FCF317F22241E2, 588, 196 }, { 0xCC20CE9BD35C78A5, 614, 204 },
{ 0x98165AF37B2153DF, 641, 212 }, { 0xE2A0B5DC971F303A, 667, 220 }, { 0xA8D9D1535CE3B396, 694, 228 }, { 0xFB9B7CD9A4A7443C, 720, 236 },
{ 0xBB764C4CA7A44410, 747, 244 }, { 0x8BAB8EEFB6409C1A, 774, 252 }, { 0xD01FEF10A657842C, 800, 260 }, { 0x9B10A4E5E9913129, 827, 268 },
{ 0xE7109BFBA19C0C9D, 853, 276 }, { 0xAC2820D9623BF429, 880, 284 }, { 0x80444B5E7AA7CF85, 907, 292 }, { 0xBF21E44003ACDD2D, 933, 300 },
{ 0x8E679C2F5E44FF8F, 960, 308 }, { 0xD433179D9C8CB841, 986, 316 }, { 0x9E19DB92B4E31BA9, 1013, 324 },
} };
// This computation gives exactly the same results for k as
// k = ceil((kAlpha - e - 1) * 0.30102999566398114)
@ -548,7 +548,7 @@ inline void grisu2_digit_gen(char* buffer, int& length, int& decimal_exponent, d
// = ((p1 ) * 2^-e + (p2 )) * 2^e
// = p1 + p2 * 2^e
const diyfp one(std::uint64_t{1} << -M_plus.e, M_plus.e);
const diyfp one(std::uint64_t{ 1 } << -M_plus.e, M_plus.e);
auto p1 = static_cast<std::uint32_t>(M_plus.f >> -one.e); // p1 = f div 2^-e (Since -e >= 32, p1 fits into a 32-bit int.)
std::uint64_t p2 = M_plus.f & (one.f - 1); // p2 = f mod 2^-e
@ -613,7 +613,7 @@ inline void grisu2_digit_gen(char* buffer, int& length, int& decimal_exponent, d
// Note:
// Since rest and delta share the same exponent e, it suffices to
// compare the significands.
const std::uint64_t rest = (std::uint64_t{p1} << -one.e) + p2;
const std::uint64_t rest = (std::uint64_t{ p1 } << -one.e) + p2;
if (rest <= delta)
{
// V = buffer * 10^n, with M- <= V <= M+.
@ -629,7 +629,7 @@ inline void grisu2_digit_gen(char* buffer, int& length, int& decimal_exponent, d
//
// 10^n = (10^n * 2^-e) * 2^e = ulp * 2^e
//
const std::uint64_t ten_n = std::uint64_t{pow10} << -one.e;
const std::uint64_t ten_n = std::uint64_t{ pow10 } << -one.e;
grisu2_round(buffer, length, dist, delta, rest, ten_n);
return;

View File

@ -392,20 +392,20 @@ template<typename BasicJsonType,
enable_if_t<std::is_constructible<BasicJsonType, T1>::value && std::is_constructible<BasicJsonType, T2>::value, int> = 0>
inline void to_json(BasicJsonType& j, const std::pair<T1, T2>& p)
{
j = {p.first, p.second};
j = { p.first, p.second };
}
// for https://github.com/nlohmann/json/pull/1134
template<typename BasicJsonType, typename T, enable_if_t<std::is_same<T, iteration_proxy_value<typename BasicJsonType::iterator>>::value, int> = 0>
inline void to_json(BasicJsonType& j, const T& b)
{
j = {{b.key(), b.value()}};
j = { { b.key(), b.value() } };
}
template<typename BasicJsonType, typename Tuple, std::size_t... Idx>
inline void to_json_tuple_impl(BasicJsonType& j, const Tuple& t, index_sequence<Idx...> /*unused*/)
{
j = {std::get<Idx>(t)...};
j = { std::get<Idx>(t)... };
}
template<typename BasicJsonType, typename T, enable_if_t<is_constructible_tuple<BasicJsonType, T>::value, int> = 0>

View File

@ -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_)
{
@ -150,7 +150,7 @@ class parse_error : public exception
static parse_error create(int id_, const position_t& pos, const std::string& what_arg, BasicJsonContext context)
{
const std::string w = concat(exception::name("parse_error", id_), "parse error", position_string(pos), ": ", exception::diagnostics(context), what_arg);
return {id_, pos.chars_read_total, w.c_str()};
return { id_, pos.chars_read_total, w.c_str() };
}
template<typename BasicJsonContext, enable_if_t<is_basic_json_context<BasicJsonContext>::value, int> = 0>
@ -162,7 +162,7 @@ class parse_error : public exception
": ",
exception::diagnostics(context),
what_arg);
return {id_, byte_, w.c_str()};
return { id_, byte_, w.c_str() };
}
/*!
@ -197,7 +197,7 @@ class invalid_iterator : public exception
static invalid_iterator create(int id_, const std::string& what_arg, BasicJsonContext context)
{
const std::string w = concat(exception::name("invalid_iterator", id_), exception::diagnostics(context), what_arg);
return {id_, w.c_str()};
return { id_, w.c_str() };
}
private:
@ -216,7 +216,7 @@ class type_error : public exception
static type_error create(int id_, const std::string& what_arg, BasicJsonContext context)
{
const std::string w = concat(exception::name("type_error", id_), exception::diagnostics(context), what_arg);
return {id_, w.c_str()};
return { id_, w.c_str() };
}
private:
@ -235,7 +235,7 @@ class out_of_range : public exception
static out_of_range create(int id_, const std::string& what_arg, BasicJsonContext context)
{
const std::string w = concat(exception::name("out_of_range", id_), exception::diagnostics(context), what_arg);
return {id_, w.c_str()};
return { id_, w.c_str() };
}
private:
@ -254,7 +254,7 @@ class other_error : public exception
static other_error create(int id_, const std::string& what_arg, BasicJsonContext context)
{
const std::string w = concat(exception::name("other_error", id_), exception::diagnostics(context), what_arg);
return {id_, w.c_str()};
return { id_, w.c_str() };
}
private:

View File

@ -340,12 +340,12 @@ class binary_reader
default: // anything else not supported (yet)
{
std::array<char, 3> cr{{}};
static_cast<void>((std::snprintf)(cr.data(),
std::array<char, 3> cr{ {} };
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)
const std::string cr_str{cr.data()};
static_cast<unsigned char>(element_type)));
const std::string cr_str{ cr.data() };
return sax->parse_error(element_type_parse_position,
cr_str,
parse_error::create(114, element_type_parse_position, concat("Unsupported BSON record type 0x", cr_str), nullptr));
@ -2970,10 +2970,10 @@ class binary_reader
*/
std::string get_token_string() const
{
std::array<char, 3> cr{{}};
std::array<char, 3> cr{ {} };
static_cast<void>(
(std::snprintf)(cr.data(), cr.size(), "%.2hhX", static_cast<unsigned char>(current))); // NOLINT(cppcoreguidelines-pro-type-vararg,hicpp-vararg)
return std::string{cr.data()};
return std::string{ cr.data() };
}
/*!
@ -3041,17 +3041,17 @@ class binary_reader
#define JSON_BINARY_READER_MAKE_BJD_OPTIMIZED_TYPE_MARKERS_ make_array<char_int_type>('F', 'H', 'N', 'S', 'T', 'Z', '[', '{')
#define JSON_BINARY_READER_MAKE_BJD_TYPES_MAP_ \
make_array<bjd_type>(bjd_type{'C', "char"}, \
bjd_type{'D', "double"}, \
bjd_type{'I', "int16"}, \
bjd_type{'L', "int64"}, \
bjd_type{'M', "uint64"}, \
bjd_type{'U', "uint8"}, \
bjd_type{'d', "single"}, \
bjd_type{'i', "int8"}, \
bjd_type{'l', "int32"}, \
bjd_type{'m', "uint32"}, \
bjd_type{'u', "uint16"})
make_array<bjd_type>(bjd_type{ 'C', "char" }, \
bjd_type{ 'D', "double" }, \
bjd_type{ 'I', "int16" }, \
bjd_type{ 'L', "int64" }, \
bjd_type{ 'M', "uint64" }, \
bjd_type{ 'U', "uint8" }, \
bjd_type{ 'd', "single" }, \
bjd_type{ 'i', "int8" }, \
bjd_type{ 'l', "int32" }, \
bjd_type{ 'm', "uint32" }, \
bjd_type{ 'u', "uint16" })
JSON_PRIVATE_UNLESS_TESTED :
// lookup tables

View File

@ -338,7 +338,7 @@ class wide_string_input_adapter
}
/// a buffer for UTF-8 bytes
std::array<std::char_traits<char>::int_type, 4> utf8_bytes = {{0, 0, 0, 0}};
std::array<std::char_traits<char>::int_type, 4> utf8_bytes = { { 0, 0, 0, 0 } };
/// index to the utf8_codes array for the next valid byte
std::size_t utf8_bytes_index = 0;

View File

@ -568,7 +568,7 @@ class json_sax_dom_callback_parser
// container
if (!keep_stack.back())
{
return {false, nullptr};
return { false, nullptr };
}
// create value
@ -580,20 +580,20 @@ class json_sax_dom_callback_parser
// do not handle this value if we just learnt it shall be discarded
if (!keep)
{
return {false, nullptr};
return { false, nullptr };
}
if (ref_stack.empty())
{
root = std::move(value);
return {true, &root};
return { true, &root };
}
// skip this value if we already decided to skip the parent
// (https://github.com/nlohmann/json/issues/971#issuecomment-413678360)
if (!ref_stack.back())
{
return {false, nullptr};
return { false, nullptr };
}
// we now only expect arrays and objects
@ -603,7 +603,7 @@ class json_sax_dom_callback_parser
if (ref_stack.back()->is_array())
{
ref_stack.back()->m_data.m_value.array->emplace_back(std::move(value));
return {true, &(ref_stack.back()->m_data.m_value.array->back())};
return { true, &(ref_stack.back()->m_data.m_value.array->back()) };
}
// object
@ -615,12 +615,12 @@ class json_sax_dom_callback_parser
if (!store_element)
{
return {false, nullptr};
return { false, nullptr };
}
JSON_ASSERT(object_element);
*object_element = std::move(value);
return {true, object_element};
return { true, object_element };
}
/// the parsed JSON value

View File

@ -173,7 +173,7 @@ class lexer : public lexer_base<BasicJsonType>
JSON_ASSERT(current == 'u');
int codepoint = 0;
const auto factors = {12u, 8u, 4u, 0u};
const auto factors = { 12u, 8u, 4u, 0u };
for (const auto factor : factors)
{
get();
@ -745,7 +745,7 @@ class lexer : public lexer_base<BasicJsonType>
case 0xDE:
case 0xDF:
{
if (JSON_HEDLEY_UNLIKELY(!next_byte_in_range({0x80, 0xBF})))
if (JSON_HEDLEY_UNLIKELY(!next_byte_in_range({ 0x80, 0xBF })))
{
return token_type::parse_error;
}
@ -755,7 +755,7 @@ class lexer : public lexer_base<BasicJsonType>
// U+0800..U+0FFF: bytes E0 A0..BF 80..BF
case 0xE0:
{
if (JSON_HEDLEY_UNLIKELY(!(next_byte_in_range({0xA0, 0xBF, 0x80, 0xBF}))))
if (JSON_HEDLEY_UNLIKELY(!(next_byte_in_range({ 0xA0, 0xBF, 0x80, 0xBF }))))
{
return token_type::parse_error;
}
@ -779,7 +779,7 @@ class lexer : public lexer_base<BasicJsonType>
case 0xEE:
case 0xEF:
{
if (JSON_HEDLEY_UNLIKELY(!(next_byte_in_range({0x80, 0xBF, 0x80, 0xBF}))))
if (JSON_HEDLEY_UNLIKELY(!(next_byte_in_range({ 0x80, 0xBF, 0x80, 0xBF }))))
{
return token_type::parse_error;
}
@ -789,7 +789,7 @@ class lexer : public lexer_base<BasicJsonType>
// U+D000..U+D7FF: bytes ED 80..9F 80..BF
case 0xED:
{
if (JSON_HEDLEY_UNLIKELY(!(next_byte_in_range({0x80, 0x9F, 0x80, 0xBF}))))
if (JSON_HEDLEY_UNLIKELY(!(next_byte_in_range({ 0x80, 0x9F, 0x80, 0xBF }))))
{
return token_type::parse_error;
}
@ -799,7 +799,7 @@ class lexer : public lexer_base<BasicJsonType>
// U+10000..U+3FFFF F0 90..BF 80..BF 80..BF
case 0xF0:
{
if (JSON_HEDLEY_UNLIKELY(!(next_byte_in_range({0x90, 0xBF, 0x80, 0xBF, 0x80, 0xBF}))))
if (JSON_HEDLEY_UNLIKELY(!(next_byte_in_range({ 0x90, 0xBF, 0x80, 0xBF, 0x80, 0xBF }))))
{
return token_type::parse_error;
}
@ -811,7 +811,7 @@ class lexer : public lexer_base<BasicJsonType>
case 0xF2:
case 0xF3:
{
if (JSON_HEDLEY_UNLIKELY(!(next_byte_in_range({0x80, 0xBF, 0x80, 0xBF, 0x80, 0xBF}))))
if (JSON_HEDLEY_UNLIKELY(!(next_byte_in_range({ 0x80, 0xBF, 0x80, 0xBF, 0x80, 0xBF }))))
{
return token_type::parse_error;
}
@ -821,7 +821,7 @@ class lexer : public lexer_base<BasicJsonType>
// U+100000..U+10FFFF F4 80..8F 80..BF 80..BF
case 0xF4:
{
if (JSON_HEDLEY_UNLIKELY(!(next_byte_in_range({0x80, 0x8F, 0x80, 0xBF, 0x80, 0xBF}))))
if (JSON_HEDLEY_UNLIKELY(!(next_byte_in_range({ 0x80, 0x8F, 0x80, 0xBF, 0x80, 0xBF }))))
{
return token_type::parse_error;
}
@ -1453,9 +1453,9 @@ scan_number_done:
if (static_cast<unsigned char>(c) <= '\x1F')
{
// 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)
std::array<char, 9> cs{ {} };
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,22 +1549,24 @@ 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':
{
std::array<char_type, 5> false_literal = {{static_cast<char_type>('f'),
std::array<char_type, 5> false_literal = { { static_cast<char_type>('f'),
static_cast<char_type>('a'),
static_cast<char_type>('l'),
static_cast<char_type>('s'),
static_cast<char_type>('e')}};
static_cast<char_type>('e') } };
return scan_literal(false_literal.data(), false_literal.size(), token_type::literal_false);
}
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);
}

View File

@ -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);

View File

@ -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()))
{
@ -250,7 +251,7 @@ class json_pointer
}
json_pointer result = *this;
result.reference_tokens = {reference_tokens[0]};
result.reference_tokens = { reference_tokens[0] };
return result;
}

View File

@ -167,7 +167,7 @@ constexpr T static_const<T>::value;
template<typename T, typename... Args>
inline constexpr std::array<T, sizeof...(Args)> make_array(Args&&... args)
{
return std::array<T, sizeof...(Args)>{{static_cast<T>(std::forward<Args>(args))...}};
return std::array<T, sizeof...(Args)>{ { static_cast<T>(std::forward<Args>(args))... } };
}
} // namespace detail

View File

@ -789,7 +789,7 @@ class binary_writer
return ubjson_prefix(v, use_bjdata) == first_prefix;
});
std::vector<CharType> bjdx = {'[', '{', 'S', 'H', 'T', 'F', 'N', 'Z'}; // excluded markers in bjdata optimized type
std::vector<CharType> bjdx = { '[', '{', 'S', 'H', 'T', 'F', 'N', 'Z' }; // excluded markers in bjdata optimized type
if (same_prefix && !(use_bjdata && std::find(bjdx.begin(), bjdx.end(), first_prefix) != bjdx.end()))
{
@ -887,7 +887,7 @@ class binary_writer
return ubjson_prefix(v, use_bjdata) == first_prefix;
});
std::vector<CharType> bjdx = {'[', '{', 'S', 'H', 'T', 'F', 'N', 'Z'}; // excluded markers in bjdata optimized type
std::vector<CharType> bjdx = { '[', '{', 'S', 'H', 'T', 'F', 'N', 'Z' }; // excluded markers in bjdata optimized type
if (same_prefix && !(use_bjdata && std::find(bjdx.begin(), bjdx.end(), first_prefix) != bjdx.end()))
{
@ -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)));

View File

@ -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;
@ -706,18 +705,21 @@ class serializer
int> = 0>
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'}},
}};
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' } },
} };
// special case for "0"
if (x == 0)
@ -887,7 +889,7 @@ class serializer
*/
static std::uint8_t decode(std::uint8_t& state, std::uint32_t& codep, const std::uint8_t byte) noexcept
{
static const std::array<std::uint8_t, 400> utf8d = {{
static const std::array<std::uint8_t, 400> utf8d = { {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, // 00..1F
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
@ -916,7 +918,7 @@ class serializer
1, // s5..s6
1, 3, 1, 1, 1, 1, 1, 3, 1, 3, 1, 1, 1, 1, 1, 1, 1, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1 // s7..s8
}};
} };
JSON_ASSERT(byte < utf8d.size());
const std::uint8_t type = utf8d[byte];
@ -960,7 +962,7 @@ class serializer
output_adapter_t<char> o = nullptr;
/// a (hopefully) large enough character buffer
std::array<char, 64> number_buffer{{}};
std::array<char, 64> number_buffer{ {} };
/// the locale
const std::lconv* loc = nullptr;
@ -970,7 +972,7 @@ class serializer
const char decimal_point = '\0';
/// string buffer
std::array<char, 512> string_buffer{{}};
std::array<char, 512> string_buffer{ {} };
/// the indentation character
const char indent_char;

View File

@ -48,8 +48,8 @@ inline void replace_substring(StringType& s, const StringType& f, const StringTy
template<typename StringType>
inline StringType escape(StringType s)
{
replace_substring(s, StringType{"~"}, StringType{"~0"});
replace_substring(s, StringType{"/"}, StringType{"~1"});
replace_substring(s, StringType{ "~" }, StringType{ "~0" });
replace_substring(s, StringType{ "/" }, StringType{ "~1" });
return s;
}
@ -63,8 +63,8 @@ inline StringType escape(StringType s)
template<typename StringType>
static void unescape(StringType& s)
{
replace_substring(s, StringType{"~1"}, StringType{"/"});
replace_substring(s, StringType{"~0"}, StringType{"~"});
replace_substring(s, StringType{ "~1" }, StringType{ "/" });
replace_substring(s, StringType{ "~0" }, StringType{ "~" });
}
} // namespace detail

View File

@ -83,7 +83,7 @@ inline std::partial_ordering operator<=>(const value_t lhs, const value_t rhs) n
inline bool operator<(const value_t lhs, const value_t rhs) noexcept
#endif
{
static constexpr std::array<std::uint8_t, 9> order = {{
static constexpr std::array<std::uint8_t, 9> order = { {
0 /* null */,
3 /* object */,
4 /* array */,
@ -93,7 +93,7 @@ inline bool operator<(const value_t lhs, const value_t rhs) noexcept
2 /* unsigned */,
2 /* float */,
6 /* binary */
}};
} };
const auto l_index = static_cast<std::size_t>(lhs);
const auto r_index = static_cast<std::size_t>(rhs);

View File

@ -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;
@ -271,25 +272,25 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spe
#endif
#if defined(__ICC) || defined(__INTEL_COMPILER)
result["compiler"] = {{"family", "icc"}, { "version", __INTEL_COMPILER }};
result["compiler"] = { { "family", "icc" }, { "version", __INTEL_COMPILER } };
#elif defined(__clang__)
result["compiler"] = {{"family", "clang"}, { "version", __clang_version__ }};
result["compiler"] = { { "family", "clang" }, { "version", __clang_version__ } };
#elif defined(__GNUC__) || defined(__GNUG__)
result["compiler"] = {{"family", "gcc"},
result["compiler"] = { { "family", "gcc" },
{ "version",
detail::concat(std::to_string(__GNUC__), '.', std::to_string(__GNUC_MINOR__), '.', std::to_string(__GNUC_PATCHLEVEL__)) }};
detail::concat(std::to_string(__GNUC__), '.', std::to_string(__GNUC_MINOR__), '.', std::to_string(__GNUC_PATCHLEVEL__)) } };
#elif defined(__HP_cc) || defined(__HP_aCC)
result["compiler"] = "hp"
#elif defined(__IBMCPP__)
result["compiler"] = {{"family", "ilecpp"}, { "version", __IBMCPP__ }};
result["compiler"] = { { "family", "ilecpp" }, { "version", __IBMCPP__ } };
#elif defined(_MSC_VER)
result["compiler"] = {{"family", "msvc"}, { "version", _MSC_VER }};
result["compiler"] = { { "family", "msvc" }, { "version", _MSC_VER } };
#elif defined(__PGI)
result["compiler"] = {{"family", "pgcpp"}, { "version", __PGI }};
result["compiler"] = { { "family", "pgcpp" }, { "version", __PGI } };
#elif defined(__SUNPRO_CC)
result["compiler"] = {{"family", "sunpro"}, { "version", __SUNPRO_CC }};
result["compiler"] = { { "family", "sunpro" }, { "version", __SUNPRO_CC } };
#else
result["compiler"] = {{"family", "unknown"}, {"version", "unknown"}};
result["compiler"] = { { "family", "unknown" }, { "version", "unknown" } };
#endif
#if defined(_MSVC_LANG)
@ -1022,7 +1023,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spe
/// @brief construct an array with count copies of given value
/// @sa https://json.nlohmann.me/api/basic_json/basic_json/
basic_json(size_type cnt, const basic_json& val)
: m_data{cnt, val}
: m_data{ cnt, val }
{
set_parents();
assert_invariant();
@ -3210,7 +3211,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spe
it.m_it.object_iterator = res.first;
// return pair of iterator and boolean
return {it, res.second};
return { it, res.second };
}
/// Helper for insertion of an iterator
@ -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()))
@ -4872,7 +4872,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spe
if (source.type() != target.type())
{
// different types: replace value
result.push_back({{"op", "replace"}, {"path", path}, {"value", target}});
result.push_back({ { "op", "replace" }, { "path", path }, { "value", target } });
return result;
}
@ -4899,14 +4899,14 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spe
{
// add operations in reverse order to avoid invalid
// indices
result.insert(result.begin() + end_index, object({{"op", "remove"}, {"path", detail::concat(path, '/', std::to_string(i))}}));
result.insert(result.begin() + end_index, object({ { "op", "remove" }, { "path", detail::concat(path, '/', std::to_string(i)) } }));
++i;
}
// add other remaining elements
while (i < target.size())
{
result.push_back({{"op", "add"}, {"path", detail::concat(path, "/-")}, {"value", target[i]}});
result.push_back({ { "op", "add" }, { "path", detail::concat(path, "/-") }, { "value", target[i] } });
++i;
}
@ -4930,7 +4930,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spe
else
{
// found a key that is not in o -> remove it
result.push_back(object({{"op", "remove"}, {"path", path_key}}));
result.push_back(object({ { "op", "remove" }, { "path", path_key } }));
}
}
@ -4941,7 +4941,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spe
{
// found a key that is not in this -> add it
const auto path_key = detail::concat(path, '/', detail::escape(it.key()));
result.push_back({{"op", "add"}, {"path", path_key}, {"value", it.value()}});
result.push_back({ { "op", "add" }, { "path", path_key }, { "value", it.value() } });
}
}
@ -4959,7 +4959,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spe
default:
{
// both primitive type: replace value
result.push_back({{"op", "replace"}, {"path", path}, {"value", target}});
result.push_back({ { "op", "replace" }, { "path", path }, { "value", target } });
break;
}
}

View File

@ -46,14 +46,14 @@ struct ordered_map : std::vector<std::pair<const Key, T>, Allocator>
: Container{}
{}
explicit ordered_map(const Allocator& alloc) noexcept(noexcept(Container(alloc)))
: Container{alloc}
: Container{ alloc }
{}
template<class It>
ordered_map(It first, It last, const Allocator& alloc = Allocator())
: Container{first, last, alloc}
: Container{ first, last, alloc }
{}
ordered_map(std::initializer_list<value_type> init, const Allocator& alloc = Allocator())
: Container{init, alloc}
: Container{ init, alloc }
{}
std::pair<iterator, bool> emplace(const key_type& key, T&& t)
@ -62,11 +62,11 @@ struct ordered_map : std::vector<std::pair<const Key, T>, Allocator>
{
if (m_compare(it->first, key))
{
return {it, false};
return { it, false };
}
}
Container::emplace_back(key, std::forward<T>(t));
return {std::prev(this->end()), true};
return { std::prev(this->end()), true };
}
template<class KeyType, detail::enable_if_t<detail::is_usable_as_key_type<key_compare, key_type, KeyType>::value, int> = 0>
@ -76,11 +76,11 @@ struct ordered_map : std::vector<std::pair<const Key, T>, Allocator>
{
if (m_compare(it->first, key))
{
return {it, false};
return { it, false };
}
}
Container::emplace_back(std::forward<KeyType>(key), std::forward<T>(t));
return {std::prev(this->end()), true};
return { std::prev(this->end()), true };
}
T& operator[](const key_type& key)
@ -169,7 +169,7 @@ struct ordered_map : std::vector<std::pair<const Key, T>, Allocator>
for (auto next = it; ++next != this->end(); ++it)
{
it->~value_type(); // Destroy but keep allocation
new (&*it) value_type{std::move(*next)};
new (&*it) value_type{ std::move(*next) };
}
Container::pop_back();
return 1;
@ -189,7 +189,7 @@ struct ordered_map : std::vector<std::pair<const Key, T>, Allocator>
for (auto next = it; ++next != this->end(); ++it)
{
it->~value_type(); // Destroy but keep allocation
new (&*it) value_type{std::move(*next)};
new (&*it) value_type{ std::move(*next) };
}
Container::pop_back();
return 1;
@ -236,7 +236,7 @@ struct ordered_map : std::vector<std::pair<const Key, T>, Allocator>
for (auto it = first; std::next(it, elements_affected) != Container::end(); ++it)
{
it->~value_type(); // destroy but keep allocation
new (&*it) value_type{std::move(*std::next(it, elements_affected))}; // "move" next element to it
new (&*it) value_type{ std::move(*std::next(it, elements_affected)) }; // "move" next element to it
}
// [ a, b, c, d, h, i, j, h, i, j ]
@ -329,11 +329,11 @@ struct ordered_map : std::vector<std::pair<const Key, T>, Allocator>
{
if (m_compare(it->first, value.first))
{
return {it, false};
return { it, false };
}
}
Container::push_back(value);
return {--this->end(), true};
return { --this->end(), true };
}
template<typename InputIt>

View File

@ -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
@ -6107,7 +6106,7 @@ constexpr T static_const<T>::value;
template<typename T, typename... Args>
inline constexpr std::array<T, sizeof...(Args)> make_array(Args&&... args)
{
return std::array<T, sizeof...(Args)>{{static_cast<T>(std::forward<Args>(args))...}};
return std::array<T, sizeof...(Args)>{ { static_cast<T>(std::forward<Args>(args))... } };
}
} // namespace detail
@ -7272,8 +7271,8 @@ inline void replace_substring(StringType& s, const StringType& f, const StringTy
template<typename StringType>
inline StringType escape(StringType s)
{
replace_substring(s, StringType{"~"}, StringType{"~0"});
replace_substring(s, StringType{"/"}, StringType{"~1"});
replace_substring(s, StringType{ "~" }, StringType{ "~0" });
replace_substring(s, StringType{ "/" }, StringType{ "~1" });
return s;
}
@ -7287,8 +7286,8 @@ inline StringType escape(StringType s)
template<typename StringType>
static void unescape(StringType& s)
{
replace_substring(s, StringType{"~1"}, StringType{"/"});
replace_substring(s, StringType{"~0"}, StringType{"~"});
replace_substring(s, StringType{ "~1" }, StringType{ "/" });
replace_substring(s, StringType{ "~0" }, StringType{ "~" });
}
} // namespace detail
@ -7379,7 +7378,7 @@ inline std::partial_ordering operator<=>(const value_t lhs, const value_t rhs) n
inline bool operator<(const value_t lhs, const value_t rhs) noexcept
#endif
{
static constexpr std::array<std::uint8_t, 9> order = {{
static constexpr std::array<std::uint8_t, 9> order = { {
0 /* null */,
3 /* object */,
4 /* array */,
@ -7389,7 +7388,7 @@ inline bool operator<(const value_t lhs, const value_t rhs) noexcept
2 /* unsigned */,
2 /* float */,
6 /* binary */
}};
} };
const auto l_index = static_cast<std::size_t>(lhs);
const auto r_index = static_cast<std::size_t>(rhs);
@ -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_)
{
@ -7543,7 +7542,7 @@ class parse_error : public exception
static parse_error create(int id_, const position_t& pos, const std::string& what_arg, BasicJsonContext context)
{
const std::string w = concat(exception::name("parse_error", id_), "parse error", position_string(pos), ": ", exception::diagnostics(context), what_arg);
return {id_, pos.chars_read_total, w.c_str()};
return { id_, pos.chars_read_total, w.c_str() };
}
template<typename BasicJsonContext, enable_if_t<is_basic_json_context<BasicJsonContext>::value, int> = 0>
@ -7555,7 +7554,7 @@ class parse_error : public exception
": ",
exception::diagnostics(context),
what_arg);
return {id_, byte_, w.c_str()};
return { id_, byte_, w.c_str() };
}
/*!
@ -7590,7 +7589,7 @@ class invalid_iterator : public exception
static invalid_iterator create(int id_, const std::string& what_arg, BasicJsonContext context)
{
const std::string w = concat(exception::name("invalid_iterator", id_), exception::diagnostics(context), what_arg);
return {id_, w.c_str()};
return { id_, w.c_str() };
}
private:
@ -7609,7 +7608,7 @@ class type_error : public exception
static type_error create(int id_, const std::string& what_arg, BasicJsonContext context)
{
const std::string w = concat(exception::name("type_error", id_), exception::diagnostics(context), what_arg);
return {id_, w.c_str()};
return { id_, w.c_str() };
}
private:
@ -7628,7 +7627,7 @@ class out_of_range : public exception
static out_of_range create(int id_, const std::string& what_arg, BasicJsonContext context)
{
const std::string w = concat(exception::name("out_of_range", id_), exception::diagnostics(context), what_arg);
return {id_, w.c_str()};
return { id_, w.c_str() };
}
private:
@ -7647,7 +7646,7 @@ class other_error : public exception
static other_error create(int id_, const std::string& what_arg, BasicJsonContext context)
{
const std::string w = concat(exception::name("other_error", id_), exception::diagnostics(context), what_arg);
return {id_, w.c_str()};
return { id_, w.c_str() };
}
private:
@ -7945,7 +7944,7 @@ template<typename BasicJsonType, typename T, std::size_t... Idx>
std::array<T, sizeof...(Idx)>
from_json_inplace_array_impl(BasicJsonType&& j, identity_tag<std::array<T, sizeof...(Idx)>> /*unused*/, index_sequence<Idx...> /*unused*/)
{
return {{std::forward<BasicJsonType>(j).at(Idx).template get<T>()...}};
return { { std::forward<BasicJsonType>(j).at(Idx).template get<T>()... } };
}
template<typename BasicJsonType, typename T, std::size_t N>
@ -8046,7 +8045,7 @@ std::tuple<Args...> from_json_tuple_impl_base(BasicJsonType&& j, index_sequence<
template<typename BasicJsonType, class A1, class A2>
std::pair<A1, A2> from_json_tuple_impl(BasicJsonType&& j, identity_tag<std::pair<A1, A2>> /*unused*/, priority_tag<0> /*unused*/)
{
return {std::forward<BasicJsonType>(j).at(0).template get<A1>(), std::forward<BasicJsonType>(j).at(1).template get<A2>()};
return { std::forward<BasicJsonType>(j).at(0).template get<A1>(), std::forward<BasicJsonType>(j).at(1).template get<A2>() };
}
template<typename BasicJsonType, typename A1, typename A2>
@ -8806,20 +8805,20 @@ template<typename BasicJsonType,
enable_if_t<std::is_constructible<BasicJsonType, T1>::value && std::is_constructible<BasicJsonType, T2>::value, int> = 0>
inline void to_json(BasicJsonType& j, const std::pair<T1, T2>& p)
{
j = {p.first, p.second};
j = { p.first, p.second };
}
// for https://github.com/nlohmann/json/pull/1134
template<typename BasicJsonType, typename T, enable_if_t<std::is_same<T, iteration_proxy_value<typename BasicJsonType::iterator>>::value, int> = 0>
inline void to_json(BasicJsonType& j, const T& b)
{
j = {{b.key(), b.value()}};
j = { { b.key(), b.value() } };
}
template<typename BasicJsonType, typename Tuple, std::size_t... Idx>
inline void to_json_tuple_impl(BasicJsonType& j, const Tuple& t, index_sequence<Idx...> /*unused*/)
{
j = {std::get<Idx>(t)...};
j = { std::get<Idx>(t)... };
}
template<typename BasicJsonType, typename T, enable_if_t<is_constructible_tuple<BasicJsonType, T>::value, int> = 0>
@ -9503,7 +9502,7 @@ class wide_string_input_adapter
}
/// a buffer for UTF-8 bytes
std::array<std::char_traits<char>::int_type, 4> utf8_bytes = {{0, 0, 0, 0}};
std::array<std::char_traits<char>::int_type, 4> utf8_bytes = { { 0, 0, 0, 0 } };
/// index to the utf8_codes array for the next valid byte
std::size_t utf8_bytes_index = 0;
@ -10233,7 +10232,7 @@ class json_sax_dom_callback_parser
// container
if (!keep_stack.back())
{
return {false, nullptr};
return { false, nullptr };
}
// create value
@ -10245,20 +10244,20 @@ class json_sax_dom_callback_parser
// do not handle this value if we just learnt it shall be discarded
if (!keep)
{
return {false, nullptr};
return { false, nullptr };
}
if (ref_stack.empty())
{
root = std::move(value);
return {true, &root};
return { true, &root };
}
// skip this value if we already decided to skip the parent
// (https://github.com/nlohmann/json/issues/971#issuecomment-413678360)
if (!ref_stack.back())
{
return {false, nullptr};
return { false, nullptr };
}
// we now only expect arrays and objects
@ -10268,7 +10267,7 @@ class json_sax_dom_callback_parser
if (ref_stack.back()->is_array())
{
ref_stack.back()->m_data.m_value.array->emplace_back(std::move(value));
return {true, &(ref_stack.back()->m_data.m_value.array->back())};
return { true, &(ref_stack.back()->m_data.m_value.array->back()) };
}
// object
@ -10280,12 +10279,12 @@ class json_sax_dom_callback_parser
if (!store_element)
{
return {false, nullptr};
return { false, nullptr };
}
JSON_ASSERT(object_element);
*object_element = std::move(value);
return {true, object_element};
return { true, object_element };
}
/// the parsed JSON value
@ -10564,7 +10563,7 @@ class lexer : public lexer_base<BasicJsonType>
JSON_ASSERT(current == 'u');
int codepoint = 0;
const auto factors = {12u, 8u, 4u, 0u};
const auto factors = { 12u, 8u, 4u, 0u };
for (const auto factor : factors)
{
get();
@ -11136,7 +11135,7 @@ class lexer : public lexer_base<BasicJsonType>
case 0xDE:
case 0xDF:
{
if (JSON_HEDLEY_UNLIKELY(!next_byte_in_range({0x80, 0xBF})))
if (JSON_HEDLEY_UNLIKELY(!next_byte_in_range({ 0x80, 0xBF })))
{
return token_type::parse_error;
}
@ -11146,7 +11145,7 @@ class lexer : public lexer_base<BasicJsonType>
// U+0800..U+0FFF: bytes E0 A0..BF 80..BF
case 0xE0:
{
if (JSON_HEDLEY_UNLIKELY(!(next_byte_in_range({0xA0, 0xBF, 0x80, 0xBF}))))
if (JSON_HEDLEY_UNLIKELY(!(next_byte_in_range({ 0xA0, 0xBF, 0x80, 0xBF }))))
{
return token_type::parse_error;
}
@ -11170,7 +11169,7 @@ class lexer : public lexer_base<BasicJsonType>
case 0xEE:
case 0xEF:
{
if (JSON_HEDLEY_UNLIKELY(!(next_byte_in_range({0x80, 0xBF, 0x80, 0xBF}))))
if (JSON_HEDLEY_UNLIKELY(!(next_byte_in_range({ 0x80, 0xBF, 0x80, 0xBF }))))
{
return token_type::parse_error;
}
@ -11180,7 +11179,7 @@ class lexer : public lexer_base<BasicJsonType>
// U+D000..U+D7FF: bytes ED 80..9F 80..BF
case 0xED:
{
if (JSON_HEDLEY_UNLIKELY(!(next_byte_in_range({0x80, 0x9F, 0x80, 0xBF}))))
if (JSON_HEDLEY_UNLIKELY(!(next_byte_in_range({ 0x80, 0x9F, 0x80, 0xBF }))))
{
return token_type::parse_error;
}
@ -11190,7 +11189,7 @@ class lexer : public lexer_base<BasicJsonType>
// U+10000..U+3FFFF F0 90..BF 80..BF 80..BF
case 0xF0:
{
if (JSON_HEDLEY_UNLIKELY(!(next_byte_in_range({0x90, 0xBF, 0x80, 0xBF, 0x80, 0xBF}))))
if (JSON_HEDLEY_UNLIKELY(!(next_byte_in_range({ 0x90, 0xBF, 0x80, 0xBF, 0x80, 0xBF }))))
{
return token_type::parse_error;
}
@ -11202,7 +11201,7 @@ class lexer : public lexer_base<BasicJsonType>
case 0xF2:
case 0xF3:
{
if (JSON_HEDLEY_UNLIKELY(!(next_byte_in_range({0x80, 0xBF, 0x80, 0xBF, 0x80, 0xBF}))))
if (JSON_HEDLEY_UNLIKELY(!(next_byte_in_range({ 0x80, 0xBF, 0x80, 0xBF, 0x80, 0xBF }))))
{
return token_type::parse_error;
}
@ -11212,7 +11211,7 @@ class lexer : public lexer_base<BasicJsonType>
// U+100000..U+10FFFF F4 80..8F 80..BF 80..BF
case 0xF4:
{
if (JSON_HEDLEY_UNLIKELY(!(next_byte_in_range({0x80, 0x8F, 0x80, 0xBF, 0x80, 0xBF}))))
if (JSON_HEDLEY_UNLIKELY(!(next_byte_in_range({ 0x80, 0x8F, 0x80, 0xBF, 0x80, 0xBF }))))
{
return token_type::parse_error;
}
@ -11844,9 +11843,9 @@ scan_number_done:
if (static_cast<unsigned char>(c) <= '\x1F')
{
// 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)
std::array<char, 9> cs{ {} };
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,22 +11939,24 @@ 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':
{
std::array<char_type, 5> false_literal = {{static_cast<char_type>('f'),
std::array<char_type, 5> false_literal = { { static_cast<char_type>('f'),
static_cast<char_type>('a'),
static_cast<char_type>('l'),
static_cast<char_type>('s'),
static_cast<char_type>('e')}};
static_cast<char_type>('e') } };
return scan_literal(false_literal.data(), false_literal.size(), token_type::literal_false);
}
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);
}
@ -12470,12 +12471,12 @@ class binary_reader
default: // anything else not supported (yet)
{
std::array<char, 3> cr{{}};
static_cast<void>((std::snprintf)(cr.data(),
std::array<char, 3> cr{ {} };
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)
const std::string cr_str{cr.data()};
static_cast<unsigned char>(element_type)));
const std::string cr_str{ cr.data() };
return sax->parse_error(element_type_parse_position,
cr_str,
parse_error::create(114, element_type_parse_position, concat("Unsupported BSON record type 0x", cr_str), nullptr));
@ -15100,10 +15101,10 @@ class binary_reader
*/
std::string get_token_string() const
{
std::array<char, 3> cr{{}};
std::array<char, 3> cr{ {} };
static_cast<void>(
(std::snprintf)(cr.data(), cr.size(), "%.2hhX", static_cast<unsigned char>(current))); // NOLINT(cppcoreguidelines-pro-type-vararg,hicpp-vararg)
return std::string{cr.data()};
return std::string{ cr.data() };
}
/*!
@ -15171,17 +15172,17 @@ class binary_reader
#define JSON_BINARY_READER_MAKE_BJD_OPTIMIZED_TYPE_MARKERS_ make_array<char_int_type>('F', 'H', 'N', 'S', 'T', 'Z', '[', '{')
#define JSON_BINARY_READER_MAKE_BJD_TYPES_MAP_ \
make_array<bjd_type>(bjd_type{'C', "char"}, \
bjd_type{'D', "double"}, \
bjd_type{'I', "int16"}, \
bjd_type{'L', "int64"}, \
bjd_type{'M', "uint64"}, \
bjd_type{'U', "uint8"}, \
bjd_type{'d', "single"}, \
bjd_type{'i', "int8"}, \
bjd_type{'l', "int32"}, \
bjd_type{'m', "uint32"}, \
bjd_type{'u', "uint16"})
make_array<bjd_type>(bjd_type{ 'C', "char" }, \
bjd_type{ 'D', "double" }, \
bjd_type{ 'I', "int16" }, \
bjd_type{ 'L', "int64" }, \
bjd_type{ 'M', "uint64" }, \
bjd_type{ 'U', "uint8" }, \
bjd_type{ 'd', "single" }, \
bjd_type{ 'i', "int8" }, \
bjd_type{ 'l', "int32" }, \
bjd_type{ 'm', "uint32" }, \
bjd_type{ 'u', "uint16" })
JSON_PRIVATE_UNLESS_TESTED :
// lookup tables
@ -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()))
{
@ -17098,7 +17099,7 @@ class json_pointer
}
json_pointer result = *this;
result.reference_tokens = {reference_tokens[0]};
result.reference_tokens = { reference_tokens[0] };
return result;
}
@ -18828,7 +18829,7 @@ class binary_writer
return ubjson_prefix(v, use_bjdata) == first_prefix;
});
std::vector<CharType> bjdx = {'[', '{', 'S', 'H', 'T', 'F', 'N', 'Z'}; // excluded markers in bjdata optimized type
std::vector<CharType> bjdx = { '[', '{', 'S', 'H', 'T', 'F', 'N', 'Z' }; // excluded markers in bjdata optimized type
if (same_prefix && !(use_bjdata && std::find(bjdx.begin(), bjdx.end(), first_prefix) != bjdx.end()))
{
@ -18926,7 +18927,7 @@ class binary_writer
return ubjson_prefix(v, use_bjdata) == first_prefix;
});
std::vector<CharType> bjdx = {'[', '{', 'S', 'H', 'T', 'F', 'N', 'Z'}; // excluded markers in bjdata optimized type
std::vector<CharType> bjdx = { '[', '{', 'S', 'H', 'T', 'F', 'N', 'Z' }; // excluded markers in bjdata optimized type
if (same_prefix && !(use_bjdata && std::find(bjdx.begin(), bjdx.end(), first_prefix) != bjdx.end()))
{
@ -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)));
@ -19939,7 +19931,7 @@ struct diyfp // f * 2^e
JSON_ASSERT(x.e == y.e);
JSON_ASSERT(x.f >= y.f);
return {x.f - y.f, x.e};
return { x.f - y.f, x.e };
}
/*!
@ -20000,11 +19992,11 @@ struct diyfp // f * 2^e
// Effectively we only need to add the highest bit in p_lo to p_hi (and
// Q_hi + 1 does not overflow).
Q += std::uint64_t{1} << (64u - 32u - 1u); // round, ties up
Q += std::uint64_t{ 1 } << (64u - 32u - 1u); // round, ties up
const std::uint64_t h = p3 + p2_hi + p1_hi + (Q >> 32u);
return {h, x.e + y.e + 64};
return { h, x.e + y.e + 64 };
}
/*!
@ -20035,7 +20027,7 @@ struct diyfp // f * 2^e
JSON_ASSERT(delta >= 0);
JSON_ASSERT(((x.f << delta) >> delta) == x.f);
return {x.f << delta, target_exponent};
return { x.f << delta, target_exponent };
}
};
@ -20070,7 +20062,7 @@ boundaries compute_boundaries(FloatType value)
constexpr int kPrecision = std::numeric_limits<FloatType>::digits; // = p (includes the hidden bit)
constexpr int kBias = std::numeric_limits<FloatType>::max_exponent - 1 + (kPrecision - 1);
constexpr int kMinExp = 1 - kBias;
constexpr std::uint64_t kHiddenBit = std::uint64_t{1} << (kPrecision - 1); // = 2^(p-1)
constexpr std::uint64_t kHiddenBit = std::uint64_t{ 1 } << (kPrecision - 1); // = 2^(p-1)
using bits_type = typename std::conditional<kPrecision == 24, std::uint32_t, std::uint64_t>::type;
@ -20113,7 +20105,7 @@ boundaries compute_boundaries(FloatType value)
// Determine w- = m- such that e_(w-) = e_(w+).
const diyfp w_minus = diyfp::normalize_to(m_minus, w_plus.e);
return {diyfp::normalize(v), w_minus, w_plus};
return { diyfp::normalize(v), w_minus, w_plus };
}
// Given normalized diyfp w, Grisu needs to find a (normalized) cached
@ -20243,28 +20235,28 @@ inline cached_power get_cached_power_for_binary_exponent(int e)
constexpr int kCachedPowersMinDecExp = -300;
constexpr int kCachedPowersDecStep = 8;
static constexpr std::array<cached_power, 79> kCachedPowers = {{
{0xAB70FE17C79AC6CA, -1060, -300}, {0xFF77B1FCBEBCDC4F, -1034, -292}, {0xBE5691EF416BD60C, -1007, -284}, {0x8DD01FAD907FFC3C, -980, -276},
{0xD3515C2831559A83, -954, -268}, {0x9D71AC8FADA6C9B5, -927, -260}, {0xEA9C227723EE8BCB, -901, -252}, {0xAECC49914078536D, -874, -244},
{0x823C12795DB6CE57, -847, -236}, {0xC21094364DFB5637, -821, -228}, {0x9096EA6F3848984F, -794, -220}, {0xD77485CB25823AC7, -768, -212},
{0xA086CFCD97BF97F4, -741, -204}, {0xEF340A98172AACE5, -715, -196}, {0xB23867FB2A35B28E, -688, -188}, {0x84C8D4DFD2C63F3B, -661, -180},
{0xC5DD44271AD3CDBA, -635, -172}, {0x936B9FCEBB25C996, -608, -164}, {0xDBAC6C247D62A584, -582, -156}, {0xA3AB66580D5FDAF6, -555, -148},
{0xF3E2F893DEC3F126, -529, -140}, {0xB5B5ADA8AAFF80B8, -502, -132}, {0x87625F056C7C4A8B, -475, -124}, {0xC9BCFF6034C13053, -449, -116},
{0x964E858C91BA2655, -422, -108}, {0xDFF9772470297EBD, -396, -100}, {0xA6DFBD9FB8E5B88F, -369, -92}, {0xF8A95FCF88747D94, -343, -84},
{0xB94470938FA89BCF, -316, -76}, {0x8A08F0F8BF0F156B, -289, -68}, {0xCDB02555653131B6, -263, -60}, {0x993FE2C6D07B7FAC, -236, -52},
{0xE45C10C42A2B3B06, -210, -44}, {0xAA242499697392D3, -183, -36}, {0xFD87B5F28300CA0E, -157, -28}, {0xBCE5086492111AEB, -130, -20},
{0x8CBCCC096F5088CC, -103, -12}, {0xD1B71758E219652C, -77, -4}, {0x9C40000000000000, -50, 4}, {0xE8D4A51000000000, -24, 12},
{0xAD78EBC5AC620000, 3, 20}, {0x813F3978F8940984, 30, 28}, {0xC097CE7BC90715B3, 56, 36}, {0x8F7E32CE7BEA5C70, 83, 44},
{0xD5D238A4ABE98068, 109, 52}, {0x9F4F2726179A2245, 136, 60}, {0xED63A231D4C4FB27, 162, 68}, {0xB0DE65388CC8ADA8, 189, 76},
{0x83C7088E1AAB65DB, 216, 84}, {0xC45D1DF942711D9A, 242, 92}, {0x924D692CA61BE758, 269, 100}, {0xDA01EE641A708DEA, 295, 108},
{0xA26DA3999AEF774A, 322, 116}, {0xF209787BB47D6B85, 348, 124}, {0xB454E4A179DD1877, 375, 132}, {0x865B86925B9BC5C2, 402, 140},
{0xC83553C5C8965D3D, 428, 148}, {0x952AB45CFA97A0B3, 455, 156}, {0xDE469FBD99A05FE3, 481, 164}, {0xA59BC234DB398C25, 508, 172},
{0xF6C69A72A3989F5C, 534, 180}, {0xB7DCBF5354E9BECE, 561, 188}, {0x88FCF317F22241E2, 588, 196}, {0xCC20CE9BD35C78A5, 614, 204},
{0x98165AF37B2153DF, 641, 212}, {0xE2A0B5DC971F303A, 667, 220}, {0xA8D9D1535CE3B396, 694, 228}, {0xFB9B7CD9A4A7443C, 720, 236},
{0xBB764C4CA7A44410, 747, 244}, {0x8BAB8EEFB6409C1A, 774, 252}, {0xD01FEF10A657842C, 800, 260}, {0x9B10A4E5E9913129, 827, 268},
{0xE7109BFBA19C0C9D, 853, 276}, {0xAC2820D9623BF429, 880, 284}, {0x80444B5E7AA7CF85, 907, 292}, {0xBF21E44003ACDD2D, 933, 300},
{0x8E679C2F5E44FF8F, 960, 308}, {0xD433179D9C8CB841, 986, 316}, {0x9E19DB92B4E31BA9, 1013, 324},
}};
static constexpr std::array<cached_power, 79> kCachedPowers = { {
{ 0xAB70FE17C79AC6CA, -1060, -300 }, { 0xFF77B1FCBEBCDC4F, -1034, -292 }, { 0xBE5691EF416BD60C, -1007, -284 }, { 0x8DD01FAD907FFC3C, -980, -276 },
{ 0xD3515C2831559A83, -954, -268 }, { 0x9D71AC8FADA6C9B5, -927, -260 }, { 0xEA9C227723EE8BCB, -901, -252 }, { 0xAECC49914078536D, -874, -244 },
{ 0x823C12795DB6CE57, -847, -236 }, { 0xC21094364DFB5637, -821, -228 }, { 0x9096EA6F3848984F, -794, -220 }, { 0xD77485CB25823AC7, -768, -212 },
{ 0xA086CFCD97BF97F4, -741, -204 }, { 0xEF340A98172AACE5, -715, -196 }, { 0xB23867FB2A35B28E, -688, -188 }, { 0x84C8D4DFD2C63F3B, -661, -180 },
{ 0xC5DD44271AD3CDBA, -635, -172 }, { 0x936B9FCEBB25C996, -608, -164 }, { 0xDBAC6C247D62A584, -582, -156 }, { 0xA3AB66580D5FDAF6, -555, -148 },
{ 0xF3E2F893DEC3F126, -529, -140 }, { 0xB5B5ADA8AAFF80B8, -502, -132 }, { 0x87625F056C7C4A8B, -475, -124 }, { 0xC9BCFF6034C13053, -449, -116 },
{ 0x964E858C91BA2655, -422, -108 }, { 0xDFF9772470297EBD, -396, -100 }, { 0xA6DFBD9FB8E5B88F, -369, -92 }, { 0xF8A95FCF88747D94, -343, -84 },
{ 0xB94470938FA89BCF, -316, -76 }, { 0x8A08F0F8BF0F156B, -289, -68 }, { 0xCDB02555653131B6, -263, -60 }, { 0x993FE2C6D07B7FAC, -236, -52 },
{ 0xE45C10C42A2B3B06, -210, -44 }, { 0xAA242499697392D3, -183, -36 }, { 0xFD87B5F28300CA0E, -157, -28 }, { 0xBCE5086492111AEB, -130, -20 },
{ 0x8CBCCC096F5088CC, -103, -12 }, { 0xD1B71758E219652C, -77, -4 }, { 0x9C40000000000000, -50, 4 }, { 0xE8D4A51000000000, -24, 12 },
{ 0xAD78EBC5AC620000, 3, 20 }, { 0x813F3978F8940984, 30, 28 }, { 0xC097CE7BC90715B3, 56, 36 }, { 0x8F7E32CE7BEA5C70, 83, 44 },
{ 0xD5D238A4ABE98068, 109, 52 }, { 0x9F4F2726179A2245, 136, 60 }, { 0xED63A231D4C4FB27, 162, 68 }, { 0xB0DE65388CC8ADA8, 189, 76 },
{ 0x83C7088E1AAB65DB, 216, 84 }, { 0xC45D1DF942711D9A, 242, 92 }, { 0x924D692CA61BE758, 269, 100 }, { 0xDA01EE641A708DEA, 295, 108 },
{ 0xA26DA3999AEF774A, 322, 116 }, { 0xF209787BB47D6B85, 348, 124 }, { 0xB454E4A179DD1877, 375, 132 }, { 0x865B86925B9BC5C2, 402, 140 },
{ 0xC83553C5C8965D3D, 428, 148 }, { 0x952AB45CFA97A0B3, 455, 156 }, { 0xDE469FBD99A05FE3, 481, 164 }, { 0xA59BC234DB398C25, 508, 172 },
{ 0xF6C69A72A3989F5C, 534, 180 }, { 0xB7DCBF5354E9BECE, 561, 188 }, { 0x88FCF317F22241E2, 588, 196 }, { 0xCC20CE9BD35C78A5, 614, 204 },
{ 0x98165AF37B2153DF, 641, 212 }, { 0xE2A0B5DC971F303A, 667, 220 }, { 0xA8D9D1535CE3B396, 694, 228 }, { 0xFB9B7CD9A4A7443C, 720, 236 },
{ 0xBB764C4CA7A44410, 747, 244 }, { 0x8BAB8EEFB6409C1A, 774, 252 }, { 0xD01FEF10A657842C, 800, 260 }, { 0x9B10A4E5E9913129, 827, 268 },
{ 0xE7109BFBA19C0C9D, 853, 276 }, { 0xAC2820D9623BF429, 880, 284 }, { 0x80444B5E7AA7CF85, 907, 292 }, { 0xBF21E44003ACDD2D, 933, 300 },
{ 0x8E679C2F5E44FF8F, 960, 308 }, { 0xD433179D9C8CB841, 986, 316 }, { 0x9E19DB92B4E31BA9, 1013, 324 },
} };
// This computation gives exactly the same results for k as
// k = ceil((kAlpha - e - 1) * 0.30102999566398114)
@ -20412,7 +20404,7 @@ inline void grisu2_digit_gen(char* buffer, int& length, int& decimal_exponent, d
// = ((p1 ) * 2^-e + (p2 )) * 2^e
// = p1 + p2 * 2^e
const diyfp one(std::uint64_t{1} << -M_plus.e, M_plus.e);
const diyfp one(std::uint64_t{ 1 } << -M_plus.e, M_plus.e);
auto p1 = static_cast<std::uint32_t>(M_plus.f >> -one.e); // p1 = f div 2^-e (Since -e >= 32, p1 fits into a 32-bit int.)
std::uint64_t p2 = M_plus.f & (one.f - 1); // p2 = f mod 2^-e
@ -20477,7 +20469,7 @@ inline void grisu2_digit_gen(char* buffer, int& length, int& decimal_exponent, d
// Note:
// Since rest and delta share the same exponent e, it suffices to
// compare the significands.
const std::uint64_t rest = (std::uint64_t{p1} << -one.e) + p2;
const std::uint64_t rest = (std::uint64_t{ p1 } << -one.e) + p2;
if (rest <= delta)
{
// V = buffer * 10^n, with M- <= V <= M+.
@ -20493,7 +20485,7 @@ inline void grisu2_digit_gen(char* buffer, int& length, int& decimal_exponent, d
//
// 10^n = (10^n * 2^-e) * 2^e = ulp * 2^e
//
const std::uint64_t ten_n = std::uint64_t{pow10} << -one.e;
const std::uint64_t ten_n = std::uint64_t{ pow10 } << -one.e;
grisu2_round(buffer, length, dist, delta, rest, ten_n);
return;
@ -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;
@ -21599,18 +21590,21 @@ class serializer
int> = 0>
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'}},
}};
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' } },
} };
// special case for "0"
if (x == 0)
@ -21780,7 +21774,7 @@ class serializer
*/
static std::uint8_t decode(std::uint8_t& state, std::uint32_t& codep, const std::uint8_t byte) noexcept
{
static const std::array<std::uint8_t, 400> utf8d = {{
static const std::array<std::uint8_t, 400> utf8d = { {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, // 00..1F
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
@ -21809,7 +21803,7 @@ class serializer
1, // s5..s6
1, 3, 1, 1, 1, 1, 1, 3, 1, 3, 1, 1, 1, 1, 1, 1, 1, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1 // s7..s8
}};
} };
JSON_ASSERT(byte < utf8d.size());
const std::uint8_t type = utf8d[byte];
@ -21853,7 +21847,7 @@ class serializer
output_adapter_t<char> o = nullptr;
/// a (hopefully) large enough character buffer
std::array<char, 64> number_buffer{{}};
std::array<char, 64> number_buffer{ {} };
/// the locale
const std::lconv* loc = nullptr;
@ -21863,7 +21857,7 @@ class serializer
const char decimal_point = '\0';
/// string buffer
std::array<char, 512> string_buffer{{}};
std::array<char, 512> string_buffer{ {} };
/// the indentation character
const char indent_char;
@ -21933,14 +21927,14 @@ struct ordered_map : std::vector<std::pair<const Key, T>, Allocator>
: Container{}
{}
explicit ordered_map(const Allocator& alloc) noexcept(noexcept(Container(alloc)))
: Container{alloc}
: Container{ alloc }
{}
template<class It>
ordered_map(It first, It last, const Allocator& alloc = Allocator())
: Container{first, last, alloc}
: Container{ first, last, alloc }
{}
ordered_map(std::initializer_list<value_type> init, const Allocator& alloc = Allocator())
: Container{init, alloc}
: Container{ init, alloc }
{}
std::pair<iterator, bool> emplace(const key_type& key, T&& t)
@ -21949,11 +21943,11 @@ struct ordered_map : std::vector<std::pair<const Key, T>, Allocator>
{
if (m_compare(it->first, key))
{
return {it, false};
return { it, false };
}
}
Container::emplace_back(key, std::forward<T>(t));
return {std::prev(this->end()), true};
return { std::prev(this->end()), true };
}
template<class KeyType, detail::enable_if_t<detail::is_usable_as_key_type<key_compare, key_type, KeyType>::value, int> = 0>
@ -21963,11 +21957,11 @@ struct ordered_map : std::vector<std::pair<const Key, T>, Allocator>
{
if (m_compare(it->first, key))
{
return {it, false};
return { it, false };
}
}
Container::emplace_back(std::forward<KeyType>(key), std::forward<T>(t));
return {std::prev(this->end()), true};
return { std::prev(this->end()), true };
}
T& operator[](const key_type& key)
@ -22056,7 +22050,7 @@ struct ordered_map : std::vector<std::pair<const Key, T>, Allocator>
for (auto next = it; ++next != this->end(); ++it)
{
it->~value_type(); // Destroy but keep allocation
new (&*it) value_type{std::move(*next)};
new (&*it) value_type{ std::move(*next) };
}
Container::pop_back();
return 1;
@ -22076,7 +22070,7 @@ struct ordered_map : std::vector<std::pair<const Key, T>, Allocator>
for (auto next = it; ++next != this->end(); ++it)
{
it->~value_type(); // Destroy but keep allocation
new (&*it) value_type{std::move(*next)};
new (&*it) value_type{ std::move(*next) };
}
Container::pop_back();
return 1;
@ -22123,7 +22117,7 @@ struct ordered_map : std::vector<std::pair<const Key, T>, Allocator>
for (auto it = first; std::next(it, elements_affected) != Container::end(); ++it)
{
it->~value_type(); // destroy but keep allocation
new (&*it) value_type{std::move(*std::next(it, elements_affected))}; // "move" next element to it
new (&*it) value_type{ std::move(*std::next(it, elements_affected)) }; // "move" next element to it
}
// [ a, b, c, d, h, i, j, h, i, j ]
@ -22216,11 +22210,11 @@ struct ordered_map : std::vector<std::pair<const Key, T>, Allocator>
{
if (m_compare(it->first, value.first))
{
return {it, false};
return { it, false };
}
}
Container::push_back(value);
return {--this->end(), true};
return { --this->end(), true };
}
template<typename InputIt>
@ -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;
@ -22452,25 +22447,25 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spe
#endif
#if defined(__ICC) || defined(__INTEL_COMPILER)
result["compiler"] = {{"family", "icc"}, { "version", __INTEL_COMPILER }};
result["compiler"] = { { "family", "icc" }, { "version", __INTEL_COMPILER } };
#elif defined(__clang__)
result["compiler"] = {{"family", "clang"}, { "version", __clang_version__ }};
result["compiler"] = { { "family", "clang" }, { "version", __clang_version__ } };
#elif defined(__GNUC__) || defined(__GNUG__)
result["compiler"] = {{"family", "gcc"},
result["compiler"] = { { "family", "gcc" },
{ "version",
detail::concat(std::to_string(__GNUC__), '.', std::to_string(__GNUC_MINOR__), '.', std::to_string(__GNUC_PATCHLEVEL__)) }};
detail::concat(std::to_string(__GNUC__), '.', std::to_string(__GNUC_MINOR__), '.', std::to_string(__GNUC_PATCHLEVEL__)) } };
#elif defined(__HP_cc) || defined(__HP_aCC)
result["compiler"] = "hp"
#elif defined(__IBMCPP__)
result["compiler"] = {{"family", "ilecpp"}, { "version", __IBMCPP__ }};
result["compiler"] = { { "family", "ilecpp" }, { "version", __IBMCPP__ } };
#elif defined(_MSC_VER)
result["compiler"] = {{"family", "msvc"}, { "version", _MSC_VER }};
result["compiler"] = { { "family", "msvc" }, { "version", _MSC_VER } };
#elif defined(__PGI)
result["compiler"] = {{"family", "pgcpp"}, { "version", __PGI }};
result["compiler"] = { { "family", "pgcpp" }, { "version", __PGI } };
#elif defined(__SUNPRO_CC)
result["compiler"] = {{"family", "sunpro"}, { "version", __SUNPRO_CC }};
result["compiler"] = { { "family", "sunpro" }, { "version", __SUNPRO_CC } };
#else
result["compiler"] = {{"family", "unknown"}, {"version", "unknown"}};
result["compiler"] = { { "family", "unknown" }, { "version", "unknown" } };
#endif
#if defined(_MSVC_LANG)
@ -23203,7 +23198,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spe
/// @brief construct an array with count copies of given value
/// @sa https://json.nlohmann.me/api/basic_json/basic_json/
basic_json(size_type cnt, const basic_json& val)
: m_data{cnt, val}
: m_data{ cnt, val }
{
set_parents();
assert_invariant();
@ -25391,7 +25386,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spe
it.m_it.object_iterator = res.first;
// return pair of iterator and boolean
return {it, res.second};
return { it, res.second };
}
/// Helper for insertion of an iterator
@ -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()))
@ -27053,7 +27047,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spe
if (source.type() != target.type())
{
// different types: replace value
result.push_back({{"op", "replace"}, {"path", path}, {"value", target}});
result.push_back({ { "op", "replace" }, { "path", path }, { "value", target } });
return result;
}
@ -27080,14 +27074,14 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spe
{
// add operations in reverse order to avoid invalid
// indices
result.insert(result.begin() + end_index, object({{"op", "remove"}, {"path", detail::concat(path, '/', std::to_string(i))}}));
result.insert(result.begin() + end_index, object({ { "op", "remove" }, { "path", detail::concat(path, '/', std::to_string(i)) } }));
++i;
}
// add other remaining elements
while (i < target.size())
{
result.push_back({{"op", "add"}, {"path", detail::concat(path, "/-")}, {"value", target[i]}});
result.push_back({ { "op", "add" }, { "path", detail::concat(path, "/-") }, { "value", target[i] } });
++i;
}
@ -27111,7 +27105,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spe
else
{
// found a key that is not in o -> remove it
result.push_back(object({{"op", "remove"}, {"path", path_key}}));
result.push_back(object({ { "op", "remove" }, { "path", path_key } }));
}
}
@ -27122,7 +27116,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spe
{
// found a key that is not in this -> add it
const auto path_key = detail::concat(path, '/', detail::escape(it.key()));
result.push_back({{"op", "add"}, {"path", path_key}, {"value", it.value()}});
result.push_back({ { "op", "add" }, { "path", path_key }, { "value", it.value() } });
}
}
@ -27140,7 +27134,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spe
default:
{
// both primitive type: replace value
result.push_back({{"op", "replace"}, {"path", path}, {"value", target}});
result.push_back({ { "op", "replace" }, { "path", path }, { "value", target } });
break;
}
}

View File

@ -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

View File

@ -27,7 +27,7 @@ TEST_CASE("custom namespace")
std::string expected = "nlohmann::basic_json";
// fallback for Clang
const std::string ns{STRINGIZE(NLOHMANN_JSON_NAMESPACE) "::basic_json"};
const std::string ns{ STRINGIZE(NLOHMANN_JSON_NAMESPACE) "::basic_json" };
CHECK(namespace_name<nlohmann::json>(ns) == expected);
}

View File

@ -33,7 +33,7 @@ TEST_CASE("default namespace")
expected += "_" STRINGIZE(NLOHMANN_JSON_VERSION_PATCH) "::basic_json";
// fallback for Clang
const std::string ns{STRINGIZE(NLOHMANN_JSON_NAMESPACE) "::basic_json"};
const std::string ns{ STRINGIZE(NLOHMANN_JSON_NAMESPACE) "::basic_json" };
CHECK(namespace_name<nlohmann::json>(ns) == expected);
}

View File

@ -32,7 +32,7 @@ TEST_CASE("default namespace without version component")
expected += "::basic_json";
// fallback for Clang
const std::string ns{STRINGIZE(NLOHMANN_JSON_NAMESPACE) "::basic_json"};
const std::string ns{ STRINGIZE(NLOHMANN_JSON_NAMESPACE) "::basic_json" };
CHECK(namespace_name<nlohmann::json>(ns) == expected);
}

View File

@ -25,6 +25,6 @@ std::size_t json_sizeof_diag_off_explicit()
void json_at_diag_off()
{
using nlohmann::json;
json j = json{{"foo", json::object()}};
json j = json{ { "foo", json::object() } };
j.at(json::json_pointer("/foo/bar"));
}

View File

@ -25,6 +25,6 @@ std::size_t json_sizeof_diag_on_explicit()
void json_at_diag_on()
{
using nlohmann::json;
json j = json{{"foo", json::object()}};
json j = json{ { "foo", json::object() } };
j.at(json::json_pointer("/foo/bar"));
}

View File

@ -162,8 +162,8 @@ static void BinaryToCbor(benchmark::State& state)
++it;
}
json::binary_t bin{in};
json j{{"type", "binary"}, {"data", bin}};
json::binary_t bin{ in };
json j{ { "type", "binary" }, { "data", bin } };
while (state.KeepRunning())
{

View File

@ -10,7 +10,7 @@
int main()
{
nlohmann::ordered_json json = {"Test"};
nlohmann::ordered_json json = { "Test" };
json.dump();
// regression for #3013 (ordered_json::reset() compile error with nvcc)

View File

@ -106,8 +106,8 @@ TEST_CASE("BJData")
{
SECTION("optimized array: negative size")
{
std::vector<uint8_t> const vM = {'[', '$', 'M', '#', '[', 'I', 0x00, 0x20, 'M', 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0xFF, ']'};
std::vector<uint8_t> const vMX = {'[', '$', 'U', '#', '[', 'M', 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 'U', 0x01, ']'};
std::vector<uint8_t> const vM = { '[', '$', 'M', '#', '[', 'I', 0x00, 0x20, 'M', 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0xFF, ']' };
std::vector<uint8_t> const vMX = { '[', '$', 'U', '#', '[', 'M', 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 'U', 0x01, ']' };
json _;
CHECK_THROWS_WITH_AS(_ = json::from_bjdata(vM),
@ -123,8 +123,8 @@ TEST_CASE("BJData")
SECTION("optimized array: integer value overflow")
{
std::vector<uint8_t> const vL = {'[', '#', 'L', 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7F};
std::vector<uint8_t> const vM = {'[', '$', 'M', '#', '[', 'I', 0x00, 0x20, 'M', 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0xFF, ']'};
std::vector<uint8_t> const vL = { '[', '#', 'L', 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7F };
std::vector<uint8_t> const vM = { '[', '$', 'M', '#', '[', 'I', 0x00, 0x20, 'M', 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0xFF, ']' };
json _;
CHECK_THROWS_WITH_AS(_ = json::from_bjdata(vL),

View File

@ -14,8 +14,8 @@ using nlohmann::json;
TEST_CASE("algorithms")
{
json j_array = {13, 29, 3, {{"one", 1}, {"two", 2}}, true, false, {1, 2, 3}, "foo", "baz"};
json j_object = {{"one", 1}, {"two", 2}};
json j_array = { 13, 29, 3, { { "one", 1 }, { "two", 2 } }, true, false, { 1, 2, 3 }, "foo", "baz" };
json j_object = { { "one", 1 }, { "two", 2 } };
SECTION("non-modifying sequence operations")
{
@ -76,7 +76,7 @@ TEST_CASE("algorithms")
std::for_each(j_array.begin(), j_array.end(), add17);
CHECK(j_array[6] == json({1, 2, 3, 17}));
CHECK(j_array[6] == json({ 1, 2, 3, 17 }));
}
}
@ -97,10 +97,10 @@ TEST_CASE("algorithms")
SECTION("std::mismatch")
{
json j_array2 = {13, 29, 3, {{"one", 1}, {"two", 2}, {"three", 3}}, true, false, {1, 2, 3}, "foo", "baz"};
json j_array2 = { 13, 29, 3, { { "one", 1 }, { "two", 2 }, { "three", 3 } }, true, false, { 1, 2, 3 }, "foo", "baz" };
auto res = std::mismatch(j_array.begin(), j_array.end(), j_array2.begin());
CHECK(*res.first == json({{"one", 1}, {"two", 2}}));
CHECK(*res.second == json({{"one", 1}, {"two", 2}, {"three", 3}}));
CHECK(*res.first == json({ { "one", 1 }, { "two", 2 } }));
CHECK(*res.second == json({ { "one", 1 }, { "two", 2 }, { "three", 3 } }));
}
SECTION("std::equal")
@ -115,7 +115,7 @@ TEST_CASE("algorithms")
SECTION("using user-defined comparison")
{
// compare objects only by size of its elements
json j_array2 = {13, 29, 3, {"Hello", "World"}, true, false, {{"one", 1}, {"two", 2}, {"three", 3}}, "foo", "baz"};
json j_array2 = { 13, 29, 3, { "Hello", "World" }, true, false, { { "one", 1 }, { "two", 2 }, { "three", 3 } }, "foo", "baz" };
CHECK(!std::equal(j_array.begin(), j_array.end(), j_array2.begin()));
CHECK(std::equal(j_array.begin(), j_array.end(), j_array2.begin(), [](const json& a, const json& b) {
return (a.size() == b.size());
@ -159,13 +159,13 @@ TEST_CASE("algorithms")
SECTION("std::reverse")
{
std::reverse(j_array.begin(), j_array.end());
CHECK(j_array == json({"baz", "foo", {1, 2, 3}, false, true, {{"one", 1}, {"two", 2}}, 3, 29, 13}));
CHECK(j_array == json({ "baz", "foo", { 1, 2, 3 }, false, true, { { "one", 1 }, { "two", 2 } }, 3, 29, 13 }));
}
SECTION("std::rotate")
{
std::rotate(j_array.begin(), j_array.begin() + 1, j_array.end());
CHECK(j_array == json({29, 3, {{"one", 1}, {"two", 2}}, true, false, {1, 2, 3}, "foo", "baz", 13}));
CHECK(j_array == json({ 29, 3, { { "one", 1 }, { "two", 2 } }, true, false, { 1, 2, 3 }, "foo", "baz", 13 }));
}
SECTION("std::partition")
@ -184,23 +184,23 @@ TEST_CASE("algorithms")
{
SECTION("with standard comparison")
{
json j = {13, 29, 3, {{"one", 1}, {"two", 2}}, true, false, {1, 2, 3}, "foo", "baz", nullptr};
json j = { 13, 29, 3, { { "one", 1 }, { "two", 2 } }, true, false, { 1, 2, 3 }, "foo", "baz", nullptr };
std::sort(j.begin(), j.end());
CHECK(j == json({nullptr, false, true, 3, 13, 29, {{"one", 1}, {"two", 2}}, {1, 2, 3}, "baz", "foo"}));
CHECK(j == json({ nullptr, false, true, 3, 13, 29, { { "one", 1 }, { "two", 2 } }, { 1, 2, 3 }, "baz", "foo" }));
}
SECTION("with user-defined comparison")
{
json j = {3, {{"one", 1}, {"two", 2}}, {1, 2, 3}, nullptr};
json j = { 3, { { "one", 1 }, { "two", 2 } }, { 1, 2, 3 }, nullptr };
std::sort(j.begin(), j.end(), [](const json& a, const json& b) {
return a.size() < b.size();
});
CHECK(j == json({nullptr, 3, {{"one", 1}, {"two", 2}}, {1, 2, 3}}));
CHECK(j == json({ nullptr, 3, { { "one", 1 }, { "two", 2 } }, { 1, 2, 3 } }));
}
SECTION("sorting an object")
{
json j({{"one", 1}, {"two", 2}});
json j({ { "one", 1 }, { "two", 2 } });
CHECK_THROWS_WITH_AS(std::sort(j.begin(), j.end()),
"[json.exception.invalid_iterator.209] cannot use offsets with object iterators",
json::invalid_iterator&);
@ -209,9 +209,9 @@ TEST_CASE("algorithms")
SECTION("std::partial_sort")
{
json j = {13, 29, 3, {{"one", 1}, {"two", 2}}, true, false, {1, 2, 3}, "foo", "baz", nullptr};
json j = { 13, 29, 3, { { "one", 1 }, { "two", 2 } }, true, false, { 1, 2, 3 }, "foo", "baz", nullptr };
std::partial_sort(j.begin(), j.begin() + 4, j.end());
CHECK(j == json({nullptr, false, true, 3, {{"one", 1}, {"two", 2}}, 29, {1, 2, 3}, "foo", "baz", 13}));
CHECK(j == json({ nullptr, false, true, 3, { { "one", 1 }, { "two", 2 } }, 29, { 1, 2, 3 }, "foo", "baz", 13 }));
}
}
@ -220,53 +220,53 @@ TEST_CASE("algorithms")
SECTION("std::merge")
{
{
json j1 = {2, 4, 6, 8};
json j2 = {1, 2, 3, 5, 7};
json j1 = { 2, 4, 6, 8 };
json j2 = { 1, 2, 3, 5, 7 };
json j3;
std::merge(j1.begin(), j1.end(), j2.begin(), j2.end(), std::back_inserter(j3));
CHECK(j3 == json({1, 2, 2, 3, 4, 5, 6, 7, 8}));
CHECK(j3 == json({ 1, 2, 2, 3, 4, 5, 6, 7, 8 }));
}
}
SECTION("std::set_difference")
{
json j1 = {1, 2, 3, 4, 5, 6, 7, 8};
json j2 = {1, 2, 3, 5, 7};
json j1 = { 1, 2, 3, 4, 5, 6, 7, 8 };
json j2 = { 1, 2, 3, 5, 7 };
json j3;
std::set_difference(j1.begin(), j1.end(), j2.begin(), j2.end(), std::back_inserter(j3));
CHECK(j3 == json({4, 6, 8}));
CHECK(j3 == json({ 4, 6, 8 }));
}
SECTION("std::set_intersection")
{
json j1 = {1, 2, 3, 4, 5, 6, 7, 8};
json j2 = {1, 2, 3, 5, 7};
json j1 = { 1, 2, 3, 4, 5, 6, 7, 8 };
json j2 = { 1, 2, 3, 5, 7 };
json j3;
std::set_intersection(j1.begin(), j1.end(), j2.begin(), j2.end(), std::back_inserter(j3));
CHECK(j3 == json({1, 2, 3, 5, 7}));
CHECK(j3 == json({ 1, 2, 3, 5, 7 }));
}
SECTION("std::set_union")
{
json j1 = {2, 4, 6, 8};
json j2 = {1, 2, 3, 5, 7};
json j1 = { 2, 4, 6, 8 };
json j2 = { 1, 2, 3, 5, 7 };
json j3;
std::set_union(j1.begin(), j1.end(), j2.begin(), j2.end(), std::back_inserter(j3));
CHECK(j3 == json({1, 2, 3, 4, 5, 6, 7, 8}));
CHECK(j3 == json({ 1, 2, 3, 4, 5, 6, 7, 8 }));
}
SECTION("std::set_symmetric_difference")
{
json j1 = {2, 4, 6, 8};
json j2 = {1, 2, 3, 5, 7};
json j1 = { 2, 4, 6, 8 };
json j2 = { 1, 2, 3, 5, 7 };
json j3;
std::set_symmetric_difference(j1.begin(), j1.end(), j2.begin(), j2.end(), std::back_inserter(j3));
CHECK(j3 == json({1, 3, 4, 5, 6, 7, 8}));
CHECK(j3 == json({ 1, 3, 4, 5, 6, 7, 8 }));
}
}
@ -275,29 +275,29 @@ TEST_CASE("algorithms")
std::make_heap(j_array.begin(), j_array.end());
CHECK(std::is_heap(j_array.begin(), j_array.end()));
std::sort_heap(j_array.begin(), j_array.end());
CHECK(j_array == json({false, true, 3, 13, 29, {{"one", 1}, {"two", 2}}, {1, 2, 3}, "baz", "foo"}));
CHECK(j_array == json({ false, true, 3, 13, 29, { { "one", 1 }, { "two", 2 } }, { 1, 2, 3 }, "baz", "foo" }));
}
SECTION("iota")
{
SECTION("int")
{
json json_arr = {0, 5, 2, 4, 10, 20, 30, 40, 50, 1};
json json_arr = { 0, 5, 2, 4, 10, 20, 30, 40, 50, 1 };
std::iota(json_arr.begin(), json_arr.end(), 0);
CHECK(json_arr == json({0, 1, 2, 3, 4, 5, 6, 7, 8, 9}));
CHECK(json_arr == json({ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }));
}
SECTION("double")
{
json json_arr = {0.5, 1.5, 1.3, 4.1, 10.2, 20.5, 30.6, 40.1, 50.22, 1.5};
json json_arr = { 0.5, 1.5, 1.3, 4.1, 10.2, 20.5, 30.6, 40.1, 50.22, 1.5 };
std::iota(json_arr.begin(), json_arr.end(), 0.5);
CHECK(json_arr == json({0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5}));
CHECK(json_arr == json({ 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5 }));
}
SECTION("char")
{
json json_arr = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', '0', '1'};
json json_arr = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', '0', '1' };
std::iota(json_arr.begin(), json_arr.end(), '0');
CHECK(json_arr == json({'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'}));
CHECK(json_arr == json({ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' }));
}
}
@ -306,7 +306,7 @@ TEST_CASE("algorithms")
SECTION("copy without if")
{
json dest_arr;
const json source_arr = {1, 2, 3, 4};
const json source_arr = { 1, 2, 3, 4 };
std::copy(source_arr.begin(), source_arr.end(), std::back_inserter(dest_arr));
@ -315,30 +315,30 @@ TEST_CASE("algorithms")
SECTION("copy if")
{
json dest_arr;
const json source_arr = {0, 3, 6, 9, 12, 15, 20};
const json source_arr = { 0, 3, 6, 9, 12, 15, 20 };
std::copy_if(source_arr.begin(), source_arr.end(), std::back_inserter(dest_arr), [](const json& _value) {
return _value.get<int>() % 3 == 0;
});
CHECK(dest_arr == json({0, 3, 6, 9, 12, 15}));
CHECK(dest_arr == json({ 0, 3, 6, 9, 12, 15 }));
}
SECTION("copy n")
{
const json source_arr = {0, 1, 2, 3, 4, 5, 6, 7};
const json source_arr = { 0, 1, 2, 3, 4, 5, 6, 7 };
json dest_arr;
const unsigned char numToCopy = 2;
std::copy_n(source_arr.begin(), numToCopy, std::back_inserter(dest_arr));
CHECK(dest_arr == json{0, 1});
CHECK(dest_arr == json{ 0, 1 });
}
SECTION("copy n chars")
{
const json source_arr = {'1', '2', '3', '4', '5', '6', '7'};
const json source_arr = { '1', '2', '3', '4', '5', '6', '7' };
json dest_arr;
const unsigned char numToCopy = 4;
std::copy_n(source_arr.begin(), numToCopy, std::back_inserter(dest_arr));
CHECK(dest_arr == json{'1', '2', '3', '4'});
CHECK(dest_arr == json{ '1', '2', '3', '4' });
}
}
}

View File

@ -169,7 +169,7 @@ TEST_CASE("controlled bad_alloc")
SECTION("basic_json(const CompatibleObjectType&)")
{
next_construct_fails = false;
const std::map<std::string, std::string> v{{"foo", "bar"}};
const std::map<std::string, std::string> v{ { "foo", "bar" } };
CHECK_NOTHROW(my_json(v));
next_construct_fails = true;
CHECK_THROWS_AS(my_json(v), std::bad_alloc&);
@ -179,7 +179,7 @@ TEST_CASE("controlled bad_alloc")
SECTION("basic_json(const CompatibleArrayType&)")
{
next_construct_fails = false;
const std::vector<std::string> v{"foo", "bar", "baz"};
const std::vector<std::string> v{ "foo", "bar", "baz" };
CHECK_NOTHROW(my_json(v));
next_construct_fails = true;
CHECK_THROWS_AS(my_json(v), std::bad_alloc&);

View File

@ -154,7 +154,7 @@ class alt_string
alt_string substr(std::size_t pos = 0, std::size_t count = npos) const
{
const std::string s = str_impl.substr(pos, count);
return {s.data(), s.size()};
return { s.data(), s.size() };
}
alt_string& replace(std::size_t pos, std::size_t count, const alt_string& str)
@ -222,14 +222,14 @@ TEST_CASE("alternative string type")
{
alt_json doc;
doc["list"] = {1, 0, 2};
doc["list"] = { 1, 0, 2 };
alt_string dump = doc.dump();
CHECK(dump == R"({"list":[1,0,2]})");
}
{
alt_json doc;
doc["object"] = {{"currency", "USD"}, {"value", 42.99}};
doc["object"] = { { "currency", "USD" }, { "value", 42.99 } };
alt_string dump = doc.dump();
CHECK(dump == R"({"object":{"currency":"USD","value":42.99}})");
}

View File

@ -142,7 +142,7 @@ TEST_CASE("Binary Formats" * doctest::skip())
const auto bjdata_1_size = json::to_bjdata(j).size();
const auto bjdata_2_size = json::to_bjdata(j, true).size();
const auto bjdata_3_size = json::to_bjdata(j, true, true).size();
const auto bson_size = json::to_bson({{"", j}}).size(); // wrap array in object for BSON
const auto bson_size = json::to_bson({ { "", j } }).size(); // wrap array in object for BSON
const auto cbor_size = json::to_cbor(j).size();
const auto msgpack_size = json::to_msgpack(j).size();
const auto ubjson_1_size = json::to_ubjson(j).size();

File diff suppressed because it is too large Load Diff

View File

@ -74,7 +74,7 @@ TEST_CASE("BSON")
SECTION("array")
{
json const j = std::vector<int>{1, 2, 3, 4, 5, 6, 7};
json const j = std::vector<int>{ 1, 2, 3, 4, 5, 6, 7 };
CHECK_THROWS_WITH_AS(json::to_bson(j),
"[json.exception.type_error.317] to serialize to BSON, top-level type must be object, but is array",
json::type_error&);
@ -83,7 +83,7 @@ TEST_CASE("BSON")
SECTION("keys containing code-point U+0000 cannot be serialized to BSON")
{
json const j = {{std::string("en\0try", 6), true}};
json const j = { { std::string("en\0try", 6), true } };
#if JSON_DIAGNOSTICS
CHECK_THROWS_WITH_AS(json::to_bson(j),
"[json.exception.out_of_range.409] (/en) BSON key cannot contain code point U+0000 (at byte 2)",
@ -96,7 +96,7 @@ TEST_CASE("BSON")
SECTION("string length must be at least 1")
{
// from https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=11175
std::vector<std::uint8_t> const v = {0x20, 0x20, 0x20, 0x20, 0x02, 0x00, 0x00, 0x00, 0x00, 0x80};
std::vector<std::uint8_t> const v = { 0x20, 0x20, 0x20, 0x20, 0x02, 0x00, 0x00, 0x00, 0x00, 0x80 };
json _;
CHECK_THROWS_WITH_AS(
_ = json::from_bson(v),
@ -128,20 +128,13 @@ TEST_CASE("BSON")
SECTION("non-empty object with bool")
{
json const j = {{"entry", true}};
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
};
@ -156,20 +149,13 @@ TEST_CASE("BSON")
SECTION("non-empty object with bool")
{
json const j = {{"entry", false}};
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
};
@ -184,7 +170,7 @@ TEST_CASE("BSON")
SECTION("non-empty object with double")
{
json const j = {{"entry", 4.2}};
json const j = { { "entry", 4.2 } };
std::vector<std::uint8_t> const expected = {
0x14, 0x00, 0x00,
@ -204,7 +190,7 @@ TEST_CASE("BSON")
SECTION("non-empty object with string")
{
json const j = {{"entry", "bsonstr"}};
json const j = { { "entry", "bsonstr" } };
std::vector<std::uint8_t> const expected = {
0x18, 0x00, 0x00,
@ -224,20 +210,13 @@ TEST_CASE("BSON")
SECTION("non-empty object with null member")
{
json const j = {{"entry", nullptr}};
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
};
@ -251,24 +230,13 @@ TEST_CASE("BSON")
SECTION("non-empty object with integer (32-bit) member")
{
json const j = {{"entry", std::int32_t{0x12345678}}};
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
};
@ -282,7 +250,7 @@ TEST_CASE("BSON")
SECTION("non-empty object with integer (64-bit) member")
{
json const j = {{"entry", std::int64_t{0x1234567804030201}}};
json const j = { { "entry", std::int64_t{ 0x1234567804030201 } } };
std::vector<std::uint8_t> const expected = {
0x14, 0x00, 0x00,
@ -302,24 +270,13 @@ TEST_CASE("BSON")
SECTION("non-empty object with negative integer (32-bit) member")
{
json const j = {{"entry", std::int32_t{-1}}};
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
};
@ -333,24 +290,13 @@ TEST_CASE("BSON")
SECTION("non-empty object with negative integer (64-bit) member")
{
json const j = {{"entry", std::int64_t{-1}}};
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
};
@ -365,7 +311,7 @@ TEST_CASE("BSON")
SECTION("non-empty object with unsigned integer (64-bit) member")
{
// directly encoding uint64 is not supported in bson (only for timestamp values)
json const j = {{"entry", std::uint64_t{0x1234567804030201}}};
json const j = { { "entry", std::uint64_t{ 0x1234567804030201 } } };
std::vector<std::uint8_t> const expected = {
0x14, 0x00, 0x00,
@ -385,24 +331,13 @@ TEST_CASE("BSON")
SECTION("non-empty object with small unsigned integer member")
{
json const j = {{"entry", std::uint64_t{0x42}}};
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
};
@ -416,7 +351,7 @@ TEST_CASE("BSON")
SECTION("non-empty object with object member")
{
json const j = {{"entry", json::object()}};
json const j = { { "entry", json::object() } };
std::vector<std::uint8_t> const expected = {
0x11,
@ -451,7 +386,7 @@ TEST_CASE("BSON")
SECTION("non-empty object with array member")
{
json const j = {{"entry", json::array()}};
json const j = { { "entry", json::array() } };
std::vector<std::uint8_t> const expected = {
0x11,
@ -486,7 +421,7 @@ TEST_CASE("BSON")
SECTION("non-empty object with non-empty array member")
{
json const j = {{"entry", json::array({1, 2, 3, 4, 5, 6, 7, 8})}};
json const j = { { "entry", json::array({ 1, 2, 3, 4, 5, 6, 7, 8 }) } };
std::vector<std::uint8_t> const expected = {
0x49, 0x00, 0x00,
@ -516,7 +451,7 @@ TEST_CASE("BSON")
{
const size_t N = 10;
const auto s = std::vector<std::uint8_t>(N, 'x');
json const j = {{"entry", json::binary(s, 0)}};
json const j = { { "entry", json::binary(s, 0) } };
std::vector<std::uint8_t> const expected = {
0x1B, 0x00, 0x00,
@ -543,8 +478,8 @@ TEST_CASE("BSON")
SECTION("non-empty object with binary member with subtype")
{
// an MD5 hash
const std::vector<std::uint8_t> md5hash = {0xd7, 0x7e, 0x27, 0x54, 0xbe, 0x12, 0x37, 0xfe, 0xd6, 0x0c, 0x33, 0x98, 0x30, 0x3b, 0x8d, 0xc4};
json const j = {{"entry", json::binary(md5hash, 5)}};
const std::vector<std::uint8_t> md5hash = { 0xd7, 0x7e, 0x27, 0x54, 0xbe, 0x12, 0x37, 0xfe, 0xd6, 0x0c, 0x33, 0x98, 0x30, 0x3b, 0x8d, 0xc4 };
json const j = { { "entry", json::binary(md5hash, 5) } };
std::vector<std::uint8_t> const expected = {
0x21, 0x00, 0x00,
@ -571,9 +506,9 @@ TEST_CASE("BSON")
SECTION("Some more complex document")
{
// directly encoding uint64 is not supported in bson (only for timestamp values)
json const j = {{"double", 42.5}, {"entry", 4.2}, {"number", 12345}, {"object", {{"string", "value"}}}};
json const j = { { "double", 42.5 }, { "entry", 4.2 }, { "number", 12345 }, { "object", { { "string", "value" } } } };
std::vector<std::uint8_t> const expected = {/*size */ 0x4f,
std::vector<std::uint8_t> const expected = { /*size */ 0x4f,
0x00,
0x00,
0x00,
@ -651,7 +586,7 @@ TEST_CASE("BSON")
'e',
0,
/*entry: obj-term.*/ 0x00,
/*obj-term*/ 0x00};
/*obj-term*/ 0x00 };
const auto result = json::to_bson(j);
CHECK(result == expected);
@ -666,10 +601,10 @@ TEST_CASE("BSON")
{
SECTION("Example 1")
{
std::vector<std::uint8_t> input = {0x16, 0x00, 0x00, 0x00, 0x02, 'h', 'e', 'l', 'l', 'o', 0x00,
0x06, 0x00, 0x00, 0x00, 'w', 'o', 'r', 'l', 'd', 0x00, 0x00};
std::vector<std::uint8_t> input = { 0x16, 0x00, 0x00, 0x00, 0x02, 'h', 'e', 'l', 'l', 'o', 0x00,
0x06, 0x00, 0x00, 0x00, 'w', 'o', 'r', 'l', 'd', 0x00, 0x00 };
json parsed = json::from_bson(input);
json expected = {{"hello", "world"}};
json expected = { { "hello", "world" } };
CHECK(parsed == expected);
auto dumped = json::to_bson(parsed);
CHECK(dumped == input);
@ -678,11 +613,11 @@ TEST_CASE("BSON")
SECTION("Example 2")
{
std::vector<std::uint8_t> input = {0x31, 0x00, 0x00, 0x00, 0x04, 'B', 'S', 'O', 'N', 0x00, 0x26, 0x00, 0x00, 0x00, 0x02, 0x30, 0x00,
std::vector<std::uint8_t> input = { 0x31, 0x00, 0x00, 0x00, 0x04, 'B', 'S', 'O', 'N', 0x00, 0x26, 0x00, 0x00, 0x00, 0x02, 0x30, 0x00,
0x08, 0x00, 0x00, 0x00, 'a', 'w', 'e', 's', 'o', 'm', 'e', 0x00, 0x01, 0x31, 0x00, 0x33, 0x33,
0x33, 0x33, 0x33, 0x33, 0x14, 0x40, 0x10, 0x32, 0x00, 0xc2, 0x07, 0x00, 0x00, 0x00, 0x00};
0x33, 0x33, 0x33, 0x33, 0x14, 0x40, 0x10, 0x32, 0x00, 0xc2, 0x07, 0x00, 0x00, 0x00, 0x00 };
json parsed = json::from_bson(input);
json expected = {{"BSON", {"awesome", 5.05, 1986}}};
json expected = { { "BSON", { "awesome", 5.05, 1986 } } };
CHECK(parsed == expected);
auto dumped = json::to_bson(parsed);
CHECK(dumped == input);
@ -693,9 +628,9 @@ TEST_CASE("BSON")
TEST_CASE("BSON input/output_adapters")
{
json json_representation = {{"double", 42.5}, {"entry", 4.2}, {"number", 12345}, {"object", {{"string", "value"}}}};
json json_representation = { { "double", 42.5 }, { "entry", 4.2 }, { "number", 12345 }, { "object", { { "string", "value" } } } };
std::vector<std::uint8_t> const bson_representation = {/*size */ 0x4f,
std::vector<std::uint8_t> const bson_representation = { /*size */ 0x4f,
0x00,
0x00,
0x00,
@ -773,7 +708,7 @@ TEST_CASE("BSON input/output_adapters")
'e',
0,
/*entry: obj-term.*/ 0x00,
/*obj-term*/ 0x00};
/*obj-term*/ 0x00 };
json j2;
CHECK_NOTHROW(j2 = json::from_bson(bson_representation));
@ -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
};
@ -982,7 +912,7 @@ TEST_CASE("Incomplete BSON Input")
{
SECTION("key")
{
json const j = {{"key", "value"}};
json const j = { { "key", "value" } };
auto bson_vec = json::to_bson(j);
SaxCountdown scp(2);
CHECK(!json::sax_parse(bson_vec, &scp, json::input_format_t::bson));
@ -990,7 +920,7 @@ TEST_CASE("Incomplete BSON Input")
SECTION("array")
{
json const j = {{"entry", json::array()}};
json const j = { { "entry", json::array() } };
auto bson_vec = json::to_bson(j);
SaxCountdown scp(2);
CHECK(!json::sax_parse(bson_vec, &scp, json::input_format_t::bson));
@ -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
};
@ -1074,7 +997,7 @@ TEST_CASE("BSON numerical data")
{
CAPTURE(i)
json const j = {{"entry", i}};
json const j = { { "entry", i } };
CHECK(j.at("entry").is_number_integer());
std::uint64_t const iu = *reinterpret_cast<const std::uint64_t*>(&i);
@ -1114,7 +1037,7 @@ TEST_CASE("BSON numerical data")
SECTION("signed std::int32_t: INT32_MIN .. INT32_MAX")
{
std::vector<int32_t> const numbers{(std::numeric_limits<int32_t>::min)(),
std::vector<int32_t> const numbers{ (std::numeric_limits<int32_t>::min)(),
-2147483647L,
-1000000000L,
-100000000L,
@ -1138,13 +1061,13 @@ TEST_CASE("BSON numerical data")
100000000L,
1000000000L,
2147483646L,
(std::numeric_limits<int32_t>::max)()};
(std::numeric_limits<int32_t>::max)() };
for (const auto i : numbers)
{
CAPTURE(i)
json const j = {{"entry", i}};
json const j = { { "entry", i } };
CHECK(j.at("entry").is_number_integer());
std::uint32_t const iu = *reinterpret_cast<const std::uint32_t*>(&i);
@ -1198,7 +1121,7 @@ TEST_CASE("BSON numerical data")
{
CAPTURE(i)
json const j = {{"entry", i}};
json const j = { { "entry", i } };
CHECK(j.at("entry").is_number_integer());
std::uint64_t const iu = *reinterpret_cast<const std::uint64_t*>(&i);
@ -1241,7 +1164,7 @@ TEST_CASE("BSON numerical data")
{
SECTION("unsigned std::uint64_t: 0 .. INT32_MAX")
{
std::vector<std::uint64_t> const numbers{0ULL,
std::vector<std::uint64_t> const numbers{ 0ULL,
1ULL,
10ULL,
100ULL,
@ -1253,13 +1176,13 @@ TEST_CASE("BSON numerical data")
100000000ULL,
1000000000ULL,
2147483646ULL,
static_cast<std::uint64_t>((std::numeric_limits<int32_t>::max)())};
static_cast<std::uint64_t>((std::numeric_limits<int32_t>::max)()) };
for (const auto i : numbers)
{
CAPTURE(i)
json const j = {{"entry", i}};
json const j = { { "entry", i } };
auto iu = i;
std::vector<std::uint8_t> const expected_bson = {
@ -1315,7 +1238,7 @@ TEST_CASE("BSON numerical data")
{
CAPTURE(i)
json const j = {{"entry", i}};
json const j = { { "entry", i } };
auto iu = i;
std::vector<std::uint8_t> const expected_bson = {
@ -1367,7 +1290,7 @@ TEST_CASE("BSON numerical data")
{
CAPTURE(i)
json const j = {{"entry", i}};
json const j = { { "entry", i } };
auto iu = i;
std::vector<std::uint8_t> const expected_bson = {
@ -1413,11 +1336,11 @@ TEST_CASE("BSON roundtrips" * doctest::skip())
{
SECTION("reference files")
{
for (const std::string filename : {TEST_DATA_DIRECTORY "/json.org/1.json",
for (const std::string filename : { TEST_DATA_DIRECTORY "/json.org/1.json",
TEST_DATA_DIRECTORY "/json.org/2.json",
TEST_DATA_DIRECTORY "/json.org/3.json",
TEST_DATA_DIRECTORY "/json.org/4.json",
TEST_DATA_DIRECTORY "/json.org/5.json"})
TEST_DATA_DIRECTORY "/json.org/5.json" })
{
CAPTURE(filename)
@ -1460,7 +1383,7 @@ TEST_CASE("BSON roundtrips" * doctest::skip())
// parse BSON file
auto packed = utils::read_binary_file(filename + ".bson");
json j2;
CHECK_NOTHROW(j2 = json::from_bson({packed.data(), packed.size()}));
CHECK_NOTHROW(j2 = json::from_bson({ packed.data(), packed.size() }));
// compare parsed JSON values
CHECK(j1 == j2);

View File

@ -45,7 +45,7 @@ TEST_CASE("byte_container_with_subtype")
SECTION("comparisons")
{
std::vector<std::uint8_t> const bytes = {{0xCA, 0xFE, 0xBA, 0xBE}};
std::vector<std::uint8_t> const bytes = { { 0xCA, 0xFE, 0xBA, 0xBE } };
nlohmann::byte_container_with_subtype<std::vector<std::uint8_t>> container1;
nlohmann::byte_container_with_subtype<std::vector<std::uint8_t>> container2({}, 42);
nlohmann::byte_container_with_subtype<std::vector<std::uint8_t>> container3(bytes);

View File

@ -74,8 +74,8 @@ TEST_CASE("capacity")
SECTION("filled array")
{
json j = {1, 2, 3}; // NOLINT(misc-const-correctness)
const json j_const = {1, 2, 3};
json j = { 1, 2, 3 }; // NOLINT(misc-const-correctness)
const json j_const = { 1, 2, 3 };
SECTION("result of empty")
{
@ -113,8 +113,8 @@ TEST_CASE("capacity")
SECTION("filled object")
{
json j = {{"one", 1}, {"two", 2}, {"three", 3}}; // NOLINT(misc-const-correctness)
const json j_const = {{"one", 1}, {"two", 2}, {"three", 3}};
json j = { { "one", 1 }, { "two", 2 }, { "three", 3 } }; // NOLINT(misc-const-correctness)
const json j_const = { { "one", 1 }, { "two", 2 }, { "three", 3 } };
SECTION("result of empty")
{
@ -269,8 +269,8 @@ TEST_CASE("capacity")
SECTION("filled array")
{
json j = {1, 2, 3}; // NOLINT(misc-const-correctness)
const json j_const = {1, 2, 3};
json j = { 1, 2, 3 }; // NOLINT(misc-const-correctness)
const json j_const = { 1, 2, 3 };
SECTION("result of size")
{
@ -312,8 +312,8 @@ TEST_CASE("capacity")
SECTION("filled object")
{
json j = {{"one", 1}, {"two", 2}, {"three", 3}}; // NOLINT(misc-const-correctness)
const json j_const = {{"one", 1}, {"two", 2}, {"three", 3}};
json j = { { "one", 1 }, { "two", 2 }, { "three", 3 } }; // NOLINT(misc-const-correctness)
const json j_const = { { "one", 1 }, { "two", 2 }, { "three", 3 } };
SECTION("result of size")
{
@ -454,8 +454,8 @@ TEST_CASE("capacity")
SECTION("filled array")
{
json j = {1, 2, 3}; // NOLINT(misc-const-correctness)
const json j_const = {1, 2, 3};
json j = { 1, 2, 3 }; // NOLINT(misc-const-correctness)
const json j_const = { 1, 2, 3 };
SECTION("result of max_size")
{
@ -481,8 +481,8 @@ TEST_CASE("capacity")
SECTION("filled object")
{
json j = {{"one", 1}, {"two", 2}, {"three", 3}}; // NOLINT(misc-const-correctness)
const json j_const = {{"one", 1}, {"two", 2}, {"three", 3}};
json j = { { "one", 1 }, { "two", 2 }, { "three", 3 } }; // NOLINT(misc-const-correctness)
const json j_const = { { "one", 1 }, { "two", 2 }, { "three", 3 } };
SECTION("result of max_size")
{

File diff suppressed because it is too large Load Diff

View File

@ -141,14 +141,14 @@ TEST_CASE("const_iterator class")
SECTION("object")
{
json const j({{"foo", "bar"}});
json const j({ { "foo", "bar" } });
json::const_iterator const it = j.cbegin();
CHECK(*it == json("bar"));
}
SECTION("array")
{
json const j({1, 2, 3, 4});
json const j({ 1, 2, 3, 4 });
json::const_iterator const it = j.cbegin();
CHECK(*it == json(1));
}
@ -174,14 +174,14 @@ TEST_CASE("const_iterator class")
SECTION("object")
{
json const j({{"foo", "bar"}});
json const j({ { "foo", "bar" } });
json::const_iterator const it = j.cbegin();
CHECK(std::string(it->type_name()) == "string");
}
SECTION("array")
{
json const j({1, 2, 3, 4});
json const j({ 1, 2, 3, 4 });
json::const_iterator const it = j.cbegin();
CHECK(std::string(it->type_name()) == "number");
}
@ -214,7 +214,7 @@ TEST_CASE("const_iterator class")
SECTION("object")
{
json const j({{"foo", "bar"}});
json const j({ { "foo", "bar" } });
json::const_iterator it = j.cbegin();
CHECK((it.m_it.object_iterator == it.m_object->m_data.m_value.object->begin()));
it++;
@ -223,7 +223,7 @@ TEST_CASE("const_iterator class")
SECTION("array")
{
json const j({1, 2, 3, 4});
json const j({ 1, 2, 3, 4 });
json::const_iterator it = j.cbegin();
CHECK((it.m_it.array_iterator == it.m_object->m_data.m_value.array->begin()));
it++;
@ -265,7 +265,7 @@ TEST_CASE("const_iterator class")
SECTION("object")
{
json const j({{"foo", "bar"}});
json const j({ { "foo", "bar" } });
json::const_iterator it = j.cbegin();
CHECK((it.m_it.object_iterator == it.m_object->m_data.m_value.object->begin()));
++it;
@ -274,7 +274,7 @@ TEST_CASE("const_iterator class")
SECTION("array")
{
json const j({1, 2, 3, 4});
json const j({ 1, 2, 3, 4 });
json::const_iterator it = j.cbegin();
CHECK((it.m_it.array_iterator == it.m_object->m_data.m_value.array->begin()));
++it;
@ -314,7 +314,7 @@ TEST_CASE("const_iterator class")
SECTION("object")
{
json const j({{"foo", "bar"}});
json const j({ { "foo", "bar" } });
json::const_iterator it = j.cend();
CHECK((it.m_it.object_iterator == it.m_object->m_data.m_value.object->end()));
it--;
@ -323,7 +323,7 @@ TEST_CASE("const_iterator class")
SECTION("array")
{
json const j({1, 2, 3, 4});
json const j({ 1, 2, 3, 4 });
json::const_iterator it = j.cend();
CHECK((it.m_it.array_iterator == it.m_object->m_data.m_value.array->end()));
it--;
@ -363,7 +363,7 @@ TEST_CASE("const_iterator class")
SECTION("object")
{
json const j({{"foo", "bar"}});
json const j({ { "foo", "bar" } });
json::const_iterator it = j.cend();
CHECK((it.m_it.object_iterator == it.m_object->m_data.m_value.object->end()));
--it;
@ -372,7 +372,7 @@ TEST_CASE("const_iterator class")
SECTION("array")
{
json const j({1, 2, 3, 4});
json const j({ 1, 2, 3, 4 });
json::const_iterator it = j.cend();
CHECK((it.m_it.array_iterator == it.m_object->m_data.m_value.array->end()));
--it;

View File

@ -131,14 +131,14 @@ TEST_CASE("iterator class")
SECTION("object")
{
json j({{"foo", "bar"}});
json j({ { "foo", "bar" } });
json::iterator const it = j.begin();
CHECK(*it == json("bar"));
}
SECTION("array")
{
json j({1, 2, 3, 4});
json j({ 1, 2, 3, 4 });
json::iterator const it = j.begin();
CHECK(*it == json(1));
}
@ -164,14 +164,14 @@ TEST_CASE("iterator class")
SECTION("object")
{
json j({{"foo", "bar"}});
json j({ { "foo", "bar" } });
json::iterator const it = j.begin();
CHECK(std::string(it->type_name()) == "string");
}
SECTION("array")
{
json j({1, 2, 3, 4});
json j({ 1, 2, 3, 4 });
json::iterator const it = j.begin();
CHECK(std::string(it->type_name()) == "number");
}
@ -204,7 +204,7 @@ TEST_CASE("iterator class")
SECTION("object")
{
json j({{"foo", "bar"}});
json j({ { "foo", "bar" } });
json::iterator it = j.begin();
CHECK((it.m_it.object_iterator == it.m_object->m_data.m_value.object->begin()));
it++;
@ -213,7 +213,7 @@ TEST_CASE("iterator class")
SECTION("array")
{
json j({1, 2, 3, 4});
json j({ 1, 2, 3, 4 });
json::iterator it = j.begin();
CHECK((it.m_it.array_iterator == it.m_object->m_data.m_value.array->begin()));
it++;
@ -255,7 +255,7 @@ TEST_CASE("iterator class")
SECTION("object")
{
json j({{"foo", "bar"}});
json j({ { "foo", "bar" } });
json::iterator it = j.begin();
CHECK((it.m_it.object_iterator == it.m_object->m_data.m_value.object->begin()));
++it;
@ -264,7 +264,7 @@ TEST_CASE("iterator class")
SECTION("array")
{
json j({1, 2, 3, 4});
json j({ 1, 2, 3, 4 });
json::iterator it = j.begin();
CHECK((it.m_it.array_iterator == it.m_object->m_data.m_value.array->begin()));
++it;
@ -304,7 +304,7 @@ TEST_CASE("iterator class")
SECTION("object")
{
json j({{"foo", "bar"}});
json j({ { "foo", "bar" } });
json::iterator it = j.end();
CHECK((it.m_it.object_iterator == it.m_object->m_data.m_value.object->end()));
it--;
@ -313,7 +313,7 @@ TEST_CASE("iterator class")
SECTION("array")
{
json j({1, 2, 3, 4});
json j({ 1, 2, 3, 4 });
json::iterator it = j.end();
CHECK((it.m_it.array_iterator == it.m_object->m_data.m_value.array->end()));
it--;
@ -353,7 +353,7 @@ TEST_CASE("iterator class")
SECTION("object")
{
json j({{"foo", "bar"}});
json j({ { "foo", "bar" } });
json::iterator it = j.end();
CHECK((it.m_it.object_iterator == it.m_object->m_data.m_value.object->end()));
--it;
@ -362,7 +362,7 @@ TEST_CASE("iterator class")
SECTION("array")
{
json j({1, 2, 3, 4});
json j({ 1, 2, 3, 4 });
json::iterator it = j.end();
CHECK((it.m_it.array_iterator == it.m_object->m_data.m_value.array->end()));
--it;

View File

@ -333,7 +333,7 @@ TEST_CASE("parser class")
SECTION("nonempty array")
{
CHECK(parser_helper("[true, false, null]") == json({true, false, nullptr}));
CHECK(parser_helper("[true, false, null]") == json({ true, false, nullptr }));
}
}
@ -347,7 +347,7 @@ TEST_CASE("parser class")
SECTION("nonempty object")
{
CHECK(parser_helper("{\"\": true, \"one\": 1, \"two\": null}") == json({{"", true}, {"one", 1}, {"two", nullptr}}));
CHECK(parser_helper("{\"\": true, \"one\": 1, \"two\": null}") == json({ { "", true }, { "one", 1 }, { "two", nullptr } }));
}
}
@ -1675,13 +1675,13 @@ TEST_CASE("parser class")
return true;
});
CHECK(j_object == json({{"foo", 2}, {"bar", {{"baz", 1}}}}));
CHECK(j_object == json({ { "foo", 2 }, { "bar", { { "baz", 1 } } } }));
json j_array = json::parse(s_array, [](int /*unused*/, json::parse_event_t /*unused*/, const json& /*unused*/) noexcept {
return true;
});
CHECK(j_array == json({1, 2, {3, 4, 5}, 4, 5}));
CHECK(j_array == json({ 1, 2, { 3, 4, 5 }, 4, 5 }));
}
SECTION("filter everything")
@ -1708,13 +1708,13 @@ TEST_CASE("parser class")
return event != json::parse_event_t::value || j != json(2);
});
CHECK(j_object == json({{"bar", {{"baz", 1}}}}));
CHECK(j_object == json({ { "bar", { { "baz", 1 } } } }));
json j_array = json::parse(s_array, [](int /*unused*/, json::parse_event_t event, const json& j) noexcept {
return event != json::parse_event_t::value || j != json(2);
});
CHECK(j_array == json({1, {3, 4, 5}, 4, 5}));
CHECK(j_array == json({ 1, { 3, 4, 5 }, 4, 5 }));
}
SECTION("filter object in array")
@ -1725,7 +1725,7 @@ TEST_CASE("parser class")
// the specified object will be discarded, and removed.
CHECK(j_filtered1.size() == 2);
CHECK(j_filtered1 == json({1, {{"qux", "baz"}}}));
CHECK(j_filtered1 == json({ 1, { { "qux", "baz" } } }));
json j_filtered2 = json::parse(structured_array, [](int /*unused*/, json::parse_event_t e, const json& /*parsed*/) noexcept {
return e != json::parse_event_t::object_end;
@ -1733,7 +1733,7 @@ TEST_CASE("parser class")
// removed all objects in array.
CHECK(j_filtered2.size() == 1);
CHECK(j_filtered2 == json({1}));
CHECK(j_filtered2 == json({ 1 }));
}
SECTION("filter specific events")
@ -1753,7 +1753,7 @@ TEST_CASE("parser class")
});
// the first completed object will be discarded
CHECK(j_object == json({{"foo", 2}}));
CHECK(j_object == json({ { "foo", 2 } }));
}
{
@ -1769,7 +1769,7 @@ TEST_CASE("parser class")
});
// the first completed array will be discarded
CHECK(j_array == json({1, 2, 4, 5}));
CHECK(j_array == json({ 1, 2, 4, 5 }));
}
}
}
@ -1796,7 +1796,7 @@ TEST_CASE("parser class")
{
SECTION("from std::vector")
{
std::vector<uint8_t> v = {'t', 'r', 'u', 'e'};
std::vector<uint8_t> v = { 't', 'r', 'u', 'e' };
json j;
json::parser(nlohmann::detail::input_adapter(std::begin(v), std::end(v))).parse(true, j);
CHECK(j == json(true));
@ -1804,7 +1804,7 @@ TEST_CASE("parser class")
SECTION("from std::array")
{
std::array<uint8_t, 5> v{{'t', 'r', 'u', 'e'}};
std::array<uint8_t, 5> v{ { 't', 'r', 'u', 'e' } };
json j;
json::parser(nlohmann::detail::input_adapter(std::begin(v), std::end(v))).parse(true, j);
CHECK(j == json(true));
@ -1812,7 +1812,7 @@ TEST_CASE("parser class")
SECTION("from array")
{
uint8_t v[] = {'t', 'r', 'u', 'e'}; // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays)
uint8_t v[] = { 't', 'r', 'u', 'e' }; // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays)
json j;
json::parser(nlohmann::detail::input_adapter(std::begin(v), std::end(v))).parse(true, j);
CHECK(j == json(true));
@ -1825,7 +1825,7 @@ TEST_CASE("parser class")
SECTION("from std::string")
{
std::string v = {'t', 'r', 'u', 'e'};
std::string v = { 't', 'r', 'u', 'e' };
json j;
json::parser(nlohmann::detail::input_adapter(std::begin(v), std::end(v))).parse(true, j);
CHECK(j == json(true));
@ -1833,7 +1833,7 @@ TEST_CASE("parser class")
SECTION("from std::initializer_list")
{
std::initializer_list<uint8_t> const v = {'t', 'r', 'u', 'e'};
std::initializer_list<uint8_t> const v = { 't', 'r', 'u', 'e' };
json j;
json::parser(nlohmann::detail::input_adapter(std::begin(v), std::end(v))).parse(true, j);
CHECK(j == json(true));
@ -1841,7 +1841,7 @@ TEST_CASE("parser class")
SECTION("from std::valarray")
{
std::valarray<uint8_t> v = {'t', 'r', 'u', 'e'};
std::valarray<uint8_t> v = { 't', 'r', 'u', 'e' };
json j;
json::parser(nlohmann::detail::input_adapter(std::begin(v), std::end(v))).parse(true, j);
CHECK(j == json(true));

View File

@ -87,29 +87,23 @@ 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
{f_, _t, _t, _t, _t, _t, _t, _t, _t, f_}, // 0
{f_, f_, _t, _t, _t, _t, _t, _t, _t, f_}, // 1
{f_, f_, f_, f_, f_, _t, _t, _t, _t, f_}, // 2
{f_, f_, f_, f_, f_, _t, _t, _t, _t, f_}, // 3
{f_, f_, f_, f_, f_, _t, _t, _t, _t, f_}, // 4
{f_, f_, f_, f_, f_, f_, _t, _t, _t, f_}, // 5
{f_, f_, f_, f_, f_, f_, f_, _t, _t, f_}, // 6
{f_, f_, f_, f_, f_, f_, f_, f_, _t, f_}, // 7
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 8
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 9
{ f_, _t, _t, _t, _t, _t, _t, _t, _t, f_ }, // 0
{ f_, f_, _t, _t, _t, _t, _t, _t, _t, f_ }, // 1
{ f_, f_, f_, f_, f_, _t, _t, _t, _t, f_ }, // 2
{ f_, f_, f_, f_, f_, _t, _t, _t, _t, f_ }, // 3
{ f_, f_, f_, f_, f_, _t, _t, _t, _t, f_ }, // 4
{ f_, f_, f_, f_, f_, f_, _t, _t, _t, f_ }, // 5
{ f_, f_, f_, f_, f_, f_, f_, _t, _t, f_ }, // 6
{ f_, f_, f_, f_, f_, f_, f_, f_, _t, f_ }, // 7
{ f_, f_, f_, f_, f_, f_, f_, f_, f_, f_ }, // 8
{ f_, f_, f_, f_, f_, f_, f_, f_, f_, f_ }, // 9
};
SECTION("comparison: less")
@ -139,16 +133,16 @@ TEST_CASE("lexicographical comparison operators")
{
std::vector<std::vector<std::partial_ordering>> expected = {
//0 1 2 3 4 5 6 7 8 9
{eq, lt, lt, lt, lt, lt, lt, lt, lt, un}, // 0
{gt, eq, lt, lt, lt, lt, lt, lt, lt, un}, // 1
{gt, gt, eq, eq, eq, lt, lt, lt, lt, un}, // 2
{gt, gt, eq, eq, eq, lt, lt, lt, lt, un}, // 3
{gt, gt, eq, eq, eq, lt, lt, lt, lt, un}, // 4
{gt, gt, gt, gt, gt, eq, lt, lt, lt, un}, // 5
{gt, gt, gt, gt, gt, gt, eq, lt, lt, un}, // 6
{gt, gt, gt, gt, gt, gt, gt, eq, lt, un}, // 7
{gt, gt, gt, gt, gt, gt, gt, gt, eq, un}, // 8
{un, un, un, un, un, un, un, un, un, un}, // 9
{ eq, lt, lt, lt, lt, lt, lt, lt, lt, un }, // 0
{ gt, eq, lt, lt, lt, lt, lt, lt, lt, un }, // 1
{ gt, gt, eq, eq, eq, lt, lt, lt, lt, un }, // 2
{ gt, gt, eq, eq, eq, lt, lt, lt, lt, un }, // 3
{ gt, gt, eq, eq, eq, lt, lt, lt, lt, un }, // 4
{ gt, gt, gt, gt, gt, eq, lt, lt, lt, un }, // 5
{ gt, gt, gt, gt, gt, gt, eq, lt, lt, un }, // 6
{ gt, gt, gt, gt, gt, gt, gt, eq, lt, un }, // 7
{ gt, gt, gt, gt, gt, gt, gt, gt, eq, un }, // 8
{ un, un, un, un, un, un, un, un, un, un }, // 9
};
// check expected partial_ordering against expected boolean
@ -197,94 +191,94 @@ TEST_CASE("lexicographical comparison operators")
"bar", // 10 11
true,
false, // 12 13
{1, 2, 3},
{"one", "two", "three"}, // 14 15
{{"first", 1}, {"second", 2}},
{{"a", "A"}, {"b", {"B"}}}, // 16 17
json::binary({1, 2, 3}),
json::binary({1, 2, 4}), // 18 19
{ 1, 2, 3 },
{ "one", "two", "three" }, // 14 15
{ { "first", 1 }, { "second", 2 } },
{ { "a", "A" }, { "b", { "B" } } }, // 16 17
json::binary({ 1, 2, 3 }),
json::binary({ 1, 2, 4 }), // 18 19
json(json::value_t::discarded),
json(json::value_t::discarded) // 20 21
};
std::vector<std::vector<bool>> expected_eq = {
//0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
{_t, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 0
{_t, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 1
{f_, f_, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 2
{f_, f_, f_, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 3
{f_, f_, f_, f_, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 4
{f_, f_, f_, f_, f_, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 5
{f_, f_, f_, f_, f_, f_, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 6
{f_, f_, f_, f_, f_, f_, f_, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 7
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 8
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 9
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 10
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 11
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 12
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, f_, f_, f_, f_, f_, f_, f_, f_}, // 13
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, f_, f_, f_, f_, f_, f_, f_}, // 14
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, f_, f_, f_, f_, f_, f_}, // 15
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, f_, f_, f_, f_, f_}, // 16
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, f_, f_, f_, f_}, // 17
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, f_, f_, f_}, // 18
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, f_, f_}, // 19
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 20
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 21
{ _t, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_ }, // 0
{ _t, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_ }, // 1
{ f_, f_, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_ }, // 2
{ f_, f_, f_, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_ }, // 3
{ f_, f_, f_, f_, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_ }, // 4
{ f_, f_, f_, f_, f_, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_ }, // 5
{ f_, f_, f_, f_, f_, f_, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_ }, // 6
{ f_, f_, f_, f_, f_, f_, f_, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_ }, // 7
{ f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_ }, // 8
{ f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_ }, // 9
{ f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_ }, // 10
{ f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_ }, // 11
{ f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_ }, // 12
{ f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, f_, f_, f_, f_, f_, f_, f_, f_ }, // 13
{ f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, f_, f_, f_, f_, f_, f_, f_ }, // 14
{ f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, f_, f_, f_, f_, f_, f_ }, // 15
{ f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, f_, f_, f_, f_, f_ }, // 16
{ f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, f_, f_, f_, f_ }, // 17
{ f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, f_, f_, f_ }, // 18
{ f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, f_, f_ }, // 19
{ f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_ }, // 20
{ f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_ }, // 21
};
std::vector<std::vector<bool>> expected_lt = {
//0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
{f_, f_, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, f_, f_}, // 0
{f_, f_, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, f_, f_}, // 1
{f_, f_, f_, _t, _t, _t, _t, _t, f_, f_, _t, _t, f_, f_, _t, _t, _t, _t, _t, _t, f_, f_}, // 2
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_, _t, _t, _t, _t, _t, _t, f_, f_}, // 3
{f_, f_, f_, _t, f_, _t, f_, _t, f_, f_, _t, _t, f_, f_, _t, _t, _t, _t, _t, _t, f_, f_}, // 4
{f_, f_, f_, _t, f_, f_, f_, _t, f_, f_, _t, _t, f_, f_, _t, _t, _t, _t, _t, _t, f_, f_}, // 5
{f_, f_, f_, _t, _t, _t, f_, _t, f_, f_, _t, _t, f_, f_, _t, _t, _t, _t, _t, _t, f_, f_}, // 6
{f_, f_, f_, _t, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_, _t, _t, _t, _t, _t, _t, f_, f_}, // 7
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_, _t, _t, _t, _t, _t, _t, f_, f_}, // 8
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_, _t, _t, _t, _t, _t, _t, f_, f_}, // 9
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_}, // 10
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, f_, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_}, // 11
{f_, f_, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, f_, f_, _t, _t, _t, _t, _t, _t, f_, f_}, // 12
{f_, f_, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, f_, _t, _t, _t, _t, _t, _t, f_, f_}, // 13
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_, f_, _t, f_, f_, _t, _t, f_, f_}, // 14
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_}, // 15
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_, _t, _t, f_, f_, _t, _t, f_, f_}, // 16
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_, _t, _t, _t, f_, _t, _t, f_, f_}, // 17
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, f_, f_}, // 18
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 19
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 20
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 21
{ f_, f_, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, f_, f_ }, // 0
{ f_, f_, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, f_, f_ }, // 1
{ f_, f_, f_, _t, _t, _t, _t, _t, f_, f_, _t, _t, f_, f_, _t, _t, _t, _t, _t, _t, f_, f_ }, // 2
{ f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_, _t, _t, _t, _t, _t, _t, f_, f_ }, // 3
{ f_, f_, f_, _t, f_, _t, f_, _t, f_, f_, _t, _t, f_, f_, _t, _t, _t, _t, _t, _t, f_, f_ }, // 4
{ f_, f_, f_, _t, f_, f_, f_, _t, f_, f_, _t, _t, f_, f_, _t, _t, _t, _t, _t, _t, f_, f_ }, // 5
{ f_, f_, f_, _t, _t, _t, f_, _t, f_, f_, _t, _t, f_, f_, _t, _t, _t, _t, _t, _t, f_, f_ }, // 6
{ f_, f_, f_, _t, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_, _t, _t, _t, _t, _t, _t, f_, f_ }, // 7
{ f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_, _t, _t, _t, _t, _t, _t, f_, f_ }, // 8
{ f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_, _t, _t, _t, _t, _t, _t, f_, f_ }, // 9
{ f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_ }, // 10
{ f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, f_, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_ }, // 11
{ f_, f_, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, f_, f_, _t, _t, _t, _t, _t, _t, f_, f_ }, // 12
{ f_, f_, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, f_, _t, _t, _t, _t, _t, _t, f_, f_ }, // 13
{ f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_, f_, _t, f_, f_, _t, _t, f_, f_ }, // 14
{ f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_ }, // 15
{ f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_, _t, _t, f_, f_, _t, _t, f_, f_ }, // 16
{ f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_, _t, _t, _t, f_, _t, _t, f_, f_ }, // 17
{ f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, f_, f_ }, // 18
{ f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_ }, // 19
{ f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_ }, // 20
{ f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_ }, // 21
};
SECTION("compares unordered")
{
std::vector<std::vector<bool>> expected = {
//0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t}, // 0
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t}, // 1
{f_, f_, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t}, // 2
{f_, f_, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t}, // 3
{f_, f_, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t}, // 4
{f_, f_, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t}, // 5
{f_, f_, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t}, // 6
{f_, f_, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t}, // 7
{f_, f_, _t, _t, _t, _t, _t, _t, _t, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t}, // 8
{f_, f_, _t, _t, _t, _t, _t, _t, _t, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t}, // 9
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t}, // 10
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t}, // 11
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t}, // 12
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t}, // 13
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t}, // 14
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t}, // 15
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t}, // 16
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t}, // 17
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t}, // 18
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t}, // 19
{_t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t}, // 20
{_t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t}, // 21
{ f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t }, // 0
{ f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t }, // 1
{ f_, f_, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t }, // 2
{ f_, f_, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t }, // 3
{ f_, f_, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t }, // 4
{ f_, f_, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t }, // 5
{ f_, f_, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t }, // 6
{ f_, f_, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t }, // 7
{ f_, f_, _t, _t, _t, _t, _t, _t, _t, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t }, // 8
{ f_, f_, _t, _t, _t, _t, _t, _t, _t, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t }, // 9
{ f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t }, // 10
{ f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t }, // 11
{ f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t }, // 12
{ f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t }, // 13
{ f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t }, // 14
{ f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t }, // 15
{ f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t }, // 16
{ f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t }, // 17
{ f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t }, // 18
{ f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t }, // 19
{ _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t }, // 20
{ _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t }, // 21
};
// check if two values compare unordered as expected
@ -306,28 +300,28 @@ TEST_CASE("lexicographical comparison operators")
{
std::vector<std::vector<bool>> expected = {
//0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 0
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 1
{f_, f_, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 2
{f_, f_, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 3
{f_, f_, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 4
{f_, f_, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 5
{f_, f_, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 6
{f_, f_, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 7
{f_, f_, _t, _t, _t, _t, _t, _t, _t, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 8
{f_, f_, _t, _t, _t, _t, _t, _t, _t, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 9
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 10
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 11
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 12
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 13
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 14
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 15
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 16
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 17
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 18
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 19
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 20
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 21
{ f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_ }, // 0
{ f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_ }, // 1
{ f_, f_, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_ }, // 2
{ f_, f_, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_ }, // 3
{ f_, f_, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_ }, // 4
{ f_, f_, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_ }, // 5
{ f_, f_, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_ }, // 6
{ f_, f_, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_ }, // 7
{ f_, f_, _t, _t, _t, _t, _t, _t, _t, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_ }, // 8
{ f_, f_, _t, _t, _t, _t, _t, _t, _t, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_ }, // 9
{ f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_ }, // 10
{ f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_ }, // 11
{ f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_ }, // 12
{ f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_ }, // 13
{ f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_ }, // 14
{ f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_ }, // 15
{ f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_ }, // 16
{ f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_ }, // 17
{ f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_ }, // 18
{ f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_ }, // 19
{ f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_ }, // 20
{ f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_ }, // 21
};
// check that two values compare unordered as expected (with legacy-mode enabled)
@ -500,28 +494,28 @@ TEST_CASE("lexicographical comparison operators")
{
std::vector<std::vector<std::partial_ordering>> expected = {
//0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
{eq, eq, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, un, un}, // 0
{eq, eq, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, un, un}, // 1
{gt, gt, eq, lt, lt, lt, lt, lt, un, un, lt, lt, gt, gt, lt, lt, lt, lt, lt, lt, un, un}, // 2
{gt, gt, gt, eq, gt, gt, gt, gt, un, un, lt, lt, gt, gt, lt, lt, lt, lt, lt, lt, un, un}, // 3
{gt, gt, gt, lt, eq, lt, gt, lt, un, un, lt, lt, gt, gt, lt, lt, lt, lt, lt, lt, un, un}, // 4
{gt, gt, gt, lt, gt, eq, gt, lt, un, un, lt, lt, gt, gt, lt, lt, lt, lt, lt, lt, un, un}, // 5
{gt, gt, gt, lt, lt, lt, eq, lt, un, un, lt, lt, gt, gt, lt, lt, lt, lt, lt, lt, un, un}, // 6
{gt, gt, gt, lt, gt, gt, gt, eq, un, un, lt, lt, gt, gt, lt, lt, lt, lt, lt, lt, un, un}, // 7
{gt, gt, un, un, un, un, un, un, un, un, lt, lt, gt, gt, lt, lt, lt, lt, lt, lt, un, un}, // 8
{gt, gt, un, un, un, un, un, un, un, un, lt, lt, gt, gt, lt, lt, lt, lt, lt, lt, un, un}, // 9
{gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, eq, gt, gt, gt, gt, gt, gt, gt, lt, lt, un, un}, // 10
{gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, lt, eq, gt, gt, gt, gt, gt, gt, lt, lt, un, un}, // 11
{gt, gt, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, eq, gt, lt, lt, lt, lt, lt, lt, un, un}, // 12
{gt, gt, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, eq, lt, lt, lt, lt, lt, lt, un, un}, // 13
{gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, lt, lt, gt, gt, eq, lt, gt, gt, lt, lt, un, un}, // 14
{gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, lt, lt, gt, gt, gt, eq, gt, gt, lt, lt, un, un}, // 15
{gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, lt, lt, gt, gt, lt, lt, eq, gt, lt, lt, un, un}, // 16
{gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, lt, lt, gt, gt, lt, lt, lt, eq, lt, lt, un, un}, // 17
{gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, eq, lt, un, un}, // 18
{gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, eq, un, un}, // 19
{un, un, un, un, un, un, un, un, un, un, un, un, un, un, un, un, un, un, un, un, un, un}, // 20
{un, un, un, un, un, un, un, un, un, un, un, un, un, un, un, un, un, un, un, un, un, un}, // 21
{ eq, eq, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, un, un }, // 0
{ eq, eq, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, un, un }, // 1
{ gt, gt, eq, lt, lt, lt, lt, lt, un, un, lt, lt, gt, gt, lt, lt, lt, lt, lt, lt, un, un }, // 2
{ gt, gt, gt, eq, gt, gt, gt, gt, un, un, lt, lt, gt, gt, lt, lt, lt, lt, lt, lt, un, un }, // 3
{ gt, gt, gt, lt, eq, lt, gt, lt, un, un, lt, lt, gt, gt, lt, lt, lt, lt, lt, lt, un, un }, // 4
{ gt, gt, gt, lt, gt, eq, gt, lt, un, un, lt, lt, gt, gt, lt, lt, lt, lt, lt, lt, un, un }, // 5
{ gt, gt, gt, lt, lt, lt, eq, lt, un, un, lt, lt, gt, gt, lt, lt, lt, lt, lt, lt, un, un }, // 6
{ gt, gt, gt, lt, gt, gt, gt, eq, un, un, lt, lt, gt, gt, lt, lt, lt, lt, lt, lt, un, un }, // 7
{ gt, gt, un, un, un, un, un, un, un, un, lt, lt, gt, gt, lt, lt, lt, lt, lt, lt, un, un }, // 8
{ gt, gt, un, un, un, un, un, un, un, un, lt, lt, gt, gt, lt, lt, lt, lt, lt, lt, un, un }, // 9
{ gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, eq, gt, gt, gt, gt, gt, gt, gt, lt, lt, un, un }, // 10
{ gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, lt, eq, gt, gt, gt, gt, gt, gt, lt, lt, un, un }, // 11
{ gt, gt, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, eq, gt, lt, lt, lt, lt, lt, lt, un, un }, // 12
{ gt, gt, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, eq, lt, lt, lt, lt, lt, lt, un, un }, // 13
{ gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, lt, lt, gt, gt, eq, lt, gt, gt, lt, lt, un, un }, // 14
{ gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, lt, lt, gt, gt, gt, eq, gt, gt, lt, lt, un, un }, // 15
{ gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, lt, lt, gt, gt, lt, lt, eq, gt, lt, lt, un, un }, // 16
{ gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, lt, lt, gt, gt, lt, lt, lt, eq, lt, lt, un, un }, // 17
{ gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, eq, lt, un, un }, // 18
{ gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, eq, un, un }, // 19
{ un, un, un, un, un, un, un, un, un, un, un, un, un, un, un, un, un, un, un, un, un, un }, // 20
{ un, un, un, un, un, un, un, un, un, un, un, un, un, un, un, un, un, un, un, un, un, un }, // 21
};
// check expected partial_ordering against expected booleans
@ -582,13 +576,13 @@ TEST_CASE("lexicographical comparison operators")
return j != json(2);
});
CHECK(j_object == json({{"bar", {{"baz", 1}}}}));
CHECK(j_object == json({ { "bar", { { "baz", 1 } } } }));
json j_array = json::parse(s_array, [](int /*unused*/, json::parse_event_t /*unused*/, const json& j) noexcept {
return j != json(2);
});
CHECK(j_array == json({1, {3, 4, 5}, 4, 5}));
CHECK(j_array == json({ 1, { 3, 4, 5 }, 4, 5 }));
}
}
#endif

View File

@ -129,7 +129,7 @@ TEST_CASE("concepts")
SECTION("Swappable")
{
{
json j{1, 2, 3};
json j{ 1, 2, 3 };
json::iterator it1 = j.begin();
json::iterator it2 = j.end();
swap(it1, it2);
@ -137,7 +137,7 @@ TEST_CASE("concepts")
CHECK(it2 == j.begin());
}
{
json j{1, 2, 3};
json j{ 1, 2, 3 };
json::const_iterator it1 = j.cbegin();
json::const_iterator it2 = j.cend();
swap(it1, it2);

View File

@ -131,7 +131,7 @@ TEST_CASE("constructors")
SECTION("filled object")
{
json::object_t const o{{"a", json(1)}, {"b", json(1u)}, {"c", json(2.2)}, {"d", json(false)}, {"e", json("string")}, {"f", json()}};
json::object_t 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);
}
@ -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);
@ -154,9 +156,9 @@ TEST_CASE("constructors")
SECTION("std::map<std::string, std::string> #600")
{
const std::map<std::string, std::string> m{
{"a", "b"},
{"c", "d"},
{"e", "f"},
{ "a", "b" },
{ "c", "d" },
{ "e", "f" },
};
json const j(m);
@ -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);
@ -212,7 +203,7 @@ TEST_CASE("constructors")
SECTION("associative container literal")
{
json const j({{"a", json(1)}, {"b", json(1u)}, {"c", json(2.2)}, {"d", json(false)}, {"e", json("string")}, {"f", json()}});
json const j({ { "a", json(1) }, { "b", json(1u) }, { "c", json(2.2) }, { "d", json(false) }, { "e", json("string") }, { "f", json() } });
CHECK(j.type() == json::value_t::object);
CHECK(j == j_reference);
}
@ -229,7 +220,7 @@ TEST_CASE("constructors")
SECTION("filled array")
{
json::array_t const a{json(1), json(1u), json(2.2), json(false), json("string"), json()};
json::array_t const a{ json(1), json(1u), json(2.2), json(false), json("string"), json() };
json const j(a);
CHECK(j.type() == json::value_t::array);
}
@ -238,12 +229,12 @@ TEST_CASE("constructors")
SECTION("create an array (implicit)")
{
// reference array
json::array_t const a_reference{json(1), json(1u), json(2.2), json(false), json("string"), json()};
json::array_t const a_reference{ json(1), json(1u), json(2.2), json(false), json("string"), json() };
json const j_reference(a_reference);
SECTION("std::list<json>")
{
std::list<json> const a{json(1), json(1u), json(2.2), json(false), json("string"), json()};
std::list<json> const a{ json(1), json(1u), json(2.2), json(false), json("string"), json() };
json const j(a);
CHECK(j.type() == json::value_t::array);
CHECK(j == j_reference);
@ -251,7 +242,7 @@ TEST_CASE("constructors")
SECTION("std::pair")
{
std::pair<float, std::string> const p{1.0f, "string"};
std::pair<float, std::string> const p{ 1.0f, "string" };
json const j(p);
CHECK(j.type() == json::value_t::array);
@ -263,7 +254,7 @@ TEST_CASE("constructors")
SECTION("std::pair with discarded values")
{
json const j{1, 2.0, "string"};
json const j{ 1, 2.0, "string" };
const auto p = j.get<std::pair<int, float>>();
CHECK(p.first == j[0]);
@ -272,7 +263,7 @@ TEST_CASE("constructors")
SECTION("std::tuple")
{
const auto t = std::make_tuple(1.0, std::string{"string"}, 42, std::vector<int>{0, 1});
const auto t = std::make_tuple(1.0, std::string{ "string" }, 42, std::vector<int>{ 0, 1 });
json const j(t);
CHECK(j.type() == json::value_t::array);
@ -287,7 +278,7 @@ TEST_CASE("constructors")
SECTION("std::tuple with discarded values")
{
json const j{1, 2.0, "string", 42};
json const j{ 1, 2.0, "string", 42 };
const auto t = j.get<std::tuple<int, float, std::string>>();
CHECK(std::get<0>(t) == j[0]);
@ -297,7 +288,7 @@ TEST_CASE("constructors")
SECTION("std::pair/tuple/array failures")
{
json const j{1};
json const j{ 1 };
CHECK_THROWS_WITH_AS((j.get<std::pair<int, int>>()), "[json.exception.out_of_range.401] array index 1 is out of range", json::out_of_range&);
CHECK_THROWS_WITH_AS((j.get<std::tuple<int, int>>()), "[json.exception.out_of_range.401] array index 1 is out of range", json::out_of_range&);
@ -306,7 +297,7 @@ TEST_CASE("constructors")
SECTION("std::forward_list<json>")
{
std::forward_list<json> const a{json(1), json(1u), json(2.2), json(false), json("string"), json()};
std::forward_list<json> const a{ json(1), json(1u), json(2.2), json(false), json("string"), json() };
json const j(a);
CHECK(j.type() == json::value_t::array);
CHECK(j == j_reference);
@ -314,7 +305,7 @@ TEST_CASE("constructors")
SECTION("std::array<json, 6>")
{
std::array<json, 6> const a{{json(1), json(1u), json(2.2), json(false), json("string"), json()}};
std::array<json, 6> const a{ { json(1), json(1u), json(2.2), json(false), json("string"), json() } };
json const j(a);
CHECK(j.type() == json::value_t::array);
CHECK(j == j_reference);
@ -325,10 +316,10 @@ TEST_CASE("constructors")
SECTION("std::valarray<int>")
{
std::valarray<int> const va = {1, 2, 3, 4, 5};
std::valarray<int> const va = { 1, 2, 3, 4, 5 };
json const j(va);
CHECK(j.type() == json::value_t::array);
CHECK(j == json({1, 2, 3, 4, 5}));
CHECK(j == json({ 1, 2, 3, 4, 5 }));
auto jva = j.get<std::valarray<int>>();
CHECK(jva.size() == va.size());
@ -340,10 +331,10 @@ TEST_CASE("constructors")
SECTION("std::valarray<double>")
{
std::valarray<double> const va = {1.2, 2.3, 3.4, 4.5, 5.6};
std::valarray<double> const va = { 1.2, 2.3, 3.4, 4.5, 5.6 };
json const j(va);
CHECK(j.type() == json::value_t::array);
CHECK(j == json({1.2, 2.3, 3.4, 4.5, 5.6}));
CHECK(j == json({ 1.2, 2.3, 3.4, 4.5, 5.6 }));
auto jva = j.get<std::valarray<double>>();
CHECK(jva.size() == va.size());
@ -355,7 +346,7 @@ TEST_CASE("constructors")
SECTION("std::vector<json>")
{
std::vector<json> const a{json(1), json(1u), json(2.2), json(false), json("string"), json()};
std::vector<json> const a{ json(1), json(1u), json(2.2), json(false), json("string"), json() };
json const j(a);
CHECK(j.type() == json::value_t::array);
CHECK(j == j_reference);
@ -363,7 +354,7 @@ TEST_CASE("constructors")
SECTION("std::deque<json>")
{
std::deque<json> const a{json(1), json(1u), json(2.2), json(false), json("string"), json()};
std::deque<json> const a{ json(1), json(1u), json(2.2), json(false), json("string"), json() };
json const j(a);
CHECK(j.type() == json::value_t::array);
CHECK(j == j_reference);
@ -371,7 +362,7 @@ TEST_CASE("constructors")
SECTION("std::set<json>")
{
std::set<json> const a{json(1), json(1u), json(2.2), json(false), json("string"), json()};
std::set<json> const a{ json(1), json(1u), json(2.2), json(false), json("string"), json() };
json const j(a);
CHECK(j.type() == json::value_t::array);
// we cannot really check for equality here
@ -379,7 +370,7 @@ TEST_CASE("constructors")
SECTION("std::unordered_set<json>")
{
std::unordered_set<json> const a{json(1), json(1u), json(2.2), json(false), json("string"), json()};
std::unordered_set<json> const a{ json(1), json(1u), json(2.2), json(false), json("string"), json() };
json const j(a);
CHECK(j.type() == json::value_t::array);
// we cannot really check for equality here
@ -387,7 +378,7 @@ TEST_CASE("constructors")
SECTION("sequence container literal")
{
json const j({json(1), json(1u), json(2.2), json(false), json("string"), json()});
json const j({ json(1), json(1u), json(2.2), json(false), json("string"), json() });
CHECK(j.type() == json::value_t::array);
CHECK(j == j_reference);
}
@ -404,7 +395,7 @@ TEST_CASE("constructors")
SECTION("filled string")
{
json::string_t const s{"Hello world"};
json::string_t const s{ "Hello world" };
json const j(s);
CHECK(j.type() == json::value_t::string);
}
@ -413,12 +404,12 @@ TEST_CASE("constructors")
SECTION("create a string (implicit)")
{
// reference string
json::string_t const s_reference{"Hello world"};
json::string_t const s_reference{ "Hello world" };
json const j_reference(s_reference);
SECTION("std::string")
{
std::string const s{"Hello world"};
std::string const s{ "Hello world" };
json const j(s);
CHECK(j.type() == json::value_t::string);
CHECK(j == j_reference);
@ -426,7 +417,7 @@ TEST_CASE("constructors")
SECTION("char[]")
{
char const s[]{"Hello world"}; // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays)
char const s[]{ "Hello world" }; // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays)
json const j(s);
CHECK(j.type() == json::value_t::string);
CHECK(j == j_reference);
@ -434,7 +425,7 @@ TEST_CASE("constructors")
SECTION("const char*")
{
const char* s{"Hello world"};
const char* s{ "Hello world" };
json const j(s);
CHECK(j.type() == json::value_t::string);
CHECK(j == j_reference);
@ -471,7 +462,7 @@ TEST_CASE("constructors")
SECTION("from std::vector<bool>::reference")
{
std::vector<bool> v{true};
std::vector<bool> v{ true };
json const j(v[0]);
CHECK(std::is_same<decltype(v[0]), std::vector<bool>::reference>::value);
CHECK(j.type() == json::value_t::boolean);
@ -479,7 +470,7 @@ TEST_CASE("constructors")
SECTION("from std::vector<bool>::const_reference")
{
const std::vector<bool> v{true};
const std::vector<bool> v{ true };
json const j(v[0]);
CHECK(std::is_same<decltype(v[0]), std::vector<bool>::const_reference>::value);
CHECK(j.type() == json::value_t::boolean);
@ -497,7 +488,7 @@ TEST_CASE("constructors")
SECTION("filled binary")
{
json::binary_t const b({1, 2, 3});
json::binary_t const b({ 1, 2, 3 });
json const j(b);
CHECK(j.type() == json::value_t::binary);
}
@ -851,7 +842,7 @@ TEST_CASE("constructors")
CHECK(j.type() == json::value_t::number_float);
// check round trip of NaN
json::number_float_t const d{j};
json::number_float_t const d{ j };
CHECK((std::isnan(d) && std::isnan(n)) == true);
// check that NaN is serialized to null
@ -866,7 +857,7 @@ TEST_CASE("constructors")
CHECK(j.type() == json::value_t::number_float);
// check round trip of infinity
json::number_float_t const d{j};
json::number_float_t const d{ j };
CHECK(d == n);
// check that inf is serialized to null
@ -949,13 +940,13 @@ TEST_CASE("constructors")
{
SECTION("explicit")
{
json const j(json::initializer_list_t{json(json::array_t())});
json const j(json::initializer_list_t{ json(json::array_t()) });
CHECK(j.type() == json::value_t::array);
}
SECTION("implicit")
{
json const j{json::array_t()};
json const j{ json::array_t() };
CHECK(j.type() == json::value_t::array);
}
}
@ -964,13 +955,13 @@ TEST_CASE("constructors")
{
SECTION("explicit")
{
json const j(json::initializer_list_t{json(json::object_t())});
json const j(json::initializer_list_t{ json(json::object_t()) });
CHECK(j.type() == json::value_t::array);
}
SECTION("implicit")
{
json const j{json::object_t()};
json const j{ json::object_t() };
CHECK(j.type() == json::value_t::array);
}
}
@ -979,13 +970,13 @@ TEST_CASE("constructors")
{
SECTION("explicit")
{
json const j(json::initializer_list_t{json("Hello world")});
json const j(json::initializer_list_t{ json("Hello world") });
CHECK(j.type() == json::value_t::array);
}
SECTION("implicit")
{
json const j{"Hello world"};
json const j{ "Hello world" };
CHECK(j.type() == json::value_t::array);
}
}
@ -994,13 +985,13 @@ TEST_CASE("constructors")
{
SECTION("explicit")
{
json const j(json::initializer_list_t{json(true)});
json const j(json::initializer_list_t{ json(true) });
CHECK(j.type() == json::value_t::array);
}
SECTION("implicit")
{
json const j{true};
json const j{ true };
CHECK(j.type() == json::value_t::array);
}
}
@ -1009,13 +1000,13 @@ TEST_CASE("constructors")
{
SECTION("explicit")
{
json const j(json::initializer_list_t{json(1)});
json const j(json::initializer_list_t{ json(1) });
CHECK(j.type() == json::value_t::array);
}
SECTION("implicit")
{
json const j{1};
json const j{ 1 };
CHECK(j.type() == json::value_t::array);
}
}
@ -1024,13 +1015,13 @@ TEST_CASE("constructors")
{
SECTION("explicit")
{
json const j(json::initializer_list_t{json(1u)});
json const j(json::initializer_list_t{ json(1u) });
CHECK(j.type() == json::value_t::array);
}
SECTION("implicit")
{
json const j{1u};
json const j{ 1u };
CHECK(j.type() == json::value_t::array);
}
}
@ -1039,13 +1030,13 @@ TEST_CASE("constructors")
{
SECTION("explicit")
{
json const j(json::initializer_list_t{json(42.23)});
json const j(json::initializer_list_t{ json(42.23) });
CHECK(j.type() == json::value_t::array);
}
SECTION("implicit")
{
json const j{42.23};
json const j{ 42.23 };
CHECK(j.type() == json::value_t::array);
}
}
@ -1055,13 +1046,13 @@ TEST_CASE("constructors")
{
SECTION("explicit")
{
json const j(json::initializer_list_t{1, 1u, 42.23, true, nullptr, json::object_t(), json::array_t()});
json const j(json::initializer_list_t{ 1, 1u, 42.23, true, nullptr, json::object_t(), json::array_t() });
CHECK(j.type() == json::value_t::array);
}
SECTION("implicit")
{
json const j{1, 1u, 42.23, true, nullptr, json::object_t(), json::array_t()};
json const j{ 1, 1u, 42.23, true, nullptr, json::object_t(), json::array_t() };
CHECK(j.type() == json::value_t::array);
}
}
@ -1070,13 +1061,13 @@ TEST_CASE("constructors")
{
SECTION("object")
{
json const j{{"one", 1}, {"two", 1u}, {"three", 2.2}, {"four", false}};
json const j{ { "one", 1 }, { "two", 1u }, { "three", 2.2 }, { "four", false } };
CHECK(j.type() == json::value_t::object);
}
SECTION("array")
{
json const j{{"one", 1}, {"two", 1u}, {"three", 2.2}, {"four", false}, 13};
json const j{ { "one", 1 }, { "two", 1u }, { "three", 2.2 }, { "four", false }, 13 };
CHECK(j.type() == json::value_t::array);
}
}
@ -1091,14 +1082,14 @@ TEST_CASE("constructors")
SECTION("object")
{
json const j = json::object({{"one", 1}, {"two", 1u}, {"three", 2.2}, {"four", false}});
json const j = json::object({ { "one", 1 }, { "two", 1u }, { "three", 2.2 }, { "four", false } });
CHECK(j.type() == json::value_t::object);
}
SECTION("object with error")
{
json _;
CHECK_THROWS_WITH_AS(_ = json::object({{"one", 1}, {"two", 1u}, {"three", 2.2}, {"four", false}, 13}),
CHECK_THROWS_WITH_AS(_ = json::object({ { "one", 1 }, { "two", 1u }, { "three", 2.2 }, { "four", false }, 13 }),
"[json.exception.type_error.301] cannot create object from initializer list",
json::type_error&);
}
@ -1111,7 +1102,7 @@ TEST_CASE("constructors")
SECTION("array")
{
json const j = json::array({{"one", 1}, {"two", 1u}, {"three", 2.2}, {"four", false}});
json const j = json::array({ { "one", 1 }, { "two", 1u }, { "three", 2.2 }, { "four", false } });
CHECK(j.type() == json::value_t::array);
}
}
@ -1125,7 +1116,7 @@ TEST_CASE("constructors")
// This should break through any short string optimization in std::string
std::string source(1024, '!');
const auto* source_addr = source.data();
json j = {std::move(source)};
json j = { std::move(source) };
const auto* target_addr = j[0].get_ref<std::string const&>().data();
const bool success = (target_addr == source_addr);
CHECK(success);
@ -1136,7 +1127,7 @@ TEST_CASE("constructors")
// This should break through any short string optimization in std::string
std::string source(1024, '!');
const auto* source_addr = source.data();
json j = {{"key", std::move(source)}};
json j = { { "key", std::move(source) } };
const auto* target_addr = j["key"].get_ref<std::string const&>().data();
const bool success = (target_addr == source_addr);
CHECK(success);
@ -1147,7 +1138,7 @@ TEST_CASE("constructors")
// This should break through any short string optimization in std::string
std::string source(1024, '!');
const auto* source_addr = source.data();
json j = {{std::move(source), 42}};
json j = { { std::move(source), 42 } };
const auto* target_addr = j.get_ref<json::object_t&>().begin()->first.data();
const bool success = (target_addr == source_addr);
CHECK(success);
@ -1158,9 +1149,9 @@ TEST_CASE("constructors")
{
SECTION("constructor with implicit types (array)")
{
json::array_t source = {1, 2, 3};
json::array_t source = { 1, 2, 3 };
const auto* source_addr = source.data();
json j{std::move(source)};
json j{ std::move(source) };
const auto* target_addr = j[0].get_ref<json::array_t const&>().data();
const bool success = (target_addr == source_addr);
CHECK(success);
@ -1168,9 +1159,9 @@ TEST_CASE("constructors")
SECTION("constructor with implicit types (object)")
{
json::array_t source = {1, 2, 3};
json::array_t source = { 1, 2, 3 };
const auto* source_addr = source.data();
json const j{{"key", std::move(source)}};
json const j{ { "key", std::move(source) } };
const auto* target_addr = j["key"].get_ref<json::array_t const&>().data();
const bool success = (target_addr == source_addr);
CHECK(success);
@ -1178,9 +1169,9 @@ TEST_CASE("constructors")
SECTION("assignment with implicit types (array)")
{
json::array_t source = {1, 2, 3};
json::array_t source = { 1, 2, 3 };
const auto* source_addr = source.data();
json j = {std::move(source)};
json j = { std::move(source) };
const auto* target_addr = j[0].get_ref<json::array_t const&>().data();
const bool success = (target_addr == source_addr);
CHECK(success);
@ -1188,9 +1179,9 @@ TEST_CASE("constructors")
SECTION("assignment with implicit types (object)")
{
json::array_t source = {1, 2, 3};
json::array_t source = { 1, 2, 3 };
const auto* source_addr = source.data();
json j = {{"key", std::move(source)}};
json j = { { "key", std::move(source) } };
const auto* target_addr = j["key"].get_ref<json::array_t const&>().data();
const bool success = (target_addr == source_addr);
CHECK(success);
@ -1201,33 +1192,33 @@ TEST_CASE("constructors")
{
SECTION("constructor with implicit types (array)")
{
json::object_t source = {{"hello", "world"}};
json::object_t source = { { "hello", "world" } };
const json* source_addr = &source.at("hello");
json j{std::move(source)};
json j{ std::move(source) };
CHECK(&(j[0].get_ref<json::object_t const&>().at("hello")) == source_addr);
}
SECTION("constructor with implicit types (object)")
{
json::object_t source = {{"hello", "world"}};
json::object_t source = { { "hello", "world" } };
const json* source_addr = &source.at("hello");
json j{{"key", std::move(source)}};
json j{ { "key", std::move(source) } };
CHECK(&(j["key"].get_ref<json::object_t const&>().at("hello")) == source_addr);
}
SECTION("assignment with implicit types (array)")
{
json::object_t source = {{"hello", "world"}};
json::object_t source = { { "hello", "world" } };
const json* source_addr = &source.at("hello");
json j = {std::move(source)};
json j = { std::move(source) };
CHECK(&(j[0].get_ref<json::object_t const&>().at("hello")) == source_addr);
}
SECTION("assignment with implicit types (object)")
{
json::object_t source = {{"hello", "world"}};
json::object_t source = { { "hello", "world" } };
const json* source_addr = &source.at("hello");
json j = {{"key", std::move(source)}};
json j = { { "key", std::move(source) } };
CHECK(&(j["key"].get_ref<json::object_t const&>().at("hello")) == source_addr);
}
}
@ -1236,33 +1227,33 @@ TEST_CASE("constructors")
{
SECTION("constructor with implicit types (array)")
{
json source{1, 2, 3};
json source{ 1, 2, 3 };
const json* source_addr = &source[0];
json j{std::move(source), {}};
json j{ std::move(source), {} };
CHECK(&j[0][0] == source_addr);
}
SECTION("constructor with implicit types (object)")
{
json source{1, 2, 3};
json source{ 1, 2, 3 };
const json* source_addr = &source[0];
json j{{"key", std::move(source)}};
json j{ { "key", std::move(source) } };
CHECK(&j["key"][0] == source_addr);
}
SECTION("assignment with implicit types (array)")
{
json source{1, 2, 3};
json source{ 1, 2, 3 };
const json* source_addr = &source[0];
json j = {std::move(source), {}};
json j = { std::move(source), {} };
CHECK(&j[0][0] == source_addr);
}
SECTION("assignment with implicit types (object)")
{
json source{1, 2, 3};
json source{ 1, 2, 3 };
const json* source_addr = &source[0];
json j = {{"key", std::move(source)}};
json j = { { "key", std::move(source) } };
CHECK(&j["key"][0] == source_addr);
}
}
@ -1273,14 +1264,14 @@ TEST_CASE("constructors")
{
SECTION("cnt = 0")
{
json const v = {1, "foo", 34.23, {1, 2, 3}, {{"A", 1}, {"B", 2u}}};
json const v = { 1, "foo", 34.23, { 1, 2, 3 }, { { "A", 1 }, { "B", 2u } } };
json const arr(0, v);
CHECK(arr.size() == 0);
}
SECTION("cnt = 1")
{
json const v = {1, "foo", 34.23, {1, 2, 3}, {{"A", 1}, {"B", 2u}}};
json const v = { 1, "foo", 34.23, { 1, 2, 3 }, { { "A", 1 }, { "B", 2u } } };
json const arr(1, v);
CHECK(arr.size() == 1);
for (const auto& x : arr)
@ -1291,7 +1282,7 @@ TEST_CASE("constructors")
SECTION("cnt = 3")
{
json const v = {1, "foo", 34.23, {1, 2, 3}, {{"A", 1}, {"B", 2u}}};
json const v = { 1, "foo", 34.23, { 1, 2, 3 }, { { "A", 1 }, { "B", 2u } } };
json const arr(3, v);
CHECK(arr.size() == 3);
for (const auto& x : arr)
@ -1308,12 +1299,12 @@ TEST_CASE("constructors")
SECTION("json(begin(), end())")
{
{
json jobject = {{"a", "a"}, {"b", 1}, {"c", 17u}};
json jobject = { { "a", "a" }, { "b", 1 }, { "c", 17u } };
json const j_new(jobject.begin(), jobject.end());
CHECK(j_new == jobject);
}
{
json jobject = {{"a", "a"}, {"b", 1}, {"c", 17u}};
json jobject = { { "a", "a" }, { "b", 1 }, { "c", 17u } };
json const j_new(jobject.cbegin(), jobject.cend());
CHECK(j_new == jobject);
}
@ -1322,12 +1313,12 @@ TEST_CASE("constructors")
SECTION("json(begin(), begin())")
{
{
json jobject = {{"a", "a"}, {"b", 1}, {"c", 17u}};
json jobject = { { "a", "a" }, { "b", 1 }, { "c", 17u } };
json const j_new(jobject.begin(), jobject.begin());
CHECK(j_new == json::object());
}
{
json const jobject = {{"a", "a"}, {"b", 1}, {"c", 17u}};
json const jobject = { { "a", "a" }, { "b", 1 }, { "c", 17u } };
json const j_new(jobject.cbegin(), jobject.cbegin());
CHECK(j_new == json::object());
}
@ -1335,16 +1326,16 @@ TEST_CASE("constructors")
SECTION("construct from subrange")
{
json const jobject = {{"a", "a"}, {"b", 1}, {"c", 17u}, {"d", false}, {"e", true}};
json const jobject = { { "a", "a" }, { "b", 1 }, { "c", 17u }, { "d", false }, { "e", true } };
json const j_new(jobject.find("b"), jobject.find("e"));
CHECK(j_new == json({{"b", 1}, {"c", 17u}, {"d", false}}));
CHECK(j_new == json({ { "b", 1 }, { "c", 17u }, { "d", false } }));
}
SECTION("incompatible iterators")
{
{
json jobject = {{"a", "a"}, {"b", 1}, {"c", 17u}, {"d", false}, {"e", true}};
json jobject2 = {{"a", "a"}, {"b", 1}, {"c", 17u}};
json jobject = { { "a", "a" }, { "b", 1 }, { "c", 17u }, { "d", false }, { "e", true } };
json jobject2 = { { "a", "a" }, { "b", 1 }, { "c", 17u } };
CHECK_THROWS_WITH_AS(json(jobject.begin(), jobject2.end()),
"[json.exception.invalid_iterator.201] iterators are not compatible",
json::invalid_iterator&);
@ -1353,8 +1344,8 @@ TEST_CASE("constructors")
json::invalid_iterator&);
}
{
json const jobject = {{"a", "a"}, {"b", 1}, {"c", 17u}, {"d", false}, {"e", true}};
json const jobject2 = {{"a", "a"}, {"b", 1}, {"c", 17u}};
json const jobject = { { "a", "a" }, { "b", 1 }, { "c", 17u }, { "d", false }, { "e", true } };
json const jobject2 = { { "a", "a" }, { "b", 1 }, { "c", 17u } };
CHECK_THROWS_WITH_AS(json(jobject.cbegin(), jobject2.cend()),
"[json.exception.invalid_iterator.201] iterators are not compatible",
json::invalid_iterator&);
@ -1370,12 +1361,12 @@ TEST_CASE("constructors")
SECTION("json(begin(), end())")
{
{
json jarray = {1, 2, 3, 4, 5};
json jarray = { 1, 2, 3, 4, 5 };
json const j_new(jarray.begin(), jarray.end());
CHECK(j_new == jarray);
}
{
json const jarray = {1, 2, 3, 4, 5};
json const jarray = { 1, 2, 3, 4, 5 };
json const j_new(jarray.cbegin(), jarray.cend());
CHECK(j_new == jarray);
}
@ -1384,12 +1375,12 @@ TEST_CASE("constructors")
SECTION("json(begin(), begin())")
{
{
json jarray = {1, 2, 3, 4, 5};
json jarray = { 1, 2, 3, 4, 5 };
json j_new(jarray.begin(), jarray.begin());
CHECK(j_new == json::array());
}
{
json const jarray = {1, 2, 3, 4, 5};
json const jarray = { 1, 2, 3, 4, 5 };
json const j_new(jarray.cbegin(), jarray.cbegin());
CHECK(j_new == json::array());
}
@ -1398,22 +1389,22 @@ TEST_CASE("constructors")
SECTION("construct from subrange")
{
{
json jarray = {1, 2, 3, 4, 5};
json jarray = { 1, 2, 3, 4, 5 };
json const j_new(jarray.begin() + 1, jarray.begin() + 3);
CHECK(j_new == json({2, 3}));
CHECK(j_new == json({ 2, 3 }));
}
{
json const jarray = {1, 2, 3, 4, 5};
json const jarray = { 1, 2, 3, 4, 5 };
json const j_new(jarray.cbegin() + 1, jarray.cbegin() + 3);
CHECK(j_new == json({2, 3}));
CHECK(j_new == json({ 2, 3 }));
}
}
SECTION("incompatible iterators")
{
{
json jarray = {1, 2, 3, 4};
json jarray2 = {2, 3, 4, 5};
json jarray = { 1, 2, 3, 4 };
json jarray2 = { 2, 3, 4, 5 };
CHECK_THROWS_WITH_AS(json(jarray.begin(), jarray2.end()),
"[json.exception.invalid_iterator.201] iterators are not compatible",
json::invalid_iterator&);
@ -1422,8 +1413,8 @@ TEST_CASE("constructors")
json::invalid_iterator&);
}
{
json const jarray = {1, 2, 3, 4};
json const jarray2 = {2, 3, 4, 5};
json const jarray = { 1, 2, 3, 4 };
json const jarray2 = { 2, 3, 4, 5 };
CHECK_THROWS_WITH_AS(json(jarray.cbegin(), jarray2.cend()),
"[json.exception.invalid_iterator.201] iterators are not compatible",
json::invalid_iterator&);
@ -1527,12 +1518,12 @@ TEST_CASE("constructors")
SECTION("binary")
{
{
json j = json::binary({1, 2, 3});
json j = json::binary({ 1, 2, 3 });
json const j_new(j.begin(), j.end());
CHECK((j == j_new));
}
{
json const j = json::binary({1, 2, 3});
json const j = json::binary({ 1, 2, 3 });
json const j_new(j.cbegin(), j.cend());
CHECK((j == j_new));
}

View File

@ -17,14 +17,14 @@ TEST_CASE("other constructors and destructor")
{
SECTION("object")
{
json j{{"foo", 1}, {"bar", false}};
json j{ { "foo", 1 }, { "bar", false } };
json k(j); // NOLINT(performance-unnecessary-copy-initialization)
CHECK(j == k);
}
SECTION("array")
{
json j{"foo", 1, 42.23, false};
json j{ "foo", 1, 42.23, false };
json k(j); // NOLINT(performance-unnecessary-copy-initialization)
CHECK(j == k);
}
@ -73,7 +73,7 @@ TEST_CASE("other constructors and destructor")
SECTION("binary")
{
json j = json::binary({1, 2, 3});
json j = json::binary({ 1, 2, 3 });
json k(j); // NOLINT(performance-unnecessary-copy-initialization)
CHECK(j == k);
}
@ -81,7 +81,7 @@ TEST_CASE("other constructors and destructor")
SECTION("move constructor")
{
json j{{"foo", "bar"}, {"baz", {1, 2, 3, 4}}, {"a", 42u}, {"b", 42.23}, {"c", nullptr}};
json j{ { "foo", "bar" }, { "baz", { 1, 2, 3, 4 } }, { "a", 42u }, { "b", 42.23 }, { "c", nullptr } };
CHECK(j.type() == json::value_t::object);
const json k(std::move(j));
CHECK(k.type() == json::value_t::object);
@ -92,7 +92,7 @@ TEST_CASE("other constructors and destructor")
{
SECTION("object")
{
json j{{"foo", 1}, {"bar", false}};
json j{ { "foo", 1 }, { "bar", false } };
json k;
k = j;
CHECK(j == k);
@ -100,7 +100,7 @@ TEST_CASE("other constructors and destructor")
SECTION("array")
{
json j{"foo", 1, 42.23, false};
json j{ "foo", 1, 42.23, false };
json k;
k = j;
CHECK(j == k);
@ -156,7 +156,7 @@ TEST_CASE("other constructors and destructor")
SECTION("binary")
{
json j = json::binary({1, 2, 3});
json j = json::binary({ 1, 2, 3 });
json k;
k = j;
CHECK(j == k);
@ -167,13 +167,13 @@ TEST_CASE("other constructors and destructor")
{
SECTION("object")
{
auto* j = new json{{"foo", 1}, {"bar", false}}; // NOLINT(cppcoreguidelines-owning-memory)
auto* j = new json{ { "foo", 1 }, { "bar", false } }; // NOLINT(cppcoreguidelines-owning-memory)
delete j; // NOLINT(cppcoreguidelines-owning-memory)
}
SECTION("array")
{
auto* j = new json{"foo", 1, 1u, false, 23.42}; // NOLINT(cppcoreguidelines-owning-memory)
auto* j = new json{ "foo", 1, 1u, false, 23.42 }; // NOLINT(cppcoreguidelines-owning-memory)
delete j; // NOLINT(cppcoreguidelines-owning-memory)
}

View File

@ -173,8 +173,8 @@ TEST_CASE("convenience functions")
using nlohmann::detail::concat;
const char* expected = "Hello, world!";
alt_string_iter const hello_iter{"Hello, "};
alt_string_data const hello_data{"Hello, "};
alt_string_iter const hello_iter{ "Hello, " };
alt_string_data const hello_data{ "Hello, " };
std::string const world = "world";
SECTION("std::string")

View File

@ -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,41 +99,41 @@ 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")
{
json::object_t o = {{"previous", "value"}};
json::object_t o = { { "previous", "value" } };
j.get_to(o);
CHECK(json(o) == j);
}
SECTION("std::map<json::string_t, json>")
{
std::map<json::string_t, json> o{{"previous", "value"}};
std::map<json::string_t, json> o{ { "previous", "value" } };
j.get_to(o);
CHECK(json(o) == j);
}
SECTION("std::multimap<json::string_t, json>")
{
std::multimap<json::string_t, json> o{{"previous", "value"}};
std::multimap<json::string_t, json> o{ { "previous", "value" } };
j.get_to(o);
CHECK(json(o) == j);
}
SECTION("std::unordered_map<json::string_t, json>")
{
std::unordered_map<json::string_t, json> o{{"previous", "value"}};
std::unordered_map<json::string_t, json> o{ { "previous", "value" } };
j.get_to(o);
CHECK(json(o) == j);
}
SECTION("std::unordered_multimap<json::string_t, json>")
{
std::unordered_multimap<json::string_t, json> o{{"previous", "value"}};
std::unordered_multimap<json::string_t, json> o{ { "previous", "value" } };
j.get_to(o);
CHECK(json(o) == j);
}
@ -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")
@ -180,7 +180,7 @@ TEST_CASE("value conversion")
SECTION("get an array (explicit)")
{
const json::array_t a_reference{json(1), json(1u), json(2.2), json(false), json("string"), json()};
const json::array_t a_reference{ json(1), json(1u), json(2.2), json(false), json("string"), json() };
json j(a_reference);
SECTION("json::array_t")
@ -218,7 +218,7 @@ TEST_CASE("value conversion")
SECTION("reserve is called on containers that supports it")
{
// make sure all values are properly copied
const json j2({1, 2, 3, 4, 5, 6, 7, 8, 9, 10});
const json j2({ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 });
auto v2 = j2.get<std::vector<int>>();
CHECK(v2.size() == 10);
}
@ -228,7 +228,7 @@ TEST_CASE("value conversion")
SECTION("built-in arrays")
{
const char str[] = "a string"; // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays)
const int nbs[] = {0, 1, 2}; // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays)
const int nbs[] = { 0, 1, 2 }; // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays)
const json j2 = nbs;
const json j3 = str;
@ -276,48 +276,48 @@ TEST_CASE("value conversion")
SECTION("get an array (explicit, get_to)")
{
const json::array_t a_reference{json(1), json(1u), json(2.2), json(false), json("string"), json()};
const json::array_t a_reference{ json(1), json(1u), json(2.2), json(false), json("string"), json() };
json j(a_reference);
SECTION("json::array_t")
{
json::array_t a{"previous", "value"};
json::array_t a{ "previous", "value" };
j.get_to(a);
CHECK(json(a) == j);
}
SECTION("std::valarray<json>")
{
std::valarray<json> a{"previous", "value"};
std::valarray<json> a{ "previous", "value" };
j.get_to(a);
CHECK(json(a) == j);
}
SECTION("std::list<json>")
{
std::list<json> a{"previous", "value"};
std::list<json> a{ "previous", "value" };
j.get_to(a);
CHECK(json(a) == j);
}
SECTION("std::forward_list<json>")
{
std::forward_list<json> a{"previous", "value"};
std::forward_list<json> a{ "previous", "value" };
j.get_to(a);
CHECK(json(a) == j);
}
SECTION("std::vector<json>")
{
std::vector<json> a{"previous", "value"};
std::vector<json> a{ "previous", "value" };
j.get_to(a);
CHECK(json(a) == j);
}
SECTION("built-in arrays")
{
const int nbs[] = {0, 1, 2}; // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays)
int nbs2[] = {0, 0, 0}; // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays)
const int nbs[] = { 0, 1, 2 }; // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays)
int nbs2[] = { 0, 0, 0 }; // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays)
const json j2 = nbs;
j2.get_to(nbs2);
@ -326,7 +326,7 @@ TEST_CASE("value conversion")
SECTION("std::deque<json>")
{
std::deque<json> a{"previous", "value"};
std::deque<json> a{ "previous", "value" };
j.get_to(a);
CHECK(json(a) == j);
}
@ -335,7 +335,7 @@ TEST_CASE("value conversion")
#if JSON_USE_IMPLICIT_CONVERSIONS
SECTION("get an array (implicit)")
{
const json::array_t a_reference{json(1), json(1u), json(2.2), json(false), json("string"), json()};
const json::array_t a_reference{ json(1), json(1u), json(2.2), json(false), json("string"), json() };
json j(a_reference);
SECTION("json::array_t")
@ -372,7 +372,7 @@ TEST_CASE("value conversion")
SECTION("get a string (explicit)")
{
const json::string_t s_reference{"Hello world"};
const json::string_t s_reference{ "Hello world" };
json j(s_reference);
SECTION("string_t")
@ -450,7 +450,7 @@ TEST_CASE("value conversion")
SECTION("get a string (explicit, get_to)")
{
const json::string_t s_reference{"Hello world"};
const json::string_t s_reference{ "Hello world" };
json j(s_reference);
SECTION("string_t")
@ -511,7 +511,7 @@ TEST_CASE("value conversion")
#if JSON_USE_IMPLICIT_CONVERSIONS
SECTION("get a string (implicit)")
{
const json::string_t s_reference{"Hello world"};
const json::string_t s_reference{ "Hello world" };
json j(s_reference);
SECTION("string_t")
@ -538,7 +538,7 @@ TEST_CASE("value conversion")
SECTION("get a boolean (explicit)")
{
const json::boolean_t b_reference{true};
const json::boolean_t b_reference{ true };
json j(b_reference);
SECTION("boolean_t")
@ -595,7 +595,7 @@ TEST_CASE("value conversion")
#if JSON_USE_IMPLICIT_CONVERSIONS
SECTION("get a boolean (implicit)")
{
const json::boolean_t b_reference{true};
const json::boolean_t b_reference{ true };
json j(b_reference);
SECTION("boolean_t")
@ -614,9 +614,9 @@ TEST_CASE("value conversion")
SECTION("get an integer number (explicit)")
{
const json::number_integer_t n_reference{42};
const json::number_integer_t n_reference{ 42 };
json j(n_reference);
const json::number_unsigned_t n_unsigned_reference{42u};
const json::number_unsigned_t n_unsigned_reference{ 42u };
json j_unsigned(n_unsigned_reference);
SECTION("number_integer_t")
@ -850,9 +850,9 @@ TEST_CASE("value conversion")
#if JSON_USE_IMPLICIT_CONVERSIONS
SECTION("get an integer number (implicit)")
{
json::number_integer_t const n_reference{42};
json::number_integer_t const n_reference{ 42 };
json j(n_reference);
json::number_unsigned_t const n_unsigned_reference{42u};
json::number_unsigned_t const n_unsigned_reference{ 42u };
json j_unsigned(n_unsigned_reference);
SECTION("number_integer_t")
@ -1063,7 +1063,7 @@ TEST_CASE("value conversion")
SECTION("get a floating-point number (explicit)")
{
json::number_float_t const n_reference{42.23};
json::number_float_t const n_reference{ 42.23 };
json const j(n_reference);
SECTION("number_float_t")
@ -1111,7 +1111,7 @@ TEST_CASE("value conversion")
#if JSON_USE_IMPLICIT_CONVERSIONS
SECTION("get a floating-point number (implicit)")
{
json::number_float_t const n_reference{42.23};
json::number_float_t const n_reference{ 42.23 };
json const j(n_reference);
SECTION("number_float_t")
@ -1136,7 +1136,7 @@ TEST_CASE("value conversion")
SECTION("get a binary value (explicit)")
{
json::binary_t const n_reference{{1, 2, 3}};
json::binary_t const n_reference{ { 1, 2, 3 } };
json j(n_reference);
SECTION("binary_t")
@ -1205,7 +1205,7 @@ TEST_CASE("value conversion")
#if JSON_USE_IMPLICIT_CONVERSIONS
SECTION("get a binary value (implicit)")
{
json::binary_t const n_reference{{1, 2, 3}};
json::binary_t const n_reference{ { 1, 2, 3 } };
json const j(n_reference);
SECTION("binary_t")
@ -1237,11 +1237,11 @@ TEST_CASE("value conversion")
{
SECTION("object-like STL containers")
{
json const j1 = {{"one", 1}, {"two", 2}, {"three", 3}};
json const j2 = {{"one", 1u}, {"two", 2u}, {"three", 3u}};
json const j3 = {{"one", 1.1}, {"two", 2.2}, {"three", 3.3}};
json const j4 = {{"one", true}, {"two", false}, {"three", true}};
json const j5 = {{"one", "eins"}, {"two", "zwei"}, {"three", "drei"}};
json const j1 = { { "one", 1 }, { "two", 2 }, { "three", 3 } };
json const j2 = { { "one", 1u }, { "two", 2u }, { "three", 3u } };
json const j3 = { { "one", 1.1 }, { "two", 2.2 }, { "three", 3.3 } };
json const j4 = { { "one", true }, { "two", false }, { "three", true } };
json const j5 = { { "one", "eins" }, { "two", "zwei" }, { "three", "drei" } };
SECTION("std::map")
{
@ -1292,11 +1292,11 @@ TEST_CASE("value conversion")
SECTION("array-like STL containers")
{
json const j1 = {1, 2, 3, 4};
json const j2 = {1u, 2u, 3u, 4u};
json const j3 = {1.2, 2.3, 3.4, 4.5};
json const j4 = {true, false, true};
json const j5 = {"one", "two", "three"};
json const j1 = { 1, 2, 3, 4 };
json const j2 = { 1u, 2u, 3u, 4u };
json const j3 = { 1.2, 2.3, 3.4, 4.5 };
json const j4 = { true, false, true };
json const j5 = { "one", "two", "three" };
SECTION("std::list")
{
@ -1326,7 +1326,7 @@ TEST_CASE("value conversion")
SECTION("std::array is larger than JSON")
{
std::array<int, 6> arr6 = {{1, 2, 3, 4, 5, 6}};
std::array<int, 6> arr6 = { { 1, 2, 3, 4, 5, 6 } };
CHECK_THROWS_WITH_AS(j1.get_to(arr6),
"[json.exception.out_of_range.401] "
"array index 4 is out of range",
@ -1335,7 +1335,7 @@ TEST_CASE("value conversion")
SECTION("std::array is smaller than JSON")
{
std::array<int, 2> arr2 = {{8, 9}};
std::array<int, 2> arr2 = { { 8, 9 } };
j1.get_to(arr2);
CHECK(arr2[0] == 1);
CHECK(arr2[1] == 2);
@ -1389,13 +1389,13 @@ TEST_CASE("value conversion")
SECTION("std::map (array of pairs)")
{
std::map<int, int> m{{0, 1}, {1, 2}, {2, 3}};
std::map<int, int> m{ { 0, 1 }, { 1, 2 }, { 2, 3 } };
json const j6 = m;
auto m2 = j6.get<std::map<int, int>>();
CHECK(m == m2);
json const j7 = {0, 1, 2, 3};
json const j7 = { 0, 1, 2, 3 };
json const j8 = 2;
CHECK_THROWS_WITH_AS((j7.get<std::map<int, int>>()),
"[json.exception.type_error.302] type must be array, "
@ -1408,7 +1408,7 @@ TEST_CASE("value conversion")
SECTION("superfluous entries")
{
json const j9 = {{0, 1, 2}, {1, 2, 3}, {2, 3, 4}};
json const j9 = { { 0, 1, 2 }, { 1, 2, 3 }, { 2, 3, 4 } };
m2 = j9.get<std::map<int, int>>();
CHECK(m == m2);
}
@ -1416,13 +1416,13 @@ TEST_CASE("value conversion")
SECTION("std::unordered_map (array of pairs)")
{
std::unordered_map<int, int> m{{0, 1}, {1, 2}, {2, 3}};
std::unordered_map<int, int> m{ { 0, 1 }, { 1, 2 }, { 2, 3 } };
json const j6 = m;
auto m2 = j6.get<std::unordered_map<int, int>>();
CHECK(m == m2);
json const j7 = {0, 1, 2, 3};
json const j7 = { 0, 1, 2, 3 };
json const j8 = 2;
CHECK_THROWS_WITH_AS((j7.get<std::unordered_map<int, int>>()),
"[json.exception.type_error.302] type must be array, "
@ -1435,7 +1435,7 @@ TEST_CASE("value conversion")
SECTION("superfluous entries")
{
json const j9{{0, 1, 2}, {1, 2, 3}, {2, 3, 4}};
json const j9{ { 0, 1, 2 }, { 1, 2, 3 }, { 2, 3, 4 } };
m2 = j9.get<std::unordered_map<int, int>>();
CHECK(m == m2);
}
@ -1466,11 +1466,11 @@ enum class cards
// NOLINTNEXTLINE(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays) - false positive
NLOHMANN_JSON_SERIALIZE_ENUM(cards,
{{cards::kreuz, "kreuz"},
{cards::pik, "pik"},
{cards::pik, "puk"}, // second entry for cards::puk; will not be used
{cards::herz, "herz"},
{cards::karo, "karo"}})
{ { cards::kreuz, "kreuz" },
{ cards::pik, "pik" },
{ cards::pik, "puk" }, // second entry for cards::puk; will not be used
{ cards::herz, "herz" },
{ cards::karo, "karo" } })
enum TaskState
{
@ -1483,10 +1483,10 @@ enum TaskState
// NOLINTNEXTLINE(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays) - false positive
NLOHMANN_JSON_SERIALIZE_ENUM(TaskState,
{
{TS_INVALID, nullptr},
{TS_STOPPED, "stopped"},
{TS_RUNNING, "running"},
{TS_COMPLETED, "completed"},
{ TS_INVALID, nullptr },
{ TS_STOPPED, "stopped" },
{ TS_RUNNING, "running" },
{ TS_COMPLETED, "completed" },
})
TEST_CASE("JSON to enum mapping")

View File

@ -258,7 +258,7 @@ TEST_CASE("JSON Visit Node")
json["array"].push_back(1);
json["array"].push_back(json);
std::set<std::string> expected{"/null - null - null",
std::set<std::string> expected{ "/null - null - null",
"/int - number_integer - -1",
"/uint - number_unsigned - 1",
"/float - number_float - 1.0",
@ -274,7 +274,7 @@ TEST_CASE("JSON Visit Node")
"/array/2/boolean - boolean - true",
"/array/2/string - string - \"string\"",
"/array/2/array/0 - number_integer - 0",
"/array/2/array/1 - number_integer - 1"};
"/array/2/array/1 - number_integer - 1" };
json.visit([&](const json_with_visitor_t::json_pointer& p, const json_with_visitor_t& j) {
std::stringstream str;

View File

@ -231,12 +231,12 @@ TEST_CASE("deserialization")
ss3 << R"(["foo",1,2,3,false,{"one":1}])";
json j = json::parse(ss1);
CHECK(json::accept(ss2));
CHECK(j == json({"foo", 1, 2, 3, false, {{"one", 1}}}));
CHECK(j == json({ "foo", 1, 2, 3, false, { { "one", 1 } } }));
SaxEventLogger l;
CHECK(json::sax_parse(ss3, &l));
CHECK(l.events.size() == 11);
CHECK(l.events == std::vector<std::string>({"start_array()",
CHECK(l.events == std::vector<std::string>({ "start_array()",
"string(foo)",
"number_unsigned(1)",
"number_unsigned(2)",
@ -246,7 +246,7 @@ TEST_CASE("deserialization")
"key(one)",
"number_unsigned(1)",
"end_object()",
"end_array()"}));
"end_array()" }));
}
SECTION("string literal")
@ -254,12 +254,12 @@ TEST_CASE("deserialization")
const auto* s = R"(["foo",1,2,3,false,{"one":1}])";
json j = json::parse(s);
CHECK(json::accept(s));
CHECK(j == json({"foo", 1, 2, 3, false, {{"one", 1}}}));
CHECK(j == json({ "foo", 1, 2, 3, false, { { "one", 1 } } }));
SaxEventLogger l;
CHECK(json::sax_parse(s, &l));
CHECK(l.events.size() == 11);
CHECK(l.events == std::vector<std::string>({"start_array()",
CHECK(l.events == std::vector<std::string>({ "start_array()",
"string(foo)",
"number_unsigned(1)",
"number_unsigned(2)",
@ -269,7 +269,7 @@ TEST_CASE("deserialization")
"key(one)",
"number_unsigned(1)",
"end_object()",
"end_array()"}));
"end_array()" }));
}
SECTION("string_t")
@ -277,12 +277,12 @@ TEST_CASE("deserialization")
json::string_t const s = R"(["foo",1,2,3,false,{"one":1}])";
json j = json::parse(s);
CHECK(json::accept(s));
CHECK(j == json({"foo", 1, 2, 3, false, {{"one", 1}}}));
CHECK(j == json({ "foo", 1, 2, 3, false, { { "one", 1 } } }));
SaxEventLogger l;
CHECK(json::sax_parse(s, &l));
CHECK(l.events.size() == 11);
CHECK(l.events == std::vector<std::string>({"start_array()",
CHECK(l.events == std::vector<std::string>({ "start_array()",
"string(foo)",
"number_unsigned(1)",
"number_unsigned(2)",
@ -292,7 +292,7 @@ TEST_CASE("deserialization")
"key(one)",
"number_unsigned(1)",
"end_object()",
"end_array()"}));
"end_array()" }));
}
SECTION("operator<<")
@ -301,7 +301,7 @@ TEST_CASE("deserialization")
ss << R"(["foo",1,2,3,false,{"one":1}])";
json j;
j << ss;
CHECK(j == json({"foo", 1, 2, 3, false, {{"one", 1}}}));
CHECK(j == json({ "foo", 1, 2, 3, false, { { "one", 1 } } }));
}
SECTION("operator>>")
@ -310,12 +310,12 @@ TEST_CASE("deserialization")
ss << R"(["foo",1,2,3,false,{"one":1}])";
json j;
ss >> j;
CHECK(j == json({"foo", 1, 2, 3, false, {{"one", 1}}}));
CHECK(j == json({ "foo", 1, 2, 3, false, { { "one", 1 } } }));
}
SECTION("user-defined string literal")
{
CHECK("[\"foo\",1,2,3,false,{\"one\":1}]"_json == json({"foo", 1, 2, 3, false, {{"one", 1}}}));
CHECK("[\"foo\",1,2,3,false,{\"one\":1}]"_json == json({ "foo", 1, 2, 3, false, { { "one", 1 } } }));
}
}
@ -346,7 +346,7 @@ TEST_CASE("deserialization")
SaxEventLogger l;
CHECK(!json::sax_parse(ss5, &l));
CHECK(l.events.size() == 11);
CHECK(l.events == std::vector<std::string>({"start_array()",
CHECK(l.events == std::vector<std::string>({ "start_array()",
"string(foo)",
"number_unsigned(1)",
"number_unsigned(2)",
@ -356,7 +356,7 @@ TEST_CASE("deserialization")
"key(one)",
"number_unsigned(1)",
"end_object()",
"parse_error(29)"}));
"parse_error(29)" }));
}
SECTION("string")
@ -376,7 +376,7 @@ TEST_CASE("deserialization")
SaxEventLogger l;
CHECK(!json::sax_parse(s, &l));
CHECK(l.events.size() == 11);
CHECK(l.events == std::vector<std::string>({"start_array()",
CHECK(l.events == std::vector<std::string>({ "start_array()",
"string(foo)",
"number_unsigned(1)",
"number_unsigned(2)",
@ -386,7 +386,7 @@ TEST_CASE("deserialization")
"key(one)",
"number_unsigned(1)",
"end_object()",
"parse_error(29)"}));
"parse_error(29)" }));
}
SECTION("operator<<")
@ -426,38 +426,38 @@ TEST_CASE("deserialization")
{
SECTION("from std::vector")
{
std::vector<uint8_t> const v = {'t', 'r', 'u', 'e'};
std::vector<uint8_t> const v = { 't', 'r', 'u', 'e' };
CHECK(json::parse(v) == json(true));
CHECK(json::accept(v));
SaxEventLogger l;
CHECK(json::sax_parse(v, &l));
CHECK(l.events.size() == 1);
CHECK(l.events == std::vector<std::string>({"boolean(true)"}));
CHECK(l.events == std::vector<std::string>({ "boolean(true)" }));
}
SECTION("from std::array")
{
std::array<uint8_t, 5> const v{{'t', 'r', 'u', 'e'}};
std::array<uint8_t, 5> const v{ { 't', 'r', 'u', 'e' } };
CHECK(json::parse(v) == json(true));
CHECK(json::accept(v));
SaxEventLogger l;
CHECK(json::sax_parse(v, &l));
CHECK(l.events.size() == 1);
CHECK(l.events == std::vector<std::string>({"boolean(true)"}));
CHECK(l.events == std::vector<std::string>({ "boolean(true)" }));
}
SECTION("from array")
{
uint8_t v[] = {'t', 'r', 'u', 'e'}; // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays)
uint8_t v[] = { 't', 'r', 'u', 'e' }; // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays)
CHECK(json::parse(v) == json(true));
CHECK(json::accept(v));
SaxEventLogger l;
CHECK(json::sax_parse(v, &l));
CHECK(l.events.size() == 1);
CHECK(l.events == std::vector<std::string>({"boolean(true)"}));
CHECK(l.events == std::vector<std::string>({ "boolean(true)" }));
}
SECTION("from chars")
@ -474,33 +474,33 @@ TEST_CASE("deserialization")
SaxEventLogger l;
CHECK(json::sax_parse(v, &l));
CHECK(l.events.size() == 1);
CHECK(l.events == std::vector<std::string>({"boolean(true)"}));
CHECK(l.events == std::vector<std::string>({ "boolean(true)" }));
delete[] v; // NOLINT(cppcoreguidelines-owning-memory)
}
SECTION("from std::string")
{
std::string const v = {'t', 'r', 'u', 'e'};
std::string const v = { 't', 'r', 'u', 'e' };
CHECK(json::parse(v) == json(true));
CHECK(json::accept(v));
SaxEventLogger l;
CHECK(json::sax_parse(v, &l));
CHECK(l.events.size() == 1);
CHECK(l.events == std::vector<std::string>({"boolean(true)"}));
CHECK(l.events == std::vector<std::string>({ "boolean(true)" }));
}
SECTION("from std::initializer_list")
{
std::initializer_list<uint8_t> const v = {'t', 'r', 'u', 'e'};
std::initializer_list<uint8_t> const v = { 't', 'r', 'u', 'e' };
CHECK(json::parse(v) == json(true));
CHECK(json::accept(v));
SaxEventLogger l;
CHECK(json::sax_parse(v, &l));
CHECK(l.events.size() == 1);
CHECK(l.events == std::vector<std::string>({"boolean(true)"}));
CHECK(l.events == std::vector<std::string>({ "boolean(true)" }));
}
SECTION("empty container")
@ -513,7 +513,7 @@ TEST_CASE("deserialization")
SaxEventLogger l;
CHECK(!json::sax_parse(v, &l));
CHECK(l.events.size() == 1);
CHECK(l.events == std::vector<std::string>({"parse_error(1)"}));
CHECK(l.events == std::vector<std::string>({ "parse_error(1)" }));
}
}
@ -521,74 +521,74 @@ TEST_CASE("deserialization")
{
SECTION("from std::vector")
{
std::vector<uint8_t> v = {'t', 'r', 'u', 'e'};
std::vector<uint8_t> v = { 't', 'r', 'u', 'e' };
CHECK(json::parse(std::begin(v), std::end(v)) == json(true));
CHECK(json::accept(std::begin(v), std::end(v)));
SaxEventLogger l;
CHECK(json::sax_parse(std::begin(v), std::end(v), &l));
CHECK(l.events.size() == 1);
CHECK(l.events == std::vector<std::string>({"boolean(true)"}));
CHECK(l.events == std::vector<std::string>({ "boolean(true)" }));
}
SECTION("from std::array")
{
std::array<uint8_t, 5> v{{'t', 'r', 'u', 'e'}};
std::array<uint8_t, 5> v{ { 't', 'r', 'u', 'e' } };
CHECK(json::parse(std::begin(v), std::end(v)) == json(true));
CHECK(json::accept(std::begin(v), std::end(v)));
SaxEventLogger l;
CHECK(json::sax_parse(std::begin(v), std::end(v), &l));
CHECK(l.events.size() == 1);
CHECK(l.events == std::vector<std::string>({"boolean(true)"}));
CHECK(l.events == std::vector<std::string>({ "boolean(true)" }));
}
SECTION("from array")
{
uint8_t v[] = {'t', 'r', 'u', 'e'}; // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays)
uint8_t v[] = { 't', 'r', 'u', 'e' }; // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays)
CHECK(json::parse(std::begin(v), std::end(v)) == json(true));
CHECK(json::accept(std::begin(v), std::end(v)));
SaxEventLogger l;
CHECK(json::sax_parse(std::begin(v), std::end(v), &l));
CHECK(l.events.size() == 1);
CHECK(l.events == std::vector<std::string>({"boolean(true)"}));
CHECK(l.events == std::vector<std::string>({ "boolean(true)" }));
}
SECTION("from std::string")
{
std::string v = {'t', 'r', 'u', 'e'};
std::string v = { 't', 'r', 'u', 'e' };
CHECK(json::parse(std::begin(v), std::end(v)) == json(true));
CHECK(json::accept(std::begin(v), std::end(v)));
SaxEventLogger l;
CHECK(json::sax_parse(std::begin(v), std::end(v), &l));
CHECK(l.events.size() == 1);
CHECK(l.events == std::vector<std::string>({"boolean(true)"}));
CHECK(l.events == std::vector<std::string>({ "boolean(true)" }));
}
SECTION("from std::initializer_list")
{
std::initializer_list<uint8_t> const v = {'t', 'r', 'u', 'e'};
std::initializer_list<uint8_t> const v = { 't', 'r', 'u', 'e' };
CHECK(json::parse(std::begin(v), std::end(v)) == json(true));
CHECK(json::accept(std::begin(v), std::end(v)));
SaxEventLogger l;
CHECK(json::sax_parse(std::begin(v), std::end(v), &l));
CHECK(l.events.size() == 1);
CHECK(l.events == std::vector<std::string>({"boolean(true)"}));
CHECK(l.events == std::vector<std::string>({ "boolean(true)" }));
}
SECTION("from std::valarray")
{
std::valarray<uint8_t> v = {'t', 'r', 'u', 'e'};
std::valarray<uint8_t> v = { 't', 'r', 'u', 'e' };
CHECK(json::parse(std::begin(v), std::end(v)) == json(true));
CHECK(json::accept(std::begin(v), std::end(v)));
SaxEventLogger l;
CHECK(json::sax_parse(std::begin(v), std::end(v), &l));
CHECK(l.events.size() == 1);
CHECK(l.events == std::vector<std::string>({"boolean(true)"}));
CHECK(l.events == std::vector<std::string>({ "boolean(true)" }));
}
SECTION("with empty range")
@ -601,7 +601,7 @@ TEST_CASE("deserialization")
SaxEventLogger l;
CHECK(!json::sax_parse(std::begin(v), std::end(v), &l));
CHECK(l.events.size() == 1);
CHECK(l.events == std::vector<std::string>({"parse_error(1)"}));
CHECK(l.events == std::vector<std::string>({ "parse_error(1)" }));
}
SECTION("iterator_input_adapter advances iterators correctly")
@ -631,7 +631,7 @@ TEST_CASE("deserialization")
{
SECTION("case 1")
{
std::array<std::uint8_t, 9> v = {{'\"', 'a', 'a', 'a', 'a', 'a', 'a', '\\', 'u'}};
std::array<std::uint8_t, 9> v = { { '\"', 'a', 'a', 'a', 'a', 'a', 'a', '\\', 'u' } };
json _;
CHECK_THROWS_AS(_ = json::parse(std::begin(v), std::end(v)), json::parse_error&);
CHECK(!json::accept(std::begin(v), std::end(v)));
@ -643,12 +643,12 @@ TEST_CASE("deserialization")
SaxEventLogger l;
CHECK(!json::sax_parse(std::begin(v), std::end(v), &l));
CHECK(l.events.size() == 1);
CHECK(l.events == std::vector<std::string>({"parse_error(10)"}));
CHECK(l.events == std::vector<std::string>({ "parse_error(10)" }));
}
SECTION("case 2")
{
std::array<std::uint8_t, 10> v = {{'\"', 'a', 'a', 'a', 'a', 'a', 'a', '\\', 'u', '1'}};
std::array<std::uint8_t, 10> v = { { '\"', 'a', 'a', 'a', 'a', 'a', 'a', '\\', 'u', '1' } };
json _;
CHECK_THROWS_AS(_ = json::parse(std::begin(v), std::end(v)), json::parse_error&);
CHECK(!json::accept(std::begin(v), std::end(v)));
@ -660,12 +660,12 @@ TEST_CASE("deserialization")
SaxEventLogger l;
CHECK(!json::sax_parse(std::begin(v), std::end(v), &l));
CHECK(l.events.size() == 1);
CHECK(l.events == std::vector<std::string>({"parse_error(11)"}));
CHECK(l.events == std::vector<std::string>({ "parse_error(11)" }));
}
SECTION("case 3")
{
std::array<std::uint8_t, 17> v = {{'\"', 'a', 'a', 'a', 'a', 'a', 'a', '\\', 'u', '1', '1', '1', '1', '1', '1', '1', '1'}};
std::array<std::uint8_t, 17> v = { { '\"', 'a', 'a', 'a', 'a', 'a', 'a', '\\', 'u', '1', '1', '1', '1', '1', '1', '1', '1' } };
json _;
CHECK_THROWS_AS(_ = json::parse(std::begin(v), std::end(v)), json::parse_error&);
CHECK(!json::accept(std::begin(v), std::end(v)));
@ -677,12 +677,12 @@ TEST_CASE("deserialization")
SaxEventLogger l;
CHECK(!json::sax_parse(std::begin(v), std::end(v), &l));
CHECK(l.events.size() == 1);
CHECK(l.events == std::vector<std::string>({"parse_error(18)"}));
CHECK(l.events == std::vector<std::string>({ "parse_error(18)" }));
}
SECTION("case 4")
{
std::array<std::uint8_t, 17> v = {{'\"', 'a', 'a', 'a', 'a', 'a', 'a', 'u', '1', '1', '1', '1', '1', '1', '1', '1', '\\'}};
std::array<std::uint8_t, 17> v = { { '\"', 'a', 'a', 'a', 'a', 'a', 'a', 'u', '1', '1', '1', '1', '1', '1', '1', '1', '\\' } };
json _;
CHECK_THROWS_AS(_ = json::parse(std::begin(v), std::end(v)), json::parse_error&);
CHECK(!json::accept(std::begin(v), std::end(v)));
@ -694,12 +694,12 @@ TEST_CASE("deserialization")
SaxEventLogger l;
CHECK(!json::sax_parse(std::begin(v), std::end(v), &l));
CHECK(l.events.size() == 1);
CHECK(l.events == std::vector<std::string>({"parse_error(18)"}));
CHECK(l.events == std::vector<std::string>({ "parse_error(18)" }));
}
SECTION("case 5")
{
std::array<std::uint8_t, 3> v = {{'\"', 0x7F, 0xC1}};
std::array<std::uint8_t, 3> v = { { '\"', 0x7F, 0xC1 } };
json _;
CHECK_THROWS_AS(_ = json::parse(std::begin(v), std::end(v)), json::parse_error&);
CHECK(!json::accept(std::begin(v), std::end(v)));
@ -711,12 +711,12 @@ TEST_CASE("deserialization")
SaxEventLogger l;
CHECK(!json::sax_parse(std::begin(v), std::end(v), &l));
CHECK(l.events.size() == 1);
CHECK(l.events == std::vector<std::string>({"parse_error(3)"}));
CHECK(l.events == std::vector<std::string>({ "parse_error(3)" }));
}
SECTION("case 6")
{
std::array<std::uint8_t, 4> v = {{'\"', 0x7F, 0xDF, 0x7F}};
std::array<std::uint8_t, 4> v = { { '\"', 0x7F, 0xDF, 0x7F } };
json _;
CHECK_THROWS_WITH_AS(
_ = json::parse(std::begin(v), std::end(v)),
@ -731,12 +731,12 @@ TEST_CASE("deserialization")
SaxEventLogger l;
CHECK(!json::sax_parse(std::begin(v), std::end(v), &l));
CHECK(l.events.size() == 1);
CHECK(l.events == std::vector<std::string>({"parse_error(4)"}));
CHECK(l.events == std::vector<std::string>({ "parse_error(4)" }));
}
SECTION("case 7")
{
std::array<std::uint8_t, 4> v = {{'\"', 0x7F, 0xDF, 0xC0}};
std::array<std::uint8_t, 4> v = { { '\"', 0x7F, 0xDF, 0xC0 } };
json _;
CHECK_THROWS_AS(_ = json::parse(std::begin(v), std::end(v)), json::parse_error&);
CHECK(!json::accept(std::begin(v), std::end(v)));
@ -748,12 +748,12 @@ TEST_CASE("deserialization")
SaxEventLogger l;
CHECK(!json::sax_parse(std::begin(v), std::end(v), &l));
CHECK(l.events.size() == 1);
CHECK(l.events == std::vector<std::string>({"parse_error(4)"}));
CHECK(l.events == std::vector<std::string>({ "parse_error(4)" }));
}
SECTION("case 8")
{
std::array<std::uint8_t, 4> v = {{'\"', 0x7F, 0xE0, 0x9F}};
std::array<std::uint8_t, 4> v = { { '\"', 0x7F, 0xE0, 0x9F } };
json _;
CHECK_THROWS_AS(_ = json::parse(std::begin(v), std::end(v)), json::parse_error&);
CHECK(!json::accept(std::begin(v), std::end(v)));
@ -765,12 +765,12 @@ TEST_CASE("deserialization")
SaxEventLogger l;
CHECK(!json::sax_parse(std::begin(v), std::end(v), &l));
CHECK(l.events.size() == 1);
CHECK(l.events == std::vector<std::string>({"parse_error(4)"}));
CHECK(l.events == std::vector<std::string>({ "parse_error(4)" }));
}
SECTION("case 9")
{
std::array<std::uint8_t, 4> v = {{'\"', 0x7F, 0xEF, 0xC0}};
std::array<std::uint8_t, 4> v = { { '\"', 0x7F, 0xEF, 0xC0 } };
json _;
CHECK_THROWS_AS(_ = json::parse(std::begin(v), std::end(v)), json::parse_error&);
CHECK(!json::accept(std::begin(v), std::end(v)));
@ -782,12 +782,12 @@ TEST_CASE("deserialization")
SaxEventLogger l;
CHECK(!json::sax_parse(std::begin(v), std::end(v), &l));
CHECK(l.events.size() == 1);
CHECK(l.events == std::vector<std::string>({"parse_error(4)"}));
CHECK(l.events == std::vector<std::string>({ "parse_error(4)" }));
}
SECTION("case 10")
{
std::array<std::uint8_t, 4> v = {{'\"', 0x7F, 0xED, 0x7F}};
std::array<std::uint8_t, 4> v = { { '\"', 0x7F, 0xED, 0x7F } };
json _;
CHECK_THROWS_AS(_ = json::parse(std::begin(v), std::end(v)), json::parse_error&);
CHECK(!json::accept(std::begin(v), std::end(v)));
@ -799,12 +799,12 @@ TEST_CASE("deserialization")
SaxEventLogger l;
CHECK(!json::sax_parse(std::begin(v), std::end(v), &l));
CHECK(l.events.size() == 1);
CHECK(l.events == std::vector<std::string>({"parse_error(4)"}));
CHECK(l.events == std::vector<std::string>({ "parse_error(4)" }));
}
SECTION("case 11")
{
std::array<std::uint8_t, 4> v = {{'\"', 0x7F, 0xF0, 0x8F}};
std::array<std::uint8_t, 4> v = { { '\"', 0x7F, 0xF0, 0x8F } };
json _;
CHECK_THROWS_AS(_ = json::parse(std::begin(v), std::end(v)), json::parse_error&);
CHECK(!json::accept(std::begin(v), std::end(v)));
@ -816,12 +816,12 @@ TEST_CASE("deserialization")
SaxEventLogger l;
CHECK(!json::sax_parse(std::begin(v), std::end(v), &l));
CHECK(l.events.size() == 1);
CHECK(l.events == std::vector<std::string>({"parse_error(4)"}));
CHECK(l.events == std::vector<std::string>({ "parse_error(4)" }));
}
SECTION("case 12")
{
std::array<std::uint8_t, 4> v = {{'\"', 0x7F, 0xF0, 0xC0}};
std::array<std::uint8_t, 4> v = { { '\"', 0x7F, 0xF0, 0xC0 } };
json _;
CHECK_THROWS_AS(_ = json::parse(std::begin(v), std::end(v)), json::parse_error&);
CHECK(!json::accept(std::begin(v), std::end(v)));
@ -833,12 +833,12 @@ TEST_CASE("deserialization")
SaxEventLogger l;
CHECK(!json::sax_parse(std::begin(v), std::end(v), &l));
CHECK(l.events.size() == 1);
CHECK(l.events == std::vector<std::string>({"parse_error(4)"}));
CHECK(l.events == std::vector<std::string>({ "parse_error(4)" }));
}
SECTION("case 13")
{
std::array<std::uint8_t, 4> v = {{'\"', 0x7F, 0xF3, 0x7F}};
std::array<std::uint8_t, 4> v = { { '\"', 0x7F, 0xF3, 0x7F } };
json _;
CHECK_THROWS_AS(_ = json::parse(std::begin(v), std::end(v)), json::parse_error&);
CHECK(!json::accept(std::begin(v), std::end(v)));
@ -850,12 +850,12 @@ TEST_CASE("deserialization")
SaxEventLogger l;
CHECK(!json::sax_parse(std::begin(v), std::end(v), &l));
CHECK(l.events.size() == 1);
CHECK(l.events == std::vector<std::string>({"parse_error(4)"}));
CHECK(l.events == std::vector<std::string>({ "parse_error(4)" }));
}
SECTION("case 14")
{
std::array<std::uint8_t, 4> v = {{'\"', 0x7F, 0xF3, 0xC0}};
std::array<std::uint8_t, 4> v = { { '\"', 0x7F, 0xF3, 0xC0 } };
json _;
CHECK_THROWS_AS(_ = json::parse(std::begin(v), std::end(v)), json::parse_error&);
CHECK(!json::accept(std::begin(v), std::end(v)));
@ -867,12 +867,12 @@ TEST_CASE("deserialization")
SaxEventLogger l;
CHECK(!json::sax_parse(std::begin(v), std::end(v), &l));
CHECK(l.events.size() == 1);
CHECK(l.events == std::vector<std::string>({"parse_error(4)"}));
CHECK(l.events == std::vector<std::string>({ "parse_error(4)" }));
}
SECTION("case 15")
{
std::array<std::uint8_t, 4> v = {{'\"', 0x7F, 0xF4, 0x7F}};
std::array<std::uint8_t, 4> v = { { '\"', 0x7F, 0xF4, 0x7F } };
json _;
CHECK_THROWS_AS(_ = json::parse(std::begin(v), std::end(v)), json::parse_error&);
CHECK(!json::accept(std::begin(v), std::end(v)));
@ -884,12 +884,12 @@ TEST_CASE("deserialization")
SaxEventLogger l;
CHECK(!json::sax_parse(std::begin(v), std::end(v), &l));
CHECK(l.events.size() == 1);
CHECK(l.events == std::vector<std::string>({"parse_error(4)"}));
CHECK(l.events == std::vector<std::string>({ "parse_error(4)" }));
}
SECTION("case 16")
{
std::array<std::uint8_t, 6> v = {{'{', '\"', '\"', ':', '1', '1'}};
std::array<std::uint8_t, 6> v = { { '{', '\"', '\"', ':', '1', '1' } };
json _;
CHECK_THROWS_AS(_ = json::parse(std::begin(v), std::end(v)), json::parse_error&);
CHECK(!json::accept(std::begin(v), std::end(v)));
@ -901,7 +901,7 @@ TEST_CASE("deserialization")
SaxEventLogger l;
CHECK(!json::sax_parse(std::begin(v), std::end(v), &l));
CHECK(l.events.size() == 4);
CHECK(l.events == std::vector<std::string>({"start_object()", "key()", "number_unsigned(11)", "parse_error(7)"}));
CHECK(l.events == std::vector<std::string>({ "start_object()", "key()", "number_unsigned(11)", "parse_error(7)" }));
}
}
}
@ -926,7 +926,7 @@ TEST_CASE("deserialization")
SaxEventLogger l;
CHECK(!json::sax_parse(bom, &l));
CHECK(l.events.size() == 1);
CHECK(l.events == std::vector<std::string>({"parse_error(4)"}));
CHECK(l.events == std::vector<std::string>({ "parse_error(4)" }));
}
SECTION("BOM and content")
@ -939,9 +939,9 @@ TEST_CASE("deserialization")
CHECK(json::sax_parse(std::istringstream(bom + "1"), &l1));
CHECK(json::sax_parse(bom + "1", &l2));
CHECK(l1.events.size() == 1);
CHECK(l1.events == std::vector<std::string>({"number_unsigned(1)"}));
CHECK(l1.events == std::vector<std::string>({ "number_unsigned(1)" }));
CHECK(l2.events.size() == 1);
CHECK(l2.events == std::vector<std::string>({"number_unsigned(1)"}));
CHECK(l2.events == std::vector<std::string>({ "number_unsigned(1)" }));
}
SECTION("2 byte of BOM")
@ -962,9 +962,9 @@ TEST_CASE("deserialization")
CHECK(!json::sax_parse(std::istringstream(bom.substr(0, 2)), &l1));
CHECK(!json::sax_parse(bom.substr(0, 2), &l2));
CHECK(l1.events.size() == 1);
CHECK(l1.events == std::vector<std::string>({"parse_error(3)"}));
CHECK(l1.events == std::vector<std::string>({ "parse_error(3)" }));
CHECK(l2.events.size() == 1);
CHECK(l2.events == std::vector<std::string>({"parse_error(3)"}));
CHECK(l2.events == std::vector<std::string>({ "parse_error(3)" }));
}
SECTION("1 byte of BOM")
@ -985,9 +985,9 @@ TEST_CASE("deserialization")
CHECK(!json::sax_parse(std::istringstream(bom.substr(0, 1)), &l1));
CHECK(!json::sax_parse(bom.substr(0, 1), &l2));
CHECK(l1.events.size() == 1);
CHECK(l1.events == std::vector<std::string>({"parse_error(2)"}));
CHECK(l1.events == std::vector<std::string>({ "parse_error(2)" }));
CHECK(l2.events.size() == 1);
CHECK(l2.events == std::vector<std::string>({"parse_error(2)"}));
CHECK(l2.events == std::vector<std::string>({ "parse_error(2)" }));
}
SECTION("variations")
@ -1019,7 +1019,7 @@ TEST_CASE("deserialization")
SaxEventLogger l;
CHECK(json::sax_parse(s + "null", &l));
CHECK(l.events.size() == 1);
CHECK(l.events == std::vector<std::string>({"null()"}));
CHECK(l.events == std::vector<std::string>({ "null()" }));
}
else
{
@ -1034,15 +1034,15 @@ TEST_CASE("deserialization")
if (i0 != 0)
{
CHECK(l.events == std::vector<std::string>({"parse_error(1)"}));
CHECK(l.events == std::vector<std::string>({ "parse_error(1)" }));
}
else if (i1 != 0)
{
CHECK(l.events == std::vector<std::string>({"parse_error(2)"}));
CHECK(l.events == std::vector<std::string>({ "parse_error(2)" }));
}
else
{
CHECK(l.events == std::vector<std::string>({"parse_error(3)"}));
CHECK(l.events == std::vector<std::string>({ "parse_error(3)" }));
}
}
}
@ -1072,7 +1072,7 @@ TEST_CASE("deserialization")
json::sax_parse(s, &default_logger);
CHECK(default_logger.events.size() == 14);
CHECK(default_logger.events == std::vector<std::string>({"start_array()",
CHECK(default_logger.events == std::vector<std::string>({ "start_array()",
"number_unsigned(1)",
"start_array()",
"string(string)",
@ -1085,18 +1085,22 @@ TEST_CASE("deserialization")
"key(key2)",
"boolean(false)",
"end_object()",
"end_array()"}));
"end_array()" }));
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);
CHECK(exit_after_key.events == std::vector<std::string>({"start_array()",
CHECK(exit_after_key.events == std::vector<std::string>({ "start_array()",
"number_unsigned(1)",
"start_array()",
"string(string)",
@ -1104,11 +1108,11 @@ TEST_CASE("deserialization")
"end_array()",
"null()",
"start_object()",
"key(key1)"}));
"key(key1)" }));
json::sax_parse(s, &exit_after_start_array);
CHECK(exit_after_start_array.events.size() == 1);
CHECK(exit_after_start_array.events == std::vector<std::string>({"start_array()"}));
CHECK(exit_after_start_array.events == std::vector<std::string>({ "start_array()" }));
}
SECTION("JSON Lines")
@ -1169,21 +1173,22 @@ TEST_CASE_TEMPLATE("deserialization of different character types (ASCII)",
std::int32_t,
std::uint32_t)
{
std::vector<T> const v = {'t', 'r', 'u', 'e'};
std::vector<T> const v = { 't', 'r', 'u', 'e' };
CHECK(json::parse(v) == json(true));
CHECK(json::accept(v));
SaxEventLogger l;
CHECK(json::sax_parse(v, &l));
CHECK(l.events.size() == 1);
CHECK(l.events == std::vector<std::string>({"boolean(true)"}));
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)
{
// 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));
@ -1195,7 +1200,7 @@ TEST_CASE_TEMPLATE("deserialization of different character types (UTF-8)", T, ch
TEST_CASE_TEMPLATE("deserialization of different character types (UTF-16)", T, char16_t, std::uint16_t)
{
// a star emoji
std::vector<T> const v = {static_cast<T>('"'), static_cast<T>(0x2b50), static_cast<T>(0xfe0f), static_cast<T>('"')};
std::vector<T> const v = { static_cast<T>('"'), static_cast<T>(0x2b50), static_cast<T>(0xfe0f), static_cast<T>('"') };
CHECK(json::parse(v).dump(-1, ' ', true) == "\"\\u2b50\\ufe0f\"");
CHECK(json::accept(v));
@ -1207,7 +1212,7 @@ TEST_CASE_TEMPLATE("deserialization of different character types (UTF-16)", T, c
TEST_CASE_TEMPLATE("deserialization of different character types (UTF-32)", T, char32_t, std::uint32_t)
{
// a star emoji
std::vector<T> const v = {static_cast<T>('"'), static_cast<T>(0x2b50), static_cast<T>(0xfe0f), static_cast<T>('"')};
std::vector<T> const v = { static_cast<T>('"'), static_cast<T>(0x2b50), static_cast<T>(0xfe0f), static_cast<T>('"') };
CHECK(json::parse(v).dump(-1, ' ', true) == "\"\\u2b50\\ufe0f\"");
CHECK(json::accept(v));

View File

@ -90,8 +90,8 @@ TEST_CASE("Better diagnostics")
SECTION("Wrong type in update()")
{
json j = {{"foo", "bar"}};
json k = {{"bla", 1}};
json j = { { "foo", "bar" } };
json k = { { "bla", 1 } };
CHECK_THROWS_WITH_AS(j.update(k["bla"].begin(), k["bla"].end()),
"[json.exception.type_error.312] (/bla) cannot use update() with number",
@ -104,14 +104,14 @@ TEST_CASE("Regression tests for extended diagnostics")
{
SECTION("Regression test for https://github.com/nlohmann/json/pull/2562#pullrequestreview-574858448")
{
CHECK_THROWS_WITH_AS(json({"0", "0"})[1].get<int>(), "[json.exception.type_error.302] (/1) type must be number, but is string", json::type_error);
CHECK_THROWS_WITH_AS(json({"0", "1"})[1].get<int>(), "[json.exception.type_error.302] (/1) type must be number, but is string", json::type_error);
CHECK_THROWS_WITH_AS(json({ "0", "0" })[1].get<int>(), "[json.exception.type_error.302] (/1) type must be number, but is string", json::type_error);
CHECK_THROWS_WITH_AS(json({ "0", "1" })[1].get<int>(), "[json.exception.type_error.302] (/1) type must be number, but is string", json::type_error);
}
SECTION("Regression test for https://github.com/nlohmann/json/pull/2562/files/380a613f2b5d32425021129cd1f371ddcfd54ddf#r563259793")
{
json j;
j["/foo"] = {1, 2, 3};
j["/foo"] = { 1, 2, 3 };
CHECK_THROWS_WITH_AS(j.unflatten(), "[json.exception.type_error.315] (/~1foo) values in object must be primitive", json::type_error);
}
@ -173,7 +173,7 @@ TEST_CASE("Regression tests for extended diagnostics")
// iterator insert(const_iterator pos, const_iterator first, const_iterator last)
{
json j_arr = json::array();
json j_objects = {json::object(), json::object()};
json j_objects = { json::object(), json::object() };
j_arr.insert(j_arr.begin(), j_objects.begin(), j_objects.end());
json j_obj = json::object();
j_obj["key"] = j_arr;

View File

@ -16,7 +16,7 @@ TEST_CASE("element access 1")
{
SECTION("array")
{
json j = {1, 1u, true, nullptr, "string", 42.23, json::object(), {1, 2, 3}};
json j = { 1, 1u, true, nullptr, "string", 42.23, json::object(), { 1, 2, 3 } };
const json j_const = j;
SECTION("access specified element with bounds checking")
@ -30,7 +30,7 @@ TEST_CASE("element access 1")
CHECK(j.at(4) == json("string"));
CHECK(j.at(5) == json(42.23));
CHECK(j.at(6) == json::object());
CHECK(j.at(7) == json({1, 2, 3}));
CHECK(j.at(7) == json({ 1, 2, 3 }));
CHECK(j_const.at(0) == json(1));
CHECK(j_const.at(1) == json(1u));
@ -39,7 +39,7 @@ TEST_CASE("element access 1")
CHECK(j_const.at(4) == json("string"));
CHECK(j_const.at(5) == json(42.23));
CHECK(j_const.at(6) == json::object());
CHECK(j_const.at(7) == json({1, 2, 3}));
CHECK(j_const.at(7) == json({ 1, 2, 3 }));
}
SECTION("access outside bounds")
@ -119,8 +119,8 @@ TEST_CASE("element access 1")
{
CHECK(j.front() == json(1));
CHECK(j_const.front() == json(1));
CHECK(j.back() == json({1, 2, 3}));
CHECK(j_const.back() == json({1, 2, 3}));
CHECK(j.back() == json({ 1, 2, 3 }));
CHECK(j_const.back() == json({ 1, 2, 3 }));
}
SECTION("access specified element")
@ -134,7 +134,7 @@ TEST_CASE("element access 1")
CHECK(j[4] == json("string"));
CHECK(j[5] == json(42.23));
CHECK(j[6] == json::object());
CHECK(j[7] == json({1, 2, 3}));
CHECK(j[7] == json({ 1, 2, 3 }));
CHECK(j_const[0] == json(1));
CHECK(j_const[1] == json(1u));
@ -143,7 +143,7 @@ TEST_CASE("element access 1")
CHECK(j_const[4] == json("string"));
CHECK(j_const[5] == json(42.23));
CHECK(j_const[6] == json::object());
CHECK(j_const[7] == json({1, 2, 3}));
CHECK(j_const[7] == json({ 1, 2, 3 }));
}
SECTION("access on non-array type")
@ -164,7 +164,7 @@ TEST_CASE("element access 1")
{
json j_nonarray;
j_nonarray[3] = 42;
CHECK(j_nonarray == json({nullptr, nullptr, nullptr, 42}));
CHECK(j_nonarray == json({ nullptr, nullptr, nullptr, 42 }));
}
}
@ -247,47 +247,47 @@ TEST_CASE("element access 1")
SECTION("remove element by index")
{
{
json jarray = {1, 1u, true, nullptr, "string", 42.23, json::object(), {1, 2, 3}};
json jarray = { 1, 1u, true, nullptr, "string", 42.23, json::object(), { 1, 2, 3 } };
jarray.erase(0);
CHECK(jarray == json({1u, true, nullptr, "string", 42.23, json::object(), {1, 2, 3}}));
CHECK(jarray == json({ 1u, true, nullptr, "string", 42.23, json::object(), { 1, 2, 3 } }));
}
{
json jarray = {1, 1u, true, nullptr, "string", 42.23, json::object(), {1, 2, 3}};
json jarray = { 1, 1u, true, nullptr, "string", 42.23, json::object(), { 1, 2, 3 } };
jarray.erase(1);
CHECK(jarray == json({1, true, nullptr, "string", 42.23, json::object(), {1, 2, 3}}));
CHECK(jarray == json({ 1, true, nullptr, "string", 42.23, json::object(), { 1, 2, 3 } }));
}
{
json jarray = {1, 1u, true, nullptr, "string", 42.23, json::object(), {1, 2, 3}};
json jarray = { 1, 1u, true, nullptr, "string", 42.23, json::object(), { 1, 2, 3 } };
jarray.erase(2);
CHECK(jarray == json({1, 1u, nullptr, "string", 42.23, json::object(), {1, 2, 3}}));
CHECK(jarray == json({ 1, 1u, nullptr, "string", 42.23, json::object(), { 1, 2, 3 } }));
}
{
json jarray = {1, 1u, true, nullptr, "string", 42.23, json::object(), {1, 2, 3}};
json jarray = { 1, 1u, true, nullptr, "string", 42.23, json::object(), { 1, 2, 3 } };
jarray.erase(3);
CHECK(jarray == json({1, 1u, true, "string", 42.23, json::object(), {1, 2, 3}}));
CHECK(jarray == json({ 1, 1u, true, "string", 42.23, json::object(), { 1, 2, 3 } }));
}
{
json jarray = {1, 1u, true, nullptr, "string", 42.23, json::object(), {1, 2, 3}};
json jarray = { 1, 1u, true, nullptr, "string", 42.23, json::object(), { 1, 2, 3 } };
jarray.erase(4);
CHECK(jarray == json({1, 1u, true, nullptr, 42.23, json::object(), {1, 2, 3}}));
CHECK(jarray == json({ 1, 1u, true, nullptr, 42.23, json::object(), { 1, 2, 3 } }));
}
{
json jarray = {1, 1u, true, nullptr, "string", 42.23, json::object(), {1, 2, 3}};
json jarray = { 1, 1u, true, nullptr, "string", 42.23, json::object(), { 1, 2, 3 } };
jarray.erase(5);
CHECK(jarray == json({1, 1u, true, nullptr, "string", json::object(), {1, 2, 3}}));
CHECK(jarray == json({ 1, 1u, true, nullptr, "string", json::object(), { 1, 2, 3 } }));
}
{
json jarray = {1, 1u, true, nullptr, "string", 42.23, json::object(), {1, 2, 3}};
json jarray = { 1, 1u, true, nullptr, "string", 42.23, json::object(), { 1, 2, 3 } };
jarray.erase(6);
CHECK(jarray == json({1, 1u, true, nullptr, "string", 42.23, {1, 2, 3}}));
CHECK(jarray == json({ 1, 1u, true, nullptr, "string", 42.23, { 1, 2, 3 } }));
}
{
json jarray = {1, 1u, true, nullptr, "string", 42.23, json::object(), {1, 2, 3}};
json jarray = { 1, 1u, true, nullptr, "string", 42.23, json::object(), { 1, 2, 3 } };
jarray.erase(7);
CHECK(jarray == json({1, 1u, true, nullptr, "string", 42.23, json::object()}));
CHECK(jarray == json({ 1, 1u, true, nullptr, "string", 42.23, json::object() }));
}
{
json jarray = {1, 1u, true, nullptr, "string", 42.23, json::object(), {1, 2, 3}};
json jarray = { 1, 1u, true, nullptr, "string", 42.23, json::object(), { 1, 2, 3 } };
CHECK_THROWS_WITH_AS(jarray.erase(8), "[json.exception.out_of_range.401] array index 8 is out of range", json::out_of_range&);
}
}
@ -297,15 +297,15 @@ TEST_CASE("element access 1")
SECTION("erase(begin())")
{
{
json jarray = {1, 1u, true, nullptr, "string", 42.23, json::object(), {1, 2, 3}};
json jarray = { 1, 1u, true, nullptr, "string", 42.23, json::object(), { 1, 2, 3 } };
json::iterator const it2 = jarray.erase(jarray.begin());
CHECK(jarray == json({1u, true, nullptr, "string", 42.23, json::object(), {1, 2, 3}}));
CHECK(jarray == json({ 1u, true, nullptr, "string", 42.23, json::object(), { 1, 2, 3 } }));
CHECK(*it2 == json(1u));
}
{
json jarray = {1, 1u, true, nullptr, "string", 42.23, json::object(), {1, 2, 3}};
json jarray = { 1, 1u, true, nullptr, "string", 42.23, json::object(), { 1, 2, 3 } };
json::const_iterator const it2 = jarray.erase(jarray.cbegin());
CHECK(jarray == json({1u, true, nullptr, "string", 42.23, json::object(), {1, 2, 3}}));
CHECK(jarray == json({ 1u, true, nullptr, "string", 42.23, json::object(), { 1, 2, 3 } }));
CHECK(*it2 == json(1u));
}
}
@ -313,13 +313,13 @@ TEST_CASE("element access 1")
SECTION("erase(begin(), end())")
{
{
json jarray = {1, 1u, true, nullptr, "string", 42.23, json::object(), {1, 2, 3}};
json jarray = { 1, 1u, true, nullptr, "string", 42.23, json::object(), { 1, 2, 3 } };
json::iterator it2 = jarray.erase(jarray.begin(), jarray.end());
CHECK(jarray == json::array());
CHECK(it2 == jarray.end());
}
{
json jarray = {1, 1u, true, nullptr, "string", 42.23, json::object(), {1, 2, 3}};
json jarray = { 1, 1u, true, nullptr, "string", 42.23, json::object(), { 1, 2, 3 } };
json::const_iterator it2 = jarray.erase(jarray.cbegin(), jarray.cend());
CHECK(jarray == json::array());
CHECK(it2 == jarray.cend());
@ -329,15 +329,15 @@ TEST_CASE("element access 1")
SECTION("erase(begin(), begin())")
{
{
json jarray = {1, 1u, true, nullptr, "string", 42.23, json::object(), {1, 2, 3}};
json jarray = { 1, 1u, true, nullptr, "string", 42.23, json::object(), { 1, 2, 3 } };
json::iterator const it2 = jarray.erase(jarray.begin(), jarray.begin());
CHECK(jarray == json({1, 1u, true, nullptr, "string", 42.23, json::object(), {1, 2, 3}}));
CHECK(jarray == json({ 1, 1u, true, nullptr, "string", 42.23, json::object(), { 1, 2, 3 } }));
CHECK(*it2 == json(1));
}
{
json jarray = {1, 1u, true, nullptr, "string", 42.23, json::object(), {1, 2, 3}};
json jarray = { 1, 1u, true, nullptr, "string", 42.23, json::object(), { 1, 2, 3 } };
json::const_iterator const it2 = jarray.erase(jarray.cbegin(), jarray.cbegin());
CHECK(jarray == json({1, 1u, true, nullptr, "string", 42.23, json::object(), {1, 2, 3}}));
CHECK(jarray == json({ 1, 1u, true, nullptr, "string", 42.23, json::object(), { 1, 2, 3 } }));
CHECK(*it2 == json(1));
}
}
@ -345,17 +345,17 @@ TEST_CASE("element access 1")
SECTION("erase at offset")
{
{
json jarray = {1, 1u, true, nullptr, "string", 42.23, json::object(), {1, 2, 3}};
json jarray = { 1, 1u, true, nullptr, "string", 42.23, json::object(), { 1, 2, 3 } };
json::iterator const it = jarray.begin() + 4;
json::iterator const it2 = jarray.erase(it);
CHECK(jarray == json({1, 1u, true, nullptr, 42.23, json::object(), {1, 2, 3}}));
CHECK(jarray == json({ 1, 1u, true, nullptr, 42.23, json::object(), { 1, 2, 3 } }));
CHECK(*it2 == json(42.23));
}
{
json jarray = {1, 1u, true, nullptr, "string", 42.23, json::object(), {1, 2, 3}};
json jarray = { 1, 1u, true, nullptr, "string", 42.23, json::object(), { 1, 2, 3 } };
json::const_iterator const it = jarray.cbegin() + 4;
json::const_iterator const it2 = jarray.erase(it);
CHECK(jarray == json({1, 1u, true, nullptr, 42.23, json::object(), {1, 2, 3}}));
CHECK(jarray == json({ 1, 1u, true, nullptr, 42.23, json::object(), { 1, 2, 3 } }));
CHECK(*it2 == json(42.23));
}
}
@ -363,15 +363,15 @@ TEST_CASE("element access 1")
SECTION("erase subrange")
{
{
json jarray = {1, 1u, true, nullptr, "string", 42.23, json::object(), {1, 2, 3}};
json jarray = { 1, 1u, true, nullptr, "string", 42.23, json::object(), { 1, 2, 3 } };
json::iterator const it2 = jarray.erase(jarray.begin() + 3, jarray.begin() + 6);
CHECK(jarray == json({1, 1u, true, json::object(), {1, 2, 3}}));
CHECK(jarray == json({ 1, 1u, true, json::object(), { 1, 2, 3 } }));
CHECK(*it2 == json::object());
}
{
json jarray = {1, 1u, true, nullptr, "string", 42.23, json::object(), {1, 2, 3}};
json jarray = { 1, 1u, true, nullptr, "string", 42.23, json::object(), { 1, 2, 3 } };
json::const_iterator const it2 = jarray.erase(jarray.cbegin() + 3, jarray.cbegin() + 6);
CHECK(jarray == json({1, 1u, true, json::object(), {1, 2, 3}}));
CHECK(jarray == json({ 1, 1u, true, json::object(), { 1, 2, 3 } }));
CHECK(*it2 == json::object());
}
}
@ -379,8 +379,8 @@ TEST_CASE("element access 1")
SECTION("different arrays")
{
{
json jarray = {1, 1u, true, nullptr, "string", 42.23, json::object(), {1, 2, 3}};
json jarray2 = {"foo", "bar"};
json jarray = { 1, 1u, true, nullptr, "string", 42.23, json::object(), { 1, 2, 3 } };
json jarray2 = { "foo", "bar" };
CHECK_THROWS_WITH_AS(jarray.erase(jarray2.begin()),
"[json.exception.invalid_iterator.202] iterator does not fit current value",
@ -396,8 +396,8 @@ TEST_CASE("element access 1")
json::invalid_iterator&);
}
{
json jarray = {1, 1u, true, nullptr, "string", 42.23, json::object(), {1, 2, 3}};
json const jarray2 = {"foo", "bar"};
json jarray = { 1, 1u, true, nullptr, "string", 42.23, json::object(), { 1, 2, 3 } };
json const jarray2 = { "foo", "bar" };
CHECK_THROWS_WITH_AS(jarray.erase(jarray2.cbegin()),
"[json.exception.invalid_iterator.202] iterator does not fit current value",
@ -648,13 +648,13 @@ TEST_CASE("element access 1")
SECTION("binary")
{
{
json j = json::binary({1, 2, 3});
json j = json::binary({ 1, 2, 3 });
json::iterator it = j.erase(j.begin());
CHECK(j.type() == json::value_t::null);
CHECK(it == j.end());
}
{
json j = json::binary({1, 2, 3});
json j = json::binary({ 1, 2, 3 });
json::const_iterator it = j.erase(j.cbegin());
CHECK(j.type() == json::value_t::null);
CHECK(it == j.end());
@ -822,13 +822,13 @@ TEST_CASE("element access 1")
SECTION("binary")
{
{
json j = json::binary({1, 2, 3});
json j = json::binary({ 1, 2, 3 });
json::iterator it = j.erase(j.begin(), j.end());
CHECK(j.type() == json::value_t::null);
CHECK(it == j.end());
}
{
json j = json::binary({1, 2, 3});
json j = json::binary({ 1, 2, 3 });
json::const_iterator it = j.erase(j.cbegin(), j.cend());
CHECK(j.type() == json::value_t::null);
CHECK(it == j.end());

View File

@ -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")
@ -42,7 +36,7 @@ TEST_CASE_TEMPLATE("element access 2", Json, nlohmann::json, nlohmann::ordered_j
CHECK(j.at("string") == Json("hello world"));
CHECK(j.at("floating") == Json(42.23));
CHECK(j.at("object") == Json::object());
CHECK(j.at("array") == Json({1, 2, 3}));
CHECK(j.at("array") == Json({ 1, 2, 3 }));
CHECK(j_const.at("integer") == Json(1));
CHECK(j_const.at("unsigned") == Json(1u));
@ -51,7 +45,7 @@ TEST_CASE_TEMPLATE("element access 2", Json, nlohmann::json, nlohmann::ordered_j
CHECK(j_const.at("string") == Json("hello world"));
CHECK(j_const.at("floating") == Json(42.23));
CHECK(j_const.at("object") == Json::object());
CHECK(j_const.at("array") == Json({1, 2, 3}));
CHECK(j_const.at("array") == Json({ 1, 2, 3 }));
#ifdef JSON_HAS_CPP_17
CHECK(j.at(std::string_view("integer")) == Json(1));
@ -61,7 +55,7 @@ TEST_CASE_TEMPLATE("element access 2", Json, nlohmann::json, nlohmann::ordered_j
CHECK(j.at(std::string_view("string")) == Json("hello world"));
CHECK(j.at(std::string_view("floating")) == Json(42.23));
CHECK(j.at(std::string_view("object")) == Json::object());
CHECK(j.at(std::string_view("array")) == Json({1, 2, 3}));
CHECK(j.at(std::string_view("array")) == Json({ 1, 2, 3 }));
CHECK(j_const.at(std::string_view("integer")) == Json(1));
CHECK(j_const.at(std::string_view("unsigned")) == Json(1u));
@ -70,7 +64,7 @@ TEST_CASE_TEMPLATE("element access 2", Json, nlohmann::json, nlohmann::ordered_j
CHECK(j_const.at(std::string_view("string")) == Json("hello world"));
CHECK(j_const.at(std::string_view("floating")) == Json(42.23));
CHECK(j_const.at(std::string_view("object")) == Json::object());
CHECK(j_const.at(std::string_view("array")) == Json({1, 2, 3}));
CHECK(j_const.at(std::string_view("array")) == Json({ 1, 2, 3 }));
#endif
}
@ -236,8 +230,8 @@ TEST_CASE_TEMPLATE("element access 2", Json, nlohmann::json, nlohmann::ordered_j
CHECK(j.value("string", std::string("bar")) == "hello world");
CHECK(j.value("floating", 12.34) == Approx(42.23));
CHECK(j.value("floating", 12) == 42);
CHECK(j.value("object", Json({{"foo", "bar"}})) == Json::object());
CHECK(j.value("array", Json({10, 100})) == Json({1, 2, 3}));
CHECK(j.value("object", Json({ { "foo", "bar" } })) == Json::object());
CHECK(j.value("array", Json({ 10, 100 })) == Json({ 1, 2, 3 }));
CHECK(j_const.value("integer", 2) == 1);
CHECK(j_const.value("integer", 1.0) == Approx(1));
@ -248,8 +242,8 @@ TEST_CASE_TEMPLATE("element access 2", Json, nlohmann::json, nlohmann::ordered_j
CHECK(j_const.value("string", std::string("bar")) == "hello world");
CHECK(j_const.value("floating", 12.34) == Approx(42.23));
CHECK(j_const.value("floating", 12) == 42);
CHECK(j_const.value("object", Json({{"foo", "bar"}})) == Json::object());
CHECK(j_const.value("array", Json({10, 100})) == Json({1, 2, 3}));
CHECK(j_const.value("object", Json({ { "foo", "bar" } })) == Json::object());
CHECK(j_const.value("array", Json({ 10, 100 })) == Json({ 1, 2, 3 }));
#ifdef JSON_HAS_CPP_17
CHECK(j.value(std::string_view("integer"), 2) == 1);
@ -262,8 +256,8 @@ TEST_CASE_TEMPLATE("element access 2", Json, nlohmann::json, nlohmann::ordered_j
CHECK(j.value(std::string_view("string"), std::string("bar")) == "hello world");
CHECK(j.value(std::string_view("floating"), 12.34) == Approx(42.23));
CHECK(j.value(std::string_view("floating"), 12) == 42);
CHECK(j.value(std::string_view("object"), Json({{"foo", "bar"}})) == Json::object());
CHECK(j.value(std::string_view("array"), Json({10, 100})) == Json({1, 2, 3}));
CHECK(j.value(std::string_view("object"), Json({ { "foo", "bar" } })) == Json::object());
CHECK(j.value(std::string_view("array"), Json({ 10, 100 })) == Json({ 1, 2, 3 }));
CHECK(j_const.value(std::string_view("integer"), 2) == 1);
CHECK(j_const.value(std::string_view("integer"), 1.0) == Approx(1));
@ -274,8 +268,8 @@ TEST_CASE_TEMPLATE("element access 2", Json, nlohmann::json, nlohmann::ordered_j
CHECK(j_const.value(std::string_view("string"), std::string("bar")) == "hello world");
CHECK(j_const.value(std::string_view("floating"), 12.34) == Approx(42.23));
CHECK(j_const.value(std::string_view("floating"), 12) == 42);
CHECK(j_const.value(std::string_view("object"), Json({{"foo", "bar"}})) == Json::object());
CHECK(j_const.value(std::string_view("array"), Json({10, 100})) == Json({1, 2, 3}));
CHECK(j_const.value(std::string_view("object"), Json({ { "foo", "bar" } })) == Json::object());
CHECK(j_const.value(std::string_view("array"), Json({ 10, 100 })) == Json({ 1, 2, 3 }));
#endif
}
@ -286,16 +280,16 @@ TEST_CASE_TEMPLATE("element access 2", Json, nlohmann::json, nlohmann::ordered_j
CHECK(j.value("_", false) == false);
CHECK(j.value("_", "bar") == "bar");
CHECK(j.value("_", 12.34) == Approx(12.34));
CHECK(j.value("_", Json({{"foo", "bar"}})) == Json({{"foo", "bar"}}));
CHECK(j.value("_", Json({10, 100})) == Json({10, 100}));
CHECK(j.value("_", Json({ { "foo", "bar" } })) == Json({ { "foo", "bar" } }));
CHECK(j.value("_", Json({ 10, 100 })) == Json({ 10, 100 }));
CHECK(j_const.value("_", 2) == 2);
CHECK(j_const.value("_", 2u) == 2u);
CHECK(j_const.value("_", false) == false);
CHECK(j_const.value("_", "bar") == "bar");
CHECK(j_const.value("_", 12.34) == Approx(12.34));
CHECK(j_const.value("_", Json({{"foo", "bar"}})) == Json({{"foo", "bar"}}));
CHECK(j_const.value("_", Json({10, 100})) == Json({10, 100}));
CHECK(j_const.value("_", Json({ { "foo", "bar" } })) == Json({ { "foo", "bar" } }));
CHECK(j_const.value("_", Json({ 10, 100 })) == Json({ 10, 100 }));
#ifdef JSON_HAS_CPP_17
CHECK(j.value(std::string_view("_"), 2) == 2);
@ -303,16 +297,16 @@ TEST_CASE_TEMPLATE("element access 2", Json, nlohmann::json, nlohmann::ordered_j
CHECK(j.value(std::string_view("_"), false) == false);
CHECK(j.value(std::string_view("_"), "bar") == "bar");
CHECK(j.value(std::string_view("_"), 12.34) == Approx(12.34));
CHECK(j.value(std::string_view("_"), Json({{"foo", "bar"}})) == Json({{"foo", "bar"}}));
CHECK(j.value(std::string_view("_"), Json({10, 100})) == Json({10, 100}));
CHECK(j.value(std::string_view("_"), Json({ { "foo", "bar" } })) == Json({ { "foo", "bar" } }));
CHECK(j.value(std::string_view("_"), Json({ 10, 100 })) == Json({ 10, 100 }));
CHECK(j_const.value(std::string_view("_"), 2) == 2);
CHECK(j_const.value(std::string_view("_"), 2u) == 2u);
CHECK(j_const.value(std::string_view("_"), false) == false);
CHECK(j_const.value(std::string_view("_"), "bar") == "bar");
CHECK(j_const.value(std::string_view("_"), 12.34) == Approx(12.34));
CHECK(j_const.value(std::string_view("_"), Json({{"foo", "bar"}})) == Json({{"foo", "bar"}}));
CHECK(j_const.value(std::string_view("_"), Json({10, 100})) == Json({10, 100}));
CHECK(j_const.value(std::string_view("_"), Json({ { "foo", "bar" } })) == Json({ { "foo", "bar" } }));
CHECK(j_const.value(std::string_view("_"), Json({ 10, 100 })) == Json({ 10, 100 }));
#endif
}
@ -481,8 +475,8 @@ TEST_CASE_TEMPLATE("element access 2", Json, nlohmann::json, nlohmann::ordered_j
CHECK(j.value("/string"_json_pointer, std::string("bar")) == "hello world");
CHECK(j.value("/floating"_json_pointer, 12.34) == Approx(42.23));
CHECK(j.value("/floating"_json_pointer, 12) == 42);
CHECK(j.value("/object"_json_pointer, Json({{"foo", "bar"}})) == Json::object());
CHECK(j.value("/array"_json_pointer, Json({10, 100})) == Json({1, 2, 3}));
CHECK(j.value("/object"_json_pointer, Json({ { "foo", "bar" } })) == Json::object());
CHECK(j.value("/array"_json_pointer, Json({ 10, 100 })) == Json({ 1, 2, 3 }));
CHECK(j_const.value("/integer"_json_pointer, 2) == 1);
CHECK(j_const.value("/integer"_json_pointer, 1.0) == Approx(1));
@ -493,8 +487,8 @@ TEST_CASE_TEMPLATE("element access 2", Json, nlohmann::json, nlohmann::ordered_j
CHECK(j_const.value("/string"_json_pointer, std::string("bar")) == "hello world");
CHECK(j_const.value("/floating"_json_pointer, 12.34) == Approx(42.23));
CHECK(j_const.value("/floating"_json_pointer, 12) == 42);
CHECK(j_const.value("/object"_json_pointer, Json({{"foo", "bar"}})) == Json::object());
CHECK(j_const.value("/array"_json_pointer, Json({10, 100})) == Json({1, 2, 3}));
CHECK(j_const.value("/object"_json_pointer, Json({ { "foo", "bar" } })) == Json::object());
CHECK(j_const.value("/array"_json_pointer, Json({ 10, 100 })) == Json({ 1, 2, 3 }));
}
SECTION("access on non-object type")
@ -586,7 +580,7 @@ TEST_CASE_TEMPLATE("element access 2", Json, nlohmann::json, nlohmann::ordered_j
}
}
SECTION("non-const operator[]"){{Json j_null;
SECTION("non-const operator[]"){ { Json j_null;
CHECK(j_null.is_null());
j_null["key"] = 1;
CHECK(j_null.is_object());
@ -616,14 +610,14 @@ SECTION("front and back")
CHECK(j.front() == Json(1));
CHECK(j_const.front() == Json(1));
// "array" is last key
CHECK(j.back() == Json({1, 2, 3}));
CHECK(j_const.back() == Json({1, 2, 3}));
CHECK(j.back() == Json({ 1, 2, 3 }));
CHECK(j_const.back() == Json({ 1, 2, 3 }));
}
else
{
// "array" is the smallest key
CHECK(j.front() == Json({1, 2, 3}));
CHECK(j_const.front() == Json({1, 2, 3}));
CHECK(j.front() == Json({ 1, 2, 3 }));
CHECK(j_const.front() == Json({ 1, 2, 3 }));
// "unsigned" is the largest key
CHECK(j.back() == Json(1u));
CHECK(j_const.back() == Json(1u));
@ -655,7 +649,7 @@ SECTION("access specified element")
CHECK(j["object"] == Json::object());
CHECK(j[typename Json::object_t::key_type("object")] == j["object"]);
CHECK(j["array"] == Json({1, 2, 3}));
CHECK(j["array"] == Json({ 1, 2, 3 }));
CHECK(j[typename Json::object_t::key_type("array")] == j["array"]);
CHECK(j_const["integer"] == Json(1));
@ -676,7 +670,7 @@ SECTION("access specified element")
CHECK(j_const["object"] == Json::object());
CHECK(j_const[typename Json::object_t::key_type("object")] == j["object"]);
CHECK(j_const["array"] == Json({1, 2, 3}));
CHECK(j_const["array"] == Json({ 1, 2, 3 }));
CHECK(j_const[typename Json::object_t::key_type("array")] == j["array"]);
}
@ -704,7 +698,7 @@ SECTION("access specified element")
CHECK(j["object"] == Json::object());
CHECK(j[std::string_view("object")] == j["object"]);
CHECK(j["array"] == Json({1, 2, 3}));
CHECK(j["array"] == Json({ 1, 2, 3 }));
CHECK(j[std::string_view("array")] == j["array"]);
CHECK(j_const["integer"] == Json(1));
@ -725,7 +719,7 @@ SECTION("access specified element")
CHECK(j_const["object"] == Json::object());
CHECK(j_const[std::string_view("object")] == j["object"]);
CHECK(j_const["array"] == Json({1, 2, 3}));
CHECK(j_const["array"] == Json({ 1, 2, 3 }));
CHECK(j_const[std::string_view("array")] == j["array"]);
}
#endif
@ -1014,15 +1008,15 @@ SECTION("remove specified element")
SECTION("erase(begin())")
{
{
Json jobject = {{"a", "a"}, {"b", 1}, {"c", 17u}};
Json jobject = { { "a", "a" }, { "b", 1 }, { "c", 17u } };
typename Json::iterator const it2 = jobject.erase(jobject.begin());
CHECK(jobject == Json({{"b", 1}, {"c", 17u}}));
CHECK(jobject == Json({ { "b", 1 }, { "c", 17u } }));
CHECK(*it2 == Json(1));
}
{
Json jobject = {{"a", "a"}, {"b", 1}, {"c", 17u}};
Json jobject = { { "a", "a" }, { "b", 1 }, { "c", 17u } };
typename Json::const_iterator const it2 = jobject.erase(jobject.cbegin());
CHECK(jobject == Json({{"b", 1}, {"c", 17u}}));
CHECK(jobject == Json({ { "b", 1 }, { "c", 17u } }));
CHECK(*it2 == Json(1));
}
}
@ -1030,13 +1024,13 @@ SECTION("remove specified element")
SECTION("erase(begin(), end())")
{
{
Json jobject = {{"a", "a"}, {"b", 1}, {"c", 17u}};
Json jobject = { { "a", "a" }, { "b", 1 }, { "c", 17u } };
typename Json::iterator it2 = jobject.erase(jobject.begin(), jobject.end());
CHECK(jobject == Json::object());
CHECK(it2 == jobject.end());
}
{
Json jobject = {{"a", "a"}, {"b", 1}, {"c", 17u}};
Json jobject = { { "a", "a" }, { "b", 1 }, { "c", 17u } };
typename Json::const_iterator it2 = jobject.erase(jobject.cbegin(), jobject.cend());
CHECK(jobject == Json::object());
CHECK(it2 == jobject.cend());
@ -1046,15 +1040,15 @@ SECTION("remove specified element")
SECTION("erase(begin(), begin())")
{
{
Json jobject = {{"a", "a"}, {"b", 1}, {"c", 17u}};
Json jobject = { { "a", "a" }, { "b", 1 }, { "c", 17u } };
typename Json::iterator const it2 = jobject.erase(jobject.begin(), jobject.begin());
CHECK(jobject == Json({{"a", "a"}, {"b", 1}, {"c", 17u}}));
CHECK(jobject == Json({ { "a", "a" }, { "b", 1 }, { "c", 17u } }));
CHECK(*it2 == Json("a"));
}
{
Json jobject = {{"a", "a"}, {"b", 1}, {"c", 17u}};
Json jobject = { { "a", "a" }, { "b", 1 }, { "c", 17u } };
typename Json::const_iterator const it2 = jobject.erase(jobject.cbegin(), jobject.cbegin());
CHECK(jobject == Json({{"a", "a"}, {"b", 1}, {"c", 17u}}));
CHECK(jobject == Json({ { "a", "a" }, { "b", 1 }, { "c", 17u } }));
CHECK(*it2 == Json("a"));
}
}
@ -1062,17 +1056,17 @@ SECTION("remove specified element")
SECTION("erase at offset")
{
{
Json jobject = {{"a", "a"}, {"b", 1}, {"c", 17u}};
Json jobject = { { "a", "a" }, { "b", 1 }, { "c", 17u } };
typename Json::iterator const it = jobject.find("b");
typename Json::iterator const it2 = jobject.erase(it);
CHECK(jobject == Json({{"a", "a"}, {"c", 17u}}));
CHECK(jobject == Json({ { "a", "a" }, { "c", 17u } }));
CHECK(*it2 == Json(17));
}
{
Json jobject = {{"a", "a"}, {"b", 1}, {"c", 17u}};
Json jobject = { { "a", "a" }, { "b", 1 }, { "c", 17u } };
typename Json::const_iterator const it = jobject.find("b");
typename Json::const_iterator const it2 = jobject.erase(it);
CHECK(jobject == Json({{"a", "a"}, {"c", 17u}}));
CHECK(jobject == Json({ { "a", "a" }, { "c", 17u } }));
CHECK(*it2 == Json(17));
}
}
@ -1080,15 +1074,15 @@ SECTION("remove specified element")
SECTION("erase subrange")
{
{
Json jobject = {{"a", "a"}, {"b", 1}, {"c", 17u}, {"d", false}, {"e", true}};
Json jobject = { { "a", "a" }, { "b", 1 }, { "c", 17u }, { "d", false }, { "e", true } };
typename Json::iterator const it2 = jobject.erase(jobject.find("b"), jobject.find("e"));
CHECK(jobject == Json({{"a", "a"}, {"e", true}}));
CHECK(jobject == Json({ { "a", "a" }, { "e", true } }));
CHECK(*it2 == Json(true));
}
{
Json jobject = {{"a", "a"}, {"b", 1}, {"c", 17u}, {"d", false}, {"e", true}};
Json jobject = { { "a", "a" }, { "b", 1 }, { "c", 17u }, { "d", false }, { "e", true } };
typename Json::const_iterator const it2 = jobject.erase(jobject.find("b"), jobject.find("e"));
CHECK(jobject == Json({{"a", "a"}, {"e", true}}));
CHECK(jobject == Json({ { "a", "a" }, { "e", true } }));
CHECK(*it2 == Json(true));
}
}
@ -1096,8 +1090,8 @@ SECTION("remove specified element")
SECTION("different objects")
{
{
Json jobject = {{"a", "a"}, {"b", 1}, {"c", 17u}, {"d", false}, {"e", true}};
Json jobject2 = {{"a", "a"}, {"b", 1}, {"c", 17u}};
Json jobject = { { "a", "a" }, { "b", 1 }, { "c", 17u }, { "d", false }, { "e", true } };
Json jobject2 = { { "a", "a" }, { "b", 1 }, { "c", 17u } };
CHECK_THROWS_WITH_AS(jobject.erase(jobject2.begin()),
"[json.exception.invalid_iterator.202] iterator does not fit current value",
typename Json::invalid_iterator&);
@ -1112,8 +1106,8 @@ SECTION("remove specified element")
typename Json::invalid_iterator&);
}
{
Json jobject = {{"a", "a"}, {"b", 1}, {"c", 17u}, {"d", false}, {"e", true}};
Json jobject2 = {{"a", "a"}, {"b", 1}, {"c", 17u}};
Json jobject = { { "a", "a" }, { "b", 1 }, { "c", 17u }, { "d", false }, { "e", true } };
Json jobject2 = { { "a", "a" }, { "b", 1 }, { "c", 17u } };
CHECK_THROWS_WITH_AS(jobject.erase(jobject2.cbegin()),
"[json.exception.invalid_iterator.202] iterator does not fit current value",
typename Json::invalid_iterator&);
@ -1210,7 +1204,7 @@ SECTION("find an element in an object")
{
SECTION("existing element")
{
for (const auto* key : {"integer", "unsigned", "floating", "null", "string", "boolean", "object", "array"})
for (const auto* key : { "integer", "unsigned", "floating", "null", "string", "boolean", "object", "array" })
{
CHECK(j.find(key) != j.end());
CHECK(*j.find(key) == j.at(key));
@ -1218,7 +1212,7 @@ SECTION("find an element in an object")
CHECK(*j_const.find(key) == j_const.at(key));
}
#ifdef JSON_HAS_CPP_17
for (const std::string_view key : {"integer", "unsigned", "floating", "null", "string", "boolean", "object", "array"})
for (const std::string_view key : { "integer", "unsigned", "floating", "null", "string", "boolean", "object", "array" })
{
CHECK(j.find(key) != j.end());
CHECK(*j.find(key) == j.at(key));
@ -1359,13 +1353,13 @@ SECTION("count keys in an object")
{
SECTION("existing element")
{
for (const auto* key : {"integer", "unsigned", "floating", "null", "string", "boolean", "object", "array"})
for (const auto* key : { "integer", "unsigned", "floating", "null", "string", "boolean", "object", "array" })
{
CHECK(j.count(key) == 1);
CHECK(j_const.count(key) == 1);
}
#ifdef JSON_HAS_CPP_17
for (const std::string_view key : {"integer", "unsigned", "floating", "null", "string", "boolean", "object", "array"})
for (const std::string_view key : { "integer", "unsigned", "floating", "null", "string", "boolean", "object", "array" })
{
CHECK(j.count(key) == 1);
CHECK(j_const.count(key) == 1);
@ -1504,14 +1498,14 @@ SECTION("check existence of key in an object")
{
SECTION("existing element")
{
for (const auto* key : {"integer", "unsigned", "floating", "null", "string", "boolean", "object", "array"})
for (const auto* key : { "integer", "unsigned", "floating", "null", "string", "boolean", "object", "array" })
{
CHECK(j.contains(key) == true);
CHECK(j_const.contains(key) == true);
}
#ifdef JSON_HAS_CPP_17
for (const std::string_view key : {"integer", "unsigned", "floating", "null", "string", "boolean", "object", "array"})
for (const std::string_view key : { "integer", "unsigned", "floating", "null", "string", "boolean", "object", "array" })
{
CHECK(j.contains(key) == true);
CHECK(j_const.contains(key) == true);
@ -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")
{
@ -1679,16 +1661,16 @@ TEST_CASE_TEMPLATE("element access 2 (throwing tests)", Json, nlohmann::json, nl
CHECK(j.value("/not/existing"_json_pointer, false) == false);
CHECK(j.value("/not/existing"_json_pointer, "bar") == "bar");
CHECK(j.value("/not/existing"_json_pointer, 12.34) == Approx(12.34));
CHECK(j.value("/not/existing"_json_pointer, Json({{"foo", "bar"}})) == Json({{"foo", "bar"}}));
CHECK(j.value("/not/existing"_json_pointer, Json({10, 100})) == Json({10, 100}));
CHECK(j.value("/not/existing"_json_pointer, Json({ { "foo", "bar" } })) == Json({ { "foo", "bar" } }));
CHECK(j.value("/not/existing"_json_pointer, Json({ 10, 100 })) == Json({ 10, 100 }));
CHECK(j_const.value("/not/existing"_json_pointer, 2) == 2);
CHECK(j_const.value("/not/existing"_json_pointer, 2u) == 2u);
CHECK(j_const.value("/not/existing"_json_pointer, false) == false);
CHECK(j_const.value("/not/existing"_json_pointer, "bar") == "bar");
CHECK(j_const.value("/not/existing"_json_pointer, 12.34) == Approx(12.34));
CHECK(j_const.value("/not/existing"_json_pointer, Json({{"foo", "bar"}})) == Json({{"foo", "bar"}}));
CHECK(j_const.value("/not/existing"_json_pointer, Json({10, 100})) == Json({10, 100}));
CHECK(j_const.value("/not/existing"_json_pointer, Json({ { "foo", "bar" } })) == Json({ { "foo", "bar" } }));
CHECK(j_const.value("/not/existing"_json_pointer, Json({ 10, 100 })) == Json({ 10, 100 }));
}
}
}
@ -1705,7 +1687,7 @@ TEST_CASE_TEMPLATE("element access 2 (additional value() tests)", Json, nlohmann
// test assumes string_t and object_t::key_type are the same
REQUIRE(std::is_same<string_t, typename Json::object_t::key_type>::value);
Json j{{"foo", "bar"}, {"baz", 42}};
Json j{ { "foo", "bar" }, { "baz", 42 } };
const char* cpstr = "default";
const char castr[] = "default"; // NOLINT(hicpp-avoid-c-arrays,modernize-avoid-c-arrays,cppcoreguidelines-avoid-c-arrays)
@ -1714,7 +1696,7 @@ TEST_CASE_TEMPLATE("element access 2 (additional value() tests)", Json, nlohmann
number_integer_t integer = 69;
std::size_t size = 69;
SECTION("deduced ValueType"){SECTION("literal key"){CHECK(j.value("foo", "default") == "bar");
SECTION("deduced ValueType"){ SECTION("literal key"){ CHECK(j.value("foo", "default") == "bar");
CHECK(j.value("foo", cpstr) == "bar");
CHECK(j.value("foo", castr) == "bar");
CHECK(j.value("foo", str) == "bar");

View File

@ -43,19 +43,19 @@ TEST_CASE("hash<nlohmann::json>")
// array
hashes.insert(std::hash<json>{}(json::array()));
hashes.insert(std::hash<json>{}(json::array({1, 2, 3})));
hashes.insert(std::hash<json>{}(json::array({ 1, 2, 3 })));
// object
hashes.insert(std::hash<json>{}(json::object()));
hashes.insert(std::hash<json>{}(json::object({{"foo", "bar"}})));
hashes.insert(std::hash<json>{}(json::object({ { "foo", "bar" } })));
// binary
hashes.insert(std::hash<json>{}(json::binary({})));
hashes.insert(std::hash<json>{}(json::binary({}, 0)));
hashes.insert(std::hash<json>{}(json::binary({}, 42)));
hashes.insert(std::hash<json>{}(json::binary({1, 2, 3})));
hashes.insert(std::hash<json>{}(json::binary({1, 2, 3}, 0)));
hashes.insert(std::hash<json>{}(json::binary({1, 2, 3}, 42)));
hashes.insert(std::hash<json>{}(json::binary({ 1, 2, 3 })));
hashes.insert(std::hash<json>{}(json::binary({ 1, 2, 3 }, 0)));
hashes.insert(std::hash<json>{}(json::binary({ 1, 2, 3 }, 42)));
// discarded
hashes.insert(std::hash<json>{}(json(json::value_t::discarded)));
@ -92,19 +92,19 @@ TEST_CASE("hash<nlohmann::ordered_json>")
// array
hashes.insert(std::hash<ordered_json>{}(ordered_json::array()));
hashes.insert(std::hash<ordered_json>{}(ordered_json::array({1, 2, 3})));
hashes.insert(std::hash<ordered_json>{}(ordered_json::array({ 1, 2, 3 })));
// object
hashes.insert(std::hash<ordered_json>{}(ordered_json::object()));
hashes.insert(std::hash<ordered_json>{}(ordered_json::object({{"foo", "bar"}})));
hashes.insert(std::hash<ordered_json>{}(ordered_json::object({ { "foo", "bar" } })));
// binary
hashes.insert(std::hash<ordered_json>{}(ordered_json::binary({})));
hashes.insert(std::hash<ordered_json>{}(ordered_json::binary({}, 0)));
hashes.insert(std::hash<ordered_json>{}(ordered_json::binary({}, 42)));
hashes.insert(std::hash<ordered_json>{}(ordered_json::binary({1, 2, 3})));
hashes.insert(std::hash<ordered_json>{}(ordered_json::binary({1, 2, 3}, 0)));
hashes.insert(std::hash<ordered_json>{}(ordered_json::binary({1, 2, 3}, 42)));
hashes.insert(std::hash<ordered_json>{}(ordered_json::binary({ 1, 2, 3 })));
hashes.insert(std::hash<ordered_json>{}(ordered_json::binary({ 1, 2, 3 }, 0)));
hashes.insert(std::hash<ordered_json>{}(ordered_json::binary({ 1, 2, 3 }, 42)));
// discarded
hashes.insert(std::hash<ordered_json>{}(ordered_json(ordered_json::value_t::discarded)));

View File

@ -21,7 +21,7 @@ TEST_CASE("object inspection")
{
SECTION("object")
{
json const j{{"foo", 1}, {"bar", false}};
json const j{ { "foo", 1 }, { "bar", false } };
CHECK(!j.is_null());
CHECK(!j.is_boolean());
CHECK(!j.is_number());
@ -39,7 +39,7 @@ TEST_CASE("object inspection")
SECTION("array")
{
json const j{"foo", 1, 1u, 42.23, false};
json const j{ "foo", 1, 1u, 42.23, false };
CHECK(!j.is_null());
CHECK(!j.is_boolean());
CHECK(!j.is_number());
@ -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")
{
@ -242,7 +243,7 @@ TEST_CASE("object inspection")
// inside the dump() function
CHECK(j.dump(1024).size() == 15472);
const auto binary = json::binary({1, 2, 3}, 128);
const auto binary = json::binary({ 1, 2, 3 }, 128);
CHECK(binary.dump(1024).size() == 2086);
}
@ -328,7 +329,7 @@ TEST_CASE("object inspection")
SECTION("round trips")
{
for (const auto& s : {"3.141592653589793", "1000000000000000010E5"})
for (const auto& s : { "3.141592653589793", "1000000000000000010E5" })
{
json const j1 = json::parse(s);
std::string s1 = j1.dump();
@ -348,13 +349,13 @@ TEST_CASE("object inspection")
SECTION("object")
{
json const j = {{"foo", "bar"}};
json const j = { { "foo", "bar" } };
CHECK(j.type() == json::value_t::object);
}
SECTION("array")
{
json const j = {1, 2, 3, 4};
json const j = { 1, 2, 3, 4 };
CHECK(j.type() == json::value_t::array);
}
@ -400,14 +401,14 @@ TEST_CASE("object inspection")
SECTION("object")
{
json const j = {{"foo", "bar"}};
json const j = { { "foo", "bar" } };
json::value_t t = j;
CHECK(t == j.type());
}
SECTION("array")
{
json const j = {1, 2, 3, 4};
json const j = { 1, 2, 3, 4 };
json::value_t t = j;
CHECK(t == j.type());
}

View File

@ -25,7 +25,7 @@ TEST_CASE("iterator_wrapper")
{
SECTION("value")
{
json j = {{"A", 1}, {"B", 2}};
json j = { { "A", 1 }, { "B", 2 } };
int counter = 1;
for (auto i : json::iterator_wrapper(j)) // NOLINT(performance-for-range-copy)
@ -58,7 +58,7 @@ TEST_CASE("iterator_wrapper")
SECTION("reference")
{
json j = {{"A", 1}, {"B", 2}};
json j = { { "A", 1 }, { "B", 2 } };
int counter = 1;
for (auto& i : json::iterator_wrapper(j)) // NOLINT(readability-qualified-auto)
@ -97,12 +97,12 @@ TEST_CASE("iterator_wrapper")
CHECK(counter == 3);
// check if values where changed
CHECK(j == json({{"A", 11}, {"B", 22}}));
CHECK(j == json({ { "A", 11 }, { "B", 22 } }));
}
SECTION("const value")
{
json j = {{"A", 1}, {"B", 2}};
json j = { { "A", 1 }, { "B", 2 } };
int counter = 1;
for (const auto i : json::iterator_wrapper(j)) // NOLINT(performance-for-range-copy)
@ -135,7 +135,7 @@ TEST_CASE("iterator_wrapper")
SECTION("const reference")
{
json j = {{"A", 1}, {"B", 2}};
json j = { { "A", 1 }, { "B", 2 } };
int counter = 1;
for (const auto& i : json::iterator_wrapper(j))
@ -171,7 +171,7 @@ TEST_CASE("iterator_wrapper")
{
SECTION("value")
{
const json j = {{"A", 1}, {"B", 2}};
const json j = { { "A", 1 }, { "B", 2 } };
int counter = 1;
for (auto i : json::iterator_wrapper(j)) // NOLINT(performance-for-range-copy)
@ -204,7 +204,7 @@ TEST_CASE("iterator_wrapper")
SECTION("reference")
{
const json j = {{"A", 1}, {"B", 2}};
const json j = { { "A", 1 }, { "B", 2 } };
int counter = 1;
for (auto& i : json::iterator_wrapper(j)) // NOLINT(readability-qualified-auto)
@ -237,7 +237,7 @@ TEST_CASE("iterator_wrapper")
SECTION("const value")
{
const json j = {{"A", 1}, {"B", 2}};
const json j = { { "A", 1 }, { "B", 2 } };
int counter = 1;
for (const auto i : json::iterator_wrapper(j)) // NOLINT(performance-for-range-copy)
@ -270,7 +270,7 @@ TEST_CASE("iterator_wrapper")
SECTION("const reference")
{
const json j = {{"A", 1}, {"B", 2}};
const json j = { { "A", 1 }, { "B", 2 } };
int counter = 1;
for (const auto& i : json::iterator_wrapper(j))
@ -306,7 +306,7 @@ TEST_CASE("iterator_wrapper")
{
SECTION("value")
{
json j = {"A", "B"};
json j = { "A", "B" };
int counter = 1;
for (auto i : json::iterator_wrapper(j)) // NOLINT(performance-for-range-copy)
@ -339,7 +339,7 @@ TEST_CASE("iterator_wrapper")
SECTION("reference")
{
json j = {"A", "B"};
json j = { "A", "B" };
int counter = 1;
for (auto& i : json::iterator_wrapper(j)) // NOLINT(readability-qualified-auto)
@ -378,12 +378,12 @@ TEST_CASE("iterator_wrapper")
CHECK(counter == 3);
// check if values where changed
CHECK(j == json({"AA", "BB"}));
CHECK(j == json({ "AA", "BB" }));
}
SECTION("const value")
{
json j = {"A", "B"};
json j = { "A", "B" };
int counter = 1;
for (const auto i : json::iterator_wrapper(j)) // NOLINT(performance-for-range-copy)
@ -416,7 +416,7 @@ TEST_CASE("iterator_wrapper")
SECTION("const reference")
{
json j = {"A", "B"};
json j = { "A", "B" };
int counter = 1;
for (const auto& i : json::iterator_wrapper(j))
@ -452,7 +452,7 @@ TEST_CASE("iterator_wrapper")
{
SECTION("value")
{
const json j = {"A", "B"};
const json j = { "A", "B" };
int counter = 1;
for (auto i : json::iterator_wrapper(j)) // NOLINT(performance-for-range-copy)
@ -485,7 +485,7 @@ TEST_CASE("iterator_wrapper")
SECTION("reference")
{
const json j = {"A", "B"};
const json j = { "A", "B" };
int counter = 1;
for (auto& i : json::iterator_wrapper(j)) // NOLINT(readability-qualified-auto)
@ -518,7 +518,7 @@ TEST_CASE("iterator_wrapper")
SECTION("const value")
{
const json j = {"A", "B"};
const json j = { "A", "B" };
int counter = 1;
for (const auto i : json::iterator_wrapper(j)) // NOLINT(performance-for-range-copy)
@ -551,7 +551,7 @@ TEST_CASE("iterator_wrapper")
SECTION("const reference")
{
const json j = {"A", "B"};
const json j = { "A", "B" };
int counter = 1;
for (const auto& i : json::iterator_wrapper(j))
@ -718,7 +718,7 @@ TEST_CASE("iterator_wrapper")
TEST_CASE("items()")
{
SECTION("object"){SECTION("value"){json j = {{"A", 1}, {"B", 2}};
SECTION("object"){ SECTION("value"){ json j = { { "A", 1 }, { "B", 2 } };
int counter = 1;
for (auto i : j.items()) // NOLINT(performance-for-range-copy)
@ -751,7 +751,7 @@ TEST_CASE("items()")
SECTION("reference")
{
json j = {{"A", 1}, {"B", 2}};
json j = { { "A", 1 }, { "B", 2 } };
int counter = 1;
for (auto& i : j.items()) // NOLINT(readability-qualified-auto)
@ -790,12 +790,12 @@ SECTION("reference")
CHECK(counter == 3);
// check if values where changed
CHECK(j == json({{"A", 11}, {"B", 22}}));
CHECK(j == json({ { "A", 11 }, { "B", 22 } }));
}
SECTION("const value")
{
json j = {{"A", 1}, {"B", 2}};
json j = { { "A", 1 }, { "B", 2 } };
int counter = 1;
for (const auto i : j.items()) // NOLINT(performance-for-range-copy)
@ -828,7 +828,7 @@ SECTION("const value")
SECTION("const reference")
{
json j = {{"A", 1}, {"B", 2}};
json j = { { "A", 1 }, { "B", 2 } };
int counter = 1;
for (const auto& i : j.items())
@ -862,7 +862,7 @@ SECTION("const reference")
#ifdef JSON_HAS_CPP_17
SECTION("structured bindings")
{
json j = {{"A", 1}, {"B", 2}};
json j = { { "A", 1 }, { "B", 2 } };
std::map<std::string, int> m;
@ -880,7 +880,7 @@ SECTION("const object")
{
SECTION("value")
{
const json j = {{"A", 1}, {"B", 2}};
const json j = { { "A", 1 }, { "B", 2 } };
int counter = 1;
for (auto i : j.items()) // NOLINT(performance-for-range-copy)
@ -913,7 +913,7 @@ SECTION("const object")
SECTION("reference")
{
const json j = {{"A", 1}, {"B", 2}};
const json j = { { "A", 1 }, { "B", 2 } };
int counter = 1;
for (auto& i : j.items()) // NOLINT(readability-qualified-auto)
@ -946,7 +946,7 @@ SECTION("const object")
SECTION("const value")
{
const json j = {{"A", 1}, {"B", 2}};
const json j = { { "A", 1 }, { "B", 2 } };
int counter = 1;
for (const auto i : j.items()) // NOLINT(performance-for-range-copy)
@ -979,7 +979,7 @@ SECTION("const object")
SECTION("const reference")
{
const json j = {{"A", 1}, {"B", 2}};
const json j = { { "A", 1 }, { "B", 2 } };
int counter = 1;
for (const auto& i : j.items())
@ -1015,7 +1015,7 @@ SECTION("array")
{
SECTION("value")
{
json j = {"A", "B"};
json j = { "A", "B" };
int counter = 1;
for (auto i : j.items()) // NOLINT(performance-for-range-copy)
@ -1048,7 +1048,7 @@ SECTION("array")
SECTION("reference")
{
json j = {"A", "B"};
json j = { "A", "B" };
int counter = 1;
for (auto& i : j.items()) // NOLINT(readability-qualified-auto)
@ -1087,12 +1087,12 @@ SECTION("array")
CHECK(counter == 3);
// check if values where changed
CHECK(j == json({"AA", "BB"}));
CHECK(j == json({ "AA", "BB" }));
}
SECTION("const value")
{
json j = {"A", "B"};
json j = { "A", "B" };
int counter = 1;
for (const auto i : j.items()) // NOLINT(performance-for-range-copy)
@ -1125,7 +1125,7 @@ SECTION("array")
SECTION("const reference")
{
json j = {"A", "B"};
json j = { "A", "B" };
int counter = 1;
for (const auto& i : j.items())
@ -1161,7 +1161,7 @@ SECTION("const array")
{
SECTION("value")
{
const json j = {"A", "B"};
const json j = { "A", "B" };
int counter = 1;
for (auto i : j.items()) // NOLINT(performance-for-range-copy)
@ -1194,7 +1194,7 @@ SECTION("const array")
SECTION("reference")
{
const json j = {"A", "B"};
const json j = { "A", "B" };
int counter = 1;
for (auto& i : j.items()) // NOLINT(readability-qualified-auto)
@ -1227,7 +1227,7 @@ SECTION("const array")
SECTION("const value")
{
const json j = {"A", "B"};
const json j = { "A", "B" };
int counter = 1;
for (const auto i : j.items()) // NOLINT(performance-for-range-copy)
@ -1260,7 +1260,7 @@ SECTION("const array")
SECTION("const reference")
{
const json j = {"A", "B"};
const json j = { "A", "B" };
int counter = 1;
for (const auto& i : j.items())

View File

@ -531,7 +531,7 @@ TEST_CASE("iterators 1")
SECTION("array")
{
json j = {1, 2, 3};
json j = { 1, 2, 3 };
json j_const(j);
SECTION("json + begin/end")
@ -715,7 +715,7 @@ TEST_CASE("iterators 1")
SECTION("object")
{
json j = {{"A", 1}, {"B", 2}, {"C", 3}};
json j = { { "A", 1 }, { "B", 2 }, { "C", 3 } };
json j_const(j);
SECTION("json + begin/end")
@ -1580,7 +1580,7 @@ TEST_CASE("iterators 1")
}
SECTION("array")
{
json j = {1, 2, 3};
json j = { 1, 2, 3 };
json::const_iterator it = j.begin();
CHECK(it == j.cbegin());
it = j.begin();
@ -1588,7 +1588,7 @@ TEST_CASE("iterators 1")
}
SECTION("object")
{
json j = {{"A", 1}, {"B", 2}, {"C", 3}};
json j = { { "A", 1 }, { "B", 2 }, { "C", 3 } };
json::const_iterator it = j.begin();
CHECK(it == j.cbegin());
it = j.begin();

View File

@ -27,7 +27,7 @@ TEST_CASE("iterators 2")
{
SECTION("iterator comparisons")
{
json j_values = {nullptr, true, 42, 42u, 23.23, {{"one", 1}, {"two", 2}}, {1, 2, 3, 4, 5}, "Hello, world"};
json j_values = { nullptr, true, 42, 42u, 23.23, { { "one", 1 }, { "two", 2 } }, { 1, 2, 3, 4, 5 }, "Hello, world" };
for (json& j : j_values)
{
@ -347,8 +347,8 @@ TEST_CASE("iterators 2")
SECTION("iterator arithmetic")
{
json j_object = {{"one", 1}, {"two", 2}, {"three", 3}};
json j_array = {1, 2, 3, 4, 5, 6};
json j_object = { { "one", 1 }, { "two", 2 }, { "three", 3 } };
json j_array = { 1, 2, 3, 4, 5, 6 };
json j_null = nullptr;
json j_value = 42;
@ -555,7 +555,7 @@ TEST_CASE("iterators 2")
SECTION("reverse iterator comparisons")
{
json j_values = {nullptr, true, 42, 42u, 23.23, {{"one", 1}, {"two", 2}}, {1, 2, 3, 4, 5}, "Hello, world"};
json j_values = { nullptr, true, 42, 42u, 23.23, { { "one", 1 }, { "two", 2 } }, { 1, 2, 3, 4, 5 }, "Hello, world" };
for (json& j : j_values)
{
@ -875,8 +875,8 @@ TEST_CASE("iterators 2")
SECTION("reverse iterator arithmetic")
{
json j_object = {{"one", 1}, {"two", 2}, {"three", 3}};
json j_array = {1, 2, 3, 4, 5, 6};
json j_object = { { "one", 1 }, { "two", 2 }, { "three", 3 } };
json j_array = { 1, 2, 3, 4, 5, 6 };
json j_null = nullptr;
json j_value = 42;
@ -1107,7 +1107,7 @@ TEST_CASE("iterators 2")
{
SECTION("copy")
{
json j{"foo", "bar"};
json j{ "foo", "bar" };
auto j_copied = json::array();
std::ranges::copy(j, std::back_inserter(j_copied));
@ -1117,7 +1117,7 @@ TEST_CASE("iterators 2")
SECTION("find_if")
{
json j{1, 3, 2, 4};
json j{ 1, 3, 2, 4 };
auto j_even = json::array();
#if JSON_USE_IMPLICIT_CONVERSIONS
@ -1144,8 +1144,8 @@ TEST_CASE("iterators 2")
{
SECTION("reverse")
{
json j{1, 2, 3, 4, 5};
json j_expected{5, 4, 3, 2, 1};
json j{ 1, 2, 3, 4, 5 };
json j_expected{ 5, 4, 3, 2, 1 };
auto reversed = j | std::views::reverse;
CHECK(std::ranges::equal(reversed, j_expected));
@ -1154,11 +1154,11 @@ TEST_CASE("iterators 2")
SECTION("transform")
{
json j{
{"a_key", "a_value"},
{"b_key", "b_value"},
{"c_key", "c_value"},
{ "a_key", "a_value" },
{ "b_key", "b_value" },
{ "c_key", "c_value" },
};
json j_expected{"a_key", "b_key", "c_key"};
json j_expected{ "a_key", "b_key", "c_key" };
auto transformed = j.items() | std::views::transform([](const auto& item) {
return item.key();

View File

@ -77,9 +77,9 @@ TEST_CASE("JSON patch")
{
// If removing an element from an array, any elements above the
// specified index are shifted one position to the left.
json const doc = {1, 2, 3, 4};
json const patch = {{{"op", "remove"}, {"path", "/1"}}};
CHECK(doc.patch(patch) == json({1, 3, 4}));
json const doc = { 1, 2, 3, 4 };
json const patch = { { { "op", "remove" }, { "path", "/1" } } };
CHECK(doc.patch(patch) == json({ 1, 3, 4 }));
}
SECTION("A.1. Adding an Object Member")
@ -529,7 +529,7 @@ TEST_CASE("JSON patch")
)"_json;
// The resulting JSON document:
json expected = {1, 2, 3};
json expected = { 1, 2, 3 };
// check if patched value is as expected
CHECK(doc.patch(patch) == expected);
@ -545,7 +545,7 @@ TEST_CASE("JSON patch")
// exactly the number of elements in the array which is legal.
// An example target JSON document:
json const doc = {0, 1, 2};
json const doc = { 0, 1, 2 };
// A JSON Patch document:
json const patch = R"(
@ -555,7 +555,7 @@ TEST_CASE("JSON patch")
)"_json;
// The resulting JSON document:
json expected = {0, 1, 2, 3};
json expected = { 0, 1, 2, 3 };
// check if patched value is as expected
CHECK(doc.patch(patch) == expected);
@ -611,7 +611,7 @@ TEST_CASE("JSON patch")
SECTION("replace")
{
json const j = "string";
json const patch = {{{"op", "replace"}, {"path", ""}, {"value", 1}}};
json const patch = { { { "op", "replace" }, { "path", "" }, { "value", 1 } } };
CHECK(j.patch(patch) == json(1));
}
@ -640,13 +640,13 @@ TEST_CASE("JSON patch")
}
{
// a JSON value
json j = {"good", "bad", "ugly"};
json j = { "good", "bad", "ugly" };
// a JSON pointer
auto ptr = json::json_pointer("/2");
// use to access elements
j[ptr] = {{"it", "cattivo"}};
j[ptr] = { { "it", "cattivo" } };
CHECK(j == R"(["good","bad",{"it":"cattivo"}])"_json);
// use user-defined string literal
@ -666,7 +666,7 @@ TEST_CASE("JSON patch")
SECTION("not an array")
{
json const j;
json const patch = {{"op", "add"}, {"path", ""}, {"value", 1}};
json const patch = { { "op", "add" }, { "path", "" }, { "value", 1 } };
CHECK_THROWS_WITH_AS(j.patch(patch),
"[json.exception.parse_error.104] parse error: JSON patch must be an array of objects",
json::parse_error&);
@ -675,7 +675,7 @@ TEST_CASE("JSON patch")
SECTION("not an array of objects")
{
json const j;
json const patch = {"op", "add", "path", "", "value", 1};
json const patch = { "op", "add", "path", "", "value", 1 };
#if JSON_DIAGNOSTICS
CHECK_THROWS_WITH_AS(j.patch(patch),
"[json.exception.parse_error.104] parse error: (/0) JSON patch must be an array of objects",
@ -690,7 +690,7 @@ TEST_CASE("JSON patch")
SECTION("missing 'op'")
{
json const j;
json const patch = {{{"foo", "bar"}}};
json const patch = { { { "foo", "bar" } } };
#if JSON_DIAGNOSTICS
CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: (/0) operation must have member 'op'", json::parse_error&);
#else
@ -701,7 +701,7 @@ TEST_CASE("JSON patch")
SECTION("non-string 'op'")
{
json const j;
json const patch = {{{"op", 1}}};
json const patch = { { { "op", 1 } } };
#if JSON_DIAGNOSTICS
CHECK_THROWS_WITH_AS(j.patch(patch),
"[json.exception.parse_error.105] parse error: (/0) operation must have string member 'op'",
@ -716,7 +716,7 @@ TEST_CASE("JSON patch")
SECTION("invalid operation")
{
json const j;
json const patch = {{{"op", "foo"}, {"path", ""}}};
json const patch = { { { "op", "foo" }, { "path", "" } } };
#if JSON_DIAGNOSTICS
CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: (/0) operation value 'foo' is invalid", json::parse_error&);
#else
@ -730,7 +730,7 @@ TEST_CASE("JSON patch")
SECTION("missing 'path'")
{
json const j;
json const patch = {{{"op", "add"}}};
json const patch = { { { "op", "add" } } };
#if JSON_DIAGNOSTICS
CHECK_THROWS_WITH_AS(j.patch(patch),
"[json.exception.parse_error.105] parse error: (/0) operation 'add' must have member 'path'",
@ -745,7 +745,7 @@ TEST_CASE("JSON patch")
SECTION("non-string 'path'")
{
json const j;
json const patch = {{{"op", "add"}, {"path", 1}}};
json const patch = { { { "op", "add" }, { "path", 1 } } };
#if JSON_DIAGNOSTICS
CHECK_THROWS_WITH_AS(j.patch(patch),
"[json.exception.parse_error.105] parse error: (/0) operation 'add' must have string member 'path'",
@ -760,7 +760,7 @@ TEST_CASE("JSON patch")
SECTION("missing 'value'")
{
json const j;
json const patch = {{{"op", "add"}, {"path", ""}}};
json const patch = { { { "op", "add" }, { "path", "" } } };
#if JSON_DIAGNOSTICS
CHECK_THROWS_WITH_AS(j.patch(patch),
"[json.exception.parse_error.105] parse error: (/0) operation 'add' must have member 'value'",
@ -774,8 +774,8 @@ TEST_CASE("JSON patch")
SECTION("invalid array index")
{
json const j = {1, 2};
json const patch = {{{"op", "add"}, {"path", "/4"}, {"value", 4}}};
json const j = { 1, 2 };
json const patch = { { { "op", "add" }, { "path", "/4" }, { "value", 4 } } };
CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.out_of_range.401] array index 4 is out of range", json::out_of_range&);
}
}
@ -785,7 +785,7 @@ TEST_CASE("JSON patch")
SECTION("missing 'path'")
{
json const j;
json const patch = {{{"op", "remove"}}};
json const patch = { { { "op", "remove" } } };
#if JSON_DIAGNOSTICS
CHECK_THROWS_WITH_AS(j.patch(patch),
"[json.exception.parse_error.105] parse error: (/0) operation 'remove' must have member 'path'",
@ -800,7 +800,7 @@ TEST_CASE("JSON patch")
SECTION("non-string 'path'")
{
json const j;
json const patch = {{{"op", "remove"}, {"path", 1}}};
json const patch = { { { "op", "remove" }, { "path", 1 } } };
#if JSON_DIAGNOSTICS
CHECK_THROWS_WITH_AS(j.patch(patch),
"[json.exception.parse_error.105] parse error: (/0) operation 'remove' must have string member 'path'",
@ -814,22 +814,22 @@ TEST_CASE("JSON patch")
SECTION("nonexisting target location (array)")
{
json const j = {1, 2, 3};
json const patch = {{{"op", "remove"}, {"path", "/17"}}};
json const j = { 1, 2, 3 };
json const patch = { { { "op", "remove" }, { "path", "/17" } } };
CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.out_of_range.401] array index 17 is out of range", json::out_of_range&);
}
SECTION("nonexisting target location (object)")
{
json const j = {{"foo", 1}, {"bar", 2}};
json const patch = {{{"op", "remove"}, {"path", "/baz"}}};
json const j = { { "foo", 1 }, { "bar", 2 } };
json const patch = { { { "op", "remove" }, { "path", "/baz" } } };
CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.out_of_range.403] key 'baz' not found", json::out_of_range&);
}
SECTION("root element as target location")
{
json const j = "string";
json const patch = {{{"op", "remove"}, {"path", ""}}};
json const patch = { { { "op", "remove" }, { "path", "" } } };
CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.out_of_range.405] JSON pointer has no parent", json::out_of_range&);
}
}
@ -839,7 +839,7 @@ TEST_CASE("JSON patch")
SECTION("missing 'path'")
{
json const j;
json const patch = {{{"op", "replace"}}};
json const patch = { { { "op", "replace" } } };
#if JSON_DIAGNOSTICS
CHECK_THROWS_WITH_AS(j.patch(patch),
"[json.exception.parse_error.105] parse error: (/0) operation 'replace' must have member 'path'",
@ -854,7 +854,7 @@ TEST_CASE("JSON patch")
SECTION("non-string 'path'")
{
json const j;
json const patch = {{{"op", "replace"}, {"path", 1}}};
json const patch = { { { "op", "replace" }, { "path", 1 } } };
#if JSON_DIAGNOSTICS
CHECK_THROWS_WITH_AS(j.patch(patch),
"[json.exception.parse_error.105] parse error: (/0) operation 'replace' must have string member 'path'",
@ -869,7 +869,7 @@ TEST_CASE("JSON patch")
SECTION("missing 'value'")
{
json const j;
json const patch = {{{"op", "replace"}, {"path", ""}}};
json const patch = { { { "op", "replace" }, { "path", "" } } };
#if JSON_DIAGNOSTICS
CHECK_THROWS_WITH_AS(j.patch(patch),
"[json.exception.parse_error.105] parse error: (/0) operation 'replace' must have member 'value'",
@ -883,15 +883,15 @@ TEST_CASE("JSON patch")
SECTION("nonexisting target location (array)")
{
json const j = {1, 2, 3};
json const patch = {{{"op", "replace"}, {"path", "/17"}, {"value", 19}}};
json const j = { 1, 2, 3 };
json const patch = { { { "op", "replace" }, { "path", "/17" }, { "value", 19 } } };
CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.out_of_range.401] array index 17 is out of range", json::out_of_range&);
}
SECTION("nonexisting target location (object)")
{
json const j = {{"foo", 1}, {"bar", 2}};
json const patch = {{{"op", "replace"}, {"path", "/baz"}, {"value", 3}}};
json const j = { { "foo", 1 }, { "bar", 2 } };
json const patch = { { { "op", "replace" }, { "path", "/baz" }, { "value", 3 } } };
CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.out_of_range.403] key 'baz' not found", json::out_of_range&);
}
}
@ -901,7 +901,7 @@ TEST_CASE("JSON patch")
SECTION("missing 'path'")
{
json const j;
json const patch = {{{"op", "move"}}};
json const patch = { { { "op", "move" } } };
#if JSON_DIAGNOSTICS
CHECK_THROWS_WITH_AS(j.patch(patch),
"[json.exception.parse_error.105] parse error: (/0) operation 'move' must have member 'path'",
@ -916,7 +916,7 @@ TEST_CASE("JSON patch")
SECTION("non-string 'path'")
{
json const j;
json const patch = {{{"op", "move"}, {"path", 1}}};
json const patch = { { { "op", "move" }, { "path", 1 } } };
#if JSON_DIAGNOSTICS
CHECK_THROWS_WITH_AS(j.patch(patch),
"[json.exception.parse_error.105] parse error: (/0) operation 'move' must have string member 'path'",
@ -931,7 +931,7 @@ TEST_CASE("JSON patch")
SECTION("missing 'from'")
{
json const j;
json const patch = {{{"op", "move"}, {"path", ""}}};
json const patch = { { { "op", "move" }, { "path", "" } } };
CHECK_THROWS_AS(j.patch(patch), json::parse_error&);
#if JSON_DIAGNOSTICS
CHECK_THROWS_WITH_AS(j.patch(patch),
@ -947,7 +947,7 @@ TEST_CASE("JSON patch")
SECTION("non-string 'from'")
{
json const j;
json const patch = {{{"op", "move"}, {"path", ""}, {"from", 1}}};
json const patch = { { { "op", "move" }, { "path", "" }, { "from", 1 } } };
CHECK_THROWS_AS(j.patch(patch), json::parse_error&);
#if JSON_DIAGNOSTICS
CHECK_THROWS_WITH_AS(j.patch(patch),
@ -962,15 +962,15 @@ TEST_CASE("JSON patch")
SECTION("nonexisting from location (array)")
{
json const j = {1, 2, 3};
json const patch = {{{"op", "move"}, {"path", "/0"}, {"from", "/5"}}};
json const j = { 1, 2, 3 };
json const patch = { { { "op", "move" }, { "path", "/0" }, { "from", "/5" } } };
CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.out_of_range.401] array index 5 is out of range", json::out_of_range&);
}
SECTION("nonexisting from location (object)")
{
json const j = {{"foo", 1}, {"bar", 2}};
json const patch = {{{"op", "move"}, {"path", "/baz"}, {"from", "/baz"}}};
json const j = { { "foo", 1 }, { "bar", 2 } };
json const patch = { { { "op", "move" }, { "path", "/baz" }, { "from", "/baz" } } };
CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.out_of_range.403] key 'baz' not found", json::out_of_range&);
}
}
@ -980,7 +980,7 @@ TEST_CASE("JSON patch")
SECTION("missing 'path'")
{
json const j;
json const patch = {{{"op", "copy"}}};
json const patch = { { { "op", "copy" } } };
#if JSON_DIAGNOSTICS
CHECK_THROWS_WITH_AS(j.patch(patch),
"[json.exception.parse_error.105] parse error: (/0) operation 'copy' must have member 'path'",
@ -995,7 +995,7 @@ TEST_CASE("JSON patch")
SECTION("non-string 'path'")
{
json const j;
json const patch = {{{"op", "copy"}, {"path", 1}}};
json const patch = { { { "op", "copy" }, { "path", 1 } } };
#if JSON_DIAGNOSTICS
CHECK_THROWS_WITH_AS(j.patch(patch),
"[json.exception.parse_error.105] parse error: (/0) operation 'copy' must have string member 'path'",
@ -1010,7 +1010,7 @@ TEST_CASE("JSON patch")
SECTION("missing 'from'")
{
json const j;
json const patch = {{{"op", "copy"}, {"path", ""}}};
json const patch = { { { "op", "copy" }, { "path", "" } } };
#if JSON_DIAGNOSTICS
CHECK_THROWS_WITH_AS(j.patch(patch),
"[json.exception.parse_error.105] parse error: (/0) operation 'copy' must have member 'from'",
@ -1025,7 +1025,7 @@ TEST_CASE("JSON patch")
SECTION("non-string 'from'")
{
json const j;
json const patch = {{{"op", "copy"}, {"path", ""}, {"from", 1}}};
json const patch = { { { "op", "copy" }, { "path", "" }, { "from", 1 } } };
#if JSON_DIAGNOSTICS
CHECK_THROWS_WITH_AS(j.patch(patch),
"[json.exception.parse_error.105] parse error: (/0) operation 'copy' must have string member 'from'",
@ -1039,15 +1039,15 @@ TEST_CASE("JSON patch")
SECTION("nonexisting from location (array)")
{
json const j = {1, 2, 3};
json const patch = {{{"op", "copy"}, {"path", "/0"}, {"from", "/5"}}};
json const j = { 1, 2, 3 };
json const patch = { { { "op", "copy" }, { "path", "/0" }, { "from", "/5" } } };
CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.out_of_range.401] array index 5 is out of range", json::out_of_range&);
}
SECTION("nonexisting from location (object)")
{
json const j = {{"foo", 1}, {"bar", 2}};
json const patch = {{{"op", "copy"}, {"path", "/fob"}, {"from", "/baz"}}};
json const j = { { "foo", 1 }, { "bar", 2 } };
json const patch = { { { "op", "copy" }, { "path", "/fob" }, { "from", "/baz" } } };
CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.out_of_range.403] key 'baz' not found", json::out_of_range&);
}
}
@ -1057,7 +1057,7 @@ TEST_CASE("JSON patch")
SECTION("missing 'path'")
{
json const j;
json const patch = {{{"op", "test"}}};
json const patch = { { { "op", "test" } } };
#if JSON_DIAGNOSTICS
CHECK_THROWS_WITH_AS(j.patch(patch),
"[json.exception.parse_error.105] parse error: (/0) operation 'test' must have member 'path'",
@ -1072,7 +1072,7 @@ TEST_CASE("JSON patch")
SECTION("non-string 'path'")
{
json const j;
json const patch = {{{"op", "test"}, {"path", 1}}};
json const patch = { { { "op", "test" }, { "path", 1 } } };
#if JSON_DIAGNOSTICS
CHECK_THROWS_WITH_AS(j.patch(patch),
"[json.exception.parse_error.105] parse error: (/0) operation 'test' must have string member 'path'",
@ -1087,7 +1087,7 @@ TEST_CASE("JSON patch")
SECTION("missing 'value'")
{
json const j;
json const patch = {{{"op", "test"}, {"path", ""}}};
json const patch = { { { "op", "test" }, { "path", "" } } };
#if JSON_DIAGNOSTICS
CHECK_THROWS_WITH_AS(j.patch(patch),
"[json.exception.parse_error.105] parse error: (/0) operation 'test' must have member 'value'",
@ -1347,7 +1347,7 @@ TEST_CASE("JSON patch")
SECTION("Tests from github.com/json-patch/json-patch-tests")
{
for (const auto* filename : {TEST_DATA_DIRECTORY "/json-patch-tests/spec_tests.json", TEST_DATA_DIRECTORY "/json-patch-tests/tests.json"})
for (const auto* filename : { TEST_DATA_DIRECTORY "/json-patch-tests/spec_tests.json", TEST_DATA_DIRECTORY "/json-patch-tests/tests.json" })
{
CAPTURE(filename)
std::ifstream f(filename);

View File

@ -40,7 +40,7 @@ TEST_CASE("JSON pointers")
SECTION("array index error")
{
json v = {1, 2, 3, 4};
json v = { 1, 2, 3, 4 };
json::json_pointer const ptr("/10e");
CHECK_THROWS_WITH_AS(v[ptr], "[json.exception.out_of_range.404] unresolved reference token '10e'", json::out_of_range&);
}
@ -131,15 +131,15 @@ TEST_CASE("JSON pointers")
CHECK(!j.contains(json::json_pointer("/a/c/1")));
CHECK_NOTHROW(j[json::json_pointer("/a/c/1")] = 42);
CHECK(j["a"]["c"] == json({nullptr, 42}));
CHECK(j["a"]["c"] == json({ nullptr, 42 }));
CHECK(j.contains(json::json_pointer("/a/c/1")));
CHECK(!j.contains(json::json_pointer("/a/d/-")));
CHECK_NOTHROW(j[json::json_pointer("/a/d/-")] = 42);
CHECK(!j.contains(json::json_pointer("/a/d/-")));
CHECK(j["a"]["d"] == json::array({42}));
CHECK(j["a"]["d"] == json::array({ 42 }));
// "/a/b" works for JSON {"a": {"b": 42}}
CHECK(json({{"a", {{"b", 42}}}})[json::json_pointer("/a/b")] == json(42));
CHECK(json({ { "a", { { "b", 42 } } } })[json::json_pointer("/a/b")] == json(42));
// unresolved access
json j_primitive = 1;
@ -251,7 +251,7 @@ TEST_CASE("JSON pointers")
{
SECTION("nonconst access")
{
json j = {1, 2, 3};
json j = { 1, 2, 3 };
const json j_const = j;
// check reading access
@ -269,7 +269,7 @@ TEST_CASE("JSON pointers")
// assign to nonexisting index (with gap)
j["/5"_json_pointer] = 55;
CHECK(j == json({1, 13, 3, 33, nullptr, 55}));
CHECK(j == json({ 1, 13, 3, 33, nullptr, 55 }));
// error with leading 0
CHECK_THROWS_WITH_AS(j["/01"_json_pointer],
@ -353,13 +353,13 @@ TEST_CASE("JSON pointers")
CHECK(!j_const.contains("/one"_json_pointer));
CHECK(!j_const.contains("/one"_json_pointer));
CHECK_THROWS_WITH_AS(json({{"/list/0", 1}, {"/list/1", 2}, {"/list/three", 3}}).unflatten(),
CHECK_THROWS_WITH_AS(json({ { "/list/0", 1 }, { "/list/1", 2 }, { "/list/three", 3 } }).unflatten(),
"[json.exception.parse_error.109] parse error: array index 'three' is not a number",
json::parse_error&);
// assign to "-"
j["/-"_json_pointer] = 99;
CHECK(j == json({1, 13, 3, 33, nullptr, 55, 99}));
CHECK(j == json({ 1, 13, 3, 33, nullptr, 55, 99 }));
// error when using "-" in const object
CHECK_THROWS_WITH_AS(j_const["/-"_json_pointer], "[json.exception.out_of_range.402] array index '-' (3) is out of range", json::out_of_range&);
@ -373,7 +373,7 @@ TEST_CASE("JSON pointers")
SECTION("const access")
{
const json j = {1, 2, 3};
const json j = { 1, 2, 3 };
// check reading access
CHECK(j["/0"_json_pointer] == j[0]);
@ -397,28 +397,29 @@ TEST_CASE("JSON pointers")
SECTION("flatten")
{
json j = {{"pi", 3.141},
{"happy", true},
{"name", "Niels"},
{"nothing", nullptr},
{"answer", {{"everything", 42}}},
{"list", {1, 0, 2}},
{"object", {{"currency", "USD"}, {"value", 42.99}, {"", "empty string"}, {"/", "slash"}, {"~", "tilde"}, {"~1", "tilde1"}}}};
json j = { { "pi", 3.141 },
{ "happy", true },
{ "name", "Niels" },
{ "nothing", nullptr },
{ "answer", { { "everything", 42 } } },
{ "list", { 1, 0, 2 } },
{ "object",
{ { "currency", "USD" }, { "value", 42.99 }, { "", "empty string" }, { "/", "slash" }, { "~", "tilde" }, { "~1", "tilde1" } } } };
json j_flatten = {{"/pi", 3.141},
{"/happy", true},
{"/name", "Niels"},
{"/nothing", nullptr},
{"/answer/everything", 42},
{"/list/0", 1},
{"/list/1", 0},
{"/list/2", 2},
{"/object/currency", "USD"},
{"/object/value", 42.99},
{"/object/", "empty string"},
{"/object/~1", "slash"},
{"/object/~0", "tilde"},
{"/object/~01", "tilde1"}};
json j_flatten = { { "/pi", 3.141 },
{ "/happy", true },
{ "/name", "Niels" },
{ "/nothing", nullptr },
{ "/answer/everything", 42 },
{ "/list/0", 1 },
{ "/list/1", 0 },
{ "/list/2", 2 },
{ "/object/currency", "USD" },
{ "/object/value", 42.99 },
{ "/object/", "empty string" },
{ "/object/~1", "slash" },
{ "/object/~0", "tilde" },
{ "/object/~01", "tilde1" } };
// check if flattened result is as expected
CHECK(j.flatten() == j_flatten);
@ -431,15 +432,17 @@ TEST_CASE("JSON pointers")
// error for nonprimitve values
#if JSON_DIAGNOSTICS
CHECK_THROWS_WITH_AS(json({{"/1", {1, 2, 3}}}).unflatten(),
CHECK_THROWS_WITH_AS(json({ { "/1", { 1, 2, 3 } } }).unflatten(),
"[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
json const j_error = {{"", 42}, {"/foo", 17}};
json const j_error = { { "", 42 }, { "/foo", 17 } };
CHECK_THROWS_WITH_AS(j_error.unflatten(), "[json.exception.type_error.313] invalid value to unflatten", json::type_error&);
// explicit roundtrip check
@ -464,7 +467,7 @@ TEST_CASE("JSON pointers")
SECTION("string representation")
{
for (const auto* ptr_str : {"", "/foo", "/foo/0", "/", "/a~1b", "/c%d", "/e^f", "/g|h", "/i\\j", "/k\"l", "/ ", "/m~0n"})
for (const auto* ptr_str : { "", "/foo", "/foo/0", "/", "/a~1b", "/c%d", "/e^f", "/g|h", "/i\\j", "/k\"l", "/ ", "/m~0n" })
{
json::json_pointer const ptr(ptr_str);
std::stringstream ss;
@ -496,14 +499,15 @@ TEST_CASE("JSON pointers")
SECTION("empty, push, pop and parent")
{
const json j = {{"", "Hello"},
{"pi", 3.141},
{"happy", true},
{"name", "Niels"},
{"nothing", nullptr},
{"answer", {{"everything", 42}}},
{"list", {1, 0, 2}},
{"object", {{"currency", "USD"}, {"value", 42.99}, {"", "empty string"}, {"/", "slash"}, {"~", "tilde"}, {"~1", "tilde1"}}}};
const json j = { { "", "Hello" },
{ "pi", 3.141 },
{ "happy", true },
{ "name", "Niels" },
{ "nothing", nullptr },
{ "answer", { { "everything", 42 } } },
{ "list", { 1, 0, 2 } },
{ "object",
{ { "currency", "USD" }, { "value", 42.99 }, { "", "empty string" }, { "/", "slash" }, { "~", "tilde" }, { "~1", "tilde1" } } } };
// empty json_pointer returns the root JSON-object
auto ptr = ""_json_pointer;
@ -555,14 +559,15 @@ TEST_CASE("JSON pointers")
SECTION("operators")
{
const json j = {{"", "Hello"},
{"pi", 3.141},
{"happy", true},
{"name", "Niels"},
{"nothing", nullptr},
{"answer", {{"everything", 42}}},
{"list", {1, 0, 2}},
{"object", {{"currency", "USD"}, {"value", 42.99}, {"", "empty string"}, {"/", "slash"}, {"~", "tilde"}, {"~1", "tilde1"}}}};
const json j = { { "", "Hello" },
{ "pi", 3.141 },
{ "happy", true },
{ "name", "Niels" },
{ "nothing", nullptr },
{ "answer", { { "everything", 42 } } },
{ "list", { 1, 0, 2 } },
{ "object",
{ { "currency", "USD" }, { "value", 42.99 }, { "", "empty string" }, { "/", "slash" }, { "~", "tilde" }, { "~1", "tilde1" } } } };
// empty json_pointer returns the root JSON-object
auto ptr = ""_json_pointer;
@ -602,7 +607,7 @@ TEST_CASE("JSON pointers")
{
const char* ptr_cpstring = "/foo/bar";
const char ptr_castring[] = "/foo/bar"; // NOLINT(hicpp-avoid-c-arrays,modernize-avoid-c-arrays,cppcoreguidelines-avoid-c-arrays)
std::string ptr_string{"/foo/bar"};
std::string ptr_string{ "/foo/bar" };
auto ptr1 = json::json_pointer(ptr_string);
auto ptr2 = json::json_pointer(ptr_string);
@ -694,10 +699,10 @@ TEST_CASE("JSON pointers")
CHECK(std::is_same<json_ptr_str::string_t, json_ptr_j::string_t>::value);
CHECK(std::is_same<json_ptr_str::string_t, json_ptr_oj::string_t>::value);
std::string const ptr_string{"/foo/0"};
json_ptr_str ptr{ptr_string};
json_ptr_j ptr_j{ptr_string};
json_ptr_oj ptr_oj{ptr_string};
std::string const ptr_string{ "/foo/0" };
json_ptr_str ptr{ ptr_string };
json_ptr_j ptr_j{ ptr_string };
json_ptr_oj ptr_oj{ ptr_string };
CHECK(j.contains(ptr));
CHECK(j.contains(ptr_j));

View File

@ -20,7 +20,7 @@ TEST_CASE("version information")
CHECK(j["name"] == "JSON for Modern C++");
CHECK(j["copyright"] == "(C) 2013-2023 Niels Lohmann");
CHECK(j["url"] == "https://github.com/nlohmann/json");
CHECK(j["version"] == json({{"string", "3.11.3"}, {"major", 3}, {"minor", 11}, {"patch", 3}}));
CHECK(j["version"] == json({ { "string", "3.11.3" }, { "major", 3 }, { "minor", 11 }, { "patch", 3 } }));
CHECK(j.find("platform") != j.end());
CHECK(j.at("compiler").find("family") != j.at("compiler").end());

View File

@ -51,7 +51,7 @@ TEST_CASE("modifiers")
SECTION("filled array")
{
json j = {1, 2, 3};
json j = { 1, 2, 3 };
json const k = j;
j.clear();
@ -76,7 +76,7 @@ TEST_CASE("modifiers")
SECTION("filled object")
{
json j = {{"one", 1}, {"two", 2}, {"three", 3}};
json j = { { "one", 1 }, { "two", 2 }, { "three", 3 } };
json const k = j;
j.clear();
@ -101,7 +101,7 @@ TEST_CASE("modifiers")
SECTION("filled binary")
{
json j = json::binary({1, 2, 3, 4, 5});
json j = json::binary({ 1, 2, 3, 4, 5 });
json const k = j;
j.clear();
@ -164,15 +164,15 @@ TEST_CASE("modifiers")
j.push_back(1);
j.push_back(2);
CHECK(j.type() == json::value_t::array);
CHECK(j == json({1, 2}));
CHECK(j == json({ 1, 2 }));
}
SECTION("array")
{
json j = {1, 2, 3};
json j = { 1, 2, 3 };
j.push_back("Hello");
CHECK(j.type() == json::value_t::array);
CHECK(j == json({1, 2, 3, "Hello"}));
CHECK(j == json({ 1, 2, 3, "Hello" }));
}
SECTION("other type")
@ -191,16 +191,16 @@ TEST_CASE("modifiers")
j.push_back(k);
j.push_back(k);
CHECK(j.type() == json::value_t::array);
CHECK(j == json({1, 1}));
CHECK(j == json({ 1, 1 }));
}
SECTION("array")
{
json j = {1, 2, 3};
json j = { 1, 2, 3 };
json const k("Hello");
j.push_back(k);
CHECK(j.type() == json::value_t::array);
CHECK(j == json({1, 2, 3, "Hello"}));
CHECK(j == json({ 1, 2, 3, "Hello" }));
}
SECTION("other type")
@ -217,8 +217,8 @@ TEST_CASE("modifiers")
SECTION("null")
{
json j;
j.push_back(json::object_t::value_type({"one", 1}));
j.push_back(json::object_t::value_type({"two", 2}));
j.push_back(json::object_t::value_type({ "one", 1 }));
j.push_back(json::object_t::value_type({ "two", 2 }));
CHECK(j.type() == json::value_t::object);
CHECK(j.size() == 2);
CHECK(j["one"] == json(1));
@ -228,8 +228,8 @@ TEST_CASE("modifiers")
SECTION("object")
{
json j(json::value_t::object);
j.push_back(json::object_t::value_type({"one", 1}));
j.push_back(json::object_t::value_type({"two", 2}));
j.push_back(json::object_t::value_type({ "one", 1 }));
j.push_back(json::object_t::value_type({ "two", 2 }));
CHECK(j.size() == 2);
CHECK(j["one"] == json(1));
CHECK(j["two"] == json(2));
@ -239,7 +239,7 @@ TEST_CASE("modifiers")
{
json j = 1;
json const k("Hello");
CHECK_THROWS_WITH_AS(j.push_back(json::object_t::value_type({"one", 1})),
CHECK_THROWS_WITH_AS(j.push_back(json::object_t::value_type({ "one", 1 })),
"[json.exception.type_error.308] cannot use push_back() with number",
json::type_error&);
}
@ -250,35 +250,35 @@ TEST_CASE("modifiers")
SECTION("null")
{
json j;
j.push_back({"foo", "bar"});
CHECK(j == json::array({{"foo", "bar"}}));
j.push_back({ "foo", "bar" });
CHECK(j == json::array({ { "foo", "bar" } }));
json k;
k.push_back({1, 2, 3});
CHECK(k == json::array({{1, 2, 3}}));
k.push_back({ 1, 2, 3 });
CHECK(k == json::array({ { 1, 2, 3 } }));
}
SECTION("array")
{
json j = {1, 2, 3};
j.push_back({"foo", "bar"});
CHECK(j == json({1, 2, 3, {"foo", "bar"}}));
json j = { 1, 2, 3 };
j.push_back({ "foo", "bar" });
CHECK(j == json({ 1, 2, 3, { "foo", "bar" } }));
json k = {1, 2, 3};
k.push_back({1, 2, 3});
CHECK(k == json({1, 2, 3, {1, 2, 3}}));
json k = { 1, 2, 3 };
k.push_back({ 1, 2, 3 });
CHECK(k == json({ 1, 2, 3, { 1, 2, 3 } }));
}
SECTION("object")
{
json j = {{"key1", 1}};
j.push_back({"key2", "bar"});
CHECK(j == json({{"key1", 1}, {"key2", "bar"}}));
json j = { { "key1", 1 } };
j.push_back({ "key2", "bar" });
CHECK(j == json({ { "key1", 1 }, { "key2", "bar" } }));
// invalid values (no string/val pair)
CHECK_THROWS_WITH_AS(j.push_back({1}), "[json.exception.type_error.308] cannot use push_back() with object", json::type_error&);
CHECK_THROWS_WITH_AS(j.push_back({1, 2}), "[json.exception.type_error.308] cannot use push_back() with object", json::type_error&);
CHECK_THROWS_WITH_AS(j.push_back({1, 2, 3, 4}), "[json.exception.type_error.308] cannot use push_back() with object", json::type_error&);
CHECK_THROWS_WITH_AS(j.push_back({ 1 }), "[json.exception.type_error.308] cannot use push_back() with object", json::type_error&);
CHECK_THROWS_WITH_AS(j.push_back({ 1, 2 }), "[json.exception.type_error.308] cannot use push_back() with object", json::type_error&);
CHECK_THROWS_WITH_AS(j.push_back({ 1, 2, 3, 4 }), "[json.exception.type_error.308] cannot use push_back() with object", json::type_error&);
}
}
}
@ -295,25 +295,25 @@ TEST_CASE("modifiers")
auto& x2 = j.emplace_back(2);
CHECK(x2 == 2);
CHECK(j.type() == json::value_t::array);
CHECK(j == json({1, 2}));
CHECK(j == json({ 1, 2 }));
}
SECTION("array")
{
json j = {1, 2, 3};
json j = { 1, 2, 3 };
auto& x = j.emplace_back("Hello");
CHECK(x == "Hello");
CHECK(j.type() == json::value_t::array);
CHECK(j == json({1, 2, 3, "Hello"}));
CHECK(j == json({ 1, 2, 3, "Hello" }));
}
SECTION("multiple values")
{
json j;
auto& x = j.emplace_back(3, "foo");
CHECK(x == json({"foo", "foo", "foo"}));
CHECK(x == json({ "foo", "foo", "foo" }));
CHECK(j.type() == json::value_t::array);
CHECK(j == json({{"foo", "foo", "foo"}}));
CHECK(j == json({ { "foo", "foo", "foo" } }));
}
}
@ -352,13 +352,13 @@ TEST_CASE("modifiers")
CHECK(*res3.first == "bam");
// the final object
CHECK(j == json({{"baz", "bam"}, {"foo", "bar"}}));
CHECK(j == json({ { "baz", "bam" }, { "foo", "bar" } }));
}
SECTION("object")
{
// start with an object
json j = {{"foo", "bar"}};
json j = { { "foo", "bar" } };
// add a new key
auto res1 = j.emplace("baz", "bam");
@ -371,7 +371,7 @@ TEST_CASE("modifiers")
CHECK(*res2.first == "bar");
// check final object
CHECK(j == json({{"baz", "bam"}, {"foo", "bar"}}));
CHECK(j == json({ { "baz", "bam" }, { "foo", "bar" } }));
}
}
@ -394,15 +394,15 @@ TEST_CASE("modifiers")
j += 1;
j += 2;
CHECK(j.type() == json::value_t::array);
CHECK(j == json({1, 2}));
CHECK(j == json({ 1, 2 }));
}
SECTION("array")
{
json j = {1, 2, 3};
json j = { 1, 2, 3 };
j += "Hello";
CHECK(j.type() == json::value_t::array);
CHECK(j == json({1, 2, 3, "Hello"}));
CHECK(j == json({ 1, 2, 3, "Hello" }));
}
SECTION("other type")
@ -421,16 +421,16 @@ TEST_CASE("modifiers")
j += k;
j += k;
CHECK(j.type() == json::value_t::array);
CHECK(j == json({1, 1}));
CHECK(j == json({ 1, 1 }));
}
SECTION("array")
{
json j = {1, 2, 3};
json j = { 1, 2, 3 };
json const k("Hello");
j += k;
CHECK(j.type() == json::value_t::array);
CHECK(j == json({1, 2, 3, "Hello"}));
CHECK(j == json({ 1, 2, 3, "Hello" }));
}
SECTION("other type")
@ -447,8 +447,8 @@ TEST_CASE("modifiers")
SECTION("null")
{
json j;
j += json::object_t::value_type({"one", 1});
j += json::object_t::value_type({"two", 2});
j += json::object_t::value_type({ "one", 1 });
j += json::object_t::value_type({ "two", 2 });
CHECK(j.type() == json::value_t::object);
CHECK(j.size() == 2);
CHECK(j["one"] == json(1));
@ -458,8 +458,8 @@ TEST_CASE("modifiers")
SECTION("object")
{
json j(json::value_t::object);
j += json::object_t::value_type({"one", 1});
j += json::object_t::value_type({"two", 2});
j += json::object_t::value_type({ "one", 1 });
j += json::object_t::value_type({ "two", 2 });
CHECK(j.size() == 2);
CHECK(j["one"] == json(1));
CHECK(j["two"] == json(2));
@ -469,7 +469,7 @@ TEST_CASE("modifiers")
{
json j = 1;
json const k("Hello");
CHECK_THROWS_WITH_AS(j += json::object_t::value_type({"one", 1}),
CHECK_THROWS_WITH_AS(j += json::object_t::value_type({ "one", 1 }),
"[json.exception.type_error.308] cannot use push_back() with number",
json::type_error&);
}
@ -480,40 +480,40 @@ TEST_CASE("modifiers")
SECTION("null")
{
json j;
j += {"foo", "bar"};
CHECK(j == json::array({{"foo", "bar"}}));
j += { "foo", "bar" };
CHECK(j == json::array({ { "foo", "bar" } }));
json k;
k += {1, 2, 3};
CHECK(k == json::array({{1, 2, 3}}));
k += { 1, 2, 3 };
CHECK(k == json::array({ { 1, 2, 3 } }));
}
SECTION("array")
{
json j = {1, 2, 3};
j += {"foo", "bar"};
CHECK(j == json({1, 2, 3, {"foo", "bar"}}));
json j = { 1, 2, 3 };
j += { "foo", "bar" };
CHECK(j == json({ 1, 2, 3, { "foo", "bar" } }));
json k = {1, 2, 3};
k += {1, 2, 3};
CHECK(k == json({1, 2, 3, {1, 2, 3}}));
json k = { 1, 2, 3 };
k += { 1, 2, 3 };
CHECK(k == json({ 1, 2, 3, { 1, 2, 3 } }));
}
SECTION("object")
{
json j = {{"key1", 1}};
j += {"key2", "bar"};
CHECK(j == json({{"key1", 1}, {"key2", "bar"}}));
json j = { { "key1", 1 } };
j += { "key2", "bar" };
CHECK(j == json({ { "key1", 1 }, { "key2", "bar" } }));
json k = {{"key1", 1}};
CHECK_THROWS_WITH_AS((k += {1, 2, 3, 4}), "[json.exception.type_error.308] cannot use push_back() with object", json::type_error&);
json k = { { "key1", 1 } };
CHECK_THROWS_WITH_AS((k += { 1, 2, 3, 4 }), "[json.exception.type_error.308] cannot use push_back() with object", json::type_error&);
}
}
}
SECTION("insert()")
{
json j_array = {1, 2, 3, 4};
json j_array = { 1, 2, 3, 4 };
json j_value = 5;
SECTION("value at position")
@ -524,7 +524,7 @@ TEST_CASE("modifiers")
CHECK(j_array.size() == 5);
CHECK(*it == j_value);
CHECK(j_array.begin() == it);
CHECK(j_array == json({5, 1, 2, 3, 4}));
CHECK(j_array == json({ 5, 1, 2, 3, 4 }));
}
SECTION("insert in the middle")
@ -533,7 +533,7 @@ TEST_CASE("modifiers")
CHECK(j_array.size() == 5);
CHECK(*it == j_value);
CHECK((it - j_array.begin()) == 2);
CHECK(j_array == json({1, 2, 5, 3, 4}));
CHECK(j_array == json({ 1, 2, 5, 3, 4 }));
}
SECTION("insert before end()")
@ -542,7 +542,7 @@ TEST_CASE("modifiers")
CHECK(j_array.size() == 5);
CHECK(*it == j_value);
CHECK((j_array.end() - it) == 1);
CHECK(j_array == json({1, 2, 3, 4, 5}));
CHECK(j_array == json({ 1, 2, 3, 4, 5 }));
}
}
@ -554,7 +554,7 @@ TEST_CASE("modifiers")
CHECK(j_array.size() == 5);
CHECK(*it == j_value);
CHECK(j_array.begin() == it);
CHECK(j_array == json({5, 1, 2, 3, 4}));
CHECK(j_array == json({ 5, 1, 2, 3, 4 }));
}
SECTION("insert in the middle")
@ -563,7 +563,7 @@ TEST_CASE("modifiers")
CHECK(j_array.size() == 5);
CHECK(*it == j_value);
CHECK((it - j_array.begin()) == 2);
CHECK(j_array == json({1, 2, 5, 3, 4}));
CHECK(j_array == json({ 1, 2, 5, 3, 4 }));
}
SECTION("insert before end()")
@ -572,7 +572,7 @@ TEST_CASE("modifiers")
CHECK(j_array.size() == 5);
CHECK(*it == j_value);
CHECK((j_array.end() - it) == 1);
CHECK(j_array == json({1, 2, 3, 4, 5}));
CHECK(j_array == json({ 1, 2, 3, 4, 5 }));
}
}
@ -584,7 +584,7 @@ TEST_CASE("modifiers")
CHECK(j_array.size() == 7);
CHECK(*it == j_value);
CHECK(j_array.begin() == it);
CHECK(j_array == json({5, 5, 5, 1, 2, 3, 4}));
CHECK(j_array == json({ 5, 5, 5, 1, 2, 3, 4 }));
}
SECTION("insert in the middle")
@ -593,7 +593,7 @@ TEST_CASE("modifiers")
CHECK(j_array.size() == 7);
CHECK(*it == j_value);
CHECK((it - j_array.begin()) == 2);
CHECK(j_array == json({1, 2, 5, 5, 5, 3, 4}));
CHECK(j_array == json({ 1, 2, 5, 5, 5, 3, 4 }));
}
SECTION("insert before end()")
@ -602,7 +602,7 @@ TEST_CASE("modifiers")
CHECK(j_array.size() == 7);
CHECK(*it == j_value);
CHECK((j_array.end() - it) == 3);
CHECK(j_array == json({1, 2, 3, 4, 5, 5, 5}));
CHECK(j_array == json({ 1, 2, 3, 4, 5, 5, 5 }));
}
SECTION("insert nothing (count = 0)")
@ -612,13 +612,13 @@ TEST_CASE("modifiers")
// the returned iterator points to the first inserted element;
// there were 4 elements, so it should point to the 5th
CHECK(it == j_array.begin() + 4);
CHECK(j_array == json({1, 2, 3, 4}));
CHECK(j_array == json({ 1, 2, 3, 4 }));
}
}
SECTION("range for array")
{
json j_other_array = {"first", "second"};
json j_other_array = { "first", "second" };
SECTION("proper usage")
{
@ -626,7 +626,7 @@ TEST_CASE("modifiers")
CHECK(j_array.size() == 6);
CHECK(*it == *j_other_array.begin());
CHECK((j_array.end() - it) == 2);
CHECK(j_array == json({1, 2, 3, 4, "first", "second"}));
CHECK(j_array == json({ 1, 2, 3, 4, "first", "second" }));
}
SECTION("empty range")
@ -634,12 +634,12 @@ TEST_CASE("modifiers")
auto it = j_array.insert(j_array.end(), j_other_array.begin(), j_other_array.begin());
CHECK(j_array.size() == 4);
CHECK(it == j_array.end());
CHECK(j_array == json({1, 2, 3, 4}));
CHECK(j_array == json({ 1, 2, 3, 4 }));
}
SECTION("invalid iterators")
{
json j_other_array2 = {"first", "second"};
json j_other_array2 = { "first", "second" };
CHECK_THROWS_WITH_AS(j_array.insert(j_array.end(), j_array.begin(), j_array.end()),
"[json.exception.invalid_iterator.211] passed iterators may not belong to container",
@ -652,8 +652,8 @@ TEST_CASE("modifiers")
SECTION("range for object")
{
json j_object1 = {{"one", "eins"}, {"two", "zwei"}};
json j_object2 = {{"eleven", "elf"}, {"seventeen", "siebzehn"}};
json j_object1 = { { "one", "eins" }, { "two", "zwei" } };
json j_object2 = { { "eleven", "elf" }, { "seventeen", "siebzehn" } };
SECTION("proper usage")
{
@ -669,7 +669,7 @@ TEST_CASE("modifiers")
SECTION("invalid iterators")
{
json const j_other_array2 = {"first", "second"};
json const j_other_array2 = { "first", "second" };
CHECK_THROWS_WITH_AS(j_array.insert(j_object2.begin(), j_object2.end()),
"[json.exception.type_error.309] cannot use insert() with array",
@ -687,37 +687,37 @@ TEST_CASE("modifiers")
{
SECTION("insert before begin()")
{
auto it = j_array.insert(j_array.begin(), {7, 8, 9});
auto it = j_array.insert(j_array.begin(), { 7, 8, 9 });
CHECK(j_array.size() == 7);
CHECK(*it == json(7));
CHECK(j_array.begin() == it);
CHECK(j_array == json({7, 8, 9, 1, 2, 3, 4}));
CHECK(j_array == json({ 7, 8, 9, 1, 2, 3, 4 }));
}
SECTION("insert in the middle")
{
auto it = j_array.insert(j_array.begin() + 2, {7, 8, 9});
auto it = j_array.insert(j_array.begin() + 2, { 7, 8, 9 });
CHECK(j_array.size() == 7);
CHECK(*it == json(7));
CHECK((it - j_array.begin()) == 2);
CHECK(j_array == json({1, 2, 7, 8, 9, 3, 4}));
CHECK(j_array == json({ 1, 2, 7, 8, 9, 3, 4 }));
}
SECTION("insert before end()")
{
auto it = j_array.insert(j_array.end(), {7, 8, 9});
auto it = j_array.insert(j_array.end(), { 7, 8, 9 });
CHECK(j_array.size() == 7);
CHECK(*it == json(7));
CHECK((j_array.end() - it) == 3);
CHECK(j_array == json({1, 2, 3, 4, 7, 8, 9}));
CHECK(j_array == json({ 1, 2, 3, 4, 7, 8, 9 }));
}
}
SECTION("invalid iterator")
{
// pass iterator to a different array
json j_another_array = {1, 2};
json j_yet_another_array = {"first", "second"};
json j_another_array = { 1, 2 };
json j_yet_another_array = { "first", "second" };
CHECK_THROWS_WITH_AS(j_array.insert(j_another_array.end(), 10),
"[json.exception.invalid_iterator.202] iterator does not fit current value",
json::invalid_iterator&);
@ -730,7 +730,7 @@ TEST_CASE("modifiers")
CHECK_THROWS_WITH_AS(j_array.insert(j_another_array.end(), j_yet_another_array.begin(), j_yet_another_array.end()),
"[json.exception.invalid_iterator.202] iterator does not fit current value",
json::invalid_iterator&);
CHECK_THROWS_WITH_AS(j_array.insert(j_another_array.end(), {1, 2, 3, 4}),
CHECK_THROWS_WITH_AS(j_array.insert(j_another_array.end(), { 1, 2, 3, 4 }),
"[json.exception.invalid_iterator.202] iterator does not fit current value",
json::invalid_iterator&);
}
@ -739,7 +739,7 @@ TEST_CASE("modifiers")
{
// call insert on a non-array type
json j_nonarray = 3;
json j_yet_another_array = {"first", "second"};
json j_yet_another_array = { "first", "second" };
CHECK_THROWS_WITH_AS(j_nonarray.insert(j_nonarray.end(), 10), "[json.exception.type_error.309] cannot use insert() with number", json::type_error&);
CHECK_THROWS_WITH_AS(j_nonarray.insert(j_nonarray.end(), j_value),
"[json.exception.type_error.309] cannot use insert() with number",
@ -750,7 +750,7 @@ TEST_CASE("modifiers")
CHECK_THROWS_WITH_AS(j_nonarray.insert(j_nonarray.end(), j_yet_another_array.begin(), j_yet_another_array.end()),
"[json.exception.type_error.309] cannot use insert() with number",
json::type_error&);
CHECK_THROWS_WITH_AS(j_nonarray.insert(j_nonarray.end(), {1, 2, 3, 4}),
CHECK_THROWS_WITH_AS(j_nonarray.insert(j_nonarray.end(), { 1, 2, 3, 4 }),
"[json.exception.type_error.309] cannot use insert() with number",
json::type_error&);
}
@ -760,16 +760,16 @@ TEST_CASE("modifiers")
{
SECTION("non-recursive (default)")
{
json j_object1 = {{"one", "eins"}, {"two", "zwei"}};
json j_object2 = {{"three", "drei"}, {"two", "zwo"}};
json j_array = {1, 2, 3, 4};
json j_object1 = { { "one", "eins" }, { "two", "zwei" } };
json j_object2 = { { "three", "drei" }, { "two", "zwo" } };
json j_array = { 1, 2, 3, 4 };
SECTION("const reference")
{
SECTION("proper usage")
{
j_object1.update(j_object2);
CHECK(j_object1 == json({{"one", "eins"}, {"two", "zwo"}, {"three", "drei"}}));
CHECK(j_object1 == json({ { "one", "eins" }, { "two", "zwo" }, { "three", "drei" } }));
json j_null;
j_null.update(j_object2);
@ -789,7 +789,7 @@ TEST_CASE("modifiers")
SECTION("proper usage")
{
j_object1.update(j_object2.begin(), j_object2.end());
CHECK(j_object1 == json({{"one", "eins"}, {"two", "zwo"}, {"three", "drei"}}));
CHECK(j_object1 == json({ { "one", "eins" }, { "two", "zwo" }, { "three", "drei" } }));
json j_null;
j_null.update(j_object2.begin(), j_object2.end());
@ -799,12 +799,12 @@ TEST_CASE("modifiers")
SECTION("empty range")
{
j_object1.update(j_object2.begin(), j_object2.begin());
CHECK(j_object1 == json({{"one", "eins"}, {"two", "zwei"}}));
CHECK(j_object1 == json({ { "one", "eins" }, { "two", "zwei" } }));
}
SECTION("invalid iterators")
{
json const j_other_array2 = {"first", "second"};
json const j_other_array2 = { "first", "second" };
CHECK_THROWS_WITH_AS(j_array.update(j_object2.begin(), j_object2.end()),
"[json.exception.type_error.312] cannot use update() with array",
@ -825,18 +825,18 @@ TEST_CASE("modifiers")
{
SECTION("extend object")
{
json j1 = {{"string", "s"}, {"numbers", {{"one", 1}}}};
json const j2 = {{"string", "t"}, {"numbers", {{"two", 2}}}};
json j1 = { { "string", "s" }, { "numbers", { { "one", 1 } } } };
json const j2 = { { "string", "t" }, { "numbers", { { "two", 2 } } } };
j1.update(j2, true);
CHECK(j1 == json({{"string", "t"}, {"numbers", {{"one", 1}, {"two", 2}}}}));
CHECK(j1 == json({ { "string", "t" }, { "numbers", { { "one", 1 }, { "two", 2 } } } }));
}
SECTION("replace object")
{
json j1 = {{"string", "s"}, {"numbers", {{"one", 1}}}};
json const j2 = {{"string", "t"}, {"numbers", 1}};
json j1 = { { "string", "s" }, { "numbers", { { "one", 1 } } } };
json const j2 = { { "string", "t" }, { "numbers", 1 } };
j1.update(j2, true);
CHECK(j1 == json({{"string", "t"}, {"numbers", 1}}));
CHECK(j1 == json({ { "string", "t" }, { "numbers", 1 } }));
}
}
}
@ -874,22 +874,22 @@ TEST_CASE("modifiers")
{
SECTION("array_t type")
{
json j = {1, 2, 3, 4};
json::array_t a = {"foo", "bar", "baz"};
json j = { 1, 2, 3, 4 };
json::array_t a = { "foo", "bar", "baz" };
j.swap(a);
CHECK(j == json({"foo", "bar", "baz"}));
CHECK(j == json({ "foo", "bar", "baz" }));
j.swap(a);
CHECK(j == json({1, 2, 3, 4}));
CHECK(j == json({ 1, 2, 3, 4 }));
}
SECTION("non-array_t type")
{
json j = 17;
json::array_t a = {"foo", "bar", "baz"};
json::array_t a = { "foo", "bar", "baz" };
CHECK_THROWS_WITH_AS(j.swap(a), "[json.exception.type_error.310] cannot use swap(array_t&) with number", json::type_error&);
}
@ -899,22 +899,22 @@ TEST_CASE("modifiers")
{
SECTION("object_t type")
{
json j = {{"one", 1}, {"two", 2}};
json::object_t o = {{"cow", "Kuh"}, {"chicken", "Huhn"}};
json j = { { "one", 1 }, { "two", 2 } };
json::object_t o = { { "cow", "Kuh" }, { "chicken", "Huhn" } };
j.swap(o);
CHECK(j == json({{"cow", "Kuh"}, {"chicken", "Huhn"}}));
CHECK(j == json({ { "cow", "Kuh" }, { "chicken", "Huhn" } }));
j.swap(o);
CHECK(j == json({{"one", 1}, {"two", 2}}));
CHECK(j == json({ { "one", 1 }, { "two", 2 } }));
}
SECTION("non-object_t type")
{
json j = 17;
json::object_t o = {{"cow", "Kuh"}, {"chicken", "Huhn"}};
json::object_t o = { { "cow", "Kuh" }, { "chicken", "Huhn" } };
CHECK_THROWS_WITH_AS(j.swap(o), "[json.exception.type_error.310] cannot use swap(object_t&) with number", json::type_error&);
}
@ -949,37 +949,37 @@ TEST_CASE("modifiers")
{
SECTION("binary_t type")
{
json j = json::binary({1, 2, 3, 4});
json::binary_t s = {{5, 6, 7, 8}};
json j = json::binary({ 1, 2, 3, 4 });
json::binary_t s = { { 5, 6, 7, 8 } };
j.swap(s);
CHECK(j == json::binary({5, 6, 7, 8}));
CHECK(j == json::binary({ 5, 6, 7, 8 }));
j.swap(s);
CHECK(j == json::binary({1, 2, 3, 4}));
CHECK(j == json::binary({ 1, 2, 3, 4 }));
}
SECTION("binary_t::container_type type")
{
json j = json::binary({1, 2, 3, 4});
std::vector<std::uint8_t> s = {{5, 6, 7, 8}};
json j = json::binary({ 1, 2, 3, 4 });
std::vector<std::uint8_t> s = { { 5, 6, 7, 8 } };
j.swap(s);
CHECK(j == json::binary({5, 6, 7, 8}));
CHECK(j == json::binary({ 5, 6, 7, 8 }));
j.swap(s);
CHECK(j == json::binary({1, 2, 3, 4}));
CHECK(j == json::binary({ 1, 2, 3, 4 }));
}
SECTION("non-binary_t type")
{
json j = 17;
json::binary_t s1 = {{1, 2, 3, 4}};
std::vector<std::uint8_t> s2 = {{5, 6, 7, 8}};
json::binary_t s1 = { { 1, 2, 3, 4 } };
std::vector<std::uint8_t> s2 = { { 5, 6, 7, 8 } };
CHECK_THROWS_WITH_AS(j.swap(s1), "[json.exception.type_error.310] cannot use swap(binary_t&) with number", json::type_error);
CHECK_THROWS_WITH_AS(j.swap(s2), "[json.exception.type_error.310] cannot use swap(binary_t::container_type&) with number", json::type_error);

View File

@ -118,7 +118,7 @@ TEST_CASE("MessagePack")
SECTION("null")
{
json const j = nullptr;
std::vector<uint8_t> const expected = {0xc0};
std::vector<uint8_t> const expected = { 0xc0 };
const auto result = json::to_msgpack(j);
CHECK(result == expected);
@ -132,7 +132,7 @@ TEST_CASE("MessagePack")
SECTION("true")
{
json const j = true;
std::vector<uint8_t> const expected = {0xc3};
std::vector<uint8_t> const expected = { 0xc3 };
const auto result = json::to_msgpack(j);
CHECK(result == expected);
@ -144,7 +144,7 @@ TEST_CASE("MessagePack")
SECTION("false")
{
json const j = false;
std::vector<uint8_t> const expected = {0xc2};
std::vector<uint8_t> const expected = { 0xc2 };
const auto result = json::to_msgpack(j);
CHECK(result == expected);
@ -171,7 +171,7 @@ TEST_CASE("MessagePack")
CHECK(j.is_number_integer());
// create expected byte vector
std::vector<uint8_t> const expected{static_cast<uint8_t>(i)};
std::vector<uint8_t> const expected{ static_cast<uint8_t>(i) };
// compare result + size
const auto result = json::to_msgpack(j);
@ -201,7 +201,7 @@ TEST_CASE("MessagePack")
CHECK(j.is_number_integer());
// create expected byte vector
std::vector<uint8_t> const expected{static_cast<uint8_t>(i)};
std::vector<uint8_t> const expected{ static_cast<uint8_t>(i) };
// compare result + size
const auto result = json::to_msgpack(j);
@ -290,7 +290,7 @@ TEST_CASE("MessagePack")
SECTION("65536..4294967295 (int 32)")
{
for (uint32_t i : {65536u, 77777u, 1048576u, 4294967295u})
for (uint32_t i : { 65536u, 77777u, 1048576u, 4294967295u })
{
CAPTURE(i)
@ -329,7 +329,7 @@ TEST_CASE("MessagePack")
SECTION("4294967296..9223372036854775807 (int 64)")
{
for (uint64_t i : {4294967296LU, 9223372036854775807LU})
for (uint64_t i : { 4294967296LU, 9223372036854775807LU })
{
CAPTURE(i)
@ -408,7 +408,7 @@ TEST_CASE("MessagePack")
SECTION("-9263 (int 16)")
{
json const j = -9263;
std::vector<uint8_t> const expected = {0xd1, 0xdb, 0xd1};
std::vector<uint8_t> const expected = { 0xd1, 0xdb, 0xd1 };
const auto result = json::to_msgpack(j);
CHECK(result == expected);
@ -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)
{
@ -565,7 +561,7 @@ TEST_CASE("MessagePack")
CHECK(j.is_number_unsigned());
// create expected byte vector
std::vector<uint8_t> const expected{static_cast<uint8_t>(i)};
std::vector<uint8_t> const expected{ static_cast<uint8_t>(i) };
// compare result + size
const auto result = json::to_msgpack(j);
@ -652,7 +648,7 @@ TEST_CASE("MessagePack")
SECTION("65536..4294967295 (uint 32)")
{
for (const uint32_t i : {65536u, 77777u, 1048576u, 4294967295u})
for (const uint32_t i : { 65536u, 77777u, 1048576u, 4294967295u })
{
CAPTURE(i)
@ -690,7 +686,7 @@ TEST_CASE("MessagePack")
SECTION("4294967296..18446744073709551615 (uint 64)")
{
for (const uint64_t i : {4294967296LU, 18446744073709551615LU})
for (const uint64_t i : { 4294967296LU, 18446744073709551615LU })
{
CAPTURE(i)
@ -739,7 +735,7 @@ TEST_CASE("MessagePack")
{
double const v = 3.1415925;
json const j = v;
std::vector<uint8_t> const expected = {0xcb, 0x40, 0x09, 0x21, 0xfb, 0x3f, 0xa6, 0xde, 0xfc};
std::vector<uint8_t> const expected = { 0xcb, 0x40, 0x09, 0x21, 0xfb, 0x3f, 0xa6, 0xde, 0xfc };
const auto result = json::to_msgpack(j);
CHECK(result == expected);
@ -753,7 +749,7 @@ TEST_CASE("MessagePack")
{
double const v = 1.0;
json const j = v;
std::vector<uint8_t> const expected = {0xca, 0x3f, 0x80, 0x00, 0x00};
std::vector<uint8_t> const expected = { 0xca, 0x3f, 0x80, 0x00, 0x00 };
const auto result = json::to_msgpack(j);
CHECK(result == expected);
@ -767,7 +763,7 @@ TEST_CASE("MessagePack")
{
double const v = 128.1280059814453125;
json const j = v;
std::vector<uint8_t> const expected = {0xca, 0x43, 0x00, 0x20, 0xc5};
std::vector<uint8_t> const expected = { 0xca, 0x43, 0x00, 0x20, 0xc5 };
const auto result = json::to_msgpack(j);
CHECK(result == expected);
@ -784,8 +780,8 @@ TEST_CASE("MessagePack")
SECTION("N = 0..31")
{
// explicitly enumerate the first byte for all 32 strings
const std::vector<uint8_t> first_bytes = {0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf,
0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf};
const std::vector<uint8_t> first_bytes = { 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf,
0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf };
for (size_t N = 0; N < first_bytes.size(); ++N)
{
@ -856,7 +852,7 @@ TEST_CASE("MessagePack")
SECTION("N = 256..65535")
{
for (size_t N : {256u, 999u, 1025u, 3333u, 2048u, 65535u})
for (size_t N : { 256u, 999u, 1025u, 3333u, 2048u, 65535u })
{
CAPTURE(N)
@ -886,7 +882,7 @@ TEST_CASE("MessagePack")
SECTION("N = 65536..4294967295")
{
for (size_t N : {65536u, 77777u, 1048576u})
for (size_t N : { 65536u, 77777u, 1048576u })
{
CAPTURE(N)
@ -922,7 +918,7 @@ TEST_CASE("MessagePack")
SECTION("empty")
{
json const j = json::array();
std::vector<uint8_t> const expected = {0x90};
std::vector<uint8_t> const expected = { 0x90 };
const auto result = json::to_msgpack(j);
CHECK(result == expected);
@ -933,8 +929,8 @@ TEST_CASE("MessagePack")
SECTION("[null]")
{
json const j = {nullptr};
std::vector<uint8_t> const expected = {0x91, 0xc0};
json const j = { nullptr };
std::vector<uint8_t> const expected = { 0x91, 0xc0 };
const auto result = json::to_msgpack(j);
CHECK(result == expected);
@ -946,7 +942,7 @@ TEST_CASE("MessagePack")
SECTION("[1,2,3,4,5]")
{
json const j = json::parse("[1,2,3,4,5]");
std::vector<uint8_t> const expected = {0x95, 0x01, 0x02, 0x03, 0x04, 0x05};
std::vector<uint8_t> const expected = { 0x95, 0x01, 0x02, 0x03, 0x04, 0x05 };
const auto result = json::to_msgpack(j);
CHECK(result == expected);
@ -958,7 +954,7 @@ TEST_CASE("MessagePack")
SECTION("[[[[]]]]")
{
json const j = json::parse("[[[[]]]]");
std::vector<uint8_t> const expected = {0x91, 0x91, 0x91, 0x90};
std::vector<uint8_t> const expected = { 0x91, 0x91, 0x91, 0x90 };
const auto result = json::to_msgpack(j);
CHECK(result == expected);
@ -1012,7 +1008,7 @@ TEST_CASE("MessagePack")
SECTION("empty")
{
json const j = json::object();
std::vector<uint8_t> const expected = {0x80};
std::vector<uint8_t> const expected = { 0x80 };
const auto result = json::to_msgpack(j);
CHECK(result == expected);
@ -1023,8 +1019,8 @@ TEST_CASE("MessagePack")
SECTION("{\"\":null}")
{
json const j = {{"", nullptr}};
std::vector<uint8_t> const expected = {0x81, 0xa0, 0xc0};
json const j = { { "", nullptr } };
std::vector<uint8_t> const expected = { 0x81, 0xa0, 0xc0 };
const auto result = json::to_msgpack(j);
CHECK(result == expected);
@ -1036,7 +1032,7 @@ TEST_CASE("MessagePack")
SECTION("{\"a\": {\"b\": {\"c\": {}}}}")
{
json const j = json::parse(R"({"a": {"b": {"c": {}}}})");
std::vector<uint8_t> const expected = {0x81, 0xa1, 0x61, 0x81, 0xa1, 0x62, 0x81, 0xa1, 0x63, 0x80};
std::vector<uint8_t> const expected = { 0x81, 0xa1, 0x61, 0x81, 0xa1, 0x62, 0x81, 0xa1, 0x63, 0x80 };
const auto result = json::to_msgpack(j);
CHECK(result == expected);
@ -1177,7 +1173,7 @@ TEST_CASE("MessagePack")
SECTION("N = 256..65535")
{
for (std::size_t N : {256u, 999u, 1025u, 3333u, 2048u, 65535u})
for (std::size_t N : { 256u, 999u, 1025u, 3333u, 2048u, 65535u })
{
CAPTURE(N)
@ -1210,7 +1206,7 @@ TEST_CASE("MessagePack")
SECTION("N = 65536..4294967295")
{
for (std::size_t N : {65536u, 77777u, 1048576u})
for (std::size_t N : { 65536u, 77777u, 1048576u })
{
CAPTURE(N)
@ -1283,7 +1279,7 @@ TEST_CASE("MessagePack")
SECTION("N = 256..65535")
{
for (std::size_t N : {256u, 999u, 1025u, 3333u, 2048u, 65535u})
for (std::size_t N : { 256u, 999u, 1025u, 3333u, 2048u, 65535u })
{
CAPTURE(N)
@ -1313,7 +1309,7 @@ TEST_CASE("MessagePack")
SECTION("N = 65536..4294967295")
{
for (std::size_t N : {65536u, 77777u, 1048576u})
for (std::size_t N : { 65536u, 77777u, 1048576u })
{
CAPTURE(N)
@ -1347,7 +1343,7 @@ TEST_CASE("MessagePack")
SECTION("from float32")
{
auto given = std::vector<uint8_t>({0xca, 0x41, 0xc8, 0x00, 0x01});
auto given = std::vector<uint8_t>({ 0xca, 0x41, 0xc8, 0x00, 0x01 });
json const j = json::from_msgpack(given);
CHECK(j.get<double>() == Approx(25.0000019073486));
}
@ -1369,107 +1365,107 @@ TEST_CASE("MessagePack")
json _;
CHECK_THROWS_WITH_AS(
_ = json::from_msgpack(std::vector<uint8_t>({0x87})),
_ = json::from_msgpack(std::vector<uint8_t>({ 0x87 })),
"[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing MessagePack string: unexpected end of input",
json::parse_error&);
CHECK_THROWS_WITH_AS(
_ = json::from_msgpack(std::vector<uint8_t>({0xcc})),
_ = json::from_msgpack(std::vector<uint8_t>({ 0xcc })),
"[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing MessagePack number: unexpected end of input",
json::parse_error&);
CHECK_THROWS_WITH_AS(
_ = json::from_msgpack(std::vector<uint8_t>({0xcd})),
_ = json::from_msgpack(std::vector<uint8_t>({ 0xcd })),
"[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing MessagePack number: unexpected end of input",
json::parse_error&);
CHECK_THROWS_WITH_AS(
_ = json::from_msgpack(std::vector<uint8_t>({0xcd, 0x00})),
_ = json::from_msgpack(std::vector<uint8_t>({ 0xcd, 0x00 })),
"[json.exception.parse_error.110] parse error at byte 3: syntax error while parsing MessagePack number: unexpected end of input",
json::parse_error&);
CHECK_THROWS_WITH_AS(
_ = json::from_msgpack(std::vector<uint8_t>({0xce})),
_ = json::from_msgpack(std::vector<uint8_t>({ 0xce })),
"[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing MessagePack number: unexpected end of input",
json::parse_error&);
CHECK_THROWS_WITH_AS(
_ = json::from_msgpack(std::vector<uint8_t>({0xce, 0x00})),
_ = json::from_msgpack(std::vector<uint8_t>({ 0xce, 0x00 })),
"[json.exception.parse_error.110] parse error at byte 3: syntax error while parsing MessagePack number: unexpected end of input",
json::parse_error&);
CHECK_THROWS_WITH_AS(
_ = json::from_msgpack(std::vector<uint8_t>({0xce, 0x00, 0x00})),
_ = json::from_msgpack(std::vector<uint8_t>({ 0xce, 0x00, 0x00 })),
"[json.exception.parse_error.110] parse error at byte 4: syntax error while parsing MessagePack number: unexpected end of input",
json::parse_error&);
CHECK_THROWS_WITH_AS(
_ = json::from_msgpack(std::vector<uint8_t>({0xce, 0x00, 0x00, 0x00})),
_ = json::from_msgpack(std::vector<uint8_t>({ 0xce, 0x00, 0x00, 0x00 })),
"[json.exception.parse_error.110] parse error at byte 5: syntax error while parsing MessagePack number: unexpected end of input",
json::parse_error&);
CHECK_THROWS_WITH_AS(
_ = json::from_msgpack(std::vector<uint8_t>({0xcf})),
_ = json::from_msgpack(std::vector<uint8_t>({ 0xcf })),
"[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing MessagePack number: unexpected end of input",
json::parse_error&);
CHECK_THROWS_WITH_AS(
_ = json::from_msgpack(std::vector<uint8_t>({0xcf, 0x00})),
_ = json::from_msgpack(std::vector<uint8_t>({ 0xcf, 0x00 })),
"[json.exception.parse_error.110] parse error at byte 3: syntax error while parsing MessagePack number: unexpected end of input",
json::parse_error&);
CHECK_THROWS_WITH_AS(
_ = json::from_msgpack(std::vector<uint8_t>({0xcf, 0x00, 0x00})),
_ = json::from_msgpack(std::vector<uint8_t>({ 0xcf, 0x00, 0x00 })),
"[json.exception.parse_error.110] parse error at byte 4: syntax error while parsing MessagePack number: unexpected end of input",
json::parse_error&);
CHECK_THROWS_WITH_AS(
_ = json::from_msgpack(std::vector<uint8_t>({0xcf, 0x00, 0x00, 0x00})),
_ = json::from_msgpack(std::vector<uint8_t>({ 0xcf, 0x00, 0x00, 0x00 })),
"[json.exception.parse_error.110] parse error at byte 5: syntax error while parsing MessagePack number: unexpected end of input",
json::parse_error&);
CHECK_THROWS_WITH_AS(
_ = json::from_msgpack(std::vector<uint8_t>({0xcf, 0x00, 0x00, 0x00, 0x00})),
_ = json::from_msgpack(std::vector<uint8_t>({ 0xcf, 0x00, 0x00, 0x00, 0x00 })),
"[json.exception.parse_error.110] parse error at byte 6: syntax error while parsing MessagePack number: unexpected end of input",
json::parse_error&);
CHECK_THROWS_WITH_AS(
_ = json::from_msgpack(std::vector<uint8_t>({0xcf, 0x00, 0x00, 0x00, 0x00, 0x00})),
_ = json::from_msgpack(std::vector<uint8_t>({ 0xcf, 0x00, 0x00, 0x00, 0x00, 0x00 })),
"[json.exception.parse_error.110] parse error at byte 7: syntax error while parsing MessagePack number: unexpected end of input",
json::parse_error&);
CHECK_THROWS_WITH_AS(
_ = json::from_msgpack(std::vector<uint8_t>({0xcf, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00})),
_ = json::from_msgpack(std::vector<uint8_t>({ 0xcf, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 })),
"[json.exception.parse_error.110] parse error at byte 8: syntax error while parsing MessagePack number: unexpected end of input",
json::parse_error&);
CHECK_THROWS_WITH_AS(
_ = json::from_msgpack(std::vector<uint8_t>({0xcf, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00})),
_ = json::from_msgpack(std::vector<uint8_t>({ 0xcf, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 })),
"[json.exception.parse_error.110] parse error at byte 9: syntax error while parsing MessagePack number: unexpected end of input",
json::parse_error&);
CHECK_THROWS_WITH_AS(
_ = json::from_msgpack(std::vector<uint8_t>({0xa5, 0x68, 0x65})),
_ = json::from_msgpack(std::vector<uint8_t>({ 0xa5, 0x68, 0x65 })),
"[json.exception.parse_error.110] parse error at byte 4: syntax error while parsing MessagePack string: unexpected end of input",
json::parse_error&);
CHECK_THROWS_WITH_AS(
_ = json::from_msgpack(std::vector<uint8_t>({0x92, 0x01})),
_ = json::from_msgpack(std::vector<uint8_t>({ 0x92, 0x01 })),
"[json.exception.parse_error.110] parse error at byte 3: syntax error while parsing MessagePack value: unexpected end of input",
json::parse_error&);
CHECK_THROWS_WITH_AS(
_ = json::from_msgpack(std::vector<uint8_t>({0x81, 0xa1, 0x61})),
_ = json::from_msgpack(std::vector<uint8_t>({ 0x81, 0xa1, 0x61 })),
"[json.exception.parse_error.110] parse error at byte 4: syntax error while parsing MessagePack value: unexpected end of input",
json::parse_error&);
CHECK_THROWS_WITH_AS(
_ = json::from_msgpack(std::vector<uint8_t>({0xc4, 0x02})),
_ = json::from_msgpack(std::vector<uint8_t>({ 0xc4, 0x02 })),
"[json.exception.parse_error.110] parse error at byte 3: syntax error while parsing MessagePack binary: unexpected end of input",
json::parse_error&);
CHECK(json::from_msgpack(std::vector<uint8_t>({0x87}), true, false).is_discarded());
CHECK(json::from_msgpack(std::vector<uint8_t>({0xcc}), true, false).is_discarded());
CHECK(json::from_msgpack(std::vector<uint8_t>({0xcd}), true, false).is_discarded());
CHECK(json::from_msgpack(std::vector<uint8_t>({0xcd, 0x00}), true, false).is_discarded());
CHECK(json::from_msgpack(std::vector<uint8_t>({0xce}), true, false).is_discarded());
CHECK(json::from_msgpack(std::vector<uint8_t>({0xce, 0x00}), true, false).is_discarded());
CHECK(json::from_msgpack(std::vector<uint8_t>({0xce, 0x00, 0x00}), true, false).is_discarded());
CHECK(json::from_msgpack(std::vector<uint8_t>({0xce, 0x00, 0x00, 0x00}), true, false).is_discarded());
CHECK(json::from_msgpack(std::vector<uint8_t>({0xcf}), true, false).is_discarded());
CHECK(json::from_msgpack(std::vector<uint8_t>({0xcf, 0x00}), true, false).is_discarded());
CHECK(json::from_msgpack(std::vector<uint8_t>({0xcf, 0x00, 0x00}), true, false).is_discarded());
CHECK(json::from_msgpack(std::vector<uint8_t>({0xcf, 0x00, 0x00, 0x00}), true, false).is_discarded());
CHECK(json::from_msgpack(std::vector<uint8_t>({0xcf, 0x00, 0x00, 0x00, 0x00}), true, false).is_discarded());
CHECK(json::from_msgpack(std::vector<uint8_t>({0xcf, 0x00, 0x00, 0x00, 0x00, 0x00}), true, false).is_discarded());
CHECK(json::from_msgpack(std::vector<uint8_t>({0xcf, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}), true, false).is_discarded());
CHECK(json::from_msgpack(std::vector<uint8_t>({0xcf, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}), true, false).is_discarded());
CHECK(json::from_msgpack(std::vector<uint8_t>({0xa5, 0x68, 0x65}), true, false).is_discarded());
CHECK(json::from_msgpack(std::vector<uint8_t>({0x92, 0x01}), true, false).is_discarded());
CHECK(json::from_msgpack(std::vector<uint8_t>({0x81, 0xA1, 0x61}), true, false).is_discarded());
CHECK(json::from_msgpack(std::vector<uint8_t>({0xc4, 0x02}), true, false).is_discarded());
CHECK(json::from_msgpack(std::vector<uint8_t>({0xc4}), true, false).is_discarded());
CHECK(json::from_msgpack(std::vector<uint8_t>({ 0x87 }), true, false).is_discarded());
CHECK(json::from_msgpack(std::vector<uint8_t>({ 0xcc }), true, false).is_discarded());
CHECK(json::from_msgpack(std::vector<uint8_t>({ 0xcd }), true, false).is_discarded());
CHECK(json::from_msgpack(std::vector<uint8_t>({ 0xcd, 0x00 }), true, false).is_discarded());
CHECK(json::from_msgpack(std::vector<uint8_t>({ 0xce }), true, false).is_discarded());
CHECK(json::from_msgpack(std::vector<uint8_t>({ 0xce, 0x00 }), true, false).is_discarded());
CHECK(json::from_msgpack(std::vector<uint8_t>({ 0xce, 0x00, 0x00 }), true, false).is_discarded());
CHECK(json::from_msgpack(std::vector<uint8_t>({ 0xce, 0x00, 0x00, 0x00 }), true, false).is_discarded());
CHECK(json::from_msgpack(std::vector<uint8_t>({ 0xcf }), true, false).is_discarded());
CHECK(json::from_msgpack(std::vector<uint8_t>({ 0xcf, 0x00 }), true, false).is_discarded());
CHECK(json::from_msgpack(std::vector<uint8_t>({ 0xcf, 0x00, 0x00 }), true, false).is_discarded());
CHECK(json::from_msgpack(std::vector<uint8_t>({ 0xcf, 0x00, 0x00, 0x00 }), true, false).is_discarded());
CHECK(json::from_msgpack(std::vector<uint8_t>({ 0xcf, 0x00, 0x00, 0x00, 0x00 }), true, false).is_discarded());
CHECK(json::from_msgpack(std::vector<uint8_t>({ 0xcf, 0x00, 0x00, 0x00, 0x00, 0x00 }), true, false).is_discarded());
CHECK(json::from_msgpack(std::vector<uint8_t>({ 0xcf, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }), true, false).is_discarded());
CHECK(json::from_msgpack(std::vector<uint8_t>({ 0xcf, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }), true, false).is_discarded());
CHECK(json::from_msgpack(std::vector<uint8_t>({ 0xa5, 0x68, 0x65 }), true, false).is_discarded());
CHECK(json::from_msgpack(std::vector<uint8_t>({ 0x92, 0x01 }), true, false).is_discarded());
CHECK(json::from_msgpack(std::vector<uint8_t>({ 0x81, 0xA1, 0x61 }), true, false).is_discarded());
CHECK(json::from_msgpack(std::vector<uint8_t>({ 0xc4, 0x02 }), true, false).is_discarded());
CHECK(json::from_msgpack(std::vector<uint8_t>({ 0xc4 }), true, false).is_discarded());
}
SECTION("unsupported bytes")
@ -1477,19 +1473,19 @@ TEST_CASE("MessagePack")
SECTION("concrete examples")
{
json _;
CHECK_THROWS_WITH_AS(_ = json::from_msgpack(std::vector<uint8_t>({0xc1})),
CHECK_THROWS_WITH_AS(_ = json::from_msgpack(std::vector<uint8_t>({ 0xc1 })),
"[json.exception.parse_error.112] parse error at byte 1: syntax error while parsing MessagePack value: invalid byte: 0xC1",
json::parse_error&);
}
SECTION("all unsupported bytes")
{
for (auto byte : {// never used
0xc1})
for (auto byte : { // never used
0xc1 })
{
json _;
CHECK_THROWS_AS(_ = json::from_msgpack(std::vector<uint8_t>({static_cast<uint8_t>(byte)})), json::parse_error&);
CHECK(json::from_msgpack(std::vector<uint8_t>({static_cast<uint8_t>(byte)}), true, false).is_discarded());
CHECK_THROWS_AS(_ = json::from_msgpack(std::vector<uint8_t>({ static_cast<uint8_t>(byte) })), json::parse_error&);
CHECK(json::from_msgpack(std::vector<uint8_t>({ static_cast<uint8_t>(byte) }), true, false).is_discarded());
}
}
}
@ -1498,15 +1494,15 @@ TEST_CASE("MessagePack")
{
json _;
CHECK_THROWS_WITH_AS(
_ = json::from_msgpack(std::vector<uint8_t>({0x81, 0xff, 0x01})),
_ = json::from_msgpack(std::vector<uint8_t>({ 0x81, 0xff, 0x01 })),
"[json.exception.parse_error.113] parse error at byte 2: syntax error while parsing MessagePack string: expected length specification (0xA0-0xBF, 0xD9-0xDB); last byte: 0xFF",
json::parse_error&);
CHECK(json::from_msgpack(std::vector<uint8_t>({0x81, 0xff, 0x01}), true, false).is_discarded());
CHECK(json::from_msgpack(std::vector<uint8_t>({ 0x81, 0xff, 0x01 }), true, false).is_discarded());
}
SECTION("strict mode")
{
std::vector<uint8_t> const vec = {0xc0, 0xc0};
std::vector<uint8_t> const vec = { 0xc0, 0xc0 };
SECTION("non-strict mode")
{
const auto result = json::from_msgpack(vec, false);
@ -1529,21 +1525,21 @@ TEST_CASE("MessagePack")
{
SECTION("start_array(len)")
{
std::vector<uint8_t> const v = {0x93, 0x01, 0x02, 0x03};
std::vector<uint8_t> const v = { 0x93, 0x01, 0x02, 0x03 };
SaxCountdown scp(0);
CHECK(!json::sax_parse(v, &scp, json::input_format_t::msgpack));
}
SECTION("start_object(len)")
{
std::vector<uint8_t> const v = {0x81, 0xa3, 0x66, 0x6F, 0x6F, 0xc2};
std::vector<uint8_t> const v = { 0x81, 0xa3, 0x66, 0x6F, 0x6F, 0xc2 };
SaxCountdown scp(0);
CHECK(!json::sax_parse(v, &scp, json::input_format_t::msgpack));
}
SECTION("key()")
{
std::vector<uint8_t> const v = {0x81, 0xa3, 0x66, 0x6F, 0x6F, 0xc2};
std::vector<uint8_t> const v = { 0x81, 0xa3, 0x66, 0x6F, 0x6F, 0xc2 };
SaxCountdown scp(1);
CHECK(!json::sax_parse(v, &scp, json::input_format_t::msgpack));
}
@ -1615,7 +1611,7 @@ TEST_CASE("MessagePack roundtrips" * doctest::skip())
exclude_packed.insert(TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_simple.json");
exclude_packed.insert(TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_string_unicode.json");
for (std::string filename : {TEST_DATA_DIRECTORY "/json_nlohmann_tests/all_unicode.json",
for (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",
@ -1759,7 +1755,7 @@ TEST_CASE("MessagePack roundtrips" * doctest::skip())
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_structure_string_empty.json",
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_structure_trailing_newline.json",
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_structure_true_in_array.json",
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_structure_whitespace_array.json"})
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_structure_whitespace_array.json" })
{
CAPTURE(filename)
@ -1802,7 +1798,7 @@ TEST_CASE("MessagePack roundtrips" * doctest::skip())
// parse MessagePack file
auto packed = utils::read_binary_file(filename + ".msgpack");
json j2;
CHECK_NOTHROW(j2 = json::from_msgpack({packed.data(), packed.size()}));
CHECK_NOTHROW(j2 = json::from_msgpack({ packed.data(), packed.size() }));
// compare parsed JSON values
CHECK(j1 == j2);

View File

@ -48,7 +48,7 @@ TEST_CASE("check_for_mem_leak_on_adl_to_json-1")
{
try
{
const nlohmann::json j = Foo{1, 0};
const nlohmann::json j = Foo{ 1, 0 };
std::cout << j.dump() << "\n";
}
catch (...) // NOLINT(bugprone-empty-catch)
@ -61,7 +61,7 @@ TEST_CASE("check_for_mem_leak_on_adl_to_json-2")
{
try
{
const nlohmann::json j = Foo{1, 1};
const nlohmann::json j = Foo{ 1, 1 };
std::cout << j.dump() << "\n";
}
catch (...) // NOLINT(bugprone-empty-catch)
@ -74,7 +74,7 @@ TEST_CASE("check_for_mem_leak_on_adl_to_json-2")
{
try
{
const nlohmann::json j = Foo{1, 2};
const nlohmann::json j = Foo{ 1, 2 };
std::cout << j.dump() << "\n";
}
catch (...) // NOLINT(bugprone-empty-catch)

View File

@ -45,11 +45,11 @@ TEST_CASE("ordered_json")
CHECK(oj.dump() == "{\"element3\":3,\"element2\":2}");
// There are no dup keys cause constructor calls emplace...
json const multi{{"z", 1}, {"m", 2}, {"m", 3}, {"y", 4}, {"m", 5}};
json const multi{ { "z", 1 }, { "m", 2 }, { "m", 3 }, { "y", 4 }, { "m", 5 } };
CHECK(multi.size() == 3);
CHECK(multi.dump() == "{\"m\":2,\"y\":4,\"z\":1}");
ordered_json multi_ordered{{"z", 1}, {"m", 2}, {"m", 3}, {"y", 4}, {"m", 5}};
ordered_json multi_ordered{ { "z", 1 }, { "m", 2 }, { "m", 3 }, { "y", 4 }, { "m", 5 } };
CHECK(multi_ordered.size() == 3);
CHECK(multi_ordered.dump() == "{\"z\":1,\"m\":2,\"y\":4}");
CHECK(multi_ordered.erase("m") == 1);
@ -57,14 +57,14 @@ TEST_CASE("ordered_json")
// Ranged insert test.
// It seems that values shouldn't be overwritten. Only new values are added
json j1{{"c", 1}, {"b", 2}, {"a", 3}};
const json j2{{"c", 77}, {"d", 42}, {"a", 4}};
json j1{ { "c", 1 }, { "b", 2 }, { "a", 3 } };
const json j2{ { "c", 77 }, { "d", 42 }, { "a", 4 } };
j1.insert(j2.cbegin(), j2.cend());
CHECK(j1.size() == 4);
CHECK(j1.dump() == "{\"a\":3,\"b\":2,\"c\":1,\"d\":42}");
ordered_json oj1{{"c", 1}, {"b", 2}, {"a", 3}};
const ordered_json oj2{{"c", 77}, {"d", 42}, {"a", 4}};
ordered_json oj1{ { "c", 1 }, { "b", 2 }, { "a", 3 } };
const ordered_json oj2{ { "c", 77 }, { "d", 42 }, { "a", 4 } };
oj1.insert(oj2.cbegin(), oj2.cend());
CHECK(oj1.size() == 4);
CHECK(oj1.dump() == "{\"c\":1,\"b\":2,\"a\":3,\"d\":42}");

View File

@ -17,14 +17,14 @@ TEST_CASE("ordered_map")
{
SECTION("constructor from iterator range")
{
std::map<std::string, std::string> m{{"eins", "one"}, {"zwei", "two"}, {"drei", "three"}};
std::map<std::string, std::string> m{ { "eins", "one" }, { "zwei", "two" }, { "drei", "three" } };
ordered_map<std::string, std::string> const om(m.begin(), m.end());
CHECK(om.size() == 3);
}
SECTION("copy assignment")
{
std::map<std::string, std::string> m{{"eins", "one"}, {"zwei", "two"}, {"drei", "three"}};
std::map<std::string, std::string> m{ { "eins", "one" }, { "zwei", "two" }, { "drei", "three" } };
ordered_map<std::string, std::string> om(m.begin(), m.end());
const auto com = om;
om.clear(); // silence a warning by forbidding having "const auto& com = om;"
@ -34,7 +34,7 @@ TEST_CASE("ordered_map")
SECTION("at")
{
std::map<std::string, std::string> m{{"eins", "one"}, {"zwei", "two"}, {"drei", "three"}};
std::map<std::string, std::string> m{ { "eins", "one" }, { "zwei", "two" }, { "drei", "three" } };
ordered_map<std::string, std::string> om(m.begin(), m.end());
const auto com = om;
@ -67,7 +67,7 @@ TEST_CASE("ordered_map")
SECTION("operator[]")
{
std::map<std::string, std::string> m{{"eins", "one"}, {"zwei", "two"}, {"drei", "three"}};
std::map<std::string, std::string> m{ { "eins", "one" }, { "zwei", "two" }, { "drei", "three" } };
ordered_map<std::string, std::string> om(m.begin(), m.end());
const auto com = om;
@ -280,8 +280,8 @@ TEST_CASE("ordered_map")
SECTION("const value_type&")
{
ordered_map<std::string, std::string>::value_type const vt1{"eins", "1"};
ordered_map<std::string, std::string>::value_type const vt4{"vier", "four"};
ordered_map<std::string, std::string>::value_type const vt1{ "eins", "1" };
ordered_map<std::string, std::string>::value_type const vt4{ "vier", "four" };
auto res1 = om.insert(vt1);
CHECK(res1.first == om.begin());
@ -296,12 +296,12 @@ TEST_CASE("ordered_map")
SECTION("value_type&&")
{
auto res1 = om.insert({"eins", "1"});
auto res1 = om.insert({ "eins", "1" });
CHECK(res1.first == om.begin());
CHECK(res1.second == false);
CHECK(om.size() == 3);
auto res4 = om.insert({"vier", "four"});
auto res4 = om.insert({ "vier", "four" });
CHECK(res4.first == om.begin() + 3);
CHECK(res4.second == true);
CHECK(om.size() == 4);

View File

@ -16,7 +16,7 @@ TEST_CASE("pointer access")
SECTION("pointer access to object_t")
{
using test_type = json::object_t;
json value = {{"one", 1}, {"two", 2}};
json value = { { "one", 1 }, { "two", 2 } };
// check if pointers are returned correctly
test_type* p1 = value.get_ptr<test_type*>();
@ -45,7 +45,7 @@ TEST_CASE("pointer access")
SECTION("pointer access to const object_t")
{
using test_type = const json::object_t;
const json value = {{"one", 1}, {"two", 2}};
const json value = { { "one", 1 }, { "two", 2 } };
// check if pointers are returned correctly
test_type* p1 = value.get_ptr<test_type*>();
@ -74,7 +74,7 @@ TEST_CASE("pointer access")
SECTION("pointer access to array_t")
{
using test_type = json::array_t;
json value = {1, 2, 3, 4};
json value = { 1, 2, 3, 4 };
// check if pointers are returned correctly
test_type* p1 = value.get_ptr<test_type*>();
@ -103,7 +103,7 @@ TEST_CASE("pointer access")
SECTION("pointer access to const array_t")
{
using test_type = const json::array_t;
const json value = {1, 2, 3, 4};
const json value = { 1, 2, 3, 4 };
// check if pointers are returned correctly
test_type* p1 = value.get_ptr<test_type*>();
@ -422,7 +422,7 @@ TEST_CASE("pointer access")
SECTION("pointer access to const binary_t")
{
using test_type = const json::binary_t;
const json value = json::binary({1, 2, 3});
const json value = json::binary({ 1, 2, 3 });
// check if pointers are returned correctly
test_type* p1 = value.get_ptr<test_type*>();

View File

@ -55,24 +55,24 @@ TEST_CASE("README" * doctest::skip())
j["answer"]["everything"] = 42;
// add an array that is stored as std::vector (using an initializer list)
j["list"] = {1, 0, 2};
j["list"] = { 1, 0, 2 };
// add another object (using an initializer list of pairs)
j["object"] = {{"currency", "USD"}, {"value", 42.99}};
j["object"] = { { "currency", "USD" }, { "value", 42.99 } };
// instead, you could also write (which looks very similar to the JSON above)
json const j2 = {{"pi", 3.141},
{"happy", true},
{"name", "Niels"},
{"nothing", nullptr},
{"answer", {{"everything", 42}}},
{"list", {1, 0, 2}},
{"object", {{"currency", "USD"}, {"value", 42.99}}}};
json const j2 = { { "pi", 3.141 },
{ "happy", true },
{ "name", "Niels" },
{ "nothing", nullptr },
{ "answer", { { "everything", 42 } } },
{ "list", { 1, 0, 2 } },
{ "object", { { "currency", "USD" }, { "value", 42.99 } } } };
}
{
// ways to express the empty array []
json const empty_array_implicit = {{}};
json const empty_array_implicit = { {} };
CHECK(empty_array_implicit.is_array());
json const empty_array_explicit = json::array();
CHECK(empty_array_explicit.is_array());
@ -82,7 +82,7 @@ TEST_CASE("README" * doctest::skip())
CHECK(empty_object_explicit.is_object());
// a way to express an _array_ of key/value pairs [["currency", "USD"], ["value", 42.99]]
json array_not_object = json::array({{"currency", "USD"}, {"value", 42.99}});
json array_not_object = json::array({ { "currency", "USD" }, { "value", 42.99 } });
CHECK(array_not_object.is_array());
CHECK(array_not_object.size() == 2);
CHECK(array_not_object[0].is_array());
@ -142,7 +142,7 @@ TEST_CASE("README" * doctest::skip())
// getter/setter
const auto tmp = j[0].get<std::string>();
j[1] = 42;
bool foo{j.at(2)};
bool foo{ j.at(2) };
CHECK(foo == true);
// other stuff
@ -166,57 +166,57 @@ TEST_CASE("README" * doctest::skip())
}
{
std::vector<int> const c_vector{1, 2, 3, 4};
std::vector<int> const c_vector{ 1, 2, 3, 4 };
json const j_vec(c_vector);
// [1, 2, 3, 4]
std::deque<float> const c_deque{1.2f, 2.3f, 3.4f, 5.6f};
std::deque<float> const c_deque{ 1.2f, 2.3f, 3.4f, 5.6f };
json const j_deque(c_deque);
// [1.2, 2.3, 3.4, 5.6]
std::list<bool> const c_list{true, true, false, true};
std::list<bool> const c_list{ true, true, false, true };
json const j_list(c_list);
// [true, true, false, true]
std::forward_list<int64_t> const c_flist{12345678909876, 23456789098765, 34567890987654, 45678909876543};
std::forward_list<int64_t> const c_flist{ 12345678909876, 23456789098765, 34567890987654, 45678909876543 };
json const j_flist(c_flist);
// [12345678909876, 23456789098765, 34567890987654, 45678909876543]
std::array<unsigned long, 4> const c_array{{1, 2, 3, 4}};
std::array<unsigned long, 4> const c_array{ { 1, 2, 3, 4 } };
json const j_array(c_array);
// [1, 2, 3, 4]
std::set<std::string> const c_set{"one", "two", "three", "four", "one"};
std::set<std::string> const c_set{ "one", "two", "three", "four", "one" };
json const j_set(c_set); // only one entry for "one" is used
// ["four", "one", "three", "two"]
std::unordered_set<std::string> const c_uset{"one", "two", "three", "four", "one"};
std::unordered_set<std::string> const c_uset{ "one", "two", "three", "four", "one" };
json const j_uset(c_uset); // only one entry for "one" is used
// maybe ["two", "three", "four", "one"]
std::multiset<std::string> const c_mset{"one", "two", "one", "four"};
std::multiset<std::string> const c_mset{ "one", "two", "one", "four" };
json const j_mset(c_mset); // both entries for "one" are used
// maybe ["one", "two", "one", "four"]
std::unordered_multiset<std::string> const c_umset{"one", "two", "one", "four"};
std::unordered_multiset<std::string> const c_umset{ "one", "two", "one", "four" };
json const j_umset(c_umset); // both entries for "one" are used
// maybe ["one", "two", "one", "four"]
}
{
std::map<std::string, int> const c_map{{"one", 1}, {"two", 2}, {"three", 3}};
std::map<std::string, int> const c_map{ { "one", 1 }, { "two", 2 }, { "three", 3 } };
json const j_map(c_map);
// {"one": 1, "two": 2, "three": 3}
std::unordered_map<const char*, float> const c_umap{{"one", 1.2f}, {"two", 2.3f}, {"three", 3.4f}};
std::unordered_map<const char*, float> const c_umap{ { "one", 1.2f }, { "two", 2.3f }, { "three", 3.4f } };
json const j_umap(c_umap);
// {"one": 1.2, "two": 2.3, "three": 3.4}
std::multimap<std::string, bool> const c_mmap{{"one", true}, {"two", true}, {"three", false}, {"three", true}};
std::multimap<std::string, bool> const c_mmap{ { "one", true }, { "two", true }, { "three", false }, { "three", true } };
json const j_mmap(c_mmap); // only one entry for key "three" is used
// maybe {"one": true, "two": true, "three": true}
std::unordered_multimap<std::string, bool> const c_ummap{{"one", true}, {"two", true}, {"three", false}, {"three", true}};
std::unordered_multimap<std::string, bool> const c_ummap{ { "one", true }, { "two", true }, { "three", false }, { "three", true } };
json const j_ummap(c_ummap); // only one entry for key "three" is used
// maybe {"one": true, "two": true, "three": true}
}
@ -230,13 +230,13 @@ TEST_CASE("README" * doctest::skip())
// Booleans
bool const b1 = true;
json const jb = b1;
bool b2{jb};
bool b2{ jb };
CHECK(b2 == true);
// numbers
int const i = 42;
json const jn = i;
double f{jn};
double f{ jn };
CHECK(f == 42);
// etc.

View File

@ -14,16 +14,16 @@ using nlohmann::json;
TEST_CASE("reference access")
{
// create a JSON value with different types
const json json_types = {{"boolean", true},
{"number", {{"integer", 42}, {"floating-point", 17.23}}},
{"string", "Hello, world!"},
{"array", {1, 2, 3, 4, 5}},
{"null", nullptr}};
const json json_types = { { "boolean", true },
{ "number", { { "integer", 42 }, { "floating-point", 17.23 } } },
{ "string", "Hello, world!" },
{ "array", { 1, 2, 3, 4, 5 } },
{ "null", nullptr } };
SECTION("reference access to object_t")
{
using test_type = json::object_t;
json value = {{"one", 1}, {"two", 2}};
json value = { { "one", 1 }, { "two", 2 } };
// check if references are returned correctly
auto& p1 = value.get_ref<test_type&>();
@ -59,7 +59,7 @@ TEST_CASE("reference access")
SECTION("const reference access to const object_t")
{
using test_type = json::object_t;
const json value = {{"one", 1}, {"two", 2}};
const json value = { { "one", 1 }, { "two", 2 } };
// this should not compile
// test_type& p1 = value.get_ref<test_type&>();
@ -73,7 +73,7 @@ TEST_CASE("reference access")
SECTION("reference access to array_t")
{
using test_type = json::array_t;
json value = {1, 2, 3, 4};
json value = { 1, 2, 3, 4 };
// check if references are returned correctly
auto& p1 = value.get_ref<test_type&>();

View File

@ -59,7 +59,7 @@ struct foo_serializer<T, typename std::enable_if<std::is_same<foo, T>::value>::t
template<typename BasicJsonType>
static void to_json(BasicJsonType& j, const T& value)
{
j = BasicJsonType{{"x", value.x}};
j = BasicJsonType{ { "x", value.x } };
}
template<typename BasicJsonType>
static void from_json(const BasicJsonType& j, T& value) // !!!
@ -105,7 +105,7 @@ struct nocopy // NOLINT(cppcoreguidelines-special-member-functions,hicpp-specia
friend void to_json(json& j, const nocopy& n)
{
j = {{"val", n.val}};
j = { { "val", n.val } };
}
};
} // namespace
@ -146,12 +146,12 @@ TEST_CASE("regression tests 1")
{
json const j1 = NAN;
CHECK(j1.is_number_float());
json::number_float_t const f1{j1};
json::number_float_t const f1{ j1 };
CHECK(std::isnan(f1));
json const j2 = static_cast<json::number_float_t>(NAN);
CHECK(j2.is_number_float());
json::number_float_t const f2{j2};
json::number_float_t const f2{ j2 };
CHECK(std::isnan(f2));
}
@ -159,12 +159,12 @@ TEST_CASE("regression tests 1")
{
json const j1 = INFINITY;
CHECK(j1.is_number_float());
json::number_float_t const f1{j1};
json::number_float_t const f1{ j1 };
CHECK(!std::isfinite(f1));
json const j2 = static_cast<json::number_float_t>(INFINITY);
CHECK(j2.is_number_float());
json::number_float_t const f2{j2};
json::number_float_t const f2{ j2 };
CHECK(!std::isfinite(f2));
}
}
@ -190,7 +190,7 @@ TEST_CASE("regression tests 1")
static_assert(std::is_same<decltype(anon_enum_value), decltype(u)>::value, "types must be the same");
j.push_back(json::object({{"game_type", t}}));
j.push_back(json::object({ { "game_type", t } }));
}
SECTION("issue #76 - dump() / parse() not idempotent")
@ -241,9 +241,9 @@ TEST_CASE("regression tests 1")
auto test = j["Test"].get<std::string>();
CHECK(test == "Test1");
int number{j["Number"]};
int number{ j["Number"] };
CHECK(number == 100);
float foo{j["Foo"]};
float foo{ j["Foo"] };
CHECK(static_cast<double>(foo) == Approx(42.42));
}
@ -281,41 +281,41 @@ TEST_CASE("regression tests 1")
SECTION("issue #93 reverse_iterator operator inheritance problem")
{
{
json a = {1, 2, 3};
json a = { 1, 2, 3 };
json::reverse_iterator rit = a.rbegin();
++rit;
CHECK(*rit == json(2));
CHECK(rit.value() == json(2));
}
{
json a = {1, 2, 3};
json a = { 1, 2, 3 };
json::reverse_iterator const rit = ++a.rbegin();
CHECK(*rit == json(2));
CHECK(rit.value() == json(2));
}
{
json a = {1, 2, 3};
json a = { 1, 2, 3 };
json::reverse_iterator rit = a.rbegin();
++rit;
json b = {0, 0, 0};
json b = { 0, 0, 0 };
std::transform(rit, a.rend(), b.rbegin(), [](json el) {
return el;
});
CHECK(b == json({0, 1, 2}));
CHECK(b == json({ 0, 1, 2 }));
}
{
json a = {1, 2, 3};
json b = {0, 0, 0};
json a = { 1, 2, 3 };
json b = { 0, 0, 0 };
std::transform(++a.rbegin(), a.rend(), b.rbegin(), [](json el) {
return el;
});
CHECK(b == json({0, 1, 2}));
CHECK(b == json({ 0, 1, 2 }));
}
}
SECTION("issue #100 - failed to iterator json object with reverse_iterator")
{
json config = {{"111", 111}, {"112", 112}, {"113", 113}};
json config = { { "111", 111 }, { "112", 112 }, { "113", 113 } };
std::stringstream ss;
@ -335,9 +335,9 @@ TEST_CASE("regression tests 1")
SECTION("issue #101 - binary string causes numbers to be dumped as hex")
{
int64_t const number = 10;
std::string const bytes{"\x00"
std::string const bytes{ "\x00"
"asdf\n",
6};
6 };
json j;
j["int64"] = number;
j["binary string"] = bytes;
@ -348,7 +348,7 @@ TEST_CASE("regression tests 1")
SECTION("issue #111 - subsequent unicode chars")
{
std::string const bytes{0x7, 0x7};
std::string const bytes{ 0x7, 0x7 };
json j;
j["string"] = bytes;
CHECK(j["string"] == "\u0007\u0007");
@ -357,7 +357,7 @@ TEST_CASE("regression tests 1")
#if JSON_USE_IMPLICIT_CONVERSIONS
SECTION("issue #144 - implicit assignment to std::string fails")
{
json o = {{"name", "value"}};
json o = { { "name", "value" } };
std::string s1 = o["name"];
CHECK(s1 == "value");
@ -558,8 +558,8 @@ TEST_CASE("regression tests 1")
SECTION("issue #233 - Can't use basic_json::iterator as a base iterator for std::move_iterator")
{
json source = {"a", "b", "c"};
json expected = {"a", "b"};
json source = { "a", "b", "c" };
json expected = { "a", "b" };
json dest;
std::copy_n(std::make_move_iterator(source.begin()), 2, std::back_inserter(dest));
@ -569,11 +569,11 @@ TEST_CASE("regression tests 1")
SECTION("issue #235 - ambiguous overload for 'push_back' and 'operator+='")
{
json data = {{"key", "value"}};
data.push_back({"key2", "value2"});
data += {"key3", "value3"};
json data = { { "key", "value" } };
data.push_back({ "key2", "value2" });
data += { "key3", "value3" };
CHECK(data == json({{"key", "value"}, {"key2", "value2"}, {"key3", "value3"}}));
CHECK(data == json({ { "key", "value" }, { "key2", "value2" }, { "key3", "value3" } }));
}
SECTION("issue #269 - diff generates incorrect patch when removing multiple array elements")
@ -588,10 +588,10 @@ TEST_CASE("regression tests 1")
SECTION("issue #283 - value() does not work with _json_pointer types")
{
json j = {
{"object", {{"key1", 1}, {"key2", 2}}},
{ "object", { { "key1", 1 }, { "key2", 2 } } },
};
int at_integer{j.at("/object/key2"_json_pointer)};
int at_integer{ j.at("/object/key2"_json_pointer) };
int val_integer = j.value("/object/key2"_json_pointer, 0);
CHECK(at_integer == val_integer);
@ -608,7 +608,7 @@ TEST_CASE("regression tests 1")
SECTION("issue #306 - Parsing fails without space at end of file")
{
for (const auto* filename : {TEST_DATA_DIRECTORY "/regression/broken_file.json", TEST_DATA_DIRECTORY "/regression/working_file.json"})
for (const auto* filename : { TEST_DATA_DIRECTORY "/regression/broken_file.json", TEST_DATA_DIRECTORY "/regression/working_file.json" })
{
CAPTURE(filename)
json j;
@ -619,10 +619,10 @@ TEST_CASE("regression tests 1")
SECTION("issue #310 - make json_benchmarks no longer working in 2.0.4")
{
for (const auto* filename : {TEST_DATA_DIRECTORY "/regression/floats.json",
for (const auto* filename : { TEST_DATA_DIRECTORY "/regression/floats.json",
TEST_DATA_DIRECTORY "/regression/signed_ints.json",
TEST_DATA_DIRECTORY "/regression/unsigned_ints.json",
TEST_DATA_DIRECTORY "/regression/small_signed_ints.json"})
TEST_DATA_DIRECTORY "/regression/small_signed_ints.json" })
{
CAPTURE(filename)
json j;
@ -635,7 +635,7 @@ TEST_CASE("regression tests 1")
{
json j;
j["/this/that/2"_json_pointer] = 27;
CHECK(j == json({{"this", {{"that", {nullptr, nullptr, 27}}}}}));
CHECK(j == json({ { "this", { { "that", { nullptr, nullptr, 27 } } } } }));
}
SECTION("issue #329 - serialized value not always can be parsed")
@ -837,9 +837,9 @@ TEST_CASE("regression tests 1")
ss << "{\n \"one\" : 1,\n \"two\" : 2\n}\n{\n \"three\" : 3\n}";
json j;
CHECK_NOTHROW(ss >> j);
CHECK(j == json({{"one", 1}, {"two", 2}}));
CHECK(j == json({ { "one", 1 }, { "two", 2 } }));
CHECK_NOTHROW(ss >> j);
CHECK(j == json({{"three", 3}}));
CHECK(j == json({ { "three", 3 } }));
CHECK_THROWS_WITH_AS(
ss >> j,
@ -869,12 +869,12 @@ TEST_CASE("regression tests 1")
if (i == 0)
{
CHECK(val == json({{"one", 1}, {"two", 2}}));
CHECK(val == json({ { "one", 1 }, { "two", 2 } }));
}
if (i == 1)
{
CHECK(val == json({{"three", 3}}));
CHECK(val == json({ { "three", 3 } }));
}
++i;
@ -911,7 +911,7 @@ TEST_CASE("regression tests 1")
SECTION("issue #405 - Heap-buffer-overflow (OSS-Fuzz issue 342)")
{
// original test case
std::vector<uint8_t> const vec{0x65, 0xf5, 0x0a, 0x48, 0x21};
std::vector<uint8_t> const vec{ 0x65, 0xf5, 0x0a, 0x48, 0x21 };
json _;
CHECK_THROWS_WITH_AS(_ = json::from_cbor(vec),
"[json.exception.parse_error.110] parse error at byte 6: syntax error while parsing CBOR string: unexpected end of input",
@ -923,31 +923,31 @@ TEST_CASE("regression tests 1")
json _;
// original test case: incomplete float64
std::vector<uint8_t> const vec1{0xcb, 0x8f, 0x0a};
std::vector<uint8_t> const vec1{ 0xcb, 0x8f, 0x0a };
CHECK_THROWS_WITH_AS(_ = json::from_msgpack(vec1),
"[json.exception.parse_error.110] parse error at byte 4: syntax error while parsing MessagePack number: unexpected end of input",
json::parse_error&);
// related test case: incomplete float32
std::vector<uint8_t> const vec2{0xca, 0x8f, 0x0a};
std::vector<uint8_t> const vec2{ 0xca, 0x8f, 0x0a };
CHECK_THROWS_WITH_AS(_ = json::from_msgpack(vec2),
"[json.exception.parse_error.110] parse error at byte 4: syntax error while parsing MessagePack number: unexpected end of input",
json::parse_error&);
// related test case: incomplete Half-Precision Float (CBOR)
std::vector<uint8_t> const vec3{0xf9, 0x8f};
std::vector<uint8_t> const vec3{ 0xf9, 0x8f };
CHECK_THROWS_WITH_AS(_ = json::from_cbor(vec3),
"[json.exception.parse_error.110] parse error at byte 3: syntax error while parsing CBOR number: unexpected end of input",
json::parse_error&);
// related test case: incomplete Single-Precision Float (CBOR)
std::vector<uint8_t> const vec4{0xfa, 0x8f, 0x0a};
std::vector<uint8_t> const vec4{ 0xfa, 0x8f, 0x0a };
CHECK_THROWS_WITH_AS(_ = json::from_cbor(vec4),
"[json.exception.parse_error.110] parse error at byte 4: syntax error while parsing CBOR number: unexpected end of input",
json::parse_error&);
// related test case: incomplete Double-Precision Float (CBOR)
std::vector<uint8_t> const vec5{0xfb, 0x8f, 0x0a};
std::vector<uint8_t> const vec5{ 0xfb, 0x8f, 0x0a };
CHECK_THROWS_WITH_AS(_ = json::from_cbor(vec5),
"[json.exception.parse_error.110] parse error at byte 4: syntax error while parsing CBOR number: unexpected end of input",
json::parse_error&);
@ -958,19 +958,19 @@ TEST_CASE("regression tests 1")
json _;
// original test case
std::vector<uint8_t> const vec1{0x87};
std::vector<uint8_t> const vec1{ 0x87 };
CHECK_THROWS_WITH_AS(_ = json::from_msgpack(vec1),
"[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing MessagePack string: unexpected end of input",
json::parse_error&);
// more test cases for MessagePack
for (auto b : {0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e,
for (auto b : { 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e,
0x8f, // fixmap
0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e,
0x9f, // fixarray
0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae,
0xaf, // fixstr
0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf})
0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf })
{
std::vector<uint8_t> const vec(1, static_cast<uint8_t>(b));
CHECK_THROWS_AS(_ = json::from_msgpack(vec), json::parse_error&);
@ -1005,19 +1005,19 @@ TEST_CASE("regression tests 1")
json _;
// original test case: empty UTF-8 string (indefinite length)
std::vector<uint8_t> const vec1{0x7f};
std::vector<uint8_t> const vec1{ 0x7f };
CHECK_THROWS_WITH_AS(_ = json::from_cbor(vec1),
"[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing CBOR string: unexpected end of input",
json::parse_error&);
// related test case: empty array (indefinite length)
std::vector<uint8_t> const vec2{0x9f};
std::vector<uint8_t> const vec2{ 0x9f };
CHECK_THROWS_WITH_AS(_ = json::from_cbor(vec2),
"[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing CBOR value: unexpected end of input",
json::parse_error&);
// related test case: empty map (indefinite length)
std::vector<uint8_t> const vec3{0xbf};
std::vector<uint8_t> const vec3{ 0xbf };
CHECK_THROWS_WITH_AS(_ = json::from_cbor(vec3),
"[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing CBOR string: unexpected end of input",
json::parse_error&);
@ -1026,13 +1026,13 @@ TEST_CASE("regression tests 1")
SECTION("issue #412 - Heap-buffer-overflow (OSS-Fuzz issue 367)")
{
// original test case
std::vector<uint8_t> const vec{0xab, 0x98, 0x98, 0x98, 0x98, 0x98, 0x98, 0x98, 0x98, 0x98, 0x98, 0x98, 0x98, 0x00, 0x00, 0x00, 0x60, 0xab, 0x98, 0x98,
std::vector<uint8_t> const vec{ 0xab, 0x98, 0x98, 0x98, 0x98, 0x98, 0x98, 0x98, 0x98, 0x98, 0x98, 0x98, 0x98, 0x00, 0x00, 0x00, 0x60, 0xab, 0x98, 0x98,
0x98, 0x98, 0x98, 0x98, 0x98, 0x98, 0x98, 0x98, 0x98, 0x00, 0x00, 0x00, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60,
0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60,
0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60,
0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0xa0, 0x9f, 0x9f, 0x97, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60,
0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60,
0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60};
0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60 };
json _;
CHECK_THROWS_WITH_AS(
@ -1041,19 +1041,19 @@ TEST_CASE("regression tests 1")
json::parse_error&);
// related test case: nonempty UTF-8 string (indefinite length)
std::vector<uint8_t> const vec1{0x7f, 0x61, 0x61};
std::vector<uint8_t> const vec1{ 0x7f, 0x61, 0x61 };
CHECK_THROWS_WITH_AS(_ = json::from_cbor(vec1),
"[json.exception.parse_error.110] parse error at byte 4: syntax error while parsing CBOR string: unexpected end of input",
json::parse_error&);
// related test case: nonempty array (indefinite length)
std::vector<uint8_t> const vec2{0x9f, 0x01};
std::vector<uint8_t> const vec2{ 0x9f, 0x01 };
CHECK_THROWS_WITH_AS(_ = json::from_cbor(vec2),
"[json.exception.parse_error.110] parse error at byte 3: syntax error while parsing CBOR value: unexpected end of input",
json::parse_error&);
// related test case: nonempty map (indefinite length)
std::vector<uint8_t> const vec3{0xbf, 0x61, 0x61, 0x01};
std::vector<uint8_t> const vec3{ 0xbf, 0x61, 0x61, 0x01 };
CHECK_THROWS_WITH_AS(_ = json::from_cbor(vec3),
"[json.exception.parse_error.110] parse error at byte 5: syntax error while parsing CBOR string: unexpected end of input",
json::parse_error&);
@ -1080,9 +1080,9 @@ TEST_CASE("regression tests 1")
SECTION("issue #416 - Use-of-uninitialized-value (OSS-Fuzz issue 377)")
{
// original test case
std::vector<uint8_t> const vec1{0x94, 0xfa, 0xfa, 0xfa, 0xfa, 0xfa, 0xfa, 0xfa, 0x3a, 0x96, 0x96, 0xb4, 0xb4, 0xb4, 0xb4, 0xb4,
std::vector<uint8_t> const vec1{ 0x94, 0xfa, 0xfa, 0xfa, 0xfa, 0xfa, 0xfa, 0xfa, 0x3a, 0x96, 0x96, 0xb4, 0xb4, 0xb4, 0xb4, 0xb4,
0xb4, 0xb4, 0xb4, 0xb4, 0xb4, 0xb4, 0xb4, 0x71, 0xb4, 0xb4, 0xfa, 0xfa, 0xfa, 0xfa, 0xfa, 0x3a,
0x96, 0x96, 0xb4, 0xb4, 0xfa, 0x94, 0x94, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61, 0xfa};
0x96, 0x96, 0xb4, 0xb4, 0xfa, 0x94, 0x94, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61, 0xfa };
json _;
CHECK_THROWS_WITH_AS(
@ -1091,9 +1091,9 @@ TEST_CASE("regression tests 1")
json::parse_error&);
// related test case: double-precision
std::vector<uint8_t> const vec2{0x94, 0xfa, 0xfa, 0xfa, 0xfa, 0xfa, 0xfa, 0xfa, 0x3a, 0x96, 0x96, 0xb4, 0xb4, 0xb4, 0xb4, 0xb4,
std::vector<uint8_t> const vec2{ 0x94, 0xfa, 0xfa, 0xfa, 0xfa, 0xfa, 0xfa, 0xfa, 0x3a, 0x96, 0x96, 0xb4, 0xb4, 0xb4, 0xb4, 0xb4,
0xb4, 0xb4, 0xb4, 0xb4, 0xb4, 0xb4, 0xb4, 0x71, 0xb4, 0xb4, 0xfa, 0xfa, 0xfa, 0xfa, 0xfa, 0x3a,
0x96, 0x96, 0xb4, 0xb4, 0xfa, 0x94, 0x94, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61, 0xfb};
0x96, 0x96, 0xb4, 0xb4, 0xfa, 0x94, 0x94, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61, 0xfb };
CHECK_THROWS_WITH_AS(
_ = json::from_cbor(vec2),
"[json.exception.parse_error.113] parse error at byte 13: syntax error while parsing CBOR string: expected length specification (0x60-0x7B) or indefinite string type (0x7F); last byte: 0xB4",
@ -1102,7 +1102,7 @@ TEST_CASE("regression tests 1")
SECTION("issue #452 - Heap-buffer-overflow (OSS-Fuzz issue 585)")
{
std::vector<uint8_t> const vec = {'-', '0', '1', '2', '2', '7', '4'};
std::vector<uint8_t> const vec = { '-', '0', '1', '2', '2', '7', '4' };
json _;
CHECK_THROWS_AS(_ = json::parse(vec), json::parse_error&);
}
@ -1135,7 +1135,7 @@ TEST_CASE("regression tests 1")
#if JSON_USE_IMPLICIT_CONVERSIONS
SECTION("issue #473 - inconsistent behavior in conversion to array type")
{
json const j_array = {1, 2, 3, 4};
json const j_array = { 1, 2, 3, 4 };
json const j_number = 42;
json const j_null = nullptr;
@ -1183,7 +1183,7 @@ TEST_CASE("regression tests 1")
SECTION("issue #494 - conversion from vector<bool> to json fails to build")
{
std::vector<bool> const boolVector = {false, true, false, false};
std::vector<bool> const boolVector = { false, true, false, false };
json j;
j["bool_vector"] = boolVector;
@ -1192,7 +1192,7 @@ TEST_CASE("regression tests 1")
SECTION("issue #504 - assertion error (OSS-Fuzz 856)")
{
std::vector<uint8_t> const vec1 = {0xf9, 0xff, 0xff, 0x4a, 0x3a, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x01, 0x37, 0x02, 0x38};
std::vector<uint8_t> const vec1 = { 0xf9, 0xff, 0xff, 0x4a, 0x3a, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x01, 0x37, 0x02, 0x38 };
json const j1 = json::from_cbor(vec1, false);
// step 2: round trip
@ -1247,7 +1247,7 @@ TEST_CASE("regression tests 1")
SECTION("issue #575 - heap-buffer-overflow (OSS-Fuzz 1400)")
{
json _;
std::vector<uint8_t> const vec = {'"', '\\', '"', 'X', '"', '"'};
std::vector<uint8_t> const vec = { '"', '\\', '"', 'X', '"', '"' };
CHECK_THROWS_AS(_ = json::parse(vec), json::parse_error&);
}
@ -1257,7 +1257,7 @@ TEST_CASE("regression tests 1")
SECTION("example 1")
{
// create a map
std::map<std::string, int> m1{{"key", 1}};
std::map<std::string, int> m1{ { "key", 1 } };
// create and print a JSON from the map
json const j = m1;
@ -1272,7 +1272,7 @@ TEST_CASE("regression tests 1")
SECTION("example 2")
{
// create a map
std::map<std::string, std::string> m1{{"key", "val"}};
std::map<std::string, std::string> m1{ { "key", "val" } };
// create and print a JSON from the map
json const j = m1;
@ -1305,7 +1305,7 @@ TEST_CASE("regression tests 1")
SECTION("full example")
{
std::valarray<double> v = {1.2, 2.3, 3.4, 4.5};
std::valarray<double> v = { 1.2, 2.3, 3.4, 4.5 };
json j = v;
std::valarray<double> vj = j;
@ -1336,10 +1336,10 @@ TEST_CASE("regression tests 1")
auto m1 = j1.get<std::map<std::string, std::string>>();
auto m2 = j2.get<std::map<std::string, std::string>>();
int i3{j3};
int i3{ j3 };
CHECK(m1 == (std::map<std::string, std::string>{{"first", "one"}}));
CHECK(m2 == (std::map<std::string, std::string>{{"second", "two"}}));
CHECK(m1 == (std::map<std::string, std::string>{ { "first", "one" } }));
CHECK(m2 == (std::map<std::string, std::string>{ { "second", "two" } }));
CHECK(i3 == 3);
}
}
@ -1371,14 +1371,14 @@ TEST_CASE("regression tests 1")
{
nocopy n;
json j;
j = {{"nocopy", n}};
j = { { "nocopy", n } };
CHECK(j["nocopy"]["val"] == 0);
}
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&);
@ -1388,7 +1388,7 @@ TEST_CASE("regression tests 1")
SECTION("issue #843 - converting to array not working")
{
json j;
std::array<int, 4> ar = {{1, 1, 1, 1}};
std::array<int, 4> ar = { { 1, 1, 1, 1 } };
j = ar;
ar = j;
}
@ -1418,7 +1418,7 @@ TEST_CASE("regression tests 1")
SECTION("issue #961 - incorrect parsing of indefinite length CBOR strings")
{
std::vector<uint8_t> const v_cbor = {0x7F, 0x64, 'a', 'b', 'c', 'd', 0x63, '1', '2', '3', 0xFF};
std::vector<uint8_t> const v_cbor = { 0x7F, 0x64, 'a', 'b', 'c', 'd', 0x63, '1', '2', '3', 0xFF };
json j = json::from_cbor(v_cbor);
CHECK(j == "abcd123");
}
@ -1426,7 +1426,7 @@ TEST_CASE("regression tests 1")
SECTION("issue #962 - Timeout (OSS-Fuzz 6034)")
{
json _;
std::vector<uint8_t> v_ubjson = {'[', '$', 'Z', '#', 'L', 0x78, 0x28, 0x00, 0x68, 0x28, 0x69, 0x69, 0x17};
std::vector<uint8_t> v_ubjson = { '[', '$', 'Z', '#', 'L', 0x78, 0x28, 0x00, 0x68, 0x28, 0x69, 0x69, 0x17 };
CHECK_THROWS_AS(_ = json::from_ubjson(v_ubjson), json::out_of_range&);
//CHECK_THROWS_WITH(json::from_ubjson(v_ubjson),
// "[json.exception.out_of_range.408] excessive array size: 8658170730974374167");
@ -1476,7 +1476,7 @@ TEST_CASE("regression tests 1")
SECTION("issue #977 - Assigning between different json types")
{
foo_json lj = ns::foo{3};
foo_json lj = ns::foo{ 3 };
ns::foo ff(lj);
CHECK(lj.is_object());
CHECK(lj.size() == 1);

View File

@ -74,8 +74,8 @@ enum class for_1647
// NOLINTNEXTLINE(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays): this is a false positive
NLOHMANN_JSON_SERIALIZE_ENUM(for_1647,
{
{for_1647::one, "one"},
{for_1647::two, "two"},
{ for_1647::one, "one" },
{ for_1647::two, "two" },
})
} // namespace
@ -418,15 +418,15 @@ TEST_CASE("regression tests 2")
CHECK(float_json::from_msgpack(float_json::to_msgpack(j)) == j);
CHECK(float_json::from_ubjson(float_json::to_ubjson(j)) == j);
float_json j2 = {1000.0, 2000.0, 3000.0};
float_json j2 = { 1000.0, 2000.0, 3000.0 };
CHECK(float_json::from_ubjson(float_json::to_ubjson(j2, true, true)) == j2);
}
SECTION("issue #1045 - Using STL algorithms with JSON containers with expected results?")
{
json diffs = nlohmann::json::array();
json m1{{"key1", 42}};
json m2{{"key2", 42}};
json m1{ { "key1", 42 } };
json m2{ { "key2", 42 } };
auto p1 = m1.items();
auto p2 = m2.items();
@ -451,15 +451,15 @@ TEST_CASE("regression tests 2")
"with std::pair")
{
const json j = {
{"1", {{"a", "testa_1"}, {"b", "testb_1"}}},
{"2", {{"a", "testa_2"}, {"b", "testb_2"}}},
{"3", {{"a", "testa_3"}, {"b", "testb_3"}}},
{ "1", { { "a", "testa_1" }, { "b", "testb_1" } } },
{ "2", { { "a", "testa_2" }, { "b", "testb_2" } } },
{ "3", { { "a", "testa_3" }, { "b", "testb_3" } } },
};
std::map<std::string, Data> expected{
{"1", {"testa_1", "testb_1"}},
{"2", {"testa_2", "testb_2"}},
{"3", {"testa_3", "testb_3"}},
{ "1", { "testa_1", "testb_1" } },
{ "2", { "testa_2", "testb_2" } },
{ "3", { "testa_3", "testb_3" } },
};
const auto data = j.get<decltype(expected)>();
CHECK(expected == data);
@ -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)
{
@ -534,10 +535,10 @@ TEST_CASE("regression tests 2")
SECTION("issue #1727 - Contains with non-const lvalue json_pointer picks the wrong overload")
{
const json j = {{"root", {{"settings", {{"logging", true}}}}}};
const json j = { { "root", { { "settings", { { "logging", true } } } } } };
auto jptr1 = "/root/settings/logging"_json_pointer;
auto jptr2 = json::json_pointer{"/root/settings/logging"};
auto jptr2 = json::json_pointer{ "/root/settings/logging" };
CHECK(j.contains(jptr1));
CHECK(j.contains(jptr2));
@ -570,7 +571,7 @@ TEST_CASE("regression tests 2")
SECTION("string array")
{
const std::array<char, 2> input = {{'B', 0x00}};
const std::array<char, 2> input = { { 'B', 0x00 } };
const json cbor = json::from_cbor(input, true, false);
CHECK(cbor.is_discarded());
}
@ -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
@ -618,7 +619,7 @@ TEST_CASE("regression tests 2")
SECTION("PR #2181 - regression bug with lvalue")
{
// see https://github.com/nlohmann/json/pull/2181#issuecomment-653326060
const json j{{"x", "test"}};
const json j{ { "x", "test" } };
const std::string defval = "default value";
auto val = j.value("x", defval);
auto val2 = j.value("y", defval);
@ -626,22 +627,22 @@ TEST_CASE("regression tests 2")
SECTION("issue #2293 - eof doesn't cause parsing to stop")
{
const std::vector<uint8_t> data = {0x7B, 0x6F, 0x62, 0x6A, 0x65, 0x63, 0x74, 0x20, 0x4F, 0x42};
const std::vector<uint8_t> data = { 0x7B, 0x6F, 0x62, 0x6A, 0x65, 0x63, 0x74, 0x20, 0x4F, 0x42 };
const json result = json::from_cbor(data, true, false);
CHECK(result.is_discarded());
}
SECTION("issue #2315 - json.update and vector<pair>does not work with ordered_json")
{
nlohmann::ordered_json jsonAnimals = {{"animal", "dog"}};
const nlohmann::ordered_json jsonCat = {{"animal", "cat"}};
nlohmann::ordered_json jsonAnimals = { { "animal", "dog" } };
const nlohmann::ordered_json jsonCat = { { "animal", "cat" } };
jsonAnimals.update(jsonCat);
CHECK(jsonAnimals["animal"] == "cat");
auto jsonAnimals_parsed = nlohmann::ordered_json::parse(jsonAnimals.dump());
CHECK(jsonAnimals == jsonAnimals_parsed);
const std::vector<std::pair<std::string, int64_t>> intData = {std::make_pair("aaaa", 11), std::make_pair("bbb", 222)};
const std::vector<std::pair<std::string, int64_t>> intData = { std::make_pair("aaaa", 11), std::make_pair("bbb", 222) };
nlohmann::ordered_json jsonObj;
for (const auto& data : intData)
{
@ -675,7 +676,7 @@ TEST_CASE("regression tests 2")
SECTION("std::array")
{
{
const json j = {7, 4};
const json j = { 7, 4 };
auto arr = j.get<std::array<NonDefaultConstructible, 2>>();
CHECK(arr[0].x == 7);
CHECK(arr[1].x == 4);
@ -690,21 +691,21 @@ TEST_CASE("regression tests 2")
SECTION("std::pair")
{
{
const json j = {3, 8};
const json j = { 3, 8 };
auto p = j.get<std::pair<NonDefaultConstructible, NonDefaultConstructible>>();
CHECK(p.first.x == 3);
CHECK(p.second.x == 8);
}
{
const json j = {4, 1};
const json j = { 4, 1 };
auto p = j.get<std::pair<int, NonDefaultConstructible>>();
CHECK(p.first == 4);
CHECK(p.second.x == 1);
}
{
const json j = {6, 7};
const json j = { 6, 7 };
auto p = j.get<std::pair<NonDefaultConstructible, int>>();
CHECK(p.first.x == 6);
CHECK(p.second == 7);
@ -719,13 +720,13 @@ TEST_CASE("regression tests 2")
SECTION("std::tuple")
{
{
const json j = {9};
const json j = { 9 };
auto t = j.get<std::tuple<NonDefaultConstructible>>();
CHECK(std::get<0>(t).x == 9);
}
{
const json j = {9, 8, 7};
const json j = { 9, 8, 7 };
auto t = j.get<std::tuple<NonDefaultConstructible, int, NonDefaultConstructible>>();
CHECK(std::get<0>(t).x == 9);
CHECK(std::get<1>(t) == 8);
@ -803,7 +804,7 @@ TEST_CASE("regression tests 2")
SECTION("issue #2982 - to_{binary format} does not provide a mechanism for specifying a custom allocator for the returned type")
{
std::vector<std::uint8_t, my_allocator<std::uint8_t>> my_vector;
json j = {1, 2, 3, 4};
json j = { 1, 2, 3, 4 };
json::to_cbor(j, my_vector);
json k = json::from_cbor(my_vector);
CHECK(j == k);
@ -836,7 +837,7 @@ TEST_CASE("regression tests 2")
SECTION("issue #3108 - ordered_json doesn't support range based erase")
{
ordered_json j = {1, 2, 2, 4};
ordered_json j = { 1, 2, 2, 4 };
auto last = std::unique(j.begin(), j.end());
j.erase(last, j.end());
@ -855,8 +856,8 @@ TEST_CASE("regression tests 2")
SECTION("issue #3343 - json and ordered_json are not interchangable")
{
json::object_t jobj({{"product", "one"}});
ordered_json::object_t ojobj({{"product", "one"}});
json::object_t jobj({ { "product", "one" } });
ordered_json::object_t ojobj({ { "product", "one" } });
auto jit = jobj.begin();
auto ojit = ojobj.begin();
@ -867,7 +868,7 @@ TEST_CASE("regression tests 2")
SECTION("issue #3171 - if class is_constructible from std::string wrong from_json overload is being selected, compilation failed")
{
const json j{{"str", "value"}};
const json j{ { "str", "value" } };
// failed with: error: no match for operator= (operand types are for_3171_derived and const nlohmann::basic_json<>::string_t
// {aka const std::__cxx11::basic_string<char>})
@ -881,7 +882,7 @@ TEST_CASE("regression tests 2")
SECTION("issue #3312 - Parse to custom class from unordered_json breaks on G++11.2.0 with C++20")
{
// see test for #3171
const ordered_json j = {{"name", "class"}};
const ordered_json j = { { "name", "class" } };
for_3312 obj{};
j.get_to(obj);
@ -913,7 +914,7 @@ TEST_CASE("regression tests 2")
SECTION("issue #3333 - Ambiguous conversion from nlohmann::basic_json<> to custom class")
{
const json j{{"x", 1}, {"y", 2}};
const json j{ { "x", 1 }, { "y", 2 } };
for_3333 p = j;
CHECK(p.x == 1);

View File

@ -21,7 +21,7 @@ TEST_CASE("serialization")
SECTION("no given width")
{
std::stringstream ss;
const json j = {"foo", 1, 2, 3, false, {{"one", 1}}};
const json j = { "foo", 1, 2, 3, false, { { "one", 1 } } };
ss << j;
CHECK(ss.str() == "[\"foo\",1,2,3,false,{\"one\":1}]");
}
@ -29,7 +29,7 @@ TEST_CASE("serialization")
SECTION("given width")
{
std::stringstream ss;
const json j = {"foo", 1, 2, 3, false, {{"one", 1}}};
const json j = { "foo", 1, 2, 3, false, { { "one", 1 } } };
ss << std::setw(4) << j;
CHECK(ss.str() == "[\n \"foo\",\n 1,\n 2,\n 3,\n false,\n {\n \"one\": 1\n }\n]");
}
@ -37,7 +37,7 @@ TEST_CASE("serialization")
SECTION("given fill")
{
std::stringstream ss;
const json j = {"foo", 1, 2, 3, false, {{"one", 1}}};
const json j = { "foo", 1, 2, 3, false, { { "one", 1 } } };
ss << std::setw(1) << std::setfill('\t') << j;
CHECK(ss.str() == "[\n\t\"foo\",\n\t1,\n\t2,\n\t3,\n\tfalse,\n\t{\n\t\t\"one\": 1\n\t}\n]");
}
@ -48,7 +48,7 @@ TEST_CASE("serialization")
SECTION("no given width")
{
std::stringstream ss;
const json j = {"foo", 1, 2, 3, false, {{"one", 1}}};
const json j = { "foo", 1, 2, 3, false, { { "one", 1 } } };
j >> ss;
CHECK(ss.str() == "[\"foo\",1,2,3,false,{\"one\":1}]");
}
@ -56,7 +56,7 @@ TEST_CASE("serialization")
SECTION("given width")
{
std::stringstream ss;
const json j = {"foo", 1, 2, 3, false, {{"one", 1}}};
const json j = { "foo", 1, 2, 3, false, { { "one", 1 } } };
ss.width(4);
j >> ss;
CHECK(ss.str() == "[\n \"foo\",\n 1,\n 2,\n 3,\n false,\n {\n \"one\": 1\n }\n]");
@ -65,7 +65,7 @@ TEST_CASE("serialization")
SECTION("given fill")
{
std::stringstream ss;
const json j = {"foo", 1, 2, 3, false, {{"one", 1}}};
const json j = { "foo", 1, 2, 3, false, { { "one", 1 } } };
ss.width(1);
ss.fill('\t');
j >> ss;
@ -249,20 +249,20 @@ TEST_CASE_TEMPLATE("serialization for extreme integer values", T, int32_t, uint3
TEST_CASE("dump with binary values")
{
auto binary = json::binary({1, 2, 3, 4});
auto binary = json::binary({ 1, 2, 3, 4 });
auto binary_empty = json::binary({});
auto binary_with_subtype = json::binary({1, 2, 3, 4}, 128);
auto binary_with_subtype = json::binary({ 1, 2, 3, 4 }, 128);
auto binary_empty_with_subtype = json::binary({}, 128);
const json object = {{"key", binary}};
const json object_empty = {{"key", binary_empty}};
const json object_with_subtype = {{"key", binary_with_subtype}};
const json object_empty_with_subtype = {{"key", binary_empty_with_subtype}};
const json object = { { "key", binary } };
const json object_empty = { { "key", binary_empty } };
const json object_with_subtype = { { "key", binary_with_subtype } };
const json object_empty_with_subtype = { { "key", binary_empty_with_subtype } };
const json array = {"value", 1, binary};
const json array_empty = {"value", 1, binary_empty};
const json array_with_subtype = {"value", 1, binary_with_subtype};
const json array_empty_with_subtype = {"value", 1, binary_empty_with_subtype};
const json array = { "value", 1, binary };
const json array_empty = { "value", 1, binary_empty };
const json array_with_subtype = { "value", 1, binary_with_subtype };
const json array_empty_with_subtype = { "value", 1, binary_empty_with_subtype };
SECTION("normal")
{

View File

@ -20,7 +20,7 @@ TEST_CASE("compliance tests from json.org")
SECTION("expected failures")
{
for (const auto* filename : {//TEST_DATA_DIRECTORY "/json_tests/fail1.json",
for (const auto* filename : { //TEST_DATA_DIRECTORY "/json_tests/fail1.json",
TEST_DATA_DIRECTORY "/json_tests/fail2.json",
TEST_DATA_DIRECTORY "/json_tests/fail3.json",
TEST_DATA_DIRECTORY "/json_tests/fail4.json",
@ -52,7 +52,7 @@ TEST_CASE("compliance tests from json.org")
TEST_DATA_DIRECTORY "/json_tests/fail30.json",
TEST_DATA_DIRECTORY "/json_tests/fail31.json",
TEST_DATA_DIRECTORY "/json_tests/fail32.json",
TEST_DATA_DIRECTORY "/json_tests/fail33.json"})
TEST_DATA_DIRECTORY "/json_tests/fail33.json" })
{
CAPTURE(filename)
std::ifstream f(filename);
@ -82,7 +82,7 @@ TEST_CASE("compliance tests from json.org")
SECTION("expected passes")
{
for (const auto* filename :
{TEST_DATA_DIRECTORY "/json_tests/pass1.json", TEST_DATA_DIRECTORY "/json_tests/pass2.json", TEST_DATA_DIRECTORY "/json_tests/pass3.json"})
{ TEST_DATA_DIRECTORY "/json_tests/pass1.json", TEST_DATA_DIRECTORY "/json_tests/pass2.json", TEST_DATA_DIRECTORY "/json_tests/pass3.json" })
{
CAPTURE(filename)
std::ifstream f(filename);
@ -453,7 +453,7 @@ TEST_CASE("nst's JSONTestSuite")
{
SECTION("y")
{
for (const auto* filename : {TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_array_arraysWithSpaces.json",
for (const auto* filename : { TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_array_arraysWithSpaces.json",
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_array_empty-string.json",
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_array_empty.json",
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_array_ending_with_newline.json",
@ -548,7 +548,7 @@ TEST_CASE("nst's JSONTestSuite")
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_structure_string_empty.json",
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_structure_trailing_newline.json",
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_structure_true_in_array.json",
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_structure_whitespace_array.json"})
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_structure_whitespace_array.json" })
{
CAPTURE(filename)
std::ifstream f(filename);
@ -559,7 +559,7 @@ TEST_CASE("nst's JSONTestSuite")
SECTION("n")
{
for (const auto* filename : {TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_array_1_true_without_comma.json",
for (const auto* filename : { TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_array_1_true_without_comma.json",
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_array_a_invalid_utf8.json",
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_array_colon_instead_of_comma.json",
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_array_comma_after_close.json",
@ -753,7 +753,7 @@ TEST_CASE("nst's JSONTestSuite")
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_unclosed_object.json",
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_unicode-identifier.json",
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_whitespace_U+2060_word_joiner.json",
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_whitespace_formfeed.json"})
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_whitespace_formfeed.json" })
{
CAPTURE(filename)
std::ifstream f(filename);
@ -767,7 +767,7 @@ TEST_CASE("nst's JSONTestSuite")
// these tests fail above, because the parser does not end on EOF;
// they succeed when the operator>> is used, because it does not
// have this constraint
for (const auto* filename : {TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_array_comma_after_close.json",
for (const auto* filename : { TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_array_comma_after_close.json",
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_array_extra_close.json",
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_object_trailing_comment.json",
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_object_trailing_comment_open.json",
@ -782,7 +782,7 @@ TEST_CASE("nst's JSONTestSuite")
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_number_with_trailing_garbage.json",
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_object_followed_by_closing_object.json",
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_object_with_trailing_garbage.json",
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_trailing_#.json"})
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_trailing_#.json" })
{
CAPTURE(filename)
std::ifstream f(filename);
@ -793,7 +793,7 @@ TEST_CASE("nst's JSONTestSuite")
SECTION("i -> y")
{
for (const auto* filename : {// we do not pose a limit on nesting
for (const auto* filename : { // we do not pose a limit on nesting
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/i_structure_500_nested_arrays.json",
// we silently ignore BOMs
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/i_structure_UTF-8_BOM_empty_object.json",
@ -801,7 +801,7 @@ TEST_CASE("nst's JSONTestSuite")
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/i_string_unicode_U+10FFFE_nonchar.json",
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/i_string_unicode_U+1FFFE_nonchar.json",
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/i_string_unicode_U+FDD0_nonchar.json",
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/i_string_unicode_U+FFFE_nonchar.json"})
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/i_string_unicode_U+FFFE_nonchar.json" })
{
CAPTURE(filename)
std::ifstream f(filename);
@ -813,11 +813,11 @@ TEST_CASE("nst's JSONTestSuite")
// numbers that overflow during parsing
SECTION("i/y -> n (out of range)")
{
for (const auto* filename : {TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/i_number_neg_int_huge_exp.json",
for (const auto* filename : { TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/i_number_neg_int_huge_exp.json",
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/i_number_pos_double_huge_exp.json",
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_huge_exp.json",
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_real_neg_overflow.json",
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_real_pos_overflow.json"})
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_real_pos_overflow.json" })
{
CAPTURE(filename)
std::ifstream f(filename);
@ -828,7 +828,7 @@ TEST_CASE("nst's JSONTestSuite")
SECTION("i -> n")
{
for (const auto* filename : {TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/i_object_key_lone_2nd_surrogate.json",
for (const auto* filename : { TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/i_object_key_lone_2nd_surrogate.json",
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/i_string_1st_surrogate_but_2nd_missing.json",
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/i_string_1st_valid_surrogate_2nd_invalid.json",
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/i_string_UTF-16_invalid_lonely_surrogate.json",
@ -840,7 +840,7 @@ TEST_CASE("nst's JSONTestSuite")
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/i_string_inverted_surrogates_U+1D11E.json",
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/i_string_lone_second_surrogate.json",
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/i_string_not_in_unicode_range.json",
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/i_string_truncated-utf-8.json"})
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/i_string_truncated-utf-8.json" })
{
CAPTURE(filename)
std::ifstream f(filename);
@ -857,7 +857,7 @@ TEST_CASE("nst's JSONTestSuite (2)")
{
SECTION("y")
{
for (const auto* filename : {TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_array_arraysWithSpaces.json",
for (const auto* filename : { TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_array_arraysWithSpaces.json",
TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_array_empty-string.json",
TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_array_empty.json",
TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_array_ending_with_newline.json",
@ -951,7 +951,7 @@ TEST_CASE("nst's JSONTestSuite (2)")
TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_structure_string_empty.json",
TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_structure_trailing_newline.json",
TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_structure_true_in_array.json",
TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_structure_whitespace_array.json"})
TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_structure_whitespace_array.json" })
{
CAPTURE(filename)
std::ifstream f(filename);
@ -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",
@ -1149,7 +1150,7 @@ TEST_CASE("nst's JSONTestSuite (2)")
TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_unclosed_object.json",
TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_unicode-identifier.json",
TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_whitespace_U+2060_word_joiner.json",
TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_whitespace_formfeed.json"})
TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_whitespace_formfeed.json" })
{
CAPTURE(filename)
std::ifstream f(filename);
@ -1162,8 +1163,8 @@ TEST_CASE("nst's JSONTestSuite (2)")
SECTION("n (previously overflowed)")
{
for (const auto* filename : {TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_100000_opening_arrays.json",
TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_open_array_object.json"})
for (const auto* filename : { TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_100000_opening_arrays.json",
TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_open_array_object.json" })
{
CAPTURE(filename)
std::ifstream f(filename);
@ -1173,7 +1174,7 @@ TEST_CASE("nst's JSONTestSuite (2)")
SECTION("i -> y")
{
for (const auto* filename : {TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_number_double_huge_neg_exp.json",
for (const auto* filename : { TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_number_double_huge_neg_exp.json",
//TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_number_huge_exp.json",
//TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_number_neg_int_huge_exp.json",
//TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_number_pos_double_huge_exp.json",
@ -1207,7 +1208,7 @@ TEST_CASE("nst's JSONTestSuite (2)")
//TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_string_utf16BE_no_BOM.json",
//TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_string_utf16LE_no_BOM.json",
TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_structure_500_nested_arrays.json",
TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_structure_UTF-8_BOM_empty_object.json"})
TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_structure_UTF-8_BOM_empty_object.json" })
{
CAPTURE(filename)
std::ifstream f(filename);

File diff suppressed because it is too large Load Diff

View File

@ -130,7 +130,7 @@ static void to_json(BasicJsonType& j, country c)
template<typename BasicJsonType>
static void to_json(BasicJsonType& j, const person& p)
{
j = BasicJsonType{{"age", p.m_age}, {"name", p.m_name}, {"country", p.m_country}};
j = BasicJsonType{ { "age", p.m_age }, { "name", p.m_name }, { "country", p.m_country } };
}
static void to_json(nlohmann::json& j, const address& a)
@ -140,12 +140,12 @@ static void to_json(nlohmann::json& j, const address& a)
static void to_json(nlohmann::json& j, const contact& c)
{
j = json{{"person", c.m_person}, {"address", c.m_address}};
j = json{ { "person", c.m_person }, { "address", c.m_address } };
}
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 }, { "contacts", cb.m_contacts } };
}
// operators
@ -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
@ -235,14 +237,14 @@ static void from_json(const nlohmann::json& j, contact_book& cb)
TEST_CASE("basic usage" * doctest::test_suite("udt"))
{
// a bit narcissistic maybe :) ?
const udt::age a{23};
const udt::name n{"theo"};
const udt::country c{udt::country::france};
const udt::person sfinae_addict{a, n, c};
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::age a{ 23 };
const udt::name n{ "theo" };
const udt::country c{ udt::country::france };
const udt::person sfinae_addict{ a, n, c };
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 } } };
SECTION("conversion to json via free-functions")
{
@ -282,7 +284,7 @@ TEST_CASE("basic usage" * doctest::test_suite("udt"))
CHECK(person == sfinae_addict);
CHECK(contact == cpp_programmer);
CHECK(contacts == book.m_contacts);
CHECK(book_name == udt::name{"C++"});
CHECK(book_name == udt::name{ "C++" });
CHECK(book == parsed_book);
}
@ -320,7 +322,7 @@ TEST_CASE("basic usage" * doctest::test_suite("udt"))
CHECK(person == sfinae_addict);
CHECK(contact == cpp_programmer);
CHECK(contacts == book.m_contacts);
CHECK(book_name == udt::name{"C++"});
CHECK(book_name == udt::name{ "C++" });
CHECK(book == parsed_book);
}
#endif
@ -395,7 +397,7 @@ TEST_CASE("adl_serializer specialization" * doctest::test_suite("udt"))
json j = optPerson;
CHECK(j.is_null());
optPerson.reset(new udt::person{{42}, {"John Doe"}, udt::country::russia}); // NOLINT(cppcoreguidelines-owning-memory,modernize-make-shared)
optPerson.reset(new udt::person{ { 42 }, { "John Doe" }, udt::country::russia }); // NOLINT(cppcoreguidelines-owning-memory,modernize-make-shared)
j = optPerson;
CHECK_FALSE(j.is_null());
@ -404,7 +406,7 @@ TEST_CASE("adl_serializer specialization" * doctest::test_suite("udt"))
SECTION("from_json")
{
auto person = udt::person{{42}, {"John Doe"}, udt::country::russia};
auto person = udt::person{ { 42 }, { "John Doe" }, udt::country::russia };
json j = person;
auto optPerson = j.get<std::shared_ptr<udt::person>>();
@ -421,7 +423,7 @@ TEST_CASE("adl_serializer specialization" * doctest::test_suite("udt"))
{
SECTION("to_json")
{
udt::legacy_type const lt{"4242"};
udt::legacy_type const lt{ "4242" };
json const j = lt;
CHECK(j.get<int>() == 4242);
@ -449,24 +451,24 @@ struct adl_serializer<std::vector<float>>
static void from_json(const json& /*unnamed*/, type& opt)
{
opt = {42.0, 42.0, 42.0};
opt = { 42.0, 42.0, 42.0 };
}
// preferred version
static type from_json(const json& /*unnamed*/)
{
return {4.0, 5.0, 6.0};
return { 4.0, 5.0, 6.0 };
}
};
} // namespace nlohmann
TEST_CASE("even supported types can be specialized" * doctest::test_suite("udt"))
{
json const j = std::vector<float>{1.0, 2.0, 3.0};
json const j = std::vector<float>{ 1.0, 2.0, 3.0 };
CHECK(j.dump() == R"("hijacked!")");
auto f = j.get<std::vector<float>>();
// the single argument from_json method is preferred
CHECK((f == std::vector<float>{4.0, 5.0, 6.0}));
CHECK((f == std::vector<float>{ 4.0, 5.0, 6.0 }));
}
namespace nlohmann
@ -508,7 +510,7 @@ TEST_CASE("Non-copyable types" * doctest::test_suite("udt"))
json j = optPerson;
CHECK(j.is_null());
optPerson.reset(new udt::person{{42}, {"John Doe"}, udt::country::russia}); // NOLINT(cppcoreguidelines-owning-memory,modernize-make-unique)
optPerson.reset(new udt::person{ { 42 }, { "John Doe" }, udt::country::russia }); // NOLINT(cppcoreguidelines-owning-memory,modernize-make-unique)
j = optPerson;
CHECK_FALSE(j.is_null());
@ -517,7 +519,7 @@ TEST_CASE("Non-copyable types" * doctest::test_suite("udt"))
SECTION("from_json")
{
auto person = udt::person{{42}, {"John Doe"}, udt::country::russia};
auto person = udt::person{ { 42 }, { "John Doe" }, udt::country::russia };
json j = person;
auto optPerson = j.get<std::unique_ptr<udt::person>>();
@ -635,14 +637,14 @@ TEST_CASE("custom serializer for pods" * doctest::test_suite("udt"))
{
using custom_json = nlohmann::basic_json<std::map, std::vector, std::string, bool, std::int64_t, std::uint64_t, double, std::allocator, pod_serializer>;
auto p = udt::small_pod{42, '/', 42};
auto p = udt::small_pod{ 42, '/', 42 };
custom_json const j = p;
auto p2 = j.get<udt::small_pod>();
CHECK(p == p2);
auto np = udt::non_pod{{"non-pod"}};
auto np = udt::non_pod{ { "non-pod" } };
custom_json const j2 = np;
auto np2 = j2.get<udt::non_pod>();
CHECK(np == np2);
@ -671,7 +673,7 @@ struct another_adl_serializer
TEST_CASE("custom serializer that does adl by default" * doctest::test_suite("udt"))
{
auto me = udt::person{{23}, {"theo"}, udt::country::france};
auto me = udt::person{ { 23 }, { "theo" }, udt::country::france };
json const j = me;
custom_json const cj = me;
@ -708,9 +710,9 @@ TEST_CASE("different basic_json types conversions")
SECTION("array")
{
json const j = {1, 2, 3};
json const j = { 1, 2, 3 };
custom_json const cj = j;
CHECK((cj == std::vector<int>{1, 2, 3}));
CHECK((cj == std::vector<int>{ 1, 2, 3 }));
}
SECTION("integer")
@ -743,7 +745,7 @@ TEST_CASE("different basic_json types conversions")
SECTION("binary")
{
json j = json::binary({1, 2, 3}, 42);
json j = json::binary({ 1, 2, 3 }, 42);
custom_json cj = j;
CHECK(cj.get_binary().subtype() == 42);
std::vector<std::uint8_t> cv = cj.get_binary();
@ -753,7 +755,7 @@ TEST_CASE("different basic_json types conversions")
SECTION("object")
{
json const j = {{"forty", "two"}};
json const j = { { "forty", "two" } };
custom_json cj = j;
auto m = j.get<std::map<std::string, std::string>>();
CHECK(cj == m);
@ -853,7 +855,7 @@ class no_iterator_type
TEST_CASE("compatible array type, without iterator type alias")
{
no_iterator_type const vec{1, 2, 3};
no_iterator_type const vec{ 1, 2, 3 };
json const j = vec;
}

View File

@ -245,8 +245,8 @@ class person_without_default_constructor_1
}
person_without_default_constructor_1(std::string name_, int age_)
: name{std::move(name_)}
, age{age_}
: name{ std::move(name_) }
, age{ age_ }
{}
NLOHMANN_DEFINE_TYPE_INTRUSIVE_ONLY_SERIALIZE(person_without_default_constructor_1, name, age)
@ -264,8 +264,8 @@ class person_without_default_constructor_2
}
person_without_default_constructor_2(std::string name_, int age_)
: name{std::move(name_)}
, age{age_}
: name{ std::move(name_) }
, age{ age_ }
{}
};
@ -282,7 +282,7 @@ TEST_CASE_TEMPLATE("Serialization/deserialization via NLOHMANN_DEFINE_TYPE_INTRU
SECTION("person")
{
// serialization
T p1("Erik", 1, {{"haircuts", 2}});
T p1("Erik", 1, { { "haircuts", 2 } });
CHECK(json(p1).dump() == "{\"age\":1,\"metadata\":{\"haircuts\":2},\"name\":\"Erik\"}");
// deserialization
@ -312,7 +312,7 @@ TEST_CASE_TEMPLATE("Serialization/deserialization via NLOHMANN_DEFINE_TYPE_INTRU
CHECK(json(p0).dump() == "{\"age\":0,\"metadata\":null,\"name\":\"\"}");
// serialization
T p1("Erik", 1, {{"haircuts", 2}});
T p1("Erik", 1, { { "haircuts", 2 } });
CHECK(json(p1).dump() == "{\"age\":1,\"metadata\":{\"haircuts\":2},\"name\":\"Erik\"}");
// deserialization
@ -419,11 +419,11 @@ TEST_CASE_TEMPLATE(
{
{
// serialization of a single object
T person{"Erik", 1};
T person{ "Erik", 1 };
CHECK(json(person).dump() == "{\"age\":1,\"name\":\"Erik\"}");
// serialization of a container with objects
std::vector<T> const two_persons{{"Erik", 1}, {"Kyle", 2}};
std::vector<T> const two_persons{ { "Erik", 1 }, { "Kyle", 2 } };
CHECK(json(two_persons).dump() == "[{\"age\":1,\"name\":\"Erik\"},{\"age\":2,\"name\":\"Kyle\"}]");
}
}

View File

@ -44,7 +44,7 @@ const char* end(const MyContainer& c)
TEST_CASE("Custom container non-member begin/end")
{
const MyContainer data{"[1,2,3,4]"};
const MyContainer data{ "[1,2,3,4]" };
json as_json = json::parse(data);
CHECK(as_json.at(0) == 1);
CHECK(as_json.at(1) == 2);
@ -69,7 +69,7 @@ TEST_CASE("Custom container member begin/end")
}
};
const MyContainer2 data{"[1,2,3,4]"};
const MyContainer2 data{ "[1,2,3,4]" };
json as_json = json::parse(data);
CHECK(as_json.at(0) == 1);
CHECK(as_json.at(1) == 2);
@ -115,8 +115,8 @@ TEST_CASE("Custom iterator")
CHECK(std::is_same<MyIterator::reference, const char&>::value);
CHECK(std::is_same<MyIterator::iterator_category, std::input_iterator_tag>::value);
const MyIterator begin{raw_data};
const MyIterator end{raw_data + strlen(raw_data)}; // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic)
const MyIterator begin{ raw_data };
const MyIterator end{ raw_data + strlen(raw_data) }; // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic)
json as_json = json::parse(begin, end);
CHECK(as_json.at(0) == 1);