mirror of
https://github.com/nlohmann/json.git
synced 2026-05-02 04:32:29 +00:00
🎨 use Clang-Format
This commit is contained in:
@@ -12,7 +12,9 @@
|
||||
|
||||
// define custom namespace
|
||||
#define NLOHMANN_JSON_NAMESPACE nlohmann // this line may be omitted
|
||||
#define NLOHMANN_JSON_NAMESPACE_BEGIN namespace nlohmann {
|
||||
#define NLOHMANN_JSON_NAMESPACE_BEGIN \
|
||||
namespace nlohmann \
|
||||
{
|
||||
#define NLOHMANN_JSON_NAMESPACE_END }
|
||||
#include <nlohmann/json_fwd.hpp>
|
||||
|
||||
|
||||
@@ -6,12 +6,12 @@
|
||||
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#include <benchmark/benchmark.h>
|
||||
#include <fstream>
|
||||
#include <nlohmann/json.hpp>
|
||||
#include <numeric>
|
||||
#include <test_data.hpp>
|
||||
#include <vector>
|
||||
#include <nlohmann/json.hpp>
|
||||
#include <benchmark/benchmark.h>
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
|
||||
@@ -26,8 +26,8 @@ drivers.
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include <nlohmann/json.hpp>
|
||||
#include <sstream>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
|
||||
@@ -20,8 +20,8 @@ drivers.
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include <nlohmann/json.hpp>
|
||||
#include <sstream>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
|
||||
@@ -20,8 +20,8 @@ drivers.
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include <nlohmann/json.hpp>
|
||||
#include <sstream>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
|
||||
@@ -21,8 +21,8 @@ drivers.
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include <nlohmann/json.hpp>
|
||||
#include <sstream>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
|
||||
@@ -20,8 +20,8 @@ drivers.
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include <nlohmann/json.hpp>
|
||||
#include <sstream>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
|
||||
@@ -26,8 +26,8 @@ drivers.
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include <nlohmann/json.hpp>
|
||||
#include <sstream>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
|
||||
@@ -13,7 +13,8 @@
|
||||
#include <memory> // unique_ptr
|
||||
#include <test_data.hpp>
|
||||
|
||||
namespace utils {
|
||||
namespace utils
|
||||
{
|
||||
|
||||
inline bool check_testsuite_downloaded()
|
||||
{
|
||||
@@ -23,7 +24,10 @@ inline bool check_testsuite_downloaded()
|
||||
|
||||
TEST_CASE("check test suite is downloaded")
|
||||
{
|
||||
REQUIRE_MESSAGE(utils::check_testsuite_downloaded(), "Test data not found in '" TEST_DATA_DIRECTORY "'. Please execute target 'download_test_data' before running this test suite. See <https://github.com/nlohmann/json#execute-unit-tests> for more information.");
|
||||
REQUIRE_MESSAGE(
|
||||
utils::check_testsuite_downloaded(),
|
||||
"Test data not found in '" TEST_DATA_DIRECTORY
|
||||
"'. Please execute target 'download_test_data' before running this test suite. See <https://github.com/nlohmann/json#execute-unit-tests> for more information.");
|
||||
}
|
||||
|
||||
} // namespace utils
|
||||
|
||||
@@ -12,7 +12,8 @@
|
||||
#include <fstream> // ifstream, istreambuf_iterator, ios
|
||||
#include <vector> // vector
|
||||
|
||||
namespace utils {
|
||||
namespace utils
|
||||
{
|
||||
|
||||
inline std::vector<std::uint8_t> read_binary_file(const std::string& filename)
|
||||
{
|
||||
|
||||
@@ -110,10 +110,14 @@ TEST_CASE("BJData")
|
||||
std::vector<uint8_t> const vMX = {'[', '$', 'U', '#', '[', 'M', 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 'U', 0x01, ']'};
|
||||
|
||||
json _;
|
||||
CHECK_THROWS_WITH_AS(_ = json::from_bjdata(vM), "[json.exception.out_of_range.408] syntax error while parsing BJData size: integer value overflow", json::out_of_range&);
|
||||
CHECK_THROWS_WITH_AS(_ = json::from_bjdata(vM),
|
||||
"[json.exception.out_of_range.408] syntax error while parsing BJData size: integer value overflow",
|
||||
json::out_of_range&);
|
||||
CHECK(json::from_bjdata(vM, true, false).is_discarded());
|
||||
|
||||
CHECK_THROWS_WITH_AS(_ = json::from_bjdata(vMX), "[json.exception.out_of_range.408] syntax error while parsing BJData size: integer value overflow", json::out_of_range&);
|
||||
CHECK_THROWS_WITH_AS(_ = json::from_bjdata(vMX),
|
||||
"[json.exception.out_of_range.408] syntax error while parsing BJData size: integer value overflow",
|
||||
json::out_of_range&);
|
||||
CHECK(json::from_bjdata(vMX, true, false).is_discarded());
|
||||
}
|
||||
|
||||
@@ -123,10 +127,14 @@ TEST_CASE("BJData")
|
||||
std::vector<uint8_t> const vM = {'[', '$', 'M', '#', '[', 'I', 0x00, 0x20, 'M', 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0xFF, ']'};
|
||||
|
||||
json _;
|
||||
CHECK_THROWS_WITH_AS(_ = json::from_bjdata(vL), "[json.exception.out_of_range.408] syntax error while parsing BJData size: integer value overflow", json::out_of_range&);
|
||||
CHECK_THROWS_WITH_AS(_ = json::from_bjdata(vL),
|
||||
"[json.exception.out_of_range.408] syntax error while parsing BJData size: integer value overflow",
|
||||
json::out_of_range&);
|
||||
CHECK(json::from_bjdata(vL, true, false).is_discarded());
|
||||
|
||||
CHECK_THROWS_WITH_AS(_ = json::from_bjdata(vM), "[json.exception.out_of_range.408] syntax error while parsing BJData size: integer value overflow", json::out_of_range&);
|
||||
CHECK_THROWS_WITH_AS(_ = json::from_bjdata(vM),
|
||||
"[json.exception.out_of_range.408] syntax error while parsing BJData size: integer value overflow",
|
||||
json::out_of_range&);
|
||||
CHECK(json::from_bjdata(vM, true, false).is_discarded());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -201,7 +201,9 @@ TEST_CASE("algorithms")
|
||||
SECTION("sorting an object")
|
||||
{
|
||||
json j({{"one", 1}, {"two", 2}});
|
||||
CHECK_THROWS_WITH_AS(std::sort(j.begin(), j.end()), "[json.exception.invalid_iterator.209] cannot use offsets with object iterators", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(std::sort(j.begin(), j.end()),
|
||||
"[json.exception.invalid_iterator.209] cannot use offsets with object iterators",
|
||||
json::invalid_iterator&);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,8 @@
|
||||
#include <nlohmann/json.hpp>
|
||||
using nlohmann::json;
|
||||
|
||||
namespace {
|
||||
namespace
|
||||
{
|
||||
// special test case to check if memory is leaked if constructor throws
|
||||
template<class T>
|
||||
struct bad_allocator : std::allocator<T>
|
||||
@@ -43,21 +44,15 @@ TEST_CASE("bad_alloc")
|
||||
SECTION("bad_alloc")
|
||||
{
|
||||
// create JSON type using the throwing allocator
|
||||
using bad_json = nlohmann::basic_json<std::map,
|
||||
std::vector,
|
||||
std::string,
|
||||
bool,
|
||||
std::int64_t,
|
||||
std::uint64_t,
|
||||
double,
|
||||
bad_allocator>;
|
||||
using bad_json = nlohmann::basic_json<std::map, std::vector, std::string, bool, std::int64_t, std::uint64_t, double, bad_allocator>;
|
||||
|
||||
// creating an object should throw
|
||||
CHECK_THROWS_AS(bad_json(bad_json::value_t::object), std::bad_alloc&);
|
||||
}
|
||||
}
|
||||
|
||||
namespace {
|
||||
namespace
|
||||
{
|
||||
bool next_construct_fails = false;
|
||||
bool next_destroy_fails = false;
|
||||
bool next_deallocate_fails = false;
|
||||
@@ -123,14 +118,7 @@ void my_allocator_clean_up(T* p)
|
||||
TEST_CASE("controlled bad_alloc")
|
||||
{
|
||||
// create JSON type using the throwing allocator
|
||||
using my_json = nlohmann::basic_json<std::map,
|
||||
std::vector,
|
||||
std::string,
|
||||
bool,
|
||||
std::int64_t,
|
||||
std::uint64_t,
|
||||
double,
|
||||
my_allocator>;
|
||||
using my_json = nlohmann::basic_json<std::map, std::vector, std::string, bool, std::int64_t, std::uint64_t, double, my_allocator>;
|
||||
|
||||
SECTION("class json_value")
|
||||
{
|
||||
@@ -219,7 +207,8 @@ TEST_CASE("controlled bad_alloc")
|
||||
}
|
||||
}
|
||||
|
||||
namespace {
|
||||
namespace
|
||||
{
|
||||
template<class T>
|
||||
struct allocator_no_forward : std::allocator<T>
|
||||
{
|
||||
@@ -247,14 +236,7 @@ TEST_CASE("bad my_allocator::construct")
|
||||
{
|
||||
SECTION("my_allocator::construct doesn't forward")
|
||||
{
|
||||
using bad_alloc_json = nlohmann::basic_json<std::map,
|
||||
std::vector,
|
||||
std::string,
|
||||
bool,
|
||||
std::int64_t,
|
||||
std::uint64_t,
|
||||
double,
|
||||
allocator_no_forward>;
|
||||
using bad_alloc_json = nlohmann::basic_json<std::map, std::vector, std::string, bool, std::int64_t, std::uint64_t, double, allocator_no_forward>;
|
||||
|
||||
bad_alloc_json j;
|
||||
j["test"] = bad_alloc_json::array_t();
|
||||
|
||||
@@ -174,16 +174,7 @@ void int_to_string(alt_string& target, std::size_t value)
|
||||
target = std::to_string(value).c_str();
|
||||
}
|
||||
|
||||
using alt_json = nlohmann::basic_json<
|
||||
std::map,
|
||||
std::vector,
|
||||
alt_string,
|
||||
bool,
|
||||
std::int64_t,
|
||||
std::uint64_t,
|
||||
double,
|
||||
std::allocator,
|
||||
nlohmann::adl_serializer>;
|
||||
using alt_json = nlohmann::basic_json<std::map, std::vector, alt_string, bool, std::int64_t, std::uint64_t, double, std::allocator, nlohmann::adl_serializer>;
|
||||
|
||||
bool operator<(const char* op1, const alt_string& op2) noexcept
|
||||
{
|
||||
|
||||
@@ -18,10 +18,10 @@ DOCTEST_CLANG_SUPPRESS_WARNING("-Wstrict-overflow")
|
||||
static int assert_counter;
|
||||
|
||||
/// set failure variable to true instead of calling assert(x)
|
||||
#define JSON_ASSERT(x) \
|
||||
{ \
|
||||
if (!(x)) \
|
||||
++assert_counter; \
|
||||
#define JSON_ASSERT(x) \
|
||||
{ \
|
||||
if (!(x)) \
|
||||
++assert_counter; \
|
||||
}
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
+541
-991
File diff suppressed because it is too large
Load Diff
+699
-974
File diff suppressed because it is too large
Load Diff
+525
-558
File diff suppressed because it is too large
Load Diff
@@ -12,7 +12,8 @@
|
||||
#include <nlohmann/json.hpp>
|
||||
using nlohmann::json;
|
||||
|
||||
namespace {
|
||||
namespace
|
||||
{
|
||||
// shortcut to scan a string literal
|
||||
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)
|
||||
|
||||
+484
-269
@@ -17,7 +17,8 @@ using namespace nlohmann::literals; // NOLINT(google-build-using-namespace)
|
||||
|
||||
#include <valarray>
|
||||
|
||||
namespace {
|
||||
namespace
|
||||
{
|
||||
class SaxEventLogger
|
||||
{
|
||||
public:
|
||||
@@ -358,48 +359,156 @@ TEST_CASE("parser class")
|
||||
SECTION("errors")
|
||||
{
|
||||
// error: tab in string
|
||||
CHECK_THROWS_WITH_AS(parser_helper("\"\t\""), "[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing value - invalid string: control character U+0009 (HT) must be escaped to \\u0009 or \\t; last read: '\"<U+0009>'", json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
parser_helper("\"\t\""),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing value - invalid string: control character U+0009 (HT) must be escaped to \\u0009 or \\t; last read: '\"<U+0009>'",
|
||||
json::parse_error&);
|
||||
// error: newline in string
|
||||
CHECK_THROWS_WITH_AS(parser_helper("\"\n\""), "[json.exception.parse_error.101] parse error at line 2, column 0: syntax error while parsing value - invalid string: control character U+000A (LF) must be escaped to \\u000A or \\n; last read: '\"<U+000A>'", json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(parser_helper("\"\r\""), "[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing value - invalid string: control character U+000D (CR) must be escaped to \\u000D or \\r; last read: '\"<U+000D>'", json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
parser_helper("\"\n\""),
|
||||
"[json.exception.parse_error.101] parse error at line 2, column 0: syntax error while parsing value - invalid string: control character U+000A (LF) must be escaped to \\u000A or \\n; last read: '\"<U+000A>'",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
parser_helper("\"\r\""),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing value - invalid string: control character U+000D (CR) must be escaped to \\u000D or \\r; last read: '\"<U+000D>'",
|
||||
json::parse_error&);
|
||||
// error: backspace in string
|
||||
CHECK_THROWS_WITH_AS(parser_helper("\"\b\""), "[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing value - invalid string: control character U+0008 (BS) must be escaped to \\u0008 or \\b; last read: '\"<U+0008>'", json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
parser_helper("\"\b\""),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing value - invalid string: control character U+0008 (BS) must be escaped to \\u0008 or \\b; last read: '\"<U+0008>'",
|
||||
json::parse_error&);
|
||||
// improve code coverage
|
||||
CHECK_THROWS_AS(parser_helper("\uFF01"), json::parse_error&);
|
||||
CHECK_THROWS_AS(parser_helper("[-4:1,]"), json::parse_error&);
|
||||
// unescaped control characters
|
||||
CHECK_THROWS_WITH_AS(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: '\"'", json::parse_error&); // NOLINT(bugprone-string-literal-with-embedded-nul)
|
||||
CHECK_THROWS_WITH_AS(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>'", json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(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>'", json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(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>'", json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(parser_helper("\"\x04\""), "[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing value - invalid string: control character U+0004 (EOT) must be escaped to \\u0004; last read: '\"<U+0004>'", json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(parser_helper("\"\x05\""), "[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing value - invalid string: control character U+0005 (ENQ) must be escaped to \\u0005; last read: '\"<U+0005>'", json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(parser_helper("\"\x06\""), "[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing value - invalid string: control character U+0006 (ACK) must be escaped to \\u0006; last read: '\"<U+0006>'", json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(parser_helper("\"\x07\""), "[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing value - invalid string: control character U+0007 (BEL) must be escaped to \\u0007; last read: '\"<U+0007>'", json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(parser_helper("\"\x08\""), "[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing value - invalid string: control character U+0008 (BS) must be escaped to \\u0008 or \\b; last read: '\"<U+0008>'", json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(parser_helper("\"\x09\""), "[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing value - invalid string: control character U+0009 (HT) must be escaped to \\u0009 or \\t; last read: '\"<U+0009>'", json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(parser_helper("\"\x0a\""), "[json.exception.parse_error.101] parse error at line 2, column 0: syntax error while parsing value - invalid string: control character U+000A (LF) must be escaped to \\u000A or \\n; last read: '\"<U+000A>'", json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(parser_helper("\"\x0b\""), "[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing value - invalid string: control character U+000B (VT) must be escaped to \\u000B; last read: '\"<U+000B>'", json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(parser_helper("\"\x0c\""), "[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing value - invalid string: control character U+000C (FF) must be escaped to \\u000C or \\f; last read: '\"<U+000C>'", json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(parser_helper("\"\x0d\""), "[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing value - invalid string: control character U+000D (CR) must be escaped to \\u000D or \\r; last read: '\"<U+000D>'", json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(parser_helper("\"\x0e\""), "[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing value - invalid string: control character U+000E (SO) must be escaped to \\u000E; last read: '\"<U+000E>'", json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(parser_helper("\"\x0f\""), "[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing value - invalid string: control character U+000F (SI) must be escaped to \\u000F; last read: '\"<U+000F>'", json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(parser_helper("\"\x10\""), "[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing value - invalid string: control character U+0010 (DLE) must be escaped to \\u0010; last read: '\"<U+0010>'", json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(parser_helper("\"\x11\""), "[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing value - invalid string: control character U+0011 (DC1) must be escaped to \\u0011; last read: '\"<U+0011>'", json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(parser_helper("\"\x12\""), "[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing value - invalid string: control character U+0012 (DC2) must be escaped to \\u0012; last read: '\"<U+0012>'", json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(parser_helper("\"\x13\""), "[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing value - invalid string: control character U+0013 (DC3) must be escaped to \\u0013; last read: '\"<U+0013>'", json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(parser_helper("\"\x14\""), "[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing value - invalid string: control character U+0014 (DC4) must be escaped to \\u0014; last read: '\"<U+0014>'", json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(parser_helper("\"\x15\""), "[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing value - invalid string: control character U+0015 (NAK) must be escaped to \\u0015; last read: '\"<U+0015>'", json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(parser_helper("\"\x16\""), "[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing value - invalid string: control character U+0016 (SYN) must be escaped to \\u0016; last read: '\"<U+0016>'", json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(parser_helper("\"\x17\""), "[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing value - invalid string: control character U+0017 (ETB) must be escaped to \\u0017; last read: '\"<U+0017>'", json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(parser_helper("\"\x18\""), "[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing value - invalid string: control character U+0018 (CAN) must be escaped to \\u0018; last read: '\"<U+0018>'", json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(parser_helper("\"\x19\""), "[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing value - invalid string: control character U+0019 (EM) must be escaped to \\u0019; last read: '\"<U+0019>'", json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(parser_helper("\"\x1a\""), "[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing value - invalid string: control character U+001A (SUB) must be escaped to \\u001A; last read: '\"<U+001A>'", json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(parser_helper("\"\x1b\""), "[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing value - invalid string: control character U+001B (ESC) must be escaped to \\u001B; last read: '\"<U+001B>'", json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(parser_helper("\"\x1c\""), "[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing value - invalid string: control character U+001C (FS) must be escaped to \\u001C; last read: '\"<U+001C>'", json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(parser_helper("\"\x1d\""), "[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing value - invalid string: control character U+001D (GS) must be escaped to \\u001D; last read: '\"<U+001D>'", json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(parser_helper("\"\x1e\""), "[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing value - invalid string: control character U+001E (RS) must be escaped to \\u001E; last read: '\"<U+001E>'", json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(parser_helper("\"\x1f\""), "[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing value - invalid string: control character U+001F (US) must be escaped to \\u001F; last read: '\"<U+001F>'", json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
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: '\"'",
|
||||
json::parse_error&); // NOLINT(bugprone-string-literal-with-embedded-nul)
|
||||
CHECK_THROWS_WITH_AS(
|
||||
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>'",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
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>'",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
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>'",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
parser_helper("\"\x04\""),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing value - invalid string: control character U+0004 (EOT) must be escaped to \\u0004; last read: '\"<U+0004>'",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
parser_helper("\"\x05\""),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing value - invalid string: control character U+0005 (ENQ) must be escaped to \\u0005; last read: '\"<U+0005>'",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
parser_helper("\"\x06\""),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing value - invalid string: control character U+0006 (ACK) must be escaped to \\u0006; last read: '\"<U+0006>'",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
parser_helper("\"\x07\""),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing value - invalid string: control character U+0007 (BEL) must be escaped to \\u0007; last read: '\"<U+0007>'",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
parser_helper("\"\x08\""),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing value - invalid string: control character U+0008 (BS) must be escaped to \\u0008 or \\b; last read: '\"<U+0008>'",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
parser_helper("\"\x09\""),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing value - invalid string: control character U+0009 (HT) must be escaped to \\u0009 or \\t; last read: '\"<U+0009>'",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
parser_helper("\"\x0a\""),
|
||||
"[json.exception.parse_error.101] parse error at line 2, column 0: syntax error while parsing value - invalid string: control character U+000A (LF) must be escaped to \\u000A or \\n; last read: '\"<U+000A>'",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
parser_helper("\"\x0b\""),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing value - invalid string: control character U+000B (VT) must be escaped to \\u000B; last read: '\"<U+000B>'",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
parser_helper("\"\x0c\""),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing value - invalid string: control character U+000C (FF) must be escaped to \\u000C or \\f; last read: '\"<U+000C>'",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
parser_helper("\"\x0d\""),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing value - invalid string: control character U+000D (CR) must be escaped to \\u000D or \\r; last read: '\"<U+000D>'",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
parser_helper("\"\x0e\""),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing value - invalid string: control character U+000E (SO) must be escaped to \\u000E; last read: '\"<U+000E>'",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
parser_helper("\"\x0f\""),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing value - invalid string: control character U+000F (SI) must be escaped to \\u000F; last read: '\"<U+000F>'",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
parser_helper("\"\x10\""),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing value - invalid string: control character U+0010 (DLE) must be escaped to \\u0010; last read: '\"<U+0010>'",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
parser_helper("\"\x11\""),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing value - invalid string: control character U+0011 (DC1) must be escaped to \\u0011; last read: '\"<U+0011>'",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
parser_helper("\"\x12\""),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing value - invalid string: control character U+0012 (DC2) must be escaped to \\u0012; last read: '\"<U+0012>'",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
parser_helper("\"\x13\""),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing value - invalid string: control character U+0013 (DC3) must be escaped to \\u0013; last read: '\"<U+0013>'",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
parser_helper("\"\x14\""),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing value - invalid string: control character U+0014 (DC4) must be escaped to \\u0014; last read: '\"<U+0014>'",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
parser_helper("\"\x15\""),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing value - invalid string: control character U+0015 (NAK) must be escaped to \\u0015; last read: '\"<U+0015>'",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
parser_helper("\"\x16\""),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing value - invalid string: control character U+0016 (SYN) must be escaped to \\u0016; last read: '\"<U+0016>'",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
parser_helper("\"\x17\""),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing value - invalid string: control character U+0017 (ETB) must be escaped to \\u0017; last read: '\"<U+0017>'",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
parser_helper("\"\x18\""),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing value - invalid string: control character U+0018 (CAN) must be escaped to \\u0018; last read: '\"<U+0018>'",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
parser_helper("\"\x19\""),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing value - invalid string: control character U+0019 (EM) must be escaped to \\u0019; last read: '\"<U+0019>'",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
parser_helper("\"\x1a\""),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing value - invalid string: control character U+001A (SUB) must be escaped to \\u001A; last read: '\"<U+001A>'",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
parser_helper("\"\x1b\""),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing value - invalid string: control character U+001B (ESC) must be escaped to \\u001B; last read: '\"<U+001B>'",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
parser_helper("\"\x1c\""),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing value - invalid string: control character U+001C (FS) must be escaped to \\u001C; last read: '\"<U+001C>'",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
parser_helper("\"\x1d\""),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing value - invalid string: control character U+001D (GS) must be escaped to \\u001D; last read: '\"<U+001D>'",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
parser_helper("\"\x1e\""),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing value - invalid string: control character U+001E (RS) must be escaped to \\u001E; last read: '\"<U+001E>'",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
parser_helper("\"\x1f\""),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing value - invalid string: control character U+001F (US) must be escaped to \\u001F; last read: '\"<U+001F>'",
|
||||
json::parse_error&);
|
||||
|
||||
SECTION("additional test for null byte")
|
||||
{
|
||||
@@ -410,7 +519,10 @@ TEST_CASE("parser class")
|
||||
std::string s = "\"1\"";
|
||||
s[1] = '\0';
|
||||
json _;
|
||||
CHECK_THROWS_WITH_AS(_ = json::parse(s.begin(), s.end()), "[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing value - invalid string: control character U+0000 (NUL) must be escaped to \\u0000; last read: '\"<U+0000>'", json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
_ = json::parse(s.begin(), s.end()),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing value - invalid string: control character U+0000 (NUL) must be escaped to \\u0000; last read: '\"<U+0000>'",
|
||||
json::parse_error&);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -581,7 +693,9 @@ TEST_CASE("parser class")
|
||||
SECTION("overflow")
|
||||
{
|
||||
// overflows during parsing yield an exception
|
||||
CHECK_THROWS_WITH_AS(parser_helper("1.18973e+4932").empty(), "[json.exception.out_of_range.406] number overflow parsing '1.18973e+4932'", json::out_of_range&);
|
||||
CHECK_THROWS_WITH_AS(parser_helper("1.18973e+4932").empty(),
|
||||
"[json.exception.out_of_range.406] number overflow parsing '1.18973e+4932'",
|
||||
json::out_of_range&);
|
||||
}
|
||||
|
||||
SECTION("invalid numbers")
|
||||
@@ -590,57 +704,74 @@ TEST_CASE("parser class")
|
||||
CHECK_THROWS_AS(parser_helper("+1"), json::parse_error&);
|
||||
CHECK_THROWS_AS(parser_helper("+0"), json::parse_error&);
|
||||
|
||||
CHECK_THROWS_WITH_AS(parser_helper("01"),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing value - unexpected number literal; expected end of input",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(parser_helper("-01"),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 3: syntax error while parsing value - unexpected number literal; expected end of input",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(parser_helper("--1"),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing value - invalid number; expected digit after '-'; last read: '--'",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(parser_helper("1."),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 3: syntax error while parsing value - invalid number; expected digit after '.'; last read: '1.'",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(parser_helper("1E"),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 3: syntax error while parsing value - invalid number; expected '+', '-', or digit after exponent; last read: '1E'",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(parser_helper("1E-"),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 4: syntax error while parsing value - invalid number; expected digit after exponent sign; last read: '1E-'",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(parser_helper("1.E1"),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 3: syntax error while parsing value - invalid number; expected digit after '.'; last read: '1.E'",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(parser_helper("-1E"),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 4: syntax error while parsing value - invalid number; expected '+', '-', or digit after exponent; last read: '-1E'",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(parser_helper("-0E#"),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 4: syntax error while parsing value - invalid number; expected '+', '-', or digit after exponent; last read: '-0E#'",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(parser_helper("-0E-#"),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 5: syntax error while parsing value - invalid number; expected digit after exponent sign; last read: '-0E-#'",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(parser_helper("-0#"),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 3: syntax error while parsing value - invalid literal; last read: '-0#'; expected end of input",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(parser_helper("-0.0:"),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 5: syntax error while parsing value - unexpected ':'; expected end of input",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(parser_helper("-0.0Z"),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 5: syntax error while parsing value - invalid literal; last read: '-0.0Z'; expected end of input",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(parser_helper("-0E123:"),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 7: syntax error while parsing value - unexpected ':'; expected end of input",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(parser_helper("-0e0-:"),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 6: syntax error while parsing value - invalid number; expected digit after '-'; last read: '-:'; expected end of input",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(parser_helper("-0e-:"),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 5: syntax error while parsing value - invalid number; expected digit after exponent sign; last read: '-0e-:'",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(parser_helper("-0f"),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 4: syntax error while parsing value - invalid literal; last read: '-0f'; expected end of input",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
parser_helper("01"),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing value - unexpected number literal; expected end of input",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
parser_helper("-01"),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 3: syntax error while parsing value - unexpected number literal; expected end of input",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
parser_helper("--1"),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing value - invalid number; expected digit after '-'; last read: '--'",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
parser_helper("1."),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 3: syntax error while parsing value - invalid number; expected digit after '.'; last read: '1.'",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
parser_helper("1E"),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 3: syntax error while parsing value - invalid number; expected '+', '-', or digit after exponent; last read: '1E'",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
parser_helper("1E-"),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 4: syntax error while parsing value - invalid number; expected digit after exponent sign; last read: '1E-'",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
parser_helper("1.E1"),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 3: syntax error while parsing value - invalid number; expected digit after '.'; last read: '1.E'",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
parser_helper("-1E"),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 4: syntax error while parsing value - invalid number; expected '+', '-', or digit after exponent; last read: '-1E'",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
parser_helper("-0E#"),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 4: syntax error while parsing value - invalid number; expected '+', '-', or digit after exponent; last read: '-0E#'",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
parser_helper("-0E-#"),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 5: syntax error while parsing value - invalid number; expected digit after exponent sign; last read: '-0E-#'",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
parser_helper("-0#"),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 3: syntax error while parsing value - invalid literal; last read: '-0#'; expected end of input",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
parser_helper("-0.0:"),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 5: syntax error while parsing value - unexpected ':'; expected end of input",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
parser_helper("-0.0Z"),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 5: syntax error while parsing value - invalid literal; last read: '-0.0Z'; expected end of input",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
parser_helper("-0E123:"),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 7: syntax error while parsing value - unexpected ':'; expected end of input",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
parser_helper("-0e0-:"),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 6: syntax error while parsing value - invalid number; expected digit after '-'; last read: '-:'; expected end of input",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
parser_helper("-0e-:"),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 5: syntax error while parsing value - invalid number; expected digit after exponent sign; last read: '-0e-:'",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
parser_helper("-0f"),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 4: syntax error while parsing value - invalid literal; last read: '-0f'; expected end of input",
|
||||
json::parse_error&);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -910,171 +1041,222 @@ TEST_CASE("parser class")
|
||||
SECTION("parse errors")
|
||||
{
|
||||
// unexpected end of number
|
||||
CHECK_THROWS_WITH_AS(parser_helper("0."),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 3: syntax error while parsing value - invalid number; expected digit after '.'; last read: '0.'",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(parser_helper("-"),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing value - invalid number; expected digit after '-'; last read: '-'",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(parser_helper("--"),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing value - invalid number; expected digit after '-'; last read: '--'",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(parser_helper("-0."),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 4: syntax error while parsing value - invalid number; expected digit after '.'; last read: '-0.'",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(parser_helper("-."),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing value - invalid number; expected digit after '-'; last read: '-.'",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(parser_helper("-:"),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing value - invalid number; expected digit after '-'; last read: '-:'",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(parser_helper("0.:"),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 3: syntax error while parsing value - invalid number; expected digit after '.'; last read: '0.:'",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(parser_helper("e."),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 1: syntax error while parsing value - invalid literal; last read: 'e'",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(parser_helper("1e."),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 3: syntax error while parsing value - invalid number; expected '+', '-', or digit after exponent; last read: '1e.'",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(parser_helper("1e/"),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 3: syntax error while parsing value - invalid number; expected '+', '-', or digit after exponent; last read: '1e/'",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(parser_helper("1e:"),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 3: syntax error while parsing value - invalid number; expected '+', '-', or digit after exponent; last read: '1e:'",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(parser_helper("1E."),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 3: syntax error while parsing value - invalid number; expected '+', '-', or digit after exponent; last read: '1E.'",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(parser_helper("1E/"),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 3: syntax error while parsing value - invalid number; expected '+', '-', or digit after exponent; last read: '1E/'",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(parser_helper("1E:"),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 3: syntax error while parsing value - invalid number; expected '+', '-', or digit after exponent; last read: '1E:'",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
parser_helper("0."),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 3: syntax error while parsing value - invalid number; expected digit after '.'; last read: '0.'",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
parser_helper("-"),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing value - invalid number; expected digit after '-'; last read: '-'",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
parser_helper("--"),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing value - invalid number; expected digit after '-'; last read: '--'",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
parser_helper("-0."),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 4: syntax error while parsing value - invalid number; expected digit after '.'; last read: '-0.'",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
parser_helper("-."),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing value - invalid number; expected digit after '-'; last read: '-.'",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
parser_helper("-:"),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing value - invalid number; expected digit after '-'; last read: '-:'",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
parser_helper("0.:"),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 3: syntax error while parsing value - invalid number; expected digit after '.'; last read: '0.:'",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
parser_helper("e."),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 1: syntax error while parsing value - invalid literal; last read: 'e'",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
parser_helper("1e."),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 3: syntax error while parsing value - invalid number; expected '+', '-', or digit after exponent; last read: '1e.'",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
parser_helper("1e/"),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 3: syntax error while parsing value - invalid number; expected '+', '-', or digit after exponent; last read: '1e/'",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
parser_helper("1e:"),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 3: syntax error while parsing value - invalid number; expected '+', '-', or digit after exponent; last read: '1e:'",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
parser_helper("1E."),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 3: syntax error while parsing value - invalid number; expected '+', '-', or digit after exponent; last read: '1E.'",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
parser_helper("1E/"),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 3: syntax error while parsing value - invalid number; expected '+', '-', or digit after exponent; last read: '1E/'",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
parser_helper("1E:"),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 3: syntax error while parsing value - invalid number; expected '+', '-', or digit after exponent; last read: '1E:'",
|
||||
json::parse_error&);
|
||||
|
||||
// unexpected end of null
|
||||
CHECK_THROWS_WITH_AS(parser_helper("n"),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing value - invalid literal; last read: 'n'",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(parser_helper("nu"),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 3: syntax error while parsing value - invalid literal; last read: 'nu'",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(parser_helper("nul"),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 4: syntax error while parsing value - invalid literal; last read: 'nul'",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(parser_helper("nulk"),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 4: syntax error while parsing value - invalid literal; last read: 'nulk'",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(parser_helper("nulm"),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 4: syntax error while parsing value - invalid literal; last read: 'nulm'",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
parser_helper("n"),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing value - invalid literal; last read: 'n'",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
parser_helper("nu"),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 3: syntax error while parsing value - invalid literal; last read: 'nu'",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
parser_helper("nul"),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 4: syntax error while parsing value - invalid literal; last read: 'nul'",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
parser_helper("nulk"),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 4: syntax error while parsing value - invalid literal; last read: 'nulk'",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
parser_helper("nulm"),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 4: syntax error while parsing value - invalid literal; last read: 'nulm'",
|
||||
json::parse_error&);
|
||||
|
||||
// unexpected end of true
|
||||
CHECK_THROWS_WITH_AS(parser_helper("t"),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing value - invalid literal; last read: 't'",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(parser_helper("tr"),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 3: syntax error while parsing value - invalid literal; last read: 'tr'",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(parser_helper("tru"),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 4: syntax error while parsing value - invalid literal; last read: 'tru'",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(parser_helper("trud"),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 4: syntax error while parsing value - invalid literal; last read: 'trud'",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(parser_helper("truf"),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 4: syntax error while parsing value - invalid literal; last read: 'truf'",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
parser_helper("t"),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing value - invalid literal; last read: 't'",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
parser_helper("tr"),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 3: syntax error while parsing value - invalid literal; last read: 'tr'",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
parser_helper("tru"),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 4: syntax error while parsing value - invalid literal; last read: 'tru'",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
parser_helper("trud"),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 4: syntax error while parsing value - invalid literal; last read: 'trud'",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
parser_helper("truf"),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 4: syntax error while parsing value - invalid literal; last read: 'truf'",
|
||||
json::parse_error&);
|
||||
|
||||
// unexpected end of false
|
||||
CHECK_THROWS_WITH_AS(parser_helper("f"),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing value - invalid literal; last read: 'f'",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(parser_helper("fa"),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 3: syntax error while parsing value - invalid literal; last read: 'fa'",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(parser_helper("fal"),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 4: syntax error while parsing value - invalid literal; last read: 'fal'",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(parser_helper("fals"),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 5: syntax error while parsing value - invalid literal; last read: 'fals'",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(parser_helper("falsd"),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 5: syntax error while parsing value - invalid literal; last read: 'falsd'",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(parser_helper("falsf"),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 5: syntax error while parsing value - invalid literal; last read: 'falsf'",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
parser_helper("f"),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing value - invalid literal; last read: 'f'",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
parser_helper("fa"),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 3: syntax error while parsing value - invalid literal; last read: 'fa'",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
parser_helper("fal"),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 4: syntax error while parsing value - invalid literal; last read: 'fal'",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
parser_helper("fals"),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 5: syntax error while parsing value - invalid literal; last read: 'fals'",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
parser_helper("falsd"),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 5: syntax error while parsing value - invalid literal; last read: 'falsd'",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
parser_helper("falsf"),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 5: syntax error while parsing value - invalid literal; last read: 'falsf'",
|
||||
json::parse_error&);
|
||||
|
||||
// missing/unexpected end of array
|
||||
CHECK_THROWS_WITH_AS(parser_helper("["),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing value - unexpected end of input; expected '[', '{', or a literal",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(parser_helper("[1"),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 3: syntax error while parsing array - unexpected end of input; expected ']'",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(parser_helper("[1,"),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 4: syntax error while parsing value - unexpected end of input; expected '[', '{', or a literal",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(parser_helper("[1,]"),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 4: syntax error while parsing value - unexpected ']'; expected '[', '{', or a literal",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(parser_helper("]"),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 1: syntax error while parsing value - unexpected ']'; expected '[', '{', or a literal",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
parser_helper("["),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing value - unexpected end of input; expected '[', '{', or a literal",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
parser_helper("[1"),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 3: syntax error while parsing array - unexpected end of input; expected ']'",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
parser_helper("[1,"),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 4: syntax error while parsing value - unexpected end of input; expected '[', '{', or a literal",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
parser_helper("[1,]"),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 4: syntax error while parsing value - unexpected ']'; expected '[', '{', or a literal",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
parser_helper("]"),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 1: syntax error while parsing value - unexpected ']'; expected '[', '{', or a literal",
|
||||
json::parse_error&);
|
||||
|
||||
// missing/unexpected end of object
|
||||
CHECK_THROWS_WITH_AS(parser_helper("{"),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing object key - unexpected end of input; expected string literal",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(parser_helper("{\"foo\""),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 7: syntax error while parsing object separator - unexpected end of input; expected ':'",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(parser_helper("{\"foo\":"),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 8: syntax error while parsing value - unexpected end of input; expected '[', '{', or a literal",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(parser_helper("{\"foo\":}"),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 8: syntax error while parsing value - unexpected '}'; expected '[', '{', or a literal",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(parser_helper("{\"foo\":1,}"),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 10: syntax error while parsing object key - unexpected '}'; expected string literal",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(parser_helper("}"),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 1: syntax error while parsing value - unexpected '}'; expected '[', '{', or a literal",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
parser_helper("{"),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing object key - unexpected end of input; expected string literal",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
parser_helper("{\"foo\""),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 7: syntax error while parsing object separator - unexpected end of input; expected ':'",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
parser_helper("{\"foo\":"),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 8: syntax error while parsing value - unexpected end of input; expected '[', '{', or a literal",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
parser_helper("{\"foo\":}"),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 8: syntax error while parsing value - unexpected '}'; expected '[', '{', or a literal",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
parser_helper("{\"foo\":1,}"),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 10: syntax error while parsing object key - unexpected '}'; expected string literal",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
parser_helper("}"),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 1: syntax error while parsing value - unexpected '}'; expected '[', '{', or a literal",
|
||||
json::parse_error&);
|
||||
|
||||
// missing/unexpected end of string
|
||||
CHECK_THROWS_WITH_AS(parser_helper("\""),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing value - invalid string: missing closing quote; last read: '\"'",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(parser_helper("\"\\\""),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 4: syntax error while parsing value - invalid string: missing closing quote; last read: '\"\\\"'",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(parser_helper("\"\\u\""),
|
||||
"[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: '\"\\u\"'",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(parser_helper("\"\\u0\""),
|
||||
"[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: '\"\\u0\"'",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(parser_helper("\"\\u01\""),
|
||||
"[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: '\"\\u01\"'",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(parser_helper("\"\\u012\""),
|
||||
"[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: '\"\\u012\"'",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(parser_helper("\"\\u"),
|
||||
"[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: '\"\\u'",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(parser_helper("\"\\u0"),
|
||||
"[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: '\"\\u0'",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(parser_helper("\"\\u01"),
|
||||
"[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: '\"\\u01'",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(parser_helper("\"\\u012"),
|
||||
"[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: '\"\\u012'",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
parser_helper("\""),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing value - invalid string: missing closing quote; last read: '\"'",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
parser_helper("\"\\\""),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 4: syntax error while parsing value - invalid string: missing closing quote; last read: '\"\\\"'",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
parser_helper("\"\\u\""),
|
||||
"[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: '\"\\u\"'",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
parser_helper("\"\\u0\""),
|
||||
"[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: '\"\\u0\"'",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
parser_helper("\"\\u01\""),
|
||||
"[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: '\"\\u01\"'",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
parser_helper("\"\\u012\""),
|
||||
"[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: '\"\\u012\"'",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
parser_helper("\"\\u"),
|
||||
"[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: '\"\\u'",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
parser_helper("\"\\u0"),
|
||||
"[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: '\"\\u0'",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
parser_helper("\"\\u01"),
|
||||
"[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: '\"\\u01'",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
parser_helper("\"\\u012"),
|
||||
"[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: '\"\\u012'",
|
||||
json::parse_error&);
|
||||
|
||||
// invalid escapes
|
||||
for (int c = 1; c < 128; ++c)
|
||||
@@ -1110,8 +1292,10 @@ TEST_CASE("parser class")
|
||||
// only check error message if c is not a control character
|
||||
if (c > 0x1f)
|
||||
{
|
||||
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)) + "'");
|
||||
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;
|
||||
}
|
||||
@@ -1185,8 +1369,10 @@ TEST_CASE("parser class")
|
||||
// only check error message if c is not a control character
|
||||
if (c > 0x1f)
|
||||
{
|
||||
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) + "'");
|
||||
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)
|
||||
@@ -1194,8 +1380,10 @@ TEST_CASE("parser class")
|
||||
// only check error message if c is not a control character
|
||||
if (c > 0x1f)
|
||||
{
|
||||
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) + "'");
|
||||
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)
|
||||
@@ -1203,8 +1391,10 @@ TEST_CASE("parser class")
|
||||
// only check error message if c is not a control character
|
||||
if (c > 0x1f)
|
||||
{
|
||||
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) + "'");
|
||||
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)
|
||||
@@ -1212,8 +1402,10 @@ TEST_CASE("parser class")
|
||||
// only check error message if c is not a control character
|
||||
if (c > 0x1f)
|
||||
{
|
||||
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) + "'");
|
||||
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) + "'");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1222,17 +1414,23 @@ TEST_CASE("parser class")
|
||||
json _;
|
||||
|
||||
// missing part of a surrogate pair
|
||||
CHECK_THROWS_WITH_AS(_ = json::parse("\"\\uD80C\""), "[json.exception.parse_error.101] parse error at line 1, column 8: syntax error while parsing value - invalid string: surrogate U+D800..U+DBFF must be followed by U+DC00..U+DFFF; last read: '\"\\uD80C\"'", json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
_ = json::parse("\"\\uD80C\""),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 8: syntax error while parsing value - invalid string: surrogate U+D800..U+DBFF must be followed by U+DC00..U+DFFF; last read: '\"\\uD80C\"'",
|
||||
json::parse_error&);
|
||||
// invalid surrogate pair
|
||||
CHECK_THROWS_WITH_AS(_ = json::parse("\"\\uD80C\\uD80C\""),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 13: syntax error while parsing value - invalid string: surrogate U+D800..U+DBFF must be followed by U+DC00..U+DFFF; last read: '\"\\uD80C\\uD80C'",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(_ = json::parse("\"\\uD80C\\u0000\""),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 13: syntax error while parsing value - invalid string: surrogate U+D800..U+DBFF must be followed by U+DC00..U+DFFF; last read: '\"\\uD80C\\u0000'",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(_ = json::parse("\"\\uD80C\\uFFFF\""),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 13: syntax error while parsing value - invalid string: surrogate U+D800..U+DBFF must be followed by U+DC00..U+DFFF; last read: '\"\\uD80C\\uFFFF'",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
_ = json::parse("\"\\uD80C\\uD80C\""),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 13: syntax error while parsing value - invalid string: surrogate U+D800..U+DBFF must be followed by U+DC00..U+DFFF; last read: '\"\\uD80C\\uD80C'",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
_ = json::parse("\"\\uD80C\\u0000\""),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 13: syntax error while parsing value - invalid string: surrogate U+D800..U+DBFF must be followed by U+DC00..U+DFFF; last read: '\"\\uD80C\\u0000'",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
_ = json::parse("\"\\uD80C\\uFFFF\""),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 13: syntax error while parsing value - invalid string: surrogate U+D800..U+DBFF must be followed by U+DC00..U+DFFF; last read: '\"\\uD80C\\uFFFF'",
|
||||
json::parse_error&);
|
||||
}
|
||||
|
||||
SECTION("parse errors (accept)")
|
||||
@@ -1423,9 +1621,15 @@ TEST_CASE("parser class")
|
||||
SECTION("tests found by mutate++")
|
||||
{
|
||||
// test case to make sure no comma precedes the first key
|
||||
CHECK_THROWS_WITH_AS(parser_helper("{,\"key\": false}"), "[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing object key - unexpected ','; expected string literal", json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
parser_helper("{,\"key\": false}"),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing object key - unexpected ','; expected string literal",
|
||||
json::parse_error&);
|
||||
// test case to make sure an object is properly closed
|
||||
CHECK_THROWS_WITH_AS(parser_helper("[{\"key\": false true]"), "[json.exception.parse_error.101] parse error at line 1, column 19: syntax error while parsing object - unexpected true literal; expected '}'", json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
parser_helper("[{\"key\": false true]"),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 19: syntax error while parsing object - unexpected true literal; expected '}'",
|
||||
json::parse_error&);
|
||||
|
||||
// test case to make sure the callback is properly evaluated after reading a key
|
||||
{
|
||||
@@ -1655,9 +1859,14 @@ TEST_CASE("parser class")
|
||||
CHECK(json::parse("{\"foo\": true:", cb, false).is_discarded());
|
||||
|
||||
json _;
|
||||
CHECK_THROWS_WITH_AS(_ = json::parse("{\"foo\": true:", cb), "[json.exception.parse_error.101] parse error at line 1, column 13: syntax error while parsing object - unexpected ':'; expected '}'", json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
_ = json::parse("{\"foo\": true:", cb),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 13: syntax error while parsing object - unexpected ':'; expected '}'",
|
||||
json::parse_error&);
|
||||
|
||||
CHECK_THROWS_WITH_AS(_ = json::parse("1.18973e+4932", cb), "[json.exception.out_of_range.406] number overflow parsing '1.18973e+4932'", json::out_of_range&);
|
||||
CHECK_THROWS_WITH_AS(_ = json::parse("1.18973e+4932", cb),
|
||||
"[json.exception.out_of_range.406] number overflow parsing '1.18973e+4932'",
|
||||
json::out_of_range&);
|
||||
}
|
||||
|
||||
SECTION("SAX parser")
|
||||
@@ -1739,7 +1948,13 @@ TEST_CASE("parser class")
|
||||
SECTION("error messages for comments")
|
||||
{
|
||||
json _;
|
||||
CHECK_THROWS_WITH_AS(_ = json::parse("/a", nullptr, true, true), "[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing value - invalid comment; expecting '/' or '*' after '/'; last read: '/a'", json::parse_error);
|
||||
CHECK_THROWS_WITH_AS(_ = json::parse("/*", nullptr, true, true), "[json.exception.parse_error.101] parse error at line 1, column 3: syntax error while parsing value - invalid comment; missing closing '*/'; last read: '/*<U+0000>'", json::parse_error);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
_ = json::parse("/a", nullptr, true, true),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing value - invalid comment; expecting '/' or '*' after '/'; last read: '/a'",
|
||||
json::parse_error);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
_ = json::parse("/*", nullptr, true, true),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 3: syntax error while parsing value - invalid comment; missing closing '*/'; last read: '/*<U+0000>'",
|
||||
json::parse_error);
|
||||
}
|
||||
}
|
||||
|
||||
+189
-197
@@ -21,7 +21,8 @@ using nlohmann::json;
|
||||
|
||||
#if JSON_HAS_THREE_WAY_COMPARISON
|
||||
// this can be replaced with the doctest stl extension header in version 2.5
|
||||
namespace doctest {
|
||||
namespace doctest
|
||||
{
|
||||
template<>
|
||||
struct StringMaker<std::partial_ordering>
|
||||
{
|
||||
@@ -50,7 +51,8 @@ struct StringMaker<std::partial_ordering>
|
||||
|
||||
#endif
|
||||
|
||||
namespace {
|
||||
namespace
|
||||
{
|
||||
// helper function to check std::less<json::value_t>
|
||||
// see https://en.cppreference.com/w/cpp/utility/functional/less
|
||||
template<typename A, typename B, typename U = std::less<json::value_t>>
|
||||
@@ -85,33 +87,30 @@ TEST_CASE("lexicographical comparison operators")
|
||||
|
||||
SECTION("types")
|
||||
{
|
||||
std::vector<json::value_t> j_types =
|
||||
{
|
||||
json::value_t::null,
|
||||
json::value_t::boolean,
|
||||
json::value_t::number_integer,
|
||||
json::value_t::number_unsigned,
|
||||
json::value_t::number_float,
|
||||
json::value_t::object,
|
||||
json::value_t::array,
|
||||
json::value_t::string,
|
||||
json::value_t::binary,
|
||||
json::value_t::discarded};
|
||||
std::vector<json::value_t> j_types = {json::value_t::null,
|
||||
json::value_t::boolean,
|
||||
json::value_t::number_integer,
|
||||
json::value_t::number_unsigned,
|
||||
json::value_t::number_float,
|
||||
json::value_t::object,
|
||||
json::value_t::array,
|
||||
json::value_t::string,
|
||||
json::value_t::binary,
|
||||
json::value_t::discarded};
|
||||
|
||||
std::vector<std::vector<bool>> expected_lt =
|
||||
{
|
||||
//0 1 2 3 4 5 6 7 8 9
|
||||
{f_, _t, _t, _t, _t, _t, _t, _t, _t, f_}, // 0
|
||||
{f_, f_, _t, _t, _t, _t, _t, _t, _t, f_}, // 1
|
||||
{f_, f_, f_, f_, f_, _t, _t, _t, _t, f_}, // 2
|
||||
{f_, f_, f_, f_, f_, _t, _t, _t, _t, f_}, // 3
|
||||
{f_, f_, f_, f_, f_, _t, _t, _t, _t, f_}, // 4
|
||||
{f_, f_, f_, f_, f_, f_, _t, _t, _t, f_}, // 5
|
||||
{f_, f_, f_, f_, f_, f_, f_, _t, _t, f_}, // 6
|
||||
{f_, f_, f_, f_, f_, f_, f_, f_, _t, f_}, // 7
|
||||
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 8
|
||||
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 9
|
||||
};
|
||||
std::vector<std::vector<bool>> expected_lt = {
|
||||
//0 1 2 3 4 5 6 7 8 9
|
||||
{f_, _t, _t, _t, _t, _t, _t, _t, _t, f_}, // 0
|
||||
{f_, f_, _t, _t, _t, _t, _t, _t, _t, f_}, // 1
|
||||
{f_, f_, f_, f_, f_, _t, _t, _t, _t, f_}, // 2
|
||||
{f_, f_, f_, f_, f_, _t, _t, _t, _t, f_}, // 3
|
||||
{f_, f_, f_, f_, f_, _t, _t, _t, _t, f_}, // 4
|
||||
{f_, f_, f_, f_, f_, f_, _t, _t, _t, f_}, // 5
|
||||
{f_, f_, f_, f_, f_, f_, f_, _t, _t, f_}, // 6
|
||||
{f_, f_, f_, f_, f_, f_, f_, f_, _t, f_}, // 7
|
||||
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 8
|
||||
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 9
|
||||
};
|
||||
|
||||
SECTION("comparison: less")
|
||||
{
|
||||
@@ -138,20 +137,19 @@ TEST_CASE("lexicographical comparison operators")
|
||||
// JSON_HAS_CPP_20 (do not remove; see note at top of file)
|
||||
SECTION("comparison: 3-way")
|
||||
{
|
||||
std::vector<std::vector<std::partial_ordering>> expected =
|
||||
{
|
||||
//0 1 2 3 4 5 6 7 8 9
|
||||
{eq, lt, lt, lt, lt, lt, lt, lt, lt, un}, // 0
|
||||
{gt, eq, lt, lt, lt, lt, lt, lt, lt, un}, // 1
|
||||
{gt, gt, eq, eq, eq, lt, lt, lt, lt, un}, // 2
|
||||
{gt, gt, eq, eq, eq, lt, lt, lt, lt, un}, // 3
|
||||
{gt, gt, eq, eq, eq, lt, lt, lt, lt, un}, // 4
|
||||
{gt, gt, gt, gt, gt, eq, lt, lt, lt, un}, // 5
|
||||
{gt, gt, gt, gt, gt, gt, eq, lt, lt, un}, // 6
|
||||
{gt, gt, gt, gt, gt, gt, gt, eq, lt, un}, // 7
|
||||
{gt, gt, gt, gt, gt, gt, gt, gt, eq, un}, // 8
|
||||
{un, un, un, un, un, un, un, un, un, un}, // 9
|
||||
};
|
||||
std::vector<std::vector<std::partial_ordering>> expected = {
|
||||
//0 1 2 3 4 5 6 7 8 9
|
||||
{eq, lt, lt, lt, lt, lt, lt, lt, lt, un}, // 0
|
||||
{gt, eq, lt, lt, lt, lt, lt, lt, lt, un}, // 1
|
||||
{gt, gt, eq, eq, eq, lt, lt, lt, lt, un}, // 2
|
||||
{gt, gt, eq, eq, eq, lt, lt, lt, lt, un}, // 3
|
||||
{gt, gt, eq, eq, eq, lt, lt, lt, lt, un}, // 4
|
||||
{gt, gt, gt, gt, gt, eq, lt, lt, lt, un}, // 5
|
||||
{gt, gt, gt, gt, gt, gt, eq, lt, lt, un}, // 6
|
||||
{gt, gt, gt, gt, gt, gt, gt, eq, lt, un}, // 7
|
||||
{gt, gt, gt, gt, gt, gt, gt, gt, eq, un}, // 8
|
||||
{un, un, un, un, un, un, un, un, un, un}, // 9
|
||||
};
|
||||
|
||||
// check expected partial_ordering against expected boolean
|
||||
REQUIRE(expected.size() == expected_lt.size());
|
||||
@@ -184,114 +182,110 @@ TEST_CASE("lexicographical comparison operators")
|
||||
|
||||
SECTION("values")
|
||||
{
|
||||
json j_values =
|
||||
{
|
||||
nullptr,
|
||||
nullptr, // 0 1
|
||||
-17,
|
||||
42, // 2 3
|
||||
8u,
|
||||
13u, // 4 5
|
||||
3.14159,
|
||||
23.42, // 6 7
|
||||
nan,
|
||||
nan, // 8 9
|
||||
"foo",
|
||||
"bar", // 10 11
|
||||
true,
|
||||
false, // 12 13
|
||||
{1, 2, 3},
|
||||
{"one", "two", "three"}, // 14 15
|
||||
{{"first", 1}, {"second", 2}},
|
||||
{{"a", "A"}, {"b", {"B"}}}, // 16 17
|
||||
json::binary({1, 2, 3}),
|
||||
json::binary({1, 2, 4}), // 18 19
|
||||
json(json::value_t::discarded),
|
||||
json(json::value_t::discarded) // 20 21
|
||||
};
|
||||
json j_values = {
|
||||
nullptr,
|
||||
nullptr, // 0 1
|
||||
-17,
|
||||
42, // 2 3
|
||||
8u,
|
||||
13u, // 4 5
|
||||
3.14159,
|
||||
23.42, // 6 7
|
||||
nan,
|
||||
nan, // 8 9
|
||||
"foo",
|
||||
"bar", // 10 11
|
||||
true,
|
||||
false, // 12 13
|
||||
{1, 2, 3},
|
||||
{"one", "two", "three"}, // 14 15
|
||||
{{"first", 1}, {"second", 2}},
|
||||
{{"a", "A"}, {"b", {"B"}}}, // 16 17
|
||||
json::binary({1, 2, 3}),
|
||||
json::binary({1, 2, 4}), // 18 19
|
||||
json(json::value_t::discarded),
|
||||
json(json::value_t::discarded) // 20 21
|
||||
};
|
||||
|
||||
std::vector<std::vector<bool>> expected_eq =
|
||||
{
|
||||
//0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
|
||||
{_t, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 0
|
||||
{_t, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 1
|
||||
{f_, f_, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 2
|
||||
{f_, f_, f_, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 3
|
||||
{f_, f_, f_, f_, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 4
|
||||
{f_, f_, f_, f_, f_, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 5
|
||||
{f_, f_, f_, f_, f_, f_, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 6
|
||||
{f_, f_, f_, f_, f_, f_, f_, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 7
|
||||
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 8
|
||||
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 9
|
||||
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 10
|
||||
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 11
|
||||
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 12
|
||||
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, f_, f_, f_, f_, f_, f_, f_, f_}, // 13
|
||||
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, f_, f_, f_, f_, f_, f_, f_}, // 14
|
||||
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, f_, f_, f_, f_, f_, f_}, // 15
|
||||
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, f_, f_, f_, f_, f_}, // 16
|
||||
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, f_, f_, f_, f_}, // 17
|
||||
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, f_, f_, f_}, // 18
|
||||
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, f_, f_}, // 19
|
||||
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 20
|
||||
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 21
|
||||
};
|
||||
std::vector<std::vector<bool>> expected_eq = {
|
||||
//0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
|
||||
{_t, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 0
|
||||
{_t, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 1
|
||||
{f_, f_, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 2
|
||||
{f_, f_, f_, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 3
|
||||
{f_, f_, f_, f_, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 4
|
||||
{f_, f_, f_, f_, f_, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 5
|
||||
{f_, f_, f_, f_, f_, f_, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 6
|
||||
{f_, f_, f_, f_, f_, f_, f_, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 7
|
||||
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 8
|
||||
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 9
|
||||
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 10
|
||||
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 11
|
||||
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 12
|
||||
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, f_, f_, f_, f_, f_, f_, f_, f_}, // 13
|
||||
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, f_, f_, f_, f_, f_, f_, f_}, // 14
|
||||
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, f_, f_, f_, f_, f_, f_}, // 15
|
||||
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, f_, f_, f_, f_, f_}, // 16
|
||||
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, f_, f_, f_, f_}, // 17
|
||||
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, f_, f_, f_}, // 18
|
||||
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, f_, f_}, // 19
|
||||
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 20
|
||||
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 21
|
||||
};
|
||||
|
||||
std::vector<std::vector<bool>> expected_lt =
|
||||
{
|
||||
//0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
|
||||
{f_, f_, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, f_, f_}, // 0
|
||||
{f_, f_, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, f_, f_}, // 1
|
||||
{f_, f_, f_, _t, _t, _t, _t, _t, f_, f_, _t, _t, f_, f_, _t, _t, _t, _t, _t, _t, f_, f_}, // 2
|
||||
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_, _t, _t, _t, _t, _t, _t, f_, f_}, // 3
|
||||
{f_, f_, f_, _t, f_, _t, f_, _t, f_, f_, _t, _t, f_, f_, _t, _t, _t, _t, _t, _t, f_, f_}, // 4
|
||||
{f_, f_, f_, _t, f_, f_, f_, _t, f_, f_, _t, _t, f_, f_, _t, _t, _t, _t, _t, _t, f_, f_}, // 5
|
||||
{f_, f_, f_, _t, _t, _t, f_, _t, f_, f_, _t, _t, f_, f_, _t, _t, _t, _t, _t, _t, f_, f_}, // 6
|
||||
{f_, f_, f_, _t, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_, _t, _t, _t, _t, _t, _t, f_, f_}, // 7
|
||||
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_, _t, _t, _t, _t, _t, _t, f_, f_}, // 8
|
||||
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_, _t, _t, _t, _t, _t, _t, f_, f_}, // 9
|
||||
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_}, // 10
|
||||
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, f_, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_}, // 11
|
||||
{f_, f_, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, f_, f_, _t, _t, _t, _t, _t, _t, f_, f_}, // 12
|
||||
{f_, f_, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, f_, _t, _t, _t, _t, _t, _t, f_, f_}, // 13
|
||||
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_, f_, _t, f_, f_, _t, _t, f_, f_}, // 14
|
||||
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_}, // 15
|
||||
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_, _t, _t, f_, f_, _t, _t, f_, f_}, // 16
|
||||
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_, _t, _t, _t, f_, _t, _t, f_, f_}, // 17
|
||||
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, f_, f_}, // 18
|
||||
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 19
|
||||
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 20
|
||||
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 21
|
||||
};
|
||||
std::vector<std::vector<bool>> expected_lt = {
|
||||
//0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
|
||||
{f_, f_, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, f_, f_}, // 0
|
||||
{f_, f_, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, f_, f_}, // 1
|
||||
{f_, f_, f_, _t, _t, _t, _t, _t, f_, f_, _t, _t, f_, f_, _t, _t, _t, _t, _t, _t, f_, f_}, // 2
|
||||
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_, _t, _t, _t, _t, _t, _t, f_, f_}, // 3
|
||||
{f_, f_, f_, _t, f_, _t, f_, _t, f_, f_, _t, _t, f_, f_, _t, _t, _t, _t, _t, _t, f_, f_}, // 4
|
||||
{f_, f_, f_, _t, f_, f_, f_, _t, f_, f_, _t, _t, f_, f_, _t, _t, _t, _t, _t, _t, f_, f_}, // 5
|
||||
{f_, f_, f_, _t, _t, _t, f_, _t, f_, f_, _t, _t, f_, f_, _t, _t, _t, _t, _t, _t, f_, f_}, // 6
|
||||
{f_, f_, f_, _t, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_, _t, _t, _t, _t, _t, _t, f_, f_}, // 7
|
||||
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_, _t, _t, _t, _t, _t, _t, f_, f_}, // 8
|
||||
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_, _t, _t, _t, _t, _t, _t, f_, f_}, // 9
|
||||
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_}, // 10
|
||||
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, f_, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_}, // 11
|
||||
{f_, f_, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, f_, f_, _t, _t, _t, _t, _t, _t, f_, f_}, // 12
|
||||
{f_, f_, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, f_, _t, _t, _t, _t, _t, _t, f_, f_}, // 13
|
||||
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_, f_, _t, f_, f_, _t, _t, f_, f_}, // 14
|
||||
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_}, // 15
|
||||
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_, _t, _t, f_, f_, _t, _t, f_, f_}, // 16
|
||||
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_, _t, _t, _t, f_, _t, _t, f_, f_}, // 17
|
||||
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, f_, f_}, // 18
|
||||
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 19
|
||||
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 20
|
||||
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 21
|
||||
};
|
||||
|
||||
SECTION("compares unordered")
|
||||
{
|
||||
std::vector<std::vector<bool>> expected =
|
||||
{
|
||||
//0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
|
||||
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t}, // 0
|
||||
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t}, // 1
|
||||
{f_, f_, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t}, // 2
|
||||
{f_, f_, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t}, // 3
|
||||
{f_, f_, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t}, // 4
|
||||
{f_, f_, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t}, // 5
|
||||
{f_, f_, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t}, // 6
|
||||
{f_, f_, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t}, // 7
|
||||
{f_, f_, _t, _t, _t, _t, _t, _t, _t, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t}, // 8
|
||||
{f_, f_, _t, _t, _t, _t, _t, _t, _t, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t}, // 9
|
||||
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t}, // 10
|
||||
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t}, // 11
|
||||
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t}, // 12
|
||||
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t}, // 13
|
||||
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t}, // 14
|
||||
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t}, // 15
|
||||
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t}, // 16
|
||||
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t}, // 17
|
||||
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t}, // 18
|
||||
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t}, // 19
|
||||
{_t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t}, // 20
|
||||
{_t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t}, // 21
|
||||
};
|
||||
std::vector<std::vector<bool>> expected = {
|
||||
//0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
|
||||
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t}, // 0
|
||||
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t}, // 1
|
||||
{f_, f_, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t}, // 2
|
||||
{f_, f_, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t}, // 3
|
||||
{f_, f_, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t}, // 4
|
||||
{f_, f_, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t}, // 5
|
||||
{f_, f_, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t}, // 6
|
||||
{f_, f_, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t}, // 7
|
||||
{f_, f_, _t, _t, _t, _t, _t, _t, _t, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t}, // 8
|
||||
{f_, f_, _t, _t, _t, _t, _t, _t, _t, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t}, // 9
|
||||
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t}, // 10
|
||||
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t}, // 11
|
||||
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t}, // 12
|
||||
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t}, // 13
|
||||
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t}, // 14
|
||||
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t}, // 15
|
||||
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t}, // 16
|
||||
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t}, // 17
|
||||
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t}, // 18
|
||||
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, _t, _t}, // 19
|
||||
{_t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t}, // 20
|
||||
{_t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t, _t}, // 21
|
||||
};
|
||||
|
||||
// check if two values compare unordered as expected
|
||||
REQUIRE(expected.size() == j_values.size());
|
||||
@@ -310,32 +304,31 @@ TEST_CASE("lexicographical comparison operators")
|
||||
#if JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON
|
||||
SECTION("compares unordered (inverse)")
|
||||
{
|
||||
std::vector<std::vector<bool>> expected =
|
||||
{
|
||||
//0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
|
||||
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 0
|
||||
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 1
|
||||
{f_, f_, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 2
|
||||
{f_, f_, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 3
|
||||
{f_, f_, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 4
|
||||
{f_, f_, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 5
|
||||
{f_, f_, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 6
|
||||
{f_, f_, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 7
|
||||
{f_, f_, _t, _t, _t, _t, _t, _t, _t, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 8
|
||||
{f_, f_, _t, _t, _t, _t, _t, _t, _t, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 9
|
||||
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 10
|
||||
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 11
|
||||
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 12
|
||||
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 13
|
||||
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 14
|
||||
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 15
|
||||
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 16
|
||||
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 17
|
||||
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 18
|
||||
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 19
|
||||
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 20
|
||||
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 21
|
||||
};
|
||||
std::vector<std::vector<bool>> expected = {
|
||||
//0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
|
||||
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 0
|
||||
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 1
|
||||
{f_, f_, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 2
|
||||
{f_, f_, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 3
|
||||
{f_, f_, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 4
|
||||
{f_, f_, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 5
|
||||
{f_, f_, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 6
|
||||
{f_, f_, f_, f_, f_, f_, f_, f_, _t, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 7
|
||||
{f_, f_, _t, _t, _t, _t, _t, _t, _t, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 8
|
||||
{f_, f_, _t, _t, _t, _t, _t, _t, _t, _t, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 9
|
||||
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 10
|
||||
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 11
|
||||
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 12
|
||||
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 13
|
||||
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 14
|
||||
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 15
|
||||
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 16
|
||||
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 17
|
||||
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 18
|
||||
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 19
|
||||
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 20
|
||||
{f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_, f_}, // 21
|
||||
};
|
||||
|
||||
// check that two values compare unordered as expected (with legacy-mode enabled)
|
||||
REQUIRE(expected.size() == j_values.size());
|
||||
@@ -505,32 +498,31 @@ TEST_CASE("lexicographical comparison operators")
|
||||
// JSON_HAS_CPP_20 (do not remove; see note at top of file)
|
||||
SECTION("comparison: 3-way")
|
||||
{
|
||||
std::vector<std::vector<std::partial_ordering>> expected =
|
||||
{
|
||||
//0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
|
||||
{eq, eq, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, un, un}, // 0
|
||||
{eq, eq, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, un, un}, // 1
|
||||
{gt, gt, eq, lt, lt, lt, lt, lt, un, un, lt, lt, gt, gt, lt, lt, lt, lt, lt, lt, un, un}, // 2
|
||||
{gt, gt, gt, eq, gt, gt, gt, gt, un, un, lt, lt, gt, gt, lt, lt, lt, lt, lt, lt, un, un}, // 3
|
||||
{gt, gt, gt, lt, eq, lt, gt, lt, un, un, lt, lt, gt, gt, lt, lt, lt, lt, lt, lt, un, un}, // 4
|
||||
{gt, gt, gt, lt, gt, eq, gt, lt, un, un, lt, lt, gt, gt, lt, lt, lt, lt, lt, lt, un, un}, // 5
|
||||
{gt, gt, gt, lt, lt, lt, eq, lt, un, un, lt, lt, gt, gt, lt, lt, lt, lt, lt, lt, un, un}, // 6
|
||||
{gt, gt, gt, lt, gt, gt, gt, eq, un, un, lt, lt, gt, gt, lt, lt, lt, lt, lt, lt, un, un}, // 7
|
||||
{gt, gt, un, un, un, un, un, un, un, un, lt, lt, gt, gt, lt, lt, lt, lt, lt, lt, un, un}, // 8
|
||||
{gt, gt, un, un, un, un, un, un, un, un, lt, lt, gt, gt, lt, lt, lt, lt, lt, lt, un, un}, // 9
|
||||
{gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, eq, gt, gt, gt, gt, gt, gt, gt, lt, lt, un, un}, // 10
|
||||
{gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, lt, eq, gt, gt, gt, gt, gt, gt, lt, lt, un, un}, // 11
|
||||
{gt, gt, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, eq, gt, lt, lt, lt, lt, lt, lt, un, un}, // 12
|
||||
{gt, gt, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, eq, lt, lt, lt, lt, lt, lt, un, un}, // 13
|
||||
{gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, lt, lt, gt, gt, eq, lt, gt, gt, lt, lt, un, un}, // 14
|
||||
{gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, lt, lt, gt, gt, gt, eq, gt, gt, lt, lt, un, un}, // 15
|
||||
{gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, lt, lt, gt, gt, lt, lt, eq, gt, lt, lt, un, un}, // 16
|
||||
{gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, lt, lt, gt, gt, lt, lt, lt, eq, lt, lt, un, un}, // 17
|
||||
{gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, eq, lt, un, un}, // 18
|
||||
{gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, eq, un, un}, // 19
|
||||
{un, un, un, un, un, un, un, un, un, un, un, un, un, un, un, un, un, un, un, un, un, un}, // 20
|
||||
{un, un, un, un, un, un, un, un, un, un, un, un, un, un, un, un, un, un, un, un, un, un}, // 21
|
||||
};
|
||||
std::vector<std::vector<std::partial_ordering>> expected = {
|
||||
//0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
|
||||
{eq, eq, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, un, un}, // 0
|
||||
{eq, eq, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, un, un}, // 1
|
||||
{gt, gt, eq, lt, lt, lt, lt, lt, un, un, lt, lt, gt, gt, lt, lt, lt, lt, lt, lt, un, un}, // 2
|
||||
{gt, gt, gt, eq, gt, gt, gt, gt, un, un, lt, lt, gt, gt, lt, lt, lt, lt, lt, lt, un, un}, // 3
|
||||
{gt, gt, gt, lt, eq, lt, gt, lt, un, un, lt, lt, gt, gt, lt, lt, lt, lt, lt, lt, un, un}, // 4
|
||||
{gt, gt, gt, lt, gt, eq, gt, lt, un, un, lt, lt, gt, gt, lt, lt, lt, lt, lt, lt, un, un}, // 5
|
||||
{gt, gt, gt, lt, lt, lt, eq, lt, un, un, lt, lt, gt, gt, lt, lt, lt, lt, lt, lt, un, un}, // 6
|
||||
{gt, gt, gt, lt, gt, gt, gt, eq, un, un, lt, lt, gt, gt, lt, lt, lt, lt, lt, lt, un, un}, // 7
|
||||
{gt, gt, un, un, un, un, un, un, un, un, lt, lt, gt, gt, lt, lt, lt, lt, lt, lt, un, un}, // 8
|
||||
{gt, gt, un, un, un, un, un, un, un, un, lt, lt, gt, gt, lt, lt, lt, lt, lt, lt, un, un}, // 9
|
||||
{gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, eq, gt, gt, gt, gt, gt, gt, gt, lt, lt, un, un}, // 10
|
||||
{gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, lt, eq, gt, gt, gt, gt, gt, gt, lt, lt, un, un}, // 11
|
||||
{gt, gt, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, eq, gt, lt, lt, lt, lt, lt, lt, un, un}, // 12
|
||||
{gt, gt, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, lt, eq, lt, lt, lt, lt, lt, lt, un, un}, // 13
|
||||
{gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, lt, lt, gt, gt, eq, lt, gt, gt, lt, lt, un, un}, // 14
|
||||
{gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, lt, lt, gt, gt, gt, eq, gt, gt, lt, lt, un, un}, // 15
|
||||
{gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, lt, lt, gt, gt, lt, lt, eq, gt, lt, lt, un, un}, // 16
|
||||
{gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, lt, lt, gt, gt, lt, lt, lt, eq, lt, lt, un, un}, // 17
|
||||
{gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, eq, lt, un, un}, // 18
|
||||
{gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, gt, eq, un, un}, // 19
|
||||
{un, un, un, un, un, un, un, un, un, un, un, un, un, un, un, un, un, un, un, un, un, un}, // 20
|
||||
{un, un, un, un, un, un, un, un, un, un, un, un, un, un, un, un, un, un, un, un, un, un}, // 21
|
||||
};
|
||||
|
||||
// check expected partial_ordering against expected booleans
|
||||
REQUIRE(expected.size() == expected_eq.size());
|
||||
|
||||
@@ -52,8 +52,7 @@ TEST_CASE("concepts")
|
||||
// X::size_type must return an unsigned integer
|
||||
CHECK((std::is_unsigned<json::size_type>::value));
|
||||
// X::size_type can represent any non-negative value of X::difference_type
|
||||
CHECK(static_cast<json::size_type>((std::numeric_limits<json::difference_type>::max)()) <=
|
||||
(std::numeric_limits<json::size_type>::max)());
|
||||
CHECK(static_cast<json::size_type>((std::numeric_limits<json::difference_type>::max)()) <= (std::numeric_limits<json::size_type>::max)());
|
||||
|
||||
// the expression "X u" has the post-condition "u.empty()"
|
||||
{
|
||||
|
||||
@@ -173,7 +173,12 @@ TEST_CASE("constructors")
|
||||
|
||||
SECTION("std::multimap<json::string_t, json>")
|
||||
{
|
||||
std::multimap<json::string_t, json> const o{{"a", json(1)}, {"b", json(1u)}, {"c", json(2.2)}, {"d", json(false)}, {"e", json("string")}, {"f", json()}};
|
||||
std::multimap<json::string_t, json> const o{{"a", json(1)},
|
||||
{"b", json(1u)},
|
||||
{"c", json(2.2)},
|
||||
{"d", json(false)},
|
||||
{"e", json("string")},
|
||||
{"f", json()}};
|
||||
json const j(o);
|
||||
CHECK(j.type() == json::value_t::object);
|
||||
CHECK(j == j_reference);
|
||||
@@ -181,7 +186,12 @@ TEST_CASE("constructors")
|
||||
|
||||
SECTION("std::unordered_map<json::string_t, json>")
|
||||
{
|
||||
std::unordered_map<json::string_t, json> const o{{"a", json(1)}, {"b", json(1u)}, {"c", json(2.2)}, {"d", json(false)}, {"e", json("string")}, {"f", json()}};
|
||||
std::unordered_map<json::string_t, json> const o{{"a", json(1)},
|
||||
{"b", json(1u)},
|
||||
{"c", json(2.2)},
|
||||
{"d", json(false)},
|
||||
{"e", json("string")},
|
||||
{"f", json()}};
|
||||
json const j(o);
|
||||
CHECK(j.type() == json::value_t::object);
|
||||
CHECK(j == j_reference);
|
||||
@@ -189,7 +199,12 @@ TEST_CASE("constructors")
|
||||
|
||||
SECTION("std::unordered_multimap<json::string_t, json>")
|
||||
{
|
||||
std::unordered_multimap<json::string_t, json> const o{{"a", json(1)}, {"b", json(1u)}, {"c", json(2.2)}, {"d", json(false)}, {"e", json("string")}, {"f", json()}};
|
||||
std::unordered_multimap<json::string_t, json> const o{{"a", json(1)},
|
||||
{"b", json(1u)},
|
||||
{"c", json(2.2)},
|
||||
{"d", json(false)},
|
||||
{"e", json("string")},
|
||||
{"f", json()}};
|
||||
json const j(o);
|
||||
CHECK(j.type() == json::value_t::object);
|
||||
CHECK(j == j_reference);
|
||||
@@ -1083,7 +1098,9 @@ TEST_CASE("constructors")
|
||||
SECTION("object with error")
|
||||
{
|
||||
json _;
|
||||
CHECK_THROWS_WITH_AS(_ = json::object({{"one", 1}, {"two", 1u}, {"three", 2.2}, {"four", false}, 13}), "[json.exception.type_error.301] cannot create object from initializer list", json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(_ = json::object({{"one", 1}, {"two", 1u}, {"three", 2.2}, {"four", false}, 13}),
|
||||
"[json.exception.type_error.301] cannot create object from initializer list",
|
||||
json::type_error&);
|
||||
}
|
||||
|
||||
SECTION("empty array")
|
||||
@@ -1328,14 +1345,22 @@ TEST_CASE("constructors")
|
||||
{
|
||||
json jobject = {{"a", "a"}, {"b", 1}, {"c", 17u}, {"d", false}, {"e", true}};
|
||||
json jobject2 = {{"a", "a"}, {"b", 1}, {"c", 17u}};
|
||||
CHECK_THROWS_WITH_AS(json(jobject.begin(), jobject2.end()), "[json.exception.invalid_iterator.201] iterators are not compatible", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(json(jobject2.begin(), jobject.end()), "[json.exception.invalid_iterator.201] iterators are not compatible", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(json(jobject.begin(), jobject2.end()),
|
||||
"[json.exception.invalid_iterator.201] iterators are not compatible",
|
||||
json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(json(jobject2.begin(), jobject.end()),
|
||||
"[json.exception.invalid_iterator.201] iterators are not compatible",
|
||||
json::invalid_iterator&);
|
||||
}
|
||||
{
|
||||
json const jobject = {{"a", "a"}, {"b", 1}, {"c", 17u}, {"d", false}, {"e", true}};
|
||||
json const jobject2 = {{"a", "a"}, {"b", 1}, {"c", 17u}};
|
||||
CHECK_THROWS_WITH_AS(json(jobject.cbegin(), jobject2.cend()), "[json.exception.invalid_iterator.201] iterators are not compatible", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(json(jobject2.cbegin(), jobject.cend()), "[json.exception.invalid_iterator.201] iterators are not compatible", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(json(jobject.cbegin(), jobject2.cend()),
|
||||
"[json.exception.invalid_iterator.201] iterators are not compatible",
|
||||
json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(json(jobject2.cbegin(), jobject.cend()),
|
||||
"[json.exception.invalid_iterator.201] iterators are not compatible",
|
||||
json::invalid_iterator&);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1389,14 +1414,22 @@ TEST_CASE("constructors")
|
||||
{
|
||||
json jarray = {1, 2, 3, 4};
|
||||
json jarray2 = {2, 3, 4, 5};
|
||||
CHECK_THROWS_WITH_AS(json(jarray.begin(), jarray2.end()), "[json.exception.invalid_iterator.201] iterators are not compatible", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(json(jarray2.begin(), jarray.end()), "[json.exception.invalid_iterator.201] iterators are not compatible", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(json(jarray.begin(), jarray2.end()),
|
||||
"[json.exception.invalid_iterator.201] iterators are not compatible",
|
||||
json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(json(jarray2.begin(), jarray.end()),
|
||||
"[json.exception.invalid_iterator.201] iterators are not compatible",
|
||||
json::invalid_iterator&);
|
||||
}
|
||||
{
|
||||
json const jarray = {1, 2, 3, 4};
|
||||
json const jarray2 = {2, 3, 4, 5};
|
||||
CHECK_THROWS_WITH_AS(json(jarray.cbegin(), jarray2.cend()), "[json.exception.invalid_iterator.201] iterators are not compatible", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(json(jarray2.cbegin(), jarray.cend()), "[json.exception.invalid_iterator.201] iterators are not compatible", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(json(jarray.cbegin(), jarray2.cend()),
|
||||
"[json.exception.invalid_iterator.201] iterators are not compatible",
|
||||
json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(json(jarray2.cbegin(), jarray.cend()),
|
||||
"[json.exception.invalid_iterator.201] iterators are not compatible",
|
||||
json::invalid_iterator&);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1409,11 +1442,15 @@ TEST_CASE("constructors")
|
||||
{
|
||||
{
|
||||
json j;
|
||||
CHECK_THROWS_WITH_AS(json(j.begin(), j.end()), "[json.exception.invalid_iterator.206] cannot construct with iterators from null", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(json(j.begin(), j.end()),
|
||||
"[json.exception.invalid_iterator.206] cannot construct with iterators from null",
|
||||
json::invalid_iterator&);
|
||||
}
|
||||
{
|
||||
json const j;
|
||||
CHECK_THROWS_WITH_AS(json(j.cbegin(), j.cend()), "[json.exception.invalid_iterator.206] cannot construct with iterators from null", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(json(j.cbegin(), j.cend()),
|
||||
"[json.exception.invalid_iterator.206] cannot construct with iterators from null",
|
||||
json::invalid_iterator&);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1509,12 +1546,16 @@ TEST_CASE("constructors")
|
||||
{
|
||||
json j = "foo";
|
||||
CHECK_THROWS_WITH_AS(json(j.end(), j.end()), "[json.exception.invalid_iterator.204] iterators out of range", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(json(j.begin(), j.begin()), "[json.exception.invalid_iterator.204] iterators out of range", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(json(j.begin(), j.begin()),
|
||||
"[json.exception.invalid_iterator.204] iterators out of range",
|
||||
json::invalid_iterator&);
|
||||
}
|
||||
{
|
||||
json const j = "bar";
|
||||
CHECK_THROWS_WITH_AS(json(j.cend(), j.cend()), "[json.exception.invalid_iterator.204] iterators out of range", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(json(j.cbegin(), j.cbegin()), "[json.exception.invalid_iterator.204] iterators out of range", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(json(j.cbegin(), j.cbegin()),
|
||||
"[json.exception.invalid_iterator.204] iterators out of range",
|
||||
json::invalid_iterator&);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1523,12 +1564,16 @@ TEST_CASE("constructors")
|
||||
{
|
||||
json j = false;
|
||||
CHECK_THROWS_WITH_AS(json(j.end(), j.end()), "[json.exception.invalid_iterator.204] iterators out of range", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(json(j.begin(), j.begin()), "[json.exception.invalid_iterator.204] iterators out of range", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(json(j.begin(), j.begin()),
|
||||
"[json.exception.invalid_iterator.204] iterators out of range",
|
||||
json::invalid_iterator&);
|
||||
}
|
||||
{
|
||||
json const j = true;
|
||||
CHECK_THROWS_WITH_AS(json(j.cend(), j.cend()), "[json.exception.invalid_iterator.204] iterators out of range", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(json(j.cbegin(), j.cbegin()), "[json.exception.invalid_iterator.204] iterators out of range", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(json(j.cbegin(), j.cbegin()),
|
||||
"[json.exception.invalid_iterator.204] iterators out of range",
|
||||
json::invalid_iterator&);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1537,12 +1582,16 @@ TEST_CASE("constructors")
|
||||
{
|
||||
json j = 17;
|
||||
CHECK_THROWS_WITH_AS(json(j.end(), j.end()), "[json.exception.invalid_iterator.204] iterators out of range", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(json(j.begin(), j.begin()), "[json.exception.invalid_iterator.204] iterators out of range", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(json(j.begin(), j.begin()),
|
||||
"[json.exception.invalid_iterator.204] iterators out of range",
|
||||
json::invalid_iterator&);
|
||||
}
|
||||
{
|
||||
json const j = 17;
|
||||
CHECK_THROWS_WITH_AS(json(j.cend(), j.cend()), "[json.exception.invalid_iterator.204] iterators out of range", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(json(j.cbegin(), j.cbegin()), "[json.exception.invalid_iterator.204] iterators out of range", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(json(j.cbegin(), j.cbegin()),
|
||||
"[json.exception.invalid_iterator.204] iterators out of range",
|
||||
json::invalid_iterator&);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1551,12 +1600,16 @@ TEST_CASE("constructors")
|
||||
{
|
||||
json j = 17u;
|
||||
CHECK_THROWS_WITH_AS(json(j.end(), j.end()), "[json.exception.invalid_iterator.204] iterators out of range", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(json(j.begin(), j.begin()), "[json.exception.invalid_iterator.204] iterators out of range", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(json(j.begin(), j.begin()),
|
||||
"[json.exception.invalid_iterator.204] iterators out of range",
|
||||
json::invalid_iterator&);
|
||||
}
|
||||
{
|
||||
json const j = 17u;
|
||||
CHECK_THROWS_WITH_AS(json(j.cend(), j.cend()), "[json.exception.invalid_iterator.204] iterators out of range", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(json(j.cbegin(), j.cbegin()), "[json.exception.invalid_iterator.204] iterators out of range", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(json(j.cbegin(), j.cbegin()),
|
||||
"[json.exception.invalid_iterator.204] iterators out of range",
|
||||
json::invalid_iterator&);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1565,12 +1618,16 @@ TEST_CASE("constructors")
|
||||
{
|
||||
json j = 23.42;
|
||||
CHECK_THROWS_WITH_AS(json(j.end(), j.end()), "[json.exception.invalid_iterator.204] iterators out of range", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(json(j.begin(), j.begin()), "[json.exception.invalid_iterator.204] iterators out of range", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(json(j.begin(), j.begin()),
|
||||
"[json.exception.invalid_iterator.204] iterators out of range",
|
||||
json::invalid_iterator&);
|
||||
}
|
||||
{
|
||||
json const j = 23.42;
|
||||
CHECK_THROWS_WITH_AS(json(j.cend(), j.cend()), "[json.exception.invalid_iterator.204] iterators out of range", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(json(j.cbegin(), j.cbegin()), "[json.exception.invalid_iterator.204] iterators out of range", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(json(j.cbegin(), j.cbegin()),
|
||||
"[json.exception.invalid_iterator.204] iterators out of range",
|
||||
json::invalid_iterator&);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,8 @@ using nlohmann::json;
|
||||
|
||||
#include <sstream>
|
||||
|
||||
namespace {
|
||||
namespace
|
||||
{
|
||||
struct alt_string_iter
|
||||
{
|
||||
alt_string_iter() = default;
|
||||
|
||||
+162
-276
@@ -36,12 +36,8 @@ TEST_CASE("value conversion")
|
||||
{
|
||||
SECTION("get an object (explicit)")
|
||||
{
|
||||
const json::object_t o_reference = {{"object", json::object()},
|
||||
{"array", {1, 2, 3, 4}},
|
||||
{"number", 42},
|
||||
{"boolean", false},
|
||||
{"null", nullptr},
|
||||
{"string", "Hello world"}};
|
||||
const json::object_t o_reference =
|
||||
{{"object", json::object()}, {"array", {1, 2, 3, 4}}, {"number", 42}, {"boolean", false}, {"null", nullptr}, {"string", "Hello world"}};
|
||||
json j(o_reference);
|
||||
|
||||
SECTION("json::object_t")
|
||||
@@ -52,73 +48,59 @@ TEST_CASE("value conversion")
|
||||
|
||||
SECTION("std::map<json::string_t, json>")
|
||||
{
|
||||
const std::map<json::string_t, json> o =
|
||||
j.get<std::map<json::string_t, json>>();
|
||||
const std::map<json::string_t, json> o = j.get<std::map<json::string_t, json>>();
|
||||
CHECK(json(o) == j);
|
||||
}
|
||||
|
||||
SECTION("std::multimap<json::string_t, json>")
|
||||
{
|
||||
const std::multimap<json::string_t, json> o =
|
||||
j.get<std::multimap<json::string_t, json>>();
|
||||
const std::multimap<json::string_t, json> o = j.get<std::multimap<json::string_t, json>>();
|
||||
CHECK(json(o) == j);
|
||||
}
|
||||
|
||||
SECTION("std::unordered_map<json::string_t, json>")
|
||||
{
|
||||
const std::unordered_map<json::string_t, json> o =
|
||||
j.get<std::unordered_map<json::string_t, json>>();
|
||||
const std::unordered_map<json::string_t, json> o = j.get<std::unordered_map<json::string_t, json>>();
|
||||
CHECK(json(o) == j);
|
||||
}
|
||||
|
||||
SECTION("std::unordered_multimap<json::string_t, json>")
|
||||
{
|
||||
const std::unordered_multimap<json::string_t, json> o =
|
||||
j.get<std::unordered_multimap<json::string_t, json>>();
|
||||
const std::unordered_multimap<json::string_t, json> o = j.get<std::unordered_multimap<json::string_t, json>>();
|
||||
CHECK(json(o) == j);
|
||||
}
|
||||
|
||||
SECTION("exception in case of a non-object type")
|
||||
{
|
||||
CHECK_THROWS_WITH_AS(
|
||||
json(json::value_t::null).get<json::object_t>(),
|
||||
"[json.exception.type_error.302] type must be object, but is null",
|
||||
json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
json(json::value_t::array).get<json::object_t>(),
|
||||
"[json.exception.type_error.302] type must be object, but is array",
|
||||
json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
json(json::value_t::string).get<json::object_t>(),
|
||||
"[json.exception.type_error.302] type must be object, but is string",
|
||||
json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(json(json::value_t::null).get<json::object_t>(),
|
||||
"[json.exception.type_error.302] type must be object, but is null",
|
||||
json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(json(json::value_t::array).get<json::object_t>(),
|
||||
"[json.exception.type_error.302] type must be object, but is array",
|
||||
json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(json(json::value_t::string).get<json::object_t>(),
|
||||
"[json.exception.type_error.302] type must be object, but is string",
|
||||
json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(json(json::value_t::boolean).get<json::object_t>(),
|
||||
"[json.exception.type_error.302] type must be object, "
|
||||
"but is boolean",
|
||||
json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
json(json::value_t::number_integer).get<json::object_t>(),
|
||||
"[json.exception.type_error.302] type must be object, but is number",
|
||||
json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
json(json::value_t::number_unsigned).get<json::object_t>(),
|
||||
"[json.exception.type_error.302] type must be object, but is number",
|
||||
json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
json(json::value_t::number_float).get<json::object_t>(),
|
||||
"[json.exception.type_error.302] type must be object, but is number",
|
||||
json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(json(json::value_t::number_integer).get<json::object_t>(),
|
||||
"[json.exception.type_error.302] type must be object, but is number",
|
||||
json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(json(json::value_t::number_unsigned).get<json::object_t>(),
|
||||
"[json.exception.type_error.302] type must be object, but is number",
|
||||
json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(json(json::value_t::number_float).get<json::object_t>(),
|
||||
"[json.exception.type_error.302] type must be object, but is number",
|
||||
json::type_error&);
|
||||
}
|
||||
}
|
||||
|
||||
SECTION("get an object (explicit, get_to)")
|
||||
{
|
||||
const json::object_t o_reference = {{"object", json::object()},
|
||||
{"array", {1, 2, 3, 4}},
|
||||
{"number", 42},
|
||||
{"boolean", false},
|
||||
{"null", nullptr},
|
||||
{"string", "Hello world"}};
|
||||
const json::object_t o_reference =
|
||||
{{"object", json::object()}, {"array", {1, 2, 3, 4}}, {"number", 42}, {"boolean", false}, {"null", nullptr}, {"string", "Hello world"}};
|
||||
json j(o_reference);
|
||||
|
||||
SECTION("json::object_t")
|
||||
@@ -160,12 +142,8 @@ TEST_CASE("value conversion")
|
||||
#if JSON_USE_IMPLICIT_CONVERSIONS
|
||||
SECTION("get an object (implicit)")
|
||||
{
|
||||
const json::object_t o_reference = {{"object", json::object()},
|
||||
{"array", {1, 2, 3, 4}},
|
||||
{"number", 42},
|
||||
{"boolean", false},
|
||||
{"null", nullptr},
|
||||
{"string", "Hello world"}};
|
||||
const json::object_t o_reference =
|
||||
{{"object", json::object()}, {"array", {1, 2, 3, 4}}, {"number", 42}, {"boolean", false}, {"null", nullptr}, {"string", "Hello world"}};
|
||||
json j(o_reference);
|
||||
|
||||
SECTION("json::object_t")
|
||||
@@ -222,10 +200,9 @@ TEST_CASE("value conversion")
|
||||
const std::forward_list<json> a = j.get<std::forward_list<json>>();
|
||||
CHECK(json(a) == j);
|
||||
|
||||
CHECK_THROWS_WITH_AS(
|
||||
json(json::value_t::null).get<std::forward_list<json>>(),
|
||||
"[json.exception.type_error.302] type must be array, but is null",
|
||||
json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(json(json::value_t::null).get<std::forward_list<json>>(),
|
||||
"[json.exception.type_error.302] type must be array, but is null",
|
||||
json::type_error&);
|
||||
}
|
||||
|
||||
SECTION("std::vector<json>")
|
||||
@@ -233,10 +210,9 @@ TEST_CASE("value conversion")
|
||||
const std::vector<json> a = j.get<std::vector<json>>();
|
||||
CHECK(json(a) == j);
|
||||
|
||||
CHECK_THROWS_WITH_AS(
|
||||
json(json::value_t::null).get<std::vector<json>>(),
|
||||
"[json.exception.type_error.302] type must be array, but is null",
|
||||
json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(json(json::value_t::null).get<std::vector<json>>(),
|
||||
"[json.exception.type_error.302] type must be array, but is null",
|
||||
json::type_error&);
|
||||
|
||||
#if !defined(JSON_NOEXCEPTION)
|
||||
SECTION("reserve is called on containers that supports it")
|
||||
@@ -271,38 +247,30 @@ TEST_CASE("value conversion")
|
||||
|
||||
SECTION("exception in case of a non-array type")
|
||||
{
|
||||
CHECK_THROWS_WITH_AS(
|
||||
json(json::value_t::object).get<std::vector<int>>(),
|
||||
"[json.exception.type_error.302] type must be array, but is object",
|
||||
json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
json(json::value_t::null).get<json::array_t>(),
|
||||
"[json.exception.type_error.302] type must be array, but is null",
|
||||
json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
json(json::value_t::object).get<json::array_t>(),
|
||||
"[json.exception.type_error.302] type must be array, but is object",
|
||||
json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
json(json::value_t::string).get<json::array_t>(),
|
||||
"[json.exception.type_error.302] type must be array, but is string",
|
||||
json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
json(json::value_t::boolean).get<json::array_t>(),
|
||||
"[json.exception.type_error.302] type must be array, but is boolean",
|
||||
json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
json(json::value_t::number_integer).get<json::array_t>(),
|
||||
"[json.exception.type_error.302] type must be array, but is number",
|
||||
json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
json(json::value_t::number_unsigned).get<json::array_t>(),
|
||||
"[json.exception.type_error.302] type must be array, but is number",
|
||||
json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
json(json::value_t::number_float).get<json::array_t>(),
|
||||
"[json.exception.type_error.302] type must be array, but is number",
|
||||
json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(json(json::value_t::object).get<std::vector<int>>(),
|
||||
"[json.exception.type_error.302] type must be array, but is object",
|
||||
json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(json(json::value_t::null).get<json::array_t>(),
|
||||
"[json.exception.type_error.302] type must be array, but is null",
|
||||
json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(json(json::value_t::object).get<json::array_t>(),
|
||||
"[json.exception.type_error.302] type must be array, but is object",
|
||||
json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(json(json::value_t::string).get<json::array_t>(),
|
||||
"[json.exception.type_error.302] type must be array, but is string",
|
||||
json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(json(json::value_t::boolean).get<json::array_t>(),
|
||||
"[json.exception.type_error.302] type must be array, but is boolean",
|
||||
json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(json(json::value_t::number_integer).get<json::array_t>(),
|
||||
"[json.exception.type_error.302] type must be array, but is number",
|
||||
json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(json(json::value_t::number_unsigned).get<json::array_t>(),
|
||||
"[json.exception.type_error.302] type must be array, but is number",
|
||||
json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(json(json::value_t::number_float).get<json::array_t>(),
|
||||
"[json.exception.type_error.302] type must be array, but is number",
|
||||
json::type_error&);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -428,34 +396,28 @@ TEST_CASE("value conversion")
|
||||
|
||||
SECTION("exception in case of a non-string type")
|
||||
{
|
||||
CHECK_THROWS_WITH_AS(
|
||||
json(json::value_t::null).get<json::string_t>(),
|
||||
"[json.exception.type_error.302] type must be string, but is null",
|
||||
json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
json(json::value_t::object).get<json::string_t>(),
|
||||
"[json.exception.type_error.302] type must be string, but is object",
|
||||
json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
json(json::value_t::array).get<json::string_t>(),
|
||||
"[json.exception.type_error.302] type must be string, but is array",
|
||||
json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(json(json::value_t::null).get<json::string_t>(),
|
||||
"[json.exception.type_error.302] type must be string, but is null",
|
||||
json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(json(json::value_t::object).get<json::string_t>(),
|
||||
"[json.exception.type_error.302] type must be string, but is object",
|
||||
json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(json(json::value_t::array).get<json::string_t>(),
|
||||
"[json.exception.type_error.302] type must be string, but is array",
|
||||
json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(json(json::value_t::boolean).get<json::string_t>(),
|
||||
"[json.exception.type_error.302] type must be string, "
|
||||
"but is boolean",
|
||||
json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
json(json::value_t::number_integer).get<json::string_t>(),
|
||||
"[json.exception.type_error.302] type must be string, but is number",
|
||||
json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
json(json::value_t::number_unsigned).get<json::string_t>(),
|
||||
"[json.exception.type_error.302] type must be string, but is number",
|
||||
json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
json(json::value_t::number_float).get<json::string_t>(),
|
||||
"[json.exception.type_error.302] type must be string, but is number",
|
||||
json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(json(json::value_t::number_integer).get<json::string_t>(),
|
||||
"[json.exception.type_error.302] type must be string, but is number",
|
||||
json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(json(json::value_t::number_unsigned).get<json::string_t>(),
|
||||
"[json.exception.type_error.302] type must be string, but is number",
|
||||
json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(json(json::value_t::number_float).get<json::string_t>(),
|
||||
"[json.exception.type_error.302] type must be string, but is number",
|
||||
json::type_error&);
|
||||
}
|
||||
|
||||
#if defined(JSON_HAS_CPP_17)
|
||||
@@ -599,40 +561,34 @@ TEST_CASE("value conversion")
|
||||
|
||||
SECTION("exception in case of a non-number type")
|
||||
{
|
||||
CHECK_THROWS_AS(json(json::value_t::string).get<uint8_t>(),
|
||||
json::type_error&);
|
||||
CHECK_THROWS_AS(json(json::value_t::string).get<uint8_t>(), json::type_error&);
|
||||
|
||||
CHECK_THROWS_WITH_AS(
|
||||
json(json::value_t::null).get<json::boolean_t>(),
|
||||
"[json.exception.type_error.302] type must be boolean, but is null",
|
||||
json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(json(json::value_t::null).get<json::boolean_t>(),
|
||||
"[json.exception.type_error.302] type must be boolean, but is null",
|
||||
json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(json(json::value_t::object).get<json::boolean_t>(),
|
||||
"[json.exception.type_error.302] type must be boolean, "
|
||||
"but is object",
|
||||
json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
json(json::value_t::array).get<json::boolean_t>(),
|
||||
"[json.exception.type_error.302] type must be boolean, but is array",
|
||||
json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(json(json::value_t::array).get<json::boolean_t>(),
|
||||
"[json.exception.type_error.302] type must be boolean, but is array",
|
||||
json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(json(json::value_t::string).get<json::boolean_t>(),
|
||||
"[json.exception.type_error.302] type must be boolean, "
|
||||
"but is string",
|
||||
json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
json(json::value_t::number_integer).get<json::boolean_t>(),
|
||||
"[json.exception.type_error.302] type must be boolean, but is "
|
||||
"number",
|
||||
json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
json(json::value_t::number_unsigned).get<json::boolean_t>(),
|
||||
"[json.exception.type_error.302] type must be boolean, but is "
|
||||
"number",
|
||||
json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
json(json::value_t::number_float).get<json::boolean_t>(),
|
||||
"[json.exception.type_error.302] type must be boolean, but is "
|
||||
"number",
|
||||
json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(json(json::value_t::number_integer).get<json::boolean_t>(),
|
||||
"[json.exception.type_error.302] type must be boolean, but is "
|
||||
"number",
|
||||
json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(json(json::value_t::number_unsigned).get<json::boolean_t>(),
|
||||
"[json.exception.type_error.302] type must be boolean, but is "
|
||||
"number",
|
||||
json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(json(json::value_t::number_float).get<json::boolean_t>(),
|
||||
"[json.exception.type_error.302] type must be boolean, but is "
|
||||
"number",
|
||||
json::type_error&);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -869,32 +825,25 @@ TEST_CASE("value conversion")
|
||||
|
||||
SECTION("exception in case of a non-number type")
|
||||
{
|
||||
CHECK_THROWS_WITH_AS(
|
||||
json(json::value_t::null).get<json::number_integer_t>(),
|
||||
"[json.exception.type_error.302] type must be number, but is null",
|
||||
json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
json(json::value_t::object).get<json::number_integer_t>(),
|
||||
"[json.exception.type_error.302] type must be number, but is object",
|
||||
json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
json(json::value_t::array).get<json::number_integer_t>(),
|
||||
"[json.exception.type_error.302] type must be number, but is array",
|
||||
json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
json(json::value_t::string).get<json::number_integer_t>(),
|
||||
"[json.exception.type_error.302] type must be number, but is string",
|
||||
json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
json(json::value_t::boolean).get<json::number_integer_t>(),
|
||||
"[json.exception.type_error.302] type must be number, but is "
|
||||
"boolean",
|
||||
json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(json(json::value_t::null).get<json::number_integer_t>(),
|
||||
"[json.exception.type_error.302] type must be number, but is null",
|
||||
json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(json(json::value_t::object).get<json::number_integer_t>(),
|
||||
"[json.exception.type_error.302] type must be number, but is object",
|
||||
json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(json(json::value_t::array).get<json::number_integer_t>(),
|
||||
"[json.exception.type_error.302] type must be number, but is array",
|
||||
json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(json(json::value_t::string).get<json::number_integer_t>(),
|
||||
"[json.exception.type_error.302] type must be number, but is string",
|
||||
json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(json(json::value_t::boolean).get<json::number_integer_t>(),
|
||||
"[json.exception.type_error.302] type must be number, but is "
|
||||
"boolean",
|
||||
json::type_error&);
|
||||
|
||||
CHECK_NOTHROW(
|
||||
json(json::value_t::number_float).get<json::number_integer_t>());
|
||||
CHECK_NOTHROW(
|
||||
json(json::value_t::number_float).get<json::number_unsigned_t>());
|
||||
CHECK_NOTHROW(json(json::value_t::number_float).get<json::number_integer_t>());
|
||||
CHECK_NOTHROW(json(json::value_t::number_float).get<json::number_unsigned_t>());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1137,32 +1086,25 @@ TEST_CASE("value conversion")
|
||||
|
||||
SECTION("exception in case of a non-string type")
|
||||
{
|
||||
CHECK_THROWS_WITH_AS(
|
||||
json(json::value_t::null).get<json::number_float_t>(),
|
||||
"[json.exception.type_error.302] type must be number, but is null",
|
||||
json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
json(json::value_t::object).get<json::number_float_t>(),
|
||||
"[json.exception.type_error.302] type must be number, but is object",
|
||||
json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
json(json::value_t::array).get<json::number_float_t>(),
|
||||
"[json.exception.type_error.302] type must be number, but is array",
|
||||
json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
json(json::value_t::string).get<json::number_float_t>(),
|
||||
"[json.exception.type_error.302] type must be number, but is string",
|
||||
json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
json(json::value_t::boolean).get<json::number_float_t>(),
|
||||
"[json.exception.type_error.302] type must be number, but is "
|
||||
"boolean",
|
||||
json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(json(json::value_t::null).get<json::number_float_t>(),
|
||||
"[json.exception.type_error.302] type must be number, but is null",
|
||||
json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(json(json::value_t::object).get<json::number_float_t>(),
|
||||
"[json.exception.type_error.302] type must be number, but is object",
|
||||
json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(json(json::value_t::array).get<json::number_float_t>(),
|
||||
"[json.exception.type_error.302] type must be number, but is array",
|
||||
json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(json(json::value_t::string).get<json::number_float_t>(),
|
||||
"[json.exception.type_error.302] type must be number, but is string",
|
||||
json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(json(json::value_t::boolean).get<json::number_float_t>(),
|
||||
"[json.exception.type_error.302] type must be number, but is "
|
||||
"boolean",
|
||||
json::type_error&);
|
||||
|
||||
CHECK_NOTHROW(
|
||||
json(json::value_t::number_integer).get<json::number_float_t>());
|
||||
CHECK_NOTHROW(
|
||||
json(json::value_t::number_unsigned).get<json::number_float_t>());
|
||||
CHECK_NOTHROW(json(json::value_t::number_integer).get<json::number_float_t>());
|
||||
CHECK_NOTHROW(json(json::value_t::number_unsigned).get<json::number_float_t>());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1232,69 +1174,31 @@ TEST_CASE("value conversion")
|
||||
const json j_string_const(json::value_t::string);
|
||||
const json j_boolean_const(json::value_t::boolean);
|
||||
|
||||
CHECK_THROWS_WITH_AS(j_null.get<json::binary_t>(),
|
||||
"[json.exception.type_error.302] type must be binary, but is null",
|
||||
json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_object.get<json::binary_t>(),
|
||||
"[json.exception.type_error.302] type must be binary, but is object",
|
||||
json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_array.get<json::binary_t>(),
|
||||
"[json.exception.type_error.302] type must be binary, but is array",
|
||||
json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_string.get<json::binary_t>(),
|
||||
"[json.exception.type_error.302] type must be binary, but is string",
|
||||
json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_boolean.get<json::binary_t>(),
|
||||
"[json.exception.type_error.302] type must be binary, but is boolean",
|
||||
json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_null.get<json::binary_t>(), "[json.exception.type_error.302] type must be binary, but is null", json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_object.get<json::binary_t>(), "[json.exception.type_error.302] type must be binary, but is object", json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_array.get<json::binary_t>(), "[json.exception.type_error.302] type must be binary, but is array", json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_string.get<json::binary_t>(), "[json.exception.type_error.302] type must be binary, but is string", json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_boolean.get<json::binary_t>(), "[json.exception.type_error.302] type must be binary, but is boolean", json::type_error&);
|
||||
|
||||
CHECK_THROWS_WITH_AS(j_null_const.get<json::binary_t>(),
|
||||
"[json.exception.type_error.302] type must be binary, but is null",
|
||||
json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_object_const.get<json::binary_t>(),
|
||||
"[json.exception.type_error.302] type must be binary, but is object",
|
||||
json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_array_const.get<json::binary_t>(),
|
||||
"[json.exception.type_error.302] type must be binary, but is array",
|
||||
json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_string_const.get<json::binary_t>(),
|
||||
"[json.exception.type_error.302] type must be binary, but is string",
|
||||
json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_null_const.get<json::binary_t>(), "[json.exception.type_error.302] type must be binary, but is null", json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_object_const.get<json::binary_t>(), "[json.exception.type_error.302] type must be binary, but is object", json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_array_const.get<json::binary_t>(), "[json.exception.type_error.302] type must be binary, but is array", json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_string_const.get<json::binary_t>(), "[json.exception.type_error.302] type must be binary, but is string", json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_boolean_const.get<json::binary_t>(),
|
||||
"[json.exception.type_error.302] type must be binary, but is boolean",
|
||||
json::type_error&);
|
||||
|
||||
CHECK_THROWS_WITH_AS(j_null.get_binary(),
|
||||
"[json.exception.type_error.302] type must be binary, but is null",
|
||||
json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_object.get_binary(),
|
||||
"[json.exception.type_error.302] type must be binary, but is object",
|
||||
json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_array.get_binary(),
|
||||
"[json.exception.type_error.302] type must be binary, but is array",
|
||||
json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_string.get_binary(),
|
||||
"[json.exception.type_error.302] type must be binary, but is string",
|
||||
json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_boolean.get_binary(),
|
||||
"[json.exception.type_error.302] type must be binary, but is boolean",
|
||||
json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_null.get_binary(), "[json.exception.type_error.302] type must be binary, but is null", json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_object.get_binary(), "[json.exception.type_error.302] type must be binary, but is object", json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_array.get_binary(), "[json.exception.type_error.302] type must be binary, but is array", json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_string.get_binary(), "[json.exception.type_error.302] type must be binary, but is string", json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_boolean.get_binary(), "[json.exception.type_error.302] type must be binary, but is boolean", json::type_error&);
|
||||
|
||||
CHECK_THROWS_WITH_AS(j_null_const.get_binary(),
|
||||
"[json.exception.type_error.302] type must be binary, but is null",
|
||||
json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_object_const.get_binary(),
|
||||
"[json.exception.type_error.302] type must be binary, but is object",
|
||||
json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_array_const.get_binary(),
|
||||
"[json.exception.type_error.302] type must be binary, but is array",
|
||||
json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_string_const.get_binary(),
|
||||
"[json.exception.type_error.302] type must be binary, but is string",
|
||||
json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_boolean_const.get_binary(),
|
||||
"[json.exception.type_error.302] type must be binary, but is boolean",
|
||||
json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_null_const.get_binary(), "[json.exception.type_error.302] type must be binary, but is null", json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_object_const.get_binary(), "[json.exception.type_error.302] type must be binary, but is object", json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_array_const.get_binary(), "[json.exception.type_error.302] type must be binary, but is array", json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_string_const.get_binary(), "[json.exception.type_error.302] type must be binary, but is string", json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_boolean_const.get_binary(), "[json.exception.type_error.302] type must be binary, but is boolean", json::type_error&);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1380,10 +1284,9 @@ TEST_CASE("value conversion")
|
||||
|
||||
SECTION("exception in case of a non-object type")
|
||||
{
|
||||
CHECK_THROWS_WITH_AS(
|
||||
(json().get<std::map<std::string, int>>()),
|
||||
"[json.exception.type_error.302] type must be object, but is null",
|
||||
json::type_error&);
|
||||
CHECK_THROWS_WITH_AS((json().get<std::map<std::string, int>>()),
|
||||
"[json.exception.type_error.302] type must be object, but is null",
|
||||
json::type_error&);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1424,8 +1327,9 @@ TEST_CASE("value conversion")
|
||||
SECTION("std::array is larger than JSON")
|
||||
{
|
||||
std::array<int, 6> arr6 = {{1, 2, 3, 4, 5, 6}};
|
||||
CHECK_THROWS_WITH_AS(j1.get_to(arr6), "[json.exception.out_of_range.401] "
|
||||
"array index 4 is out of range",
|
||||
CHECK_THROWS_WITH_AS(j1.get_to(arr6),
|
||||
"[json.exception.out_of_range.401] "
|
||||
"array index 4 is out of range",
|
||||
json::out_of_range&);
|
||||
}
|
||||
|
||||
@@ -1541,30 +1445,12 @@ TEST_CASE("value conversion")
|
||||
{
|
||||
// does type really must be an array? or it rather must not be null?
|
||||
// that's what I thought when other test like this one broke
|
||||
CHECK_THROWS_WITH_AS(
|
||||
(json().get<std::list<int>>()),
|
||||
"[json.exception.type_error.302] type must be array, but is null",
|
||||
json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
(json().get<std::vector<int>>()),
|
||||
"[json.exception.type_error.302] type must be array, but is null",
|
||||
json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
(json().get<std::vector<json>>()),
|
||||
"[json.exception.type_error.302] type must be array, but is null",
|
||||
json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
(json().get<std::list<json>>()),
|
||||
"[json.exception.type_error.302] type must be array, but is null",
|
||||
json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
(json().get<std::valarray<int>>()),
|
||||
"[json.exception.type_error.302] type must be array, but is null",
|
||||
json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
(json().get<std::map<int, int>>()),
|
||||
"[json.exception.type_error.302] type must be array, but is null",
|
||||
json::type_error&);
|
||||
CHECK_THROWS_WITH_AS((json().get<std::list<int>>()), "[json.exception.type_error.302] type must be array, but is null", json::type_error&);
|
||||
CHECK_THROWS_WITH_AS((json().get<std::vector<int>>()), "[json.exception.type_error.302] type must be array, but is null", json::type_error&);
|
||||
CHECK_THROWS_WITH_AS((json().get<std::vector<json>>()), "[json.exception.type_error.302] type must be array, but is null", json::type_error&);
|
||||
CHECK_THROWS_WITH_AS((json().get<std::list<json>>()), "[json.exception.type_error.302] type must be array, but is null", json::type_error&);
|
||||
CHECK_THROWS_WITH_AS((json().get<std::valarray<int>>()), "[json.exception.type_error.302] type must be array, but is null", json::type_error&);
|
||||
CHECK_THROWS_WITH_AS((json().get<std::map<int, int>>()), "[json.exception.type_error.302] type must be array, but is null", json::type_error&);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,19 +36,17 @@ class json_metadata
|
||||
};
|
||||
|
||||
template<class T>
|
||||
using json_with_metadata =
|
||||
nlohmann::basic_json<
|
||||
std::map,
|
||||
std::vector,
|
||||
std::string,
|
||||
bool,
|
||||
std::int64_t,
|
||||
std::uint64_t,
|
||||
double,
|
||||
std::allocator,
|
||||
nlohmann::adl_serializer,
|
||||
std::vector<std::uint8_t>,
|
||||
json_metadata<T>>;
|
||||
using json_with_metadata = nlohmann::basic_json<std::map,
|
||||
std::vector,
|
||||
std::string,
|
||||
bool,
|
||||
std::int64_t,
|
||||
std::uint64_t,
|
||||
double,
|
||||
std::allocator,
|
||||
nlohmann::adl_serializer,
|
||||
std::vector<std::uint8_t>,
|
||||
json_metadata<T>>;
|
||||
|
||||
TEST_CASE("JSON Node Metadata")
|
||||
{
|
||||
@@ -196,18 +194,17 @@ class visitor_adaptor
|
||||
void do_visit(const Ptr& ptr, const Fnc& fnc) const;
|
||||
};
|
||||
|
||||
using json_with_visitor_t = nlohmann::basic_json<
|
||||
std::map,
|
||||
std::vector,
|
||||
std::string,
|
||||
bool,
|
||||
std::int64_t,
|
||||
std::uint64_t,
|
||||
double,
|
||||
std::allocator,
|
||||
nlohmann::adl_serializer,
|
||||
std::vector<std::uint8_t>,
|
||||
visitor_adaptor>;
|
||||
using json_with_visitor_t = nlohmann::basic_json<std::map,
|
||||
std::vector,
|
||||
std::string,
|
||||
bool,
|
||||
std::int64_t,
|
||||
std::uint64_t,
|
||||
double,
|
||||
std::allocator,
|
||||
nlohmann::adl_serializer,
|
||||
std::vector<std::uint8_t>,
|
||||
visitor_adaptor>;
|
||||
|
||||
template<class Fnc>
|
||||
void visitor_adaptor::visit(const Fnc& fnc) const
|
||||
@@ -261,72 +258,69 @@ TEST_CASE("JSON Visit Node")
|
||||
json["array"].push_back(1);
|
||||
json["array"].push_back(json);
|
||||
|
||||
std::set<std::string> expected{
|
||||
"/null - null - null",
|
||||
"/int - number_integer - -1",
|
||||
"/uint - number_unsigned - 1",
|
||||
"/float - number_float - 1.0",
|
||||
"/boolean - boolean - true",
|
||||
"/string - string - \"string\"",
|
||||
"/array/0 - number_integer - 0",
|
||||
"/array/1 - number_integer - 1",
|
||||
std::set<std::string> expected{"/null - null - null",
|
||||
"/int - number_integer - -1",
|
||||
"/uint - number_unsigned - 1",
|
||||
"/float - number_float - 1.0",
|
||||
"/boolean - boolean - true",
|
||||
"/string - string - \"string\"",
|
||||
"/array/0 - number_integer - 0",
|
||||
"/array/1 - number_integer - 1",
|
||||
|
||||
"/array/2/null - null - null",
|
||||
"/array/2/int - number_integer - -1",
|
||||
"/array/2/uint - number_unsigned - 1",
|
||||
"/array/2/float - number_float - 1.0",
|
||||
"/array/2/boolean - boolean - true",
|
||||
"/array/2/string - string - \"string\"",
|
||||
"/array/2/array/0 - number_integer - 0",
|
||||
"/array/2/array/1 - number_integer - 1"};
|
||||
"/array/2/null - null - null",
|
||||
"/array/2/int - number_integer - -1",
|
||||
"/array/2/uint - number_unsigned - 1",
|
||||
"/array/2/float - number_float - 1.0",
|
||||
"/array/2/boolean - boolean - true",
|
||||
"/array/2/string - string - \"string\"",
|
||||
"/array/2/array/0 - number_integer - 0",
|
||||
"/array/2/array/1 - number_integer - 1"};
|
||||
|
||||
json.visit(
|
||||
[&](const json_with_visitor_t::json_pointer& p,
|
||||
const json_with_visitor_t& j) {
|
||||
std::stringstream str;
|
||||
str << p.to_string() << " - ";
|
||||
using value_t = nlohmann::detail::value_t;
|
||||
switch (j.type())
|
||||
{
|
||||
case value_t::object:
|
||||
str << "object";
|
||||
break;
|
||||
case value_t::array:
|
||||
str << "array";
|
||||
break;
|
||||
case value_t::discarded:
|
||||
str << "discarded";
|
||||
break;
|
||||
case value_t::null:
|
||||
str << "null";
|
||||
break;
|
||||
case value_t::string:
|
||||
str << "string";
|
||||
break;
|
||||
case value_t::boolean:
|
||||
str << "boolean";
|
||||
break;
|
||||
case value_t::number_integer:
|
||||
str << "number_integer";
|
||||
break;
|
||||
case value_t::number_unsigned:
|
||||
str << "number_unsigned";
|
||||
break;
|
||||
case value_t::number_float:
|
||||
str << "number_float";
|
||||
break;
|
||||
case value_t::binary:
|
||||
str << "binary";
|
||||
break;
|
||||
default:
|
||||
str << "error";
|
||||
break;
|
||||
}
|
||||
str << " - " << j.dump();
|
||||
CHECK(json.at(p) == j);
|
||||
INFO(str.str());
|
||||
CHECK(expected.count(str.str()) == 1);
|
||||
expected.erase(str.str());
|
||||
});
|
||||
json.visit([&](const json_with_visitor_t::json_pointer& p, const json_with_visitor_t& j) {
|
||||
std::stringstream str;
|
||||
str << p.to_string() << " - ";
|
||||
using value_t = nlohmann::detail::value_t;
|
||||
switch (j.type())
|
||||
{
|
||||
case value_t::object:
|
||||
str << "object";
|
||||
break;
|
||||
case value_t::array:
|
||||
str << "array";
|
||||
break;
|
||||
case value_t::discarded:
|
||||
str << "discarded";
|
||||
break;
|
||||
case value_t::null:
|
||||
str << "null";
|
||||
break;
|
||||
case value_t::string:
|
||||
str << "string";
|
||||
break;
|
||||
case value_t::boolean:
|
||||
str << "boolean";
|
||||
break;
|
||||
case value_t::number_integer:
|
||||
str << "number_integer";
|
||||
break;
|
||||
case value_t::number_unsigned:
|
||||
str << "number_unsigned";
|
||||
break;
|
||||
case value_t::number_float:
|
||||
str << "number_float";
|
||||
break;
|
||||
case value_t::binary:
|
||||
str << "binary";
|
||||
break;
|
||||
default:
|
||||
str << "error";
|
||||
break;
|
||||
}
|
||||
str << " - " << j.dump();
|
||||
CHECK(json.at(p) == j);
|
||||
INFO(str.str());
|
||||
CHECK(expected.count(str.str()) == 1);
|
||||
expected.erase(str.str());
|
||||
});
|
||||
CHECK(expected.empty());
|
||||
}
|
||||
|
||||
@@ -20,7 +20,8 @@ using namespace nlohmann::literals; // NOLINT(google-build-using-namespace)
|
||||
#include <sstream>
|
||||
#include <valarray>
|
||||
|
||||
namespace {
|
||||
namespace
|
||||
{
|
||||
struct SaxEventLogger : public nlohmann::json_sax<json>
|
||||
{
|
||||
bool null() override
|
||||
@@ -176,8 +177,7 @@ class proxy_iterator
|
||||
using value_type = typename std::iterator_traits<iterator>::value_type;
|
||||
using reference = typename std::iterator_traits<iterator>::reference;
|
||||
using pointer = typename std::iterator_traits<iterator>::pointer;
|
||||
using difference_type =
|
||||
typename std::iterator_traits<iterator>::difference_type;
|
||||
using difference_type = typename std::iterator_traits<iterator>::difference_type;
|
||||
using iterator_category = std::input_iterator_tag;
|
||||
|
||||
proxy_iterator() = default;
|
||||
@@ -236,8 +236,17 @@ TEST_CASE("deserialization")
|
||||
SaxEventLogger l;
|
||||
CHECK(json::sax_parse(ss3, &l));
|
||||
CHECK(l.events.size() == 11);
|
||||
CHECK(l.events == std::vector<std::string>(
|
||||
{"start_array()", "string(foo)", "number_unsigned(1)", "number_unsigned(2)", "number_unsigned(3)", "boolean(false)", "start_object()", "key(one)", "number_unsigned(1)", "end_object()", "end_array()"}));
|
||||
CHECK(l.events == std::vector<std::string>({"start_array()",
|
||||
"string(foo)",
|
||||
"number_unsigned(1)",
|
||||
"number_unsigned(2)",
|
||||
"number_unsigned(3)",
|
||||
"boolean(false)",
|
||||
"start_object()",
|
||||
"key(one)",
|
||||
"number_unsigned(1)",
|
||||
"end_object()",
|
||||
"end_array()"}));
|
||||
}
|
||||
|
||||
SECTION("string literal")
|
||||
@@ -250,8 +259,17 @@ TEST_CASE("deserialization")
|
||||
SaxEventLogger l;
|
||||
CHECK(json::sax_parse(s, &l));
|
||||
CHECK(l.events.size() == 11);
|
||||
CHECK(l.events == std::vector<std::string>(
|
||||
{"start_array()", "string(foo)", "number_unsigned(1)", "number_unsigned(2)", "number_unsigned(3)", "boolean(false)", "start_object()", "key(one)", "number_unsigned(1)", "end_object()", "end_array()"}));
|
||||
CHECK(l.events == std::vector<std::string>({"start_array()",
|
||||
"string(foo)",
|
||||
"number_unsigned(1)",
|
||||
"number_unsigned(2)",
|
||||
"number_unsigned(3)",
|
||||
"boolean(false)",
|
||||
"start_object()",
|
||||
"key(one)",
|
||||
"number_unsigned(1)",
|
||||
"end_object()",
|
||||
"end_array()"}));
|
||||
}
|
||||
|
||||
SECTION("string_t")
|
||||
@@ -264,8 +282,17 @@ TEST_CASE("deserialization")
|
||||
SaxEventLogger l;
|
||||
CHECK(json::sax_parse(s, &l));
|
||||
CHECK(l.events.size() == 11);
|
||||
CHECK(l.events == std::vector<std::string>(
|
||||
{"start_array()", "string(foo)", "number_unsigned(1)", "number_unsigned(2)", "number_unsigned(3)", "boolean(false)", "start_object()", "key(one)", "number_unsigned(1)", "end_object()", "end_array()"}));
|
||||
CHECK(l.events == std::vector<std::string>({"start_array()",
|
||||
"string(foo)",
|
||||
"number_unsigned(1)",
|
||||
"number_unsigned(2)",
|
||||
"number_unsigned(3)",
|
||||
"boolean(false)",
|
||||
"start_object()",
|
||||
"key(one)",
|
||||
"number_unsigned(1)",
|
||||
"end_object()",
|
||||
"end_array()"}));
|
||||
}
|
||||
|
||||
SECTION("operator<<")
|
||||
@@ -306,7 +333,10 @@ TEST_CASE("deserialization")
|
||||
ss5 << R"(["foo",1,2,3,false,{"one":1})";
|
||||
|
||||
json _;
|
||||
CHECK_THROWS_WITH_AS(_ = json::parse(ss1), "[json.exception.parse_error.101] parse error at line 1, column 29: syntax error while parsing array - unexpected end of input; expected ']'", json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
_ = json::parse(ss1),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 29: syntax error while parsing array - unexpected end of input; expected ']'",
|
||||
json::parse_error&);
|
||||
CHECK(!json::accept(ss3));
|
||||
|
||||
json j_error;
|
||||
@@ -316,15 +346,27 @@ TEST_CASE("deserialization")
|
||||
SaxEventLogger l;
|
||||
CHECK(!json::sax_parse(ss5, &l));
|
||||
CHECK(l.events.size() == 11);
|
||||
CHECK(l.events == std::vector<std::string>(
|
||||
{"start_array()", "string(foo)", "number_unsigned(1)", "number_unsigned(2)", "number_unsigned(3)", "boolean(false)", "start_object()", "key(one)", "number_unsigned(1)", "end_object()", "parse_error(29)"}));
|
||||
CHECK(l.events == std::vector<std::string>({"start_array()",
|
||||
"string(foo)",
|
||||
"number_unsigned(1)",
|
||||
"number_unsigned(2)",
|
||||
"number_unsigned(3)",
|
||||
"boolean(false)",
|
||||
"start_object()",
|
||||
"key(one)",
|
||||
"number_unsigned(1)",
|
||||
"end_object()",
|
||||
"parse_error(29)"}));
|
||||
}
|
||||
|
||||
SECTION("string")
|
||||
{
|
||||
json::string_t const s = R"(["foo",1,2,3,false,{"one":1})";
|
||||
json _;
|
||||
CHECK_THROWS_WITH_AS(_ = json::parse(s), "[json.exception.parse_error.101] parse error at line 1, column 29: syntax error while parsing array - unexpected end of input; expected ']'", json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
_ = json::parse(s),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 29: syntax error while parsing array - unexpected end of input; expected ']'",
|
||||
json::parse_error&);
|
||||
CHECK(!json::accept(s));
|
||||
|
||||
json j_error;
|
||||
@@ -334,8 +376,17 @@ TEST_CASE("deserialization")
|
||||
SaxEventLogger l;
|
||||
CHECK(!json::sax_parse(s, &l));
|
||||
CHECK(l.events.size() == 11);
|
||||
CHECK(l.events == std::vector<std::string>(
|
||||
{"start_array()", "string(foo)", "number_unsigned(1)", "number_unsigned(2)", "number_unsigned(3)", "boolean(false)", "start_object()", "key(one)", "number_unsigned(1)", "end_object()", "parse_error(29)"}));
|
||||
CHECK(l.events == std::vector<std::string>({"start_array()",
|
||||
"string(foo)",
|
||||
"number_unsigned(1)",
|
||||
"number_unsigned(2)",
|
||||
"number_unsigned(3)",
|
||||
"boolean(false)",
|
||||
"start_object()",
|
||||
"key(one)",
|
||||
"number_unsigned(1)",
|
||||
"end_object()",
|
||||
"parse_error(29)"}));
|
||||
}
|
||||
|
||||
SECTION("operator<<")
|
||||
@@ -343,7 +394,10 @@ TEST_CASE("deserialization")
|
||||
std::stringstream ss;
|
||||
ss << R"(["foo",1,2,3,false,{"one":1})";
|
||||
json j;
|
||||
CHECK_THROWS_WITH_AS(j << ss, "[json.exception.parse_error.101] parse error at line 1, column 29: syntax error while parsing array - unexpected end of input; expected ']'", json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
j << ss,
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 29: syntax error while parsing array - unexpected end of input; expected ']'",
|
||||
json::parse_error&);
|
||||
}
|
||||
|
||||
SECTION("operator>>")
|
||||
@@ -351,12 +405,18 @@ TEST_CASE("deserialization")
|
||||
std::stringstream ss;
|
||||
ss << R"(["foo",1,2,3,false,{"one":1})";
|
||||
json j;
|
||||
CHECK_THROWS_WITH_AS(ss >> j, "[json.exception.parse_error.101] parse error at line 1, column 29: syntax error while parsing array - unexpected end of input; expected ']'", json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
ss >> j,
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 29: syntax error while parsing array - unexpected end of input; expected ']'",
|
||||
json::parse_error&);
|
||||
}
|
||||
|
||||
SECTION("user-defined string literal")
|
||||
{
|
||||
CHECK_THROWS_WITH_AS("[\"foo\",1,2,3,false,{\"one\":1}"_json, "[json.exception.parse_error.101] parse error at line 1, column 29: syntax error while parsing array - unexpected end of input; expected ']'", json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
"[\"foo\",1,2,3,false,{\"one\":1}"_json,
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 29: syntax error while parsing array - unexpected end of input; expected ']'",
|
||||
json::parse_error&);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -658,7 +718,10 @@ TEST_CASE("deserialization")
|
||||
{
|
||||
std::array<std::uint8_t, 4> v = {{'\"', 0x7F, 0xDF, 0x7F}};
|
||||
json _;
|
||||
CHECK_THROWS_WITH_AS(_ = json::parse(std::begin(v), std::end(v)), "[json.exception.parse_error.101] parse error at line 1, column 4: syntax error while parsing value - invalid string: ill-formed UTF-8 byte; last read: '\"\x7f\xdf\x7f'", json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
_ = json::parse(std::begin(v), std::end(v)),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 4: syntax error while parsing value - invalid string: ill-formed UTF-8 byte; last read: '\"\x7f\xdf\x7f'",
|
||||
json::parse_error&);
|
||||
CHECK(!json::accept(std::begin(v), std::end(v)));
|
||||
|
||||
json j_error;
|
||||
@@ -838,8 +901,7 @@ TEST_CASE("deserialization")
|
||||
SaxEventLogger l;
|
||||
CHECK(!json::sax_parse(std::begin(v), std::end(v), &l));
|
||||
CHECK(l.events.size() == 4);
|
||||
CHECK(l.events == std::vector<std::string>(
|
||||
{"start_object()", "key()", "number_unsigned(11)", "parse_error(7)"}));
|
||||
CHECK(l.events == std::vector<std::string>({"start_object()", "key()", "number_unsigned(11)", "parse_error(7)"}));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -851,15 +913,20 @@ TEST_CASE("deserialization")
|
||||
SECTION("BOM only")
|
||||
{
|
||||
json _;
|
||||
CHECK_THROWS_WITH_AS(_ = json::parse(bom), "[json.exception.parse_error.101] parse error at line 1, column 4: syntax error while parsing value - unexpected end of input; expected '[', '{', or a literal", json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
_ = json::parse(bom),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 4: syntax error while parsing value - unexpected end of input; expected '[', '{', or a literal",
|
||||
json::parse_error&);
|
||||
|
||||
CHECK_THROWS_WITH_AS(_ = json::parse(std::istringstream(bom)), "[json.exception.parse_error.101] parse error at line 1, column 4: syntax error while parsing value - unexpected end of input; expected '[', '{', or a literal", json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
_ = json::parse(std::istringstream(bom)),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 4: syntax error while parsing value - unexpected end of input; expected '[', '{', or a literal",
|
||||
json::parse_error&);
|
||||
|
||||
SaxEventLogger l;
|
||||
CHECK(!json::sax_parse(bom, &l));
|
||||
CHECK(l.events.size() == 1);
|
||||
CHECK(l.events == std::vector<std::string>(
|
||||
{"parse_error(4)"}));
|
||||
CHECK(l.events == std::vector<std::string>({"parse_error(4)"}));
|
||||
}
|
||||
|
||||
SECTION("BOM and content")
|
||||
@@ -872,49 +939,55 @@ TEST_CASE("deserialization")
|
||||
CHECK(json::sax_parse(std::istringstream(bom + "1"), &l1));
|
||||
CHECK(json::sax_parse(bom + "1", &l2));
|
||||
CHECK(l1.events.size() == 1);
|
||||
CHECK(l1.events == std::vector<std::string>(
|
||||
{"number_unsigned(1)"}));
|
||||
CHECK(l1.events == std::vector<std::string>({"number_unsigned(1)"}));
|
||||
CHECK(l2.events.size() == 1);
|
||||
CHECK(l2.events == std::vector<std::string>(
|
||||
{"number_unsigned(1)"}));
|
||||
CHECK(l2.events == std::vector<std::string>({"number_unsigned(1)"}));
|
||||
}
|
||||
|
||||
SECTION("2 byte of BOM")
|
||||
{
|
||||
json _;
|
||||
CHECK_THROWS_WITH_AS(_ = json::parse(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'", json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
_ = json::parse(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'",
|
||||
json::parse_error&);
|
||||
|
||||
CHECK_THROWS_WITH_AS(_ = 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'", json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
_ = 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'",
|
||||
json::parse_error&);
|
||||
|
||||
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);
|
||||
CHECK(l1.events == std::vector<std::string>(
|
||||
{"parse_error(3)"}));
|
||||
CHECK(l1.events == std::vector<std::string>({"parse_error(3)"}));
|
||||
CHECK(l2.events.size() == 1);
|
||||
CHECK(l2.events == std::vector<std::string>(
|
||||
{"parse_error(3)"}));
|
||||
CHECK(l2.events == std::vector<std::string>({"parse_error(3)"}));
|
||||
}
|
||||
|
||||
SECTION("1 byte of BOM")
|
||||
{
|
||||
json _;
|
||||
CHECK_THROWS_WITH_AS(_ = json::parse(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'", json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
_ = json::parse(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'",
|
||||
json::parse_error&);
|
||||
|
||||
CHECK_THROWS_WITH_AS(_ = 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'", json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
_ = 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'",
|
||||
json::parse_error&);
|
||||
|
||||
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);
|
||||
CHECK(l1.events == std::vector<std::string>(
|
||||
{"parse_error(2)"}));
|
||||
CHECK(l1.events == std::vector<std::string>({"parse_error(2)"}));
|
||||
CHECK(l2.events.size() == 1);
|
||||
CHECK(l2.events == std::vector<std::string>(
|
||||
{"parse_error(2)"}));
|
||||
CHECK(l2.events == std::vector<std::string>({"parse_error(2)"}));
|
||||
}
|
||||
|
||||
SECTION("variations")
|
||||
@@ -946,8 +1019,7 @@ TEST_CASE("deserialization")
|
||||
SaxEventLogger l;
|
||||
CHECK(json::sax_parse(s + "null", &l));
|
||||
CHECK(l.events.size() == 1);
|
||||
CHECK(l.events == std::vector<std::string>(
|
||||
{"null()"}));
|
||||
CHECK(l.events == std::vector<std::string>({"null()"}));
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -962,18 +1034,15 @@ TEST_CASE("deserialization")
|
||||
|
||||
if (i0 != 0)
|
||||
{
|
||||
CHECK(l.events == std::vector<std::string>(
|
||||
{"parse_error(1)"}));
|
||||
CHECK(l.events == std::vector<std::string>({"parse_error(1)"}));
|
||||
}
|
||||
else if (i1 != 0)
|
||||
{
|
||||
CHECK(l.events == std::vector<std::string>(
|
||||
{"parse_error(2)"}));
|
||||
CHECK(l.events == std::vector<std::string>({"parse_error(2)"}));
|
||||
}
|
||||
else
|
||||
{
|
||||
CHECK(l.events == std::vector<std::string>(
|
||||
{"parse_error(3)"}));
|
||||
CHECK(l.events == std::vector<std::string>({"parse_error(3)"}));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1003,23 +1072,43 @@ TEST_CASE("deserialization")
|
||||
|
||||
json::sax_parse(s, &default_logger);
|
||||
CHECK(default_logger.events.size() == 14);
|
||||
CHECK(default_logger.events == std::vector<std::string>(
|
||||
{"start_array()", "number_unsigned(1)", "start_array()", "string(string)", "number_float(43.12)", "end_array()", "null()", "start_object()", "key(key1)", "boolean(true)", "key(key2)", "boolean(false)", "end_object()", "end_array()"}));
|
||||
CHECK(default_logger.events == std::vector<std::string>({"start_array()",
|
||||
"number_unsigned(1)",
|
||||
"start_array()",
|
||||
"string(string)",
|
||||
"number_float(43.12)",
|
||||
"end_array()",
|
||||
"null()",
|
||||
"start_object()",
|
||||
"key(key1)",
|
||||
"boolean(true)",
|
||||
"key(key2)",
|
||||
"boolean(false)",
|
||||
"end_object()",
|
||||
"end_array()"}));
|
||||
|
||||
json::sax_parse(s, &exit_after_start_object);
|
||||
CHECK(exit_after_start_object.events.size() == 8);
|
||||
CHECK(exit_after_start_object.events == std::vector<std::string>(
|
||||
{"start_array()", "number_unsigned(1)", "start_array()", "string(string)", "number_float(43.12)", "end_array()", "null()", "start_object()"}));
|
||||
CHECK(
|
||||
exit_after_start_object.events ==
|
||||
std::vector<std::string>(
|
||||
{"start_array()", "number_unsigned(1)", "start_array()", "string(string)", "number_float(43.12)", "end_array()", "null()", "start_object()"}));
|
||||
|
||||
json::sax_parse(s, &exit_after_key);
|
||||
CHECK(exit_after_key.events.size() == 9);
|
||||
CHECK(exit_after_key.events == std::vector<std::string>(
|
||||
{"start_array()", "number_unsigned(1)", "start_array()", "string(string)", "number_float(43.12)", "end_array()", "null()", "start_object()", "key(key1)"}));
|
||||
CHECK(exit_after_key.events == std::vector<std::string>({"start_array()",
|
||||
"number_unsigned(1)",
|
||||
"start_array()",
|
||||
"string(string)",
|
||||
"number_float(43.12)",
|
||||
"end_array()",
|
||||
"null()",
|
||||
"start_object()",
|
||||
"key(key1)"}));
|
||||
|
||||
json::sax_parse(s, &exit_after_start_array);
|
||||
CHECK(exit_after_start_array.events.size() == 1);
|
||||
CHECK(exit_after_start_array.events == std::vector<std::string>(
|
||||
{"start_array()"}));
|
||||
CHECK(exit_after_start_array.events == std::vector<std::string>({"start_array()"}));
|
||||
}
|
||||
|
||||
SECTION("JSON Lines")
|
||||
@@ -1065,7 +1154,20 @@ TEST_CASE("deserialization")
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE_TEMPLATE("deserialization of different character types (ASCII)", T, char, unsigned char, signed char, wchar_t, char16_t, char32_t, std::uint8_t, std::int8_t, std::int16_t, std::uint16_t, std::int32_t, std::uint32_t)
|
||||
TEST_CASE_TEMPLATE("deserialization of different character types (ASCII)",
|
||||
T,
|
||||
char,
|
||||
unsigned char,
|
||||
signed char,
|
||||
wchar_t,
|
||||
char16_t,
|
||||
char32_t,
|
||||
std::uint8_t,
|
||||
std::int8_t,
|
||||
std::int16_t,
|
||||
std::uint16_t,
|
||||
std::int32_t,
|
||||
std::uint32_t)
|
||||
{
|
||||
std::vector<T> const v = {'t', 'r', 'u', 'e'};
|
||||
CHECK(json::parse(v) == json(true));
|
||||
@@ -1080,7 +1182,8 @@ TEST_CASE_TEMPLATE("deserialization of different character types (ASCII)", T, ch
|
||||
TEST_CASE_TEMPLATE("deserialization of different character types (UTF-8)", T, char, unsigned char, std::uint8_t)
|
||||
{
|
||||
// a star emoji
|
||||
std::vector<T> const v = {'"', static_cast<T>(0xe2u), static_cast<T>(0xadu), static_cast<T>(0x90u), static_cast<T>(0xefu), static_cast<T>(0xb8u), static_cast<T>(0x8fu), '"'};
|
||||
std::vector<T> const v =
|
||||
{'"', static_cast<T>(0xe2u), static_cast<T>(0xadu), static_cast<T>(0x90u), static_cast<T>(0xefu), static_cast<T>(0xb8u), static_cast<T>(0x8fu), '"'};
|
||||
CHECK(json::parse(v).dump(-1, ' ', true) == "\"\\u2b50\\ufe0f\"");
|
||||
CHECK(json::accept(v));
|
||||
|
||||
|
||||
@@ -32,7 +32,9 @@ TEST_CASE("Better diagnostics")
|
||||
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);
|
||||
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")
|
||||
@@ -53,14 +55,18 @@ TEST_CASE("Better diagnostics")
|
||||
{
|
||||
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);
|
||||
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);
|
||||
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")
|
||||
@@ -68,13 +74,18 @@ TEST_CASE("Better diagnostics")
|
||||
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);
|
||||
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: attempting to parse an empty input; check that your input string or stream contains the expected JSON", json::parse_error);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
_ = json::parse(""),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 1: attempting to parse an empty input; check that your input string or stream contains the expected JSON",
|
||||
json::parse_error);
|
||||
}
|
||||
|
||||
SECTION("Wrong type in update()")
|
||||
@@ -82,7 +93,9 @@ TEST_CASE("Better diagnostics")
|
||||
json j = {{"foo", "bar"}};
|
||||
json k = {{"bla", 1}};
|
||||
|
||||
CHECK_THROWS_WITH_AS(j.update(k["bla"].begin(), k["bla"].end()), "[json.exception.type_error.312] (/bla) cannot use update() with number", json::type_error);
|
||||
CHECK_THROWS_WITH_AS(j.update(k["bla"].begin(), k["bla"].end()),
|
||||
"[json.exception.type_error.312] (/bla) cannot use update() with number",
|
||||
json::type_error);
|
||||
CHECK_THROWS_WITH_AS(j.update(k["bla"]), "[json.exception.type_error.312] (/bla) cannot use update() with number", json::type_error);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,7 +46,8 @@ TEST_CASE("Tests with disabled exceptions")
|
||||
sax_no_exception sax(j);
|
||||
|
||||
CHECK(!json::sax_parse("xyz", &sax));
|
||||
CHECK(*sax_no_exception::error_string == "[json.exception.parse_error.101] parse error at line 1, column 1: syntax error while parsing value - invalid literal; last read: 'x'");
|
||||
CHECK(*sax_no_exception::error_string ==
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 1: syntax error while parsing value - invalid literal; last read: 'x'");
|
||||
delete sax_no_exception::error_string; // NOLINT(cppcoreguidelines-owning-memory)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,12 +44,8 @@ TEST_CASE("element access 1")
|
||||
|
||||
SECTION("access outside bounds")
|
||||
{
|
||||
CHECK_THROWS_WITH_AS(j.at(8),
|
||||
"[json.exception.out_of_range.401] array index 8 is out of range",
|
||||
json::out_of_range&);
|
||||
CHECK_THROWS_WITH_AS(j_const.at(8),
|
||||
"[json.exception.out_of_range.401] array index 8 is out of range",
|
||||
json::out_of_range&);
|
||||
CHECK_THROWS_WITH_AS(j.at(8), "[json.exception.out_of_range.401] array index 8 is out of range", json::out_of_range&);
|
||||
CHECK_THROWS_WITH_AS(j_const.at(8), "[json.exception.out_of_range.401] array index 8 is out of range", json::out_of_range&);
|
||||
}
|
||||
|
||||
SECTION("access on non-array type")
|
||||
@@ -159,7 +155,9 @@ TEST_CASE("element access 1")
|
||||
json j_nonarray(json::value_t::null);
|
||||
const json j_nonarray_const(j_nonarray);
|
||||
CHECK_NOTHROW(j_nonarray[0]);
|
||||
CHECK_THROWS_WITH_AS(j_nonarray_const[0], "[json.exception.type_error.305] cannot use operator[] with a numeric argument with null", json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonarray_const[0],
|
||||
"[json.exception.type_error.305] cannot use operator[] with a numeric argument with null",
|
||||
json::type_error&);
|
||||
}
|
||||
|
||||
SECTION("implicit transformation to properly filled array")
|
||||
@@ -174,48 +172,72 @@ TEST_CASE("element access 1")
|
||||
{
|
||||
json j_nonarray(json::value_t::boolean);
|
||||
const json j_nonarray_const(j_nonarray);
|
||||
CHECK_THROWS_WITH_AS(j_nonarray[0], "[json.exception.type_error.305] cannot use operator[] with a numeric argument with boolean", json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonarray_const[0], "[json.exception.type_error.305] cannot use operator[] with a numeric argument with boolean", json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonarray[0],
|
||||
"[json.exception.type_error.305] cannot use operator[] with a numeric argument with boolean",
|
||||
json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonarray_const[0],
|
||||
"[json.exception.type_error.305] cannot use operator[] with a numeric argument with boolean",
|
||||
json::type_error&);
|
||||
}
|
||||
|
||||
SECTION("string")
|
||||
{
|
||||
json j_nonarray(json::value_t::string);
|
||||
const json j_nonarray_const(j_nonarray);
|
||||
CHECK_THROWS_WITH_AS(j_nonarray[0], "[json.exception.type_error.305] cannot use operator[] with a numeric argument with string", json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonarray_const[0], "[json.exception.type_error.305] cannot use operator[] with a numeric argument with string", json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonarray[0],
|
||||
"[json.exception.type_error.305] cannot use operator[] with a numeric argument with string",
|
||||
json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonarray_const[0],
|
||||
"[json.exception.type_error.305] cannot use operator[] with a numeric argument with string",
|
||||
json::type_error&);
|
||||
}
|
||||
|
||||
SECTION("object")
|
||||
{
|
||||
json j_nonarray(json::value_t::object);
|
||||
const json j_nonarray_const(j_nonarray);
|
||||
CHECK_THROWS_WITH_AS(j_nonarray[0], "[json.exception.type_error.305] cannot use operator[] with a numeric argument with object", json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonarray_const[0], "[json.exception.type_error.305] cannot use operator[] with a numeric argument with object", json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonarray[0],
|
||||
"[json.exception.type_error.305] cannot use operator[] with a numeric argument with object",
|
||||
json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonarray_const[0],
|
||||
"[json.exception.type_error.305] cannot use operator[] with a numeric argument with object",
|
||||
json::type_error&);
|
||||
}
|
||||
|
||||
SECTION("number (integer)")
|
||||
{
|
||||
json j_nonarray(json::value_t::number_integer);
|
||||
const json j_nonarray_const(j_nonarray);
|
||||
CHECK_THROWS_WITH_AS(j_nonarray[0], "[json.exception.type_error.305] cannot use operator[] with a numeric argument with number", json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonarray_const[0], "[json.exception.type_error.305] cannot use operator[] with a numeric argument with number", json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonarray[0],
|
||||
"[json.exception.type_error.305] cannot use operator[] with a numeric argument with number",
|
||||
json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonarray_const[0],
|
||||
"[json.exception.type_error.305] cannot use operator[] with a numeric argument with number",
|
||||
json::type_error&);
|
||||
}
|
||||
|
||||
SECTION("number (unsigned)")
|
||||
{
|
||||
json j_nonarray(json::value_t::number_unsigned);
|
||||
const json j_nonarray_const(j_nonarray);
|
||||
CHECK_THROWS_WITH_AS(j_nonarray[0], "[json.exception.type_error.305] cannot use operator[] with a numeric argument with number", json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonarray_const[0], "[json.exception.type_error.305] cannot use operator[] with a numeric argument with number", json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonarray[0],
|
||||
"[json.exception.type_error.305] cannot use operator[] with a numeric argument with number",
|
||||
json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonarray_const[0],
|
||||
"[json.exception.type_error.305] cannot use operator[] with a numeric argument with number",
|
||||
json::type_error&);
|
||||
}
|
||||
|
||||
SECTION("number (floating-point)")
|
||||
{
|
||||
json j_nonarray(json::value_t::number_float);
|
||||
const json j_nonarray_const(j_nonarray);
|
||||
CHECK_THROWS_WITH_AS(j_nonarray[0], "[json.exception.type_error.305] cannot use operator[] with a numeric argument with number", json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonarray_const[0], "[json.exception.type_error.305] cannot use operator[] with a numeric argument with number", json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonarray[0],
|
||||
"[json.exception.type_error.305] cannot use operator[] with a numeric argument with number",
|
||||
json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonarray_const[0],
|
||||
"[json.exception.type_error.305] cannot use operator[] with a numeric argument with number",
|
||||
json::type_error&);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -539,9 +561,7 @@ TEST_CASE("element access 1")
|
||||
}
|
||||
{
|
||||
json j;
|
||||
CHECK_THROWS_WITH_AS(j.erase(j.begin()),
|
||||
"[json.exception.type_error.307] cannot use erase() with null",
|
||||
json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j.erase(j.begin()), "[json.exception.type_error.307] cannot use erase() with null", json::type_error&);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -823,12 +843,16 @@ TEST_CASE("element access 1")
|
||||
{
|
||||
json j = "foo";
|
||||
CHECK_THROWS_WITH_AS(j.erase(j.end(), j.end()), "[json.exception.invalid_iterator.204] iterators out of range", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(j.erase(j.begin(), j.begin()), "[json.exception.invalid_iterator.204] iterators out of range", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(j.erase(j.begin(), j.begin()),
|
||||
"[json.exception.invalid_iterator.204] iterators out of range",
|
||||
json::invalid_iterator&);
|
||||
}
|
||||
{
|
||||
json j = "bar";
|
||||
CHECK_THROWS_WITH_AS(j.erase(j.cend(), j.cend()), "[json.exception.invalid_iterator.204] iterators out of range", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(j.erase(j.cbegin(), j.cbegin()), "[json.exception.invalid_iterator.204] iterators out of range", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(j.erase(j.cbegin(), j.cbegin()),
|
||||
"[json.exception.invalid_iterator.204] iterators out of range",
|
||||
json::invalid_iterator&);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -837,12 +861,16 @@ TEST_CASE("element access 1")
|
||||
{
|
||||
json j = false;
|
||||
CHECK_THROWS_WITH_AS(j.erase(j.end(), j.end()), "[json.exception.invalid_iterator.204] iterators out of range", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(j.erase(j.begin(), j.begin()), "[json.exception.invalid_iterator.204] iterators out of range", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(j.erase(j.begin(), j.begin()),
|
||||
"[json.exception.invalid_iterator.204] iterators out of range",
|
||||
json::invalid_iterator&);
|
||||
}
|
||||
{
|
||||
json j = true;
|
||||
CHECK_THROWS_WITH_AS(j.erase(j.cend(), j.cend()), "[json.exception.invalid_iterator.204] iterators out of range", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(j.erase(j.cbegin(), j.cbegin()), "[json.exception.invalid_iterator.204] iterators out of range", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(j.erase(j.cbegin(), j.cbegin()),
|
||||
"[json.exception.invalid_iterator.204] iterators out of range",
|
||||
json::invalid_iterator&);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -851,12 +879,16 @@ TEST_CASE("element access 1")
|
||||
{
|
||||
json j = 17;
|
||||
CHECK_THROWS_WITH_AS(j.erase(j.end(), j.end()), "[json.exception.invalid_iterator.204] iterators out of range", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(j.erase(j.begin(), j.begin()), "[json.exception.invalid_iterator.204] iterators out of range", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(j.erase(j.begin(), j.begin()),
|
||||
"[json.exception.invalid_iterator.204] iterators out of range",
|
||||
json::invalid_iterator&);
|
||||
}
|
||||
{
|
||||
json j = 17;
|
||||
CHECK_THROWS_WITH_AS(j.erase(j.cend(), j.cend()), "[json.exception.invalid_iterator.204] iterators out of range", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(j.erase(j.cbegin(), j.cbegin()), "[json.exception.invalid_iterator.204] iterators out of range", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(j.erase(j.cbegin(), j.cbegin()),
|
||||
"[json.exception.invalid_iterator.204] iterators out of range",
|
||||
json::invalid_iterator&);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -865,12 +897,16 @@ TEST_CASE("element access 1")
|
||||
{
|
||||
json j = 17u;
|
||||
CHECK_THROWS_WITH_AS(j.erase(j.end(), j.end()), "[json.exception.invalid_iterator.204] iterators out of range", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(j.erase(j.begin(), j.begin()), "[json.exception.invalid_iterator.204] iterators out of range", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(j.erase(j.begin(), j.begin()),
|
||||
"[json.exception.invalid_iterator.204] iterators out of range",
|
||||
json::invalid_iterator&);
|
||||
}
|
||||
{
|
||||
json j = 17u;
|
||||
CHECK_THROWS_WITH_AS(j.erase(j.cend(), j.cend()), "[json.exception.invalid_iterator.204] iterators out of range", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(j.erase(j.cbegin(), j.cbegin()), "[json.exception.invalid_iterator.204] iterators out of range", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(j.erase(j.cbegin(), j.cbegin()),
|
||||
"[json.exception.invalid_iterator.204] iterators out of range",
|
||||
json::invalid_iterator&);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -879,12 +915,16 @@ TEST_CASE("element access 1")
|
||||
{
|
||||
json j = 23.42;
|
||||
CHECK_THROWS_WITH_AS(j.erase(j.end(), j.end()), "[json.exception.invalid_iterator.204] iterators out of range", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(j.erase(j.begin(), j.begin()), "[json.exception.invalid_iterator.204] iterators out of range", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(j.erase(j.begin(), j.begin()),
|
||||
"[json.exception.invalid_iterator.204] iterators out of range",
|
||||
json::invalid_iterator&);
|
||||
}
|
||||
{
|
||||
json j = 23.42;
|
||||
CHECK_THROWS_WITH_AS(j.erase(j.cend(), j.cend()), "[json.exception.invalid_iterator.204] iterators out of range", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(j.erase(j.cbegin(), j.cbegin()), "[json.exception.invalid_iterator.204] iterators out of range", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(j.erase(j.cbegin(), j.cbegin()),
|
||||
"[json.exception.invalid_iterator.204] iterators out of range",
|
||||
json::invalid_iterator&);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+315
-117
@@ -21,7 +21,14 @@ TEST_CASE_TEMPLATE("element access 2", Json, nlohmann::json, nlohmann::ordered_j
|
||||
{
|
||||
SECTION("object")
|
||||
{
|
||||
Json j = {{"integer", 1}, {"unsigned", 1u}, {"floating", 42.23}, {"null", nullptr}, {"string", "hello world"}, {"boolean", true}, {"object", Json::object()}, {"array", {1, 2, 3}}};
|
||||
Json j = {{"integer", 1},
|
||||
{"unsigned", 1u},
|
||||
{"floating", 42.23},
|
||||
{"null", nullptr},
|
||||
{"string", "hello world"},
|
||||
{"boolean", true},
|
||||
{"object", Json::object()},
|
||||
{"array", {1, 2, 3}}};
|
||||
const Json j_const = j;
|
||||
|
||||
SECTION("access specified element with bounds checking")
|
||||
@@ -74,7 +81,9 @@ TEST_CASE_TEMPLATE("element access 2", Json, nlohmann::json, nlohmann::ordered_j
|
||||
|
||||
#ifdef JSON_HAS_CPP_17
|
||||
CHECK_THROWS_WITH_AS(j.at(std::string_view("foo")), "[json.exception.out_of_range.403] key 'foo' not found", typename Json::out_of_range&);
|
||||
CHECK_THROWS_WITH_AS(j_const.at(std::string_view("foo")), "[json.exception.out_of_range.403] key 'foo' not found", typename Json::out_of_range&);
|
||||
CHECK_THROWS_WITH_AS(j_const.at(std::string_view("foo")),
|
||||
"[json.exception.out_of_range.403] key 'foo' not found",
|
||||
typename Json::out_of_range&);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -88,8 +97,12 @@ TEST_CASE_TEMPLATE("element access 2", Json, nlohmann::json, nlohmann::ordered_j
|
||||
CHECK_THROWS_WITH_AS(j_nonobject_const.at("foo"), "[json.exception.type_error.304] cannot use at() with null", typename Json::type_error&);
|
||||
|
||||
#ifdef JSON_HAS_CPP_17
|
||||
CHECK_THROWS_WITH_AS(j_nonobject.at(std::string_view(std::string_view("foo"))), "[json.exception.type_error.304] cannot use at() with null", typename Json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonobject_const.at(std::string_view(std::string_view("foo"))), "[json.exception.type_error.304] cannot use at() with null", typename Json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonobject.at(std::string_view(std::string_view("foo"))),
|
||||
"[json.exception.type_error.304] cannot use at() with null",
|
||||
typename Json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonobject_const.at(std::string_view(std::string_view("foo"))),
|
||||
"[json.exception.type_error.304] cannot use at() with null",
|
||||
typename Json::type_error&);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -98,11 +111,17 @@ TEST_CASE_TEMPLATE("element access 2", Json, nlohmann::json, nlohmann::ordered_j
|
||||
Json j_nonobject(Json::value_t::boolean);
|
||||
const Json j_nonobject_const(j_nonobject);
|
||||
CHECK_THROWS_WITH_AS(j_nonobject.at("foo"), "[json.exception.type_error.304] cannot use at() with boolean", typename Json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonobject_const.at("foo"), "[json.exception.type_error.304] cannot use at() with boolean", typename Json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonobject_const.at("foo"),
|
||||
"[json.exception.type_error.304] cannot use at() with boolean",
|
||||
typename Json::type_error&);
|
||||
|
||||
#ifdef JSON_HAS_CPP_17
|
||||
CHECK_THROWS_WITH_AS(j_nonobject.at(std::string_view("foo")), "[json.exception.type_error.304] cannot use at() with boolean", typename Json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonobject_const.at(std::string_view("foo")), "[json.exception.type_error.304] cannot use at() with boolean", typename Json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonobject.at(std::string_view("foo")),
|
||||
"[json.exception.type_error.304] cannot use at() with boolean",
|
||||
typename Json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonobject_const.at(std::string_view("foo")),
|
||||
"[json.exception.type_error.304] cannot use at() with boolean",
|
||||
typename Json::type_error&);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -111,11 +130,17 @@ TEST_CASE_TEMPLATE("element access 2", Json, nlohmann::json, nlohmann::ordered_j
|
||||
Json j_nonobject(Json::value_t::string);
|
||||
const Json j_nonobject_const(j_nonobject);
|
||||
CHECK_THROWS_WITH_AS(j_nonobject.at("foo"), "[json.exception.type_error.304] cannot use at() with string", typename Json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonobject_const.at("foo"), "[json.exception.type_error.304] cannot use at() with string", typename Json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonobject_const.at("foo"),
|
||||
"[json.exception.type_error.304] cannot use at() with string",
|
||||
typename Json::type_error&);
|
||||
|
||||
#ifdef JSON_HAS_CPP_17
|
||||
CHECK_THROWS_WITH_AS(j_nonobject.at(std::string_view("foo")), "[json.exception.type_error.304] cannot use at() with string", typename Json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonobject_const.at(std::string_view("foo")), "[json.exception.type_error.304] cannot use at() with string", typename Json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonobject.at(std::string_view("foo")),
|
||||
"[json.exception.type_error.304] cannot use at() with string",
|
||||
typename Json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonobject_const.at(std::string_view("foo")),
|
||||
"[json.exception.type_error.304] cannot use at() with string",
|
||||
typename Json::type_error&);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -127,8 +152,12 @@ TEST_CASE_TEMPLATE("element access 2", Json, nlohmann::json, nlohmann::ordered_j
|
||||
CHECK_THROWS_WITH_AS(j_nonobject_const.at("foo"), "[json.exception.type_error.304] cannot use at() with array", typename Json::type_error&);
|
||||
|
||||
#ifdef JSON_HAS_CPP_17
|
||||
CHECK_THROWS_WITH_AS(j_nonobject.at(std::string_view("foo")), "[json.exception.type_error.304] cannot use at() with array", typename Json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonobject_const.at(std::string_view("foo")), "[json.exception.type_error.304] cannot use at() with array", typename Json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonobject.at(std::string_view("foo")),
|
||||
"[json.exception.type_error.304] cannot use at() with array",
|
||||
typename Json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonobject_const.at(std::string_view("foo")),
|
||||
"[json.exception.type_error.304] cannot use at() with array",
|
||||
typename Json::type_error&);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -137,11 +166,17 @@ TEST_CASE_TEMPLATE("element access 2", Json, nlohmann::json, nlohmann::ordered_j
|
||||
Json j_nonobject(Json::value_t::number_integer);
|
||||
const Json j_nonobject_const(j_nonobject);
|
||||
CHECK_THROWS_WITH_AS(j_nonobject.at("foo"), "[json.exception.type_error.304] cannot use at() with number", typename Json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonobject_const.at("foo"), "[json.exception.type_error.304] cannot use at() with number", typename Json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonobject_const.at("foo"),
|
||||
"[json.exception.type_error.304] cannot use at() with number",
|
||||
typename Json::type_error&);
|
||||
|
||||
#ifdef JSON_HAS_CPP_17
|
||||
CHECK_THROWS_WITH_AS(j_nonobject.at(std::string_view("foo")), "[json.exception.type_error.304] cannot use at() with number", typename Json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonobject_const.at(std::string_view("foo")), "[json.exception.type_error.304] cannot use at() with number", typename Json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonobject.at(std::string_view("foo")),
|
||||
"[json.exception.type_error.304] cannot use at() with number",
|
||||
typename Json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonobject_const.at(std::string_view("foo")),
|
||||
"[json.exception.type_error.304] cannot use at() with number",
|
||||
typename Json::type_error&);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -150,11 +185,17 @@ TEST_CASE_TEMPLATE("element access 2", Json, nlohmann::json, nlohmann::ordered_j
|
||||
Json j_nonobject(Json::value_t::number_unsigned);
|
||||
const Json j_nonobject_const(j_nonobject);
|
||||
CHECK_THROWS_WITH_AS(j_nonobject.at("foo"), "[json.exception.type_error.304] cannot use at() with number", typename Json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonobject_const.at("foo"), "[json.exception.type_error.304] cannot use at() with number", typename Json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonobject_const.at("foo"),
|
||||
"[json.exception.type_error.304] cannot use at() with number",
|
||||
typename Json::type_error&);
|
||||
|
||||
#ifdef JSON_HAS_CPP_17
|
||||
CHECK_THROWS_WITH_AS(j_nonobject.at(std::string_view("foo")), "[json.exception.type_error.304] cannot use at() with number", typename Json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonobject_const.at(std::string_view("foo")), "[json.exception.type_error.304] cannot use at() with number", typename Json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonobject.at(std::string_view("foo")),
|
||||
"[json.exception.type_error.304] cannot use at() with number",
|
||||
typename Json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonobject_const.at(std::string_view("foo")),
|
||||
"[json.exception.type_error.304] cannot use at() with number",
|
||||
typename Json::type_error&);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -163,11 +204,17 @@ TEST_CASE_TEMPLATE("element access 2", Json, nlohmann::json, nlohmann::ordered_j
|
||||
Json j_nonobject(Json::value_t::number_float);
|
||||
const Json j_nonobject_const(j_nonobject);
|
||||
CHECK_THROWS_WITH_AS(j_nonobject.at("foo"), "[json.exception.type_error.304] cannot use at() with number", typename Json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonobject_const.at("foo"), "[json.exception.type_error.304] cannot use at() with number", typename Json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonobject_const.at("foo"),
|
||||
"[json.exception.type_error.304] cannot use at() with number",
|
||||
typename Json::type_error&);
|
||||
|
||||
#ifdef JSON_HAS_CPP_17
|
||||
CHECK_THROWS_WITH_AS(j_nonobject.at(std::string_view("foo")), "[json.exception.type_error.304] cannot use at() with number", typename Json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonobject_const.at(std::string_view("foo")), "[json.exception.type_error.304] cannot use at() with number", typename Json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonobject.at(std::string_view("foo")),
|
||||
"[json.exception.type_error.304] cannot use at() with number",
|
||||
typename Json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonobject_const.at(std::string_view("foo")),
|
||||
"[json.exception.type_error.304] cannot use at() with number",
|
||||
typename Json::type_error&);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -275,12 +322,20 @@ TEST_CASE_TEMPLATE("element access 2", Json, nlohmann::json, nlohmann::ordered_j
|
||||
{
|
||||
Json j_nonobject(Json::value_t::null);
|
||||
const Json j_nonobject_const(Json::value_t::null);
|
||||
CHECK_THROWS_WITH_AS(j_nonobject.value("foo", 1), "[json.exception.type_error.306] cannot use value() with null", typename Json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonobject_const.value("foo", 1), "[json.exception.type_error.306] cannot use value() with null", typename Json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonobject.value("foo", 1),
|
||||
"[json.exception.type_error.306] cannot use value() with null",
|
||||
typename Json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonobject_const.value("foo", 1),
|
||||
"[json.exception.type_error.306] cannot use value() with null",
|
||||
typename Json::type_error&);
|
||||
|
||||
#ifdef JSON_HAS_CPP_17
|
||||
CHECK_THROWS_WITH_AS(j_nonobject.value(std::string_view("foo"), 1), "[json.exception.type_error.306] cannot use value() with null", typename Json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonobject_const.value(std::string_view("foo"), 1), "[json.exception.type_error.306] cannot use value() with null", typename Json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonobject.value(std::string_view("foo"), 1),
|
||||
"[json.exception.type_error.306] cannot use value() with null",
|
||||
typename Json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonobject_const.value(std::string_view("foo"), 1),
|
||||
"[json.exception.type_error.306] cannot use value() with null",
|
||||
typename Json::type_error&);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -288,12 +343,20 @@ TEST_CASE_TEMPLATE("element access 2", Json, nlohmann::json, nlohmann::ordered_j
|
||||
{
|
||||
Json j_nonobject(Json::value_t::boolean);
|
||||
const Json j_nonobject_const(Json::value_t::boolean);
|
||||
CHECK_THROWS_WITH_AS(j_nonobject.value("foo", 1), "[json.exception.type_error.306] cannot use value() with boolean", typename Json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonobject_const.value("foo", 1), "[json.exception.type_error.306] cannot use value() with boolean", typename Json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonobject.value("foo", 1),
|
||||
"[json.exception.type_error.306] cannot use value() with boolean",
|
||||
typename Json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonobject_const.value("foo", 1),
|
||||
"[json.exception.type_error.306] cannot use value() with boolean",
|
||||
typename Json::type_error&);
|
||||
|
||||
#ifdef JSON_HAS_CPP_17
|
||||
CHECK_THROWS_WITH_AS(j_nonobject.value(std::string_view("foo"), 1), "[json.exception.type_error.306] cannot use value() with boolean", typename Json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonobject_const.value(std::string_view("foo"), 1), "[json.exception.type_error.306] cannot use value() with boolean", typename Json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonobject.value(std::string_view("foo"), 1),
|
||||
"[json.exception.type_error.306] cannot use value() with boolean",
|
||||
typename Json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonobject_const.value(std::string_view("foo"), 1),
|
||||
"[json.exception.type_error.306] cannot use value() with boolean",
|
||||
typename Json::type_error&);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -301,12 +364,20 @@ TEST_CASE_TEMPLATE("element access 2", Json, nlohmann::json, nlohmann::ordered_j
|
||||
{
|
||||
Json j_nonobject(Json::value_t::string);
|
||||
const Json j_nonobject_const(Json::value_t::string);
|
||||
CHECK_THROWS_WITH_AS(j_nonobject.value("foo", 1), "[json.exception.type_error.306] cannot use value() with string", typename Json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonobject_const.value("foo", 1), "[json.exception.type_error.306] cannot use value() with string", typename Json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonobject.value("foo", 1),
|
||||
"[json.exception.type_error.306] cannot use value() with string",
|
||||
typename Json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonobject_const.value("foo", 1),
|
||||
"[json.exception.type_error.306] cannot use value() with string",
|
||||
typename Json::type_error&);
|
||||
|
||||
#ifdef JSON_HAS_CPP_17
|
||||
CHECK_THROWS_WITH_AS(j_nonobject.value(std::string_view("foo"), 1), "[json.exception.type_error.306] cannot use value() with string", typename Json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonobject_const.value(std::string_view("foo"), 1), "[json.exception.type_error.306] cannot use value() with string", typename Json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonobject.value(std::string_view("foo"), 1),
|
||||
"[json.exception.type_error.306] cannot use value() with string",
|
||||
typename Json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonobject_const.value(std::string_view("foo"), 1),
|
||||
"[json.exception.type_error.306] cannot use value() with string",
|
||||
typename Json::type_error&);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -314,12 +385,20 @@ TEST_CASE_TEMPLATE("element access 2", Json, nlohmann::json, nlohmann::ordered_j
|
||||
{
|
||||
Json j_nonobject(Json::value_t::array);
|
||||
const Json j_nonobject_const(Json::value_t::array);
|
||||
CHECK_THROWS_WITH_AS(j_nonobject.value("foo", 1), "[json.exception.type_error.306] cannot use value() with array", typename Json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonobject_const.value("foo", 1), "[json.exception.type_error.306] cannot use value() with array", typename Json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonobject.value("foo", 1),
|
||||
"[json.exception.type_error.306] cannot use value() with array",
|
||||
typename Json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonobject_const.value("foo", 1),
|
||||
"[json.exception.type_error.306] cannot use value() with array",
|
||||
typename Json::type_error&);
|
||||
|
||||
#ifdef JSON_HAS_CPP_17
|
||||
CHECK_THROWS_WITH_AS(j_nonobject.value(std::string_view("foo"), 1), "[json.exception.type_error.306] cannot use value() with array", typename Json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonobject_const.value(std::string_view("foo"), 1), "[json.exception.type_error.306] cannot use value() with array", typename Json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonobject.value(std::string_view("foo"), 1),
|
||||
"[json.exception.type_error.306] cannot use value() with array",
|
||||
typename Json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonobject_const.value(std::string_view("foo"), 1),
|
||||
"[json.exception.type_error.306] cannot use value() with array",
|
||||
typename Json::type_error&);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -327,12 +406,20 @@ TEST_CASE_TEMPLATE("element access 2", Json, nlohmann::json, nlohmann::ordered_j
|
||||
{
|
||||
Json j_nonobject(Json::value_t::number_integer);
|
||||
const Json j_nonobject_const(Json::value_t::number_integer);
|
||||
CHECK_THROWS_WITH_AS(j_nonobject.value("foo", 1), "[json.exception.type_error.306] cannot use value() with number", typename Json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonobject_const.value("foo", 1), "[json.exception.type_error.306] cannot use value() with number", typename Json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonobject.value("foo", 1),
|
||||
"[json.exception.type_error.306] cannot use value() with number",
|
||||
typename Json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonobject_const.value("foo", 1),
|
||||
"[json.exception.type_error.306] cannot use value() with number",
|
||||
typename Json::type_error&);
|
||||
|
||||
#ifdef JSON_HAS_CPP_17
|
||||
CHECK_THROWS_WITH_AS(j_nonobject.value(std::string_view("foo"), 1), "[json.exception.type_error.306] cannot use value() with number", typename Json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonobject_const.value(std::string_view("foo"), 1), "[json.exception.type_error.306] cannot use value() with number", typename Json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonobject.value(std::string_view("foo"), 1),
|
||||
"[json.exception.type_error.306] cannot use value() with number",
|
||||
typename Json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonobject_const.value(std::string_view("foo"), 1),
|
||||
"[json.exception.type_error.306] cannot use value() with number",
|
||||
typename Json::type_error&);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -340,12 +427,20 @@ TEST_CASE_TEMPLATE("element access 2", Json, nlohmann::json, nlohmann::ordered_j
|
||||
{
|
||||
Json j_nonobject(Json::value_t::number_unsigned);
|
||||
const Json j_nonobject_const(Json::value_t::number_unsigned);
|
||||
CHECK_THROWS_WITH_AS(j_nonobject.value("foo", 1), "[json.exception.type_error.306] cannot use value() with number", typename Json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonobject_const.value("foo", 1), "[json.exception.type_error.306] cannot use value() with number", typename Json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonobject.value("foo", 1),
|
||||
"[json.exception.type_error.306] cannot use value() with number",
|
||||
typename Json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonobject_const.value("foo", 1),
|
||||
"[json.exception.type_error.306] cannot use value() with number",
|
||||
typename Json::type_error&);
|
||||
|
||||
#ifdef JSON_HAS_CPP_17
|
||||
CHECK_THROWS_WITH_AS(j_nonobject.value(std::string_view("foo"), 1), "[json.exception.type_error.306] cannot use value() with number", typename Json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonobject_const.value(std::string_view("foo"), 1), "[json.exception.type_error.306] cannot use value() with number", typename Json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonobject.value(std::string_view("foo"), 1),
|
||||
"[json.exception.type_error.306] cannot use value() with number",
|
||||
typename Json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonobject_const.value(std::string_view("foo"), 1),
|
||||
"[json.exception.type_error.306] cannot use value() with number",
|
||||
typename Json::type_error&);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -353,12 +448,20 @@ TEST_CASE_TEMPLATE("element access 2", Json, nlohmann::json, nlohmann::ordered_j
|
||||
{
|
||||
Json j_nonobject(Json::value_t::number_float);
|
||||
const Json j_nonobject_const(Json::value_t::number_float);
|
||||
CHECK_THROWS_WITH_AS(j_nonobject.value("foo", 1), "[json.exception.type_error.306] cannot use value() with number", typename Json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonobject_const.value("foo", 1), "[json.exception.type_error.306] cannot use value() with number", typename Json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonobject.value("foo", 1),
|
||||
"[json.exception.type_error.306] cannot use value() with number",
|
||||
typename Json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonobject_const.value("foo", 1),
|
||||
"[json.exception.type_error.306] cannot use value() with number",
|
||||
typename Json::type_error&);
|
||||
|
||||
#ifdef JSON_HAS_CPP_17
|
||||
CHECK_THROWS_WITH_AS(j_nonobject.value(std::string_view("foo"), 1), "[json.exception.type_error.306] cannot use value() with number", typename Json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonobject_const.value(std::string_view("foo"), 1), "[json.exception.type_error.306] cannot use value() with number", typename Json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonobject.value(std::string_view("foo"), 1),
|
||||
"[json.exception.type_error.306] cannot use value() with number",
|
||||
typename Json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonobject_const.value(std::string_view("foo"), 1),
|
||||
"[json.exception.type_error.306] cannot use value() with number",
|
||||
typename Json::type_error&);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -400,63 +503,90 @@ TEST_CASE_TEMPLATE("element access 2", Json, nlohmann::json, nlohmann::ordered_j
|
||||
{
|
||||
Json j_nonobject(Json::value_t::null);
|
||||
const Json j_nonobject_const(Json::value_t::null);
|
||||
CHECK_THROWS_WITH_AS(j_nonobject.value("/foo"_json_pointer, 1), "[json.exception.type_error.306] cannot use value() with null", typename Json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonobject_const.value("/foo"_json_pointer, 1), "[json.exception.type_error.306] cannot use value() with null", typename Json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonobject.value("/foo"_json_pointer, 1),
|
||||
"[json.exception.type_error.306] cannot use value() with null",
|
||||
typename Json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonobject_const.value("/foo"_json_pointer, 1),
|
||||
"[json.exception.type_error.306] cannot use value() with null",
|
||||
typename Json::type_error&);
|
||||
}
|
||||
|
||||
SECTION("boolean")
|
||||
{
|
||||
Json j_nonobject(Json::value_t::boolean);
|
||||
const Json j_nonobject_const(Json::value_t::boolean);
|
||||
CHECK_THROWS_WITH_AS(j_nonobject.value("/foo"_json_pointer, 1), "[json.exception.type_error.306] cannot use value() with boolean", typename Json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonobject_const.value("/foo"_json_pointer, 1), "[json.exception.type_error.306] cannot use value() with boolean", typename Json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonobject.value("/foo"_json_pointer, 1),
|
||||
"[json.exception.type_error.306] cannot use value() with boolean",
|
||||
typename Json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonobject_const.value("/foo"_json_pointer, 1),
|
||||
"[json.exception.type_error.306] cannot use value() with boolean",
|
||||
typename Json::type_error&);
|
||||
}
|
||||
|
||||
SECTION("string")
|
||||
{
|
||||
Json j_nonobject(Json::value_t::string);
|
||||
const Json j_nonobject_const(Json::value_t::string);
|
||||
CHECK_THROWS_WITH_AS(j_nonobject.value("/foo"_json_pointer, 1), "[json.exception.type_error.306] cannot use value() with string", typename Json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonobject_const.value("/foo"_json_pointer, 1), "[json.exception.type_error.306] cannot use value() with string", typename Json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonobject.value("/foo"_json_pointer, 1),
|
||||
"[json.exception.type_error.306] cannot use value() with string",
|
||||
typename Json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonobject_const.value("/foo"_json_pointer, 1),
|
||||
"[json.exception.type_error.306] cannot use value() with string",
|
||||
typename Json::type_error&);
|
||||
}
|
||||
|
||||
SECTION("array")
|
||||
{
|
||||
Json j_nonobject(Json::value_t::array);
|
||||
const Json j_nonobject_const(Json::value_t::array);
|
||||
CHECK_THROWS_WITH_AS(j_nonobject.value("/foo"_json_pointer, 1), "[json.exception.type_error.306] cannot use value() with array", typename Json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonobject_const.value("/foo"_json_pointer, 1), "[json.exception.type_error.306] cannot use value() with array", typename Json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonobject.value("/foo"_json_pointer, 1),
|
||||
"[json.exception.type_error.306] cannot use value() with array",
|
||||
typename Json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonobject_const.value("/foo"_json_pointer, 1),
|
||||
"[json.exception.type_error.306] cannot use value() with array",
|
||||
typename Json::type_error&);
|
||||
}
|
||||
|
||||
SECTION("number (integer)")
|
||||
{
|
||||
Json j_nonobject(Json::value_t::number_integer);
|
||||
const Json j_nonobject_const(Json::value_t::number_integer);
|
||||
CHECK_THROWS_WITH_AS(j_nonobject.value("/foo"_json_pointer, 1), "[json.exception.type_error.306] cannot use value() with number", typename Json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonobject_const.value("/foo"_json_pointer, 1), "[json.exception.type_error.306] cannot use value() with number", typename Json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonobject.value("/foo"_json_pointer, 1),
|
||||
"[json.exception.type_error.306] cannot use value() with number",
|
||||
typename Json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonobject_const.value("/foo"_json_pointer, 1),
|
||||
"[json.exception.type_error.306] cannot use value() with number",
|
||||
typename Json::type_error&);
|
||||
}
|
||||
|
||||
SECTION("number (unsigned)")
|
||||
{
|
||||
Json j_nonobject(Json::value_t::number_unsigned);
|
||||
const Json j_nonobject_const(Json::value_t::number_unsigned);
|
||||
CHECK_THROWS_WITH_AS(j_nonobject.value("/foo"_json_pointer, 1), "[json.exception.type_error.306] cannot use value() with number", typename Json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonobject_const.value("/foo"_json_pointer, 1), "[json.exception.type_error.306] cannot use value() with number", typename Json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonobject.value("/foo"_json_pointer, 1),
|
||||
"[json.exception.type_error.306] cannot use value() with number",
|
||||
typename Json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonobject_const.value("/foo"_json_pointer, 1),
|
||||
"[json.exception.type_error.306] cannot use value() with number",
|
||||
typename Json::type_error&);
|
||||
}
|
||||
|
||||
SECTION("number (floating-point)")
|
||||
{
|
||||
Json j_nonobject(Json::value_t::number_float);
|
||||
const Json j_nonobject_const(Json::value_t::number_float);
|
||||
CHECK_THROWS_WITH_AS(j_nonobject.value("/foo"_json_pointer, 1), "[json.exception.type_error.306] cannot use value() with number", typename Json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonobject_const.value("/foo"_json_pointer, 1), "[json.exception.type_error.306] cannot use value() with number", typename Json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonobject.value("/foo"_json_pointer, 1),
|
||||
"[json.exception.type_error.306] cannot use value() with number",
|
||||
typename Json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonobject_const.value("/foo"_json_pointer, 1),
|
||||
"[json.exception.type_error.306] cannot use value() with number",
|
||||
typename Json::type_error&);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SECTION("non-const operator[]"){
|
||||
{Json j_null;
|
||||
SECTION("non-const operator[]"){{Json j_null;
|
||||
CHECK(j_null.is_null());
|
||||
j_null["key"] = 1;
|
||||
CHECK(j_null.is_object());
|
||||
@@ -610,12 +740,18 @@ SECTION("access specified element")
|
||||
|
||||
CHECK_NOTHROW(j_nonobject["foo"]);
|
||||
CHECK_NOTHROW(j_nonobject2[typename Json::object_t::key_type("foo")]);
|
||||
CHECK_THROWS_WITH_AS(j_const_nonobject["foo"], "[json.exception.type_error.305] cannot use operator[] with a string argument with null", typename Json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_const_nonobject[typename Json::object_t::key_type("foo")], "[json.exception.type_error.305] cannot use operator[] with a string argument with null", typename Json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_const_nonobject["foo"],
|
||||
"[json.exception.type_error.305] cannot use operator[] with a string argument with null",
|
||||
typename Json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_const_nonobject[typename Json::object_t::key_type("foo")],
|
||||
"[json.exception.type_error.305] cannot use operator[] with a string argument with null",
|
||||
typename Json::type_error&);
|
||||
|
||||
#ifdef JSON_HAS_CPP_17
|
||||
CHECK_NOTHROW(j_nonobject2[std::string_view("foo")]);
|
||||
CHECK_THROWS_WITH_AS(j_const_nonobject[std::string_view("foo")], "[json.exception.type_error.305] cannot use operator[] with a string argument with null", typename Json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_const_nonobject[std::string_view("foo")],
|
||||
"[json.exception.type_error.305] cannot use operator[] with a string argument with null",
|
||||
typename Json::type_error&);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -637,8 +773,12 @@ SECTION("access specified element")
|
||||
typename Json::type_error&);
|
||||
|
||||
#ifdef JSON_HAS_CPP_17
|
||||
CHECK_THROWS_WITH_AS(j_nonobject[std::string_view("foo")], "[json.exception.type_error.305] cannot use operator[] with a string argument with boolean", typename Json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_const_nonobject[std::string_view("foo")], "[json.exception.type_error.305] cannot use operator[] with a string argument with boolean", typename Json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonobject[std::string_view("foo")],
|
||||
"[json.exception.type_error.305] cannot use operator[] with a string argument with boolean",
|
||||
typename Json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_const_nonobject[std::string_view("foo")],
|
||||
"[json.exception.type_error.305] cannot use operator[] with a string argument with boolean",
|
||||
typename Json::type_error&);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -660,8 +800,12 @@ SECTION("access specified element")
|
||||
typename Json::type_error&);
|
||||
|
||||
#ifdef JSON_HAS_CPP_17
|
||||
CHECK_THROWS_WITH_AS(j_nonobject[std::string_view("foo")], "[json.exception.type_error.305] cannot use operator[] with a string argument with string", typename Json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_const_nonobject[std::string_view("foo")], "[json.exception.type_error.305] cannot use operator[] with a string argument with string", typename Json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonobject[std::string_view("foo")],
|
||||
"[json.exception.type_error.305] cannot use operator[] with a string argument with string",
|
||||
typename Json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_const_nonobject[std::string_view("foo")],
|
||||
"[json.exception.type_error.305] cannot use operator[] with a string argument with string",
|
||||
typename Json::type_error&);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -672,7 +816,9 @@ SECTION("access specified element")
|
||||
CHECK_THROWS_WITH_AS(j_nonobject["foo"],
|
||||
"[json.exception.type_error.305] cannot use operator[] with a string argument with array",
|
||||
typename Json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonobject[typename Json::object_t::key_type("foo")], "[json.exception.type_error.305] cannot use operator[] with a string argument with array", typename Json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonobject[typename Json::object_t::key_type("foo")],
|
||||
"[json.exception.type_error.305] cannot use operator[] with a string argument with array",
|
||||
typename Json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_const_nonobject["foo"],
|
||||
"[json.exception.type_error.305] cannot use operator[] with a string argument with array",
|
||||
typename Json::type_error&);
|
||||
@@ -681,8 +827,12 @@ SECTION("access specified element")
|
||||
typename Json::type_error&);
|
||||
|
||||
#ifdef JSON_HAS_CPP_17
|
||||
CHECK_THROWS_WITH_AS(j_nonobject[std::string_view("foo")], "[json.exception.type_error.305] cannot use operator[] with a string argument with array", typename Json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_const_nonobject[std::string_view("foo")], "[json.exception.type_error.305] cannot use operator[] with a string argument with array", typename Json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonobject[std::string_view("foo")],
|
||||
"[json.exception.type_error.305] cannot use operator[] with a string argument with array",
|
||||
typename Json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_const_nonobject[std::string_view("foo")],
|
||||
"[json.exception.type_error.305] cannot use operator[] with a string argument with array",
|
||||
typename Json::type_error&);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -704,8 +854,12 @@ SECTION("access specified element")
|
||||
typename Json::type_error&);
|
||||
|
||||
#ifdef JSON_HAS_CPP_17
|
||||
CHECK_THROWS_WITH_AS(j_nonobject[std::string_view("foo")], "[json.exception.type_error.305] cannot use operator[] with a string argument with number", typename Json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_const_nonobject[std::string_view("foo")], "[json.exception.type_error.305] cannot use operator[] with a string argument with number", typename Json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonobject[std::string_view("foo")],
|
||||
"[json.exception.type_error.305] cannot use operator[] with a string argument with number",
|
||||
typename Json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_const_nonobject[std::string_view("foo")],
|
||||
"[json.exception.type_error.305] cannot use operator[] with a string argument with number",
|
||||
typename Json::type_error&);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -727,8 +881,12 @@ SECTION("access specified element")
|
||||
typename Json::type_error&);
|
||||
|
||||
#ifdef JSON_HAS_CPP_17
|
||||
CHECK_THROWS_WITH_AS(j_nonobject[std::string_view("foo")], "[json.exception.type_error.305] cannot use operator[] with a string argument with number", typename Json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_const_nonobject[std::string_view("foo")], "[json.exception.type_error.305] cannot use operator[] with a string argument with number", typename Json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonobject[std::string_view("foo")],
|
||||
"[json.exception.type_error.305] cannot use operator[] with a string argument with number",
|
||||
typename Json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_const_nonobject[std::string_view("foo")],
|
||||
"[json.exception.type_error.305] cannot use operator[] with a string argument with number",
|
||||
typename Json::type_error&);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -750,8 +908,12 @@ SECTION("access specified element")
|
||||
typename Json::type_error&);
|
||||
|
||||
#ifdef JSON_HAS_CPP_17
|
||||
CHECK_THROWS_WITH_AS(j_nonobject[std::string_view("foo")], "[json.exception.type_error.305] cannot use operator[] with a string argument with number", typename Json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_const_nonobject[std::string_view("foo")], "[json.exception.type_error.305] cannot use operator[] with a string argument with number", typename Json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonobject[std::string_view("foo")],
|
||||
"[json.exception.type_error.305] cannot use operator[] with a string argument with number",
|
||||
typename Json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_const_nonobject[std::string_view("foo")],
|
||||
"[json.exception.type_error.305] cannot use operator[] with a string argument with number",
|
||||
typename Json::type_error&);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -976,7 +1138,9 @@ SECTION("remove specified element")
|
||||
CHECK_THROWS_WITH_AS(j_nonobject.erase("foo"), "[json.exception.type_error.307] cannot use erase() with null", typename Json::type_error&);
|
||||
|
||||
#ifdef JSON_HAS_CPP_17
|
||||
CHECK_THROWS_WITH_AS(j_nonobject.erase(std::string_view("foo")), "[json.exception.type_error.307] cannot use erase() with null", typename Json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonobject.erase(std::string_view("foo")),
|
||||
"[json.exception.type_error.307] cannot use erase() with null",
|
||||
typename Json::type_error&);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -986,7 +1150,9 @@ SECTION("remove specified element")
|
||||
CHECK_THROWS_WITH_AS(j_nonobject.erase("foo"), "[json.exception.type_error.307] cannot use erase() with boolean", typename Json::type_error&);
|
||||
|
||||
#ifdef JSON_HAS_CPP_17
|
||||
CHECK_THROWS_WITH_AS(j_nonobject.erase(std::string_view("foo")), "[json.exception.type_error.307] cannot use erase() with boolean", typename Json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonobject.erase(std::string_view("foo")),
|
||||
"[json.exception.type_error.307] cannot use erase() with boolean",
|
||||
typename Json::type_error&);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -996,7 +1162,9 @@ SECTION("remove specified element")
|
||||
CHECK_THROWS_WITH_AS(j_nonobject.erase("foo"), "[json.exception.type_error.307] cannot use erase() with string", typename Json::type_error&);
|
||||
|
||||
#ifdef JSON_HAS_CPP_17
|
||||
CHECK_THROWS_WITH_AS(j_nonobject.erase(std::string_view("foo")), "[json.exception.type_error.307] cannot use erase() with string", typename Json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonobject.erase(std::string_view("foo")),
|
||||
"[json.exception.type_error.307] cannot use erase() with string",
|
||||
typename Json::type_error&);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -1006,7 +1174,9 @@ SECTION("remove specified element")
|
||||
CHECK_THROWS_WITH_AS(j_nonobject.erase("foo"), "[json.exception.type_error.307] cannot use erase() with array", typename Json::type_error&);
|
||||
|
||||
#ifdef JSON_HAS_CPP_17
|
||||
CHECK_THROWS_WITH_AS(j_nonobject.erase(std::string_view("foo")), "[json.exception.type_error.307] cannot use erase() with array", typename Json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonobject.erase(std::string_view("foo")),
|
||||
"[json.exception.type_error.307] cannot use erase() with array",
|
||||
typename Json::type_error&);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -1016,7 +1186,9 @@ SECTION("remove specified element")
|
||||
CHECK_THROWS_WITH_AS(j_nonobject.erase("foo"), "[json.exception.type_error.307] cannot use erase() with number", typename Json::type_error&);
|
||||
|
||||
#ifdef JSON_HAS_CPP_17
|
||||
CHECK_THROWS_WITH_AS(j_nonobject.erase(std::string_view("foo")), "[json.exception.type_error.307] cannot use erase() with number", typename Json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonobject.erase(std::string_view("foo")),
|
||||
"[json.exception.type_error.307] cannot use erase() with number",
|
||||
typename Json::type_error&);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -1026,7 +1198,9 @@ SECTION("remove specified element")
|
||||
CHECK_THROWS_WITH_AS(j_nonobject.erase("foo"), "[json.exception.type_error.307] cannot use erase() with number", typename Json::type_error&);
|
||||
|
||||
#ifdef JSON_HAS_CPP_17
|
||||
CHECK_THROWS_WITH_AS(j_nonobject.erase(std::string_view("foo")), "[json.exception.type_error.307] cannot use erase() with number", typename Json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonobject.erase(std::string_view("foo")),
|
||||
"[json.exception.type_error.307] cannot use erase() with number",
|
||||
typename Json::type_error&);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -1036,8 +1210,7 @@ SECTION("find an element in an object")
|
||||
{
|
||||
SECTION("existing element")
|
||||
{
|
||||
for (const auto* key :
|
||||
{"integer", "unsigned", "floating", "null", "string", "boolean", "object", "array"})
|
||||
for (const auto* key : {"integer", "unsigned", "floating", "null", "string", "boolean", "object", "array"})
|
||||
{
|
||||
CHECK(j.find(key) != j.end());
|
||||
CHECK(*j.find(key) == j.at(key));
|
||||
@@ -1045,8 +1218,7 @@ SECTION("find an element in an object")
|
||||
CHECK(*j_const.find(key) == j_const.at(key));
|
||||
}
|
||||
#ifdef JSON_HAS_CPP_17
|
||||
for (const std::string_view key :
|
||||
{"integer", "unsigned", "floating", "null", "string", "boolean", "object", "array"})
|
||||
for (const std::string_view key : {"integer", "unsigned", "floating", "null", "string", "boolean", "object", "array"})
|
||||
{
|
||||
CHECK(j.find(key) != j.end());
|
||||
CHECK(*j.find(key) == j.at(key));
|
||||
@@ -1187,15 +1359,13 @@ SECTION("count keys in an object")
|
||||
{
|
||||
SECTION("existing element")
|
||||
{
|
||||
for (const auto* key :
|
||||
{"integer", "unsigned", "floating", "null", "string", "boolean", "object", "array"})
|
||||
for (const auto* key : {"integer", "unsigned", "floating", "null", "string", "boolean", "object", "array"})
|
||||
{
|
||||
CHECK(j.count(key) == 1);
|
||||
CHECK(j_const.count(key) == 1);
|
||||
}
|
||||
#ifdef JSON_HAS_CPP_17
|
||||
for (const std::string_view key :
|
||||
{"integer", "unsigned", "floating", "null", "string", "boolean", "object", "array"})
|
||||
for (const std::string_view key : {"integer", "unsigned", "floating", "null", "string", "boolean", "object", "array"})
|
||||
{
|
||||
CHECK(j.count(key) == 1);
|
||||
CHECK(j_const.count(key) == 1);
|
||||
@@ -1334,16 +1504,14 @@ SECTION("check existence of key in an object")
|
||||
{
|
||||
SECTION("existing element")
|
||||
{
|
||||
for (const auto* key :
|
||||
{"integer", "unsigned", "floating", "null", "string", "boolean", "object", "array"})
|
||||
for (const auto* key : {"integer", "unsigned", "floating", "null", "string", "boolean", "object", "array"})
|
||||
{
|
||||
CHECK(j.contains(key) == true);
|
||||
CHECK(j_const.contains(key) == true);
|
||||
}
|
||||
|
||||
#ifdef JSON_HAS_CPP_17
|
||||
for (const std::string_view key :
|
||||
{"integer", "unsigned", "floating", "null", "string", "boolean", "object", "array"})
|
||||
for (const std::string_view key : {"integer", "unsigned", "floating", "null", "string", "boolean", "object", "array"})
|
||||
{
|
||||
CHECK(j.contains(key) == true);
|
||||
CHECK(j_const.contains(key) == true);
|
||||
@@ -1483,8 +1651,22 @@ TEST_CASE_TEMPLATE("element access 2 (throwing tests)", Json, nlohmann::json, nl
|
||||
{
|
||||
SECTION("object")
|
||||
{
|
||||
Json j = {{"integer", 1}, {"unsigned", 1u}, {"floating", 42.23}, {"null", nullptr}, {"string", "hello world"}, {"boolean", true}, {"object", Json::object()}, {"array", {1, 2, 3}}};
|
||||
const Json j_const = {{"integer", 1}, {"unsigned", 1u}, {"floating", 42.23}, {"null", nullptr}, {"string", "hello world"}, {"boolean", true}, {"object", Json::object()}, {"array", {1, 2, 3}}};
|
||||
Json j = {{"integer", 1},
|
||||
{"unsigned", 1u},
|
||||
{"floating", 42.23},
|
||||
{"null", nullptr},
|
||||
{"string", "hello world"},
|
||||
{"boolean", true},
|
||||
{"object", Json::object()},
|
||||
{"array", {1, 2, 3}}};
|
||||
const Json j_const = {{"integer", 1},
|
||||
{"unsigned", 1u},
|
||||
{"floating", 42.23},
|
||||
{"null", nullptr},
|
||||
{"string", "hello world"},
|
||||
{"boolean", true},
|
||||
{"object", Json::object()},
|
||||
{"array", {1, 2, 3}}};
|
||||
|
||||
SECTION("access specified element with default value")
|
||||
{
|
||||
@@ -1523,9 +1705,7 @@ TEST_CASE_TEMPLATE("element access 2 (additional value() tests)", Json, nlohmann
|
||||
// test assumes string_t and object_t::key_type are the same
|
||||
REQUIRE(std::is_same<string_t, typename Json::object_t::key_type>::value);
|
||||
|
||||
Json j{
|
||||
{"foo", "bar"},
|
||||
{"baz", 42}};
|
||||
Json j{{"foo", "bar"}, {"baz", 42}};
|
||||
|
||||
const char* cpstr = "default";
|
||||
const char castr[] = "default"; // NOLINT(hicpp-avoid-c-arrays,modernize-avoid-c-arrays,cppcoreguidelines-avoid-c-arrays)
|
||||
@@ -1534,9 +1714,7 @@ TEST_CASE_TEMPLATE("element access 2 (additional value() tests)", Json, nlohmann
|
||||
number_integer_t integer = 69;
|
||||
std::size_t size = 69;
|
||||
|
||||
SECTION("deduced ValueType"){
|
||||
SECTION("literal key"){
|
||||
CHECK(j.value("foo", "default") == "bar");
|
||||
SECTION("deduced ValueType"){SECTION("literal key"){CHECK(j.value("foo", "default") == "bar");
|
||||
CHECK(j.value("foo", cpstr) == "bar");
|
||||
CHECK(j.value("foo", castr) == "bar");
|
||||
CHECK(j.value("foo", str) == "bar");
|
||||
@@ -1684,8 +1862,12 @@ SECTION("explicit ValueType")
|
||||
CHECK(j.template value<std::size_t>("bar", 47) == 47);
|
||||
CHECK(j.template value<std::size_t>("bar", size) == size);
|
||||
|
||||
CHECK_THROWS_WITH_AS(Json().template value<string_t>("foo", "default"), "[json.exception.type_error.306] cannot use value() with null", typename Json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(Json().template value<string_t>("foo", str), "[json.exception.type_error.306] cannot use value() with null", typename Json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(Json().template value<string_t>("foo", "default"),
|
||||
"[json.exception.type_error.306] cannot use value() with null",
|
||||
typename Json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(Json().template value<string_t>("foo", str),
|
||||
"[json.exception.type_error.306] cannot use value() with null",
|
||||
typename Json::type_error&);
|
||||
}
|
||||
|
||||
SECTION("const char * key")
|
||||
@@ -1713,8 +1895,12 @@ SECTION("explicit ValueType")
|
||||
CHECK(j.template value<std::size_t>(key_notfound, 47) == 47);
|
||||
CHECK(j.template value<std::size_t>(key_notfound, size) == size);
|
||||
|
||||
CHECK_THROWS_WITH_AS(Json().template value<string_t>(key, "default"), "[json.exception.type_error.306] cannot use value() with null", typename Json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(Json().template value<string_t>(key, str), "[json.exception.type_error.306] cannot use value() with null", typename Json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(Json().template value<string_t>(key, "default"),
|
||||
"[json.exception.type_error.306] cannot use value() with null",
|
||||
typename Json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(Json().template value<string_t>(key, str),
|
||||
"[json.exception.type_error.306] cannot use value() with null",
|
||||
typename Json::type_error&);
|
||||
}
|
||||
|
||||
SECTION("const char(&)[] key")
|
||||
@@ -1742,8 +1928,12 @@ SECTION("explicit ValueType")
|
||||
CHECK(j.template value<std::size_t>(key_notfound, 47) == 47);
|
||||
CHECK(j.template value<std::size_t>(key_notfound, size) == size);
|
||||
|
||||
CHECK_THROWS_WITH_AS(Json().template value<string_t>(key, "default"), "[json.exception.type_error.306] cannot use value() with null", typename Json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(Json().template value<string_t>(key, str), "[json.exception.type_error.306] cannot use value() with null", typename Json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(Json().template value<string_t>(key, "default"),
|
||||
"[json.exception.type_error.306] cannot use value() with null",
|
||||
typename Json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(Json().template value<string_t>(key, str),
|
||||
"[json.exception.type_error.306] cannot use value() with null",
|
||||
typename Json::type_error&);
|
||||
}
|
||||
|
||||
SECTION("string_t/object_t::key_type key")
|
||||
@@ -1767,8 +1957,12 @@ SECTION("explicit ValueType")
|
||||
CHECK(j.template value<std::size_t>(key_notfound, 0) == 0);
|
||||
CHECK(j.template value<std::size_t>(key_notfound, 47) == 47);
|
||||
|
||||
CHECK_THROWS_WITH_AS(Json().template value<string_t>(key, "default"), "[json.exception.type_error.306] cannot use value() with null", typename Json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(Json().template value<string_t>(key, str), "[json.exception.type_error.306] cannot use value() with null", typename Json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(Json().template value<string_t>(key, "default"),
|
||||
"[json.exception.type_error.306] cannot use value() with null",
|
||||
typename Json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(Json().template value<string_t>(key, str),
|
||||
"[json.exception.type_error.306] cannot use value() with null",
|
||||
typename Json::type_error&);
|
||||
}
|
||||
|
||||
#ifdef JSON_HAS_CPP_17
|
||||
@@ -1804,8 +1998,12 @@ SECTION("explicit ValueType")
|
||||
|
||||
CHECK(j.template value<std::string_view>(key_notfound, "default") == "default");
|
||||
|
||||
CHECK_THROWS_WITH_AS(Json().template value<string_t>(key, "default"), "[json.exception.type_error.306] cannot use value() with null", typename Json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(Json().template value<string_t>(key, str), "[json.exception.type_error.306] cannot use value() with null", typename Json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(Json().template value<string_t>(key, "default"),
|
||||
"[json.exception.type_error.306] cannot use value() with null",
|
||||
typename Json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(Json().template value<string_t>(key, str),
|
||||
"[json.exception.type_error.306] cannot use value() with null",
|
||||
typename Json::type_error&);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -206,8 +206,7 @@ TEST_CASE("object inspection")
|
||||
|
||||
SECTION("no indent / indent=-1")
|
||||
{
|
||||
CHECK(j.dump() ==
|
||||
"{\"array\":[1,2,3,4],\"boolean\":false,\"null\":null,\"number\":42,\"object\":{},\"string\":\"Hello world\"}");
|
||||
CHECK(j.dump() == "{\"array\":[1,2,3,4],\"boolean\":false,\"null\":null,\"number\":42,\"object\":{},\"string\":\"Hello world\"}");
|
||||
|
||||
CHECK(j.dump() == j.dump(-1));
|
||||
}
|
||||
@@ -220,14 +219,16 @@ TEST_CASE("object inspection")
|
||||
|
||||
SECTION("indent=1, space='\t'")
|
||||
{
|
||||
CHECK(j.dump(1, '\t') ==
|
||||
"{\n\t\"array\": [\n\t\t1,\n\t\t2,\n\t\t3,\n\t\t4\n\t],\n\t\"boolean\": false,\n\t\"null\": null,\n\t\"number\": 42,\n\t\"object\": {},\n\t\"string\": \"Hello world\"\n}");
|
||||
CHECK(
|
||||
j.dump(1, '\t') ==
|
||||
"{\n\t\"array\": [\n\t\t1,\n\t\t2,\n\t\t3,\n\t\t4\n\t],\n\t\"boolean\": false,\n\t\"null\": null,\n\t\"number\": 42,\n\t\"object\": {},\n\t\"string\": \"Hello world\"\n}");
|
||||
}
|
||||
|
||||
SECTION("indent=4")
|
||||
{
|
||||
CHECK(j.dump(4) ==
|
||||
"{\n \"array\": [\n 1,\n 2,\n 3,\n 4\n ],\n \"boolean\": false,\n \"null\": null,\n \"number\": 42,\n \"object\": {},\n \"string\": \"Hello world\"\n}");
|
||||
CHECK(
|
||||
j.dump(4) ==
|
||||
"{\n \"array\": [\n 1,\n 2,\n 3,\n 4\n ],\n \"boolean\": false,\n \"null\": null,\n \"number\": 42,\n \"object\": {},\n \"string\": \"Hello world\"\n}");
|
||||
}
|
||||
|
||||
SECTION("indent=x")
|
||||
@@ -291,8 +292,7 @@ TEST_CASE("object inspection")
|
||||
json const value = json::parse(f_unescaped);
|
||||
std::string text = value.dump(4, ' ', true);
|
||||
|
||||
std::string expected((std::istreambuf_iterator<char>(f_escaped)),
|
||||
std::istreambuf_iterator<char>());
|
||||
std::string expected((std::istreambuf_iterator<char>(f_escaped)), std::istreambuf_iterator<char>());
|
||||
CHECK(text == expected);
|
||||
}
|
||||
}
|
||||
@@ -328,8 +328,7 @@ TEST_CASE("object inspection")
|
||||
|
||||
SECTION("round trips")
|
||||
{
|
||||
for (const auto& s :
|
||||
{"3.141592653589793", "1000000000000000010E5"})
|
||||
for (const auto& s : {"3.141592653589793", "1000000000000000010E5"})
|
||||
{
|
||||
json const j1 = json::parse(s);
|
||||
std::string s1 = j1.dump();
|
||||
|
||||
@@ -718,9 +718,7 @@ TEST_CASE("iterator_wrapper")
|
||||
|
||||
TEST_CASE("items()")
|
||||
{
|
||||
SECTION("object"){
|
||||
SECTION("value"){
|
||||
json j = {{"A", 1}, {"B", 2}};
|
||||
SECTION("object"){SECTION("value"){json j = {{"A", 1}, {"B", 2}};
|
||||
int counter = 1;
|
||||
|
||||
for (auto i : j.items()) // NOLINT(performance-for-range-copy)
|
||||
|
||||
+312
-104
@@ -74,23 +74,47 @@ TEST_CASE("iterators 2")
|
||||
if (j.type() == json::value_t::object)
|
||||
{
|
||||
#if JSON_DIAGNOSTICS
|
||||
CHECK_THROWS_WITH_AS(it1 < it1, "[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1 < it2, "[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it2 < it3, "[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1 < it3, "[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1_c < it1_c, "[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1_c < it2_c, "[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it2_c < it3_c, "[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1_c < it3_c, "[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1 < it1,
|
||||
"[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators",
|
||||
json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1 < it2,
|
||||
"[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators",
|
||||
json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it2 < it3,
|
||||
"[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators",
|
||||
json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1 < it3,
|
||||
"[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators",
|
||||
json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1_c < it1_c,
|
||||
"[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators",
|
||||
json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1_c < it2_c,
|
||||
"[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators",
|
||||
json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it2_c < it3_c,
|
||||
"[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators",
|
||||
json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1_c < it3_c,
|
||||
"[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators",
|
||||
json::invalid_iterator&);
|
||||
#else
|
||||
CHECK_THROWS_WITH_AS(it1 < it1, "[json.exception.invalid_iterator.213] cannot compare order of object iterators", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1 < it2, "[json.exception.invalid_iterator.213] cannot compare order of object iterators", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it2 < it3, "[json.exception.invalid_iterator.213] cannot compare order of object iterators", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1 < it3, "[json.exception.invalid_iterator.213] cannot compare order of object iterators", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1_c < it1_c, "[json.exception.invalid_iterator.213] cannot compare order of object iterators", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1_c < it2_c, "[json.exception.invalid_iterator.213] cannot compare order of object iterators", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it2_c < it3_c, "[json.exception.invalid_iterator.213] cannot compare order of object iterators", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1_c < it3_c, "[json.exception.invalid_iterator.213] cannot compare order of object iterators", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1_c < it1_c,
|
||||
"[json.exception.invalid_iterator.213] cannot compare order of object iterators",
|
||||
json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1_c < it2_c,
|
||||
"[json.exception.invalid_iterator.213] cannot compare order of object iterators",
|
||||
json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it2_c < it3_c,
|
||||
"[json.exception.invalid_iterator.213] cannot compare order of object iterators",
|
||||
json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1_c < it3_c,
|
||||
"[json.exception.invalid_iterator.213] cannot compare order of object iterators",
|
||||
json::invalid_iterator&);
|
||||
#endif
|
||||
}
|
||||
else
|
||||
@@ -111,23 +135,47 @@ TEST_CASE("iterators 2")
|
||||
if (j.type() == json::value_t::object)
|
||||
{
|
||||
#if JSON_DIAGNOSTICS
|
||||
CHECK_THROWS_WITH_AS(it1 <= it1, "[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1 <= it2, "[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it2 <= it3, "[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1 <= it3, "[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1_c <= it1_c, "[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1_c <= it2_c, "[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it2_c <= it3_c, "[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1_c <= it3_c, "[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1 <= it1,
|
||||
"[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators",
|
||||
json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1 <= it2,
|
||||
"[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators",
|
||||
json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it2 <= it3,
|
||||
"[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators",
|
||||
json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1 <= it3,
|
||||
"[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators",
|
||||
json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1_c <= it1_c,
|
||||
"[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators",
|
||||
json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1_c <= it2_c,
|
||||
"[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators",
|
||||
json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it2_c <= it3_c,
|
||||
"[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators",
|
||||
json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1_c <= it3_c,
|
||||
"[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators",
|
||||
json::invalid_iterator&);
|
||||
#else
|
||||
CHECK_THROWS_WITH_AS(it1 <= it1, "[json.exception.invalid_iterator.213] cannot compare order of object iterators", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1 <= it2, "[json.exception.invalid_iterator.213] cannot compare order of object iterators", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it2 <= it3, "[json.exception.invalid_iterator.213] cannot compare order of object iterators", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1 <= it3, "[json.exception.invalid_iterator.213] cannot compare order of object iterators", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1_c <= it1_c, "[json.exception.invalid_iterator.213] cannot compare order of object iterators", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1_c <= it2_c, "[json.exception.invalid_iterator.213] cannot compare order of object iterators", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it2_c <= it3_c, "[json.exception.invalid_iterator.213] cannot compare order of object iterators", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1_c <= it3_c, "[json.exception.invalid_iterator.213] cannot compare order of object iterators", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1_c <= it1_c,
|
||||
"[json.exception.invalid_iterator.213] cannot compare order of object iterators",
|
||||
json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1_c <= it2_c,
|
||||
"[json.exception.invalid_iterator.213] cannot compare order of object iterators",
|
||||
json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it2_c <= it3_c,
|
||||
"[json.exception.invalid_iterator.213] cannot compare order of object iterators",
|
||||
json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1_c <= it3_c,
|
||||
"[json.exception.invalid_iterator.213] cannot compare order of object iterators",
|
||||
json::invalid_iterator&);
|
||||
#endif
|
||||
}
|
||||
else
|
||||
@@ -149,23 +197,47 @@ TEST_CASE("iterators 2")
|
||||
if (j.type() == json::value_t::object)
|
||||
{
|
||||
#if JSON_DIAGNOSTICS
|
||||
CHECK_THROWS_WITH_AS(it1 > it1, "[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1 > it2, "[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it2 > it3, "[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1 > it3, "[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1_c > it1_c, "[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1_c > it2_c, "[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it2_c > it3_c, "[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1_c > it3_c, "[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1 > it1,
|
||||
"[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators",
|
||||
json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1 > it2,
|
||||
"[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators",
|
||||
json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it2 > it3,
|
||||
"[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators",
|
||||
json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1 > it3,
|
||||
"[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators",
|
||||
json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1_c > it1_c,
|
||||
"[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators",
|
||||
json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1_c > it2_c,
|
||||
"[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators",
|
||||
json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it2_c > it3_c,
|
||||
"[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators",
|
||||
json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1_c > it3_c,
|
||||
"[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators",
|
||||
json::invalid_iterator&);
|
||||
#else
|
||||
CHECK_THROWS_WITH_AS(it1 > it1, "[json.exception.invalid_iterator.213] cannot compare order of object iterators", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1 > it2, "[json.exception.invalid_iterator.213] cannot compare order of object iterators", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it2 > it3, "[json.exception.invalid_iterator.213] cannot compare order of object iterators", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1 > it3, "[json.exception.invalid_iterator.213] cannot compare order of object iterators", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1_c > it1_c, "[json.exception.invalid_iterator.213] cannot compare order of object iterators", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1_c > it2_c, "[json.exception.invalid_iterator.213] cannot compare order of object iterators", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it2_c > it3_c, "[json.exception.invalid_iterator.213] cannot compare order of object iterators", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1_c > it3_c, "[json.exception.invalid_iterator.213] cannot compare order of object iterators", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1_c > it1_c,
|
||||
"[json.exception.invalid_iterator.213] cannot compare order of object iterators",
|
||||
json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1_c > it2_c,
|
||||
"[json.exception.invalid_iterator.213] cannot compare order of object iterators",
|
||||
json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it2_c > it3_c,
|
||||
"[json.exception.invalid_iterator.213] cannot compare order of object iterators",
|
||||
json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1_c > it3_c,
|
||||
"[json.exception.invalid_iterator.213] cannot compare order of object iterators",
|
||||
json::invalid_iterator&);
|
||||
#endif
|
||||
}
|
||||
else
|
||||
@@ -187,23 +259,47 @@ TEST_CASE("iterators 2")
|
||||
if (j.type() == json::value_t::object)
|
||||
{
|
||||
#if JSON_DIAGNOSTICS
|
||||
CHECK_THROWS_WITH_AS(it1 >= it1, "[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1 >= it2, "[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it2 >= it3, "[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1 >= it3, "[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1_c >= it1_c, "[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1_c >= it2_c, "[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it2_c >= it3_c, "[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1_c >= it3_c, "[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1 >= it1,
|
||||
"[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators",
|
||||
json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1 >= it2,
|
||||
"[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators",
|
||||
json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it2 >= it3,
|
||||
"[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators",
|
||||
json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1 >= it3,
|
||||
"[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators",
|
||||
json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1_c >= it1_c,
|
||||
"[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators",
|
||||
json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1_c >= it2_c,
|
||||
"[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators",
|
||||
json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it2_c >= it3_c,
|
||||
"[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators",
|
||||
json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1_c >= it3_c,
|
||||
"[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators",
|
||||
json::invalid_iterator&);
|
||||
#else
|
||||
CHECK_THROWS_WITH_AS(it1 >= it1, "[json.exception.invalid_iterator.213] cannot compare order of object iterators", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1 >= it2, "[json.exception.invalid_iterator.213] cannot compare order of object iterators", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it2 >= it3, "[json.exception.invalid_iterator.213] cannot compare order of object iterators", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1 >= it3, "[json.exception.invalid_iterator.213] cannot compare order of object iterators", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1_c >= it1_c, "[json.exception.invalid_iterator.213] cannot compare order of object iterators", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1_c >= it2_c, "[json.exception.invalid_iterator.213] cannot compare order of object iterators", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it2_c >= it3_c, "[json.exception.invalid_iterator.213] cannot compare order of object iterators", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1_c >= it3_c, "[json.exception.invalid_iterator.213] cannot compare order of object iterators", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1_c >= it1_c,
|
||||
"[json.exception.invalid_iterator.213] cannot compare order of object iterators",
|
||||
json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1_c >= it2_c,
|
||||
"[json.exception.invalid_iterator.213] cannot compare order of object iterators",
|
||||
json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it2_c >= it3_c,
|
||||
"[json.exception.invalid_iterator.213] cannot compare order of object iterators",
|
||||
json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1_c >= it3_c,
|
||||
"[json.exception.invalid_iterator.213] cannot compare order of object iterators",
|
||||
json::invalid_iterator&);
|
||||
#endif
|
||||
}
|
||||
else
|
||||
@@ -231,10 +327,18 @@ TEST_CASE("iterators 2")
|
||||
#if JSON_DIAGNOSTICS
|
||||
// the output differs in each loop, so we cannot fix a string for the expected exception
|
||||
#else
|
||||
CHECK_THROWS_WITH_AS(j.begin() == k.begin(), "[json.exception.invalid_iterator.212] cannot compare iterators of different containers", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(j.cbegin() == k.cbegin(), "[json.exception.invalid_iterator.212] cannot compare iterators of different containers", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(j.begin() < k.begin(), "[json.exception.invalid_iterator.212] cannot compare iterators of different containers", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(j.cbegin() < k.cbegin(), "[json.exception.invalid_iterator.212] cannot compare iterators of different containers", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(j.begin() == k.begin(),
|
||||
"[json.exception.invalid_iterator.212] cannot compare iterators of different containers",
|
||||
json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(j.cbegin() == k.cbegin(),
|
||||
"[json.exception.invalid_iterator.212] cannot compare iterators of different containers",
|
||||
json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(j.begin() < k.begin(),
|
||||
"[json.exception.invalid_iterator.212] cannot compare iterators of different containers",
|
||||
json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(j.cbegin() < k.cbegin(),
|
||||
"[json.exception.invalid_iterator.212] cannot compare iterators of different containers",
|
||||
json::invalid_iterator&);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -498,23 +602,47 @@ TEST_CASE("iterators 2")
|
||||
if (j.type() == json::value_t::object)
|
||||
{
|
||||
#if JSON_DIAGNOSTICS
|
||||
CHECK_THROWS_WITH_AS(it1 < it1, "[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1 < it2, "[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it2 < it3, "[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1 < it3, "[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1_c < it1_c, "[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1_c < it2_c, "[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it2_c < it3_c, "[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1_c < it3_c, "[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1 < it1,
|
||||
"[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators",
|
||||
json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1 < it2,
|
||||
"[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators",
|
||||
json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it2 < it3,
|
||||
"[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators",
|
||||
json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1 < it3,
|
||||
"[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators",
|
||||
json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1_c < it1_c,
|
||||
"[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators",
|
||||
json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1_c < it2_c,
|
||||
"[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators",
|
||||
json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it2_c < it3_c,
|
||||
"[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators",
|
||||
json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1_c < it3_c,
|
||||
"[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators",
|
||||
json::invalid_iterator&);
|
||||
#else
|
||||
CHECK_THROWS_WITH_AS(it1 < it1, "[json.exception.invalid_iterator.213] cannot compare order of object iterators", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1 < it2, "[json.exception.invalid_iterator.213] cannot compare order of object iterators", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it2 < it3, "[json.exception.invalid_iterator.213] cannot compare order of object iterators", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1 < it3, "[json.exception.invalid_iterator.213] cannot compare order of object iterators", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1_c < it1_c, "[json.exception.invalid_iterator.213] cannot compare order of object iterators", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1_c < it2_c, "[json.exception.invalid_iterator.213] cannot compare order of object iterators", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it2_c < it3_c, "[json.exception.invalid_iterator.213] cannot compare order of object iterators", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1_c < it3_c, "[json.exception.invalid_iterator.213] cannot compare order of object iterators", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1_c < it1_c,
|
||||
"[json.exception.invalid_iterator.213] cannot compare order of object iterators",
|
||||
json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1_c < it2_c,
|
||||
"[json.exception.invalid_iterator.213] cannot compare order of object iterators",
|
||||
json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it2_c < it3_c,
|
||||
"[json.exception.invalid_iterator.213] cannot compare order of object iterators",
|
||||
json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1_c < it3_c,
|
||||
"[json.exception.invalid_iterator.213] cannot compare order of object iterators",
|
||||
json::invalid_iterator&);
|
||||
#endif
|
||||
}
|
||||
else
|
||||
@@ -535,23 +663,47 @@ TEST_CASE("iterators 2")
|
||||
if (j.type() == json::value_t::object)
|
||||
{
|
||||
#if JSON_DIAGNOSTICS
|
||||
CHECK_THROWS_WITH_AS(it1 <= it1, "[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1 <= it2, "[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it2 <= it3, "[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1 <= it3, "[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1_c <= it1_c, "[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1_c <= it2_c, "[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it2_c <= it3_c, "[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1_c <= it3_c, "[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1 <= it1,
|
||||
"[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators",
|
||||
json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1 <= it2,
|
||||
"[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators",
|
||||
json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it2 <= it3,
|
||||
"[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators",
|
||||
json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1 <= it3,
|
||||
"[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators",
|
||||
json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1_c <= it1_c,
|
||||
"[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators",
|
||||
json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1_c <= it2_c,
|
||||
"[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators",
|
||||
json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it2_c <= it3_c,
|
||||
"[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators",
|
||||
json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1_c <= it3_c,
|
||||
"[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators",
|
||||
json::invalid_iterator&);
|
||||
#else
|
||||
CHECK_THROWS_WITH_AS(it1 <= it1, "[json.exception.invalid_iterator.213] cannot compare order of object iterators", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1 <= it2, "[json.exception.invalid_iterator.213] cannot compare order of object iterators", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it2 <= it3, "[json.exception.invalid_iterator.213] cannot compare order of object iterators", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1 <= it3, "[json.exception.invalid_iterator.213] cannot compare order of object iterators", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1_c <= it1_c, "[json.exception.invalid_iterator.213] cannot compare order of object iterators", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1_c <= it2_c, "[json.exception.invalid_iterator.213] cannot compare order of object iterators", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it2_c <= it3_c, "[json.exception.invalid_iterator.213] cannot compare order of object iterators", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1_c <= it3_c, "[json.exception.invalid_iterator.213] cannot compare order of object iterators", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1_c <= it1_c,
|
||||
"[json.exception.invalid_iterator.213] cannot compare order of object iterators",
|
||||
json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1_c <= it2_c,
|
||||
"[json.exception.invalid_iterator.213] cannot compare order of object iterators",
|
||||
json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it2_c <= it3_c,
|
||||
"[json.exception.invalid_iterator.213] cannot compare order of object iterators",
|
||||
json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1_c <= it3_c,
|
||||
"[json.exception.invalid_iterator.213] cannot compare order of object iterators",
|
||||
json::invalid_iterator&);
|
||||
#endif
|
||||
}
|
||||
else
|
||||
@@ -573,23 +725,47 @@ TEST_CASE("iterators 2")
|
||||
if (j.type() == json::value_t::object)
|
||||
{
|
||||
#if JSON_DIAGNOSTICS
|
||||
CHECK_THROWS_WITH_AS(it1 > it1, "[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1 > it2, "[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it2 > it3, "[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1 > it3, "[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1_c > it1_c, "[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1_c > it2_c, "[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it2_c > it3_c, "[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1_c > it3_c, "[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1 > it1,
|
||||
"[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators",
|
||||
json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1 > it2,
|
||||
"[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators",
|
||||
json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it2 > it3,
|
||||
"[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators",
|
||||
json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1 > it3,
|
||||
"[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators",
|
||||
json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1_c > it1_c,
|
||||
"[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators",
|
||||
json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1_c > it2_c,
|
||||
"[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators",
|
||||
json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it2_c > it3_c,
|
||||
"[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators",
|
||||
json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1_c > it3_c,
|
||||
"[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators",
|
||||
json::invalid_iterator&);
|
||||
#else
|
||||
CHECK_THROWS_WITH_AS(it1 > it1, "[json.exception.invalid_iterator.213] cannot compare order of object iterators", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1 > it2, "[json.exception.invalid_iterator.213] cannot compare order of object iterators", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it2 > it3, "[json.exception.invalid_iterator.213] cannot compare order of object iterators", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1 > it3, "[json.exception.invalid_iterator.213] cannot compare order of object iterators", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1_c > it1_c, "[json.exception.invalid_iterator.213] cannot compare order of object iterators", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1_c > it2_c, "[json.exception.invalid_iterator.213] cannot compare order of object iterators", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it2_c > it3_c, "[json.exception.invalid_iterator.213] cannot compare order of object iterators", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1_c > it3_c, "[json.exception.invalid_iterator.213] cannot compare order of object iterators", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1_c > it1_c,
|
||||
"[json.exception.invalid_iterator.213] cannot compare order of object iterators",
|
||||
json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1_c > it2_c,
|
||||
"[json.exception.invalid_iterator.213] cannot compare order of object iterators",
|
||||
json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it2_c > it3_c,
|
||||
"[json.exception.invalid_iterator.213] cannot compare order of object iterators",
|
||||
json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1_c > it3_c,
|
||||
"[json.exception.invalid_iterator.213] cannot compare order of object iterators",
|
||||
json::invalid_iterator&);
|
||||
#endif
|
||||
}
|
||||
else
|
||||
@@ -611,23 +787,47 @@ TEST_CASE("iterators 2")
|
||||
if (j.type() == json::value_t::object)
|
||||
{
|
||||
#if JSON_DIAGNOSTICS
|
||||
CHECK_THROWS_WITH_AS(it1 >= it1, "[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1 >= it2, "[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it2 >= it3, "[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1 >= it3, "[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1_c >= it1_c, "[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1_c >= it2_c, "[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it2_c >= it3_c, "[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1_c >= it3_c, "[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1 >= it1,
|
||||
"[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators",
|
||||
json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1 >= it2,
|
||||
"[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators",
|
||||
json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it2 >= it3,
|
||||
"[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators",
|
||||
json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1 >= it3,
|
||||
"[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators",
|
||||
json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1_c >= it1_c,
|
||||
"[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators",
|
||||
json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1_c >= it2_c,
|
||||
"[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators",
|
||||
json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it2_c >= it3_c,
|
||||
"[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators",
|
||||
json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1_c >= it3_c,
|
||||
"[json.exception.invalid_iterator.213] (/5) cannot compare order of object iterators",
|
||||
json::invalid_iterator&);
|
||||
#else
|
||||
CHECK_THROWS_WITH_AS(it1 >= it1, "[json.exception.invalid_iterator.213] cannot compare order of object iterators", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1 >= it2, "[json.exception.invalid_iterator.213] cannot compare order of object iterators", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it2 >= it3, "[json.exception.invalid_iterator.213] cannot compare order of object iterators", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1 >= it3, "[json.exception.invalid_iterator.213] cannot compare order of object iterators", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1_c >= it1_c, "[json.exception.invalid_iterator.213] cannot compare order of object iterators", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1_c >= it2_c, "[json.exception.invalid_iterator.213] cannot compare order of object iterators", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it2_c >= it3_c, "[json.exception.invalid_iterator.213] cannot compare order of object iterators", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1_c >= it3_c, "[json.exception.invalid_iterator.213] cannot compare order of object iterators", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1_c >= it1_c,
|
||||
"[json.exception.invalid_iterator.213] cannot compare order of object iterators",
|
||||
json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1_c >= it2_c,
|
||||
"[json.exception.invalid_iterator.213] cannot compare order of object iterators",
|
||||
json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it2_c >= it3_c,
|
||||
"[json.exception.invalid_iterator.213] cannot compare order of object iterators",
|
||||
json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(it1_c >= it3_c,
|
||||
"[json.exception.invalid_iterator.213] cannot compare order of object iterators",
|
||||
json::invalid_iterator&);
|
||||
#endif
|
||||
}
|
||||
else
|
||||
@@ -655,10 +855,18 @@ TEST_CASE("iterators 2")
|
||||
#if JSON_DIAGNOSTICS
|
||||
// the output differs in each loop, so we cannot fix a string for the expected exception
|
||||
#else
|
||||
CHECK_THROWS_WITH_AS(j.rbegin() == k.rbegin(), "[json.exception.invalid_iterator.212] cannot compare iterators of different containers", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(j.crbegin() == k.crbegin(), "[json.exception.invalid_iterator.212] cannot compare iterators of different containers", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(j.rbegin() < k.rbegin(), "[json.exception.invalid_iterator.212] cannot compare iterators of different containers", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(j.crbegin() < k.crbegin(), "[json.exception.invalid_iterator.212] cannot compare iterators of different containers", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(j.rbegin() == k.rbegin(),
|
||||
"[json.exception.invalid_iterator.212] cannot compare iterators of different containers",
|
||||
json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(j.crbegin() == k.crbegin(),
|
||||
"[json.exception.invalid_iterator.212] cannot compare iterators of different containers",
|
||||
json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(j.rbegin() < k.rbegin(),
|
||||
"[json.exception.invalid_iterator.212] cannot compare iterators of different containers",
|
||||
json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(j.crbegin() < k.crbegin(),
|
||||
"[json.exception.invalid_iterator.212] cannot compare iterators of different containers",
|
||||
json::invalid_iterator&);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
+144
-71
@@ -667,7 +667,9 @@ TEST_CASE("JSON patch")
|
||||
{
|
||||
json const j;
|
||||
json const patch = {{"op", "add"}, {"path", ""}, {"value", 1}};
|
||||
CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.104] parse error: JSON patch must be an array of objects", json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(j.patch(patch),
|
||||
"[json.exception.parse_error.104] parse error: JSON patch must be an array of objects",
|
||||
json::parse_error&);
|
||||
}
|
||||
|
||||
SECTION("not an array of objects")
|
||||
@@ -675,9 +677,13 @@ TEST_CASE("JSON patch")
|
||||
json const j;
|
||||
json const patch = {"op", "add", "path", "", "value", 1};
|
||||
#if JSON_DIAGNOSTICS
|
||||
CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.104] parse error: (/0) JSON patch must be an array of objects", json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(j.patch(patch),
|
||||
"[json.exception.parse_error.104] parse error: (/0) JSON patch must be an array of objects",
|
||||
json::parse_error&);
|
||||
#else
|
||||
CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.104] parse error: JSON patch must be an array of objects", json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(j.patch(patch),
|
||||
"[json.exception.parse_error.104] parse error: JSON patch must be an array of objects",
|
||||
json::parse_error&);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -697,9 +703,13 @@ TEST_CASE("JSON patch")
|
||||
json const j;
|
||||
json const patch = {{{"op", 1}}};
|
||||
#if JSON_DIAGNOSTICS
|
||||
CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: (/0) operation must have string member 'op'", json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(j.patch(patch),
|
||||
"[json.exception.parse_error.105] parse error: (/0) operation must have string member 'op'",
|
||||
json::parse_error&);
|
||||
#else
|
||||
CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: operation must have string member 'op'", json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(j.patch(patch),
|
||||
"[json.exception.parse_error.105] parse error: operation must have string member 'op'",
|
||||
json::parse_error&);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -722,9 +732,13 @@ TEST_CASE("JSON patch")
|
||||
json const j;
|
||||
json const patch = {{{"op", "add"}}};
|
||||
#if JSON_DIAGNOSTICS
|
||||
CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: (/0) operation 'add' must have member 'path'", json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(j.patch(patch),
|
||||
"[json.exception.parse_error.105] parse error: (/0) operation 'add' must have member 'path'",
|
||||
json::parse_error&);
|
||||
#else
|
||||
CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: operation 'add' must have member 'path'", json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(j.patch(patch),
|
||||
"[json.exception.parse_error.105] parse error: operation 'add' must have member 'path'",
|
||||
json::parse_error&);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -733,9 +747,13 @@ TEST_CASE("JSON patch")
|
||||
json const j;
|
||||
json const patch = {{{"op", "add"}, {"path", 1}}};
|
||||
#if JSON_DIAGNOSTICS
|
||||
CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: (/0) operation 'add' must have string member 'path'", json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(j.patch(patch),
|
||||
"[json.exception.parse_error.105] parse error: (/0) operation 'add' must have string member 'path'",
|
||||
json::parse_error&);
|
||||
#else
|
||||
CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: operation 'add' must have string member 'path'", json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(j.patch(patch),
|
||||
"[json.exception.parse_error.105] parse error: operation 'add' must have string member 'path'",
|
||||
json::parse_error&);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -744,9 +762,13 @@ TEST_CASE("JSON patch")
|
||||
json const j;
|
||||
json const patch = {{{"op", "add"}, {"path", ""}}};
|
||||
#if JSON_DIAGNOSTICS
|
||||
CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: (/0) operation 'add' must have member 'value'", json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(j.patch(patch),
|
||||
"[json.exception.parse_error.105] parse error: (/0) operation 'add' must have member 'value'",
|
||||
json::parse_error&);
|
||||
#else
|
||||
CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: operation 'add' must have member 'value'", json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(j.patch(patch),
|
||||
"[json.exception.parse_error.105] parse error: operation 'add' must have member 'value'",
|
||||
json::parse_error&);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -765,9 +787,13 @@ TEST_CASE("JSON patch")
|
||||
json const j;
|
||||
json const patch = {{{"op", "remove"}}};
|
||||
#if JSON_DIAGNOSTICS
|
||||
CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: (/0) operation 'remove' must have member 'path'", json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(j.patch(patch),
|
||||
"[json.exception.parse_error.105] parse error: (/0) operation 'remove' must have member 'path'",
|
||||
json::parse_error&);
|
||||
#else
|
||||
CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: operation 'remove' must have member 'path'", json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(j.patch(patch),
|
||||
"[json.exception.parse_error.105] parse error: operation 'remove' must have member 'path'",
|
||||
json::parse_error&);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -776,9 +802,13 @@ TEST_CASE("JSON patch")
|
||||
json const j;
|
||||
json const patch = {{{"op", "remove"}, {"path", 1}}};
|
||||
#if JSON_DIAGNOSTICS
|
||||
CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: (/0) operation 'remove' must have string member 'path'", json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(j.patch(patch),
|
||||
"[json.exception.parse_error.105] parse error: (/0) operation 'remove' must have string member 'path'",
|
||||
json::parse_error&);
|
||||
#else
|
||||
CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: operation 'remove' must have string member 'path'", json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(j.patch(patch),
|
||||
"[json.exception.parse_error.105] parse error: operation 'remove' must have string member 'path'",
|
||||
json::parse_error&);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -811,9 +841,13 @@ TEST_CASE("JSON patch")
|
||||
json const j;
|
||||
json const patch = {{{"op", "replace"}}};
|
||||
#if JSON_DIAGNOSTICS
|
||||
CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: (/0) operation 'replace' must have member 'path'", json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(j.patch(patch),
|
||||
"[json.exception.parse_error.105] parse error: (/0) operation 'replace' must have member 'path'",
|
||||
json::parse_error&);
|
||||
#else
|
||||
CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: operation 'replace' must have member 'path'", json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(j.patch(patch),
|
||||
"[json.exception.parse_error.105] parse error: operation 'replace' must have member 'path'",
|
||||
json::parse_error&);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -822,9 +856,13 @@ TEST_CASE("JSON patch")
|
||||
json const j;
|
||||
json const patch = {{{"op", "replace"}, {"path", 1}}};
|
||||
#if JSON_DIAGNOSTICS
|
||||
CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: (/0) operation 'replace' must have string member 'path'", json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(j.patch(patch),
|
||||
"[json.exception.parse_error.105] parse error: (/0) operation 'replace' must have string member 'path'",
|
||||
json::parse_error&);
|
||||
#else
|
||||
CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: operation 'replace' must have string member 'path'", json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(j.patch(patch),
|
||||
"[json.exception.parse_error.105] parse error: operation 'replace' must have string member 'path'",
|
||||
json::parse_error&);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -833,9 +871,13 @@ TEST_CASE("JSON patch")
|
||||
json const j;
|
||||
json const patch = {{{"op", "replace"}, {"path", ""}}};
|
||||
#if JSON_DIAGNOSTICS
|
||||
CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: (/0) operation 'replace' must have member 'value'", json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(j.patch(patch),
|
||||
"[json.exception.parse_error.105] parse error: (/0) operation 'replace' must have member 'value'",
|
||||
json::parse_error&);
|
||||
#else
|
||||
CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: operation 'replace' must have member 'value'", json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(j.patch(patch),
|
||||
"[json.exception.parse_error.105] parse error: operation 'replace' must have member 'value'",
|
||||
json::parse_error&);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -861,9 +903,13 @@ TEST_CASE("JSON patch")
|
||||
json const j;
|
||||
json const patch = {{{"op", "move"}}};
|
||||
#if JSON_DIAGNOSTICS
|
||||
CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: (/0) operation 'move' must have member 'path'", json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(j.patch(patch),
|
||||
"[json.exception.parse_error.105] parse error: (/0) operation 'move' must have member 'path'",
|
||||
json::parse_error&);
|
||||
#else
|
||||
CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: operation 'move' must have member 'path'", json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(j.patch(patch),
|
||||
"[json.exception.parse_error.105] parse error: operation 'move' must have member 'path'",
|
||||
json::parse_error&);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -872,9 +918,13 @@ TEST_CASE("JSON patch")
|
||||
json const j;
|
||||
json const patch = {{{"op", "move"}, {"path", 1}}};
|
||||
#if JSON_DIAGNOSTICS
|
||||
CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: (/0) operation 'move' must have string member 'path'", json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(j.patch(patch),
|
||||
"[json.exception.parse_error.105] parse error: (/0) operation 'move' must have string member 'path'",
|
||||
json::parse_error&);
|
||||
#else
|
||||
CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: operation 'move' must have string member 'path'", json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(j.patch(patch),
|
||||
"[json.exception.parse_error.105] parse error: operation 'move' must have string member 'path'",
|
||||
json::parse_error&);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -884,9 +934,13 @@ TEST_CASE("JSON patch")
|
||||
json const patch = {{{"op", "move"}, {"path", ""}}};
|
||||
CHECK_THROWS_AS(j.patch(patch), json::parse_error&);
|
||||
#if JSON_DIAGNOSTICS
|
||||
CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: (/0) operation 'move' must have member 'from'", json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(j.patch(patch),
|
||||
"[json.exception.parse_error.105] parse error: (/0) operation 'move' must have member 'from'",
|
||||
json::parse_error&);
|
||||
#else
|
||||
CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: operation 'move' must have member 'from'", json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(j.patch(patch),
|
||||
"[json.exception.parse_error.105] parse error: operation 'move' must have member 'from'",
|
||||
json::parse_error&);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -896,9 +950,13 @@ TEST_CASE("JSON patch")
|
||||
json const patch = {{{"op", "move"}, {"path", ""}, {"from", 1}}};
|
||||
CHECK_THROWS_AS(j.patch(patch), json::parse_error&);
|
||||
#if JSON_DIAGNOSTICS
|
||||
CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: (/0) operation 'move' must have string member 'from'", json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(j.patch(patch),
|
||||
"[json.exception.parse_error.105] parse error: (/0) operation 'move' must have string member 'from'",
|
||||
json::parse_error&);
|
||||
#else
|
||||
CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: operation 'move' must have string member 'from'", json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(j.patch(patch),
|
||||
"[json.exception.parse_error.105] parse error: operation 'move' must have string member 'from'",
|
||||
json::parse_error&);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -924,9 +982,13 @@ TEST_CASE("JSON patch")
|
||||
json const j;
|
||||
json const patch = {{{"op", "copy"}}};
|
||||
#if JSON_DIAGNOSTICS
|
||||
CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: (/0) operation 'copy' must have member 'path'", json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(j.patch(patch),
|
||||
"[json.exception.parse_error.105] parse error: (/0) operation 'copy' must have member 'path'",
|
||||
json::parse_error&);
|
||||
#else
|
||||
CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: operation 'copy' must have member 'path'", json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(j.patch(patch),
|
||||
"[json.exception.parse_error.105] parse error: operation 'copy' must have member 'path'",
|
||||
json::parse_error&);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -935,9 +997,13 @@ TEST_CASE("JSON patch")
|
||||
json const j;
|
||||
json const patch = {{{"op", "copy"}, {"path", 1}}};
|
||||
#if JSON_DIAGNOSTICS
|
||||
CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: (/0) operation 'copy' must have string member 'path'", json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(j.patch(patch),
|
||||
"[json.exception.parse_error.105] parse error: (/0) operation 'copy' must have string member 'path'",
|
||||
json::parse_error&);
|
||||
#else
|
||||
CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: operation 'copy' must have string member 'path'", json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(j.patch(patch),
|
||||
"[json.exception.parse_error.105] parse error: operation 'copy' must have string member 'path'",
|
||||
json::parse_error&);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -946,9 +1012,13 @@ TEST_CASE("JSON patch")
|
||||
json const j;
|
||||
json const patch = {{{"op", "copy"}, {"path", ""}}};
|
||||
#if JSON_DIAGNOSTICS
|
||||
CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: (/0) operation 'copy' must have member 'from'", json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(j.patch(patch),
|
||||
"[json.exception.parse_error.105] parse error: (/0) operation 'copy' must have member 'from'",
|
||||
json::parse_error&);
|
||||
#else
|
||||
CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: operation 'copy' must have member 'from'", json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(j.patch(patch),
|
||||
"[json.exception.parse_error.105] parse error: operation 'copy' must have member 'from'",
|
||||
json::parse_error&);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -957,9 +1027,13 @@ TEST_CASE("JSON patch")
|
||||
json const j;
|
||||
json const patch = {{{"op", "copy"}, {"path", ""}, {"from", 1}}};
|
||||
#if JSON_DIAGNOSTICS
|
||||
CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: (/0) operation 'copy' must have string member 'from'", json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(j.patch(patch),
|
||||
"[json.exception.parse_error.105] parse error: (/0) operation 'copy' must have string member 'from'",
|
||||
json::parse_error&);
|
||||
#else
|
||||
CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: operation 'copy' must have string member 'from'", json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(j.patch(patch),
|
||||
"[json.exception.parse_error.105] parse error: operation 'copy' must have string member 'from'",
|
||||
json::parse_error&);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -985,9 +1059,13 @@ TEST_CASE("JSON patch")
|
||||
json const j;
|
||||
json const patch = {{{"op", "test"}}};
|
||||
#if JSON_DIAGNOSTICS
|
||||
CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: (/0) operation 'test' must have member 'path'", json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(j.patch(patch),
|
||||
"[json.exception.parse_error.105] parse error: (/0) operation 'test' must have member 'path'",
|
||||
json::parse_error&);
|
||||
#else
|
||||
CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: operation 'test' must have member 'path'", json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(j.patch(patch),
|
||||
"[json.exception.parse_error.105] parse error: operation 'test' must have member 'path'",
|
||||
json::parse_error&);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -996,9 +1074,13 @@ TEST_CASE("JSON patch")
|
||||
json const j;
|
||||
json const patch = {{{"op", "test"}, {"path", 1}}};
|
||||
#if JSON_DIAGNOSTICS
|
||||
CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: (/0) operation 'test' must have string member 'path'", json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(j.patch(patch),
|
||||
"[json.exception.parse_error.105] parse error: (/0) operation 'test' must have string member 'path'",
|
||||
json::parse_error&);
|
||||
#else
|
||||
CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: operation 'test' must have string member 'path'", json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(j.patch(patch),
|
||||
"[json.exception.parse_error.105] parse error: operation 'test' must have string member 'path'",
|
||||
json::parse_error&);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -1007,9 +1089,13 @@ TEST_CASE("JSON patch")
|
||||
json const j;
|
||||
json const patch = {{{"op", "test"}, {"path", ""}}};
|
||||
#if JSON_DIAGNOSTICS
|
||||
CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: (/0) operation 'test' must have member 'value'", json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(j.patch(patch),
|
||||
"[json.exception.parse_error.105] parse error: (/0) operation 'test' must have member 'value'",
|
||||
json::parse_error&);
|
||||
#else
|
||||
CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: operation 'test' must have member 'value'", json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(j.patch(patch),
|
||||
"[json.exception.parse_error.105] parse error: operation 'test' must have member 'value'",
|
||||
json::parse_error&);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -1216,65 +1302,52 @@ TEST_CASE("JSON patch")
|
||||
{
|
||||
SECTION("add")
|
||||
{
|
||||
CHECK(R"( {} )"_json.patch(
|
||||
R"( [{"op": "add", "path": "/foo", "value": "bar"}] )"_json) == R"( {"foo": "bar"} )"_json);
|
||||
CHECK(R"( {} )"_json.patch(R"( [{"op": "add", "path": "/foo", "value": "bar"}] )"_json) == R"( {"foo": "bar"} )"_json);
|
||||
|
||||
CHECK(R"( {"foo": [1, 3]} )"_json.patch(
|
||||
R"( [{"op": "add", "path": "/foo", "value": "bar"}] )"_json) == R"( {"foo": "bar"} )"_json);
|
||||
CHECK(R"( {"foo": [1, 3]} )"_json.patch(R"( [{"op": "add", "path": "/foo", "value": "bar"}] )"_json) == R"( {"foo": "bar"} )"_json);
|
||||
|
||||
CHECK(R"( {"foo": [{}]} )"_json.patch(
|
||||
R"( [{"op": "add", "path": "/foo/0/bar", "value": "baz"}] )"_json) == R"( {"foo": [{"bar": "baz"}]} )"_json);
|
||||
CHECK(R"( {"foo": [{}]} )"_json.patch(R"( [{"op": "add", "path": "/foo/0/bar", "value": "baz"}] )"_json) == R"( {"foo": [{"bar": "baz"}]} )"_json);
|
||||
}
|
||||
|
||||
SECTION("remove")
|
||||
{
|
||||
CHECK(R"( {"foo": "bar"} )"_json.patch(
|
||||
R"( [{"op": "remove", "path": "/foo"}] )"_json) == R"( {} )"_json);
|
||||
CHECK(R"( {"foo": "bar"} )"_json.patch(R"( [{"op": "remove", "path": "/foo"}] )"_json) == R"( {} )"_json);
|
||||
|
||||
CHECK(R"( {"foo": [1, 2, 3]} )"_json.patch(
|
||||
R"( [{"op": "remove", "path": "/foo/1"}] )"_json) == R"( {"foo": [1, 3]} )"_json);
|
||||
CHECK(R"( {"foo": [1, 2, 3]} )"_json.patch(R"( [{"op": "remove", "path": "/foo/1"}] )"_json) == R"( {"foo": [1, 3]} )"_json);
|
||||
|
||||
CHECK(R"( {"foo": [{"bar": "baz"}]} )"_json.patch(
|
||||
R"( [{"op": "remove", "path": "/foo/0/bar"}] )"_json) == R"( {"foo": [{}]} )"_json);
|
||||
CHECK(R"( {"foo": [{"bar": "baz"}]} )"_json.patch(R"( [{"op": "remove", "path": "/foo/0/bar"}] )"_json) == R"( {"foo": [{}]} )"_json);
|
||||
}
|
||||
|
||||
SECTION("replace")
|
||||
{
|
||||
CHECK(R"( {"foo": "bar"} )"_json.patch(
|
||||
R"( [{"op": "replace", "path": "/foo", "value": 1}] )"_json) == R"( {"foo": 1} )"_json);
|
||||
CHECK(R"( {"foo": "bar"} )"_json.patch(R"( [{"op": "replace", "path": "/foo", "value": 1}] )"_json) == R"( {"foo": 1} )"_json);
|
||||
|
||||
CHECK(R"( {"foo": [1, 2, 3]} )"_json.patch(
|
||||
R"( [{"op": "replace", "path": "/foo/1", "value": 4}] )"_json) == R"( {"foo": [1, 4, 3]} )"_json);
|
||||
CHECK(R"( {"foo": [1, 2, 3]} )"_json.patch(R"( [{"op": "replace", "path": "/foo/1", "value": 4}] )"_json) == R"( {"foo": [1, 4, 3]} )"_json);
|
||||
|
||||
CHECK(R"( {"foo": [{"bar": "baz"}]} )"_json.patch(
|
||||
R"( [{"op": "replace", "path": "/foo/0/bar", "value": 1}] )"_json) == R"( {"foo": [{"bar": 1}]} )"_json);
|
||||
CHECK(R"( {"foo": [{"bar": "baz"}]} )"_json.patch(R"( [{"op": "replace", "path": "/foo/0/bar", "value": 1}] )"_json) ==
|
||||
R"( {"foo": [{"bar": 1}]} )"_json);
|
||||
}
|
||||
|
||||
SECTION("move")
|
||||
{
|
||||
CHECK(R"( {"foo": [1, 2, 3]} )"_json.patch(
|
||||
R"( [{"op": "move", "from": "/foo", "path": "/bar"}] )"_json) == R"( {"bar": [1, 2, 3]} )"_json);
|
||||
CHECK(R"( {"foo": [1, 2, 3]} )"_json.patch(R"( [{"op": "move", "from": "/foo", "path": "/bar"}] )"_json) == R"( {"bar": [1, 2, 3]} )"_json);
|
||||
}
|
||||
|
||||
SECTION("copy")
|
||||
{
|
||||
CHECK(R"( {"foo": [1, 2, 3]} )"_json.patch(
|
||||
R"( [{"op": "copy", "from": "/foo/1", "path": "/bar"}] )"_json) == R"( {"foo": [1, 2, 3], "bar": 2} )"_json);
|
||||
CHECK(R"( {"foo": [1, 2, 3]} )"_json.patch(R"( [{"op": "copy", "from": "/foo/1", "path": "/bar"}] )"_json) ==
|
||||
R"( {"foo": [1, 2, 3], "bar": 2} )"_json);
|
||||
}
|
||||
|
||||
SECTION("copy")
|
||||
{
|
||||
CHECK_NOTHROW(R"( {"foo": "bar"} )"_json.patch(
|
||||
R"( [{"op": "test", "path": "/foo", "value": "bar"}] )"_json));
|
||||
CHECK_NOTHROW(R"( {"foo": "bar"} )"_json.patch(R"( [{"op": "test", "path": "/foo", "value": "bar"}] )"_json));
|
||||
}
|
||||
}
|
||||
|
||||
SECTION("Tests from github.com/json-patch/json-patch-tests")
|
||||
{
|
||||
for (const auto* filename :
|
||||
{
|
||||
TEST_DATA_DIRECTORY "/json-patch-tests/spec_tests.json",
|
||||
TEST_DATA_DIRECTORY "/json-patch-tests/tests.json"})
|
||||
for (const auto* filename : {TEST_DATA_DIRECTORY "/json-patch-tests/spec_tests.json", TEST_DATA_DIRECTORY "/json-patch-tests/tests.json"})
|
||||
{
|
||||
CAPTURE(filename)
|
||||
std::ifstream f(filename);
|
||||
|
||||
+59
-101
@@ -35,20 +35,14 @@ TEST_CASE("JSON pointers")
|
||||
json::parse_error&);
|
||||
|
||||
json::json_pointer p;
|
||||
CHECK_THROWS_WITH_AS(p.top(),
|
||||
"[json.exception.out_of_range.405] JSON pointer has no parent",
|
||||
json::out_of_range&);
|
||||
CHECK_THROWS_WITH_AS(p.pop_back(),
|
||||
"[json.exception.out_of_range.405] JSON pointer has no parent",
|
||||
json::out_of_range&);
|
||||
CHECK_THROWS_WITH_AS(p.top(), "[json.exception.out_of_range.405] JSON pointer has no parent", json::out_of_range&);
|
||||
CHECK_THROWS_WITH_AS(p.pop_back(), "[json.exception.out_of_range.405] JSON pointer has no parent", json::out_of_range&);
|
||||
|
||||
SECTION("array index error")
|
||||
{
|
||||
json v = {1, 2, 3, 4};
|
||||
json::json_pointer const ptr("/10e");
|
||||
CHECK_THROWS_WITH_AS(v[ptr],
|
||||
"[json.exception.out_of_range.404] unresolved reference token '10e'",
|
||||
json::out_of_range&);
|
||||
CHECK_THROWS_WITH_AS(v[ptr], "[json.exception.out_of_range.404] unresolved reference token '10e'", json::out_of_range&);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -149,9 +143,7 @@ TEST_CASE("JSON pointers")
|
||||
|
||||
// unresolved access
|
||||
json j_primitive = 1;
|
||||
CHECK_THROWS_WITH_AS(j_primitive["/foo"_json_pointer],
|
||||
"[json.exception.out_of_range.404] unresolved reference token 'foo'",
|
||||
json::out_of_range&);
|
||||
CHECK_THROWS_WITH_AS(j_primitive["/foo"_json_pointer], "[json.exception.out_of_range.404] unresolved reference token 'foo'", json::out_of_range&);
|
||||
CHECK_THROWS_WITH_AS(j_primitive.at("/foo"_json_pointer),
|
||||
"[json.exception.out_of_range.404] unresolved reference token 'foo'",
|
||||
json::out_of_range&);
|
||||
@@ -213,15 +205,11 @@ TEST_CASE("JSON pointers")
|
||||
CHECK(j[json::json_pointer("/m~0n")] == j["m~n"]);
|
||||
|
||||
// unescaped access
|
||||
CHECK_THROWS_WITH_AS(j.at(json::json_pointer("/a/b")),
|
||||
"[json.exception.out_of_range.403] key 'a' not found",
|
||||
json::out_of_range&);
|
||||
CHECK_THROWS_WITH_AS(j.at(json::json_pointer("/a/b")), "[json.exception.out_of_range.403] key 'a' not found", json::out_of_range&);
|
||||
|
||||
// unresolved access
|
||||
const json j_primitive = 1;
|
||||
CHECK_THROWS_WITH_AS(j_primitive["/foo"_json_pointer],
|
||||
"[json.exception.out_of_range.404] unresolved reference token 'foo'",
|
||||
json::out_of_range&);
|
||||
CHECK_THROWS_WITH_AS(j_primitive["/foo"_json_pointer], "[json.exception.out_of_range.404] unresolved reference token 'foo'", json::out_of_range&);
|
||||
CHECK_THROWS_WITH_AS(j_primitive.at("/foo"_json_pointer),
|
||||
"[json.exception.out_of_range.404] unresolved reference token 'foo'",
|
||||
json::out_of_range&);
|
||||
@@ -324,12 +312,8 @@ TEST_CASE("JSON pointers")
|
||||
"[json.exception.parse_error.109] parse error: array index '+1' is not a number",
|
||||
json::parse_error&);
|
||||
|
||||
CHECK_THROWS_WITH_AS(j["/1+1"_json_pointer] = 1,
|
||||
"[json.exception.out_of_range.404] unresolved reference token '1+1'",
|
||||
json::out_of_range&);
|
||||
CHECK_THROWS_WITH_AS(j_const["/1+1"_json_pointer] == 1,
|
||||
"[json.exception.out_of_range.404] unresolved reference token '1+1'",
|
||||
json::out_of_range&);
|
||||
CHECK_THROWS_WITH_AS(j["/1+1"_json_pointer] = 1, "[json.exception.out_of_range.404] unresolved reference token '1+1'", json::out_of_range&);
|
||||
CHECK_THROWS_WITH_AS(j_const["/1+1"_json_pointer] == 1, "[json.exception.out_of_range.404] unresolved reference token '1+1'", json::out_of_range&);
|
||||
|
||||
{
|
||||
auto too_large_index = std::to_string((std::numeric_limits<unsigned long long>::max)()) + "1";
|
||||
@@ -378,18 +362,12 @@ TEST_CASE("JSON pointers")
|
||||
CHECK(j == json({1, 13, 3, 33, nullptr, 55, 99}));
|
||||
|
||||
// error when using "-" in const object
|
||||
CHECK_THROWS_WITH_AS(j_const["/-"_json_pointer],
|
||||
"[json.exception.out_of_range.402] array index '-' (3) is out of range",
|
||||
json::out_of_range&);
|
||||
CHECK_THROWS_WITH_AS(j_const["/-"_json_pointer], "[json.exception.out_of_range.402] array index '-' (3) is out of range", json::out_of_range&);
|
||||
CHECK(!j_const.contains("/-"_json_pointer));
|
||||
|
||||
// error when using "-" with at
|
||||
CHECK_THROWS_WITH_AS(j.at("/-"_json_pointer),
|
||||
"[json.exception.out_of_range.402] array index '-' (7) is out of range",
|
||||
json::out_of_range&);
|
||||
CHECK_THROWS_WITH_AS(j_const.at("/-"_json_pointer),
|
||||
"[json.exception.out_of_range.402] array index '-' (3) is out of range",
|
||||
json::out_of_range&);
|
||||
CHECK_THROWS_WITH_AS(j.at("/-"_json_pointer), "[json.exception.out_of_range.402] array index '-' (7) is out of range", json::out_of_range&);
|
||||
CHECK_THROWS_WITH_AS(j_const.at("/-"_json_pointer), "[json.exception.out_of_range.402] array index '-' (3) is out of range", json::out_of_range&);
|
||||
CHECK(!j_const.contains("/-"_json_pointer));
|
||||
}
|
||||
|
||||
@@ -403,56 +381,44 @@ TEST_CASE("JSON pointers")
|
||||
CHECK(j["/2"_json_pointer] == j[2]);
|
||||
|
||||
// assign to nonexisting index
|
||||
CHECK_THROWS_WITH_AS(j.at("/3"_json_pointer),
|
||||
"[json.exception.out_of_range.401] array index 3 is out of range",
|
||||
json::out_of_range&);
|
||||
CHECK_THROWS_WITH_AS(j.at("/3"_json_pointer), "[json.exception.out_of_range.401] array index 3 is out of range", json::out_of_range&);
|
||||
CHECK(!j.contains("/3"_json_pointer));
|
||||
|
||||
// assign to nonexisting index (with gap)
|
||||
CHECK_THROWS_WITH_AS(j.at("/5"_json_pointer),
|
||||
"[json.exception.out_of_range.401] array index 5 is out of range",
|
||||
json::out_of_range&);
|
||||
CHECK_THROWS_WITH_AS(j.at("/5"_json_pointer), "[json.exception.out_of_range.401] array index 5 is out of range", json::out_of_range&);
|
||||
CHECK(!j.contains("/5"_json_pointer));
|
||||
|
||||
// assign to "-"
|
||||
CHECK_THROWS_WITH_AS(j["/-"_json_pointer],
|
||||
"[json.exception.out_of_range.402] array index '-' (3) is out of range",
|
||||
json::out_of_range&);
|
||||
CHECK_THROWS_WITH_AS(j.at("/-"_json_pointer),
|
||||
"[json.exception.out_of_range.402] array index '-' (3) is out of range",
|
||||
json::out_of_range&);
|
||||
CHECK_THROWS_WITH_AS(j["/-"_json_pointer], "[json.exception.out_of_range.402] array index '-' (3) is out of range", json::out_of_range&);
|
||||
CHECK_THROWS_WITH_AS(j.at("/-"_json_pointer), "[json.exception.out_of_range.402] array index '-' (3) is out of range", json::out_of_range&);
|
||||
CHECK(!j.contains("/-"_json_pointer));
|
||||
}
|
||||
}
|
||||
|
||||
SECTION("flatten")
|
||||
{
|
||||
json j =
|
||||
{
|
||||
{"pi", 3.141},
|
||||
{"happy", true},
|
||||
{"name", "Niels"},
|
||||
{"nothing", nullptr},
|
||||
{"answer", {{"everything", 42}}},
|
||||
{"list", {1, 0, 2}},
|
||||
{"object", {{"currency", "USD"}, {"value", 42.99}, {"", "empty string"}, {"/", "slash"}, {"~", "tilde"}, {"~1", "tilde1"}}}};
|
||||
json j = {{"pi", 3.141},
|
||||
{"happy", true},
|
||||
{"name", "Niels"},
|
||||
{"nothing", nullptr},
|
||||
{"answer", {{"everything", 42}}},
|
||||
{"list", {1, 0, 2}},
|
||||
{"object", {{"currency", "USD"}, {"value", 42.99}, {"", "empty string"}, {"/", "slash"}, {"~", "tilde"}, {"~1", "tilde1"}}}};
|
||||
|
||||
json j_flatten =
|
||||
{
|
||||
{"/pi", 3.141},
|
||||
{"/happy", true},
|
||||
{"/name", "Niels"},
|
||||
{"/nothing", nullptr},
|
||||
{"/answer/everything", 42},
|
||||
{"/list/0", 1},
|
||||
{"/list/1", 0},
|
||||
{"/list/2", 2},
|
||||
{"/object/currency", "USD"},
|
||||
{"/object/value", 42.99},
|
||||
{"/object/", "empty string"},
|
||||
{"/object/~1", "slash"},
|
||||
{"/object/~0", "tilde"},
|
||||
{"/object/~01", "tilde1"}};
|
||||
json j_flatten = {{"/pi", 3.141},
|
||||
{"/happy", true},
|
||||
{"/name", "Niels"},
|
||||
{"/nothing", nullptr},
|
||||
{"/answer/everything", 42},
|
||||
{"/list/0", 1},
|
||||
{"/list/1", 0},
|
||||
{"/list/2", 2},
|
||||
{"/object/currency", "USD"},
|
||||
{"/object/value", 42.99},
|
||||
{"/object/", "empty string"},
|
||||
{"/object/~1", "slash"},
|
||||
{"/object/~0", "tilde"},
|
||||
{"/object/~01", "tilde1"}};
|
||||
|
||||
// check if flattened result is as expected
|
||||
CHECK(j.flatten() == j_flatten);
|
||||
@@ -461,22 +427,20 @@ TEST_CASE("JSON pointers")
|
||||
CHECK(j_flatten.unflatten() == j);
|
||||
|
||||
// error for nonobjects
|
||||
CHECK_THROWS_WITH_AS(json(1).unflatten(),
|
||||
"[json.exception.type_error.314] only objects can be unflattened",
|
||||
json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(json(1).unflatten(), "[json.exception.type_error.314] only objects can be unflattened", json::type_error&);
|
||||
|
||||
// error for nonprimitve values
|
||||
#if JSON_DIAGNOSTICS
|
||||
CHECK_THROWS_WITH_AS(json({{"/1", {1, 2, 3}}}).unflatten(), "[json.exception.type_error.315] (/~11) values in object must be primitive", json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(json({{"/1", {1, 2, 3}}}).unflatten(),
|
||||
"[json.exception.type_error.315] (/~11) values in object must be primitive",
|
||||
json::type_error&);
|
||||
#else
|
||||
CHECK_THROWS_WITH_AS(json({{"/1", {1, 2, 3}}}).unflatten(), "[json.exception.type_error.315] values in object must be primitive", json::type_error&);
|
||||
#endif
|
||||
|
||||
// error for conflicting values
|
||||
json const j_error = {{"", 42}, {"/foo", 17}};
|
||||
CHECK_THROWS_WITH_AS(j_error.unflatten(),
|
||||
"[json.exception.type_error.313] invalid value to unflatten",
|
||||
json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_error.unflatten(), "[json.exception.type_error.313] invalid value to unflatten", json::type_error&);
|
||||
|
||||
// explicit roundtrip check
|
||||
CHECK(j.flatten().unflatten() == j);
|
||||
@@ -500,8 +464,7 @@ TEST_CASE("JSON pointers")
|
||||
|
||||
SECTION("string representation")
|
||||
{
|
||||
for (const auto* ptr_str :
|
||||
{"", "/foo", "/foo/0", "/", "/a~1b", "/c%d", "/e^f", "/g|h", "/i\\j", "/k\"l", "/ ", "/m~0n"})
|
||||
for (const auto* ptr_str : {"", "/foo", "/foo/0", "/", "/a~1b", "/c%d", "/e^f", "/g|h", "/i\\j", "/k\"l", "/ ", "/m~0n"})
|
||||
{
|
||||
json::json_pointer const ptr(ptr_str);
|
||||
std::stringstream ss;
|
||||
@@ -533,16 +496,14 @@ TEST_CASE("JSON pointers")
|
||||
|
||||
SECTION("empty, push, pop and parent")
|
||||
{
|
||||
const json j =
|
||||
{
|
||||
{"", "Hello"},
|
||||
{"pi", 3.141},
|
||||
{"happy", true},
|
||||
{"name", "Niels"},
|
||||
{"nothing", nullptr},
|
||||
{"answer", {{"everything", 42}}},
|
||||
{"list", {1, 0, 2}},
|
||||
{"object", {{"currency", "USD"}, {"value", 42.99}, {"", "empty string"}, {"/", "slash"}, {"~", "tilde"}, {"~1", "tilde1"}}}};
|
||||
const json j = {{"", "Hello"},
|
||||
{"pi", 3.141},
|
||||
{"happy", true},
|
||||
{"name", "Niels"},
|
||||
{"nothing", nullptr},
|
||||
{"answer", {{"everything", 42}}},
|
||||
{"list", {1, 0, 2}},
|
||||
{"object", {{"currency", "USD"}, {"value", 42.99}, {"", "empty string"}, {"/", "slash"}, {"~", "tilde"}, {"~1", "tilde1"}}}};
|
||||
|
||||
// empty json_pointer returns the root JSON-object
|
||||
auto ptr = ""_json_pointer;
|
||||
@@ -589,22 +550,19 @@ TEST_CASE("JSON pointers")
|
||||
CHECK(ptr.empty());
|
||||
CHECK(j[ptr] == j);
|
||||
|
||||
CHECK_THROWS_WITH(ptr.pop_back(),
|
||||
"[json.exception.out_of_range.405] JSON pointer has no parent");
|
||||
CHECK_THROWS_WITH(ptr.pop_back(), "[json.exception.out_of_range.405] JSON pointer has no parent");
|
||||
}
|
||||
|
||||
SECTION("operators")
|
||||
{
|
||||
const json j =
|
||||
{
|
||||
{"", "Hello"},
|
||||
{"pi", 3.141},
|
||||
{"happy", true},
|
||||
{"name", "Niels"},
|
||||
{"nothing", nullptr},
|
||||
{"answer", {{"everything", 42}}},
|
||||
{"list", {1, 0, 2}},
|
||||
{"object", {{"currency", "USD"}, {"value", 42.99}, {"", "empty string"}, {"/", "slash"}, {"~", "tilde"}, {"~1", "tilde1"}}}};
|
||||
const json j = {{"", "Hello"},
|
||||
{"pi", 3.141},
|
||||
{"happy", true},
|
||||
{"name", "Niels"},
|
||||
{"nothing", nullptr},
|
||||
{"answer", {{"everything", 42}}},
|
||||
{"list", {1, 0, 2}},
|
||||
{"object", {{"currency", "USD"}, {"value", 42.99}, {"", "empty string"}, {"/", "slash"}, {"~", "tilde"}, {"~1", "tilde1"}}}};
|
||||
|
||||
// empty json_pointer returns the root JSON-object
|
||||
auto ptr = ""_json_pointer;
|
||||
|
||||
@@ -20,11 +20,7 @@ TEST_CASE("version information")
|
||||
CHECK(j["name"] == "JSON for Modern C++");
|
||||
CHECK(j["copyright"] == "(C) 2013-2023 Niels Lohmann");
|
||||
CHECK(j["url"] == "https://github.com/nlohmann/json");
|
||||
CHECK(j["version"] == json(
|
||||
{{"string", "3.11.3"},
|
||||
{"major", 3},
|
||||
{"minor", 11},
|
||||
{"patch", 3}}));
|
||||
CHECK(j["version"] == json({{"string", "3.11.3"}, {"major", 3}, {"minor", 11}, {"patch", 3}}));
|
||||
|
||||
CHECK(j.find("platform") != j.end());
|
||||
CHECK(j.at("compiler").find("family") != j.at("compiler").end());
|
||||
|
||||
@@ -239,7 +239,9 @@ TEST_CASE("modifiers")
|
||||
{
|
||||
json j = 1;
|
||||
json const k("Hello");
|
||||
CHECK_THROWS_WITH_AS(j.push_back(json::object_t::value_type({"one", 1})), "[json.exception.type_error.308] cannot use push_back() with number", json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j.push_back(json::object_t::value_type({"one", 1})),
|
||||
"[json.exception.type_error.308] cannot use push_back() with number",
|
||||
json::type_error&);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -467,7 +469,9 @@ TEST_CASE("modifiers")
|
||||
{
|
||||
json j = 1;
|
||||
json const k("Hello");
|
||||
CHECK_THROWS_WITH_AS(j += json::object_t::value_type({"one", 1}), "[json.exception.type_error.308] cannot use push_back() with number", json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j += json::object_t::value_type({"one", 1}),
|
||||
"[json.exception.type_error.308] cannot use push_back() with number",
|
||||
json::type_error&);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -637,8 +641,12 @@ TEST_CASE("modifiers")
|
||||
{
|
||||
json j_other_array2 = {"first", "second"};
|
||||
|
||||
CHECK_THROWS_WITH_AS(j_array.insert(j_array.end(), j_array.begin(), j_array.end()), "[json.exception.invalid_iterator.211] passed iterators may not belong to container", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(j_array.insert(j_array.end(), j_other_array.begin(), j_other_array2.end()), "[json.exception.invalid_iterator.210] iterators do not fit", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(j_array.insert(j_array.end(), j_array.begin(), j_array.end()),
|
||||
"[json.exception.invalid_iterator.211] passed iterators may not belong to container",
|
||||
json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(j_array.insert(j_array.end(), j_other_array.begin(), j_other_array2.end()),
|
||||
"[json.exception.invalid_iterator.210] iterators do not fit",
|
||||
json::invalid_iterator&);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -663,9 +671,15 @@ TEST_CASE("modifiers")
|
||||
{
|
||||
json const j_other_array2 = {"first", "second"};
|
||||
|
||||
CHECK_THROWS_WITH_AS(j_array.insert(j_object2.begin(), j_object2.end()), "[json.exception.type_error.309] cannot use insert() with array", json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_object1.insert(j_object1.begin(), j_object2.end()), "[json.exception.invalid_iterator.210] iterators do not fit", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(j_object1.insert(j_array.begin(), j_array.end()), "[json.exception.invalid_iterator.202] iterators first and last must point to objects", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(j_array.insert(j_object2.begin(), j_object2.end()),
|
||||
"[json.exception.type_error.309] cannot use insert() with array",
|
||||
json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_object1.insert(j_object1.begin(), j_object2.end()),
|
||||
"[json.exception.invalid_iterator.210] iterators do not fit",
|
||||
json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(j_object1.insert(j_array.begin(), j_array.end()),
|
||||
"[json.exception.invalid_iterator.202] iterators first and last must point to objects",
|
||||
json::invalid_iterator&);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -704,11 +718,21 @@ TEST_CASE("modifiers")
|
||||
// pass iterator to a different array
|
||||
json j_another_array = {1, 2};
|
||||
json j_yet_another_array = {"first", "second"};
|
||||
CHECK_THROWS_WITH_AS(j_array.insert(j_another_array.end(), 10), "[json.exception.invalid_iterator.202] iterator does not fit current value", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(j_array.insert(j_another_array.end(), j_value), "[json.exception.invalid_iterator.202] iterator does not fit current value", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(j_array.insert(j_another_array.end(), 10, 11), "[json.exception.invalid_iterator.202] iterator does not fit current value", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(j_array.insert(j_another_array.end(), j_yet_another_array.begin(), j_yet_another_array.end()), "[json.exception.invalid_iterator.202] iterator does not fit current value", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(j_array.insert(j_another_array.end(), {1, 2, 3, 4}), "[json.exception.invalid_iterator.202] iterator does not fit current value", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(j_array.insert(j_another_array.end(), 10),
|
||||
"[json.exception.invalid_iterator.202] iterator does not fit current value",
|
||||
json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(j_array.insert(j_another_array.end(), j_value),
|
||||
"[json.exception.invalid_iterator.202] iterator does not fit current value",
|
||||
json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(j_array.insert(j_another_array.end(), 10, 11),
|
||||
"[json.exception.invalid_iterator.202] iterator does not fit current value",
|
||||
json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(j_array.insert(j_another_array.end(), j_yet_another_array.begin(), j_yet_another_array.end()),
|
||||
"[json.exception.invalid_iterator.202] iterator does not fit current value",
|
||||
json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(j_array.insert(j_another_array.end(), {1, 2, 3, 4}),
|
||||
"[json.exception.invalid_iterator.202] iterator does not fit current value",
|
||||
json::invalid_iterator&);
|
||||
}
|
||||
|
||||
SECTION("non-array type")
|
||||
@@ -717,10 +741,18 @@ TEST_CASE("modifiers")
|
||||
json j_nonarray = 3;
|
||||
json j_yet_another_array = {"first", "second"};
|
||||
CHECK_THROWS_WITH_AS(j_nonarray.insert(j_nonarray.end(), 10), "[json.exception.type_error.309] cannot use insert() with number", json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonarray.insert(j_nonarray.end(), j_value), "[json.exception.type_error.309] cannot use insert() with number", json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonarray.insert(j_nonarray.end(), 10, 11), "[json.exception.type_error.309] cannot use insert() with number", json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonarray.insert(j_nonarray.end(), j_yet_another_array.begin(), j_yet_another_array.end()), "[json.exception.type_error.309] cannot use insert() with number", json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonarray.insert(j_nonarray.end(), {1, 2, 3, 4}), "[json.exception.type_error.309] cannot use insert() with number", json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonarray.insert(j_nonarray.end(), j_value),
|
||||
"[json.exception.type_error.309] cannot use insert() with number",
|
||||
json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonarray.insert(j_nonarray.end(), 10, 11),
|
||||
"[json.exception.type_error.309] cannot use insert() with number",
|
||||
json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonarray.insert(j_nonarray.end(), j_yet_another_array.begin(), j_yet_another_array.end()),
|
||||
"[json.exception.type_error.309] cannot use insert() with number",
|
||||
json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_nonarray.insert(j_nonarray.end(), {1, 2, 3, 4}),
|
||||
"[json.exception.type_error.309] cannot use insert() with number",
|
||||
json::type_error&);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -774,9 +806,15 @@ TEST_CASE("modifiers")
|
||||
{
|
||||
json const j_other_array2 = {"first", "second"};
|
||||
|
||||
CHECK_THROWS_WITH_AS(j_array.update(j_object2.begin(), j_object2.end()), "[json.exception.type_error.312] cannot use update() with array", json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_object1.update(j_object1.begin(), j_object2.end()), "[json.exception.invalid_iterator.210] iterators do not fit", json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(j_object1.update(j_array.begin(), j_array.end()), "[json.exception.type_error.312] cannot use update() with array", json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_array.update(j_object2.begin(), j_object2.end()),
|
||||
"[json.exception.type_error.312] cannot use update() with array",
|
||||
json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j_object1.update(j_object1.begin(), j_object2.end()),
|
||||
"[json.exception.invalid_iterator.210] iterators do not fit",
|
||||
json::invalid_iterator&);
|
||||
CHECK_THROWS_WITH_AS(j_object1.update(j_array.begin(), j_array.end()),
|
||||
"[json.exception.type_error.312] cannot use update() with array",
|
||||
json::type_error&);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+282
-385
@@ -22,7 +22,8 @@ using namespace nlohmann::literals; // NOLINT(google-build-using-namespace)
|
||||
#include <set>
|
||||
#include <sstream>
|
||||
|
||||
namespace {
|
||||
namespace
|
||||
{
|
||||
class SaxCountdown
|
||||
{
|
||||
public:
|
||||
@@ -90,7 +91,9 @@ class SaxCountdown
|
||||
return events_left-- > 0;
|
||||
}
|
||||
|
||||
bool parse_error(std::size_t /*unused*/, const std::string& /*unused*/, const json::exception& /*unused*/) // NOLINT(readability-convert-member-functions-to-static)
|
||||
bool parse_error(std::size_t /*unused*/,
|
||||
const std::string& /*unused*/,
|
||||
const json::exception& /*unused*/) // NOLINT(readability-convert-member-functions-to-static)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -168,8 +171,7 @@ TEST_CASE("MessagePack")
|
||||
CHECK(j.is_number_integer());
|
||||
|
||||
// create expected byte vector
|
||||
std::vector<uint8_t> const expected{
|
||||
static_cast<uint8_t>(i)};
|
||||
std::vector<uint8_t> const expected{static_cast<uint8_t>(i)};
|
||||
|
||||
// compare result + size
|
||||
const auto result = json::to_msgpack(j);
|
||||
@@ -288,12 +290,7 @@ TEST_CASE("MessagePack")
|
||||
|
||||
SECTION("65536..4294967295 (int 32)")
|
||||
{
|
||||
for (uint32_t i :
|
||||
{
|
||||
65536u,
|
||||
77777u,
|
||||
1048576u,
|
||||
4294967295u})
|
||||
for (uint32_t i : {65536u, 77777u, 1048576u, 4294967295u})
|
||||
{
|
||||
CAPTURE(i)
|
||||
|
||||
@@ -320,10 +317,8 @@ TEST_CASE("MessagePack")
|
||||
|
||||
// check individual bytes
|
||||
CHECK(result[0] == 0xce);
|
||||
uint32_t const restored = (static_cast<uint32_t>(result[1]) << 030) +
|
||||
(static_cast<uint32_t>(result[2]) << 020) +
|
||||
(static_cast<uint32_t>(result[3]) << 010) +
|
||||
static_cast<uint32_t>(result[4]);
|
||||
uint32_t const restored = (static_cast<uint32_t>(result[1]) << 030) + (static_cast<uint32_t>(result[2]) << 020) +
|
||||
(static_cast<uint32_t>(result[3]) << 010) + static_cast<uint32_t>(result[4]);
|
||||
CHECK(restored == i);
|
||||
|
||||
// roundtrip
|
||||
@@ -334,10 +329,7 @@ TEST_CASE("MessagePack")
|
||||
|
||||
SECTION("4294967296..9223372036854775807 (int 64)")
|
||||
{
|
||||
for (uint64_t i :
|
||||
{
|
||||
4294967296LU,
|
||||
9223372036854775807LU})
|
||||
for (uint64_t i : {4294967296LU, 9223372036854775807LU})
|
||||
{
|
||||
CAPTURE(i)
|
||||
|
||||
@@ -368,14 +360,10 @@ TEST_CASE("MessagePack")
|
||||
|
||||
// check individual bytes
|
||||
CHECK(result[0] == 0xcf);
|
||||
uint64_t const restored = (static_cast<uint64_t>(result[1]) << 070) +
|
||||
(static_cast<uint64_t>(result[2]) << 060) +
|
||||
(static_cast<uint64_t>(result[3]) << 050) +
|
||||
(static_cast<uint64_t>(result[4]) << 040) +
|
||||
(static_cast<uint64_t>(result[5]) << 030) +
|
||||
(static_cast<uint64_t>(result[6]) << 020) +
|
||||
(static_cast<uint64_t>(result[7]) << 010) +
|
||||
static_cast<uint64_t>(result[8]);
|
||||
uint64_t const restored = (static_cast<uint64_t>(result[1]) << 070) + (static_cast<uint64_t>(result[2]) << 060) +
|
||||
(static_cast<uint64_t>(result[3]) << 050) + (static_cast<uint64_t>(result[4]) << 040) +
|
||||
(static_cast<uint64_t>(result[5]) << 030) + (static_cast<uint64_t>(result[6]) << 020) +
|
||||
(static_cast<uint64_t>(result[7]) << 010) + static_cast<uint64_t>(result[8]);
|
||||
CHECK(restored == i);
|
||||
|
||||
// roundtrip
|
||||
@@ -503,10 +491,8 @@ TEST_CASE("MessagePack")
|
||||
|
||||
// check individual bytes
|
||||
CHECK(result[0] == 0xd2);
|
||||
uint32_t const restored = (static_cast<uint32_t>(result[1]) << 030) +
|
||||
(static_cast<uint32_t>(result[2]) << 020) +
|
||||
(static_cast<uint32_t>(result[3]) << 010) +
|
||||
static_cast<uint32_t>(result[4]);
|
||||
uint32_t const restored = (static_cast<uint32_t>(result[1]) << 030) + (static_cast<uint32_t>(result[2]) << 020) +
|
||||
(static_cast<uint32_t>(result[3]) << 010) + static_cast<uint32_t>(result[4]);
|
||||
CHECK(static_cast<std::int32_t>(restored) == i);
|
||||
|
||||
// roundtrip
|
||||
@@ -551,14 +537,10 @@ TEST_CASE("MessagePack")
|
||||
|
||||
// check individual bytes
|
||||
CHECK(result[0] == 0xd3);
|
||||
int64_t const restored = (static_cast<int64_t>(result[1]) << 070) +
|
||||
(static_cast<int64_t>(result[2]) << 060) +
|
||||
(static_cast<int64_t>(result[3]) << 050) +
|
||||
(static_cast<int64_t>(result[4]) << 040) +
|
||||
(static_cast<int64_t>(result[5]) << 030) +
|
||||
(static_cast<int64_t>(result[6]) << 020) +
|
||||
(static_cast<int64_t>(result[7]) << 010) +
|
||||
static_cast<int64_t>(result[8]);
|
||||
int64_t const restored = (static_cast<int64_t>(result[1]) << 070) + (static_cast<int64_t>(result[2]) << 060) +
|
||||
(static_cast<int64_t>(result[3]) << 050) + (static_cast<int64_t>(result[4]) << 040) +
|
||||
(static_cast<int64_t>(result[5]) << 030) + (static_cast<int64_t>(result[6]) << 020) +
|
||||
(static_cast<int64_t>(result[7]) << 010) + static_cast<int64_t>(result[8]);
|
||||
CHECK(restored == i);
|
||||
|
||||
// roundtrip
|
||||
@@ -670,12 +652,7 @@ TEST_CASE("MessagePack")
|
||||
|
||||
SECTION("65536..4294967295 (uint 32)")
|
||||
{
|
||||
for (const uint32_t i :
|
||||
{
|
||||
65536u,
|
||||
77777u,
|
||||
1048576u,
|
||||
4294967295u})
|
||||
for (const uint32_t i : {65536u, 77777u, 1048576u, 4294967295u})
|
||||
{
|
||||
CAPTURE(i)
|
||||
|
||||
@@ -701,10 +678,8 @@ TEST_CASE("MessagePack")
|
||||
|
||||
// check individual bytes
|
||||
CHECK(result[0] == 0xce);
|
||||
uint32_t const restored = (static_cast<uint32_t>(result[1]) << 030) +
|
||||
(static_cast<uint32_t>(result[2]) << 020) +
|
||||
(static_cast<uint32_t>(result[3]) << 010) +
|
||||
static_cast<uint32_t>(result[4]);
|
||||
uint32_t const restored = (static_cast<uint32_t>(result[1]) << 030) + (static_cast<uint32_t>(result[2]) << 020) +
|
||||
(static_cast<uint32_t>(result[3]) << 010) + static_cast<uint32_t>(result[4]);
|
||||
CHECK(restored == i);
|
||||
|
||||
// roundtrip
|
||||
@@ -715,10 +690,7 @@ TEST_CASE("MessagePack")
|
||||
|
||||
SECTION("4294967296..18446744073709551615 (uint 64)")
|
||||
{
|
||||
for (const uint64_t i :
|
||||
{
|
||||
4294967296LU,
|
||||
18446744073709551615LU})
|
||||
for (const uint64_t i : {4294967296LU, 18446744073709551615LU})
|
||||
{
|
||||
CAPTURE(i)
|
||||
|
||||
@@ -748,14 +720,10 @@ TEST_CASE("MessagePack")
|
||||
|
||||
// check individual bytes
|
||||
CHECK(result[0] == 0xcf);
|
||||
uint64_t const restored = (static_cast<uint64_t>(result[1]) << 070) +
|
||||
(static_cast<uint64_t>(result[2]) << 060) +
|
||||
(static_cast<uint64_t>(result[3]) << 050) +
|
||||
(static_cast<uint64_t>(result[4]) << 040) +
|
||||
(static_cast<uint64_t>(result[5]) << 030) +
|
||||
(static_cast<uint64_t>(result[6]) << 020) +
|
||||
(static_cast<uint64_t>(result[7]) << 010) +
|
||||
static_cast<uint64_t>(result[8]);
|
||||
uint64_t const restored = (static_cast<uint64_t>(result[1]) << 070) + (static_cast<uint64_t>(result[2]) << 060) +
|
||||
(static_cast<uint64_t>(result[3]) << 050) + (static_cast<uint64_t>(result[4]) << 040) +
|
||||
(static_cast<uint64_t>(result[5]) << 030) + (static_cast<uint64_t>(result[6]) << 020) +
|
||||
(static_cast<uint64_t>(result[7]) << 010) + static_cast<uint64_t>(result[8]);
|
||||
CHECK(restored == i);
|
||||
|
||||
// roundtrip
|
||||
@@ -771,17 +739,7 @@ TEST_CASE("MessagePack")
|
||||
{
|
||||
double const v = 3.1415925;
|
||||
json const j = v;
|
||||
std::vector<uint8_t> const expected =
|
||||
{
|
||||
0xcb,
|
||||
0x40,
|
||||
0x09,
|
||||
0x21,
|
||||
0xfb,
|
||||
0x3f,
|
||||
0xa6,
|
||||
0xde,
|
||||
0xfc};
|
||||
std::vector<uint8_t> const expected = {0xcb, 0x40, 0x09, 0x21, 0xfb, 0x3f, 0xa6, 0xde, 0xfc};
|
||||
const auto result = json::to_msgpack(j);
|
||||
CHECK(result == expected);
|
||||
|
||||
@@ -795,13 +753,7 @@ TEST_CASE("MessagePack")
|
||||
{
|
||||
double const v = 1.0;
|
||||
json const j = v;
|
||||
std::vector<uint8_t> const expected =
|
||||
{
|
||||
0xca,
|
||||
0x3f,
|
||||
0x80,
|
||||
0x00,
|
||||
0x00};
|
||||
std::vector<uint8_t> const expected = {0xca, 0x3f, 0x80, 0x00, 0x00};
|
||||
const auto result = json::to_msgpack(j);
|
||||
CHECK(result == expected);
|
||||
|
||||
@@ -815,13 +767,7 @@ TEST_CASE("MessagePack")
|
||||
{
|
||||
double const v = 128.1280059814453125;
|
||||
json const j = v;
|
||||
std::vector<uint8_t> const expected =
|
||||
{
|
||||
0xca,
|
||||
0x43,
|
||||
0x00,
|
||||
0x20,
|
||||
0xc5};
|
||||
std::vector<uint8_t> const expected = {0xca, 0x43, 0x00, 0x20, 0xc5};
|
||||
const auto result = json::to_msgpack(j);
|
||||
CHECK(result == expected);
|
||||
|
||||
@@ -838,40 +784,8 @@ TEST_CASE("MessagePack")
|
||||
SECTION("N = 0..31")
|
||||
{
|
||||
// explicitly enumerate the first byte for all 32 strings
|
||||
const std::vector<uint8_t> first_bytes =
|
||||
{
|
||||
0xa0,
|
||||
0xa1,
|
||||
0xa2,
|
||||
0xa3,
|
||||
0xa4,
|
||||
0xa5,
|
||||
0xa6,
|
||||
0xa7,
|
||||
0xa8,
|
||||
0xa9,
|
||||
0xaa,
|
||||
0xab,
|
||||
0xac,
|
||||
0xad,
|
||||
0xae,
|
||||
0xaf,
|
||||
0xb0,
|
||||
0xb1,
|
||||
0xb2,
|
||||
0xb3,
|
||||
0xb4,
|
||||
0xb5,
|
||||
0xb6,
|
||||
0xb7,
|
||||
0xb8,
|
||||
0xb9,
|
||||
0xba,
|
||||
0xbb,
|
||||
0xbc,
|
||||
0xbd,
|
||||
0xbe,
|
||||
0xbf};
|
||||
const std::vector<uint8_t> first_bytes = {0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf,
|
||||
0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf};
|
||||
|
||||
for (size_t N = 0; N < first_bytes.size(); ++N)
|
||||
{
|
||||
@@ -942,14 +856,7 @@ TEST_CASE("MessagePack")
|
||||
|
||||
SECTION("N = 256..65535")
|
||||
{
|
||||
for (size_t N :
|
||||
{
|
||||
256u,
|
||||
999u,
|
||||
1025u,
|
||||
3333u,
|
||||
2048u,
|
||||
65535u})
|
||||
for (size_t N : {256u, 999u, 1025u, 3333u, 2048u, 65535u})
|
||||
{
|
||||
CAPTURE(N)
|
||||
|
||||
@@ -979,11 +886,7 @@ TEST_CASE("MessagePack")
|
||||
|
||||
SECTION("N = 65536..4294967295")
|
||||
{
|
||||
for (size_t N :
|
||||
{
|
||||
65536u,
|
||||
77777u,
|
||||
1048576u})
|
||||
for (size_t N : {65536u, 77777u, 1048576u})
|
||||
{
|
||||
CAPTURE(N)
|
||||
|
||||
@@ -1133,18 +1036,7 @@ TEST_CASE("MessagePack")
|
||||
SECTION("{\"a\": {\"b\": {\"c\": {}}}}")
|
||||
{
|
||||
json const j = json::parse(R"({"a": {"b": {"c": {}}}})");
|
||||
std::vector<uint8_t> const expected =
|
||||
{
|
||||
0x81,
|
||||
0xa1,
|
||||
0x61,
|
||||
0x81,
|
||||
0xa1,
|
||||
0x62,
|
||||
0x81,
|
||||
0xa1,
|
||||
0x63,
|
||||
0x80};
|
||||
std::vector<uint8_t> const expected = {0x81, 0xa1, 0x61, 0x81, 0xa1, 0x62, 0x81, 0xa1, 0x63, 0x80};
|
||||
const auto result = json::to_msgpack(j);
|
||||
CHECK(result == expected);
|
||||
|
||||
@@ -1285,14 +1177,7 @@ TEST_CASE("MessagePack")
|
||||
|
||||
SECTION("N = 256..65535")
|
||||
{
|
||||
for (std::size_t N :
|
||||
{
|
||||
256u,
|
||||
999u,
|
||||
1025u,
|
||||
3333u,
|
||||
2048u,
|
||||
65535u})
|
||||
for (std::size_t N : {256u, 999u, 1025u, 3333u, 2048u, 65535u})
|
||||
{
|
||||
CAPTURE(N)
|
||||
|
||||
@@ -1325,11 +1210,7 @@ TEST_CASE("MessagePack")
|
||||
|
||||
SECTION("N = 65536..4294967295")
|
||||
{
|
||||
for (std::size_t N :
|
||||
{
|
||||
65536u,
|
||||
77777u,
|
||||
1048576u})
|
||||
for (std::size_t N : {65536u, 77777u, 1048576u})
|
||||
{
|
||||
CAPTURE(N)
|
||||
|
||||
@@ -1402,14 +1283,7 @@ TEST_CASE("MessagePack")
|
||||
|
||||
SECTION("N = 256..65535")
|
||||
{
|
||||
for (std::size_t N :
|
||||
{
|
||||
256u,
|
||||
999u,
|
||||
1025u,
|
||||
3333u,
|
||||
2048u,
|
||||
65535u})
|
||||
for (std::size_t N : {256u, 999u, 1025u, 3333u, 2048u, 65535u})
|
||||
{
|
||||
CAPTURE(N)
|
||||
|
||||
@@ -1439,11 +1313,7 @@ TEST_CASE("MessagePack")
|
||||
|
||||
SECTION("N = 65536..4294967295")
|
||||
{
|
||||
for (std::size_t N :
|
||||
{
|
||||
65536u,
|
||||
77777u,
|
||||
1048576u})
|
||||
for (std::size_t N : {65536u, 77777u, 1048576u})
|
||||
{
|
||||
CAPTURE(N)
|
||||
|
||||
@@ -1487,7 +1357,10 @@ TEST_CASE("MessagePack")
|
||||
SECTION("empty byte vector")
|
||||
{
|
||||
json _;
|
||||
CHECK_THROWS_WITH_AS(_ = json::from_msgpack(std::vector<uint8_t>()), "[json.exception.parse_error.110] parse error at byte 1: syntax error while parsing MessagePack value: unexpected end of input", json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
_ = json::from_msgpack(std::vector<uint8_t>()),
|
||||
"[json.exception.parse_error.110] parse error at byte 1: syntax error while parsing MessagePack value: unexpected end of input",
|
||||
json::parse_error&);
|
||||
CHECK(json::from_msgpack(std::vector<uint8_t>(), true, false).is_discarded());
|
||||
}
|
||||
|
||||
@@ -1495,66 +1368,86 @@ TEST_CASE("MessagePack")
|
||||
{
|
||||
json _;
|
||||
|
||||
CHECK_THROWS_WITH_AS(_ = json::from_msgpack(std::vector<uint8_t>({0x87})),
|
||||
"[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing MessagePack string: unexpected end of input",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(_ = json::from_msgpack(std::vector<uint8_t>({0xcc})),
|
||||
"[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing MessagePack number: unexpected end of input",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(_ = json::from_msgpack(std::vector<uint8_t>({0xcd})),
|
||||
"[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing MessagePack number: unexpected end of input",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(_ = json::from_msgpack(std::vector<uint8_t>({0xcd, 0x00})),
|
||||
"[json.exception.parse_error.110] parse error at byte 3: syntax error while parsing MessagePack number: unexpected end of input",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(_ = json::from_msgpack(std::vector<uint8_t>({0xce})),
|
||||
"[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing MessagePack number: unexpected end of input",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(_ = json::from_msgpack(std::vector<uint8_t>({0xce, 0x00})),
|
||||
"[json.exception.parse_error.110] parse error at byte 3: syntax error while parsing MessagePack number: unexpected end of input",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(_ = json::from_msgpack(std::vector<uint8_t>({0xce, 0x00, 0x00})),
|
||||
"[json.exception.parse_error.110] parse error at byte 4: syntax error while parsing MessagePack number: unexpected end of input",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(_ = json::from_msgpack(std::vector<uint8_t>({0xce, 0x00, 0x00, 0x00})),
|
||||
"[json.exception.parse_error.110] parse error at byte 5: syntax error while parsing MessagePack number: unexpected end of input",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(_ = json::from_msgpack(std::vector<uint8_t>({0xcf})),
|
||||
"[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing MessagePack number: unexpected end of input",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(_ = json::from_msgpack(std::vector<uint8_t>({0xcf, 0x00})),
|
||||
"[json.exception.parse_error.110] parse error at byte 3: syntax error while parsing MessagePack number: unexpected end of input",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(_ = json::from_msgpack(std::vector<uint8_t>({0xcf, 0x00, 0x00})),
|
||||
"[json.exception.parse_error.110] parse error at byte 4: syntax error while parsing MessagePack number: unexpected end of input",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(_ = json::from_msgpack(std::vector<uint8_t>({0xcf, 0x00, 0x00, 0x00})),
|
||||
"[json.exception.parse_error.110] parse error at byte 5: syntax error while parsing MessagePack number: unexpected end of input",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(_ = json::from_msgpack(std::vector<uint8_t>({0xcf, 0x00, 0x00, 0x00, 0x00})),
|
||||
"[json.exception.parse_error.110] parse error at byte 6: syntax error while parsing MessagePack number: unexpected end of input",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(_ = json::from_msgpack(std::vector<uint8_t>({0xcf, 0x00, 0x00, 0x00, 0x00, 0x00})),
|
||||
"[json.exception.parse_error.110] parse error at byte 7: syntax error while parsing MessagePack number: unexpected end of input",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(_ = json::from_msgpack(std::vector<uint8_t>({0xcf, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00})),
|
||||
"[json.exception.parse_error.110] parse error at byte 8: syntax error while parsing MessagePack number: unexpected end of input",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(_ = json::from_msgpack(std::vector<uint8_t>({0xcf, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00})),
|
||||
"[json.exception.parse_error.110] parse error at byte 9: syntax error while parsing MessagePack number: unexpected end of input",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(_ = json::from_msgpack(std::vector<uint8_t>({0xa5, 0x68, 0x65})),
|
||||
"[json.exception.parse_error.110] parse error at byte 4: syntax error while parsing MessagePack string: unexpected end of input",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(_ = json::from_msgpack(std::vector<uint8_t>({0x92, 0x01})),
|
||||
"[json.exception.parse_error.110] parse error at byte 3: syntax error while parsing MessagePack value: unexpected end of input",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(_ = json::from_msgpack(std::vector<uint8_t>({0x81, 0xa1, 0x61})),
|
||||
"[json.exception.parse_error.110] parse error at byte 4: syntax error while parsing MessagePack value: unexpected end of input",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(_ = json::from_msgpack(std::vector<uint8_t>({0xc4, 0x02})),
|
||||
"[json.exception.parse_error.110] parse error at byte 3: syntax error while parsing MessagePack binary: unexpected end of input",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
_ = json::from_msgpack(std::vector<uint8_t>({0x87})),
|
||||
"[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing MessagePack string: unexpected end of input",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
_ = json::from_msgpack(std::vector<uint8_t>({0xcc})),
|
||||
"[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing MessagePack number: unexpected end of input",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
_ = json::from_msgpack(std::vector<uint8_t>({0xcd})),
|
||||
"[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing MessagePack number: unexpected end of input",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
_ = json::from_msgpack(std::vector<uint8_t>({0xcd, 0x00})),
|
||||
"[json.exception.parse_error.110] parse error at byte 3: syntax error while parsing MessagePack number: unexpected end of input",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
_ = json::from_msgpack(std::vector<uint8_t>({0xce})),
|
||||
"[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing MessagePack number: unexpected end of input",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
_ = json::from_msgpack(std::vector<uint8_t>({0xce, 0x00})),
|
||||
"[json.exception.parse_error.110] parse error at byte 3: syntax error while parsing MessagePack number: unexpected end of input",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
_ = json::from_msgpack(std::vector<uint8_t>({0xce, 0x00, 0x00})),
|
||||
"[json.exception.parse_error.110] parse error at byte 4: syntax error while parsing MessagePack number: unexpected end of input",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
_ = json::from_msgpack(std::vector<uint8_t>({0xce, 0x00, 0x00, 0x00})),
|
||||
"[json.exception.parse_error.110] parse error at byte 5: syntax error while parsing MessagePack number: unexpected end of input",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
_ = json::from_msgpack(std::vector<uint8_t>({0xcf})),
|
||||
"[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing MessagePack number: unexpected end of input",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
_ = json::from_msgpack(std::vector<uint8_t>({0xcf, 0x00})),
|
||||
"[json.exception.parse_error.110] parse error at byte 3: syntax error while parsing MessagePack number: unexpected end of input",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
_ = json::from_msgpack(std::vector<uint8_t>({0xcf, 0x00, 0x00})),
|
||||
"[json.exception.parse_error.110] parse error at byte 4: syntax error while parsing MessagePack number: unexpected end of input",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
_ = json::from_msgpack(std::vector<uint8_t>({0xcf, 0x00, 0x00, 0x00})),
|
||||
"[json.exception.parse_error.110] parse error at byte 5: syntax error while parsing MessagePack number: unexpected end of input",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
_ = json::from_msgpack(std::vector<uint8_t>({0xcf, 0x00, 0x00, 0x00, 0x00})),
|
||||
"[json.exception.parse_error.110] parse error at byte 6: syntax error while parsing MessagePack number: unexpected end of input",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
_ = json::from_msgpack(std::vector<uint8_t>({0xcf, 0x00, 0x00, 0x00, 0x00, 0x00})),
|
||||
"[json.exception.parse_error.110] parse error at byte 7: syntax error while parsing MessagePack number: unexpected end of input",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
_ = json::from_msgpack(std::vector<uint8_t>({0xcf, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00})),
|
||||
"[json.exception.parse_error.110] parse error at byte 8: syntax error while parsing MessagePack number: unexpected end of input",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
_ = json::from_msgpack(std::vector<uint8_t>({0xcf, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00})),
|
||||
"[json.exception.parse_error.110] parse error at byte 9: syntax error while parsing MessagePack number: unexpected end of input",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
_ = json::from_msgpack(std::vector<uint8_t>({0xa5, 0x68, 0x65})),
|
||||
"[json.exception.parse_error.110] parse error at byte 4: syntax error while parsing MessagePack string: unexpected end of input",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
_ = json::from_msgpack(std::vector<uint8_t>({0x92, 0x01})),
|
||||
"[json.exception.parse_error.110] parse error at byte 3: syntax error while parsing MessagePack value: unexpected end of input",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
_ = json::from_msgpack(std::vector<uint8_t>({0x81, 0xa1, 0x61})),
|
||||
"[json.exception.parse_error.110] parse error at byte 4: syntax error while parsing MessagePack value: unexpected end of input",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
_ = json::from_msgpack(std::vector<uint8_t>({0xc4, 0x02})),
|
||||
"[json.exception.parse_error.110] parse error at byte 3: syntax error while parsing MessagePack binary: unexpected end of input",
|
||||
json::parse_error&);
|
||||
|
||||
CHECK(json::from_msgpack(std::vector<uint8_t>({0x87}), true, false).is_discarded());
|
||||
CHECK(json::from_msgpack(std::vector<uint8_t>({0xcc}), true, false).is_discarded());
|
||||
@@ -1584,15 +1477,15 @@ TEST_CASE("MessagePack")
|
||||
SECTION("concrete examples")
|
||||
{
|
||||
json _;
|
||||
CHECK_THROWS_WITH_AS(_ = json::from_msgpack(std::vector<uint8_t>({0xc1})), "[json.exception.parse_error.112] parse error at byte 1: syntax error while parsing MessagePack value: invalid byte: 0xC1", json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(_ = json::from_msgpack(std::vector<uint8_t>({0xc1})),
|
||||
"[json.exception.parse_error.112] parse error at byte 1: syntax error while parsing MessagePack value: invalid byte: 0xC1",
|
||||
json::parse_error&);
|
||||
}
|
||||
|
||||
SECTION("all unsupported bytes")
|
||||
{
|
||||
for (auto byte :
|
||||
{
|
||||
// never used
|
||||
0xc1})
|
||||
for (auto byte : {// never used
|
||||
0xc1})
|
||||
{
|
||||
json _;
|
||||
CHECK_THROWS_AS(_ = json::from_msgpack(std::vector<uint8_t>({static_cast<uint8_t>(byte)})), json::parse_error&);
|
||||
@@ -1604,7 +1497,10 @@ TEST_CASE("MessagePack")
|
||||
SECTION("invalid string in map")
|
||||
{
|
||||
json _;
|
||||
CHECK_THROWS_WITH_AS(_ = json::from_msgpack(std::vector<uint8_t>({0x81, 0xff, 0x01})), "[json.exception.parse_error.113] parse error at byte 2: syntax error while parsing MessagePack string: expected length specification (0xA0-0xBF, 0xD9-0xDB); last byte: 0xFF", json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
_ = json::from_msgpack(std::vector<uint8_t>({0x81, 0xff, 0x01})),
|
||||
"[json.exception.parse_error.113] parse error at byte 2: syntax error while parsing MessagePack string: expected length specification (0xA0-0xBF, 0xD9-0xDB); last byte: 0xFF",
|
||||
json::parse_error&);
|
||||
CHECK(json::from_msgpack(std::vector<uint8_t>({0x81, 0xff, 0x01}), true, false).is_discarded());
|
||||
}
|
||||
|
||||
@@ -1620,7 +1516,10 @@ TEST_CASE("MessagePack")
|
||||
SECTION("strict mode")
|
||||
{
|
||||
json _;
|
||||
CHECK_THROWS_WITH_AS(_ = json::from_msgpack(vec), "[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing MessagePack value: expected end of input; last byte: 0xC0", json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
_ = json::from_msgpack(vec),
|
||||
"[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing MessagePack value: expected end of input; last byte: 0xC0",
|
||||
json::parse_error&);
|
||||
CHECK(json::from_msgpack(vec, true, false).is_discarded());
|
||||
}
|
||||
}
|
||||
@@ -1716,153 +1615,151 @@ TEST_CASE("MessagePack roundtrips" * doctest::skip())
|
||||
exclude_packed.insert(TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_simple.json");
|
||||
exclude_packed.insert(TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_string_unicode.json");
|
||||
|
||||
for (std::string filename :
|
||||
{
|
||||
TEST_DATA_DIRECTORY "/json_nlohmann_tests/all_unicode.json",
|
||||
TEST_DATA_DIRECTORY "/json.org/1.json",
|
||||
TEST_DATA_DIRECTORY "/json.org/2.json",
|
||||
TEST_DATA_DIRECTORY "/json.org/3.json",
|
||||
TEST_DATA_DIRECTORY "/json.org/4.json",
|
||||
TEST_DATA_DIRECTORY "/json.org/5.json",
|
||||
TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip01.json",
|
||||
TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip02.json",
|
||||
TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip03.json",
|
||||
TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip04.json",
|
||||
TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip05.json",
|
||||
TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip06.json",
|
||||
TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip07.json",
|
||||
TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip08.json",
|
||||
TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip09.json",
|
||||
TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip10.json",
|
||||
TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip11.json",
|
||||
TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip12.json",
|
||||
TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip13.json",
|
||||
TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip14.json",
|
||||
TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip15.json",
|
||||
TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip16.json",
|
||||
TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip17.json",
|
||||
TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip18.json",
|
||||
TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip19.json",
|
||||
TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip20.json",
|
||||
TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip21.json",
|
||||
TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip22.json",
|
||||
TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip23.json",
|
||||
TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip24.json",
|
||||
TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip25.json",
|
||||
TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip26.json",
|
||||
TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip27.json",
|
||||
TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip28.json",
|
||||
TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip29.json",
|
||||
TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip30.json",
|
||||
TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip31.json",
|
||||
TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip32.json",
|
||||
TEST_DATA_DIRECTORY "/json_testsuite/sample.json", // kills AppVeyor
|
||||
TEST_DATA_DIRECTORY "/json_tests/pass1.json",
|
||||
TEST_DATA_DIRECTORY "/json_tests/pass2.json",
|
||||
TEST_DATA_DIRECTORY "/json_tests/pass3.json",
|
||||
TEST_DATA_DIRECTORY "/regression/floats.json",
|
||||
TEST_DATA_DIRECTORY "/regression/signed_ints.json",
|
||||
TEST_DATA_DIRECTORY "/regression/unsigned_ints.json",
|
||||
TEST_DATA_DIRECTORY "/regression/working_file.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_array_arraysWithSpaces.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_array_empty-string.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_array_empty.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_array_ending_with_newline.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_array_false.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_array_heterogeneous.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_array_null.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_array_with_1_and_newline.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_array_with_leading_space.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_array_with_several_null.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_array_with_trailing_space.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_0e+1.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_0e1.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_after_space.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_double_close_to_zero.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_double_huge_neg_exp.json",
|
||||
//TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_huge_exp.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_int_with_exp.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_minus_zero.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_negative_int.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_negative_one.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_negative_zero.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_real_capital_e.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_real_capital_e_neg_exp.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_real_capital_e_pos_exp.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_real_exponent.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_real_fraction_exponent.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_real_neg_exp.json",
|
||||
//TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_real_neg_overflow.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_real_pos_exponent.json",
|
||||
//TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_real_pos_overflow.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_real_underflow.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_simple_int.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_simple_real.json",
|
||||
//TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_too_big_neg_int.json",
|
||||
//TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_too_big_pos_int.json",
|
||||
//TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_very_big_negative_int.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_basic.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_duplicated_key.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_duplicated_key_and_value.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_empty.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_empty_key.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_escaped_null_in_key.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_extreme_numbers.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_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",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_with_newlines.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_1_2_3_bytes_UTF-8_sequences.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_UTF-16_Surrogates_U+1D11E_MUSICAL_SYMBOL_G_CLEF.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_accepted_surrogate_pair.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_accepted_surrogate_pairs.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_allowed_escapes.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_backslash_and_u_escaped_zero.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_backslash_doublequotes.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_comments.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_double_escape_a.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_double_escape_n.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_escaped_control_character.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_escaped_noncharacter.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_in_array.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_in_array_with_leading_space.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_last_surrogates_1_and_2.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_newline_uescaped.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_nonCharacterInUTF-8_U+10FFFF.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_nonCharacterInUTF-8_U+1FFFF.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_nonCharacterInUTF-8_U+FFFF.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_null_escape.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_one-byte-utf-8.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_pi.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_simple_ascii.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_space.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_three-byte-utf-8.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_two-byte-utf-8.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_u+2028_line_sep.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_u+2029_par_sep.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_uEscape.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_unescaped_char_delete.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_unicode.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_unicodeEscapedBackslash.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_unicode_2.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_unicode_U+200B_ZERO_WIDTH_SPACE.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_unicode_U+2064_invisible_plus.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_unicode_escaped_double_quote.json",
|
||||
// TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_utf16.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_utf8.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_with_del_character.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_structure_lonely_false.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_structure_lonely_int.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_structure_lonely_negative_real.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_structure_lonely_null.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_structure_lonely_string.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_structure_lonely_true.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_structure_string_empty.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_structure_trailing_newline.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_structure_true_in_array.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_structure_whitespace_array.json"})
|
||||
for (std::string filename : {TEST_DATA_DIRECTORY "/json_nlohmann_tests/all_unicode.json",
|
||||
TEST_DATA_DIRECTORY "/json.org/1.json",
|
||||
TEST_DATA_DIRECTORY "/json.org/2.json",
|
||||
TEST_DATA_DIRECTORY "/json.org/3.json",
|
||||
TEST_DATA_DIRECTORY "/json.org/4.json",
|
||||
TEST_DATA_DIRECTORY "/json.org/5.json",
|
||||
TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip01.json",
|
||||
TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip02.json",
|
||||
TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip03.json",
|
||||
TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip04.json",
|
||||
TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip05.json",
|
||||
TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip06.json",
|
||||
TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip07.json",
|
||||
TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip08.json",
|
||||
TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip09.json",
|
||||
TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip10.json",
|
||||
TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip11.json",
|
||||
TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip12.json",
|
||||
TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip13.json",
|
||||
TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip14.json",
|
||||
TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip15.json",
|
||||
TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip16.json",
|
||||
TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip17.json",
|
||||
TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip18.json",
|
||||
TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip19.json",
|
||||
TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip20.json",
|
||||
TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip21.json",
|
||||
TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip22.json",
|
||||
TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip23.json",
|
||||
TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip24.json",
|
||||
TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip25.json",
|
||||
TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip26.json",
|
||||
TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip27.json",
|
||||
TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip28.json",
|
||||
TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip29.json",
|
||||
TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip30.json",
|
||||
TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip31.json",
|
||||
TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip32.json",
|
||||
TEST_DATA_DIRECTORY "/json_testsuite/sample.json", // kills AppVeyor
|
||||
TEST_DATA_DIRECTORY "/json_tests/pass1.json",
|
||||
TEST_DATA_DIRECTORY "/json_tests/pass2.json",
|
||||
TEST_DATA_DIRECTORY "/json_tests/pass3.json",
|
||||
TEST_DATA_DIRECTORY "/regression/floats.json",
|
||||
TEST_DATA_DIRECTORY "/regression/signed_ints.json",
|
||||
TEST_DATA_DIRECTORY "/regression/unsigned_ints.json",
|
||||
TEST_DATA_DIRECTORY "/regression/working_file.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_array_arraysWithSpaces.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_array_empty-string.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_array_empty.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_array_ending_with_newline.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_array_false.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_array_heterogeneous.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_array_null.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_array_with_1_and_newline.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_array_with_leading_space.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_array_with_several_null.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_array_with_trailing_space.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_0e+1.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_0e1.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_after_space.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_double_close_to_zero.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_double_huge_neg_exp.json",
|
||||
//TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_huge_exp.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_int_with_exp.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_minus_zero.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_negative_int.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_negative_one.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_negative_zero.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_real_capital_e.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_real_capital_e_neg_exp.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_real_capital_e_pos_exp.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_real_exponent.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_real_fraction_exponent.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_real_neg_exp.json",
|
||||
//TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_real_neg_overflow.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_real_pos_exponent.json",
|
||||
//TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_real_pos_overflow.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_real_underflow.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_simple_int.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_simple_real.json",
|
||||
//TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_too_big_neg_int.json",
|
||||
//TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_too_big_pos_int.json",
|
||||
//TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_very_big_negative_int.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_basic.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_duplicated_key.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_duplicated_key_and_value.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_empty.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_empty_key.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_escaped_null_in_key.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_extreme_numbers.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_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",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_with_newlines.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_1_2_3_bytes_UTF-8_sequences.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_UTF-16_Surrogates_U+1D11E_MUSICAL_SYMBOL_G_CLEF.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_accepted_surrogate_pair.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_accepted_surrogate_pairs.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_allowed_escapes.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_backslash_and_u_escaped_zero.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_backslash_doublequotes.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_comments.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_double_escape_a.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_double_escape_n.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_escaped_control_character.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_escaped_noncharacter.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_in_array.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_in_array_with_leading_space.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_last_surrogates_1_and_2.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_newline_uescaped.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_nonCharacterInUTF-8_U+10FFFF.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_nonCharacterInUTF-8_U+1FFFF.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_nonCharacterInUTF-8_U+FFFF.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_null_escape.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_one-byte-utf-8.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_pi.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_simple_ascii.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_space.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_three-byte-utf-8.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_two-byte-utf-8.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_u+2028_line_sep.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_u+2029_par_sep.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_uEscape.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_unescaped_char_delete.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_unicode.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_unicodeEscapedBackslash.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_unicode_2.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_unicode_U+200B_ZERO_WIDTH_SPACE.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_unicode_U+2064_invisible_plus.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_unicode_escaped_double_quote.json",
|
||||
// TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_utf16.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_utf8.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_with_del_character.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_structure_lonely_false.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_structure_lonely_int.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_structure_lonely_negative_real.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_structure_lonely_null.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_structure_lonely_string.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_structure_lonely_true.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_structure_string_empty.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_structure_trailing_newline.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_structure_true_in_array.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_structure_whitespace_array.json"})
|
||||
{
|
||||
CAPTURE(filename)
|
||||
|
||||
|
||||
@@ -18,7 +18,8 @@ struct Foo
|
||||
int b;
|
||||
};
|
||||
|
||||
namespace nlohmann {
|
||||
namespace nlohmann
|
||||
{
|
||||
template<>
|
||||
struct adl_serializer<Foo>
|
||||
{
|
||||
|
||||
@@ -16,7 +16,8 @@ DOCTEST_GCC_SUPPRESS_WARNING("-Wnoexcept")
|
||||
|
||||
using nlohmann::json;
|
||||
|
||||
namespace {
|
||||
namespace
|
||||
{
|
||||
enum test
|
||||
{
|
||||
};
|
||||
|
||||
@@ -61,15 +61,13 @@ TEST_CASE("README" * doctest::skip())
|
||||
j["object"] = {{"currency", "USD"}, {"value", 42.99}};
|
||||
|
||||
// instead, you could also write (which looks very similar to the JSON above)
|
||||
json const j2 =
|
||||
{
|
||||
{"pi", 3.141},
|
||||
{"happy", true},
|
||||
{"name", "Niels"},
|
||||
{"nothing", nullptr},
|
||||
{"answer", {{"everything", 42}}},
|
||||
{"list", {1, 0, 2}},
|
||||
{"object", {{"currency", "USD"}, {"value", 42.99}}}};
|
||||
json const j2 = {{"pi", 3.141},
|
||||
{"happy", true},
|
||||
{"name", "Niels"},
|
||||
{"nothing", nullptr},
|
||||
{"answer", {{"everything", 42}}},
|
||||
{"list", {1, 0, 2}},
|
||||
{"object", {{"currency", "USD"}, {"value", 42.99}}}};
|
||||
}
|
||||
|
||||
{
|
||||
|
||||
@@ -14,13 +14,11 @@ using nlohmann::json;
|
||||
TEST_CASE("reference access")
|
||||
{
|
||||
// create a JSON value with different types
|
||||
const json json_types =
|
||||
{
|
||||
{"boolean", true},
|
||||
{"number", {{"integer", 42}, {"floating-point", 17.23}}},
|
||||
{"string", "Hello, world!"},
|
||||
{"array", {1, 2, 3, 4, 5}},
|
||||
{"null", nullptr}};
|
||||
const json json_types = {{"boolean", true},
|
||||
{"number", {{"integer", 42}, {"floating-point", 17.23}}},
|
||||
{"string", "Hello, world!"},
|
||||
{"array", {1, 2, 3, 4, 5}},
|
||||
{"null", nullptr}};
|
||||
|
||||
SECTION("reference access to object_t")
|
||||
{
|
||||
@@ -246,7 +244,9 @@ TEST_CASE("reference access")
|
||||
//CHECK_THROWS_WITH_AS(value.get_ref<json::number_integer_t&>(),
|
||||
// "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number", json::type_error&);
|
||||
CHECK_NOTHROW(value.get_ref<json::number_unsigned_t&>());
|
||||
CHECK_THROWS_WITH_AS(value.get_ref<json::number_float_t&>(), "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number", json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(value.get_ref<json::number_float_t&>(),
|
||||
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number",
|
||||
json::type_error&);
|
||||
}
|
||||
|
||||
SECTION("reference access to number_float_t")
|
||||
@@ -264,12 +264,24 @@ TEST_CASE("reference access")
|
||||
CHECK(p2 == value.get<test_type>());
|
||||
|
||||
// check if mismatching references throw correctly
|
||||
CHECK_THROWS_WITH_AS(value.get_ref<json::object_t&>(), "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number", json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(value.get_ref<json::array_t&>(), "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number", json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(value.get_ref<json::string_t&>(), "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number", json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(value.get_ref<json::boolean_t&>(), "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number", json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(value.get_ref<json::number_integer_t&>(), "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number", json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(value.get_ref<json::number_unsigned_t&>(), "[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number", json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(value.get_ref<json::object_t&>(),
|
||||
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number",
|
||||
json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(value.get_ref<json::array_t&>(),
|
||||
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number",
|
||||
json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(value.get_ref<json::string_t&>(),
|
||||
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number",
|
||||
json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(value.get_ref<json::boolean_t&>(),
|
||||
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number",
|
||||
json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(value.get_ref<json::number_integer_t&>(),
|
||||
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number",
|
||||
json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(value.get_ref<json::number_unsigned_t&>(),
|
||||
"[json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number",
|
||||
json::type_error&);
|
||||
CHECK_NOTHROW(value.get_ref<json::number_float_t&>());
|
||||
}
|
||||
}
|
||||
|
||||
+154
-458
@@ -43,7 +43,8 @@ using my_json = nlohmann::basic_json<my_workaround_fifo_map>;
|
||||
// for #977
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
|
||||
namespace ns {
|
||||
namespace ns
|
||||
{
|
||||
struct foo
|
||||
{
|
||||
int x;
|
||||
@@ -83,13 +84,15 @@ struct foo_serializer<T, typename std::enable_if<!std::is_same<foo, T>::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>>;
|
||||
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>>;
|
||||
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
// for #805
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
|
||||
namespace {
|
||||
namespace
|
||||
{
|
||||
struct nocopy // NOLINT(cppcoreguidelines-special-member-functions,hicpp-special-member-functions)
|
||||
{
|
||||
nocopy() = default;
|
||||
@@ -187,8 +190,7 @@ TEST_CASE("regression tests 1")
|
||||
|
||||
static_assert(std::is_same<decltype(anon_enum_value), decltype(u)>::value, "types must be the same");
|
||||
|
||||
j.push_back(json::object(
|
||||
{{"game_type", t}}));
|
||||
j.push_back(json::object({{"game_type", t}}));
|
||||
}
|
||||
|
||||
SECTION("issue #76 - dump() / parse() not idempotent")
|
||||
@@ -248,8 +250,7 @@ TEST_CASE("regression tests 1")
|
||||
SECTION("issue #89 - nonstandard integer type")
|
||||
{
|
||||
// create JSON class with nonstandard integer number type
|
||||
using custom_json =
|
||||
nlohmann::basic_json<std::map, std::vector, std::string, bool, int32_t, uint32_t, float>;
|
||||
using custom_json = nlohmann::basic_json<std::map, std::vector, std::string, bool, int32_t, uint32_t, float>;
|
||||
custom_json j;
|
||||
j["int_1"] = 1;
|
||||
CHECK(j["int_1"] == 1);
|
||||
@@ -314,11 +315,7 @@ TEST_CASE("regression tests 1")
|
||||
|
||||
SECTION("issue #100 - failed to iterator json object with reverse_iterator")
|
||||
{
|
||||
json config =
|
||||
{
|
||||
{"111", 111},
|
||||
{"112", 112},
|
||||
{"113", 113}};
|
||||
json config = {{"111", 111}, {"112", 112}, {"113", 113}};
|
||||
|
||||
std::stringstream ss;
|
||||
|
||||
@@ -464,13 +461,11 @@ TEST_CASE("regression tests 1")
|
||||
// create JSON class with nonstandard float number type
|
||||
|
||||
// float
|
||||
nlohmann::basic_json<std::map, std::vector, std::string, bool, int32_t, uint32_t, float> const j_float =
|
||||
1.23e25f;
|
||||
nlohmann::basic_json<std::map, std::vector, std::string, bool, int32_t, uint32_t, float> const j_float = 1.23e25f;
|
||||
CHECK(j_float.get<float>() == 1.23e25f);
|
||||
|
||||
// double
|
||||
nlohmann::basic_json<std::map, std::vector, std::string, bool, int64_t, uint64_t, double> const j_double =
|
||||
1.23e35;
|
||||
nlohmann::basic_json<std::map, std::vector, std::string, bool, int64_t, uint64_t, double> const j_double = 1.23e35;
|
||||
CHECK(j_double.get<double>() == 1.23e35);
|
||||
|
||||
// long double
|
||||
@@ -592,10 +587,9 @@ TEST_CASE("regression tests 1")
|
||||
|
||||
SECTION("issue #283 - value() does not work with _json_pointer types")
|
||||
{
|
||||
json j =
|
||||
{
|
||||
{"object", {{"key1", 1}, {"key2", 2}}},
|
||||
};
|
||||
json j = {
|
||||
{"object", {{"key1", 1}, {"key2", 2}}},
|
||||
};
|
||||
|
||||
int at_integer{j.at("/object/key2"_json_pointer)};
|
||||
int val_integer = j.value("/object/key2"_json_pointer, 0);
|
||||
@@ -614,10 +608,7 @@ TEST_CASE("regression tests 1")
|
||||
|
||||
SECTION("issue #306 - Parsing fails without space at end of file")
|
||||
{
|
||||
for (const auto* filename :
|
||||
{
|
||||
TEST_DATA_DIRECTORY "/regression/broken_file.json",
|
||||
TEST_DATA_DIRECTORY "/regression/working_file.json"})
|
||||
for (const auto* filename : {TEST_DATA_DIRECTORY "/regression/broken_file.json", TEST_DATA_DIRECTORY "/regression/working_file.json"})
|
||||
{
|
||||
CAPTURE(filename)
|
||||
json j;
|
||||
@@ -628,12 +619,10 @@ TEST_CASE("regression tests 1")
|
||||
|
||||
SECTION("issue #310 - make json_benchmarks no longer working in 2.0.4")
|
||||
{
|
||||
for (const auto* filename :
|
||||
{
|
||||
TEST_DATA_DIRECTORY "/regression/floats.json",
|
||||
TEST_DATA_DIRECTORY "/regression/signed_ints.json",
|
||||
TEST_DATA_DIRECTORY "/regression/unsigned_ints.json",
|
||||
TEST_DATA_DIRECTORY "/regression/small_signed_ints.json"})
|
||||
for (const auto* filename : {TEST_DATA_DIRECTORY "/regression/floats.json",
|
||||
TEST_DATA_DIRECTORY "/regression/signed_ints.json",
|
||||
TEST_DATA_DIRECTORY "/regression/unsigned_ints.json",
|
||||
TEST_DATA_DIRECTORY "/regression/small_signed_ints.json"})
|
||||
{
|
||||
CAPTURE(filename)
|
||||
json j;
|
||||
@@ -716,7 +705,10 @@ TEST_CASE("regression tests 1")
|
||||
{
|
||||
std::ifstream f("file_not_found.json");
|
||||
json _;
|
||||
CHECK_THROWS_WITH_AS(_ = json::parse(f), "[json.exception.parse_error.101] parse error at line 1, column 1: attempting to parse an empty input; check that your input string or stream contains the expected JSON", json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
_ = json::parse(f),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 1: attempting to parse an empty input; check that your input string or stream contains the expected JSON",
|
||||
json::parse_error&);
|
||||
}
|
||||
|
||||
SECTION("issue #367 - calling stream at EOF")
|
||||
@@ -730,7 +722,10 @@ TEST_CASE("regression tests 1")
|
||||
// ss is not at EOF; this yielded an error before the fix
|
||||
// (threw basic_string::append). No, it should just throw
|
||||
// a parse error because of the EOF.
|
||||
CHECK_THROWS_WITH_AS(ss >> j, "[json.exception.parse_error.101] parse error at line 1, column 1: attempting to parse an empty input; check that your input string or stream contains the expected JSON", json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
ss >> j,
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 1: attempting to parse an empty input; check that your input string or stream contains the expected JSON",
|
||||
json::parse_error&);
|
||||
}
|
||||
|
||||
SECTION("issue #367 - behavior of operator>> should more closely resemble that of built-in overloads")
|
||||
@@ -739,7 +734,10 @@ TEST_CASE("regression tests 1")
|
||||
{
|
||||
std::stringstream ss;
|
||||
json j;
|
||||
CHECK_THROWS_WITH_AS(ss >> j, "[json.exception.parse_error.101] parse error at line 1, column 1: attempting to parse an empty input; check that your input string or stream contains the expected JSON", json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
ss >> j,
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 1: attempting to parse an empty input; check that your input string or stream contains the expected JSON",
|
||||
json::parse_error&);
|
||||
}
|
||||
|
||||
SECTION("(whitespace)")
|
||||
@@ -747,9 +745,10 @@ TEST_CASE("regression tests 1")
|
||||
std::stringstream ss;
|
||||
ss << " ";
|
||||
json j;
|
||||
CHECK_THROWS_WITH_AS(ss >> j,
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 4: syntax error while parsing value - unexpected end of input; expected '[', '{', or a literal",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
ss >> j,
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 4: syntax error while parsing value - unexpected end of input; expected '[', '{', or a literal",
|
||||
json::parse_error&);
|
||||
}
|
||||
|
||||
SECTION("one value")
|
||||
@@ -760,7 +759,10 @@ TEST_CASE("regression tests 1")
|
||||
CHECK_NOTHROW(ss >> j);
|
||||
CHECK(j == 111);
|
||||
|
||||
CHECK_THROWS_WITH_AS(ss >> j, "[json.exception.parse_error.101] parse error at line 1, column 1: attempting to parse an empty input; check that your input string or stream contains the expected JSON", json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
ss >> j,
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 1: attempting to parse an empty input; check that your input string or stream contains the expected JSON",
|
||||
json::parse_error&);
|
||||
}
|
||||
|
||||
SECTION("one value + whitespace")
|
||||
@@ -771,9 +773,10 @@ TEST_CASE("regression tests 1")
|
||||
CHECK_NOTHROW(ss >> j);
|
||||
CHECK(j == 222);
|
||||
|
||||
CHECK_THROWS_WITH_AS(ss >> j,
|
||||
"[json.exception.parse_error.101] parse error at line 2, column 1: syntax error while parsing value - unexpected end of input; expected '[', '{', or a literal",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
ss >> j,
|
||||
"[json.exception.parse_error.101] parse error at line 2, column 1: syntax error while parsing value - unexpected end of input; expected '[', '{', or a literal",
|
||||
json::parse_error&);
|
||||
}
|
||||
|
||||
SECTION("whitespace + one value")
|
||||
@@ -784,7 +787,10 @@ TEST_CASE("regression tests 1")
|
||||
CHECK_NOTHROW(ss >> j);
|
||||
CHECK(j == 333);
|
||||
|
||||
CHECK_THROWS_WITH_AS(ss >> j, "[json.exception.parse_error.101] parse error at line 1, column 1: attempting to parse an empty input; check that your input string or stream contains the expected JSON", json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
ss >> j,
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 1: attempting to parse an empty input; check that your input string or stream contains the expected JSON",
|
||||
json::parse_error&);
|
||||
}
|
||||
|
||||
SECTION("three values")
|
||||
@@ -799,7 +805,10 @@ TEST_CASE("regression tests 1")
|
||||
CHECK_NOTHROW(ss >> j);
|
||||
CHECK(j == 333);
|
||||
|
||||
CHECK_THROWS_WITH_AS(ss >> j, "[json.exception.parse_error.101] parse error at line 1, column 1: attempting to parse an empty input; check that your input string or stream contains the expected JSON", json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
ss >> j,
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 1: attempting to parse an empty input; check that your input string or stream contains the expected JSON",
|
||||
json::parse_error&);
|
||||
}
|
||||
|
||||
SECTION("literals without whitespace")
|
||||
@@ -816,7 +825,10 @@ TEST_CASE("regression tests 1")
|
||||
CHECK_NOTHROW(ss >> j);
|
||||
CHECK(j == "");
|
||||
|
||||
CHECK_THROWS_WITH_AS(ss >> j, "[json.exception.parse_error.101] parse error at line 1, column 1: attempting to parse an empty input; check that your input string or stream contains the expected JSON", json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
ss >> j,
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 1: attempting to parse an empty input; check that your input string or stream contains the expected JSON",
|
||||
json::parse_error&);
|
||||
}
|
||||
|
||||
SECTION("example from #529")
|
||||
@@ -829,7 +841,10 @@ TEST_CASE("regression tests 1")
|
||||
CHECK_NOTHROW(ss >> j);
|
||||
CHECK(j == json({{"three", 3}}));
|
||||
|
||||
CHECK_THROWS_WITH_AS(ss >> j, "[json.exception.parse_error.101] parse error at line 1, column 1: attempting to parse an empty input; check that your input string or stream contains the expected JSON", json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
ss >> j,
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 1: attempting to parse an empty input; check that your input string or stream contains the expected JSON",
|
||||
json::parse_error&);
|
||||
}
|
||||
|
||||
SECTION("second example from #529")
|
||||
@@ -898,7 +913,9 @@ TEST_CASE("regression tests 1")
|
||||
// original test case
|
||||
std::vector<uint8_t> const vec{0x65, 0xf5, 0x0a, 0x48, 0x21};
|
||||
json _;
|
||||
CHECK_THROWS_WITH_AS(_ = json::from_cbor(vec), "[json.exception.parse_error.110] parse error at byte 6: syntax error while parsing CBOR string: unexpected end of input", json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(_ = json::from_cbor(vec),
|
||||
"[json.exception.parse_error.110] parse error at byte 6: syntax error while parsing CBOR string: unexpected end of input",
|
||||
json::parse_error&);
|
||||
}
|
||||
|
||||
SECTION("issue #407 - Heap-buffer-overflow (OSS-Fuzz issue 343)")
|
||||
@@ -907,23 +924,33 @@ TEST_CASE("regression tests 1")
|
||||
|
||||
// original test case: incomplete float64
|
||||
std::vector<uint8_t> const vec1{0xcb, 0x8f, 0x0a};
|
||||
CHECK_THROWS_WITH_AS(_ = json::from_msgpack(vec1), "[json.exception.parse_error.110] parse error at byte 4: syntax error while parsing MessagePack number: unexpected end of input", json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(_ = json::from_msgpack(vec1),
|
||||
"[json.exception.parse_error.110] parse error at byte 4: syntax error while parsing MessagePack number: unexpected end of input",
|
||||
json::parse_error&);
|
||||
|
||||
// related test case: incomplete float32
|
||||
std::vector<uint8_t> const vec2{0xca, 0x8f, 0x0a};
|
||||
CHECK_THROWS_WITH_AS(_ = json::from_msgpack(vec2), "[json.exception.parse_error.110] parse error at byte 4: syntax error while parsing MessagePack number: unexpected end of input", json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(_ = json::from_msgpack(vec2),
|
||||
"[json.exception.parse_error.110] parse error at byte 4: syntax error while parsing MessagePack number: unexpected end of input",
|
||||
json::parse_error&);
|
||||
|
||||
// related test case: incomplete Half-Precision Float (CBOR)
|
||||
std::vector<uint8_t> const vec3{0xf9, 0x8f};
|
||||
CHECK_THROWS_WITH_AS(_ = json::from_cbor(vec3), "[json.exception.parse_error.110] parse error at byte 3: syntax error while parsing CBOR number: unexpected end of input", json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(_ = json::from_cbor(vec3),
|
||||
"[json.exception.parse_error.110] parse error at byte 3: syntax error while parsing CBOR number: unexpected end of input",
|
||||
json::parse_error&);
|
||||
|
||||
// related test case: incomplete Single-Precision Float (CBOR)
|
||||
std::vector<uint8_t> const vec4{0xfa, 0x8f, 0x0a};
|
||||
CHECK_THROWS_WITH_AS(_ = json::from_cbor(vec4), "[json.exception.parse_error.110] parse error at byte 4: syntax error while parsing CBOR number: unexpected end of input", json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(_ = json::from_cbor(vec4),
|
||||
"[json.exception.parse_error.110] parse error at byte 4: syntax error while parsing CBOR number: unexpected end of input",
|
||||
json::parse_error&);
|
||||
|
||||
// related test case: incomplete Double-Precision Float (CBOR)
|
||||
std::vector<uint8_t> const vec5{0xfb, 0x8f, 0x0a};
|
||||
CHECK_THROWS_WITH_AS(_ = json::from_cbor(vec5), "[json.exception.parse_error.110] parse error at byte 4: syntax error while parsing CBOR number: unexpected end of input", json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(_ = json::from_cbor(vec5),
|
||||
"[json.exception.parse_error.110] parse error at byte 4: syntax error while parsing CBOR number: unexpected end of input",
|
||||
json::parse_error&);
|
||||
}
|
||||
|
||||
SECTION("issue #408 - Heap-buffer-overflow (OSS-Fuzz issue 344)")
|
||||
@@ -932,148 +959,30 @@ TEST_CASE("regression tests 1")
|
||||
|
||||
// original test case
|
||||
std::vector<uint8_t> const vec1{0x87};
|
||||
CHECK_THROWS_WITH_AS(_ = json::from_msgpack(vec1), "[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing MessagePack string: unexpected end of input", json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(_ = json::from_msgpack(vec1),
|
||||
"[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing MessagePack string: unexpected end of input",
|
||||
json::parse_error&);
|
||||
|
||||
// more test cases for MessagePack
|
||||
for (auto b :
|
||||
{
|
||||
0x81,
|
||||
0x82,
|
||||
0x83,
|
||||
0x84,
|
||||
0x85,
|
||||
0x86,
|
||||
0x87,
|
||||
0x88,
|
||||
0x89,
|
||||
0x8a,
|
||||
0x8b,
|
||||
0x8c,
|
||||
0x8d,
|
||||
0x8e,
|
||||
0x8f, // fixmap
|
||||
0x91,
|
||||
0x92,
|
||||
0x93,
|
||||
0x94,
|
||||
0x95,
|
||||
0x96,
|
||||
0x97,
|
||||
0x98,
|
||||
0x99,
|
||||
0x9a,
|
||||
0x9b,
|
||||
0x9c,
|
||||
0x9d,
|
||||
0x9e,
|
||||
0x9f, // fixarray
|
||||
0xa1,
|
||||
0xa2,
|
||||
0xa3,
|
||||
0xa4,
|
||||
0xa5,
|
||||
0xa6,
|
||||
0xa7,
|
||||
0xa8,
|
||||
0xa9,
|
||||
0xaa,
|
||||
0xab,
|
||||
0xac,
|
||||
0xad,
|
||||
0xae,
|
||||
0xaf, // fixstr
|
||||
0xb0,
|
||||
0xb1,
|
||||
0xb2,
|
||||
0xb3,
|
||||
0xb4,
|
||||
0xb5,
|
||||
0xb6,
|
||||
0xb7,
|
||||
0xb8,
|
||||
0xb9,
|
||||
0xba,
|
||||
0xbb,
|
||||
0xbc,
|
||||
0xbd,
|
||||
0xbe,
|
||||
0xbf})
|
||||
for (auto b : {0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e,
|
||||
0x8f, // fixmap
|
||||
0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e,
|
||||
0x9f, // fixarray
|
||||
0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae,
|
||||
0xaf, // fixstr
|
||||
0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf})
|
||||
{
|
||||
std::vector<uint8_t> const vec(1, static_cast<uint8_t>(b));
|
||||
CHECK_THROWS_AS(_ = json::from_msgpack(vec), json::parse_error&);
|
||||
}
|
||||
|
||||
// more test cases for CBOR
|
||||
for (auto b :
|
||||
{
|
||||
0x61,
|
||||
0x62,
|
||||
0x63,
|
||||
0x64,
|
||||
0x65,
|
||||
0x66,
|
||||
0x67,
|
||||
0x68,
|
||||
0x69,
|
||||
0x6a,
|
||||
0x6b,
|
||||
0x6c,
|
||||
0x6d,
|
||||
0x6e,
|
||||
0x6f,
|
||||
0x70,
|
||||
0x71,
|
||||
0x72,
|
||||
0x73,
|
||||
0x74,
|
||||
0x75,
|
||||
0x76,
|
||||
for (auto b : {
|
||||
0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76,
|
||||
0x77, // UTF-8 string
|
||||
0x81,
|
||||
0x82,
|
||||
0x83,
|
||||
0x84,
|
||||
0x85,
|
||||
0x86,
|
||||
0x87,
|
||||
0x88,
|
||||
0x89,
|
||||
0x8a,
|
||||
0x8b,
|
||||
0x8c,
|
||||
0x8d,
|
||||
0x8e,
|
||||
0x8f,
|
||||
0x90,
|
||||
0x91,
|
||||
0x92,
|
||||
0x93,
|
||||
0x94,
|
||||
0x95,
|
||||
0x96,
|
||||
0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96,
|
||||
0x97, // array
|
||||
0xa1,
|
||||
0xa2,
|
||||
0xa3,
|
||||
0xa4,
|
||||
0xa5,
|
||||
0xa6,
|
||||
0xa7,
|
||||
0xa8,
|
||||
0xa9,
|
||||
0xaa,
|
||||
0xab,
|
||||
0xac,
|
||||
0xad,
|
||||
0xae,
|
||||
0xaf,
|
||||
0xb0,
|
||||
0xb1,
|
||||
0xb2,
|
||||
0xb3,
|
||||
0xb4,
|
||||
0xb5,
|
||||
0xb6,
|
||||
0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6,
|
||||
0xb7 // map
|
||||
})
|
||||
{
|
||||
@@ -1083,8 +992,12 @@ TEST_CASE("regression tests 1")
|
||||
|
||||
// special case: empty input
|
||||
std::vector<uint8_t> const vec2;
|
||||
CHECK_THROWS_WITH_AS(_ = json::from_cbor(vec2), "[json.exception.parse_error.110] parse error at byte 1: syntax error while parsing CBOR value: unexpected end of input", json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(_ = json::from_msgpack(vec2), "[json.exception.parse_error.110] parse error at byte 1: syntax error while parsing MessagePack value: unexpected end of input", json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(_ = json::from_cbor(vec2),
|
||||
"[json.exception.parse_error.110] parse error at byte 1: syntax error while parsing CBOR value: unexpected end of input",
|
||||
json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(_ = json::from_msgpack(vec2),
|
||||
"[json.exception.parse_error.110] parse error at byte 1: syntax error while parsing MessagePack value: unexpected end of input",
|
||||
json::parse_error&);
|
||||
}
|
||||
|
||||
SECTION("issue #411 - Heap-buffer-overflow (OSS-Fuzz issue 366)")
|
||||
@@ -1093,180 +1006,65 @@ TEST_CASE("regression tests 1")
|
||||
|
||||
// original test case: empty UTF-8 string (indefinite length)
|
||||
std::vector<uint8_t> const vec1{0x7f};
|
||||
CHECK_THROWS_WITH_AS(_ = json::from_cbor(vec1), "[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing CBOR string: unexpected end of input", json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(_ = json::from_cbor(vec1),
|
||||
"[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing CBOR string: unexpected end of input",
|
||||
json::parse_error&);
|
||||
|
||||
// related test case: empty array (indefinite length)
|
||||
std::vector<uint8_t> const vec2{0x9f};
|
||||
CHECK_THROWS_WITH_AS(_ = json::from_cbor(vec2), "[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing CBOR value: unexpected end of input", json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(_ = json::from_cbor(vec2),
|
||||
"[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing CBOR value: unexpected end of input",
|
||||
json::parse_error&);
|
||||
|
||||
// related test case: empty map (indefinite length)
|
||||
std::vector<uint8_t> const vec3{0xbf};
|
||||
CHECK_THROWS_WITH_AS(_ = json::from_cbor(vec3), "[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing CBOR string: unexpected end of input", json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(_ = json::from_cbor(vec3),
|
||||
"[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing CBOR string: unexpected end of input",
|
||||
json::parse_error&);
|
||||
}
|
||||
|
||||
SECTION("issue #412 - Heap-buffer-overflow (OSS-Fuzz issue 367)")
|
||||
{
|
||||
// original test case
|
||||
std::vector<uint8_t> const vec{
|
||||
0xab,
|
||||
0x98,
|
||||
0x98,
|
||||
0x98,
|
||||
0x98,
|
||||
0x98,
|
||||
0x98,
|
||||
0x98,
|
||||
0x98,
|
||||
0x98,
|
||||
0x98,
|
||||
0x98,
|
||||
0x98,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x60,
|
||||
0xab,
|
||||
0x98,
|
||||
0x98,
|
||||
0x98,
|
||||
0x98,
|
||||
0x98,
|
||||
0x98,
|
||||
0x98,
|
||||
0x98,
|
||||
0x98,
|
||||
0x98,
|
||||
0x98,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x60,
|
||||
0x60,
|
||||
0x60,
|
||||
0x60,
|
||||
0x60,
|
||||
0x60,
|
||||
0x60,
|
||||
0x60,
|
||||
0x60,
|
||||
0x60,
|
||||
0x60,
|
||||
0x60,
|
||||
0x60,
|
||||
0x60,
|
||||
0x60,
|
||||
0x60,
|
||||
0x60,
|
||||
0x60,
|
||||
0x60,
|
||||
0x60,
|
||||
0x60,
|
||||
0x60,
|
||||
0x60,
|
||||
0x60,
|
||||
0x60,
|
||||
0x60,
|
||||
0x60,
|
||||
0x60,
|
||||
0x60,
|
||||
0x60,
|
||||
0x60,
|
||||
0x60,
|
||||
0x60,
|
||||
0x60,
|
||||
0x60,
|
||||
0x60,
|
||||
0x60,
|
||||
0x60,
|
||||
0x60,
|
||||
0x60,
|
||||
0x60,
|
||||
0x60,
|
||||
0x60,
|
||||
0x60,
|
||||
0x60,
|
||||
0x60,
|
||||
0x60,
|
||||
0x60,
|
||||
0x60,
|
||||
0x60,
|
||||
0x60,
|
||||
0x60,
|
||||
0x60,
|
||||
0x60,
|
||||
0xa0,
|
||||
0x9f,
|
||||
0x9f,
|
||||
0x97,
|
||||
0x60,
|
||||
0x60,
|
||||
0x60,
|
||||
0x60,
|
||||
0x60,
|
||||
0x60,
|
||||
0x60,
|
||||
0x60,
|
||||
0x60,
|
||||
0x60,
|
||||
0x60,
|
||||
0x60,
|
||||
0x60,
|
||||
0x60,
|
||||
0x60,
|
||||
0x60,
|
||||
0x60,
|
||||
0x60,
|
||||
0x60,
|
||||
0x60,
|
||||
0x60,
|
||||
0x60,
|
||||
0x60,
|
||||
0x60,
|
||||
0x60,
|
||||
0x60,
|
||||
0x60,
|
||||
0x60,
|
||||
0x60,
|
||||
0x60,
|
||||
0x60,
|
||||
0x60,
|
||||
0x60,
|
||||
0x60,
|
||||
0x60,
|
||||
0x60,
|
||||
0x60,
|
||||
0x60,
|
||||
0x60,
|
||||
0x60,
|
||||
0x60,
|
||||
0x60,
|
||||
0x60,
|
||||
0x60,
|
||||
0x60,
|
||||
0x60};
|
||||
std::vector<uint8_t> const vec{0xab, 0x98, 0x98, 0x98, 0x98, 0x98, 0x98, 0x98, 0x98, 0x98, 0x98, 0x98, 0x98, 0x00, 0x00, 0x00, 0x60, 0xab, 0x98, 0x98,
|
||||
0x98, 0x98, 0x98, 0x98, 0x98, 0x98, 0x98, 0x98, 0x98, 0x00, 0x00, 0x00, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60,
|
||||
0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60,
|
||||
0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60,
|
||||
0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0xa0, 0x9f, 0x9f, 0x97, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60,
|
||||
0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60,
|
||||
0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60};
|
||||
|
||||
json _;
|
||||
CHECK_THROWS_WITH_AS(_ = json::from_cbor(vec), "[json.exception.parse_error.113] parse error at byte 2: syntax error while parsing CBOR string: expected length specification (0x60-0x7B) or indefinite string type (0x7F); last byte: 0x98", json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
_ = json::from_cbor(vec),
|
||||
"[json.exception.parse_error.113] parse error at byte 2: syntax error while parsing CBOR string: expected length specification (0x60-0x7B) or indefinite string type (0x7F); last byte: 0x98",
|
||||
json::parse_error&);
|
||||
|
||||
// related test case: nonempty UTF-8 string (indefinite length)
|
||||
std::vector<uint8_t> const vec1{0x7f, 0x61, 0x61};
|
||||
CHECK_THROWS_WITH_AS(_ = json::from_cbor(vec1), "[json.exception.parse_error.110] parse error at byte 4: syntax error while parsing CBOR string: unexpected end of input", json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(_ = json::from_cbor(vec1),
|
||||
"[json.exception.parse_error.110] parse error at byte 4: syntax error while parsing CBOR string: unexpected end of input",
|
||||
json::parse_error&);
|
||||
|
||||
// related test case: nonempty array (indefinite length)
|
||||
std::vector<uint8_t> const vec2{0x9f, 0x01};
|
||||
CHECK_THROWS_WITH_AS(_ = json::from_cbor(vec2), "[json.exception.parse_error.110] parse error at byte 3: syntax error while parsing CBOR value: unexpected end of input", json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(_ = json::from_cbor(vec2),
|
||||
"[json.exception.parse_error.110] parse error at byte 3: syntax error while parsing CBOR value: unexpected end of input",
|
||||
json::parse_error&);
|
||||
|
||||
// related test case: nonempty map (indefinite length)
|
||||
std::vector<uint8_t> const vec3{0xbf, 0x61, 0x61, 0x01};
|
||||
CHECK_THROWS_WITH_AS(_ = json::from_cbor(vec3), "[json.exception.parse_error.110] parse error at byte 5: syntax error while parsing CBOR string: unexpected end of input", json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(_ = json::from_cbor(vec3),
|
||||
"[json.exception.parse_error.110] parse error at byte 5: syntax error while parsing CBOR string: unexpected end of input",
|
||||
json::parse_error&);
|
||||
}
|
||||
|
||||
SECTION("issue #414 - compare with literal 0)")
|
||||
{
|
||||
#define CHECK_TYPE(v) \
|
||||
CHECK((json(v) == (v))); \
|
||||
CHECK(((v) == json(v))); \
|
||||
CHECK_FALSE((json(v) != (v))); \
|
||||
#define CHECK_TYPE(v) \
|
||||
CHECK((json(v) == (v))); \
|
||||
CHECK(((v) == json(v))); \
|
||||
CHECK_FALSE((json(v) != (v))); \
|
||||
CHECK_FALSE(((v) != json(v)));
|
||||
|
||||
CHECK_TYPE(nullptr)
|
||||
@@ -1282,110 +1080,24 @@ TEST_CASE("regression tests 1")
|
||||
SECTION("issue #416 - Use-of-uninitialized-value (OSS-Fuzz issue 377)")
|
||||
{
|
||||
// original test case
|
||||
std::vector<uint8_t> const vec1{
|
||||
0x94,
|
||||
0xfa,
|
||||
0xfa,
|
||||
0xfa,
|
||||
0xfa,
|
||||
0xfa,
|
||||
0xfa,
|
||||
0xfa,
|
||||
0x3a,
|
||||
0x96,
|
||||
0x96,
|
||||
0xb4,
|
||||
0xb4,
|
||||
0xb4,
|
||||
0xb4,
|
||||
0xb4,
|
||||
0xb4,
|
||||
0xb4,
|
||||
0xb4,
|
||||
0xb4,
|
||||
0xb4,
|
||||
0xb4,
|
||||
0xb4,
|
||||
0x71,
|
||||
0xb4,
|
||||
0xb4,
|
||||
0xfa,
|
||||
0xfa,
|
||||
0xfa,
|
||||
0xfa,
|
||||
0xfa,
|
||||
0x3a,
|
||||
0x96,
|
||||
0x96,
|
||||
0xb4,
|
||||
0xb4,
|
||||
0xfa,
|
||||
0x94,
|
||||
0x94,
|
||||
0x61,
|
||||
0x61,
|
||||
0x61,
|
||||
0x61,
|
||||
0x61,
|
||||
0x61,
|
||||
0x61,
|
||||
0x61,
|
||||
0xfa};
|
||||
std::vector<uint8_t> const vec1{0x94, 0xfa, 0xfa, 0xfa, 0xfa, 0xfa, 0xfa, 0xfa, 0x3a, 0x96, 0x96, 0xb4, 0xb4, 0xb4, 0xb4, 0xb4,
|
||||
0xb4, 0xb4, 0xb4, 0xb4, 0xb4, 0xb4, 0xb4, 0x71, 0xb4, 0xb4, 0xfa, 0xfa, 0xfa, 0xfa, 0xfa, 0x3a,
|
||||
0x96, 0x96, 0xb4, 0xb4, 0xfa, 0x94, 0x94, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61, 0xfa};
|
||||
|
||||
json _;
|
||||
CHECK_THROWS_WITH_AS(_ = json::from_cbor(vec1), "[json.exception.parse_error.113] parse error at byte 13: syntax error while parsing CBOR string: expected length specification (0x60-0x7B) or indefinite string type (0x7F); last byte: 0xB4", json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
_ = json::from_cbor(vec1),
|
||||
"[json.exception.parse_error.113] parse error at byte 13: syntax error while parsing CBOR string: expected length specification (0x60-0x7B) or indefinite string type (0x7F); last byte: 0xB4",
|
||||
json::parse_error&);
|
||||
|
||||
// related test case: double-precision
|
||||
std::vector<uint8_t> const vec2{
|
||||
0x94,
|
||||
0xfa,
|
||||
0xfa,
|
||||
0xfa,
|
||||
0xfa,
|
||||
0xfa,
|
||||
0xfa,
|
||||
0xfa,
|
||||
0x3a,
|
||||
0x96,
|
||||
0x96,
|
||||
0xb4,
|
||||
0xb4,
|
||||
0xb4,
|
||||
0xb4,
|
||||
0xb4,
|
||||
0xb4,
|
||||
0xb4,
|
||||
0xb4,
|
||||
0xb4,
|
||||
0xb4,
|
||||
0xb4,
|
||||
0xb4,
|
||||
0x71,
|
||||
0xb4,
|
||||
0xb4,
|
||||
0xfa,
|
||||
0xfa,
|
||||
0xfa,
|
||||
0xfa,
|
||||
0xfa,
|
||||
0x3a,
|
||||
0x96,
|
||||
0x96,
|
||||
0xb4,
|
||||
0xb4,
|
||||
0xfa,
|
||||
0x94,
|
||||
0x94,
|
||||
0x61,
|
||||
0x61,
|
||||
0x61,
|
||||
0x61,
|
||||
0x61,
|
||||
0x61,
|
||||
0x61,
|
||||
0x61,
|
||||
0xfb};
|
||||
CHECK_THROWS_WITH_AS(_ = json::from_cbor(vec2), "[json.exception.parse_error.113] parse error at byte 13: syntax error while parsing CBOR string: expected length specification (0x60-0x7B) or indefinite string type (0x7F); last byte: 0xB4", json::parse_error&);
|
||||
std::vector<uint8_t> const vec2{0x94, 0xfa, 0xfa, 0xfa, 0xfa, 0xfa, 0xfa, 0xfa, 0x3a, 0x96, 0x96, 0xb4, 0xb4, 0xb4, 0xb4, 0xb4,
|
||||
0xb4, 0xb4, 0xb4, 0xb4, 0xb4, 0xb4, 0xb4, 0x71, 0xb4, 0xb4, 0xfa, 0xfa, 0xfa, 0xfa, 0xfa, 0x3a,
|
||||
0x96, 0x96, 0xb4, 0xb4, 0xfa, 0x94, 0x94, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61, 0xfb};
|
||||
CHECK_THROWS_WITH_AS(
|
||||
_ = json::from_cbor(vec2),
|
||||
"[json.exception.parse_error.113] parse error at byte 13: syntax error while parsing CBOR string: expected length specification (0x60-0x7B) or indefinite string type (0x7F); last byte: 0xB4",
|
||||
json::parse_error&);
|
||||
}
|
||||
|
||||
SECTION("issue #452 - Heap-buffer-overflow (OSS-Fuzz issue 585)")
|
||||
@@ -1636,8 +1348,8 @@ TEST_CASE("regression tests 1")
|
||||
{
|
||||
{
|
||||
std::ifstream is;
|
||||
is.exceptions(
|
||||
is.exceptions() | std::ios_base::failbit | std::ios_base::badbit); // handle different exceptions as 'file not found', 'permission denied'
|
||||
is.exceptions(is.exceptions() | std::ios_base::failbit |
|
||||
std::ios_base::badbit); // handle different exceptions as 'file not found', 'permission denied'
|
||||
|
||||
is.open(TEST_DATA_DIRECTORY "/regression/working_file.json");
|
||||
json _;
|
||||
@@ -1646,11 +1358,10 @@ TEST_CASE("regression tests 1")
|
||||
|
||||
{
|
||||
std::ifstream is;
|
||||
is.exceptions(
|
||||
is.exceptions() | std::ios_base::failbit | std::ios_base::badbit); // handle different exceptions as 'file not found', 'permission denied'
|
||||
is.exceptions(is.exceptions() | std::ios_base::failbit |
|
||||
std::ios_base::badbit); // handle different exceptions as 'file not found', 'permission denied'
|
||||
|
||||
is.open(TEST_DATA_DIRECTORY "/json_nlohmann_tests/all_unicode.json.cbor",
|
||||
std::ios_base::in | std::ios_base::binary);
|
||||
is.open(TEST_DATA_DIRECTORY "/json_nlohmann_tests/all_unicode.json.cbor", std::ios_base::in | std::ios_base::binary);
|
||||
json _;
|
||||
CHECK_NOTHROW(_ = nlohmann::json::from_cbor(is));
|
||||
}
|
||||
@@ -1666,7 +1377,8 @@ TEST_CASE("regression tests 1")
|
||||
|
||||
SECTION("issue #838 - incorrect parse error with binary data in keys")
|
||||
{
|
||||
std::array<uint8_t, 28> key1 = {{103, 92, 117, 48, 48, 48, 55, 92, 114, 215, 126, 214, 95, 92, 34, 174, 40, 71, 38, 174, 40, 71, 38, 223, 134, 247, 127, 0}};
|
||||
std::array<uint8_t, 28> key1 = {
|
||||
{103, 92, 117, 48, 48, 48, 55, 92, 114, 215, 126, 214, 95, 92, 34, 174, 40, 71, 38, 174, 40, 71, 38, 223, 134, 247, 127, 0}};
|
||||
std::string const key1_str(reinterpret_cast<char*>(key1.data()));
|
||||
json const j = key1_str;
|
||||
CHECK_THROWS_WITH_AS(j.dump(), "[json.exception.type_error.316] invalid UTF-8 byte at index 10: 0x7E", json::type_error&);
|
||||
@@ -1696,33 +1408,17 @@ TEST_CASE("regression tests 1")
|
||||
auto p1 = R"([{"op": "move",
|
||||
"from": "/one/two/three",
|
||||
"path": "/a/b/c"}])"_json;
|
||||
CHECK_THROWS_WITH_AS(model.patch(p1),
|
||||
"[json.exception.out_of_range.403] key 'a' not found",
|
||||
json::out_of_range&);
|
||||
CHECK_THROWS_WITH_AS(model.patch(p1), "[json.exception.out_of_range.403] key 'a' not found", json::out_of_range&);
|
||||
|
||||
auto p2 = R"([{"op": "copy",
|
||||
"from": "/one/two/three",
|
||||
"path": "/a/b/c"}])"_json;
|
||||
CHECK_THROWS_WITH_AS(model.patch(p2),
|
||||
"[json.exception.out_of_range.403] key 'a' not found",
|
||||
json::out_of_range&);
|
||||
CHECK_THROWS_WITH_AS(model.patch(p2), "[json.exception.out_of_range.403] key 'a' not found", json::out_of_range&);
|
||||
}
|
||||
|
||||
SECTION("issue #961 - incorrect parsing of indefinite length CBOR strings")
|
||||
{
|
||||
std::vector<uint8_t> const v_cbor =
|
||||
{
|
||||
0x7F,
|
||||
0x64,
|
||||
'a',
|
||||
'b',
|
||||
'c',
|
||||
'd',
|
||||
0x63,
|
||||
'1',
|
||||
'2',
|
||||
'3',
|
||||
0xFF};
|
||||
std::vector<uint8_t> const v_cbor = {0x7F, 0x64, 'a', 'b', 'c', 'd', 0x63, '1', '2', '3', 0xFF};
|
||||
json j = json::from_cbor(v_cbor);
|
||||
CHECK(j == "abcd123");
|
||||
}
|
||||
|
||||
@@ -55,7 +55,8 @@ using float_json = nlohmann::basic_json<std::map, std::vector, std::string, bool
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
// for #1647
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
namespace {
|
||||
namespace
|
||||
{
|
||||
struct NonDefaultFromJsonStruct
|
||||
{};
|
||||
|
||||
@@ -111,7 +112,8 @@ bool operator==(Data const& lhs, Data const& rhs)
|
||||
// return !(lhs == rhs);
|
||||
//}
|
||||
|
||||
namespace nlohmann {
|
||||
namespace nlohmann
|
||||
{
|
||||
template<>
|
||||
struct adl_serializer<NonDefaultFromJsonStruct>
|
||||
{
|
||||
@@ -144,7 +146,8 @@ struct NonDefaultConstructible
|
||||
int x;
|
||||
};
|
||||
|
||||
namespace nlohmann {
|
||||
namespace nlohmann
|
||||
{
|
||||
template<>
|
||||
struct adl_serializer<NonDefaultConstructible>
|
||||
{
|
||||
@@ -429,16 +432,10 @@ TEST_CASE("regression tests 2")
|
||||
|
||||
using it_type = decltype(p1.begin());
|
||||
|
||||
std::set_difference(
|
||||
p1.begin(),
|
||||
p1.end(),
|
||||
p2.begin(),
|
||||
p2.end(),
|
||||
std::inserter(diffs, diffs.end()),
|
||||
[&](const it_type& e1, const it_type& e2) -> bool {
|
||||
using comper_pair = std::pair<std::string, decltype(e1.value())>; // Trying to avoid unneeded copy
|
||||
return comper_pair(e1.key(), e1.value()) < comper_pair(e2.key(), e2.value()); // Using pair comper
|
||||
});
|
||||
std::set_difference(p1.begin(), p1.end(), p2.begin(), p2.end(), std::inserter(diffs, diffs.end()), [&](const it_type& e1, const it_type& e2) -> bool {
|
||||
using comper_pair = std::pair<std::string, decltype(e1.value())>; // Trying to avoid unneeded copy
|
||||
return comper_pair(e1.key(), e1.value()) < comper_pair(e2.key(), e2.value()); // Using pair comper
|
||||
});
|
||||
|
||||
CHECK(diffs.size() == 1); // Note the change here, was 2
|
||||
}
|
||||
@@ -453,12 +450,11 @@ TEST_CASE("regression tests 2")
|
||||
SECTION("issue #1299 - compile error in from_json converting to container "
|
||||
"with std::pair")
|
||||
{
|
||||
const json j =
|
||||
{
|
||||
{"1", {{"a", "testa_1"}, {"b", "testb_1"}}},
|
||||
{"2", {{"a", "testa_2"}, {"b", "testb_2"}}},
|
||||
{"3", {{"a", "testa_3"}, {"b", "testb_3"}}},
|
||||
};
|
||||
const json j = {
|
||||
{"1", {{"a", "testa_1"}, {"b", "testb_1"}}},
|
||||
{"2", {{"a", "testa_2"}, {"b", "testb_2"}}},
|
||||
{"3", {{"a", "testa_3"}, {"b", "testb_3"}}},
|
||||
};
|
||||
|
||||
std::map<std::string, Data> expected{
|
||||
{"1", {"testa_1", "testb_1"}},
|
||||
@@ -508,9 +504,11 @@ TEST_CASE("regression tests 2")
|
||||
SECTION("test case in issue #1445")
|
||||
{
|
||||
nlohmann::json dump_test;
|
||||
const std::array<int, 108> data =
|
||||
{
|
||||
{109, 108, 103, 125, -122, -53, 115, 18, 3, 0, 102, 19, 1, 15, -110, 13, -3, -1, -81, 32, 2, 0, 0, 0, 0, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -80, 2, 0, 0, 96, -118, 46, -116, 46, 109, -84, -87, 108, 14, 109, -24, -83, 13, -18, -51, -83, -52, -115, 14, 6, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 64, 3, 0, 0, 0, 35, -74, -73, 55, 57, -128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 33, 0, 0, 0, -96, -54, -28, -26}};
|
||||
const std::array<int, 108> data = {{109, 108, 103, 125, -122, -53, 115, 18, 3, 0, 102, 19, 1, 15, -110, 13, -3, -1, -81, 32, 2, 0,
|
||||
0, 0, 0, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -80, 2, 0, 0,
|
||||
96, -118, 46, -116, 46, 109, -84, -87, 108, 14, 109, -24, -83, 13, -18, -51, -83, -52, -115, 14, 6, 32,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 64, 3, 0, 0, 0, 35, -74, -73, 55, 57, -128,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 33, 0, 0, 0, -96, -54, -28, -26}};
|
||||
std::string s;
|
||||
for (const int i : data)
|
||||
{
|
||||
@@ -607,14 +605,14 @@ TEST_CASE("regression tests 2")
|
||||
|
||||
SECTION("issue #2067 - cannot serialize binary data to text JSON")
|
||||
{
|
||||
const std::array<unsigned char, 23> data = {{0x81, 0xA4, 0x64, 0x61, 0x74, 0x61, 0xC4, 0x0F, 0x33, 0x30, 0x30, 0x32, 0x33, 0x34, 0x30, 0x31, 0x30, 0x37, 0x30, 0x35, 0x30, 0x31, 0x30}};
|
||||
const std::array<unsigned char, 23> data = {
|
||||
{0x81, 0xA4, 0x64, 0x61, 0x74, 0x61, 0xC4, 0x0F, 0x33, 0x30, 0x30, 0x32, 0x33, 0x34, 0x30, 0x31, 0x30, 0x37, 0x30, 0x35, 0x30, 0x31, 0x30}};
|
||||
const json j = json::from_msgpack(data.data(), data.size());
|
||||
CHECK_NOTHROW(
|
||||
j.dump(4, // Indent
|
||||
' ', // Indent char
|
||||
false, // Ensure ascii
|
||||
json::error_handler_t::strict // Error
|
||||
));
|
||||
CHECK_NOTHROW(j.dump(4, // Indent
|
||||
' ', // Indent char
|
||||
false, // Ensure ascii
|
||||
json::error_handler_t::strict // Error
|
||||
));
|
||||
}
|
||||
|
||||
SECTION("PR #2181 - regression bug with lvalue")
|
||||
@@ -628,18 +626,7 @@ TEST_CASE("regression tests 2")
|
||||
|
||||
SECTION("issue #2293 - eof doesn't cause parsing to stop")
|
||||
{
|
||||
const std::vector<uint8_t> data =
|
||||
{
|
||||
0x7B,
|
||||
0x6F,
|
||||
0x62,
|
||||
0x6A,
|
||||
0x65,
|
||||
0x63,
|
||||
0x74,
|
||||
0x20,
|
||||
0x4F,
|
||||
0x42};
|
||||
const std::vector<uint8_t> data = {0x7B, 0x6F, 0x62, 0x6A, 0x65, 0x63, 0x74, 0x20, 0x4F, 0x42};
|
||||
const json result = json::from_cbor(data, true, false);
|
||||
CHECK(result.is_discarded());
|
||||
}
|
||||
@@ -654,8 +641,7 @@ TEST_CASE("regression tests 2")
|
||||
auto jsonAnimals_parsed = nlohmann::ordered_json::parse(jsonAnimals.dump());
|
||||
CHECK(jsonAnimals == jsonAnimals_parsed);
|
||||
|
||||
const std::vector<std::pair<std::string, int64_t>> intData = {std::make_pair("aaaa", 11),
|
||||
std::make_pair("bbb", 222)};
|
||||
const std::vector<std::pair<std::string, int64_t>> intData = {std::make_pair("aaaa", 11), std::make_pair("bbb", 222)};
|
||||
nlohmann::ordered_json jsonObj;
|
||||
for (const auto& data : intData)
|
||||
{
|
||||
@@ -785,7 +771,8 @@ TEST_CASE("regression tests 2")
|
||||
sax_no_exception sax(j);
|
||||
|
||||
CHECK(!json::sax_parse("xyz", &sax));
|
||||
CHECK(*sax_no_exception::error_string == "[json.exception.parse_error.101] parse error at line 1, column 1: syntax error while parsing value - invalid literal; last read: 'x'");
|
||||
CHECK(*sax_no_exception::error_string ==
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 1: syntax error while parsing value - invalid literal; last read: 'x'");
|
||||
delete sax_no_exception::error_string; // NOLINT(cppcoreguidelines-owning-memory)
|
||||
}
|
||||
|
||||
@@ -856,9 +843,11 @@ TEST_CASE("regression tests 2")
|
||||
|
||||
CHECK(j.dump() == "[1,2,4]");
|
||||
|
||||
j.erase(std::remove_if(j.begin(), j.end(), [](const ordered_json& val) {
|
||||
return val == 2;
|
||||
}),
|
||||
j.erase(std::remove_if(j.begin(),
|
||||
j.end(),
|
||||
[](const ordered_json& val) {
|
||||
return val == 2;
|
||||
}),
|
||||
j.end());
|
||||
|
||||
CHECK(j.dump() == "[1,4]");
|
||||
@@ -924,9 +913,7 @@ TEST_CASE("regression tests 2")
|
||||
|
||||
SECTION("issue #3333 - Ambiguous conversion from nlohmann::basic_json<> to custom class")
|
||||
{
|
||||
const json j{
|
||||
{"x", 1},
|
||||
{"y", 2}};
|
||||
const json j{{"x", 1}, {"y", 2}};
|
||||
for_3333 p = j;
|
||||
|
||||
CHECK(p.x == 1);
|
||||
|
||||
@@ -31,8 +31,7 @@ TEST_CASE("serialization")
|
||||
std::stringstream ss;
|
||||
const json j = {"foo", 1, 2, 3, false, {{"one", 1}}};
|
||||
ss << std::setw(4) << j;
|
||||
CHECK(ss.str() ==
|
||||
"[\n \"foo\",\n 1,\n 2,\n 3,\n false,\n {\n \"one\": 1\n }\n]");
|
||||
CHECK(ss.str() == "[\n \"foo\",\n 1,\n 2,\n 3,\n false,\n {\n \"one\": 1\n }\n]");
|
||||
}
|
||||
|
||||
SECTION("given fill")
|
||||
@@ -40,8 +39,7 @@ TEST_CASE("serialization")
|
||||
std::stringstream ss;
|
||||
const json j = {"foo", 1, 2, 3, false, {{"one", 1}}};
|
||||
ss << std::setw(1) << std::setfill('\t') << j;
|
||||
CHECK(ss.str() ==
|
||||
"[\n\t\"foo\",\n\t1,\n\t2,\n\t3,\n\tfalse,\n\t{\n\t\t\"one\": 1\n\t}\n]");
|
||||
CHECK(ss.str() == "[\n\t\"foo\",\n\t1,\n\t2,\n\t3,\n\tfalse,\n\t{\n\t\t\"one\": 1\n\t}\n]");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,8 +59,7 @@ TEST_CASE("serialization")
|
||||
const json j = {"foo", 1, 2, 3, false, {{"one", 1}}};
|
||||
ss.width(4);
|
||||
j >> ss;
|
||||
CHECK(ss.str() ==
|
||||
"[\n \"foo\",\n 1,\n 2,\n 3,\n false,\n {\n \"one\": 1\n }\n]");
|
||||
CHECK(ss.str() == "[\n \"foo\",\n 1,\n 2,\n 3,\n false,\n {\n \"one\": 1\n }\n]");
|
||||
}
|
||||
|
||||
SECTION("given fill")
|
||||
@@ -72,8 +69,7 @@ TEST_CASE("serialization")
|
||||
ss.width(1);
|
||||
ss.fill('\t');
|
||||
j >> ss;
|
||||
CHECK(ss.str() ==
|
||||
"[\n\t\"foo\",\n\t1,\n\t2,\n\t3,\n\tfalse,\n\t{\n\t\t\"one\": 1\n\t}\n]");
|
||||
CHECK(ss.str() == "[\n\t\"foo\",\n\t1,\n\t2,\n\t3,\n\tfalse,\n\t{\n\t\t\"one\": 1\n\t}\n]");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -84,7 +80,9 @@ TEST_CASE("serialization")
|
||||
const json j = "ä\xA9ü";
|
||||
|
||||
CHECK_THROWS_WITH_AS(j.dump(), "[json.exception.type_error.316] invalid UTF-8 byte at index 2: 0xA9", json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j.dump(1, ' ', false, json::error_handler_t::strict), "[json.exception.type_error.316] invalid UTF-8 byte at index 2: 0xA9", json::type_error&);
|
||||
CHECK_THROWS_WITH_AS(j.dump(1, ' ', false, json::error_handler_t::strict),
|
||||
"[json.exception.type_error.316] invalid UTF-8 byte at index 2: 0xA9",
|
||||
json::type_error&);
|
||||
CHECK(j.dump(-1, ' ', false, json::error_handler_t::ignore) == "\"äü\"");
|
||||
CHECK(j.dump(-1, ' ', false, json::error_handler_t::replace) == "\"ä\xEF\xBF\xBDü\"");
|
||||
CHECK(j.dump(-1, ' ', true, json::error_handler_t::replace) == "\"\\u00e4\\ufffd\\u00fc\"");
|
||||
@@ -124,78 +122,96 @@ TEST_CASE("serialization")
|
||||
};
|
||||
|
||||
test("\xC2", "\\ufffd");
|
||||
test("\xC2\x41\x42", "\\ufffd"
|
||||
"\x41"
|
||||
"\x42");
|
||||
test("\xC2\xF4", "\\ufffd"
|
||||
"\\ufffd");
|
||||
test("\xC2\x41\x42",
|
||||
"\\ufffd"
|
||||
"\x41"
|
||||
"\x42");
|
||||
test("\xC2\xF4",
|
||||
"\\ufffd"
|
||||
"\\ufffd");
|
||||
|
||||
test("\xF0\x80\x80\x41", "\\ufffd"
|
||||
"\\ufffd"
|
||||
"\\ufffd"
|
||||
"\x41");
|
||||
test("\xF1\x80\x80\x41", "\\ufffd"
|
||||
"\x41");
|
||||
test("\xF2\x80\x80\x41", "\\ufffd"
|
||||
"\x41");
|
||||
test("\xF3\x80\x80\x41", "\\ufffd"
|
||||
"\x41");
|
||||
test("\xF4\x80\x80\x41", "\\ufffd"
|
||||
"\x41");
|
||||
test("\xF5\x80\x80\x41", "\\ufffd"
|
||||
"\\ufffd"
|
||||
"\\ufffd"
|
||||
"\x41");
|
||||
test("\xF0\x80\x80\x41",
|
||||
"\\ufffd"
|
||||
"\\ufffd"
|
||||
"\\ufffd"
|
||||
"\x41");
|
||||
test("\xF1\x80\x80\x41",
|
||||
"\\ufffd"
|
||||
"\x41");
|
||||
test("\xF2\x80\x80\x41",
|
||||
"\\ufffd"
|
||||
"\x41");
|
||||
test("\xF3\x80\x80\x41",
|
||||
"\\ufffd"
|
||||
"\x41");
|
||||
test("\xF4\x80\x80\x41",
|
||||
"\\ufffd"
|
||||
"\x41");
|
||||
test("\xF5\x80\x80\x41",
|
||||
"\\ufffd"
|
||||
"\\ufffd"
|
||||
"\\ufffd"
|
||||
"\x41");
|
||||
|
||||
test("\xF0\x90\x80\x41", "\\ufffd"
|
||||
"\x41");
|
||||
test("\xF1\x90\x80\x41", "\\ufffd"
|
||||
"\x41");
|
||||
test("\xF2\x90\x80\x41", "\\ufffd"
|
||||
"\x41");
|
||||
test("\xF3\x90\x80\x41", "\\ufffd"
|
||||
"\x41");
|
||||
test("\xF4\x90\x80\x41", "\\ufffd"
|
||||
"\\ufffd"
|
||||
"\\ufffd"
|
||||
"\x41");
|
||||
test("\xF5\x90\x80\x41", "\\ufffd"
|
||||
"\\ufffd"
|
||||
"\\ufffd"
|
||||
"\x41");
|
||||
test("\xF0\x90\x80\x41",
|
||||
"\\ufffd"
|
||||
"\x41");
|
||||
test("\xF1\x90\x80\x41",
|
||||
"\\ufffd"
|
||||
"\x41");
|
||||
test("\xF2\x90\x80\x41",
|
||||
"\\ufffd"
|
||||
"\x41");
|
||||
test("\xF3\x90\x80\x41",
|
||||
"\\ufffd"
|
||||
"\x41");
|
||||
test("\xF4\x90\x80\x41",
|
||||
"\\ufffd"
|
||||
"\\ufffd"
|
||||
"\\ufffd"
|
||||
"\x41");
|
||||
test("\xF5\x90\x80\x41",
|
||||
"\\ufffd"
|
||||
"\\ufffd"
|
||||
"\\ufffd"
|
||||
"\x41");
|
||||
|
||||
test("\xC0\xAF\xE0\x80\xBF\xF0\x81\x82\x41", "\\ufffd"
|
||||
"\\ufffd"
|
||||
"\\ufffd"
|
||||
"\\ufffd"
|
||||
"\\ufffd"
|
||||
"\\ufffd"
|
||||
"\\ufffd"
|
||||
"\\ufffd"
|
||||
"\x41");
|
||||
test("\xED\xA0\x80\xED\xBF\xBF\xED\xAF\x41", "\\ufffd"
|
||||
"\\ufffd"
|
||||
"\\ufffd"
|
||||
"\\ufffd"
|
||||
"\\ufffd"
|
||||
"\\ufffd"
|
||||
"\\ufffd"
|
||||
"\\ufffd"
|
||||
"\x41");
|
||||
test("\xF4\x91\x92\x93\xFF\x41\x80\xBF\x42", "\\ufffd"
|
||||
"\\ufffd"
|
||||
"\\ufffd"
|
||||
"\\ufffd"
|
||||
"\\ufffd"
|
||||
"\x41"
|
||||
"\\ufffd"
|
||||
"\\ufffd"
|
||||
"\x42");
|
||||
test("\xE1\x80\xE2\xF0\x91\x92\xF1\xBF\x41", "\\ufffd"
|
||||
"\\ufffd"
|
||||
"\\ufffd"
|
||||
"\\ufffd"
|
||||
"\x41");
|
||||
test("\xC0\xAF\xE0\x80\xBF\xF0\x81\x82\x41",
|
||||
"\\ufffd"
|
||||
"\\ufffd"
|
||||
"\\ufffd"
|
||||
"\\ufffd"
|
||||
"\\ufffd"
|
||||
"\\ufffd"
|
||||
"\\ufffd"
|
||||
"\\ufffd"
|
||||
"\x41");
|
||||
test("\xED\xA0\x80\xED\xBF\xBF\xED\xAF\x41",
|
||||
"\\ufffd"
|
||||
"\\ufffd"
|
||||
"\\ufffd"
|
||||
"\\ufffd"
|
||||
"\\ufffd"
|
||||
"\\ufffd"
|
||||
"\\ufffd"
|
||||
"\\ufffd"
|
||||
"\x41");
|
||||
test("\xF4\x91\x92\x93\xFF\x41\x80\xBF\x42",
|
||||
"\\ufffd"
|
||||
"\\ufffd"
|
||||
"\\ufffd"
|
||||
"\\ufffd"
|
||||
"\\ufffd"
|
||||
"\x41"
|
||||
"\\ufffd"
|
||||
"\\ufffd"
|
||||
"\x42");
|
||||
test("\xE1\x80\xE2\xF0\x91\x92\xF1\xBF\x41",
|
||||
"\\ufffd"
|
||||
"\\ufffd"
|
||||
"\\ufffd"
|
||||
"\\ufffd"
|
||||
"\x41");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+711
-749
File diff suppressed because it is too large
Load Diff
@@ -15,7 +15,8 @@
|
||||
#include <nlohmann/json.hpp>
|
||||
using nlohmann::detail::dtoa_impl::reinterpret_bits;
|
||||
|
||||
namespace {
|
||||
namespace
|
||||
{
|
||||
float make_float(uint32_t sign_bit, uint32_t biased_exponent, uint32_t significand)
|
||||
{
|
||||
assert(sign_bit == 0 || sign_bit == 1);
|
||||
@@ -60,9 +61,7 @@ float make_float(uint64_t f, int e)
|
||||
e--;
|
||||
}
|
||||
|
||||
const uint64_t biased_exponent = (e == kDenormalExponent && (f & kHiddenBit) == 0)
|
||||
? 0
|
||||
: static_cast<uint64_t>(e + kExponentBias);
|
||||
const uint64_t biased_exponent = (e == kDenormalExponent && (f & kHiddenBit) == 0) ? 0 : static_cast<uint64_t>(e + kExponentBias);
|
||||
|
||||
const uint64_t bits = (f & kSignificandMask) | (biased_exponent << kPhysicalSignificandSize);
|
||||
return reinterpret_bits<float>(static_cast<uint32_t>(bits));
|
||||
@@ -112,9 +111,7 @@ double make_double(uint64_t f, int e)
|
||||
e--;
|
||||
}
|
||||
|
||||
const uint64_t biased_exponent = (e == kDenormalExponent && (f & kHiddenBit) == 0)
|
||||
? 0
|
||||
: static_cast<uint64_t>(e + kExponentBias);
|
||||
const uint64_t biased_exponent = (e == kDenormalExponent && (f & kHiddenBit) == 0) ? 0 : static_cast<uint64_t>(e + kExponentBias);
|
||||
|
||||
const uint64_t bits = (f & kSignificandMask) | (biased_exponent << kPhysicalSignificandSize);
|
||||
return reinterpret_bits<double>(bits);
|
||||
|
||||
+266
-470
File diff suppressed because it is too large
Load Diff
+33
-44
@@ -23,7 +23,8 @@ using namespace nlohmann::literals; // NOLINT(google-build-using-namespace)
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
namespace udt {
|
||||
namespace udt
|
||||
{
|
||||
enum class country
|
||||
{
|
||||
china,
|
||||
@@ -92,7 +93,8 @@ struct contact_book
|
||||
} // namespace udt
|
||||
|
||||
// to_json methods
|
||||
namespace udt {
|
||||
namespace udt
|
||||
{
|
||||
// templates because of the custom_json tests (see below)
|
||||
template<typename BasicJsonType>
|
||||
static void to_json(BasicJsonType& j, age a)
|
||||
@@ -169,19 +171,18 @@ static bool operator==(const person& lhs, const person& rhs)
|
||||
|
||||
static bool operator==(const contact& lhs, const contact& rhs)
|
||||
{
|
||||
return std::tie(lhs.m_person, lhs.m_address) ==
|
||||
std::tie(rhs.m_person, rhs.m_address);
|
||||
return std::tie(lhs.m_person, lhs.m_address) == std::tie(rhs.m_person, rhs.m_address);
|
||||
}
|
||||
|
||||
static bool operator==(const contact_book& lhs, const contact_book& rhs)
|
||||
{
|
||||
return std::tie(lhs.m_book_name, lhs.m_contacts) ==
|
||||
std::tie(rhs.m_book_name, rhs.m_contacts);
|
||||
return std::tie(lhs.m_book_name, lhs.m_contacts) == std::tie(rhs.m_book_name, rhs.m_contacts);
|
||||
}
|
||||
} // namespace udt
|
||||
|
||||
// from_json methods
|
||||
namespace udt {
|
||||
namespace udt
|
||||
{
|
||||
template<typename BasicJsonType>
|
||||
static void from_json(const BasicJsonType& j, age& a)
|
||||
{
|
||||
@@ -198,11 +199,7 @@ template<typename BasicJsonType>
|
||||
static void from_json(const BasicJsonType& j, country& c)
|
||||
{
|
||||
const auto str = j.template get<std::string>();
|
||||
const std::map<std::string, country> m =
|
||||
{
|
||||
{"中华人民共和国", country::china},
|
||||
{"France", country::france},
|
||||
{"Российская Федерация", country::russia}};
|
||||
const std::map<std::string, country> m = {{"中华人民共和国", country::china}, {"France", country::france}, {"Российская Федерация", country::russia}};
|
||||
|
||||
const auto it = m.find(str);
|
||||
// TODO(nlohmann) test exceptions
|
||||
@@ -238,8 +235,7 @@ static void from_json(const nlohmann::json& j, contact_book& cb)
|
||||
TEST_CASE("basic usage" * doctest::test_suite("udt"))
|
||||
{
|
||||
// a bit narcissistic maybe :) ?
|
||||
const udt::age a{
|
||||
23};
|
||||
const udt::age a{23};
|
||||
const udt::name n{"theo"};
|
||||
const udt::country c{udt::country::france};
|
||||
const udt::person sfinae_addict{a, n, c};
|
||||
@@ -255,8 +251,7 @@ TEST_CASE("basic usage" * doctest::test_suite("udt"))
|
||||
CHECK(json(c) == json("France"));
|
||||
CHECK(json(sfinae_addict) == R"({"name":"theo", "age":23, "country":"France"})"_json);
|
||||
CHECK(json("Paris") == json(addr));
|
||||
CHECK(json(cpp_programmer) ==
|
||||
R"({"person" : {"age":23, "name":"theo", "country":"France"}, "address":"Paris"})"_json);
|
||||
CHECK(json(cpp_programmer) == R"({"person" : {"age":23, "name":"theo", "country":"France"}, "address":"Paris"})"_json);
|
||||
|
||||
CHECK(
|
||||
json(book) ==
|
||||
@@ -271,15 +266,13 @@ TEST_CASE("basic usage" * doctest::test_suite("udt"))
|
||||
{
|
||||
const auto parsed_book = big_json.get<udt::contact_book>();
|
||||
const auto book_name = big_json["name"].get<udt::name>();
|
||||
const auto contacts =
|
||||
big_json["contacts"].get<std::vector<udt::contact>>();
|
||||
const auto contacts = big_json["contacts"].get<std::vector<udt::contact>>();
|
||||
const auto contact_json = big_json["contacts"].at(0);
|
||||
const auto contact = contact_json.get<udt::contact>();
|
||||
const auto person = contact_json["person"].get<udt::person>();
|
||||
const auto address = contact_json["address"].get<udt::address>();
|
||||
const auto age = contact_json["person"]["age"].get<udt::age>();
|
||||
const auto country =
|
||||
contact_json["person"]["country"].get<udt::country>();
|
||||
const auto country = contact_json["person"]["country"].get<udt::country>();
|
||||
const auto name = contact_json["person"]["name"].get<udt::name>();
|
||||
|
||||
CHECK(age == a);
|
||||
@@ -334,7 +327,8 @@ TEST_CASE("basic usage" * doctest::test_suite("udt"))
|
||||
}
|
||||
}
|
||||
|
||||
namespace udt {
|
||||
namespace udt
|
||||
{
|
||||
struct legacy_type
|
||||
{
|
||||
std::string number{};
|
||||
@@ -345,7 +339,8 @@ struct legacy_type
|
||||
};
|
||||
} // namespace udt
|
||||
|
||||
namespace nlohmann {
|
||||
namespace nlohmann
|
||||
{
|
||||
template<typename T>
|
||||
struct adl_serializer<std::shared_ptr<T>>
|
||||
{
|
||||
@@ -441,7 +436,8 @@ TEST_CASE("adl_serializer specialization" * doctest::test_suite("udt"))
|
||||
}
|
||||
}
|
||||
|
||||
namespace nlohmann {
|
||||
namespace nlohmann
|
||||
{
|
||||
template<>
|
||||
struct adl_serializer<std::vector<float>>
|
||||
{
|
||||
@@ -473,7 +469,8 @@ TEST_CASE("even supported types can be specialized" * doctest::test_suite("udt")
|
||||
CHECK((f == std::vector<float>{4.0, 5.0, 6.0}));
|
||||
}
|
||||
|
||||
namespace nlohmann {
|
||||
namespace nlohmann
|
||||
{
|
||||
template<typename T>
|
||||
struct adl_serializer<std::unique_ptr<T>>
|
||||
{
|
||||
@@ -540,12 +537,7 @@ template<typename T, typename = void>
|
||||
struct pod_serializer
|
||||
{
|
||||
// use adl for non-pods, or scalar types
|
||||
template<
|
||||
typename BasicJsonType,
|
||||
typename U = T,
|
||||
typename std::enable_if<
|
||||
!(std::is_pod<U>::value && std::is_class<U>::value),
|
||||
int>::type = 0>
|
||||
template<typename BasicJsonType, typename U = T, typename std::enable_if<!(std::is_pod<U>::value && std::is_class<U>::value), int>::type = 0>
|
||||
static void from_json(const BasicJsonType& j, U& t)
|
||||
{
|
||||
using nlohmann::from_json;
|
||||
@@ -576,12 +568,7 @@ struct pod_serializer
|
||||
std::memcpy(&t, bytes, sizeof(value));
|
||||
}
|
||||
|
||||
template<
|
||||
typename BasicJsonType,
|
||||
typename U = T,
|
||||
typename std::enable_if<
|
||||
!(std::is_pod<U>::value && std::is_class<U>::value),
|
||||
int>::type = 0>
|
||||
template<typename BasicJsonType, typename U = T, typename std::enable_if<!(std::is_pod<U>::value && std::is_class<U>::value), int>::type = 0>
|
||||
static void to_json(BasicJsonType& j, const T& t)
|
||||
{
|
||||
using nlohmann::to_json;
|
||||
@@ -598,7 +585,8 @@ struct pod_serializer
|
||||
}
|
||||
};
|
||||
|
||||
namespace udt {
|
||||
namespace udt
|
||||
{
|
||||
struct small_pod
|
||||
{
|
||||
int begin;
|
||||
@@ -629,8 +617,7 @@ static void from_json(const BasicJsonType& j, non_pod& np)
|
||||
|
||||
static bool operator==(small_pod lhs, small_pod rhs) noexcept
|
||||
{
|
||||
return std::tie(lhs.begin, lhs.middle, lhs.end) ==
|
||||
std::tie(rhs.begin, rhs.middle, rhs.end);
|
||||
return std::tie(lhs.begin, lhs.middle, lhs.end) == std::tie(rhs.begin, rhs.middle, rhs.end);
|
||||
}
|
||||
|
||||
static bool operator==(const non_pod& lhs, const non_pod& rhs) noexcept
|
||||
@@ -646,8 +633,7 @@ static std::ostream& operator<<(std::ostream& os, small_pod l)
|
||||
|
||||
TEST_CASE("custom serializer for pods" * doctest::test_suite("udt"))
|
||||
{
|
||||
using custom_json =
|
||||
nlohmann::basic_json<std::map, std::vector, std::string, bool, std::int64_t, std::uint64_t, double, std::allocator, pod_serializer>;
|
||||
using custom_json = nlohmann::basic_json<std::map, std::vector, std::string, bool, std::int64_t, std::uint64_t, double, std::allocator, pod_serializer>;
|
||||
|
||||
auto p = udt::small_pod{42, '/', 42};
|
||||
custom_json const j = p;
|
||||
@@ -781,7 +767,8 @@ TEST_CASE("different basic_json types conversions")
|
||||
}
|
||||
}
|
||||
|
||||
namespace {
|
||||
namespace
|
||||
{
|
||||
struct incomplete;
|
||||
|
||||
// std::is_constructible is broken on macOS' libc++
|
||||
@@ -801,7 +788,8 @@ TEST_CASE("an incomplete type does not trigger a compiler error in non-evaluated
|
||||
static_assert(!is_constructible_patched<json, incomplete>::value, "");
|
||||
}
|
||||
|
||||
namespace {
|
||||
namespace
|
||||
{
|
||||
class Evil
|
||||
{
|
||||
public:
|
||||
@@ -839,7 +827,8 @@ TEST_CASE("Issue #1237")
|
||||
static_assert(!std::is_convertible<json, non_convertible_type>::value, "");
|
||||
}
|
||||
|
||||
namespace {
|
||||
namespace
|
||||
{
|
||||
class no_iterator_type
|
||||
{
|
||||
public:
|
||||
|
||||
@@ -13,7 +13,8 @@
|
||||
#include <nlohmann/json.hpp>
|
||||
using nlohmann::json;
|
||||
|
||||
namespace persons {
|
||||
namespace persons
|
||||
{
|
||||
class person_with_private_data
|
||||
{
|
||||
private:
|
||||
@@ -157,32 +158,9 @@ class person_with_private_alphabet
|
||||
public:
|
||||
bool operator==(const person_with_private_alphabet& other) const
|
||||
{
|
||||
return a == other.a &&
|
||||
b == other.b &&
|
||||
c == other.c &&
|
||||
d == other.d &&
|
||||
e == other.e &&
|
||||
f == other.f &&
|
||||
g == other.g &&
|
||||
h == other.h &&
|
||||
i == other.i &&
|
||||
j == other.j &&
|
||||
k == other.k &&
|
||||
l == other.l &&
|
||||
m == other.m &&
|
||||
n == other.n &&
|
||||
o == other.o &&
|
||||
p == other.p &&
|
||||
q == other.q &&
|
||||
r == other.r &&
|
||||
s == other.s &&
|
||||
t == other.t &&
|
||||
u == other.u &&
|
||||
v == other.v &&
|
||||
w == other.w &&
|
||||
x == other.x &&
|
||||
y == other.y &&
|
||||
z == other.z;
|
||||
return a == other.a && b == other.b && c == other.c && d == other.d && e == other.e && f == other.f && g == other.g && h == other.h && i == other.i &&
|
||||
j == other.j && k == other.k && l == other.l && m == other.m && n == other.n && o == other.o && p == other.p && q == other.q && r == other.r &&
|
||||
s == other.s && t == other.t && u == other.u && v == other.v && w == other.w && x == other.x && y == other.y && z == other.z;
|
||||
}
|
||||
|
||||
private:
|
||||
@@ -220,32 +198,9 @@ class person_with_public_alphabet
|
||||
public:
|
||||
bool operator==(const person_with_public_alphabet& other) const
|
||||
{
|
||||
return a == other.a &&
|
||||
b == other.b &&
|
||||
c == other.c &&
|
||||
d == other.d &&
|
||||
e == other.e &&
|
||||
f == other.f &&
|
||||
g == other.g &&
|
||||
h == other.h &&
|
||||
i == other.i &&
|
||||
j == other.j &&
|
||||
k == other.k &&
|
||||
l == other.l &&
|
||||
m == other.m &&
|
||||
n == other.n &&
|
||||
o == other.o &&
|
||||
p == other.p &&
|
||||
q == other.q &&
|
||||
r == other.r &&
|
||||
s == other.s &&
|
||||
t == other.t &&
|
||||
u == other.u &&
|
||||
v == other.v &&
|
||||
w == other.w &&
|
||||
x == other.x &&
|
||||
y == other.y &&
|
||||
z == other.z;
|
||||
return a == other.a && b == other.b && c == other.c && d == other.d && e == other.e && f == other.f && g == other.g && h == other.h && i == other.i &&
|
||||
j == other.j && k == other.k && l == other.l && m == other.m && n == other.n && o == other.o && p == other.p && q == other.q && r == other.r &&
|
||||
s == other.s && t == other.t && u == other.u && v == other.v && w == other.w && x == other.x && y == other.y && z == other.z;
|
||||
}
|
||||
|
||||
int a = 0;
|
||||
@@ -318,7 +273,11 @@ NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_ONLY_SERIALIZE(person_without_default_constru
|
||||
|
||||
} // namespace persons
|
||||
|
||||
TEST_CASE_TEMPLATE("Serialization/deserialization via NLOHMANN_DEFINE_TYPE_INTRUSIVE and NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE", T, persons::person_with_private_data, persons::person_without_private_data_1, persons::person_without_private_data_2)
|
||||
TEST_CASE_TEMPLATE("Serialization/deserialization via NLOHMANN_DEFINE_TYPE_INTRUSIVE and NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE",
|
||||
T,
|
||||
persons::person_with_private_data,
|
||||
persons::person_without_private_data_1,
|
||||
persons::person_without_private_data_2)
|
||||
{
|
||||
SECTION("person")
|
||||
{
|
||||
@@ -341,7 +300,10 @@ TEST_CASE_TEMPLATE("Serialization/deserialization via NLOHMANN_DEFINE_TYPE_INTRU
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE_TEMPLATE("Serialization/deserialization via NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT and NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT", T, persons::person_with_private_data_2, persons::person_without_private_data_3)
|
||||
TEST_CASE_TEMPLATE("Serialization/deserialization via NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT and NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT",
|
||||
T,
|
||||
persons::person_with_private_data_2,
|
||||
persons::person_without_private_data_3)
|
||||
{
|
||||
SECTION("person with default values")
|
||||
{
|
||||
@@ -373,7 +335,11 @@ TEST_CASE_TEMPLATE("Serialization/deserialization via NLOHMANN_DEFINE_TYPE_INTRU
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE_TEMPLATE("Serialization/deserialization of classes with 26 public/private member variables via NLOHMANN_DEFINE_TYPE_INTRUSIVE and NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE", T, persons::person_with_private_alphabet, persons::person_with_public_alphabet)
|
||||
TEST_CASE_TEMPLATE(
|
||||
"Serialization/deserialization of classes with 26 public/private member variables via NLOHMANN_DEFINE_TYPE_INTRUSIVE and NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE",
|
||||
T,
|
||||
persons::person_with_private_alphabet,
|
||||
persons::person_with_public_alphabet)
|
||||
{
|
||||
SECTION("alphabet")
|
||||
{
|
||||
@@ -443,7 +409,11 @@ TEST_CASE_TEMPLATE("Serialization/deserialization of classes with 26 public/priv
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE_TEMPLATE("Serialization of non-default-constructible classes via NLOHMANN_DEFINE_TYPE_INTRUSIVE_ONLY_SERIALIZE and NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_ONLY_SERIALIZE", T, persons::person_without_default_constructor_1, persons::person_without_default_constructor_2)
|
||||
TEST_CASE_TEMPLATE(
|
||||
"Serialization of non-default-constructible classes via NLOHMANN_DEFINE_TYPE_INTRUSIVE_ONLY_SERIALIZE and NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_ONLY_SERIALIZE",
|
||||
T,
|
||||
persons::person_without_default_constructor_1,
|
||||
persons::person_without_default_constructor_2)
|
||||
{
|
||||
SECTION("person")
|
||||
{
|
||||
@@ -453,9 +423,7 @@ TEST_CASE_TEMPLATE("Serialization of non-default-constructible classes via NLOHM
|
||||
CHECK(json(person).dump() == "{\"age\":1,\"name\":\"Erik\"}");
|
||||
|
||||
// serialization of a container with objects
|
||||
std::vector<T> const two_persons{
|
||||
{"Erik", 1},
|
||||
{"Kyle", 2}};
|
||||
std::vector<T> const two_persons{{"Erik", 1}, {"Kyle", 2}};
|
||||
CHECK(json(two_persons).dump() == "[{\"age\":1,\"name\":\"Erik\"},{\"age\":2,\"name\":\"Kyle\"}]");
|
||||
}
|
||||
}
|
||||
|
||||
+36
-10
@@ -85,19 +85,40 @@ TEST_CASE("Unicode (1/5)" * doctest::skip())
|
||||
{
|
||||
json _;
|
||||
|
||||
CHECK_THROWS_WITH_AS(_ = json::parse("\"\\uDC00\\uDC00\""), "[json.exception.parse_error.101] parse error at line 1, column 7: syntax error while parsing value - invalid string: surrogate U+DC00..U+DFFF must follow U+D800..U+DBFF; last read: '\"\\uDC00'", json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
_ = json::parse("\"\\uDC00\\uDC00\""),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 7: syntax error while parsing value - invalid string: surrogate U+DC00..U+DFFF must follow U+D800..U+DBFF; last read: '\"\\uDC00'",
|
||||
json::parse_error&);
|
||||
|
||||
CHECK_THROWS_WITH_AS(_ = json::parse("\"\\uD7FF\\uDC00\""), "[json.exception.parse_error.101] parse error at line 1, column 13: syntax error while parsing value - invalid string: surrogate U+DC00..U+DFFF must follow U+D800..U+DBFF; last read: '\"\\uD7FF\\uDC00'", json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
_ = json::parse("\"\\uD7FF\\uDC00\""),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 13: syntax error while parsing value - invalid string: surrogate U+DC00..U+DFFF must follow U+D800..U+DBFF; last read: '\"\\uD7FF\\uDC00'",
|
||||
json::parse_error&);
|
||||
|
||||
CHECK_THROWS_WITH_AS(_ = json::parse("\"\\uD800]\""), "[json.exception.parse_error.101] parse error at line 1, column 8: syntax error while parsing value - invalid string: surrogate U+D800..U+DBFF must be followed by U+DC00..U+DFFF; last read: '\"\\uD800]'", json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
_ = json::parse("\"\\uD800]\""),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 8: syntax error while parsing value - invalid string: surrogate U+D800..U+DBFF must be followed by U+DC00..U+DFFF; last read: '\"\\uD800]'",
|
||||
json::parse_error&);
|
||||
|
||||
CHECK_THROWS_WITH_AS(_ = json::parse("\"\\uD800\\v\""), "[json.exception.parse_error.101] parse error at line 1, column 9: syntax error while parsing value - invalid string: surrogate U+D800..U+DBFF must be followed by U+DC00..U+DFFF; last read: '\"\\uD800\\v'", json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
_ = json::parse("\"\\uD800\\v\""),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 9: syntax error while parsing value - invalid string: surrogate U+D800..U+DBFF must be followed by U+DC00..U+DFFF; last read: '\"\\uD800\\v'",
|
||||
json::parse_error&);
|
||||
|
||||
CHECK_THROWS_WITH_AS(_ = json::parse("\"\\uD800\\u123\""), "[json.exception.parse_error.101] parse error at line 1, column 13: syntax error while parsing value - invalid string: '\\u' must be followed by 4 hex digits; last read: '\"\\uD800\\u123\"'", json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
_ = json::parse("\"\\uD800\\u123\""),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 13: syntax error while parsing value - invalid string: '\\u' must be followed by 4 hex digits; last read: '\"\\uD800\\u123\"'",
|
||||
json::parse_error&);
|
||||
|
||||
CHECK_THROWS_WITH_AS(_ = json::parse("\"\\uD800\\uDBFF\""), "[json.exception.parse_error.101] parse error at line 1, column 13: syntax error while parsing value - invalid string: surrogate U+D800..U+DBFF must be followed by U+DC00..U+DFFF; last read: '\"\\uD800\\uDBFF'", json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
_ = json::parse("\"\\uD800\\uDBFF\""),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 13: syntax error while parsing value - invalid string: surrogate U+D800..U+DBFF must be followed by U+DC00..U+DFFF; last read: '\"\\uD800\\uDBFF'",
|
||||
json::parse_error&);
|
||||
|
||||
CHECK_THROWS_WITH_AS(_ = json::parse("\"\\uD800\\uE000\""), "[json.exception.parse_error.101] parse error at line 1, column 13: syntax error while parsing value - invalid string: surrogate U+D800..U+DBFF must be followed by U+DC00..U+DFFF; last read: '\"\\uD800\\uE000'", json::parse_error&);
|
||||
CHECK_THROWS_WITH_AS(
|
||||
_ = json::parse("\"\\uD800\\uE000\""),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 13: syntax error while parsing value - invalid string: surrogate U+D800..U+DBFF must be followed by U+DC00..U+DFFF; last read: '\"\\uD800\\uE000'",
|
||||
json::parse_error&);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -222,7 +243,8 @@ TEST_CASE("Unicode (1/5)" * doctest::skip())
|
||||
}
|
||||
}
|
||||
|
||||
namespace {
|
||||
namespace
|
||||
{
|
||||
void roundtrip(bool success_expected, const std::string& s);
|
||||
|
||||
void roundtrip(bool success_expected, const std::string& s)
|
||||
@@ -353,13 +375,17 @@ TEST_CASE("Markus Kuhn's UTF-8 decoder capability and stress test")
|
||||
roundtrip(false, "\x80\xbf\x80\xbf\x80\xbf\x80");
|
||||
|
||||
// 3.1.9 Sequence of all 64 possible continuation bytes (0x80-0xbf)
|
||||
roundtrip(false, "\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf\xb0\xb1\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba\xbb\xbc\xbd\xbe\xbf");
|
||||
roundtrip(
|
||||
false,
|
||||
"\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf\xb0\xb1\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba\xbb\xbc\xbd\xbe\xbf");
|
||||
}
|
||||
|
||||
SECTION("3.2 Lonely start characters")
|
||||
{
|
||||
// 3.2.1 All 32 first bytes of 2-byte sequences (0xc0-0xdf)
|
||||
roundtrip(false, "\xc0 \xc1 \xc2 \xc3 \xc4 \xc5 \xc6 \xc7 \xc8 \xc9 \xca \xcb \xcc \xcd \xce \xcf \xd0 \xd1 \xd2 \xd3 \xd4 \xd5 \xd6 \xd7 \xd8 \xd9 \xda \xdb \xdc \xdd \xde \xdf");
|
||||
roundtrip(
|
||||
false,
|
||||
"\xc0 \xc1 \xc2 \xc3 \xc4 \xc5 \xc6 \xc7 \xc8 \xc9 \xca \xcb \xcc \xcd \xce \xcf \xd0 \xd1 \xd2 \xd3 \xd4 \xd5 \xd6 \xd7 \xd8 \xd9 \xda \xdb \xdc \xdd \xde \xdf");
|
||||
// 3.2.2 All 16 first bytes of 3-byte sequences (0xe0-0xef)
|
||||
roundtrip(false, "\xe0 \xe1 \xe2 \xe3 \xe4 \xe5 \xe6 \xe7 \xe8 \xe9 \xea \xeb \xec \xed \xee \xef");
|
||||
// 3.2.3 All 8 first bytes of 4-byte sequences (0xf0-0xf7)
|
||||
|
||||
@@ -24,7 +24,8 @@ using nlohmann::json;
|
||||
DOCTEST_CLANG_SUPPRESS_WARNING_PUSH
|
||||
DOCTEST_CLANG_SUPPRESS_WARNING("-Wexit-time-destructors")
|
||||
|
||||
namespace {
|
||||
namespace
|
||||
{
|
||||
extern size_t calls;
|
||||
size_t calls = 0;
|
||||
|
||||
|
||||
@@ -24,7 +24,8 @@ using nlohmann::json;
|
||||
DOCTEST_CLANG_SUPPRESS_WARNING_PUSH
|
||||
DOCTEST_CLANG_SUPPRESS_WARNING("-Wexit-time-destructors")
|
||||
|
||||
namespace {
|
||||
namespace
|
||||
{
|
||||
extern size_t calls;
|
||||
size_t calls = 0;
|
||||
|
||||
|
||||
@@ -24,7 +24,8 @@ using nlohmann::json;
|
||||
DOCTEST_CLANG_SUPPRESS_WARNING_PUSH
|
||||
DOCTEST_CLANG_SUPPRESS_WARNING("-Wexit-time-destructors")
|
||||
|
||||
namespace {
|
||||
namespace
|
||||
{
|
||||
extern size_t calls;
|
||||
size_t calls = 0;
|
||||
|
||||
|
||||
@@ -24,7 +24,8 @@ using nlohmann::json;
|
||||
DOCTEST_CLANG_SUPPRESS_WARNING_PUSH
|
||||
DOCTEST_CLANG_SUPPRESS_WARNING("-Wexit-time-destructors")
|
||||
|
||||
namespace {
|
||||
namespace
|
||||
{
|
||||
extern size_t calls;
|
||||
size_t calls = 0;
|
||||
|
||||
|
||||
@@ -13,7 +13,8 @@ using nlohmann::json;
|
||||
|
||||
#include <list>
|
||||
|
||||
namespace {
|
||||
namespace
|
||||
{
|
||||
TEST_CASE("Use arbitrary stdlib container")
|
||||
{
|
||||
std::string raw_data = "[1,2,3,4]";
|
||||
|
||||
@@ -13,7 +13,8 @@ using nlohmann::json;
|
||||
|
||||
// ICPC errors out on multibyte character sequences in source files
|
||||
#ifndef __INTEL_COMPILER
|
||||
namespace {
|
||||
namespace
|
||||
{
|
||||
bool wstring_is_utf16();
|
||||
bool wstring_is_utf16()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user