mirror of
https://github.com/nlohmann/json.git
synced 2026-03-30 21:02:52 +00:00
Merge branch 'develop' of https://github.com/nlohmann/json into issue2592
This commit is contained in:
@@ -1 +0,0 @@
|
||||
unsigned-integer-overflow:stl_bvector.h
|
||||
@@ -43,7 +43,7 @@ TEST_CASE("algorithms")
|
||||
{
|
||||
CHECK(std::all_of(j_array.begin(), j_array.end(), [](const json & value)
|
||||
{
|
||||
return value.size() > 0;
|
||||
return !value.empty();
|
||||
}));
|
||||
CHECK(std::all_of(j_object.begin(), j_object.end(), [](const json & value)
|
||||
{
|
||||
@@ -67,7 +67,7 @@ TEST_CASE("algorithms")
|
||||
{
|
||||
CHECK(std::none_of(j_array.begin(), j_array.end(), [](const json & value)
|
||||
{
|
||||
return value.size() == 0;
|
||||
return value.empty();
|
||||
}));
|
||||
CHECK(std::none_of(j_object.begin(), j_object.end(), [](const json & value)
|
||||
{
|
||||
|
||||
@@ -40,12 +40,12 @@ template<class T>
|
||||
struct bad_allocator : std::allocator<T>
|
||||
{
|
||||
template<class... Args>
|
||||
void construct(T*, Args&& ...)
|
||||
void construct(T* /*unused*/, Args&& ... /*unused*/)
|
||||
{
|
||||
throw std::bad_alloc();
|
||||
}
|
||||
};
|
||||
}
|
||||
} // namespace
|
||||
|
||||
TEST_CASE("bad_alloc")
|
||||
{
|
||||
@@ -85,10 +85,8 @@ struct my_allocator : std::allocator<T>
|
||||
next_construct_fails = false;
|
||||
throw std::bad_alloc();
|
||||
}
|
||||
else
|
||||
{
|
||||
::new (reinterpret_cast<void*>(p)) T(std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
::new (reinterpret_cast<void*>(p)) T(std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
void deallocate(T* p, std::size_t n)
|
||||
@@ -98,10 +96,8 @@ struct my_allocator : std::allocator<T>
|
||||
next_deallocate_fails = false;
|
||||
throw std::bad_alloc();
|
||||
}
|
||||
else
|
||||
{
|
||||
std::allocator<T>::deallocate(p, n);
|
||||
}
|
||||
|
||||
std::allocator<T>::deallocate(p, n);
|
||||
}
|
||||
|
||||
void destroy(T* p)
|
||||
@@ -111,10 +107,8 @@ struct my_allocator : std::allocator<T>
|
||||
next_destroy_fails = false;
|
||||
throw std::bad_alloc();
|
||||
}
|
||||
else
|
||||
{
|
||||
p->~T();
|
||||
}
|
||||
|
||||
p->~T();
|
||||
}
|
||||
|
||||
template <class U>
|
||||
@@ -133,7 +127,7 @@ void my_allocator_clean_up(T* p)
|
||||
alloc.destroy(p);
|
||||
alloc.deallocate(p, 1);
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
TEST_CASE("controlled bad_alloc")
|
||||
{
|
||||
@@ -239,9 +233,9 @@ namespace
|
||||
template<class T>
|
||||
struct allocator_no_forward : std::allocator<T>
|
||||
{
|
||||
allocator_no_forward() {}
|
||||
allocator_no_forward() = default;
|
||||
template <class U>
|
||||
allocator_no_forward(allocator_no_forward<U>) {}
|
||||
allocator_no_forward(allocator_no_forward<U> /*unused*/) {}
|
||||
|
||||
template <class U>
|
||||
struct rebind
|
||||
@@ -256,7 +250,7 @@ struct allocator_no_forward : std::allocator<T>
|
||||
::new (static_cast<void*>(p)) T(args...);
|
||||
}
|
||||
};
|
||||
}
|
||||
} // namespace
|
||||
|
||||
TEST_CASE("bad my_allocator::construct")
|
||||
{
|
||||
|
||||
@@ -152,7 +152,7 @@ class alt_string
|
||||
private:
|
||||
std::string str_impl {};
|
||||
|
||||
friend bool ::operator<(const char*, const alt_string&);
|
||||
friend bool ::operator<(const char* /*op1*/, const alt_string& /*op2*/);
|
||||
};
|
||||
|
||||
void int_to_string(alt_string& target, std::size_t value)
|
||||
@@ -233,24 +233,24 @@ TEST_CASE("alternative string type")
|
||||
|
||||
SECTION("parse")
|
||||
{
|
||||
auto doc = alt_json::parse("{\"foo\": \"bar\"}");
|
||||
auto doc = alt_json::parse(R"({"foo": "bar"})");
|
||||
alt_string dump = doc.dump();
|
||||
CHECK(dump == R"({"foo":"bar"})");
|
||||
}
|
||||
|
||||
SECTION("items")
|
||||
{
|
||||
auto doc = alt_json::parse("{\"foo\": \"bar\"}");
|
||||
auto doc = alt_json::parse(R"({"foo": "bar"})");
|
||||
|
||||
for ( auto item : doc.items() )
|
||||
for (const auto& item : doc.items())
|
||||
{
|
||||
CHECK( item.key() == "foo" );
|
||||
CHECK( item.value() == "bar" );
|
||||
CHECK(item.key() == "foo");
|
||||
CHECK(item.value() == "bar");
|
||||
}
|
||||
|
||||
auto doc_array = alt_json::parse("[\"foo\", \"bar\"]");
|
||||
auto doc_array = alt_json::parse(R"(["foo", "bar"])");
|
||||
|
||||
for ( auto item : doc_array.items() )
|
||||
for (const auto& item : doc_array.items())
|
||||
{
|
||||
if (item.key() == "0" )
|
||||
{
|
||||
@@ -258,11 +258,11 @@ TEST_CASE("alternative string type")
|
||||
}
|
||||
else if (item.key() == "1" )
|
||||
{
|
||||
CHECK( item.value() == "bar" );
|
||||
CHECK(item.value() == "bar");
|
||||
}
|
||||
else
|
||||
{
|
||||
CHECK( false );
|
||||
CHECK(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -101,7 +101,11 @@ TEST_CASE("BSON")
|
||||
{ std::string("en\0try", 6), true }
|
||||
};
|
||||
CHECK_THROWS_AS(json::to_bson(j), json::out_of_range&);
|
||||
#if JSON_DIAGNOSTICS
|
||||
CHECK_THROWS_WITH(json::to_bson(j), "[json.exception.out_of_range.409] (/en) BSON key cannot contain code point U+0000 (at byte 2)");
|
||||
#else
|
||||
CHECK_THROWS_WITH(json::to_bson(j), "[json.exception.out_of_range.409] BSON key cannot contain code point U+0000 (at byte 2)");
|
||||
#endif
|
||||
}
|
||||
|
||||
SECTION("string length must be at least 1")
|
||||
@@ -683,42 +687,42 @@ class SaxCountdown
|
||||
return events_left-- > 0;
|
||||
}
|
||||
|
||||
bool boolean(bool)
|
||||
bool boolean(bool /*unused*/)
|
||||
{
|
||||
return events_left-- > 0;
|
||||
}
|
||||
|
||||
bool number_integer(json::number_integer_t)
|
||||
bool number_integer(json::number_integer_t /*unused*/)
|
||||
{
|
||||
return events_left-- > 0;
|
||||
}
|
||||
|
||||
bool number_unsigned(json::number_unsigned_t)
|
||||
bool number_unsigned(json::number_unsigned_t /*unused*/)
|
||||
{
|
||||
return events_left-- > 0;
|
||||
}
|
||||
|
||||
bool number_float(json::number_float_t, const std::string&)
|
||||
bool number_float(json::number_float_t /*unused*/, const std::string& /*unused*/)
|
||||
{
|
||||
return events_left-- > 0;
|
||||
}
|
||||
|
||||
bool string(std::string&)
|
||||
bool string(std::string& /*unused*/)
|
||||
{
|
||||
return events_left-- > 0;
|
||||
}
|
||||
|
||||
bool binary(std::vector<std::uint8_t>&)
|
||||
bool binary(std::vector<std::uint8_t>& /*unused*/)
|
||||
{
|
||||
return events_left-- > 0;
|
||||
}
|
||||
|
||||
bool start_object(std::size_t)
|
||||
bool start_object(std::size_t /*unused*/)
|
||||
{
|
||||
return events_left-- > 0;
|
||||
}
|
||||
|
||||
bool key(std::string&)
|
||||
bool key(std::string& /*unused*/)
|
||||
{
|
||||
return events_left-- > 0;
|
||||
}
|
||||
@@ -728,7 +732,7 @@ class SaxCountdown
|
||||
return events_left-- > 0;
|
||||
}
|
||||
|
||||
bool start_array(std::size_t)
|
||||
bool start_array(std::size_t /*unused*/)
|
||||
{
|
||||
return events_left-- > 0;
|
||||
}
|
||||
@@ -738,7 +742,7 @@ class SaxCountdown
|
||||
return events_left-- > 0;
|
||||
}
|
||||
|
||||
bool parse_error(std::size_t, const std::string&, const json::exception&)
|
||||
bool parse_error(std::size_t /*unused*/, const std::string& /*unused*/, const json::exception& /*unused*/) // NOLINT(readability-convert-member-functions-to-static)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -746,7 +750,7 @@ class SaxCountdown
|
||||
private:
|
||||
int events_left = 0;
|
||||
};
|
||||
}
|
||||
} // namespace
|
||||
|
||||
TEST_CASE("Incomplete BSON Input")
|
||||
{
|
||||
@@ -1235,7 +1239,11 @@ TEST_CASE("BSON numerical data")
|
||||
};
|
||||
|
||||
CHECK_THROWS_AS(json::to_bson(j), json::out_of_range&);
|
||||
#if JSON_DIAGNOSTICS
|
||||
CHECK_THROWS_WITH_STD_STR(json::to_bson(j), "[json.exception.out_of_range.407] (/entry) integer number " + std::to_string(i) + " cannot be represented by BSON as it does not fit int64");
|
||||
#else
|
||||
CHECK_THROWS_WITH_STD_STR(json::to_bson(j), "[json.exception.out_of_range.407] integer number " + std::to_string(i) + " cannot be represented by BSON as it does not fit int64");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -437,7 +437,7 @@ TEST_CASE("capacity")
|
||||
SECTION("boolean")
|
||||
{
|
||||
json j = true;
|
||||
const json j_const(j);
|
||||
const json j_const = true;
|
||||
|
||||
SECTION("result of max_size")
|
||||
{
|
||||
@@ -449,7 +449,7 @@ TEST_CASE("capacity")
|
||||
SECTION("string")
|
||||
{
|
||||
json j = "hello world";
|
||||
const json j_const(j);
|
||||
const json j_const = "hello world";
|
||||
|
||||
SECTION("result of max_size")
|
||||
{
|
||||
@@ -463,7 +463,7 @@ TEST_CASE("capacity")
|
||||
SECTION("empty array")
|
||||
{
|
||||
json j = json::array();
|
||||
const json j_const(j);
|
||||
const json j_const = json::array();
|
||||
|
||||
SECTION("result of max_size")
|
||||
{
|
||||
@@ -475,7 +475,7 @@ TEST_CASE("capacity")
|
||||
SECTION("filled array")
|
||||
{
|
||||
json j = {1, 2, 3};
|
||||
const json j_const(j);
|
||||
const json j_const = {1, 2, 3};
|
||||
|
||||
SECTION("result of max_size")
|
||||
{
|
||||
@@ -490,7 +490,7 @@ TEST_CASE("capacity")
|
||||
SECTION("empty object")
|
||||
{
|
||||
json j = json::object();
|
||||
const json j_const(j);
|
||||
const json j_const = json::object();
|
||||
|
||||
SECTION("result of max_size")
|
||||
{
|
||||
@@ -502,7 +502,7 @@ TEST_CASE("capacity")
|
||||
SECTION("filled object")
|
||||
{
|
||||
json j = {{"one", 1}, {"two", 2}, {"three", 3}};
|
||||
const json j_const(j);
|
||||
const json j_const = {{"one", 1}, {"two", 2}, {"three", 3}};
|
||||
|
||||
SECTION("result of max_size")
|
||||
{
|
||||
@@ -515,7 +515,7 @@ TEST_CASE("capacity")
|
||||
SECTION("number (integer)")
|
||||
{
|
||||
json j = -23;
|
||||
const json j_const(j);
|
||||
const json j_const = -23;
|
||||
|
||||
SECTION("result of max_size")
|
||||
{
|
||||
@@ -527,7 +527,7 @@ TEST_CASE("capacity")
|
||||
SECTION("number (unsigned)")
|
||||
{
|
||||
json j = 23u;
|
||||
const json j_const(j);
|
||||
const json j_const = 23u;
|
||||
|
||||
SECTION("result of max_size")
|
||||
{
|
||||
@@ -539,7 +539,7 @@ TEST_CASE("capacity")
|
||||
SECTION("number (float)")
|
||||
{
|
||||
json j = 23.42;
|
||||
const json j_const(j);
|
||||
const json j_const = 23.42;
|
||||
|
||||
SECTION("result of max_size")
|
||||
{
|
||||
@@ -551,7 +551,7 @@ TEST_CASE("capacity")
|
||||
SECTION("null")
|
||||
{
|
||||
json j = nullptr;
|
||||
const json j_const(j);
|
||||
const json j_const = nullptr;
|
||||
|
||||
SECTION("result of max_size")
|
||||
{
|
||||
|
||||
@@ -54,42 +54,42 @@ class SaxCountdown
|
||||
return events_left-- > 0;
|
||||
}
|
||||
|
||||
bool boolean(bool)
|
||||
bool boolean(bool /*unused*/)
|
||||
{
|
||||
return events_left-- > 0;
|
||||
}
|
||||
|
||||
bool number_integer(json::number_integer_t)
|
||||
bool number_integer(json::number_integer_t /*unused*/)
|
||||
{
|
||||
return events_left-- > 0;
|
||||
}
|
||||
|
||||
bool number_unsigned(json::number_unsigned_t)
|
||||
bool number_unsigned(json::number_unsigned_t /*unused*/)
|
||||
{
|
||||
return events_left-- > 0;
|
||||
}
|
||||
|
||||
bool number_float(json::number_float_t, const std::string&)
|
||||
bool number_float(json::number_float_t /*unused*/, const std::string& /*unused*/)
|
||||
{
|
||||
return events_left-- > 0;
|
||||
}
|
||||
|
||||
bool string(std::string&)
|
||||
bool string(std::string& /*unused*/)
|
||||
{
|
||||
return events_left-- > 0;
|
||||
}
|
||||
|
||||
bool binary(std::vector<std::uint8_t>&)
|
||||
bool binary(std::vector<std::uint8_t>& /*unused*/)
|
||||
{
|
||||
return events_left-- > 0;
|
||||
}
|
||||
|
||||
bool start_object(std::size_t)
|
||||
bool start_object(std::size_t /*unused*/)
|
||||
{
|
||||
return events_left-- > 0;
|
||||
}
|
||||
|
||||
bool key(std::string&)
|
||||
bool key(std::string& /*unused*/)
|
||||
{
|
||||
return events_left-- > 0;
|
||||
}
|
||||
@@ -99,7 +99,7 @@ class SaxCountdown
|
||||
return events_left-- > 0;
|
||||
}
|
||||
|
||||
bool start_array(std::size_t)
|
||||
bool start_array(std::size_t /*unused*/)
|
||||
{
|
||||
return events_left-- > 0;
|
||||
}
|
||||
@@ -109,7 +109,7 @@ class SaxCountdown
|
||||
return events_left-- > 0;
|
||||
}
|
||||
|
||||
bool parse_error(std::size_t, const std::string&, const json::exception&)
|
||||
bool parse_error(std::size_t /*unused*/, const std::string& /*unused*/, const json::exception& /*unused*/) // NOLINT(readability-convert-member-functions-to-static)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -117,7 +117,7 @@ class SaxCountdown
|
||||
private:
|
||||
int events_left = 0;
|
||||
};
|
||||
}
|
||||
} // namespace
|
||||
|
||||
TEST_CASE("CBOR")
|
||||
{
|
||||
@@ -219,7 +219,7 @@ TEST_CASE("CBOR")
|
||||
// create expected byte vector
|
||||
std::vector<uint8_t> expected;
|
||||
expected.push_back(static_cast<uint8_t>(0x3b));
|
||||
uint64_t positive = static_cast<uint64_t>(-1 - i);
|
||||
auto positive = static_cast<uint64_t>(-1 - i);
|
||||
expected.push_back(static_cast<uint8_t>((positive >> 56) & 0xff));
|
||||
expected.push_back(static_cast<uint8_t>((positive >> 48) & 0xff));
|
||||
expected.push_back(static_cast<uint8_t>((positive >> 40) & 0xff));
|
||||
@@ -276,7 +276,7 @@ TEST_CASE("CBOR")
|
||||
// create expected byte vector
|
||||
std::vector<uint8_t> expected;
|
||||
expected.push_back(static_cast<uint8_t>(0x3a));
|
||||
uint32_t positive = static_cast<uint32_t>(static_cast<uint64_t>(-1 - i) & 0x00000000ffffffff);
|
||||
auto positive = static_cast<uint32_t>(static_cast<uint64_t>(-1 - i) & 0x00000000ffffffff);
|
||||
expected.push_back(static_cast<uint8_t>((positive >> 24) & 0xff));
|
||||
expected.push_back(static_cast<uint8_t>((positive >> 16) & 0xff));
|
||||
expected.push_back(static_cast<uint8_t>((positive >> 8) & 0xff));
|
||||
@@ -294,7 +294,7 @@ TEST_CASE("CBOR")
|
||||
(static_cast<uint32_t>(result[3]) << 010) +
|
||||
static_cast<uint32_t>(result[4]);
|
||||
CHECK(restored == positive);
|
||||
CHECK(-1ll - restored == i);
|
||||
CHECK(-1LL - restored == i);
|
||||
|
||||
// roundtrip
|
||||
CHECK(json::from_cbor(result) == j);
|
||||
@@ -317,7 +317,7 @@ TEST_CASE("CBOR")
|
||||
// create expected byte vector
|
||||
std::vector<uint8_t> expected;
|
||||
expected.push_back(static_cast<uint8_t>(0x39));
|
||||
uint16_t positive = static_cast<uint16_t>(-1 - i);
|
||||
auto positive = static_cast<uint16_t>(-1 - i);
|
||||
expected.push_back(static_cast<uint8_t>((positive >> 8) & 0xff));
|
||||
expected.push_back(static_cast<uint8_t>(positive & 0xff));
|
||||
|
||||
@@ -328,7 +328,7 @@ TEST_CASE("CBOR")
|
||||
|
||||
// check individual bytes
|
||||
CHECK(result[0] == 0x39);
|
||||
uint16_t restored = static_cast<uint16_t>(static_cast<uint8_t>(result[1]) * 256 + static_cast<uint8_t>(result[2]));
|
||||
auto restored = static_cast<uint16_t>(static_cast<uint8_t>(result[1]) * 256 + static_cast<uint8_t>(result[2]));
|
||||
CHECK(restored == positive);
|
||||
CHECK(-1 - restored == i);
|
||||
|
||||
@@ -346,7 +346,7 @@ TEST_CASE("CBOR")
|
||||
const auto result = json::to_cbor(j);
|
||||
CHECK(result == expected);
|
||||
|
||||
int16_t restored = static_cast<int16_t>(-1 - ((result[1] << 8) + result[2]));
|
||||
auto restored = static_cast<int16_t>(-1 - ((result[1] << 8) + result[2]));
|
||||
CHECK(restored == -9263);
|
||||
|
||||
// roundtrip
|
||||
@@ -506,7 +506,7 @@ TEST_CASE("CBOR")
|
||||
|
||||
// check individual bytes
|
||||
CHECK(result[0] == 0x19);
|
||||
uint16_t restored = static_cast<uint16_t>(static_cast<uint8_t>(result[1]) * 256 + static_cast<uint8_t>(result[2]));
|
||||
auto restored = static_cast<uint16_t>(static_cast<uint8_t>(result[1]) * 256 + static_cast<uint8_t>(result[2]));
|
||||
CHECK(restored == i);
|
||||
|
||||
// roundtrip
|
||||
@@ -611,7 +611,7 @@ TEST_CASE("CBOR")
|
||||
|
||||
SECTION("-32768..-129 (int 16)")
|
||||
{
|
||||
for (int16_t i = -32768; i <= -129; ++i)
|
||||
for (int16_t i = -32768; i <= int16_t(-129); ++i)
|
||||
{
|
||||
CAPTURE(i)
|
||||
|
||||
@@ -634,7 +634,7 @@ TEST_CASE("CBOR")
|
||||
|
||||
// check individual bytes
|
||||
CHECK(result[0] == 0xd1);
|
||||
int16_t restored = static_cast<int16_t>((result[1] << 8) + result[2]);
|
||||
auto restored = static_cast<int16_t>((result[1] << 8) + result[2]);
|
||||
CHECK(restored == i);
|
||||
|
||||
// roundtrip
|
||||
@@ -699,7 +699,7 @@ TEST_CASE("CBOR")
|
||||
|
||||
// check individual bytes
|
||||
CHECK(result[0] == 0x18);
|
||||
uint8_t restored = static_cast<uint8_t>(result[1]);
|
||||
auto restored = static_cast<uint8_t>(result[1]);
|
||||
CHECK(restored == i);
|
||||
|
||||
// roundtrip
|
||||
@@ -733,7 +733,7 @@ TEST_CASE("CBOR")
|
||||
|
||||
// check individual bytes
|
||||
CHECK(result[0] == 0x19);
|
||||
uint16_t restored = static_cast<uint16_t>(static_cast<uint8_t>(result[1]) * 256 + static_cast<uint8_t>(result[2]));
|
||||
auto restored = static_cast<uint16_t>(static_cast<uint8_t>(result[1]) * 256 + static_cast<uint8_t>(result[2]));
|
||||
CHECK(restored == i);
|
||||
|
||||
// roundtrip
|
||||
@@ -940,7 +940,7 @@ TEST_CASE("CBOR")
|
||||
}
|
||||
SECTION("-3.40282e+38(lowest float)")
|
||||
{
|
||||
double v = static_cast<double>(std::numeric_limits<float>::lowest());
|
||||
auto v = static_cast<double>(std::numeric_limits<float>::lowest());
|
||||
json j = v;
|
||||
std::vector<uint8_t> expected =
|
||||
{
|
||||
@@ -1340,7 +1340,7 @@ TEST_CASE("CBOR")
|
||||
|
||||
SECTION("{\"a\": {\"b\": {\"c\": {}}}}")
|
||||
{
|
||||
json j = json::parse("{\"a\": {\"b\": {\"c\": {}}}}");
|
||||
json j = json::parse(R"({"a": {"b": {"c": {}}}})");
|
||||
std::vector<uint8_t> expected =
|
||||
{
|
||||
0xa1, 0x61, 0x61, 0xa1, 0x61, 0x62, 0xa1, 0x61, 0x63, 0xa0
|
||||
@@ -2029,20 +2029,18 @@ TEST_CASE("CBOR roundtrips" * doctest::skip())
|
||||
SECTION("input from flynn")
|
||||
{
|
||||
// most of these are excluded due to differences in key order (not a real problem)
|
||||
auto exclude_packed = std::set<std::string>
|
||||
{
|
||||
TEST_DATA_DIRECTORY "/json.org/1.json",
|
||||
TEST_DATA_DIRECTORY "/json.org/2.json",
|
||||
TEST_DATA_DIRECTORY "/json.org/3.json",
|
||||
TEST_DATA_DIRECTORY "/json.org/4.json",
|
||||
TEST_DATA_DIRECTORY "/json.org/5.json",
|
||||
TEST_DATA_DIRECTORY "/json_testsuite/sample.json", // kills AppVeyor
|
||||
TEST_DATA_DIRECTORY "/json_tests/pass1.json",
|
||||
TEST_DATA_DIRECTORY "/regression/working_file.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_duplicated_key.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_long_strings.json",
|
||||
};
|
||||
std::set<std::string> exclude_packed;
|
||||
exclude_packed.insert(TEST_DATA_DIRECTORY "/json.org/1.json");
|
||||
exclude_packed.insert(TEST_DATA_DIRECTORY "/json.org/2.json");
|
||||
exclude_packed.insert(TEST_DATA_DIRECTORY "/json.org/3.json");
|
||||
exclude_packed.insert(TEST_DATA_DIRECTORY "/json.org/4.json");
|
||||
exclude_packed.insert(TEST_DATA_DIRECTORY "/json.org/5.json");
|
||||
exclude_packed.insert(TEST_DATA_DIRECTORY "/json_testsuite/sample.json"); // kills AppVeyor
|
||||
exclude_packed.insert(TEST_DATA_DIRECTORY "/json_tests/pass1.json");
|
||||
exclude_packed.insert(TEST_DATA_DIRECTORY "/regression/working_file.json");
|
||||
exclude_packed.insert(TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object.json");
|
||||
exclude_packed.insert(TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_duplicated_key.json");
|
||||
exclude_packed.insert(TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_long_strings.json");
|
||||
|
||||
for (std::string filename :
|
||||
{
|
||||
@@ -2249,7 +2247,7 @@ TEST_CASE("CBOR roundtrips" * doctest::skip())
|
||||
// parse CBOR file
|
||||
auto packed = utils::read_binary_file(filename + ".cbor");
|
||||
|
||||
if (!exclude_packed.count(filename))
|
||||
if (exclude_packed.count(filename) == 0u)
|
||||
{
|
||||
{
|
||||
INFO_WITH_TEMP(filename + ": output adapters: std::vector<uint8_t>");
|
||||
@@ -2323,7 +2321,7 @@ TEST_CASE("all CBOR first bytes")
|
||||
// check that parse_error.112 is only thrown if the
|
||||
// first byte is in the unsupported set
|
||||
INFO_WITH_TEMP(e.what());
|
||||
if (std::find(unsupported.begin(), unsupported.end(), byte) != unsupported.end())
|
||||
if (unsupported.find(byte) != unsupported.end())
|
||||
{
|
||||
CHECK(e.id == 112);
|
||||
}
|
||||
|
||||
@@ -36,19 +36,19 @@ using nlohmann::json;
|
||||
namespace
|
||||
{
|
||||
// shortcut to scan a string literal
|
||||
json::lexer::token_type scan_string(const char* s, const bool ignore_comments = false);
|
||||
json::lexer::token_type scan_string(const char* s, bool ignore_comments = false);
|
||||
json::lexer::token_type scan_string(const char* s, const bool ignore_comments)
|
||||
{
|
||||
auto ia = nlohmann::detail::input_adapter(s);
|
||||
return nlohmann::detail::lexer<json, decltype(ia)>(std::move(ia), ignore_comments).scan();
|
||||
}
|
||||
return nlohmann::detail::lexer<json, decltype(ia)>(std::move(ia), ignore_comments).scan(); // NOLINT(hicpp-move-const-arg,performance-move-const-arg)
|
||||
}
|
||||
} // namespace
|
||||
|
||||
std::string get_error_message(const char* s, const bool ignore_comments = false);
|
||||
std::string get_error_message(const char* s, bool ignore_comments = false);
|
||||
std::string get_error_message(const char* s, const bool ignore_comments)
|
||||
{
|
||||
auto ia = nlohmann::detail::input_adapter(s);
|
||||
auto lexer = nlohmann::detail::lexer<json, decltype(ia)>(std::move(ia), ignore_comments);
|
||||
auto lexer = nlohmann::detail::lexer<json, decltype(ia)>(std::move(ia), ignore_comments); // NOLINT(hicpp-move-const-arg,performance-move-const-arg)
|
||||
lexer.scan();
|
||||
return lexer.get_error_message();
|
||||
}
|
||||
|
||||
@@ -42,13 +42,13 @@ class SaxEventLogger
|
||||
public:
|
||||
bool null()
|
||||
{
|
||||
events.push_back("null()");
|
||||
events.emplace_back("null()");
|
||||
return true;
|
||||
}
|
||||
|
||||
bool boolean(bool val)
|
||||
{
|
||||
events.push_back(val ? "boolean(true)" : "boolean(false)");
|
||||
events.emplace_back(val ? "boolean(true)" : "boolean(false)");
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ class SaxEventLogger
|
||||
return true;
|
||||
}
|
||||
|
||||
bool number_float(json::number_float_t, const std::string& s)
|
||||
bool number_float(json::number_float_t /*unused*/, const std::string& s)
|
||||
{
|
||||
events.push_back("number_float(" + s + ")");
|
||||
return true;
|
||||
@@ -79,7 +79,7 @@ class SaxEventLogger
|
||||
bool binary(json::binary_t& val)
|
||||
{
|
||||
std::string binary_contents = "binary(";
|
||||
std::string comma_space = "";
|
||||
std::string comma_space;
|
||||
for (auto b : val)
|
||||
{
|
||||
binary_contents.append(comma_space);
|
||||
@@ -95,7 +95,7 @@ class SaxEventLogger
|
||||
{
|
||||
if (elements == std::size_t(-1))
|
||||
{
|
||||
events.push_back("start_object()");
|
||||
events.emplace_back("start_object()");
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -112,7 +112,7 @@ class SaxEventLogger
|
||||
|
||||
bool end_object()
|
||||
{
|
||||
events.push_back("end_object()");
|
||||
events.emplace_back("end_object()");
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -120,7 +120,7 @@ class SaxEventLogger
|
||||
{
|
||||
if (elements == std::size_t(-1))
|
||||
{
|
||||
events.push_back("start_array()");
|
||||
events.emplace_back("start_array()");
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -131,11 +131,11 @@ class SaxEventLogger
|
||||
|
||||
bool end_array()
|
||||
{
|
||||
events.push_back("end_array()");
|
||||
events.emplace_back("end_array()");
|
||||
return true;
|
||||
}
|
||||
|
||||
bool parse_error(std::size_t position, const std::string&, const json::exception&)
|
||||
bool parse_error(std::size_t position, const std::string& /*unused*/, const json::exception& /*unused*/)
|
||||
{
|
||||
errored = true;
|
||||
events.push_back("parse_error(" + std::to_string(position) + ")");
|
||||
@@ -157,42 +157,42 @@ class SaxCountdown : public nlohmann::json::json_sax_t
|
||||
return events_left-- > 0;
|
||||
}
|
||||
|
||||
bool boolean(bool) override
|
||||
bool boolean(bool /*val*/) override
|
||||
{
|
||||
return events_left-- > 0;
|
||||
}
|
||||
|
||||
bool number_integer(json::number_integer_t) override
|
||||
bool number_integer(json::number_integer_t /*val*/) override
|
||||
{
|
||||
return events_left-- > 0;
|
||||
}
|
||||
|
||||
bool number_unsigned(json::number_unsigned_t) override
|
||||
bool number_unsigned(json::number_unsigned_t /*val*/) override
|
||||
{
|
||||
return events_left-- > 0;
|
||||
}
|
||||
|
||||
bool number_float(json::number_float_t, const std::string&) override
|
||||
bool number_float(json::number_float_t /*val*/, const std::string& /*s*/) override
|
||||
{
|
||||
return events_left-- > 0;
|
||||
}
|
||||
|
||||
bool string(std::string&) override
|
||||
bool string(std::string& /*val*/) override
|
||||
{
|
||||
return events_left-- > 0;
|
||||
}
|
||||
|
||||
bool binary(json::binary_t&) override
|
||||
bool binary(json::binary_t& /*val*/) override
|
||||
{
|
||||
return events_left-- > 0;
|
||||
}
|
||||
|
||||
bool start_object(std::size_t) override
|
||||
bool start_object(std::size_t /*elements*/) override
|
||||
{
|
||||
return events_left-- > 0;
|
||||
}
|
||||
|
||||
bool key(std::string&) override
|
||||
bool key(std::string& /*val*/) override
|
||||
{
|
||||
return events_left-- > 0;
|
||||
}
|
||||
@@ -202,7 +202,7 @@ class SaxCountdown : public nlohmann::json::json_sax_t
|
||||
return events_left-- > 0;
|
||||
}
|
||||
|
||||
bool start_array(std::size_t) override
|
||||
bool start_array(std::size_t /*elements*/) override
|
||||
{
|
||||
return events_left-- > 0;
|
||||
}
|
||||
@@ -212,7 +212,7 @@ class SaxCountdown : public nlohmann::json::json_sax_t
|
||||
return events_left-- > 0;
|
||||
}
|
||||
|
||||
bool parse_error(std::size_t, const std::string&, const json::exception&) override
|
||||
bool parse_error(std::size_t /*position*/, const std::string& /*last_token*/, const json::exception& /*ex*/) override
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -267,7 +267,7 @@ bool accept_helper(const std::string& s)
|
||||
CHECK(json::parser(nlohmann::detail::input_adapter(s)).accept(false) == !el.errored);
|
||||
|
||||
// 5. parse with simple callback
|
||||
json::parser_callback_t cb = [](int, json::parse_event_t, json&)
|
||||
json::parser_callback_t cb = [](int /*unused*/, json::parse_event_t /*unused*/, json& /*unused*/)
|
||||
{
|
||||
return true;
|
||||
};
|
||||
@@ -395,7 +395,7 @@ TEST_CASE("parser class")
|
||||
CHECK_THROWS_AS(parser_helper("\uFF01"), json::parse_error&);
|
||||
CHECK_THROWS_AS(parser_helper("[-4:1,]"), json::parse_error&);
|
||||
// unescaped control characters
|
||||
CHECK_THROWS_AS(parser_helper("\"\x00\""), json::parse_error&);
|
||||
CHECK_THROWS_AS(parser_helper("\"\x00\""), json::parse_error&); // NOLINT(bugprone-string-literal-with-embedded-nul)
|
||||
CHECK_THROWS_AS(parser_helper("\"\x01\""), json::parse_error&);
|
||||
CHECK_THROWS_AS(parser_helper("\"\x02\""), json::parse_error&);
|
||||
CHECK_THROWS_AS(parser_helper("\"\x03\""), json::parse_error&);
|
||||
@@ -427,7 +427,7 @@ TEST_CASE("parser class")
|
||||
CHECK_THROWS_AS(parser_helper("\"\x1d\""), json::parse_error&);
|
||||
CHECK_THROWS_AS(parser_helper("\"\x1e\""), json::parse_error&);
|
||||
CHECK_THROWS_AS(parser_helper("\"\x1f\""), json::parse_error&);
|
||||
CHECK_THROWS_WITH(parser_helper("\"\x00\""), "[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing value - invalid string: missing closing quote; last read: '\"'");
|
||||
CHECK_THROWS_WITH(parser_helper("\"\x00\""), "[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing value - invalid string: missing closing quote; last read: '\"'"); // NOLINT(bugprone-string-literal-with-embedded-nul)
|
||||
CHECK_THROWS_WITH(parser_helper("\"\x01\""), "[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing value - invalid string: control character U+0001 (SOH) must be escaped to \\u0001; last read: '\"<U+0001>'");
|
||||
CHECK_THROWS_WITH(parser_helper("\"\x02\""), "[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing value - invalid string: control character U+0002 (STX) must be escaped to \\u0002; last read: '\"<U+0002>'");
|
||||
CHECK_THROWS_WITH(parser_helper("\"\x03\""), "[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing value - invalid string: control character U+0003 (ETX) must be escaped to \\u0003; last read: '\"<U+0003>'");
|
||||
@@ -589,7 +589,7 @@ TEST_CASE("parser class")
|
||||
|
||||
SECTION("edge cases")
|
||||
{
|
||||
// From RFC7159, Section 6:
|
||||
// From RFC8259, Section 6:
|
||||
// Note that when such software is used, numbers that are
|
||||
// integers and are in the range [-(2**53)+1, (2**53)-1]
|
||||
// are interoperable in the sense that implementations will
|
||||
@@ -603,7 +603,7 @@ TEST_CASE("parser class")
|
||||
|
||||
SECTION("over the edge cases") // issue #178 - Integer conversion to unsigned (incorrect handling of 64 bit integers)
|
||||
{
|
||||
// While RFC7159, Section 6 specifies a preference for support
|
||||
// While RFC8259, Section 6 specifies a preference for support
|
||||
// for ranges in range of IEEE 754-2008 binary64 (double precision)
|
||||
// this does not accommodate 64 bit integers without loss of accuracy.
|
||||
// As 64 bit integers are now widely used in software, it is desirable
|
||||
@@ -641,8 +641,8 @@ TEST_CASE("parser class")
|
||||
SECTION("overflow")
|
||||
{
|
||||
// overflows during parsing yield an exception
|
||||
CHECK_THROWS_AS(parser_helper("1.18973e+4932") == json(), json::out_of_range&);
|
||||
CHECK_THROWS_WITH(parser_helper("1.18973e+4932") == json(),
|
||||
CHECK_THROWS_AS(parser_helper("1.18973e+4932").empty(), json::out_of_range&);
|
||||
CHECK_THROWS_WITH(parser_helper("1.18973e+4932").empty(),
|
||||
"[json.exception.out_of_range.406] number overflow parsing '1.18973e+4932'");
|
||||
}
|
||||
|
||||
@@ -770,7 +770,7 @@ TEST_CASE("parser class")
|
||||
CHECK(accept_helper("\uFF01") == false);
|
||||
CHECK(accept_helper("[-4:1,]") == false);
|
||||
// unescaped control characters
|
||||
CHECK(accept_helper("\"\x00\"") == false);
|
||||
CHECK(accept_helper("\"\x00\"") == false); // NOLINT(bugprone-string-literal-with-embedded-nul)
|
||||
CHECK(accept_helper("\"\x01\"") == false);
|
||||
CHECK(accept_helper("\"\x02\"") == false);
|
||||
CHECK(accept_helper("\"\x03\"") == false);
|
||||
@@ -888,7 +888,7 @@ TEST_CASE("parser class")
|
||||
|
||||
SECTION("edge cases")
|
||||
{
|
||||
// From RFC7159, Section 6:
|
||||
// From RFC8259, Section 6:
|
||||
// Note that when such software is used, numbers that are
|
||||
// integers and are in the range [-(2**53)+1, (2**53)-1]
|
||||
// are interoperable in the sense that implementations will
|
||||
@@ -902,7 +902,7 @@ TEST_CASE("parser class")
|
||||
|
||||
SECTION("over the edge cases") // issue #178 - Integer conversion to unsigned (incorrect handling of 64 bit integers)
|
||||
{
|
||||
// While RFC7159, Section 6 specifies a preference for support
|
||||
// While RFC8259, Section 6 specifies a preference for support
|
||||
// for ranges in range of IEEE 754-2008 binary64 (double precision)
|
||||
// this does not accommodate 64 bit integers without loss of accuracy.
|
||||
// As 64 bit integers are now widely used in software, it is desirable
|
||||
@@ -1155,7 +1155,7 @@ TEST_CASE("parser class")
|
||||
case ('r'):
|
||||
case ('t'):
|
||||
{
|
||||
CHECK_NOTHROW(parser_helper(s.c_str()));
|
||||
CHECK_NOTHROW(parser_helper(s));
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -1168,11 +1168,11 @@ TEST_CASE("parser class")
|
||||
// any other combination of backslash and character is invalid
|
||||
default:
|
||||
{
|
||||
CHECK_THROWS_AS(parser_helper(s.c_str()), json::parse_error&);
|
||||
CHECK_THROWS_AS(parser_helper(s), json::parse_error&);
|
||||
// only check error message if c is not a control character
|
||||
if (c > 0x1f)
|
||||
{
|
||||
CHECK_THROWS_WITH_STD_STR(parser_helper(s.c_str()),
|
||||
CHECK_THROWS_WITH_STD_STR(parser_helper(s),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 3: syntax error while parsing value - invalid string: forbidden character after backslash; last read: '\"\\" + std::string(1, static_cast<char>(c)) + "'");
|
||||
}
|
||||
break;
|
||||
@@ -1233,49 +1233,49 @@ TEST_CASE("parser class")
|
||||
if (valid(c))
|
||||
{
|
||||
CAPTURE(s1)
|
||||
CHECK_NOTHROW(parser_helper(s1.c_str()));
|
||||
CHECK_NOTHROW(parser_helper(s1));
|
||||
CAPTURE(s2)
|
||||
CHECK_NOTHROW(parser_helper(s2.c_str()));
|
||||
CHECK_NOTHROW(parser_helper(s2));
|
||||
CAPTURE(s3)
|
||||
CHECK_NOTHROW(parser_helper(s3.c_str()));
|
||||
CHECK_NOTHROW(parser_helper(s3));
|
||||
CAPTURE(s4)
|
||||
CHECK_NOTHROW(parser_helper(s4.c_str()));
|
||||
CHECK_NOTHROW(parser_helper(s4));
|
||||
}
|
||||
else
|
||||
{
|
||||
CAPTURE(s1)
|
||||
CHECK_THROWS_AS(parser_helper(s1.c_str()), json::parse_error&);
|
||||
CHECK_THROWS_AS(parser_helper(s1), json::parse_error&);
|
||||
// only check error message if c is not a control character
|
||||
if (c > 0x1f)
|
||||
{
|
||||
CHECK_THROWS_WITH_STD_STR(parser_helper(s1.c_str()),
|
||||
CHECK_THROWS_WITH_STD_STR(parser_helper(s1),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 7: syntax error while parsing value - invalid string: '\\u' must be followed by 4 hex digits; last read: '" + s1.substr(0, 7) + "'");
|
||||
}
|
||||
|
||||
CAPTURE(s2)
|
||||
CHECK_THROWS_AS(parser_helper(s2.c_str()), json::parse_error&);
|
||||
CHECK_THROWS_AS(parser_helper(s2), json::parse_error&);
|
||||
// only check error message if c is not a control character
|
||||
if (c > 0x1f)
|
||||
{
|
||||
CHECK_THROWS_WITH_STD_STR(parser_helper(s2.c_str()),
|
||||
CHECK_THROWS_WITH_STD_STR(parser_helper(s2),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 6: syntax error while parsing value - invalid string: '\\u' must be followed by 4 hex digits; last read: '" + s2.substr(0, 6) + "'");
|
||||
}
|
||||
|
||||
CAPTURE(s3)
|
||||
CHECK_THROWS_AS(parser_helper(s3.c_str()), json::parse_error&);
|
||||
CHECK_THROWS_AS(parser_helper(s3), json::parse_error&);
|
||||
// only check error message if c is not a control character
|
||||
if (c > 0x1f)
|
||||
{
|
||||
CHECK_THROWS_WITH_STD_STR(parser_helper(s3.c_str()),
|
||||
CHECK_THROWS_WITH_STD_STR(parser_helper(s3),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 5: syntax error while parsing value - invalid string: '\\u' must be followed by 4 hex digits; last read: '" + s3.substr(0, 5) + "'");
|
||||
}
|
||||
|
||||
CAPTURE(s4)
|
||||
CHECK_THROWS_AS(parser_helper(s4.c_str()), json::parse_error&);
|
||||
CHECK_THROWS_AS(parser_helper(s4), json::parse_error&);
|
||||
// only check error message if c is not a control character
|
||||
if (c > 0x1f)
|
||||
{
|
||||
CHECK_THROWS_WITH_STD_STR(parser_helper(s4.c_str()),
|
||||
CHECK_THROWS_WITH_STD_STR(parser_helper(s4),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 4: syntax error while parsing value - invalid string: '\\u' must be followed by 4 hex digits; last read: '" + s4.substr(0, 4) + "'");
|
||||
}
|
||||
}
|
||||
@@ -1381,7 +1381,7 @@ TEST_CASE("parser class")
|
||||
case ('r'):
|
||||
case ('t'):
|
||||
{
|
||||
CHECK(json::parser(nlohmann::detail::input_adapter(std::string(s.c_str()))).accept());
|
||||
CHECK(json::parser(nlohmann::detail::input_adapter(std::string(s))).accept());
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -1394,7 +1394,7 @@ TEST_CASE("parser class")
|
||||
// any other combination of backslash and character is invalid
|
||||
default:
|
||||
{
|
||||
CHECK(json::parser(nlohmann::detail::input_adapter(std::string(s.c_str()))).accept() == false);
|
||||
CHECK(json::parser(nlohmann::detail::input_adapter(std::string(s))).accept() == false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -1453,27 +1453,27 @@ TEST_CASE("parser class")
|
||||
if (valid(c))
|
||||
{
|
||||
CAPTURE(s1)
|
||||
CHECK(json::parser(nlohmann::detail::input_adapter(std::string(s1.c_str()))).accept());
|
||||
CHECK(json::parser(nlohmann::detail::input_adapter(std::string(s1))).accept());
|
||||
CAPTURE(s2)
|
||||
CHECK(json::parser(nlohmann::detail::input_adapter(std::string(s2.c_str()))).accept());
|
||||
CHECK(json::parser(nlohmann::detail::input_adapter(std::string(s2))).accept());
|
||||
CAPTURE(s3)
|
||||
CHECK(json::parser(nlohmann::detail::input_adapter(std::string(s3.c_str()))).accept());
|
||||
CHECK(json::parser(nlohmann::detail::input_adapter(std::string(s3))).accept());
|
||||
CAPTURE(s4)
|
||||
CHECK(json::parser(nlohmann::detail::input_adapter(std::string(s4.c_str()))).accept());
|
||||
CHECK(json::parser(nlohmann::detail::input_adapter(std::string(s4))).accept());
|
||||
}
|
||||
else
|
||||
{
|
||||
CAPTURE(s1)
|
||||
CHECK(json::parser(nlohmann::detail::input_adapter(std::string(s1.c_str()))).accept() == false);
|
||||
CHECK(json::parser(nlohmann::detail::input_adapter(std::string(s1))).accept() == false);
|
||||
|
||||
CAPTURE(s2)
|
||||
CHECK(json::parser(nlohmann::detail::input_adapter(std::string(s2.c_str()))).accept() == false);
|
||||
CHECK(json::parser(nlohmann::detail::input_adapter(std::string(s2))).accept() == false);
|
||||
|
||||
CAPTURE(s3)
|
||||
CHECK(json::parser(nlohmann::detail::input_adapter(std::string(s3.c_str()))).accept() == false);
|
||||
CHECK(json::parser(nlohmann::detail::input_adapter(std::string(s3))).accept() == false);
|
||||
|
||||
CAPTURE(s4)
|
||||
CHECK(json::parser(nlohmann::detail::input_adapter(std::string(s4.c_str()))).accept() == false);
|
||||
CHECK(json::parser(nlohmann::detail::input_adapter(std::string(s4))).accept() == false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1499,16 +1499,9 @@ TEST_CASE("parser class")
|
||||
|
||||
// test case to make sure the callback is properly evaluated after reading a key
|
||||
{
|
||||
json::parser_callback_t cb = [](int, json::parse_event_t event, json&)
|
||||
json::parser_callback_t cb = [](int /*unused*/, json::parse_event_t event, json& /*unused*/)
|
||||
{
|
||||
if (event == json::parse_event_t::key)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return event != json::parse_event_t::key;
|
||||
};
|
||||
|
||||
json x = json::parse("{\"key\": false}", cb);
|
||||
@@ -1518,7 +1511,7 @@ TEST_CASE("parser class")
|
||||
|
||||
SECTION("callback function")
|
||||
{
|
||||
auto s_object = R"(
|
||||
const auto* s_object = R"(
|
||||
{
|
||||
"foo": 2,
|
||||
"bar": {
|
||||
@@ -1527,11 +1520,11 @@ TEST_CASE("parser class")
|
||||
}
|
||||
)";
|
||||
|
||||
auto s_array = R"(
|
||||
const auto* s_array = R"(
|
||||
[1,2,[3,4,5],4,5]
|
||||
)";
|
||||
|
||||
auto structured_array = R"(
|
||||
const auto* structured_array = R"(
|
||||
[
|
||||
1,
|
||||
{
|
||||
@@ -1545,14 +1538,14 @@ TEST_CASE("parser class")
|
||||
|
||||
SECTION("filter nothing")
|
||||
{
|
||||
json j_object = json::parse(s_object, [](int, json::parse_event_t, const json&)
|
||||
json j_object = json::parse(s_object, [](int /*unused*/, json::parse_event_t /*unused*/, const json& /*unused*/)
|
||||
{
|
||||
return true;
|
||||
});
|
||||
|
||||
CHECK (j_object == json({{"foo", 2}, {"bar", {{"baz", 1}}}}));
|
||||
|
||||
json j_array = json::parse(s_array, [](int, json::parse_event_t, const json&)
|
||||
json j_array = json::parse(s_array, [](int /*unused*/, json::parse_event_t /*unused*/, const json& /*unused*/)
|
||||
{
|
||||
return true;
|
||||
});
|
||||
@@ -1562,7 +1555,7 @@ TEST_CASE("parser class")
|
||||
|
||||
SECTION("filter everything")
|
||||
{
|
||||
json j_object = json::parse(s_object, [](int, json::parse_event_t, const json&)
|
||||
json j_object = json::parse(s_object, [](int /*unused*/, json::parse_event_t /*unused*/, const json& /*unused*/)
|
||||
{
|
||||
return false;
|
||||
});
|
||||
@@ -1570,7 +1563,7 @@ TEST_CASE("parser class")
|
||||
// the top-level object will be discarded, leaving a null
|
||||
CHECK (j_object.is_null());
|
||||
|
||||
json j_array = json::parse(s_array, [](int, json::parse_event_t, const json&)
|
||||
json j_array = json::parse(s_array, [](int /*unused*/, json::parse_event_t /*unused*/, const json& /*unused*/)
|
||||
{
|
||||
return false;
|
||||
});
|
||||
@@ -1581,31 +1574,17 @@ TEST_CASE("parser class")
|
||||
|
||||
SECTION("filter specific element")
|
||||
{
|
||||
json j_object = json::parse(s_object, [](int, json::parse_event_t, const json & j)
|
||||
json j_object = json::parse(s_object, [](int /*unused*/, json::parse_event_t /*unused*/, const json & j)
|
||||
{
|
||||
// filter all number(2) elements
|
||||
if (j == json(2))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return j != json(2);
|
||||
});
|
||||
|
||||
CHECK (j_object == json({{"bar", {{"baz", 1}}}}));
|
||||
|
||||
json j_array = json::parse(s_array, [](int, json::parse_event_t, const json & j)
|
||||
json j_array = json::parse(s_array, [](int /*unused*/, json::parse_event_t /*unused*/, const json & j)
|
||||
{
|
||||
if (j == json(2))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return j != json(2);
|
||||
});
|
||||
|
||||
CHECK (j_array == json({1, {3, 4, 5}, 4, 5}));
|
||||
@@ -1613,32 +1592,18 @@ TEST_CASE("parser class")
|
||||
|
||||
SECTION("filter object in array")
|
||||
{
|
||||
json j_filtered1 = json::parse(structured_array, [](int, json::parse_event_t e, const json & parsed)
|
||||
json j_filtered1 = json::parse(structured_array, [](int /*unused*/, json::parse_event_t e, const json & parsed)
|
||||
{
|
||||
if (e == json::parse_event_t::object_end && parsed.contains("foo"))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return !(e == json::parse_event_t::object_end && parsed.contains("foo"));
|
||||
});
|
||||
|
||||
// the specified object will be discarded, and removed.
|
||||
CHECK (j_filtered1.size() == 2);
|
||||
CHECK (j_filtered1 == json({1, {{"qux", "baz"}}}));
|
||||
|
||||
json j_filtered2 = json::parse(structured_array, [](int, json::parse_event_t e, const json& /*parsed*/)
|
||||
json j_filtered2 = json::parse(structured_array, [](int /*unused*/, json::parse_event_t e, const json& /*parsed*/)
|
||||
{
|
||||
if (e == json::parse_event_t::object_end)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return e != json::parse_event_t::object_end;
|
||||
});
|
||||
|
||||
// removed all objects in array.
|
||||
@@ -1651,7 +1616,7 @@ TEST_CASE("parser class")
|
||||
SECTION("first closing event")
|
||||
{
|
||||
{
|
||||
json j_object = json::parse(s_object, [](int, json::parse_event_t e, const json&)
|
||||
json j_object = json::parse(s_object, [](int /*unused*/, json::parse_event_t e, const json& /*unused*/)
|
||||
{
|
||||
static bool first = true;
|
||||
if (e == json::parse_event_t::object_end && first)
|
||||
@@ -1659,10 +1624,8 @@ TEST_CASE("parser class")
|
||||
first = false;
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
// the first completed object will be discarded
|
||||
@@ -1670,7 +1633,7 @@ TEST_CASE("parser class")
|
||||
}
|
||||
|
||||
{
|
||||
json j_array = json::parse(s_array, [](int, json::parse_event_t e, const json&)
|
||||
json j_array = json::parse(s_array, [](int /*unused*/, json::parse_event_t e, const json& /*unused*/)
|
||||
{
|
||||
static bool first = true;
|
||||
if (e == json::parse_event_t::array_end && first)
|
||||
@@ -1678,10 +1641,8 @@ TEST_CASE("parser class")
|
||||
first = false;
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
// the first completed array will be discarded
|
||||
@@ -1696,29 +1657,15 @@ TEST_CASE("parser class")
|
||||
// object and array is discarded only after the closing character
|
||||
// has been read
|
||||
|
||||
json j_empty_object = json::parse("{}", [](int, json::parse_event_t e, const json&)
|
||||
json j_empty_object = json::parse("{}", [](int /*unused*/, json::parse_event_t e, const json& /*unused*/)
|
||||
{
|
||||
if (e == json::parse_event_t::object_end)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return e != json::parse_event_t::object_end;
|
||||
});
|
||||
CHECK(j_empty_object == json());
|
||||
|
||||
json j_empty_array = json::parse("[]", [](int, json::parse_event_t e, const json&)
|
||||
json j_empty_array = json::parse("[]", [](int /*unused*/, json::parse_event_t e, const json& /*unused*/)
|
||||
{
|
||||
if (e == json::parse_event_t::array_end)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return e != json::parse_event_t::array_end;
|
||||
});
|
||||
CHECK(j_empty_array == json());
|
||||
}
|
||||
@@ -1744,7 +1691,7 @@ TEST_CASE("parser class")
|
||||
|
||||
SECTION("from array")
|
||||
{
|
||||
uint8_t v[] = {'t', 'r', 'u', 'e'};
|
||||
uint8_t v[] = {'t', 'r', 'u', 'e'}; // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays)
|
||||
json j;
|
||||
json::parser(nlohmann::detail::input_adapter(std::begin(v), std::end(v))).parse(true, j);
|
||||
CHECK(j == json(true));
|
||||
@@ -1784,7 +1731,7 @@ TEST_CASE("parser class")
|
||||
{
|
||||
SECTION("parser with callback")
|
||||
{
|
||||
json::parser_callback_t cb = [](int, json::parse_event_t, json&)
|
||||
json::parser_callback_t cb = [](int /*unused*/, json::parse_event_t /*unused*/, json& /*unused*/)
|
||||
{
|
||||
return true;
|
||||
};
|
||||
|
||||
@@ -41,7 +41,7 @@ bool f(A a, B b, U u = U())
|
||||
{
|
||||
return u(a, b);
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
TEST_CASE("lexicographical comparison operators")
|
||||
{
|
||||
@@ -143,10 +143,10 @@ TEST_CASE("lexicographical comparison operators")
|
||||
|
||||
// comparison with discarded elements
|
||||
json j_discarded(json::value_t::discarded);
|
||||
for (size_t i = 0; i < j_values.size(); ++i)
|
||||
for (const auto& v : j_values)
|
||||
{
|
||||
CHECK( (j_values[i] == j_discarded) == false);
|
||||
CHECK( (j_discarded == j_values[i]) == false);
|
||||
CHECK( (v == j_discarded) == false);
|
||||
CHECK( (j_discarded == v) == false);
|
||||
CHECK( (j_discarded == j_discarded) == false);
|
||||
}
|
||||
|
||||
|
||||
@@ -436,7 +436,7 @@ TEST_CASE("constructors")
|
||||
|
||||
SECTION("char[]")
|
||||
{
|
||||
char s[] {"Hello world"};
|
||||
char s[] {"Hello world"}; // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays)
|
||||
json j(s);
|
||||
CHECK(j.type() == json::value_t::string);
|
||||
CHECK(j == j_reference);
|
||||
@@ -794,7 +794,7 @@ TEST_CASE("constructors")
|
||||
|
||||
SECTION("integer literal with l suffix")
|
||||
{
|
||||
json j(42l);
|
||||
json j(42L);
|
||||
CHECK(j.type() == json::value_t::number_integer);
|
||||
CHECK(j == j_reference);
|
||||
}
|
||||
@@ -808,7 +808,7 @@ TEST_CASE("constructors")
|
||||
|
||||
SECTION("integer literal with ll suffix")
|
||||
{
|
||||
json j(42ll);
|
||||
json j(42LL);
|
||||
CHECK(j.type() == json::value_t::number_integer);
|
||||
CHECK(j == j_reference);
|
||||
}
|
||||
@@ -892,7 +892,7 @@ TEST_CASE("constructors")
|
||||
|
||||
SECTION("long double")
|
||||
{
|
||||
long double n = 42.23l;
|
||||
long double n = 42.23L;
|
||||
json j(n);
|
||||
CHECK(j.type() == json::value_t::number_float);
|
||||
CHECK(j.m_value.number_float == Approx(j_reference.m_value.number_float));
|
||||
@@ -914,7 +914,7 @@ TEST_CASE("constructors")
|
||||
|
||||
SECTION("integer literal with l suffix")
|
||||
{
|
||||
json j(42.23l);
|
||||
json j(42.23L);
|
||||
CHECK(j.type() == json::value_t::number_float);
|
||||
CHECK(j.m_value.number_float == Approx(j_reference.m_value.number_float));
|
||||
}
|
||||
@@ -1115,84 +1115,113 @@ TEST_CASE("constructors")
|
||||
{
|
||||
SECTION("string")
|
||||
{
|
||||
// This should break through any short string optimization in std::string
|
||||
std::string source(1024, '!');
|
||||
const char* source_addr = source.data();
|
||||
|
||||
SECTION("constructor with implicit types (array)")
|
||||
{
|
||||
// This should break through any short string optimization in std::string
|
||||
std::string source(1024, '!');
|
||||
const auto* source_addr = source.data();
|
||||
json j = {std::move(source)};
|
||||
CHECK(j[0].get_ref<std::string const&>().data() == source_addr);
|
||||
const auto* target_addr = j[0].get_ref<std::string const&>().data();
|
||||
const bool success = (target_addr == source_addr);
|
||||
CHECK(success);
|
||||
}
|
||||
|
||||
SECTION("constructor with implicit types (object)")
|
||||
{
|
||||
// This should break through any short string optimization in std::string
|
||||
std::string source(1024, '!');
|
||||
const auto* source_addr = source.data();
|
||||
json j = {{"key", std::move(source)}};
|
||||
CHECK(j["key"].get_ref<std::string const&>().data() == source_addr);
|
||||
const auto* target_addr = j["key"].get_ref<std::string const&>().data();
|
||||
const bool success = (target_addr == source_addr);
|
||||
CHECK(success);
|
||||
}
|
||||
|
||||
SECTION("constructor with implicit types (object key)")
|
||||
{
|
||||
// This should break through any short string optimization in std::string
|
||||
std::string source(1024, '!');
|
||||
const auto* source_addr = source.data();
|
||||
json j = {{std::move(source), 42}};
|
||||
CHECK(j.get_ref<json::object_t&>().begin()->first.data() == source_addr);
|
||||
const auto* target_addr = j.get_ref<json::object_t&>().begin()->first.data();
|
||||
const bool success = (target_addr == source_addr);
|
||||
CHECK(success);
|
||||
}
|
||||
}
|
||||
|
||||
SECTION("array")
|
||||
{
|
||||
json::array_t source = {1, 2, 3};
|
||||
const json* source_addr = source.data();
|
||||
|
||||
SECTION("constructor with implicit types (array)")
|
||||
{
|
||||
json::array_t source = {1, 2, 3};
|
||||
const auto* source_addr = source.data();
|
||||
json j {std::move(source)};
|
||||
CHECK(j[0].get_ref<json::array_t const&>().data() == source_addr);
|
||||
const auto* target_addr = j[0].get_ref<json::array_t const&>().data();
|
||||
const bool success = (target_addr == source_addr);
|
||||
CHECK(success);
|
||||
}
|
||||
|
||||
SECTION("constructor with implicit types (object)")
|
||||
{
|
||||
json::array_t source = {1, 2, 3};
|
||||
const auto* source_addr = source.data();
|
||||
json j {{"key", std::move(source)}};
|
||||
CHECK(j["key"].get_ref<json::array_t const&>().data() == source_addr);
|
||||
const auto* target_addr = j["key"].get_ref<json::array_t const&>().data();
|
||||
const bool success = (target_addr == source_addr);
|
||||
CHECK(success);
|
||||
}
|
||||
|
||||
SECTION("assignment with implicit types (array)")
|
||||
{
|
||||
json::array_t source = {1, 2, 3};
|
||||
const auto* source_addr = source.data();
|
||||
json j = {std::move(source)};
|
||||
CHECK(j[0].get_ref<json::array_t const&>().data() == source_addr);
|
||||
const auto* target_addr = j[0].get_ref<json::array_t const&>().data();
|
||||
const bool success = (target_addr == source_addr);
|
||||
CHECK(success);
|
||||
}
|
||||
|
||||
SECTION("assignment with implicit types (object)")
|
||||
{
|
||||
json::array_t source = {1, 2, 3};
|
||||
const auto* source_addr = source.data();
|
||||
json j = {{"key", std::move(source)}};
|
||||
CHECK(j["key"].get_ref<json::array_t const&>().data() == source_addr);
|
||||
const auto* target_addr = j["key"].get_ref<json::array_t const&>().data();
|
||||
const bool success = (target_addr == source_addr);
|
||||
CHECK(success);
|
||||
}
|
||||
}
|
||||
|
||||
SECTION("object")
|
||||
{
|
||||
json::object_t source = {{"hello", "world"}};
|
||||
const json* source_addr = &source.at("hello");
|
||||
|
||||
SECTION("constructor with implicit types (array)")
|
||||
{
|
||||
json::object_t source = {{"hello", "world"}};
|
||||
const json* source_addr = &source.at("hello");
|
||||
json j {std::move(source)};
|
||||
CHECK(&(j[0].get_ref<json::object_t const&>().at("hello")) == source_addr);
|
||||
}
|
||||
|
||||
SECTION("constructor with implicit types (object)")
|
||||
{
|
||||
json::object_t source = {{"hello", "world"}};
|
||||
const json* source_addr = &source.at("hello");
|
||||
json j {{"key", std::move(source)}};
|
||||
CHECK(&(j["key"].get_ref<json::object_t const&>().at("hello")) == source_addr);
|
||||
}
|
||||
|
||||
SECTION("assignment with implicit types (array)")
|
||||
{
|
||||
json::object_t source = {{"hello", "world"}};
|
||||
const json* source_addr = &source.at("hello");
|
||||
json j = {std::move(source)};
|
||||
CHECK(&(j[0].get_ref<json::object_t const&>().at("hello")) == source_addr);
|
||||
}
|
||||
|
||||
SECTION("assignment with implicit types (object)")
|
||||
{
|
||||
json::object_t source = {{"hello", "world"}};
|
||||
const json* source_addr = &source.at("hello");
|
||||
json j = {{"key", std::move(source)}};
|
||||
CHECK(&(j["key"].get_ref<json::object_t const&>().at("hello")) == source_addr);
|
||||
}
|
||||
@@ -1200,29 +1229,34 @@ TEST_CASE("constructors")
|
||||
|
||||
SECTION("json")
|
||||
{
|
||||
json source {1, 2, 3};
|
||||
const json* source_addr = &source[0];
|
||||
|
||||
SECTION("constructor with implicit types (array)")
|
||||
{
|
||||
json source {1, 2, 3};
|
||||
const json* source_addr = &source[0];
|
||||
json j {std::move(source), {}};
|
||||
CHECK(&j[0][0] == source_addr);
|
||||
}
|
||||
|
||||
SECTION("constructor with implicit types (object)")
|
||||
{
|
||||
json source {1, 2, 3};
|
||||
const json* source_addr = &source[0];
|
||||
json j {{"key", std::move(source)}};
|
||||
CHECK(&j["key"][0] == source_addr);
|
||||
}
|
||||
|
||||
SECTION("assignment with implicit types (array)")
|
||||
{
|
||||
json source {1, 2, 3};
|
||||
const json* source_addr = &source[0];
|
||||
json j = {std::move(source), {}};
|
||||
CHECK(&j[0][0] == source_addr);
|
||||
}
|
||||
|
||||
SECTION("assignment with implicit types (object)")
|
||||
{
|
||||
json source {1, 2, 3};
|
||||
const json* source_addr = &source[0];
|
||||
json j = {{"key", std::move(source)}};
|
||||
CHECK(&j["key"][0] == source_addr);
|
||||
}
|
||||
|
||||
@@ -39,63 +39,63 @@ TEST_CASE("other constructors and destructor")
|
||||
SECTION("object")
|
||||
{
|
||||
json j {{"foo", 1}, {"bar", false}};
|
||||
json k(j);
|
||||
json k(j); // NOLINT(performance-unnecessary-copy-initialization)
|
||||
CHECK(j == k);
|
||||
}
|
||||
|
||||
SECTION("array")
|
||||
{
|
||||
json j {"foo", 1, 42.23, false};
|
||||
json k(j);
|
||||
json k(j); // NOLINT(performance-unnecessary-copy-initialization)
|
||||
CHECK(j == k);
|
||||
}
|
||||
|
||||
SECTION("null")
|
||||
{
|
||||
json j(nullptr);
|
||||
json k(j);
|
||||
json k(j); // NOLINT(performance-unnecessary-copy-initialization)
|
||||
CHECK(j == k);
|
||||
}
|
||||
|
||||
SECTION("boolean")
|
||||
{
|
||||
json j(true);
|
||||
json k(j);
|
||||
json k(j); // NOLINT(performance-unnecessary-copy-initialization)
|
||||
CHECK(j == k);
|
||||
}
|
||||
|
||||
SECTION("string")
|
||||
{
|
||||
json j("Hello world");
|
||||
json k(j);
|
||||
json k(j); // NOLINT(performance-unnecessary-copy-initialization)
|
||||
CHECK(j == k);
|
||||
}
|
||||
|
||||
SECTION("number (integer)")
|
||||
{
|
||||
json j(42);
|
||||
json k(j);
|
||||
json k(j); // NOLINT(performance-unnecessary-copy-initialization)
|
||||
CHECK(j == k);
|
||||
}
|
||||
|
||||
SECTION("number (unsigned)")
|
||||
{
|
||||
json j(42u);
|
||||
json k(j);
|
||||
json k(j); // NOLINT(performance-unnecessary-copy-initialization)
|
||||
CHECK(j == k);
|
||||
}
|
||||
|
||||
SECTION("number (floating-point)")
|
||||
{
|
||||
json j(42.23);
|
||||
json k(j);
|
||||
json k(j); // NOLINT(performance-unnecessary-copy-initialization)
|
||||
CHECK(j == k);
|
||||
}
|
||||
|
||||
SECTION("binary")
|
||||
{
|
||||
json j = json::binary({1, 2, 3});
|
||||
json k(j);
|
||||
json k(j); // NOLINT(performance-unnecessary-copy-initialization)
|
||||
CHECK(j == k);
|
||||
}
|
||||
}
|
||||
@@ -106,7 +106,7 @@ TEST_CASE("other constructors and destructor")
|
||||
CHECK(j.type() == json::value_t::object);
|
||||
json k(std::move(j));
|
||||
CHECK(k.type() == json::value_t::object);
|
||||
CHECK(j.type() == json::value_t::null);
|
||||
CHECK(j.type() == json::value_t::null); // NOLINT: access after move is OK here
|
||||
}
|
||||
|
||||
SECTION("copy assignment")
|
||||
@@ -188,20 +188,20 @@ TEST_CASE("other constructors and destructor")
|
||||
{
|
||||
SECTION("object")
|
||||
{
|
||||
auto j = new json {{"foo", 1}, {"bar", false}};
|
||||
delete j;
|
||||
auto* j = new json {{"foo", 1}, {"bar", false}}; // NOLINT(cppcoreguidelines-owning-memory)
|
||||
delete j; // NOLINT(cppcoreguidelines-owning-memory)
|
||||
}
|
||||
|
||||
SECTION("array")
|
||||
{
|
||||
auto j = new json {"foo", 1, 1u, false, 23.42};
|
||||
delete j;
|
||||
auto* j = new json {"foo", 1, 1u, false, 23.42}; // NOLINT(cppcoreguidelines-owning-memory)
|
||||
delete j; // NOLINT(cppcoreguidelines-owning-memory)
|
||||
}
|
||||
|
||||
SECTION("string")
|
||||
{
|
||||
auto j = new json("Hello world");
|
||||
delete j;
|
||||
auto* j = new json("Hello world"); // NOLINT(cppcoreguidelines-owning-memory)
|
||||
delete j; // NOLINT(cppcoreguidelines-owning-memory)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ using nlohmann::json;
|
||||
|
||||
namespace
|
||||
{
|
||||
void check_escaped(const char* original, const char* escaped = "", const bool ensure_ascii = false);
|
||||
void check_escaped(const char* original, const char* escaped = "", bool ensure_ascii = false);
|
||||
void check_escaped(const char* original, const char* escaped, const bool ensure_ascii)
|
||||
{
|
||||
std::stringstream ss;
|
||||
@@ -45,7 +45,7 @@ void check_escaped(const char* original, const char* escaped, const bool ensure_
|
||||
s.dump_escaped(original, ensure_ascii);
|
||||
CHECK(ss.str() == escaped);
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
TEST_CASE("convenience functions")
|
||||
{
|
||||
|
||||
@@ -282,8 +282,8 @@ TEST_CASE("value conversion")
|
||||
|
||||
SECTION("built-in arrays")
|
||||
{
|
||||
const char str[] = "a string";
|
||||
const int nbs[] = {0, 1, 2};
|
||||
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)
|
||||
|
||||
json j2 = nbs;
|
||||
json j3 = str;
|
||||
@@ -387,8 +387,8 @@ TEST_CASE("value conversion")
|
||||
|
||||
SECTION("built-in arrays")
|
||||
{
|
||||
const int nbs[] = {0, 1, 2};
|
||||
int nbs2[] = {0, 0, 0};
|
||||
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)
|
||||
|
||||
json j2 = nbs;
|
||||
j2.get_to(nbs2);
|
||||
@@ -633,7 +633,7 @@ TEST_CASE("value conversion")
|
||||
|
||||
SECTION("boolean_t")
|
||||
{
|
||||
json::boolean_t b = j.get<json::boolean_t>();
|
||||
auto b = j.get<json::boolean_t>();
|
||||
CHECK(json(b) == j);
|
||||
}
|
||||
|
||||
@@ -726,25 +726,25 @@ TEST_CASE("value conversion")
|
||||
|
||||
SECTION("number_integer_t")
|
||||
{
|
||||
json::number_integer_t n = j.get<json::number_integer_t>();
|
||||
auto n = j.get<json::number_integer_t>();
|
||||
CHECK(json(n) == j);
|
||||
}
|
||||
|
||||
SECTION("number_unsigned_t")
|
||||
{
|
||||
json::number_unsigned_t n = j_unsigned.get<json::number_unsigned_t>();
|
||||
auto n = j_unsigned.get<json::number_unsigned_t>();
|
||||
CHECK(json(n) == j_unsigned);
|
||||
}
|
||||
|
||||
SECTION("short")
|
||||
{
|
||||
short n = j.get<short>();
|
||||
auto n = j.get<short>();
|
||||
CHECK(json(n) == j);
|
||||
}
|
||||
|
||||
SECTION("unsigned short")
|
||||
{
|
||||
unsigned short n = j.get<unsigned short>();
|
||||
auto n = j.get<unsigned short>();
|
||||
CHECK(json(n) == j);
|
||||
}
|
||||
|
||||
@@ -756,7 +756,7 @@ TEST_CASE("value conversion")
|
||||
|
||||
SECTION("unsigned int")
|
||||
{
|
||||
unsigned int n = j.get<unsigned int>();
|
||||
auto n = j.get<unsigned int>();
|
||||
CHECK(json(n) == j);
|
||||
}
|
||||
|
||||
@@ -768,163 +768,163 @@ TEST_CASE("value conversion")
|
||||
|
||||
SECTION("unsigned long")
|
||||
{
|
||||
unsigned long n = j.get<unsigned long>();
|
||||
auto n = j.get<unsigned long>();
|
||||
CHECK(json(n) == j);
|
||||
}
|
||||
|
||||
SECTION("long long")
|
||||
{
|
||||
long long n = j.get<long long>();
|
||||
auto n = j.get<long long>();
|
||||
CHECK(json(n) == j);
|
||||
}
|
||||
|
||||
SECTION("unsigned long long")
|
||||
{
|
||||
unsigned long long n = j.get<unsigned long long>();
|
||||
auto n = j.get<unsigned long long>();
|
||||
CHECK(json(n) == j);
|
||||
}
|
||||
|
||||
SECTION("int8_t")
|
||||
{
|
||||
int8_t n = j.get<int8_t>();
|
||||
auto n = j.get<int8_t>();
|
||||
CHECK(json(n) == j);
|
||||
}
|
||||
|
||||
SECTION("int16_t")
|
||||
{
|
||||
int16_t n = j.get<int16_t>();
|
||||
auto n = j.get<int16_t>();
|
||||
CHECK(json(n) == j);
|
||||
}
|
||||
|
||||
SECTION("int32_t")
|
||||
{
|
||||
int32_t n = j.get<int32_t>();
|
||||
auto n = j.get<int32_t>();
|
||||
CHECK(json(n) == j);
|
||||
}
|
||||
|
||||
SECTION("int64_t")
|
||||
{
|
||||
int64_t n = j.get<int64_t>();
|
||||
auto n = j.get<int64_t>();
|
||||
CHECK(json(n) == j);
|
||||
}
|
||||
|
||||
SECTION("int8_fast_t")
|
||||
{
|
||||
int_fast8_t n = j.get<int_fast8_t>();
|
||||
auto n = j.get<int_fast8_t>();
|
||||
CHECK(json(n) == j);
|
||||
}
|
||||
|
||||
SECTION("int16_fast_t")
|
||||
{
|
||||
int_fast16_t n = j.get<int_fast16_t>();
|
||||
auto n = j.get<int_fast16_t>();
|
||||
CHECK(json(n) == j);
|
||||
}
|
||||
|
||||
SECTION("int32_fast_t")
|
||||
{
|
||||
int_fast32_t n = j.get<int_fast32_t>();
|
||||
auto n = j.get<int_fast32_t>();
|
||||
CHECK(json(n) == j);
|
||||
}
|
||||
|
||||
SECTION("int64_fast_t")
|
||||
{
|
||||
int_fast64_t n = j.get<int_fast64_t>();
|
||||
auto n = j.get<int_fast64_t>();
|
||||
CHECK(json(n) == j);
|
||||
}
|
||||
|
||||
SECTION("int8_least_t")
|
||||
{
|
||||
int_least8_t n = j.get<int_least8_t>();
|
||||
auto n = j.get<int_least8_t>();
|
||||
CHECK(json(n) == j);
|
||||
}
|
||||
|
||||
SECTION("int16_least_t")
|
||||
{
|
||||
int_least16_t n = j.get<int_least16_t>();
|
||||
auto n = j.get<int_least16_t>();
|
||||
CHECK(json(n) == j);
|
||||
}
|
||||
|
||||
SECTION("int32_least_t")
|
||||
{
|
||||
int_least32_t n = j.get<int_least32_t>();
|
||||
auto n = j.get<int_least32_t>();
|
||||
CHECK(json(n) == j);
|
||||
}
|
||||
|
||||
SECTION("int64_least_t")
|
||||
{
|
||||
int_least64_t n = j.get<int_least64_t>();
|
||||
auto n = j.get<int_least64_t>();
|
||||
CHECK(json(n) == j);
|
||||
}
|
||||
|
||||
SECTION("uint8_t")
|
||||
{
|
||||
uint8_t n = j.get<uint8_t>();
|
||||
auto n = j.get<uint8_t>();
|
||||
CHECK(json(n) == j);
|
||||
}
|
||||
|
||||
SECTION("uint16_t")
|
||||
{
|
||||
uint16_t n = j.get<uint16_t>();
|
||||
auto n = j.get<uint16_t>();
|
||||
CHECK(json(n) == j);
|
||||
}
|
||||
|
||||
SECTION("uint32_t")
|
||||
{
|
||||
uint32_t n = j.get<uint32_t>();
|
||||
auto n = j.get<uint32_t>();
|
||||
CHECK(json(n) == j);
|
||||
}
|
||||
|
||||
SECTION("uint64_t")
|
||||
{
|
||||
uint64_t n = j.get<uint64_t>();
|
||||
auto n = j.get<uint64_t>();
|
||||
CHECK(json(n) == j);
|
||||
}
|
||||
|
||||
SECTION("uint8_fast_t")
|
||||
{
|
||||
uint_fast8_t n = j.get<uint_fast8_t>();
|
||||
auto n = j.get<uint_fast8_t>();
|
||||
CHECK(json(n) == j);
|
||||
}
|
||||
|
||||
SECTION("uint16_fast_t")
|
||||
{
|
||||
uint_fast16_t n = j.get<uint_fast16_t>();
|
||||
auto n = j.get<uint_fast16_t>();
|
||||
CHECK(json(n) == j);
|
||||
}
|
||||
|
||||
SECTION("uint32_fast_t")
|
||||
{
|
||||
uint_fast32_t n = j.get<uint_fast32_t>();
|
||||
auto n = j.get<uint_fast32_t>();
|
||||
CHECK(json(n) == j);
|
||||
}
|
||||
|
||||
SECTION("uint64_fast_t")
|
||||
{
|
||||
uint_fast64_t n = j.get<uint_fast64_t>();
|
||||
auto n = j.get<uint_fast64_t>();
|
||||
CHECK(json(n) == j);
|
||||
}
|
||||
|
||||
SECTION("uint8_least_t")
|
||||
{
|
||||
uint_least8_t n = j.get<uint_least8_t>();
|
||||
auto n = j.get<uint_least8_t>();
|
||||
CHECK(json(n) == j);
|
||||
}
|
||||
|
||||
SECTION("uint16_least_t")
|
||||
{
|
||||
uint_least16_t n = j.get<uint_least16_t>();
|
||||
auto n = j.get<uint_least16_t>();
|
||||
CHECK(json(n) == j);
|
||||
}
|
||||
|
||||
SECTION("uint32_least_t")
|
||||
{
|
||||
uint_least32_t n = j.get<uint_least32_t>();
|
||||
auto n = j.get<uint_least32_t>();
|
||||
CHECK(json(n) == j);
|
||||
}
|
||||
|
||||
SECTION("uint64_least_t")
|
||||
{
|
||||
uint_least64_t n = j.get<uint_least64_t>();
|
||||
auto n = j.get<uint_least64_t>();
|
||||
CHECK(json(n) == j);
|
||||
}
|
||||
|
||||
@@ -976,13 +976,13 @@ TEST_CASE("value conversion")
|
||||
|
||||
SECTION("number_integer_t")
|
||||
{
|
||||
json::number_integer_t n = j.get<json::number_integer_t>();
|
||||
auto n = j.get<json::number_integer_t>();
|
||||
CHECK(json(n) == j);
|
||||
}
|
||||
|
||||
SECTION("number_unsigned_t")
|
||||
{
|
||||
json::number_unsigned_t n = j_unsigned.get<json::number_unsigned_t>();
|
||||
auto n = j_unsigned.get<json::number_unsigned_t>();
|
||||
CHECK(json(n) == j_unsigned);
|
||||
}
|
||||
|
||||
@@ -1187,19 +1187,19 @@ TEST_CASE("value conversion")
|
||||
|
||||
SECTION("number_float_t")
|
||||
{
|
||||
json::number_float_t n = j.get<json::number_float_t>();
|
||||
auto n = j.get<json::number_float_t>();
|
||||
CHECK(json(n).m_value.number_float == Approx(j.m_value.number_float));
|
||||
}
|
||||
|
||||
SECTION("float")
|
||||
{
|
||||
float n = j.get<float>();
|
||||
auto n = j.get<float>();
|
||||
CHECK(json(n).m_value.number_float == Approx(j.m_value.number_float));
|
||||
}
|
||||
|
||||
SECTION("double")
|
||||
{
|
||||
double n = j.get<double>();
|
||||
auto n = j.get<double>();
|
||||
CHECK(json(n).m_value.number_float == Approx(j.m_value.number_float));
|
||||
}
|
||||
|
||||
@@ -1639,6 +1639,7 @@ TEST_CASE("value conversion")
|
||||
|
||||
enum class cards {kreuz, pik, herz, karo};
|
||||
|
||||
// NOLINTNEXTLINE(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays) - false positive
|
||||
NLOHMANN_JSON_SERIALIZE_ENUM(cards,
|
||||
{
|
||||
{cards::kreuz, "kreuz"},
|
||||
@@ -1656,6 +1657,7 @@ enum TaskState
|
||||
TS_INVALID = -1,
|
||||
};
|
||||
|
||||
// NOLINTNEXTLINE(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays) - false positive
|
||||
NLOHMANN_JSON_SERIALIZE_ENUM(TaskState,
|
||||
{
|
||||
{TS_INVALID, nullptr},
|
||||
|
||||
@@ -42,13 +42,13 @@ struct SaxEventLogger : public nlohmann::json_sax<json>
|
||||
{
|
||||
bool null() override
|
||||
{
|
||||
events.push_back("null()");
|
||||
events.emplace_back("null()");
|
||||
return true;
|
||||
}
|
||||
|
||||
bool boolean(bool val) override
|
||||
{
|
||||
events.push_back(val ? "boolean(true)" : "boolean(false)");
|
||||
events.emplace_back(val ? "boolean(true)" : "boolean(false)");
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ struct SaxEventLogger : public nlohmann::json_sax<json>
|
||||
return true;
|
||||
}
|
||||
|
||||
bool number_float(json::number_float_t, const std::string& s) override
|
||||
bool number_float(json::number_float_t /*val*/, const std::string& s) override
|
||||
{
|
||||
events.push_back("number_float(" + s + ")");
|
||||
return true;
|
||||
@@ -79,7 +79,7 @@ struct SaxEventLogger : public nlohmann::json_sax<json>
|
||||
bool binary(json::binary_t& val) override
|
||||
{
|
||||
std::string binary_contents = "binary(";
|
||||
std::string comma_space = "";
|
||||
std::string comma_space;
|
||||
for (auto b : val)
|
||||
{
|
||||
binary_contents.append(comma_space);
|
||||
@@ -95,7 +95,7 @@ struct SaxEventLogger : public nlohmann::json_sax<json>
|
||||
{
|
||||
if (elements == std::size_t(-1))
|
||||
{
|
||||
events.push_back("start_object()");
|
||||
events.emplace_back("start_object()");
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -112,7 +112,7 @@ struct SaxEventLogger : public nlohmann::json_sax<json>
|
||||
|
||||
bool end_object() override
|
||||
{
|
||||
events.push_back("end_object()");
|
||||
events.emplace_back("end_object()");
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -120,7 +120,7 @@ struct SaxEventLogger : public nlohmann::json_sax<json>
|
||||
{
|
||||
if (elements == std::size_t(-1))
|
||||
{
|
||||
events.push_back("start_array()");
|
||||
events.emplace_back("start_array()");
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -131,11 +131,11 @@ struct SaxEventLogger : public nlohmann::json_sax<json>
|
||||
|
||||
bool end_array() override
|
||||
{
|
||||
events.push_back("end_array()");
|
||||
events.emplace_back("end_array()");
|
||||
return true;
|
||||
}
|
||||
|
||||
bool parse_error(std::size_t position, const std::string&, const json::exception&) override
|
||||
bool parse_error(std::size_t position, const std::string& /*last_token*/, const json::exception& /*ex*/) override
|
||||
{
|
||||
events.push_back("parse_error(" + std::to_string(position) + ")");
|
||||
return false;
|
||||
@@ -150,7 +150,7 @@ struct SaxEventLoggerExitAfterStartObject : public SaxEventLogger
|
||||
{
|
||||
if (elements == std::size_t(-1))
|
||||
{
|
||||
events.push_back("start_object()");
|
||||
events.emplace_back("start_object()");
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -175,7 +175,7 @@ struct SaxEventLoggerExitAfterStartArray : public SaxEventLogger
|
||||
{
|
||||
if (elements == std::size_t(-1))
|
||||
{
|
||||
events.push_back("start_array()");
|
||||
events.emplace_back("start_array()");
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -184,7 +184,7 @@ struct SaxEventLoggerExitAfterStartArray : public SaxEventLogger
|
||||
return false;
|
||||
}
|
||||
};
|
||||
}
|
||||
} // namespace
|
||||
|
||||
TEST_CASE("deserialization")
|
||||
{
|
||||
@@ -192,10 +192,12 @@ TEST_CASE("deserialization")
|
||||
{
|
||||
SECTION("stream")
|
||||
{
|
||||
std::stringstream ss1, ss2, ss3;
|
||||
ss1 << "[\"foo\",1,2,3,false,{\"one\":1}]";
|
||||
ss2 << "[\"foo\",1,2,3,false,{\"one\":1}]";
|
||||
ss3 << "[\"foo\",1,2,3,false,{\"one\":1}]";
|
||||
std::stringstream ss1;
|
||||
std::stringstream ss2;
|
||||
std::stringstream ss3;
|
||||
ss1 << R"(["foo",1,2,3,false,{"one":1}])";
|
||||
ss2 << R"(["foo",1,2,3,false,{"one":1}])";
|
||||
ss3 << R"(["foo",1,2,3,false,{"one":1}])";
|
||||
json j = json::parse(ss1);
|
||||
CHECK(json::accept(ss2));
|
||||
CHECK(j == json({"foo", 1, 2, 3, false, {{"one", 1}}}));
|
||||
@@ -214,7 +216,7 @@ TEST_CASE("deserialization")
|
||||
|
||||
SECTION("string literal")
|
||||
{
|
||||
auto s = "[\"foo\",1,2,3,false,{\"one\":1}]";
|
||||
const auto* s = R"(["foo",1,2,3,false,{"one":1}])";
|
||||
json j = json::parse(s);
|
||||
CHECK(json::accept(s));
|
||||
CHECK(j == json({"foo", 1, 2, 3, false, {{"one", 1}}}));
|
||||
@@ -233,7 +235,7 @@ TEST_CASE("deserialization")
|
||||
|
||||
SECTION("string_t")
|
||||
{
|
||||
json::string_t s = "[\"foo\",1,2,3,false,{\"one\":1}]";
|
||||
json::string_t s = R"(["foo",1,2,3,false,{"one":1}])";
|
||||
json j = json::parse(s);
|
||||
CHECK(json::accept(s));
|
||||
CHECK(j == json({"foo", 1, 2, 3, false, {{"one", 1}}}));
|
||||
@@ -253,7 +255,7 @@ TEST_CASE("deserialization")
|
||||
SECTION("operator<<")
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << "[\"foo\",1,2,3,false,{\"one\":1}]";
|
||||
ss << R"(["foo",1,2,3,false,{"one":1}])";
|
||||
json j;
|
||||
j << ss;
|
||||
CHECK(j == json({"foo", 1, 2, 3, false, {{"one", 1}}}));
|
||||
@@ -262,7 +264,7 @@ TEST_CASE("deserialization")
|
||||
SECTION("operator>>")
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << "[\"foo\",1,2,3,false,{\"one\":1}]";
|
||||
ss << R"(["foo",1,2,3,false,{"one":1}])";
|
||||
json j;
|
||||
ss >> j;
|
||||
CHECK(j == json({"foo", 1, 2, 3, false, {{"one", 1}}}));
|
||||
@@ -278,12 +280,16 @@ TEST_CASE("deserialization")
|
||||
{
|
||||
SECTION("stream")
|
||||
{
|
||||
std::stringstream ss1, ss2, ss3, ss4, ss5;
|
||||
ss1 << "[\"foo\",1,2,3,false,{\"one\":1}";
|
||||
ss2 << "[\"foo\",1,2,3,false,{\"one\":1}";
|
||||
ss3 << "[\"foo\",1,2,3,false,{\"one\":1}";
|
||||
ss4 << "[\"foo\",1,2,3,false,{\"one\":1}";
|
||||
ss5 << "[\"foo\",1,2,3,false,{\"one\":1}";
|
||||
std::stringstream ss1;
|
||||
std::stringstream ss2;
|
||||
std::stringstream ss3;
|
||||
std::stringstream ss4;
|
||||
std::stringstream ss5;
|
||||
ss1 << R"(["foo",1,2,3,false,{"one":1})";
|
||||
ss2 << R"(["foo",1,2,3,false,{"one":1})";
|
||||
ss3 << R"(["foo",1,2,3,false,{"one":1})";
|
||||
ss4 << R"(["foo",1,2,3,false,{"one":1})";
|
||||
ss5 << R"(["foo",1,2,3,false,{"one":1})";
|
||||
|
||||
json _;
|
||||
CHECK_THROWS_AS(_ = json::parse(ss1), json::parse_error&);
|
||||
@@ -309,7 +315,7 @@ TEST_CASE("deserialization")
|
||||
|
||||
SECTION("string")
|
||||
{
|
||||
json::string_t s = "[\"foo\",1,2,3,false,{\"one\":1}";
|
||||
json::string_t s = R"(["foo",1,2,3,false,{"one":1})";
|
||||
json _;
|
||||
CHECK_THROWS_AS(_ = json::parse(s), json::parse_error&);
|
||||
CHECK_THROWS_WITH(_ = json::parse(s),
|
||||
@@ -334,9 +340,10 @@ TEST_CASE("deserialization")
|
||||
|
||||
SECTION("operator<<")
|
||||
{
|
||||
std::stringstream ss1, ss2;
|
||||
ss1 << "[\"foo\",1,2,3,false,{\"one\":1}";
|
||||
ss2 << "[\"foo\",1,2,3,false,{\"one\":1}";
|
||||
std::stringstream ss1;
|
||||
std::stringstream ss2;
|
||||
ss1 << R"(["foo",1,2,3,false,{"one":1})";
|
||||
ss2 << R"(["foo",1,2,3,false,{"one":1})";
|
||||
json j;
|
||||
CHECK_THROWS_AS(j << ss1, json::parse_error&);
|
||||
CHECK_THROWS_WITH(j << ss2,
|
||||
@@ -345,9 +352,10 @@ TEST_CASE("deserialization")
|
||||
|
||||
SECTION("operator>>")
|
||||
{
|
||||
std::stringstream ss1, ss2;
|
||||
ss1 << "[\"foo\",1,2,3,false,{\"one\":1}";
|
||||
ss2 << "[\"foo\",1,2,3,false,{\"one\":1}";
|
||||
std::stringstream ss1;
|
||||
std::stringstream ss2;
|
||||
ss1 << R"(["foo",1,2,3,false,{"one":1})";
|
||||
ss2 << R"(["foo",1,2,3,false,{"one":1})";
|
||||
json j;
|
||||
CHECK_THROWS_AS(ss1 >> j, json::parse_error&);
|
||||
CHECK_THROWS_WITH(ss2 >> j,
|
||||
@@ -392,7 +400,7 @@ TEST_CASE("deserialization")
|
||||
|
||||
SECTION("from array")
|
||||
{
|
||||
uint8_t v[] = {'t', 'r', 'u', 'e'};
|
||||
uint8_t v[] = {'t', 'r', 'u', 'e'}; // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays)
|
||||
CHECK(json::parse(v) == json(true));
|
||||
CHECK(json::accept(v));
|
||||
|
||||
@@ -404,7 +412,7 @@ TEST_CASE("deserialization")
|
||||
|
||||
SECTION("from chars")
|
||||
{
|
||||
uint8_t* v = new uint8_t[5];
|
||||
auto* v = new uint8_t[5]; // NOLINT(cppcoreguidelines-owning-memory)
|
||||
v[0] = 't';
|
||||
v[1] = 'r';
|
||||
v[2] = 'u';
|
||||
@@ -418,7 +426,7 @@ TEST_CASE("deserialization")
|
||||
CHECK(l.events.size() == 1);
|
||||
CHECK(l.events == std::vector<std::string>({"boolean(true)"}));
|
||||
|
||||
delete[] v;
|
||||
delete[] v; // NOLINT(cppcoreguidelines-owning-memory)
|
||||
}
|
||||
|
||||
SECTION("from std::string")
|
||||
@@ -488,7 +496,7 @@ TEST_CASE("deserialization")
|
||||
|
||||
SECTION("from array")
|
||||
{
|
||||
uint8_t v[] = {'t', 'r', 'u', 'e'};
|
||||
uint8_t v[] = {'t', 'r', 'u', 'e'}; // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays)
|
||||
CHECK(json::parse(std::begin(v), std::end(v)) == json(true));
|
||||
CHECK(json::accept(std::begin(v), std::end(v)));
|
||||
|
||||
@@ -553,7 +561,7 @@ TEST_CASE("deserialization")
|
||||
{
|
||||
SECTION("case 1")
|
||||
{
|
||||
uint8_t v[] = {'\"', 'a', 'a', 'a', 'a', 'a', 'a', '\\', 'u'};
|
||||
std::array<std::uint8_t, 9> v = {{'\"', 'a', 'a', 'a', 'a', 'a', 'a', '\\', 'u'}};
|
||||
json _;
|
||||
CHECK_THROWS_AS(_ = json::parse(std::begin(v), std::end(v)), json::parse_error&);
|
||||
CHECK(!json::accept(std::begin(v), std::end(v)));
|
||||
@@ -570,7 +578,7 @@ TEST_CASE("deserialization")
|
||||
|
||||
SECTION("case 2")
|
||||
{
|
||||
uint8_t v[] = {'\"', 'a', 'a', 'a', 'a', 'a', 'a', '\\', 'u', '1'};
|
||||
std::array<std::uint8_t, 10> v = {{'\"', 'a', 'a', 'a', 'a', 'a', 'a', '\\', 'u', '1'}};
|
||||
json _;
|
||||
CHECK_THROWS_AS(_ = json::parse(std::begin(v), std::end(v)), json::parse_error&);
|
||||
CHECK(!json::accept(std::begin(v), std::end(v)));
|
||||
@@ -587,7 +595,7 @@ TEST_CASE("deserialization")
|
||||
|
||||
SECTION("case 3")
|
||||
{
|
||||
uint8_t v[] = {'\"', 'a', 'a', 'a', 'a', 'a', 'a', '\\', 'u', '1', '1', '1', '1', '1', '1', '1', '1'};
|
||||
std::array<std::uint8_t, 17> v = {{'\"', 'a', 'a', 'a', 'a', 'a', 'a', '\\', 'u', '1', '1', '1', '1', '1', '1', '1', '1'}};
|
||||
json _;
|
||||
CHECK_THROWS_AS(_ = json::parse(std::begin(v), std::end(v)), json::parse_error&);
|
||||
CHECK(!json::accept(std::begin(v), std::end(v)));
|
||||
@@ -604,7 +612,7 @@ TEST_CASE("deserialization")
|
||||
|
||||
SECTION("case 4")
|
||||
{
|
||||
uint8_t v[] = {'\"', 'a', 'a', 'a', 'a', 'a', 'a', 'u', '1', '1', '1', '1', '1', '1', '1', '1', '\\'};
|
||||
std::array<std::uint8_t, 17> v = {{'\"', 'a', 'a', 'a', 'a', 'a', 'a', 'u', '1', '1', '1', '1', '1', '1', '1', '1', '\\'}};
|
||||
json _;
|
||||
CHECK_THROWS_AS(_ = json::parse(std::begin(v), std::end(v)), json::parse_error&);
|
||||
CHECK(!json::accept(std::begin(v), std::end(v)));
|
||||
@@ -621,7 +629,7 @@ TEST_CASE("deserialization")
|
||||
|
||||
SECTION("case 5")
|
||||
{
|
||||
uint8_t v[] = {'\"', 0x7F, 0xC1};
|
||||
std::array<std::uint8_t, 3> v = {{'\"', 0x7F, 0xC1}};
|
||||
json _;
|
||||
CHECK_THROWS_AS(_ = json::parse(std::begin(v), std::end(v)), json::parse_error&);
|
||||
CHECK(!json::accept(std::begin(v), std::end(v)));
|
||||
@@ -638,7 +646,7 @@ TEST_CASE("deserialization")
|
||||
|
||||
SECTION("case 6")
|
||||
{
|
||||
uint8_t v[] = {'\"', 0x7F, 0xDF, 0x7F};
|
||||
std::array<std::uint8_t, 4> v = {{'\"', 0x7F, 0xDF, 0x7F}};
|
||||
json _;
|
||||
CHECK_THROWS_AS(_ = json::parse(std::begin(v), std::end(v)), json::parse_error&);
|
||||
CHECK_THROWS_WITH(_ = json::parse(std::begin(v), std::end(v)),
|
||||
@@ -657,7 +665,7 @@ TEST_CASE("deserialization")
|
||||
|
||||
SECTION("case 7")
|
||||
{
|
||||
uint8_t v[] = {'\"', 0x7F, 0xDF, 0xC0};
|
||||
std::array<std::uint8_t, 4> v = {{'\"', 0x7F, 0xDF, 0xC0}};
|
||||
json _;
|
||||
CHECK_THROWS_AS(_ = json::parse(std::begin(v), std::end(v)), json::parse_error&);
|
||||
CHECK(!json::accept(std::begin(v), std::end(v)));
|
||||
@@ -674,7 +682,7 @@ TEST_CASE("deserialization")
|
||||
|
||||
SECTION("case 8")
|
||||
{
|
||||
uint8_t v[] = {'\"', 0x7F, 0xE0, 0x9F};
|
||||
std::array<std::uint8_t, 4> v = {{'\"', 0x7F, 0xE0, 0x9F}};
|
||||
json _;
|
||||
CHECK_THROWS_AS(_ = json::parse(std::begin(v), std::end(v)), json::parse_error&);
|
||||
CHECK(!json::accept(std::begin(v), std::end(v)));
|
||||
@@ -691,7 +699,7 @@ TEST_CASE("deserialization")
|
||||
|
||||
SECTION("case 9")
|
||||
{
|
||||
uint8_t v[] = {'\"', 0x7F, 0xEF, 0xC0};
|
||||
std::array<std::uint8_t, 4> v = {{'\"', 0x7F, 0xEF, 0xC0}};
|
||||
json _;
|
||||
CHECK_THROWS_AS(_ = json::parse(std::begin(v), std::end(v)), json::parse_error&);
|
||||
CHECK(!json::accept(std::begin(v), std::end(v)));
|
||||
@@ -708,7 +716,7 @@ TEST_CASE("deserialization")
|
||||
|
||||
SECTION("case 10")
|
||||
{
|
||||
uint8_t v[] = {'\"', 0x7F, 0xED, 0x7F};
|
||||
std::array<std::uint8_t, 4> v = {{'\"', 0x7F, 0xED, 0x7F}};
|
||||
json _;
|
||||
CHECK_THROWS_AS(_ = json::parse(std::begin(v), std::end(v)), json::parse_error&);
|
||||
CHECK(!json::accept(std::begin(v), std::end(v)));
|
||||
@@ -725,7 +733,7 @@ TEST_CASE("deserialization")
|
||||
|
||||
SECTION("case 11")
|
||||
{
|
||||
uint8_t v[] = {'\"', 0x7F, 0xF0, 0x8F};
|
||||
std::array<std::uint8_t, 4> v = {{'\"', 0x7F, 0xF0, 0x8F}};
|
||||
json _;
|
||||
CHECK_THROWS_AS(_ = json::parse(std::begin(v), std::end(v)), json::parse_error&);
|
||||
CHECK(!json::accept(std::begin(v), std::end(v)));
|
||||
@@ -742,7 +750,7 @@ TEST_CASE("deserialization")
|
||||
|
||||
SECTION("case 12")
|
||||
{
|
||||
uint8_t v[] = {'\"', 0x7F, 0xF0, 0xC0};
|
||||
std::array<std::uint8_t, 4> v = {{'\"', 0x7F, 0xF0, 0xC0}};
|
||||
json _;
|
||||
CHECK_THROWS_AS(_ = json::parse(std::begin(v), std::end(v)), json::parse_error&);
|
||||
CHECK(!json::accept(std::begin(v), std::end(v)));
|
||||
@@ -759,7 +767,7 @@ TEST_CASE("deserialization")
|
||||
|
||||
SECTION("case 13")
|
||||
{
|
||||
uint8_t v[] = {'\"', 0x7F, 0xF3, 0x7F};
|
||||
std::array<std::uint8_t, 4> v = {{'\"', 0x7F, 0xF3, 0x7F}};
|
||||
json _;
|
||||
CHECK_THROWS_AS(_ = json::parse(std::begin(v), std::end(v)), json::parse_error&);
|
||||
CHECK(!json::accept(std::begin(v), std::end(v)));
|
||||
@@ -776,7 +784,7 @@ TEST_CASE("deserialization")
|
||||
|
||||
SECTION("case 14")
|
||||
{
|
||||
uint8_t v[] = {'\"', 0x7F, 0xF3, 0xC0};
|
||||
std::array<std::uint8_t, 4> v = {{'\"', 0x7F, 0xF3, 0xC0}};
|
||||
json _;
|
||||
CHECK_THROWS_AS(_ = json::parse(std::begin(v), std::end(v)), json::parse_error&);
|
||||
CHECK(!json::accept(std::begin(v), std::end(v)));
|
||||
@@ -793,7 +801,7 @@ TEST_CASE("deserialization")
|
||||
|
||||
SECTION("case 15")
|
||||
{
|
||||
uint8_t v[] = {'\"', 0x7F, 0xF4, 0x7F};
|
||||
std::array<std::uint8_t, 4> v = {{'\"', 0x7F, 0xF4, 0x7F}};
|
||||
json _;
|
||||
CHECK_THROWS_AS(_ = json::parse(std::begin(v), std::end(v)), json::parse_error&);
|
||||
CHECK(!json::accept(std::begin(v), std::end(v)));
|
||||
@@ -810,7 +818,7 @@ TEST_CASE("deserialization")
|
||||
|
||||
SECTION("case 16")
|
||||
{
|
||||
uint8_t v[] = {'{', '\"', '\"', ':', '1', '1'};
|
||||
std::array<std::uint8_t, 6> v = {{'{', '\"', '\"', ':', '1', '1'}};
|
||||
json _;
|
||||
CHECK_THROWS_AS(_ = json::parse(std::begin(v), std::end(v)), json::parse_error&);
|
||||
CHECK(!json::accept(std::begin(v), std::end(v)));
|
||||
@@ -860,7 +868,8 @@ TEST_CASE("deserialization")
|
||||
CHECK(json::parse(bom + "1") == 1);
|
||||
CHECK(json::parse(std::istringstream(bom + "1")) == 1);
|
||||
|
||||
SaxEventLogger l1, l2;
|
||||
SaxEventLogger l1;
|
||||
SaxEventLogger l2;
|
||||
CHECK(json::sax_parse(std::istringstream(bom + "1"), &l1));
|
||||
CHECK(json::sax_parse(bom + "1", &l2));
|
||||
CHECK(l1.events.size() == 1);
|
||||
@@ -886,7 +895,8 @@ TEST_CASE("deserialization")
|
||||
CHECK_THROWS_WITH(_ = json::parse(std::istringstream(bom.substr(0, 2))),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 3: syntax error while parsing value - invalid BOM; must be 0xEF 0xBB 0xBF if given; last read: '\xEF\xBB'");
|
||||
|
||||
SaxEventLogger l1, l2;
|
||||
SaxEventLogger l1;
|
||||
SaxEventLogger l2;
|
||||
CHECK(!json::sax_parse(std::istringstream(bom.substr(0, 2)), &l1));
|
||||
CHECK(!json::sax_parse(bom.substr(0, 2), &l2));
|
||||
CHECK(l1.events.size() == 1);
|
||||
@@ -912,7 +922,8 @@ TEST_CASE("deserialization")
|
||||
CHECK_THROWS_WITH(_ = json::parse(std::istringstream(bom.substr(0, 1))),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing value - invalid BOM; must be 0xEF 0xBB 0xBF if given; last read: '\xEF'");
|
||||
|
||||
SaxEventLogger l1, l2;
|
||||
SaxEventLogger l1;
|
||||
SaxEventLogger l2;
|
||||
CHECK(!json::sax_parse(std::istringstream(bom.substr(0, 1)), &l1));
|
||||
CHECK(!json::sax_parse(bom.substr(0, 1), &l2));
|
||||
CHECK(l1.events.size() == 1);
|
||||
@@ -942,7 +953,7 @@ TEST_CASE("deserialization")
|
||||
CAPTURE(i1)
|
||||
CAPTURE(i2)
|
||||
|
||||
std::string s = "";
|
||||
std::string s;
|
||||
s.push_back(static_cast<char>(bom[0] + i0));
|
||||
s.push_back(static_cast<char>(bom[1] + i1));
|
||||
s.push_back(static_cast<char>(bom[2] + i2));
|
||||
@@ -1012,7 +1023,7 @@ TEST_CASE("deserialization")
|
||||
|
||||
SECTION("SAX and early abort")
|
||||
{
|
||||
std::string s = "[1, [\"string\", 43.12], null, {\"key1\": true, \"key2\": false}]";
|
||||
std::string s = R"([1, ["string", 43.12], null, {"key1": true, "key2": false}])";
|
||||
|
||||
SaxEventLogger default_logger;
|
||||
SaxEventLoggerExitAfterStartObject exit_after_start_object;
|
||||
|
||||
177
test/src/unit-diagnostics.cpp
Normal file
177
test/src/unit-diagnostics.cpp
Normal file
@@ -0,0 +1,177 @@
|
||||
/*
|
||||
__ _____ _____ _____
|
||||
__| | __| | | | JSON for Modern C++ (test suite)
|
||||
| | |__ | | | | | | version 3.9.1
|
||||
|_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
|
||||
Licensed under the MIT License <http://opensource.org/licenses/MIT>.
|
||||
SPDX-License-Identifier: MIT
|
||||
Copyright (c) 2013-2019 Niels Lohmann <http://nlohmann.me>.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "doctest_compatibility.h"
|
||||
|
||||
#ifdef JSON_DIAGNOSTICS
|
||||
#undef JSON_DIAGNOSTICS
|
||||
#endif
|
||||
|
||||
#define JSON_DIAGNOSTICS 1
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
using nlohmann::json;
|
||||
|
||||
TEST_CASE("Better diagnostics")
|
||||
{
|
||||
SECTION("empty JSON Pointer")
|
||||
{
|
||||
json j = 1;
|
||||
std::string s;
|
||||
CHECK_THROWS_WITH_AS(s = j.get<std::string>(), "[json.exception.type_error.302] type must be string, but is number", json::type_error);
|
||||
}
|
||||
|
||||
SECTION("invalid type")
|
||||
{
|
||||
json j;
|
||||
j["a"]["b"]["c"] = 1;
|
||||
std::string s;
|
||||
CHECK_THROWS_WITH_AS(s = j["a"]["b"]["c"].get<std::string>(), "[json.exception.type_error.302] (/a/b/c) type must be string, but is number", json::type_error);
|
||||
}
|
||||
|
||||
SECTION("missing key")
|
||||
{
|
||||
json j;
|
||||
j["object"]["object"] = true;
|
||||
CHECK_THROWS_WITH_AS(j["object"].at("not_found"), "[json.exception.out_of_range.403] (/object) key 'not_found' not found", json::out_of_range);
|
||||
}
|
||||
|
||||
SECTION("array index out of range")
|
||||
{
|
||||
json j;
|
||||
j["array"][4] = true;
|
||||
CHECK_THROWS_WITH_AS(j["array"].at(5), "[json.exception.out_of_range.401] (/array) array index 5 is out of range", json::out_of_range);
|
||||
}
|
||||
|
||||
SECTION("array index at wrong type")
|
||||
{
|
||||
json j;
|
||||
j["array"][4] = true;
|
||||
CHECK_THROWS_WITH_AS(j["array"][4][5], "[json.exception.type_error.305] (/array/4) cannot use operator[] with a numeric argument with boolean", json::type_error);
|
||||
}
|
||||
|
||||
SECTION("wrong iterator")
|
||||
{
|
||||
json j;
|
||||
j["array"] = json::array();
|
||||
CHECK_THROWS_WITH_AS(j["array"].erase(j.begin()), "[json.exception.invalid_iterator.202] (/array) iterator does not fit current value", json::invalid_iterator);
|
||||
}
|
||||
|
||||
SECTION("JSON Pointer escaping")
|
||||
{
|
||||
json j;
|
||||
j["a/b"]["m~n"] = 1;
|
||||
std::string s;
|
||||
CHECK_THROWS_WITH_AS(s = j["a/b"]["m~n"].get<std::string>(), "[json.exception.type_error.302] (/a~1b/m~0n) type must be string, but is number", json::type_error);
|
||||
}
|
||||
|
||||
SECTION("Parse error")
|
||||
{
|
||||
json _;
|
||||
CHECK_THROWS_WITH_AS(_ = json::parse(""), "[json.exception.parse_error.101] parse error at line 1, column 1: syntax error while parsing value - unexpected end of input; expected '[', '{', or a literal", json::parse_error);
|
||||
}
|
||||
|
||||
SECTION("Regression test for https://github.com/nlohmann/json/pull/2562#pullrequestreview-574858448")
|
||||
{
|
||||
CHECK_THROWS_WITH_AS(json({"0", "0"})[1].get<int>(), "[json.exception.type_error.302] (/1) type must be number, but is string", json::type_error);
|
||||
CHECK_THROWS_WITH_AS(json({"0", "1"})[1].get<int>(), "[json.exception.type_error.302] (/1) type must be number, but is string", json::type_error);
|
||||
}
|
||||
|
||||
SECTION("Regression test for https://github.com/nlohmann/json/pull/2562/files/380a613f2b5d32425021129cd1f371ddcfd54ddf#r563259793")
|
||||
{
|
||||
json j;
|
||||
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);
|
||||
}
|
||||
|
||||
SECTION("Regression test for https://github.com/nlohmann/json/issues/2838")
|
||||
{
|
||||
// void push_back(basic_json&& val)
|
||||
{
|
||||
json j_arr = json::array();
|
||||
j_arr.push_back(json::object());
|
||||
j_arr.push_back(json::object());
|
||||
j_arr.push_back(json::object());
|
||||
j_arr.push_back(json::object());
|
||||
json j_obj = json::object();
|
||||
j_obj["key"] = j_arr;
|
||||
}
|
||||
|
||||
// void push_back(const basic_json& val)
|
||||
{
|
||||
json j_arr = json::array();
|
||||
auto object = json::object();
|
||||
j_arr.push_back(object);
|
||||
j_arr.push_back(object);
|
||||
j_arr.push_back(object);
|
||||
j_arr.push_back(object);
|
||||
json j_obj = json::object();
|
||||
j_obj["key"] = j_arr;
|
||||
}
|
||||
|
||||
// reference emplace_back(Args&& ... args)
|
||||
{
|
||||
json j_arr = json::array();
|
||||
j_arr.emplace_back(json::object());
|
||||
j_arr.emplace_back(json::object());
|
||||
j_arr.emplace_back(json::object());
|
||||
j_arr.emplace_back(json::object());
|
||||
json j_obj = json::object();
|
||||
j_obj["key"] = j_arr;
|
||||
}
|
||||
|
||||
// iterator insert(const_iterator pos, const basic_json& val)
|
||||
{
|
||||
json j_arr = json::array();
|
||||
j_arr.insert(j_arr.begin(), json::object());
|
||||
j_arr.insert(j_arr.begin(), json::object());
|
||||
j_arr.insert(j_arr.begin(), json::object());
|
||||
j_arr.insert(j_arr.begin(), json::object());
|
||||
json j_obj = json::object();
|
||||
j_obj["key"] = j_arr;
|
||||
}
|
||||
|
||||
// iterator insert(const_iterator pos, size_type cnt, const basic_json& val)
|
||||
{
|
||||
json j_arr = json::array();
|
||||
j_arr.insert(j_arr.begin(), 2, json::object());
|
||||
json j_obj = json::object();
|
||||
j_obj["key"] = j_arr;
|
||||
}
|
||||
|
||||
// iterator insert(const_iterator pos, const_iterator first, const_iterator last)
|
||||
{
|
||||
json j_arr = json::array();
|
||||
json j_objects = {json::object(), json::object()};
|
||||
j_arr.insert(j_arr.begin(), j_objects.begin(), j_objects.end());
|
||||
json j_obj = json::object();
|
||||
j_obj["key"] = j_arr;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -202,7 +202,7 @@ TEST_CASE("element access 2")
|
||||
SECTION("null")
|
||||
{
|
||||
json j_nonobject(json::value_t::null);
|
||||
const json j_nonobject_const(j_nonobject);
|
||||
const json j_nonobject_const(json::value_t::null);
|
||||
CHECK_THROWS_AS(j_nonobject.value("foo", 1), json::type_error&);
|
||||
CHECK_THROWS_AS(j_nonobject_const.value("foo", 1), json::type_error&);
|
||||
CHECK_THROWS_WITH(j_nonobject.value("foo", 1),
|
||||
@@ -214,7 +214,7 @@ TEST_CASE("element access 2")
|
||||
SECTION("boolean")
|
||||
{
|
||||
json j_nonobject(json::value_t::boolean);
|
||||
const json j_nonobject_const(j_nonobject);
|
||||
const json j_nonobject_const(json::value_t::boolean);
|
||||
CHECK_THROWS_AS(j_nonobject.value("foo", 1), json::type_error&);
|
||||
CHECK_THROWS_AS(j_nonobject_const.value("foo", 1), json::type_error&);
|
||||
CHECK_THROWS_WITH(j_nonobject.value("foo", 1),
|
||||
@@ -226,7 +226,7 @@ TEST_CASE("element access 2")
|
||||
SECTION("string")
|
||||
{
|
||||
json j_nonobject(json::value_t::string);
|
||||
const json j_nonobject_const(j_nonobject);
|
||||
const json j_nonobject_const(json::value_t::string);
|
||||
CHECK_THROWS_AS(j_nonobject.value("foo", 1), json::type_error&);
|
||||
CHECK_THROWS_AS(j_nonobject_const.value("foo", 1), json::type_error&);
|
||||
CHECK_THROWS_WITH(j_nonobject.value("foo", 1),
|
||||
@@ -238,7 +238,7 @@ TEST_CASE("element access 2")
|
||||
SECTION("array")
|
||||
{
|
||||
json j_nonobject(json::value_t::array);
|
||||
const json j_nonobject_const(j_nonobject);
|
||||
const json j_nonobject_const(json::value_t::array);
|
||||
CHECK_THROWS_AS(j_nonobject.value("foo", 1), json::type_error&);
|
||||
CHECK_THROWS_AS(j_nonobject_const.value("foo", 1), json::type_error&);
|
||||
CHECK_THROWS_WITH(j_nonobject.value("foo", 1),
|
||||
@@ -250,7 +250,7 @@ TEST_CASE("element access 2")
|
||||
SECTION("number (integer)")
|
||||
{
|
||||
json j_nonobject(json::value_t::number_integer);
|
||||
const json j_nonobject_const(j_nonobject);
|
||||
const json j_nonobject_const(json::value_t::number_integer);
|
||||
CHECK_THROWS_AS(j_nonobject.value("foo", 1), json::type_error&);
|
||||
CHECK_THROWS_AS(j_nonobject_const.value("foo", 1), json::type_error&);
|
||||
CHECK_THROWS_WITH(j_nonobject.value("foo", 1),
|
||||
@@ -262,7 +262,7 @@ TEST_CASE("element access 2")
|
||||
SECTION("number (unsigned)")
|
||||
{
|
||||
json j_nonobject(json::value_t::number_unsigned);
|
||||
const json j_nonobject_const(j_nonobject);
|
||||
const json j_nonobject_const(json::value_t::number_unsigned);
|
||||
CHECK_THROWS_AS(j_nonobject.value("foo", 1), json::type_error&);
|
||||
CHECK_THROWS_AS(j_nonobject_const.value("foo", 1), json::type_error&);
|
||||
CHECK_THROWS_WITH(j_nonobject.value("foo", 1),
|
||||
@@ -274,7 +274,7 @@ TEST_CASE("element access 2")
|
||||
SECTION("number (floating-point)")
|
||||
{
|
||||
json j_nonobject(json::value_t::number_float);
|
||||
const json j_nonobject_const(j_nonobject);
|
||||
const json j_nonobject_const(json::value_t::number_float);
|
||||
CHECK_THROWS_AS(j_nonobject.value("foo", 1), json::type_error&);
|
||||
CHECK_THROWS_AS(j_nonobject_const.value("foo", 1), json::type_error&);
|
||||
CHECK_THROWS_WITH(j_nonobject.value("foo", 1),
|
||||
@@ -320,7 +320,7 @@ TEST_CASE("element access 2")
|
||||
SECTION("null")
|
||||
{
|
||||
json j_nonobject(json::value_t::null);
|
||||
const json j_nonobject_const(j_nonobject);
|
||||
const json j_nonobject_const(json::value_t::null);
|
||||
CHECK_THROWS_AS(j_nonobject.value("/foo"_json_pointer, 1), json::type_error&);
|
||||
CHECK_THROWS_AS(j_nonobject_const.value("/foo"_json_pointer, 1), json::type_error&);
|
||||
CHECK_THROWS_WITH(j_nonobject.value("/foo"_json_pointer, 1),
|
||||
@@ -332,7 +332,7 @@ TEST_CASE("element access 2")
|
||||
SECTION("boolean")
|
||||
{
|
||||
json j_nonobject(json::value_t::boolean);
|
||||
const json j_nonobject_const(j_nonobject);
|
||||
const json j_nonobject_const(json::value_t::boolean);
|
||||
CHECK_THROWS_AS(j_nonobject.value("/foo"_json_pointer, 1), json::type_error&);
|
||||
CHECK_THROWS_AS(j_nonobject_const.value("/foo"_json_pointer, 1), json::type_error&);
|
||||
CHECK_THROWS_WITH(j_nonobject.value("/foo"_json_pointer, 1),
|
||||
@@ -344,7 +344,7 @@ TEST_CASE("element access 2")
|
||||
SECTION("string")
|
||||
{
|
||||
json j_nonobject(json::value_t::string);
|
||||
const json j_nonobject_const(j_nonobject);
|
||||
const json j_nonobject_const(json::value_t::string);
|
||||
CHECK_THROWS_AS(j_nonobject.value("/foo"_json_pointer, 1), json::type_error&);
|
||||
CHECK_THROWS_AS(j_nonobject_const.value("/foo"_json_pointer, 1), json::type_error&);
|
||||
CHECK_THROWS_WITH(j_nonobject.value("/foo"_json_pointer, 1),
|
||||
@@ -356,7 +356,7 @@ TEST_CASE("element access 2")
|
||||
SECTION("array")
|
||||
{
|
||||
json j_nonobject(json::value_t::array);
|
||||
const json j_nonobject_const(j_nonobject);
|
||||
const json j_nonobject_const(json::value_t::array);
|
||||
CHECK_THROWS_AS(j_nonobject.value("/foo"_json_pointer, 1), json::type_error&);
|
||||
CHECK_THROWS_AS(j_nonobject_const.value("/foo"_json_pointer, 1), json::type_error&);
|
||||
CHECK_THROWS_WITH(j_nonobject.value("/foo"_json_pointer, 1),
|
||||
@@ -368,7 +368,7 @@ TEST_CASE("element access 2")
|
||||
SECTION("number (integer)")
|
||||
{
|
||||
json j_nonobject(json::value_t::number_integer);
|
||||
const json j_nonobject_const(j_nonobject);
|
||||
const json j_nonobject_const(json::value_t::number_integer);
|
||||
CHECK_THROWS_AS(j_nonobject.value("/foo"_json_pointer, 1), json::type_error&);
|
||||
CHECK_THROWS_AS(j_nonobject_const.value("/foo"_json_pointer, 1), json::type_error&);
|
||||
CHECK_THROWS_WITH(j_nonobject.value("/foo"_json_pointer, 1),
|
||||
@@ -380,7 +380,7 @@ TEST_CASE("element access 2")
|
||||
SECTION("number (unsigned)")
|
||||
{
|
||||
json j_nonobject(json::value_t::number_unsigned);
|
||||
const json j_nonobject_const(j_nonobject);
|
||||
const json j_nonobject_const(json::value_t::number_unsigned);
|
||||
CHECK_THROWS_AS(j_nonobject.value("/foo"_json_pointer, 1), json::type_error&);
|
||||
CHECK_THROWS_AS(j_nonobject_const.value("/foo"_json_pointer, 1), json::type_error&);
|
||||
CHECK_THROWS_WITH(j_nonobject.value("/foo"_json_pointer, 1),
|
||||
@@ -392,7 +392,7 @@ TEST_CASE("element access 2")
|
||||
SECTION("number (floating-point)")
|
||||
{
|
||||
json j_nonobject(json::value_t::number_float);
|
||||
const json j_nonobject_const(j_nonobject);
|
||||
const json j_nonobject_const(json::value_t::number_float);
|
||||
CHECK_THROWS_AS(j_nonobject.value("/foo"_json_pointer, 1), json::type_error&);
|
||||
CHECK_THROWS_AS(j_nonobject_const.value("/foo"_json_pointer, 1), json::type_error&);
|
||||
CHECK_THROWS_WITH(j_nonobject.value("/foo"_json_pointer, 1),
|
||||
@@ -811,7 +811,7 @@ TEST_CASE("element access 2")
|
||||
{
|
||||
SECTION("existing element")
|
||||
{
|
||||
for (auto key :
|
||||
for (const auto* key :
|
||||
{"integer", "unsigned", "floating", "null", "string", "boolean", "object", "array"
|
||||
})
|
||||
{
|
||||
@@ -900,7 +900,7 @@ TEST_CASE("element access 2")
|
||||
{
|
||||
SECTION("existing element")
|
||||
{
|
||||
for (auto key :
|
||||
for (const auto* key :
|
||||
{"integer", "unsigned", "floating", "null", "string", "boolean", "object", "array"
|
||||
})
|
||||
{
|
||||
@@ -920,7 +920,7 @@ TEST_CASE("element access 2")
|
||||
SECTION("null")
|
||||
{
|
||||
json j_nonobject(json::value_t::null);
|
||||
const json j_nonobject_const(j_nonobject);
|
||||
const json j_nonobject_const(json::value_t::null);
|
||||
CHECK(j_nonobject.count("foo") == 0);
|
||||
CHECK(j_nonobject_const.count("foo") == 0);
|
||||
}
|
||||
@@ -928,7 +928,7 @@ TEST_CASE("element access 2")
|
||||
SECTION("string")
|
||||
{
|
||||
json j_nonobject(json::value_t::string);
|
||||
const json j_nonobject_const(j_nonobject);
|
||||
const json j_nonobject_const(json::value_t::string);
|
||||
CHECK(j_nonobject.count("foo") == 0);
|
||||
CHECK(j_nonobject_const.count("foo") == 0);
|
||||
}
|
||||
@@ -936,7 +936,7 @@ TEST_CASE("element access 2")
|
||||
SECTION("object")
|
||||
{
|
||||
json j_nonobject(json::value_t::object);
|
||||
const json j_nonobject_const(j_nonobject);
|
||||
const json j_nonobject_const(json::value_t::object);
|
||||
CHECK(j_nonobject.count("foo") == 0);
|
||||
CHECK(j_nonobject_const.count("foo") == 0);
|
||||
}
|
||||
@@ -944,7 +944,7 @@ TEST_CASE("element access 2")
|
||||
SECTION("array")
|
||||
{
|
||||
json j_nonobject(json::value_t::array);
|
||||
const json j_nonobject_const(j_nonobject);
|
||||
const json j_nonobject_const(json::value_t::array);
|
||||
CHECK(j_nonobject.count("foo") == 0);
|
||||
CHECK(j_nonobject_const.count("foo") == 0);
|
||||
}
|
||||
@@ -952,7 +952,7 @@ TEST_CASE("element access 2")
|
||||
SECTION("boolean")
|
||||
{
|
||||
json j_nonobject(json::value_t::boolean);
|
||||
const json j_nonobject_const(j_nonobject);
|
||||
const json j_nonobject_const(json::value_t::boolean);
|
||||
CHECK(j_nonobject.count("foo") == 0);
|
||||
CHECK(j_nonobject_const.count("foo") == 0);
|
||||
}
|
||||
@@ -960,7 +960,7 @@ TEST_CASE("element access 2")
|
||||
SECTION("number (integer)")
|
||||
{
|
||||
json j_nonobject(json::value_t::number_integer);
|
||||
const json j_nonobject_const(j_nonobject);
|
||||
const json j_nonobject_const(json::value_t::number_integer);
|
||||
CHECK(j_nonobject.count("foo") == 0);
|
||||
CHECK(j_nonobject_const.count("foo") == 0);
|
||||
}
|
||||
@@ -968,7 +968,7 @@ TEST_CASE("element access 2")
|
||||
SECTION("number (unsigned)")
|
||||
{
|
||||
json j_nonobject(json::value_t::number_unsigned);
|
||||
const json j_nonobject_const(j_nonobject);
|
||||
const json j_nonobject_const(json::value_t::number_unsigned);
|
||||
CHECK(j_nonobject.count("foo") == 0);
|
||||
CHECK(j_nonobject_const.count("foo") == 0);
|
||||
}
|
||||
@@ -976,7 +976,7 @@ TEST_CASE("element access 2")
|
||||
SECTION("number (floating-point)")
|
||||
{
|
||||
json j_nonobject(json::value_t::number_float);
|
||||
const json j_nonobject_const(j_nonobject);
|
||||
const json j_nonobject_const(json::value_t::number_float);
|
||||
CHECK(j_nonobject.count("foo") == 0);
|
||||
CHECK(j_nonobject_const.count("foo") == 0);
|
||||
}
|
||||
@@ -987,7 +987,7 @@ TEST_CASE("element access 2")
|
||||
{
|
||||
SECTION("existing element")
|
||||
{
|
||||
for (auto key :
|
||||
for (const auto* key :
|
||||
{"integer", "unsigned", "floating", "null", "string", "boolean", "object", "array"
|
||||
})
|
||||
{
|
||||
@@ -1007,7 +1007,7 @@ TEST_CASE("element access 2")
|
||||
SECTION("null")
|
||||
{
|
||||
json j_nonobject(json::value_t::null);
|
||||
const json j_nonobject_const(j_nonobject);
|
||||
const json j_nonobject_const(json::value_t::null);
|
||||
CHECK(j_nonobject.contains("foo") == false);
|
||||
CHECK(j_nonobject_const.contains("foo") == false);
|
||||
}
|
||||
@@ -1015,7 +1015,7 @@ TEST_CASE("element access 2")
|
||||
SECTION("string")
|
||||
{
|
||||
json j_nonobject(json::value_t::string);
|
||||
const json j_nonobject_const(j_nonobject);
|
||||
const json j_nonobject_const(json::value_t::string);
|
||||
CHECK(j_nonobject.contains("foo") == false);
|
||||
CHECK(j_nonobject_const.contains("foo") == false);
|
||||
}
|
||||
@@ -1023,7 +1023,7 @@ TEST_CASE("element access 2")
|
||||
SECTION("object")
|
||||
{
|
||||
json j_nonobject(json::value_t::object);
|
||||
const json j_nonobject_const(j_nonobject);
|
||||
const json j_nonobject_const(json::value_t::object);
|
||||
CHECK(j_nonobject.contains("foo") == false);
|
||||
CHECK(j_nonobject_const.contains("foo") == false);
|
||||
}
|
||||
@@ -1031,7 +1031,7 @@ TEST_CASE("element access 2")
|
||||
SECTION("array")
|
||||
{
|
||||
json j_nonobject(json::value_t::array);
|
||||
const json j_nonobject_const(j_nonobject);
|
||||
const json j_nonobject_const(json::value_t::array);
|
||||
CHECK(j_nonobject.contains("foo") == false);
|
||||
CHECK(j_nonobject_const.contains("foo") == false);
|
||||
}
|
||||
@@ -1039,7 +1039,7 @@ TEST_CASE("element access 2")
|
||||
SECTION("boolean")
|
||||
{
|
||||
json j_nonobject(json::value_t::boolean);
|
||||
const json j_nonobject_const(j_nonobject);
|
||||
const json j_nonobject_const(json::value_t::boolean);
|
||||
CHECK(j_nonobject.contains("foo") == false);
|
||||
CHECK(j_nonobject_const.contains("foo") == false);
|
||||
}
|
||||
@@ -1047,7 +1047,7 @@ TEST_CASE("element access 2")
|
||||
SECTION("number (integer)")
|
||||
{
|
||||
json j_nonobject(json::value_t::number_integer);
|
||||
const json j_nonobject_const(j_nonobject);
|
||||
const json j_nonobject_const(json::value_t::number_integer);
|
||||
CHECK(j_nonobject.contains("foo") == false);
|
||||
CHECK(j_nonobject_const.contains("foo") == false);
|
||||
}
|
||||
@@ -1055,7 +1055,7 @@ TEST_CASE("element access 2")
|
||||
SECTION("number (unsigned)")
|
||||
{
|
||||
json j_nonobject(json::value_t::number_unsigned);
|
||||
const json j_nonobject_const(j_nonobject);
|
||||
const json j_nonobject_const(json::value_t::number_unsigned);
|
||||
CHECK(j_nonobject.contains("foo") == false);
|
||||
CHECK(j_nonobject_const.contains("foo") == false);
|
||||
}
|
||||
@@ -1063,7 +1063,7 @@ TEST_CASE("element access 2")
|
||||
SECTION("number (floating-point)")
|
||||
{
|
||||
json j_nonobject(json::value_t::number_float);
|
||||
const json j_nonobject_const(j_nonobject);
|
||||
const json j_nonobject_const(json::value_t::number_float);
|
||||
CHECK(j_nonobject.contains("foo") == false);
|
||||
CHECK(j_nonobject_const.contains("foo") == false);
|
||||
}
|
||||
@@ -1078,7 +1078,7 @@ TEST_CASE("element access 2 (throwing tests)")
|
||||
SECTION("object")
|
||||
{
|
||||
json j = {{"integer", 1}, {"unsigned", 1u}, {"floating", 42.23}, {"null", nullptr}, {"string", "hello world"}, {"boolean", true}, {"object", json::object()}, {"array", {1, 2, 3}}};
|
||||
const json j_const = j;
|
||||
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")
|
||||
{
|
||||
|
||||
@@ -48,7 +48,7 @@ TEST_CASE("iterator_wrapper")
|
||||
json j = { {"A", 1}, {"B", 2} };
|
||||
int counter = 1;
|
||||
|
||||
for (auto i : json::iterator_wrapper(j))
|
||||
for (auto i : json::iterator_wrapper(j)) // NOLINT(performance-for-range-copy)
|
||||
{
|
||||
switch (counter++)
|
||||
{
|
||||
@@ -125,7 +125,7 @@ TEST_CASE("iterator_wrapper")
|
||||
json j = { {"A", 1}, {"B", 2} };
|
||||
int counter = 1;
|
||||
|
||||
for (const auto i : json::iterator_wrapper(j))
|
||||
for (const auto i : json::iterator_wrapper(j)) // NOLINT(performance-for-range-copy)
|
||||
{
|
||||
switch (counter++)
|
||||
{
|
||||
@@ -194,7 +194,7 @@ TEST_CASE("iterator_wrapper")
|
||||
const json j = { {"A", 1}, {"B", 2} };
|
||||
int counter = 1;
|
||||
|
||||
for (auto i : json::iterator_wrapper(j))
|
||||
for (auto i : json::iterator_wrapper(j)) // NOLINT(performance-for-range-copy)
|
||||
{
|
||||
switch (counter++)
|
||||
{
|
||||
@@ -260,7 +260,7 @@ TEST_CASE("iterator_wrapper")
|
||||
const json j = { {"A", 1}, {"B", 2} };
|
||||
int counter = 1;
|
||||
|
||||
for (const auto i : json::iterator_wrapper(j))
|
||||
for (const auto i : json::iterator_wrapper(j)) // NOLINT(performance-for-range-copy)
|
||||
{
|
||||
switch (counter++)
|
||||
{
|
||||
@@ -329,7 +329,7 @@ TEST_CASE("iterator_wrapper")
|
||||
json j = { "A", "B" };
|
||||
int counter = 1;
|
||||
|
||||
for (auto i : json::iterator_wrapper(j))
|
||||
for (auto i : json::iterator_wrapper(j)) // NOLINT(performance-for-range-copy)
|
||||
{
|
||||
switch (counter++)
|
||||
{
|
||||
@@ -406,7 +406,7 @@ TEST_CASE("iterator_wrapper")
|
||||
json j = { "A", "B" };
|
||||
int counter = 1;
|
||||
|
||||
for (const auto i : json::iterator_wrapper(j))
|
||||
for (const auto i : json::iterator_wrapper(j)) // NOLINT(performance-for-range-copy)
|
||||
{
|
||||
switch (counter++)
|
||||
{
|
||||
@@ -475,7 +475,7 @@ TEST_CASE("iterator_wrapper")
|
||||
const json j = { "A", "B" };
|
||||
int counter = 1;
|
||||
|
||||
for (auto i : json::iterator_wrapper(j))
|
||||
for (auto i : json::iterator_wrapper(j)) // NOLINT(performance-for-range-copy)
|
||||
{
|
||||
switch (counter++)
|
||||
{
|
||||
@@ -541,7 +541,7 @@ TEST_CASE("iterator_wrapper")
|
||||
const json j = { "A", "B" };
|
||||
int counter = 1;
|
||||
|
||||
for (const auto i : json::iterator_wrapper(j))
|
||||
for (const auto i : json::iterator_wrapper(j)) // NOLINT(performance-for-range-copy)
|
||||
{
|
||||
switch (counter++)
|
||||
{
|
||||
@@ -610,7 +610,7 @@ TEST_CASE("iterator_wrapper")
|
||||
json j = 1;
|
||||
int counter = 1;
|
||||
|
||||
for (auto i : json::iterator_wrapper(j))
|
||||
for (auto i : json::iterator_wrapper(j)) // NOLINT(performance-for-range-copy)
|
||||
{
|
||||
++counter;
|
||||
CHECK(i.key() == "");
|
||||
@@ -646,7 +646,7 @@ TEST_CASE("iterator_wrapper")
|
||||
json j = 1;
|
||||
int counter = 1;
|
||||
|
||||
for (const auto i : json::iterator_wrapper(j))
|
||||
for (const auto i : json::iterator_wrapper(j)) // NOLINT(performance-for-range-copy)
|
||||
{
|
||||
++counter;
|
||||
CHECK(i.key() == "");
|
||||
@@ -679,7 +679,7 @@ TEST_CASE("iterator_wrapper")
|
||||
const json j = 1;
|
||||
int counter = 1;
|
||||
|
||||
for (auto i : json::iterator_wrapper(j))
|
||||
for (auto i : json::iterator_wrapper(j)) // NOLINT(performance-for-range-copy)
|
||||
{
|
||||
++counter;
|
||||
CHECK(i.key() == "");
|
||||
@@ -709,7 +709,7 @@ TEST_CASE("iterator_wrapper")
|
||||
const json j = 1;
|
||||
int counter = 1;
|
||||
|
||||
for (const auto i : json::iterator_wrapper(j))
|
||||
for (const auto i : json::iterator_wrapper(j)) // NOLINT(performance-for-range-copy)
|
||||
{
|
||||
++counter;
|
||||
CHECK(i.key() == "");
|
||||
@@ -745,7 +745,7 @@ TEST_CASE("items()")
|
||||
json j = { {"A", 1}, {"B", 2} };
|
||||
int counter = 1;
|
||||
|
||||
for (auto i : j.items())
|
||||
for (auto i : j.items()) // NOLINT(performance-for-range-copy)
|
||||
{
|
||||
switch (counter++)
|
||||
{
|
||||
@@ -822,7 +822,7 @@ TEST_CASE("items()")
|
||||
json j = { {"A", 1}, {"B", 2} };
|
||||
int counter = 1;
|
||||
|
||||
for (const auto i : j.items())
|
||||
for (const auto i : j.items()) // NOLINT(performance-for-range-copy)
|
||||
{
|
||||
switch (counter++)
|
||||
{
|
||||
@@ -907,7 +907,7 @@ TEST_CASE("items()")
|
||||
const json j = { {"A", 1}, {"B", 2} };
|
||||
int counter = 1;
|
||||
|
||||
for (auto i : j.items())
|
||||
for (auto i : j.items()) // NOLINT(performance-for-range-copy)
|
||||
{
|
||||
switch (counter++)
|
||||
{
|
||||
@@ -973,7 +973,7 @@ TEST_CASE("items()")
|
||||
const json j = { {"A", 1}, {"B", 2} };
|
||||
int counter = 1;
|
||||
|
||||
for (const auto i : j.items())
|
||||
for (const auto i : j.items()) // NOLINT(performance-for-range-copy)
|
||||
{
|
||||
switch (counter++)
|
||||
{
|
||||
@@ -1042,7 +1042,7 @@ TEST_CASE("items()")
|
||||
json j = { "A", "B" };
|
||||
int counter = 1;
|
||||
|
||||
for (auto i : j.items())
|
||||
for (auto i : j.items()) // NOLINT(performance-for-range-copy)
|
||||
{
|
||||
switch (counter++)
|
||||
{
|
||||
@@ -1119,7 +1119,7 @@ TEST_CASE("items()")
|
||||
json j = { "A", "B" };
|
||||
int counter = 1;
|
||||
|
||||
for (const auto i : j.items())
|
||||
for (const auto i : j.items()) // NOLINT(performance-for-range-copy)
|
||||
{
|
||||
switch (counter++)
|
||||
{
|
||||
@@ -1188,7 +1188,7 @@ TEST_CASE("items()")
|
||||
const json j = { "A", "B" };
|
||||
int counter = 1;
|
||||
|
||||
for (auto i : j.items())
|
||||
for (auto i : j.items()) // NOLINT(performance-for-range-copy)
|
||||
{
|
||||
switch (counter++)
|
||||
{
|
||||
@@ -1254,7 +1254,7 @@ TEST_CASE("items()")
|
||||
const json j = { "A", "B" };
|
||||
int counter = 1;
|
||||
|
||||
for (const auto i : j.items())
|
||||
for (const auto i : j.items()) // NOLINT(performance-for-range-copy)
|
||||
{
|
||||
switch (counter++)
|
||||
{
|
||||
@@ -1323,7 +1323,7 @@ TEST_CASE("items()")
|
||||
json j = 1;
|
||||
int counter = 1;
|
||||
|
||||
for (auto i : j.items())
|
||||
for (auto i : j.items()) // NOLINT(performance-for-range-copy)
|
||||
{
|
||||
++counter;
|
||||
CHECK(i.key() == "");
|
||||
@@ -1359,7 +1359,7 @@ TEST_CASE("items()")
|
||||
json j = 1;
|
||||
int counter = 1;
|
||||
|
||||
for (const auto i : j.items())
|
||||
for (const auto i : j.items()) // NOLINT(performance-for-range-copy)
|
||||
{
|
||||
++counter;
|
||||
CHECK(i.key() == "");
|
||||
@@ -1392,7 +1392,7 @@ TEST_CASE("items()")
|
||||
const json j = 1;
|
||||
int counter = 1;
|
||||
|
||||
for (auto i : j.items())
|
||||
for (auto i : j.items()) // NOLINT(performance-for-range-copy)
|
||||
{
|
||||
++counter;
|
||||
CHECK(i.key() == "");
|
||||
@@ -1422,7 +1422,7 @@ TEST_CASE("items()")
|
||||
const json j = 1;
|
||||
int counter = 1;
|
||||
|
||||
for (const auto i : j.items())
|
||||
for (const auto i : j.items()) // NOLINT(performance-for-range-copy)
|
||||
{
|
||||
++counter;
|
||||
CHECK(i.key() == "");
|
||||
|
||||
@@ -90,6 +90,16 @@ TEST_CASE("iterators 2")
|
||||
CHECK_THROWS_AS(it1_c < it2_c, json::invalid_iterator&);
|
||||
CHECK_THROWS_AS(it2_c < it3_c, json::invalid_iterator&);
|
||||
CHECK_THROWS_AS(it1_c < it3_c, json::invalid_iterator&);
|
||||
#if JSON_DIAGNOSTICS
|
||||
CHECK_THROWS_WITH(it1 < it1, "[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators");
|
||||
CHECK_THROWS_WITH(it1 < it2, "[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators");
|
||||
CHECK_THROWS_WITH(it2 < it3, "[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators");
|
||||
CHECK_THROWS_WITH(it1 < it3, "[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators");
|
||||
CHECK_THROWS_WITH(it1_c < it1_c, "[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators");
|
||||
CHECK_THROWS_WITH(it1_c < it2_c, "[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators");
|
||||
CHECK_THROWS_WITH(it2_c < it3_c, "[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators");
|
||||
CHECK_THROWS_WITH(it1_c < it3_c, "[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators");
|
||||
#else
|
||||
CHECK_THROWS_WITH(it1 < it1, "[json.exception.invalid_iterator.213] cannot compare order of object iterators");
|
||||
CHECK_THROWS_WITH(it1 < it2, "[json.exception.invalid_iterator.213] cannot compare order of object iterators");
|
||||
CHECK_THROWS_WITH(it2 < it3, "[json.exception.invalid_iterator.213] cannot compare order of object iterators");
|
||||
@@ -98,6 +108,7 @@ TEST_CASE("iterators 2")
|
||||
CHECK_THROWS_WITH(it1_c < it2_c, "[json.exception.invalid_iterator.213] cannot compare order of object iterators");
|
||||
CHECK_THROWS_WITH(it2_c < it3_c, "[json.exception.invalid_iterator.213] cannot compare order of object iterators");
|
||||
CHECK_THROWS_WITH(it1_c < it3_c, "[json.exception.invalid_iterator.213] cannot compare order of object iterators");
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -124,6 +135,16 @@ TEST_CASE("iterators 2")
|
||||
CHECK_THROWS_AS(it1_c <= it2_c, json::invalid_iterator&);
|
||||
CHECK_THROWS_AS(it2_c <= it3_c, json::invalid_iterator&);
|
||||
CHECK_THROWS_AS(it1_c <= it3_c, json::invalid_iterator&);
|
||||
#if JSON_DIAGNOSTICS
|
||||
CHECK_THROWS_WITH(it1 <= it1, "[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators");
|
||||
CHECK_THROWS_WITH(it1 <= it2, "[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators");
|
||||
CHECK_THROWS_WITH(it2 <= it3, "[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators");
|
||||
CHECK_THROWS_WITH(it1 <= it3, "[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators");
|
||||
CHECK_THROWS_WITH(it1_c <= it1_c, "[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators");
|
||||
CHECK_THROWS_WITH(it1_c <= it2_c, "[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators");
|
||||
CHECK_THROWS_WITH(it2_c <= it3_c, "[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators");
|
||||
CHECK_THROWS_WITH(it1_c <= it3_c, "[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators");
|
||||
#else
|
||||
CHECK_THROWS_WITH(it1 <= it1, "[json.exception.invalid_iterator.213] cannot compare order of object iterators");
|
||||
CHECK_THROWS_WITH(it1 <= it2, "[json.exception.invalid_iterator.213] cannot compare order of object iterators");
|
||||
CHECK_THROWS_WITH(it2 <= it3, "[json.exception.invalid_iterator.213] cannot compare order of object iterators");
|
||||
@@ -132,6 +153,7 @@ TEST_CASE("iterators 2")
|
||||
CHECK_THROWS_WITH(it1_c <= it2_c, "[json.exception.invalid_iterator.213] cannot compare order of object iterators");
|
||||
CHECK_THROWS_WITH(it2_c <= it3_c, "[json.exception.invalid_iterator.213] cannot compare order of object iterators");
|
||||
CHECK_THROWS_WITH(it1_c <= it3_c, "[json.exception.invalid_iterator.213] cannot compare order of object iterators");
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -159,6 +181,16 @@ TEST_CASE("iterators 2")
|
||||
CHECK_THROWS_AS(it1_c > it2_c, json::invalid_iterator&);
|
||||
CHECK_THROWS_AS(it2_c > it3_c, json::invalid_iterator&);
|
||||
CHECK_THROWS_AS(it1_c > it3_c, json::invalid_iterator&);
|
||||
#if JSON_DIAGNOSTICS
|
||||
CHECK_THROWS_WITH(it1 > it1, "[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators");
|
||||
CHECK_THROWS_WITH(it1 > it2, "[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators");
|
||||
CHECK_THROWS_WITH(it2 > it3, "[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators");
|
||||
CHECK_THROWS_WITH(it1 > it3, "[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators");
|
||||
CHECK_THROWS_WITH(it1_c > it1_c, "[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators");
|
||||
CHECK_THROWS_WITH(it1_c > it2_c, "[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators");
|
||||
CHECK_THROWS_WITH(it2_c > it3_c, "[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators");
|
||||
CHECK_THROWS_WITH(it1_c > it3_c, "[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators");
|
||||
#else
|
||||
CHECK_THROWS_WITH(it1 > it1, "[json.exception.invalid_iterator.213] cannot compare order of object iterators");
|
||||
CHECK_THROWS_WITH(it1 > it2, "[json.exception.invalid_iterator.213] cannot compare order of object iterators");
|
||||
CHECK_THROWS_WITH(it2 > it3, "[json.exception.invalid_iterator.213] cannot compare order of object iterators");
|
||||
@@ -167,6 +199,7 @@ TEST_CASE("iterators 2")
|
||||
CHECK_THROWS_WITH(it1_c > it2_c, "[json.exception.invalid_iterator.213] cannot compare order of object iterators");
|
||||
CHECK_THROWS_WITH(it2_c > it3_c, "[json.exception.invalid_iterator.213] cannot compare order of object iterators");
|
||||
CHECK_THROWS_WITH(it1_c > it3_c, "[json.exception.invalid_iterator.213] cannot compare order of object iterators");
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -194,6 +227,16 @@ TEST_CASE("iterators 2")
|
||||
CHECK_THROWS_AS(it1_c >= it2_c, json::invalid_iterator&);
|
||||
CHECK_THROWS_AS(it2_c >= it3_c, json::invalid_iterator&);
|
||||
CHECK_THROWS_AS(it1_c >= it3_c, json::invalid_iterator&);
|
||||
#if JSON_DIAGNOSTICS
|
||||
CHECK_THROWS_WITH(it1 >= it1, "[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators");
|
||||
CHECK_THROWS_WITH(it1 >= it2, "[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators");
|
||||
CHECK_THROWS_WITH(it2 >= it3, "[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators");
|
||||
CHECK_THROWS_WITH(it1 >= it3, "[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators");
|
||||
CHECK_THROWS_WITH(it1_c >= it1_c, "[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators");
|
||||
CHECK_THROWS_WITH(it1_c >= it2_c, "[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators");
|
||||
CHECK_THROWS_WITH(it2_c >= it3_c, "[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators");
|
||||
CHECK_THROWS_WITH(it1_c >= it3_c, "[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators");
|
||||
#else
|
||||
CHECK_THROWS_WITH(it1 >= it1, "[json.exception.invalid_iterator.213] cannot compare order of object iterators");
|
||||
CHECK_THROWS_WITH(it1 >= it2, "[json.exception.invalid_iterator.213] cannot compare order of object iterators");
|
||||
CHECK_THROWS_WITH(it2 >= it3, "[json.exception.invalid_iterator.213] cannot compare order of object iterators");
|
||||
@@ -202,6 +245,7 @@ TEST_CASE("iterators 2")
|
||||
CHECK_THROWS_WITH(it1_c >= it2_c, "[json.exception.invalid_iterator.213] cannot compare order of object iterators");
|
||||
CHECK_THROWS_WITH(it2_c >= it3_c, "[json.exception.invalid_iterator.213] cannot compare order of object iterators");
|
||||
CHECK_THROWS_WITH(it1_c >= it3_c, "[json.exception.invalid_iterator.213] cannot compare order of object iterators");
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -227,13 +271,16 @@ TEST_CASE("iterators 2")
|
||||
{
|
||||
CHECK_THROWS_AS(j.begin() == k.begin(), json::invalid_iterator&);
|
||||
CHECK_THROWS_AS(j.cbegin() == k.cbegin(), json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH(j.begin() == k.begin(), "[json.exception.invalid_iterator.212] cannot compare iterators of different containers");
|
||||
CHECK_THROWS_WITH(j.cbegin() == k.cbegin(), "[json.exception.invalid_iterator.212] cannot compare iterators of different containers");
|
||||
|
||||
CHECK_THROWS_AS(j.begin() < k.begin(), json::invalid_iterator&);
|
||||
CHECK_THROWS_AS(j.cbegin() < k.cbegin(), json::invalid_iterator&);
|
||||
#if JSON_DIAGNOSTICS
|
||||
// the output differs in each loop, so we cannot fix a string for the expected exception
|
||||
#else
|
||||
CHECK_THROWS_WITH(j.begin() == k.begin(), "[json.exception.invalid_iterator.212] cannot compare iterators of different containers");
|
||||
CHECK_THROWS_WITH(j.cbegin() == k.cbegin(), "[json.exception.invalid_iterator.212] cannot compare iterators of different containers");
|
||||
CHECK_THROWS_WITH(j.begin() < k.begin(), "[json.exception.invalid_iterator.212] cannot compare iterators of different containers");
|
||||
CHECK_THROWS_WITH(j.cbegin() < k.cbegin(), "[json.exception.invalid_iterator.212] cannot compare iterators of different containers");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -525,6 +572,16 @@ TEST_CASE("iterators 2")
|
||||
CHECK_THROWS_AS(it1_c < it2_c, json::invalid_iterator&);
|
||||
CHECK_THROWS_AS(it2_c < it3_c, json::invalid_iterator&);
|
||||
CHECK_THROWS_AS(it1_c < it3_c, json::invalid_iterator&);
|
||||
#if JSON_DIAGNOSTICS
|
||||
CHECK_THROWS_WITH(it1 < it1, "[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators");
|
||||
CHECK_THROWS_WITH(it1 < it2, "[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators");
|
||||
CHECK_THROWS_WITH(it2 < it3, "[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators");
|
||||
CHECK_THROWS_WITH(it1 < it3, "[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators");
|
||||
CHECK_THROWS_WITH(it1_c < it1_c, "[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators");
|
||||
CHECK_THROWS_WITH(it1_c < it2_c, "[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators");
|
||||
CHECK_THROWS_WITH(it2_c < it3_c, "[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators");
|
||||
CHECK_THROWS_WITH(it1_c < it3_c, "[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators");
|
||||
#else
|
||||
CHECK_THROWS_WITH(it1 < it1, "[json.exception.invalid_iterator.213] cannot compare order of object iterators");
|
||||
CHECK_THROWS_WITH(it1 < it2, "[json.exception.invalid_iterator.213] cannot compare order of object iterators");
|
||||
CHECK_THROWS_WITH(it2 < it3, "[json.exception.invalid_iterator.213] cannot compare order of object iterators");
|
||||
@@ -533,6 +590,7 @@ TEST_CASE("iterators 2")
|
||||
CHECK_THROWS_WITH(it1_c < it2_c, "[json.exception.invalid_iterator.213] cannot compare order of object iterators");
|
||||
CHECK_THROWS_WITH(it2_c < it3_c, "[json.exception.invalid_iterator.213] cannot compare order of object iterators");
|
||||
CHECK_THROWS_WITH(it1_c < it3_c, "[json.exception.invalid_iterator.213] cannot compare order of object iterators");
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -559,6 +617,16 @@ TEST_CASE("iterators 2")
|
||||
CHECK_THROWS_AS(it1_c <= it2_c, json::invalid_iterator&);
|
||||
CHECK_THROWS_AS(it2_c <= it3_c, json::invalid_iterator&);
|
||||
CHECK_THROWS_AS(it1_c <= it3_c, json::invalid_iterator&);
|
||||
#if JSON_DIAGNOSTICS
|
||||
CHECK_THROWS_WITH(it1 <= it1, "[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators");
|
||||
CHECK_THROWS_WITH(it1 <= it2, "[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators");
|
||||
CHECK_THROWS_WITH(it2 <= it3, "[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators");
|
||||
CHECK_THROWS_WITH(it1 <= it3, "[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators");
|
||||
CHECK_THROWS_WITH(it1_c <= it1_c, "[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators");
|
||||
CHECK_THROWS_WITH(it1_c <= it2_c, "[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators");
|
||||
CHECK_THROWS_WITH(it2_c <= it3_c, "[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators");
|
||||
CHECK_THROWS_WITH(it1_c <= it3_c, "[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators");
|
||||
#else
|
||||
CHECK_THROWS_WITH(it1 <= it1, "[json.exception.invalid_iterator.213] cannot compare order of object iterators");
|
||||
CHECK_THROWS_WITH(it1 <= it2, "[json.exception.invalid_iterator.213] cannot compare order of object iterators");
|
||||
CHECK_THROWS_WITH(it2 <= it3, "[json.exception.invalid_iterator.213] cannot compare order of object iterators");
|
||||
@@ -567,6 +635,7 @@ TEST_CASE("iterators 2")
|
||||
CHECK_THROWS_WITH(it1_c <= it2_c, "[json.exception.invalid_iterator.213] cannot compare order of object iterators");
|
||||
CHECK_THROWS_WITH(it2_c <= it3_c, "[json.exception.invalid_iterator.213] cannot compare order of object iterators");
|
||||
CHECK_THROWS_WITH(it1_c <= it3_c, "[json.exception.invalid_iterator.213] cannot compare order of object iterators");
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -594,6 +663,16 @@ TEST_CASE("iterators 2")
|
||||
CHECK_THROWS_AS(it1_c > it2_c, json::invalid_iterator&);
|
||||
CHECK_THROWS_AS(it2_c > it3_c, json::invalid_iterator&);
|
||||
CHECK_THROWS_AS(it1_c > it3_c, json::invalid_iterator&);
|
||||
#if JSON_DIAGNOSTICS
|
||||
CHECK_THROWS_WITH(it1 > it1, "[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators");
|
||||
CHECK_THROWS_WITH(it1 > it2, "[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators");
|
||||
CHECK_THROWS_WITH(it2 > it3, "[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators");
|
||||
CHECK_THROWS_WITH(it1 > it3, "[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators");
|
||||
CHECK_THROWS_WITH(it1_c > it1_c, "[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators");
|
||||
CHECK_THROWS_WITH(it1_c > it2_c, "[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators");
|
||||
CHECK_THROWS_WITH(it2_c > it3_c, "[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators");
|
||||
CHECK_THROWS_WITH(it1_c > it3_c, "[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators");
|
||||
#else
|
||||
CHECK_THROWS_WITH(it1 > it1, "[json.exception.invalid_iterator.213] cannot compare order of object iterators");
|
||||
CHECK_THROWS_WITH(it1 > it2, "[json.exception.invalid_iterator.213] cannot compare order of object iterators");
|
||||
CHECK_THROWS_WITH(it2 > it3, "[json.exception.invalid_iterator.213] cannot compare order of object iterators");
|
||||
@@ -602,6 +681,7 @@ TEST_CASE("iterators 2")
|
||||
CHECK_THROWS_WITH(it1_c > it2_c, "[json.exception.invalid_iterator.213] cannot compare order of object iterators");
|
||||
CHECK_THROWS_WITH(it2_c > it3_c, "[json.exception.invalid_iterator.213] cannot compare order of object iterators");
|
||||
CHECK_THROWS_WITH(it1_c > it3_c, "[json.exception.invalid_iterator.213] cannot compare order of object iterators");
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -629,6 +709,16 @@ TEST_CASE("iterators 2")
|
||||
CHECK_THROWS_AS(it1_c >= it2_c, json::invalid_iterator&);
|
||||
CHECK_THROWS_AS(it2_c >= it3_c, json::invalid_iterator&);
|
||||
CHECK_THROWS_AS(it1_c >= it3_c, json::invalid_iterator&);
|
||||
#if JSON_DIAGNOSTICS
|
||||
CHECK_THROWS_WITH(it1 >= it1, "[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators");
|
||||
CHECK_THROWS_WITH(it1 >= it2, "[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators");
|
||||
CHECK_THROWS_WITH(it2 >= it3, "[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators");
|
||||
CHECK_THROWS_WITH(it1 >= it3, "[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators");
|
||||
CHECK_THROWS_WITH(it1_c >= it1_c, "[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators");
|
||||
CHECK_THROWS_WITH(it1_c >= it2_c, "[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators");
|
||||
CHECK_THROWS_WITH(it2_c >= it3_c, "[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators");
|
||||
CHECK_THROWS_WITH(it1_c >= it3_c, "[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators");
|
||||
#else
|
||||
CHECK_THROWS_WITH(it1 >= it1, "[json.exception.invalid_iterator.213] cannot compare order of object iterators");
|
||||
CHECK_THROWS_WITH(it1 >= it2, "[json.exception.invalid_iterator.213] cannot compare order of object iterators");
|
||||
CHECK_THROWS_WITH(it2 >= it3, "[json.exception.invalid_iterator.213] cannot compare order of object iterators");
|
||||
@@ -637,6 +727,7 @@ TEST_CASE("iterators 2")
|
||||
CHECK_THROWS_WITH(it1_c >= it2_c, "[json.exception.invalid_iterator.213] cannot compare order of object iterators");
|
||||
CHECK_THROWS_WITH(it2_c >= it3_c, "[json.exception.invalid_iterator.213] cannot compare order of object iterators");
|
||||
CHECK_THROWS_WITH(it1_c >= it3_c, "[json.exception.invalid_iterator.213] cannot compare order of object iterators");
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -662,13 +753,16 @@ TEST_CASE("iterators 2")
|
||||
{
|
||||
CHECK_THROWS_AS(j.rbegin() == k.rbegin(), json::invalid_iterator&);
|
||||
CHECK_THROWS_AS(j.crbegin() == k.crbegin(), json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH(j.rbegin() == k.rbegin(), "[json.exception.invalid_iterator.212] cannot compare iterators of different containers");
|
||||
CHECK_THROWS_WITH(j.crbegin() == k.crbegin(), "[json.exception.invalid_iterator.212] cannot compare iterators of different containers");
|
||||
|
||||
CHECK_THROWS_AS(j.rbegin() < k.rbegin(), json::invalid_iterator&);
|
||||
CHECK_THROWS_AS(j.crbegin() < k.crbegin(), json::invalid_iterator&);
|
||||
#if JSON_DIAGNOSTICS
|
||||
// the output differs in each loop, so we cannot fix a string for the expected exception
|
||||
#else
|
||||
CHECK_THROWS_WITH(j.rbegin() == k.rbegin(), "[json.exception.invalid_iterator.212] cannot compare iterators of different containers");
|
||||
CHECK_THROWS_WITH(j.crbegin() == k.crbegin(), "[json.exception.invalid_iterator.212] cannot compare iterators of different containers");
|
||||
CHECK_THROWS_WITH(j.rbegin() < k.rbegin(), "[json.exception.invalid_iterator.212] cannot compare iterators of different containers");
|
||||
CHECK_THROWS_WITH(j.crbegin() < k.crbegin(), "[json.exception.invalid_iterator.212] cannot compare iterators of different containers");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -343,7 +343,11 @@ TEST_CASE("JSON patch")
|
||||
|
||||
// check that evaluation throws
|
||||
CHECK_THROWS_AS(doc.patch(patch), json::other_error&);
|
||||
#if JSON_DIAGNOSTICS
|
||||
CHECK_THROWS_WITH_STD_STR(doc.patch(patch), "[json.exception.other_error.501] (/0) unsuccessful: " + patch[0].dump());
|
||||
#else
|
||||
CHECK_THROWS_WITH_STD_STR(doc.patch(patch), "[json.exception.other_error.501] unsuccessful: " + patch[0].dump());
|
||||
#endif
|
||||
}
|
||||
|
||||
SECTION("A.10. Adding a Nested Member Object")
|
||||
@@ -484,7 +488,11 @@ TEST_CASE("JSON patch")
|
||||
|
||||
// check that evaluation throws
|
||||
CHECK_THROWS_AS(doc.patch(patch), json::other_error&);
|
||||
#if JSON_DIAGNOSTICS
|
||||
CHECK_THROWS_WITH_STD_STR(doc.patch(patch), "[json.exception.other_error.501] (/0) unsuccessful: " + patch[0].dump());
|
||||
#else
|
||||
CHECK_THROWS_WITH_STD_STR(doc.patch(patch), "[json.exception.other_error.501] unsuccessful: " + patch[0].dump());
|
||||
#endif
|
||||
}
|
||||
|
||||
SECTION("A.16. Adding an Array Value")
|
||||
@@ -683,8 +691,11 @@ TEST_CASE("JSON patch")
|
||||
json j;
|
||||
json patch = {"op", "add", "path", "", "value", 1};
|
||||
CHECK_THROWS_AS(j.patch(patch), json::parse_error&);
|
||||
CHECK_THROWS_WITH(j.patch(patch),
|
||||
"[json.exception.parse_error.104] parse error: JSON patch must be an array of objects");
|
||||
#if JSON_DIAGNOSTICS
|
||||
CHECK_THROWS_WITH(j.patch(patch), "[json.exception.parse_error.104] parse error: (/0) JSON patch must be an array of objects");
|
||||
#else
|
||||
CHECK_THROWS_WITH(j.patch(patch), "[json.exception.parse_error.104] parse error: JSON patch must be an array of objects");
|
||||
#endif
|
||||
}
|
||||
|
||||
SECTION("missing 'op'")
|
||||
@@ -692,8 +703,11 @@ TEST_CASE("JSON patch")
|
||||
json j;
|
||||
json patch = {{{"foo", "bar"}}};
|
||||
CHECK_THROWS_AS(j.patch(patch), json::parse_error&);
|
||||
CHECK_THROWS_WITH(j.patch(patch),
|
||||
"[json.exception.parse_error.105] parse error: operation must have member 'op'");
|
||||
#if JSON_DIAGNOSTICS
|
||||
CHECK_THROWS_WITH(j.patch(patch), "[json.exception.parse_error.105] parse error: (/0) operation must have member 'op'");
|
||||
#else
|
||||
CHECK_THROWS_WITH(j.patch(patch), "[json.exception.parse_error.105] parse error: operation must have member 'op'");
|
||||
#endif
|
||||
}
|
||||
|
||||
SECTION("non-string 'op'")
|
||||
@@ -701,8 +715,11 @@ TEST_CASE("JSON patch")
|
||||
json j;
|
||||
json patch = {{{"op", 1}}};
|
||||
CHECK_THROWS_AS(j.patch(patch), json::parse_error&);
|
||||
CHECK_THROWS_WITH(j.patch(patch),
|
||||
"[json.exception.parse_error.105] parse error: operation must have string member 'op'");
|
||||
#if JSON_DIAGNOSTICS
|
||||
CHECK_THROWS_WITH(j.patch(patch), "[json.exception.parse_error.105] parse error: (/0) operation must have string member 'op'");
|
||||
#else
|
||||
CHECK_THROWS_WITH(j.patch(patch), "[json.exception.parse_error.105] parse error: operation must have string member 'op'");
|
||||
#endif
|
||||
}
|
||||
|
||||
SECTION("invalid operation")
|
||||
@@ -710,8 +727,11 @@ TEST_CASE("JSON patch")
|
||||
json j;
|
||||
json patch = {{{"op", "foo"}, {"path", ""}}};
|
||||
CHECK_THROWS_AS(j.patch(patch), json::parse_error&);
|
||||
CHECK_THROWS_WITH(j.patch(patch),
|
||||
"[json.exception.parse_error.105] parse error: operation value 'foo' is invalid");
|
||||
#if JSON_DIAGNOSTICS
|
||||
CHECK_THROWS_WITH(j.patch(patch), "[json.exception.parse_error.105] parse error: (/0) operation value 'foo' is invalid");
|
||||
#else
|
||||
CHECK_THROWS_WITH(j.patch(patch), "[json.exception.parse_error.105] parse error: operation value 'foo' is invalid");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@@ -722,8 +742,11 @@ TEST_CASE("JSON patch")
|
||||
json j;
|
||||
json patch = {{{"op", "add"}}};
|
||||
CHECK_THROWS_AS(j.patch(patch), json::parse_error&);
|
||||
CHECK_THROWS_WITH(j.patch(patch),
|
||||
"[json.exception.parse_error.105] parse error: operation 'add' must have member 'path'");
|
||||
#if JSON_DIAGNOSTICS
|
||||
CHECK_THROWS_WITH(j.patch(patch), "[json.exception.parse_error.105] parse error: (/0) operation 'add' must have member 'path'");
|
||||
#else
|
||||
CHECK_THROWS_WITH(j.patch(patch), "[json.exception.parse_error.105] parse error: operation 'add' must have member 'path'");
|
||||
#endif
|
||||
}
|
||||
|
||||
SECTION("non-string 'path'")
|
||||
@@ -731,8 +754,11 @@ TEST_CASE("JSON patch")
|
||||
json j;
|
||||
json patch = {{{"op", "add"}, {"path", 1}}};
|
||||
CHECK_THROWS_AS(j.patch(patch), json::parse_error&);
|
||||
CHECK_THROWS_WITH(j.patch(patch),
|
||||
"[json.exception.parse_error.105] parse error: operation 'add' must have string member 'path'");
|
||||
#if JSON_DIAGNOSTICS
|
||||
CHECK_THROWS_WITH(j.patch(patch), "[json.exception.parse_error.105] parse error: (/0) operation 'add' must have string member 'path'");
|
||||
#else
|
||||
CHECK_THROWS_WITH(j.patch(patch), "[json.exception.parse_error.105] parse error: operation 'add' must have string member 'path'");
|
||||
#endif
|
||||
}
|
||||
|
||||
SECTION("missing 'value'")
|
||||
@@ -740,8 +766,11 @@ TEST_CASE("JSON patch")
|
||||
json j;
|
||||
json patch = {{{"op", "add"}, {"path", ""}}};
|
||||
CHECK_THROWS_AS(j.patch(patch), json::parse_error&);
|
||||
CHECK_THROWS_WITH(j.patch(patch),
|
||||
"[json.exception.parse_error.105] parse error: operation 'add' must have member 'value'");
|
||||
#if JSON_DIAGNOSTICS
|
||||
CHECK_THROWS_WITH(j.patch(patch), "[json.exception.parse_error.105] parse error: (/0) operation 'add' must have member 'value'");
|
||||
#else
|
||||
CHECK_THROWS_WITH(j.patch(patch), "[json.exception.parse_error.105] parse error: operation 'add' must have member 'value'");
|
||||
#endif
|
||||
}
|
||||
|
||||
SECTION("invalid array index")
|
||||
@@ -761,8 +790,11 @@ TEST_CASE("JSON patch")
|
||||
json j;
|
||||
json patch = {{{"op", "remove"}}};
|
||||
CHECK_THROWS_AS(j.patch(patch), json::parse_error&);
|
||||
CHECK_THROWS_WITH(j.patch(patch),
|
||||
"[json.exception.parse_error.105] parse error: operation 'remove' must have member 'path'");
|
||||
#if JSON_DIAGNOSTICS
|
||||
CHECK_THROWS_WITH(j.patch(patch), "[json.exception.parse_error.105] parse error: (/0) operation 'remove' must have member 'path'");
|
||||
#else
|
||||
CHECK_THROWS_WITH(j.patch(patch), "[json.exception.parse_error.105] parse error: operation 'remove' must have member 'path'");
|
||||
#endif
|
||||
}
|
||||
|
||||
SECTION("non-string 'path'")
|
||||
@@ -770,8 +802,11 @@ TEST_CASE("JSON patch")
|
||||
json j;
|
||||
json patch = {{{"op", "remove"}, {"path", 1}}};
|
||||
CHECK_THROWS_AS(j.patch(patch), json::parse_error&);
|
||||
CHECK_THROWS_WITH(j.patch(patch),
|
||||
"[json.exception.parse_error.105] parse error: operation 'remove' must have string member 'path'");
|
||||
#if JSON_DIAGNOSTICS
|
||||
CHECK_THROWS_WITH(j.patch(patch), "[json.exception.parse_error.105] parse error: (/0) operation 'remove' must have string member 'path'");
|
||||
#else
|
||||
CHECK_THROWS_WITH(j.patch(patch), "[json.exception.parse_error.105] parse error: operation 'remove' must have string member 'path'");
|
||||
#endif
|
||||
}
|
||||
|
||||
SECTION("nonexisting target location (array)")
|
||||
@@ -809,8 +844,11 @@ TEST_CASE("JSON patch")
|
||||
json j;
|
||||
json patch = {{{"op", "replace"}}};
|
||||
CHECK_THROWS_AS(j.patch(patch), json::parse_error&);
|
||||
CHECK_THROWS_WITH(j.patch(patch),
|
||||
"[json.exception.parse_error.105] parse error: operation 'replace' must have member 'path'");
|
||||
#if JSON_DIAGNOSTICS
|
||||
CHECK_THROWS_WITH(j.patch(patch), "[json.exception.parse_error.105] parse error: (/0) operation 'replace' must have member 'path'");
|
||||
#else
|
||||
CHECK_THROWS_WITH(j.patch(patch), "[json.exception.parse_error.105] parse error: operation 'replace' must have member 'path'");
|
||||
#endif
|
||||
}
|
||||
|
||||
SECTION("non-string 'path'")
|
||||
@@ -818,8 +856,11 @@ TEST_CASE("JSON patch")
|
||||
json j;
|
||||
json patch = {{{"op", "replace"}, {"path", 1}}};
|
||||
CHECK_THROWS_AS(j.patch(patch), json::parse_error&);
|
||||
CHECK_THROWS_WITH(j.patch(patch),
|
||||
"[json.exception.parse_error.105] parse error: operation 'replace' must have string member 'path'");
|
||||
#if JSON_DIAGNOSTICS
|
||||
CHECK_THROWS_WITH(j.patch(patch), "[json.exception.parse_error.105] parse error: (/0) operation 'replace' must have string member 'path'");
|
||||
#else
|
||||
CHECK_THROWS_WITH(j.patch(patch), "[json.exception.parse_error.105] parse error: operation 'replace' must have string member 'path'");
|
||||
#endif
|
||||
}
|
||||
|
||||
SECTION("missing 'value'")
|
||||
@@ -827,8 +868,11 @@ TEST_CASE("JSON patch")
|
||||
json j;
|
||||
json patch = {{{"op", "replace"}, {"path", ""}}};
|
||||
CHECK_THROWS_AS(j.patch(patch), json::parse_error&);
|
||||
CHECK_THROWS_WITH(j.patch(patch),
|
||||
"[json.exception.parse_error.105] parse error: operation 'replace' must have member 'value'");
|
||||
#if JSON_DIAGNOSTICS
|
||||
CHECK_THROWS_WITH(j.patch(patch), "[json.exception.parse_error.105] parse error: (/0) operation 'replace' must have member 'value'");
|
||||
#else
|
||||
CHECK_THROWS_WITH(j.patch(patch), "[json.exception.parse_error.105] parse error: operation 'replace' must have member 'value'");
|
||||
#endif
|
||||
}
|
||||
|
||||
SECTION("nonexisting target location (array)")
|
||||
@@ -857,8 +901,11 @@ TEST_CASE("JSON patch")
|
||||
json j;
|
||||
json patch = {{{"op", "move"}}};
|
||||
CHECK_THROWS_AS(j.patch(patch), json::parse_error&);
|
||||
CHECK_THROWS_WITH(j.patch(patch),
|
||||
"[json.exception.parse_error.105] parse error: operation 'move' must have member 'path'");
|
||||
#if JSON_DIAGNOSTICS
|
||||
CHECK_THROWS_WITH(j.patch(patch), "[json.exception.parse_error.105] parse error: (/0) operation 'move' must have member 'path'");
|
||||
#else
|
||||
CHECK_THROWS_WITH(j.patch(patch), "[json.exception.parse_error.105] parse error: operation 'move' must have member 'path'");
|
||||
#endif
|
||||
}
|
||||
|
||||
SECTION("non-string 'path'")
|
||||
@@ -866,8 +913,11 @@ TEST_CASE("JSON patch")
|
||||
json j;
|
||||
json patch = {{{"op", "move"}, {"path", 1}}};
|
||||
CHECK_THROWS_AS(j.patch(patch), json::parse_error&);
|
||||
CHECK_THROWS_WITH(j.patch(patch),
|
||||
"[json.exception.parse_error.105] parse error: operation 'move' must have string member 'path'");
|
||||
#if JSON_DIAGNOSTICS
|
||||
CHECK_THROWS_WITH(j.patch(patch), "[json.exception.parse_error.105] parse error: (/0) operation 'move' must have string member 'path'");
|
||||
#else
|
||||
CHECK_THROWS_WITH(j.patch(patch), "[json.exception.parse_error.105] parse error: operation 'move' must have string member 'path'");
|
||||
#endif
|
||||
}
|
||||
|
||||
SECTION("missing 'from'")
|
||||
@@ -875,8 +925,11 @@ TEST_CASE("JSON patch")
|
||||
json j;
|
||||
json patch = {{{"op", "move"}, {"path", ""}}};
|
||||
CHECK_THROWS_AS(j.patch(patch), json::parse_error&);
|
||||
CHECK_THROWS_WITH(j.patch(patch),
|
||||
"[json.exception.parse_error.105] parse error: operation 'move' must have member 'from'");
|
||||
#if JSON_DIAGNOSTICS
|
||||
CHECK_THROWS_WITH(j.patch(patch), "[json.exception.parse_error.105] parse error: (/0) operation 'move' must have member 'from'");
|
||||
#else
|
||||
CHECK_THROWS_WITH(j.patch(patch), "[json.exception.parse_error.105] parse error: operation 'move' must have member 'from'");
|
||||
#endif
|
||||
}
|
||||
|
||||
SECTION("non-string 'from'")
|
||||
@@ -884,8 +937,11 @@ TEST_CASE("JSON patch")
|
||||
json j;
|
||||
json patch = {{{"op", "move"}, {"path", ""}, {"from", 1}}};
|
||||
CHECK_THROWS_AS(j.patch(patch), json::parse_error&);
|
||||
CHECK_THROWS_WITH(j.patch(patch),
|
||||
"[json.exception.parse_error.105] parse error: operation 'move' must have string member 'from'");
|
||||
#if JSON_DIAGNOSTICS
|
||||
CHECK_THROWS_WITH(j.patch(patch), "[json.exception.parse_error.105] parse error: (/0) operation 'move' must have string member 'from'");
|
||||
#else
|
||||
CHECK_THROWS_WITH(j.patch(patch), "[json.exception.parse_error.105] parse error: operation 'move' must have string member 'from'");
|
||||
#endif
|
||||
}
|
||||
|
||||
SECTION("nonexisting from location (array)")
|
||||
@@ -914,8 +970,11 @@ TEST_CASE("JSON patch")
|
||||
json j;
|
||||
json patch = {{{"op", "copy"}}};
|
||||
CHECK_THROWS_AS(j.patch(patch), json::parse_error&);
|
||||
CHECK_THROWS_WITH(j.patch(patch),
|
||||
"[json.exception.parse_error.105] parse error: operation 'copy' must have member 'path'");
|
||||
#if JSON_DIAGNOSTICS
|
||||
CHECK_THROWS_WITH(j.patch(patch), "[json.exception.parse_error.105] parse error: (/0) operation 'copy' must have member 'path'");
|
||||
#else
|
||||
CHECK_THROWS_WITH(j.patch(patch), "[json.exception.parse_error.105] parse error: operation 'copy' must have member 'path'");
|
||||
#endif
|
||||
}
|
||||
|
||||
SECTION("non-string 'path'")
|
||||
@@ -923,8 +982,11 @@ TEST_CASE("JSON patch")
|
||||
json j;
|
||||
json patch = {{{"op", "copy"}, {"path", 1}}};
|
||||
CHECK_THROWS_AS(j.patch(patch), json::parse_error&);
|
||||
CHECK_THROWS_WITH(j.patch(patch),
|
||||
"[json.exception.parse_error.105] parse error: operation 'copy' must have string member 'path'");
|
||||
#if JSON_DIAGNOSTICS
|
||||
CHECK_THROWS_WITH(j.patch(patch), "[json.exception.parse_error.105] parse error: (/0) operation 'copy' must have string member 'path'");
|
||||
#else
|
||||
CHECK_THROWS_WITH(j.patch(patch), "[json.exception.parse_error.105] parse error: operation 'copy' must have string member 'path'");
|
||||
#endif
|
||||
}
|
||||
|
||||
SECTION("missing 'from'")
|
||||
@@ -932,8 +994,11 @@ TEST_CASE("JSON patch")
|
||||
json j;
|
||||
json patch = {{{"op", "copy"}, {"path", ""}}};
|
||||
CHECK_THROWS_AS(j.patch(patch), json::parse_error&);
|
||||
CHECK_THROWS_WITH(j.patch(patch),
|
||||
"[json.exception.parse_error.105] parse error: operation 'copy' must have member 'from'");
|
||||
#if JSON_DIAGNOSTICS
|
||||
CHECK_THROWS_WITH(j.patch(patch), "[json.exception.parse_error.105] parse error: (/0) operation 'copy' must have member 'from'");
|
||||
#else
|
||||
CHECK_THROWS_WITH(j.patch(patch), "[json.exception.parse_error.105] parse error: operation 'copy' must have member 'from'");
|
||||
#endif
|
||||
}
|
||||
|
||||
SECTION("non-string 'from'")
|
||||
@@ -941,8 +1006,11 @@ TEST_CASE("JSON patch")
|
||||
json j;
|
||||
json patch = {{{"op", "copy"}, {"path", ""}, {"from", 1}}};
|
||||
CHECK_THROWS_AS(j.patch(patch), json::parse_error&);
|
||||
CHECK_THROWS_WITH(j.patch(patch),
|
||||
"[json.exception.parse_error.105] parse error: operation 'copy' must have string member 'from'");
|
||||
#if JSON_DIAGNOSTICS
|
||||
CHECK_THROWS_WITH(j.patch(patch), "[json.exception.parse_error.105] parse error: (/0) operation 'copy' must have string member 'from'");
|
||||
#else
|
||||
CHECK_THROWS_WITH(j.patch(patch), "[json.exception.parse_error.105] parse error: operation 'copy' must have string member 'from'");
|
||||
#endif
|
||||
}
|
||||
|
||||
SECTION("nonexisting from location (array)")
|
||||
@@ -971,8 +1039,11 @@ TEST_CASE("JSON patch")
|
||||
json j;
|
||||
json patch = {{{"op", "test"}}};
|
||||
CHECK_THROWS_AS(j.patch(patch), json::parse_error&);
|
||||
CHECK_THROWS_WITH(j.patch(patch),
|
||||
"[json.exception.parse_error.105] parse error: operation 'test' must have member 'path'");
|
||||
#if JSON_DIAGNOSTICS
|
||||
CHECK_THROWS_WITH(j.patch(patch), "[json.exception.parse_error.105] parse error: (/0) operation 'test' must have member 'path'");
|
||||
#else
|
||||
CHECK_THROWS_WITH(j.patch(patch), "[json.exception.parse_error.105] parse error: operation 'test' must have member 'path'");
|
||||
#endif
|
||||
}
|
||||
|
||||
SECTION("non-string 'path'")
|
||||
@@ -980,8 +1051,11 @@ TEST_CASE("JSON patch")
|
||||
json j;
|
||||
json patch = {{{"op", "test"}, {"path", 1}}};
|
||||
CHECK_THROWS_AS(j.patch(patch), json::parse_error&);
|
||||
CHECK_THROWS_WITH(j.patch(patch),
|
||||
"[json.exception.parse_error.105] parse error: operation 'test' must have string member 'path'");
|
||||
#if JSON_DIAGNOSTICS
|
||||
CHECK_THROWS_WITH(j.patch(patch), "[json.exception.parse_error.105] parse error: (/0) operation 'test' must have string member 'path'");
|
||||
#else
|
||||
CHECK_THROWS_WITH(j.patch(patch), "[json.exception.parse_error.105] parse error: operation 'test' must have string member 'path'");
|
||||
#endif
|
||||
}
|
||||
|
||||
SECTION("missing 'value'")
|
||||
@@ -989,8 +1063,11 @@ TEST_CASE("JSON patch")
|
||||
json j;
|
||||
json patch = {{{"op", "test"}, {"path", ""}}};
|
||||
CHECK_THROWS_AS(j.patch(patch), json::parse_error&);
|
||||
CHECK_THROWS_WITH(j.patch(patch),
|
||||
"[json.exception.parse_error.105] parse error: operation 'test' must have member 'value'");
|
||||
#if JSON_DIAGNOSTICS
|
||||
CHECK_THROWS_WITH(j.patch(patch), "[json.exception.parse_error.105] parse error: (/0) operation 'test' must have member 'value'");
|
||||
#else
|
||||
CHECK_THROWS_WITH(j.patch(patch), "[json.exception.parse_error.105] parse error: operation 'test' must have member 'value'");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1183,7 +1260,11 @@ TEST_CASE("JSON patch")
|
||||
|
||||
// the test will fail
|
||||
CHECK_THROWS_AS(doc.patch(patch), json::other_error&);
|
||||
#if JSON_DIAGNOSTICS
|
||||
CHECK_THROWS_WITH_STD_STR(doc.patch(patch), "[json.exception.other_error.501] (/0) unsuccessful: " + patch[0].dump());
|
||||
#else
|
||||
CHECK_THROWS_WITH_STD_STR(doc.patch(patch), "[json.exception.other_error.501] unsuccessful: " + patch[0].dump());
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1258,7 +1339,7 @@ TEST_CASE("JSON patch")
|
||||
|
||||
SECTION("Tests from github.com/json-patch/json-patch-tests")
|
||||
{
|
||||
for (auto filename :
|
||||
for (const auto* filename :
|
||||
{
|
||||
TEST_DATA_DIRECTORY "/json-patch-tests/spec_tests.json",
|
||||
TEST_DATA_DIRECTORY "/json-patch-tests/tests.json"
|
||||
|
||||
@@ -504,8 +504,11 @@ TEST_CASE("JSON pointers")
|
||||
|
||||
// error for nonprimitve values
|
||||
CHECK_THROWS_AS(json({{"/1", {1, 2, 3}}}).unflatten(), json::type_error&);
|
||||
CHECK_THROWS_WITH(json({{"/1", {1, 2, 3}}}).unflatten(),
|
||||
"[json.exception.type_error.315] values in object must be primitive");
|
||||
#if JSON_DIAGNOSTICS
|
||||
CHECK_THROWS_WITH(json({{"/1", {1, 2, 3}}}).unflatten(), "[json.exception.type_error.315] (/~11) values in object must be primitive");
|
||||
#else
|
||||
CHECK_THROWS_WITH(json({{"/1", {1, 2, 3}}}).unflatten(), "[json.exception.type_error.315] values in object must be primitive");
|
||||
#endif
|
||||
|
||||
// error for conflicting values
|
||||
json j_error = {{"", 42}, {"/foo", 17}};
|
||||
@@ -535,7 +538,7 @@ TEST_CASE("JSON pointers")
|
||||
|
||||
SECTION("string representation")
|
||||
{
|
||||
for (auto ptr :
|
||||
for (const auto* ptr :
|
||||
{"", "/foo", "/foo/0", "/", "/a~1b", "/c%d", "/e^f", "/g|h", "/i\\j", "/k\"l", "/ ", "/m~0n"
|
||||
})
|
||||
{
|
||||
|
||||
@@ -52,42 +52,42 @@ class SaxCountdown
|
||||
return events_left-- > 0;
|
||||
}
|
||||
|
||||
bool boolean(bool)
|
||||
bool boolean(bool /*unused*/)
|
||||
{
|
||||
return events_left-- > 0;
|
||||
}
|
||||
|
||||
bool number_integer(json::number_integer_t)
|
||||
bool number_integer(json::number_integer_t /*unused*/)
|
||||
{
|
||||
return events_left-- > 0;
|
||||
}
|
||||
|
||||
bool number_unsigned(json::number_unsigned_t)
|
||||
bool number_unsigned(json::number_unsigned_t /*unused*/)
|
||||
{
|
||||
return events_left-- > 0;
|
||||
}
|
||||
|
||||
bool number_float(json::number_float_t, const std::string&)
|
||||
bool number_float(json::number_float_t /*unused*/, const std::string& /*unused*/)
|
||||
{
|
||||
return events_left-- > 0;
|
||||
}
|
||||
|
||||
bool string(std::string&)
|
||||
bool string(std::string& /*unused*/)
|
||||
{
|
||||
return events_left-- > 0;
|
||||
}
|
||||
|
||||
bool binary(std::vector<std::uint8_t>&)
|
||||
bool binary(std::vector<std::uint8_t>& /*unused*/)
|
||||
{
|
||||
return events_left-- > 0;
|
||||
}
|
||||
|
||||
bool start_object(std::size_t)
|
||||
bool start_object(std::size_t /*unused*/)
|
||||
{
|
||||
return events_left-- > 0;
|
||||
}
|
||||
|
||||
bool key(std::string&)
|
||||
bool key(std::string& /*unused*/)
|
||||
{
|
||||
return events_left-- > 0;
|
||||
}
|
||||
@@ -97,7 +97,7 @@ class SaxCountdown
|
||||
return events_left-- > 0;
|
||||
}
|
||||
|
||||
bool start_array(std::size_t)
|
||||
bool start_array(std::size_t /*unused*/)
|
||||
{
|
||||
return events_left-- > 0;
|
||||
}
|
||||
@@ -107,7 +107,7 @@ class SaxCountdown
|
||||
return events_left-- > 0;
|
||||
}
|
||||
|
||||
bool parse_error(std::size_t, const std::string&, const json::exception&)
|
||||
bool parse_error(std::size_t /*unused*/, const std::string& /*unused*/, const json::exception& /*unused*/) // NOLINT(readability-convert-member-functions-to-static)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -115,7 +115,7 @@ class SaxCountdown
|
||||
private:
|
||||
int events_left = 0;
|
||||
};
|
||||
}
|
||||
} // namespace
|
||||
|
||||
TEST_CASE("MessagePack")
|
||||
{
|
||||
@@ -258,7 +258,7 @@ TEST_CASE("MessagePack")
|
||||
|
||||
// check individual bytes
|
||||
CHECK(result[0] == 0xcc);
|
||||
uint8_t restored = static_cast<uint8_t>(result[1]);
|
||||
auto restored = static_cast<uint8_t>(result[1]);
|
||||
CHECK(restored == i);
|
||||
|
||||
// roundtrip
|
||||
@@ -293,7 +293,7 @@ TEST_CASE("MessagePack")
|
||||
|
||||
// check individual bytes
|
||||
CHECK(result[0] == 0xcd);
|
||||
uint16_t restored = static_cast<uint16_t>(static_cast<uint8_t>(result[1]) * 256 + static_cast<uint8_t>(result[2]));
|
||||
auto restored = static_cast<uint16_t>(static_cast<uint8_t>(result[1]) * 256 + static_cast<uint8_t>(result[2]));
|
||||
CHECK(restored == i);
|
||||
|
||||
// roundtrip
|
||||
@@ -436,7 +436,7 @@ TEST_CASE("MessagePack")
|
||||
const auto result = json::to_msgpack(j);
|
||||
CHECK(result == expected);
|
||||
|
||||
int16_t restored = static_cast<int16_t>((result[1] << 8) + result[2]);
|
||||
auto restored = static_cast<int16_t>((result[1] << 8) + result[2]);
|
||||
CHECK(restored == -9263);
|
||||
|
||||
// roundtrip
|
||||
@@ -446,7 +446,7 @@ TEST_CASE("MessagePack")
|
||||
|
||||
SECTION("-32768..-129 (int 16)")
|
||||
{
|
||||
for (int16_t i = -32768; i <= -129; ++i)
|
||||
for (int16_t i = -32768; i <= int16_t(-129); ++i)
|
||||
{
|
||||
CAPTURE(i)
|
||||
|
||||
@@ -469,7 +469,7 @@ TEST_CASE("MessagePack")
|
||||
|
||||
// check individual bytes
|
||||
CHECK(result[0] == 0xd1);
|
||||
int16_t restored = static_cast<int16_t>((result[1] << 8) + result[2]);
|
||||
auto restored = static_cast<int16_t>((result[1] << 8) + result[2]);
|
||||
CHECK(restored == i);
|
||||
|
||||
// roundtrip
|
||||
@@ -485,7 +485,7 @@ TEST_CASE("MessagePack")
|
||||
numbers.push_back(-65536);
|
||||
numbers.push_back(-77777);
|
||||
numbers.push_back(-1048576);
|
||||
numbers.push_back(-2147483648ll);
|
||||
numbers.push_back(-2147483648LL);
|
||||
for (auto i : numbers)
|
||||
{
|
||||
CAPTURE(i)
|
||||
@@ -527,7 +527,7 @@ TEST_CASE("MessagePack")
|
||||
{
|
||||
std::vector<int64_t> numbers;
|
||||
numbers.push_back(INT64_MIN);
|
||||
numbers.push_back(-2147483649ll);
|
||||
numbers.push_back(-2147483649LL);
|
||||
for (auto i : numbers)
|
||||
{
|
||||
CAPTURE(i)
|
||||
@@ -630,7 +630,7 @@ TEST_CASE("MessagePack")
|
||||
|
||||
// check individual bytes
|
||||
CHECK(result[0] == 0xcc);
|
||||
uint8_t restored = static_cast<uint8_t>(result[1]);
|
||||
auto restored = static_cast<uint8_t>(result[1]);
|
||||
CHECK(restored == i);
|
||||
|
||||
// roundtrip
|
||||
@@ -664,7 +664,7 @@ TEST_CASE("MessagePack")
|
||||
|
||||
// check individual bytes
|
||||
CHECK(result[0] == 0xcd);
|
||||
uint16_t restored = static_cast<uint16_t>(static_cast<uint8_t>(result[1]) * 256 + static_cast<uint8_t>(result[2]));
|
||||
auto restored = static_cast<uint16_t>(static_cast<uint8_t>(result[1]) * 256 + static_cast<uint8_t>(result[2]));
|
||||
CHECK(restored == i);
|
||||
|
||||
// roundtrip
|
||||
@@ -1088,7 +1088,7 @@ TEST_CASE("MessagePack")
|
||||
|
||||
SECTION("{\"a\": {\"b\": {\"c\": {}}}}")
|
||||
{
|
||||
json j = json::parse("{\"a\": {\"b\": {\"c\": {}}}}");
|
||||
json j = json::parse(R"({"a": {"b": {"c": {}}}})");
|
||||
std::vector<uint8_t> expected =
|
||||
{
|
||||
0x81, 0xa1, 0x61, 0x81, 0xa1, 0x62, 0x81, 0xa1, 0x63, 0x80
|
||||
@@ -1647,23 +1647,21 @@ TEST_CASE("MessagePack roundtrips" * doctest::skip())
|
||||
SECTION("input from msgpack-python")
|
||||
{
|
||||
// most of these are excluded due to differences in key order (not a real problem)
|
||||
auto exclude_packed = std::set<std::string>
|
||||
{
|
||||
TEST_DATA_DIRECTORY "/json.org/1.json",
|
||||
TEST_DATA_DIRECTORY "/json.org/2.json",
|
||||
TEST_DATA_DIRECTORY "/json.org/3.json",
|
||||
TEST_DATA_DIRECTORY "/json.org/4.json",
|
||||
TEST_DATA_DIRECTORY "/json.org/5.json",
|
||||
TEST_DATA_DIRECTORY "/json_testsuite/sample.json", // kills AppVeyor
|
||||
TEST_DATA_DIRECTORY "/json_tests/pass1.json",
|
||||
TEST_DATA_DIRECTORY "/regression/working_file.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_duplicated_key.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_string_unicode.json",
|
||||
};
|
||||
std::set<std::string> exclude_packed;
|
||||
exclude_packed.insert(TEST_DATA_DIRECTORY "/json.org/1.json");
|
||||
exclude_packed.insert(TEST_DATA_DIRECTORY "/json.org/2.json");
|
||||
exclude_packed.insert(TEST_DATA_DIRECTORY "/json.org/3.json");
|
||||
exclude_packed.insert(TEST_DATA_DIRECTORY "/json.org/4.json");
|
||||
exclude_packed.insert(TEST_DATA_DIRECTORY "/json.org/5.json");
|
||||
exclude_packed.insert(TEST_DATA_DIRECTORY "/json_testsuite/sample.json"); // kills AppVeyor
|
||||
exclude_packed.insert(TEST_DATA_DIRECTORY "/json_tests/pass1.json");
|
||||
exclude_packed.insert(TEST_DATA_DIRECTORY "/regression/working_file.json");
|
||||
exclude_packed.insert(TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object.json");
|
||||
exclude_packed.insert(TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_basic.json");
|
||||
exclude_packed.insert(TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_duplicated_key.json");
|
||||
exclude_packed.insert(TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_long_strings.json");
|
||||
exclude_packed.insert(TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_simple.json");
|
||||
exclude_packed.insert(TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_string_unicode.json");
|
||||
|
||||
for (std::string filename :
|
||||
{
|
||||
@@ -1870,7 +1868,7 @@ TEST_CASE("MessagePack roundtrips" * doctest::skip())
|
||||
// parse MessagePack file
|
||||
auto packed = utils::read_binary_file(filename + ".msgpack");
|
||||
|
||||
if (!exclude_packed.count(filename))
|
||||
if (exclude_packed.count(filename) == 0u)
|
||||
{
|
||||
{
|
||||
INFO_WITH_TEMP(filename + ": output adapters: std::vector<uint8_t>");
|
||||
|
||||
@@ -42,16 +42,16 @@ enum test
|
||||
struct pod {};
|
||||
struct pod_bis {};
|
||||
|
||||
void to_json(json&, pod) noexcept;
|
||||
void to_json(json&, pod_bis);
|
||||
void from_json(const json&, pod) noexcept;
|
||||
void from_json(const json&, pod_bis);
|
||||
void to_json(json&, pod) noexcept {}
|
||||
void to_json(json&, pod_bis) {}
|
||||
void from_json(const json&, pod) noexcept {}
|
||||
void from_json(const json&, pod_bis) {}
|
||||
void to_json(json& /*unused*/, pod /*unused*/) noexcept;
|
||||
void to_json(json& /*unused*/, pod_bis /*unused*/);
|
||||
void from_json(const json& /*unused*/, pod /*unused*/) noexcept;
|
||||
void from_json(const json& /*unused*/, pod_bis /*unused*/);
|
||||
void to_json(json& /*unused*/, pod /*unused*/) noexcept {}
|
||||
void to_json(json& /*unused*/, pod_bis /*unused*/) {}
|
||||
void from_json(const json& /*unused*/, pod /*unused*/) noexcept {}
|
||||
void from_json(const json& /*unused*/, pod_bis /*unused*/) {}
|
||||
|
||||
static json* j = nullptr;
|
||||
json* j = nullptr;
|
||||
|
||||
static_assert(noexcept(json{}), "");
|
||||
static_assert(noexcept(nlohmann::to_json(*j, 2)), "");
|
||||
@@ -66,7 +66,7 @@ static_assert(noexcept(json(pod{})), "");
|
||||
static_assert(noexcept(j->get<pod>()), "");
|
||||
static_assert(!noexcept(j->get<pod_bis>()), "");
|
||||
static_assert(noexcept(json(pod{})), "");
|
||||
}
|
||||
} // namespace
|
||||
|
||||
TEST_CASE("runtime checks")
|
||||
{
|
||||
|
||||
@@ -49,6 +49,7 @@ TEST_CASE("ordered_map")
|
||||
std::map<std::string, std::string> m {{"eins", "one"}, {"zwei", "two"}, {"drei", "three"}};
|
||||
ordered_map<std::string, std::string> om(m.begin(), m.end());
|
||||
const auto com = om;
|
||||
om.clear(); // silence a warning by forbidding having "const auto& com = om;"
|
||||
CHECK(com.size() == 3);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ TEST_CASE("README" * doctest::skip())
|
||||
{
|
||||
{
|
||||
// redirect std::cout for the README file
|
||||
auto old_cout_buffer = std::cout.rdbuf();
|
||||
auto* old_cout_buffer = std::cout.rdbuf();
|
||||
std::ostringstream new_stream;
|
||||
std::cout.rdbuf(new_stream.rdbuf());
|
||||
{
|
||||
@@ -123,7 +123,7 @@ TEST_CASE("README" * doctest::skip())
|
||||
|
||||
{
|
||||
// create object from string literal
|
||||
json j = "{ \"happy\": true, \"pi\": 3.141 }"_json;
|
||||
json j = "{ \"happy\": true, \"pi\": 3.141 }"_json; // NOLINT(modernize-raw-string-literal)
|
||||
|
||||
// or even nicer with a raw string literal
|
||||
auto j2 = R"(
|
||||
@@ -134,7 +134,7 @@ TEST_CASE("README" * doctest::skip())
|
||||
)"_json;
|
||||
|
||||
// or explicitly
|
||||
auto j3 = json::parse("{ \"happy\": true, \"pi\": 3.141 }");
|
||||
auto j3 = json::parse(R"({"happy": true, "pi": 3.141})");
|
||||
|
||||
// explicit conversion to string
|
||||
std::string s = j.dump(); // {\"happy\":true,\"pi\":3.141}
|
||||
@@ -158,17 +158,17 @@ TEST_CASE("README" * doctest::skip())
|
||||
j.push_back(true);
|
||||
|
||||
// comparison
|
||||
bool x = (j == "[\"foo\", 1, true]"_json); // true
|
||||
bool x = (j == R"(["foo", 1, true])"_json); // true
|
||||
CHECK(x == true);
|
||||
|
||||
// iterate the array
|
||||
for (json::iterator it = j.begin(); it != j.end(); ++it)
|
||||
for (json::iterator it = j.begin(); it != j.end(); ++it) // NOLINT(modernize-loop-convert)
|
||||
{
|
||||
std::cout << *it << '\n';
|
||||
}
|
||||
|
||||
// range-based for
|
||||
for (auto element : j)
|
||||
for (auto& element : j)
|
||||
{
|
||||
std::cout << element << '\n';
|
||||
}
|
||||
|
||||
@@ -56,11 +56,11 @@ TEST_CASE("reference access")
|
||||
json value = {{"one", 1}, {"two", 2}};
|
||||
|
||||
// check if references are returned correctly
|
||||
test_type& p1 = value.get_ref<test_type&>();
|
||||
auto& p1 = value.get_ref<test_type&>();
|
||||
CHECK(&p1 == value.get_ptr<test_type*>());
|
||||
CHECK(p1 == value.get<test_type>());
|
||||
|
||||
const test_type& p2 = value.get_ref<const test_type&>();
|
||||
const auto& p2 = value.get_ref<const test_type&>();
|
||||
CHECK(&p2 == value.get_ptr<const test_type*>());
|
||||
CHECK(p2 == value.get<test_type>());
|
||||
|
||||
@@ -95,7 +95,7 @@ TEST_CASE("reference access")
|
||||
// test_type& p1 = value.get_ref<test_type&>();
|
||||
|
||||
// check if references are returned correctly
|
||||
const test_type& p2 = value.get_ref<const test_type&>();
|
||||
const auto& p2 = value.get_ref<const test_type&>();
|
||||
CHECK(&p2 == value.get_ptr<const test_type*>());
|
||||
CHECK(p2 == value.get<test_type>());
|
||||
}
|
||||
@@ -106,11 +106,11 @@ TEST_CASE("reference access")
|
||||
json value = {1, 2, 3, 4};
|
||||
|
||||
// check if references are returned correctly
|
||||
test_type& p1 = value.get_ref<test_type&>();
|
||||
auto& p1 = value.get_ref<test_type&>();
|
||||
CHECK(&p1 == value.get_ptr<test_type*>());
|
||||
CHECK(p1 == value.get<test_type>());
|
||||
|
||||
const test_type& p2 = value.get_ref<const test_type&>();
|
||||
const auto& p2 = value.get_ref<const test_type&>();
|
||||
CHECK(&p2 == value.get_ptr<const test_type*>());
|
||||
CHECK(p2 == value.get<test_type>());
|
||||
|
||||
@@ -142,11 +142,11 @@ TEST_CASE("reference access")
|
||||
json value = "hello";
|
||||
|
||||
// check if references are returned correctly
|
||||
test_type& p1 = value.get_ref<test_type&>();
|
||||
auto& p1 = value.get_ref<test_type&>();
|
||||
CHECK(&p1 == value.get_ptr<test_type*>());
|
||||
CHECK(p1 == value.get<test_type>());
|
||||
|
||||
const test_type& p2 = value.get_ref<const test_type&>();
|
||||
const auto& p2 = value.get_ref<const test_type&>();
|
||||
CHECK(&p2 == value.get_ptr<const test_type*>());
|
||||
CHECK(p2 == value.get<test_type>());
|
||||
|
||||
@@ -178,11 +178,11 @@ TEST_CASE("reference access")
|
||||
json value = false;
|
||||
|
||||
// check if references are returned correctly
|
||||
test_type& p1 = value.get_ref<test_type&>();
|
||||
auto& p1 = value.get_ref<test_type&>();
|
||||
CHECK(&p1 == value.get_ptr<test_type*>());
|
||||
CHECK(p1 == value.get<test_type>());
|
||||
|
||||
const test_type& p2 = value.get_ref<const test_type&>();
|
||||
const auto& p2 = value.get_ref<const test_type&>();
|
||||
CHECK(&p2 == value.get_ptr<const test_type*>());
|
||||
CHECK(p2 == value.get<test_type>());
|
||||
|
||||
@@ -214,11 +214,11 @@ TEST_CASE("reference access")
|
||||
json value = -23;
|
||||
|
||||
// check if references are returned correctly
|
||||
test_type& p1 = value.get_ref<test_type&>();
|
||||
auto& p1 = value.get_ref<test_type&>();
|
||||
CHECK(&p1 == value.get_ptr<test_type*>());
|
||||
CHECK(p1 == value.get<test_type>());
|
||||
|
||||
const test_type& p2 = value.get_ref<const test_type&>();
|
||||
const auto& p2 = value.get_ref<const test_type&>();
|
||||
CHECK(&p2 == value.get_ptr<const test_type*>());
|
||||
CHECK(p2 == value.get<test_type>());
|
||||
|
||||
@@ -250,11 +250,11 @@ TEST_CASE("reference access")
|
||||
json value = 23u;
|
||||
|
||||
// check if references are returned correctly
|
||||
test_type& p1 = value.get_ref<test_type&>();
|
||||
auto& p1 = value.get_ref<test_type&>();
|
||||
CHECK(&p1 == value.get_ptr<test_type*>());
|
||||
CHECK(p1 == value.get<test_type>());
|
||||
|
||||
const test_type& p2 = value.get_ref<const test_type&>();
|
||||
const auto& p2 = value.get_ref<const test_type&>();
|
||||
CHECK(&p2 == value.get_ptr<const test_type*>());
|
||||
CHECK(p2 == value.get<test_type>());
|
||||
|
||||
@@ -286,11 +286,11 @@ TEST_CASE("reference access")
|
||||
json value = 42.23;
|
||||
|
||||
// check if references are returned correctly
|
||||
test_type& p1 = value.get_ref<test_type&>();
|
||||
auto& p1 = value.get_ref<test_type&>();
|
||||
CHECK(&p1 == value.get_ptr<test_type*>());
|
||||
CHECK(p1 == value.get<test_type>());
|
||||
|
||||
const test_type& p2 = value.get_ref<const test_type&>();
|
||||
const auto& p2 = value.get_ref<const test_type&>();
|
||||
CHECK(&p2 == value.get_ptr<const test_type*>());
|
||||
CHECK(p2 == value.get<test_type>());
|
||||
|
||||
|
||||
@@ -94,7 +94,7 @@ template<typename T>
|
||||
struct foo_serializer < T, typename std::enable_if < !std::is_same<foo, T>::value >::type >
|
||||
{
|
||||
template <typename BasicJsonType>
|
||||
static void to_json(BasicJsonType& j, const T& value) noexcept
|
||||
static void to_json(BasicJsonType& j, const T& value) noexcept // NOLINT(bugprone-exception-escape)
|
||||
{
|
||||
::nlohmann::to_json(j, value);
|
||||
}
|
||||
@@ -104,7 +104,7 @@ struct foo_serializer < T, typename std::enable_if < !std::is_same<foo, T>::valu
|
||||
::nlohmann::from_json(j, value);
|
||||
}
|
||||
};
|
||||
}
|
||||
} // namespace ns
|
||||
|
||||
using foo_json = nlohmann::basic_json<std::map, std::vector, std::string, bool, std::int64_t,
|
||||
std::uint64_t, double, std::allocator, ns::foo_serializer, std::vector<std::uint8_t>>;
|
||||
@@ -115,10 +115,13 @@ using foo_json = nlohmann::basic_json<std::map, std::vector, std::string, bool,
|
||||
|
||||
namespace
|
||||
{
|
||||
struct nocopy
|
||||
struct nocopy // NOLINT(cppcoreguidelines-special-member-functions,hicpp-special-member-functions)
|
||||
{
|
||||
nocopy() = default;
|
||||
nocopy(const nocopy&) = delete;
|
||||
nocopy(nocopy&&) = delete;
|
||||
nocopy& operator=(const nocopy&) = delete;
|
||||
nocopy& operator=(nocopy&&) = delete;
|
||||
|
||||
int val = 0;
|
||||
|
||||
@@ -127,7 +130,7 @@ struct nocopy
|
||||
j = {{"val", n.val}};
|
||||
}
|
||||
};
|
||||
}
|
||||
} // namespace
|
||||
|
||||
TEST_CASE("regression tests 1")
|
||||
{
|
||||
@@ -135,7 +138,7 @@ TEST_CASE("regression tests 1")
|
||||
{
|
||||
SECTION("escape_doublequote")
|
||||
{
|
||||
auto s = "[\"\\\"foo\\\"\"]";
|
||||
const auto* s = R"(["\"foo\""])";
|
||||
json j = json::parse(s);
|
||||
auto expected = R"(["\"foo\""])"_json;
|
||||
CHECK(j == expected);
|
||||
@@ -245,7 +248,7 @@ TEST_CASE("regression tests 1")
|
||||
|
||||
SECTION("issue #82 - lexer::get_number return NAN")
|
||||
{
|
||||
const auto content = R"(
|
||||
const auto* const content = R"(
|
||||
{
|
||||
"Test":"Test1",
|
||||
"Number":100,
|
||||
@@ -394,7 +397,11 @@ TEST_CASE("regression tests 1")
|
||||
// improve coverage
|
||||
o["int"] = 1;
|
||||
CHECK_THROWS_AS(s2 = o["int"], json::type_error);
|
||||
#if JSON_DIAGNOSTICS
|
||||
CHECK_THROWS_WITH(s2 = o["int"], "[json.exception.type_error.302] (/int) type must be string, but is number");
|
||||
#else
|
||||
CHECK_THROWS_WITH(s2 = o["int"], "[json.exception.type_error.302] type must be string, but is number");
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -408,18 +415,18 @@ TEST_CASE("regression tests 1")
|
||||
json j;
|
||||
|
||||
// Non-const access with key as "char []"
|
||||
char array_key[] = "Key1";
|
||||
char array_key[] = "Key1"; // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays)
|
||||
CHECK_NOTHROW(j[array_key] = 1);
|
||||
CHECK(j[array_key] == json(1));
|
||||
|
||||
// Non-const access with key as "const char[]"
|
||||
const char const_array_key[] = "Key2";
|
||||
const char const_array_key[] = "Key2"; // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays)
|
||||
CHECK_NOTHROW(j[const_array_key] = 2);
|
||||
CHECK(j[const_array_key] == json(2));
|
||||
|
||||
// Non-const access with key as "char *"
|
||||
char _ptr_key[] = "Key3";
|
||||
char* ptr_key = &_ptr_key[0];
|
||||
char _ptr_key[] = "Key3"; // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays)
|
||||
char* ptr_key = &_ptr_key[0]; // NOLINT(cppcoreguidelines-pro-type-vararg,hicpp-vararg)
|
||||
CHECK_NOTHROW(j[ptr_key] = 3);
|
||||
CHECK(j[ptr_key] == json(3));
|
||||
|
||||
@@ -633,7 +640,7 @@ TEST_CASE("regression tests 1")
|
||||
|
||||
SECTION("issue #306 - Parsing fails without space at end of file")
|
||||
{
|
||||
for (auto filename :
|
||||
for (const auto* filename :
|
||||
{
|
||||
TEST_DATA_DIRECTORY "/regression/broken_file.json",
|
||||
TEST_DATA_DIRECTORY "/regression/working_file.json"
|
||||
@@ -648,7 +655,7 @@ TEST_CASE("regression tests 1")
|
||||
|
||||
SECTION("issue #310 - make json_benchmarks no longer working in 2.0.4")
|
||||
{
|
||||
for (auto filename :
|
||||
for (const auto* filename :
|
||||
{
|
||||
TEST_DATA_DIRECTORY "/regression/floats.json",
|
||||
TEST_DATA_DIRECTORY "/regression/signed_ints.json",
|
||||
@@ -732,7 +739,7 @@ TEST_CASE("regression tests 1")
|
||||
check_roundtrip(83623297654460.33);
|
||||
check_roundtrip(701466573254773.6);
|
||||
check_roundtrip(1369013370304513);
|
||||
check_roundtrip(96963648023094720);
|
||||
check_roundtrip(96963648023094720); // NOLINT(bugprone-narrowing-conversions,cppcoreguidelines-narrowing-conversions)
|
||||
check_roundtrip(3.478237409280108e+17);
|
||||
}
|
||||
|
||||
@@ -1099,17 +1106,17 @@ TEST_CASE("regression tests 1")
|
||||
SECTION("issue #414 - compare with literal 0)")
|
||||
{
|
||||
#define CHECK_TYPE(v) \
|
||||
CHECK((json(v) == v));\
|
||||
CHECK((v == json(v)));\
|
||||
CHECK_FALSE((json(v) != v));\
|
||||
CHECK_FALSE((v != json(v)));
|
||||
CHECK((json(v) == (v)));\
|
||||
CHECK(((v) == json(v)));\
|
||||
CHECK_FALSE((json(v) != (v)));\
|
||||
CHECK_FALSE(((v) != json(v)));
|
||||
|
||||
CHECK_TYPE(nullptr)
|
||||
CHECK_TYPE(0)
|
||||
CHECK_TYPE(0u)
|
||||
CHECK_TYPE(0L)
|
||||
CHECK_TYPE(0.0)
|
||||
CHECK_TYPE("")
|
||||
CHECK_TYPE("") // NOLINT(readability-container-size-empty)
|
||||
|
||||
#undef CHECK_TYPE
|
||||
}
|
||||
@@ -1385,8 +1392,10 @@ TEST_CASE("regression tests 1")
|
||||
{
|
||||
SECTION("example 1")
|
||||
{
|
||||
std::istringstream i1_2_3( "{\"first\": \"one\" }{\"second\": \"two\"}3" );
|
||||
json j1, j2, j3;
|
||||
std::istringstream i1_2_3( R"({"first": "one" }{"second": "two"}3)" );
|
||||
json j1;
|
||||
json j2;
|
||||
json j3;
|
||||
i1_2_3 >> j1;
|
||||
i1_2_3 >> j2;
|
||||
i1_2_3 >> j3;
|
||||
@@ -1441,8 +1450,8 @@ TEST_CASE("regression tests 1")
|
||||
|
||||
SECTION("issue #838 - incorrect parse error with binary data in keys")
|
||||
{
|
||||
uint8_t key1[] = { 103, 92, 117, 48, 48, 48, 55, 92, 114, 215, 126, 214, 95, 92, 34, 174, 40, 71, 38, 174, 40, 71, 38, 223, 134, 247, 127, 0 };
|
||||
std::string key1_str(reinterpret_cast<char*>(key1));
|
||||
std::array<uint8_t, 28> key1 = {{ 103, 92, 117, 48, 48, 48, 55, 92, 114, 215, 126, 214, 95, 92, 34, 174, 40, 71, 38, 174, 40, 71, 38, 223, 134, 247, 127, 0 }};
|
||||
std::string key1_str(reinterpret_cast<char*>(key1.data()));
|
||||
json j = key1_str;
|
||||
CHECK_THROWS_AS(j.dump(), json::type_error&);
|
||||
CHECK_THROWS_WITH(j.dump(), "[json.exception.type_error.316] invalid UTF-8 byte at index 10: 0x7E");
|
||||
@@ -1524,7 +1533,7 @@ TEST_CASE("regression tests 1")
|
||||
SECTION("issue #971 - Add a SAX parser - late bug")
|
||||
{
|
||||
// a JSON text
|
||||
auto text = R"(
|
||||
const auto* text = R"(
|
||||
{
|
||||
"Image": {
|
||||
"Width": 800,
|
||||
@@ -1545,14 +1554,7 @@ TEST_CASE("regression tests 1")
|
||||
json::parser_callback_t cb = [](int /*depth*/, json::parse_event_t event, json & parsed)
|
||||
{
|
||||
// skip object elements with key "Thumbnail"
|
||||
if (event == json::parse_event_t::key && parsed == json("Thumbnail"))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return !(event == json::parse_event_t::key && parsed == json("Thumbnail"));
|
||||
};
|
||||
|
||||
// parse (with callback) and serialize JSON
|
||||
|
||||
@@ -37,11 +37,9 @@ DOCTEST_GCC_SUPPRESS_WARNING("-Wfloat-equal")
|
||||
#include <nlohmann/json.hpp>
|
||||
using nlohmann::json;
|
||||
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <list>
|
||||
#include <cstdio>
|
||||
#include <test_data.hpp>
|
||||
#include <utility>
|
||||
|
||||
#if (defined(__cplusplus) && __cplusplus >= 201703L) || (defined(_HAS_CXX17) && _HAS_CXX17 == 1) // fix for issue #464
|
||||
#define JSON_HAS_CPP_17
|
||||
@@ -68,19 +66,20 @@ namespace
|
||||
{
|
||||
struct NonDefaultFromJsonStruct { };
|
||||
|
||||
inline bool operator== (NonDefaultFromJsonStruct const&, NonDefaultFromJsonStruct const&)
|
||||
inline bool operator== (NonDefaultFromJsonStruct const& /*unused*/, NonDefaultFromJsonStruct const& /*unused*/)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
enum class for_1647 { one, two };
|
||||
|
||||
// NOLINTNEXTLINE(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays): this is a false positive
|
||||
NLOHMANN_JSON_SERIALIZE_ENUM(for_1647,
|
||||
{
|
||||
{for_1647::one, "one"},
|
||||
{for_1647::two, "two"},
|
||||
})
|
||||
}
|
||||
} // namespace
|
||||
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
// for #1299
|
||||
@@ -89,17 +88,19 @@ NLOHMANN_JSON_SERIALIZE_ENUM(for_1647,
|
||||
struct Data
|
||||
{
|
||||
Data() = default;
|
||||
Data(const std::string& a_, const std::string b_) : a(a_), b(b_) {}
|
||||
Data(std::string a_, std::string b_) : a(std::move(a_)), b(std::move(b_)) {}
|
||||
std::string a {};
|
||||
std::string b {};
|
||||
};
|
||||
|
||||
void from_json(const json& j, Data& data);
|
||||
void from_json(const json& j, Data& data)
|
||||
{
|
||||
j["a"].get_to(data.a);
|
||||
j["b"].get_to(data.b);
|
||||
}
|
||||
|
||||
bool operator==(Data const& lhs, Data const& rhs);
|
||||
bool operator==(Data const& lhs, Data const& rhs)
|
||||
{
|
||||
return lhs.a == rhs.a && lhs.b == rhs.b;
|
||||
@@ -115,12 +116,12 @@ namespace nlohmann
|
||||
template <>
|
||||
struct adl_serializer<NonDefaultFromJsonStruct>
|
||||
{
|
||||
static NonDefaultFromJsonStruct from_json (json const&) noexcept
|
||||
static NonDefaultFromJsonStruct from_json (json const& /*unused*/) noexcept
|
||||
{
|
||||
return {};
|
||||
}
|
||||
};
|
||||
}
|
||||
} // namespace nlohmann
|
||||
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
// for #1805
|
||||
@@ -133,11 +134,34 @@ struct NotSerializableData
|
||||
};
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
// for #2574
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
|
||||
struct NonDefaultConstructible
|
||||
{
|
||||
explicit NonDefaultConstructible (int a) : x(a) { }
|
||||
int x;
|
||||
};
|
||||
|
||||
namespace nlohmann
|
||||
{
|
||||
template <>
|
||||
struct adl_serializer<NonDefaultConstructible>
|
||||
{
|
||||
static NonDefaultConstructible from_json (json const& j)
|
||||
{
|
||||
return NonDefaultConstructible(j.get<int>());
|
||||
}
|
||||
};
|
||||
} // namespace nlohmann
|
||||
|
||||
|
||||
TEST_CASE("regression tests 2")
|
||||
{
|
||||
SECTION("issue #1001 - Fix memory leak during parser callback")
|
||||
{
|
||||
auto geojsonExample = R"(
|
||||
const auto* geojsonExample = R"(
|
||||
{ "type": "FeatureCollection",
|
||||
"features": [
|
||||
{ "type": "Feature",
|
||||
@@ -172,7 +196,7 @@ TEST_CASE("regression tests 2")
|
||||
]
|
||||
})";
|
||||
|
||||
json::parser_callback_t cb = [&](int, json::parse_event_t event, json & parsed)
|
||||
json::parser_callback_t cb = [&](int /*level*/, json::parse_event_t event, json & parsed)
|
||||
{
|
||||
// skip uninteresting events
|
||||
if (event == json::parse_event_t::value && !parsed.is_primitive())
|
||||
@@ -288,7 +312,7 @@ TEST_CASE("regression tests 2")
|
||||
json dump_test;
|
||||
dump_test["1"] = std::string(length, -1);
|
||||
|
||||
std::string expected = "{\"1\":\"";
|
||||
std::string expected = R"({"1":")";
|
||||
for (int i = 0; i < length; ++i)
|
||||
{
|
||||
expected += "\\ufffd";
|
||||
@@ -305,7 +329,7 @@ TEST_CASE("regression tests 2")
|
||||
json dump_test;
|
||||
dump_test["1"] = std::string(length, -2);
|
||||
|
||||
std::string expected = "{\"1\":\"";
|
||||
std::string expected = R"({"1":")";
|
||||
for (int i = 0; i < length; ++i)
|
||||
{
|
||||
expected += "\xEF\xBF\xBD";
|
||||
@@ -318,29 +342,31 @@ TEST_CASE("regression tests 2")
|
||||
SECTION("test case in issue #1445")
|
||||
{
|
||||
nlohmann::json dump_test;
|
||||
const int data[] =
|
||||
const std::array<int, 108> data =
|
||||
{
|
||||
109, 108, 103, 125, -122, -53, 115,
|
||||
18, 3, 0, 102, 19, 1, 15,
|
||||
-110, 13, -3, -1, -81, 32, 2,
|
||||
0, 0, 0, 0, 0, 0, 0,
|
||||
8, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, -80, 2,
|
||||
0, 0, 96, -118, 46, -116, 46,
|
||||
109, -84, -87, 108, 14, 109, -24,
|
||||
-83, 13, -18, -51, -83, -52, -115,
|
||||
14, 6, 32, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0,
|
||||
64, 3, 0, 0, 0, 35, -74,
|
||||
-73, 55, 57, -128, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 33, 0, 0, 0, -96,
|
||||
-54, -28, -26
|
||||
{
|
||||
109, 108, 103, 125, -122, -53, 115,
|
||||
18, 3, 0, 102, 19, 1, 15,
|
||||
-110, 13, -3, -1, -81, 32, 2,
|
||||
0, 0, 0, 0, 0, 0, 0,
|
||||
8, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, -80, 2,
|
||||
0, 0, 96, -118, 46, -116, 46,
|
||||
109, -84, -87, 108, 14, 109, -24,
|
||||
-83, 13, -18, -51, -83, -52, -115,
|
||||
14, 6, 32, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0,
|
||||
64, 3, 0, 0, 0, 35, -74,
|
||||
-73, 55, 57, -128, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 33, 0, 0, 0, -96,
|
||||
-54, -28, -26
|
||||
}
|
||||
};
|
||||
std::string s;
|
||||
for (unsigned i = 0; i < sizeof(data) / sizeof(int); i++)
|
||||
for (int i : data)
|
||||
{
|
||||
s += static_cast<char>(data[i]);
|
||||
s += static_cast<char>(i);
|
||||
}
|
||||
dump_test["1"] = s;
|
||||
dump_test.dump(-1, ' ', true, nlohmann::json::error_handler_t::replace);
|
||||
@@ -395,7 +421,7 @@ TEST_CASE("regression tests 2")
|
||||
|
||||
SECTION("string array")
|
||||
{
|
||||
const char input[] = { 'B', 0x00 };
|
||||
const std::array<char, 2> input = {{ 'B', 0x00 }};
|
||||
json cbor = json::from_cbor(input, true, false);
|
||||
CHECK(cbor.is_discarded());
|
||||
}
|
||||
@@ -430,8 +456,8 @@ TEST_CASE("regression tests 2")
|
||||
|
||||
SECTION("issue #2067 - cannot serialize binary data to text JSON")
|
||||
{
|
||||
const unsigned char data[] = {0x81, 0xA4, 0x64, 0x61, 0x74, 0x61, 0xC4, 0x0F, 0x33, 0x30, 0x30, 0x32, 0x33, 0x34, 0x30, 0x31, 0x30, 0x37, 0x30, 0x35, 0x30, 0x31, 0x30};
|
||||
json j = json::from_msgpack(data, sizeof(data) / sizeof(data[0]));
|
||||
const std::array<unsigned char, 23> data = {{0x81, 0xA4, 0x64, 0x61, 0x74, 0x61, 0xC4, 0x0F, 0x33, 0x30, 0x30, 0x32, 0x33, 0x34, 0x30, 0x31, 0x30, 0x37, 0x30, 0x35, 0x30, 0x31, 0x30}};
|
||||
json j = json::from_msgpack(data.data(), data.size());
|
||||
CHECK_NOTHROW(
|
||||
j.dump(4, // Indent
|
||||
' ', // Indent char
|
||||
@@ -498,4 +524,74 @@ TEST_CASE("regression tests 2")
|
||||
CHECK(j.dump() == "\"Hello, world!\"");
|
||||
}
|
||||
#endif
|
||||
|
||||
SECTION("issue #2574 - Deserialization to std::array, std::pair, and std::tuple with non-default constructable types fails")
|
||||
{
|
||||
SECTION("std::array")
|
||||
{
|
||||
{
|
||||
json j = { 7, 4 };
|
||||
auto arr = j.get<std::array<NonDefaultConstructible, 2>>();
|
||||
CHECK(arr[0].x == 7);
|
||||
CHECK(arr[1].x == 4);
|
||||
|
||||
}
|
||||
|
||||
{
|
||||
json j = 7;
|
||||
CHECK_THROWS_AS((j.get<std::array<NonDefaultConstructible, 1>>()), json::type_error);
|
||||
}
|
||||
}
|
||||
|
||||
SECTION("std::pair")
|
||||
{
|
||||
{
|
||||
json j = { 3, 8 };
|
||||
auto p = j.get<std::pair<NonDefaultConstructible, NonDefaultConstructible>>();
|
||||
CHECK(p.first.x == 3);
|
||||
CHECK(p.second.x == 8);
|
||||
}
|
||||
|
||||
{
|
||||
json j = { 4, 1 };
|
||||
auto p = j.get<std::pair<int, NonDefaultConstructible>>();
|
||||
CHECK(p.first == 4);
|
||||
CHECK(p.second.x == 1);
|
||||
}
|
||||
|
||||
{
|
||||
json j = { 6, 7 };
|
||||
auto p = j.get<std::pair<NonDefaultConstructible, int>>();
|
||||
CHECK(p.first.x == 6);
|
||||
CHECK(p.second == 7);
|
||||
}
|
||||
|
||||
{
|
||||
json j = 7;
|
||||
CHECK_THROWS_AS((j.get<std::pair<NonDefaultConstructible, int>>()), json::type_error);
|
||||
}
|
||||
}
|
||||
|
||||
SECTION("std::tuple")
|
||||
{
|
||||
{
|
||||
json j = { 9 };
|
||||
auto t = j.get<std::tuple<NonDefaultConstructible>>();
|
||||
CHECK(std::get<0>(t).x == 9);
|
||||
}
|
||||
|
||||
{
|
||||
json j = { 9, 8, 7 };
|
||||
auto t = j.get<std::tuple<NonDefaultConstructible, int, NonDefaultConstructible>>();
|
||||
CHECK(std::get<0>(t).x == 9);
|
||||
CHECK(std::get<1>(t) == 8);
|
||||
CHECK(std::get<2>(t).x == 7);
|
||||
}
|
||||
|
||||
{
|
||||
json j = 7;
|
||||
CHECK_THROWS_AS((j.get<std::tuple<NonDefaultConstructible>>()), json::type_error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -183,10 +183,10 @@ TEST_CASE("serialization")
|
||||
CHECK(to_string(j) == "\"" + expected + "\"");
|
||||
};
|
||||
|
||||
test("{\"x\":5,\"y\":6}", "{\\\"x\\\":5,\\\"y\\\":6}");
|
||||
test("{\"x\":[10,null,null,null]}", "{\\\"x\\\":[10,null,null,null]}");
|
||||
test(R"({"x":5,"y":6})", R"({\"x\":5,\"y\":6})");
|
||||
test("{\"x\":[10,null,null,null]}", R"({\"x\":[10,null,null,null]})");
|
||||
test("test", "test");
|
||||
test("[3,\"false\",false]", "[3,\\\"false\\\",false]");
|
||||
test("[3,\"false\",false]", R"([3,\"false\",false])");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ TEST_CASE("compliance tests from json.org")
|
||||
|
||||
SECTION("expected failures")
|
||||
{
|
||||
for (auto filename :
|
||||
for (const auto* filename :
|
||||
{
|
||||
//TEST_DATA_DIRECTORY "/json_tests/fail1.json",
|
||||
TEST_DATA_DIRECTORY "/json_tests/fail2.json",
|
||||
@@ -90,7 +90,7 @@ TEST_CASE("compliance tests from json.org")
|
||||
// these tests fail above, because the parser does not end on EOF;
|
||||
// they succeed when the operator>> is used, because it does not
|
||||
// have this constraint
|
||||
for (auto filename :
|
||||
for (const auto* filename :
|
||||
{
|
||||
TEST_DATA_DIRECTORY "/json_tests/fail7.json",
|
||||
TEST_DATA_DIRECTORY "/json_tests/fail8.json",
|
||||
@@ -106,7 +106,7 @@ TEST_CASE("compliance tests from json.org")
|
||||
|
||||
SECTION("expected passes")
|
||||
{
|
||||
for (auto filename :
|
||||
for (const auto* filename :
|
||||
{
|
||||
TEST_DATA_DIRECTORY "/json_tests/pass1.json",
|
||||
TEST_DATA_DIRECTORY "/json_tests/pass2.json",
|
||||
@@ -235,13 +235,9 @@ TEST_CASE("compliance tests from nativejson-benchmark")
|
||||
5708990770823839524233143877797980545530986496.0);
|
||||
|
||||
{
|
||||
char n1e308[312]; // '1' followed by 308 '0'
|
||||
std::string n1e308(312, '0'); // '1' followed by 308 '0'
|
||||
n1e308[0] = '[';
|
||||
n1e308[1] = '1';
|
||||
for (int j = 2; j < 310; j++)
|
||||
{
|
||||
n1e308[j] = '0';
|
||||
}
|
||||
n1e308[310] = ']';
|
||||
n1e308[311] = '\0';
|
||||
TEST_DOUBLE(n1e308, 1E308);
|
||||
@@ -272,20 +268,20 @@ TEST_CASE("compliance tests from nativejson-benchmark")
|
||||
|
||||
TEST_STRING("[\"\"]", "");
|
||||
TEST_STRING("[\"Hello\"]", "Hello");
|
||||
TEST_STRING("[\"Hello\\nWorld\"]", "Hello\nWorld");
|
||||
TEST_STRING(R"(["Hello\nWorld"])", "Hello\nWorld");
|
||||
//TEST_STRING("[\"Hello\\u0000World\"]", "Hello\0World");
|
||||
TEST_STRING("[\"\\\"\\\\/\\b\\f\\n\\r\\t\"]", "\"\\/\b\f\n\r\t");
|
||||
TEST_STRING("[\"\\u0024\"]", "\x24"); // Dollar sign U+0024
|
||||
TEST_STRING("[\"\\u00A2\"]", "\xC2\xA2"); // Cents sign U+00A2
|
||||
TEST_STRING("[\"\\u20AC\"]", "\xE2\x82\xAC"); // Euro sign U+20AC
|
||||
TEST_STRING("[\"\\uD834\\uDD1E\"]", "\xF0\x9D\x84\x9E"); // G clef sign U+1D11E
|
||||
TEST_STRING(R"(["\"\\/\b\f\n\r\t"])", "\"\\/\b\f\n\r\t");
|
||||
TEST_STRING(R"(["\u0024"])", "$"); // Dollar sign U+0024
|
||||
TEST_STRING(R"(["\u00A2"])", "\xC2\xA2"); // Cents sign U+00A2
|
||||
TEST_STRING(R"(["\u20AC"])", "\xE2\x82\xAC"); // Euro sign U+20AC
|
||||
TEST_STRING(R"(["\uD834\uDD1E"])", "\xF0\x9D\x84\x9E"); // G clef sign U+1D11E
|
||||
}
|
||||
|
||||
SECTION("roundtrip")
|
||||
{
|
||||
// test cases are from https://github.com/miloyip/nativejson-benchmark/tree/master/test/data/roundtrip
|
||||
|
||||
for (auto filename :
|
||||
for (const auto* filename :
|
||||
{
|
||||
TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip01.json",
|
||||
TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip02.json",
|
||||
@@ -422,9 +418,9 @@ TEST_CASE("json.org examples")
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("RFC 7159 examples")
|
||||
TEST_CASE("RFC 8259 examples")
|
||||
{
|
||||
// here, we list all JSON values from the RFC 7159 document
|
||||
// here, we list all JSON values from the RFC 8259 document
|
||||
|
||||
SECTION("7. Strings")
|
||||
{
|
||||
@@ -441,7 +437,7 @@ TEST_CASE("RFC 7159 examples")
|
||||
SECTION("13 Examples")
|
||||
{
|
||||
{
|
||||
auto json_contents = R"(
|
||||
const auto* json_contents = R"(
|
||||
{
|
||||
"Image": {
|
||||
"Width": 800,
|
||||
@@ -462,7 +458,7 @@ TEST_CASE("RFC 7159 examples")
|
||||
}
|
||||
|
||||
{
|
||||
auto json_contents = R"(
|
||||
const auto* json_contents = R"(
|
||||
[
|
||||
{
|
||||
"precision": "zip",
|
||||
@@ -500,7 +496,7 @@ TEST_CASE("nst's JSONTestSuite")
|
||||
{
|
||||
SECTION("y")
|
||||
{
|
||||
for (auto filename :
|
||||
for (const auto* filename :
|
||||
{
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_array_arraysWithSpaces.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_array_empty-string.json",
|
||||
@@ -610,7 +606,7 @@ TEST_CASE("nst's JSONTestSuite")
|
||||
|
||||
SECTION("n")
|
||||
{
|
||||
for (auto filename :
|
||||
for (const auto* filename :
|
||||
{
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_array_1_true_without_comma.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_array_a_invalid_utf8.json",
|
||||
@@ -822,7 +818,7 @@ TEST_CASE("nst's JSONTestSuite")
|
||||
// these tests fail above, because the parser does not end on EOF;
|
||||
// they succeed when the operator>> is used, because it does not
|
||||
// have this constraint
|
||||
for (auto filename :
|
||||
for (const auto* filename :
|
||||
{
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_array_comma_after_close.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_array_extra_close.json",
|
||||
@@ -852,7 +848,7 @@ TEST_CASE("nst's JSONTestSuite")
|
||||
|
||||
SECTION("i -> y")
|
||||
{
|
||||
for (auto filename :
|
||||
for (const auto* filename :
|
||||
{
|
||||
// we do not pose a limit on nesting
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/i_structure_500_nested_arrays.json",
|
||||
@@ -876,7 +872,7 @@ TEST_CASE("nst's JSONTestSuite")
|
||||
// numbers that overflow during parsing
|
||||
SECTION("i/y -> n (out of range)")
|
||||
{
|
||||
for (auto filename :
|
||||
for (const auto* filename :
|
||||
{
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/i_number_neg_int_huge_exp.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/i_number_pos_double_huge_exp.json",
|
||||
@@ -895,7 +891,7 @@ TEST_CASE("nst's JSONTestSuite")
|
||||
|
||||
SECTION("i -> n")
|
||||
{
|
||||
for (auto filename :
|
||||
for (const auto* filename :
|
||||
{
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/i_object_key_lone_2nd_surrogate.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/i_string_1st_surrogate_but_2nd_missing.json",
|
||||
@@ -928,7 +924,7 @@ TEST_CASE("nst's JSONTestSuite (2)")
|
||||
{
|
||||
SECTION("y")
|
||||
{
|
||||
for (auto filename :
|
||||
for (const auto* filename :
|
||||
{
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_array_arraysWithSpaces.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_array_empty-string.json",
|
||||
@@ -1039,7 +1035,7 @@ TEST_CASE("nst's JSONTestSuite (2)")
|
||||
|
||||
SECTION("n")
|
||||
{
|
||||
for (auto filename :
|
||||
for (const auto* filename :
|
||||
{
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_array_1_true_without_comma.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_array_a_invalid_utf8.json",
|
||||
@@ -1241,7 +1237,7 @@ TEST_CASE("nst's JSONTestSuite (2)")
|
||||
|
||||
SECTION("n (previously overflowed)")
|
||||
{
|
||||
for (auto filename :
|
||||
for (const auto* filename :
|
||||
{
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_100000_opening_arrays.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_open_array_object.json"
|
||||
@@ -1256,7 +1252,7 @@ TEST_CASE("nst's JSONTestSuite (2)")
|
||||
|
||||
SECTION("i -> y")
|
||||
{
|
||||
for (auto filename :
|
||||
for (const auto* filename :
|
||||
{
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_number_double_huge_neg_exp.json",
|
||||
//TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_number_huge_exp.json",
|
||||
@@ -1307,7 +1303,7 @@ TEST_CASE("nst's JSONTestSuite (2)")
|
||||
|
||||
SECTION("i -> n")
|
||||
{
|
||||
for (auto filename :
|
||||
for (const auto* filename :
|
||||
{
|
||||
//TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_number_double_huge_neg_exp.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_number_huge_exp.json",
|
||||
@@ -1373,7 +1369,7 @@ std::string trim(const std::string& str)
|
||||
size_t last = str.find_last_not_of(' ');
|
||||
return str.substr(first, (last - first + 1));
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
TEST_CASE("Big List of Naughty Strings")
|
||||
{
|
||||
@@ -1399,7 +1395,7 @@ TEST_CASE("Big List of Naughty Strings")
|
||||
line = trim(line);
|
||||
|
||||
// remove trailing comma
|
||||
line = line.substr(0, line.find_last_of(","));
|
||||
line = line.substr(0, line.find_last_of(','));
|
||||
|
||||
// discard lines without at least two characters (quotes)
|
||||
if (line.size() < 2)
|
||||
|
||||
@@ -38,7 +38,7 @@ using nlohmann::detail::dtoa_impl::reinterpret_bits;
|
||||
|
||||
namespace
|
||||
{
|
||||
static float make_float(uint32_t sign_bit, uint32_t biased_exponent, uint32_t significand)
|
||||
float make_float(uint32_t sign_bit, uint32_t biased_exponent, uint32_t significand)
|
||||
{
|
||||
assert(sign_bit == 0 || sign_bit == 1);
|
||||
assert(biased_exponent <= 0xFF);
|
||||
@@ -54,7 +54,7 @@ static float make_float(uint32_t sign_bit, uint32_t biased_exponent, uint32_t si
|
||||
}
|
||||
|
||||
// ldexp -- convert f * 2^e to IEEE single precision
|
||||
static float make_float(uint64_t f, int e)
|
||||
float make_float(uint64_t f, int e)
|
||||
{
|
||||
constexpr uint64_t kHiddenBit = 0x00800000;
|
||||
constexpr uint64_t kSignificandMask = 0x007FFFFF;
|
||||
@@ -90,7 +90,7 @@ static float make_float(uint64_t f, int e)
|
||||
return reinterpret_bits<float>(static_cast<uint32_t>(bits));
|
||||
}
|
||||
|
||||
static double make_double(uint64_t sign_bit, uint64_t biased_exponent, uint64_t significand)
|
||||
double make_double(uint64_t sign_bit, uint64_t biased_exponent, uint64_t significand)
|
||||
{
|
||||
assert(sign_bit == 0 || sign_bit == 1);
|
||||
assert(biased_exponent <= 0x7FF);
|
||||
@@ -106,7 +106,7 @@ static double make_double(uint64_t sign_bit, uint64_t biased_exponent, uint64_t
|
||||
}
|
||||
|
||||
// ldexp -- convert f * 2^e to IEEE double precision
|
||||
static double make_double(uint64_t f, int e)
|
||||
double make_double(uint64_t f, int e)
|
||||
{
|
||||
constexpr uint64_t kHiddenBit = 0x0010000000000000;
|
||||
constexpr uint64_t kSignificandMask = 0x000FFFFFFFFFFFFF;
|
||||
@@ -141,7 +141,7 @@ static double make_double(uint64_t f, int e)
|
||||
uint64_t bits = (f & kSignificandMask) | (biased_exponent << kPhysicalSignificandSize);
|
||||
return reinterpret_bits<double>(bits);
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
TEST_CASE("digit gen")
|
||||
{
|
||||
@@ -153,12 +153,12 @@ TEST_CASE("digit gen")
|
||||
CAPTURE(digits)
|
||||
CAPTURE(expected_exponent)
|
||||
|
||||
char buf[32];
|
||||
std::array<char, 32> buf{};
|
||||
int len = 0;
|
||||
int exponent = 0;
|
||||
nlohmann::detail::dtoa_impl::grisu2(buf, len, exponent, number);
|
||||
nlohmann::detail::dtoa_impl::grisu2(buf.data(), len, exponent, number);
|
||||
|
||||
CHECK(digits == std::string(buf, buf + len));
|
||||
CHECK(digits == std::string(buf.data(), buf.data() + len));
|
||||
CHECK(expected_exponent == exponent);
|
||||
};
|
||||
|
||||
@@ -217,12 +217,12 @@ TEST_CASE("digit gen")
|
||||
CAPTURE(digits)
|
||||
CAPTURE(expected_exponent)
|
||||
|
||||
char buf[32];
|
||||
std::array<char, 32> buf{};
|
||||
int len = 0;
|
||||
int exponent = 0;
|
||||
nlohmann::detail::dtoa_impl::grisu2(buf, len, exponent, number);
|
||||
nlohmann::detail::dtoa_impl::grisu2(buf.data(), len, exponent, number);
|
||||
|
||||
CHECK(digits == std::string(buf, buf + len));
|
||||
CHECK(digits == std::string(buf.data(), buf.data() + len));
|
||||
CHECK(expected_exponent == exponent);
|
||||
};
|
||||
|
||||
@@ -360,7 +360,7 @@ TEST_CASE("formatting")
|
||||
auto check_float = [](float number, const std::string & expected)
|
||||
{
|
||||
std::array<char, 33> buf{};
|
||||
char* end = nlohmann::detail::to_chars(buf.data(), buf.data() + 32, number);
|
||||
char* end = nlohmann::detail::to_chars(buf.data(), buf.data() + 32, number); // NOLINT(cppcoreguidelines-pro-type-vararg,hicpp-vararg)
|
||||
std::string actual(buf.data(), end);
|
||||
|
||||
CHECK(actual == expected);
|
||||
@@ -420,7 +420,7 @@ TEST_CASE("formatting")
|
||||
auto check_double = [](double number, const std::string & expected)
|
||||
{
|
||||
std::array<char, 33> buf{};
|
||||
char* end = nlohmann::detail::to_chars(buf.data(), buf.data() + 32, number);
|
||||
char* end = nlohmann::detail::to_chars(buf.data(), buf.data() + 32, number); // NOLINT(cppcoreguidelines-pro-type-vararg,hicpp-vararg)
|
||||
std::string actual(buf.data(), end);
|
||||
|
||||
CHECK(actual == expected);
|
||||
|
||||
@@ -51,42 +51,42 @@ class SaxCountdown
|
||||
return events_left-- > 0;
|
||||
}
|
||||
|
||||
bool boolean(bool)
|
||||
bool boolean(bool /*unused*/)
|
||||
{
|
||||
return events_left-- > 0;
|
||||
}
|
||||
|
||||
bool number_integer(json::number_integer_t)
|
||||
bool number_integer(json::number_integer_t /*unused*/)
|
||||
{
|
||||
return events_left-- > 0;
|
||||
}
|
||||
|
||||
bool number_unsigned(json::number_unsigned_t)
|
||||
bool number_unsigned(json::number_unsigned_t /*unused*/)
|
||||
{
|
||||
return events_left-- > 0;
|
||||
}
|
||||
|
||||
bool number_float(json::number_float_t, const std::string&)
|
||||
bool number_float(json::number_float_t /*unused*/, const std::string& /*unused*/)
|
||||
{
|
||||
return events_left-- > 0;
|
||||
}
|
||||
|
||||
bool string(std::string&)
|
||||
bool string(std::string& /*unused*/)
|
||||
{
|
||||
return events_left-- > 0;
|
||||
}
|
||||
|
||||
bool binary(std::vector<std::uint8_t>&)
|
||||
bool binary(std::vector<std::uint8_t>& /*unused*/)
|
||||
{
|
||||
return events_left-- > 0;
|
||||
}
|
||||
|
||||
bool start_object(std::size_t)
|
||||
bool start_object(std::size_t /*unused*/)
|
||||
{
|
||||
return events_left-- > 0;
|
||||
}
|
||||
|
||||
bool key(std::string&)
|
||||
bool key(std::string& /*unused*/)
|
||||
{
|
||||
return events_left-- > 0;
|
||||
}
|
||||
@@ -96,7 +96,7 @@ class SaxCountdown
|
||||
return events_left-- > 0;
|
||||
}
|
||||
|
||||
bool start_array(std::size_t)
|
||||
bool start_array(std::size_t /*unused*/)
|
||||
{
|
||||
return events_left-- > 0;
|
||||
}
|
||||
@@ -106,7 +106,7 @@ class SaxCountdown
|
||||
return events_left-- > 0;
|
||||
}
|
||||
|
||||
bool parse_error(std::size_t, const std::string&, const json::exception&)
|
||||
bool parse_error(std::size_t /*unused*/, const std::string& /*unused*/, const json::exception& /*unused*/) // NOLINT(readability-convert-member-functions-to-static)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -114,7 +114,7 @@ class SaxCountdown
|
||||
private:
|
||||
int events_left = 0;
|
||||
};
|
||||
}
|
||||
} // namespace
|
||||
|
||||
TEST_CASE("UBJSON")
|
||||
{
|
||||
@@ -175,16 +175,16 @@ TEST_CASE("UBJSON")
|
||||
{
|
||||
std::vector<int64_t> numbers;
|
||||
numbers.push_back((std::numeric_limits<int64_t>::min)());
|
||||
numbers.push_back(-1000000000000000000ll);
|
||||
numbers.push_back(-100000000000000000ll);
|
||||
numbers.push_back(-10000000000000000ll);
|
||||
numbers.push_back(-1000000000000000ll);
|
||||
numbers.push_back(-100000000000000ll);
|
||||
numbers.push_back(-10000000000000ll);
|
||||
numbers.push_back(-1000000000000ll);
|
||||
numbers.push_back(-100000000000ll);
|
||||
numbers.push_back(-10000000000ll);
|
||||
numbers.push_back(-2147483649ll);
|
||||
numbers.push_back(-1000000000000000000LL);
|
||||
numbers.push_back(-100000000000000000LL);
|
||||
numbers.push_back(-10000000000000000LL);
|
||||
numbers.push_back(-1000000000000000LL);
|
||||
numbers.push_back(-100000000000000LL);
|
||||
numbers.push_back(-10000000000000LL);
|
||||
numbers.push_back(-1000000000000LL);
|
||||
numbers.push_back(-100000000000LL);
|
||||
numbers.push_back(-10000000000LL);
|
||||
numbers.push_back(-2147483649LL);
|
||||
for (auto i : numbers)
|
||||
{
|
||||
CAPTURE(i)
|
||||
@@ -302,7 +302,7 @@ TEST_CASE("UBJSON")
|
||||
|
||||
// check individual bytes
|
||||
CHECK(result[0] == 'I');
|
||||
int16_t restored = static_cast<int16_t>(((result[1] << 8) + result[2]));
|
||||
auto restored = static_cast<int16_t>(((result[1] << 8) + result[2]));
|
||||
CHECK(restored == i);
|
||||
|
||||
// roundtrip
|
||||
@@ -323,7 +323,7 @@ TEST_CASE("UBJSON")
|
||||
|
||||
// check individual bytes
|
||||
CHECK(result[0] == 'I');
|
||||
int16_t restored = static_cast<int16_t>(((result[1] << 8) + result[2]));
|
||||
auto restored = static_cast<int16_t>(((result[1] << 8) + result[2]));
|
||||
CHECK(restored == -9263);
|
||||
|
||||
// roundtrip
|
||||
@@ -455,7 +455,7 @@ TEST_CASE("UBJSON")
|
||||
|
||||
// check individual bytes
|
||||
CHECK(result[0] == 'I');
|
||||
uint16_t restored = static_cast<uint16_t>(static_cast<uint8_t>(result[1]) * 256 + static_cast<uint8_t>(result[2]));
|
||||
auto restored = static_cast<uint16_t>(static_cast<uint8_t>(result[1]) * 256 + static_cast<uint8_t>(result[2]));
|
||||
CHECK(restored == i);
|
||||
|
||||
// roundtrip
|
||||
@@ -583,7 +583,7 @@ TEST_CASE("UBJSON")
|
||||
|
||||
// check individual bytes
|
||||
CHECK(result[0] == 'i');
|
||||
uint8_t restored = static_cast<uint8_t>(result[1]);
|
||||
auto restored = static_cast<uint8_t>(result[1]);
|
||||
CHECK(restored == i);
|
||||
|
||||
// roundtrip
|
||||
@@ -616,7 +616,7 @@ TEST_CASE("UBJSON")
|
||||
|
||||
// check individual bytes
|
||||
CHECK(result[0] == 'U');
|
||||
uint8_t restored = static_cast<uint8_t>(result[1]);
|
||||
auto restored = static_cast<uint8_t>(result[1]);
|
||||
CHECK(restored == i);
|
||||
|
||||
// roundtrip
|
||||
@@ -650,7 +650,7 @@ TEST_CASE("UBJSON")
|
||||
|
||||
// check individual bytes
|
||||
CHECK(result[0] == 'I');
|
||||
uint16_t restored = static_cast<uint16_t>(static_cast<uint8_t>(result[1]) * 256 + static_cast<uint8_t>(result[2]));
|
||||
auto restored = static_cast<uint16_t>(static_cast<uint8_t>(result[1]) * 256 + static_cast<uint8_t>(result[2]));
|
||||
CHECK(restored == i);
|
||||
|
||||
// roundtrip
|
||||
@@ -1535,7 +1535,7 @@ TEST_CASE("UBJSON")
|
||||
{
|
||||
SECTION("size=false type=false")
|
||||
{
|
||||
json j = json::parse("{\"a\": {\"b\": {\"c\": {}}}}");
|
||||
json j = json::parse(R"({"a": {"b": {"c": {}}}})");
|
||||
std::vector<uint8_t> expected =
|
||||
{
|
||||
'{', 'i', 1, 'a', '{', 'i', 1, 'b', '{', 'i', 1, 'c', '{', '}', '}', '}', '}'
|
||||
@@ -1550,7 +1550,7 @@ TEST_CASE("UBJSON")
|
||||
|
||||
SECTION("size=true type=false")
|
||||
{
|
||||
json j = json::parse("{\"a\": {\"b\": {\"c\": {}}}}");
|
||||
json j = json::parse(R"({"a": {"b": {"c": {}}}})");
|
||||
std::vector<uint8_t> expected =
|
||||
{
|
||||
'{', '#', 'i', 1, 'i', 1, 'a', '{', '#', 'i', 1, 'i', 1, 'b', '{', '#', 'i', 1, 'i', 1, 'c', '{', '#', 'i', 0
|
||||
@@ -1565,7 +1565,7 @@ TEST_CASE("UBJSON")
|
||||
|
||||
SECTION("size=true type=true")
|
||||
{
|
||||
json j = json::parse("{\"a\": {\"b\": {\"c\": {}}}}");
|
||||
json j = json::parse(R"({"a": {"b": {"c": {}}}})");
|
||||
std::vector<uint8_t> expected =
|
||||
{
|
||||
'{', '$', '{', '#', 'i', 1, 'i', 1, 'a', '$', '{', '#', 'i', 1, 'i', 1, 'b', '$', '{', '#', 'i', 1, 'i', 1, 'c', '#', 'i', 0
|
||||
@@ -1610,7 +1610,7 @@ TEST_CASE("UBJSON")
|
||||
CHECK_THROWS_AS(_ = json::from_ubjson(v_ubjson), json::out_of_range&);
|
||||
|
||||
json j;
|
||||
nlohmann::detail::json_sax_dom_callback_parser<json> scp(j, [](int, json::parse_event_t, const json&)
|
||||
nlohmann::detail::json_sax_dom_callback_parser<json> scp(j, [](int /*unused*/, json::parse_event_t /*unused*/, const json& /*unused*/)
|
||||
{
|
||||
return true;
|
||||
});
|
||||
@@ -1624,7 +1624,7 @@ TEST_CASE("UBJSON")
|
||||
CHECK_THROWS_AS(_ = json::from_ubjson(v_ubjson), json::out_of_range&);
|
||||
|
||||
json j;
|
||||
nlohmann::detail::json_sax_dom_callback_parser<json> scp(j, [](int, json::parse_event_t, const json&)
|
||||
nlohmann::detail::json_sax_dom_callback_parser<json> scp(j, [](int /*unused*/, json::parse_event_t /*unused*/, const json& /*unused*/)
|
||||
{
|
||||
return true;
|
||||
});
|
||||
@@ -2439,7 +2439,7 @@ TEST_CASE("all UBJSON first bytes")
|
||||
// check that parse_error.112 is only thrown if the
|
||||
// first byte is not in the supported set
|
||||
INFO_WITH_TEMP(e.what());
|
||||
if (std::find(supported.begin(), supported.end(), byte) == supported.end())
|
||||
if (supported.find(byte) == supported.end())
|
||||
{
|
||||
CHECK(e.id == 112);
|
||||
}
|
||||
|
||||
@@ -32,10 +32,11 @@ SOFTWARE.
|
||||
#include <nlohmann/json.hpp>
|
||||
using nlohmann::json;
|
||||
|
||||
#include <array>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
|
||||
namespace udt
|
||||
{
|
||||
@@ -55,40 +56,40 @@ struct age
|
||||
struct name
|
||||
{
|
||||
std::string m_val;
|
||||
name(const std::string rhs = "") : m_val(rhs) {}
|
||||
name(std::string rhs = "") : m_val(std::move(rhs)) {}
|
||||
};
|
||||
|
||||
struct address
|
||||
{
|
||||
std::string m_val;
|
||||
address(const std::string rhs = "") : m_val(rhs) {}
|
||||
address(std::string rhs = "") : m_val(std::move(rhs)) {}
|
||||
};
|
||||
|
||||
struct person
|
||||
{
|
||||
age m_age;
|
||||
name m_name;
|
||||
country m_country;
|
||||
person() : m_age(), m_name(), m_country() {}
|
||||
person(const age& a, const name& n, const country& c) : m_age(a), m_name(n), m_country(c) {}
|
||||
age m_age{};
|
||||
name m_name{};
|
||||
country m_country{};
|
||||
person() = default;
|
||||
person(const age& a, name n, const country& c) : m_age(a), m_name(std::move(n)), m_country(c) {}
|
||||
};
|
||||
|
||||
struct contact
|
||||
{
|
||||
person m_person;
|
||||
address m_address;
|
||||
contact() : m_person(), m_address() {}
|
||||
contact(const person& p, const address& a) : m_person(p), m_address(a) {}
|
||||
person m_person{};
|
||||
address m_address{};
|
||||
contact() = default;
|
||||
contact(person p, address a) : m_person(std::move(p)), m_address(std::move(a)) {}
|
||||
};
|
||||
|
||||
struct contact_book
|
||||
{
|
||||
name m_book_name;
|
||||
std::vector<contact> m_contacts;
|
||||
contact_book() : m_book_name(), m_contacts() {}
|
||||
contact_book(const name& n, const std::vector<contact>& c) : m_book_name(n), m_contacts(c) {}
|
||||
name m_book_name{};
|
||||
std::vector<contact> m_contacts{};
|
||||
contact_book() = default;
|
||||
contact_book(name n, std::vector<contact> c) : m_book_name(std::move(n)), m_contacts(std::move(c)) {}
|
||||
};
|
||||
}
|
||||
} // namespace udt
|
||||
|
||||
// to_json methods
|
||||
namespace udt
|
||||
@@ -178,7 +179,7 @@ static bool operator==(const contact_book& lhs, const contact_book& rhs)
|
||||
return std::tie(lhs.m_book_name, lhs.m_contacts) ==
|
||||
std::tie(rhs.m_book_name, rhs.m_contacts);
|
||||
}
|
||||
}
|
||||
} // namespace udt
|
||||
|
||||
// from_json methods
|
||||
namespace udt
|
||||
@@ -199,7 +200,7 @@ template <typename BasicJsonType>
|
||||
static void from_json(const BasicJsonType& j, country& c)
|
||||
{
|
||||
const auto str = j.template get<std::string>();
|
||||
static const std::map<std::string, country> m =
|
||||
const std::map<std::string, country> m =
|
||||
{
|
||||
{"中华人民共和国", country::china},
|
||||
{"France", country::france},
|
||||
@@ -207,7 +208,7 @@ static void from_json(const BasicJsonType& j, country& c)
|
||||
};
|
||||
|
||||
const auto it = m.find(str);
|
||||
// TODO test exceptions
|
||||
// TODO(nlohmann) test exceptions
|
||||
c = it->second;
|
||||
}
|
||||
|
||||
@@ -235,7 +236,7 @@ static void from_json(const nlohmann::json& j, contact_book& cb)
|
||||
cb.m_book_name = j["name"].get<name>();
|
||||
cb.m_contacts = j["contacts"].get<std::vector<contact>>();
|
||||
}
|
||||
}
|
||||
} // namespace udt
|
||||
|
||||
TEST_CASE("basic usage" * doctest::test_suite("udt"))
|
||||
{
|
||||
@@ -344,11 +345,11 @@ namespace udt
|
||||
{
|
||||
struct legacy_type
|
||||
{
|
||||
std::string number;
|
||||
legacy_type() : number() {}
|
||||
legacy_type(const std::string& n) : number(n) {}
|
||||
std::string number{};
|
||||
legacy_type() = default;
|
||||
legacy_type(std::string n) : number(std::move(n)) {}
|
||||
};
|
||||
}
|
||||
} // namespace udt
|
||||
|
||||
namespace nlohmann
|
||||
{
|
||||
@@ -375,7 +376,7 @@ struct adl_serializer<std::shared_ptr<T>>
|
||||
}
|
||||
else
|
||||
{
|
||||
opt.reset(new T(j.get<T>()));
|
||||
opt.reset(new T(j.get<T>())); // NOLINT(cppcoreguidelines-owning-memory)
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -393,7 +394,7 @@ struct adl_serializer<udt::legacy_type>
|
||||
l.number = std::to_string(j.get<int>());
|
||||
}
|
||||
};
|
||||
}
|
||||
} // namespace nlohmann
|
||||
|
||||
TEST_CASE("adl_serializer specialization" * doctest::test_suite("udt"))
|
||||
{
|
||||
@@ -406,7 +407,7 @@ TEST_CASE("adl_serializer specialization" * doctest::test_suite("udt"))
|
||||
json j = optPerson;
|
||||
CHECK(j.is_null());
|
||||
|
||||
optPerson.reset(new udt::person{{42}, {"John Doe"}, udt::country::russia});
|
||||
optPerson.reset(new udt::person{{42}, {"John Doe"}, udt::country::russia}); // NOLINT(cppcoreguidelines-owning-memory,modernize-make-shared)
|
||||
j = optPerson;
|
||||
CHECK_FALSE(j.is_null());
|
||||
|
||||
@@ -453,23 +454,23 @@ template <>
|
||||
struct adl_serializer<std::vector<float>>
|
||||
{
|
||||
using type = std::vector<float>;
|
||||
static void to_json(json& j, const type&)
|
||||
static void to_json(json& j, const type& /*type*/)
|
||||
{
|
||||
j = "hijacked!";
|
||||
}
|
||||
|
||||
static void from_json(const json&, type& opt)
|
||||
static void from_json(const json& /*unnamed*/, type& opt)
|
||||
{
|
||||
opt = {42.0, 42.0, 42.0};
|
||||
}
|
||||
|
||||
// preferred version
|
||||
static type from_json(const json&)
|
||||
static type from_json(const json& /*unnamed*/)
|
||||
{
|
||||
return {4.0, 5.0, 6.0};
|
||||
}
|
||||
};
|
||||
}
|
||||
} // namespace nlohmann
|
||||
|
||||
TEST_CASE("even supported types can be specialized" * doctest::test_suite("udt"))
|
||||
{
|
||||
@@ -504,13 +505,11 @@ struct adl_serializer<std::unique_ptr<T>>
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
else
|
||||
{
|
||||
return std::unique_ptr<T>(new T(j.get<T>()));
|
||||
}
|
||||
|
||||
return std::unique_ptr<T>(new T(j.get<T>()));
|
||||
}
|
||||
};
|
||||
}
|
||||
} // namespace nlohmann
|
||||
|
||||
TEST_CASE("Non-copyable types" * doctest::test_suite("udt"))
|
||||
{
|
||||
@@ -521,7 +520,7 @@ TEST_CASE("Non-copyable types" * doctest::test_suite("udt"))
|
||||
json j = optPerson;
|
||||
CHECK(j.is_null());
|
||||
|
||||
optPerson.reset(new udt::person{{42}, {"John Doe"}, udt::country::russia});
|
||||
optPerson.reset(new udt::person{{42}, {"John Doe"}, udt::country::russia}); // NOLINT(cppcoreguidelines-owning-memory,modernize-make-unique)
|
||||
j = optPerson;
|
||||
CHECK_FALSE(j.is_null());
|
||||
|
||||
@@ -566,8 +565,8 @@ struct pod_serializer
|
||||
std::is_pod<U>::value && std::is_class<U>::value, int >::type = 0 >
|
||||
static void from_json(const BasicJsonType& j, U& t)
|
||||
{
|
||||
std::uint64_t value;
|
||||
// TODO The following block is no longer relevant in this serializer, make another one that shows the issue
|
||||
std::uint64_t value = 0;
|
||||
// The following block is no longer relevant in this serializer, make another one that shows the issue
|
||||
// the problem arises only when one from_json method is defined without any constraint
|
||||
//
|
||||
// Why cannot we simply use: j.get<std::uint64_t>() ?
|
||||
@@ -582,7 +581,7 @@ struct pod_serializer
|
||||
// calling get calls from_json, for now, we cannot do this in custom
|
||||
// serializers
|
||||
nlohmann::from_json(j, value);
|
||||
auto bytes = static_cast<char*>(static_cast<void*>(&value));
|
||||
auto* bytes = static_cast<char*>(static_cast<void*>(&value));
|
||||
std::memcpy(&t, bytes, sizeof(value));
|
||||
}
|
||||
|
||||
@@ -601,8 +600,8 @@ struct pod_serializer
|
||||
std::is_pod<U>::value && std::is_class<U>::value, int >::type = 0 >
|
||||
static void to_json(BasicJsonType& j, const T& t) noexcept
|
||||
{
|
||||
auto bytes = static_cast< const unsigned char*>(static_cast<const void*>(&t));
|
||||
std::uint64_t value;
|
||||
const auto* bytes = static_cast< const unsigned char*>(static_cast<const void*>(&t));
|
||||
std::uint64_t value = 0;
|
||||
std::memcpy(&value, bytes, sizeof(value));
|
||||
nlohmann::to_json(j, value);
|
||||
}
|
||||
@@ -619,9 +618,9 @@ struct small_pod
|
||||
|
||||
struct non_pod
|
||||
{
|
||||
std::string s;
|
||||
non_pod() : s() {}
|
||||
non_pod(const std::string& S) : s(S) {}
|
||||
std::string s{};
|
||||
non_pod() = default;
|
||||
non_pod(std::string S) : s(std::move(S)) {}
|
||||
};
|
||||
|
||||
template <typename BasicJsonType>
|
||||
@@ -651,7 +650,7 @@ static std::ostream& operator<<(std::ostream& os, small_pod l)
|
||||
{
|
||||
return os << "begin: " << l.begin << ", middle: " << l.middle << ", end: " << l.end;
|
||||
}
|
||||
}
|
||||
} // namespace udt
|
||||
|
||||
TEST_CASE("custom serializer for pods" * doctest::test_suite("udt"))
|
||||
{
|
||||
@@ -803,7 +802,7 @@ struct is_constructible_patched : std::false_type {};
|
||||
|
||||
template <typename T>
|
||||
struct is_constructible_patched<T, decltype(void(json(std::declval<T>())))> : std::true_type {};
|
||||
}
|
||||
} // namespace
|
||||
|
||||
TEST_CASE("an incomplete type does not trigger a compiler error in non-evaluated context" * doctest::test_suite("udt"))
|
||||
{
|
||||
@@ -822,8 +821,8 @@ class Evil
|
||||
int m_i = 0;
|
||||
};
|
||||
|
||||
void from_json(const json&, Evil&) {}
|
||||
}
|
||||
void from_json(const json& /*unused*/, Evil& /*unused*/) {}
|
||||
} // namespace
|
||||
|
||||
TEST_CASE("Issue #924")
|
||||
{
|
||||
|
||||
@@ -39,7 +39,7 @@ namespace persons
|
||||
class person_with_private_data
|
||||
{
|
||||
private:
|
||||
std::string name = "";
|
||||
std::string name{};
|
||||
int age = 0;
|
||||
json metadata = nullptr;
|
||||
|
||||
@@ -62,7 +62,7 @@ class person_with_private_data
|
||||
class person_without_private_data_1
|
||||
{
|
||||
public:
|
||||
std::string name = "";
|
||||
std::string name{};
|
||||
int age = 0;
|
||||
json metadata = nullptr;
|
||||
|
||||
@@ -84,7 +84,7 @@ class person_without_private_data_1
|
||||
class person_without_private_data_2
|
||||
{
|
||||
public:
|
||||
std::string name = "";
|
||||
std::string name{};
|
||||
int age = 0;
|
||||
json metadata = nullptr;
|
||||
|
||||
|
||||
@@ -168,7 +168,7 @@ void check_utf8string(bool success_expected, int byte1, int byte2 = -1, int byte
|
||||
CHECK_THROWS_AS(_ = json::parse(json_string), json::parse_error&);
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
TEST_CASE("Unicode" * doctest::skip())
|
||||
{
|
||||
@@ -1159,7 +1159,7 @@ TEST_CASE("Unicode" * doctest::skip())
|
||||
|
||||
SECTION("check JSON Pointers")
|
||||
{
|
||||
for (auto s : j)
|
||||
for (const auto& s : j)
|
||||
{
|
||||
// skip non-string JSON values
|
||||
if (!s.is_string())
|
||||
@@ -1176,13 +1176,13 @@ TEST_CASE("Unicode" * doctest::skip())
|
||||
}
|
||||
|
||||
// JSON Pointers must begin with "/"
|
||||
ptr = "/" + ptr;
|
||||
ptr.insert(0, "/");
|
||||
|
||||
CHECK_NOTHROW(json::json_pointer("/" + ptr));
|
||||
|
||||
// check escape/unescape roundtrip
|
||||
auto escaped = json::json_pointer::escape(ptr);
|
||||
json::json_pointer::unescape(escaped);
|
||||
auto escaped = nlohmann::detail::escape(ptr);
|
||||
nlohmann::detail::unescape(escaped);
|
||||
CHECK(escaped == ptr);
|
||||
}
|
||||
}
|
||||
@@ -1256,7 +1256,7 @@ void roundtrip(bool success_expected, const std::string& s)
|
||||
CHECK_THROWS_AS(_ = json::parse(ps), json::parse_error&);
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
TEST_CASE("Markus Kuhn's UTF-8 decoder capability and stress test")
|
||||
{
|
||||
|
||||
@@ -60,7 +60,7 @@ const char* begin(const MyContainer& c)
|
||||
|
||||
const char* end(const MyContainer& c)
|
||||
{
|
||||
return c.data + strlen(c.data);
|
||||
return c.data + strlen(c.data); // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic)
|
||||
}
|
||||
|
||||
TEST_CASE("Custom container non-member begin/end")
|
||||
@@ -88,7 +88,7 @@ TEST_CASE("Custom container member begin/end")
|
||||
|
||||
const char* end() const
|
||||
{
|
||||
return data + strlen(data);
|
||||
return data + strlen(data); // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic)
|
||||
}
|
||||
};
|
||||
|
||||
@@ -114,7 +114,7 @@ TEST_CASE("Custom iterator")
|
||||
|
||||
MyIterator& operator++()
|
||||
{
|
||||
++ptr;
|
||||
++ptr; // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic)
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -131,8 +131,15 @@ TEST_CASE("Custom iterator")
|
||||
const char* ptr;
|
||||
};
|
||||
|
||||
// avoid -Wunused-local-typedefs
|
||||
CHECK(std::is_same<MyIterator::difference_type, std::size_t>::value);
|
||||
CHECK(std::is_same<MyIterator::value_type, char>::value);
|
||||
CHECK(std::is_same<MyIterator::pointer, const char*>::value);
|
||||
CHECK(std::is_same<MyIterator::reference, const char&>::value);
|
||||
CHECK(std::is_same<MyIterator::iterator_category, std::input_iterator_tag>::value);
|
||||
|
||||
MyIterator begin{raw_data};
|
||||
MyIterator end{raw_data + strlen(raw_data)};
|
||||
MyIterator end{raw_data + strlen(raw_data)}; // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic)
|
||||
|
||||
json as_json = json::parse(begin, end);
|
||||
CHECK(as_json.at(0) == 1);
|
||||
|
||||
@@ -51,7 +51,7 @@ bool u32string_is_utf32()
|
||||
{
|
||||
return (std::u32string(U"💩") == std::u32string(U"\U0001F4A9"));
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
TEST_CASE("wide strings")
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user