mirror of
https://github.com/nlohmann/json.git
synced 2024-11-27 16:49:02 +08:00
🎨 use Clang-Format
This commit is contained in:
parent
286f0c7647
commit
af3f87e84e
@ -46,7 +46,7 @@ BreakStringLiterals: false
|
|||||||
ColumnLimit: 160
|
ColumnLimit: 160
|
||||||
CompactNamespaces: false
|
CompactNamespaces: false
|
||||||
ConstructorInitializerIndentWidth: 2
|
ConstructorInitializerIndentWidth: 2
|
||||||
Cpp11BracedListStyle: true
|
Cpp11BracedListStyle: false
|
||||||
PointerAlignment: Left
|
PointerAlignment: Left
|
||||||
FixNamespaceComments: true
|
FixNamespaceComments: true
|
||||||
#IndentCaseBlocks: false
|
#IndentCaseBlocks: false
|
||||||
@ -92,3 +92,6 @@ IncludeCategories:
|
|||||||
Priority: 3
|
Priority: 3
|
||||||
- Regex: '.*'
|
- Regex: '.*'
|
||||||
Priority: 4
|
Priority: 4
|
||||||
|
|
||||||
|
Macros:
|
||||||
|
- JSON_PRIVATE_UNLESS_TESTED=private
|
||||||
|
16
.github/workflows/ubuntu.yml
vendored
16
.github/workflows/ubuntu.yml
vendored
@ -43,10 +43,20 @@ jobs:
|
|||||||
|
|
||||||
ci_static_analysis:
|
ci_static_analysis:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
container: silkeh/clang:dev
|
container: ghcr.io/nlohmann/json-ci:v2.4.0
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
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:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
- name: Get latest CMake and ninja
|
- name: Get latest CMake and ninja
|
||||||
@ -54,7 +64,7 @@ jobs:
|
|||||||
- name: Run CMake
|
- name: Run CMake
|
||||||
run: cmake -S . -B build -DJSON_CI=On
|
run: cmake -S . -B build -DJSON_CI=On
|
||||||
- name: Build
|
- name: Build
|
||||||
run: cmake --build build --target ${{ matrix.target }}
|
run: cmake --build build --target ci_test_amalgamation
|
||||||
|
|
||||||
ci_static_analysis_ubuntu:
|
ci_static_analysis_ubuntu:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
@ -252,7 +252,7 @@ template<typename BasicJsonType, typename T, std::size_t... Idx>
|
|||||||
std::array<T, sizeof...(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*/)
|
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>
|
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>
|
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*/)
|
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>
|
template<typename BasicJsonType, typename A1, typename A2>
|
||||||
|
@ -75,7 +75,7 @@ struct diyfp // f * 2^e
|
|||||||
JSON_ASSERT(x.e == y.e);
|
JSON_ASSERT(x.e == y.e);
|
||||||
JSON_ASSERT(x.f >= y.f);
|
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
|
// Effectively we only need to add the highest bit in p_lo to p_hi (and
|
||||||
// Q_hi + 1 does not overflow).
|
// 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);
|
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(delta >= 0);
|
||||||
JSON_ASSERT(((x.f << delta) >> delta) == x.f);
|
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 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 kBias = std::numeric_limits<FloatType>::max_exponent - 1 + (kPrecision - 1);
|
||||||
constexpr int kMinExp = 1 - kBias;
|
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;
|
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+).
|
// Determine w- = m- such that e_(w-) = e_(w+).
|
||||||
const diyfp w_minus = diyfp::normalize_to(m_minus, w_plus.e);
|
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
|
// 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 kCachedPowersMinDecExp = -300;
|
||||||
constexpr int kCachedPowersDecStep = 8;
|
constexpr int kCachedPowersDecStep = 8;
|
||||||
|
|
||||||
static constexpr std::array<cached_power, 79> kCachedPowers = {{
|
static constexpr std::array<cached_power, 79> kCachedPowers = { {
|
||||||
{0xAB70FE17C79AC6CA, -1060, -300}, {0xFF77B1FCBEBCDC4F, -1034, -292}, {0xBE5691EF416BD60C, -1007, -284}, {0x8DD01FAD907FFC3C, -980, -276},
|
{ 0xAB70FE17C79AC6CA, -1060, -300 }, { 0xFF77B1FCBEBCDC4F, -1034, -292 }, { 0xBE5691EF416BD60C, -1007, -284 }, { 0x8DD01FAD907FFC3C, -980, -276 },
|
||||||
{0xD3515C2831559A83, -954, -268}, {0x9D71AC8FADA6C9B5, -927, -260}, {0xEA9C227723EE8BCB, -901, -252}, {0xAECC49914078536D, -874, -244},
|
{ 0xD3515C2831559A83, -954, -268 }, { 0x9D71AC8FADA6C9B5, -927, -260 }, { 0xEA9C227723EE8BCB, -901, -252 }, { 0xAECC49914078536D, -874, -244 },
|
||||||
{0x823C12795DB6CE57, -847, -236}, {0xC21094364DFB5637, -821, -228}, {0x9096EA6F3848984F, -794, -220}, {0xD77485CB25823AC7, -768, -212},
|
{ 0x823C12795DB6CE57, -847, -236 }, { 0xC21094364DFB5637, -821, -228 }, { 0x9096EA6F3848984F, -794, -220 }, { 0xD77485CB25823AC7, -768, -212 },
|
||||||
{0xA086CFCD97BF97F4, -741, -204}, {0xEF340A98172AACE5, -715, -196}, {0xB23867FB2A35B28E, -688, -188}, {0x84C8D4DFD2C63F3B, -661, -180},
|
{ 0xA086CFCD97BF97F4, -741, -204 }, { 0xEF340A98172AACE5, -715, -196 }, { 0xB23867FB2A35B28E, -688, -188 }, { 0x84C8D4DFD2C63F3B, -661, -180 },
|
||||||
{0xC5DD44271AD3CDBA, -635, -172}, {0x936B9FCEBB25C996, -608, -164}, {0xDBAC6C247D62A584, -582, -156}, {0xA3AB66580D5FDAF6, -555, -148},
|
{ 0xC5DD44271AD3CDBA, -635, -172 }, { 0x936B9FCEBB25C996, -608, -164 }, { 0xDBAC6C247D62A584, -582, -156 }, { 0xA3AB66580D5FDAF6, -555, -148 },
|
||||||
{0xF3E2F893DEC3F126, -529, -140}, {0xB5B5ADA8AAFF80B8, -502, -132}, {0x87625F056C7C4A8B, -475, -124}, {0xC9BCFF6034C13053, -449, -116},
|
{ 0xF3E2F893DEC3F126, -529, -140 }, { 0xB5B5ADA8AAFF80B8, -502, -132 }, { 0x87625F056C7C4A8B, -475, -124 }, { 0xC9BCFF6034C13053, -449, -116 },
|
||||||
{0x964E858C91BA2655, -422, -108}, {0xDFF9772470297EBD, -396, -100}, {0xA6DFBD9FB8E5B88F, -369, -92}, {0xF8A95FCF88747D94, -343, -84},
|
{ 0x964E858C91BA2655, -422, -108 }, { 0xDFF9772470297EBD, -396, -100 }, { 0xA6DFBD9FB8E5B88F, -369, -92 }, { 0xF8A95FCF88747D94, -343, -84 },
|
||||||
{0xB94470938FA89BCF, -316, -76}, {0x8A08F0F8BF0F156B, -289, -68}, {0xCDB02555653131B6, -263, -60}, {0x993FE2C6D07B7FAC, -236, -52},
|
{ 0xB94470938FA89BCF, -316, -76 }, { 0x8A08F0F8BF0F156B, -289, -68 }, { 0xCDB02555653131B6, -263, -60 }, { 0x993FE2C6D07B7FAC, -236, -52 },
|
||||||
{0xE45C10C42A2B3B06, -210, -44}, {0xAA242499697392D3, -183, -36}, {0xFD87B5F28300CA0E, -157, -28}, {0xBCE5086492111AEB, -130, -20},
|
{ 0xE45C10C42A2B3B06, -210, -44 }, { 0xAA242499697392D3, -183, -36 }, { 0xFD87B5F28300CA0E, -157, -28 }, { 0xBCE5086492111AEB, -130, -20 },
|
||||||
{0x8CBCCC096F5088CC, -103, -12}, {0xD1B71758E219652C, -77, -4}, {0x9C40000000000000, -50, 4}, {0xE8D4A51000000000, -24, 12},
|
{ 0x8CBCCC096F5088CC, -103, -12 }, { 0xD1B71758E219652C, -77, -4 }, { 0x9C40000000000000, -50, 4 }, { 0xE8D4A51000000000, -24, 12 },
|
||||||
{0xAD78EBC5AC620000, 3, 20}, {0x813F3978F8940984, 30, 28}, {0xC097CE7BC90715B3, 56, 36}, {0x8F7E32CE7BEA5C70, 83, 44},
|
{ 0xAD78EBC5AC620000, 3, 20 }, { 0x813F3978F8940984, 30, 28 }, { 0xC097CE7BC90715B3, 56, 36 }, { 0x8F7E32CE7BEA5C70, 83, 44 },
|
||||||
{0xD5D238A4ABE98068, 109, 52}, {0x9F4F2726179A2245, 136, 60}, {0xED63A231D4C4FB27, 162, 68}, {0xB0DE65388CC8ADA8, 189, 76},
|
{ 0xD5D238A4ABE98068, 109, 52 }, { 0x9F4F2726179A2245, 136, 60 }, { 0xED63A231D4C4FB27, 162, 68 }, { 0xB0DE65388CC8ADA8, 189, 76 },
|
||||||
{0x83C7088E1AAB65DB, 216, 84}, {0xC45D1DF942711D9A, 242, 92}, {0x924D692CA61BE758, 269, 100}, {0xDA01EE641A708DEA, 295, 108},
|
{ 0x83C7088E1AAB65DB, 216, 84 }, { 0xC45D1DF942711D9A, 242, 92 }, { 0x924D692CA61BE758, 269, 100 }, { 0xDA01EE641A708DEA, 295, 108 },
|
||||||
{0xA26DA3999AEF774A, 322, 116}, {0xF209787BB47D6B85, 348, 124}, {0xB454E4A179DD1877, 375, 132}, {0x865B86925B9BC5C2, 402, 140},
|
{ 0xA26DA3999AEF774A, 322, 116 }, { 0xF209787BB47D6B85, 348, 124 }, { 0xB454E4A179DD1877, 375, 132 }, { 0x865B86925B9BC5C2, 402, 140 },
|
||||||
{0xC83553C5C8965D3D, 428, 148}, {0x952AB45CFA97A0B3, 455, 156}, {0xDE469FBD99A05FE3, 481, 164}, {0xA59BC234DB398C25, 508, 172},
|
{ 0xC83553C5C8965D3D, 428, 148 }, { 0x952AB45CFA97A0B3, 455, 156 }, { 0xDE469FBD99A05FE3, 481, 164 }, { 0xA59BC234DB398C25, 508, 172 },
|
||||||
{0xF6C69A72A3989F5C, 534, 180}, {0xB7DCBF5354E9BECE, 561, 188}, {0x88FCF317F22241E2, 588, 196}, {0xCC20CE9BD35C78A5, 614, 204},
|
{ 0xF6C69A72A3989F5C, 534, 180 }, { 0xB7DCBF5354E9BECE, 561, 188 }, { 0x88FCF317F22241E2, 588, 196 }, { 0xCC20CE9BD35C78A5, 614, 204 },
|
||||||
{0x98165AF37B2153DF, 641, 212}, {0xE2A0B5DC971F303A, 667, 220}, {0xA8D9D1535CE3B396, 694, 228}, {0xFB9B7CD9A4A7443C, 720, 236},
|
{ 0x98165AF37B2153DF, 641, 212 }, { 0xE2A0B5DC971F303A, 667, 220 }, { 0xA8D9D1535CE3B396, 694, 228 }, { 0xFB9B7CD9A4A7443C, 720, 236 },
|
||||||
{0xBB764C4CA7A44410, 747, 244}, {0x8BAB8EEFB6409C1A, 774, 252}, {0xD01FEF10A657842C, 800, 260}, {0x9B10A4E5E9913129, 827, 268},
|
{ 0xBB764C4CA7A44410, 747, 244 }, { 0x8BAB8EEFB6409C1A, 774, 252 }, { 0xD01FEF10A657842C, 800, 260 }, { 0x9B10A4E5E9913129, 827, 268 },
|
||||||
{0xE7109BFBA19C0C9D, 853, 276}, {0xAC2820D9623BF429, 880, 284}, {0x80444B5E7AA7CF85, 907, 292}, {0xBF21E44003ACDD2D, 933, 300},
|
{ 0xE7109BFBA19C0C9D, 853, 276 }, { 0xAC2820D9623BF429, 880, 284 }, { 0x80444B5E7AA7CF85, 907, 292 }, { 0xBF21E44003ACDD2D, 933, 300 },
|
||||||
{0x8E679C2F5E44FF8F, 960, 308}, {0xD433179D9C8CB841, 986, 316}, {0x9E19DB92B4E31BA9, 1013, 324},
|
{ 0x8E679C2F5E44FF8F, 960, 308 }, { 0xD433179D9C8CB841, 986, 316 }, { 0x9E19DB92B4E31BA9, 1013, 324 },
|
||||||
}};
|
} };
|
||||||
|
|
||||||
// This computation gives exactly the same results for k as
|
// This computation gives exactly the same results for k as
|
||||||
// k = ceil((kAlpha - e - 1) * 0.30102999566398114)
|
// 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 ) * 2^-e + (p2 )) * 2^e
|
||||||
// = p1 + 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.)
|
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
|
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:
|
// Note:
|
||||||
// Since rest and delta share the same exponent e, it suffices to
|
// Since rest and delta share the same exponent e, it suffices to
|
||||||
// compare the significands.
|
// 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)
|
if (rest <= delta)
|
||||||
{
|
{
|
||||||
// V = buffer * 10^n, with M- <= V <= M+.
|
// 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
|
// 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);
|
grisu2_round(buffer, length, dist, delta, rest, ten_n);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
@ -392,20 +392,20 @@ template<typename BasicJsonType,
|
|||||||
enable_if_t<std::is_constructible<BasicJsonType, T1>::value && std::is_constructible<BasicJsonType, T2>::value, int> = 0>
|
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)
|
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
|
// 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>
|
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)
|
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>
|
template<typename BasicJsonType, typename Tuple, std::size_t... Idx>
|
||||||
inline void to_json_tuple_impl(BasicJsonType& j, const Tuple& t, index_sequence<Idx...> /*unused*/)
|
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>
|
template<typename BasicJsonType, typename T, enable_if_t<is_constructible_tuple<BasicJsonType, T>::value, int> = 0>
|
||||||
|
@ -51,8 +51,8 @@ class exception : public std::exception
|
|||||||
JSON_HEDLEY_NON_NULL(3)
|
JSON_HEDLEY_NON_NULL(3)
|
||||||
exception(int id_, const char* what_arg)
|
exception(int id_, const char* what_arg)
|
||||||
: id(id_)
|
: id(id_)
|
||||||
, m(what_arg)
|
, m(what_arg) // NOLINT(bugprone-throw-keyword-missing)
|
||||||
{} // NOLINT(bugprone-throw-keyword-missing)
|
{}
|
||||||
|
|
||||||
static std::string name(const std::string& ename, int id_)
|
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)
|
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);
|
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>
|
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),
|
exception::diagnostics(context),
|
||||||
what_arg);
|
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)
|
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);
|
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:
|
private:
|
||||||
@ -216,7 +216,7 @@ class type_error : public exception
|
|||||||
static type_error create(int id_, const std::string& what_arg, BasicJsonContext context)
|
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);
|
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:
|
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)
|
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);
|
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:
|
private:
|
||||||
@ -254,7 +254,7 @@ class other_error : public exception
|
|||||||
static other_error create(int id_, const std::string& what_arg, BasicJsonContext context)
|
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);
|
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:
|
private:
|
||||||
|
@ -340,12 +340,12 @@ class binary_reader
|
|||||||
|
|
||||||
default: // anything else not supported (yet)
|
default: // anything else not supported (yet)
|
||||||
{
|
{
|
||||||
std::array<char, 3> cr{{}};
|
std::array<char, 3> cr{ {} };
|
||||||
static_cast<void>((std::snprintf)(cr.data(),
|
static_cast<void>((std::snprintf)(cr.data(), // NOLINT(cppcoreguidelines-pro-type-vararg,hicpp-vararg)
|
||||||
cr.size(),
|
cr.size(),
|
||||||
"%.2hhX",
|
"%.2hhX",
|
||||||
static_cast<unsigned char>(element_type))); // NOLINT(cppcoreguidelines-pro-type-vararg,hicpp-vararg)
|
static_cast<unsigned char>(element_type)));
|
||||||
const std::string cr_str{cr.data()};
|
const std::string cr_str{ cr.data() };
|
||||||
return sax->parse_error(element_type_parse_position,
|
return sax->parse_error(element_type_parse_position,
|
||||||
cr_str,
|
cr_str,
|
||||||
parse_error::create(114, element_type_parse_position, concat("Unsupported BSON record type 0x", cr_str), nullptr));
|
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::string get_token_string() const
|
||||||
{
|
{
|
||||||
std::array<char, 3> cr{{}};
|
std::array<char, 3> cr{ {} };
|
||||||
static_cast<void>(
|
static_cast<void>(
|
||||||
(std::snprintf)(cr.data(), cr.size(), "%.2hhX", static_cast<unsigned char>(current))); // NOLINT(cppcoreguidelines-pro-type-vararg,hicpp-vararg)
|
(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,22 +3041,22 @@ 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_OPTIMIZED_TYPE_MARKERS_ make_array<char_int_type>('F', 'H', 'N', 'S', 'T', 'Z', '[', '{')
|
||||||
|
|
||||||
#define JSON_BINARY_READER_MAKE_BJD_TYPES_MAP_ \
|
#define JSON_BINARY_READER_MAKE_BJD_TYPES_MAP_ \
|
||||||
make_array<bjd_type>(bjd_type{'C', "char"}, \
|
make_array<bjd_type>(bjd_type{ 'C', "char" }, \
|
||||||
bjd_type{'D', "double"}, \
|
bjd_type{ 'D', "double" }, \
|
||||||
bjd_type{'I', "int16"}, \
|
bjd_type{ 'I', "int16" }, \
|
||||||
bjd_type{'L', "int64"}, \
|
bjd_type{ 'L', "int64" }, \
|
||||||
bjd_type{'M', "uint64"}, \
|
bjd_type{ 'M', "uint64" }, \
|
||||||
bjd_type{'U', "uint8"}, \
|
bjd_type{ 'U', "uint8" }, \
|
||||||
bjd_type{'d', "single"}, \
|
bjd_type{ 'd', "single" }, \
|
||||||
bjd_type{'i', "int8"}, \
|
bjd_type{ 'i', "int8" }, \
|
||||||
bjd_type{'l', "int32"}, \
|
bjd_type{ 'l', "int32" }, \
|
||||||
bjd_type{'m', "uint32"}, \
|
bjd_type{ 'm', "uint32" }, \
|
||||||
bjd_type{'u', "uint16"})
|
bjd_type{ 'u', "uint16" })
|
||||||
|
|
||||||
JSON_PRIVATE_UNLESS_TESTED :
|
JSON_PRIVATE_UNLESS_TESTED :
|
||||||
// lookup tables
|
// lookup tables
|
||||||
// NOLINTNEXTLINE(cppcoreguidelines-non-private-member-variables-in-classes)
|
// NOLINTNEXTLINE(cppcoreguidelines-non-private-member-variables-in-classes)
|
||||||
const decltype(JSON_BINARY_READER_MAKE_BJD_OPTIMIZED_TYPE_MARKERS_) bjd_optimized_type_markers = JSON_BINARY_READER_MAKE_BJD_OPTIMIZED_TYPE_MARKERS_;
|
const decltype(JSON_BINARY_READER_MAKE_BJD_OPTIMIZED_TYPE_MARKERS_) bjd_optimized_type_markers = JSON_BINARY_READER_MAKE_BJD_OPTIMIZED_TYPE_MARKERS_;
|
||||||
|
|
||||||
using bjd_type = std::pair<char_int_type, string_t>;
|
using bjd_type = std::pair<char_int_type, string_t>;
|
||||||
// NOLINTNEXTLINE(cppcoreguidelines-non-private-member-variables-in-classes)
|
// NOLINTNEXTLINE(cppcoreguidelines-non-private-member-variables-in-classes)
|
||||||
|
@ -338,7 +338,7 @@ class wide_string_input_adapter
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// a buffer for UTF-8 bytes
|
/// 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
|
/// index to the utf8_codes array for the next valid byte
|
||||||
std::size_t utf8_bytes_index = 0;
|
std::size_t utf8_bytes_index = 0;
|
||||||
|
@ -568,7 +568,7 @@ class json_sax_dom_callback_parser
|
|||||||
// container
|
// container
|
||||||
if (!keep_stack.back())
|
if (!keep_stack.back())
|
||||||
{
|
{
|
||||||
return {false, nullptr};
|
return { false, nullptr };
|
||||||
}
|
}
|
||||||
|
|
||||||
// create value
|
// 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
|
// do not handle this value if we just learnt it shall be discarded
|
||||||
if (!keep)
|
if (!keep)
|
||||||
{
|
{
|
||||||
return {false, nullptr};
|
return { false, nullptr };
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ref_stack.empty())
|
if (ref_stack.empty())
|
||||||
{
|
{
|
||||||
root = std::move(value);
|
root = std::move(value);
|
||||||
return {true, &root};
|
return { true, &root };
|
||||||
}
|
}
|
||||||
|
|
||||||
// skip this value if we already decided to skip the parent
|
// skip this value if we already decided to skip the parent
|
||||||
// (https://github.com/nlohmann/json/issues/971#issuecomment-413678360)
|
// (https://github.com/nlohmann/json/issues/971#issuecomment-413678360)
|
||||||
if (!ref_stack.back())
|
if (!ref_stack.back())
|
||||||
{
|
{
|
||||||
return {false, nullptr};
|
return { false, nullptr };
|
||||||
}
|
}
|
||||||
|
|
||||||
// we now only expect arrays and objects
|
// we now only expect arrays and objects
|
||||||
@ -603,7 +603,7 @@ class json_sax_dom_callback_parser
|
|||||||
if (ref_stack.back()->is_array())
|
if (ref_stack.back()->is_array())
|
||||||
{
|
{
|
||||||
ref_stack.back()->m_data.m_value.array->emplace_back(std::move(value));
|
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
|
// object
|
||||||
@ -615,12 +615,12 @@ class json_sax_dom_callback_parser
|
|||||||
|
|
||||||
if (!store_element)
|
if (!store_element)
|
||||||
{
|
{
|
||||||
return {false, nullptr};
|
return { false, nullptr };
|
||||||
}
|
}
|
||||||
|
|
||||||
JSON_ASSERT(object_element);
|
JSON_ASSERT(object_element);
|
||||||
*object_element = std::move(value);
|
*object_element = std::move(value);
|
||||||
return {true, object_element};
|
return { true, object_element };
|
||||||
}
|
}
|
||||||
|
|
||||||
/// the parsed JSON value
|
/// the parsed JSON value
|
||||||
|
@ -173,7 +173,7 @@ class lexer : public lexer_base<BasicJsonType>
|
|||||||
JSON_ASSERT(current == 'u');
|
JSON_ASSERT(current == 'u');
|
||||||
int codepoint = 0;
|
int codepoint = 0;
|
||||||
|
|
||||||
const auto factors = {12u, 8u, 4u, 0u};
|
const auto factors = { 12u, 8u, 4u, 0u };
|
||||||
for (const auto factor : factors)
|
for (const auto factor : factors)
|
||||||
{
|
{
|
||||||
get();
|
get();
|
||||||
@ -745,7 +745,7 @@ class lexer : public lexer_base<BasicJsonType>
|
|||||||
case 0xDE:
|
case 0xDE:
|
||||||
case 0xDF:
|
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;
|
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
|
// U+0800..U+0FFF: bytes E0 A0..BF 80..BF
|
||||||
case 0xE0:
|
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;
|
return token_type::parse_error;
|
||||||
}
|
}
|
||||||
@ -779,7 +779,7 @@ class lexer : public lexer_base<BasicJsonType>
|
|||||||
case 0xEE:
|
case 0xEE:
|
||||||
case 0xEF:
|
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;
|
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
|
// U+D000..U+D7FF: bytes ED 80..9F 80..BF
|
||||||
case 0xED:
|
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;
|
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
|
// U+10000..U+3FFFF F0 90..BF 80..BF 80..BF
|
||||||
case 0xF0:
|
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;
|
return token_type::parse_error;
|
||||||
}
|
}
|
||||||
@ -811,7 +811,7 @@ class lexer : public lexer_base<BasicJsonType>
|
|||||||
case 0xF2:
|
case 0xF2:
|
||||||
case 0xF3:
|
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;
|
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
|
// U+100000..U+10FFFF F4 80..8F 80..BF 80..BF
|
||||||
case 0xF4:
|
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;
|
return token_type::parse_error;
|
||||||
}
|
}
|
||||||
@ -1453,9 +1453,9 @@ scan_number_done:
|
|||||||
if (static_cast<unsigned char>(c) <= '\x1F')
|
if (static_cast<unsigned char>(c) <= '\x1F')
|
||||||
{
|
{
|
||||||
// escape control characters
|
// escape control characters
|
||||||
std::array<char, 9> cs{{}};
|
std::array<char, 9> cs{ {} };
|
||||||
static_cast<void>((
|
static_cast<void>(( // NOLINT(cppcoreguidelines-pro-type-vararg,hicpp-vararg)
|
||||||
std::snprintf)(cs.data(), cs.size(), "<U+%.4X>", static_cast<unsigned char>(c))); // NOLINT(cppcoreguidelines-pro-type-vararg,hicpp-vararg)
|
std::snprintf)(cs.data(), cs.size(), "<U+%.4X>", static_cast<unsigned char>(c)));
|
||||||
result += cs.data();
|
result += cs.data();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -1549,22 +1549,24 @@ scan_number_done:
|
|||||||
case 't':
|
case 't':
|
||||||
{
|
{
|
||||||
std::array<char_type, 4> true_literal = {
|
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);
|
return scan_literal(true_literal.data(), true_literal.size(), token_type::literal_true);
|
||||||
}
|
}
|
||||||
case 'f':
|
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>('a'),
|
||||||
static_cast<char_type>('l'),
|
static_cast<char_type>('l'),
|
||||||
static_cast<char_type>('s'),
|
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);
|
return scan_literal(false_literal.data(), false_literal.size(), token_type::literal_false);
|
||||||
}
|
}
|
||||||
case 'n':
|
case 'n':
|
||||||
{
|
{
|
||||||
std::array<char_type, 4> null_literal = {
|
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);
|
return scan_literal(null_literal.data(), null_literal.size(), token_type::literal_null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -192,12 +192,11 @@ class iter_impl // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
|
|||||||
}
|
}
|
||||||
|
|
||||||
JSON_PRIVATE_UNLESS_TESTED :
|
JSON_PRIVATE_UNLESS_TESTED :
|
||||||
/*!
|
/*!
|
||||||
@brief set the iterator to the first value
|
@brief set the iterator to the first value
|
||||||
@pre The iterator is initialized; i.e. `m_object != nullptr`.
|
@pre The iterator is initialized; i.e. `m_object != nullptr`.
|
||||||
*/
|
*/
|
||||||
void
|
void set_begin() noexcept
|
||||||
set_begin() noexcept
|
|
||||||
{
|
{
|
||||||
JSON_ASSERT(m_object != nullptr);
|
JSON_ASSERT(m_object != nullptr);
|
||||||
|
|
||||||
@ -746,8 +745,8 @@ class iter_impl // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
|
|||||||
}
|
}
|
||||||
|
|
||||||
JSON_PRIVATE_UNLESS_TESTED :
|
JSON_PRIVATE_UNLESS_TESTED :
|
||||||
/// associated JSON instance
|
/// associated JSON instance
|
||||||
pointer m_object = nullptr;
|
pointer m_object = nullptr;
|
||||||
/// the actual iterator of the associated instance
|
/// the actual iterator of the associated instance
|
||||||
internal_iterator<typename std::remove_const<BasicJsonType>::type> m_it{};
|
internal_iterator<typename std::remove_const<BasicJsonType>::type> m_it{};
|
||||||
};
|
};
|
||||||
|
@ -34,8 +34,8 @@ class primitive_iterator_t
|
|||||||
static constexpr difference_type end_value = begin_value + 1;
|
static constexpr difference_type end_value = begin_value + 1;
|
||||||
|
|
||||||
JSON_PRIVATE_UNLESS_TESTED :
|
JSON_PRIVATE_UNLESS_TESTED :
|
||||||
/// iterator as signed integer type
|
/// iterator as signed integer type
|
||||||
difference_type m_it = (std::numeric_limits<std::ptrdiff_t>::min)();
|
difference_type m_it = (std::numeric_limits<std::ptrdiff_t>::min)();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
constexpr difference_type get_value() const noexcept
|
constexpr difference_type get_value() const noexcept
|
||||||
|
@ -242,7 +242,8 @@ class json_pointer
|
|||||||
return static_cast<size_type>(res);
|
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()))
|
if (JSON_HEDLEY_UNLIKELY(empty()))
|
||||||
{
|
{
|
||||||
@ -250,7 +251,7 @@ class json_pointer
|
|||||||
}
|
}
|
||||||
|
|
||||||
json_pointer result = *this;
|
json_pointer result = *this;
|
||||||
result.reference_tokens = {reference_tokens[0]};
|
result.reference_tokens = { reference_tokens[0] };
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -167,7 +167,7 @@ constexpr T static_const<T>::value;
|
|||||||
template<typename T, typename... Args>
|
template<typename T, typename... Args>
|
||||||
inline constexpr std::array<T, sizeof...(Args)> make_array(Args&&... 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
|
} // namespace detail
|
||||||
|
@ -789,7 +789,7 @@ class binary_writer
|
|||||||
return ubjson_prefix(v, use_bjdata) == first_prefix;
|
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()))
|
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;
|
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()))
|
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)
|
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'},
|
std::map<string_t, CharType> bjdtype = { { "uint8", 'U' }, { "int8", 'i' }, { "uint16", 'u' }, { "int16", 'I' }, { "uint32", 'm' }, { "int32", 'l' },
|
||||||
{"int8", 'i'},
|
{ "uint64", 'M' }, { "int64", 'L' }, { "single", 'd' }, { "double", 'D' }, { "char", 'C' } };
|
||||||
{"uint16", 'u'},
|
|
||||||
{"int16", 'I'},
|
|
||||||
{"uint32", 'm'},
|
|
||||||
{"int32", 'l'},
|
|
||||||
{"uint64", 'M'},
|
|
||||||
{"int64", 'L'},
|
|
||||||
{"single", 'd'},
|
|
||||||
{"double", 'D'},
|
|
||||||
{"char", 'C'}};
|
|
||||||
|
|
||||||
string_t key = "_ArrayType_";
|
string_t key = "_ArrayType_";
|
||||||
auto it = bjdtype.find(static_cast<string_t>(value.at(key)));
|
auto it = bjdtype.find(static_cast<string_t>(value.at(key)));
|
||||||
|
@ -365,7 +365,7 @@ class serializer
|
|||||||
}
|
}
|
||||||
|
|
||||||
JSON_PRIVATE_UNLESS_TESTED :
|
JSON_PRIVATE_UNLESS_TESTED :
|
||||||
/*!
|
/*!
|
||||||
@brief dump escaped string
|
@brief dump escaped string
|
||||||
|
|
||||||
Escape a string by replacing certain special characters by a sequence of an
|
Escape a string by replacing certain special characters by a sequence of an
|
||||||
@ -379,8 +379,7 @@ class serializer
|
|||||||
|
|
||||||
@complexity Linear in the length of string @a s.
|
@complexity Linear in the length of string @a s.
|
||||||
*/
|
*/
|
||||||
void
|
void dump_escaped(const string_t& s, const bool ensure_ascii)
|
||||||
dump_escaped(const string_t& s, const bool ensure_ascii)
|
|
||||||
{
|
{
|
||||||
std::uint32_t codepoint{};
|
std::uint32_t codepoint{};
|
||||||
std::uint8_t state = UTF8_ACCEPT;
|
std::uint8_t state = UTF8_ACCEPT;
|
||||||
@ -706,18 +705,21 @@ class serializer
|
|||||||
int> = 0>
|
int> = 0>
|
||||||
void dump_integer(NumberType x)
|
void dump_integer(NumberType x)
|
||||||
{
|
{
|
||||||
static constexpr std::array<std::array<char, 2>, 100> digits_to_99{{
|
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'}},
|
{ { '0', '0' } }, { { '0', '1' } }, { { '0', '2' } }, { { '0', '3' } }, { { '0', '4' } }, { { '0', '5' } }, { { '0', '6' } }, { { '0', '7' } },
|
||||||
{{'1', '0'}}, {{'1', '1'}}, {{'1', '2'}}, {{'1', '3'}}, {{'1', '4'}}, {{'1', '5'}}, {{'1', '6'}}, {{'1', '7'}}, {{'1', '8'}}, {{'1', '9'}},
|
{ { '0', '8' } }, { { '0', '9' } }, { { '1', '0' } }, { { '1', '1' } }, { { '1', '2' } }, { { '1', '3' } }, { { '1', '4' } }, { { '1', '5' } },
|
||||||
{{'2', '0'}}, {{'2', '1'}}, {{'2', '2'}}, {{'2', '3'}}, {{'2', '4'}}, {{'2', '5'}}, {{'2', '6'}}, {{'2', '7'}}, {{'2', '8'}}, {{'2', '9'}},
|
{ { '1', '6' } }, { { '1', '7' } }, { { '1', '8' } }, { { '1', '9' } }, { { '2', '0' } }, { { '2', '1' } }, { { '2', '2' } }, { { '2', '3' } },
|
||||||
{{'3', '0'}}, {{'3', '1'}}, {{'3', '2'}}, {{'3', '3'}}, {{'3', '4'}}, {{'3', '5'}}, {{'3', '6'}}, {{'3', '7'}}, {{'3', '8'}}, {{'3', '9'}},
|
{ { '2', '4' } }, { { '2', '5' } }, { { '2', '6' } }, { { '2', '7' } }, { { '2', '8' } }, { { '2', '9' } }, { { '3', '0' } }, { { '3', '1' } },
|
||||||
{{'4', '0'}}, {{'4', '1'}}, {{'4', '2'}}, {{'4', '3'}}, {{'4', '4'}}, {{'4', '5'}}, {{'4', '6'}}, {{'4', '7'}}, {{'4', '8'}}, {{'4', '9'}},
|
{ { '3', '2' } }, { { '3', '3' } }, { { '3', '4' } }, { { '3', '5' } }, { { '3', '6' } }, { { '3', '7' } }, { { '3', '8' } }, { { '3', '9' } },
|
||||||
{{'5', '0'}}, {{'5', '1'}}, {{'5', '2'}}, {{'5', '3'}}, {{'5', '4'}}, {{'5', '5'}}, {{'5', '6'}}, {{'5', '7'}}, {{'5', '8'}}, {{'5', '9'}},
|
{ { '4', '0' } }, { { '4', '1' } }, { { '4', '2' } }, { { '4', '3' } }, { { '4', '4' } }, { { '4', '5' } }, { { '4', '6' } }, { { '4', '7' } },
|
||||||
{{'6', '0'}}, {{'6', '1'}}, {{'6', '2'}}, {{'6', '3'}}, {{'6', '4'}}, {{'6', '5'}}, {{'6', '6'}}, {{'6', '7'}}, {{'6', '8'}}, {{'6', '9'}},
|
{ { '4', '8' } }, { { '4', '9' } }, { { '5', '0' } }, { { '5', '1' } }, { { '5', '2' } }, { { '5', '3' } }, { { '5', '4' } }, { { '5', '5' } },
|
||||||
{{'7', '0'}}, {{'7', '1'}}, {{'7', '2'}}, {{'7', '3'}}, {{'7', '4'}}, {{'7', '5'}}, {{'7', '6'}}, {{'7', '7'}}, {{'7', '8'}}, {{'7', '9'}},
|
{ { '5', '6' } }, { { '5', '7' } }, { { '5', '8' } }, { { '5', '9' } }, { { '6', '0' } }, { { '6', '1' } }, { { '6', '2' } }, { { '6', '3' } },
|
||||||
{{'8', '0'}}, {{'8', '1'}}, {{'8', '2'}}, {{'8', '3'}}, {{'8', '4'}}, {{'8', '5'}}, {{'8', '6'}}, {{'8', '7'}}, {{'8', '8'}}, {{'8', '9'}},
|
{ { '6', '4' } }, { { '6', '5' } }, { { '6', '6' } }, { { '6', '7' } }, { { '6', '8' } }, { { '6', '9' } }, { { '7', '0' } }, { { '7', '1' } },
|
||||||
{{'9', '0'}}, {{'9', '1'}}, {{'9', '2'}}, {{'9', '3'}}, {{'9', '4'}}, {{'9', '5'}}, {{'9', '6'}}, {{'9', '7'}}, {{'9', '8'}}, {{'9', '9'}},
|
{ { '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"
|
// special case for "0"
|
||||||
if (x == 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 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, 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, // 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,
|
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, // 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, 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
|
1 // s7..s8
|
||||||
}};
|
} };
|
||||||
|
|
||||||
JSON_ASSERT(byte < utf8d.size());
|
JSON_ASSERT(byte < utf8d.size());
|
||||||
const std::uint8_t type = utf8d[byte];
|
const std::uint8_t type = utf8d[byte];
|
||||||
@ -960,7 +962,7 @@ class serializer
|
|||||||
output_adapter_t<char> o = nullptr;
|
output_adapter_t<char> o = nullptr;
|
||||||
|
|
||||||
/// a (hopefully) large enough character buffer
|
/// a (hopefully) large enough character buffer
|
||||||
std::array<char, 64> number_buffer{{}};
|
std::array<char, 64> number_buffer{ {} };
|
||||||
|
|
||||||
/// the locale
|
/// the locale
|
||||||
const std::lconv* loc = nullptr;
|
const std::lconv* loc = nullptr;
|
||||||
@ -970,7 +972,7 @@ class serializer
|
|||||||
const char decimal_point = '\0';
|
const char decimal_point = '\0';
|
||||||
|
|
||||||
/// string buffer
|
/// string buffer
|
||||||
std::array<char, 512> string_buffer{{}};
|
std::array<char, 512> string_buffer{ {} };
|
||||||
|
|
||||||
/// the indentation character
|
/// the indentation character
|
||||||
const char indent_char;
|
const char indent_char;
|
||||||
|
@ -48,8 +48,8 @@ inline void replace_substring(StringType& s, const StringType& f, const StringTy
|
|||||||
template<typename StringType>
|
template<typename StringType>
|
||||||
inline StringType escape(StringType s)
|
inline StringType escape(StringType s)
|
||||||
{
|
{
|
||||||
replace_substring(s, StringType{"~"}, StringType{"~0"});
|
replace_substring(s, StringType{ "~" }, StringType{ "~0" });
|
||||||
replace_substring(s, StringType{"/"}, StringType{"~1"});
|
replace_substring(s, StringType{ "/" }, StringType{ "~1" });
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -63,8 +63,8 @@ inline StringType escape(StringType s)
|
|||||||
template<typename StringType>
|
template<typename StringType>
|
||||||
static void unescape(StringType& s)
|
static void unescape(StringType& s)
|
||||||
{
|
{
|
||||||
replace_substring(s, StringType{"~1"}, StringType{"/"});
|
replace_substring(s, StringType{ "~1" }, StringType{ "/" });
|
||||||
replace_substring(s, StringType{"~0"}, StringType{"~"});
|
replace_substring(s, StringType{ "~0" }, StringType{ "~" });
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace detail
|
} // namespace detail
|
||||||
|
@ -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
|
inline bool operator<(const value_t lhs, const value_t rhs) noexcept
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
static constexpr std::array<std::uint8_t, 9> order = {{
|
static constexpr std::array<std::uint8_t, 9> order = { {
|
||||||
0 /* null */,
|
0 /* null */,
|
||||||
3 /* object */,
|
3 /* object */,
|
||||||
4 /* array */,
|
4 /* array */,
|
||||||
@ -93,7 +93,7 @@ inline bool operator<(const value_t lhs, const value_t rhs) noexcept
|
|||||||
2 /* unsigned */,
|
2 /* unsigned */,
|
||||||
2 /* float */,
|
2 /* float */,
|
||||||
6 /* binary */
|
6 /* binary */
|
||||||
}};
|
} };
|
||||||
|
|
||||||
const auto l_index = static_cast<std::size_t>(lhs);
|
const auto l_index = static_cast<std::size_t>(lhs);
|
||||||
const auto r_index = static_cast<std::size_t>(rhs);
|
const auto r_index = static_cast<std::size_t>(rhs);
|
||||||
|
@ -126,8 +126,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spe
|
|||||||
using json_base_class_t = ::nlohmann::detail::json_base_class<CustomBaseClass>;
|
using json_base_class_t = ::nlohmann::detail::json_base_class<CustomBaseClass>;
|
||||||
|
|
||||||
JSON_PRIVATE_UNLESS_TESTED :
|
JSON_PRIVATE_UNLESS_TESTED :
|
||||||
// convenience aliases for types residing in namespace detail;
|
// convenience aliases for types residing in namespace detail;
|
||||||
using lexer = ::nlohmann::detail::lexer_base<basic_json>;
|
using lexer = ::nlohmann::detail::lexer_base<basic_json>;
|
||||||
|
|
||||||
template<typename InputAdapterType>
|
template<typename InputAdapterType>
|
||||||
static ::nlohmann::detail::parser<basic_json, InputAdapterType>
|
static ::nlohmann::detail::parser<basic_json, InputAdapterType>
|
||||||
@ -155,7 +155,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spe
|
|||||||
template<typename CharType>
|
template<typename CharType>
|
||||||
using binary_writer = ::nlohmann::detail::binary_writer<basic_json, 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:
|
public:
|
||||||
using value_t = detail::value_t;
|
using value_t = detail::value_t;
|
||||||
@ -271,25 +272,25 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spe
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(__ICC) || defined(__INTEL_COMPILER)
|
#if defined(__ICC) || defined(__INTEL_COMPILER)
|
||||||
result["compiler"] = {{"family", "icc"}, { "version", __INTEL_COMPILER }};
|
result["compiler"] = { { "family", "icc" }, { "version", __INTEL_COMPILER } };
|
||||||
#elif defined(__clang__)
|
#elif defined(__clang__)
|
||||||
result["compiler"] = {{"family", "clang"}, { "version", __clang_version__ }};
|
result["compiler"] = { { "family", "clang" }, { "version", __clang_version__ } };
|
||||||
#elif defined(__GNUC__) || defined(__GNUG__)
|
#elif defined(__GNUC__) || defined(__GNUG__)
|
||||||
result["compiler"] = {{"family", "gcc"},
|
result["compiler"] = { { "family", "gcc" },
|
||||||
{ "version",
|
{ "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)
|
#elif defined(__HP_cc) || defined(__HP_aCC)
|
||||||
result["compiler"] = "hp"
|
result["compiler"] = "hp"
|
||||||
#elif defined(__IBMCPP__)
|
#elif defined(__IBMCPP__)
|
||||||
result["compiler"] = {{"family", "ilecpp"}, { "version", __IBMCPP__ }};
|
result["compiler"] = { { "family", "ilecpp" }, { "version", __IBMCPP__ } };
|
||||||
#elif defined(_MSC_VER)
|
#elif defined(_MSC_VER)
|
||||||
result["compiler"] = {{"family", "msvc"}, { "version", _MSC_VER }};
|
result["compiler"] = { { "family", "msvc" }, { "version", _MSC_VER } };
|
||||||
#elif defined(__PGI)
|
#elif defined(__PGI)
|
||||||
result["compiler"] = {{"family", "pgcpp"}, { "version", __PGI }};
|
result["compiler"] = { { "family", "pgcpp" }, { "version", __PGI } };
|
||||||
#elif defined(__SUNPRO_CC)
|
#elif defined(__SUNPRO_CC)
|
||||||
result["compiler"] = {{"family", "sunpro"}, { "version", __SUNPRO_CC }};
|
result["compiler"] = { { "family", "sunpro" }, { "version", __SUNPRO_CC } };
|
||||||
#else
|
#else
|
||||||
result["compiler"] = {{"family", "unknown"}, {"version", "unknown"}};
|
result["compiler"] = { { "family", "unknown" }, { "version", "unknown" } };
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(_MSVC_LANG)
|
#if defined(_MSVC_LANG)
|
||||||
@ -383,7 +384,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spe
|
|||||||
////////////////////////
|
////////////////////////
|
||||||
|
|
||||||
JSON_PRIVATE_UNLESS_TESTED :
|
JSON_PRIVATE_UNLESS_TESTED :
|
||||||
/*!
|
/*!
|
||||||
@brief a JSON value
|
@brief a JSON value
|
||||||
|
|
||||||
The actual storage for a JSON value of the @ref basic_json class. This
|
The actual storage for a JSON value of the @ref basic_json class. This
|
||||||
@ -408,7 +409,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spe
|
|||||||
|
|
||||||
@since version 1.0.0
|
@since version 1.0.0
|
||||||
*/
|
*/
|
||||||
union json_value
|
union json_value
|
||||||
{
|
{
|
||||||
/// object (stored with pointer to save storage)
|
/// object (stored with pointer to save storage)
|
||||||
object_t* object;
|
object_t* object;
|
||||||
@ -1022,7 +1023,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spe
|
|||||||
/// @brief construct an array with count copies of given value
|
/// @brief construct an array with count copies of given value
|
||||||
/// @sa https://json.nlohmann.me/api/basic_json/basic_json/
|
/// @sa https://json.nlohmann.me/api/basic_json/basic_json/
|
||||||
basic_json(size_type cnt, const basic_json& val)
|
basic_json(size_type cnt, const basic_json& val)
|
||||||
: m_data{cnt, val}
|
: m_data{ cnt, val }
|
||||||
{
|
{
|
||||||
set_parents();
|
set_parents();
|
||||||
assert_invariant();
|
assert_invariant();
|
||||||
@ -3210,7 +3211,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spe
|
|||||||
it.m_it.object_iterator = res.first;
|
it.m_it.object_iterator = res.first;
|
||||||
|
|
||||||
// return pair of iterator and boolean
|
// return pair of iterator and boolean
|
||||||
return {it, res.second};
|
return { it, res.second };
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Helper for insertion of an iterator
|
/// Helper for insertion of an iterator
|
||||||
@ -3599,13 +3600,12 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spe
|
|||||||
return (default_result);
|
return (default_result);
|
||||||
|
|
||||||
JSON_PRIVATE_UNLESS_TESTED :
|
JSON_PRIVATE_UNLESS_TESTED :
|
||||||
// returns true if:
|
// returns true if:
|
||||||
// - any operand is NaN and the other operand is of number type
|
// - any operand is NaN and the other operand is of number type
|
||||||
// - any operand is discarded
|
// - any operand is discarded
|
||||||
// in legacy mode, discarded values are considered ordered if
|
// in legacy mode, discarded values are considered ordered if
|
||||||
// an operation is computed as an odd number of inverses of others
|
// an operation is computed as an odd number of inverses of others
|
||||||
static bool
|
static bool compares_unordered(const_reference lhs, const_reference rhs, bool inverse = false) noexcept
|
||||||
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()) ||
|
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()))
|
(rhs.is_number_float() && std::isnan(rhs.m_data.m_value.number_float) && lhs.is_number()))
|
||||||
@ -4106,11 +4106,11 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spe
|
|||||||
}
|
}
|
||||||
|
|
||||||
JSON_PRIVATE_UNLESS_TESTED :
|
JSON_PRIVATE_UNLESS_TESTED :
|
||||||
//////////////////////
|
//////////////////////
|
||||||
// member variables //
|
// member variables //
|
||||||
//////////////////////
|
//////////////////////
|
||||||
|
|
||||||
struct data
|
struct data
|
||||||
{
|
{
|
||||||
/// the type of the current element
|
/// the type of the current element
|
||||||
value_t m_type = value_t::null;
|
value_t m_type = value_t::null;
|
||||||
@ -4872,7 +4872,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spe
|
|||||||
if (source.type() != target.type())
|
if (source.type() != target.type())
|
||||||
{
|
{
|
||||||
// different types: replace value
|
// different types: replace value
|
||||||
result.push_back({{"op", "replace"}, {"path", path}, {"value", target}});
|
result.push_back({ { "op", "replace" }, { "path", path }, { "value", target } });
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -4899,14 +4899,14 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spe
|
|||||||
{
|
{
|
||||||
// add operations in reverse order to avoid invalid
|
// add operations in reverse order to avoid invalid
|
||||||
// indices
|
// 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;
|
++i;
|
||||||
}
|
}
|
||||||
|
|
||||||
// add other remaining elements
|
// add other remaining elements
|
||||||
while (i < target.size())
|
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;
|
++i;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -4930,7 +4930,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spe
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
// found a key that is not in o -> remove it
|
// 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
|
// found a key that is not in this -> add it
|
||||||
const auto path_key = detail::concat(path, '/', detail::escape(it.key()));
|
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:
|
default:
|
||||||
{
|
{
|
||||||
// both primitive type: replace value
|
// both primitive type: replace value
|
||||||
result.push_back({{"op", "replace"}, {"path", path}, {"value", target}});
|
result.push_back({ { "op", "replace" }, { "path", path }, { "value", target } });
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -46,14 +46,14 @@ struct ordered_map : std::vector<std::pair<const Key, T>, Allocator>
|
|||||||
: Container{}
|
: Container{}
|
||||||
{}
|
{}
|
||||||
explicit ordered_map(const Allocator& alloc) noexcept(noexcept(Container(alloc)))
|
explicit ordered_map(const Allocator& alloc) noexcept(noexcept(Container(alloc)))
|
||||||
: Container{alloc}
|
: Container{ alloc }
|
||||||
{}
|
{}
|
||||||
template<class It>
|
template<class It>
|
||||||
ordered_map(It first, It last, const Allocator& alloc = Allocator())
|
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())
|
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)
|
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))
|
if (m_compare(it->first, key))
|
||||||
{
|
{
|
||||||
return {it, false};
|
return { it, false };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Container::emplace_back(key, std::forward<T>(t));
|
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>
|
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))
|
if (m_compare(it->first, key))
|
||||||
{
|
{
|
||||||
return {it, false};
|
return { it, false };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Container::emplace_back(std::forward<KeyType>(key), std::forward<T>(t));
|
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)
|
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)
|
for (auto next = it; ++next != this->end(); ++it)
|
||||||
{
|
{
|
||||||
it->~value_type(); // Destroy but keep allocation
|
it->~value_type(); // Destroy but keep allocation
|
||||||
new (&*it) value_type{std::move(*next)};
|
new (&*it) value_type{ std::move(*next) };
|
||||||
}
|
}
|
||||||
Container::pop_back();
|
Container::pop_back();
|
||||||
return 1;
|
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)
|
for (auto next = it; ++next != this->end(); ++it)
|
||||||
{
|
{
|
||||||
it->~value_type(); // Destroy but keep allocation
|
it->~value_type(); // Destroy but keep allocation
|
||||||
new (&*it) value_type{std::move(*next)};
|
new (&*it) value_type{ std::move(*next) };
|
||||||
}
|
}
|
||||||
Container::pop_back();
|
Container::pop_back();
|
||||||
return 1;
|
return 1;
|
||||||
@ -235,8 +235,8 @@ struct ordered_map : std::vector<std::pair<const Key, T>, Allocator>
|
|||||||
|
|
||||||
for (auto it = first; std::next(it, elements_affected) != Container::end(); ++it)
|
for (auto it = first; std::next(it, elements_affected) != Container::end(); ++it)
|
||||||
{
|
{
|
||||||
it->~value_type(); // destroy but keep allocation
|
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 ]
|
// [ 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))
|
if (m_compare(it->first, value.first))
|
||||||
{
|
{
|
||||||
return {it, false};
|
return { it, false };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Container::push_back(value);
|
Container::push_back(value);
|
||||||
return {--this->end(), true};
|
return { --this->end(), true };
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename InputIt>
|
template<typename InputIt>
|
||||||
|
@ -213,6 +213,7 @@ NLOHMANN_JSON_NAMESPACE_END
|
|||||||
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>
|
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>
|
||||||
// SPDX-License-Identifier: MIT
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
#include <utility> // declval, pair
|
||||||
// #include <nlohmann/detail/meta/detected.hpp>
|
// #include <nlohmann/detail/meta/detected.hpp>
|
||||||
// __ _____ _____ _____
|
// __ _____ _____ _____
|
||||||
// __| | __| | | | JSON for Modern C++
|
// __| | __| | | | JSON for Modern C++
|
||||||
@ -2024,8 +2025,6 @@ JSON_HEDLEY_DIAGNOSTIC_POP
|
|||||||
|
|
||||||
#endif /* !defined(JSON_HEDLEY_VERSION) || (JSON_HEDLEY_VERSION < X) */
|
#endif /* !defined(JSON_HEDLEY_VERSION) || (JSON_HEDLEY_VERSION < X) */
|
||||||
|
|
||||||
#include <utility> // declval, pair
|
|
||||||
|
|
||||||
// This file contains all internal macro definitions (except those affecting ABI)
|
// 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
|
// 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>
|
template<typename T, typename... Args>
|
||||||
inline constexpr std::array<T, sizeof...(Args)> make_array(Args&&... 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
|
} // namespace detail
|
||||||
@ -7272,8 +7271,8 @@ inline void replace_substring(StringType& s, const StringType& f, const StringTy
|
|||||||
template<typename StringType>
|
template<typename StringType>
|
||||||
inline StringType escape(StringType s)
|
inline StringType escape(StringType s)
|
||||||
{
|
{
|
||||||
replace_substring(s, StringType{"~"}, StringType{"~0"});
|
replace_substring(s, StringType{ "~" }, StringType{ "~0" });
|
||||||
replace_substring(s, StringType{"/"}, StringType{"~1"});
|
replace_substring(s, StringType{ "/" }, StringType{ "~1" });
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -7287,8 +7286,8 @@ inline StringType escape(StringType s)
|
|||||||
template<typename StringType>
|
template<typename StringType>
|
||||||
static void unescape(StringType& s)
|
static void unescape(StringType& s)
|
||||||
{
|
{
|
||||||
replace_substring(s, StringType{"~1"}, StringType{"/"});
|
replace_substring(s, StringType{ "~1" }, StringType{ "/" });
|
||||||
replace_substring(s, StringType{"~0"}, StringType{"~"});
|
replace_substring(s, StringType{ "~0" }, StringType{ "~" });
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace detail
|
} // 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
|
inline bool operator<(const value_t lhs, const value_t rhs) noexcept
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
static constexpr std::array<std::uint8_t, 9> order = {{
|
static constexpr std::array<std::uint8_t, 9> order = { {
|
||||||
0 /* null */,
|
0 /* null */,
|
||||||
3 /* object */,
|
3 /* object */,
|
||||||
4 /* array */,
|
4 /* array */,
|
||||||
@ -7389,7 +7388,7 @@ inline bool operator<(const value_t lhs, const value_t rhs) noexcept
|
|||||||
2 /* unsigned */,
|
2 /* unsigned */,
|
||||||
2 /* float */,
|
2 /* float */,
|
||||||
6 /* binary */
|
6 /* binary */
|
||||||
}};
|
} };
|
||||||
|
|
||||||
const auto l_index = static_cast<std::size_t>(lhs);
|
const auto l_index = static_cast<std::size_t>(lhs);
|
||||||
const auto r_index = static_cast<std::size_t>(rhs);
|
const auto r_index = static_cast<std::size_t>(rhs);
|
||||||
@ -7444,8 +7443,8 @@ class exception : public std::exception
|
|||||||
JSON_HEDLEY_NON_NULL(3)
|
JSON_HEDLEY_NON_NULL(3)
|
||||||
exception(int id_, const char* what_arg)
|
exception(int id_, const char* what_arg)
|
||||||
: id(id_)
|
: id(id_)
|
||||||
, m(what_arg)
|
, m(what_arg) // NOLINT(bugprone-throw-keyword-missing)
|
||||||
{} // NOLINT(bugprone-throw-keyword-missing)
|
{}
|
||||||
|
|
||||||
static std::string name(const std::string& ename, int id_)
|
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)
|
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);
|
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>
|
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),
|
exception::diagnostics(context),
|
||||||
what_arg);
|
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)
|
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);
|
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:
|
private:
|
||||||
@ -7609,7 +7608,7 @@ class type_error : public exception
|
|||||||
static type_error create(int id_, const std::string& what_arg, BasicJsonContext context)
|
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);
|
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:
|
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)
|
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);
|
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:
|
private:
|
||||||
@ -7647,7 +7646,7 @@ class other_error : public exception
|
|||||||
static other_error create(int id_, const std::string& what_arg, BasicJsonContext context)
|
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);
|
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:
|
private:
|
||||||
@ -7945,7 +7944,7 @@ template<typename BasicJsonType, typename T, std::size_t... Idx>
|
|||||||
std::array<T, sizeof...(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*/)
|
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>
|
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>
|
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*/)
|
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>
|
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>
|
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)
|
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
|
// 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>
|
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)
|
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>
|
template<typename BasicJsonType, typename Tuple, std::size_t... Idx>
|
||||||
inline void to_json_tuple_impl(BasicJsonType& j, const Tuple& t, index_sequence<Idx...> /*unused*/)
|
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>
|
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
|
/// 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
|
/// index to the utf8_codes array for the next valid byte
|
||||||
std::size_t utf8_bytes_index = 0;
|
std::size_t utf8_bytes_index = 0;
|
||||||
@ -10233,7 +10232,7 @@ class json_sax_dom_callback_parser
|
|||||||
// container
|
// container
|
||||||
if (!keep_stack.back())
|
if (!keep_stack.back())
|
||||||
{
|
{
|
||||||
return {false, nullptr};
|
return { false, nullptr };
|
||||||
}
|
}
|
||||||
|
|
||||||
// create value
|
// 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
|
// do not handle this value if we just learnt it shall be discarded
|
||||||
if (!keep)
|
if (!keep)
|
||||||
{
|
{
|
||||||
return {false, nullptr};
|
return { false, nullptr };
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ref_stack.empty())
|
if (ref_stack.empty())
|
||||||
{
|
{
|
||||||
root = std::move(value);
|
root = std::move(value);
|
||||||
return {true, &root};
|
return { true, &root };
|
||||||
}
|
}
|
||||||
|
|
||||||
// skip this value if we already decided to skip the parent
|
// skip this value if we already decided to skip the parent
|
||||||
// (https://github.com/nlohmann/json/issues/971#issuecomment-413678360)
|
// (https://github.com/nlohmann/json/issues/971#issuecomment-413678360)
|
||||||
if (!ref_stack.back())
|
if (!ref_stack.back())
|
||||||
{
|
{
|
||||||
return {false, nullptr};
|
return { false, nullptr };
|
||||||
}
|
}
|
||||||
|
|
||||||
// we now only expect arrays and objects
|
// we now only expect arrays and objects
|
||||||
@ -10268,7 +10267,7 @@ class json_sax_dom_callback_parser
|
|||||||
if (ref_stack.back()->is_array())
|
if (ref_stack.back()->is_array())
|
||||||
{
|
{
|
||||||
ref_stack.back()->m_data.m_value.array->emplace_back(std::move(value));
|
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
|
// object
|
||||||
@ -10280,12 +10279,12 @@ class json_sax_dom_callback_parser
|
|||||||
|
|
||||||
if (!store_element)
|
if (!store_element)
|
||||||
{
|
{
|
||||||
return {false, nullptr};
|
return { false, nullptr };
|
||||||
}
|
}
|
||||||
|
|
||||||
JSON_ASSERT(object_element);
|
JSON_ASSERT(object_element);
|
||||||
*object_element = std::move(value);
|
*object_element = std::move(value);
|
||||||
return {true, object_element};
|
return { true, object_element };
|
||||||
}
|
}
|
||||||
|
|
||||||
/// the parsed JSON value
|
/// the parsed JSON value
|
||||||
@ -10564,7 +10563,7 @@ class lexer : public lexer_base<BasicJsonType>
|
|||||||
JSON_ASSERT(current == 'u');
|
JSON_ASSERT(current == 'u');
|
||||||
int codepoint = 0;
|
int codepoint = 0;
|
||||||
|
|
||||||
const auto factors = {12u, 8u, 4u, 0u};
|
const auto factors = { 12u, 8u, 4u, 0u };
|
||||||
for (const auto factor : factors)
|
for (const auto factor : factors)
|
||||||
{
|
{
|
||||||
get();
|
get();
|
||||||
@ -11136,7 +11135,7 @@ class lexer : public lexer_base<BasicJsonType>
|
|||||||
case 0xDE:
|
case 0xDE:
|
||||||
case 0xDF:
|
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;
|
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
|
// U+0800..U+0FFF: bytes E0 A0..BF 80..BF
|
||||||
case 0xE0:
|
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;
|
return token_type::parse_error;
|
||||||
}
|
}
|
||||||
@ -11170,7 +11169,7 @@ class lexer : public lexer_base<BasicJsonType>
|
|||||||
case 0xEE:
|
case 0xEE:
|
||||||
case 0xEF:
|
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;
|
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
|
// U+D000..U+D7FF: bytes ED 80..9F 80..BF
|
||||||
case 0xED:
|
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;
|
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
|
// U+10000..U+3FFFF F0 90..BF 80..BF 80..BF
|
||||||
case 0xF0:
|
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;
|
return token_type::parse_error;
|
||||||
}
|
}
|
||||||
@ -11202,7 +11201,7 @@ class lexer : public lexer_base<BasicJsonType>
|
|||||||
case 0xF2:
|
case 0xF2:
|
||||||
case 0xF3:
|
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;
|
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
|
// U+100000..U+10FFFF F4 80..8F 80..BF 80..BF
|
||||||
case 0xF4:
|
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;
|
return token_type::parse_error;
|
||||||
}
|
}
|
||||||
@ -11844,9 +11843,9 @@ scan_number_done:
|
|||||||
if (static_cast<unsigned char>(c) <= '\x1F')
|
if (static_cast<unsigned char>(c) <= '\x1F')
|
||||||
{
|
{
|
||||||
// escape control characters
|
// escape control characters
|
||||||
std::array<char, 9> cs{{}};
|
std::array<char, 9> cs{ {} };
|
||||||
static_cast<void>((
|
static_cast<void>(( // NOLINT(cppcoreguidelines-pro-type-vararg,hicpp-vararg)
|
||||||
std::snprintf)(cs.data(), cs.size(), "<U+%.4X>", static_cast<unsigned char>(c))); // NOLINT(cppcoreguidelines-pro-type-vararg,hicpp-vararg)
|
std::snprintf)(cs.data(), cs.size(), "<U+%.4X>", static_cast<unsigned char>(c)));
|
||||||
result += cs.data();
|
result += cs.data();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -11940,22 +11939,24 @@ scan_number_done:
|
|||||||
case 't':
|
case 't':
|
||||||
{
|
{
|
||||||
std::array<char_type, 4> true_literal = {
|
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);
|
return scan_literal(true_literal.data(), true_literal.size(), token_type::literal_true);
|
||||||
}
|
}
|
||||||
case 'f':
|
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>('a'),
|
||||||
static_cast<char_type>('l'),
|
static_cast<char_type>('l'),
|
||||||
static_cast<char_type>('s'),
|
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);
|
return scan_literal(false_literal.data(), false_literal.size(), token_type::literal_false);
|
||||||
}
|
}
|
||||||
case 'n':
|
case 'n':
|
||||||
{
|
{
|
||||||
std::array<char_type, 4> null_literal = {
|
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);
|
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)
|
default: // anything else not supported (yet)
|
||||||
{
|
{
|
||||||
std::array<char, 3> cr{{}};
|
std::array<char, 3> cr{ {} };
|
||||||
static_cast<void>((std::snprintf)(cr.data(),
|
static_cast<void>((std::snprintf)(cr.data(), // NOLINT(cppcoreguidelines-pro-type-vararg,hicpp-vararg)
|
||||||
cr.size(),
|
cr.size(),
|
||||||
"%.2hhX",
|
"%.2hhX",
|
||||||
static_cast<unsigned char>(element_type))); // NOLINT(cppcoreguidelines-pro-type-vararg,hicpp-vararg)
|
static_cast<unsigned char>(element_type)));
|
||||||
const std::string cr_str{cr.data()};
|
const std::string cr_str{ cr.data() };
|
||||||
return sax->parse_error(element_type_parse_position,
|
return sax->parse_error(element_type_parse_position,
|
||||||
cr_str,
|
cr_str,
|
||||||
parse_error::create(114, element_type_parse_position, concat("Unsupported BSON record type 0x", cr_str), nullptr));
|
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::string get_token_string() const
|
||||||
{
|
{
|
||||||
std::array<char, 3> cr{{}};
|
std::array<char, 3> cr{ {} };
|
||||||
static_cast<void>(
|
static_cast<void>(
|
||||||
(std::snprintf)(cr.data(), cr.size(), "%.2hhX", static_cast<unsigned char>(current))); // NOLINT(cppcoreguidelines-pro-type-vararg,hicpp-vararg)
|
(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,22 +15172,22 @@ 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_OPTIMIZED_TYPE_MARKERS_ make_array<char_int_type>('F', 'H', 'N', 'S', 'T', 'Z', '[', '{')
|
||||||
|
|
||||||
#define JSON_BINARY_READER_MAKE_BJD_TYPES_MAP_ \
|
#define JSON_BINARY_READER_MAKE_BJD_TYPES_MAP_ \
|
||||||
make_array<bjd_type>(bjd_type{'C', "char"}, \
|
make_array<bjd_type>(bjd_type{ 'C', "char" }, \
|
||||||
bjd_type{'D', "double"}, \
|
bjd_type{ 'D', "double" }, \
|
||||||
bjd_type{'I', "int16"}, \
|
bjd_type{ 'I', "int16" }, \
|
||||||
bjd_type{'L', "int64"}, \
|
bjd_type{ 'L', "int64" }, \
|
||||||
bjd_type{'M', "uint64"}, \
|
bjd_type{ 'M', "uint64" }, \
|
||||||
bjd_type{'U', "uint8"}, \
|
bjd_type{ 'U', "uint8" }, \
|
||||||
bjd_type{'d', "single"}, \
|
bjd_type{ 'd', "single" }, \
|
||||||
bjd_type{'i', "int8"}, \
|
bjd_type{ 'i', "int8" }, \
|
||||||
bjd_type{'l', "int32"}, \
|
bjd_type{ 'l', "int32" }, \
|
||||||
bjd_type{'m', "uint32"}, \
|
bjd_type{ 'm', "uint32" }, \
|
||||||
bjd_type{'u', "uint16"})
|
bjd_type{ 'u', "uint16" })
|
||||||
|
|
||||||
JSON_PRIVATE_UNLESS_TESTED :
|
JSON_PRIVATE_UNLESS_TESTED :
|
||||||
// lookup tables
|
// lookup tables
|
||||||
// NOLINTNEXTLINE(cppcoreguidelines-non-private-member-variables-in-classes)
|
// NOLINTNEXTLINE(cppcoreguidelines-non-private-member-variables-in-classes)
|
||||||
const decltype(JSON_BINARY_READER_MAKE_BJD_OPTIMIZED_TYPE_MARKERS_) bjd_optimized_type_markers = JSON_BINARY_READER_MAKE_BJD_OPTIMIZED_TYPE_MARKERS_;
|
const decltype(JSON_BINARY_READER_MAKE_BJD_OPTIMIZED_TYPE_MARKERS_) bjd_optimized_type_markers = JSON_BINARY_READER_MAKE_BJD_OPTIMIZED_TYPE_MARKERS_;
|
||||||
|
|
||||||
using bjd_type = std::pair<char_int_type, string_t>;
|
using bjd_type = std::pair<char_int_type, string_t>;
|
||||||
// NOLINTNEXTLINE(cppcoreguidelines-non-private-member-variables-in-classes)
|
// NOLINTNEXTLINE(cppcoreguidelines-non-private-member-variables-in-classes)
|
||||||
@ -15787,8 +15788,8 @@ class primitive_iterator_t
|
|||||||
static constexpr difference_type end_value = begin_value + 1;
|
static constexpr difference_type end_value = begin_value + 1;
|
||||||
|
|
||||||
JSON_PRIVATE_UNLESS_TESTED :
|
JSON_PRIVATE_UNLESS_TESTED :
|
||||||
/// iterator as signed integer type
|
/// iterator as signed integer type
|
||||||
difference_type m_it = (std::numeric_limits<std::ptrdiff_t>::min)();
|
difference_type m_it = (std::numeric_limits<std::ptrdiff_t>::min)();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
constexpr difference_type get_value() const noexcept
|
constexpr difference_type get_value() const noexcept
|
||||||
@ -16107,12 +16108,11 @@ class iter_impl // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
|
|||||||
}
|
}
|
||||||
|
|
||||||
JSON_PRIVATE_UNLESS_TESTED :
|
JSON_PRIVATE_UNLESS_TESTED :
|
||||||
/*!
|
/*!
|
||||||
@brief set the iterator to the first value
|
@brief set the iterator to the first value
|
||||||
@pre The iterator is initialized; i.e. `m_object != nullptr`.
|
@pre The iterator is initialized; i.e. `m_object != nullptr`.
|
||||||
*/
|
*/
|
||||||
void
|
void set_begin() noexcept
|
||||||
set_begin() noexcept
|
|
||||||
{
|
{
|
||||||
JSON_ASSERT(m_object != nullptr);
|
JSON_ASSERT(m_object != nullptr);
|
||||||
|
|
||||||
@ -16661,8 +16661,8 @@ class iter_impl // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
|
|||||||
}
|
}
|
||||||
|
|
||||||
JSON_PRIVATE_UNLESS_TESTED :
|
JSON_PRIVATE_UNLESS_TESTED :
|
||||||
/// associated JSON instance
|
/// associated JSON instance
|
||||||
pointer m_object = nullptr;
|
pointer m_object = nullptr;
|
||||||
/// the actual iterator of the associated instance
|
/// the actual iterator of the associated instance
|
||||||
internal_iterator<typename std::remove_const<BasicJsonType>::type> m_it{};
|
internal_iterator<typename std::remove_const<BasicJsonType>::type> m_it{};
|
||||||
};
|
};
|
||||||
@ -17090,7 +17090,8 @@ class json_pointer
|
|||||||
return static_cast<size_type>(res);
|
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()))
|
if (JSON_HEDLEY_UNLIKELY(empty()))
|
||||||
{
|
{
|
||||||
@ -17098,7 +17099,7 @@ class json_pointer
|
|||||||
}
|
}
|
||||||
|
|
||||||
json_pointer result = *this;
|
json_pointer result = *this;
|
||||||
result.reference_tokens = {reference_tokens[0]};
|
result.reference_tokens = { reference_tokens[0] };
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -18828,7 +18829,7 @@ class binary_writer
|
|||||||
return ubjson_prefix(v, use_bjdata) == first_prefix;
|
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()))
|
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;
|
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()))
|
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)
|
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'},
|
std::map<string_t, CharType> bjdtype = { { "uint8", 'U' }, { "int8", 'i' }, { "uint16", 'u' }, { "int16", 'I' }, { "uint32", 'm' }, { "int32", 'l' },
|
||||||
{"int8", 'i'},
|
{ "uint64", 'M' }, { "int64", 'L' }, { "single", 'd' }, { "double", 'D' }, { "char", 'C' } };
|
||||||
{"uint16", 'u'},
|
|
||||||
{"int16", 'I'},
|
|
||||||
{"uint32", 'm'},
|
|
||||||
{"int32", 'l'},
|
|
||||||
{"uint64", 'M'},
|
|
||||||
{"int64", 'L'},
|
|
||||||
{"single", 'd'},
|
|
||||||
{"double", 'D'},
|
|
||||||
{"char", 'C'}};
|
|
||||||
|
|
||||||
string_t key = "_ArrayType_";
|
string_t key = "_ArrayType_";
|
||||||
auto it = bjdtype.find(static_cast<string_t>(value.at(key)));
|
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.e == y.e);
|
||||||
JSON_ASSERT(x.f >= y.f);
|
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
|
// Effectively we only need to add the highest bit in p_lo to p_hi (and
|
||||||
// Q_hi + 1 does not overflow).
|
// 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);
|
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(delta >= 0);
|
||||||
JSON_ASSERT(((x.f << delta) >> delta) == x.f);
|
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 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 kBias = std::numeric_limits<FloatType>::max_exponent - 1 + (kPrecision - 1);
|
||||||
constexpr int kMinExp = 1 - kBias;
|
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;
|
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+).
|
// Determine w- = m- such that e_(w-) = e_(w+).
|
||||||
const diyfp w_minus = diyfp::normalize_to(m_minus, w_plus.e);
|
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
|
// 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 kCachedPowersMinDecExp = -300;
|
||||||
constexpr int kCachedPowersDecStep = 8;
|
constexpr int kCachedPowersDecStep = 8;
|
||||||
|
|
||||||
static constexpr std::array<cached_power, 79> kCachedPowers = {{
|
static constexpr std::array<cached_power, 79> kCachedPowers = { {
|
||||||
{0xAB70FE17C79AC6CA, -1060, -300}, {0xFF77B1FCBEBCDC4F, -1034, -292}, {0xBE5691EF416BD60C, -1007, -284}, {0x8DD01FAD907FFC3C, -980, -276},
|
{ 0xAB70FE17C79AC6CA, -1060, -300 }, { 0xFF77B1FCBEBCDC4F, -1034, -292 }, { 0xBE5691EF416BD60C, -1007, -284 }, { 0x8DD01FAD907FFC3C, -980, -276 },
|
||||||
{0xD3515C2831559A83, -954, -268}, {0x9D71AC8FADA6C9B5, -927, -260}, {0xEA9C227723EE8BCB, -901, -252}, {0xAECC49914078536D, -874, -244},
|
{ 0xD3515C2831559A83, -954, -268 }, { 0x9D71AC8FADA6C9B5, -927, -260 }, { 0xEA9C227723EE8BCB, -901, -252 }, { 0xAECC49914078536D, -874, -244 },
|
||||||
{0x823C12795DB6CE57, -847, -236}, {0xC21094364DFB5637, -821, -228}, {0x9096EA6F3848984F, -794, -220}, {0xD77485CB25823AC7, -768, -212},
|
{ 0x823C12795DB6CE57, -847, -236 }, { 0xC21094364DFB5637, -821, -228 }, { 0x9096EA6F3848984F, -794, -220 }, { 0xD77485CB25823AC7, -768, -212 },
|
||||||
{0xA086CFCD97BF97F4, -741, -204}, {0xEF340A98172AACE5, -715, -196}, {0xB23867FB2A35B28E, -688, -188}, {0x84C8D4DFD2C63F3B, -661, -180},
|
{ 0xA086CFCD97BF97F4, -741, -204 }, { 0xEF340A98172AACE5, -715, -196 }, { 0xB23867FB2A35B28E, -688, -188 }, { 0x84C8D4DFD2C63F3B, -661, -180 },
|
||||||
{0xC5DD44271AD3CDBA, -635, -172}, {0x936B9FCEBB25C996, -608, -164}, {0xDBAC6C247D62A584, -582, -156}, {0xA3AB66580D5FDAF6, -555, -148},
|
{ 0xC5DD44271AD3CDBA, -635, -172 }, { 0x936B9FCEBB25C996, -608, -164 }, { 0xDBAC6C247D62A584, -582, -156 }, { 0xA3AB66580D5FDAF6, -555, -148 },
|
||||||
{0xF3E2F893DEC3F126, -529, -140}, {0xB5B5ADA8AAFF80B8, -502, -132}, {0x87625F056C7C4A8B, -475, -124}, {0xC9BCFF6034C13053, -449, -116},
|
{ 0xF3E2F893DEC3F126, -529, -140 }, { 0xB5B5ADA8AAFF80B8, -502, -132 }, { 0x87625F056C7C4A8B, -475, -124 }, { 0xC9BCFF6034C13053, -449, -116 },
|
||||||
{0x964E858C91BA2655, -422, -108}, {0xDFF9772470297EBD, -396, -100}, {0xA6DFBD9FB8E5B88F, -369, -92}, {0xF8A95FCF88747D94, -343, -84},
|
{ 0x964E858C91BA2655, -422, -108 }, { 0xDFF9772470297EBD, -396, -100 }, { 0xA6DFBD9FB8E5B88F, -369, -92 }, { 0xF8A95FCF88747D94, -343, -84 },
|
||||||
{0xB94470938FA89BCF, -316, -76}, {0x8A08F0F8BF0F156B, -289, -68}, {0xCDB02555653131B6, -263, -60}, {0x993FE2C6D07B7FAC, -236, -52},
|
{ 0xB94470938FA89BCF, -316, -76 }, { 0x8A08F0F8BF0F156B, -289, -68 }, { 0xCDB02555653131B6, -263, -60 }, { 0x993FE2C6D07B7FAC, -236, -52 },
|
||||||
{0xE45C10C42A2B3B06, -210, -44}, {0xAA242499697392D3, -183, -36}, {0xFD87B5F28300CA0E, -157, -28}, {0xBCE5086492111AEB, -130, -20},
|
{ 0xE45C10C42A2B3B06, -210, -44 }, { 0xAA242499697392D3, -183, -36 }, { 0xFD87B5F28300CA0E, -157, -28 }, { 0xBCE5086492111AEB, -130, -20 },
|
||||||
{0x8CBCCC096F5088CC, -103, -12}, {0xD1B71758E219652C, -77, -4}, {0x9C40000000000000, -50, 4}, {0xE8D4A51000000000, -24, 12},
|
{ 0x8CBCCC096F5088CC, -103, -12 }, { 0xD1B71758E219652C, -77, -4 }, { 0x9C40000000000000, -50, 4 }, { 0xE8D4A51000000000, -24, 12 },
|
||||||
{0xAD78EBC5AC620000, 3, 20}, {0x813F3978F8940984, 30, 28}, {0xC097CE7BC90715B3, 56, 36}, {0x8F7E32CE7BEA5C70, 83, 44},
|
{ 0xAD78EBC5AC620000, 3, 20 }, { 0x813F3978F8940984, 30, 28 }, { 0xC097CE7BC90715B3, 56, 36 }, { 0x8F7E32CE7BEA5C70, 83, 44 },
|
||||||
{0xD5D238A4ABE98068, 109, 52}, {0x9F4F2726179A2245, 136, 60}, {0xED63A231D4C4FB27, 162, 68}, {0xB0DE65388CC8ADA8, 189, 76},
|
{ 0xD5D238A4ABE98068, 109, 52 }, { 0x9F4F2726179A2245, 136, 60 }, { 0xED63A231D4C4FB27, 162, 68 }, { 0xB0DE65388CC8ADA8, 189, 76 },
|
||||||
{0x83C7088E1AAB65DB, 216, 84}, {0xC45D1DF942711D9A, 242, 92}, {0x924D692CA61BE758, 269, 100}, {0xDA01EE641A708DEA, 295, 108},
|
{ 0x83C7088E1AAB65DB, 216, 84 }, { 0xC45D1DF942711D9A, 242, 92 }, { 0x924D692CA61BE758, 269, 100 }, { 0xDA01EE641A708DEA, 295, 108 },
|
||||||
{0xA26DA3999AEF774A, 322, 116}, {0xF209787BB47D6B85, 348, 124}, {0xB454E4A179DD1877, 375, 132}, {0x865B86925B9BC5C2, 402, 140},
|
{ 0xA26DA3999AEF774A, 322, 116 }, { 0xF209787BB47D6B85, 348, 124 }, { 0xB454E4A179DD1877, 375, 132 }, { 0x865B86925B9BC5C2, 402, 140 },
|
||||||
{0xC83553C5C8965D3D, 428, 148}, {0x952AB45CFA97A0B3, 455, 156}, {0xDE469FBD99A05FE3, 481, 164}, {0xA59BC234DB398C25, 508, 172},
|
{ 0xC83553C5C8965D3D, 428, 148 }, { 0x952AB45CFA97A0B3, 455, 156 }, { 0xDE469FBD99A05FE3, 481, 164 }, { 0xA59BC234DB398C25, 508, 172 },
|
||||||
{0xF6C69A72A3989F5C, 534, 180}, {0xB7DCBF5354E9BECE, 561, 188}, {0x88FCF317F22241E2, 588, 196}, {0xCC20CE9BD35C78A5, 614, 204},
|
{ 0xF6C69A72A3989F5C, 534, 180 }, { 0xB7DCBF5354E9BECE, 561, 188 }, { 0x88FCF317F22241E2, 588, 196 }, { 0xCC20CE9BD35C78A5, 614, 204 },
|
||||||
{0x98165AF37B2153DF, 641, 212}, {0xE2A0B5DC971F303A, 667, 220}, {0xA8D9D1535CE3B396, 694, 228}, {0xFB9B7CD9A4A7443C, 720, 236},
|
{ 0x98165AF37B2153DF, 641, 212 }, { 0xE2A0B5DC971F303A, 667, 220 }, { 0xA8D9D1535CE3B396, 694, 228 }, { 0xFB9B7CD9A4A7443C, 720, 236 },
|
||||||
{0xBB764C4CA7A44410, 747, 244}, {0x8BAB8EEFB6409C1A, 774, 252}, {0xD01FEF10A657842C, 800, 260}, {0x9B10A4E5E9913129, 827, 268},
|
{ 0xBB764C4CA7A44410, 747, 244 }, { 0x8BAB8EEFB6409C1A, 774, 252 }, { 0xD01FEF10A657842C, 800, 260 }, { 0x9B10A4E5E9913129, 827, 268 },
|
||||||
{0xE7109BFBA19C0C9D, 853, 276}, {0xAC2820D9623BF429, 880, 284}, {0x80444B5E7AA7CF85, 907, 292}, {0xBF21E44003ACDD2D, 933, 300},
|
{ 0xE7109BFBA19C0C9D, 853, 276 }, { 0xAC2820D9623BF429, 880, 284 }, { 0x80444B5E7AA7CF85, 907, 292 }, { 0xBF21E44003ACDD2D, 933, 300 },
|
||||||
{0x8E679C2F5E44FF8F, 960, 308}, {0xD433179D9C8CB841, 986, 316}, {0x9E19DB92B4E31BA9, 1013, 324},
|
{ 0x8E679C2F5E44FF8F, 960, 308 }, { 0xD433179D9C8CB841, 986, 316 }, { 0x9E19DB92B4E31BA9, 1013, 324 },
|
||||||
}};
|
} };
|
||||||
|
|
||||||
// This computation gives exactly the same results for k as
|
// This computation gives exactly the same results for k as
|
||||||
// k = ceil((kAlpha - e - 1) * 0.30102999566398114)
|
// 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 ) * 2^-e + (p2 )) * 2^e
|
||||||
// = p1 + 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.)
|
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
|
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:
|
// Note:
|
||||||
// Since rest and delta share the same exponent e, it suffices to
|
// Since rest and delta share the same exponent e, it suffices to
|
||||||
// compare the significands.
|
// 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)
|
if (rest <= delta)
|
||||||
{
|
{
|
||||||
// V = buffer * 10^n, with M- <= V <= M+.
|
// 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
|
// 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);
|
grisu2_round(buffer, length, dist, delta, rest, ten_n);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
@ -21258,7 +21250,7 @@ class serializer
|
|||||||
}
|
}
|
||||||
|
|
||||||
JSON_PRIVATE_UNLESS_TESTED :
|
JSON_PRIVATE_UNLESS_TESTED :
|
||||||
/*!
|
/*!
|
||||||
@brief dump escaped string
|
@brief dump escaped string
|
||||||
|
|
||||||
Escape a string by replacing certain special characters by a sequence of an
|
Escape a string by replacing certain special characters by a sequence of an
|
||||||
@ -21272,8 +21264,7 @@ class serializer
|
|||||||
|
|
||||||
@complexity Linear in the length of string @a s.
|
@complexity Linear in the length of string @a s.
|
||||||
*/
|
*/
|
||||||
void
|
void dump_escaped(const string_t& s, const bool ensure_ascii)
|
||||||
dump_escaped(const string_t& s, const bool ensure_ascii)
|
|
||||||
{
|
{
|
||||||
std::uint32_t codepoint{};
|
std::uint32_t codepoint{};
|
||||||
std::uint8_t state = UTF8_ACCEPT;
|
std::uint8_t state = UTF8_ACCEPT;
|
||||||
@ -21599,18 +21590,21 @@ class serializer
|
|||||||
int> = 0>
|
int> = 0>
|
||||||
void dump_integer(NumberType x)
|
void dump_integer(NumberType x)
|
||||||
{
|
{
|
||||||
static constexpr std::array<std::array<char, 2>, 100> digits_to_99{{
|
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'}},
|
{ { '0', '0' } }, { { '0', '1' } }, { { '0', '2' } }, { { '0', '3' } }, { { '0', '4' } }, { { '0', '5' } }, { { '0', '6' } }, { { '0', '7' } },
|
||||||
{{'1', '0'}}, {{'1', '1'}}, {{'1', '2'}}, {{'1', '3'}}, {{'1', '4'}}, {{'1', '5'}}, {{'1', '6'}}, {{'1', '7'}}, {{'1', '8'}}, {{'1', '9'}},
|
{ { '0', '8' } }, { { '0', '9' } }, { { '1', '0' } }, { { '1', '1' } }, { { '1', '2' } }, { { '1', '3' } }, { { '1', '4' } }, { { '1', '5' } },
|
||||||
{{'2', '0'}}, {{'2', '1'}}, {{'2', '2'}}, {{'2', '3'}}, {{'2', '4'}}, {{'2', '5'}}, {{'2', '6'}}, {{'2', '7'}}, {{'2', '8'}}, {{'2', '9'}},
|
{ { '1', '6' } }, { { '1', '7' } }, { { '1', '8' } }, { { '1', '9' } }, { { '2', '0' } }, { { '2', '1' } }, { { '2', '2' } }, { { '2', '3' } },
|
||||||
{{'3', '0'}}, {{'3', '1'}}, {{'3', '2'}}, {{'3', '3'}}, {{'3', '4'}}, {{'3', '5'}}, {{'3', '6'}}, {{'3', '7'}}, {{'3', '8'}}, {{'3', '9'}},
|
{ { '2', '4' } }, { { '2', '5' } }, { { '2', '6' } }, { { '2', '7' } }, { { '2', '8' } }, { { '2', '9' } }, { { '3', '0' } }, { { '3', '1' } },
|
||||||
{{'4', '0'}}, {{'4', '1'}}, {{'4', '2'}}, {{'4', '3'}}, {{'4', '4'}}, {{'4', '5'}}, {{'4', '6'}}, {{'4', '7'}}, {{'4', '8'}}, {{'4', '9'}},
|
{ { '3', '2' } }, { { '3', '3' } }, { { '3', '4' } }, { { '3', '5' } }, { { '3', '6' } }, { { '3', '7' } }, { { '3', '8' } }, { { '3', '9' } },
|
||||||
{{'5', '0'}}, {{'5', '1'}}, {{'5', '2'}}, {{'5', '3'}}, {{'5', '4'}}, {{'5', '5'}}, {{'5', '6'}}, {{'5', '7'}}, {{'5', '8'}}, {{'5', '9'}},
|
{ { '4', '0' } }, { { '4', '1' } }, { { '4', '2' } }, { { '4', '3' } }, { { '4', '4' } }, { { '4', '5' } }, { { '4', '6' } }, { { '4', '7' } },
|
||||||
{{'6', '0'}}, {{'6', '1'}}, {{'6', '2'}}, {{'6', '3'}}, {{'6', '4'}}, {{'6', '5'}}, {{'6', '6'}}, {{'6', '7'}}, {{'6', '8'}}, {{'6', '9'}},
|
{ { '4', '8' } }, { { '4', '9' } }, { { '5', '0' } }, { { '5', '1' } }, { { '5', '2' } }, { { '5', '3' } }, { { '5', '4' } }, { { '5', '5' } },
|
||||||
{{'7', '0'}}, {{'7', '1'}}, {{'7', '2'}}, {{'7', '3'}}, {{'7', '4'}}, {{'7', '5'}}, {{'7', '6'}}, {{'7', '7'}}, {{'7', '8'}}, {{'7', '9'}},
|
{ { '5', '6' } }, { { '5', '7' } }, { { '5', '8' } }, { { '5', '9' } }, { { '6', '0' } }, { { '6', '1' } }, { { '6', '2' } }, { { '6', '3' } },
|
||||||
{{'8', '0'}}, {{'8', '1'}}, {{'8', '2'}}, {{'8', '3'}}, {{'8', '4'}}, {{'8', '5'}}, {{'8', '6'}}, {{'8', '7'}}, {{'8', '8'}}, {{'8', '9'}},
|
{ { '6', '4' } }, { { '6', '5' } }, { { '6', '6' } }, { { '6', '7' } }, { { '6', '8' } }, { { '6', '9' } }, { { '7', '0' } }, { { '7', '1' } },
|
||||||
{{'9', '0'}}, {{'9', '1'}}, {{'9', '2'}}, {{'9', '3'}}, {{'9', '4'}}, {{'9', '5'}}, {{'9', '6'}}, {{'9', '7'}}, {{'9', '8'}}, {{'9', '9'}},
|
{ { '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"
|
// special case for "0"
|
||||||
if (x == 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 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, 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, // 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,
|
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, // 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, 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
|
1 // s7..s8
|
||||||
}};
|
} };
|
||||||
|
|
||||||
JSON_ASSERT(byte < utf8d.size());
|
JSON_ASSERT(byte < utf8d.size());
|
||||||
const std::uint8_t type = utf8d[byte];
|
const std::uint8_t type = utf8d[byte];
|
||||||
@ -21853,7 +21847,7 @@ class serializer
|
|||||||
output_adapter_t<char> o = nullptr;
|
output_adapter_t<char> o = nullptr;
|
||||||
|
|
||||||
/// a (hopefully) large enough character buffer
|
/// a (hopefully) large enough character buffer
|
||||||
std::array<char, 64> number_buffer{{}};
|
std::array<char, 64> number_buffer{ {} };
|
||||||
|
|
||||||
/// the locale
|
/// the locale
|
||||||
const std::lconv* loc = nullptr;
|
const std::lconv* loc = nullptr;
|
||||||
@ -21863,7 +21857,7 @@ class serializer
|
|||||||
const char decimal_point = '\0';
|
const char decimal_point = '\0';
|
||||||
|
|
||||||
/// string buffer
|
/// string buffer
|
||||||
std::array<char, 512> string_buffer{{}};
|
std::array<char, 512> string_buffer{ {} };
|
||||||
|
|
||||||
/// the indentation character
|
/// the indentation character
|
||||||
const char indent_char;
|
const char indent_char;
|
||||||
@ -21933,14 +21927,14 @@ struct ordered_map : std::vector<std::pair<const Key, T>, Allocator>
|
|||||||
: Container{}
|
: Container{}
|
||||||
{}
|
{}
|
||||||
explicit ordered_map(const Allocator& alloc) noexcept(noexcept(Container(alloc)))
|
explicit ordered_map(const Allocator& alloc) noexcept(noexcept(Container(alloc)))
|
||||||
: Container{alloc}
|
: Container{ alloc }
|
||||||
{}
|
{}
|
||||||
template<class It>
|
template<class It>
|
||||||
ordered_map(It first, It last, const Allocator& alloc = Allocator())
|
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())
|
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)
|
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))
|
if (m_compare(it->first, key))
|
||||||
{
|
{
|
||||||
return {it, false};
|
return { it, false };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Container::emplace_back(key, std::forward<T>(t));
|
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>
|
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))
|
if (m_compare(it->first, key))
|
||||||
{
|
{
|
||||||
return {it, false};
|
return { it, false };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Container::emplace_back(std::forward<KeyType>(key), std::forward<T>(t));
|
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)
|
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)
|
for (auto next = it; ++next != this->end(); ++it)
|
||||||
{
|
{
|
||||||
it->~value_type(); // Destroy but keep allocation
|
it->~value_type(); // Destroy but keep allocation
|
||||||
new (&*it) value_type{std::move(*next)};
|
new (&*it) value_type{ std::move(*next) };
|
||||||
}
|
}
|
||||||
Container::pop_back();
|
Container::pop_back();
|
||||||
return 1;
|
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)
|
for (auto next = it; ++next != this->end(); ++it)
|
||||||
{
|
{
|
||||||
it->~value_type(); // Destroy but keep allocation
|
it->~value_type(); // Destroy but keep allocation
|
||||||
new (&*it) value_type{std::move(*next)};
|
new (&*it) value_type{ std::move(*next) };
|
||||||
}
|
}
|
||||||
Container::pop_back();
|
Container::pop_back();
|
||||||
return 1;
|
return 1;
|
||||||
@ -22122,8 +22116,8 @@ struct ordered_map : std::vector<std::pair<const Key, T>, Allocator>
|
|||||||
|
|
||||||
for (auto it = first; std::next(it, elements_affected) != Container::end(); ++it)
|
for (auto it = first; std::next(it, elements_affected) != Container::end(); ++it)
|
||||||
{
|
{
|
||||||
it->~value_type(); // destroy but keep allocation
|
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 ]
|
// [ 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))
|
if (m_compare(it->first, value.first))
|
||||||
{
|
{
|
||||||
return {it, false};
|
return { it, false };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Container::push_back(value);
|
Container::push_back(value);
|
||||||
return {--this->end(), true};
|
return { --this->end(), true };
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename InputIt>
|
template<typename InputIt>
|
||||||
@ -22307,8 +22301,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spe
|
|||||||
using json_base_class_t = ::nlohmann::detail::json_base_class<CustomBaseClass>;
|
using json_base_class_t = ::nlohmann::detail::json_base_class<CustomBaseClass>;
|
||||||
|
|
||||||
JSON_PRIVATE_UNLESS_TESTED :
|
JSON_PRIVATE_UNLESS_TESTED :
|
||||||
// convenience aliases for types residing in namespace detail;
|
// convenience aliases for types residing in namespace detail;
|
||||||
using lexer = ::nlohmann::detail::lexer_base<basic_json>;
|
using lexer = ::nlohmann::detail::lexer_base<basic_json>;
|
||||||
|
|
||||||
template<typename InputAdapterType>
|
template<typename InputAdapterType>
|
||||||
static ::nlohmann::detail::parser<basic_json, InputAdapterType>
|
static ::nlohmann::detail::parser<basic_json, InputAdapterType>
|
||||||
@ -22336,7 +22330,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spe
|
|||||||
template<typename CharType>
|
template<typename CharType>
|
||||||
using binary_writer = ::nlohmann::detail::binary_writer<basic_json, 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:
|
public:
|
||||||
using value_t = detail::value_t;
|
using value_t = detail::value_t;
|
||||||
@ -22452,25 +22447,25 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spe
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(__ICC) || defined(__INTEL_COMPILER)
|
#if defined(__ICC) || defined(__INTEL_COMPILER)
|
||||||
result["compiler"] = {{"family", "icc"}, { "version", __INTEL_COMPILER }};
|
result["compiler"] = { { "family", "icc" }, { "version", __INTEL_COMPILER } };
|
||||||
#elif defined(__clang__)
|
#elif defined(__clang__)
|
||||||
result["compiler"] = {{"family", "clang"}, { "version", __clang_version__ }};
|
result["compiler"] = { { "family", "clang" }, { "version", __clang_version__ } };
|
||||||
#elif defined(__GNUC__) || defined(__GNUG__)
|
#elif defined(__GNUC__) || defined(__GNUG__)
|
||||||
result["compiler"] = {{"family", "gcc"},
|
result["compiler"] = { { "family", "gcc" },
|
||||||
{ "version",
|
{ "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)
|
#elif defined(__HP_cc) || defined(__HP_aCC)
|
||||||
result["compiler"] = "hp"
|
result["compiler"] = "hp"
|
||||||
#elif defined(__IBMCPP__)
|
#elif defined(__IBMCPP__)
|
||||||
result["compiler"] = {{"family", "ilecpp"}, { "version", __IBMCPP__ }};
|
result["compiler"] = { { "family", "ilecpp" }, { "version", __IBMCPP__ } };
|
||||||
#elif defined(_MSC_VER)
|
#elif defined(_MSC_VER)
|
||||||
result["compiler"] = {{"family", "msvc"}, { "version", _MSC_VER }};
|
result["compiler"] = { { "family", "msvc" }, { "version", _MSC_VER } };
|
||||||
#elif defined(__PGI)
|
#elif defined(__PGI)
|
||||||
result["compiler"] = {{"family", "pgcpp"}, { "version", __PGI }};
|
result["compiler"] = { { "family", "pgcpp" }, { "version", __PGI } };
|
||||||
#elif defined(__SUNPRO_CC)
|
#elif defined(__SUNPRO_CC)
|
||||||
result["compiler"] = {{"family", "sunpro"}, { "version", __SUNPRO_CC }};
|
result["compiler"] = { { "family", "sunpro" }, { "version", __SUNPRO_CC } };
|
||||||
#else
|
#else
|
||||||
result["compiler"] = {{"family", "unknown"}, {"version", "unknown"}};
|
result["compiler"] = { { "family", "unknown" }, { "version", "unknown" } };
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(_MSVC_LANG)
|
#if defined(_MSVC_LANG)
|
||||||
@ -22564,7 +22559,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spe
|
|||||||
////////////////////////
|
////////////////////////
|
||||||
|
|
||||||
JSON_PRIVATE_UNLESS_TESTED :
|
JSON_PRIVATE_UNLESS_TESTED :
|
||||||
/*!
|
/*!
|
||||||
@brief a JSON value
|
@brief a JSON value
|
||||||
|
|
||||||
The actual storage for a JSON value of the @ref basic_json class. This
|
The actual storage for a JSON value of the @ref basic_json class. This
|
||||||
@ -22589,7 +22584,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spe
|
|||||||
|
|
||||||
@since version 1.0.0
|
@since version 1.0.0
|
||||||
*/
|
*/
|
||||||
union json_value
|
union json_value
|
||||||
{
|
{
|
||||||
/// object (stored with pointer to save storage)
|
/// object (stored with pointer to save storage)
|
||||||
object_t* object;
|
object_t* object;
|
||||||
@ -23203,7 +23198,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spe
|
|||||||
/// @brief construct an array with count copies of given value
|
/// @brief construct an array with count copies of given value
|
||||||
/// @sa https://json.nlohmann.me/api/basic_json/basic_json/
|
/// @sa https://json.nlohmann.me/api/basic_json/basic_json/
|
||||||
basic_json(size_type cnt, const basic_json& val)
|
basic_json(size_type cnt, const basic_json& val)
|
||||||
: m_data{cnt, val}
|
: m_data{ cnt, val }
|
||||||
{
|
{
|
||||||
set_parents();
|
set_parents();
|
||||||
assert_invariant();
|
assert_invariant();
|
||||||
@ -25391,7 +25386,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spe
|
|||||||
it.m_it.object_iterator = res.first;
|
it.m_it.object_iterator = res.first;
|
||||||
|
|
||||||
// return pair of iterator and boolean
|
// return pair of iterator and boolean
|
||||||
return {it, res.second};
|
return { it, res.second };
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Helper for insertion of an iterator
|
/// Helper for insertion of an iterator
|
||||||
@ -25780,13 +25775,12 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spe
|
|||||||
return (default_result);
|
return (default_result);
|
||||||
|
|
||||||
JSON_PRIVATE_UNLESS_TESTED :
|
JSON_PRIVATE_UNLESS_TESTED :
|
||||||
// returns true if:
|
// returns true if:
|
||||||
// - any operand is NaN and the other operand is of number type
|
// - any operand is NaN and the other operand is of number type
|
||||||
// - any operand is discarded
|
// - any operand is discarded
|
||||||
// in legacy mode, discarded values are considered ordered if
|
// in legacy mode, discarded values are considered ordered if
|
||||||
// an operation is computed as an odd number of inverses of others
|
// an operation is computed as an odd number of inverses of others
|
||||||
static bool
|
static bool compares_unordered(const_reference lhs, const_reference rhs, bool inverse = false) noexcept
|
||||||
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()) ||
|
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()))
|
(rhs.is_number_float() && std::isnan(rhs.m_data.m_value.number_float) && lhs.is_number()))
|
||||||
@ -26287,11 +26281,11 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spe
|
|||||||
}
|
}
|
||||||
|
|
||||||
JSON_PRIVATE_UNLESS_TESTED :
|
JSON_PRIVATE_UNLESS_TESTED :
|
||||||
//////////////////////
|
//////////////////////
|
||||||
// member variables //
|
// member variables //
|
||||||
//////////////////////
|
//////////////////////
|
||||||
|
|
||||||
struct data
|
struct data
|
||||||
{
|
{
|
||||||
/// the type of the current element
|
/// the type of the current element
|
||||||
value_t m_type = value_t::null;
|
value_t m_type = value_t::null;
|
||||||
@ -27053,7 +27047,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spe
|
|||||||
if (source.type() != target.type())
|
if (source.type() != target.type())
|
||||||
{
|
{
|
||||||
// different types: replace value
|
// different types: replace value
|
||||||
result.push_back({{"op", "replace"}, {"path", path}, {"value", target}});
|
result.push_back({ { "op", "replace" }, { "path", path }, { "value", target } });
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -27080,14 +27074,14 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spe
|
|||||||
{
|
{
|
||||||
// add operations in reverse order to avoid invalid
|
// add operations in reverse order to avoid invalid
|
||||||
// indices
|
// 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;
|
++i;
|
||||||
}
|
}
|
||||||
|
|
||||||
// add other remaining elements
|
// add other remaining elements
|
||||||
while (i < target.size())
|
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;
|
++i;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -27111,7 +27105,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spe
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
// found a key that is not in o -> remove it
|
// 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
|
// found a key that is not in this -> add it
|
||||||
const auto path_key = detail::concat(path, '/', detail::escape(it.key()));
|
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:
|
default:
|
||||||
{
|
{
|
||||||
// both primitive type: replace value
|
// both primitive type: replace value
|
||||||
result.push_back({{"op", "replace"}, {"path", path}, {"value", target}});
|
result.push_back({ { "op", "replace" }, { "path", path }, { "value", target } });
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -24,8 +24,6 @@
|
|||||||
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>
|
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>
|
||||||
// SPDX-License-Identifier: MIT
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// This file contains all macro definitions affecting or depending on the ABI
|
// This file contains all macro definitions affecting or depending on the ABI
|
||||||
|
|
||||||
#ifndef JSON_SKIP_LIBRARY_VERSION_CHECK
|
#ifndef JSON_SKIP_LIBRARY_VERSION_CHECK
|
||||||
@ -103,7 +101,6 @@
|
|||||||
} // namespace nlohmann
|
} // namespace nlohmann
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@brief namespace for Niels Lohmann
|
@brief namespace for Niels Lohmann
|
||||||
@see https://github.com/nlohmann
|
@see https://github.com/nlohmann
|
||||||
|
@ -27,7 +27,7 @@ TEST_CASE("custom namespace")
|
|||||||
std::string expected = "nlohmann::basic_json";
|
std::string expected = "nlohmann::basic_json";
|
||||||
|
|
||||||
// fallback for Clang
|
// 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);
|
CHECK(namespace_name<nlohmann::json>(ns) == expected);
|
||||||
}
|
}
|
||||||
|
@ -33,7 +33,7 @@ TEST_CASE("default namespace")
|
|||||||
expected += "_" STRINGIZE(NLOHMANN_JSON_VERSION_PATCH) "::basic_json";
|
expected += "_" STRINGIZE(NLOHMANN_JSON_VERSION_PATCH) "::basic_json";
|
||||||
|
|
||||||
// fallback for Clang
|
// 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);
|
CHECK(namespace_name<nlohmann::json>(ns) == expected);
|
||||||
}
|
}
|
||||||
|
@ -32,7 +32,7 @@ TEST_CASE("default namespace without version component")
|
|||||||
expected += "::basic_json";
|
expected += "::basic_json";
|
||||||
|
|
||||||
// fallback for Clang
|
// 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);
|
CHECK(namespace_name<nlohmann::json>(ns) == expected);
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,6 @@ std::size_t json_sizeof_diag_off_explicit()
|
|||||||
void json_at_diag_off()
|
void json_at_diag_off()
|
||||||
{
|
{
|
||||||
using nlohmann::json;
|
using nlohmann::json;
|
||||||
json j = json{{"foo", json::object()}};
|
json j = json{ { "foo", json::object() } };
|
||||||
j.at(json::json_pointer("/foo/bar"));
|
j.at(json::json_pointer("/foo/bar"));
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,6 @@ std::size_t json_sizeof_diag_on_explicit()
|
|||||||
void json_at_diag_on()
|
void json_at_diag_on()
|
||||||
{
|
{
|
||||||
using nlohmann::json;
|
using nlohmann::json;
|
||||||
json j = json{{"foo", json::object()}};
|
json j = json{ { "foo", json::object() } };
|
||||||
j.at(json::json_pointer("/foo/bar"));
|
j.at(json::json_pointer("/foo/bar"));
|
||||||
}
|
}
|
||||||
|
@ -162,8 +162,8 @@ static void BinaryToCbor(benchmark::State& state)
|
|||||||
++it;
|
++it;
|
||||||
}
|
}
|
||||||
|
|
||||||
json::binary_t bin{in};
|
json::binary_t bin{ in };
|
||||||
json j{{"type", "binary"}, {"data", bin}};
|
json j{ { "type", "binary" }, { "data", bin } };
|
||||||
|
|
||||||
while (state.KeepRunning())
|
while (state.KeepRunning())
|
||||||
{
|
{
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
nlohmann::ordered_json json = {"Test"};
|
nlohmann::ordered_json json = { "Test" };
|
||||||
json.dump();
|
json.dump();
|
||||||
|
|
||||||
// regression for #3013 (ordered_json::reset() compile error with nvcc)
|
// regression for #3013 (ordered_json::reset() compile error with nvcc)
|
||||||
|
@ -106,8 +106,8 @@ TEST_CASE("BJData")
|
|||||||
{
|
{
|
||||||
SECTION("optimized array: negative size")
|
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 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 vMX = { '[', '$', 'U', '#', '[', 'M', 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 'U', 0x01, ']' };
|
||||||
|
|
||||||
json _;
|
json _;
|
||||||
CHECK_THROWS_WITH_AS(_ = json::from_bjdata(vM),
|
CHECK_THROWS_WITH_AS(_ = json::from_bjdata(vM),
|
||||||
@ -123,8 +123,8 @@ TEST_CASE("BJData")
|
|||||||
|
|
||||||
SECTION("optimized array: integer value overflow")
|
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 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 vM = { '[', '$', 'M', '#', '[', 'I', 0x00, 0x20, 'M', 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0xFF, ']' };
|
||||||
|
|
||||||
json _;
|
json _;
|
||||||
CHECK_THROWS_WITH_AS(_ = json::from_bjdata(vL),
|
CHECK_THROWS_WITH_AS(_ = json::from_bjdata(vL),
|
||||||
|
@ -14,8 +14,8 @@ using nlohmann::json;
|
|||||||
|
|
||||||
TEST_CASE("algorithms")
|
TEST_CASE("algorithms")
|
||||||
{
|
{
|
||||||
json j_array = {13, 29, 3, {{"one", 1}, {"two", 2}}, true, false, {1, 2, 3}, "foo", "baz"};
|
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_object = { { "one", 1 }, { "two", 2 } };
|
||||||
|
|
||||||
SECTION("non-modifying sequence operations")
|
SECTION("non-modifying sequence operations")
|
||||||
{
|
{
|
||||||
@ -76,7 +76,7 @@ TEST_CASE("algorithms")
|
|||||||
|
|
||||||
std::for_each(j_array.begin(), j_array.end(), add17);
|
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")
|
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());
|
auto res = std::mismatch(j_array.begin(), j_array.end(), j_array2.begin());
|
||||||
CHECK(*res.first == json({{"one", 1}, {"two", 2}}));
|
CHECK(*res.first == json({ { "one", 1 }, { "two", 2 } }));
|
||||||
CHECK(*res.second == json({{"one", 1}, {"two", 2}, {"three", 3}}));
|
CHECK(*res.second == json({ { "one", 1 }, { "two", 2 }, { "three", 3 } }));
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("std::equal")
|
SECTION("std::equal")
|
||||||
@ -115,7 +115,7 @@ TEST_CASE("algorithms")
|
|||||||
SECTION("using user-defined comparison")
|
SECTION("using user-defined comparison")
|
||||||
{
|
{
|
||||||
// compare objects only by size of its elements
|
// 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()));
|
||||||
CHECK(std::equal(j_array.begin(), j_array.end(), j_array2.begin(), [](const json& a, const json& b) {
|
CHECK(std::equal(j_array.begin(), j_array.end(), j_array2.begin(), [](const json& a, const json& b) {
|
||||||
return (a.size() == b.size());
|
return (a.size() == b.size());
|
||||||
@ -159,13 +159,13 @@ TEST_CASE("algorithms")
|
|||||||
SECTION("std::reverse")
|
SECTION("std::reverse")
|
||||||
{
|
{
|
||||||
std::reverse(j_array.begin(), j_array.end());
|
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")
|
SECTION("std::rotate")
|
||||||
{
|
{
|
||||||
std::rotate(j_array.begin(), j_array.begin() + 1, j_array.end());
|
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")
|
SECTION("std::partition")
|
||||||
@ -184,23 +184,23 @@ TEST_CASE("algorithms")
|
|||||||
{
|
{
|
||||||
SECTION("with standard comparison")
|
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());
|
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")
|
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) {
|
std::sort(j.begin(), j.end(), [](const json& a, const json& b) {
|
||||||
return a.size() < b.size();
|
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")
|
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()),
|
CHECK_THROWS_WITH_AS(std::sort(j.begin(), j.end()),
|
||||||
"[json.exception.invalid_iterator.209] cannot use offsets with object iterators",
|
"[json.exception.invalid_iterator.209] cannot use offsets with object iterators",
|
||||||
json::invalid_iterator&);
|
json::invalid_iterator&);
|
||||||
@ -209,9 +209,9 @@ TEST_CASE("algorithms")
|
|||||||
|
|
||||||
SECTION("std::partial_sort")
|
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());
|
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")
|
SECTION("std::merge")
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
json j1 = {2, 4, 6, 8};
|
json j1 = { 2, 4, 6, 8 };
|
||||||
json j2 = {1, 2, 3, 5, 7};
|
json j2 = { 1, 2, 3, 5, 7 };
|
||||||
json j3;
|
json j3;
|
||||||
|
|
||||||
std::merge(j1.begin(), j1.end(), j2.begin(), j2.end(), std::back_inserter(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")
|
SECTION("std::set_difference")
|
||||||
{
|
{
|
||||||
json j1 = {1, 2, 3, 4, 5, 6, 7, 8};
|
json j1 = { 1, 2, 3, 4, 5, 6, 7, 8 };
|
||||||
json j2 = {1, 2, 3, 5, 7};
|
json j2 = { 1, 2, 3, 5, 7 };
|
||||||
json j3;
|
json j3;
|
||||||
|
|
||||||
std::set_difference(j1.begin(), j1.end(), j2.begin(), j2.end(), std::back_inserter(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")
|
SECTION("std::set_intersection")
|
||||||
{
|
{
|
||||||
json j1 = {1, 2, 3, 4, 5, 6, 7, 8};
|
json j1 = { 1, 2, 3, 4, 5, 6, 7, 8 };
|
||||||
json j2 = {1, 2, 3, 5, 7};
|
json j2 = { 1, 2, 3, 5, 7 };
|
||||||
json j3;
|
json j3;
|
||||||
|
|
||||||
std::set_intersection(j1.begin(), j1.end(), j2.begin(), j2.end(), std::back_inserter(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")
|
SECTION("std::set_union")
|
||||||
{
|
{
|
||||||
json j1 = {2, 4, 6, 8};
|
json j1 = { 2, 4, 6, 8 };
|
||||||
json j2 = {1, 2, 3, 5, 7};
|
json j2 = { 1, 2, 3, 5, 7 };
|
||||||
json j3;
|
json j3;
|
||||||
|
|
||||||
std::set_union(j1.begin(), j1.end(), j2.begin(), j2.end(), std::back_inserter(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")
|
SECTION("std::set_symmetric_difference")
|
||||||
{
|
{
|
||||||
json j1 = {2, 4, 6, 8};
|
json j1 = { 2, 4, 6, 8 };
|
||||||
json j2 = {1, 2, 3, 5, 7};
|
json j2 = { 1, 2, 3, 5, 7 };
|
||||||
json j3;
|
json j3;
|
||||||
|
|
||||||
std::set_symmetric_difference(j1.begin(), j1.end(), j2.begin(), j2.end(), std::back_inserter(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());
|
std::make_heap(j_array.begin(), j_array.end());
|
||||||
CHECK(std::is_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());
|
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("iota")
|
||||||
{
|
{
|
||||||
SECTION("int")
|
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);
|
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")
|
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);
|
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")
|
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');
|
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")
|
SECTION("copy without if")
|
||||||
{
|
{
|
||||||
json dest_arr;
|
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));
|
std::copy(source_arr.begin(), source_arr.end(), std::back_inserter(dest_arr));
|
||||||
|
|
||||||
@ -315,30 +315,30 @@ TEST_CASE("algorithms")
|
|||||||
SECTION("copy if")
|
SECTION("copy if")
|
||||||
{
|
{
|
||||||
json dest_arr;
|
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) {
|
std::copy_if(source_arr.begin(), source_arr.end(), std::back_inserter(dest_arr), [](const json& _value) {
|
||||||
return _value.get<int>() % 3 == 0;
|
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")
|
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;
|
json dest_arr;
|
||||||
const unsigned char numToCopy = 2;
|
const unsigned char numToCopy = 2;
|
||||||
|
|
||||||
std::copy_n(source_arr.begin(), numToCopy, std::back_inserter(dest_arr));
|
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")
|
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;
|
json dest_arr;
|
||||||
const unsigned char numToCopy = 4;
|
const unsigned char numToCopy = 4;
|
||||||
|
|
||||||
std::copy_n(source_arr.begin(), numToCopy, std::back_inserter(dest_arr));
|
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' });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -169,7 +169,7 @@ TEST_CASE("controlled bad_alloc")
|
|||||||
SECTION("basic_json(const CompatibleObjectType&)")
|
SECTION("basic_json(const CompatibleObjectType&)")
|
||||||
{
|
{
|
||||||
next_construct_fails = false;
|
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));
|
CHECK_NOTHROW(my_json(v));
|
||||||
next_construct_fails = true;
|
next_construct_fails = true;
|
||||||
CHECK_THROWS_AS(my_json(v), std::bad_alloc&);
|
CHECK_THROWS_AS(my_json(v), std::bad_alloc&);
|
||||||
@ -179,7 +179,7 @@ TEST_CASE("controlled bad_alloc")
|
|||||||
SECTION("basic_json(const CompatibleArrayType&)")
|
SECTION("basic_json(const CompatibleArrayType&)")
|
||||||
{
|
{
|
||||||
next_construct_fails = false;
|
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));
|
CHECK_NOTHROW(my_json(v));
|
||||||
next_construct_fails = true;
|
next_construct_fails = true;
|
||||||
CHECK_THROWS_AS(my_json(v), std::bad_alloc&);
|
CHECK_THROWS_AS(my_json(v), std::bad_alloc&);
|
||||||
|
@ -154,7 +154,7 @@ class alt_string
|
|||||||
alt_string substr(std::size_t pos = 0, std::size_t count = npos) const
|
alt_string substr(std::size_t pos = 0, std::size_t count = npos) const
|
||||||
{
|
{
|
||||||
const std::string s = str_impl.substr(pos, count);
|
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)
|
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;
|
alt_json doc;
|
||||||
doc["list"] = {1, 0, 2};
|
doc["list"] = { 1, 0, 2 };
|
||||||
alt_string dump = doc.dump();
|
alt_string dump = doc.dump();
|
||||||
CHECK(dump == R"({"list":[1,0,2]})");
|
CHECK(dump == R"({"list":[1,0,2]})");
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
alt_json doc;
|
alt_json doc;
|
||||||
doc["object"] = {{"currency", "USD"}, {"value", 42.99}};
|
doc["object"] = { { "currency", "USD" }, { "value", 42.99 } };
|
||||||
alt_string dump = doc.dump();
|
alt_string dump = doc.dump();
|
||||||
CHECK(dump == R"({"object":{"currency":"USD","value":42.99}})");
|
CHECK(dump == R"({"object":{"currency":"USD","value":42.99}})");
|
||||||
}
|
}
|
||||||
|
@ -142,7 +142,7 @@ TEST_CASE("Binary Formats" * doctest::skip())
|
|||||||
const auto bjdata_1_size = json::to_bjdata(j).size();
|
const auto bjdata_1_size = json::to_bjdata(j).size();
|
||||||
const auto bjdata_2_size = json::to_bjdata(j, true).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 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 cbor_size = json::to_cbor(j).size();
|
||||||
const auto msgpack_size = json::to_msgpack(j).size();
|
const auto msgpack_size = json::to_msgpack(j).size();
|
||||||
const auto ubjson_1_size = json::to_ubjson(j).size();
|
const auto ubjson_1_size = json::to_ubjson(j).size();
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -74,7 +74,7 @@ TEST_CASE("BSON")
|
|||||||
|
|
||||||
SECTION("array")
|
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),
|
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.exception.type_error.317] to serialize to BSON, top-level type must be object, but is array",
|
||||||
json::type_error&);
|
json::type_error&);
|
||||||
@ -83,7 +83,7 @@ TEST_CASE("BSON")
|
|||||||
|
|
||||||
SECTION("keys containing code-point U+0000 cannot be serialized to 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
|
#if JSON_DIAGNOSTICS
|
||||||
CHECK_THROWS_WITH_AS(json::to_bson(j),
|
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)",
|
"[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")
|
SECTION("string length must be at least 1")
|
||||||
{
|
{
|
||||||
// from https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=11175
|
// 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 _;
|
json _;
|
||||||
CHECK_THROWS_WITH_AS(
|
CHECK_THROWS_WITH_AS(
|
||||||
_ = json::from_bson(v),
|
_ = json::from_bson(v),
|
||||||
@ -128,20 +128,13 @@ TEST_CASE("BSON")
|
|||||||
|
|
||||||
SECTION("non-empty object with bool")
|
SECTION("non-empty object with bool")
|
||||||
{
|
{
|
||||||
json const j = {{"entry", true}};
|
json const j = { { "entry", true } };
|
||||||
|
|
||||||
std::vector<std::uint8_t> const expected = {
|
std::vector<std::uint8_t> const expected = {
|
||||||
0x0D,
|
0x0D, 0x00, 0x00,
|
||||||
0x00,
|
|
||||||
0x00,
|
|
||||||
0x00, // size (little endian)
|
0x00, // size (little endian)
|
||||||
0x08, // entry: boolean
|
0x08, // entry: boolean
|
||||||
'e',
|
'e', 'n', 't', 'r', 'y', '\x00',
|
||||||
'n',
|
|
||||||
't',
|
|
||||||
'r',
|
|
||||||
'y',
|
|
||||||
'\x00',
|
|
||||||
0x01, // value = true
|
0x01, // value = true
|
||||||
0x00 // end marker
|
0x00 // end marker
|
||||||
};
|
};
|
||||||
@ -156,20 +149,13 @@ TEST_CASE("BSON")
|
|||||||
|
|
||||||
SECTION("non-empty object with bool")
|
SECTION("non-empty object with bool")
|
||||||
{
|
{
|
||||||
json const j = {{"entry", false}};
|
json const j = { { "entry", false } };
|
||||||
|
|
||||||
std::vector<std::uint8_t> const expected = {
|
std::vector<std::uint8_t> const expected = {
|
||||||
0x0D,
|
0x0D, 0x00, 0x00,
|
||||||
0x00,
|
|
||||||
0x00,
|
|
||||||
0x00, // size (little endian)
|
0x00, // size (little endian)
|
||||||
0x08, // entry: boolean
|
0x08, // entry: boolean
|
||||||
'e',
|
'e', 'n', 't', 'r', 'y', '\x00',
|
||||||
'n',
|
|
||||||
't',
|
|
||||||
'r',
|
|
||||||
'y',
|
|
||||||
'\x00',
|
|
||||||
0x00, // value = false
|
0x00, // value = false
|
||||||
0x00 // end marker
|
0x00 // end marker
|
||||||
};
|
};
|
||||||
@ -184,7 +170,7 @@ TEST_CASE("BSON")
|
|||||||
|
|
||||||
SECTION("non-empty object with double")
|
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 = {
|
std::vector<std::uint8_t> const expected = {
|
||||||
0x14, 0x00, 0x00,
|
0x14, 0x00, 0x00,
|
||||||
@ -204,7 +190,7 @@ TEST_CASE("BSON")
|
|||||||
|
|
||||||
SECTION("non-empty object with string")
|
SECTION("non-empty object with string")
|
||||||
{
|
{
|
||||||
json const j = {{"entry", "bsonstr"}};
|
json const j = { { "entry", "bsonstr" } };
|
||||||
|
|
||||||
std::vector<std::uint8_t> const expected = {
|
std::vector<std::uint8_t> const expected = {
|
||||||
0x18, 0x00, 0x00,
|
0x18, 0x00, 0x00,
|
||||||
@ -224,20 +210,13 @@ TEST_CASE("BSON")
|
|||||||
|
|
||||||
SECTION("non-empty object with null member")
|
SECTION("non-empty object with null member")
|
||||||
{
|
{
|
||||||
json const j = {{"entry", nullptr}};
|
json const j = { { "entry", nullptr } };
|
||||||
|
|
||||||
std::vector<std::uint8_t> const expected = {
|
std::vector<std::uint8_t> const expected = {
|
||||||
0x0C,
|
0x0C, 0x00, 0x00,
|
||||||
0x00,
|
|
||||||
0x00,
|
|
||||||
0x00, // size (little endian)
|
0x00, // size (little endian)
|
||||||
0x0A, /// entry: null
|
0x0A, /// entry: null
|
||||||
'e',
|
'e', 'n', 't', 'r', 'y', '\x00',
|
||||||
'n',
|
|
||||||
't',
|
|
||||||
'r',
|
|
||||||
'y',
|
|
||||||
'\x00',
|
|
||||||
0x00 // end marker
|
0x00 // end marker
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -251,24 +230,13 @@ TEST_CASE("BSON")
|
|||||||
|
|
||||||
SECTION("non-empty object with integer (32-bit) member")
|
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 = {
|
std::vector<std::uint8_t> const expected = {
|
||||||
0x10,
|
0x10, 0x00, 0x00,
|
||||||
0x00,
|
|
||||||
0x00,
|
|
||||||
0x00, // size (little endian)
|
0x00, // size (little endian)
|
||||||
0x10, /// entry: int32
|
0x10, /// entry: int32
|
||||||
'e',
|
'e', 'n', 't', 'r', 'y', '\x00', 0x78, 0x56, 0x34, 0x12,
|
||||||
'n',
|
|
||||||
't',
|
|
||||||
'r',
|
|
||||||
'y',
|
|
||||||
'\x00',
|
|
||||||
0x78,
|
|
||||||
0x56,
|
|
||||||
0x34,
|
|
||||||
0x12,
|
|
||||||
0x00 // end marker
|
0x00 // end marker
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -282,7 +250,7 @@ TEST_CASE("BSON")
|
|||||||
|
|
||||||
SECTION("non-empty object with integer (64-bit) member")
|
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 = {
|
std::vector<std::uint8_t> const expected = {
|
||||||
0x14, 0x00, 0x00,
|
0x14, 0x00, 0x00,
|
||||||
@ -302,24 +270,13 @@ TEST_CASE("BSON")
|
|||||||
|
|
||||||
SECTION("non-empty object with negative integer (32-bit) member")
|
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 = {
|
std::vector<std::uint8_t> const expected = {
|
||||||
0x10,
|
0x10, 0x00, 0x00,
|
||||||
0x00,
|
|
||||||
0x00,
|
|
||||||
0x00, // size (little endian)
|
0x00, // size (little endian)
|
||||||
0x10, /// entry: int32
|
0x10, /// entry: int32
|
||||||
'e',
|
'e', 'n', 't', 'r', 'y', '\x00', 0xFF, 0xFF, 0xFF, 0xFF,
|
||||||
'n',
|
|
||||||
't',
|
|
||||||
'r',
|
|
||||||
'y',
|
|
||||||
'\x00',
|
|
||||||
0xFF,
|
|
||||||
0xFF,
|
|
||||||
0xFF,
|
|
||||||
0xFF,
|
|
||||||
0x00 // end marker
|
0x00 // end marker
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -333,24 +290,13 @@ TEST_CASE("BSON")
|
|||||||
|
|
||||||
SECTION("non-empty object with negative integer (64-bit) member")
|
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 = {
|
std::vector<std::uint8_t> const expected = {
|
||||||
0x10,
|
0x10, 0x00, 0x00,
|
||||||
0x00,
|
|
||||||
0x00,
|
|
||||||
0x00, // size (little endian)
|
0x00, // size (little endian)
|
||||||
0x10, /// entry: int32
|
0x10, /// entry: int32
|
||||||
'e',
|
'e', 'n', 't', 'r', 'y', '\x00', 0xFF, 0xFF, 0xFF, 0xFF,
|
||||||
'n',
|
|
||||||
't',
|
|
||||||
'r',
|
|
||||||
'y',
|
|
||||||
'\x00',
|
|
||||||
0xFF,
|
|
||||||
0xFF,
|
|
||||||
0xFF,
|
|
||||||
0xFF,
|
|
||||||
0x00 // end marker
|
0x00 // end marker
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -365,7 +311,7 @@ TEST_CASE("BSON")
|
|||||||
SECTION("non-empty object with unsigned integer (64-bit) member")
|
SECTION("non-empty object with unsigned integer (64-bit) member")
|
||||||
{
|
{
|
||||||
// directly encoding uint64 is not supported in bson (only for timestamp values)
|
// 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 = {
|
std::vector<std::uint8_t> const expected = {
|
||||||
0x14, 0x00, 0x00,
|
0x14, 0x00, 0x00,
|
||||||
@ -385,24 +331,13 @@ TEST_CASE("BSON")
|
|||||||
|
|
||||||
SECTION("non-empty object with small unsigned integer member")
|
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 = {
|
std::vector<std::uint8_t> const expected = {
|
||||||
0x10,
|
0x10, 0x00, 0x00,
|
||||||
0x00,
|
|
||||||
0x00,
|
|
||||||
0x00, // size (little endian)
|
0x00, // size (little endian)
|
||||||
0x10, /// entry: int32
|
0x10, /// entry: int32
|
||||||
'e',
|
'e', 'n', 't', 'r', 'y', '\x00', 0x42, 0x00, 0x00, 0x00,
|
||||||
'n',
|
|
||||||
't',
|
|
||||||
'r',
|
|
||||||
'y',
|
|
||||||
'\x00',
|
|
||||||
0x42,
|
|
||||||
0x00,
|
|
||||||
0x00,
|
|
||||||
0x00,
|
|
||||||
0x00 // end marker
|
0x00 // end marker
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -416,7 +351,7 @@ TEST_CASE("BSON")
|
|||||||
|
|
||||||
SECTION("non-empty object with object member")
|
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 = {
|
std::vector<std::uint8_t> const expected = {
|
||||||
0x11,
|
0x11,
|
||||||
@ -451,7 +386,7 @@ TEST_CASE("BSON")
|
|||||||
|
|
||||||
SECTION("non-empty object with array member")
|
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 = {
|
std::vector<std::uint8_t> const expected = {
|
||||||
0x11,
|
0x11,
|
||||||
@ -486,7 +421,7 @@ TEST_CASE("BSON")
|
|||||||
|
|
||||||
SECTION("non-empty object with non-empty array member")
|
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 = {
|
std::vector<std::uint8_t> const expected = {
|
||||||
0x49, 0x00, 0x00,
|
0x49, 0x00, 0x00,
|
||||||
@ -516,7 +451,7 @@ TEST_CASE("BSON")
|
|||||||
{
|
{
|
||||||
const size_t N = 10;
|
const size_t N = 10;
|
||||||
const auto s = std::vector<std::uint8_t>(N, 'x');
|
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 = {
|
std::vector<std::uint8_t> const expected = {
|
||||||
0x1B, 0x00, 0x00,
|
0x1B, 0x00, 0x00,
|
||||||
@ -543,8 +478,8 @@ TEST_CASE("BSON")
|
|||||||
SECTION("non-empty object with binary member with subtype")
|
SECTION("non-empty object with binary member with subtype")
|
||||||
{
|
{
|
||||||
// an MD5 hash
|
// 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};
|
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)}};
|
json const j = { { "entry", json::binary(md5hash, 5) } };
|
||||||
|
|
||||||
std::vector<std::uint8_t> const expected = {
|
std::vector<std::uint8_t> const expected = {
|
||||||
0x21, 0x00, 0x00,
|
0x21, 0x00, 0x00,
|
||||||
@ -571,87 +506,87 @@ TEST_CASE("BSON")
|
|||||||
SECTION("Some more complex document")
|
SECTION("Some more complex document")
|
||||||
{
|
{
|
||||||
// directly encoding uint64 is not supported in bson (only for timestamp values)
|
// 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,
|
0x00,
|
||||||
0x00,
|
0x00,
|
||||||
/*entry*/ 0x01,
|
/*entry*/ 0x01,
|
||||||
'd',
|
'd',
|
||||||
'o',
|
'o',
|
||||||
'u',
|
'u',
|
||||||
'b',
|
'b',
|
||||||
'l',
|
'l',
|
||||||
'e',
|
'e',
|
||||||
0x00,
|
0x00,
|
||||||
0x00,
|
0x00,
|
||||||
0x00,
|
0x00,
|
||||||
0x00,
|
0x00,
|
||||||
0x00,
|
0x00,
|
||||||
0x00,
|
0x00,
|
||||||
0x40,
|
0x40,
|
||||||
0x45,
|
0x45,
|
||||||
0x40,
|
0x40,
|
||||||
/*entry*/ 0x01,
|
/*entry*/ 0x01,
|
||||||
'e',
|
'e',
|
||||||
'n',
|
'n',
|
||||||
't',
|
't',
|
||||||
'r',
|
'r',
|
||||||
'y',
|
'y',
|
||||||
0x00,
|
0x00,
|
||||||
0xcd,
|
0xcd,
|
||||||
0xcc,
|
0xcc,
|
||||||
0xcc,
|
0xcc,
|
||||||
0xcc,
|
0xcc,
|
||||||
0xcc,
|
0xcc,
|
||||||
0xcc,
|
0xcc,
|
||||||
0x10,
|
0x10,
|
||||||
0x40,
|
0x40,
|
||||||
/*entry*/ 0x10,
|
/*entry*/ 0x10,
|
||||||
'n',
|
'n',
|
||||||
'u',
|
'u',
|
||||||
'm',
|
'm',
|
||||||
'b',
|
'b',
|
||||||
'e',
|
'e',
|
||||||
'r',
|
'r',
|
||||||
0x00,
|
0x00,
|
||||||
0x39,
|
0x39,
|
||||||
0x30,
|
0x30,
|
||||||
0x00,
|
0x00,
|
||||||
0x00,
|
0x00,
|
||||||
/*entry*/ 0x03,
|
/*entry*/ 0x03,
|
||||||
'o',
|
'o',
|
||||||
'b',
|
'b',
|
||||||
'j',
|
'j',
|
||||||
'e',
|
'e',
|
||||||
'c',
|
'c',
|
||||||
't',
|
't',
|
||||||
0x00,
|
0x00,
|
||||||
/*entry: obj-size */ 0x17,
|
/*entry: obj-size */ 0x17,
|
||||||
0x00,
|
0x00,
|
||||||
0x00,
|
0x00,
|
||||||
0x00,
|
0x00,
|
||||||
/*entry: obj-entry*/ 0x02,
|
/*entry: obj-entry*/ 0x02,
|
||||||
's',
|
's',
|
||||||
't',
|
't',
|
||||||
'r',
|
'r',
|
||||||
'i',
|
'i',
|
||||||
'n',
|
'n',
|
||||||
'g',
|
'g',
|
||||||
0x00,
|
0x00,
|
||||||
0x06,
|
0x06,
|
||||||
0x00,
|
0x00,
|
||||||
0x00,
|
0x00,
|
||||||
0x00,
|
0x00,
|
||||||
'v',
|
'v',
|
||||||
'a',
|
'a',
|
||||||
'l',
|
'l',
|
||||||
'u',
|
'u',
|
||||||
'e',
|
'e',
|
||||||
0,
|
0,
|
||||||
/*entry: obj-term.*/ 0x00,
|
/*entry: obj-term.*/ 0x00,
|
||||||
/*obj-term*/ 0x00};
|
/*obj-term*/ 0x00 };
|
||||||
|
|
||||||
const auto result = json::to_bson(j);
|
const auto result = json::to_bson(j);
|
||||||
CHECK(result == expected);
|
CHECK(result == expected);
|
||||||
@ -666,10 +601,10 @@ TEST_CASE("BSON")
|
|||||||
{
|
{
|
||||||
SECTION("Example 1")
|
SECTION("Example 1")
|
||||||
{
|
{
|
||||||
std::vector<std::uint8_t> input = {0x16, 0x00, 0x00, 0x00, 0x02, 'h', 'e', 'l', 'l', 'o', 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};
|
0x06, 0x00, 0x00, 0x00, 'w', 'o', 'r', 'l', 'd', 0x00, 0x00 };
|
||||||
json parsed = json::from_bson(input);
|
json parsed = json::from_bson(input);
|
||||||
json expected = {{"hello", "world"}};
|
json expected = { { "hello", "world" } };
|
||||||
CHECK(parsed == expected);
|
CHECK(parsed == expected);
|
||||||
auto dumped = json::to_bson(parsed);
|
auto dumped = json::to_bson(parsed);
|
||||||
CHECK(dumped == input);
|
CHECK(dumped == input);
|
||||||
@ -678,11 +613,11 @@ TEST_CASE("BSON")
|
|||||||
|
|
||||||
SECTION("Example 2")
|
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,
|
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 parsed = json::from_bson(input);
|
||||||
json expected = {{"BSON", {"awesome", 5.05, 1986}}};
|
json expected = { { "BSON", { "awesome", 5.05, 1986 } } };
|
||||||
CHECK(parsed == expected);
|
CHECK(parsed == expected);
|
||||||
auto dumped = json::to_bson(parsed);
|
auto dumped = json::to_bson(parsed);
|
||||||
CHECK(dumped == input);
|
CHECK(dumped == input);
|
||||||
@ -693,87 +628,87 @@ TEST_CASE("BSON")
|
|||||||
|
|
||||||
TEST_CASE("BSON input/output_adapters")
|
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,
|
0x00,
|
||||||
0x00,
|
0x00,
|
||||||
/*entry*/ 0x01,
|
/*entry*/ 0x01,
|
||||||
'd',
|
'd',
|
||||||
'o',
|
'o',
|
||||||
'u',
|
'u',
|
||||||
'b',
|
'b',
|
||||||
'l',
|
'l',
|
||||||
'e',
|
'e',
|
||||||
0x00,
|
0x00,
|
||||||
0x00,
|
0x00,
|
||||||
0x00,
|
0x00,
|
||||||
0x00,
|
0x00,
|
||||||
0x00,
|
0x00,
|
||||||
0x00,
|
0x00,
|
||||||
0x40,
|
0x40,
|
||||||
0x45,
|
0x45,
|
||||||
0x40,
|
0x40,
|
||||||
/*entry*/ 0x01,
|
/*entry*/ 0x01,
|
||||||
'e',
|
'e',
|
||||||
'n',
|
'n',
|
||||||
't',
|
't',
|
||||||
'r',
|
'r',
|
||||||
'y',
|
'y',
|
||||||
0x00,
|
0x00,
|
||||||
0xcd,
|
0xcd,
|
||||||
0xcc,
|
0xcc,
|
||||||
0xcc,
|
0xcc,
|
||||||
0xcc,
|
0xcc,
|
||||||
0xcc,
|
0xcc,
|
||||||
0xcc,
|
0xcc,
|
||||||
0x10,
|
0x10,
|
||||||
0x40,
|
0x40,
|
||||||
/*entry*/ 0x10,
|
/*entry*/ 0x10,
|
||||||
'n',
|
'n',
|
||||||
'u',
|
'u',
|
||||||
'm',
|
'm',
|
||||||
'b',
|
'b',
|
||||||
'e',
|
'e',
|
||||||
'r',
|
'r',
|
||||||
0x00,
|
0x00,
|
||||||
0x39,
|
0x39,
|
||||||
0x30,
|
0x30,
|
||||||
0x00,
|
0x00,
|
||||||
0x00,
|
0x00,
|
||||||
/*entry*/ 0x03,
|
/*entry*/ 0x03,
|
||||||
'o',
|
'o',
|
||||||
'b',
|
'b',
|
||||||
'j',
|
'j',
|
||||||
'e',
|
'e',
|
||||||
'c',
|
'c',
|
||||||
't',
|
't',
|
||||||
0x00,
|
0x00,
|
||||||
/*entry: obj-size */ 0x17,
|
/*entry: obj-size */ 0x17,
|
||||||
0x00,
|
0x00,
|
||||||
0x00,
|
0x00,
|
||||||
0x00,
|
0x00,
|
||||||
/*entry: obj-entry*/ 0x02,
|
/*entry: obj-entry*/ 0x02,
|
||||||
's',
|
's',
|
||||||
't',
|
't',
|
||||||
'r',
|
'r',
|
||||||
'i',
|
'i',
|
||||||
'n',
|
'n',
|
||||||
'g',
|
'g',
|
||||||
0x00,
|
0x00,
|
||||||
0x06,
|
0x06,
|
||||||
0x00,
|
0x00,
|
||||||
0x00,
|
0x00,
|
||||||
0x00,
|
0x00,
|
||||||
'v',
|
'v',
|
||||||
'a',
|
'a',
|
||||||
'l',
|
'l',
|
||||||
'u',
|
'u',
|
||||||
'e',
|
'e',
|
||||||
0,
|
0,
|
||||||
/*entry: obj-term.*/ 0x00,
|
/*entry: obj-term.*/ 0x00,
|
||||||
/*obj-term*/ 0x00};
|
/*obj-term*/ 0x00 };
|
||||||
|
|
||||||
json j2;
|
json j2;
|
||||||
CHECK_NOTHROW(j2 = json::from_bson(bson_representation));
|
CHECK_NOTHROW(j2 = json::from_bson(bson_representation));
|
||||||
@ -895,13 +830,10 @@ TEST_CASE("Incomplete BSON Input")
|
|||||||
SECTION("Incomplete BSON Input 1")
|
SECTION("Incomplete BSON Input 1")
|
||||||
{
|
{
|
||||||
std::vector<std::uint8_t> const incomplete_bson = {
|
std::vector<std::uint8_t> const incomplete_bson = {
|
||||||
0x0D,
|
0x0D, 0x00, 0x00,
|
||||||
0x00,
|
|
||||||
0x00,
|
|
||||||
0x00, // size (little endian)
|
0x00, // size (little endian)
|
||||||
0x08, // entry: boolean
|
0x08, // entry: boolean
|
||||||
'e',
|
'e', 'n',
|
||||||
'n',
|
|
||||||
't' // unexpected EOF
|
't' // unexpected EOF
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -919,9 +851,7 @@ TEST_CASE("Incomplete BSON Input")
|
|||||||
SECTION("Incomplete BSON Input 2")
|
SECTION("Incomplete BSON Input 2")
|
||||||
{
|
{
|
||||||
std::vector<std::uint8_t> const incomplete_bson = {
|
std::vector<std::uint8_t> const incomplete_bson = {
|
||||||
0x0D,
|
0x0D, 0x00, 0x00,
|
||||||
0x00,
|
|
||||||
0x00,
|
|
||||||
0x00, // size (little endian)
|
0x00, // size (little endian)
|
||||||
0x08, // entry: boolean, unexpected EOF
|
0x08, // entry: boolean, unexpected EOF
|
||||||
};
|
};
|
||||||
@ -982,7 +912,7 @@ TEST_CASE("Incomplete BSON Input")
|
|||||||
{
|
{
|
||||||
SECTION("key")
|
SECTION("key")
|
||||||
{
|
{
|
||||||
json const j = {{"key", "value"}};
|
json const j = { { "key", "value" } };
|
||||||
auto bson_vec = json::to_bson(j);
|
auto bson_vec = json::to_bson(j);
|
||||||
SaxCountdown scp(2);
|
SaxCountdown scp(2);
|
||||||
CHECK(!json::sax_parse(bson_vec, &scp, json::input_format_t::bson));
|
CHECK(!json::sax_parse(bson_vec, &scp, json::input_format_t::bson));
|
||||||
@ -990,7 +920,7 @@ TEST_CASE("Incomplete BSON Input")
|
|||||||
|
|
||||||
SECTION("array")
|
SECTION("array")
|
||||||
{
|
{
|
||||||
json const j = {{"entry", json::array()}};
|
json const j = { { "entry", json::array() } };
|
||||||
auto bson_vec = json::to_bson(j);
|
auto bson_vec = json::to_bson(j);
|
||||||
SaxCountdown scp(2);
|
SaxCountdown scp(2);
|
||||||
CHECK(!json::sax_parse(bson_vec, &scp, json::input_format_t::bson));
|
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")
|
TEST_CASE("Unsupported BSON input")
|
||||||
{
|
{
|
||||||
std::vector<std::uint8_t> const bson = {
|
std::vector<std::uint8_t> const bson = {
|
||||||
0x0C,
|
0x0C, 0x00, 0x00,
|
||||||
0x00,
|
|
||||||
0x00,
|
|
||||||
0x00, // size (little endian)
|
0x00, // size (little endian)
|
||||||
0xFF, // entry type: Min key (not supported yet)
|
0xFF, // entry type: Min key (not supported yet)
|
||||||
'e',
|
'e', 'n', 't', 'r', 'y', '\x00',
|
||||||
'n',
|
|
||||||
't',
|
|
||||||
'r',
|
|
||||||
'y',
|
|
||||||
'\x00',
|
|
||||||
0x00 // end marker
|
0x00 // end marker
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -1074,7 +997,7 @@ TEST_CASE("BSON numerical data")
|
|||||||
{
|
{
|
||||||
CAPTURE(i)
|
CAPTURE(i)
|
||||||
|
|
||||||
json const j = {{"entry", i}};
|
json const j = { { "entry", i } };
|
||||||
CHECK(j.at("entry").is_number_integer());
|
CHECK(j.at("entry").is_number_integer());
|
||||||
|
|
||||||
std::uint64_t const iu = *reinterpret_cast<const std::uint64_t*>(&i);
|
std::uint64_t const iu = *reinterpret_cast<const std::uint64_t*>(&i);
|
||||||
@ -1114,37 +1037,37 @@ TEST_CASE("BSON numerical data")
|
|||||||
|
|
||||||
SECTION("signed std::int32_t: INT32_MIN .. INT32_MAX")
|
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,
|
-2147483647L,
|
||||||
-1000000000L,
|
-1000000000L,
|
||||||
-100000000L,
|
-100000000L,
|
||||||
-10000000L,
|
-10000000L,
|
||||||
-1000000L,
|
-1000000L,
|
||||||
-100000L,
|
-100000L,
|
||||||
-10000L,
|
-10000L,
|
||||||
-1000L,
|
-1000L,
|
||||||
-100L,
|
-100L,
|
||||||
-10L,
|
-10L,
|
||||||
-1L,
|
-1L,
|
||||||
0L,
|
0L,
|
||||||
1L,
|
1L,
|
||||||
10L,
|
10L,
|
||||||
100L,
|
100L,
|
||||||
1000L,
|
1000L,
|
||||||
10000L,
|
10000L,
|
||||||
100000L,
|
100000L,
|
||||||
1000000L,
|
1000000L,
|
||||||
10000000L,
|
10000000L,
|
||||||
100000000L,
|
100000000L,
|
||||||
1000000000L,
|
1000000000L,
|
||||||
2147483646L,
|
2147483646L,
|
||||||
(std::numeric_limits<int32_t>::max)()};
|
(std::numeric_limits<int32_t>::max)() };
|
||||||
|
|
||||||
for (const auto i : numbers)
|
for (const auto i : numbers)
|
||||||
{
|
{
|
||||||
CAPTURE(i)
|
CAPTURE(i)
|
||||||
|
|
||||||
json const j = {{"entry", i}};
|
json const j = { { "entry", i } };
|
||||||
CHECK(j.at("entry").is_number_integer());
|
CHECK(j.at("entry").is_number_integer());
|
||||||
|
|
||||||
std::uint32_t const iu = *reinterpret_cast<const std::uint32_t*>(&i);
|
std::uint32_t const iu = *reinterpret_cast<const std::uint32_t*>(&i);
|
||||||
@ -1198,7 +1121,7 @@ TEST_CASE("BSON numerical data")
|
|||||||
{
|
{
|
||||||
CAPTURE(i)
|
CAPTURE(i)
|
||||||
|
|
||||||
json const j = {{"entry", i}};
|
json const j = { { "entry", i } };
|
||||||
CHECK(j.at("entry").is_number_integer());
|
CHECK(j.at("entry").is_number_integer());
|
||||||
|
|
||||||
std::uint64_t const iu = *reinterpret_cast<const std::uint64_t*>(&i);
|
std::uint64_t const iu = *reinterpret_cast<const std::uint64_t*>(&i);
|
||||||
@ -1241,25 +1164,25 @@ TEST_CASE("BSON numerical data")
|
|||||||
{
|
{
|
||||||
SECTION("unsigned std::uint64_t: 0 .. INT32_MAX")
|
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,
|
1ULL,
|
||||||
10ULL,
|
10ULL,
|
||||||
100ULL,
|
100ULL,
|
||||||
1000ULL,
|
1000ULL,
|
||||||
10000ULL,
|
10000ULL,
|
||||||
100000ULL,
|
100000ULL,
|
||||||
1000000ULL,
|
1000000ULL,
|
||||||
10000000ULL,
|
10000000ULL,
|
||||||
100000000ULL,
|
100000000ULL,
|
||||||
1000000000ULL,
|
1000000000ULL,
|
||||||
2147483646ULL,
|
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)
|
for (const auto i : numbers)
|
||||||
{
|
{
|
||||||
CAPTURE(i)
|
CAPTURE(i)
|
||||||
|
|
||||||
json const j = {{"entry", i}};
|
json const j = { { "entry", i } };
|
||||||
|
|
||||||
auto iu = i;
|
auto iu = i;
|
||||||
std::vector<std::uint8_t> const expected_bson = {
|
std::vector<std::uint8_t> const expected_bson = {
|
||||||
@ -1315,7 +1238,7 @@ TEST_CASE("BSON numerical data")
|
|||||||
{
|
{
|
||||||
CAPTURE(i)
|
CAPTURE(i)
|
||||||
|
|
||||||
json const j = {{"entry", i}};
|
json const j = { { "entry", i } };
|
||||||
|
|
||||||
auto iu = i;
|
auto iu = i;
|
||||||
std::vector<std::uint8_t> const expected_bson = {
|
std::vector<std::uint8_t> const expected_bson = {
|
||||||
@ -1367,7 +1290,7 @@ TEST_CASE("BSON numerical data")
|
|||||||
{
|
{
|
||||||
CAPTURE(i)
|
CAPTURE(i)
|
||||||
|
|
||||||
json const j = {{"entry", i}};
|
json const j = { { "entry", i } };
|
||||||
|
|
||||||
auto iu = i;
|
auto iu = i;
|
||||||
std::vector<std::uint8_t> const expected_bson = {
|
std::vector<std::uint8_t> const expected_bson = {
|
||||||
@ -1413,11 +1336,11 @@ TEST_CASE("BSON roundtrips" * doctest::skip())
|
|||||||
{
|
{
|
||||||
SECTION("reference files")
|
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/2.json",
|
||||||
TEST_DATA_DIRECTORY "/json.org/3.json",
|
TEST_DATA_DIRECTORY "/json.org/3.json",
|
||||||
TEST_DATA_DIRECTORY "/json.org/4.json",
|
TEST_DATA_DIRECTORY "/json.org/4.json",
|
||||||
TEST_DATA_DIRECTORY "/json.org/5.json"})
|
TEST_DATA_DIRECTORY "/json.org/5.json" })
|
||||||
{
|
{
|
||||||
CAPTURE(filename)
|
CAPTURE(filename)
|
||||||
|
|
||||||
@ -1460,7 +1383,7 @@ TEST_CASE("BSON roundtrips" * doctest::skip())
|
|||||||
// parse BSON file
|
// parse BSON file
|
||||||
auto packed = utils::read_binary_file(filename + ".bson");
|
auto packed = utils::read_binary_file(filename + ".bson");
|
||||||
json j2;
|
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
|
// compare parsed JSON values
|
||||||
CHECK(j1 == j2);
|
CHECK(j1 == j2);
|
||||||
|
@ -45,7 +45,7 @@ TEST_CASE("byte_container_with_subtype")
|
|||||||
|
|
||||||
SECTION("comparisons")
|
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>> container1;
|
||||||
nlohmann::byte_container_with_subtype<std::vector<std::uint8_t>> container2({}, 42);
|
nlohmann::byte_container_with_subtype<std::vector<std::uint8_t>> container2({}, 42);
|
||||||
nlohmann::byte_container_with_subtype<std::vector<std::uint8_t>> container3(bytes);
|
nlohmann::byte_container_with_subtype<std::vector<std::uint8_t>> container3(bytes);
|
||||||
|
@ -74,8 +74,8 @@ TEST_CASE("capacity")
|
|||||||
|
|
||||||
SECTION("filled array")
|
SECTION("filled array")
|
||||||
{
|
{
|
||||||
json j = {1, 2, 3}; // NOLINT(misc-const-correctness)
|
json j = { 1, 2, 3 }; // NOLINT(misc-const-correctness)
|
||||||
const json j_const = {1, 2, 3};
|
const json j_const = { 1, 2, 3 };
|
||||||
|
|
||||||
SECTION("result of empty")
|
SECTION("result of empty")
|
||||||
{
|
{
|
||||||
@ -113,8 +113,8 @@ TEST_CASE("capacity")
|
|||||||
|
|
||||||
SECTION("filled object")
|
SECTION("filled object")
|
||||||
{
|
{
|
||||||
json j = {{"one", 1}, {"two", 2}, {"three", 3}}; // NOLINT(misc-const-correctness)
|
json j = { { "one", 1 }, { "two", 2 }, { "three", 3 } }; // NOLINT(misc-const-correctness)
|
||||||
const json j_const = {{"one", 1}, {"two", 2}, {"three", 3}};
|
const json j_const = { { "one", 1 }, { "two", 2 }, { "three", 3 } };
|
||||||
|
|
||||||
SECTION("result of empty")
|
SECTION("result of empty")
|
||||||
{
|
{
|
||||||
@ -269,8 +269,8 @@ TEST_CASE("capacity")
|
|||||||
|
|
||||||
SECTION("filled array")
|
SECTION("filled array")
|
||||||
{
|
{
|
||||||
json j = {1, 2, 3}; // NOLINT(misc-const-correctness)
|
json j = { 1, 2, 3 }; // NOLINT(misc-const-correctness)
|
||||||
const json j_const = {1, 2, 3};
|
const json j_const = { 1, 2, 3 };
|
||||||
|
|
||||||
SECTION("result of size")
|
SECTION("result of size")
|
||||||
{
|
{
|
||||||
@ -312,8 +312,8 @@ TEST_CASE("capacity")
|
|||||||
|
|
||||||
SECTION("filled object")
|
SECTION("filled object")
|
||||||
{
|
{
|
||||||
json j = {{"one", 1}, {"two", 2}, {"three", 3}}; // NOLINT(misc-const-correctness)
|
json j = { { "one", 1 }, { "two", 2 }, { "three", 3 } }; // NOLINT(misc-const-correctness)
|
||||||
const json j_const = {{"one", 1}, {"two", 2}, {"three", 3}};
|
const json j_const = { { "one", 1 }, { "two", 2 }, { "three", 3 } };
|
||||||
|
|
||||||
SECTION("result of size")
|
SECTION("result of size")
|
||||||
{
|
{
|
||||||
@ -454,8 +454,8 @@ TEST_CASE("capacity")
|
|||||||
|
|
||||||
SECTION("filled array")
|
SECTION("filled array")
|
||||||
{
|
{
|
||||||
json j = {1, 2, 3}; // NOLINT(misc-const-correctness)
|
json j = { 1, 2, 3 }; // NOLINT(misc-const-correctness)
|
||||||
const json j_const = {1, 2, 3};
|
const json j_const = { 1, 2, 3 };
|
||||||
|
|
||||||
SECTION("result of max_size")
|
SECTION("result of max_size")
|
||||||
{
|
{
|
||||||
@ -481,8 +481,8 @@ TEST_CASE("capacity")
|
|||||||
|
|
||||||
SECTION("filled object")
|
SECTION("filled object")
|
||||||
{
|
{
|
||||||
json j = {{"one", 1}, {"two", 2}, {"three", 3}}; // NOLINT(misc-const-correctness)
|
json j = { { "one", 1 }, { "two", 2 }, { "three", 3 } }; // NOLINT(misc-const-correctness)
|
||||||
const json j_const = {{"one", 1}, {"two", 2}, {"three", 3}};
|
const json j_const = { { "one", 1 }, { "two", 2 }, { "three", 3 } };
|
||||||
|
|
||||||
SECTION("result of max_size")
|
SECTION("result of max_size")
|
||||||
{
|
{
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -141,14 +141,14 @@ TEST_CASE("const_iterator class")
|
|||||||
|
|
||||||
SECTION("object")
|
SECTION("object")
|
||||||
{
|
{
|
||||||
json const j({{"foo", "bar"}});
|
json const j({ { "foo", "bar" } });
|
||||||
json::const_iterator const it = j.cbegin();
|
json::const_iterator const it = j.cbegin();
|
||||||
CHECK(*it == json("bar"));
|
CHECK(*it == json("bar"));
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("array")
|
SECTION("array")
|
||||||
{
|
{
|
||||||
json const j({1, 2, 3, 4});
|
json const j({ 1, 2, 3, 4 });
|
||||||
json::const_iterator const it = j.cbegin();
|
json::const_iterator const it = j.cbegin();
|
||||||
CHECK(*it == json(1));
|
CHECK(*it == json(1));
|
||||||
}
|
}
|
||||||
@ -174,14 +174,14 @@ TEST_CASE("const_iterator class")
|
|||||||
|
|
||||||
SECTION("object")
|
SECTION("object")
|
||||||
{
|
{
|
||||||
json const j({{"foo", "bar"}});
|
json const j({ { "foo", "bar" } });
|
||||||
json::const_iterator const it = j.cbegin();
|
json::const_iterator const it = j.cbegin();
|
||||||
CHECK(std::string(it->type_name()) == "string");
|
CHECK(std::string(it->type_name()) == "string");
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("array")
|
SECTION("array")
|
||||||
{
|
{
|
||||||
json const j({1, 2, 3, 4});
|
json const j({ 1, 2, 3, 4 });
|
||||||
json::const_iterator const it = j.cbegin();
|
json::const_iterator const it = j.cbegin();
|
||||||
CHECK(std::string(it->type_name()) == "number");
|
CHECK(std::string(it->type_name()) == "number");
|
||||||
}
|
}
|
||||||
@ -214,7 +214,7 @@ TEST_CASE("const_iterator class")
|
|||||||
|
|
||||||
SECTION("object")
|
SECTION("object")
|
||||||
{
|
{
|
||||||
json const j({{"foo", "bar"}});
|
json const j({ { "foo", "bar" } });
|
||||||
json::const_iterator it = j.cbegin();
|
json::const_iterator it = j.cbegin();
|
||||||
CHECK((it.m_it.object_iterator == it.m_object->m_data.m_value.object->begin()));
|
CHECK((it.m_it.object_iterator == it.m_object->m_data.m_value.object->begin()));
|
||||||
it++;
|
it++;
|
||||||
@ -223,7 +223,7 @@ TEST_CASE("const_iterator class")
|
|||||||
|
|
||||||
SECTION("array")
|
SECTION("array")
|
||||||
{
|
{
|
||||||
json const j({1, 2, 3, 4});
|
json const j({ 1, 2, 3, 4 });
|
||||||
json::const_iterator it = j.cbegin();
|
json::const_iterator it = j.cbegin();
|
||||||
CHECK((it.m_it.array_iterator == it.m_object->m_data.m_value.array->begin()));
|
CHECK((it.m_it.array_iterator == it.m_object->m_data.m_value.array->begin()));
|
||||||
it++;
|
it++;
|
||||||
@ -265,7 +265,7 @@ TEST_CASE("const_iterator class")
|
|||||||
|
|
||||||
SECTION("object")
|
SECTION("object")
|
||||||
{
|
{
|
||||||
json const j({{"foo", "bar"}});
|
json const j({ { "foo", "bar" } });
|
||||||
json::const_iterator it = j.cbegin();
|
json::const_iterator it = j.cbegin();
|
||||||
CHECK((it.m_it.object_iterator == it.m_object->m_data.m_value.object->begin()));
|
CHECK((it.m_it.object_iterator == it.m_object->m_data.m_value.object->begin()));
|
||||||
++it;
|
++it;
|
||||||
@ -274,7 +274,7 @@ TEST_CASE("const_iterator class")
|
|||||||
|
|
||||||
SECTION("array")
|
SECTION("array")
|
||||||
{
|
{
|
||||||
json const j({1, 2, 3, 4});
|
json const j({ 1, 2, 3, 4 });
|
||||||
json::const_iterator it = j.cbegin();
|
json::const_iterator it = j.cbegin();
|
||||||
CHECK((it.m_it.array_iterator == it.m_object->m_data.m_value.array->begin()));
|
CHECK((it.m_it.array_iterator == it.m_object->m_data.m_value.array->begin()));
|
||||||
++it;
|
++it;
|
||||||
@ -314,7 +314,7 @@ TEST_CASE("const_iterator class")
|
|||||||
|
|
||||||
SECTION("object")
|
SECTION("object")
|
||||||
{
|
{
|
||||||
json const j({{"foo", "bar"}});
|
json const j({ { "foo", "bar" } });
|
||||||
json::const_iterator it = j.cend();
|
json::const_iterator it = j.cend();
|
||||||
CHECK((it.m_it.object_iterator == it.m_object->m_data.m_value.object->end()));
|
CHECK((it.m_it.object_iterator == it.m_object->m_data.m_value.object->end()));
|
||||||
it--;
|
it--;
|
||||||
@ -323,7 +323,7 @@ TEST_CASE("const_iterator class")
|
|||||||
|
|
||||||
SECTION("array")
|
SECTION("array")
|
||||||
{
|
{
|
||||||
json const j({1, 2, 3, 4});
|
json const j({ 1, 2, 3, 4 });
|
||||||
json::const_iterator it = j.cend();
|
json::const_iterator it = j.cend();
|
||||||
CHECK((it.m_it.array_iterator == it.m_object->m_data.m_value.array->end()));
|
CHECK((it.m_it.array_iterator == it.m_object->m_data.m_value.array->end()));
|
||||||
it--;
|
it--;
|
||||||
@ -363,7 +363,7 @@ TEST_CASE("const_iterator class")
|
|||||||
|
|
||||||
SECTION("object")
|
SECTION("object")
|
||||||
{
|
{
|
||||||
json const j({{"foo", "bar"}});
|
json const j({ { "foo", "bar" } });
|
||||||
json::const_iterator it = j.cend();
|
json::const_iterator it = j.cend();
|
||||||
CHECK((it.m_it.object_iterator == it.m_object->m_data.m_value.object->end()));
|
CHECK((it.m_it.object_iterator == it.m_object->m_data.m_value.object->end()));
|
||||||
--it;
|
--it;
|
||||||
@ -372,7 +372,7 @@ TEST_CASE("const_iterator class")
|
|||||||
|
|
||||||
SECTION("array")
|
SECTION("array")
|
||||||
{
|
{
|
||||||
json const j({1, 2, 3, 4});
|
json const j({ 1, 2, 3, 4 });
|
||||||
json::const_iterator it = j.cend();
|
json::const_iterator it = j.cend();
|
||||||
CHECK((it.m_it.array_iterator == it.m_object->m_data.m_value.array->end()));
|
CHECK((it.m_it.array_iterator == it.m_object->m_data.m_value.array->end()));
|
||||||
--it;
|
--it;
|
||||||
|
@ -131,14 +131,14 @@ TEST_CASE("iterator class")
|
|||||||
|
|
||||||
SECTION("object")
|
SECTION("object")
|
||||||
{
|
{
|
||||||
json j({{"foo", "bar"}});
|
json j({ { "foo", "bar" } });
|
||||||
json::iterator const it = j.begin();
|
json::iterator const it = j.begin();
|
||||||
CHECK(*it == json("bar"));
|
CHECK(*it == json("bar"));
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("array")
|
SECTION("array")
|
||||||
{
|
{
|
||||||
json j({1, 2, 3, 4});
|
json j({ 1, 2, 3, 4 });
|
||||||
json::iterator const it = j.begin();
|
json::iterator const it = j.begin();
|
||||||
CHECK(*it == json(1));
|
CHECK(*it == json(1));
|
||||||
}
|
}
|
||||||
@ -164,14 +164,14 @@ TEST_CASE("iterator class")
|
|||||||
|
|
||||||
SECTION("object")
|
SECTION("object")
|
||||||
{
|
{
|
||||||
json j({{"foo", "bar"}});
|
json j({ { "foo", "bar" } });
|
||||||
json::iterator const it = j.begin();
|
json::iterator const it = j.begin();
|
||||||
CHECK(std::string(it->type_name()) == "string");
|
CHECK(std::string(it->type_name()) == "string");
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("array")
|
SECTION("array")
|
||||||
{
|
{
|
||||||
json j({1, 2, 3, 4});
|
json j({ 1, 2, 3, 4 });
|
||||||
json::iterator const it = j.begin();
|
json::iterator const it = j.begin();
|
||||||
CHECK(std::string(it->type_name()) == "number");
|
CHECK(std::string(it->type_name()) == "number");
|
||||||
}
|
}
|
||||||
@ -204,7 +204,7 @@ TEST_CASE("iterator class")
|
|||||||
|
|
||||||
SECTION("object")
|
SECTION("object")
|
||||||
{
|
{
|
||||||
json j({{"foo", "bar"}});
|
json j({ { "foo", "bar" } });
|
||||||
json::iterator it = j.begin();
|
json::iterator it = j.begin();
|
||||||
CHECK((it.m_it.object_iterator == it.m_object->m_data.m_value.object->begin()));
|
CHECK((it.m_it.object_iterator == it.m_object->m_data.m_value.object->begin()));
|
||||||
it++;
|
it++;
|
||||||
@ -213,7 +213,7 @@ TEST_CASE("iterator class")
|
|||||||
|
|
||||||
SECTION("array")
|
SECTION("array")
|
||||||
{
|
{
|
||||||
json j({1, 2, 3, 4});
|
json j({ 1, 2, 3, 4 });
|
||||||
json::iterator it = j.begin();
|
json::iterator it = j.begin();
|
||||||
CHECK((it.m_it.array_iterator == it.m_object->m_data.m_value.array->begin()));
|
CHECK((it.m_it.array_iterator == it.m_object->m_data.m_value.array->begin()));
|
||||||
it++;
|
it++;
|
||||||
@ -255,7 +255,7 @@ TEST_CASE("iterator class")
|
|||||||
|
|
||||||
SECTION("object")
|
SECTION("object")
|
||||||
{
|
{
|
||||||
json j({{"foo", "bar"}});
|
json j({ { "foo", "bar" } });
|
||||||
json::iterator it = j.begin();
|
json::iterator it = j.begin();
|
||||||
CHECK((it.m_it.object_iterator == it.m_object->m_data.m_value.object->begin()));
|
CHECK((it.m_it.object_iterator == it.m_object->m_data.m_value.object->begin()));
|
||||||
++it;
|
++it;
|
||||||
@ -264,7 +264,7 @@ TEST_CASE("iterator class")
|
|||||||
|
|
||||||
SECTION("array")
|
SECTION("array")
|
||||||
{
|
{
|
||||||
json j({1, 2, 3, 4});
|
json j({ 1, 2, 3, 4 });
|
||||||
json::iterator it = j.begin();
|
json::iterator it = j.begin();
|
||||||
CHECK((it.m_it.array_iterator == it.m_object->m_data.m_value.array->begin()));
|
CHECK((it.m_it.array_iterator == it.m_object->m_data.m_value.array->begin()));
|
||||||
++it;
|
++it;
|
||||||
@ -304,7 +304,7 @@ TEST_CASE("iterator class")
|
|||||||
|
|
||||||
SECTION("object")
|
SECTION("object")
|
||||||
{
|
{
|
||||||
json j({{"foo", "bar"}});
|
json j({ { "foo", "bar" } });
|
||||||
json::iterator it = j.end();
|
json::iterator it = j.end();
|
||||||
CHECK((it.m_it.object_iterator == it.m_object->m_data.m_value.object->end()));
|
CHECK((it.m_it.object_iterator == it.m_object->m_data.m_value.object->end()));
|
||||||
it--;
|
it--;
|
||||||
@ -313,7 +313,7 @@ TEST_CASE("iterator class")
|
|||||||
|
|
||||||
SECTION("array")
|
SECTION("array")
|
||||||
{
|
{
|
||||||
json j({1, 2, 3, 4});
|
json j({ 1, 2, 3, 4 });
|
||||||
json::iterator it = j.end();
|
json::iterator it = j.end();
|
||||||
CHECK((it.m_it.array_iterator == it.m_object->m_data.m_value.array->end()));
|
CHECK((it.m_it.array_iterator == it.m_object->m_data.m_value.array->end()));
|
||||||
it--;
|
it--;
|
||||||
@ -353,7 +353,7 @@ TEST_CASE("iterator class")
|
|||||||
|
|
||||||
SECTION("object")
|
SECTION("object")
|
||||||
{
|
{
|
||||||
json j({{"foo", "bar"}});
|
json j({ { "foo", "bar" } });
|
||||||
json::iterator it = j.end();
|
json::iterator it = j.end();
|
||||||
CHECK((it.m_it.object_iterator == it.m_object->m_data.m_value.object->end()));
|
CHECK((it.m_it.object_iterator == it.m_object->m_data.m_value.object->end()));
|
||||||
--it;
|
--it;
|
||||||
@ -362,7 +362,7 @@ TEST_CASE("iterator class")
|
|||||||
|
|
||||||
SECTION("array")
|
SECTION("array")
|
||||||
{
|
{
|
||||||
json j({1, 2, 3, 4});
|
json j({ 1, 2, 3, 4 });
|
||||||
json::iterator it = j.end();
|
json::iterator it = j.end();
|
||||||
CHECK((it.m_it.array_iterator == it.m_object->m_data.m_value.array->end()));
|
CHECK((it.m_it.array_iterator == it.m_object->m_data.m_value.array->end()));
|
||||||
--it;
|
--it;
|
||||||
|
@ -333,7 +333,7 @@ TEST_CASE("parser class")
|
|||||||
|
|
||||||
SECTION("nonempty array")
|
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")
|
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;
|
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 {
|
json j_array = json::parse(s_array, [](int /*unused*/, json::parse_event_t /*unused*/, const json& /*unused*/) noexcept {
|
||||||
return true;
|
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")
|
SECTION("filter everything")
|
||||||
@ -1708,13 +1708,13 @@ TEST_CASE("parser class")
|
|||||||
return event != json::parse_event_t::value || j != json(2);
|
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 {
|
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);
|
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")
|
SECTION("filter object in array")
|
||||||
@ -1725,7 +1725,7 @@ TEST_CASE("parser class")
|
|||||||
|
|
||||||
// the specified object will be discarded, and removed.
|
// the specified object will be discarded, and removed.
|
||||||
CHECK(j_filtered1.size() == 2);
|
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 {
|
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;
|
return e != json::parse_event_t::object_end;
|
||||||
@ -1733,7 +1733,7 @@ TEST_CASE("parser class")
|
|||||||
|
|
||||||
// removed all objects in array.
|
// removed all objects in array.
|
||||||
CHECK(j_filtered2.size() == 1);
|
CHECK(j_filtered2.size() == 1);
|
||||||
CHECK(j_filtered2 == json({1}));
|
CHECK(j_filtered2 == json({ 1 }));
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("filter specific events")
|
SECTION("filter specific events")
|
||||||
@ -1753,7 +1753,7 @@ TEST_CASE("parser class")
|
|||||||
});
|
});
|
||||||
|
|
||||||
// the first completed object will be discarded
|
// 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
|
// 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")
|
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 j;
|
||||||
json::parser(nlohmann::detail::input_adapter(std::begin(v), std::end(v))).parse(true, j);
|
json::parser(nlohmann::detail::input_adapter(std::begin(v), std::end(v))).parse(true, j);
|
||||||
CHECK(j == json(true));
|
CHECK(j == json(true));
|
||||||
@ -1804,7 +1804,7 @@ TEST_CASE("parser class")
|
|||||||
|
|
||||||
SECTION("from std::array")
|
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 j;
|
||||||
json::parser(nlohmann::detail::input_adapter(std::begin(v), std::end(v))).parse(true, j);
|
json::parser(nlohmann::detail::input_adapter(std::begin(v), std::end(v))).parse(true, j);
|
||||||
CHECK(j == json(true));
|
CHECK(j == json(true));
|
||||||
@ -1812,7 +1812,7 @@ TEST_CASE("parser class")
|
|||||||
|
|
||||||
SECTION("from array")
|
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 j;
|
||||||
json::parser(nlohmann::detail::input_adapter(std::begin(v), std::end(v))).parse(true, j);
|
json::parser(nlohmann::detail::input_adapter(std::begin(v), std::end(v))).parse(true, j);
|
||||||
CHECK(j == json(true));
|
CHECK(j == json(true));
|
||||||
@ -1825,7 +1825,7 @@ TEST_CASE("parser class")
|
|||||||
|
|
||||||
SECTION("from std::string")
|
SECTION("from std::string")
|
||||||
{
|
{
|
||||||
std::string v = {'t', 'r', 'u', 'e'};
|
std::string v = { 't', 'r', 'u', 'e' };
|
||||||
json j;
|
json j;
|
||||||
json::parser(nlohmann::detail::input_adapter(std::begin(v), std::end(v))).parse(true, j);
|
json::parser(nlohmann::detail::input_adapter(std::begin(v), std::end(v))).parse(true, j);
|
||||||
CHECK(j == json(true));
|
CHECK(j == json(true));
|
||||||
@ -1833,7 +1833,7 @@ TEST_CASE("parser class")
|
|||||||
|
|
||||||
SECTION("from std::initializer_list")
|
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 j;
|
||||||
json::parser(nlohmann::detail::input_adapter(std::begin(v), std::end(v))).parse(true, j);
|
json::parser(nlohmann::detail::input_adapter(std::begin(v), std::end(v))).parse(true, j);
|
||||||
CHECK(j == json(true));
|
CHECK(j == json(true));
|
||||||
@ -1841,7 +1841,7 @@ TEST_CASE("parser class")
|
|||||||
|
|
||||||
SECTION("from std::valarray")
|
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 j;
|
||||||
json::parser(nlohmann::detail::input_adapter(std::begin(v), std::end(v))).parse(true, j);
|
json::parser(nlohmann::detail::input_adapter(std::begin(v), std::end(v))).parse(true, j);
|
||||||
CHECK(j == json(true));
|
CHECK(j == json(true));
|
||||||
|
@ -87,29 +87,23 @@ TEST_CASE("lexicographical comparison operators")
|
|||||||
|
|
||||||
SECTION("types")
|
SECTION("types")
|
||||||
{
|
{
|
||||||
std::vector<json::value_t> j_types = {json::value_t::null,
|
std::vector<json::value_t> j_types = {
|
||||||
json::value_t::boolean,
|
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::number_integer,
|
json::value_t::object, json::value_t::array, json::value_t::string, json::value_t::binary, json::value_t::discarded
|
||||||
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 = {
|
std::vector<std::vector<bool>> expected_lt = {
|
||||||
//0 1 2 3 4 5 6 7 8 9
|
//0 1 2 3 4 5 6 7 8 9
|
||||||
{f_, _t, _t, _t, _t, _t, _t, _t, _t, f_}, // 0
|
{ f_, _t, _t, _t, _t, _t, _t, _t, _t, f_ }, // 0
|
||||||
{f_, f_, _t, _t, _t, _t, _t, _t, _t, f_}, // 1
|
{ 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_ }, // 2
|
||||||
{f_, f_, f_, f_, f_, _t, _t, _t, _t, f_}, // 3
|
{ 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_, _t, _t, _t, _t, f_ }, // 4
|
||||||
{f_, f_, f_, f_, f_, f_, _t, _t, _t, f_}, // 5
|
{ 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_, _t, _t, f_ }, // 6
|
||||||
{f_, f_, f_, f_, f_, f_, f_, f_, _t, f_}, // 7
|
{ 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_ }, // 8
|
||||||
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 9
|
{ f_, f_, f_, f_, f_, f_, f_, f_, f_, f_ }, // 9
|
||||||
};
|
};
|
||||||
|
|
||||||
SECTION("comparison: less")
|
SECTION("comparison: less")
|
||||||
@ -139,16 +133,16 @@ TEST_CASE("lexicographical comparison operators")
|
|||||||
{
|
{
|
||||||
std::vector<std::vector<std::partial_ordering>> expected = {
|
std::vector<std::vector<std::partial_ordering>> expected = {
|
||||||
//0 1 2 3 4 5 6 7 8 9
|
//0 1 2 3 4 5 6 7 8 9
|
||||||
{eq, lt, lt, lt, lt, lt, lt, lt, lt, un}, // 0
|
{ eq, lt, lt, lt, lt, lt, lt, lt, lt, un }, // 0
|
||||||
{gt, eq, lt, lt, lt, lt, lt, lt, lt, un}, // 1
|
{ 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 }, // 2
|
||||||
{gt, gt, eq, eq, eq, lt, lt, lt, lt, un}, // 3
|
{ gt, gt, eq, eq, eq, lt, lt, lt, lt, un }, // 3
|
||||||
{gt, gt, eq, eq, eq, lt, lt, lt, lt, un}, // 4
|
{ 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, eq, lt, lt, lt, un }, // 5
|
||||||
{gt, gt, gt, gt, gt, gt, eq, lt, lt, un}, // 6
|
{ 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, eq, lt, un }, // 7
|
||||||
{gt, gt, gt, gt, gt, gt, gt, gt, eq, un}, // 8
|
{ gt, gt, gt, gt, gt, gt, gt, gt, eq, un }, // 8
|
||||||
{un, un, un, un, un, un, un, un, un, un}, // 9
|
{ un, un, un, un, un, un, un, un, un, un }, // 9
|
||||||
};
|
};
|
||||||
|
|
||||||
// check expected partial_ordering against expected boolean
|
// check expected partial_ordering against expected boolean
|
||||||
@ -197,94 +191,94 @@ TEST_CASE("lexicographical comparison operators")
|
|||||||
"bar", // 10 11
|
"bar", // 10 11
|
||||||
true,
|
true,
|
||||||
false, // 12 13
|
false, // 12 13
|
||||||
{1, 2, 3},
|
{ 1, 2, 3 },
|
||||||
{"one", "two", "three"}, // 14 15
|
{ "one", "two", "three" }, // 14 15
|
||||||
{{"first", 1}, {"second", 2}},
|
{ { "first", 1 }, { "second", 2 } },
|
||||||
{{"a", "A"}, {"b", {"B"}}}, // 16 17
|
{ { "a", "A" }, { "b", { "B" } } }, // 16 17
|
||||||
json::binary({1, 2, 3}),
|
json::binary({ 1, 2, 3 }),
|
||||||
json::binary({1, 2, 4}), // 18 19
|
json::binary({ 1, 2, 4 }), // 18 19
|
||||||
json(json::value_t::discarded),
|
json(json::value_t::discarded),
|
||||||
json(json::value_t::discarded) // 20 21
|
json(json::value_t::discarded) // 20 21
|
||||||
};
|
};
|
||||||
|
|
||||||
std::vector<std::vector<bool>> expected_eq = {
|
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
|
//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_ }, // 0
|
||||||
{_t, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 1
|
{ _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_, _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_, _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_, _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_, _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_, _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_, _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_ }, // 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_, 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_, _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_, _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_, _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_, _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_, _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_, _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_, _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_, _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_, _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_, _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_ }, // 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_ }, // 21
|
||||||
};
|
};
|
||||||
|
|
||||||
std::vector<std::vector<bool>> expected_lt = {
|
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
|
//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_ }, // 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_, _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_, _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_, 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_, _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, 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, _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_, _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_ }, // 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_, _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_, 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_, 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, 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_, _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_, _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_, 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, 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_, _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_, _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_ }, // 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_ }, // 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_ }, // 21
|
||||||
};
|
};
|
||||||
|
|
||||||
SECTION("compares unordered")
|
SECTION("compares unordered")
|
||||||
{
|
{
|
||||||
std::vector<std::vector<bool>> expected = {
|
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
|
//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 }, // 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_, 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 }, // 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 }, // 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 }, // 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 }, // 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 }, // 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_, 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 }, // 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_, _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 }, // 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 }, // 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 }, // 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 }, // 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 }, // 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 }, // 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 }, // 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 }, // 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 }, // 18
|
||||||
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t}, // 19
|
{ 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 }, // 20
|
||||||
{_t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t}, // 21
|
{ _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
|
// check if two values compare unordered as expected
|
||||||
@ -306,28 +300,28 @@ TEST_CASE("lexicographical comparison operators")
|
|||||||
{
|
{
|
||||||
std::vector<std::vector<bool>> expected = {
|
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
|
//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_ }, // 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_, 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_ }, // 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_ }, // 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_ }, // 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_ }, // 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_ }, // 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_, 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_ }, // 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_, _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_ }, // 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_ }, // 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_ }, // 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_ }, // 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_ }, // 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_ }, // 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_ }, // 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_ }, // 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_ }, // 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_ }, // 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_ }, // 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_ }, // 21
|
||||||
};
|
};
|
||||||
|
|
||||||
// check that two values compare unordered as expected (with legacy-mode enabled)
|
// 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 = {
|
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
|
//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 }, // 0
|
||||||
{eq, eq, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, un, un}, // 1
|
{ 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, 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, 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, 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, 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, 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, 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 }, // 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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 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
|
{ 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 }, // 20
|
||||||
{un, un, un, un, un, un, un, un, un, un, un, un, un, un, un, un, un, un, un, un, un, un}, // 21
|
{ 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
|
// check expected partial_ordering against expected booleans
|
||||||
@ -582,13 +576,13 @@ TEST_CASE("lexicographical comparison operators")
|
|||||||
return j != json(2);
|
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 {
|
json j_array = json::parse(s_array, [](int /*unused*/, json::parse_event_t /*unused*/, const json& j) noexcept {
|
||||||
return j != json(2);
|
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
|
#endif
|
||||||
|
@ -129,7 +129,7 @@ TEST_CASE("concepts")
|
|||||||
SECTION("Swappable")
|
SECTION("Swappable")
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
json j{1, 2, 3};
|
json j{ 1, 2, 3 };
|
||||||
json::iterator it1 = j.begin();
|
json::iterator it1 = j.begin();
|
||||||
json::iterator it2 = j.end();
|
json::iterator it2 = j.end();
|
||||||
swap(it1, it2);
|
swap(it1, it2);
|
||||||
@ -137,7 +137,7 @@ TEST_CASE("concepts")
|
|||||||
CHECK(it2 == j.begin());
|
CHECK(it2 == j.begin());
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
json j{1, 2, 3};
|
json j{ 1, 2, 3 };
|
||||||
json::const_iterator it1 = j.cbegin();
|
json::const_iterator it1 = j.cbegin();
|
||||||
json::const_iterator it2 = j.cend();
|
json::const_iterator it2 = j.cend();
|
||||||
swap(it1, it2);
|
swap(it1, it2);
|
||||||
|
@ -131,7 +131,7 @@ TEST_CASE("constructors")
|
|||||||
|
|
||||||
SECTION("filled object")
|
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);
|
json const j(o);
|
||||||
CHECK(j.type() == json::value_t::object);
|
CHECK(j.type() == json::value_t::object);
|
||||||
}
|
}
|
||||||
@ -140,12 +140,14 @@ TEST_CASE("constructors")
|
|||||||
SECTION("create an object (implicit)")
|
SECTION("create an object (implicit)")
|
||||||
{
|
{
|
||||||
// reference object
|
// 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);
|
json const j_reference(o_reference);
|
||||||
|
|
||||||
SECTION("std::map<json::string_t, json>")
|
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);
|
json const j(o);
|
||||||
CHECK(j.type() == json::value_t::object);
|
CHECK(j.type() == json::value_t::object);
|
||||||
CHECK(j == j_reference);
|
CHECK(j == j_reference);
|
||||||
@ -154,9 +156,9 @@ TEST_CASE("constructors")
|
|||||||
SECTION("std::map<std::string, std::string> #600")
|
SECTION("std::map<std::string, std::string> #600")
|
||||||
{
|
{
|
||||||
const std::map<std::string, std::string> m{
|
const std::map<std::string, std::string> m{
|
||||||
{"a", "b"},
|
{ "a", "b" },
|
||||||
{"c", "d"},
|
{ "c", "d" },
|
||||||
{"e", "f"},
|
{ "e", "f" },
|
||||||
};
|
};
|
||||||
|
|
||||||
json const j(m);
|
json const j(m);
|
||||||
@ -165,7 +167,8 @@ TEST_CASE("constructors")
|
|||||||
|
|
||||||
SECTION("std::map<const char*, json>")
|
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);
|
json const j(o);
|
||||||
CHECK(j.type() == json::value_t::object);
|
CHECK(j.type() == json::value_t::object);
|
||||||
CHECK(j == j_reference);
|
CHECK(j == j_reference);
|
||||||
@ -173,12 +176,8 @@ TEST_CASE("constructors")
|
|||||||
|
|
||||||
SECTION("std::multimap<json::string_t, json>")
|
SECTION("std::multimap<json::string_t, json>")
|
||||||
{
|
{
|
||||||
std::multimap<json::string_t, json> const o{{"a", json(1)},
|
std::multimap<json::string_t, json> const o{ { "a", json(1) }, { "b", json(1u) }, { "c", json(2.2) },
|
||||||
{"b", json(1u)},
|
{ "d", json(false) }, { "e", json("string") }, { "f", json() } };
|
||||||
{"c", json(2.2)},
|
|
||||||
{"d", json(false)},
|
|
||||||
{"e", json("string")},
|
|
||||||
{"f", json()}};
|
|
||||||
json const j(o);
|
json const j(o);
|
||||||
CHECK(j.type() == json::value_t::object);
|
CHECK(j.type() == json::value_t::object);
|
||||||
CHECK(j == j_reference);
|
CHECK(j == j_reference);
|
||||||
@ -186,12 +185,8 @@ TEST_CASE("constructors")
|
|||||||
|
|
||||||
SECTION("std::unordered_map<json::string_t, json>")
|
SECTION("std::unordered_map<json::string_t, json>")
|
||||||
{
|
{
|
||||||
std::unordered_map<json::string_t, json> const o{{"a", json(1)},
|
std::unordered_map<json::string_t, json> const o{ { "a", json(1) }, { "b", json(1u) }, { "c", json(2.2) },
|
||||||
{"b", json(1u)},
|
{ "d", json(false) }, { "e", json("string") }, { "f", json() } };
|
||||||
{"c", json(2.2)},
|
|
||||||
{"d", json(false)},
|
|
||||||
{"e", json("string")},
|
|
||||||
{"f", json()}};
|
|
||||||
json const j(o);
|
json const j(o);
|
||||||
CHECK(j.type() == json::value_t::object);
|
CHECK(j.type() == json::value_t::object);
|
||||||
CHECK(j == j_reference);
|
CHECK(j == j_reference);
|
||||||
@ -199,12 +194,8 @@ TEST_CASE("constructors")
|
|||||||
|
|
||||||
SECTION("std::unordered_multimap<json::string_t, json>")
|
SECTION("std::unordered_multimap<json::string_t, json>")
|
||||||
{
|
{
|
||||||
std::unordered_multimap<json::string_t, json> const o{{"a", json(1)},
|
std::unordered_multimap<json::string_t, json> const o{ { "a", json(1) }, { "b", json(1u) }, { "c", json(2.2) },
|
||||||
{"b", json(1u)},
|
{ "d", json(false) }, { "e", json("string") }, { "f", json() } };
|
||||||
{"c", json(2.2)},
|
|
||||||
{"d", json(false)},
|
|
||||||
{"e", json("string")},
|
|
||||||
{"f", json()}};
|
|
||||||
json const j(o);
|
json const j(o);
|
||||||
CHECK(j.type() == json::value_t::object);
|
CHECK(j.type() == json::value_t::object);
|
||||||
CHECK(j == j_reference);
|
CHECK(j == j_reference);
|
||||||
@ -212,7 +203,7 @@ TEST_CASE("constructors")
|
|||||||
|
|
||||||
SECTION("associative container literal")
|
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.type() == json::value_t::object);
|
||||||
CHECK(j == j_reference);
|
CHECK(j == j_reference);
|
||||||
}
|
}
|
||||||
@ -229,7 +220,7 @@ TEST_CASE("constructors")
|
|||||||
|
|
||||||
SECTION("filled array")
|
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);
|
json const j(a);
|
||||||
CHECK(j.type() == json::value_t::array);
|
CHECK(j.type() == json::value_t::array);
|
||||||
}
|
}
|
||||||
@ -238,12 +229,12 @@ TEST_CASE("constructors")
|
|||||||
SECTION("create an array (implicit)")
|
SECTION("create an array (implicit)")
|
||||||
{
|
{
|
||||||
// reference array
|
// 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);
|
json const j_reference(a_reference);
|
||||||
|
|
||||||
SECTION("std::list<json>")
|
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);
|
json const j(a);
|
||||||
CHECK(j.type() == json::value_t::array);
|
CHECK(j.type() == json::value_t::array);
|
||||||
CHECK(j == j_reference);
|
CHECK(j == j_reference);
|
||||||
@ -251,7 +242,7 @@ TEST_CASE("constructors")
|
|||||||
|
|
||||||
SECTION("std::pair")
|
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);
|
json const j(p);
|
||||||
|
|
||||||
CHECK(j.type() == json::value_t::array);
|
CHECK(j.type() == json::value_t::array);
|
||||||
@ -263,7 +254,7 @@ TEST_CASE("constructors")
|
|||||||
|
|
||||||
SECTION("std::pair with discarded values")
|
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>>();
|
const auto p = j.get<std::pair<int, float>>();
|
||||||
CHECK(p.first == j[0]);
|
CHECK(p.first == j[0]);
|
||||||
@ -272,7 +263,7 @@ TEST_CASE("constructors")
|
|||||||
|
|
||||||
SECTION("std::tuple")
|
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);
|
json const j(t);
|
||||||
|
|
||||||
CHECK(j.type() == json::value_t::array);
|
CHECK(j.type() == json::value_t::array);
|
||||||
@ -287,7 +278,7 @@ TEST_CASE("constructors")
|
|||||||
|
|
||||||
SECTION("std::tuple with discarded values")
|
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>>();
|
const auto t = j.get<std::tuple<int, float, std::string>>();
|
||||||
CHECK(std::get<0>(t) == j[0]);
|
CHECK(std::get<0>(t) == j[0]);
|
||||||
@ -297,7 +288,7 @@ TEST_CASE("constructors")
|
|||||||
|
|
||||||
SECTION("std::pair/tuple/array failures")
|
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::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&);
|
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>")
|
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);
|
json const j(a);
|
||||||
CHECK(j.type() == json::value_t::array);
|
CHECK(j.type() == json::value_t::array);
|
||||||
CHECK(j == j_reference);
|
CHECK(j == j_reference);
|
||||||
@ -314,7 +305,7 @@ TEST_CASE("constructors")
|
|||||||
|
|
||||||
SECTION("std::array<json, 6>")
|
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);
|
json const j(a);
|
||||||
CHECK(j.type() == json::value_t::array);
|
CHECK(j.type() == json::value_t::array);
|
||||||
CHECK(j == j_reference);
|
CHECK(j == j_reference);
|
||||||
@ -325,10 +316,10 @@ TEST_CASE("constructors")
|
|||||||
|
|
||||||
SECTION("std::valarray<int>")
|
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);
|
json const j(va);
|
||||||
CHECK(j.type() == json::value_t::array);
|
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>>();
|
auto jva = j.get<std::valarray<int>>();
|
||||||
CHECK(jva.size() == va.size());
|
CHECK(jva.size() == va.size());
|
||||||
@ -340,10 +331,10 @@ TEST_CASE("constructors")
|
|||||||
|
|
||||||
SECTION("std::valarray<double>")
|
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);
|
json const j(va);
|
||||||
CHECK(j.type() == json::value_t::array);
|
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>>();
|
auto jva = j.get<std::valarray<double>>();
|
||||||
CHECK(jva.size() == va.size());
|
CHECK(jva.size() == va.size());
|
||||||
@ -355,7 +346,7 @@ TEST_CASE("constructors")
|
|||||||
|
|
||||||
SECTION("std::vector<json>")
|
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);
|
json const j(a);
|
||||||
CHECK(j.type() == json::value_t::array);
|
CHECK(j.type() == json::value_t::array);
|
||||||
CHECK(j == j_reference);
|
CHECK(j == j_reference);
|
||||||
@ -363,7 +354,7 @@ TEST_CASE("constructors")
|
|||||||
|
|
||||||
SECTION("std::deque<json>")
|
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);
|
json const j(a);
|
||||||
CHECK(j.type() == json::value_t::array);
|
CHECK(j.type() == json::value_t::array);
|
||||||
CHECK(j == j_reference);
|
CHECK(j == j_reference);
|
||||||
@ -371,7 +362,7 @@ TEST_CASE("constructors")
|
|||||||
|
|
||||||
SECTION("std::set<json>")
|
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);
|
json const j(a);
|
||||||
CHECK(j.type() == json::value_t::array);
|
CHECK(j.type() == json::value_t::array);
|
||||||
// we cannot really check for equality here
|
// we cannot really check for equality here
|
||||||
@ -379,7 +370,7 @@ TEST_CASE("constructors")
|
|||||||
|
|
||||||
SECTION("std::unordered_set<json>")
|
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);
|
json const j(a);
|
||||||
CHECK(j.type() == json::value_t::array);
|
CHECK(j.type() == json::value_t::array);
|
||||||
// we cannot really check for equality here
|
// we cannot really check for equality here
|
||||||
@ -387,7 +378,7 @@ TEST_CASE("constructors")
|
|||||||
|
|
||||||
SECTION("sequence container literal")
|
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.type() == json::value_t::array);
|
||||||
CHECK(j == j_reference);
|
CHECK(j == j_reference);
|
||||||
}
|
}
|
||||||
@ -404,7 +395,7 @@ TEST_CASE("constructors")
|
|||||||
|
|
||||||
SECTION("filled string")
|
SECTION("filled string")
|
||||||
{
|
{
|
||||||
json::string_t const s{"Hello world"};
|
json::string_t const s{ "Hello world" };
|
||||||
json const j(s);
|
json const j(s);
|
||||||
CHECK(j.type() == json::value_t::string);
|
CHECK(j.type() == json::value_t::string);
|
||||||
}
|
}
|
||||||
@ -413,12 +404,12 @@ TEST_CASE("constructors")
|
|||||||
SECTION("create a string (implicit)")
|
SECTION("create a string (implicit)")
|
||||||
{
|
{
|
||||||
// reference string
|
// reference string
|
||||||
json::string_t const s_reference{"Hello world"};
|
json::string_t const s_reference{ "Hello world" };
|
||||||
json const j_reference(s_reference);
|
json const j_reference(s_reference);
|
||||||
|
|
||||||
SECTION("std::string")
|
SECTION("std::string")
|
||||||
{
|
{
|
||||||
std::string const s{"Hello world"};
|
std::string const s{ "Hello world" };
|
||||||
json const j(s);
|
json const j(s);
|
||||||
CHECK(j.type() == json::value_t::string);
|
CHECK(j.type() == json::value_t::string);
|
||||||
CHECK(j == j_reference);
|
CHECK(j == j_reference);
|
||||||
@ -426,7 +417,7 @@ TEST_CASE("constructors")
|
|||||||
|
|
||||||
SECTION("char[]")
|
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);
|
json const j(s);
|
||||||
CHECK(j.type() == json::value_t::string);
|
CHECK(j.type() == json::value_t::string);
|
||||||
CHECK(j == j_reference);
|
CHECK(j == j_reference);
|
||||||
@ -434,7 +425,7 @@ TEST_CASE("constructors")
|
|||||||
|
|
||||||
SECTION("const char*")
|
SECTION("const char*")
|
||||||
{
|
{
|
||||||
const char* s{"Hello world"};
|
const char* s{ "Hello world" };
|
||||||
json const j(s);
|
json const j(s);
|
||||||
CHECK(j.type() == json::value_t::string);
|
CHECK(j.type() == json::value_t::string);
|
||||||
CHECK(j == j_reference);
|
CHECK(j == j_reference);
|
||||||
@ -471,7 +462,7 @@ TEST_CASE("constructors")
|
|||||||
|
|
||||||
SECTION("from std::vector<bool>::reference")
|
SECTION("from std::vector<bool>::reference")
|
||||||
{
|
{
|
||||||
std::vector<bool> v{true};
|
std::vector<bool> v{ true };
|
||||||
json const j(v[0]);
|
json const j(v[0]);
|
||||||
CHECK(std::is_same<decltype(v[0]), std::vector<bool>::reference>::value);
|
CHECK(std::is_same<decltype(v[0]), std::vector<bool>::reference>::value);
|
||||||
CHECK(j.type() == json::value_t::boolean);
|
CHECK(j.type() == json::value_t::boolean);
|
||||||
@ -479,7 +470,7 @@ TEST_CASE("constructors")
|
|||||||
|
|
||||||
SECTION("from std::vector<bool>::const_reference")
|
SECTION("from std::vector<bool>::const_reference")
|
||||||
{
|
{
|
||||||
const std::vector<bool> v{true};
|
const std::vector<bool> v{ true };
|
||||||
json const j(v[0]);
|
json const j(v[0]);
|
||||||
CHECK(std::is_same<decltype(v[0]), std::vector<bool>::const_reference>::value);
|
CHECK(std::is_same<decltype(v[0]), std::vector<bool>::const_reference>::value);
|
||||||
CHECK(j.type() == json::value_t::boolean);
|
CHECK(j.type() == json::value_t::boolean);
|
||||||
@ -497,7 +488,7 @@ TEST_CASE("constructors")
|
|||||||
|
|
||||||
SECTION("filled binary")
|
SECTION("filled binary")
|
||||||
{
|
{
|
||||||
json::binary_t const b({1, 2, 3});
|
json::binary_t const b({ 1, 2, 3 });
|
||||||
json const j(b);
|
json const j(b);
|
||||||
CHECK(j.type() == json::value_t::binary);
|
CHECK(j.type() == json::value_t::binary);
|
||||||
}
|
}
|
||||||
@ -851,7 +842,7 @@ TEST_CASE("constructors")
|
|||||||
CHECK(j.type() == json::value_t::number_float);
|
CHECK(j.type() == json::value_t::number_float);
|
||||||
|
|
||||||
// check round trip of NaN
|
// 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((std::isnan(d) && std::isnan(n)) == true);
|
||||||
|
|
||||||
// check that NaN is serialized to null
|
// check that NaN is serialized to null
|
||||||
@ -866,7 +857,7 @@ TEST_CASE("constructors")
|
|||||||
CHECK(j.type() == json::value_t::number_float);
|
CHECK(j.type() == json::value_t::number_float);
|
||||||
|
|
||||||
// check round trip of infinity
|
// check round trip of infinity
|
||||||
json::number_float_t const d{j};
|
json::number_float_t const d{ j };
|
||||||
CHECK(d == n);
|
CHECK(d == n);
|
||||||
|
|
||||||
// check that inf is serialized to null
|
// check that inf is serialized to null
|
||||||
@ -949,13 +940,13 @@ TEST_CASE("constructors")
|
|||||||
{
|
{
|
||||||
SECTION("explicit")
|
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);
|
CHECK(j.type() == json::value_t::array);
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("implicit")
|
SECTION("implicit")
|
||||||
{
|
{
|
||||||
json const j{json::array_t()};
|
json const j{ json::array_t() };
|
||||||
CHECK(j.type() == json::value_t::array);
|
CHECK(j.type() == json::value_t::array);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -964,13 +955,13 @@ TEST_CASE("constructors")
|
|||||||
{
|
{
|
||||||
SECTION("explicit")
|
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);
|
CHECK(j.type() == json::value_t::array);
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("implicit")
|
SECTION("implicit")
|
||||||
{
|
{
|
||||||
json const j{json::object_t()};
|
json const j{ json::object_t() };
|
||||||
CHECK(j.type() == json::value_t::array);
|
CHECK(j.type() == json::value_t::array);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -979,13 +970,13 @@ TEST_CASE("constructors")
|
|||||||
{
|
{
|
||||||
SECTION("explicit")
|
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);
|
CHECK(j.type() == json::value_t::array);
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("implicit")
|
SECTION("implicit")
|
||||||
{
|
{
|
||||||
json const j{"Hello world"};
|
json const j{ "Hello world" };
|
||||||
CHECK(j.type() == json::value_t::array);
|
CHECK(j.type() == json::value_t::array);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -994,13 +985,13 @@ TEST_CASE("constructors")
|
|||||||
{
|
{
|
||||||
SECTION("explicit")
|
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);
|
CHECK(j.type() == json::value_t::array);
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("implicit")
|
SECTION("implicit")
|
||||||
{
|
{
|
||||||
json const j{true};
|
json const j{ true };
|
||||||
CHECK(j.type() == json::value_t::array);
|
CHECK(j.type() == json::value_t::array);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1009,13 +1000,13 @@ TEST_CASE("constructors")
|
|||||||
{
|
{
|
||||||
SECTION("explicit")
|
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);
|
CHECK(j.type() == json::value_t::array);
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("implicit")
|
SECTION("implicit")
|
||||||
{
|
{
|
||||||
json const j{1};
|
json const j{ 1 };
|
||||||
CHECK(j.type() == json::value_t::array);
|
CHECK(j.type() == json::value_t::array);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1024,13 +1015,13 @@ TEST_CASE("constructors")
|
|||||||
{
|
{
|
||||||
SECTION("explicit")
|
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);
|
CHECK(j.type() == json::value_t::array);
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("implicit")
|
SECTION("implicit")
|
||||||
{
|
{
|
||||||
json const j{1u};
|
json const j{ 1u };
|
||||||
CHECK(j.type() == json::value_t::array);
|
CHECK(j.type() == json::value_t::array);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1039,13 +1030,13 @@ TEST_CASE("constructors")
|
|||||||
{
|
{
|
||||||
SECTION("explicit")
|
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);
|
CHECK(j.type() == json::value_t::array);
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("implicit")
|
SECTION("implicit")
|
||||||
{
|
{
|
||||||
json const j{42.23};
|
json const j{ 42.23 };
|
||||||
CHECK(j.type() == json::value_t::array);
|
CHECK(j.type() == json::value_t::array);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1055,13 +1046,13 @@ TEST_CASE("constructors")
|
|||||||
{
|
{
|
||||||
SECTION("explicit")
|
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);
|
CHECK(j.type() == json::value_t::array);
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("implicit")
|
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);
|
CHECK(j.type() == json::value_t::array);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1070,13 +1061,13 @@ TEST_CASE("constructors")
|
|||||||
{
|
{
|
||||||
SECTION("object")
|
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);
|
CHECK(j.type() == json::value_t::object);
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("array")
|
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);
|
CHECK(j.type() == json::value_t::array);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1091,14 +1082,14 @@ TEST_CASE("constructors")
|
|||||||
|
|
||||||
SECTION("object")
|
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);
|
CHECK(j.type() == json::value_t::object);
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("object with error")
|
SECTION("object with error")
|
||||||
{
|
{
|
||||||
json _;
|
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.exception.type_error.301] cannot create object from initializer list",
|
||||||
json::type_error&);
|
json::type_error&);
|
||||||
}
|
}
|
||||||
@ -1111,7 +1102,7 @@ TEST_CASE("constructors")
|
|||||||
|
|
||||||
SECTION("array")
|
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);
|
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
|
// This should break through any short string optimization in std::string
|
||||||
std::string source(1024, '!');
|
std::string source(1024, '!');
|
||||||
const auto* source_addr = source.data();
|
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 auto* target_addr = j[0].get_ref<std::string const&>().data();
|
||||||
const bool success = (target_addr == source_addr);
|
const bool success = (target_addr == source_addr);
|
||||||
CHECK(success);
|
CHECK(success);
|
||||||
@ -1136,7 +1127,7 @@ TEST_CASE("constructors")
|
|||||||
// This should break through any short string optimization in std::string
|
// This should break through any short string optimization in std::string
|
||||||
std::string source(1024, '!');
|
std::string source(1024, '!');
|
||||||
const auto* source_addr = source.data();
|
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 auto* target_addr = j["key"].get_ref<std::string const&>().data();
|
||||||
const bool success = (target_addr == source_addr);
|
const bool success = (target_addr == source_addr);
|
||||||
CHECK(success);
|
CHECK(success);
|
||||||
@ -1147,7 +1138,7 @@ TEST_CASE("constructors")
|
|||||||
// This should break through any short string optimization in std::string
|
// This should break through any short string optimization in std::string
|
||||||
std::string source(1024, '!');
|
std::string source(1024, '!');
|
||||||
const auto* source_addr = source.data();
|
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 auto* target_addr = j.get_ref<json::object_t&>().begin()->first.data();
|
||||||
const bool success = (target_addr == source_addr);
|
const bool success = (target_addr == source_addr);
|
||||||
CHECK(success);
|
CHECK(success);
|
||||||
@ -1158,9 +1149,9 @@ TEST_CASE("constructors")
|
|||||||
{
|
{
|
||||||
SECTION("constructor with implicit types (array)")
|
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();
|
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 auto* target_addr = j[0].get_ref<json::array_t const&>().data();
|
||||||
const bool success = (target_addr == source_addr);
|
const bool success = (target_addr == source_addr);
|
||||||
CHECK(success);
|
CHECK(success);
|
||||||
@ -1168,9 +1159,9 @@ TEST_CASE("constructors")
|
|||||||
|
|
||||||
SECTION("constructor with implicit types (object)")
|
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();
|
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 auto* target_addr = j["key"].get_ref<json::array_t const&>().data();
|
||||||
const bool success = (target_addr == source_addr);
|
const bool success = (target_addr == source_addr);
|
||||||
CHECK(success);
|
CHECK(success);
|
||||||
@ -1178,9 +1169,9 @@ TEST_CASE("constructors")
|
|||||||
|
|
||||||
SECTION("assignment with implicit types (array)")
|
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();
|
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 auto* target_addr = j[0].get_ref<json::array_t const&>().data();
|
||||||
const bool success = (target_addr == source_addr);
|
const bool success = (target_addr == source_addr);
|
||||||
CHECK(success);
|
CHECK(success);
|
||||||
@ -1188,9 +1179,9 @@ TEST_CASE("constructors")
|
|||||||
|
|
||||||
SECTION("assignment with implicit types (object)")
|
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();
|
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 auto* target_addr = j["key"].get_ref<json::array_t const&>().data();
|
||||||
const bool success = (target_addr == source_addr);
|
const bool success = (target_addr == source_addr);
|
||||||
CHECK(success);
|
CHECK(success);
|
||||||
@ -1201,33 +1192,33 @@ TEST_CASE("constructors")
|
|||||||
{
|
{
|
||||||
SECTION("constructor with implicit types (array)")
|
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");
|
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);
|
CHECK(&(j[0].get_ref<json::object_t const&>().at("hello")) == source_addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("constructor with implicit types (object)")
|
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");
|
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);
|
CHECK(&(j["key"].get_ref<json::object_t const&>().at("hello")) == source_addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("assignment with implicit types (array)")
|
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");
|
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);
|
CHECK(&(j[0].get_ref<json::object_t const&>().at("hello")) == source_addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("assignment with implicit types (object)")
|
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");
|
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);
|
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)")
|
SECTION("constructor with implicit types (array)")
|
||||||
{
|
{
|
||||||
json source{1, 2, 3};
|
json source{ 1, 2, 3 };
|
||||||
const json* source_addr = &source[0];
|
const json* source_addr = &source[0];
|
||||||
json j{std::move(source), {}};
|
json j{ std::move(source), {} };
|
||||||
CHECK(&j[0][0] == source_addr);
|
CHECK(&j[0][0] == source_addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("constructor with implicit types (object)")
|
SECTION("constructor with implicit types (object)")
|
||||||
{
|
{
|
||||||
json source{1, 2, 3};
|
json source{ 1, 2, 3 };
|
||||||
const json* source_addr = &source[0];
|
const json* source_addr = &source[0];
|
||||||
json j{{"key", std::move(source)}};
|
json j{ { "key", std::move(source) } };
|
||||||
CHECK(&j["key"][0] == source_addr);
|
CHECK(&j["key"][0] == source_addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("assignment with implicit types (array)")
|
SECTION("assignment with implicit types (array)")
|
||||||
{
|
{
|
||||||
json source{1, 2, 3};
|
json source{ 1, 2, 3 };
|
||||||
const json* source_addr = &source[0];
|
const json* source_addr = &source[0];
|
||||||
json j = {std::move(source), {}};
|
json j = { std::move(source), {} };
|
||||||
CHECK(&j[0][0] == source_addr);
|
CHECK(&j[0][0] == source_addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("assignment with implicit types (object)")
|
SECTION("assignment with implicit types (object)")
|
||||||
{
|
{
|
||||||
json source{1, 2, 3};
|
json source{ 1, 2, 3 };
|
||||||
const json* source_addr = &source[0];
|
const json* source_addr = &source[0];
|
||||||
json j = {{"key", std::move(source)}};
|
json j = { { "key", std::move(source) } };
|
||||||
CHECK(&j["key"][0] == source_addr);
|
CHECK(&j["key"][0] == source_addr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1273,14 +1264,14 @@ TEST_CASE("constructors")
|
|||||||
{
|
{
|
||||||
SECTION("cnt = 0")
|
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);
|
json const arr(0, v);
|
||||||
CHECK(arr.size() == 0);
|
CHECK(arr.size() == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("cnt = 1")
|
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);
|
json const arr(1, v);
|
||||||
CHECK(arr.size() == 1);
|
CHECK(arr.size() == 1);
|
||||||
for (const auto& x : arr)
|
for (const auto& x : arr)
|
||||||
@ -1291,7 +1282,7 @@ TEST_CASE("constructors")
|
|||||||
|
|
||||||
SECTION("cnt = 3")
|
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);
|
json const arr(3, v);
|
||||||
CHECK(arr.size() == 3);
|
CHECK(arr.size() == 3);
|
||||||
for (const auto& x : arr)
|
for (const auto& x : arr)
|
||||||
@ -1308,12 +1299,12 @@ TEST_CASE("constructors")
|
|||||||
SECTION("json(begin(), end())")
|
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());
|
json const j_new(jobject.begin(), jobject.end());
|
||||||
CHECK(j_new == jobject);
|
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());
|
json const j_new(jobject.cbegin(), jobject.cend());
|
||||||
CHECK(j_new == jobject);
|
CHECK(j_new == jobject);
|
||||||
}
|
}
|
||||||
@ -1322,12 +1313,12 @@ TEST_CASE("constructors")
|
|||||||
SECTION("json(begin(), begin())")
|
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());
|
json const j_new(jobject.begin(), jobject.begin());
|
||||||
CHECK(j_new == json::object());
|
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());
|
json const j_new(jobject.cbegin(), jobject.cbegin());
|
||||||
CHECK(j_new == json::object());
|
CHECK(j_new == json::object());
|
||||||
}
|
}
|
||||||
@ -1335,16 +1326,16 @@ TEST_CASE("constructors")
|
|||||||
|
|
||||||
SECTION("construct from subrange")
|
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"));
|
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")
|
SECTION("incompatible iterators")
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
json jobject = {{"a", "a"}, {"b", 1}, {"c", 17u}, {"d", false}, {"e", true}};
|
json jobject = { { "a", "a" }, { "b", 1 }, { "c", 17u }, { "d", false }, { "e", true } };
|
||||||
json jobject2 = {{"a", "a"}, {"b", 1}, {"c", 17u}};
|
json jobject2 = { { "a", "a" }, { "b", 1 }, { "c", 17u } };
|
||||||
CHECK_THROWS_WITH_AS(json(jobject.begin(), jobject2.end()),
|
CHECK_THROWS_WITH_AS(json(jobject.begin(), jobject2.end()),
|
||||||
"[json.exception.invalid_iterator.201] iterators are not compatible",
|
"[json.exception.invalid_iterator.201] iterators are not compatible",
|
||||||
json::invalid_iterator&);
|
json::invalid_iterator&);
|
||||||
@ -1353,8 +1344,8 @@ TEST_CASE("constructors")
|
|||||||
json::invalid_iterator&);
|
json::invalid_iterator&);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
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 jobject2 = {{"a", "a"}, {"b", 1}, {"c", 17u}};
|
json const jobject2 = { { "a", "a" }, { "b", 1 }, { "c", 17u } };
|
||||||
CHECK_THROWS_WITH_AS(json(jobject.cbegin(), jobject2.cend()),
|
CHECK_THROWS_WITH_AS(json(jobject.cbegin(), jobject2.cend()),
|
||||||
"[json.exception.invalid_iterator.201] iterators are not compatible",
|
"[json.exception.invalid_iterator.201] iterators are not compatible",
|
||||||
json::invalid_iterator&);
|
json::invalid_iterator&);
|
||||||
@ -1370,12 +1361,12 @@ TEST_CASE("constructors")
|
|||||||
SECTION("json(begin(), end())")
|
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());
|
json const j_new(jarray.begin(), jarray.end());
|
||||||
CHECK(j_new == jarray);
|
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());
|
json const j_new(jarray.cbegin(), jarray.cend());
|
||||||
CHECK(j_new == jarray);
|
CHECK(j_new == jarray);
|
||||||
}
|
}
|
||||||
@ -1384,12 +1375,12 @@ TEST_CASE("constructors")
|
|||||||
SECTION("json(begin(), begin())")
|
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());
|
json j_new(jarray.begin(), jarray.begin());
|
||||||
CHECK(j_new == json::array());
|
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());
|
json const j_new(jarray.cbegin(), jarray.cbegin());
|
||||||
CHECK(j_new == json::array());
|
CHECK(j_new == json::array());
|
||||||
}
|
}
|
||||||
@ -1398,22 +1389,22 @@ TEST_CASE("constructors")
|
|||||||
SECTION("construct from subrange")
|
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);
|
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);
|
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")
|
SECTION("incompatible iterators")
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
json jarray = {1, 2, 3, 4};
|
json jarray = { 1, 2, 3, 4 };
|
||||||
json jarray2 = {2, 3, 4, 5};
|
json jarray2 = { 2, 3, 4, 5 };
|
||||||
CHECK_THROWS_WITH_AS(json(jarray.begin(), jarray2.end()),
|
CHECK_THROWS_WITH_AS(json(jarray.begin(), jarray2.end()),
|
||||||
"[json.exception.invalid_iterator.201] iterators are not compatible",
|
"[json.exception.invalid_iterator.201] iterators are not compatible",
|
||||||
json::invalid_iterator&);
|
json::invalid_iterator&);
|
||||||
@ -1422,8 +1413,8 @@ TEST_CASE("constructors")
|
|||||||
json::invalid_iterator&);
|
json::invalid_iterator&);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
json const jarray = {1, 2, 3, 4};
|
json const jarray = { 1, 2, 3, 4 };
|
||||||
json const jarray2 = {2, 3, 4, 5};
|
json const jarray2 = { 2, 3, 4, 5 };
|
||||||
CHECK_THROWS_WITH_AS(json(jarray.cbegin(), jarray2.cend()),
|
CHECK_THROWS_WITH_AS(json(jarray.cbegin(), jarray2.cend()),
|
||||||
"[json.exception.invalid_iterator.201] iterators are not compatible",
|
"[json.exception.invalid_iterator.201] iterators are not compatible",
|
||||||
json::invalid_iterator&);
|
json::invalid_iterator&);
|
||||||
@ -1527,12 +1518,12 @@ TEST_CASE("constructors")
|
|||||||
SECTION("binary")
|
SECTION("binary")
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
json j = json::binary({1, 2, 3});
|
json j = json::binary({ 1, 2, 3 });
|
||||||
json const j_new(j.begin(), j.end());
|
json const j_new(j.begin(), j.end());
|
||||||
CHECK((j == j_new));
|
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());
|
json const j_new(j.cbegin(), j.cend());
|
||||||
CHECK((j == j_new));
|
CHECK((j == j_new));
|
||||||
}
|
}
|
||||||
|
@ -17,14 +17,14 @@ TEST_CASE("other constructors and destructor")
|
|||||||
{
|
{
|
||||||
SECTION("object")
|
SECTION("object")
|
||||||
{
|
{
|
||||||
json j{{"foo", 1}, {"bar", false}};
|
json j{ { "foo", 1 }, { "bar", false } };
|
||||||
json k(j); // NOLINT(performance-unnecessary-copy-initialization)
|
json k(j); // NOLINT(performance-unnecessary-copy-initialization)
|
||||||
CHECK(j == k);
|
CHECK(j == k);
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("array")
|
SECTION("array")
|
||||||
{
|
{
|
||||||
json j{"foo", 1, 42.23, false};
|
json j{ "foo", 1, 42.23, false };
|
||||||
json k(j); // NOLINT(performance-unnecessary-copy-initialization)
|
json k(j); // NOLINT(performance-unnecessary-copy-initialization)
|
||||||
CHECK(j == k);
|
CHECK(j == k);
|
||||||
}
|
}
|
||||||
@ -73,7 +73,7 @@ TEST_CASE("other constructors and destructor")
|
|||||||
|
|
||||||
SECTION("binary")
|
SECTION("binary")
|
||||||
{
|
{
|
||||||
json j = json::binary({1, 2, 3});
|
json j = json::binary({ 1, 2, 3 });
|
||||||
json k(j); // NOLINT(performance-unnecessary-copy-initialization)
|
json k(j); // NOLINT(performance-unnecessary-copy-initialization)
|
||||||
CHECK(j == k);
|
CHECK(j == k);
|
||||||
}
|
}
|
||||||
@ -81,7 +81,7 @@ TEST_CASE("other constructors and destructor")
|
|||||||
|
|
||||||
SECTION("move constructor")
|
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);
|
CHECK(j.type() == json::value_t::object);
|
||||||
const json k(std::move(j));
|
const json k(std::move(j));
|
||||||
CHECK(k.type() == json::value_t::object);
|
CHECK(k.type() == json::value_t::object);
|
||||||
@ -92,7 +92,7 @@ TEST_CASE("other constructors and destructor")
|
|||||||
{
|
{
|
||||||
SECTION("object")
|
SECTION("object")
|
||||||
{
|
{
|
||||||
json j{{"foo", 1}, {"bar", false}};
|
json j{ { "foo", 1 }, { "bar", false } };
|
||||||
json k;
|
json k;
|
||||||
k = j;
|
k = j;
|
||||||
CHECK(j == k);
|
CHECK(j == k);
|
||||||
@ -100,7 +100,7 @@ TEST_CASE("other constructors and destructor")
|
|||||||
|
|
||||||
SECTION("array")
|
SECTION("array")
|
||||||
{
|
{
|
||||||
json j{"foo", 1, 42.23, false};
|
json j{ "foo", 1, 42.23, false };
|
||||||
json k;
|
json k;
|
||||||
k = j;
|
k = j;
|
||||||
CHECK(j == k);
|
CHECK(j == k);
|
||||||
@ -156,7 +156,7 @@ TEST_CASE("other constructors and destructor")
|
|||||||
|
|
||||||
SECTION("binary")
|
SECTION("binary")
|
||||||
{
|
{
|
||||||
json j = json::binary({1, 2, 3});
|
json j = json::binary({ 1, 2, 3 });
|
||||||
json k;
|
json k;
|
||||||
k = j;
|
k = j;
|
||||||
CHECK(j == k);
|
CHECK(j == k);
|
||||||
@ -167,14 +167,14 @@ TEST_CASE("other constructors and destructor")
|
|||||||
{
|
{
|
||||||
SECTION("object")
|
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)
|
delete j; // NOLINT(cppcoreguidelines-owning-memory)
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("array")
|
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)
|
delete j; // NOLINT(cppcoreguidelines-owning-memory)
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("string")
|
SECTION("string")
|
||||||
|
@ -173,8 +173,8 @@ TEST_CASE("convenience functions")
|
|||||||
using nlohmann::detail::concat;
|
using nlohmann::detail::concat;
|
||||||
|
|
||||||
const char* expected = "Hello, world!";
|
const char* expected = "Hello, world!";
|
||||||
alt_string_iter const hello_iter{"Hello, "};
|
alt_string_iter const hello_iter{ "Hello, " };
|
||||||
alt_string_data const hello_data{"Hello, "};
|
alt_string_data const hello_data{ "Hello, " };
|
||||||
std::string const world = "world";
|
std::string const world = "world";
|
||||||
|
|
||||||
SECTION("std::string")
|
SECTION("std::string")
|
||||||
|
@ -36,8 +36,8 @@ TEST_CASE("value conversion")
|
|||||||
{
|
{
|
||||||
SECTION("get an object (explicit)")
|
SECTION("get an object (explicit)")
|
||||||
{
|
{
|
||||||
const json::object_t o_reference =
|
const json::object_t o_reference = { { "object", json::object() }, { "array", { 1, 2, 3, 4 } }, { "number", 42 },
|
||||||
{{"object", json::object()}, {"array", {1, 2, 3, 4}}, {"number", 42}, {"boolean", false}, {"null", nullptr}, {"string", "Hello world"}};
|
{ "boolean", false }, { "null", nullptr }, { "string", "Hello world" } };
|
||||||
json j(o_reference);
|
json j(o_reference);
|
||||||
|
|
||||||
SECTION("json::object_t")
|
SECTION("json::object_t")
|
||||||
@ -99,41 +99,41 @@ TEST_CASE("value conversion")
|
|||||||
|
|
||||||
SECTION("get an object (explicit, get_to)")
|
SECTION("get an object (explicit, get_to)")
|
||||||
{
|
{
|
||||||
const json::object_t o_reference =
|
const json::object_t o_reference = { { "object", json::object() }, { "array", { 1, 2, 3, 4 } }, { "number", 42 },
|
||||||
{{"object", json::object()}, {"array", {1, 2, 3, 4}}, {"number", 42}, {"boolean", false}, {"null", nullptr}, {"string", "Hello world"}};
|
{ "boolean", false }, { "null", nullptr }, { "string", "Hello world" } };
|
||||||
json j(o_reference);
|
json j(o_reference);
|
||||||
|
|
||||||
SECTION("json::object_t")
|
SECTION("json::object_t")
|
||||||
{
|
{
|
||||||
json::object_t o = {{"previous", "value"}};
|
json::object_t o = { { "previous", "value" } };
|
||||||
j.get_to(o);
|
j.get_to(o);
|
||||||
CHECK(json(o) == j);
|
CHECK(json(o) == j);
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("std::map<json::string_t, json>")
|
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);
|
j.get_to(o);
|
||||||
CHECK(json(o) == j);
|
CHECK(json(o) == j);
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("std::multimap<json::string_t, json>")
|
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);
|
j.get_to(o);
|
||||||
CHECK(json(o) == j);
|
CHECK(json(o) == j);
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("std::unordered_map<json::string_t, json>")
|
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);
|
j.get_to(o);
|
||||||
CHECK(json(o) == j);
|
CHECK(json(o) == j);
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("std::unordered_multimap<json::string_t, json>")
|
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);
|
j.get_to(o);
|
||||||
CHECK(json(o) == j);
|
CHECK(json(o) == j);
|
||||||
}
|
}
|
||||||
@ -142,8 +142,8 @@ TEST_CASE("value conversion")
|
|||||||
#if JSON_USE_IMPLICIT_CONVERSIONS
|
#if JSON_USE_IMPLICIT_CONVERSIONS
|
||||||
SECTION("get an object (implicit)")
|
SECTION("get an object (implicit)")
|
||||||
{
|
{
|
||||||
const json::object_t o_reference =
|
const json::object_t o_reference = { { "object", json::object() }, { "array", { 1, 2, 3, 4 } }, { "number", 42 },
|
||||||
{{"object", json::object()}, {"array", {1, 2, 3, 4}}, {"number", 42}, {"boolean", false}, {"null", nullptr}, {"string", "Hello world"}};
|
{ "boolean", false }, { "null", nullptr }, { "string", "Hello world" } };
|
||||||
json j(o_reference);
|
json j(o_reference);
|
||||||
|
|
||||||
SECTION("json::object_t")
|
SECTION("json::object_t")
|
||||||
@ -180,7 +180,7 @@ TEST_CASE("value conversion")
|
|||||||
|
|
||||||
SECTION("get an array (explicit)")
|
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);
|
json j(a_reference);
|
||||||
|
|
||||||
SECTION("json::array_t")
|
SECTION("json::array_t")
|
||||||
@ -218,7 +218,7 @@ TEST_CASE("value conversion")
|
|||||||
SECTION("reserve is called on containers that supports it")
|
SECTION("reserve is called on containers that supports it")
|
||||||
{
|
{
|
||||||
// make sure all values are properly copied
|
// 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>>();
|
auto v2 = j2.get<std::vector<int>>();
|
||||||
CHECK(v2.size() == 10);
|
CHECK(v2.size() == 10);
|
||||||
}
|
}
|
||||||
@ -228,7 +228,7 @@ TEST_CASE("value conversion")
|
|||||||
SECTION("built-in arrays")
|
SECTION("built-in arrays")
|
||||||
{
|
{
|
||||||
const char str[] = "a string"; // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-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 j2 = nbs;
|
||||||
const json j3 = str;
|
const json j3 = str;
|
||||||
@ -276,48 +276,48 @@ TEST_CASE("value conversion")
|
|||||||
|
|
||||||
SECTION("get an array (explicit, get_to)")
|
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);
|
json j(a_reference);
|
||||||
|
|
||||||
SECTION("json::array_t")
|
SECTION("json::array_t")
|
||||||
{
|
{
|
||||||
json::array_t a{"previous", "value"};
|
json::array_t a{ "previous", "value" };
|
||||||
j.get_to(a);
|
j.get_to(a);
|
||||||
CHECK(json(a) == j);
|
CHECK(json(a) == j);
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("std::valarray<json>")
|
SECTION("std::valarray<json>")
|
||||||
{
|
{
|
||||||
std::valarray<json> a{"previous", "value"};
|
std::valarray<json> a{ "previous", "value" };
|
||||||
j.get_to(a);
|
j.get_to(a);
|
||||||
CHECK(json(a) == j);
|
CHECK(json(a) == j);
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("std::list<json>")
|
SECTION("std::list<json>")
|
||||||
{
|
{
|
||||||
std::list<json> a{"previous", "value"};
|
std::list<json> a{ "previous", "value" };
|
||||||
j.get_to(a);
|
j.get_to(a);
|
||||||
CHECK(json(a) == j);
|
CHECK(json(a) == j);
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("std::forward_list<json>")
|
SECTION("std::forward_list<json>")
|
||||||
{
|
{
|
||||||
std::forward_list<json> a{"previous", "value"};
|
std::forward_list<json> a{ "previous", "value" };
|
||||||
j.get_to(a);
|
j.get_to(a);
|
||||||
CHECK(json(a) == j);
|
CHECK(json(a) == j);
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("std::vector<json>")
|
SECTION("std::vector<json>")
|
||||||
{
|
{
|
||||||
std::vector<json> a{"previous", "value"};
|
std::vector<json> a{ "previous", "value" };
|
||||||
j.get_to(a);
|
j.get_to(a);
|
||||||
CHECK(json(a) == j);
|
CHECK(json(a) == j);
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("built-in arrays")
|
SECTION("built-in 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)
|
||||||
int nbs2[] = {0, 0, 0}; // 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;
|
const json j2 = nbs;
|
||||||
j2.get_to(nbs2);
|
j2.get_to(nbs2);
|
||||||
@ -326,7 +326,7 @@ TEST_CASE("value conversion")
|
|||||||
|
|
||||||
SECTION("std::deque<json>")
|
SECTION("std::deque<json>")
|
||||||
{
|
{
|
||||||
std::deque<json> a{"previous", "value"};
|
std::deque<json> a{ "previous", "value" };
|
||||||
j.get_to(a);
|
j.get_to(a);
|
||||||
CHECK(json(a) == j);
|
CHECK(json(a) == j);
|
||||||
}
|
}
|
||||||
@ -335,7 +335,7 @@ TEST_CASE("value conversion")
|
|||||||
#if JSON_USE_IMPLICIT_CONVERSIONS
|
#if JSON_USE_IMPLICIT_CONVERSIONS
|
||||||
SECTION("get an array (implicit)")
|
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);
|
json j(a_reference);
|
||||||
|
|
||||||
SECTION("json::array_t")
|
SECTION("json::array_t")
|
||||||
@ -372,7 +372,7 @@ TEST_CASE("value conversion")
|
|||||||
|
|
||||||
SECTION("get a string (explicit)")
|
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);
|
json j(s_reference);
|
||||||
|
|
||||||
SECTION("string_t")
|
SECTION("string_t")
|
||||||
@ -450,7 +450,7 @@ TEST_CASE("value conversion")
|
|||||||
|
|
||||||
SECTION("get a string (explicit, get_to)")
|
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);
|
json j(s_reference);
|
||||||
|
|
||||||
SECTION("string_t")
|
SECTION("string_t")
|
||||||
@ -511,7 +511,7 @@ TEST_CASE("value conversion")
|
|||||||
#if JSON_USE_IMPLICIT_CONVERSIONS
|
#if JSON_USE_IMPLICIT_CONVERSIONS
|
||||||
SECTION("get a string (implicit)")
|
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);
|
json j(s_reference);
|
||||||
|
|
||||||
SECTION("string_t")
|
SECTION("string_t")
|
||||||
@ -538,7 +538,7 @@ TEST_CASE("value conversion")
|
|||||||
|
|
||||||
SECTION("get a boolean (explicit)")
|
SECTION("get a boolean (explicit)")
|
||||||
{
|
{
|
||||||
const json::boolean_t b_reference{true};
|
const json::boolean_t b_reference{ true };
|
||||||
json j(b_reference);
|
json j(b_reference);
|
||||||
|
|
||||||
SECTION("boolean_t")
|
SECTION("boolean_t")
|
||||||
@ -595,7 +595,7 @@ TEST_CASE("value conversion")
|
|||||||
#if JSON_USE_IMPLICIT_CONVERSIONS
|
#if JSON_USE_IMPLICIT_CONVERSIONS
|
||||||
SECTION("get a boolean (implicit)")
|
SECTION("get a boolean (implicit)")
|
||||||
{
|
{
|
||||||
const json::boolean_t b_reference{true};
|
const json::boolean_t b_reference{ true };
|
||||||
json j(b_reference);
|
json j(b_reference);
|
||||||
|
|
||||||
SECTION("boolean_t")
|
SECTION("boolean_t")
|
||||||
@ -614,9 +614,9 @@ TEST_CASE("value conversion")
|
|||||||
|
|
||||||
SECTION("get an integer number (explicit)")
|
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);
|
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);
|
json j_unsigned(n_unsigned_reference);
|
||||||
|
|
||||||
SECTION("number_integer_t")
|
SECTION("number_integer_t")
|
||||||
@ -850,9 +850,9 @@ TEST_CASE("value conversion")
|
|||||||
#if JSON_USE_IMPLICIT_CONVERSIONS
|
#if JSON_USE_IMPLICIT_CONVERSIONS
|
||||||
SECTION("get an integer number (implicit)")
|
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 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);
|
json j_unsigned(n_unsigned_reference);
|
||||||
|
|
||||||
SECTION("number_integer_t")
|
SECTION("number_integer_t")
|
||||||
@ -1063,7 +1063,7 @@ TEST_CASE("value conversion")
|
|||||||
|
|
||||||
SECTION("get a floating-point number (explicit)")
|
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);
|
json const j(n_reference);
|
||||||
|
|
||||||
SECTION("number_float_t")
|
SECTION("number_float_t")
|
||||||
@ -1111,7 +1111,7 @@ TEST_CASE("value conversion")
|
|||||||
#if JSON_USE_IMPLICIT_CONVERSIONS
|
#if JSON_USE_IMPLICIT_CONVERSIONS
|
||||||
SECTION("get a floating-point number (implicit)")
|
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);
|
json const j(n_reference);
|
||||||
|
|
||||||
SECTION("number_float_t")
|
SECTION("number_float_t")
|
||||||
@ -1136,7 +1136,7 @@ TEST_CASE("value conversion")
|
|||||||
|
|
||||||
SECTION("get a binary value (explicit)")
|
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);
|
json j(n_reference);
|
||||||
|
|
||||||
SECTION("binary_t")
|
SECTION("binary_t")
|
||||||
@ -1205,7 +1205,7 @@ TEST_CASE("value conversion")
|
|||||||
#if JSON_USE_IMPLICIT_CONVERSIONS
|
#if JSON_USE_IMPLICIT_CONVERSIONS
|
||||||
SECTION("get a binary value (implicit)")
|
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);
|
json const j(n_reference);
|
||||||
|
|
||||||
SECTION("binary_t")
|
SECTION("binary_t")
|
||||||
@ -1237,11 +1237,11 @@ TEST_CASE("value conversion")
|
|||||||
{
|
{
|
||||||
SECTION("object-like STL containers")
|
SECTION("object-like STL containers")
|
||||||
{
|
{
|
||||||
json const j1 = {{"one", 1}, {"two", 2}, {"three", 3}};
|
json const j1 = { { "one", 1 }, { "two", 2 }, { "three", 3 } };
|
||||||
json const j2 = {{"one", 1u}, {"two", 2u}, {"three", 3u}};
|
json const j2 = { { "one", 1u }, { "two", 2u }, { "three", 3u } };
|
||||||
json const j3 = {{"one", 1.1}, {"two", 2.2}, {"three", 3.3}};
|
json const j3 = { { "one", 1.1 }, { "two", 2.2 }, { "three", 3.3 } };
|
||||||
json const j4 = {{"one", true}, {"two", false}, {"three", true}};
|
json const j4 = { { "one", true }, { "two", false }, { "three", true } };
|
||||||
json const j5 = {{"one", "eins"}, {"two", "zwei"}, {"three", "drei"}};
|
json const j5 = { { "one", "eins" }, { "two", "zwei" }, { "three", "drei" } };
|
||||||
|
|
||||||
SECTION("std::map")
|
SECTION("std::map")
|
||||||
{
|
{
|
||||||
@ -1292,11 +1292,11 @@ TEST_CASE("value conversion")
|
|||||||
|
|
||||||
SECTION("array-like STL containers")
|
SECTION("array-like STL containers")
|
||||||
{
|
{
|
||||||
json const j1 = {1, 2, 3, 4};
|
json const j1 = { 1, 2, 3, 4 };
|
||||||
json const j2 = {1u, 2u, 3u, 4u};
|
json const j2 = { 1u, 2u, 3u, 4u };
|
||||||
json const j3 = {1.2, 2.3, 3.4, 4.5};
|
json const j3 = { 1.2, 2.3, 3.4, 4.5 };
|
||||||
json const j4 = {true, false, true};
|
json const j4 = { true, false, true };
|
||||||
json const j5 = {"one", "two", "three"};
|
json const j5 = { "one", "two", "three" };
|
||||||
|
|
||||||
SECTION("std::list")
|
SECTION("std::list")
|
||||||
{
|
{
|
||||||
@ -1326,7 +1326,7 @@ TEST_CASE("value conversion")
|
|||||||
|
|
||||||
SECTION("std::array is larger than JSON")
|
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),
|
CHECK_THROWS_WITH_AS(j1.get_to(arr6),
|
||||||
"[json.exception.out_of_range.401] "
|
"[json.exception.out_of_range.401] "
|
||||||
"array index 4 is out of range",
|
"array index 4 is out of range",
|
||||||
@ -1335,7 +1335,7 @@ TEST_CASE("value conversion")
|
|||||||
|
|
||||||
SECTION("std::array is smaller than JSON")
|
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);
|
j1.get_to(arr2);
|
||||||
CHECK(arr2[0] == 1);
|
CHECK(arr2[0] == 1);
|
||||||
CHECK(arr2[1] == 2);
|
CHECK(arr2[1] == 2);
|
||||||
@ -1389,13 +1389,13 @@ TEST_CASE("value conversion")
|
|||||||
|
|
||||||
SECTION("std::map (array of pairs)")
|
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;
|
json const j6 = m;
|
||||||
|
|
||||||
auto m2 = j6.get<std::map<int, int>>();
|
auto m2 = j6.get<std::map<int, int>>();
|
||||||
CHECK(m == m2);
|
CHECK(m == m2);
|
||||||
|
|
||||||
json const j7 = {0, 1, 2, 3};
|
json const j7 = { 0, 1, 2, 3 };
|
||||||
json const j8 = 2;
|
json const j8 = 2;
|
||||||
CHECK_THROWS_WITH_AS((j7.get<std::map<int, int>>()),
|
CHECK_THROWS_WITH_AS((j7.get<std::map<int, int>>()),
|
||||||
"[json.exception.type_error.302] type must be array, "
|
"[json.exception.type_error.302] type must be array, "
|
||||||
@ -1408,7 +1408,7 @@ TEST_CASE("value conversion")
|
|||||||
|
|
||||||
SECTION("superfluous entries")
|
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>>();
|
m2 = j9.get<std::map<int, int>>();
|
||||||
CHECK(m == m2);
|
CHECK(m == m2);
|
||||||
}
|
}
|
||||||
@ -1416,13 +1416,13 @@ TEST_CASE("value conversion")
|
|||||||
|
|
||||||
SECTION("std::unordered_map (array of pairs)")
|
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;
|
json const j6 = m;
|
||||||
|
|
||||||
auto m2 = j6.get<std::unordered_map<int, int>>();
|
auto m2 = j6.get<std::unordered_map<int, int>>();
|
||||||
CHECK(m == m2);
|
CHECK(m == m2);
|
||||||
|
|
||||||
json const j7 = {0, 1, 2, 3};
|
json const j7 = { 0, 1, 2, 3 };
|
||||||
json const j8 = 2;
|
json const j8 = 2;
|
||||||
CHECK_THROWS_WITH_AS((j7.get<std::unordered_map<int, int>>()),
|
CHECK_THROWS_WITH_AS((j7.get<std::unordered_map<int, int>>()),
|
||||||
"[json.exception.type_error.302] type must be array, "
|
"[json.exception.type_error.302] type must be array, "
|
||||||
@ -1435,7 +1435,7 @@ TEST_CASE("value conversion")
|
|||||||
|
|
||||||
SECTION("superfluous entries")
|
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>>();
|
m2 = j9.get<std::unordered_map<int, int>>();
|
||||||
CHECK(m == m2);
|
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
|
// NOLINTNEXTLINE(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays) - false positive
|
||||||
NLOHMANN_JSON_SERIALIZE_ENUM(cards,
|
NLOHMANN_JSON_SERIALIZE_ENUM(cards,
|
||||||
{{cards::kreuz, "kreuz"},
|
{ { cards::kreuz, "kreuz" },
|
||||||
{cards::pik, "pik"},
|
{ cards::pik, "pik" },
|
||||||
{cards::pik, "puk"}, // second entry for cards::puk; will not be used
|
{ cards::pik, "puk" }, // second entry for cards::puk; will not be used
|
||||||
{cards::herz, "herz"},
|
{ cards::herz, "herz" },
|
||||||
{cards::karo, "karo"}})
|
{ cards::karo, "karo" } })
|
||||||
|
|
||||||
enum TaskState
|
enum TaskState
|
||||||
{
|
{
|
||||||
@ -1483,10 +1483,10 @@ enum TaskState
|
|||||||
// NOLINTNEXTLINE(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays) - false positive
|
// NOLINTNEXTLINE(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays) - false positive
|
||||||
NLOHMANN_JSON_SERIALIZE_ENUM(TaskState,
|
NLOHMANN_JSON_SERIALIZE_ENUM(TaskState,
|
||||||
{
|
{
|
||||||
{TS_INVALID, nullptr},
|
{ TS_INVALID, nullptr },
|
||||||
{TS_STOPPED, "stopped"},
|
{ TS_STOPPED, "stopped" },
|
||||||
{TS_RUNNING, "running"},
|
{ TS_RUNNING, "running" },
|
||||||
{TS_COMPLETED, "completed"},
|
{ TS_COMPLETED, "completed" },
|
||||||
})
|
})
|
||||||
|
|
||||||
TEST_CASE("JSON to enum mapping")
|
TEST_CASE("JSON to enum mapping")
|
||||||
|
@ -258,23 +258,23 @@ TEST_CASE("JSON Visit Node")
|
|||||||
json["array"].push_back(1);
|
json["array"].push_back(1);
|
||||||
json["array"].push_back(json);
|
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",
|
"/int - number_integer - -1",
|
||||||
"/uint - number_unsigned - 1",
|
"/uint - number_unsigned - 1",
|
||||||
"/float - number_float - 1.0",
|
"/float - number_float - 1.0",
|
||||||
"/boolean - boolean - true",
|
"/boolean - boolean - true",
|
||||||
"/string - string - \"string\"",
|
"/string - string - \"string\"",
|
||||||
"/array/0 - number_integer - 0",
|
"/array/0 - number_integer - 0",
|
||||||
"/array/1 - number_integer - 1",
|
"/array/1 - number_integer - 1",
|
||||||
|
|
||||||
"/array/2/null - null - null",
|
"/array/2/null - null - null",
|
||||||
"/array/2/int - number_integer - -1",
|
"/array/2/int - number_integer - -1",
|
||||||
"/array/2/uint - number_unsigned - 1",
|
"/array/2/uint - number_unsigned - 1",
|
||||||
"/array/2/float - number_float - 1.0",
|
"/array/2/float - number_float - 1.0",
|
||||||
"/array/2/boolean - boolean - true",
|
"/array/2/boolean - boolean - true",
|
||||||
"/array/2/string - string - \"string\"",
|
"/array/2/string - string - \"string\"",
|
||||||
"/array/2/array/0 - number_integer - 0",
|
"/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) {
|
json.visit([&](const json_with_visitor_t::json_pointer& p, const json_with_visitor_t& j) {
|
||||||
std::stringstream str;
|
std::stringstream str;
|
||||||
|
@ -231,22 +231,22 @@ TEST_CASE("deserialization")
|
|||||||
ss3 << R"(["foo",1,2,3,false,{"one":1}])";
|
ss3 << R"(["foo",1,2,3,false,{"one":1}])";
|
||||||
json j = json::parse(ss1);
|
json j = json::parse(ss1);
|
||||||
CHECK(json::accept(ss2));
|
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;
|
SaxEventLogger l;
|
||||||
CHECK(json::sax_parse(ss3, &l));
|
CHECK(json::sax_parse(ss3, &l));
|
||||||
CHECK(l.events.size() == 11);
|
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)",
|
"string(foo)",
|
||||||
"number_unsigned(1)",
|
"number_unsigned(1)",
|
||||||
"number_unsigned(2)",
|
"number_unsigned(2)",
|
||||||
"number_unsigned(3)",
|
"number_unsigned(3)",
|
||||||
"boolean(false)",
|
"boolean(false)",
|
||||||
"start_object()",
|
"start_object()",
|
||||||
"key(one)",
|
"key(one)",
|
||||||
"number_unsigned(1)",
|
"number_unsigned(1)",
|
||||||
"end_object()",
|
"end_object()",
|
||||||
"end_array()"}));
|
"end_array()" }));
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("string literal")
|
SECTION("string literal")
|
||||||
@ -254,22 +254,22 @@ TEST_CASE("deserialization")
|
|||||||
const auto* s = R"(["foo",1,2,3,false,{"one":1}])";
|
const auto* s = R"(["foo",1,2,3,false,{"one":1}])";
|
||||||
json j = json::parse(s);
|
json j = json::parse(s);
|
||||||
CHECK(json::accept(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;
|
SaxEventLogger l;
|
||||||
CHECK(json::sax_parse(s, &l));
|
CHECK(json::sax_parse(s, &l));
|
||||||
CHECK(l.events.size() == 11);
|
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)",
|
"string(foo)",
|
||||||
"number_unsigned(1)",
|
"number_unsigned(1)",
|
||||||
"number_unsigned(2)",
|
"number_unsigned(2)",
|
||||||
"number_unsigned(3)",
|
"number_unsigned(3)",
|
||||||
"boolean(false)",
|
"boolean(false)",
|
||||||
"start_object()",
|
"start_object()",
|
||||||
"key(one)",
|
"key(one)",
|
||||||
"number_unsigned(1)",
|
"number_unsigned(1)",
|
||||||
"end_object()",
|
"end_object()",
|
||||||
"end_array()"}));
|
"end_array()" }));
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("string_t")
|
SECTION("string_t")
|
||||||
@ -277,22 +277,22 @@ TEST_CASE("deserialization")
|
|||||||
json::string_t const s = R"(["foo",1,2,3,false,{"one":1}])";
|
json::string_t const s = R"(["foo",1,2,3,false,{"one":1}])";
|
||||||
json j = json::parse(s);
|
json j = json::parse(s);
|
||||||
CHECK(json::accept(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;
|
SaxEventLogger l;
|
||||||
CHECK(json::sax_parse(s, &l));
|
CHECK(json::sax_parse(s, &l));
|
||||||
CHECK(l.events.size() == 11);
|
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)",
|
"string(foo)",
|
||||||
"number_unsigned(1)",
|
"number_unsigned(1)",
|
||||||
"number_unsigned(2)",
|
"number_unsigned(2)",
|
||||||
"number_unsigned(3)",
|
"number_unsigned(3)",
|
||||||
"boolean(false)",
|
"boolean(false)",
|
||||||
"start_object()",
|
"start_object()",
|
||||||
"key(one)",
|
"key(one)",
|
||||||
"number_unsigned(1)",
|
"number_unsigned(1)",
|
||||||
"end_object()",
|
"end_object()",
|
||||||
"end_array()"}));
|
"end_array()" }));
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("operator<<")
|
SECTION("operator<<")
|
||||||
@ -301,7 +301,7 @@ TEST_CASE("deserialization")
|
|||||||
ss << R"(["foo",1,2,3,false,{"one":1}])";
|
ss << R"(["foo",1,2,3,false,{"one":1}])";
|
||||||
json j;
|
json j;
|
||||||
j << ss;
|
j << ss;
|
||||||
CHECK(j == json({"foo", 1, 2, 3, false, {{"one", 1}}}));
|
CHECK(j == json({ "foo", 1, 2, 3, false, { { "one", 1 } } }));
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("operator>>")
|
SECTION("operator>>")
|
||||||
@ -310,12 +310,12 @@ TEST_CASE("deserialization")
|
|||||||
ss << R"(["foo",1,2,3,false,{"one":1}])";
|
ss << R"(["foo",1,2,3,false,{"one":1}])";
|
||||||
json j;
|
json j;
|
||||||
ss >> 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")
|
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,17 +346,17 @@ TEST_CASE("deserialization")
|
|||||||
SaxEventLogger l;
|
SaxEventLogger l;
|
||||||
CHECK(!json::sax_parse(ss5, &l));
|
CHECK(!json::sax_parse(ss5, &l));
|
||||||
CHECK(l.events.size() == 11);
|
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)",
|
"string(foo)",
|
||||||
"number_unsigned(1)",
|
"number_unsigned(1)",
|
||||||
"number_unsigned(2)",
|
"number_unsigned(2)",
|
||||||
"number_unsigned(3)",
|
"number_unsigned(3)",
|
||||||
"boolean(false)",
|
"boolean(false)",
|
||||||
"start_object()",
|
"start_object()",
|
||||||
"key(one)",
|
"key(one)",
|
||||||
"number_unsigned(1)",
|
"number_unsigned(1)",
|
||||||
"end_object()",
|
"end_object()",
|
||||||
"parse_error(29)"}));
|
"parse_error(29)" }));
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("string")
|
SECTION("string")
|
||||||
@ -376,17 +376,17 @@ TEST_CASE("deserialization")
|
|||||||
SaxEventLogger l;
|
SaxEventLogger l;
|
||||||
CHECK(!json::sax_parse(s, &l));
|
CHECK(!json::sax_parse(s, &l));
|
||||||
CHECK(l.events.size() == 11);
|
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)",
|
"string(foo)",
|
||||||
"number_unsigned(1)",
|
"number_unsigned(1)",
|
||||||
"number_unsigned(2)",
|
"number_unsigned(2)",
|
||||||
"number_unsigned(3)",
|
"number_unsigned(3)",
|
||||||
"boolean(false)",
|
"boolean(false)",
|
||||||
"start_object()",
|
"start_object()",
|
||||||
"key(one)",
|
"key(one)",
|
||||||
"number_unsigned(1)",
|
"number_unsigned(1)",
|
||||||
"end_object()",
|
"end_object()",
|
||||||
"parse_error(29)"}));
|
"parse_error(29)" }));
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("operator<<")
|
SECTION("operator<<")
|
||||||
@ -426,38 +426,38 @@ TEST_CASE("deserialization")
|
|||||||
{
|
{
|
||||||
SECTION("from std::vector")
|
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::parse(v) == json(true));
|
||||||
CHECK(json::accept(v));
|
CHECK(json::accept(v));
|
||||||
|
|
||||||
SaxEventLogger l;
|
SaxEventLogger l;
|
||||||
CHECK(json::sax_parse(v, &l));
|
CHECK(json::sax_parse(v, &l));
|
||||||
CHECK(l.events.size() == 1);
|
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")
|
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::parse(v) == json(true));
|
||||||
CHECK(json::accept(v));
|
CHECK(json::accept(v));
|
||||||
|
|
||||||
SaxEventLogger l;
|
SaxEventLogger l;
|
||||||
CHECK(json::sax_parse(v, &l));
|
CHECK(json::sax_parse(v, &l));
|
||||||
CHECK(l.events.size() == 1);
|
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")
|
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::parse(v) == json(true));
|
||||||
CHECK(json::accept(v));
|
CHECK(json::accept(v));
|
||||||
|
|
||||||
SaxEventLogger l;
|
SaxEventLogger l;
|
||||||
CHECK(json::sax_parse(v, &l));
|
CHECK(json::sax_parse(v, &l));
|
||||||
CHECK(l.events.size() == 1);
|
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")
|
SECTION("from chars")
|
||||||
@ -474,33 +474,33 @@ TEST_CASE("deserialization")
|
|||||||
SaxEventLogger l;
|
SaxEventLogger l;
|
||||||
CHECK(json::sax_parse(v, &l));
|
CHECK(json::sax_parse(v, &l));
|
||||||
CHECK(l.events.size() == 1);
|
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)
|
delete[] v; // NOLINT(cppcoreguidelines-owning-memory)
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("from std::string")
|
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::parse(v) == json(true));
|
||||||
CHECK(json::accept(v));
|
CHECK(json::accept(v));
|
||||||
|
|
||||||
SaxEventLogger l;
|
SaxEventLogger l;
|
||||||
CHECK(json::sax_parse(v, &l));
|
CHECK(json::sax_parse(v, &l));
|
||||||
CHECK(l.events.size() == 1);
|
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")
|
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::parse(v) == json(true));
|
||||||
CHECK(json::accept(v));
|
CHECK(json::accept(v));
|
||||||
|
|
||||||
SaxEventLogger l;
|
SaxEventLogger l;
|
||||||
CHECK(json::sax_parse(v, &l));
|
CHECK(json::sax_parse(v, &l));
|
||||||
CHECK(l.events.size() == 1);
|
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")
|
SECTION("empty container")
|
||||||
@ -513,7 +513,7 @@ TEST_CASE("deserialization")
|
|||||||
SaxEventLogger l;
|
SaxEventLogger l;
|
||||||
CHECK(!json::sax_parse(v, &l));
|
CHECK(!json::sax_parse(v, &l));
|
||||||
CHECK(l.events.size() == 1);
|
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")
|
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::parse(std::begin(v), std::end(v)) == json(true));
|
||||||
CHECK(json::accept(std::begin(v), std::end(v)));
|
CHECK(json::accept(std::begin(v), std::end(v)));
|
||||||
|
|
||||||
SaxEventLogger l;
|
SaxEventLogger l;
|
||||||
CHECK(json::sax_parse(std::begin(v), std::end(v), &l));
|
CHECK(json::sax_parse(std::begin(v), std::end(v), &l));
|
||||||
CHECK(l.events.size() == 1);
|
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")
|
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::parse(std::begin(v), std::end(v)) == json(true));
|
||||||
CHECK(json::accept(std::begin(v), std::end(v)));
|
CHECK(json::accept(std::begin(v), std::end(v)));
|
||||||
|
|
||||||
SaxEventLogger l;
|
SaxEventLogger l;
|
||||||
CHECK(json::sax_parse(std::begin(v), std::end(v), &l));
|
CHECK(json::sax_parse(std::begin(v), std::end(v), &l));
|
||||||
CHECK(l.events.size() == 1);
|
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")
|
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::parse(std::begin(v), std::end(v)) == json(true));
|
||||||
CHECK(json::accept(std::begin(v), std::end(v)));
|
CHECK(json::accept(std::begin(v), std::end(v)));
|
||||||
|
|
||||||
SaxEventLogger l;
|
SaxEventLogger l;
|
||||||
CHECK(json::sax_parse(std::begin(v), std::end(v), &l));
|
CHECK(json::sax_parse(std::begin(v), std::end(v), &l));
|
||||||
CHECK(l.events.size() == 1);
|
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")
|
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::parse(std::begin(v), std::end(v)) == json(true));
|
||||||
CHECK(json::accept(std::begin(v), std::end(v)));
|
CHECK(json::accept(std::begin(v), std::end(v)));
|
||||||
|
|
||||||
SaxEventLogger l;
|
SaxEventLogger l;
|
||||||
CHECK(json::sax_parse(std::begin(v), std::end(v), &l));
|
CHECK(json::sax_parse(std::begin(v), std::end(v), &l));
|
||||||
CHECK(l.events.size() == 1);
|
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")
|
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::parse(std::begin(v), std::end(v)) == json(true));
|
||||||
CHECK(json::accept(std::begin(v), std::end(v)));
|
CHECK(json::accept(std::begin(v), std::end(v)));
|
||||||
|
|
||||||
SaxEventLogger l;
|
SaxEventLogger l;
|
||||||
CHECK(json::sax_parse(std::begin(v), std::end(v), &l));
|
CHECK(json::sax_parse(std::begin(v), std::end(v), &l));
|
||||||
CHECK(l.events.size() == 1);
|
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")
|
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::parse(std::begin(v), std::end(v)) == json(true));
|
||||||
CHECK(json::accept(std::begin(v), std::end(v)));
|
CHECK(json::accept(std::begin(v), std::end(v)));
|
||||||
|
|
||||||
SaxEventLogger l;
|
SaxEventLogger l;
|
||||||
CHECK(json::sax_parse(std::begin(v), std::end(v), &l));
|
CHECK(json::sax_parse(std::begin(v), std::end(v), &l));
|
||||||
CHECK(l.events.size() == 1);
|
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")
|
SECTION("with empty range")
|
||||||
@ -601,7 +601,7 @@ TEST_CASE("deserialization")
|
|||||||
SaxEventLogger l;
|
SaxEventLogger l;
|
||||||
CHECK(!json::sax_parse(std::begin(v), std::end(v), &l));
|
CHECK(!json::sax_parse(std::begin(v), std::end(v), &l));
|
||||||
CHECK(l.events.size() == 1);
|
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")
|
SECTION("iterator_input_adapter advances iterators correctly")
|
||||||
@ -631,7 +631,7 @@ TEST_CASE("deserialization")
|
|||||||
{
|
{
|
||||||
SECTION("case 1")
|
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 _;
|
json _;
|
||||||
CHECK_THROWS_AS(_ = json::parse(std::begin(v), std::end(v)), json::parse_error&);
|
CHECK_THROWS_AS(_ = json::parse(std::begin(v), std::end(v)), json::parse_error&);
|
||||||
CHECK(!json::accept(std::begin(v), std::end(v)));
|
CHECK(!json::accept(std::begin(v), std::end(v)));
|
||||||
@ -643,12 +643,12 @@ TEST_CASE("deserialization")
|
|||||||
SaxEventLogger l;
|
SaxEventLogger l;
|
||||||
CHECK(!json::sax_parse(std::begin(v), std::end(v), &l));
|
CHECK(!json::sax_parse(std::begin(v), std::end(v), &l));
|
||||||
CHECK(l.events.size() == 1);
|
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")
|
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 _;
|
json _;
|
||||||
CHECK_THROWS_AS(_ = json::parse(std::begin(v), std::end(v)), json::parse_error&);
|
CHECK_THROWS_AS(_ = json::parse(std::begin(v), std::end(v)), json::parse_error&);
|
||||||
CHECK(!json::accept(std::begin(v), std::end(v)));
|
CHECK(!json::accept(std::begin(v), std::end(v)));
|
||||||
@ -660,12 +660,12 @@ TEST_CASE("deserialization")
|
|||||||
SaxEventLogger l;
|
SaxEventLogger l;
|
||||||
CHECK(!json::sax_parse(std::begin(v), std::end(v), &l));
|
CHECK(!json::sax_parse(std::begin(v), std::end(v), &l));
|
||||||
CHECK(l.events.size() == 1);
|
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")
|
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 _;
|
json _;
|
||||||
CHECK_THROWS_AS(_ = json::parse(std::begin(v), std::end(v)), json::parse_error&);
|
CHECK_THROWS_AS(_ = json::parse(std::begin(v), std::end(v)), json::parse_error&);
|
||||||
CHECK(!json::accept(std::begin(v), std::end(v)));
|
CHECK(!json::accept(std::begin(v), std::end(v)));
|
||||||
@ -677,12 +677,12 @@ TEST_CASE("deserialization")
|
|||||||
SaxEventLogger l;
|
SaxEventLogger l;
|
||||||
CHECK(!json::sax_parse(std::begin(v), std::end(v), &l));
|
CHECK(!json::sax_parse(std::begin(v), std::end(v), &l));
|
||||||
CHECK(l.events.size() == 1);
|
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")
|
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 _;
|
json _;
|
||||||
CHECK_THROWS_AS(_ = json::parse(std::begin(v), std::end(v)), json::parse_error&);
|
CHECK_THROWS_AS(_ = json::parse(std::begin(v), std::end(v)), json::parse_error&);
|
||||||
CHECK(!json::accept(std::begin(v), std::end(v)));
|
CHECK(!json::accept(std::begin(v), std::end(v)));
|
||||||
@ -694,12 +694,12 @@ TEST_CASE("deserialization")
|
|||||||
SaxEventLogger l;
|
SaxEventLogger l;
|
||||||
CHECK(!json::sax_parse(std::begin(v), std::end(v), &l));
|
CHECK(!json::sax_parse(std::begin(v), std::end(v), &l));
|
||||||
CHECK(l.events.size() == 1);
|
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")
|
SECTION("case 5")
|
||||||
{
|
{
|
||||||
std::array<std::uint8_t, 3> v = {{'\"', 0x7F, 0xC1}};
|
std::array<std::uint8_t, 3> v = { { '\"', 0x7F, 0xC1 } };
|
||||||
json _;
|
json _;
|
||||||
CHECK_THROWS_AS(_ = json::parse(std::begin(v), std::end(v)), json::parse_error&);
|
CHECK_THROWS_AS(_ = json::parse(std::begin(v), std::end(v)), json::parse_error&);
|
||||||
CHECK(!json::accept(std::begin(v), std::end(v)));
|
CHECK(!json::accept(std::begin(v), std::end(v)));
|
||||||
@ -711,12 +711,12 @@ TEST_CASE("deserialization")
|
|||||||
SaxEventLogger l;
|
SaxEventLogger l;
|
||||||
CHECK(!json::sax_parse(std::begin(v), std::end(v), &l));
|
CHECK(!json::sax_parse(std::begin(v), std::end(v), &l));
|
||||||
CHECK(l.events.size() == 1);
|
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")
|
SECTION("case 6")
|
||||||
{
|
{
|
||||||
std::array<std::uint8_t, 4> v = {{'\"', 0x7F, 0xDF, 0x7F}};
|
std::array<std::uint8_t, 4> v = { { '\"', 0x7F, 0xDF, 0x7F } };
|
||||||
json _;
|
json _;
|
||||||
CHECK_THROWS_WITH_AS(
|
CHECK_THROWS_WITH_AS(
|
||||||
_ = json::parse(std::begin(v), std::end(v)),
|
_ = json::parse(std::begin(v), std::end(v)),
|
||||||
@ -731,12 +731,12 @@ TEST_CASE("deserialization")
|
|||||||
SaxEventLogger l;
|
SaxEventLogger l;
|
||||||
CHECK(!json::sax_parse(std::begin(v), std::end(v), &l));
|
CHECK(!json::sax_parse(std::begin(v), std::end(v), &l));
|
||||||
CHECK(l.events.size() == 1);
|
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")
|
SECTION("case 7")
|
||||||
{
|
{
|
||||||
std::array<std::uint8_t, 4> v = {{'\"', 0x7F, 0xDF, 0xC0}};
|
std::array<std::uint8_t, 4> v = { { '\"', 0x7F, 0xDF, 0xC0 } };
|
||||||
json _;
|
json _;
|
||||||
CHECK_THROWS_AS(_ = json::parse(std::begin(v), std::end(v)), json::parse_error&);
|
CHECK_THROWS_AS(_ = json::parse(std::begin(v), std::end(v)), json::parse_error&);
|
||||||
CHECK(!json::accept(std::begin(v), std::end(v)));
|
CHECK(!json::accept(std::begin(v), std::end(v)));
|
||||||
@ -748,12 +748,12 @@ TEST_CASE("deserialization")
|
|||||||
SaxEventLogger l;
|
SaxEventLogger l;
|
||||||
CHECK(!json::sax_parse(std::begin(v), std::end(v), &l));
|
CHECK(!json::sax_parse(std::begin(v), std::end(v), &l));
|
||||||
CHECK(l.events.size() == 1);
|
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")
|
SECTION("case 8")
|
||||||
{
|
{
|
||||||
std::array<std::uint8_t, 4> v = {{'\"', 0x7F, 0xE0, 0x9F}};
|
std::array<std::uint8_t, 4> v = { { '\"', 0x7F, 0xE0, 0x9F } };
|
||||||
json _;
|
json _;
|
||||||
CHECK_THROWS_AS(_ = json::parse(std::begin(v), std::end(v)), json::parse_error&);
|
CHECK_THROWS_AS(_ = json::parse(std::begin(v), std::end(v)), json::parse_error&);
|
||||||
CHECK(!json::accept(std::begin(v), std::end(v)));
|
CHECK(!json::accept(std::begin(v), std::end(v)));
|
||||||
@ -765,12 +765,12 @@ TEST_CASE("deserialization")
|
|||||||
SaxEventLogger l;
|
SaxEventLogger l;
|
||||||
CHECK(!json::sax_parse(std::begin(v), std::end(v), &l));
|
CHECK(!json::sax_parse(std::begin(v), std::end(v), &l));
|
||||||
CHECK(l.events.size() == 1);
|
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")
|
SECTION("case 9")
|
||||||
{
|
{
|
||||||
std::array<std::uint8_t, 4> v = {{'\"', 0x7F, 0xEF, 0xC0}};
|
std::array<std::uint8_t, 4> v = { { '\"', 0x7F, 0xEF, 0xC0 } };
|
||||||
json _;
|
json _;
|
||||||
CHECK_THROWS_AS(_ = json::parse(std::begin(v), std::end(v)), json::parse_error&);
|
CHECK_THROWS_AS(_ = json::parse(std::begin(v), std::end(v)), json::parse_error&);
|
||||||
CHECK(!json::accept(std::begin(v), std::end(v)));
|
CHECK(!json::accept(std::begin(v), std::end(v)));
|
||||||
@ -782,12 +782,12 @@ TEST_CASE("deserialization")
|
|||||||
SaxEventLogger l;
|
SaxEventLogger l;
|
||||||
CHECK(!json::sax_parse(std::begin(v), std::end(v), &l));
|
CHECK(!json::sax_parse(std::begin(v), std::end(v), &l));
|
||||||
CHECK(l.events.size() == 1);
|
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")
|
SECTION("case 10")
|
||||||
{
|
{
|
||||||
std::array<std::uint8_t, 4> v = {{'\"', 0x7F, 0xED, 0x7F}};
|
std::array<std::uint8_t, 4> v = { { '\"', 0x7F, 0xED, 0x7F } };
|
||||||
json _;
|
json _;
|
||||||
CHECK_THROWS_AS(_ = json::parse(std::begin(v), std::end(v)), json::parse_error&);
|
CHECK_THROWS_AS(_ = json::parse(std::begin(v), std::end(v)), json::parse_error&);
|
||||||
CHECK(!json::accept(std::begin(v), std::end(v)));
|
CHECK(!json::accept(std::begin(v), std::end(v)));
|
||||||
@ -799,12 +799,12 @@ TEST_CASE("deserialization")
|
|||||||
SaxEventLogger l;
|
SaxEventLogger l;
|
||||||
CHECK(!json::sax_parse(std::begin(v), std::end(v), &l));
|
CHECK(!json::sax_parse(std::begin(v), std::end(v), &l));
|
||||||
CHECK(l.events.size() == 1);
|
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")
|
SECTION("case 11")
|
||||||
{
|
{
|
||||||
std::array<std::uint8_t, 4> v = {{'\"', 0x7F, 0xF0, 0x8F}};
|
std::array<std::uint8_t, 4> v = { { '\"', 0x7F, 0xF0, 0x8F } };
|
||||||
json _;
|
json _;
|
||||||
CHECK_THROWS_AS(_ = json::parse(std::begin(v), std::end(v)), json::parse_error&);
|
CHECK_THROWS_AS(_ = json::parse(std::begin(v), std::end(v)), json::parse_error&);
|
||||||
CHECK(!json::accept(std::begin(v), std::end(v)));
|
CHECK(!json::accept(std::begin(v), std::end(v)));
|
||||||
@ -816,12 +816,12 @@ TEST_CASE("deserialization")
|
|||||||
SaxEventLogger l;
|
SaxEventLogger l;
|
||||||
CHECK(!json::sax_parse(std::begin(v), std::end(v), &l));
|
CHECK(!json::sax_parse(std::begin(v), std::end(v), &l));
|
||||||
CHECK(l.events.size() == 1);
|
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")
|
SECTION("case 12")
|
||||||
{
|
{
|
||||||
std::array<std::uint8_t, 4> v = {{'\"', 0x7F, 0xF0, 0xC0}};
|
std::array<std::uint8_t, 4> v = { { '\"', 0x7F, 0xF0, 0xC0 } };
|
||||||
json _;
|
json _;
|
||||||
CHECK_THROWS_AS(_ = json::parse(std::begin(v), std::end(v)), json::parse_error&);
|
CHECK_THROWS_AS(_ = json::parse(std::begin(v), std::end(v)), json::parse_error&);
|
||||||
CHECK(!json::accept(std::begin(v), std::end(v)));
|
CHECK(!json::accept(std::begin(v), std::end(v)));
|
||||||
@ -833,12 +833,12 @@ TEST_CASE("deserialization")
|
|||||||
SaxEventLogger l;
|
SaxEventLogger l;
|
||||||
CHECK(!json::sax_parse(std::begin(v), std::end(v), &l));
|
CHECK(!json::sax_parse(std::begin(v), std::end(v), &l));
|
||||||
CHECK(l.events.size() == 1);
|
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")
|
SECTION("case 13")
|
||||||
{
|
{
|
||||||
std::array<std::uint8_t, 4> v = {{'\"', 0x7F, 0xF3, 0x7F}};
|
std::array<std::uint8_t, 4> v = { { '\"', 0x7F, 0xF3, 0x7F } };
|
||||||
json _;
|
json _;
|
||||||
CHECK_THROWS_AS(_ = json::parse(std::begin(v), std::end(v)), json::parse_error&);
|
CHECK_THROWS_AS(_ = json::parse(std::begin(v), std::end(v)), json::parse_error&);
|
||||||
CHECK(!json::accept(std::begin(v), std::end(v)));
|
CHECK(!json::accept(std::begin(v), std::end(v)));
|
||||||
@ -850,12 +850,12 @@ TEST_CASE("deserialization")
|
|||||||
SaxEventLogger l;
|
SaxEventLogger l;
|
||||||
CHECK(!json::sax_parse(std::begin(v), std::end(v), &l));
|
CHECK(!json::sax_parse(std::begin(v), std::end(v), &l));
|
||||||
CHECK(l.events.size() == 1);
|
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")
|
SECTION("case 14")
|
||||||
{
|
{
|
||||||
std::array<std::uint8_t, 4> v = {{'\"', 0x7F, 0xF3, 0xC0}};
|
std::array<std::uint8_t, 4> v = { { '\"', 0x7F, 0xF3, 0xC0 } };
|
||||||
json _;
|
json _;
|
||||||
CHECK_THROWS_AS(_ = json::parse(std::begin(v), std::end(v)), json::parse_error&);
|
CHECK_THROWS_AS(_ = json::parse(std::begin(v), std::end(v)), json::parse_error&);
|
||||||
CHECK(!json::accept(std::begin(v), std::end(v)));
|
CHECK(!json::accept(std::begin(v), std::end(v)));
|
||||||
@ -867,12 +867,12 @@ TEST_CASE("deserialization")
|
|||||||
SaxEventLogger l;
|
SaxEventLogger l;
|
||||||
CHECK(!json::sax_parse(std::begin(v), std::end(v), &l));
|
CHECK(!json::sax_parse(std::begin(v), std::end(v), &l));
|
||||||
CHECK(l.events.size() == 1);
|
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")
|
SECTION("case 15")
|
||||||
{
|
{
|
||||||
std::array<std::uint8_t, 4> v = {{'\"', 0x7F, 0xF4, 0x7F}};
|
std::array<std::uint8_t, 4> v = { { '\"', 0x7F, 0xF4, 0x7F } };
|
||||||
json _;
|
json _;
|
||||||
CHECK_THROWS_AS(_ = json::parse(std::begin(v), std::end(v)), json::parse_error&);
|
CHECK_THROWS_AS(_ = json::parse(std::begin(v), std::end(v)), json::parse_error&);
|
||||||
CHECK(!json::accept(std::begin(v), std::end(v)));
|
CHECK(!json::accept(std::begin(v), std::end(v)));
|
||||||
@ -884,12 +884,12 @@ TEST_CASE("deserialization")
|
|||||||
SaxEventLogger l;
|
SaxEventLogger l;
|
||||||
CHECK(!json::sax_parse(std::begin(v), std::end(v), &l));
|
CHECK(!json::sax_parse(std::begin(v), std::end(v), &l));
|
||||||
CHECK(l.events.size() == 1);
|
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")
|
SECTION("case 16")
|
||||||
{
|
{
|
||||||
std::array<std::uint8_t, 6> v = {{'{', '\"', '\"', ':', '1', '1'}};
|
std::array<std::uint8_t, 6> v = { { '{', '\"', '\"', ':', '1', '1' } };
|
||||||
json _;
|
json _;
|
||||||
CHECK_THROWS_AS(_ = json::parse(std::begin(v), std::end(v)), json::parse_error&);
|
CHECK_THROWS_AS(_ = json::parse(std::begin(v), std::end(v)), json::parse_error&);
|
||||||
CHECK(!json::accept(std::begin(v), std::end(v)));
|
CHECK(!json::accept(std::begin(v), std::end(v)));
|
||||||
@ -901,7 +901,7 @@ TEST_CASE("deserialization")
|
|||||||
SaxEventLogger l;
|
SaxEventLogger l;
|
||||||
CHECK(!json::sax_parse(std::begin(v), std::end(v), &l));
|
CHECK(!json::sax_parse(std::begin(v), std::end(v), &l));
|
||||||
CHECK(l.events.size() == 4);
|
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;
|
SaxEventLogger l;
|
||||||
CHECK(!json::sax_parse(bom, &l));
|
CHECK(!json::sax_parse(bom, &l));
|
||||||
CHECK(l.events.size() == 1);
|
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")
|
SECTION("BOM and content")
|
||||||
@ -939,9 +939,9 @@ TEST_CASE("deserialization")
|
|||||||
CHECK(json::sax_parse(std::istringstream(bom + "1"), &l1));
|
CHECK(json::sax_parse(std::istringstream(bom + "1"), &l1));
|
||||||
CHECK(json::sax_parse(bom + "1", &l2));
|
CHECK(json::sax_parse(bom + "1", &l2));
|
||||||
CHECK(l1.events.size() == 1);
|
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.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")
|
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(std::istringstream(bom.substr(0, 2)), &l1));
|
||||||
CHECK(!json::sax_parse(bom.substr(0, 2), &l2));
|
CHECK(!json::sax_parse(bom.substr(0, 2), &l2));
|
||||||
CHECK(l1.events.size() == 1);
|
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.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")
|
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(std::istringstream(bom.substr(0, 1)), &l1));
|
||||||
CHECK(!json::sax_parse(bom.substr(0, 1), &l2));
|
CHECK(!json::sax_parse(bom.substr(0, 1), &l2));
|
||||||
CHECK(l1.events.size() == 1);
|
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.size() == 1);
|
||||||
CHECK(l2.events == std::vector<std::string>({"parse_error(2)"}));
|
CHECK(l2.events == std::vector<std::string>({ "parse_error(2)" }));
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("variations")
|
SECTION("variations")
|
||||||
@ -1019,7 +1019,7 @@ TEST_CASE("deserialization")
|
|||||||
SaxEventLogger l;
|
SaxEventLogger l;
|
||||||
CHECK(json::sax_parse(s + "null", &l));
|
CHECK(json::sax_parse(s + "null", &l));
|
||||||
CHECK(l.events.size() == 1);
|
CHECK(l.events.size() == 1);
|
||||||
CHECK(l.events == std::vector<std::string>({"null()"}));
|
CHECK(l.events == std::vector<std::string>({ "null()" }));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -1034,15 +1034,15 @@ TEST_CASE("deserialization")
|
|||||||
|
|
||||||
if (i0 != 0)
|
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)
|
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
|
else
|
||||||
{
|
{
|
||||||
CHECK(l.events == std::vector<std::string>({"parse_error(3)"}));
|
CHECK(l.events == std::vector<std::string>({ "parse_error(3)" }));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1072,43 +1072,47 @@ TEST_CASE("deserialization")
|
|||||||
|
|
||||||
json::sax_parse(s, &default_logger);
|
json::sax_parse(s, &default_logger);
|
||||||
CHECK(default_logger.events.size() == 14);
|
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)",
|
"number_unsigned(1)",
|
||||||
"start_array()",
|
"start_array()",
|
||||||
"string(string)",
|
"string(string)",
|
||||||
"number_float(43.12)",
|
"number_float(43.12)",
|
||||||
"end_array()",
|
"end_array()",
|
||||||
"null()",
|
"null()",
|
||||||
"start_object()",
|
"start_object()",
|
||||||
"key(key1)",
|
"key(key1)",
|
||||||
"boolean(true)",
|
"boolean(true)",
|
||||||
"key(key2)",
|
"key(key2)",
|
||||||
"boolean(false)",
|
"boolean(false)",
|
||||||
"end_object()",
|
"end_object()",
|
||||||
"end_array()"}));
|
"end_array()" }));
|
||||||
|
|
||||||
json::sax_parse(s, &exit_after_start_object);
|
json::sax_parse(s, &exit_after_start_object);
|
||||||
CHECK(exit_after_start_object.events.size() == 8);
|
CHECK(exit_after_start_object.events.size() == 8);
|
||||||
CHECK(
|
CHECK(exit_after_start_object.events == std::vector<std::string>({ "start_array()",
|
||||||
exit_after_start_object.events ==
|
"number_unsigned(1)",
|
||||||
std::vector<std::string>(
|
"start_array()",
|
||||||
{"start_array()", "number_unsigned(1)", "start_array()", "string(string)", "number_float(43.12)", "end_array()", "null()", "start_object()"}));
|
"string(string)",
|
||||||
|
"number_float(43.12)",
|
||||||
|
"end_array()",
|
||||||
|
"null()",
|
||||||
|
"start_object()" }));
|
||||||
|
|
||||||
json::sax_parse(s, &exit_after_key);
|
json::sax_parse(s, &exit_after_key);
|
||||||
CHECK(exit_after_key.events.size() == 9);
|
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)",
|
"number_unsigned(1)",
|
||||||
"start_array()",
|
"start_array()",
|
||||||
"string(string)",
|
"string(string)",
|
||||||
"number_float(43.12)",
|
"number_float(43.12)",
|
||||||
"end_array()",
|
"end_array()",
|
||||||
"null()",
|
"null()",
|
||||||
"start_object()",
|
"start_object()",
|
||||||
"key(key1)"}));
|
"key(key1)" }));
|
||||||
|
|
||||||
json::sax_parse(s, &exit_after_start_array);
|
json::sax_parse(s, &exit_after_start_array);
|
||||||
CHECK(exit_after_start_array.events.size() == 1);
|
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")
|
SECTION("JSON Lines")
|
||||||
@ -1169,21 +1173,22 @@ TEST_CASE_TEMPLATE("deserialization of different character types (ASCII)",
|
|||||||
std::int32_t,
|
std::int32_t,
|
||||||
std::uint32_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::parse(v) == json(true));
|
||||||
CHECK(json::accept(v));
|
CHECK(json::accept(v));
|
||||||
|
|
||||||
SaxEventLogger l;
|
SaxEventLogger l;
|
||||||
CHECK(json::sax_parse(v, &l));
|
CHECK(json::sax_parse(v, &l));
|
||||||
CHECK(l.events.size() == 1);
|
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)
|
TEST_CASE_TEMPLATE("deserialization of different character types (UTF-8)", T, char, unsigned char, std::uint8_t)
|
||||||
{
|
{
|
||||||
// a star emoji
|
// a star emoji
|
||||||
std::vector<T> const v =
|
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), '"'};
|
'"', 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::parse(v).dump(-1, ' ', true) == "\"\\u2b50\\ufe0f\"");
|
||||||
CHECK(json::accept(v));
|
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)
|
TEST_CASE_TEMPLATE("deserialization of different character types (UTF-16)", T, char16_t, std::uint16_t)
|
||||||
{
|
{
|
||||||
// a star emoji
|
// 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::parse(v).dump(-1, ' ', true) == "\"\\u2b50\\ufe0f\"");
|
||||||
CHECK(json::accept(v));
|
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)
|
TEST_CASE_TEMPLATE("deserialization of different character types (UTF-32)", T, char32_t, std::uint32_t)
|
||||||
{
|
{
|
||||||
// a star emoji
|
// 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::parse(v).dump(-1, ' ', true) == "\"\\u2b50\\ufe0f\"");
|
||||||
CHECK(json::accept(v));
|
CHECK(json::accept(v));
|
||||||
|
|
||||||
|
@ -90,8 +90,8 @@ TEST_CASE("Better diagnostics")
|
|||||||
|
|
||||||
SECTION("Wrong type in update()")
|
SECTION("Wrong type in update()")
|
||||||
{
|
{
|
||||||
json j = {{"foo", "bar"}};
|
json j = { { "foo", "bar" } };
|
||||||
json k = {{"bla", 1}};
|
json k = { { "bla", 1 } };
|
||||||
|
|
||||||
CHECK_THROWS_WITH_AS(j.update(k["bla"].begin(), k["bla"].end()),
|
CHECK_THROWS_WITH_AS(j.update(k["bla"].begin(), k["bla"].end()),
|
||||||
"[json.exception.type_error.312] (/bla) cannot use update() with number",
|
"[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")
|
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", "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", "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")
|
SECTION("Regression test for https://github.com/nlohmann/json/pull/2562/files/380a613f2b5d32425021129cd1f371ddcfd54ddf#r563259793")
|
||||||
{
|
{
|
||||||
json j;
|
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);
|
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)
|
// iterator insert(const_iterator pos, const_iterator first, const_iterator last)
|
||||||
{
|
{
|
||||||
json j_arr = json::array();
|
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());
|
j_arr.insert(j_arr.begin(), j_objects.begin(), j_objects.end());
|
||||||
json j_obj = json::object();
|
json j_obj = json::object();
|
||||||
j_obj["key"] = j_arr;
|
j_obj["key"] = j_arr;
|
||||||
|
@ -16,7 +16,7 @@ TEST_CASE("element access 1")
|
|||||||
{
|
{
|
||||||
SECTION("array")
|
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;
|
const json j_const = j;
|
||||||
|
|
||||||
SECTION("access specified element with bounds checking")
|
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(4) == json("string"));
|
||||||
CHECK(j.at(5) == json(42.23));
|
CHECK(j.at(5) == json(42.23));
|
||||||
CHECK(j.at(6) == json::object());
|
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(0) == json(1));
|
||||||
CHECK(j_const.at(1) == json(1u));
|
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(4) == json("string"));
|
||||||
CHECK(j_const.at(5) == json(42.23));
|
CHECK(j_const.at(5) == json(42.23));
|
||||||
CHECK(j_const.at(6) == json::object());
|
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")
|
SECTION("access outside bounds")
|
||||||
@ -119,8 +119,8 @@ TEST_CASE("element access 1")
|
|||||||
{
|
{
|
||||||
CHECK(j.front() == json(1));
|
CHECK(j.front() == json(1));
|
||||||
CHECK(j_const.front() == json(1));
|
CHECK(j_const.front() == json(1));
|
||||||
CHECK(j.back() == json({1, 2, 3}));
|
CHECK(j.back() == json({ 1, 2, 3 }));
|
||||||
CHECK(j_const.back() == json({1, 2, 3}));
|
CHECK(j_const.back() == json({ 1, 2, 3 }));
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("access specified element")
|
SECTION("access specified element")
|
||||||
@ -134,7 +134,7 @@ TEST_CASE("element access 1")
|
|||||||
CHECK(j[4] == json("string"));
|
CHECK(j[4] == json("string"));
|
||||||
CHECK(j[5] == json(42.23));
|
CHECK(j[5] == json(42.23));
|
||||||
CHECK(j[6] == json::object());
|
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[0] == json(1));
|
||||||
CHECK(j_const[1] == json(1u));
|
CHECK(j_const[1] == json(1u));
|
||||||
@ -143,7 +143,7 @@ TEST_CASE("element access 1")
|
|||||||
CHECK(j_const[4] == json("string"));
|
CHECK(j_const[4] == json("string"));
|
||||||
CHECK(j_const[5] == json(42.23));
|
CHECK(j_const[5] == json(42.23));
|
||||||
CHECK(j_const[6] == json::object());
|
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")
|
SECTION("access on non-array type")
|
||||||
@ -164,7 +164,7 @@ TEST_CASE("element access 1")
|
|||||||
{
|
{
|
||||||
json j_nonarray;
|
json j_nonarray;
|
||||||
j_nonarray[3] = 42;
|
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")
|
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);
|
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);
|
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);
|
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);
|
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);
|
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);
|
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);
|
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);
|
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&);
|
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())")
|
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());
|
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));
|
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());
|
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));
|
CHECK(*it2 == json(1u));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -313,13 +313,13 @@ TEST_CASE("element access 1")
|
|||||||
SECTION("erase(begin(), end())")
|
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());
|
json::iterator it2 = jarray.erase(jarray.begin(), jarray.end());
|
||||||
CHECK(jarray == json::array());
|
CHECK(jarray == json::array());
|
||||||
CHECK(it2 == jarray.end());
|
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());
|
json::const_iterator it2 = jarray.erase(jarray.cbegin(), jarray.cend());
|
||||||
CHECK(jarray == json::array());
|
CHECK(jarray == json::array());
|
||||||
CHECK(it2 == jarray.cend());
|
CHECK(it2 == jarray.cend());
|
||||||
@ -329,15 +329,15 @@ TEST_CASE("element access 1")
|
|||||||
SECTION("erase(begin(), begin())")
|
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());
|
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));
|
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());
|
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));
|
CHECK(*it2 == json(1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -345,17 +345,17 @@ TEST_CASE("element access 1")
|
|||||||
SECTION("erase at offset")
|
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 it = jarray.begin() + 4;
|
||||||
json::iterator const it2 = jarray.erase(it);
|
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));
|
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 it = jarray.cbegin() + 4;
|
||||||
json::const_iterator const it2 = jarray.erase(it);
|
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));
|
CHECK(*it2 == json(42.23));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -363,15 +363,15 @@ TEST_CASE("element access 1")
|
|||||||
SECTION("erase subrange")
|
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);
|
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());
|
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);
|
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());
|
CHECK(*it2 == json::object());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -379,8 +379,8 @@ TEST_CASE("element access 1")
|
|||||||
SECTION("different arrays")
|
SECTION("different arrays")
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
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 jarray2 = {"foo", "bar"};
|
json jarray2 = { "foo", "bar" };
|
||||||
|
|
||||||
CHECK_THROWS_WITH_AS(jarray.erase(jarray2.begin()),
|
CHECK_THROWS_WITH_AS(jarray.erase(jarray2.begin()),
|
||||||
"[json.exception.invalid_iterator.202] iterator does not fit current value",
|
"[json.exception.invalid_iterator.202] iterator does not fit current value",
|
||||||
@ -396,8 +396,8 @@ TEST_CASE("element access 1")
|
|||||||
json::invalid_iterator&);
|
json::invalid_iterator&);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
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 jarray2 = {"foo", "bar"};
|
json const jarray2 = { "foo", "bar" };
|
||||||
|
|
||||||
CHECK_THROWS_WITH_AS(jarray.erase(jarray2.cbegin()),
|
CHECK_THROWS_WITH_AS(jarray.erase(jarray2.cbegin()),
|
||||||
"[json.exception.invalid_iterator.202] iterator does not fit current value",
|
"[json.exception.invalid_iterator.202] iterator does not fit current value",
|
||||||
@ -648,13 +648,13 @@ TEST_CASE("element access 1")
|
|||||||
SECTION("binary")
|
SECTION("binary")
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
json j = json::binary({1, 2, 3});
|
json j = json::binary({ 1, 2, 3 });
|
||||||
json::iterator it = j.erase(j.begin());
|
json::iterator it = j.erase(j.begin());
|
||||||
CHECK(j.type() == json::value_t::null);
|
CHECK(j.type() == json::value_t::null);
|
||||||
CHECK(it == j.end());
|
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());
|
json::const_iterator it = j.erase(j.cbegin());
|
||||||
CHECK(j.type() == json::value_t::null);
|
CHECK(j.type() == json::value_t::null);
|
||||||
CHECK(it == j.end());
|
CHECK(it == j.end());
|
||||||
@ -822,13 +822,13 @@ TEST_CASE("element access 1")
|
|||||||
SECTION("binary")
|
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());
|
json::iterator it = j.erase(j.begin(), j.end());
|
||||||
CHECK(j.type() == json::value_t::null);
|
CHECK(j.type() == json::value_t::null);
|
||||||
CHECK(it == j.end());
|
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());
|
json::const_iterator it = j.erase(j.cbegin(), j.cend());
|
||||||
CHECK(j.type() == json::value_t::null);
|
CHECK(j.type() == json::value_t::null);
|
||||||
CHECK(it == j.end());
|
CHECK(it == j.end());
|
||||||
|
@ -21,14 +21,8 @@ TEST_CASE_TEMPLATE("element access 2", Json, nlohmann::json, nlohmann::ordered_j
|
|||||||
{
|
{
|
||||||
SECTION("object")
|
SECTION("object")
|
||||||
{
|
{
|
||||||
Json j = {{"integer", 1},
|
Json j = { { "integer", 1 }, { "unsigned", 1u }, { "floating", 42.23 }, { "null", nullptr }, { "string", "hello world" },
|
||||||
{"unsigned", 1u},
|
{ "boolean", true }, { "object", Json::object() }, { "array", { 1, 2, 3 } } };
|
||||||
{"floating", 42.23},
|
|
||||||
{"null", nullptr},
|
|
||||||
{"string", "hello world"},
|
|
||||||
{"boolean", true},
|
|
||||||
{"object", Json::object()},
|
|
||||||
{"array", {1, 2, 3}}};
|
|
||||||
const Json j_const = j;
|
const Json j_const = j;
|
||||||
|
|
||||||
SECTION("access specified element with bounds checking")
|
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("string") == Json("hello world"));
|
||||||
CHECK(j.at("floating") == Json(42.23));
|
CHECK(j.at("floating") == Json(42.23));
|
||||||
CHECK(j.at("object") == Json::object());
|
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("integer") == Json(1));
|
||||||
CHECK(j_const.at("unsigned") == Json(1u));
|
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("string") == Json("hello world"));
|
||||||
CHECK(j_const.at("floating") == Json(42.23));
|
CHECK(j_const.at("floating") == Json(42.23));
|
||||||
CHECK(j_const.at("object") == Json::object());
|
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
|
#ifdef JSON_HAS_CPP_17
|
||||||
CHECK(j.at(std::string_view("integer")) == Json(1));
|
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("string")) == Json("hello world"));
|
||||||
CHECK(j.at(std::string_view("floating")) == Json(42.23));
|
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("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("integer")) == Json(1));
|
||||||
CHECK(j_const.at(std::string_view("unsigned")) == Json(1u));
|
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("string")) == Json("hello world"));
|
||||||
CHECK(j_const.at(std::string_view("floating")) == Json(42.23));
|
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("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
|
#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("string", std::string("bar")) == "hello world");
|
||||||
CHECK(j.value("floating", 12.34) == Approx(42.23));
|
CHECK(j.value("floating", 12.34) == Approx(42.23));
|
||||||
CHECK(j.value("floating", 12) == 42);
|
CHECK(j.value("floating", 12) == 42);
|
||||||
CHECK(j.value("object", Json({{"foo", "bar"}})) == Json::object());
|
CHECK(j.value("object", Json({ { "foo", "bar" } })) == Json::object());
|
||||||
CHECK(j.value("array", Json({10, 100})) == Json({1, 2, 3}));
|
CHECK(j.value("array", Json({ 10, 100 })) == Json({ 1, 2, 3 }));
|
||||||
|
|
||||||
CHECK(j_const.value("integer", 2) == 1);
|
CHECK(j_const.value("integer", 2) == 1);
|
||||||
CHECK(j_const.value("integer", 1.0) == Approx(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("string", std::string("bar")) == "hello world");
|
||||||
CHECK(j_const.value("floating", 12.34) == Approx(42.23));
|
CHECK(j_const.value("floating", 12.34) == Approx(42.23));
|
||||||
CHECK(j_const.value("floating", 12) == 42);
|
CHECK(j_const.value("floating", 12) == 42);
|
||||||
CHECK(j_const.value("object", Json({{"foo", "bar"}})) == Json::object());
|
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("array", Json({ 10, 100 })) == Json({ 1, 2, 3 }));
|
||||||
|
|
||||||
#ifdef JSON_HAS_CPP_17
|
#ifdef JSON_HAS_CPP_17
|
||||||
CHECK(j.value(std::string_view("integer"), 2) == 1);
|
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("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.34) == Approx(42.23));
|
||||||
CHECK(j.value(std::string_view("floating"), 12) == 42);
|
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("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("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"), 2) == 1);
|
||||||
CHECK(j_const.value(std::string_view("integer"), 1.0) == Approx(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("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.34) == Approx(42.23));
|
||||||
CHECK(j_const.value(std::string_view("floating"), 12) == 42);
|
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("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("array"), Json({ 10, 100 })) == Json({ 1, 2, 3 }));
|
||||||
#endif
|
#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("_", false) == false);
|
||||||
CHECK(j.value("_", "bar") == "bar");
|
CHECK(j.value("_", "bar") == "bar");
|
||||||
CHECK(j.value("_", 12.34) == Approx(12.34));
|
CHECK(j.value("_", 12.34) == Approx(12.34));
|
||||||
CHECK(j.value("_", Json({{"foo", "bar"}})) == Json({{"foo", "bar"}}));
|
CHECK(j.value("_", Json({ { "foo", "bar" } })) == Json({ { "foo", "bar" } }));
|
||||||
CHECK(j.value("_", Json({10, 100})) == Json({10, 100}));
|
CHECK(j.value("_", Json({ 10, 100 })) == Json({ 10, 100 }));
|
||||||
|
|
||||||
CHECK(j_const.value("_", 2) == 2);
|
CHECK(j_const.value("_", 2) == 2);
|
||||||
CHECK(j_const.value("_", 2u) == 2u);
|
CHECK(j_const.value("_", 2u) == 2u);
|
||||||
CHECK(j_const.value("_", false) == false);
|
CHECK(j_const.value("_", false) == false);
|
||||||
CHECK(j_const.value("_", "bar") == "bar");
|
CHECK(j_const.value("_", "bar") == "bar");
|
||||||
CHECK(j_const.value("_", 12.34) == Approx(12.34));
|
CHECK(j_const.value("_", 12.34) == Approx(12.34));
|
||||||
CHECK(j_const.value("_", Json({{"foo", "bar"}})) == Json({{"foo", "bar"}}));
|
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({ 10, 100 })) == Json({ 10, 100 }));
|
||||||
|
|
||||||
#ifdef JSON_HAS_CPP_17
|
#ifdef JSON_HAS_CPP_17
|
||||||
CHECK(j.value(std::string_view("_"), 2) == 2);
|
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("_"), false) == false);
|
||||||
CHECK(j.value(std::string_view("_"), "bar") == "bar");
|
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("_"), 12.34) == Approx(12.34));
|
||||||
CHECK(j.value(std::string_view("_"), Json({{"foo", "bar"}})) == Json({{"foo", "bar"}}));
|
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({ 10, 100 })) == Json({ 10, 100 }));
|
||||||
|
|
||||||
CHECK(j_const.value(std::string_view("_"), 2) == 2);
|
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("_"), 2u) == 2u);
|
||||||
CHECK(j_const.value(std::string_view("_"), false) == false);
|
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("_"), "bar") == "bar");
|
||||||
CHECK(j_const.value(std::string_view("_"), 12.34) == Approx(12.34));
|
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({ { "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({ 10, 100 })) == Json({ 10, 100 }));
|
||||||
#endif
|
#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("/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.34) == Approx(42.23));
|
||||||
CHECK(j.value("/floating"_json_pointer, 12) == 42);
|
CHECK(j.value("/floating"_json_pointer, 12) == 42);
|
||||||
CHECK(j.value("/object"_json_pointer, Json({{"foo", "bar"}})) == Json::object());
|
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("/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, 2) == 1);
|
||||||
CHECK(j_const.value("/integer"_json_pointer, 1.0) == Approx(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("/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.34) == Approx(42.23));
|
||||||
CHECK(j_const.value("/floating"_json_pointer, 12) == 42);
|
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("/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("/array"_json_pointer, Json({ 10, 100 })) == Json({ 1, 2, 3 }));
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("access on non-object type")
|
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());
|
CHECK(j_null.is_null());
|
||||||
j_null["key"] = 1;
|
j_null["key"] = 1;
|
||||||
CHECK(j_null.is_object());
|
CHECK(j_null.is_object());
|
||||||
@ -616,14 +610,14 @@ SECTION("front and back")
|
|||||||
CHECK(j.front() == Json(1));
|
CHECK(j.front() == Json(1));
|
||||||
CHECK(j_const.front() == Json(1));
|
CHECK(j_const.front() == Json(1));
|
||||||
// "array" is last key
|
// "array" is last key
|
||||||
CHECK(j.back() == Json({1, 2, 3}));
|
CHECK(j.back() == Json({ 1, 2, 3 }));
|
||||||
CHECK(j_const.back() == Json({1, 2, 3}));
|
CHECK(j_const.back() == Json({ 1, 2, 3 }));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// "array" is the smallest key
|
// "array" is the smallest key
|
||||||
CHECK(j.front() == Json({1, 2, 3}));
|
CHECK(j.front() == Json({ 1, 2, 3 }));
|
||||||
CHECK(j_const.front() == Json({1, 2, 3}));
|
CHECK(j_const.front() == Json({ 1, 2, 3 }));
|
||||||
// "unsigned" is the largest key
|
// "unsigned" is the largest key
|
||||||
CHECK(j.back() == Json(1u));
|
CHECK(j.back() == Json(1u));
|
||||||
CHECK(j_const.back() == Json(1u));
|
CHECK(j_const.back() == Json(1u));
|
||||||
@ -655,7 +649,7 @@ SECTION("access specified element")
|
|||||||
CHECK(j["object"] == Json::object());
|
CHECK(j["object"] == Json::object());
|
||||||
CHECK(j[typename Json::object_t::key_type("object")] == j["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[typename Json::object_t::key_type("array")] == j["array"]);
|
||||||
|
|
||||||
CHECK(j_const["integer"] == Json(1));
|
CHECK(j_const["integer"] == Json(1));
|
||||||
@ -676,7 +670,7 @@ SECTION("access specified element")
|
|||||||
CHECK(j_const["object"] == Json::object());
|
CHECK(j_const["object"] == Json::object());
|
||||||
CHECK(j_const[typename Json::object_t::key_type("object")] == j["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"]);
|
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["object"] == Json::object());
|
||||||
CHECK(j[std::string_view("object")] == j["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[std::string_view("array")] == j["array"]);
|
||||||
|
|
||||||
CHECK(j_const["integer"] == Json(1));
|
CHECK(j_const["integer"] == Json(1));
|
||||||
@ -725,7 +719,7 @@ SECTION("access specified element")
|
|||||||
CHECK(j_const["object"] == Json::object());
|
CHECK(j_const["object"] == Json::object());
|
||||||
CHECK(j_const[std::string_view("object")] == j["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"]);
|
CHECK(j_const[std::string_view("array")] == j["array"]);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -1014,15 +1008,15 @@ SECTION("remove specified element")
|
|||||||
SECTION("erase(begin())")
|
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());
|
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));
|
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());
|
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));
|
CHECK(*it2 == Json(1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1030,13 +1024,13 @@ SECTION("remove specified element")
|
|||||||
SECTION("erase(begin(), end())")
|
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());
|
typename Json::iterator it2 = jobject.erase(jobject.begin(), jobject.end());
|
||||||
CHECK(jobject == Json::object());
|
CHECK(jobject == Json::object());
|
||||||
CHECK(it2 == jobject.end());
|
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());
|
typename Json::const_iterator it2 = jobject.erase(jobject.cbegin(), jobject.cend());
|
||||||
CHECK(jobject == Json::object());
|
CHECK(jobject == Json::object());
|
||||||
CHECK(it2 == jobject.cend());
|
CHECK(it2 == jobject.cend());
|
||||||
@ -1046,15 +1040,15 @@ SECTION("remove specified element")
|
|||||||
SECTION("erase(begin(), begin())")
|
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());
|
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"));
|
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());
|
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"));
|
CHECK(*it2 == Json("a"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1062,17 +1056,17 @@ SECTION("remove specified element")
|
|||||||
SECTION("erase at offset")
|
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 it = jobject.find("b");
|
||||||
typename Json::iterator const it2 = jobject.erase(it);
|
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));
|
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 it = jobject.find("b");
|
||||||
typename Json::const_iterator const it2 = jobject.erase(it);
|
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));
|
CHECK(*it2 == Json(17));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1080,15 +1074,15 @@ SECTION("remove specified element")
|
|||||||
SECTION("erase subrange")
|
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"));
|
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));
|
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"));
|
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));
|
CHECK(*it2 == Json(true));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1096,8 +1090,8 @@ SECTION("remove specified element")
|
|||||||
SECTION("different objects")
|
SECTION("different objects")
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
Json jobject = {{"a", "a"}, {"b", 1}, {"c", 17u}, {"d", false}, {"e", true}};
|
Json jobject = { { "a", "a" }, { "b", 1 }, { "c", 17u }, { "d", false }, { "e", true } };
|
||||||
Json jobject2 = {{"a", "a"}, {"b", 1}, {"c", 17u}};
|
Json jobject2 = { { "a", "a" }, { "b", 1 }, { "c", 17u } };
|
||||||
CHECK_THROWS_WITH_AS(jobject.erase(jobject2.begin()),
|
CHECK_THROWS_WITH_AS(jobject.erase(jobject2.begin()),
|
||||||
"[json.exception.invalid_iterator.202] iterator does not fit current value",
|
"[json.exception.invalid_iterator.202] iterator does not fit current value",
|
||||||
typename Json::invalid_iterator&);
|
typename Json::invalid_iterator&);
|
||||||
@ -1112,8 +1106,8 @@ SECTION("remove specified element")
|
|||||||
typename Json::invalid_iterator&);
|
typename Json::invalid_iterator&);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
Json jobject = {{"a", "a"}, {"b", 1}, {"c", 17u}, {"d", false}, {"e", true}};
|
Json jobject = { { "a", "a" }, { "b", 1 }, { "c", 17u }, { "d", false }, { "e", true } };
|
||||||
Json jobject2 = {{"a", "a"}, {"b", 1}, {"c", 17u}};
|
Json jobject2 = { { "a", "a" }, { "b", 1 }, { "c", 17u } };
|
||||||
CHECK_THROWS_WITH_AS(jobject.erase(jobject2.cbegin()),
|
CHECK_THROWS_WITH_AS(jobject.erase(jobject2.cbegin()),
|
||||||
"[json.exception.invalid_iterator.202] iterator does not fit current value",
|
"[json.exception.invalid_iterator.202] iterator does not fit current value",
|
||||||
typename Json::invalid_iterator&);
|
typename Json::invalid_iterator&);
|
||||||
@ -1210,7 +1204,7 @@ SECTION("find an element in an object")
|
|||||||
{
|
{
|
||||||
SECTION("existing element")
|
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.end());
|
||||||
CHECK(*j.find(key) == j.at(key));
|
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));
|
CHECK(*j_const.find(key) == j_const.at(key));
|
||||||
}
|
}
|
||||||
#ifdef JSON_HAS_CPP_17
|
#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.end());
|
||||||
CHECK(*j.find(key) == j.at(key));
|
CHECK(*j.find(key) == j.at(key));
|
||||||
@ -1359,13 +1353,13 @@ SECTION("count keys in an object")
|
|||||||
{
|
{
|
||||||
SECTION("existing element")
|
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.count(key) == 1);
|
||||||
CHECK(j_const.count(key) == 1);
|
CHECK(j_const.count(key) == 1);
|
||||||
}
|
}
|
||||||
#ifdef JSON_HAS_CPP_17
|
#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.count(key) == 1);
|
||||||
CHECK(j_const.count(key) == 1);
|
CHECK(j_const.count(key) == 1);
|
||||||
@ -1504,14 +1498,14 @@ SECTION("check existence of key in an object")
|
|||||||
{
|
{
|
||||||
SECTION("existing element")
|
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.contains(key) == true);
|
||||||
CHECK(j_const.contains(key) == true);
|
CHECK(j_const.contains(key) == true);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef JSON_HAS_CPP_17
|
#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.contains(key) == true);
|
||||||
CHECK(j_const.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")
|
SECTION("object")
|
||||||
{
|
{
|
||||||
Json j = {{"integer", 1},
|
Json j = { { "integer", 1 }, { "unsigned", 1u }, { "floating", 42.23 }, { "null", nullptr }, { "string", "hello world" },
|
||||||
{"unsigned", 1u},
|
{ "boolean", true }, { "object", Json::object() }, { "array", { 1, 2, 3 } } };
|
||||||
{"floating", 42.23},
|
const Json j_const = { { "integer", 1 }, { "unsigned", 1u }, { "floating", 42.23 }, { "null", nullptr }, { "string", "hello world" },
|
||||||
{"null", nullptr},
|
{ "boolean", true }, { "object", Json::object() }, { "array", { 1, 2, 3 } } };
|
||||||
{"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")
|
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, false) == false);
|
||||||
CHECK(j.value("/not/existing"_json_pointer, "bar") == "bar");
|
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, 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({ { "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({ 10, 100 })) == Json({ 10, 100 }));
|
||||||
|
|
||||||
CHECK(j_const.value("/not/existing"_json_pointer, 2) == 2);
|
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, 2u) == 2u);
|
||||||
CHECK(j_const.value("/not/existing"_json_pointer, false) == false);
|
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, "bar") == "bar");
|
||||||
CHECK(j_const.value("/not/existing"_json_pointer, 12.34) == Approx(12.34));
|
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({ { "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({ 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
|
// 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);
|
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* cpstr = "default";
|
||||||
const char castr[] = "default"; // NOLINT(hicpp-avoid-c-arrays,modernize-avoid-c-arrays,cppcoreguidelines-avoid-c-arrays)
|
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;
|
number_integer_t integer = 69;
|
||||||
std::size_t size = 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", cpstr) == "bar");
|
||||||
CHECK(j.value("foo", castr) == "bar");
|
CHECK(j.value("foo", castr) == "bar");
|
||||||
CHECK(j.value("foo", str) == "bar");
|
CHECK(j.value("foo", str) == "bar");
|
||||||
|
@ -43,19 +43,19 @@ TEST_CASE("hash<nlohmann::json>")
|
|||||||
|
|
||||||
// array
|
// array
|
||||||
hashes.insert(std::hash<json>{}(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
|
// object
|
||||||
hashes.insert(std::hash<json>{}(json::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
|
// binary
|
||||||
hashes.insert(std::hash<json>{}(json::binary({})));
|
hashes.insert(std::hash<json>{}(json::binary({})));
|
||||||
hashes.insert(std::hash<json>{}(json::binary({}, 0)));
|
hashes.insert(std::hash<json>{}(json::binary({}, 0)));
|
||||||
hashes.insert(std::hash<json>{}(json::binary({}, 42)));
|
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 })));
|
||||||
hashes.insert(std::hash<json>{}(json::binary({1, 2, 3}, 0)));
|
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 }, 42)));
|
||||||
|
|
||||||
// discarded
|
// discarded
|
||||||
hashes.insert(std::hash<json>{}(json(json::value_t::discarded)));
|
hashes.insert(std::hash<json>{}(json(json::value_t::discarded)));
|
||||||
@ -92,19 +92,19 @@ TEST_CASE("hash<nlohmann::ordered_json>")
|
|||||||
|
|
||||||
// array
|
// array
|
||||||
hashes.insert(std::hash<ordered_json>{}(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
|
// object
|
||||||
hashes.insert(std::hash<ordered_json>{}(ordered_json::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
|
// binary
|
||||||
hashes.insert(std::hash<ordered_json>{}(ordered_json::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({}, 0)));
|
||||||
hashes.insert(std::hash<ordered_json>{}(ordered_json::binary({}, 42)));
|
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 })));
|
||||||
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 }, 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 }, 42)));
|
||||||
|
|
||||||
// discarded
|
// discarded
|
||||||
hashes.insert(std::hash<ordered_json>{}(ordered_json(ordered_json::value_t::discarded)));
|
hashes.insert(std::hash<ordered_json>{}(ordered_json(ordered_json::value_t::discarded)));
|
||||||
|
@ -21,7 +21,7 @@ TEST_CASE("object inspection")
|
|||||||
{
|
{
|
||||||
SECTION("object")
|
SECTION("object")
|
||||||
{
|
{
|
||||||
json const j{{"foo", 1}, {"bar", false}};
|
json const j{ { "foo", 1 }, { "bar", false } };
|
||||||
CHECK(!j.is_null());
|
CHECK(!j.is_null());
|
||||||
CHECK(!j.is_boolean());
|
CHECK(!j.is_boolean());
|
||||||
CHECK(!j.is_number());
|
CHECK(!j.is_number());
|
||||||
@ -39,7 +39,7 @@ TEST_CASE("object inspection")
|
|||||||
|
|
||||||
SECTION("array")
|
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_null());
|
||||||
CHECK(!j.is_boolean());
|
CHECK(!j.is_boolean());
|
||||||
CHECK(!j.is_number());
|
CHECK(!j.is_number());
|
||||||
@ -202,7 +202,8 @@ TEST_CASE("object inspection")
|
|||||||
|
|
||||||
SECTION("serialization")
|
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")
|
SECTION("no indent / indent=-1")
|
||||||
{
|
{
|
||||||
@ -242,7 +243,7 @@ TEST_CASE("object inspection")
|
|||||||
// inside the dump() function
|
// inside the dump() function
|
||||||
CHECK(j.dump(1024).size() == 15472);
|
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);
|
CHECK(binary.dump(1024).size() == 2086);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -328,7 +329,7 @@ TEST_CASE("object inspection")
|
|||||||
|
|
||||||
SECTION("round trips")
|
SECTION("round trips")
|
||||||
{
|
{
|
||||||
for (const auto& s : {"3.141592653589793", "1000000000000000010E5"})
|
for (const auto& s : { "3.141592653589793", "1000000000000000010E5" })
|
||||||
{
|
{
|
||||||
json const j1 = json::parse(s);
|
json const j1 = json::parse(s);
|
||||||
std::string s1 = j1.dump();
|
std::string s1 = j1.dump();
|
||||||
@ -348,13 +349,13 @@ TEST_CASE("object inspection")
|
|||||||
|
|
||||||
SECTION("object")
|
SECTION("object")
|
||||||
{
|
{
|
||||||
json const j = {{"foo", "bar"}};
|
json const j = { { "foo", "bar" } };
|
||||||
CHECK(j.type() == json::value_t::object);
|
CHECK(j.type() == json::value_t::object);
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("array")
|
SECTION("array")
|
||||||
{
|
{
|
||||||
json const j = {1, 2, 3, 4};
|
json const j = { 1, 2, 3, 4 };
|
||||||
CHECK(j.type() == json::value_t::array);
|
CHECK(j.type() == json::value_t::array);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -400,14 +401,14 @@ TEST_CASE("object inspection")
|
|||||||
|
|
||||||
SECTION("object")
|
SECTION("object")
|
||||||
{
|
{
|
||||||
json const j = {{"foo", "bar"}};
|
json const j = { { "foo", "bar" } };
|
||||||
json::value_t t = j;
|
json::value_t t = j;
|
||||||
CHECK(t == j.type());
|
CHECK(t == j.type());
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("array")
|
SECTION("array")
|
||||||
{
|
{
|
||||||
json const j = {1, 2, 3, 4};
|
json const j = { 1, 2, 3, 4 };
|
||||||
json::value_t t = j;
|
json::value_t t = j;
|
||||||
CHECK(t == j.type());
|
CHECK(t == j.type());
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,7 @@ TEST_CASE("iterator_wrapper")
|
|||||||
{
|
{
|
||||||
SECTION("value")
|
SECTION("value")
|
||||||
{
|
{
|
||||||
json j = {{"A", 1}, {"B", 2}};
|
json j = { { "A", 1 }, { "B", 2 } };
|
||||||
int counter = 1;
|
int counter = 1;
|
||||||
|
|
||||||
for (auto i : json::iterator_wrapper(j)) // NOLINT(performance-for-range-copy)
|
for (auto i : json::iterator_wrapper(j)) // NOLINT(performance-for-range-copy)
|
||||||
@ -58,7 +58,7 @@ TEST_CASE("iterator_wrapper")
|
|||||||
|
|
||||||
SECTION("reference")
|
SECTION("reference")
|
||||||
{
|
{
|
||||||
json j = {{"A", 1}, {"B", 2}};
|
json j = { { "A", 1 }, { "B", 2 } };
|
||||||
int counter = 1;
|
int counter = 1;
|
||||||
|
|
||||||
for (auto& i : json::iterator_wrapper(j)) // NOLINT(readability-qualified-auto)
|
for (auto& i : json::iterator_wrapper(j)) // NOLINT(readability-qualified-auto)
|
||||||
@ -97,12 +97,12 @@ TEST_CASE("iterator_wrapper")
|
|||||||
CHECK(counter == 3);
|
CHECK(counter == 3);
|
||||||
|
|
||||||
// check if values where changed
|
// check if values where changed
|
||||||
CHECK(j == json({{"A", 11}, {"B", 22}}));
|
CHECK(j == json({ { "A", 11 }, { "B", 22 } }));
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("const value")
|
SECTION("const value")
|
||||||
{
|
{
|
||||||
json j = {{"A", 1}, {"B", 2}};
|
json j = { { "A", 1 }, { "B", 2 } };
|
||||||
int counter = 1;
|
int counter = 1;
|
||||||
|
|
||||||
for (const auto i : json::iterator_wrapper(j)) // NOLINT(performance-for-range-copy)
|
for (const auto i : json::iterator_wrapper(j)) // NOLINT(performance-for-range-copy)
|
||||||
@ -135,7 +135,7 @@ TEST_CASE("iterator_wrapper")
|
|||||||
|
|
||||||
SECTION("const reference")
|
SECTION("const reference")
|
||||||
{
|
{
|
||||||
json j = {{"A", 1}, {"B", 2}};
|
json j = { { "A", 1 }, { "B", 2 } };
|
||||||
int counter = 1;
|
int counter = 1;
|
||||||
|
|
||||||
for (const auto& i : json::iterator_wrapper(j))
|
for (const auto& i : json::iterator_wrapper(j))
|
||||||
@ -171,7 +171,7 @@ TEST_CASE("iterator_wrapper")
|
|||||||
{
|
{
|
||||||
SECTION("value")
|
SECTION("value")
|
||||||
{
|
{
|
||||||
const json j = {{"A", 1}, {"B", 2}};
|
const json j = { { "A", 1 }, { "B", 2 } };
|
||||||
int counter = 1;
|
int counter = 1;
|
||||||
|
|
||||||
for (auto i : json::iterator_wrapper(j)) // NOLINT(performance-for-range-copy)
|
for (auto i : json::iterator_wrapper(j)) // NOLINT(performance-for-range-copy)
|
||||||
@ -204,7 +204,7 @@ TEST_CASE("iterator_wrapper")
|
|||||||
|
|
||||||
SECTION("reference")
|
SECTION("reference")
|
||||||
{
|
{
|
||||||
const json j = {{"A", 1}, {"B", 2}};
|
const json j = { { "A", 1 }, { "B", 2 } };
|
||||||
int counter = 1;
|
int counter = 1;
|
||||||
|
|
||||||
for (auto& i : json::iterator_wrapper(j)) // NOLINT(readability-qualified-auto)
|
for (auto& i : json::iterator_wrapper(j)) // NOLINT(readability-qualified-auto)
|
||||||
@ -237,7 +237,7 @@ TEST_CASE("iterator_wrapper")
|
|||||||
|
|
||||||
SECTION("const value")
|
SECTION("const value")
|
||||||
{
|
{
|
||||||
const json j = {{"A", 1}, {"B", 2}};
|
const json j = { { "A", 1 }, { "B", 2 } };
|
||||||
int counter = 1;
|
int counter = 1;
|
||||||
|
|
||||||
for (const auto i : json::iterator_wrapper(j)) // NOLINT(performance-for-range-copy)
|
for (const auto i : json::iterator_wrapper(j)) // NOLINT(performance-for-range-copy)
|
||||||
@ -270,7 +270,7 @@ TEST_CASE("iterator_wrapper")
|
|||||||
|
|
||||||
SECTION("const reference")
|
SECTION("const reference")
|
||||||
{
|
{
|
||||||
const json j = {{"A", 1}, {"B", 2}};
|
const json j = { { "A", 1 }, { "B", 2 } };
|
||||||
int counter = 1;
|
int counter = 1;
|
||||||
|
|
||||||
for (const auto& i : json::iterator_wrapper(j))
|
for (const auto& i : json::iterator_wrapper(j))
|
||||||
@ -306,7 +306,7 @@ TEST_CASE("iterator_wrapper")
|
|||||||
{
|
{
|
||||||
SECTION("value")
|
SECTION("value")
|
||||||
{
|
{
|
||||||
json j = {"A", "B"};
|
json j = { "A", "B" };
|
||||||
int counter = 1;
|
int counter = 1;
|
||||||
|
|
||||||
for (auto i : json::iterator_wrapper(j)) // NOLINT(performance-for-range-copy)
|
for (auto i : json::iterator_wrapper(j)) // NOLINT(performance-for-range-copy)
|
||||||
@ -339,7 +339,7 @@ TEST_CASE("iterator_wrapper")
|
|||||||
|
|
||||||
SECTION("reference")
|
SECTION("reference")
|
||||||
{
|
{
|
||||||
json j = {"A", "B"};
|
json j = { "A", "B" };
|
||||||
int counter = 1;
|
int counter = 1;
|
||||||
|
|
||||||
for (auto& i : json::iterator_wrapper(j)) // NOLINT(readability-qualified-auto)
|
for (auto& i : json::iterator_wrapper(j)) // NOLINT(readability-qualified-auto)
|
||||||
@ -378,12 +378,12 @@ TEST_CASE("iterator_wrapper")
|
|||||||
CHECK(counter == 3);
|
CHECK(counter == 3);
|
||||||
|
|
||||||
// check if values where changed
|
// check if values where changed
|
||||||
CHECK(j == json({"AA", "BB"}));
|
CHECK(j == json({ "AA", "BB" }));
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("const value")
|
SECTION("const value")
|
||||||
{
|
{
|
||||||
json j = {"A", "B"};
|
json j = { "A", "B" };
|
||||||
int counter = 1;
|
int counter = 1;
|
||||||
|
|
||||||
for (const auto i : json::iterator_wrapper(j)) // NOLINT(performance-for-range-copy)
|
for (const auto i : json::iterator_wrapper(j)) // NOLINT(performance-for-range-copy)
|
||||||
@ -416,7 +416,7 @@ TEST_CASE("iterator_wrapper")
|
|||||||
|
|
||||||
SECTION("const reference")
|
SECTION("const reference")
|
||||||
{
|
{
|
||||||
json j = {"A", "B"};
|
json j = { "A", "B" };
|
||||||
int counter = 1;
|
int counter = 1;
|
||||||
|
|
||||||
for (const auto& i : json::iterator_wrapper(j))
|
for (const auto& i : json::iterator_wrapper(j))
|
||||||
@ -452,7 +452,7 @@ TEST_CASE("iterator_wrapper")
|
|||||||
{
|
{
|
||||||
SECTION("value")
|
SECTION("value")
|
||||||
{
|
{
|
||||||
const json j = {"A", "B"};
|
const json j = { "A", "B" };
|
||||||
int counter = 1;
|
int counter = 1;
|
||||||
|
|
||||||
for (auto i : json::iterator_wrapper(j)) // NOLINT(performance-for-range-copy)
|
for (auto i : json::iterator_wrapper(j)) // NOLINT(performance-for-range-copy)
|
||||||
@ -485,7 +485,7 @@ TEST_CASE("iterator_wrapper")
|
|||||||
|
|
||||||
SECTION("reference")
|
SECTION("reference")
|
||||||
{
|
{
|
||||||
const json j = {"A", "B"};
|
const json j = { "A", "B" };
|
||||||
int counter = 1;
|
int counter = 1;
|
||||||
|
|
||||||
for (auto& i : json::iterator_wrapper(j)) // NOLINT(readability-qualified-auto)
|
for (auto& i : json::iterator_wrapper(j)) // NOLINT(readability-qualified-auto)
|
||||||
@ -518,7 +518,7 @@ TEST_CASE("iterator_wrapper")
|
|||||||
|
|
||||||
SECTION("const value")
|
SECTION("const value")
|
||||||
{
|
{
|
||||||
const json j = {"A", "B"};
|
const json j = { "A", "B" };
|
||||||
int counter = 1;
|
int counter = 1;
|
||||||
|
|
||||||
for (const auto i : json::iterator_wrapper(j)) // NOLINT(performance-for-range-copy)
|
for (const auto i : json::iterator_wrapper(j)) // NOLINT(performance-for-range-copy)
|
||||||
@ -551,7 +551,7 @@ TEST_CASE("iterator_wrapper")
|
|||||||
|
|
||||||
SECTION("const reference")
|
SECTION("const reference")
|
||||||
{
|
{
|
||||||
const json j = {"A", "B"};
|
const json j = { "A", "B" };
|
||||||
int counter = 1;
|
int counter = 1;
|
||||||
|
|
||||||
for (const auto& i : json::iterator_wrapper(j))
|
for (const auto& i : json::iterator_wrapper(j))
|
||||||
@ -718,7 +718,7 @@ TEST_CASE("iterator_wrapper")
|
|||||||
|
|
||||||
TEST_CASE("items()")
|
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;
|
int counter = 1;
|
||||||
|
|
||||||
for (auto i : j.items()) // NOLINT(performance-for-range-copy)
|
for (auto i : j.items()) // NOLINT(performance-for-range-copy)
|
||||||
@ -751,7 +751,7 @@ TEST_CASE("items()")
|
|||||||
|
|
||||||
SECTION("reference")
|
SECTION("reference")
|
||||||
{
|
{
|
||||||
json j = {{"A", 1}, {"B", 2}};
|
json j = { { "A", 1 }, { "B", 2 } };
|
||||||
int counter = 1;
|
int counter = 1;
|
||||||
|
|
||||||
for (auto& i : j.items()) // NOLINT(readability-qualified-auto)
|
for (auto& i : j.items()) // NOLINT(readability-qualified-auto)
|
||||||
@ -790,12 +790,12 @@ SECTION("reference")
|
|||||||
CHECK(counter == 3);
|
CHECK(counter == 3);
|
||||||
|
|
||||||
// check if values where changed
|
// check if values where changed
|
||||||
CHECK(j == json({{"A", 11}, {"B", 22}}));
|
CHECK(j == json({ { "A", 11 }, { "B", 22 } }));
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("const value")
|
SECTION("const value")
|
||||||
{
|
{
|
||||||
json j = {{"A", 1}, {"B", 2}};
|
json j = { { "A", 1 }, { "B", 2 } };
|
||||||
int counter = 1;
|
int counter = 1;
|
||||||
|
|
||||||
for (const auto i : j.items()) // NOLINT(performance-for-range-copy)
|
for (const auto i : j.items()) // NOLINT(performance-for-range-copy)
|
||||||
@ -828,7 +828,7 @@ SECTION("const value")
|
|||||||
|
|
||||||
SECTION("const reference")
|
SECTION("const reference")
|
||||||
{
|
{
|
||||||
json j = {{"A", 1}, {"B", 2}};
|
json j = { { "A", 1 }, { "B", 2 } };
|
||||||
int counter = 1;
|
int counter = 1;
|
||||||
|
|
||||||
for (const auto& i : j.items())
|
for (const auto& i : j.items())
|
||||||
@ -862,7 +862,7 @@ SECTION("const reference")
|
|||||||
#ifdef JSON_HAS_CPP_17
|
#ifdef JSON_HAS_CPP_17
|
||||||
SECTION("structured bindings")
|
SECTION("structured bindings")
|
||||||
{
|
{
|
||||||
json j = {{"A", 1}, {"B", 2}};
|
json j = { { "A", 1 }, { "B", 2 } };
|
||||||
|
|
||||||
std::map<std::string, int> m;
|
std::map<std::string, int> m;
|
||||||
|
|
||||||
@ -880,7 +880,7 @@ SECTION("const object")
|
|||||||
{
|
{
|
||||||
SECTION("value")
|
SECTION("value")
|
||||||
{
|
{
|
||||||
const json j = {{"A", 1}, {"B", 2}};
|
const json j = { { "A", 1 }, { "B", 2 } };
|
||||||
int counter = 1;
|
int counter = 1;
|
||||||
|
|
||||||
for (auto i : j.items()) // NOLINT(performance-for-range-copy)
|
for (auto i : j.items()) // NOLINT(performance-for-range-copy)
|
||||||
@ -913,7 +913,7 @@ SECTION("const object")
|
|||||||
|
|
||||||
SECTION("reference")
|
SECTION("reference")
|
||||||
{
|
{
|
||||||
const json j = {{"A", 1}, {"B", 2}};
|
const json j = { { "A", 1 }, { "B", 2 } };
|
||||||
int counter = 1;
|
int counter = 1;
|
||||||
|
|
||||||
for (auto& i : j.items()) // NOLINT(readability-qualified-auto)
|
for (auto& i : j.items()) // NOLINT(readability-qualified-auto)
|
||||||
@ -946,7 +946,7 @@ SECTION("const object")
|
|||||||
|
|
||||||
SECTION("const value")
|
SECTION("const value")
|
||||||
{
|
{
|
||||||
const json j = {{"A", 1}, {"B", 2}};
|
const json j = { { "A", 1 }, { "B", 2 } };
|
||||||
int counter = 1;
|
int counter = 1;
|
||||||
|
|
||||||
for (const auto i : j.items()) // NOLINT(performance-for-range-copy)
|
for (const auto i : j.items()) // NOLINT(performance-for-range-copy)
|
||||||
@ -979,7 +979,7 @@ SECTION("const object")
|
|||||||
|
|
||||||
SECTION("const reference")
|
SECTION("const reference")
|
||||||
{
|
{
|
||||||
const json j = {{"A", 1}, {"B", 2}};
|
const json j = { { "A", 1 }, { "B", 2 } };
|
||||||
int counter = 1;
|
int counter = 1;
|
||||||
|
|
||||||
for (const auto& i : j.items())
|
for (const auto& i : j.items())
|
||||||
@ -1015,7 +1015,7 @@ SECTION("array")
|
|||||||
{
|
{
|
||||||
SECTION("value")
|
SECTION("value")
|
||||||
{
|
{
|
||||||
json j = {"A", "B"};
|
json j = { "A", "B" };
|
||||||
int counter = 1;
|
int counter = 1;
|
||||||
|
|
||||||
for (auto i : j.items()) // NOLINT(performance-for-range-copy)
|
for (auto i : j.items()) // NOLINT(performance-for-range-copy)
|
||||||
@ -1048,7 +1048,7 @@ SECTION("array")
|
|||||||
|
|
||||||
SECTION("reference")
|
SECTION("reference")
|
||||||
{
|
{
|
||||||
json j = {"A", "B"};
|
json j = { "A", "B" };
|
||||||
int counter = 1;
|
int counter = 1;
|
||||||
|
|
||||||
for (auto& i : j.items()) // NOLINT(readability-qualified-auto)
|
for (auto& i : j.items()) // NOLINT(readability-qualified-auto)
|
||||||
@ -1087,12 +1087,12 @@ SECTION("array")
|
|||||||
CHECK(counter == 3);
|
CHECK(counter == 3);
|
||||||
|
|
||||||
// check if values where changed
|
// check if values where changed
|
||||||
CHECK(j == json({"AA", "BB"}));
|
CHECK(j == json({ "AA", "BB" }));
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("const value")
|
SECTION("const value")
|
||||||
{
|
{
|
||||||
json j = {"A", "B"};
|
json j = { "A", "B" };
|
||||||
int counter = 1;
|
int counter = 1;
|
||||||
|
|
||||||
for (const auto i : j.items()) // NOLINT(performance-for-range-copy)
|
for (const auto i : j.items()) // NOLINT(performance-for-range-copy)
|
||||||
@ -1125,7 +1125,7 @@ SECTION("array")
|
|||||||
|
|
||||||
SECTION("const reference")
|
SECTION("const reference")
|
||||||
{
|
{
|
||||||
json j = {"A", "B"};
|
json j = { "A", "B" };
|
||||||
int counter = 1;
|
int counter = 1;
|
||||||
|
|
||||||
for (const auto& i : j.items())
|
for (const auto& i : j.items())
|
||||||
@ -1161,7 +1161,7 @@ SECTION("const array")
|
|||||||
{
|
{
|
||||||
SECTION("value")
|
SECTION("value")
|
||||||
{
|
{
|
||||||
const json j = {"A", "B"};
|
const json j = { "A", "B" };
|
||||||
int counter = 1;
|
int counter = 1;
|
||||||
|
|
||||||
for (auto i : j.items()) // NOLINT(performance-for-range-copy)
|
for (auto i : j.items()) // NOLINT(performance-for-range-copy)
|
||||||
@ -1194,7 +1194,7 @@ SECTION("const array")
|
|||||||
|
|
||||||
SECTION("reference")
|
SECTION("reference")
|
||||||
{
|
{
|
||||||
const json j = {"A", "B"};
|
const json j = { "A", "B" };
|
||||||
int counter = 1;
|
int counter = 1;
|
||||||
|
|
||||||
for (auto& i : j.items()) // NOLINT(readability-qualified-auto)
|
for (auto& i : j.items()) // NOLINT(readability-qualified-auto)
|
||||||
@ -1227,7 +1227,7 @@ SECTION("const array")
|
|||||||
|
|
||||||
SECTION("const value")
|
SECTION("const value")
|
||||||
{
|
{
|
||||||
const json j = {"A", "B"};
|
const json j = { "A", "B" };
|
||||||
int counter = 1;
|
int counter = 1;
|
||||||
|
|
||||||
for (const auto i : j.items()) // NOLINT(performance-for-range-copy)
|
for (const auto i : j.items()) // NOLINT(performance-for-range-copy)
|
||||||
@ -1260,7 +1260,7 @@ SECTION("const array")
|
|||||||
|
|
||||||
SECTION("const reference")
|
SECTION("const reference")
|
||||||
{
|
{
|
||||||
const json j = {"A", "B"};
|
const json j = { "A", "B" };
|
||||||
int counter = 1;
|
int counter = 1;
|
||||||
|
|
||||||
for (const auto& i : j.items())
|
for (const auto& i : j.items())
|
||||||
|
@ -531,7 +531,7 @@ TEST_CASE("iterators 1")
|
|||||||
|
|
||||||
SECTION("array")
|
SECTION("array")
|
||||||
{
|
{
|
||||||
json j = {1, 2, 3};
|
json j = { 1, 2, 3 };
|
||||||
json j_const(j);
|
json j_const(j);
|
||||||
|
|
||||||
SECTION("json + begin/end")
|
SECTION("json + begin/end")
|
||||||
@ -715,7 +715,7 @@ TEST_CASE("iterators 1")
|
|||||||
|
|
||||||
SECTION("object")
|
SECTION("object")
|
||||||
{
|
{
|
||||||
json j = {{"A", 1}, {"B", 2}, {"C", 3}};
|
json j = { { "A", 1 }, { "B", 2 }, { "C", 3 } };
|
||||||
json j_const(j);
|
json j_const(j);
|
||||||
|
|
||||||
SECTION("json + begin/end")
|
SECTION("json + begin/end")
|
||||||
@ -1580,7 +1580,7 @@ TEST_CASE("iterators 1")
|
|||||||
}
|
}
|
||||||
SECTION("array")
|
SECTION("array")
|
||||||
{
|
{
|
||||||
json j = {1, 2, 3};
|
json j = { 1, 2, 3 };
|
||||||
json::const_iterator it = j.begin();
|
json::const_iterator it = j.begin();
|
||||||
CHECK(it == j.cbegin());
|
CHECK(it == j.cbegin());
|
||||||
it = j.begin();
|
it = j.begin();
|
||||||
@ -1588,7 +1588,7 @@ TEST_CASE("iterators 1")
|
|||||||
}
|
}
|
||||||
SECTION("object")
|
SECTION("object")
|
||||||
{
|
{
|
||||||
json j = {{"A", 1}, {"B", 2}, {"C", 3}};
|
json j = { { "A", 1 }, { "B", 2 }, { "C", 3 } };
|
||||||
json::const_iterator it = j.begin();
|
json::const_iterator it = j.begin();
|
||||||
CHECK(it == j.cbegin());
|
CHECK(it == j.cbegin());
|
||||||
it = j.begin();
|
it = j.begin();
|
||||||
|
@ -27,7 +27,7 @@ TEST_CASE("iterators 2")
|
|||||||
{
|
{
|
||||||
SECTION("iterator comparisons")
|
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)
|
for (json& j : j_values)
|
||||||
{
|
{
|
||||||
@ -347,8 +347,8 @@ TEST_CASE("iterators 2")
|
|||||||
|
|
||||||
SECTION("iterator arithmetic")
|
SECTION("iterator arithmetic")
|
||||||
{
|
{
|
||||||
json j_object = {{"one", 1}, {"two", 2}, {"three", 3}};
|
json j_object = { { "one", 1 }, { "two", 2 }, { "three", 3 } };
|
||||||
json j_array = {1, 2, 3, 4, 5, 6};
|
json j_array = { 1, 2, 3, 4, 5, 6 };
|
||||||
json j_null = nullptr;
|
json j_null = nullptr;
|
||||||
json j_value = 42;
|
json j_value = 42;
|
||||||
|
|
||||||
@ -555,7 +555,7 @@ TEST_CASE("iterators 2")
|
|||||||
|
|
||||||
SECTION("reverse iterator comparisons")
|
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)
|
for (json& j : j_values)
|
||||||
{
|
{
|
||||||
@ -875,8 +875,8 @@ TEST_CASE("iterators 2")
|
|||||||
|
|
||||||
SECTION("reverse iterator arithmetic")
|
SECTION("reverse iterator arithmetic")
|
||||||
{
|
{
|
||||||
json j_object = {{"one", 1}, {"two", 2}, {"three", 3}};
|
json j_object = { { "one", 1 }, { "two", 2 }, { "three", 3 } };
|
||||||
json j_array = {1, 2, 3, 4, 5, 6};
|
json j_array = { 1, 2, 3, 4, 5, 6 };
|
||||||
json j_null = nullptr;
|
json j_null = nullptr;
|
||||||
json j_value = 42;
|
json j_value = 42;
|
||||||
|
|
||||||
@ -1107,7 +1107,7 @@ TEST_CASE("iterators 2")
|
|||||||
{
|
{
|
||||||
SECTION("copy")
|
SECTION("copy")
|
||||||
{
|
{
|
||||||
json j{"foo", "bar"};
|
json j{ "foo", "bar" };
|
||||||
auto j_copied = json::array();
|
auto j_copied = json::array();
|
||||||
|
|
||||||
std::ranges::copy(j, std::back_inserter(j_copied));
|
std::ranges::copy(j, std::back_inserter(j_copied));
|
||||||
@ -1117,7 +1117,7 @@ TEST_CASE("iterators 2")
|
|||||||
|
|
||||||
SECTION("find_if")
|
SECTION("find_if")
|
||||||
{
|
{
|
||||||
json j{1, 3, 2, 4};
|
json j{ 1, 3, 2, 4 };
|
||||||
auto j_even = json::array();
|
auto j_even = json::array();
|
||||||
|
|
||||||
#if JSON_USE_IMPLICIT_CONVERSIONS
|
#if JSON_USE_IMPLICIT_CONVERSIONS
|
||||||
@ -1144,8 +1144,8 @@ TEST_CASE("iterators 2")
|
|||||||
{
|
{
|
||||||
SECTION("reverse")
|
SECTION("reverse")
|
||||||
{
|
{
|
||||||
json j{1, 2, 3, 4, 5};
|
json j{ 1, 2, 3, 4, 5 };
|
||||||
json j_expected{5, 4, 3, 2, 1};
|
json j_expected{ 5, 4, 3, 2, 1 };
|
||||||
|
|
||||||
auto reversed = j | std::views::reverse;
|
auto reversed = j | std::views::reverse;
|
||||||
CHECK(std::ranges::equal(reversed, j_expected));
|
CHECK(std::ranges::equal(reversed, j_expected));
|
||||||
@ -1154,11 +1154,11 @@ TEST_CASE("iterators 2")
|
|||||||
SECTION("transform")
|
SECTION("transform")
|
||||||
{
|
{
|
||||||
json j{
|
json j{
|
||||||
{"a_key", "a_value"},
|
{ "a_key", "a_value" },
|
||||||
{"b_key", "b_value"},
|
{ "b_key", "b_value" },
|
||||||
{"c_key", "c_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) {
|
auto transformed = j.items() | std::views::transform([](const auto& item) {
|
||||||
return item.key();
|
return item.key();
|
||||||
|
@ -77,9 +77,9 @@ TEST_CASE("JSON patch")
|
|||||||
{
|
{
|
||||||
// If removing an element from an array, any elements above the
|
// If removing an element from an array, any elements above the
|
||||||
// specified index are shifted one position to the left.
|
// specified index are shifted one position to the left.
|
||||||
json const doc = {1, 2, 3, 4};
|
json const doc = { 1, 2, 3, 4 };
|
||||||
json const patch = {{{"op", "remove"}, {"path", "/1"}}};
|
json const patch = { { { "op", "remove" }, { "path", "/1" } } };
|
||||||
CHECK(doc.patch(patch) == json({1, 3, 4}));
|
CHECK(doc.patch(patch) == json({ 1, 3, 4 }));
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("A.1. Adding an Object Member")
|
SECTION("A.1. Adding an Object Member")
|
||||||
@ -529,7 +529,7 @@ TEST_CASE("JSON patch")
|
|||||||
)"_json;
|
)"_json;
|
||||||
|
|
||||||
// The resulting JSON document:
|
// The resulting JSON document:
|
||||||
json expected = {1, 2, 3};
|
json expected = { 1, 2, 3 };
|
||||||
|
|
||||||
// check if patched value is as expected
|
// check if patched value is as expected
|
||||||
CHECK(doc.patch(patch) == 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.
|
// exactly the number of elements in the array which is legal.
|
||||||
|
|
||||||
// An example target JSON document:
|
// An example target JSON document:
|
||||||
json const doc = {0, 1, 2};
|
json const doc = { 0, 1, 2 };
|
||||||
|
|
||||||
// A JSON Patch document:
|
// A JSON Patch document:
|
||||||
json const patch = R"(
|
json const patch = R"(
|
||||||
@ -555,7 +555,7 @@ TEST_CASE("JSON patch")
|
|||||||
)"_json;
|
)"_json;
|
||||||
|
|
||||||
// The resulting JSON document:
|
// The resulting JSON document:
|
||||||
json expected = {0, 1, 2, 3};
|
json expected = { 0, 1, 2, 3 };
|
||||||
|
|
||||||
// check if patched value is as expected
|
// check if patched value is as expected
|
||||||
CHECK(doc.patch(patch) == expected);
|
CHECK(doc.patch(patch) == expected);
|
||||||
@ -611,7 +611,7 @@ TEST_CASE("JSON patch")
|
|||||||
SECTION("replace")
|
SECTION("replace")
|
||||||
{
|
{
|
||||||
json const j = "string";
|
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));
|
CHECK(j.patch(patch) == json(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -640,13 +640,13 @@ TEST_CASE("JSON patch")
|
|||||||
}
|
}
|
||||||
{
|
{
|
||||||
// a JSON value
|
// a JSON value
|
||||||
json j = {"good", "bad", "ugly"};
|
json j = { "good", "bad", "ugly" };
|
||||||
|
|
||||||
// a JSON pointer
|
// a JSON pointer
|
||||||
auto ptr = json::json_pointer("/2");
|
auto ptr = json::json_pointer("/2");
|
||||||
|
|
||||||
// use to access elements
|
// use to access elements
|
||||||
j[ptr] = {{"it", "cattivo"}};
|
j[ptr] = { { "it", "cattivo" } };
|
||||||
CHECK(j == R"(["good","bad",{"it":"cattivo"}])"_json);
|
CHECK(j == R"(["good","bad",{"it":"cattivo"}])"_json);
|
||||||
|
|
||||||
// use user-defined string literal
|
// use user-defined string literal
|
||||||
@ -666,7 +666,7 @@ TEST_CASE("JSON patch")
|
|||||||
SECTION("not an array")
|
SECTION("not an array")
|
||||||
{
|
{
|
||||||
json const j;
|
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),
|
CHECK_THROWS_WITH_AS(j.patch(patch),
|
||||||
"[json.exception.parse_error.104] parse error: JSON patch must be an array of objects",
|
"[json.exception.parse_error.104] parse error: JSON patch must be an array of objects",
|
||||||
json::parse_error&);
|
json::parse_error&);
|
||||||
@ -675,7 +675,7 @@ TEST_CASE("JSON patch")
|
|||||||
SECTION("not an array of objects")
|
SECTION("not an array of objects")
|
||||||
{
|
{
|
||||||
json const j;
|
json const j;
|
||||||
json const patch = {"op", "add", "path", "", "value", 1};
|
json const patch = { "op", "add", "path", "", "value", 1 };
|
||||||
#if JSON_DIAGNOSTICS
|
#if JSON_DIAGNOSTICS
|
||||||
CHECK_THROWS_WITH_AS(j.patch(patch),
|
CHECK_THROWS_WITH_AS(j.patch(patch),
|
||||||
"[json.exception.parse_error.104] parse error: (/0) JSON patch must be an array of objects",
|
"[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'")
|
SECTION("missing 'op'")
|
||||||
{
|
{
|
||||||
json const j;
|
json const j;
|
||||||
json const patch = {{{"foo", "bar"}}};
|
json const patch = { { { "foo", "bar" } } };
|
||||||
#if JSON_DIAGNOSTICS
|
#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&);
|
CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: (/0) operation must have member 'op'", json::parse_error&);
|
||||||
#else
|
#else
|
||||||
@ -701,7 +701,7 @@ TEST_CASE("JSON patch")
|
|||||||
SECTION("non-string 'op'")
|
SECTION("non-string 'op'")
|
||||||
{
|
{
|
||||||
json const j;
|
json const j;
|
||||||
json const patch = {{{"op", 1}}};
|
json const patch = { { { "op", 1 } } };
|
||||||
#if JSON_DIAGNOSTICS
|
#if JSON_DIAGNOSTICS
|
||||||
CHECK_THROWS_WITH_AS(j.patch(patch),
|
CHECK_THROWS_WITH_AS(j.patch(patch),
|
||||||
"[json.exception.parse_error.105] parse error: (/0) operation must have string member 'op'",
|
"[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")
|
SECTION("invalid operation")
|
||||||
{
|
{
|
||||||
json const j;
|
json const j;
|
||||||
json const patch = {{{"op", "foo"}, {"path", ""}}};
|
json const patch = { { { "op", "foo" }, { "path", "" } } };
|
||||||
#if JSON_DIAGNOSTICS
|
#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&);
|
CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: (/0) operation value 'foo' is invalid", json::parse_error&);
|
||||||
#else
|
#else
|
||||||
@ -730,7 +730,7 @@ TEST_CASE("JSON patch")
|
|||||||
SECTION("missing 'path'")
|
SECTION("missing 'path'")
|
||||||
{
|
{
|
||||||
json const j;
|
json const j;
|
||||||
json const patch = {{{"op", "add"}}};
|
json const patch = { { { "op", "add" } } };
|
||||||
#if JSON_DIAGNOSTICS
|
#if JSON_DIAGNOSTICS
|
||||||
CHECK_THROWS_WITH_AS(j.patch(patch),
|
CHECK_THROWS_WITH_AS(j.patch(patch),
|
||||||
"[json.exception.parse_error.105] parse error: (/0) operation 'add' must have member 'path'",
|
"[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'")
|
SECTION("non-string 'path'")
|
||||||
{
|
{
|
||||||
json const j;
|
json const j;
|
||||||
json const patch = {{{"op", "add"}, {"path", 1}}};
|
json const patch = { { { "op", "add" }, { "path", 1 } } };
|
||||||
#if JSON_DIAGNOSTICS
|
#if JSON_DIAGNOSTICS
|
||||||
CHECK_THROWS_WITH_AS(j.patch(patch),
|
CHECK_THROWS_WITH_AS(j.patch(patch),
|
||||||
"[json.exception.parse_error.105] parse error: (/0) operation 'add' must have string member 'path'",
|
"[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'")
|
SECTION("missing 'value'")
|
||||||
{
|
{
|
||||||
json const j;
|
json const j;
|
||||||
json const patch = {{{"op", "add"}, {"path", ""}}};
|
json const patch = { { { "op", "add" }, { "path", "" } } };
|
||||||
#if JSON_DIAGNOSTICS
|
#if JSON_DIAGNOSTICS
|
||||||
CHECK_THROWS_WITH_AS(j.patch(patch),
|
CHECK_THROWS_WITH_AS(j.patch(patch),
|
||||||
"[json.exception.parse_error.105] parse error: (/0) operation 'add' must have member 'value'",
|
"[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")
|
SECTION("invalid array index")
|
||||||
{
|
{
|
||||||
json const j = {1, 2};
|
json const j = { 1, 2 };
|
||||||
json const patch = {{{"op", "add"}, {"path", "/4"}, {"value", 4}}};
|
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&);
|
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'")
|
SECTION("missing 'path'")
|
||||||
{
|
{
|
||||||
json const j;
|
json const j;
|
||||||
json const patch = {{{"op", "remove"}}};
|
json const patch = { { { "op", "remove" } } };
|
||||||
#if JSON_DIAGNOSTICS
|
#if JSON_DIAGNOSTICS
|
||||||
CHECK_THROWS_WITH_AS(j.patch(patch),
|
CHECK_THROWS_WITH_AS(j.patch(patch),
|
||||||
"[json.exception.parse_error.105] parse error: (/0) operation 'remove' must have member 'path'",
|
"[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'")
|
SECTION("non-string 'path'")
|
||||||
{
|
{
|
||||||
json const j;
|
json const j;
|
||||||
json const patch = {{{"op", "remove"}, {"path", 1}}};
|
json const patch = { { { "op", "remove" }, { "path", 1 } } };
|
||||||
#if JSON_DIAGNOSTICS
|
#if JSON_DIAGNOSTICS
|
||||||
CHECK_THROWS_WITH_AS(j.patch(patch),
|
CHECK_THROWS_WITH_AS(j.patch(patch),
|
||||||
"[json.exception.parse_error.105] parse error: (/0) operation 'remove' must have string member 'path'",
|
"[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)")
|
SECTION("nonexisting target location (array)")
|
||||||
{
|
{
|
||||||
json const j = {1, 2, 3};
|
json const j = { 1, 2, 3 };
|
||||||
json const patch = {{{"op", "remove"}, {"path", "/17"}}};
|
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&);
|
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)")
|
SECTION("nonexisting target location (object)")
|
||||||
{
|
{
|
||||||
json const j = {{"foo", 1}, {"bar", 2}};
|
json const j = { { "foo", 1 }, { "bar", 2 } };
|
||||||
json const patch = {{{"op", "remove"}, {"path", "/baz"}}};
|
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&);
|
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")
|
SECTION("root element as target location")
|
||||||
{
|
{
|
||||||
json const j = "string";
|
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&);
|
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'")
|
SECTION("missing 'path'")
|
||||||
{
|
{
|
||||||
json const j;
|
json const j;
|
||||||
json const patch = {{{"op", "replace"}}};
|
json const patch = { { { "op", "replace" } } };
|
||||||
#if JSON_DIAGNOSTICS
|
#if JSON_DIAGNOSTICS
|
||||||
CHECK_THROWS_WITH_AS(j.patch(patch),
|
CHECK_THROWS_WITH_AS(j.patch(patch),
|
||||||
"[json.exception.parse_error.105] parse error: (/0) operation 'replace' must have member 'path'",
|
"[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'")
|
SECTION("non-string 'path'")
|
||||||
{
|
{
|
||||||
json const j;
|
json const j;
|
||||||
json const patch = {{{"op", "replace"}, {"path", 1}}};
|
json const patch = { { { "op", "replace" }, { "path", 1 } } };
|
||||||
#if JSON_DIAGNOSTICS
|
#if JSON_DIAGNOSTICS
|
||||||
CHECK_THROWS_WITH_AS(j.patch(patch),
|
CHECK_THROWS_WITH_AS(j.patch(patch),
|
||||||
"[json.exception.parse_error.105] parse error: (/0) operation 'replace' must have string member 'path'",
|
"[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'")
|
SECTION("missing 'value'")
|
||||||
{
|
{
|
||||||
json const j;
|
json const j;
|
||||||
json const patch = {{{"op", "replace"}, {"path", ""}}};
|
json const patch = { { { "op", "replace" }, { "path", "" } } };
|
||||||
#if JSON_DIAGNOSTICS
|
#if JSON_DIAGNOSTICS
|
||||||
CHECK_THROWS_WITH_AS(j.patch(patch),
|
CHECK_THROWS_WITH_AS(j.patch(patch),
|
||||||
"[json.exception.parse_error.105] parse error: (/0) operation 'replace' must have member 'value'",
|
"[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)")
|
SECTION("nonexisting target location (array)")
|
||||||
{
|
{
|
||||||
json const j = {1, 2, 3};
|
json const j = { 1, 2, 3 };
|
||||||
json const patch = {{{"op", "replace"}, {"path", "/17"}, {"value", 19}}};
|
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&);
|
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)")
|
SECTION("nonexisting target location (object)")
|
||||||
{
|
{
|
||||||
json const j = {{"foo", 1}, {"bar", 2}};
|
json const j = { { "foo", 1 }, { "bar", 2 } };
|
||||||
json const patch = {{{"op", "replace"}, {"path", "/baz"}, {"value", 3}}};
|
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&);
|
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'")
|
SECTION("missing 'path'")
|
||||||
{
|
{
|
||||||
json const j;
|
json const j;
|
||||||
json const patch = {{{"op", "move"}}};
|
json const patch = { { { "op", "move" } } };
|
||||||
#if JSON_DIAGNOSTICS
|
#if JSON_DIAGNOSTICS
|
||||||
CHECK_THROWS_WITH_AS(j.patch(patch),
|
CHECK_THROWS_WITH_AS(j.patch(patch),
|
||||||
"[json.exception.parse_error.105] parse error: (/0) operation 'move' must have member 'path'",
|
"[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'")
|
SECTION("non-string 'path'")
|
||||||
{
|
{
|
||||||
json const j;
|
json const j;
|
||||||
json const patch = {{{"op", "move"}, {"path", 1}}};
|
json const patch = { { { "op", "move" }, { "path", 1 } } };
|
||||||
#if JSON_DIAGNOSTICS
|
#if JSON_DIAGNOSTICS
|
||||||
CHECK_THROWS_WITH_AS(j.patch(patch),
|
CHECK_THROWS_WITH_AS(j.patch(patch),
|
||||||
"[json.exception.parse_error.105] parse error: (/0) operation 'move' must have string member 'path'",
|
"[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'")
|
SECTION("missing 'from'")
|
||||||
{
|
{
|
||||||
json const j;
|
json const j;
|
||||||
json const patch = {{{"op", "move"}, {"path", ""}}};
|
json const patch = { { { "op", "move" }, { "path", "" } } };
|
||||||
CHECK_THROWS_AS(j.patch(patch), json::parse_error&);
|
CHECK_THROWS_AS(j.patch(patch), json::parse_error&);
|
||||||
#if JSON_DIAGNOSTICS
|
#if JSON_DIAGNOSTICS
|
||||||
CHECK_THROWS_WITH_AS(j.patch(patch),
|
CHECK_THROWS_WITH_AS(j.patch(patch),
|
||||||
@ -947,7 +947,7 @@ TEST_CASE("JSON patch")
|
|||||||
SECTION("non-string 'from'")
|
SECTION("non-string 'from'")
|
||||||
{
|
{
|
||||||
json const j;
|
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&);
|
CHECK_THROWS_AS(j.patch(patch), json::parse_error&);
|
||||||
#if JSON_DIAGNOSTICS
|
#if JSON_DIAGNOSTICS
|
||||||
CHECK_THROWS_WITH_AS(j.patch(patch),
|
CHECK_THROWS_WITH_AS(j.patch(patch),
|
||||||
@ -962,15 +962,15 @@ TEST_CASE("JSON patch")
|
|||||||
|
|
||||||
SECTION("nonexisting from location (array)")
|
SECTION("nonexisting from location (array)")
|
||||||
{
|
{
|
||||||
json const j = {1, 2, 3};
|
json const j = { 1, 2, 3 };
|
||||||
json const patch = {{{"op", "move"}, {"path", "/0"}, {"from", "/5"}}};
|
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&);
|
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)")
|
SECTION("nonexisting from location (object)")
|
||||||
{
|
{
|
||||||
json const j = {{"foo", 1}, {"bar", 2}};
|
json const j = { { "foo", 1 }, { "bar", 2 } };
|
||||||
json const patch = {{{"op", "move"}, {"path", "/baz"}, {"from", "/baz"}}};
|
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&);
|
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'")
|
SECTION("missing 'path'")
|
||||||
{
|
{
|
||||||
json const j;
|
json const j;
|
||||||
json const patch = {{{"op", "copy"}}};
|
json const patch = { { { "op", "copy" } } };
|
||||||
#if JSON_DIAGNOSTICS
|
#if JSON_DIAGNOSTICS
|
||||||
CHECK_THROWS_WITH_AS(j.patch(patch),
|
CHECK_THROWS_WITH_AS(j.patch(patch),
|
||||||
"[json.exception.parse_error.105] parse error: (/0) operation 'copy' must have member 'path'",
|
"[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'")
|
SECTION("non-string 'path'")
|
||||||
{
|
{
|
||||||
json const j;
|
json const j;
|
||||||
json const patch = {{{"op", "copy"}, {"path", 1}}};
|
json const patch = { { { "op", "copy" }, { "path", 1 } } };
|
||||||
#if JSON_DIAGNOSTICS
|
#if JSON_DIAGNOSTICS
|
||||||
CHECK_THROWS_WITH_AS(j.patch(patch),
|
CHECK_THROWS_WITH_AS(j.patch(patch),
|
||||||
"[json.exception.parse_error.105] parse error: (/0) operation 'copy' must have string member 'path'",
|
"[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'")
|
SECTION("missing 'from'")
|
||||||
{
|
{
|
||||||
json const j;
|
json const j;
|
||||||
json const patch = {{{"op", "copy"}, {"path", ""}}};
|
json const patch = { { { "op", "copy" }, { "path", "" } } };
|
||||||
#if JSON_DIAGNOSTICS
|
#if JSON_DIAGNOSTICS
|
||||||
CHECK_THROWS_WITH_AS(j.patch(patch),
|
CHECK_THROWS_WITH_AS(j.patch(patch),
|
||||||
"[json.exception.parse_error.105] parse error: (/0) operation 'copy' must have member 'from'",
|
"[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'")
|
SECTION("non-string 'from'")
|
||||||
{
|
{
|
||||||
json const j;
|
json const j;
|
||||||
json const patch = {{{"op", "copy"}, {"path", ""}, {"from", 1}}};
|
json const patch = { { { "op", "copy" }, { "path", "" }, { "from", 1 } } };
|
||||||
#if JSON_DIAGNOSTICS
|
#if JSON_DIAGNOSTICS
|
||||||
CHECK_THROWS_WITH_AS(j.patch(patch),
|
CHECK_THROWS_WITH_AS(j.patch(patch),
|
||||||
"[json.exception.parse_error.105] parse error: (/0) operation 'copy' must have string member 'from'",
|
"[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)")
|
SECTION("nonexisting from location (array)")
|
||||||
{
|
{
|
||||||
json const j = {1, 2, 3};
|
json const j = { 1, 2, 3 };
|
||||||
json const patch = {{{"op", "copy"}, {"path", "/0"}, {"from", "/5"}}};
|
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&);
|
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)")
|
SECTION("nonexisting from location (object)")
|
||||||
{
|
{
|
||||||
json const j = {{"foo", 1}, {"bar", 2}};
|
json const j = { { "foo", 1 }, { "bar", 2 } };
|
||||||
json const patch = {{{"op", "copy"}, {"path", "/fob"}, {"from", "/baz"}}};
|
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&);
|
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'")
|
SECTION("missing 'path'")
|
||||||
{
|
{
|
||||||
json const j;
|
json const j;
|
||||||
json const patch = {{{"op", "test"}}};
|
json const patch = { { { "op", "test" } } };
|
||||||
#if JSON_DIAGNOSTICS
|
#if JSON_DIAGNOSTICS
|
||||||
CHECK_THROWS_WITH_AS(j.patch(patch),
|
CHECK_THROWS_WITH_AS(j.patch(patch),
|
||||||
"[json.exception.parse_error.105] parse error: (/0) operation 'test' must have member 'path'",
|
"[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'")
|
SECTION("non-string 'path'")
|
||||||
{
|
{
|
||||||
json const j;
|
json const j;
|
||||||
json const patch = {{{"op", "test"}, {"path", 1}}};
|
json const patch = { { { "op", "test" }, { "path", 1 } } };
|
||||||
#if JSON_DIAGNOSTICS
|
#if JSON_DIAGNOSTICS
|
||||||
CHECK_THROWS_WITH_AS(j.patch(patch),
|
CHECK_THROWS_WITH_AS(j.patch(patch),
|
||||||
"[json.exception.parse_error.105] parse error: (/0) operation 'test' must have string member 'path'",
|
"[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'")
|
SECTION("missing 'value'")
|
||||||
{
|
{
|
||||||
json const j;
|
json const j;
|
||||||
json const patch = {{{"op", "test"}, {"path", ""}}};
|
json const patch = { { { "op", "test" }, { "path", "" } } };
|
||||||
#if JSON_DIAGNOSTICS
|
#if JSON_DIAGNOSTICS
|
||||||
CHECK_THROWS_WITH_AS(j.patch(patch),
|
CHECK_THROWS_WITH_AS(j.patch(patch),
|
||||||
"[json.exception.parse_error.105] parse error: (/0) operation 'test' must have member 'value'",
|
"[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")
|
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)
|
CAPTURE(filename)
|
||||||
std::ifstream f(filename);
|
std::ifstream f(filename);
|
||||||
|
@ -40,7 +40,7 @@ TEST_CASE("JSON pointers")
|
|||||||
|
|
||||||
SECTION("array index error")
|
SECTION("array index error")
|
||||||
{
|
{
|
||||||
json v = {1, 2, 3, 4};
|
json v = { 1, 2, 3, 4 };
|
||||||
json::json_pointer const ptr("/10e");
|
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&);
|
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(!j.contains(json::json_pointer("/a/c/1")));
|
||||||
CHECK_NOTHROW(j[json::json_pointer("/a/c/1")] = 42);
|
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/c/1")));
|
||||||
|
|
||||||
CHECK(!j.contains(json::json_pointer("/a/d/-")));
|
CHECK(!j.contains(json::json_pointer("/a/d/-")));
|
||||||
CHECK_NOTHROW(j[json::json_pointer("/a/d/-")] = 42);
|
CHECK_NOTHROW(j[json::json_pointer("/a/d/-")] = 42);
|
||||||
CHECK(!j.contains(json::json_pointer("/a/d/-")));
|
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}}
|
// "/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
|
// unresolved access
|
||||||
json j_primitive = 1;
|
json j_primitive = 1;
|
||||||
@ -251,7 +251,7 @@ TEST_CASE("JSON pointers")
|
|||||||
{
|
{
|
||||||
SECTION("nonconst access")
|
SECTION("nonconst access")
|
||||||
{
|
{
|
||||||
json j = {1, 2, 3};
|
json j = { 1, 2, 3 };
|
||||||
const json j_const = j;
|
const json j_const = j;
|
||||||
|
|
||||||
// check reading access
|
// check reading access
|
||||||
@ -269,7 +269,7 @@ TEST_CASE("JSON pointers")
|
|||||||
|
|
||||||
// assign to nonexisting index (with gap)
|
// assign to nonexisting index (with gap)
|
||||||
j["/5"_json_pointer] = 55;
|
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
|
// error with leading 0
|
||||||
CHECK_THROWS_WITH_AS(j["/01"_json_pointer],
|
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(!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.exception.parse_error.109] parse error: array index 'three' is not a number",
|
||||||
json::parse_error&);
|
json::parse_error&);
|
||||||
|
|
||||||
// assign to "-"
|
// assign to "-"
|
||||||
j["/-"_json_pointer] = 99;
|
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
|
// 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&);
|
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")
|
SECTION("const access")
|
||||||
{
|
{
|
||||||
const json j = {1, 2, 3};
|
const json j = { 1, 2, 3 };
|
||||||
|
|
||||||
// check reading access
|
// check reading access
|
||||||
CHECK(j["/0"_json_pointer] == j[0]);
|
CHECK(j["/0"_json_pointer] == j[0]);
|
||||||
@ -397,28 +397,29 @@ TEST_CASE("JSON pointers")
|
|||||||
|
|
||||||
SECTION("flatten")
|
SECTION("flatten")
|
||||||
{
|
{
|
||||||
json j = {{"pi", 3.141},
|
json j = { { "pi", 3.141 },
|
||||||
{"happy", true},
|
{ "happy", true },
|
||||||
{"name", "Niels"},
|
{ "name", "Niels" },
|
||||||
{"nothing", nullptr},
|
{ "nothing", nullptr },
|
||||||
{"answer", {{"everything", 42}}},
|
{ "answer", { { "everything", 42 } } },
|
||||||
{"list", {1, 0, 2}},
|
{ "list", { 1, 0, 2 } },
|
||||||
{"object", {{"currency", "USD"}, {"value", 42.99}, {"", "empty string"}, {"/", "slash"}, {"~", "tilde"}, {"~1", "tilde1"}}}};
|
{ "object",
|
||||||
|
{ { "currency", "USD" }, { "value", 42.99 }, { "", "empty string" }, { "/", "slash" }, { "~", "tilde" }, { "~1", "tilde1" } } } };
|
||||||
|
|
||||||
json j_flatten = {{"/pi", 3.141},
|
json j_flatten = { { "/pi", 3.141 },
|
||||||
{"/happy", true},
|
{ "/happy", true },
|
||||||
{"/name", "Niels"},
|
{ "/name", "Niels" },
|
||||||
{"/nothing", nullptr},
|
{ "/nothing", nullptr },
|
||||||
{"/answer/everything", 42},
|
{ "/answer/everything", 42 },
|
||||||
{"/list/0", 1},
|
{ "/list/0", 1 },
|
||||||
{"/list/1", 0},
|
{ "/list/1", 0 },
|
||||||
{"/list/2", 2},
|
{ "/list/2", 2 },
|
||||||
{"/object/currency", "USD"},
|
{ "/object/currency", "USD" },
|
||||||
{"/object/value", 42.99},
|
{ "/object/value", 42.99 },
|
||||||
{"/object/", "empty string"},
|
{ "/object/", "empty string" },
|
||||||
{"/object/~1", "slash"},
|
{ "/object/~1", "slash" },
|
||||||
{"/object/~0", "tilde"},
|
{ "/object/~0", "tilde" },
|
||||||
{"/object/~01", "tilde1"}};
|
{ "/object/~01", "tilde1" } };
|
||||||
|
|
||||||
// check if flattened result is as expected
|
// check if flattened result is as expected
|
||||||
CHECK(j.flatten() == j_flatten);
|
CHECK(j.flatten() == j_flatten);
|
||||||
@ -431,15 +432,17 @@ TEST_CASE("JSON pointers")
|
|||||||
|
|
||||||
// error for nonprimitve values
|
// error for nonprimitve values
|
||||||
#if JSON_DIAGNOSTICS
|
#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.exception.type_error.315] (/~11) values in object must be primitive",
|
||||||
json::type_error&);
|
json::type_error&);
|
||||||
#else
|
#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
|
#endif
|
||||||
|
|
||||||
// error for conflicting values
|
// 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&);
|
CHECK_THROWS_WITH_AS(j_error.unflatten(), "[json.exception.type_error.313] invalid value to unflatten", json::type_error&);
|
||||||
|
|
||||||
// explicit roundtrip check
|
// explicit roundtrip check
|
||||||
@ -464,7 +467,7 @@ TEST_CASE("JSON pointers")
|
|||||||
|
|
||||||
SECTION("string representation")
|
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);
|
json::json_pointer const ptr(ptr_str);
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
@ -496,14 +499,15 @@ TEST_CASE("JSON pointers")
|
|||||||
|
|
||||||
SECTION("empty, push, pop and parent")
|
SECTION("empty, push, pop and parent")
|
||||||
{
|
{
|
||||||
const json j = {{"", "Hello"},
|
const json j = { { "", "Hello" },
|
||||||
{"pi", 3.141},
|
{ "pi", 3.141 },
|
||||||
{"happy", true},
|
{ "happy", true },
|
||||||
{"name", "Niels"},
|
{ "name", "Niels" },
|
||||||
{"nothing", nullptr},
|
{ "nothing", nullptr },
|
||||||
{"answer", {{"everything", 42}}},
|
{ "answer", { { "everything", 42 } } },
|
||||||
{"list", {1, 0, 2}},
|
{ "list", { 1, 0, 2 } },
|
||||||
{"object", {{"currency", "USD"}, {"value", 42.99}, {"", "empty string"}, {"/", "slash"}, {"~", "tilde"}, {"~1", "tilde1"}}}};
|
{ "object",
|
||||||
|
{ { "currency", "USD" }, { "value", 42.99 }, { "", "empty string" }, { "/", "slash" }, { "~", "tilde" }, { "~1", "tilde1" } } } };
|
||||||
|
|
||||||
// empty json_pointer returns the root JSON-object
|
// empty json_pointer returns the root JSON-object
|
||||||
auto ptr = ""_json_pointer;
|
auto ptr = ""_json_pointer;
|
||||||
@ -555,14 +559,15 @@ TEST_CASE("JSON pointers")
|
|||||||
|
|
||||||
SECTION("operators")
|
SECTION("operators")
|
||||||
{
|
{
|
||||||
const json j = {{"", "Hello"},
|
const json j = { { "", "Hello" },
|
||||||
{"pi", 3.141},
|
{ "pi", 3.141 },
|
||||||
{"happy", true},
|
{ "happy", true },
|
||||||
{"name", "Niels"},
|
{ "name", "Niels" },
|
||||||
{"nothing", nullptr},
|
{ "nothing", nullptr },
|
||||||
{"answer", {{"everything", 42}}},
|
{ "answer", { { "everything", 42 } } },
|
||||||
{"list", {1, 0, 2}},
|
{ "list", { 1, 0, 2 } },
|
||||||
{"object", {{"currency", "USD"}, {"value", 42.99}, {"", "empty string"}, {"/", "slash"}, {"~", "tilde"}, {"~1", "tilde1"}}}};
|
{ "object",
|
||||||
|
{ { "currency", "USD" }, { "value", 42.99 }, { "", "empty string" }, { "/", "slash" }, { "~", "tilde" }, { "~1", "tilde1" } } } };
|
||||||
|
|
||||||
// empty json_pointer returns the root JSON-object
|
// empty json_pointer returns the root JSON-object
|
||||||
auto ptr = ""_json_pointer;
|
auto ptr = ""_json_pointer;
|
||||||
@ -602,7 +607,7 @@ TEST_CASE("JSON pointers")
|
|||||||
{
|
{
|
||||||
const char* ptr_cpstring = "/foo/bar";
|
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)
|
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 ptr1 = json::json_pointer(ptr_string);
|
||||||
auto ptr2 = 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_j::string_t>::value);
|
||||||
CHECK(std::is_same<json_ptr_str::string_t, json_ptr_oj::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"};
|
std::string const ptr_string{ "/foo/0" };
|
||||||
json_ptr_str ptr{ptr_string};
|
json_ptr_str ptr{ ptr_string };
|
||||||
json_ptr_j ptr_j{ptr_string};
|
json_ptr_j ptr_j{ ptr_string };
|
||||||
json_ptr_oj ptr_oj{ptr_string};
|
json_ptr_oj ptr_oj{ ptr_string };
|
||||||
|
|
||||||
CHECK(j.contains(ptr));
|
CHECK(j.contains(ptr));
|
||||||
CHECK(j.contains(ptr_j));
|
CHECK(j.contains(ptr_j));
|
||||||
|
@ -20,7 +20,7 @@ TEST_CASE("version information")
|
|||||||
CHECK(j["name"] == "JSON for Modern C++");
|
CHECK(j["name"] == "JSON for Modern C++");
|
||||||
CHECK(j["copyright"] == "(C) 2013-2023 Niels Lohmann");
|
CHECK(j["copyright"] == "(C) 2013-2023 Niels Lohmann");
|
||||||
CHECK(j["url"] == "https://github.com/nlohmann/json");
|
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.find("platform") != j.end());
|
||||||
CHECK(j.at("compiler").find("family") != j.at("compiler").end());
|
CHECK(j.at("compiler").find("family") != j.at("compiler").end());
|
||||||
|
@ -51,7 +51,7 @@ TEST_CASE("modifiers")
|
|||||||
|
|
||||||
SECTION("filled array")
|
SECTION("filled array")
|
||||||
{
|
{
|
||||||
json j = {1, 2, 3};
|
json j = { 1, 2, 3 };
|
||||||
json const k = j;
|
json const k = j;
|
||||||
|
|
||||||
j.clear();
|
j.clear();
|
||||||
@ -76,7 +76,7 @@ TEST_CASE("modifiers")
|
|||||||
|
|
||||||
SECTION("filled object")
|
SECTION("filled object")
|
||||||
{
|
{
|
||||||
json j = {{"one", 1}, {"two", 2}, {"three", 3}};
|
json j = { { "one", 1 }, { "two", 2 }, { "three", 3 } };
|
||||||
json const k = j;
|
json const k = j;
|
||||||
|
|
||||||
j.clear();
|
j.clear();
|
||||||
@ -101,7 +101,7 @@ TEST_CASE("modifiers")
|
|||||||
|
|
||||||
SECTION("filled binary")
|
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;
|
json const k = j;
|
||||||
|
|
||||||
j.clear();
|
j.clear();
|
||||||
@ -164,15 +164,15 @@ TEST_CASE("modifiers")
|
|||||||
j.push_back(1);
|
j.push_back(1);
|
||||||
j.push_back(2);
|
j.push_back(2);
|
||||||
CHECK(j.type() == json::value_t::array);
|
CHECK(j.type() == json::value_t::array);
|
||||||
CHECK(j == json({1, 2}));
|
CHECK(j == json({ 1, 2 }));
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("array")
|
SECTION("array")
|
||||||
{
|
{
|
||||||
json j = {1, 2, 3};
|
json j = { 1, 2, 3 };
|
||||||
j.push_back("Hello");
|
j.push_back("Hello");
|
||||||
CHECK(j.type() == json::value_t::array);
|
CHECK(j.type() == json::value_t::array);
|
||||||
CHECK(j == json({1, 2, 3, "Hello"}));
|
CHECK(j == json({ 1, 2, 3, "Hello" }));
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("other type")
|
SECTION("other type")
|
||||||
@ -191,16 +191,16 @@ TEST_CASE("modifiers")
|
|||||||
j.push_back(k);
|
j.push_back(k);
|
||||||
j.push_back(k);
|
j.push_back(k);
|
||||||
CHECK(j.type() == json::value_t::array);
|
CHECK(j.type() == json::value_t::array);
|
||||||
CHECK(j == json({1, 1}));
|
CHECK(j == json({ 1, 1 }));
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("array")
|
SECTION("array")
|
||||||
{
|
{
|
||||||
json j = {1, 2, 3};
|
json j = { 1, 2, 3 };
|
||||||
json const k("Hello");
|
json const k("Hello");
|
||||||
j.push_back(k);
|
j.push_back(k);
|
||||||
CHECK(j.type() == json::value_t::array);
|
CHECK(j.type() == json::value_t::array);
|
||||||
CHECK(j == json({1, 2, 3, "Hello"}));
|
CHECK(j == json({ 1, 2, 3, "Hello" }));
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("other type")
|
SECTION("other type")
|
||||||
@ -217,8 +217,8 @@ TEST_CASE("modifiers")
|
|||||||
SECTION("null")
|
SECTION("null")
|
||||||
{
|
{
|
||||||
json j;
|
json j;
|
||||||
j.push_back(json::object_t::value_type({"one", 1}));
|
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({ "two", 2 }));
|
||||||
CHECK(j.type() == json::value_t::object);
|
CHECK(j.type() == json::value_t::object);
|
||||||
CHECK(j.size() == 2);
|
CHECK(j.size() == 2);
|
||||||
CHECK(j["one"] == json(1));
|
CHECK(j["one"] == json(1));
|
||||||
@ -228,8 +228,8 @@ TEST_CASE("modifiers")
|
|||||||
SECTION("object")
|
SECTION("object")
|
||||||
{
|
{
|
||||||
json j(json::value_t::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({ "one", 1 }));
|
||||||
j.push_back(json::object_t::value_type({"two", 2}));
|
j.push_back(json::object_t::value_type({ "two", 2 }));
|
||||||
CHECK(j.size() == 2);
|
CHECK(j.size() == 2);
|
||||||
CHECK(j["one"] == json(1));
|
CHECK(j["one"] == json(1));
|
||||||
CHECK(j["two"] == json(2));
|
CHECK(j["two"] == json(2));
|
||||||
@ -239,7 +239,7 @@ TEST_CASE("modifiers")
|
|||||||
{
|
{
|
||||||
json j = 1;
|
json j = 1;
|
||||||
json const k("Hello");
|
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.exception.type_error.308] cannot use push_back() with number",
|
||||||
json::type_error&);
|
json::type_error&);
|
||||||
}
|
}
|
||||||
@ -250,35 +250,35 @@ TEST_CASE("modifiers")
|
|||||||
SECTION("null")
|
SECTION("null")
|
||||||
{
|
{
|
||||||
json j;
|
json j;
|
||||||
j.push_back({"foo", "bar"});
|
j.push_back({ "foo", "bar" });
|
||||||
CHECK(j == json::array({{"foo", "bar"}}));
|
CHECK(j == json::array({ { "foo", "bar" } }));
|
||||||
|
|
||||||
json k;
|
json k;
|
||||||
k.push_back({1, 2, 3});
|
k.push_back({ 1, 2, 3 });
|
||||||
CHECK(k == json::array({{1, 2, 3}}));
|
CHECK(k == json::array({ { 1, 2, 3 } }));
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("array")
|
SECTION("array")
|
||||||
{
|
{
|
||||||
json j = {1, 2, 3};
|
json j = { 1, 2, 3 };
|
||||||
j.push_back({"foo", "bar"});
|
j.push_back({ "foo", "bar" });
|
||||||
CHECK(j == json({1, 2, 3, {"foo", "bar"}}));
|
CHECK(j == json({ 1, 2, 3, { "foo", "bar" } }));
|
||||||
|
|
||||||
json k = {1, 2, 3};
|
json k = { 1, 2, 3 };
|
||||||
k.push_back({1, 2, 3});
|
k.push_back({ 1, 2, 3 });
|
||||||
CHECK(k == json({1, 2, 3, {1, 2, 3}}));
|
CHECK(k == json({ 1, 2, 3, { 1, 2, 3 } }));
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("object")
|
SECTION("object")
|
||||||
{
|
{
|
||||||
json j = {{"key1", 1}};
|
json j = { { "key1", 1 } };
|
||||||
j.push_back({"key2", "bar"});
|
j.push_back({ "key2", "bar" });
|
||||||
CHECK(j == json({{"key1", 1}, {"key2", "bar"}}));
|
CHECK(j == json({ { "key1", 1 }, { "key2", "bar" } }));
|
||||||
|
|
||||||
// invalid values (no string/val pair)
|
// 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 }), "[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 }), "[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, 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);
|
auto& x2 = j.emplace_back(2);
|
||||||
CHECK(x2 == 2);
|
CHECK(x2 == 2);
|
||||||
CHECK(j.type() == json::value_t::array);
|
CHECK(j.type() == json::value_t::array);
|
||||||
CHECK(j == json({1, 2}));
|
CHECK(j == json({ 1, 2 }));
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("array")
|
SECTION("array")
|
||||||
{
|
{
|
||||||
json j = {1, 2, 3};
|
json j = { 1, 2, 3 };
|
||||||
auto& x = j.emplace_back("Hello");
|
auto& x = j.emplace_back("Hello");
|
||||||
CHECK(x == "Hello");
|
CHECK(x == "Hello");
|
||||||
CHECK(j.type() == json::value_t::array);
|
CHECK(j.type() == json::value_t::array);
|
||||||
CHECK(j == json({1, 2, 3, "Hello"}));
|
CHECK(j == json({ 1, 2, 3, "Hello" }));
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("multiple values")
|
SECTION("multiple values")
|
||||||
{
|
{
|
||||||
json j;
|
json j;
|
||||||
auto& x = j.emplace_back(3, "foo");
|
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.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");
|
CHECK(*res3.first == "bam");
|
||||||
|
|
||||||
// the final object
|
// the final object
|
||||||
CHECK(j == json({{"baz", "bam"}, {"foo", "bar"}}));
|
CHECK(j == json({ { "baz", "bam" }, { "foo", "bar" } }));
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("object")
|
SECTION("object")
|
||||||
{
|
{
|
||||||
// start with an object
|
// start with an object
|
||||||
json j = {{"foo", "bar"}};
|
json j = { { "foo", "bar" } };
|
||||||
|
|
||||||
// add a new key
|
// add a new key
|
||||||
auto res1 = j.emplace("baz", "bam");
|
auto res1 = j.emplace("baz", "bam");
|
||||||
@ -371,7 +371,7 @@ TEST_CASE("modifiers")
|
|||||||
CHECK(*res2.first == "bar");
|
CHECK(*res2.first == "bar");
|
||||||
|
|
||||||
// check final object
|
// 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 += 1;
|
||||||
j += 2;
|
j += 2;
|
||||||
CHECK(j.type() == json::value_t::array);
|
CHECK(j.type() == json::value_t::array);
|
||||||
CHECK(j == json({1, 2}));
|
CHECK(j == json({ 1, 2 }));
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("array")
|
SECTION("array")
|
||||||
{
|
{
|
||||||
json j = {1, 2, 3};
|
json j = { 1, 2, 3 };
|
||||||
j += "Hello";
|
j += "Hello";
|
||||||
CHECK(j.type() == json::value_t::array);
|
CHECK(j.type() == json::value_t::array);
|
||||||
CHECK(j == json({1, 2, 3, "Hello"}));
|
CHECK(j == json({ 1, 2, 3, "Hello" }));
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("other type")
|
SECTION("other type")
|
||||||
@ -421,16 +421,16 @@ TEST_CASE("modifiers")
|
|||||||
j += k;
|
j += k;
|
||||||
j += k;
|
j += k;
|
||||||
CHECK(j.type() == json::value_t::array);
|
CHECK(j.type() == json::value_t::array);
|
||||||
CHECK(j == json({1, 1}));
|
CHECK(j == json({ 1, 1 }));
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("array")
|
SECTION("array")
|
||||||
{
|
{
|
||||||
json j = {1, 2, 3};
|
json j = { 1, 2, 3 };
|
||||||
json const k("Hello");
|
json const k("Hello");
|
||||||
j += k;
|
j += k;
|
||||||
CHECK(j.type() == json::value_t::array);
|
CHECK(j.type() == json::value_t::array);
|
||||||
CHECK(j == json({1, 2, 3, "Hello"}));
|
CHECK(j == json({ 1, 2, 3, "Hello" }));
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("other type")
|
SECTION("other type")
|
||||||
@ -447,8 +447,8 @@ TEST_CASE("modifiers")
|
|||||||
SECTION("null")
|
SECTION("null")
|
||||||
{
|
{
|
||||||
json j;
|
json j;
|
||||||
j += json::object_t::value_type({"one", 1});
|
j += json::object_t::value_type({ "one", 1 });
|
||||||
j += json::object_t::value_type({"two", 2});
|
j += json::object_t::value_type({ "two", 2 });
|
||||||
CHECK(j.type() == json::value_t::object);
|
CHECK(j.type() == json::value_t::object);
|
||||||
CHECK(j.size() == 2);
|
CHECK(j.size() == 2);
|
||||||
CHECK(j["one"] == json(1));
|
CHECK(j["one"] == json(1));
|
||||||
@ -458,8 +458,8 @@ TEST_CASE("modifiers")
|
|||||||
SECTION("object")
|
SECTION("object")
|
||||||
{
|
{
|
||||||
json j(json::value_t::object);
|
json j(json::value_t::object);
|
||||||
j += json::object_t::value_type({"one", 1});
|
j += json::object_t::value_type({ "one", 1 });
|
||||||
j += json::object_t::value_type({"two", 2});
|
j += json::object_t::value_type({ "two", 2 });
|
||||||
CHECK(j.size() == 2);
|
CHECK(j.size() == 2);
|
||||||
CHECK(j["one"] == json(1));
|
CHECK(j["one"] == json(1));
|
||||||
CHECK(j["two"] == json(2));
|
CHECK(j["two"] == json(2));
|
||||||
@ -469,7 +469,7 @@ TEST_CASE("modifiers")
|
|||||||
{
|
{
|
||||||
json j = 1;
|
json j = 1;
|
||||||
json const k("Hello");
|
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.exception.type_error.308] cannot use push_back() with number",
|
||||||
json::type_error&);
|
json::type_error&);
|
||||||
}
|
}
|
||||||
@ -480,40 +480,40 @@ TEST_CASE("modifiers")
|
|||||||
SECTION("null")
|
SECTION("null")
|
||||||
{
|
{
|
||||||
json j;
|
json j;
|
||||||
j += {"foo", "bar"};
|
j += { "foo", "bar" };
|
||||||
CHECK(j == json::array({{"foo", "bar"}}));
|
CHECK(j == json::array({ { "foo", "bar" } }));
|
||||||
|
|
||||||
json k;
|
json k;
|
||||||
k += {1, 2, 3};
|
k += { 1, 2, 3 };
|
||||||
CHECK(k == json::array({{1, 2, 3}}));
|
CHECK(k == json::array({ { 1, 2, 3 } }));
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("array")
|
SECTION("array")
|
||||||
{
|
{
|
||||||
json j = {1, 2, 3};
|
json j = { 1, 2, 3 };
|
||||||
j += {"foo", "bar"};
|
j += { "foo", "bar" };
|
||||||
CHECK(j == json({1, 2, 3, {"foo", "bar"}}));
|
CHECK(j == json({ 1, 2, 3, { "foo", "bar" } }));
|
||||||
|
|
||||||
json k = {1, 2, 3};
|
json k = { 1, 2, 3 };
|
||||||
k += {1, 2, 3};
|
k += { 1, 2, 3 };
|
||||||
CHECK(k == json({1, 2, 3, {1, 2, 3}}));
|
CHECK(k == json({ 1, 2, 3, { 1, 2, 3 } }));
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("object")
|
SECTION("object")
|
||||||
{
|
{
|
||||||
json j = {{"key1", 1}};
|
json j = { { "key1", 1 } };
|
||||||
j += {"key2", "bar"};
|
j += { "key2", "bar" };
|
||||||
CHECK(j == json({{"key1", 1}, {"key2", "bar"}}));
|
CHECK(j == json({ { "key1", 1 }, { "key2", "bar" } }));
|
||||||
|
|
||||||
json k = {{"key1", 1}};
|
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&);
|
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()")
|
SECTION("insert()")
|
||||||
{
|
{
|
||||||
json j_array = {1, 2, 3, 4};
|
json j_array = { 1, 2, 3, 4 };
|
||||||
json j_value = 5;
|
json j_value = 5;
|
||||||
|
|
||||||
SECTION("value at position")
|
SECTION("value at position")
|
||||||
@ -524,7 +524,7 @@ TEST_CASE("modifiers")
|
|||||||
CHECK(j_array.size() == 5);
|
CHECK(j_array.size() == 5);
|
||||||
CHECK(*it == j_value);
|
CHECK(*it == j_value);
|
||||||
CHECK(j_array.begin() == it);
|
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")
|
SECTION("insert in the middle")
|
||||||
@ -533,7 +533,7 @@ TEST_CASE("modifiers")
|
|||||||
CHECK(j_array.size() == 5);
|
CHECK(j_array.size() == 5);
|
||||||
CHECK(*it == j_value);
|
CHECK(*it == j_value);
|
||||||
CHECK((it - j_array.begin()) == 2);
|
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()")
|
SECTION("insert before end()")
|
||||||
@ -542,7 +542,7 @@ TEST_CASE("modifiers")
|
|||||||
CHECK(j_array.size() == 5);
|
CHECK(j_array.size() == 5);
|
||||||
CHECK(*it == j_value);
|
CHECK(*it == j_value);
|
||||||
CHECK((j_array.end() - it) == 1);
|
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(j_array.size() == 5);
|
||||||
CHECK(*it == j_value);
|
CHECK(*it == j_value);
|
||||||
CHECK(j_array.begin() == it);
|
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")
|
SECTION("insert in the middle")
|
||||||
@ -563,7 +563,7 @@ TEST_CASE("modifiers")
|
|||||||
CHECK(j_array.size() == 5);
|
CHECK(j_array.size() == 5);
|
||||||
CHECK(*it == j_value);
|
CHECK(*it == j_value);
|
||||||
CHECK((it - j_array.begin()) == 2);
|
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()")
|
SECTION("insert before end()")
|
||||||
@ -572,7 +572,7 @@ TEST_CASE("modifiers")
|
|||||||
CHECK(j_array.size() == 5);
|
CHECK(j_array.size() == 5);
|
||||||
CHECK(*it == j_value);
|
CHECK(*it == j_value);
|
||||||
CHECK((j_array.end() - it) == 1);
|
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(j_array.size() == 7);
|
||||||
CHECK(*it == j_value);
|
CHECK(*it == j_value);
|
||||||
CHECK(j_array.begin() == it);
|
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")
|
SECTION("insert in the middle")
|
||||||
@ -593,7 +593,7 @@ TEST_CASE("modifiers")
|
|||||||
CHECK(j_array.size() == 7);
|
CHECK(j_array.size() == 7);
|
||||||
CHECK(*it == j_value);
|
CHECK(*it == j_value);
|
||||||
CHECK((it - j_array.begin()) == 2);
|
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()")
|
SECTION("insert before end()")
|
||||||
@ -602,7 +602,7 @@ TEST_CASE("modifiers")
|
|||||||
CHECK(j_array.size() == 7);
|
CHECK(j_array.size() == 7);
|
||||||
CHECK(*it == j_value);
|
CHECK(*it == j_value);
|
||||||
CHECK((j_array.end() - it) == 3);
|
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)")
|
SECTION("insert nothing (count = 0)")
|
||||||
@ -612,13 +612,13 @@ TEST_CASE("modifiers")
|
|||||||
// the returned iterator points to the first inserted element;
|
// the returned iterator points to the first inserted element;
|
||||||
// there were 4 elements, so it should point to the 5th
|
// there were 4 elements, so it should point to the 5th
|
||||||
CHECK(it == j_array.begin() + 4);
|
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")
|
SECTION("range for array")
|
||||||
{
|
{
|
||||||
json j_other_array = {"first", "second"};
|
json j_other_array = { "first", "second" };
|
||||||
|
|
||||||
SECTION("proper usage")
|
SECTION("proper usage")
|
||||||
{
|
{
|
||||||
@ -626,7 +626,7 @@ TEST_CASE("modifiers")
|
|||||||
CHECK(j_array.size() == 6);
|
CHECK(j_array.size() == 6);
|
||||||
CHECK(*it == *j_other_array.begin());
|
CHECK(*it == *j_other_array.begin());
|
||||||
CHECK((j_array.end() - it) == 2);
|
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")
|
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());
|
auto it = j_array.insert(j_array.end(), j_other_array.begin(), j_other_array.begin());
|
||||||
CHECK(j_array.size() == 4);
|
CHECK(j_array.size() == 4);
|
||||||
CHECK(it == j_array.end());
|
CHECK(it == j_array.end());
|
||||||
CHECK(j_array == json({1, 2, 3, 4}));
|
CHECK(j_array == json({ 1, 2, 3, 4 }));
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("invalid iterators")
|
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()),
|
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",
|
"[json.exception.invalid_iterator.211] passed iterators may not belong to container",
|
||||||
@ -652,8 +652,8 @@ TEST_CASE("modifiers")
|
|||||||
|
|
||||||
SECTION("range for object")
|
SECTION("range for object")
|
||||||
{
|
{
|
||||||
json j_object1 = {{"one", "eins"}, {"two", "zwei"}};
|
json j_object1 = { { "one", "eins" }, { "two", "zwei" } };
|
||||||
json j_object2 = {{"eleven", "elf"}, {"seventeen", "siebzehn"}};
|
json j_object2 = { { "eleven", "elf" }, { "seventeen", "siebzehn" } };
|
||||||
|
|
||||||
SECTION("proper usage")
|
SECTION("proper usage")
|
||||||
{
|
{
|
||||||
@ -669,7 +669,7 @@ TEST_CASE("modifiers")
|
|||||||
|
|
||||||
SECTION("invalid iterators")
|
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()),
|
CHECK_THROWS_WITH_AS(j_array.insert(j_object2.begin(), j_object2.end()),
|
||||||
"[json.exception.type_error.309] cannot use insert() with array",
|
"[json.exception.type_error.309] cannot use insert() with array",
|
||||||
@ -687,37 +687,37 @@ TEST_CASE("modifiers")
|
|||||||
{
|
{
|
||||||
SECTION("insert before begin()")
|
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(j_array.size() == 7);
|
||||||
CHECK(*it == json(7));
|
CHECK(*it == json(7));
|
||||||
CHECK(j_array.begin() == it);
|
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")
|
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(j_array.size() == 7);
|
||||||
CHECK(*it == json(7));
|
CHECK(*it == json(7));
|
||||||
CHECK((it - j_array.begin()) == 2);
|
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()")
|
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(j_array.size() == 7);
|
||||||
CHECK(*it == json(7));
|
CHECK(*it == json(7));
|
||||||
CHECK((j_array.end() - it) == 3);
|
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")
|
SECTION("invalid iterator")
|
||||||
{
|
{
|
||||||
// pass iterator to a different array
|
// pass iterator to a different array
|
||||||
json j_another_array = {1, 2};
|
json j_another_array = { 1, 2 };
|
||||||
json j_yet_another_array = {"first", "second"};
|
json j_yet_another_array = { "first", "second" };
|
||||||
CHECK_THROWS_WITH_AS(j_array.insert(j_another_array.end(), 10),
|
CHECK_THROWS_WITH_AS(j_array.insert(j_another_array.end(), 10),
|
||||||
"[json.exception.invalid_iterator.202] iterator does not fit current value",
|
"[json.exception.invalid_iterator.202] iterator does not fit current value",
|
||||||
json::invalid_iterator&);
|
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()),
|
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.exception.invalid_iterator.202] iterator does not fit current value",
|
||||||
json::invalid_iterator&);
|
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.exception.invalid_iterator.202] iterator does not fit current value",
|
||||||
json::invalid_iterator&);
|
json::invalid_iterator&);
|
||||||
}
|
}
|
||||||
@ -739,7 +739,7 @@ TEST_CASE("modifiers")
|
|||||||
{
|
{
|
||||||
// call insert on a non-array type
|
// call insert on a non-array type
|
||||||
json j_nonarray = 3;
|
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(), 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),
|
CHECK_THROWS_WITH_AS(j_nonarray.insert(j_nonarray.end(), j_value),
|
||||||
"[json.exception.type_error.309] cannot use insert() with number",
|
"[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()),
|
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.exception.type_error.309] cannot use insert() with number",
|
||||||
json::type_error&);
|
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.exception.type_error.309] cannot use insert() with number",
|
||||||
json::type_error&);
|
json::type_error&);
|
||||||
}
|
}
|
||||||
@ -760,16 +760,16 @@ TEST_CASE("modifiers")
|
|||||||
{
|
{
|
||||||
SECTION("non-recursive (default)")
|
SECTION("non-recursive (default)")
|
||||||
{
|
{
|
||||||
json j_object1 = {{"one", "eins"}, {"two", "zwei"}};
|
json j_object1 = { { "one", "eins" }, { "two", "zwei" } };
|
||||||
json j_object2 = {{"three", "drei"}, {"two", "zwo"}};
|
json j_object2 = { { "three", "drei" }, { "two", "zwo" } };
|
||||||
json j_array = {1, 2, 3, 4};
|
json j_array = { 1, 2, 3, 4 };
|
||||||
|
|
||||||
SECTION("const reference")
|
SECTION("const reference")
|
||||||
{
|
{
|
||||||
SECTION("proper usage")
|
SECTION("proper usage")
|
||||||
{
|
{
|
||||||
j_object1.update(j_object2);
|
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;
|
json j_null;
|
||||||
j_null.update(j_object2);
|
j_null.update(j_object2);
|
||||||
@ -789,7 +789,7 @@ TEST_CASE("modifiers")
|
|||||||
SECTION("proper usage")
|
SECTION("proper usage")
|
||||||
{
|
{
|
||||||
j_object1.update(j_object2.begin(), j_object2.end());
|
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;
|
json j_null;
|
||||||
j_null.update(j_object2.begin(), j_object2.end());
|
j_null.update(j_object2.begin(), j_object2.end());
|
||||||
@ -799,12 +799,12 @@ TEST_CASE("modifiers")
|
|||||||
SECTION("empty range")
|
SECTION("empty range")
|
||||||
{
|
{
|
||||||
j_object1.update(j_object2.begin(), j_object2.begin());
|
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")
|
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()),
|
CHECK_THROWS_WITH_AS(j_array.update(j_object2.begin(), j_object2.end()),
|
||||||
"[json.exception.type_error.312] cannot use update() with array",
|
"[json.exception.type_error.312] cannot use update() with array",
|
||||||
@ -825,18 +825,18 @@ TEST_CASE("modifiers")
|
|||||||
{
|
{
|
||||||
SECTION("extend object")
|
SECTION("extend object")
|
||||||
{
|
{
|
||||||
json j1 = {{"string", "s"}, {"numbers", {{"one", 1}}}};
|
json j1 = { { "string", "s" }, { "numbers", { { "one", 1 } } } };
|
||||||
json const j2 = {{"string", "t"}, {"numbers", {{"two", 2}}}};
|
json const j2 = { { "string", "t" }, { "numbers", { { "two", 2 } } } };
|
||||||
j1.update(j2, true);
|
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")
|
SECTION("replace object")
|
||||||
{
|
{
|
||||||
json j1 = {{"string", "s"}, {"numbers", {{"one", 1}}}};
|
json j1 = { { "string", "s" }, { "numbers", { { "one", 1 } } } };
|
||||||
json const j2 = {{"string", "t"}, {"numbers", 1}};
|
json const j2 = { { "string", "t" }, { "numbers", 1 } };
|
||||||
j1.update(j2, true);
|
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")
|
SECTION("array_t type")
|
||||||
{
|
{
|
||||||
json j = {1, 2, 3, 4};
|
json j = { 1, 2, 3, 4 };
|
||||||
json::array_t a = {"foo", "bar", "baz"};
|
json::array_t a = { "foo", "bar", "baz" };
|
||||||
|
|
||||||
j.swap(a);
|
j.swap(a);
|
||||||
|
|
||||||
CHECK(j == json({"foo", "bar", "baz"}));
|
CHECK(j == json({ "foo", "bar", "baz" }));
|
||||||
|
|
||||||
j.swap(a);
|
j.swap(a);
|
||||||
|
|
||||||
CHECK(j == json({1, 2, 3, 4}));
|
CHECK(j == json({ 1, 2, 3, 4 }));
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("non-array_t type")
|
SECTION("non-array_t type")
|
||||||
{
|
{
|
||||||
json j = 17;
|
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&);
|
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")
|
SECTION("object_t type")
|
||||||
{
|
{
|
||||||
json j = {{"one", 1}, {"two", 2}};
|
json j = { { "one", 1 }, { "two", 2 } };
|
||||||
json::object_t o = {{"cow", "Kuh"}, {"chicken", "Huhn"}};
|
json::object_t o = { { "cow", "Kuh" }, { "chicken", "Huhn" } };
|
||||||
|
|
||||||
j.swap(o);
|
j.swap(o);
|
||||||
|
|
||||||
CHECK(j == json({{"cow", "Kuh"}, {"chicken", "Huhn"}}));
|
CHECK(j == json({ { "cow", "Kuh" }, { "chicken", "Huhn" } }));
|
||||||
|
|
||||||
j.swap(o);
|
j.swap(o);
|
||||||
|
|
||||||
CHECK(j == json({{"one", 1}, {"two", 2}}));
|
CHECK(j == json({ { "one", 1 }, { "two", 2 } }));
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("non-object_t type")
|
SECTION("non-object_t type")
|
||||||
{
|
{
|
||||||
json j = 17;
|
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&);
|
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")
|
SECTION("binary_t type")
|
||||||
{
|
{
|
||||||
json j = json::binary({1, 2, 3, 4});
|
json j = json::binary({ 1, 2, 3, 4 });
|
||||||
json::binary_t s = {{5, 6, 7, 8}};
|
json::binary_t s = { { 5, 6, 7, 8 } };
|
||||||
|
|
||||||
j.swap(s);
|
j.swap(s);
|
||||||
|
|
||||||
CHECK(j == json::binary({5, 6, 7, 8}));
|
CHECK(j == json::binary({ 5, 6, 7, 8 }));
|
||||||
|
|
||||||
j.swap(s);
|
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")
|
SECTION("binary_t::container_type type")
|
||||||
{
|
{
|
||||||
json j = json::binary({1, 2, 3, 4});
|
json j = json::binary({ 1, 2, 3, 4 });
|
||||||
std::vector<std::uint8_t> s = {{5, 6, 7, 8}};
|
std::vector<std::uint8_t> s = { { 5, 6, 7, 8 } };
|
||||||
|
|
||||||
j.swap(s);
|
j.swap(s);
|
||||||
|
|
||||||
CHECK(j == json::binary({5, 6, 7, 8}));
|
CHECK(j == json::binary({ 5, 6, 7, 8 }));
|
||||||
|
|
||||||
j.swap(s);
|
j.swap(s);
|
||||||
|
|
||||||
CHECK(j == json::binary({1, 2, 3, 4}));
|
CHECK(j == json::binary({ 1, 2, 3, 4 }));
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("non-binary_t type")
|
SECTION("non-binary_t type")
|
||||||
{
|
{
|
||||||
json j = 17;
|
json j = 17;
|
||||||
json::binary_t s1 = {{1, 2, 3, 4}};
|
json::binary_t s1 = { { 1, 2, 3, 4 } };
|
||||||
std::vector<std::uint8_t> s2 = {{5, 6, 7, 8}};
|
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(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);
|
CHECK_THROWS_WITH_AS(j.swap(s2), "[json.exception.type_error.310] cannot use swap(binary_t::container_type&) with number", json::type_error);
|
||||||
|
@ -118,7 +118,7 @@ TEST_CASE("MessagePack")
|
|||||||
SECTION("null")
|
SECTION("null")
|
||||||
{
|
{
|
||||||
json const j = nullptr;
|
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);
|
const auto result = json::to_msgpack(j);
|
||||||
CHECK(result == expected);
|
CHECK(result == expected);
|
||||||
|
|
||||||
@ -132,7 +132,7 @@ TEST_CASE("MessagePack")
|
|||||||
SECTION("true")
|
SECTION("true")
|
||||||
{
|
{
|
||||||
json const j = 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);
|
const auto result = json::to_msgpack(j);
|
||||||
CHECK(result == expected);
|
CHECK(result == expected);
|
||||||
|
|
||||||
@ -144,7 +144,7 @@ TEST_CASE("MessagePack")
|
|||||||
SECTION("false")
|
SECTION("false")
|
||||||
{
|
{
|
||||||
json const j = 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);
|
const auto result = json::to_msgpack(j);
|
||||||
CHECK(result == expected);
|
CHECK(result == expected);
|
||||||
|
|
||||||
@ -171,7 +171,7 @@ TEST_CASE("MessagePack")
|
|||||||
CHECK(j.is_number_integer());
|
CHECK(j.is_number_integer());
|
||||||
|
|
||||||
// create expected byte vector
|
// 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
|
// compare result + size
|
||||||
const auto result = json::to_msgpack(j);
|
const auto result = json::to_msgpack(j);
|
||||||
@ -201,7 +201,7 @@ TEST_CASE("MessagePack")
|
|||||||
CHECK(j.is_number_integer());
|
CHECK(j.is_number_integer());
|
||||||
|
|
||||||
// create expected byte vector
|
// 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
|
// compare result + size
|
||||||
const auto result = json::to_msgpack(j);
|
const auto result = json::to_msgpack(j);
|
||||||
@ -290,7 +290,7 @@ TEST_CASE("MessagePack")
|
|||||||
|
|
||||||
SECTION("65536..4294967295 (int 32)")
|
SECTION("65536..4294967295 (int 32)")
|
||||||
{
|
{
|
||||||
for (uint32_t i : {65536u, 77777u, 1048576u, 4294967295u})
|
for (uint32_t i : { 65536u, 77777u, 1048576u, 4294967295u })
|
||||||
{
|
{
|
||||||
CAPTURE(i)
|
CAPTURE(i)
|
||||||
|
|
||||||
@ -329,7 +329,7 @@ TEST_CASE("MessagePack")
|
|||||||
|
|
||||||
SECTION("4294967296..9223372036854775807 (int 64)")
|
SECTION("4294967296..9223372036854775807 (int 64)")
|
||||||
{
|
{
|
||||||
for (uint64_t i : {4294967296LU, 9223372036854775807LU})
|
for (uint64_t i : { 4294967296LU, 9223372036854775807LU })
|
||||||
{
|
{
|
||||||
CAPTURE(i)
|
CAPTURE(i)
|
||||||
|
|
||||||
@ -408,7 +408,7 @@ TEST_CASE("MessagePack")
|
|||||||
SECTION("-9263 (int 16)")
|
SECTION("-9263 (int 16)")
|
||||||
{
|
{
|
||||||
json const j = -9263;
|
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);
|
const auto result = json::to_msgpack(j);
|
||||||
CHECK(result == expected);
|
CHECK(result == expected);
|
||||||
@ -459,11 +459,7 @@ TEST_CASE("MessagePack")
|
|||||||
SECTION("-32769..-2147483648")
|
SECTION("-32769..-2147483648")
|
||||||
{
|
{
|
||||||
std::vector<int32_t> const numbers{
|
std::vector<int32_t> const numbers{
|
||||||
-32769,
|
-32769, -65536, -77777, -1048576, -2147483648LL,
|
||||||
-65536,
|
|
||||||
-77777,
|
|
||||||
-1048576,
|
|
||||||
-2147483648LL,
|
|
||||||
};
|
};
|
||||||
for (auto i : numbers)
|
for (auto i : numbers)
|
||||||
{
|
{
|
||||||
@ -565,7 +561,7 @@ TEST_CASE("MessagePack")
|
|||||||
CHECK(j.is_number_unsigned());
|
CHECK(j.is_number_unsigned());
|
||||||
|
|
||||||
// create expected byte vector
|
// 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
|
// compare result + size
|
||||||
const auto result = json::to_msgpack(j);
|
const auto result = json::to_msgpack(j);
|
||||||
@ -652,7 +648,7 @@ TEST_CASE("MessagePack")
|
|||||||
|
|
||||||
SECTION("65536..4294967295 (uint 32)")
|
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)
|
CAPTURE(i)
|
||||||
|
|
||||||
@ -690,7 +686,7 @@ TEST_CASE("MessagePack")
|
|||||||
|
|
||||||
SECTION("4294967296..18446744073709551615 (uint 64)")
|
SECTION("4294967296..18446744073709551615 (uint 64)")
|
||||||
{
|
{
|
||||||
for (const uint64_t i : {4294967296LU, 18446744073709551615LU})
|
for (const uint64_t i : { 4294967296LU, 18446744073709551615LU })
|
||||||
{
|
{
|
||||||
CAPTURE(i)
|
CAPTURE(i)
|
||||||
|
|
||||||
@ -739,7 +735,7 @@ TEST_CASE("MessagePack")
|
|||||||
{
|
{
|
||||||
double const v = 3.1415925;
|
double const v = 3.1415925;
|
||||||
json const j = v;
|
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);
|
const auto result = json::to_msgpack(j);
|
||||||
CHECK(result == expected);
|
CHECK(result == expected);
|
||||||
|
|
||||||
@ -753,7 +749,7 @@ TEST_CASE("MessagePack")
|
|||||||
{
|
{
|
||||||
double const v = 1.0;
|
double const v = 1.0;
|
||||||
json const j = v;
|
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);
|
const auto result = json::to_msgpack(j);
|
||||||
CHECK(result == expected);
|
CHECK(result == expected);
|
||||||
|
|
||||||
@ -767,7 +763,7 @@ TEST_CASE("MessagePack")
|
|||||||
{
|
{
|
||||||
double const v = 128.1280059814453125;
|
double const v = 128.1280059814453125;
|
||||||
json const j = v;
|
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);
|
const auto result = json::to_msgpack(j);
|
||||||
CHECK(result == expected);
|
CHECK(result == expected);
|
||||||
|
|
||||||
@ -784,8 +780,8 @@ TEST_CASE("MessagePack")
|
|||||||
SECTION("N = 0..31")
|
SECTION("N = 0..31")
|
||||||
{
|
{
|
||||||
// explicitly enumerate the first byte for all 32 strings
|
// 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,
|
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};
|
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)
|
for (size_t N = 0; N < first_bytes.size(); ++N)
|
||||||
{
|
{
|
||||||
@ -856,7 +852,7 @@ TEST_CASE("MessagePack")
|
|||||||
|
|
||||||
SECTION("N = 256..65535")
|
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)
|
CAPTURE(N)
|
||||||
|
|
||||||
@ -886,7 +882,7 @@ TEST_CASE("MessagePack")
|
|||||||
|
|
||||||
SECTION("N = 65536..4294967295")
|
SECTION("N = 65536..4294967295")
|
||||||
{
|
{
|
||||||
for (size_t N : {65536u, 77777u, 1048576u})
|
for (size_t N : { 65536u, 77777u, 1048576u })
|
||||||
{
|
{
|
||||||
CAPTURE(N)
|
CAPTURE(N)
|
||||||
|
|
||||||
@ -922,7 +918,7 @@ TEST_CASE("MessagePack")
|
|||||||
SECTION("empty")
|
SECTION("empty")
|
||||||
{
|
{
|
||||||
json const j = json::array();
|
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);
|
const auto result = json::to_msgpack(j);
|
||||||
CHECK(result == expected);
|
CHECK(result == expected);
|
||||||
|
|
||||||
@ -933,8 +929,8 @@ TEST_CASE("MessagePack")
|
|||||||
|
|
||||||
SECTION("[null]")
|
SECTION("[null]")
|
||||||
{
|
{
|
||||||
json const j = {nullptr};
|
json const j = { nullptr };
|
||||||
std::vector<uint8_t> const expected = {0x91, 0xc0};
|
std::vector<uint8_t> const expected = { 0x91, 0xc0 };
|
||||||
const auto result = json::to_msgpack(j);
|
const auto result = json::to_msgpack(j);
|
||||||
CHECK(result == expected);
|
CHECK(result == expected);
|
||||||
|
|
||||||
@ -946,7 +942,7 @@ TEST_CASE("MessagePack")
|
|||||||
SECTION("[1,2,3,4,5]")
|
SECTION("[1,2,3,4,5]")
|
||||||
{
|
{
|
||||||
json const j = json::parse("[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);
|
const auto result = json::to_msgpack(j);
|
||||||
CHECK(result == expected);
|
CHECK(result == expected);
|
||||||
|
|
||||||
@ -958,7 +954,7 @@ TEST_CASE("MessagePack")
|
|||||||
SECTION("[[[[]]]]")
|
SECTION("[[[[]]]]")
|
||||||
{
|
{
|
||||||
json const j = json::parse("[[[[]]]]");
|
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);
|
const auto result = json::to_msgpack(j);
|
||||||
CHECK(result == expected);
|
CHECK(result == expected);
|
||||||
|
|
||||||
@ -1012,7 +1008,7 @@ TEST_CASE("MessagePack")
|
|||||||
SECTION("empty")
|
SECTION("empty")
|
||||||
{
|
{
|
||||||
json const j = json::object();
|
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);
|
const auto result = json::to_msgpack(j);
|
||||||
CHECK(result == expected);
|
CHECK(result == expected);
|
||||||
|
|
||||||
@ -1023,8 +1019,8 @@ TEST_CASE("MessagePack")
|
|||||||
|
|
||||||
SECTION("{\"\":null}")
|
SECTION("{\"\":null}")
|
||||||
{
|
{
|
||||||
json const j = {{"", nullptr}};
|
json const j = { { "", nullptr } };
|
||||||
std::vector<uint8_t> const expected = {0x81, 0xa0, 0xc0};
|
std::vector<uint8_t> const expected = { 0x81, 0xa0, 0xc0 };
|
||||||
const auto result = json::to_msgpack(j);
|
const auto result = json::to_msgpack(j);
|
||||||
CHECK(result == expected);
|
CHECK(result == expected);
|
||||||
|
|
||||||
@ -1036,7 +1032,7 @@ TEST_CASE("MessagePack")
|
|||||||
SECTION("{\"a\": {\"b\": {\"c\": {}}}}")
|
SECTION("{\"a\": {\"b\": {\"c\": {}}}}")
|
||||||
{
|
{
|
||||||
json const j = json::parse(R"({"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);
|
const auto result = json::to_msgpack(j);
|
||||||
CHECK(result == expected);
|
CHECK(result == expected);
|
||||||
|
|
||||||
@ -1177,7 +1173,7 @@ TEST_CASE("MessagePack")
|
|||||||
|
|
||||||
SECTION("N = 256..65535")
|
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)
|
CAPTURE(N)
|
||||||
|
|
||||||
@ -1210,7 +1206,7 @@ TEST_CASE("MessagePack")
|
|||||||
|
|
||||||
SECTION("N = 65536..4294967295")
|
SECTION("N = 65536..4294967295")
|
||||||
{
|
{
|
||||||
for (std::size_t N : {65536u, 77777u, 1048576u})
|
for (std::size_t N : { 65536u, 77777u, 1048576u })
|
||||||
{
|
{
|
||||||
CAPTURE(N)
|
CAPTURE(N)
|
||||||
|
|
||||||
@ -1283,7 +1279,7 @@ TEST_CASE("MessagePack")
|
|||||||
|
|
||||||
SECTION("N = 256..65535")
|
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)
|
CAPTURE(N)
|
||||||
|
|
||||||
@ -1313,7 +1309,7 @@ TEST_CASE("MessagePack")
|
|||||||
|
|
||||||
SECTION("N = 65536..4294967295")
|
SECTION("N = 65536..4294967295")
|
||||||
{
|
{
|
||||||
for (std::size_t N : {65536u, 77777u, 1048576u})
|
for (std::size_t N : { 65536u, 77777u, 1048576u })
|
||||||
{
|
{
|
||||||
CAPTURE(N)
|
CAPTURE(N)
|
||||||
|
|
||||||
@ -1347,7 +1343,7 @@ TEST_CASE("MessagePack")
|
|||||||
|
|
||||||
SECTION("from float32")
|
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);
|
json const j = json::from_msgpack(given);
|
||||||
CHECK(j.get<double>() == Approx(25.0000019073486));
|
CHECK(j.get<double>() == Approx(25.0000019073486));
|
||||||
}
|
}
|
||||||
@ -1369,107 +1365,107 @@ TEST_CASE("MessagePack")
|
|||||||
json _;
|
json _;
|
||||||
|
|
||||||
CHECK_THROWS_WITH_AS(
|
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.exception.parse_error.110] parse error at byte 2: syntax error while parsing MessagePack string: unexpected end of input",
|
||||||
json::parse_error&);
|
json::parse_error&);
|
||||||
CHECK_THROWS_WITH_AS(
|
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.exception.parse_error.110] parse error at byte 2: syntax error while parsing MessagePack number: unexpected end of input",
|
||||||
json::parse_error&);
|
json::parse_error&);
|
||||||
CHECK_THROWS_WITH_AS(
|
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.exception.parse_error.110] parse error at byte 2: syntax error while parsing MessagePack number: unexpected end of input",
|
||||||
json::parse_error&);
|
json::parse_error&);
|
||||||
CHECK_THROWS_WITH_AS(
|
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.exception.parse_error.110] parse error at byte 3: syntax error while parsing MessagePack number: unexpected end of input",
|
||||||
json::parse_error&);
|
json::parse_error&);
|
||||||
CHECK_THROWS_WITH_AS(
|
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.exception.parse_error.110] parse error at byte 2: syntax error while parsing MessagePack number: unexpected end of input",
|
||||||
json::parse_error&);
|
json::parse_error&);
|
||||||
CHECK_THROWS_WITH_AS(
|
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.exception.parse_error.110] parse error at byte 3: syntax error while parsing MessagePack number: unexpected end of input",
|
||||||
json::parse_error&);
|
json::parse_error&);
|
||||||
CHECK_THROWS_WITH_AS(
|
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.exception.parse_error.110] parse error at byte 4: syntax error while parsing MessagePack number: unexpected end of input",
|
||||||
json::parse_error&);
|
json::parse_error&);
|
||||||
CHECK_THROWS_WITH_AS(
|
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.exception.parse_error.110] parse error at byte 5: syntax error while parsing MessagePack number: unexpected end of input",
|
||||||
json::parse_error&);
|
json::parse_error&);
|
||||||
CHECK_THROWS_WITH_AS(
|
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.exception.parse_error.110] parse error at byte 2: syntax error while parsing MessagePack number: unexpected end of input",
|
||||||
json::parse_error&);
|
json::parse_error&);
|
||||||
CHECK_THROWS_WITH_AS(
|
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.exception.parse_error.110] parse error at byte 3: syntax error while parsing MessagePack number: unexpected end of input",
|
||||||
json::parse_error&);
|
json::parse_error&);
|
||||||
CHECK_THROWS_WITH_AS(
|
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.exception.parse_error.110] parse error at byte 4: syntax error while parsing MessagePack number: unexpected end of input",
|
||||||
json::parse_error&);
|
json::parse_error&);
|
||||||
CHECK_THROWS_WITH_AS(
|
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.exception.parse_error.110] parse error at byte 5: syntax error while parsing MessagePack number: unexpected end of input",
|
||||||
json::parse_error&);
|
json::parse_error&);
|
||||||
CHECK_THROWS_WITH_AS(
|
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.exception.parse_error.110] parse error at byte 6: syntax error while parsing MessagePack number: unexpected end of input",
|
||||||
json::parse_error&);
|
json::parse_error&);
|
||||||
CHECK_THROWS_WITH_AS(
|
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.exception.parse_error.110] parse error at byte 7: syntax error while parsing MessagePack number: unexpected end of input",
|
||||||
json::parse_error&);
|
json::parse_error&);
|
||||||
CHECK_THROWS_WITH_AS(
|
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.exception.parse_error.110] parse error at byte 8: syntax error while parsing MessagePack number: unexpected end of input",
|
||||||
json::parse_error&);
|
json::parse_error&);
|
||||||
CHECK_THROWS_WITH_AS(
|
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.exception.parse_error.110] parse error at byte 9: syntax error while parsing MessagePack number: unexpected end of input",
|
||||||
json::parse_error&);
|
json::parse_error&);
|
||||||
CHECK_THROWS_WITH_AS(
|
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.exception.parse_error.110] parse error at byte 4: syntax error while parsing MessagePack string: unexpected end of input",
|
||||||
json::parse_error&);
|
json::parse_error&);
|
||||||
CHECK_THROWS_WITH_AS(
|
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.exception.parse_error.110] parse error at byte 3: syntax error while parsing MessagePack value: unexpected end of input",
|
||||||
json::parse_error&);
|
json::parse_error&);
|
||||||
CHECK_THROWS_WITH_AS(
|
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.exception.parse_error.110] parse error at byte 4: syntax error while parsing MessagePack value: unexpected end of input",
|
||||||
json::parse_error&);
|
json::parse_error&);
|
||||||
CHECK_THROWS_WITH_AS(
|
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.exception.parse_error.110] parse error at byte 3: syntax error while parsing MessagePack binary: unexpected end of input",
|
||||||
json::parse_error&);
|
json::parse_error&);
|
||||||
|
|
||||||
CHECK(json::from_msgpack(std::vector<uint8_t>({0x87}), 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>({ 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 }), 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>({ 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 }), 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 }), 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 }), 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>({ 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 }), 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 }), 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 }), 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 }), 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 }), 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 }), 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 }), 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>({ 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>({ 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>({ 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>({ 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, 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>({ 0xc4 }), true, false).is_discarded());
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("unsupported bytes")
|
SECTION("unsupported bytes")
|
||||||
@ -1477,19 +1473,19 @@ TEST_CASE("MessagePack")
|
|||||||
SECTION("concrete examples")
|
SECTION("concrete examples")
|
||||||
{
|
{
|
||||||
json _;
|
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.exception.parse_error.112] parse error at byte 1: syntax error while parsing MessagePack value: invalid byte: 0xC1",
|
||||||
json::parse_error&);
|
json::parse_error&);
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("all unsupported bytes")
|
SECTION("all unsupported bytes")
|
||||||
{
|
{
|
||||||
for (auto byte : {// never used
|
for (auto byte : { // never used
|
||||||
0xc1})
|
0xc1 })
|
||||||
{
|
{
|
||||||
json _;
|
json _;
|
||||||
CHECK_THROWS_AS(_ = json::from_msgpack(std::vector<uint8_t>({static_cast<uint8_t>(byte)})), json::parse_error&);
|
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(json::from_msgpack(std::vector<uint8_t>({ static_cast<uint8_t>(byte) }), true, false).is_discarded());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1498,15 +1494,15 @@ TEST_CASE("MessagePack")
|
|||||||
{
|
{
|
||||||
json _;
|
json _;
|
||||||
CHECK_THROWS_WITH_AS(
|
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.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&);
|
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")
|
SECTION("strict mode")
|
||||||
{
|
{
|
||||||
std::vector<uint8_t> const vec = {0xc0, 0xc0};
|
std::vector<uint8_t> const vec = { 0xc0, 0xc0 };
|
||||||
SECTION("non-strict mode")
|
SECTION("non-strict mode")
|
||||||
{
|
{
|
||||||
const auto result = json::from_msgpack(vec, false);
|
const auto result = json::from_msgpack(vec, false);
|
||||||
@ -1529,21 +1525,21 @@ TEST_CASE("MessagePack")
|
|||||||
{
|
{
|
||||||
SECTION("start_array(len)")
|
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);
|
SaxCountdown scp(0);
|
||||||
CHECK(!json::sax_parse(v, &scp, json::input_format_t::msgpack));
|
CHECK(!json::sax_parse(v, &scp, json::input_format_t::msgpack));
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("start_object(len)")
|
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);
|
SaxCountdown scp(0);
|
||||||
CHECK(!json::sax_parse(v, &scp, json::input_format_t::msgpack));
|
CHECK(!json::sax_parse(v, &scp, json::input_format_t::msgpack));
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("key()")
|
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);
|
SaxCountdown scp(1);
|
||||||
CHECK(!json::sax_parse(v, &scp, json::input_format_t::msgpack));
|
CHECK(!json::sax_parse(v, &scp, json::input_format_t::msgpack));
|
||||||
}
|
}
|
||||||
@ -1615,151 +1611,151 @@ 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_simple.json");
|
||||||
exclude_packed.insert(TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_string_unicode.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/1.json",
|
||||||
TEST_DATA_DIRECTORY "/json.org/2.json",
|
TEST_DATA_DIRECTORY "/json.org/2.json",
|
||||||
TEST_DATA_DIRECTORY "/json.org/3.json",
|
TEST_DATA_DIRECTORY "/json.org/3.json",
|
||||||
TEST_DATA_DIRECTORY "/json.org/4.json",
|
TEST_DATA_DIRECTORY "/json.org/4.json",
|
||||||
TEST_DATA_DIRECTORY "/json.org/5.json",
|
TEST_DATA_DIRECTORY "/json.org/5.json",
|
||||||
TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip01.json",
|
TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip01.json",
|
||||||
TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip02.json",
|
TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip02.json",
|
||||||
TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip03.json",
|
TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip03.json",
|
||||||
TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip04.json",
|
TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip04.json",
|
||||||
TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip05.json",
|
TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip05.json",
|
||||||
TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip06.json",
|
TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip06.json",
|
||||||
TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip07.json",
|
TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip07.json",
|
||||||
TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip08.json",
|
TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip08.json",
|
||||||
TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip09.json",
|
TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip09.json",
|
||||||
TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip10.json",
|
TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip10.json",
|
||||||
TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip11.json",
|
TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip11.json",
|
||||||
TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip12.json",
|
TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip12.json",
|
||||||
TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip13.json",
|
TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip13.json",
|
||||||
TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip14.json",
|
TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip14.json",
|
||||||
TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip15.json",
|
TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip15.json",
|
||||||
TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip16.json",
|
TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip16.json",
|
||||||
TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip17.json",
|
TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip17.json",
|
||||||
TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip18.json",
|
TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip18.json",
|
||||||
TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip19.json",
|
TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip19.json",
|
||||||
TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip20.json",
|
TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip20.json",
|
||||||
TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip21.json",
|
TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip21.json",
|
||||||
TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip22.json",
|
TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip22.json",
|
||||||
TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip23.json",
|
TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip23.json",
|
||||||
TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip24.json",
|
TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip24.json",
|
||||||
TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip25.json",
|
TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip25.json",
|
||||||
TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip26.json",
|
TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip26.json",
|
||||||
TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip27.json",
|
TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip27.json",
|
||||||
TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip28.json",
|
TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip28.json",
|
||||||
TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip29.json",
|
TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip29.json",
|
||||||
TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip30.json",
|
TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip30.json",
|
||||||
TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip31.json",
|
TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip31.json",
|
||||||
TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip32.json",
|
TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip32.json",
|
||||||
TEST_DATA_DIRECTORY "/json_testsuite/sample.json", // kills AppVeyor
|
TEST_DATA_DIRECTORY "/json_testsuite/sample.json", // kills AppVeyor
|
||||||
TEST_DATA_DIRECTORY "/json_tests/pass1.json",
|
TEST_DATA_DIRECTORY "/json_tests/pass1.json",
|
||||||
TEST_DATA_DIRECTORY "/json_tests/pass2.json",
|
TEST_DATA_DIRECTORY "/json_tests/pass2.json",
|
||||||
TEST_DATA_DIRECTORY "/json_tests/pass3.json",
|
TEST_DATA_DIRECTORY "/json_tests/pass3.json",
|
||||||
TEST_DATA_DIRECTORY "/regression/floats.json",
|
TEST_DATA_DIRECTORY "/regression/floats.json",
|
||||||
TEST_DATA_DIRECTORY "/regression/signed_ints.json",
|
TEST_DATA_DIRECTORY "/regression/signed_ints.json",
|
||||||
TEST_DATA_DIRECTORY "/regression/unsigned_ints.json",
|
TEST_DATA_DIRECTORY "/regression/unsigned_ints.json",
|
||||||
TEST_DATA_DIRECTORY "/regression/working_file.json",
|
TEST_DATA_DIRECTORY "/regression/working_file.json",
|
||||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_array_arraysWithSpaces.json",
|
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-string.json",
|
||||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_array_empty.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",
|
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_array_ending_with_newline.json",
|
||||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_array_false.json",
|
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_array_false.json",
|
||||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_array_heterogeneous.json",
|
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_array_heterogeneous.json",
|
||||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_array_null.json",
|
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_array_null.json",
|
||||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_array_with_1_and_newline.json",
|
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_array_with_1_and_newline.json",
|
||||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_array_with_leading_space.json",
|
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_array_with_leading_space.json",
|
||||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_array_with_several_null.json",
|
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_array_with_several_null.json",
|
||||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_array_with_trailing_space.json",
|
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_array_with_trailing_space.json",
|
||||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number.json",
|
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number.json",
|
||||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_0e+1.json",
|
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_0e+1.json",
|
||||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_0e1.json",
|
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_0e1.json",
|
||||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_after_space.json",
|
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_after_space.json",
|
||||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_double_close_to_zero.json",
|
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_double_close_to_zero.json",
|
||||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_double_huge_neg_exp.json",
|
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_double_huge_neg_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_huge_exp.json",
|
||||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_int_with_exp.json",
|
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_int_with_exp.json",
|
||||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_minus_zero.json",
|
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_minus_zero.json",
|
||||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_negative_int.json",
|
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_negative_int.json",
|
||||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_negative_one.json",
|
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_negative_one.json",
|
||||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_negative_zero.json",
|
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_negative_zero.json",
|
||||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_real_capital_e.json",
|
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_real_capital_e.json",
|
||||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_real_capital_e_neg_exp.json",
|
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_real_capital_e_neg_exp.json",
|
||||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_real_capital_e_pos_exp.json",
|
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_real_capital_e_pos_exp.json",
|
||||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_real_exponent.json",
|
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_real_exponent.json",
|
||||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_real_fraction_exponent.json",
|
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_real_fraction_exponent.json",
|
||||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_real_neg_exp.json",
|
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_real_neg_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_neg_overflow.json",
|
||||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_real_pos_exponent.json",
|
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_real_pos_exponent.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",
|
||||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_real_underflow.json",
|
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_real_underflow.json",
|
||||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_simple_int.json",
|
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_simple_int.json",
|
||||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_simple_real.json",
|
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_simple_real.json",
|
||||||
//TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_too_big_neg_int.json",
|
//TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_too_big_neg_int.json",
|
||||||
//TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_too_big_pos_int.json",
|
//TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_too_big_pos_int.json",
|
||||||
//TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_very_big_negative_int.json",
|
//TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_very_big_negative_int.json",
|
||||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object.json",
|
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object.json",
|
||||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_basic.json",
|
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_basic.json",
|
||||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_duplicated_key.json",
|
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_duplicated_key.json",
|
||||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_duplicated_key_and_value.json",
|
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_duplicated_key_and_value.json",
|
||||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_empty.json",
|
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_empty.json",
|
||||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_empty_key.json",
|
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_empty_key.json",
|
||||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_escaped_null_in_key.json",
|
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_escaped_null_in_key.json",
|
||||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_extreme_numbers.json",
|
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_extreme_numbers.json",
|
||||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_long_strings.json",
|
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_long_strings.json",
|
||||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_simple.json",
|
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_simple.json",
|
||||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_string_unicode.json",
|
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_string_unicode.json",
|
||||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_with_newlines.json",
|
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_with_newlines.json",
|
||||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_1_2_3_bytes_UTF-8_sequences.json",
|
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_1_2_3_bytes_UTF-8_sequences.json",
|
||||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_UTF-16_Surrogates_U+1D11E_MUSICAL_SYMBOL_G_CLEF.json",
|
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_UTF-16_Surrogates_U+1D11E_MUSICAL_SYMBOL_G_CLEF.json",
|
||||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_accepted_surrogate_pair.json",
|
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_accepted_surrogate_pair.json",
|
||||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_accepted_surrogate_pairs.json",
|
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_accepted_surrogate_pairs.json",
|
||||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_allowed_escapes.json",
|
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_allowed_escapes.json",
|
||||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_backslash_and_u_escaped_zero.json",
|
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_backslash_and_u_escaped_zero.json",
|
||||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_backslash_doublequotes.json",
|
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_backslash_doublequotes.json",
|
||||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_comments.json",
|
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_comments.json",
|
||||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_double_escape_a.json",
|
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_double_escape_a.json",
|
||||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_double_escape_n.json",
|
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_double_escape_n.json",
|
||||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_escaped_control_character.json",
|
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_escaped_control_character.json",
|
||||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_escaped_noncharacter.json",
|
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_escaped_noncharacter.json",
|
||||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_in_array.json",
|
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_in_array.json",
|
||||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_in_array_with_leading_space.json",
|
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_in_array_with_leading_space.json",
|
||||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_last_surrogates_1_and_2.json",
|
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_last_surrogates_1_and_2.json",
|
||||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_newline_uescaped.json",
|
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_newline_uescaped.json",
|
||||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_nonCharacterInUTF-8_U+10FFFF.json",
|
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_nonCharacterInUTF-8_U+10FFFF.json",
|
||||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_nonCharacterInUTF-8_U+1FFFF.json",
|
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_nonCharacterInUTF-8_U+1FFFF.json",
|
||||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_nonCharacterInUTF-8_U+FFFF.json",
|
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_nonCharacterInUTF-8_U+FFFF.json",
|
||||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_null_escape.json",
|
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_null_escape.json",
|
||||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_one-byte-utf-8.json",
|
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_one-byte-utf-8.json",
|
||||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_pi.json",
|
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_pi.json",
|
||||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_simple_ascii.json",
|
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_simple_ascii.json",
|
||||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_space.json",
|
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_space.json",
|
||||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_three-byte-utf-8.json",
|
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_three-byte-utf-8.json",
|
||||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_two-byte-utf-8.json",
|
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_two-byte-utf-8.json",
|
||||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_u+2028_line_sep.json",
|
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_u+2028_line_sep.json",
|
||||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_u+2029_par_sep.json",
|
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_u+2029_par_sep.json",
|
||||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_uEscape.json",
|
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_uEscape.json",
|
||||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_unescaped_char_delete.json",
|
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_unescaped_char_delete.json",
|
||||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_unicode.json",
|
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_unicode.json",
|
||||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_unicodeEscapedBackslash.json",
|
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_unicodeEscapedBackslash.json",
|
||||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_unicode_2.json",
|
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_unicode_2.json",
|
||||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_unicode_U+200B_ZERO_WIDTH_SPACE.json",
|
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_unicode_U+200B_ZERO_WIDTH_SPACE.json",
|
||||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_unicode_U+2064_invisible_plus.json",
|
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_unicode_U+2064_invisible_plus.json",
|
||||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_unicode_escaped_double_quote.json",
|
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_unicode_escaped_double_quote.json",
|
||||||
// TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_utf16.json",
|
// TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_utf16.json",
|
||||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_utf8.json",
|
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_utf8.json",
|
||||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_with_del_character.json",
|
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_with_del_character.json",
|
||||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_structure_lonely_false.json",
|
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_structure_lonely_false.json",
|
||||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_structure_lonely_int.json",
|
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_structure_lonely_int.json",
|
||||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_structure_lonely_negative_real.json",
|
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_structure_lonely_negative_real.json",
|
||||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_structure_lonely_null.json",
|
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_structure_lonely_null.json",
|
||||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_structure_lonely_string.json",
|
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_structure_lonely_string.json",
|
||||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_structure_lonely_true.json",
|
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_structure_lonely_true.json",
|
||||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_structure_string_empty.json",
|
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_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_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)
|
CAPTURE(filename)
|
||||||
|
|
||||||
@ -1802,7 +1798,7 @@ TEST_CASE("MessagePack roundtrips" * doctest::skip())
|
|||||||
// parse MessagePack file
|
// parse MessagePack file
|
||||||
auto packed = utils::read_binary_file(filename + ".msgpack");
|
auto packed = utils::read_binary_file(filename + ".msgpack");
|
||||||
json j2;
|
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
|
// compare parsed JSON values
|
||||||
CHECK(j1 == j2);
|
CHECK(j1 == j2);
|
||||||
|
@ -48,7 +48,7 @@ TEST_CASE("check_for_mem_leak_on_adl_to_json-1")
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
const nlohmann::json j = Foo{1, 0};
|
const nlohmann::json j = Foo{ 1, 0 };
|
||||||
std::cout << j.dump() << "\n";
|
std::cout << j.dump() << "\n";
|
||||||
}
|
}
|
||||||
catch (...) // NOLINT(bugprone-empty-catch)
|
catch (...) // NOLINT(bugprone-empty-catch)
|
||||||
@ -61,7 +61,7 @@ TEST_CASE("check_for_mem_leak_on_adl_to_json-2")
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
const nlohmann::json j = Foo{1, 1};
|
const nlohmann::json j = Foo{ 1, 1 };
|
||||||
std::cout << j.dump() << "\n";
|
std::cout << j.dump() << "\n";
|
||||||
}
|
}
|
||||||
catch (...) // NOLINT(bugprone-empty-catch)
|
catch (...) // NOLINT(bugprone-empty-catch)
|
||||||
@ -74,7 +74,7 @@ TEST_CASE("check_for_mem_leak_on_adl_to_json-2")
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
const nlohmann::json j = Foo{1, 2};
|
const nlohmann::json j = Foo{ 1, 2 };
|
||||||
std::cout << j.dump() << "\n";
|
std::cout << j.dump() << "\n";
|
||||||
}
|
}
|
||||||
catch (...) // NOLINT(bugprone-empty-catch)
|
catch (...) // NOLINT(bugprone-empty-catch)
|
||||||
|
@ -45,11 +45,11 @@ TEST_CASE("ordered_json")
|
|||||||
CHECK(oj.dump() == "{\"element3\":3,\"element2\":2}");
|
CHECK(oj.dump() == "{\"element3\":3,\"element2\":2}");
|
||||||
|
|
||||||
// There are no dup keys cause constructor calls emplace...
|
// 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.size() == 3);
|
||||||
CHECK(multi.dump() == "{\"m\":2,\"y\":4,\"z\":1}");
|
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.size() == 3);
|
||||||
CHECK(multi_ordered.dump() == "{\"z\":1,\"m\":2,\"y\":4}");
|
CHECK(multi_ordered.dump() == "{\"z\":1,\"m\":2,\"y\":4}");
|
||||||
CHECK(multi_ordered.erase("m") == 1);
|
CHECK(multi_ordered.erase("m") == 1);
|
||||||
@ -57,14 +57,14 @@ TEST_CASE("ordered_json")
|
|||||||
|
|
||||||
// Ranged insert test.
|
// Ranged insert test.
|
||||||
// It seems that values shouldn't be overwritten. Only new values are added
|
// It seems that values shouldn't be overwritten. Only new values are added
|
||||||
json j1{{"c", 1}, {"b", 2}, {"a", 3}};
|
json j1{ { "c", 1 }, { "b", 2 }, { "a", 3 } };
|
||||||
const json j2{{"c", 77}, {"d", 42}, {"a", 4}};
|
const json j2{ { "c", 77 }, { "d", 42 }, { "a", 4 } };
|
||||||
j1.insert(j2.cbegin(), j2.cend());
|
j1.insert(j2.cbegin(), j2.cend());
|
||||||
CHECK(j1.size() == 4);
|
CHECK(j1.size() == 4);
|
||||||
CHECK(j1.dump() == "{\"a\":3,\"b\":2,\"c\":1,\"d\":42}");
|
CHECK(j1.dump() == "{\"a\":3,\"b\":2,\"c\":1,\"d\":42}");
|
||||||
|
|
||||||
ordered_json oj1{{"c", 1}, {"b", 2}, {"a", 3}};
|
ordered_json oj1{ { "c", 1 }, { "b", 2 }, { "a", 3 } };
|
||||||
const ordered_json oj2{{"c", 77}, {"d", 42}, {"a", 4}};
|
const ordered_json oj2{ { "c", 77 }, { "d", 42 }, { "a", 4 } };
|
||||||
oj1.insert(oj2.cbegin(), oj2.cend());
|
oj1.insert(oj2.cbegin(), oj2.cend());
|
||||||
CHECK(oj1.size() == 4);
|
CHECK(oj1.size() == 4);
|
||||||
CHECK(oj1.dump() == "{\"c\":1,\"b\":2,\"a\":3,\"d\":42}");
|
CHECK(oj1.dump() == "{\"c\":1,\"b\":2,\"a\":3,\"d\":42}");
|
||||||
|
@ -17,14 +17,14 @@ TEST_CASE("ordered_map")
|
|||||||
{
|
{
|
||||||
SECTION("constructor from iterator range")
|
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());
|
ordered_map<std::string, std::string> const om(m.begin(), m.end());
|
||||||
CHECK(om.size() == 3);
|
CHECK(om.size() == 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("copy assignment")
|
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());
|
ordered_map<std::string, std::string> om(m.begin(), m.end());
|
||||||
const auto com = om;
|
const auto com = om;
|
||||||
om.clear(); // silence a warning by forbidding having "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")
|
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());
|
ordered_map<std::string, std::string> om(m.begin(), m.end());
|
||||||
const auto com = om;
|
const auto com = om;
|
||||||
|
|
||||||
@ -67,7 +67,7 @@ TEST_CASE("ordered_map")
|
|||||||
|
|
||||||
SECTION("operator[]")
|
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());
|
ordered_map<std::string, std::string> om(m.begin(), m.end());
|
||||||
const auto com = om;
|
const auto com = om;
|
||||||
|
|
||||||
@ -280,8 +280,8 @@ TEST_CASE("ordered_map")
|
|||||||
|
|
||||||
SECTION("const value_type&")
|
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 vt1{ "eins", "1" };
|
||||||
ordered_map<std::string, std::string>::value_type const vt4{"vier", "four"};
|
ordered_map<std::string, std::string>::value_type const vt4{ "vier", "four" };
|
||||||
|
|
||||||
auto res1 = om.insert(vt1);
|
auto res1 = om.insert(vt1);
|
||||||
CHECK(res1.first == om.begin());
|
CHECK(res1.first == om.begin());
|
||||||
@ -296,12 +296,12 @@ TEST_CASE("ordered_map")
|
|||||||
|
|
||||||
SECTION("value_type&&")
|
SECTION("value_type&&")
|
||||||
{
|
{
|
||||||
auto res1 = om.insert({"eins", "1"});
|
auto res1 = om.insert({ "eins", "1" });
|
||||||
CHECK(res1.first == om.begin());
|
CHECK(res1.first == om.begin());
|
||||||
CHECK(res1.second == false);
|
CHECK(res1.second == false);
|
||||||
CHECK(om.size() == 3);
|
CHECK(om.size() == 3);
|
||||||
|
|
||||||
auto res4 = om.insert({"vier", "four"});
|
auto res4 = om.insert({ "vier", "four" });
|
||||||
CHECK(res4.first == om.begin() + 3);
|
CHECK(res4.first == om.begin() + 3);
|
||||||
CHECK(res4.second == true);
|
CHECK(res4.second == true);
|
||||||
CHECK(om.size() == 4);
|
CHECK(om.size() == 4);
|
||||||
|
@ -16,7 +16,7 @@ TEST_CASE("pointer access")
|
|||||||
SECTION("pointer access to object_t")
|
SECTION("pointer access to object_t")
|
||||||
{
|
{
|
||||||
using test_type = json::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
|
// check if pointers are returned correctly
|
||||||
test_type* p1 = value.get_ptr<test_type*>();
|
test_type* p1 = value.get_ptr<test_type*>();
|
||||||
@ -45,7 +45,7 @@ TEST_CASE("pointer access")
|
|||||||
SECTION("pointer access to const object_t")
|
SECTION("pointer access to const object_t")
|
||||||
{
|
{
|
||||||
using test_type = const json::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
|
// check if pointers are returned correctly
|
||||||
test_type* p1 = value.get_ptr<test_type*>();
|
test_type* p1 = value.get_ptr<test_type*>();
|
||||||
@ -74,7 +74,7 @@ TEST_CASE("pointer access")
|
|||||||
SECTION("pointer access to array_t")
|
SECTION("pointer access to array_t")
|
||||||
{
|
{
|
||||||
using test_type = json::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
|
// check if pointers are returned correctly
|
||||||
test_type* p1 = value.get_ptr<test_type*>();
|
test_type* p1 = value.get_ptr<test_type*>();
|
||||||
@ -103,7 +103,7 @@ TEST_CASE("pointer access")
|
|||||||
SECTION("pointer access to const array_t")
|
SECTION("pointer access to const array_t")
|
||||||
{
|
{
|
||||||
using test_type = const json::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
|
// check if pointers are returned correctly
|
||||||
test_type* p1 = value.get_ptr<test_type*>();
|
test_type* p1 = value.get_ptr<test_type*>();
|
||||||
@ -422,7 +422,7 @@ TEST_CASE("pointer access")
|
|||||||
SECTION("pointer access to const binary_t")
|
SECTION("pointer access to const binary_t")
|
||||||
{
|
{
|
||||||
using test_type = const json::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
|
// check if pointers are returned correctly
|
||||||
test_type* p1 = value.get_ptr<test_type*>();
|
test_type* p1 = value.get_ptr<test_type*>();
|
||||||
|
@ -55,24 +55,24 @@ TEST_CASE("README" * doctest::skip())
|
|||||||
j["answer"]["everything"] = 42;
|
j["answer"]["everything"] = 42;
|
||||||
|
|
||||||
// add an array that is stored as std::vector (using an initializer list)
|
// 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)
|
// 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)
|
// instead, you could also write (which looks very similar to the JSON above)
|
||||||
json const j2 = {{"pi", 3.141},
|
json const j2 = { { "pi", 3.141 },
|
||||||
{"happy", true},
|
{ "happy", true },
|
||||||
{"name", "Niels"},
|
{ "name", "Niels" },
|
||||||
{"nothing", nullptr},
|
{ "nothing", nullptr },
|
||||||
{"answer", {{"everything", 42}}},
|
{ "answer", { { "everything", 42 } } },
|
||||||
{"list", {1, 0, 2}},
|
{ "list", { 1, 0, 2 } },
|
||||||
{"object", {{"currency", "USD"}, {"value", 42.99}}}};
|
{ "object", { { "currency", "USD" }, { "value", 42.99 } } } };
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
// ways to express the empty array []
|
// ways to express the empty array []
|
||||||
json const empty_array_implicit = {{}};
|
json const empty_array_implicit = { {} };
|
||||||
CHECK(empty_array_implicit.is_array());
|
CHECK(empty_array_implicit.is_array());
|
||||||
json const empty_array_explicit = json::array();
|
json const empty_array_explicit = json::array();
|
||||||
CHECK(empty_array_explicit.is_array());
|
CHECK(empty_array_explicit.is_array());
|
||||||
@ -82,7 +82,7 @@ TEST_CASE("README" * doctest::skip())
|
|||||||
CHECK(empty_object_explicit.is_object());
|
CHECK(empty_object_explicit.is_object());
|
||||||
|
|
||||||
// a way to express an _array_ of key/value pairs [["currency", "USD"], ["value", 42.99]]
|
// 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.is_array());
|
||||||
CHECK(array_not_object.size() == 2);
|
CHECK(array_not_object.size() == 2);
|
||||||
CHECK(array_not_object[0].is_array());
|
CHECK(array_not_object[0].is_array());
|
||||||
@ -142,7 +142,7 @@ TEST_CASE("README" * doctest::skip())
|
|||||||
// getter/setter
|
// getter/setter
|
||||||
const auto tmp = j[0].get<std::string>();
|
const auto tmp = j[0].get<std::string>();
|
||||||
j[1] = 42;
|
j[1] = 42;
|
||||||
bool foo{j.at(2)};
|
bool foo{ j.at(2) };
|
||||||
CHECK(foo == true);
|
CHECK(foo == true);
|
||||||
|
|
||||||
// other stuff
|
// 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);
|
json const j_vec(c_vector);
|
||||||
// [1, 2, 3, 4]
|
// [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);
|
json const j_deque(c_deque);
|
||||||
// [1.2, 2.3, 3.4, 5.6]
|
// [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);
|
json const j_list(c_list);
|
||||||
// [true, true, false, true]
|
// [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);
|
json const j_flist(c_flist);
|
||||||
// [12345678909876, 23456789098765, 34567890987654, 45678909876543]
|
// [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);
|
json const j_array(c_array);
|
||||||
// [1, 2, 3, 4]
|
// [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
|
json const j_set(c_set); // only one entry for "one" is used
|
||||||
// ["four", "one", "three", "two"]
|
// ["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
|
json const j_uset(c_uset); // only one entry for "one" is used
|
||||||
// maybe ["two", "three", "four", "one"]
|
// 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
|
json const j_mset(c_mset); // both entries for "one" are used
|
||||||
// maybe ["one", "two", "one", "four"]
|
// 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
|
json const j_umset(c_umset); // both entries for "one" are used
|
||||||
// maybe ["one", "two", "one", "four"]
|
// 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);
|
json const j_map(c_map);
|
||||||
// {"one": 1, "two": 2, "three": 3}
|
// {"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);
|
json const j_umap(c_umap);
|
||||||
// {"one": 1.2, "two": 2.3, "three": 3.4}
|
// {"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
|
json const j_mmap(c_mmap); // only one entry for key "three" is used
|
||||||
// maybe {"one": true, "two": true, "three": true}
|
// 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
|
json const j_ummap(c_ummap); // only one entry for key "three" is used
|
||||||
// maybe {"one": true, "two": true, "three": true}
|
// maybe {"one": true, "two": true, "three": true}
|
||||||
}
|
}
|
||||||
@ -230,13 +230,13 @@ TEST_CASE("README" * doctest::skip())
|
|||||||
// Booleans
|
// Booleans
|
||||||
bool const b1 = true;
|
bool const b1 = true;
|
||||||
json const jb = b1;
|
json const jb = b1;
|
||||||
bool b2{jb};
|
bool b2{ jb };
|
||||||
CHECK(b2 == true);
|
CHECK(b2 == true);
|
||||||
|
|
||||||
// numbers
|
// numbers
|
||||||
int const i = 42;
|
int const i = 42;
|
||||||
json const jn = i;
|
json const jn = i;
|
||||||
double f{jn};
|
double f{ jn };
|
||||||
CHECK(f == 42);
|
CHECK(f == 42);
|
||||||
|
|
||||||
// etc.
|
// etc.
|
||||||
|
@ -14,16 +14,16 @@ using nlohmann::json;
|
|||||||
TEST_CASE("reference access")
|
TEST_CASE("reference access")
|
||||||
{
|
{
|
||||||
// create a JSON value with different types
|
// create a JSON value with different types
|
||||||
const json json_types = {{"boolean", true},
|
const json json_types = { { "boolean", true },
|
||||||
{"number", {{"integer", 42}, {"floating-point", 17.23}}},
|
{ "number", { { "integer", 42 }, { "floating-point", 17.23 } } },
|
||||||
{"string", "Hello, world!"},
|
{ "string", "Hello, world!" },
|
||||||
{"array", {1, 2, 3, 4, 5}},
|
{ "array", { 1, 2, 3, 4, 5 } },
|
||||||
{"null", nullptr}};
|
{ "null", nullptr } };
|
||||||
|
|
||||||
SECTION("reference access to object_t")
|
SECTION("reference access to object_t")
|
||||||
{
|
{
|
||||||
using test_type = json::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
|
// check if references are returned correctly
|
||||||
auto& p1 = value.get_ref<test_type&>();
|
auto& p1 = value.get_ref<test_type&>();
|
||||||
@ -59,7 +59,7 @@ TEST_CASE("reference access")
|
|||||||
SECTION("const reference access to const object_t")
|
SECTION("const reference access to const object_t")
|
||||||
{
|
{
|
||||||
using test_type = json::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
|
// this should not compile
|
||||||
// test_type& p1 = value.get_ref<test_type&>();
|
// test_type& p1 = value.get_ref<test_type&>();
|
||||||
@ -73,7 +73,7 @@ TEST_CASE("reference access")
|
|||||||
SECTION("reference access to array_t")
|
SECTION("reference access to array_t")
|
||||||
{
|
{
|
||||||
using test_type = json::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
|
// check if references are returned correctly
|
||||||
auto& p1 = value.get_ref<test_type&>();
|
auto& p1 = value.get_ref<test_type&>();
|
||||||
|
@ -59,7 +59,7 @@ struct foo_serializer<T, typename std::enable_if<std::is_same<foo, T>::value>::t
|
|||||||
template<typename BasicJsonType>
|
template<typename BasicJsonType>
|
||||||
static void to_json(BasicJsonType& j, const T& value)
|
static void to_json(BasicJsonType& j, const T& value)
|
||||||
{
|
{
|
||||||
j = BasicJsonType{{"x", value.x}};
|
j = BasicJsonType{ { "x", value.x } };
|
||||||
}
|
}
|
||||||
template<typename BasicJsonType>
|
template<typename BasicJsonType>
|
||||||
static void from_json(const BasicJsonType& j, T& value) // !!!
|
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)
|
friend void to_json(json& j, const nocopy& n)
|
||||||
{
|
{
|
||||||
j = {{"val", n.val}};
|
j = { { "val", n.val } };
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
} // namespace
|
} // namespace
|
||||||
@ -146,12 +146,12 @@ TEST_CASE("regression tests 1")
|
|||||||
{
|
{
|
||||||
json const j1 = NAN;
|
json const j1 = NAN;
|
||||||
CHECK(j1.is_number_float());
|
CHECK(j1.is_number_float());
|
||||||
json::number_float_t const f1{j1};
|
json::number_float_t const f1{ j1 };
|
||||||
CHECK(std::isnan(f1));
|
CHECK(std::isnan(f1));
|
||||||
|
|
||||||
json const j2 = static_cast<json::number_float_t>(NAN);
|
json const j2 = static_cast<json::number_float_t>(NAN);
|
||||||
CHECK(j2.is_number_float());
|
CHECK(j2.is_number_float());
|
||||||
json::number_float_t const f2{j2};
|
json::number_float_t const f2{ j2 };
|
||||||
CHECK(std::isnan(f2));
|
CHECK(std::isnan(f2));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -159,12 +159,12 @@ TEST_CASE("regression tests 1")
|
|||||||
{
|
{
|
||||||
json const j1 = INFINITY;
|
json const j1 = INFINITY;
|
||||||
CHECK(j1.is_number_float());
|
CHECK(j1.is_number_float());
|
||||||
json::number_float_t const f1{j1};
|
json::number_float_t const f1{ j1 };
|
||||||
CHECK(!std::isfinite(f1));
|
CHECK(!std::isfinite(f1));
|
||||||
|
|
||||||
json const j2 = static_cast<json::number_float_t>(INFINITY);
|
json const j2 = static_cast<json::number_float_t>(INFINITY);
|
||||||
CHECK(j2.is_number_float());
|
CHECK(j2.is_number_float());
|
||||||
json::number_float_t const f2{j2};
|
json::number_float_t const f2{ j2 };
|
||||||
CHECK(!std::isfinite(f2));
|
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");
|
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")
|
SECTION("issue #76 - dump() / parse() not idempotent")
|
||||||
@ -241,9 +241,9 @@ TEST_CASE("regression tests 1")
|
|||||||
|
|
||||||
auto test = j["Test"].get<std::string>();
|
auto test = j["Test"].get<std::string>();
|
||||||
CHECK(test == "Test1");
|
CHECK(test == "Test1");
|
||||||
int number{j["Number"]};
|
int number{ j["Number"] };
|
||||||
CHECK(number == 100);
|
CHECK(number == 100);
|
||||||
float foo{j["Foo"]};
|
float foo{ j["Foo"] };
|
||||||
CHECK(static_cast<double>(foo) == Approx(42.42));
|
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")
|
SECTION("issue #93 reverse_iterator operator inheritance problem")
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
json a = {1, 2, 3};
|
json a = { 1, 2, 3 };
|
||||||
json::reverse_iterator rit = a.rbegin();
|
json::reverse_iterator rit = a.rbegin();
|
||||||
++rit;
|
++rit;
|
||||||
CHECK(*rit == json(2));
|
CHECK(*rit == json(2));
|
||||||
CHECK(rit.value() == json(2));
|
CHECK(rit.value() == json(2));
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
json a = {1, 2, 3};
|
json a = { 1, 2, 3 };
|
||||||
json::reverse_iterator const rit = ++a.rbegin();
|
json::reverse_iterator const rit = ++a.rbegin();
|
||||||
CHECK(*rit == json(2));
|
CHECK(*rit == json(2));
|
||||||
CHECK(rit.value() == json(2));
|
CHECK(rit.value() == json(2));
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
json a = {1, 2, 3};
|
json a = { 1, 2, 3 };
|
||||||
json::reverse_iterator rit = a.rbegin();
|
json::reverse_iterator rit = a.rbegin();
|
||||||
++rit;
|
++rit;
|
||||||
json b = {0, 0, 0};
|
json b = { 0, 0, 0 };
|
||||||
std::transform(rit, a.rend(), b.rbegin(), [](json el) {
|
std::transform(rit, a.rend(), b.rbegin(), [](json el) {
|
||||||
return el;
|
return el;
|
||||||
});
|
});
|
||||||
CHECK(b == json({0, 1, 2}));
|
CHECK(b == json({ 0, 1, 2 }));
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
json a = {1, 2, 3};
|
json a = { 1, 2, 3 };
|
||||||
json b = {0, 0, 0};
|
json b = { 0, 0, 0 };
|
||||||
std::transform(++a.rbegin(), a.rend(), b.rbegin(), [](json el) {
|
std::transform(++a.rbegin(), a.rend(), b.rbegin(), [](json el) {
|
||||||
return 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")
|
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;
|
std::stringstream ss;
|
||||||
|
|
||||||
@ -335,9 +335,9 @@ TEST_CASE("regression tests 1")
|
|||||||
SECTION("issue #101 - binary string causes numbers to be dumped as hex")
|
SECTION("issue #101 - binary string causes numbers to be dumped as hex")
|
||||||
{
|
{
|
||||||
int64_t const number = 10;
|
int64_t const number = 10;
|
||||||
std::string const bytes{"\x00"
|
std::string const bytes{ "\x00"
|
||||||
"asdf\n",
|
"asdf\n",
|
||||||
6};
|
6 };
|
||||||
json j;
|
json j;
|
||||||
j["int64"] = number;
|
j["int64"] = number;
|
||||||
j["binary string"] = bytes;
|
j["binary string"] = bytes;
|
||||||
@ -348,7 +348,7 @@ TEST_CASE("regression tests 1")
|
|||||||
|
|
||||||
SECTION("issue #111 - subsequent unicode chars")
|
SECTION("issue #111 - subsequent unicode chars")
|
||||||
{
|
{
|
||||||
std::string const bytes{0x7, 0x7};
|
std::string const bytes{ 0x7, 0x7 };
|
||||||
json j;
|
json j;
|
||||||
j["string"] = bytes;
|
j["string"] = bytes;
|
||||||
CHECK(j["string"] == "\u0007\u0007");
|
CHECK(j["string"] == "\u0007\u0007");
|
||||||
@ -357,7 +357,7 @@ TEST_CASE("regression tests 1")
|
|||||||
#if JSON_USE_IMPLICIT_CONVERSIONS
|
#if JSON_USE_IMPLICIT_CONVERSIONS
|
||||||
SECTION("issue #144 - implicit assignment to std::string fails")
|
SECTION("issue #144 - implicit assignment to std::string fails")
|
||||||
{
|
{
|
||||||
json o = {{"name", "value"}};
|
json o = { { "name", "value" } };
|
||||||
|
|
||||||
std::string s1 = o["name"];
|
std::string s1 = o["name"];
|
||||||
CHECK(s1 == "value");
|
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")
|
SECTION("issue #233 - Can't use basic_json::iterator as a base iterator for std::move_iterator")
|
||||||
{
|
{
|
||||||
json source = {"a", "b", "c"};
|
json source = { "a", "b", "c" };
|
||||||
json expected = {"a", "b"};
|
json expected = { "a", "b" };
|
||||||
json dest;
|
json dest;
|
||||||
|
|
||||||
std::copy_n(std::make_move_iterator(source.begin()), 2, std::back_inserter(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+='")
|
SECTION("issue #235 - ambiguous overload for 'push_back' and 'operator+='")
|
||||||
{
|
{
|
||||||
json data = {{"key", "value"}};
|
json data = { { "key", "value" } };
|
||||||
data.push_back({"key2", "value2"});
|
data.push_back({ "key2", "value2" });
|
||||||
data += {"key3", "value3"};
|
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")
|
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")
|
SECTION("issue #283 - value() does not work with _json_pointer types")
|
||||||
{
|
{
|
||||||
json j = {
|
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);
|
int val_integer = j.value("/object/key2"_json_pointer, 0);
|
||||||
|
|
||||||
CHECK(at_integer == val_integer);
|
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")
|
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)
|
CAPTURE(filename)
|
||||||
json j;
|
json j;
|
||||||
@ -619,10 +619,10 @@ TEST_CASE("regression tests 1")
|
|||||||
|
|
||||||
SECTION("issue #310 - make json_benchmarks no longer working in 2.0.4")
|
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/signed_ints.json",
|
||||||
TEST_DATA_DIRECTORY "/regression/unsigned_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)
|
CAPTURE(filename)
|
||||||
json j;
|
json j;
|
||||||
@ -635,7 +635,7 @@ TEST_CASE("regression tests 1")
|
|||||||
{
|
{
|
||||||
json j;
|
json j;
|
||||||
j["/this/that/2"_json_pointer] = 27;
|
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")
|
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}";
|
ss << "{\n \"one\" : 1,\n \"two\" : 2\n}\n{\n \"three\" : 3\n}";
|
||||||
json j;
|
json j;
|
||||||
CHECK_NOTHROW(ss >> j);
|
CHECK_NOTHROW(ss >> j);
|
||||||
CHECK(j == json({{"one", 1}, {"two", 2}}));
|
CHECK(j == json({ { "one", 1 }, { "two", 2 } }));
|
||||||
CHECK_NOTHROW(ss >> j);
|
CHECK_NOTHROW(ss >> j);
|
||||||
CHECK(j == json({{"three", 3}}));
|
CHECK(j == json({ { "three", 3 } }));
|
||||||
|
|
||||||
CHECK_THROWS_WITH_AS(
|
CHECK_THROWS_WITH_AS(
|
||||||
ss >> j,
|
ss >> j,
|
||||||
@ -869,12 +869,12 @@ TEST_CASE("regression tests 1")
|
|||||||
|
|
||||||
if (i == 0)
|
if (i == 0)
|
||||||
{
|
{
|
||||||
CHECK(val == json({{"one", 1}, {"two", 2}}));
|
CHECK(val == json({ { "one", 1 }, { "two", 2 } }));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (i == 1)
|
if (i == 1)
|
||||||
{
|
{
|
||||||
CHECK(val == json({{"three", 3}}));
|
CHECK(val == json({ { "three", 3 } }));
|
||||||
}
|
}
|
||||||
|
|
||||||
++i;
|
++i;
|
||||||
@ -911,7 +911,7 @@ TEST_CASE("regression tests 1")
|
|||||||
SECTION("issue #405 - Heap-buffer-overflow (OSS-Fuzz issue 342)")
|
SECTION("issue #405 - Heap-buffer-overflow (OSS-Fuzz issue 342)")
|
||||||
{
|
{
|
||||||
// original test case
|
// 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 _;
|
json _;
|
||||||
CHECK_THROWS_WITH_AS(_ = json::from_cbor(vec),
|
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",
|
"[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 _;
|
json _;
|
||||||
|
|
||||||
// original test case: incomplete float64
|
// 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),
|
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.exception.parse_error.110] parse error at byte 4: syntax error while parsing MessagePack number: unexpected end of input",
|
||||||
json::parse_error&);
|
json::parse_error&);
|
||||||
|
|
||||||
// related test case: incomplete float32
|
// 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),
|
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.exception.parse_error.110] parse error at byte 4: syntax error while parsing MessagePack number: unexpected end of input",
|
||||||
json::parse_error&);
|
json::parse_error&);
|
||||||
|
|
||||||
// related test case: incomplete Half-Precision Float (CBOR)
|
// 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),
|
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.exception.parse_error.110] parse error at byte 3: syntax error while parsing CBOR number: unexpected end of input",
|
||||||
json::parse_error&);
|
json::parse_error&);
|
||||||
|
|
||||||
// related test case: incomplete Single-Precision Float (CBOR)
|
// 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),
|
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.exception.parse_error.110] parse error at byte 4: syntax error while parsing CBOR number: unexpected end of input",
|
||||||
json::parse_error&);
|
json::parse_error&);
|
||||||
|
|
||||||
// related test case: incomplete Double-Precision Float (CBOR)
|
// 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),
|
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.exception.parse_error.110] parse error at byte 4: syntax error while parsing CBOR number: unexpected end of input",
|
||||||
json::parse_error&);
|
json::parse_error&);
|
||||||
@ -958,19 +958,19 @@ TEST_CASE("regression tests 1")
|
|||||||
json _;
|
json _;
|
||||||
|
|
||||||
// original test case
|
// 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),
|
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.exception.parse_error.110] parse error at byte 2: syntax error while parsing MessagePack string: unexpected end of input",
|
||||||
json::parse_error&);
|
json::parse_error&);
|
||||||
|
|
||||||
// more test cases for MessagePack
|
// 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
|
0x8f, // fixmap
|
||||||
0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e,
|
0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e,
|
||||||
0x9f, // fixarray
|
0x9f, // fixarray
|
||||||
0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae,
|
0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae,
|
||||||
0xaf, // fixstr
|
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));
|
std::vector<uint8_t> const vec(1, static_cast<uint8_t>(b));
|
||||||
CHECK_THROWS_AS(_ = json::from_msgpack(vec), json::parse_error&);
|
CHECK_THROWS_AS(_ = json::from_msgpack(vec), json::parse_error&);
|
||||||
@ -1005,19 +1005,19 @@ TEST_CASE("regression tests 1")
|
|||||||
json _;
|
json _;
|
||||||
|
|
||||||
// original test case: empty UTF-8 string (indefinite length)
|
// 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),
|
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.exception.parse_error.110] parse error at byte 2: syntax error while parsing CBOR string: unexpected end of input",
|
||||||
json::parse_error&);
|
json::parse_error&);
|
||||||
|
|
||||||
// related test case: empty array (indefinite length)
|
// 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),
|
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.exception.parse_error.110] parse error at byte 2: syntax error while parsing CBOR value: unexpected end of input",
|
||||||
json::parse_error&);
|
json::parse_error&);
|
||||||
|
|
||||||
// related test case: empty map (indefinite length)
|
// 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),
|
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.exception.parse_error.110] parse error at byte 2: syntax error while parsing CBOR string: unexpected end of input",
|
||||||
json::parse_error&);
|
json::parse_error&);
|
||||||
@ -1026,13 +1026,13 @@ TEST_CASE("regression tests 1")
|
|||||||
SECTION("issue #412 - Heap-buffer-overflow (OSS-Fuzz issue 367)")
|
SECTION("issue #412 - Heap-buffer-overflow (OSS-Fuzz issue 367)")
|
||||||
{
|
{
|
||||||
// original test case
|
// 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,
|
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, 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, 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, 0x60, 0x60, 0x60, 0x60};
|
0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60 };
|
||||||
|
|
||||||
json _;
|
json _;
|
||||||
CHECK_THROWS_WITH_AS(
|
CHECK_THROWS_WITH_AS(
|
||||||
@ -1041,19 +1041,19 @@ TEST_CASE("regression tests 1")
|
|||||||
json::parse_error&);
|
json::parse_error&);
|
||||||
|
|
||||||
// related test case: nonempty UTF-8 string (indefinite length)
|
// 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),
|
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.exception.parse_error.110] parse error at byte 4: syntax error while parsing CBOR string: unexpected end of input",
|
||||||
json::parse_error&);
|
json::parse_error&);
|
||||||
|
|
||||||
// related test case: nonempty array (indefinite length)
|
// 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),
|
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.exception.parse_error.110] parse error at byte 3: syntax error while parsing CBOR value: unexpected end of input",
|
||||||
json::parse_error&);
|
json::parse_error&);
|
||||||
|
|
||||||
// related test case: nonempty map (indefinite length)
|
// 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),
|
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.exception.parse_error.110] parse error at byte 5: syntax error while parsing CBOR string: unexpected end of input",
|
||||||
json::parse_error&);
|
json::parse_error&);
|
||||||
@ -1080,9 +1080,9 @@ TEST_CASE("regression tests 1")
|
|||||||
SECTION("issue #416 - Use-of-uninitialized-value (OSS-Fuzz issue 377)")
|
SECTION("issue #416 - Use-of-uninitialized-value (OSS-Fuzz issue 377)")
|
||||||
{
|
{
|
||||||
// original test case
|
// 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,
|
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 _;
|
json _;
|
||||||
CHECK_THROWS_WITH_AS(
|
CHECK_THROWS_WITH_AS(
|
||||||
@ -1091,9 +1091,9 @@ TEST_CASE("regression tests 1")
|
|||||||
json::parse_error&);
|
json::parse_error&);
|
||||||
|
|
||||||
// related test case: double-precision
|
// 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,
|
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(
|
CHECK_THROWS_WITH_AS(
|
||||||
_ = json::from_cbor(vec2),
|
_ = 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",
|
"[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)")
|
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 _;
|
json _;
|
||||||
CHECK_THROWS_AS(_ = json::parse(vec), json::parse_error&);
|
CHECK_THROWS_AS(_ = json::parse(vec), json::parse_error&);
|
||||||
}
|
}
|
||||||
@ -1135,7 +1135,7 @@ TEST_CASE("regression tests 1")
|
|||||||
#if JSON_USE_IMPLICIT_CONVERSIONS
|
#if JSON_USE_IMPLICIT_CONVERSIONS
|
||||||
SECTION("issue #473 - inconsistent behavior in conversion to array type")
|
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_number = 42;
|
||||||
json const j_null = nullptr;
|
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")
|
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;
|
json j;
|
||||||
j["bool_vector"] = boolVector;
|
j["bool_vector"] = boolVector;
|
||||||
|
|
||||||
@ -1192,7 +1192,7 @@ TEST_CASE("regression tests 1")
|
|||||||
|
|
||||||
SECTION("issue #504 - assertion error (OSS-Fuzz 856)")
|
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);
|
json const j1 = json::from_cbor(vec1, false);
|
||||||
|
|
||||||
// step 2: round trip
|
// step 2: round trip
|
||||||
@ -1247,7 +1247,7 @@ TEST_CASE("regression tests 1")
|
|||||||
SECTION("issue #575 - heap-buffer-overflow (OSS-Fuzz 1400)")
|
SECTION("issue #575 - heap-buffer-overflow (OSS-Fuzz 1400)")
|
||||||
{
|
{
|
||||||
json _;
|
json _;
|
||||||
std::vector<uint8_t> const vec = {'"', '\\', '"', 'X', '"', '"'};
|
std::vector<uint8_t> const vec = { '"', '\\', '"', 'X', '"', '"' };
|
||||||
CHECK_THROWS_AS(_ = json::parse(vec), json::parse_error&);
|
CHECK_THROWS_AS(_ = json::parse(vec), json::parse_error&);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1257,7 +1257,7 @@ TEST_CASE("regression tests 1")
|
|||||||
SECTION("example 1")
|
SECTION("example 1")
|
||||||
{
|
{
|
||||||
// create a map
|
// 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
|
// create and print a JSON from the map
|
||||||
json const j = m1;
|
json const j = m1;
|
||||||
@ -1272,7 +1272,7 @@ TEST_CASE("regression tests 1")
|
|||||||
SECTION("example 2")
|
SECTION("example 2")
|
||||||
{
|
{
|
||||||
// create a map
|
// 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
|
// create and print a JSON from the map
|
||||||
json const j = m1;
|
json const j = m1;
|
||||||
@ -1305,7 +1305,7 @@ TEST_CASE("regression tests 1")
|
|||||||
|
|
||||||
SECTION("full example")
|
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;
|
json j = v;
|
||||||
std::valarray<double> vj = j;
|
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 m1 = j1.get<std::map<std::string, std::string>>();
|
||||||
auto m2 = j2.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(m1 == (std::map<std::string, std::string>{ { "first", "one" } }));
|
||||||
CHECK(m2 == (std::map<std::string, std::string>{{"second", "two"}}));
|
CHECK(m2 == (std::map<std::string, std::string>{ { "second", "two" } }));
|
||||||
CHECK(i3 == 3);
|
CHECK(i3 == 3);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1371,14 +1371,14 @@ TEST_CASE("regression tests 1")
|
|||||||
{
|
{
|
||||||
nocopy n;
|
nocopy n;
|
||||||
json j;
|
json j;
|
||||||
j = {{"nocopy", n}};
|
j = { { "nocopy", n } };
|
||||||
CHECK(j["nocopy"]["val"] == 0);
|
CHECK(j["nocopy"]["val"] == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("issue #838 - incorrect parse error with binary data in keys")
|
SECTION("issue #838 - incorrect parse error with binary data in keys")
|
||||||
{
|
{
|
||||||
std::array<uint8_t, 28> key1 = {
|
std::array<uint8_t, 28> key1 = { { 103, 92, 117, 48, 48, 48, 55, 92, 114, 215, 126, 214, 95, 92,
|
||||||
{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}};
|
34, 174, 40, 71, 38, 174, 40, 71, 38, 223, 134, 247, 127, 0 } };
|
||||||
std::string const key1_str(reinterpret_cast<char*>(key1.data()));
|
std::string const key1_str(reinterpret_cast<char*>(key1.data()));
|
||||||
json const j = key1_str;
|
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&);
|
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")
|
SECTION("issue #843 - converting to array not working")
|
||||||
{
|
{
|
||||||
json j;
|
json j;
|
||||||
std::array<int, 4> ar = {{1, 1, 1, 1}};
|
std::array<int, 4> ar = { { 1, 1, 1, 1 } };
|
||||||
j = ar;
|
j = ar;
|
||||||
ar = j;
|
ar = j;
|
||||||
}
|
}
|
||||||
@ -1418,7 +1418,7 @@ TEST_CASE("regression tests 1")
|
|||||||
|
|
||||||
SECTION("issue #961 - incorrect parsing of indefinite length CBOR strings")
|
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);
|
json j = json::from_cbor(v_cbor);
|
||||||
CHECK(j == "abcd123");
|
CHECK(j == "abcd123");
|
||||||
}
|
}
|
||||||
@ -1426,7 +1426,7 @@ TEST_CASE("regression tests 1")
|
|||||||
SECTION("issue #962 - Timeout (OSS-Fuzz 6034)")
|
SECTION("issue #962 - Timeout (OSS-Fuzz 6034)")
|
||||||
{
|
{
|
||||||
json _;
|
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_AS(_ = json::from_ubjson(v_ubjson), json::out_of_range&);
|
||||||
//CHECK_THROWS_WITH(json::from_ubjson(v_ubjson),
|
//CHECK_THROWS_WITH(json::from_ubjson(v_ubjson),
|
||||||
// "[json.exception.out_of_range.408] excessive array size: 8658170730974374167");
|
// "[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")
|
SECTION("issue #977 - Assigning between different json types")
|
||||||
{
|
{
|
||||||
foo_json lj = ns::foo{3};
|
foo_json lj = ns::foo{ 3 };
|
||||||
ns::foo ff(lj);
|
ns::foo ff(lj);
|
||||||
CHECK(lj.is_object());
|
CHECK(lj.is_object());
|
||||||
CHECK(lj.size() == 1);
|
CHECK(lj.size() == 1);
|
||||||
|
@ -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
|
// NOLINTNEXTLINE(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays): this is a false positive
|
||||||
NLOHMANN_JSON_SERIALIZE_ENUM(for_1647,
|
NLOHMANN_JSON_SERIALIZE_ENUM(for_1647,
|
||||||
{
|
{
|
||||||
{for_1647::one, "one"},
|
{ for_1647::one, "one" },
|
||||||
{for_1647::two, "two"},
|
{ for_1647::two, "two" },
|
||||||
})
|
})
|
||||||
} // namespace
|
} // 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_msgpack(float_json::to_msgpack(j)) == j);
|
||||||
CHECK(float_json::from_ubjson(float_json::to_ubjson(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);
|
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?")
|
SECTION("issue #1045 - Using STL algorithms with JSON containers with expected results?")
|
||||||
{
|
{
|
||||||
json diffs = nlohmann::json::array();
|
json diffs = nlohmann::json::array();
|
||||||
json m1{{"key1", 42}};
|
json m1{ { "key1", 42 } };
|
||||||
json m2{{"key2", 42}};
|
json m2{ { "key2", 42 } };
|
||||||
auto p1 = m1.items();
|
auto p1 = m1.items();
|
||||||
auto p2 = m2.items();
|
auto p2 = m2.items();
|
||||||
|
|
||||||
@ -451,15 +451,15 @@ TEST_CASE("regression tests 2")
|
|||||||
"with std::pair")
|
"with std::pair")
|
||||||
{
|
{
|
||||||
const json j = {
|
const json j = {
|
||||||
{"1", {{"a", "testa_1"}, {"b", "testb_1"}}},
|
{ "1", { { "a", "testa_1" }, { "b", "testb_1" } } },
|
||||||
{"2", {{"a", "testa_2"}, {"b", "testb_2"}}},
|
{ "2", { { "a", "testa_2" }, { "b", "testb_2" } } },
|
||||||
{"3", {{"a", "testa_3"}, {"b", "testb_3"}}},
|
{ "3", { { "a", "testa_3" }, { "b", "testb_3" } } },
|
||||||
};
|
};
|
||||||
|
|
||||||
std::map<std::string, Data> expected{
|
std::map<std::string, Data> expected{
|
||||||
{"1", {"testa_1", "testb_1"}},
|
{ "1", { "testa_1", "testb_1" } },
|
||||||
{"2", {"testa_2", "testb_2"}},
|
{ "2", { "testa_2", "testb_2" } },
|
||||||
{"3", {"testa_3", "testb_3"}},
|
{ "3", { "testa_3", "testb_3" } },
|
||||||
};
|
};
|
||||||
const auto data = j.get<decltype(expected)>();
|
const auto data = j.get<decltype(expected)>();
|
||||||
CHECK(expected == data);
|
CHECK(expected == data);
|
||||||
@ -504,11 +504,12 @@ TEST_CASE("regression tests 2")
|
|||||||
SECTION("test case in issue #1445")
|
SECTION("test case in issue #1445")
|
||||||
{
|
{
|
||||||
nlohmann::json dump_test;
|
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,
|
const std::array<int, 108> data = {
|
||||||
0, 0, 0, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -80, 2, 0, 0,
|
{ 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,
|
||||||
96, -118, 46, -116, 46, 109, -84, -87, 108, 14, 109, -24, -83, 13, -18, -51, -83, -52, -115, 14, 6, 32,
|
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,
|
||||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 64, 3, 0, 0, 0, 35, -74, -73, 55, 57, -128,
|
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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 33, 0, 0, 0, -96, -54, -28, -26}};
|
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;
|
std::string s;
|
||||||
for (const int i : data)
|
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")
|
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 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(jptr1));
|
||||||
CHECK(j.contains(jptr2));
|
CHECK(j.contains(jptr2));
|
||||||
@ -570,7 +571,7 @@ TEST_CASE("regression tests 2")
|
|||||||
|
|
||||||
SECTION("string array")
|
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);
|
const json cbor = json::from_cbor(input, true, false);
|
||||||
CHECK(cbor.is_discarded());
|
CHECK(cbor.is_discarded());
|
||||||
}
|
}
|
||||||
@ -605,8 +606,8 @@ TEST_CASE("regression tests 2")
|
|||||||
|
|
||||||
SECTION("issue #2067 - cannot serialize binary data to text JSON")
|
SECTION("issue #2067 - cannot serialize binary data to text JSON")
|
||||||
{
|
{
|
||||||
const std::array<unsigned char, 23> data = {
|
const std::array<unsigned char, 23> data = { { 0x81, 0xA4, 0x64, 0x61, 0x74, 0x61, 0xC4, 0x0F, 0x33, 0x30, 0x30, 0x32,
|
||||||
{0x81, 0xA4, 0x64, 0x61, 0x74, 0x61, 0xC4, 0x0F, 0x33, 0x30, 0x30, 0x32, 0x33, 0x34, 0x30, 0x31, 0x30, 0x37, 0x30, 0x35, 0x30, 0x31, 0x30}};
|
0x33, 0x34, 0x30, 0x31, 0x30, 0x37, 0x30, 0x35, 0x30, 0x31, 0x30 } };
|
||||||
const json j = json::from_msgpack(data.data(), data.size());
|
const json j = json::from_msgpack(data.data(), data.size());
|
||||||
CHECK_NOTHROW(j.dump(4, // Indent
|
CHECK_NOTHROW(j.dump(4, // Indent
|
||||||
' ', // Indent char
|
' ', // Indent char
|
||||||
@ -618,7 +619,7 @@ TEST_CASE("regression tests 2")
|
|||||||
SECTION("PR #2181 - regression bug with lvalue")
|
SECTION("PR #2181 - regression bug with lvalue")
|
||||||
{
|
{
|
||||||
// see https://github.com/nlohmann/json/pull/2181#issuecomment-653326060
|
// 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";
|
const std::string defval = "default value";
|
||||||
auto val = j.value("x", defval);
|
auto val = j.value("x", defval);
|
||||||
auto val2 = j.value("y", 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")
|
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);
|
const json result = json::from_cbor(data, true, false);
|
||||||
CHECK(result.is_discarded());
|
CHECK(result.is_discarded());
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("issue #2315 - json.update and vector<pair>does not work with ordered_json")
|
SECTION("issue #2315 - json.update and vector<pair>does not work with ordered_json")
|
||||||
{
|
{
|
||||||
nlohmann::ordered_json jsonAnimals = {{"animal", "dog"}};
|
nlohmann::ordered_json jsonAnimals = { { "animal", "dog" } };
|
||||||
const nlohmann::ordered_json jsonCat = {{"animal", "cat"}};
|
const nlohmann::ordered_json jsonCat = { { "animal", "cat" } };
|
||||||
jsonAnimals.update(jsonCat);
|
jsonAnimals.update(jsonCat);
|
||||||
CHECK(jsonAnimals["animal"] == "cat");
|
CHECK(jsonAnimals["animal"] == "cat");
|
||||||
|
|
||||||
auto jsonAnimals_parsed = nlohmann::ordered_json::parse(jsonAnimals.dump());
|
auto jsonAnimals_parsed = nlohmann::ordered_json::parse(jsonAnimals.dump());
|
||||||
CHECK(jsonAnimals == jsonAnimals_parsed);
|
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;
|
nlohmann::ordered_json jsonObj;
|
||||||
for (const auto& data : intData)
|
for (const auto& data : intData)
|
||||||
{
|
{
|
||||||
@ -675,7 +676,7 @@ TEST_CASE("regression tests 2")
|
|||||||
SECTION("std::array")
|
SECTION("std::array")
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
const json j = {7, 4};
|
const json j = { 7, 4 };
|
||||||
auto arr = j.get<std::array<NonDefaultConstructible, 2>>();
|
auto arr = j.get<std::array<NonDefaultConstructible, 2>>();
|
||||||
CHECK(arr[0].x == 7);
|
CHECK(arr[0].x == 7);
|
||||||
CHECK(arr[1].x == 4);
|
CHECK(arr[1].x == 4);
|
||||||
@ -690,21 +691,21 @@ TEST_CASE("regression tests 2")
|
|||||||
SECTION("std::pair")
|
SECTION("std::pair")
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
const json j = {3, 8};
|
const json j = { 3, 8 };
|
||||||
auto p = j.get<std::pair<NonDefaultConstructible, NonDefaultConstructible>>();
|
auto p = j.get<std::pair<NonDefaultConstructible, NonDefaultConstructible>>();
|
||||||
CHECK(p.first.x == 3);
|
CHECK(p.first.x == 3);
|
||||||
CHECK(p.second.x == 8);
|
CHECK(p.second.x == 8);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
const json j = {4, 1};
|
const json j = { 4, 1 };
|
||||||
auto p = j.get<std::pair<int, NonDefaultConstructible>>();
|
auto p = j.get<std::pair<int, NonDefaultConstructible>>();
|
||||||
CHECK(p.first == 4);
|
CHECK(p.first == 4);
|
||||||
CHECK(p.second.x == 1);
|
CHECK(p.second.x == 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
const json j = {6, 7};
|
const json j = { 6, 7 };
|
||||||
auto p = j.get<std::pair<NonDefaultConstructible, int>>();
|
auto p = j.get<std::pair<NonDefaultConstructible, int>>();
|
||||||
CHECK(p.first.x == 6);
|
CHECK(p.first.x == 6);
|
||||||
CHECK(p.second == 7);
|
CHECK(p.second == 7);
|
||||||
@ -719,13 +720,13 @@ TEST_CASE("regression tests 2")
|
|||||||
SECTION("std::tuple")
|
SECTION("std::tuple")
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
const json j = {9};
|
const json j = { 9 };
|
||||||
auto t = j.get<std::tuple<NonDefaultConstructible>>();
|
auto t = j.get<std::tuple<NonDefaultConstructible>>();
|
||||||
CHECK(std::get<0>(t).x == 9);
|
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>>();
|
auto t = j.get<std::tuple<NonDefaultConstructible, int, NonDefaultConstructible>>();
|
||||||
CHECK(std::get<0>(t).x == 9);
|
CHECK(std::get<0>(t).x == 9);
|
||||||
CHECK(std::get<1>(t) == 8);
|
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")
|
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;
|
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::to_cbor(j, my_vector);
|
||||||
json k = json::from_cbor(my_vector);
|
json k = json::from_cbor(my_vector);
|
||||||
CHECK(j == k);
|
CHECK(j == k);
|
||||||
@ -836,7 +837,7 @@ TEST_CASE("regression tests 2")
|
|||||||
|
|
||||||
SECTION("issue #3108 - ordered_json doesn't support range based erase")
|
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());
|
auto last = std::unique(j.begin(), j.end());
|
||||||
j.erase(last, 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")
|
SECTION("issue #3343 - json and ordered_json are not interchangable")
|
||||||
{
|
{
|
||||||
json::object_t jobj({{"product", "one"}});
|
json::object_t jobj({ { "product", "one" } });
|
||||||
ordered_json::object_t ojobj({{"product", "one"}});
|
ordered_json::object_t ojobj({ { "product", "one" } });
|
||||||
|
|
||||||
auto jit = jobj.begin();
|
auto jit = jobj.begin();
|
||||||
auto ojit = ojobj.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")
|
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’
|
// 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>’})
|
// {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")
|
SECTION("issue #3312 - Parse to custom class from unordered_json breaks on G++11.2.0 with C++20")
|
||||||
{
|
{
|
||||||
// see test for #3171
|
// see test for #3171
|
||||||
const ordered_json j = {{"name", "class"}};
|
const ordered_json j = { { "name", "class" } };
|
||||||
for_3312 obj{};
|
for_3312 obj{};
|
||||||
|
|
||||||
j.get_to(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")
|
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;
|
for_3333 p = j;
|
||||||
|
|
||||||
CHECK(p.x == 1);
|
CHECK(p.x == 1);
|
||||||
|
@ -21,7 +21,7 @@ TEST_CASE("serialization")
|
|||||||
SECTION("no given width")
|
SECTION("no given width")
|
||||||
{
|
{
|
||||||
std::stringstream ss;
|
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;
|
ss << j;
|
||||||
CHECK(ss.str() == "[\"foo\",1,2,3,false,{\"one\":1}]");
|
CHECK(ss.str() == "[\"foo\",1,2,3,false,{\"one\":1}]");
|
||||||
}
|
}
|
||||||
@ -29,7 +29,7 @@ TEST_CASE("serialization")
|
|||||||
SECTION("given width")
|
SECTION("given width")
|
||||||
{
|
{
|
||||||
std::stringstream ss;
|
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;
|
ss << std::setw(4) << j;
|
||||||
CHECK(ss.str() == "[\n \"foo\",\n 1,\n 2,\n 3,\n false,\n {\n \"one\": 1\n }\n]");
|
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")
|
SECTION("given fill")
|
||||||
{
|
{
|
||||||
std::stringstream ss;
|
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;
|
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]");
|
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")
|
SECTION("no given width")
|
||||||
{
|
{
|
||||||
std::stringstream ss;
|
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;
|
j >> ss;
|
||||||
CHECK(ss.str() == "[\"foo\",1,2,3,false,{\"one\":1}]");
|
CHECK(ss.str() == "[\"foo\",1,2,3,false,{\"one\":1}]");
|
||||||
}
|
}
|
||||||
@ -56,7 +56,7 @@ TEST_CASE("serialization")
|
|||||||
SECTION("given width")
|
SECTION("given width")
|
||||||
{
|
{
|
||||||
std::stringstream ss;
|
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);
|
ss.width(4);
|
||||||
j >> ss;
|
j >> ss;
|
||||||
CHECK(ss.str() == "[\n \"foo\",\n 1,\n 2,\n 3,\n false,\n {\n \"one\": 1\n }\n]");
|
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")
|
SECTION("given fill")
|
||||||
{
|
{
|
||||||
std::stringstream ss;
|
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.width(1);
|
||||||
ss.fill('\t');
|
ss.fill('\t');
|
||||||
j >> ss;
|
j >> ss;
|
||||||
@ -249,20 +249,20 @@ TEST_CASE_TEMPLATE("serialization for extreme integer values", T, int32_t, uint3
|
|||||||
|
|
||||||
TEST_CASE("dump with binary values")
|
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_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);
|
auto binary_empty_with_subtype = json::binary({}, 128);
|
||||||
|
|
||||||
const json object = {{"key", binary}};
|
const json object = { { "key", binary } };
|
||||||
const json object_empty = {{"key", binary_empty}};
|
const json object_empty = { { "key", binary_empty } };
|
||||||
const json object_with_subtype = {{"key", binary_with_subtype}};
|
const json object_with_subtype = { { "key", binary_with_subtype } };
|
||||||
const json object_empty_with_subtype = {{"key", binary_empty_with_subtype}};
|
const json object_empty_with_subtype = { { "key", binary_empty_with_subtype } };
|
||||||
|
|
||||||
const json array = {"value", 1, binary};
|
const json array = { "value", 1, binary };
|
||||||
const json array_empty = {"value", 1, binary_empty};
|
const json array_empty = { "value", 1, binary_empty };
|
||||||
const json array_with_subtype = {"value", 1, binary_with_subtype};
|
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_empty_with_subtype = { "value", 1, binary_empty_with_subtype };
|
||||||
|
|
||||||
SECTION("normal")
|
SECTION("normal")
|
||||||
{
|
{
|
||||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -130,7 +130,7 @@ static void to_json(BasicJsonType& j, country c)
|
|||||||
template<typename BasicJsonType>
|
template<typename BasicJsonType>
|
||||||
static void to_json(BasicJsonType& j, const person& p)
|
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)
|
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)
|
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)
|
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
|
// operators
|
||||||
@ -199,7 +199,9 @@ template<typename BasicJsonType>
|
|||||||
static void from_json(const BasicJsonType& j, country& c)
|
static void from_json(const BasicJsonType& j, country& c)
|
||||||
{
|
{
|
||||||
const auto str = j.template get<std::string>();
|
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);
|
const auto it = m.find(str);
|
||||||
// TODO(nlohmann) test exceptions
|
// 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"))
|
TEST_CASE("basic usage" * doctest::test_suite("udt"))
|
||||||
{
|
{
|
||||||
// a bit narcissistic maybe :) ?
|
// a bit narcissistic maybe :) ?
|
||||||
const udt::age a{23};
|
const udt::age a{ 23 };
|
||||||
const udt::name n{"theo"};
|
const udt::name n{ "theo" };
|
||||||
const udt::country c{udt::country::france};
|
const udt::country c{ udt::country::france };
|
||||||
const udt::person sfinae_addict{a, n, c};
|
const udt::person sfinae_addict{ a, n, c };
|
||||||
const udt::person senior_programmer{{42}, {"王芳"}, udt::country::china};
|
const udt::person senior_programmer{ { 42 }, { "王芳" }, udt::country::china };
|
||||||
const udt::address addr{"Paris"};
|
const udt::address addr{ "Paris" };
|
||||||
const udt::contact cpp_programmer{sfinae_addict, addr};
|
const udt::contact cpp_programmer{ sfinae_addict, addr };
|
||||||
const udt::contact_book book{{"C++"}, {cpp_programmer, {senior_programmer, addr}}};
|
const udt::contact_book book{ { "C++" }, { cpp_programmer, { senior_programmer, addr } } };
|
||||||
|
|
||||||
SECTION("conversion to json via free-functions")
|
SECTION("conversion to json via free-functions")
|
||||||
{
|
{
|
||||||
@ -282,7 +284,7 @@ TEST_CASE("basic usage" * doctest::test_suite("udt"))
|
|||||||
CHECK(person == sfinae_addict);
|
CHECK(person == sfinae_addict);
|
||||||
CHECK(contact == cpp_programmer);
|
CHECK(contact == cpp_programmer);
|
||||||
CHECK(contacts == book.m_contacts);
|
CHECK(contacts == book.m_contacts);
|
||||||
CHECK(book_name == udt::name{"C++"});
|
CHECK(book_name == udt::name{ "C++" });
|
||||||
CHECK(book == parsed_book);
|
CHECK(book == parsed_book);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -320,7 +322,7 @@ TEST_CASE("basic usage" * doctest::test_suite("udt"))
|
|||||||
CHECK(person == sfinae_addict);
|
CHECK(person == sfinae_addict);
|
||||||
CHECK(contact == cpp_programmer);
|
CHECK(contact == cpp_programmer);
|
||||||
CHECK(contacts == book.m_contacts);
|
CHECK(contacts == book.m_contacts);
|
||||||
CHECK(book_name == udt::name{"C++"});
|
CHECK(book_name == udt::name{ "C++" });
|
||||||
CHECK(book == parsed_book);
|
CHECK(book == parsed_book);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -395,7 +397,7 @@ TEST_CASE("adl_serializer specialization" * doctest::test_suite("udt"))
|
|||||||
json j = optPerson;
|
json j = optPerson;
|
||||||
CHECK(j.is_null());
|
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;
|
j = optPerson;
|
||||||
CHECK_FALSE(j.is_null());
|
CHECK_FALSE(j.is_null());
|
||||||
|
|
||||||
@ -404,7 +406,7 @@ TEST_CASE("adl_serializer specialization" * doctest::test_suite("udt"))
|
|||||||
|
|
||||||
SECTION("from_json")
|
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;
|
json j = person;
|
||||||
|
|
||||||
auto optPerson = j.get<std::shared_ptr<udt::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")
|
SECTION("to_json")
|
||||||
{
|
{
|
||||||
udt::legacy_type const lt{"4242"};
|
udt::legacy_type const lt{ "4242" };
|
||||||
|
|
||||||
json const j = lt;
|
json const j = lt;
|
||||||
CHECK(j.get<int>() == 4242);
|
CHECK(j.get<int>() == 4242);
|
||||||
@ -449,24 +451,24 @@ struct adl_serializer<std::vector<float>>
|
|||||||
|
|
||||||
static void from_json(const json& /*unnamed*/, type& opt)
|
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
|
// preferred version
|
||||||
static type from_json(const json& /*unnamed*/)
|
static type from_json(const json& /*unnamed*/)
|
||||||
{
|
{
|
||||||
return {4.0, 5.0, 6.0};
|
return { 4.0, 5.0, 6.0 };
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
} // namespace nlohmann
|
} // namespace nlohmann
|
||||||
|
|
||||||
TEST_CASE("even supported types can be specialized" * doctest::test_suite("udt"))
|
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!")");
|
CHECK(j.dump() == R"("hijacked!")");
|
||||||
auto f = j.get<std::vector<float>>();
|
auto f = j.get<std::vector<float>>();
|
||||||
// the single argument from_json method is preferred
|
// 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
|
namespace nlohmann
|
||||||
@ -508,7 +510,7 @@ TEST_CASE("Non-copyable types" * doctest::test_suite("udt"))
|
|||||||
json j = optPerson;
|
json j = optPerson;
|
||||||
CHECK(j.is_null());
|
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;
|
j = optPerson;
|
||||||
CHECK_FALSE(j.is_null());
|
CHECK_FALSE(j.is_null());
|
||||||
|
|
||||||
@ -517,7 +519,7 @@ TEST_CASE("Non-copyable types" * doctest::test_suite("udt"))
|
|||||||
|
|
||||||
SECTION("from_json")
|
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;
|
json j = person;
|
||||||
|
|
||||||
auto optPerson = j.get<std::unique_ptr<udt::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>;
|
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;
|
custom_json const j = p;
|
||||||
|
|
||||||
auto p2 = j.get<udt::small_pod>();
|
auto p2 = j.get<udt::small_pod>();
|
||||||
|
|
||||||
CHECK(p == p2);
|
CHECK(p == p2);
|
||||||
|
|
||||||
auto np = udt::non_pod{{"non-pod"}};
|
auto np = udt::non_pod{ { "non-pod" } };
|
||||||
custom_json const j2 = np;
|
custom_json const j2 = np;
|
||||||
auto np2 = j2.get<udt::non_pod>();
|
auto np2 = j2.get<udt::non_pod>();
|
||||||
CHECK(np == np2);
|
CHECK(np == np2);
|
||||||
@ -671,7 +673,7 @@ struct another_adl_serializer
|
|||||||
|
|
||||||
TEST_CASE("custom serializer that does adl by default" * doctest::test_suite("udt"))
|
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;
|
json const j = me;
|
||||||
custom_json const cj = me;
|
custom_json const cj = me;
|
||||||
@ -708,9 +710,9 @@ TEST_CASE("different basic_json types conversions")
|
|||||||
|
|
||||||
SECTION("array")
|
SECTION("array")
|
||||||
{
|
{
|
||||||
json const j = {1, 2, 3};
|
json const j = { 1, 2, 3 };
|
||||||
custom_json const cj = j;
|
custom_json const cj = j;
|
||||||
CHECK((cj == std::vector<int>{1, 2, 3}));
|
CHECK((cj == std::vector<int>{ 1, 2, 3 }));
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("integer")
|
SECTION("integer")
|
||||||
@ -743,7 +745,7 @@ TEST_CASE("different basic_json types conversions")
|
|||||||
|
|
||||||
SECTION("binary")
|
SECTION("binary")
|
||||||
{
|
{
|
||||||
json j = json::binary({1, 2, 3}, 42);
|
json j = json::binary({ 1, 2, 3 }, 42);
|
||||||
custom_json cj = j;
|
custom_json cj = j;
|
||||||
CHECK(cj.get_binary().subtype() == 42);
|
CHECK(cj.get_binary().subtype() == 42);
|
||||||
std::vector<std::uint8_t> cv = cj.get_binary();
|
std::vector<std::uint8_t> cv = cj.get_binary();
|
||||||
@ -753,7 +755,7 @@ TEST_CASE("different basic_json types conversions")
|
|||||||
|
|
||||||
SECTION("object")
|
SECTION("object")
|
||||||
{
|
{
|
||||||
json const j = {{"forty", "two"}};
|
json const j = { { "forty", "two" } };
|
||||||
custom_json cj = j;
|
custom_json cj = j;
|
||||||
auto m = j.get<std::map<std::string, std::string>>();
|
auto m = j.get<std::map<std::string, std::string>>();
|
||||||
CHECK(cj == m);
|
CHECK(cj == m);
|
||||||
@ -853,7 +855,7 @@ class no_iterator_type
|
|||||||
|
|
||||||
TEST_CASE("compatible array type, without iterator type alias")
|
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;
|
json const j = vec;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -245,8 +245,8 @@ class person_without_default_constructor_1
|
|||||||
}
|
}
|
||||||
|
|
||||||
person_without_default_constructor_1(std::string name_, int age_)
|
person_without_default_constructor_1(std::string name_, int age_)
|
||||||
: name{std::move(name_)}
|
: name{ std::move(name_) }
|
||||||
, age{age_}
|
, age{ age_ }
|
||||||
{}
|
{}
|
||||||
|
|
||||||
NLOHMANN_DEFINE_TYPE_INTRUSIVE_ONLY_SERIALIZE(person_without_default_constructor_1, name, 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_)
|
person_without_default_constructor_2(std::string name_, int age_)
|
||||||
: name{std::move(name_)}
|
: name{ std::move(name_) }
|
||||||
, age{age_}
|
, age{ age_ }
|
||||||
{}
|
{}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -282,7 +282,7 @@ TEST_CASE_TEMPLATE("Serialization/deserialization via NLOHMANN_DEFINE_TYPE_INTRU
|
|||||||
SECTION("person")
|
SECTION("person")
|
||||||
{
|
{
|
||||||
// serialization
|
// serialization
|
||||||
T p1("Erik", 1, {{"haircuts", 2}});
|
T p1("Erik", 1, { { "haircuts", 2 } });
|
||||||
CHECK(json(p1).dump() == "{\"age\":1,\"metadata\":{\"haircuts\":2},\"name\":\"Erik\"}");
|
CHECK(json(p1).dump() == "{\"age\":1,\"metadata\":{\"haircuts\":2},\"name\":\"Erik\"}");
|
||||||
|
|
||||||
// deserialization
|
// deserialization
|
||||||
@ -312,7 +312,7 @@ TEST_CASE_TEMPLATE("Serialization/deserialization via NLOHMANN_DEFINE_TYPE_INTRU
|
|||||||
CHECK(json(p0).dump() == "{\"age\":0,\"metadata\":null,\"name\":\"\"}");
|
CHECK(json(p0).dump() == "{\"age\":0,\"metadata\":null,\"name\":\"\"}");
|
||||||
|
|
||||||
// serialization
|
// serialization
|
||||||
T p1("Erik", 1, {{"haircuts", 2}});
|
T p1("Erik", 1, { { "haircuts", 2 } });
|
||||||
CHECK(json(p1).dump() == "{\"age\":1,\"metadata\":{\"haircuts\":2},\"name\":\"Erik\"}");
|
CHECK(json(p1).dump() == "{\"age\":1,\"metadata\":{\"haircuts\":2},\"name\":\"Erik\"}");
|
||||||
|
|
||||||
// deserialization
|
// deserialization
|
||||||
@ -419,11 +419,11 @@ TEST_CASE_TEMPLATE(
|
|||||||
{
|
{
|
||||||
{
|
{
|
||||||
// serialization of a single object
|
// serialization of a single object
|
||||||
T person{"Erik", 1};
|
T person{ "Erik", 1 };
|
||||||
CHECK(json(person).dump() == "{\"age\":1,\"name\":\"Erik\"}");
|
CHECK(json(person).dump() == "{\"age\":1,\"name\":\"Erik\"}");
|
||||||
|
|
||||||
// serialization of a container with objects
|
// 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\"}]");
|
CHECK(json(two_persons).dump() == "[{\"age\":1,\"name\":\"Erik\"},{\"age\":2,\"name\":\"Kyle\"}]");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -44,7 +44,7 @@ const char* end(const MyContainer& c)
|
|||||||
|
|
||||||
TEST_CASE("Custom container non-member begin/end")
|
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);
|
json as_json = json::parse(data);
|
||||||
CHECK(as_json.at(0) == 1);
|
CHECK(as_json.at(0) == 1);
|
||||||
CHECK(as_json.at(1) == 2);
|
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);
|
json as_json = json::parse(data);
|
||||||
CHECK(as_json.at(0) == 1);
|
CHECK(as_json.at(0) == 1);
|
||||||
CHECK(as_json.at(1) == 2);
|
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::reference, const char&>::value);
|
||||||
CHECK(std::is_same<MyIterator::iterator_category, std::input_iterator_tag>::value);
|
CHECK(std::is_same<MyIterator::iterator_category, std::input_iterator_tag>::value);
|
||||||
|
|
||||||
const MyIterator begin{raw_data};
|
const MyIterator begin{ raw_data };
|
||||||
const MyIterator end{raw_data + strlen(raw_data)}; // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic)
|
const MyIterator end{ raw_data + strlen(raw_data) }; // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic)
|
||||||
|
|
||||||
json as_json = json::parse(begin, end);
|
json as_json = json::parse(begin, end);
|
||||||
CHECK(as_json.at(0) == 1);
|
CHECK(as_json.at(0) == 1);
|
||||||
|
Loading…
Reference in New Issue
Block a user