🚨 fix warnings
This commit is contained in:
parent
eba434a95a
commit
2d175d94e7
@ -43,7 +43,7 @@ TEST_CASE("algorithms")
|
||||
{
|
||||
CHECK(std::all_of(j_array.begin(), j_array.end(), [](const json & value)
|
||||
{
|
||||
return value.size() > 0;
|
||||
return !value.empty();
|
||||
}));
|
||||
CHECK(std::all_of(j_object.begin(), j_object.end(), [](const json & value)
|
||||
{
|
||||
@ -67,7 +67,7 @@ TEST_CASE("algorithms")
|
||||
{
|
||||
CHECK(std::none_of(j_array.begin(), j_array.end(), [](const json & value)
|
||||
{
|
||||
return value.size() == 0;
|
||||
return value.empty();
|
||||
}));
|
||||
CHECK(std::none_of(j_object.begin(), j_object.end(), [](const json & value)
|
||||
{
|
||||
|
||||
@ -40,12 +40,12 @@ template<class T>
|
||||
struct bad_allocator : std::allocator<T>
|
||||
{
|
||||
template<class... Args>
|
||||
void construct(T*, Args&& ...)
|
||||
void construct(T* /*unused*/, Args&& ... /*unused*/)
|
||||
{
|
||||
throw std::bad_alloc();
|
||||
}
|
||||
};
|
||||
}
|
||||
} // namespace
|
||||
|
||||
TEST_CASE("bad_alloc")
|
||||
{
|
||||
@ -85,10 +85,8 @@ struct my_allocator : std::allocator<T>
|
||||
next_construct_fails = false;
|
||||
throw std::bad_alloc();
|
||||
}
|
||||
else
|
||||
{
|
||||
::new (reinterpret_cast<void*>(p)) T(std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
::new (reinterpret_cast<void*>(p)) T(std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
void deallocate(T* p, std::size_t n)
|
||||
@ -98,10 +96,8 @@ struct my_allocator : std::allocator<T>
|
||||
next_deallocate_fails = false;
|
||||
throw std::bad_alloc();
|
||||
}
|
||||
else
|
||||
{
|
||||
std::allocator<T>::deallocate(p, n);
|
||||
}
|
||||
|
||||
std::allocator<T>::deallocate(p, n);
|
||||
}
|
||||
|
||||
void destroy(T* p)
|
||||
@ -111,10 +107,8 @@ struct my_allocator : std::allocator<T>
|
||||
next_destroy_fails = false;
|
||||
throw std::bad_alloc();
|
||||
}
|
||||
else
|
||||
{
|
||||
p->~T();
|
||||
}
|
||||
|
||||
p->~T();
|
||||
}
|
||||
|
||||
template <class U>
|
||||
@ -133,7 +127,7 @@ void my_allocator_clean_up(T* p)
|
||||
alloc.destroy(p);
|
||||
alloc.deallocate(p, 1);
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
TEST_CASE("controlled bad_alloc")
|
||||
{
|
||||
@ -239,7 +233,7 @@ namespace
|
||||
template<class T>
|
||||
struct allocator_no_forward : std::allocator<T>
|
||||
{
|
||||
allocator_no_forward() {}
|
||||
allocator_no_forward() = default;
|
||||
template <class U>
|
||||
allocator_no_forward(allocator_no_forward<U>) {}
|
||||
|
||||
@ -256,7 +250,7 @@ struct allocator_no_forward : std::allocator<T>
|
||||
::new (static_cast<void*>(p)) T(args...);
|
||||
}
|
||||
};
|
||||
}
|
||||
} // namespace
|
||||
|
||||
TEST_CASE("bad my_allocator::construct")
|
||||
{
|
||||
|
||||
@ -219,7 +219,7 @@ TEST_CASE("CBOR")
|
||||
// create expected byte vector
|
||||
std::vector<uint8_t> expected;
|
||||
expected.push_back(static_cast<uint8_t>(0x3b));
|
||||
uint64_t positive = static_cast<uint64_t>(-1 - i);
|
||||
auto positive = static_cast<uint64_t>(-1 - i);
|
||||
expected.push_back(static_cast<uint8_t>((positive >> 56) & 0xff));
|
||||
expected.push_back(static_cast<uint8_t>((positive >> 48) & 0xff));
|
||||
expected.push_back(static_cast<uint8_t>((positive >> 40) & 0xff));
|
||||
@ -276,7 +276,7 @@ TEST_CASE("CBOR")
|
||||
// create expected byte vector
|
||||
std::vector<uint8_t> expected;
|
||||
expected.push_back(static_cast<uint8_t>(0x3a));
|
||||
uint32_t positive = static_cast<uint32_t>(static_cast<uint64_t>(-1 - i) & 0x00000000ffffffff);
|
||||
auto positive = static_cast<uint32_t>(static_cast<uint64_t>(-1 - i) & 0x00000000ffffffff);
|
||||
expected.push_back(static_cast<uint8_t>((positive >> 24) & 0xff));
|
||||
expected.push_back(static_cast<uint8_t>((positive >> 16) & 0xff));
|
||||
expected.push_back(static_cast<uint8_t>((positive >> 8) & 0xff));
|
||||
@ -317,7 +317,7 @@ TEST_CASE("CBOR")
|
||||
// create expected byte vector
|
||||
std::vector<uint8_t> expected;
|
||||
expected.push_back(static_cast<uint8_t>(0x39));
|
||||
uint16_t positive = static_cast<uint16_t>(-1 - i);
|
||||
auto positive = static_cast<uint16_t>(-1 - i);
|
||||
expected.push_back(static_cast<uint8_t>((positive >> 8) & 0xff));
|
||||
expected.push_back(static_cast<uint8_t>(positive & 0xff));
|
||||
|
||||
@ -328,7 +328,7 @@ TEST_CASE("CBOR")
|
||||
|
||||
// check individual bytes
|
||||
CHECK(result[0] == 0x39);
|
||||
uint16_t restored = static_cast<uint16_t>(static_cast<uint8_t>(result[1]) * 256 + static_cast<uint8_t>(result[2]));
|
||||
auto restored = static_cast<uint16_t>(static_cast<uint8_t>(result[1]) * 256 + static_cast<uint8_t>(result[2]));
|
||||
CHECK(restored == positive);
|
||||
CHECK(-1 - restored == i);
|
||||
|
||||
@ -346,7 +346,7 @@ TEST_CASE("CBOR")
|
||||
const auto result = json::to_cbor(j);
|
||||
CHECK(result == expected);
|
||||
|
||||
int16_t restored = static_cast<int16_t>(-1 - ((result[1] << 8) + result[2]));
|
||||
auto restored = static_cast<int16_t>(-1 - ((result[1] << 8) + result[2]));
|
||||
CHECK(restored == -9263);
|
||||
|
||||
// roundtrip
|
||||
@ -506,7 +506,7 @@ TEST_CASE("CBOR")
|
||||
|
||||
// check individual bytes
|
||||
CHECK(result[0] == 0x19);
|
||||
uint16_t restored = static_cast<uint16_t>(static_cast<uint8_t>(result[1]) * 256 + static_cast<uint8_t>(result[2]));
|
||||
auto restored = static_cast<uint16_t>(static_cast<uint8_t>(result[1]) * 256 + static_cast<uint8_t>(result[2]));
|
||||
CHECK(restored == i);
|
||||
|
||||
// roundtrip
|
||||
@ -634,7 +634,7 @@ TEST_CASE("CBOR")
|
||||
|
||||
// check individual bytes
|
||||
CHECK(result[0] == 0xd1);
|
||||
int16_t restored = static_cast<int16_t>((result[1] << 8) + result[2]);
|
||||
auto restored = static_cast<int16_t>((result[1] << 8) + result[2]);
|
||||
CHECK(restored == i);
|
||||
|
||||
// roundtrip
|
||||
@ -699,7 +699,7 @@ TEST_CASE("CBOR")
|
||||
|
||||
// check individual bytes
|
||||
CHECK(result[0] == 0x18);
|
||||
uint8_t restored = static_cast<uint8_t>(result[1]);
|
||||
auto restored = static_cast<uint8_t>(result[1]);
|
||||
CHECK(restored == i);
|
||||
|
||||
// roundtrip
|
||||
@ -733,7 +733,7 @@ TEST_CASE("CBOR")
|
||||
|
||||
// check individual bytes
|
||||
CHECK(result[0] == 0x19);
|
||||
uint16_t restored = static_cast<uint16_t>(static_cast<uint8_t>(result[1]) * 256 + static_cast<uint8_t>(result[2]));
|
||||
auto restored = static_cast<uint16_t>(static_cast<uint8_t>(result[1]) * 256 + static_cast<uint8_t>(result[2]));
|
||||
CHECK(restored == i);
|
||||
|
||||
// roundtrip
|
||||
@ -940,7 +940,7 @@ TEST_CASE("CBOR")
|
||||
}
|
||||
SECTION("-3.40282e+38(lowest float)")
|
||||
{
|
||||
double v = static_cast<double>(std::numeric_limits<float>::lowest());
|
||||
auto v = static_cast<double>(std::numeric_limits<float>::lowest());
|
||||
json j = v;
|
||||
std::vector<uint8_t> expected =
|
||||
{
|
||||
@ -1340,7 +1340,7 @@ TEST_CASE("CBOR")
|
||||
|
||||
SECTION("{\"a\": {\"b\": {\"c\": {}}}}")
|
||||
{
|
||||
json j = json::parse("{\"a\": {\"b\": {\"c\": {}}}}");
|
||||
json j = json::parse(R"({"a": {"b": {"c": {}}}})");
|
||||
std::vector<uint8_t> expected =
|
||||
{
|
||||
0xa1, 0x61, 0x61, 0xa1, 0x61, 0x62, 0xa1, 0x61, 0x63, 0xa0
|
||||
@ -2249,7 +2249,7 @@ TEST_CASE("CBOR roundtrips" * doctest::skip())
|
||||
// parse CBOR file
|
||||
auto packed = utils::read_binary_file(filename + ".cbor");
|
||||
|
||||
if (!exclude_packed.count(filename))
|
||||
if (exclude_packed.count(filename) == 0u)
|
||||
{
|
||||
{
|
||||
INFO_WITH_TEMP(filename + ": output adapters: std::vector<uint8_t>");
|
||||
@ -2323,7 +2323,7 @@ TEST_CASE("all CBOR first bytes")
|
||||
// check that parse_error.112 is only thrown if the
|
||||
// first byte is in the unsupported set
|
||||
INFO_WITH_TEMP(e.what());
|
||||
if (std::find(unsupported.begin(), unsupported.end(), byte) != unsupported.end())
|
||||
if (unsupported.find(byte) != unsupported.end())
|
||||
{
|
||||
CHECK(e.id == 112);
|
||||
}
|
||||
|
||||
@ -36,15 +36,15 @@ using nlohmann::json;
|
||||
namespace
|
||||
{
|
||||
// shortcut to scan a string literal
|
||||
json::lexer::token_type scan_string(const char* s, const bool ignore_comments = false);
|
||||
json::lexer::token_type scan_string(const char* s, bool ignore_comments = false);
|
||||
json::lexer::token_type scan_string(const char* s, const bool ignore_comments)
|
||||
{
|
||||
auto ia = nlohmann::detail::input_adapter(s);
|
||||
return nlohmann::detail::lexer<json, decltype(ia)>(std::move(ia), ignore_comments).scan();
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
std::string get_error_message(const char* s, const bool ignore_comments = false);
|
||||
std::string get_error_message(const char* s, bool ignore_comments = false);
|
||||
std::string get_error_message(const char* s, const bool ignore_comments)
|
||||
{
|
||||
auto ia = nlohmann::detail::input_adapter(s);
|
||||
|
||||
@ -42,13 +42,13 @@ class SaxEventLogger
|
||||
public:
|
||||
bool null()
|
||||
{
|
||||
events.push_back("null()");
|
||||
events.emplace_back("null()");
|
||||
return true;
|
||||
}
|
||||
|
||||
bool boolean(bool val)
|
||||
{
|
||||
events.push_back(val ? "boolean(true)" : "boolean(false)");
|
||||
events.emplace_back(val ? "boolean(true)" : "boolean(false)");
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -64,7 +64,7 @@ class SaxEventLogger
|
||||
return true;
|
||||
}
|
||||
|
||||
bool number_float(json::number_float_t, const std::string& s)
|
||||
bool number_float(json::number_float_t /*unused*/, const std::string& s)
|
||||
{
|
||||
events.push_back("number_float(" + s + ")");
|
||||
return true;
|
||||
@ -79,7 +79,7 @@ class SaxEventLogger
|
||||
bool binary(json::binary_t& val)
|
||||
{
|
||||
std::string binary_contents = "binary(";
|
||||
std::string comma_space = "";
|
||||
std::string comma_space;
|
||||
for (auto b : val)
|
||||
{
|
||||
binary_contents.append(comma_space);
|
||||
@ -95,7 +95,7 @@ class SaxEventLogger
|
||||
{
|
||||
if (elements == std::size_t(-1))
|
||||
{
|
||||
events.push_back("start_object()");
|
||||
events.emplace_back("start_object()");
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -112,7 +112,7 @@ class SaxEventLogger
|
||||
|
||||
bool end_object()
|
||||
{
|
||||
events.push_back("end_object()");
|
||||
events.emplace_back("end_object()");
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -120,7 +120,7 @@ class SaxEventLogger
|
||||
{
|
||||
if (elements == std::size_t(-1))
|
||||
{
|
||||
events.push_back("start_array()");
|
||||
events.emplace_back("start_array()");
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -131,11 +131,11 @@ class SaxEventLogger
|
||||
|
||||
bool end_array()
|
||||
{
|
||||
events.push_back("end_array()");
|
||||
events.emplace_back("end_array()");
|
||||
return true;
|
||||
}
|
||||
|
||||
bool parse_error(std::size_t position, const std::string&, const json::exception&)
|
||||
bool parse_error(std::size_t position, const std::string& /*unused*/, const json::exception& /*unused*/)
|
||||
{
|
||||
errored = true;
|
||||
events.push_back("parse_error(" + std::to_string(position) + ")");
|
||||
@ -157,42 +157,42 @@ class SaxCountdown : public nlohmann::json::json_sax_t
|
||||
return events_left-- > 0;
|
||||
}
|
||||
|
||||
bool boolean(bool) override
|
||||
bool boolean(bool /*val*/) override
|
||||
{
|
||||
return events_left-- > 0;
|
||||
}
|
||||
|
||||
bool number_integer(json::number_integer_t) override
|
||||
bool number_integer(json::number_integer_t /*val*/) override
|
||||
{
|
||||
return events_left-- > 0;
|
||||
}
|
||||
|
||||
bool number_unsigned(json::number_unsigned_t) override
|
||||
bool number_unsigned(json::number_unsigned_t /*val*/) override
|
||||
{
|
||||
return events_left-- > 0;
|
||||
}
|
||||
|
||||
bool number_float(json::number_float_t, const std::string&) override
|
||||
bool number_float(json::number_float_t /*val*/, const std::string& /*s*/) override
|
||||
{
|
||||
return events_left-- > 0;
|
||||
}
|
||||
|
||||
bool string(std::string&) override
|
||||
bool string(std::string& /*val*/) override
|
||||
{
|
||||
return events_left-- > 0;
|
||||
}
|
||||
|
||||
bool binary(json::binary_t&) override
|
||||
bool binary(json::binary_t& /*val*/) override
|
||||
{
|
||||
return events_left-- > 0;
|
||||
}
|
||||
|
||||
bool start_object(std::size_t) override
|
||||
bool start_object(std::size_t /*elements*/) override
|
||||
{
|
||||
return events_left-- > 0;
|
||||
}
|
||||
|
||||
bool key(std::string&) override
|
||||
bool key(std::string& /*val*/) override
|
||||
{
|
||||
return events_left-- > 0;
|
||||
}
|
||||
@ -202,7 +202,7 @@ class SaxCountdown : public nlohmann::json::json_sax_t
|
||||
return events_left-- > 0;
|
||||
}
|
||||
|
||||
bool start_array(std::size_t) override
|
||||
bool start_array(std::size_t /*elements*/) override
|
||||
{
|
||||
return events_left-- > 0;
|
||||
}
|
||||
@ -212,7 +212,7 @@ class SaxCountdown : public nlohmann::json::json_sax_t
|
||||
return events_left-- > 0;
|
||||
}
|
||||
|
||||
bool parse_error(std::size_t, const std::string&, const json::exception&) override
|
||||
bool parse_error(std::size_t /*position*/, const std::string& /*last_token*/, const json::exception& /*ex*/) override
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@ -267,7 +267,7 @@ bool accept_helper(const std::string& s)
|
||||
CHECK(json::parser(nlohmann::detail::input_adapter(s)).accept(false) == !el.errored);
|
||||
|
||||
// 5. parse with simple callback
|
||||
json::parser_callback_t cb = [](int, json::parse_event_t, json&)
|
||||
json::parser_callback_t cb = [](int /*unused*/, json::parse_event_t /*unused*/, json& /*unused*/)
|
||||
{
|
||||
return true;
|
||||
};
|
||||
@ -641,8 +641,8 @@ TEST_CASE("parser class")
|
||||
SECTION("overflow")
|
||||
{
|
||||
// overflows during parsing yield an exception
|
||||
CHECK_THROWS_AS(parser_helper("1.18973e+4932") == json(), json::out_of_range&);
|
||||
CHECK_THROWS_WITH(parser_helper("1.18973e+4932") == json(),
|
||||
CHECK_THROWS_AS(parser_helper("1.18973e+4932").empty(), json::out_of_range&);
|
||||
CHECK_THROWS_WITH(parser_helper("1.18973e+4932").empty(),
|
||||
"[json.exception.out_of_range.406] number overflow parsing '1.18973e+4932'");
|
||||
}
|
||||
|
||||
@ -1155,7 +1155,7 @@ TEST_CASE("parser class")
|
||||
case ('r'):
|
||||
case ('t'):
|
||||
{
|
||||
CHECK_NOTHROW(parser_helper(s.c_str()));
|
||||
CHECK_NOTHROW(parser_helper(s));
|
||||
break;
|
||||
}
|
||||
|
||||
@ -1168,11 +1168,11 @@ TEST_CASE("parser class")
|
||||
// any other combination of backslash and character is invalid
|
||||
default:
|
||||
{
|
||||
CHECK_THROWS_AS(parser_helper(s.c_str()), json::parse_error&);
|
||||
CHECK_THROWS_AS(parser_helper(s), json::parse_error&);
|
||||
// only check error message if c is not a control character
|
||||
if (c > 0x1f)
|
||||
{
|
||||
CHECK_THROWS_WITH_STD_STR(parser_helper(s.c_str()),
|
||||
CHECK_THROWS_WITH_STD_STR(parser_helper(s),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 3: syntax error while parsing value - invalid string: forbidden character after backslash; last read: '\"\\" + std::string(1, static_cast<char>(c)) + "'");
|
||||
}
|
||||
break;
|
||||
@ -1233,49 +1233,49 @@ TEST_CASE("parser class")
|
||||
if (valid(c))
|
||||
{
|
||||
CAPTURE(s1)
|
||||
CHECK_NOTHROW(parser_helper(s1.c_str()));
|
||||
CHECK_NOTHROW(parser_helper(s1));
|
||||
CAPTURE(s2)
|
||||
CHECK_NOTHROW(parser_helper(s2.c_str()));
|
||||
CHECK_NOTHROW(parser_helper(s2));
|
||||
CAPTURE(s3)
|
||||
CHECK_NOTHROW(parser_helper(s3.c_str()));
|
||||
CHECK_NOTHROW(parser_helper(s3));
|
||||
CAPTURE(s4)
|
||||
CHECK_NOTHROW(parser_helper(s4.c_str()));
|
||||
CHECK_NOTHROW(parser_helper(s4));
|
||||
}
|
||||
else
|
||||
{
|
||||
CAPTURE(s1)
|
||||
CHECK_THROWS_AS(parser_helper(s1.c_str()), json::parse_error&);
|
||||
CHECK_THROWS_AS(parser_helper(s1), json::parse_error&);
|
||||
// only check error message if c is not a control character
|
||||
if (c > 0x1f)
|
||||
{
|
||||
CHECK_THROWS_WITH_STD_STR(parser_helper(s1.c_str()),
|
||||
CHECK_THROWS_WITH_STD_STR(parser_helper(s1),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 7: syntax error while parsing value - invalid string: '\\u' must be followed by 4 hex digits; last read: '" + s1.substr(0, 7) + "'");
|
||||
}
|
||||
|
||||
CAPTURE(s2)
|
||||
CHECK_THROWS_AS(parser_helper(s2.c_str()), json::parse_error&);
|
||||
CHECK_THROWS_AS(parser_helper(s2), json::parse_error&);
|
||||
// only check error message if c is not a control character
|
||||
if (c > 0x1f)
|
||||
{
|
||||
CHECK_THROWS_WITH_STD_STR(parser_helper(s2.c_str()),
|
||||
CHECK_THROWS_WITH_STD_STR(parser_helper(s2),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 6: syntax error while parsing value - invalid string: '\\u' must be followed by 4 hex digits; last read: '" + s2.substr(0, 6) + "'");
|
||||
}
|
||||
|
||||
CAPTURE(s3)
|
||||
CHECK_THROWS_AS(parser_helper(s3.c_str()), json::parse_error&);
|
||||
CHECK_THROWS_AS(parser_helper(s3), json::parse_error&);
|
||||
// only check error message if c is not a control character
|
||||
if (c > 0x1f)
|
||||
{
|
||||
CHECK_THROWS_WITH_STD_STR(parser_helper(s3.c_str()),
|
||||
CHECK_THROWS_WITH_STD_STR(parser_helper(s3),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 5: syntax error while parsing value - invalid string: '\\u' must be followed by 4 hex digits; last read: '" + s3.substr(0, 5) + "'");
|
||||
}
|
||||
|
||||
CAPTURE(s4)
|
||||
CHECK_THROWS_AS(parser_helper(s4.c_str()), json::parse_error&);
|
||||
CHECK_THROWS_AS(parser_helper(s4), json::parse_error&);
|
||||
// only check error message if c is not a control character
|
||||
if (c > 0x1f)
|
||||
{
|
||||
CHECK_THROWS_WITH_STD_STR(parser_helper(s4.c_str()),
|
||||
CHECK_THROWS_WITH_STD_STR(parser_helper(s4),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 4: syntax error while parsing value - invalid string: '\\u' must be followed by 4 hex digits; last read: '" + s4.substr(0, 4) + "'");
|
||||
}
|
||||
}
|
||||
@ -1381,7 +1381,7 @@ TEST_CASE("parser class")
|
||||
case ('r'):
|
||||
case ('t'):
|
||||
{
|
||||
CHECK(json::parser(nlohmann::detail::input_adapter(std::string(s.c_str()))).accept());
|
||||
CHECK(json::parser(nlohmann::detail::input_adapter(std::string(s))).accept());
|
||||
break;
|
||||
}
|
||||
|
||||
@ -1394,7 +1394,7 @@ TEST_CASE("parser class")
|
||||
// any other combination of backslash and character is invalid
|
||||
default:
|
||||
{
|
||||
CHECK(json::parser(nlohmann::detail::input_adapter(std::string(s.c_str()))).accept() == false);
|
||||
CHECK(json::parser(nlohmann::detail::input_adapter(std::string(s))).accept() == false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -1453,27 +1453,27 @@ TEST_CASE("parser class")
|
||||
if (valid(c))
|
||||
{
|
||||
CAPTURE(s1)
|
||||
CHECK(json::parser(nlohmann::detail::input_adapter(std::string(s1.c_str()))).accept());
|
||||
CHECK(json::parser(nlohmann::detail::input_adapter(std::string(s1))).accept());
|
||||
CAPTURE(s2)
|
||||
CHECK(json::parser(nlohmann::detail::input_adapter(std::string(s2.c_str()))).accept());
|
||||
CHECK(json::parser(nlohmann::detail::input_adapter(std::string(s2))).accept());
|
||||
CAPTURE(s3)
|
||||
CHECK(json::parser(nlohmann::detail::input_adapter(std::string(s3.c_str()))).accept());
|
||||
CHECK(json::parser(nlohmann::detail::input_adapter(std::string(s3))).accept());
|
||||
CAPTURE(s4)
|
||||
CHECK(json::parser(nlohmann::detail::input_adapter(std::string(s4.c_str()))).accept());
|
||||
CHECK(json::parser(nlohmann::detail::input_adapter(std::string(s4))).accept());
|
||||
}
|
||||
else
|
||||
{
|
||||
CAPTURE(s1)
|
||||
CHECK(json::parser(nlohmann::detail::input_adapter(std::string(s1.c_str()))).accept() == false);
|
||||
CHECK(json::parser(nlohmann::detail::input_adapter(std::string(s1))).accept() == false);
|
||||
|
||||
CAPTURE(s2)
|
||||
CHECK(json::parser(nlohmann::detail::input_adapter(std::string(s2.c_str()))).accept() == false);
|
||||
CHECK(json::parser(nlohmann::detail::input_adapter(std::string(s2))).accept() == false);
|
||||
|
||||
CAPTURE(s3)
|
||||
CHECK(json::parser(nlohmann::detail::input_adapter(std::string(s3.c_str()))).accept() == false);
|
||||
CHECK(json::parser(nlohmann::detail::input_adapter(std::string(s3))).accept() == false);
|
||||
|
||||
CAPTURE(s4)
|
||||
CHECK(json::parser(nlohmann::detail::input_adapter(std::string(s4.c_str()))).accept() == false);
|
||||
CHECK(json::parser(nlohmann::detail::input_adapter(std::string(s4))).accept() == false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1499,16 +1499,9 @@ TEST_CASE("parser class")
|
||||
|
||||
// test case to make sure the callback is properly evaluated after reading a key
|
||||
{
|
||||
json::parser_callback_t cb = [](int, json::parse_event_t event, json&)
|
||||
json::parser_callback_t cb = [](int /*unused*/, json::parse_event_t event, json& /*unused*/)
|
||||
{
|
||||
if (event == json::parse_event_t::key)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return event != json::parse_event_t::key;
|
||||
};
|
||||
|
||||
json x = json::parse("{\"key\": false}", cb);
|
||||
@ -1518,7 +1511,7 @@ TEST_CASE("parser class")
|
||||
|
||||
SECTION("callback function")
|
||||
{
|
||||
auto s_object = R"(
|
||||
const auto* s_object = R"(
|
||||
{
|
||||
"foo": 2,
|
||||
"bar": {
|
||||
@ -1527,11 +1520,11 @@ TEST_CASE("parser class")
|
||||
}
|
||||
)";
|
||||
|
||||
auto s_array = R"(
|
||||
const auto* s_array = R"(
|
||||
[1,2,[3,4,5],4,5]
|
||||
)";
|
||||
|
||||
auto structured_array = R"(
|
||||
const auto* structured_array = R"(
|
||||
[
|
||||
1,
|
||||
{
|
||||
@ -1545,14 +1538,14 @@ TEST_CASE("parser class")
|
||||
|
||||
SECTION("filter nothing")
|
||||
{
|
||||
json j_object = json::parse(s_object, [](int, json::parse_event_t, const json&)
|
||||
json j_object = json::parse(s_object, [](int /*unused*/, json::parse_event_t /*unused*/, const json& /*unused*/)
|
||||
{
|
||||
return true;
|
||||
});
|
||||
|
||||
CHECK (j_object == json({{"foo", 2}, {"bar", {{"baz", 1}}}}));
|
||||
|
||||
json j_array = json::parse(s_array, [](int, json::parse_event_t, const json&)
|
||||
json j_array = json::parse(s_array, [](int /*unused*/, json::parse_event_t /*unused*/, const json& /*unused*/)
|
||||
{
|
||||
return true;
|
||||
});
|
||||
@ -1562,7 +1555,7 @@ TEST_CASE("parser class")
|
||||
|
||||
SECTION("filter everything")
|
||||
{
|
||||
json j_object = json::parse(s_object, [](int, json::parse_event_t, const json&)
|
||||
json j_object = json::parse(s_object, [](int /*unused*/, json::parse_event_t /*unused*/, const json& /*unused*/)
|
||||
{
|
||||
return false;
|
||||
});
|
||||
@ -1570,7 +1563,7 @@ TEST_CASE("parser class")
|
||||
// the top-level object will be discarded, leaving a null
|
||||
CHECK (j_object.is_null());
|
||||
|
||||
json j_array = json::parse(s_array, [](int, json::parse_event_t, const json&)
|
||||
json j_array = json::parse(s_array, [](int /*unused*/, json::parse_event_t /*unused*/, const json& /*unused*/)
|
||||
{
|
||||
return false;
|
||||
});
|
||||
@ -1581,31 +1574,17 @@ TEST_CASE("parser class")
|
||||
|
||||
SECTION("filter specific element")
|
||||
{
|
||||
json j_object = json::parse(s_object, [](int, json::parse_event_t, const json & j)
|
||||
json j_object = json::parse(s_object, [](int /*unused*/, json::parse_event_t /*unused*/, const json & j)
|
||||
{
|
||||
// filter all number(2) elements
|
||||
if (j == json(2))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return j != json(2);
|
||||
});
|
||||
|
||||
CHECK (j_object == json({{"bar", {{"baz", 1}}}}));
|
||||
|
||||
json j_array = json::parse(s_array, [](int, json::parse_event_t, const json & j)
|
||||
json j_array = json::parse(s_array, [](int /*unused*/, json::parse_event_t /*unused*/, const json & j)
|
||||
{
|
||||
if (j == json(2))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return j != json(2);
|
||||
});
|
||||
|
||||
CHECK (j_array == json({1, {3, 4, 5}, 4, 5}));
|
||||
@ -1613,32 +1592,18 @@ TEST_CASE("parser class")
|
||||
|
||||
SECTION("filter object in array")
|
||||
{
|
||||
json j_filtered1 = json::parse(structured_array, [](int, json::parse_event_t e, const json & parsed)
|
||||
json j_filtered1 = json::parse(structured_array, [](int /*unused*/, json::parse_event_t e, const json & parsed)
|
||||
{
|
||||
if (e == json::parse_event_t::object_end && parsed.contains("foo"))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return !(e == json::parse_event_t::object_end && parsed.contains("foo"));
|
||||
});
|
||||
|
||||
// the specified object will be discarded, and removed.
|
||||
CHECK (j_filtered1.size() == 2);
|
||||
CHECK (j_filtered1 == json({1, {{"qux", "baz"}}}));
|
||||
|
||||
json j_filtered2 = json::parse(structured_array, [](int, json::parse_event_t e, const json& /*parsed*/)
|
||||
json j_filtered2 = json::parse(structured_array, [](int /*unused*/, json::parse_event_t e, const json& /*parsed*/)
|
||||
{
|
||||
if (e == json::parse_event_t::object_end)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return e != json::parse_event_t::object_end;
|
||||
});
|
||||
|
||||
// removed all objects in array.
|
||||
@ -1651,7 +1616,7 @@ TEST_CASE("parser class")
|
||||
SECTION("first closing event")
|
||||
{
|
||||
{
|
||||
json j_object = json::parse(s_object, [](int, json::parse_event_t e, const json&)
|
||||
json j_object = json::parse(s_object, [](int /*unused*/, json::parse_event_t e, const json& /*unused*/)
|
||||
{
|
||||
static bool first = true;
|
||||
if (e == json::parse_event_t::object_end && first)
|
||||
@ -1659,10 +1624,8 @@ TEST_CASE("parser class")
|
||||
first = false;
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
// the first completed object will be discarded
|
||||
@ -1670,7 +1633,7 @@ TEST_CASE("parser class")
|
||||
}
|
||||
|
||||
{
|
||||
json j_array = json::parse(s_array, [](int, json::parse_event_t e, const json&)
|
||||
json j_array = json::parse(s_array, [](int /*unused*/, json::parse_event_t e, const json& /*unused*/)
|
||||
{
|
||||
static bool first = true;
|
||||
if (e == json::parse_event_t::array_end && first)
|
||||
@ -1678,10 +1641,8 @@ TEST_CASE("parser class")
|
||||
first = false;
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
// the first completed array will be discarded
|
||||
@ -1696,29 +1657,15 @@ TEST_CASE("parser class")
|
||||
// object and array is discarded only after the closing character
|
||||
// has been read
|
||||
|
||||
json j_empty_object = json::parse("{}", [](int, json::parse_event_t e, const json&)
|
||||
json j_empty_object = json::parse("{}", [](int /*unused*/, json::parse_event_t e, const json& /*unused*/)
|
||||
{
|
||||
if (e == json::parse_event_t::object_end)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return e != json::parse_event_t::object_end;
|
||||
});
|
||||
CHECK(j_empty_object == json());
|
||||
|
||||
json j_empty_array = json::parse("[]", [](int, json::parse_event_t e, const json&)
|
||||
json j_empty_array = json::parse("[]", [](int /*unused*/, json::parse_event_t e, const json& /*unused*/)
|
||||
{
|
||||
if (e == json::parse_event_t::array_end)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return e != json::parse_event_t::array_end;
|
||||
});
|
||||
CHECK(j_empty_array == json());
|
||||
}
|
||||
@ -1784,7 +1731,7 @@ TEST_CASE("parser class")
|
||||
{
|
||||
SECTION("parser with callback")
|
||||
{
|
||||
json::parser_callback_t cb = [](int, json::parse_event_t, json&)
|
||||
json::parser_callback_t cb = [](int /*unused*/, json::parse_event_t /*unused*/, json& /*unused*/)
|
||||
{
|
||||
return true;
|
||||
};
|
||||
|
||||
@ -794,7 +794,7 @@ TEST_CASE("constructors")
|
||||
|
||||
SECTION("integer literal with l suffix")
|
||||
{
|
||||
json j(42l);
|
||||
json j(42L);
|
||||
CHECK(j.type() == json::value_t::number_integer);
|
||||
CHECK(j == j_reference);
|
||||
}
|
||||
@ -808,7 +808,7 @@ TEST_CASE("constructors")
|
||||
|
||||
SECTION("integer literal with ll suffix")
|
||||
{
|
||||
json j(42ll);
|
||||
json j(42LL);
|
||||
CHECK(j.type() == json::value_t::number_integer);
|
||||
CHECK(j == j_reference);
|
||||
}
|
||||
@ -892,7 +892,7 @@ TEST_CASE("constructors")
|
||||
|
||||
SECTION("long double")
|
||||
{
|
||||
long double n = 42.23l;
|
||||
long double n = 42.23L;
|
||||
json j(n);
|
||||
CHECK(j.type() == json::value_t::number_float);
|
||||
CHECK(j.m_value.number_float == Approx(j_reference.m_value.number_float));
|
||||
@ -914,7 +914,7 @@ TEST_CASE("constructors")
|
||||
|
||||
SECTION("integer literal with l suffix")
|
||||
{
|
||||
json j(42.23l);
|
||||
json j(42.23L);
|
||||
CHECK(j.type() == json::value_t::number_float);
|
||||
CHECK(j.m_value.number_float == Approx(j_reference.m_value.number_float));
|
||||
}
|
||||
|
||||
@ -633,7 +633,7 @@ TEST_CASE("value conversion")
|
||||
|
||||
SECTION("boolean_t")
|
||||
{
|
||||
json::boolean_t b = j.get<json::boolean_t>();
|
||||
auto b = j.get<json::boolean_t>();
|
||||
CHECK(json(b) == j);
|
||||
}
|
||||
|
||||
@ -726,25 +726,25 @@ TEST_CASE("value conversion")
|
||||
|
||||
SECTION("number_integer_t")
|
||||
{
|
||||
json::number_integer_t n = j.get<json::number_integer_t>();
|
||||
auto n = j.get<json::number_integer_t>();
|
||||
CHECK(json(n) == j);
|
||||
}
|
||||
|
||||
SECTION("number_unsigned_t")
|
||||
{
|
||||
json::number_unsigned_t n = j_unsigned.get<json::number_unsigned_t>();
|
||||
auto n = j_unsigned.get<json::number_unsigned_t>();
|
||||
CHECK(json(n) == j_unsigned);
|
||||
}
|
||||
|
||||
SECTION("short")
|
||||
{
|
||||
short n = j.get<short>();
|
||||
auto n = j.get<short>();
|
||||
CHECK(json(n) == j);
|
||||
}
|
||||
|
||||
SECTION("unsigned short")
|
||||
{
|
||||
unsigned short n = j.get<unsigned short>();
|
||||
auto n = j.get<unsigned short>();
|
||||
CHECK(json(n) == j);
|
||||
}
|
||||
|
||||
@ -756,7 +756,7 @@ TEST_CASE("value conversion")
|
||||
|
||||
SECTION("unsigned int")
|
||||
{
|
||||
unsigned int n = j.get<unsigned int>();
|
||||
auto n = j.get<unsigned int>();
|
||||
CHECK(json(n) == j);
|
||||
}
|
||||
|
||||
@ -768,163 +768,163 @@ TEST_CASE("value conversion")
|
||||
|
||||
SECTION("unsigned long")
|
||||
{
|
||||
unsigned long n = j.get<unsigned long>();
|
||||
auto n = j.get<unsigned long>();
|
||||
CHECK(json(n) == j);
|
||||
}
|
||||
|
||||
SECTION("long long")
|
||||
{
|
||||
long long n = j.get<long long>();
|
||||
auto n = j.get<long long>();
|
||||
CHECK(json(n) == j);
|
||||
}
|
||||
|
||||
SECTION("unsigned long long")
|
||||
{
|
||||
unsigned long long n = j.get<unsigned long long>();
|
||||
auto n = j.get<unsigned long long>();
|
||||
CHECK(json(n) == j);
|
||||
}
|
||||
|
||||
SECTION("int8_t")
|
||||
{
|
||||
int8_t n = j.get<int8_t>();
|
||||
auto n = j.get<int8_t>();
|
||||
CHECK(json(n) == j);
|
||||
}
|
||||
|
||||
SECTION("int16_t")
|
||||
{
|
||||
int16_t n = j.get<int16_t>();
|
||||
auto n = j.get<int16_t>();
|
||||
CHECK(json(n) == j);
|
||||
}
|
||||
|
||||
SECTION("int32_t")
|
||||
{
|
||||
int32_t n = j.get<int32_t>();
|
||||
auto n = j.get<int32_t>();
|
||||
CHECK(json(n) == j);
|
||||
}
|
||||
|
||||
SECTION("int64_t")
|
||||
{
|
||||
int64_t n = j.get<int64_t>();
|
||||
auto n = j.get<int64_t>();
|
||||
CHECK(json(n) == j);
|
||||
}
|
||||
|
||||
SECTION("int8_fast_t")
|
||||
{
|
||||
int_fast8_t n = j.get<int_fast8_t>();
|
||||
auto n = j.get<int_fast8_t>();
|
||||
CHECK(json(n) == j);
|
||||
}
|
||||
|
||||
SECTION("int16_fast_t")
|
||||
{
|
||||
int_fast16_t n = j.get<int_fast16_t>();
|
||||
auto n = j.get<int_fast16_t>();
|
||||
CHECK(json(n) == j);
|
||||
}
|
||||
|
||||
SECTION("int32_fast_t")
|
||||
{
|
||||
int_fast32_t n = j.get<int_fast32_t>();
|
||||
auto n = j.get<int_fast32_t>();
|
||||
CHECK(json(n) == j);
|
||||
}
|
||||
|
||||
SECTION("int64_fast_t")
|
||||
{
|
||||
int_fast64_t n = j.get<int_fast64_t>();
|
||||
auto n = j.get<int_fast64_t>();
|
||||
CHECK(json(n) == j);
|
||||
}
|
||||
|
||||
SECTION("int8_least_t")
|
||||
{
|
||||
int_least8_t n = j.get<int_least8_t>();
|
||||
auto n = j.get<int_least8_t>();
|
||||
CHECK(json(n) == j);
|
||||
}
|
||||
|
||||
SECTION("int16_least_t")
|
||||
{
|
||||
int_least16_t n = j.get<int_least16_t>();
|
||||
auto n = j.get<int_least16_t>();
|
||||
CHECK(json(n) == j);
|
||||
}
|
||||
|
||||
SECTION("int32_least_t")
|
||||
{
|
||||
int_least32_t n = j.get<int_least32_t>();
|
||||
auto n = j.get<int_least32_t>();
|
||||
CHECK(json(n) == j);
|
||||
}
|
||||
|
||||
SECTION("int64_least_t")
|
||||
{
|
||||
int_least64_t n = j.get<int_least64_t>();
|
||||
auto n = j.get<int_least64_t>();
|
||||
CHECK(json(n) == j);
|
||||
}
|
||||
|
||||
SECTION("uint8_t")
|
||||
{
|
||||
uint8_t n = j.get<uint8_t>();
|
||||
auto n = j.get<uint8_t>();
|
||||
CHECK(json(n) == j);
|
||||
}
|
||||
|
||||
SECTION("uint16_t")
|
||||
{
|
||||
uint16_t n = j.get<uint16_t>();
|
||||
auto n = j.get<uint16_t>();
|
||||
CHECK(json(n) == j);
|
||||
}
|
||||
|
||||
SECTION("uint32_t")
|
||||
{
|
||||
uint32_t n = j.get<uint32_t>();
|
||||
auto n = j.get<uint32_t>();
|
||||
CHECK(json(n) == j);
|
||||
}
|
||||
|
||||
SECTION("uint64_t")
|
||||
{
|
||||
uint64_t n = j.get<uint64_t>();
|
||||
auto n = j.get<uint64_t>();
|
||||
CHECK(json(n) == j);
|
||||
}
|
||||
|
||||
SECTION("uint8_fast_t")
|
||||
{
|
||||
uint_fast8_t n = j.get<uint_fast8_t>();
|
||||
auto n = j.get<uint_fast8_t>();
|
||||
CHECK(json(n) == j);
|
||||
}
|
||||
|
||||
SECTION("uint16_fast_t")
|
||||
{
|
||||
uint_fast16_t n = j.get<uint_fast16_t>();
|
||||
auto n = j.get<uint_fast16_t>();
|
||||
CHECK(json(n) == j);
|
||||
}
|
||||
|
||||
SECTION("uint32_fast_t")
|
||||
{
|
||||
uint_fast32_t n = j.get<uint_fast32_t>();
|
||||
auto n = j.get<uint_fast32_t>();
|
||||
CHECK(json(n) == j);
|
||||
}
|
||||
|
||||
SECTION("uint64_fast_t")
|
||||
{
|
||||
uint_fast64_t n = j.get<uint_fast64_t>();
|
||||
auto n = j.get<uint_fast64_t>();
|
||||
CHECK(json(n) == j);
|
||||
}
|
||||
|
||||
SECTION("uint8_least_t")
|
||||
{
|
||||
uint_least8_t n = j.get<uint_least8_t>();
|
||||
auto n = j.get<uint_least8_t>();
|
||||
CHECK(json(n) == j);
|
||||
}
|
||||
|
||||
SECTION("uint16_least_t")
|
||||
{
|
||||
uint_least16_t n = j.get<uint_least16_t>();
|
||||
auto n = j.get<uint_least16_t>();
|
||||
CHECK(json(n) == j);
|
||||
}
|
||||
|
||||
SECTION("uint32_least_t")
|
||||
{
|
||||
uint_least32_t n = j.get<uint_least32_t>();
|
||||
auto n = j.get<uint_least32_t>();
|
||||
CHECK(json(n) == j);
|
||||
}
|
||||
|
||||
SECTION("uint64_least_t")
|
||||
{
|
||||
uint_least64_t n = j.get<uint_least64_t>();
|
||||
auto n = j.get<uint_least64_t>();
|
||||
CHECK(json(n) == j);
|
||||
}
|
||||
|
||||
@ -976,13 +976,13 @@ TEST_CASE("value conversion")
|
||||
|
||||
SECTION("number_integer_t")
|
||||
{
|
||||
json::number_integer_t n = j.get<json::number_integer_t>();
|
||||
auto n = j.get<json::number_integer_t>();
|
||||
CHECK(json(n) == j);
|
||||
}
|
||||
|
||||
SECTION("number_unsigned_t")
|
||||
{
|
||||
json::number_unsigned_t n = j_unsigned.get<json::number_unsigned_t>();
|
||||
auto n = j_unsigned.get<json::number_unsigned_t>();
|
||||
CHECK(json(n) == j_unsigned);
|
||||
}
|
||||
|
||||
@ -1187,19 +1187,19 @@ TEST_CASE("value conversion")
|
||||
|
||||
SECTION("number_float_t")
|
||||
{
|
||||
json::number_float_t n = j.get<json::number_float_t>();
|
||||
auto n = j.get<json::number_float_t>();
|
||||
CHECK(json(n).m_value.number_float == Approx(j.m_value.number_float));
|
||||
}
|
||||
|
||||
SECTION("float")
|
||||
{
|
||||
float n = j.get<float>();
|
||||
auto n = j.get<float>();
|
||||
CHECK(json(n).m_value.number_float == Approx(j.m_value.number_float));
|
||||
}
|
||||
|
||||
SECTION("double")
|
||||
{
|
||||
double n = j.get<double>();
|
||||
auto n = j.get<double>();
|
||||
CHECK(json(n).m_value.number_float == Approx(j.m_value.number_float));
|
||||
}
|
||||
|
||||
|
||||
@ -42,13 +42,13 @@ struct SaxEventLogger : public nlohmann::json_sax<json>
|
||||
{
|
||||
bool null() override
|
||||
{
|
||||
events.push_back("null()");
|
||||
events.emplace_back("null()");
|
||||
return true;
|
||||
}
|
||||
|
||||
bool boolean(bool val) override
|
||||
{
|
||||
events.push_back(val ? "boolean(true)" : "boolean(false)");
|
||||
events.emplace_back(val ? "boolean(true)" : "boolean(false)");
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -64,7 +64,7 @@ struct SaxEventLogger : public nlohmann::json_sax<json>
|
||||
return true;
|
||||
}
|
||||
|
||||
bool number_float(json::number_float_t, const std::string& s) override
|
||||
bool number_float(json::number_float_t /*val*/, const std::string& s) override
|
||||
{
|
||||
events.push_back("number_float(" + s + ")");
|
||||
return true;
|
||||
@ -79,7 +79,7 @@ struct SaxEventLogger : public nlohmann::json_sax<json>
|
||||
bool binary(json::binary_t& val) override
|
||||
{
|
||||
std::string binary_contents = "binary(";
|
||||
std::string comma_space = "";
|
||||
std::string comma_space;
|
||||
for (auto b : val)
|
||||
{
|
||||
binary_contents.append(comma_space);
|
||||
@ -95,7 +95,7 @@ struct SaxEventLogger : public nlohmann::json_sax<json>
|
||||
{
|
||||
if (elements == std::size_t(-1))
|
||||
{
|
||||
events.push_back("start_object()");
|
||||
events.emplace_back("start_object()");
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -112,7 +112,7 @@ struct SaxEventLogger : public nlohmann::json_sax<json>
|
||||
|
||||
bool end_object() override
|
||||
{
|
||||
events.push_back("end_object()");
|
||||
events.emplace_back("end_object()");
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -120,7 +120,7 @@ struct SaxEventLogger : public nlohmann::json_sax<json>
|
||||
{
|
||||
if (elements == std::size_t(-1))
|
||||
{
|
||||
events.push_back("start_array()");
|
||||
events.emplace_back("start_array()");
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -131,11 +131,11 @@ struct SaxEventLogger : public nlohmann::json_sax<json>
|
||||
|
||||
bool end_array() override
|
||||
{
|
||||
events.push_back("end_array()");
|
||||
events.emplace_back("end_array()");
|
||||
return true;
|
||||
}
|
||||
|
||||
bool parse_error(std::size_t position, const std::string&, const json::exception&) override
|
||||
bool parse_error(std::size_t position, const std::string& /*last_token*/, const json::exception& /*ex*/) override
|
||||
{
|
||||
events.push_back("parse_error(" + std::to_string(position) + ")");
|
||||
return false;
|
||||
@ -150,7 +150,7 @@ struct SaxEventLoggerExitAfterStartObject : public SaxEventLogger
|
||||
{
|
||||
if (elements == std::size_t(-1))
|
||||
{
|
||||
events.push_back("start_object()");
|
||||
events.emplace_back("start_object()");
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -175,7 +175,7 @@ struct SaxEventLoggerExitAfterStartArray : public SaxEventLogger
|
||||
{
|
||||
if (elements == std::size_t(-1))
|
||||
{
|
||||
events.push_back("start_array()");
|
||||
events.emplace_back("start_array()");
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -184,7 +184,7 @@ struct SaxEventLoggerExitAfterStartArray : public SaxEventLogger
|
||||
return false;
|
||||
}
|
||||
};
|
||||
}
|
||||
} // namespace
|
||||
|
||||
TEST_CASE("deserialization")
|
||||
{
|
||||
@ -192,10 +192,12 @@ TEST_CASE("deserialization")
|
||||
{
|
||||
SECTION("stream")
|
||||
{
|
||||
std::stringstream ss1, ss2, ss3;
|
||||
ss1 << "[\"foo\",1,2,3,false,{\"one\":1}]";
|
||||
ss2 << "[\"foo\",1,2,3,false,{\"one\":1}]";
|
||||
ss3 << "[\"foo\",1,2,3,false,{\"one\":1}]";
|
||||
std::stringstream ss1;
|
||||
std::stringstream ss2;
|
||||
std::stringstream ss3;
|
||||
ss1 << R"(["foo",1,2,3,false,{"one":1}])";
|
||||
ss2 << R"(["foo",1,2,3,false,{"one":1}])";
|
||||
ss3 << R"(["foo",1,2,3,false,{"one":1}])";
|
||||
json j = json::parse(ss1);
|
||||
CHECK(json::accept(ss2));
|
||||
CHECK(j == json({"foo", 1, 2, 3, false, {{"one", 1}}}));
|
||||
@ -214,7 +216,7 @@ TEST_CASE("deserialization")
|
||||
|
||||
SECTION("string literal")
|
||||
{
|
||||
auto s = "[\"foo\",1,2,3,false,{\"one\":1}]";
|
||||
const auto* s = R"(["foo",1,2,3,false,{"one":1}])";
|
||||
json j = json::parse(s);
|
||||
CHECK(json::accept(s));
|
||||
CHECK(j == json({"foo", 1, 2, 3, false, {{"one", 1}}}));
|
||||
@ -233,7 +235,7 @@ TEST_CASE("deserialization")
|
||||
|
||||
SECTION("string_t")
|
||||
{
|
||||
json::string_t s = "[\"foo\",1,2,3,false,{\"one\":1}]";
|
||||
json::string_t s = R"(["foo",1,2,3,false,{"one":1}])";
|
||||
json j = json::parse(s);
|
||||
CHECK(json::accept(s));
|
||||
CHECK(j == json({"foo", 1, 2, 3, false, {{"one", 1}}}));
|
||||
@ -253,7 +255,7 @@ TEST_CASE("deserialization")
|
||||
SECTION("operator<<")
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << "[\"foo\",1,2,3,false,{\"one\":1}]";
|
||||
ss << R"(["foo",1,2,3,false,{"one":1}])";
|
||||
json j;
|
||||
j << ss;
|
||||
CHECK(j == json({"foo", 1, 2, 3, false, {{"one", 1}}}));
|
||||
@ -262,7 +264,7 @@ TEST_CASE("deserialization")
|
||||
SECTION("operator>>")
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << "[\"foo\",1,2,3,false,{\"one\":1}]";
|
||||
ss << R"(["foo",1,2,3,false,{"one":1}])";
|
||||
json j;
|
||||
ss >> j;
|
||||
CHECK(j == json({"foo", 1, 2, 3, false, {{"one", 1}}}));
|
||||
@ -278,12 +280,16 @@ TEST_CASE("deserialization")
|
||||
{
|
||||
SECTION("stream")
|
||||
{
|
||||
std::stringstream ss1, ss2, ss3, ss4, ss5;
|
||||
ss1 << "[\"foo\",1,2,3,false,{\"one\":1}";
|
||||
ss2 << "[\"foo\",1,2,3,false,{\"one\":1}";
|
||||
ss3 << "[\"foo\",1,2,3,false,{\"one\":1}";
|
||||
ss4 << "[\"foo\",1,2,3,false,{\"one\":1}";
|
||||
ss5 << "[\"foo\",1,2,3,false,{\"one\":1}";
|
||||
std::stringstream ss1;
|
||||
std::stringstream ss2;
|
||||
std::stringstream ss3;
|
||||
std::stringstream ss4;
|
||||
std::stringstream ss5;
|
||||
ss1 << R"(["foo",1,2,3,false,{"one":1})";
|
||||
ss2 << R"(["foo",1,2,3,false,{"one":1})";
|
||||
ss3 << R"(["foo",1,2,3,false,{"one":1})";
|
||||
ss4 << R"(["foo",1,2,3,false,{"one":1})";
|
||||
ss5 << R"(["foo",1,2,3,false,{"one":1})";
|
||||
|
||||
json _;
|
||||
CHECK_THROWS_AS(_ = json::parse(ss1), json::parse_error&);
|
||||
@ -309,7 +315,7 @@ TEST_CASE("deserialization")
|
||||
|
||||
SECTION("string")
|
||||
{
|
||||
json::string_t s = "[\"foo\",1,2,3,false,{\"one\":1}";
|
||||
json::string_t s = R"(["foo",1,2,3,false,{"one":1})";
|
||||
json _;
|
||||
CHECK_THROWS_AS(_ = json::parse(s), json::parse_error&);
|
||||
CHECK_THROWS_WITH(_ = json::parse(s),
|
||||
@ -334,9 +340,10 @@ TEST_CASE("deserialization")
|
||||
|
||||
SECTION("operator<<")
|
||||
{
|
||||
std::stringstream ss1, ss2;
|
||||
ss1 << "[\"foo\",1,2,3,false,{\"one\":1}";
|
||||
ss2 << "[\"foo\",1,2,3,false,{\"one\":1}";
|
||||
std::stringstream ss1;
|
||||
std::stringstream ss2;
|
||||
ss1 << R"(["foo",1,2,3,false,{"one":1})";
|
||||
ss2 << R"(["foo",1,2,3,false,{"one":1})";
|
||||
json j;
|
||||
CHECK_THROWS_AS(j << ss1, json::parse_error&);
|
||||
CHECK_THROWS_WITH(j << ss2,
|
||||
@ -345,9 +352,10 @@ TEST_CASE("deserialization")
|
||||
|
||||
SECTION("operator>>")
|
||||
{
|
||||
std::stringstream ss1, ss2;
|
||||
ss1 << "[\"foo\",1,2,3,false,{\"one\":1}";
|
||||
ss2 << "[\"foo\",1,2,3,false,{\"one\":1}";
|
||||
std::stringstream ss1;
|
||||
std::stringstream ss2;
|
||||
ss1 << R"(["foo",1,2,3,false,{"one":1})";
|
||||
ss2 << R"(["foo",1,2,3,false,{"one":1})";
|
||||
json j;
|
||||
CHECK_THROWS_AS(ss1 >> j, json::parse_error&);
|
||||
CHECK_THROWS_WITH(ss2 >> j,
|
||||
@ -404,7 +412,7 @@ TEST_CASE("deserialization")
|
||||
|
||||
SECTION("from chars")
|
||||
{
|
||||
uint8_t* v = new uint8_t[5];
|
||||
auto* v = new uint8_t[5];
|
||||
v[0] = 't';
|
||||
v[1] = 'r';
|
||||
v[2] = 'u';
|
||||
@ -860,7 +868,8 @@ TEST_CASE("deserialization")
|
||||
CHECK(json::parse(bom + "1") == 1);
|
||||
CHECK(json::parse(std::istringstream(bom + "1")) == 1);
|
||||
|
||||
SaxEventLogger l1, l2;
|
||||
SaxEventLogger l1;
|
||||
SaxEventLogger l2;
|
||||
CHECK(json::sax_parse(std::istringstream(bom + "1"), &l1));
|
||||
CHECK(json::sax_parse(bom + "1", &l2));
|
||||
CHECK(l1.events.size() == 1);
|
||||
@ -886,7 +895,8 @@ TEST_CASE("deserialization")
|
||||
CHECK_THROWS_WITH(_ = json::parse(std::istringstream(bom.substr(0, 2))),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 3: syntax error while parsing value - invalid BOM; must be 0xEF 0xBB 0xBF if given; last read: '\xEF\xBB'");
|
||||
|
||||
SaxEventLogger l1, l2;
|
||||
SaxEventLogger l1;
|
||||
SaxEventLogger l2;
|
||||
CHECK(!json::sax_parse(std::istringstream(bom.substr(0, 2)), &l1));
|
||||
CHECK(!json::sax_parse(bom.substr(0, 2), &l2));
|
||||
CHECK(l1.events.size() == 1);
|
||||
@ -912,7 +922,8 @@ TEST_CASE("deserialization")
|
||||
CHECK_THROWS_WITH(_ = json::parse(std::istringstream(bom.substr(0, 1))),
|
||||
"[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing value - invalid BOM; must be 0xEF 0xBB 0xBF if given; last read: '\xEF'");
|
||||
|
||||
SaxEventLogger l1, l2;
|
||||
SaxEventLogger l1;
|
||||
SaxEventLogger l2;
|
||||
CHECK(!json::sax_parse(std::istringstream(bom.substr(0, 1)), &l1));
|
||||
CHECK(!json::sax_parse(bom.substr(0, 1), &l2));
|
||||
CHECK(l1.events.size() == 1);
|
||||
@ -942,7 +953,7 @@ TEST_CASE("deserialization")
|
||||
CAPTURE(i1)
|
||||
CAPTURE(i2)
|
||||
|
||||
std::string s = "";
|
||||
std::string s;
|
||||
s.push_back(static_cast<char>(bom[0] + i0));
|
||||
s.push_back(static_cast<char>(bom[1] + i1));
|
||||
s.push_back(static_cast<char>(bom[2] + i2));
|
||||
@ -1012,7 +1023,7 @@ TEST_CASE("deserialization")
|
||||
|
||||
SECTION("SAX and early abort")
|
||||
{
|
||||
std::string s = "[1, [\"string\", 43.12], null, {\"key1\": true, \"key2\": false}]";
|
||||
std::string s = R"([1, ["string", 43.12], null, {"key1": true, "key2": false}])";
|
||||
|
||||
SaxEventLogger default_logger;
|
||||
SaxEventLoggerExitAfterStartObject exit_after_start_object;
|
||||
|
||||
@ -115,7 +115,7 @@ class SaxCountdown
|
||||
private:
|
||||
int events_left = 0;
|
||||
};
|
||||
}
|
||||
} // namespace
|
||||
|
||||
TEST_CASE("MessagePack")
|
||||
{
|
||||
@ -485,7 +485,7 @@ TEST_CASE("MessagePack")
|
||||
numbers.push_back(-65536);
|
||||
numbers.push_back(-77777);
|
||||
numbers.push_back(-1048576);
|
||||
numbers.push_back(-2147483648ll);
|
||||
numbers.push_back(-2147483648LL);
|
||||
for (auto i : numbers)
|
||||
{
|
||||
CAPTURE(i)
|
||||
@ -527,7 +527,7 @@ TEST_CASE("MessagePack")
|
||||
{
|
||||
std::vector<int64_t> numbers;
|
||||
numbers.push_back(INT64_MIN);
|
||||
numbers.push_back(-2147483649ll);
|
||||
numbers.push_back(-2147483649LL);
|
||||
for (auto i : numbers)
|
||||
{
|
||||
CAPTURE(i)
|
||||
|
||||
@ -42,14 +42,14 @@ enum test
|
||||
struct pod {};
|
||||
struct pod_bis {};
|
||||
|
||||
void to_json(json&, pod) noexcept;
|
||||
void to_json(json&, pod_bis);
|
||||
void from_json(const json&, pod) noexcept;
|
||||
void from_json(const json&, pod_bis);
|
||||
void to_json(json&, pod) noexcept {}
|
||||
void to_json(json&, pod_bis) {}
|
||||
void from_json(const json&, pod) noexcept {}
|
||||
void from_json(const json&, pod_bis) {}
|
||||
void to_json(json& /*unused*/, pod /*unused*/) noexcept;
|
||||
void to_json(json& /*unused*/, pod_bis /*unused*/);
|
||||
void from_json(const json& /*unused*/, pod /*unused*/) noexcept;
|
||||
void from_json(const json& /*unused*/, pod_bis /*unused*/);
|
||||
void to_json(json& /*unused*/, pod /*unused*/) noexcept {}
|
||||
void to_json(json& /*unused*/, pod_bis /*unused*/) {}
|
||||
void from_json(const json& /*unused*/, pod /*unused*/) noexcept {}
|
||||
void from_json(const json& /*unused*/, pod_bis /*unused*/) {}
|
||||
|
||||
static json* j = nullptr;
|
||||
|
||||
@ -66,7 +66,7 @@ static_assert(noexcept(json(pod{})), "");
|
||||
static_assert(noexcept(j->get<pod>()), "");
|
||||
static_assert(!noexcept(j->get<pod_bis>()), "");
|
||||
static_assert(noexcept(json(pod{})), "");
|
||||
}
|
||||
} // namespace
|
||||
|
||||
TEST_CASE("runtime checks")
|
||||
{
|
||||
|
||||
@ -104,7 +104,7 @@ struct foo_serializer < T, typename std::enable_if < !std::is_same<foo, T>::valu
|
||||
::nlohmann::from_json(j, value);
|
||||
}
|
||||
};
|
||||
}
|
||||
} // namespace ns
|
||||
|
||||
using foo_json = nlohmann::basic_json<std::map, std::vector, std::string, bool, std::int64_t,
|
||||
std::uint64_t, double, std::allocator, ns::foo_serializer, std::vector<std::uint8_t>>;
|
||||
@ -127,7 +127,7 @@ struct nocopy
|
||||
j = {{"val", n.val}};
|
||||
}
|
||||
};
|
||||
}
|
||||
} // namespace
|
||||
|
||||
TEST_CASE("regression tests 1")
|
||||
{
|
||||
@ -135,7 +135,7 @@ TEST_CASE("regression tests 1")
|
||||
{
|
||||
SECTION("escape_doublequote")
|
||||
{
|
||||
auto s = "[\"\\\"foo\\\"\"]";
|
||||
const auto* s = "[\"\\\"foo\\\"\"]";
|
||||
json j = json::parse(s);
|
||||
auto expected = R"(["\"foo\""])"_json;
|
||||
CHECK(j == expected);
|
||||
@ -245,7 +245,7 @@ TEST_CASE("regression tests 1")
|
||||
|
||||
SECTION("issue #82 - lexer::get_number return NAN")
|
||||
{
|
||||
const auto content = R"(
|
||||
const auto* const content = R"(
|
||||
{
|
||||
"Test":"Test1",
|
||||
"Number":100,
|
||||
@ -633,7 +633,7 @@ TEST_CASE("regression tests 1")
|
||||
|
||||
SECTION("issue #306 - Parsing fails without space at end of file")
|
||||
{
|
||||
for (auto filename :
|
||||
for (const auto* filename :
|
||||
{
|
||||
TEST_DATA_DIRECTORY "/regression/broken_file.json",
|
||||
TEST_DATA_DIRECTORY "/regression/working_file.json"
|
||||
@ -648,7 +648,7 @@ TEST_CASE("regression tests 1")
|
||||
|
||||
SECTION("issue #310 - make json_benchmarks no longer working in 2.0.4")
|
||||
{
|
||||
for (auto filename :
|
||||
for (const auto* filename :
|
||||
{
|
||||
TEST_DATA_DIRECTORY "/regression/floats.json",
|
||||
TEST_DATA_DIRECTORY "/regression/signed_ints.json",
|
||||
@ -1385,8 +1385,10 @@ TEST_CASE("regression tests 1")
|
||||
{
|
||||
SECTION("example 1")
|
||||
{
|
||||
std::istringstream i1_2_3( "{\"first\": \"one\" }{\"second\": \"two\"}3" );
|
||||
json j1, j2, j3;
|
||||
std::istringstream i1_2_3( R"({"first": "one" }{"second": "two"}3)" );
|
||||
json j1;
|
||||
json j2;
|
||||
json j3;
|
||||
i1_2_3 >> j1;
|
||||
i1_2_3 >> j2;
|
||||
i1_2_3 >> j3;
|
||||
@ -1524,7 +1526,7 @@ TEST_CASE("regression tests 1")
|
||||
SECTION("issue #971 - Add a SAX parser - late bug")
|
||||
{
|
||||
// a JSON text
|
||||
auto text = R"(
|
||||
const auto* text = R"(
|
||||
{
|
||||
"Image": {
|
||||
"Width": 800,
|
||||
@ -1545,14 +1547,7 @@ TEST_CASE("regression tests 1")
|
||||
json::parser_callback_t cb = [](int /*depth*/, json::parse_event_t event, json & parsed)
|
||||
{
|
||||
// skip object elements with key "Thumbnail"
|
||||
if (event == json::parse_event_t::key && parsed == json("Thumbnail"))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return !(event == json::parse_event_t::key && parsed == json("Thumbnail"));
|
||||
};
|
||||
|
||||
// parse (with callback) and serialize JSON
|
||||
|
||||
@ -37,11 +37,9 @@ DOCTEST_GCC_SUPPRESS_WARNING("-Wfloat-equal")
|
||||
#include <nlohmann/json.hpp>
|
||||
using nlohmann::json;
|
||||
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <list>
|
||||
#include <cstdio>
|
||||
#include <test_data.hpp>
|
||||
#include <utility>
|
||||
|
||||
#if (defined(__cplusplus) && __cplusplus >= 201703L) || (defined(_HAS_CXX17) && _HAS_CXX17 == 1) // fix for issue #464
|
||||
#define JSON_HAS_CPP_17
|
||||
@ -68,7 +66,7 @@ namespace
|
||||
{
|
||||
struct NonDefaultFromJsonStruct { };
|
||||
|
||||
inline bool operator== (NonDefaultFromJsonStruct const&, NonDefaultFromJsonStruct const&)
|
||||
inline bool operator== (NonDefaultFromJsonStruct const& /*unused*/, NonDefaultFromJsonStruct const& /*unused*/)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@ -80,7 +78,7 @@ NLOHMANN_JSON_SERIALIZE_ENUM(for_1647,
|
||||
{for_1647::one, "one"},
|
||||
{for_1647::two, "two"},
|
||||
})
|
||||
}
|
||||
} // namespace
|
||||
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
// for #1299
|
||||
@ -89,7 +87,7 @@ NLOHMANN_JSON_SERIALIZE_ENUM(for_1647,
|
||||
struct Data
|
||||
{
|
||||
Data() = default;
|
||||
Data(const std::string& a_, const std::string b_) : a(a_), b(b_) {}
|
||||
Data(std::string a_, const std::string b_) : a(std::move(a_)), b(b_) {}
|
||||
std::string a {};
|
||||
std::string b {};
|
||||
};
|
||||
|
||||
@ -183,10 +183,10 @@ TEST_CASE("serialization")
|
||||
CHECK(to_string(j) == "\"" + expected + "\"");
|
||||
};
|
||||
|
||||
test("{\"x\":5,\"y\":6}", "{\\\"x\\\":5,\\\"y\\\":6}");
|
||||
test("{\"x\":[10,null,null,null]}", "{\\\"x\\\":[10,null,null,null]}");
|
||||
test(R"({"x":5,"y":6})", R"({\"x\":5,\"y\":6})");
|
||||
test("{\"x\":[10,null,null,null]}", R"({\"x\":[10,null,null,null]})");
|
||||
test("test", "test");
|
||||
test("[3,\"false\",false]", "[3,\\\"false\\\",false]");
|
||||
test("[3,\"false\",false]", R"([3,\"false\",false])");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -41,7 +41,7 @@ TEST_CASE("compliance tests from json.org")
|
||||
|
||||
SECTION("expected failures")
|
||||
{
|
||||
for (auto filename :
|
||||
for (const auto* filename :
|
||||
{
|
||||
//TEST_DATA_DIRECTORY "/json_tests/fail1.json",
|
||||
TEST_DATA_DIRECTORY "/json_tests/fail2.json",
|
||||
@ -90,7 +90,7 @@ TEST_CASE("compliance tests from json.org")
|
||||
// these tests fail above, because the parser does not end on EOF;
|
||||
// they succeed when the operator>> is used, because it does not
|
||||
// have this constraint
|
||||
for (auto filename :
|
||||
for (const auto* filename :
|
||||
{
|
||||
TEST_DATA_DIRECTORY "/json_tests/fail7.json",
|
||||
TEST_DATA_DIRECTORY "/json_tests/fail8.json",
|
||||
@ -106,7 +106,7 @@ TEST_CASE("compliance tests from json.org")
|
||||
|
||||
SECTION("expected passes")
|
||||
{
|
||||
for (auto filename :
|
||||
for (const auto* filename :
|
||||
{
|
||||
TEST_DATA_DIRECTORY "/json_tests/pass1.json",
|
||||
TEST_DATA_DIRECTORY "/json_tests/pass2.json",
|
||||
@ -272,20 +272,20 @@ TEST_CASE("compliance tests from nativejson-benchmark")
|
||||
|
||||
TEST_STRING("[\"\"]", "");
|
||||
TEST_STRING("[\"Hello\"]", "Hello");
|
||||
TEST_STRING("[\"Hello\\nWorld\"]", "Hello\nWorld");
|
||||
TEST_STRING(R"(["Hello\nWorld"])", "Hello\nWorld");
|
||||
//TEST_STRING("[\"Hello\\u0000World\"]", "Hello\0World");
|
||||
TEST_STRING("[\"\\\"\\\\/\\b\\f\\n\\r\\t\"]", "\"\\/\b\f\n\r\t");
|
||||
TEST_STRING("[\"\\u0024\"]", "\x24"); // Dollar sign U+0024
|
||||
TEST_STRING("[\"\\u00A2\"]", "\xC2\xA2"); // Cents sign U+00A2
|
||||
TEST_STRING("[\"\\u20AC\"]", "\xE2\x82\xAC"); // Euro sign U+20AC
|
||||
TEST_STRING("[\"\\uD834\\uDD1E\"]", "\xF0\x9D\x84\x9E"); // G clef sign U+1D11E
|
||||
TEST_STRING(R"(["\"\\/\b\f\n\r\t"])", "\"\\/\b\f\n\r\t");
|
||||
TEST_STRING(R"(["\u0024"])", "$"); // Dollar sign U+0024
|
||||
TEST_STRING(R"(["\u00A2"])", "\xC2\xA2"); // Cents sign U+00A2
|
||||
TEST_STRING(R"(["\u20AC"])", "\xE2\x82\xAC"); // Euro sign U+20AC
|
||||
TEST_STRING(R"(["\uD834\uDD1E"])", "\xF0\x9D\x84\x9E"); // G clef sign U+1D11E
|
||||
}
|
||||
|
||||
SECTION("roundtrip")
|
||||
{
|
||||
// test cases are from https://github.com/miloyip/nativejson-benchmark/tree/master/test/data/roundtrip
|
||||
|
||||
for (auto filename :
|
||||
for (const auto* filename :
|
||||
{
|
||||
TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip01.json",
|
||||
TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip02.json",
|
||||
@ -441,7 +441,7 @@ TEST_CASE("RFC 7159 examples")
|
||||
SECTION("13 Examples")
|
||||
{
|
||||
{
|
||||
auto json_contents = R"(
|
||||
const auto* json_contents = R"(
|
||||
{
|
||||
"Image": {
|
||||
"Width": 800,
|
||||
@ -462,7 +462,7 @@ TEST_CASE("RFC 7159 examples")
|
||||
}
|
||||
|
||||
{
|
||||
auto json_contents = R"(
|
||||
const auto* json_contents = R"(
|
||||
[
|
||||
{
|
||||
"precision": "zip",
|
||||
@ -500,7 +500,7 @@ TEST_CASE("nst's JSONTestSuite")
|
||||
{
|
||||
SECTION("y")
|
||||
{
|
||||
for (auto filename :
|
||||
for (const auto* filename :
|
||||
{
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_array_arraysWithSpaces.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_array_empty-string.json",
|
||||
@ -610,7 +610,7 @@ TEST_CASE("nst's JSONTestSuite")
|
||||
|
||||
SECTION("n")
|
||||
{
|
||||
for (auto filename :
|
||||
for (const auto* filename :
|
||||
{
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_array_1_true_without_comma.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_array_a_invalid_utf8.json",
|
||||
@ -822,7 +822,7 @@ TEST_CASE("nst's JSONTestSuite")
|
||||
// these tests fail above, because the parser does not end on EOF;
|
||||
// they succeed when the operator>> is used, because it does not
|
||||
// have this constraint
|
||||
for (auto filename :
|
||||
for (const auto* filename :
|
||||
{
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_array_comma_after_close.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_array_extra_close.json",
|
||||
@ -852,7 +852,7 @@ TEST_CASE("nst's JSONTestSuite")
|
||||
|
||||
SECTION("i -> y")
|
||||
{
|
||||
for (auto filename :
|
||||
for (const auto* filename :
|
||||
{
|
||||
// we do not pose a limit on nesting
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/i_structure_500_nested_arrays.json",
|
||||
@ -876,7 +876,7 @@ TEST_CASE("nst's JSONTestSuite")
|
||||
// numbers that overflow during parsing
|
||||
SECTION("i/y -> n (out of range)")
|
||||
{
|
||||
for (auto filename :
|
||||
for (const auto* filename :
|
||||
{
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/i_number_neg_int_huge_exp.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/i_number_pos_double_huge_exp.json",
|
||||
@ -895,7 +895,7 @@ TEST_CASE("nst's JSONTestSuite")
|
||||
|
||||
SECTION("i -> n")
|
||||
{
|
||||
for (auto filename :
|
||||
for (const auto* filename :
|
||||
{
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/i_object_key_lone_2nd_surrogate.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/i_string_1st_surrogate_but_2nd_missing.json",
|
||||
@ -928,7 +928,7 @@ TEST_CASE("nst's JSONTestSuite (2)")
|
||||
{
|
||||
SECTION("y")
|
||||
{
|
||||
for (auto filename :
|
||||
for (const auto* filename :
|
||||
{
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_array_arraysWithSpaces.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_array_empty-string.json",
|
||||
@ -1039,7 +1039,7 @@ TEST_CASE("nst's JSONTestSuite (2)")
|
||||
|
||||
SECTION("n")
|
||||
{
|
||||
for (auto filename :
|
||||
for (const auto* filename :
|
||||
{
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_array_1_true_without_comma.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_array_a_invalid_utf8.json",
|
||||
@ -1241,7 +1241,7 @@ TEST_CASE("nst's JSONTestSuite (2)")
|
||||
|
||||
SECTION("n (previously overflowed)")
|
||||
{
|
||||
for (auto filename :
|
||||
for (const auto* filename :
|
||||
{
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_100000_opening_arrays.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_open_array_object.json"
|
||||
@ -1256,7 +1256,7 @@ TEST_CASE("nst's JSONTestSuite (2)")
|
||||
|
||||
SECTION("i -> y")
|
||||
{
|
||||
for (auto filename :
|
||||
for (const auto* filename :
|
||||
{
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_number_double_huge_neg_exp.json",
|
||||
//TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_number_huge_exp.json",
|
||||
@ -1307,7 +1307,7 @@ TEST_CASE("nst's JSONTestSuite (2)")
|
||||
|
||||
SECTION("i -> n")
|
||||
{
|
||||
for (auto filename :
|
||||
for (const auto* filename :
|
||||
{
|
||||
//TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_number_double_huge_neg_exp.json",
|
||||
TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_number_huge_exp.json",
|
||||
@ -1373,7 +1373,7 @@ std::string trim(const std::string& str)
|
||||
size_t last = str.find_last_not_of(' ');
|
||||
return str.substr(first, (last - first + 1));
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
TEST_CASE("Big List of Naughty Strings")
|
||||
{
|
||||
@ -1399,7 +1399,7 @@ TEST_CASE("Big List of Naughty Strings")
|
||||
line = trim(line);
|
||||
|
||||
// remove trailing comma
|
||||
line = line.substr(0, line.find_last_of(","));
|
||||
line = line.substr(0, line.find_last_of(','));
|
||||
|
||||
// discard lines without at least two characters (quotes)
|
||||
if (line.size() < 2)
|
||||
|
||||
@ -54,7 +54,7 @@ float make_float(uint32_t sign_bit, uint32_t biased_exponent, uint32_t significa
|
||||
}
|
||||
|
||||
// ldexp -- convert f * 2^e to IEEE single precision
|
||||
static float make_float(uint64_t f, int e)
|
||||
float make_float(uint64_t f, int e)
|
||||
{
|
||||
constexpr uint64_t kHiddenBit = 0x00800000;
|
||||
constexpr uint64_t kSignificandMask = 0x007FFFFF;
|
||||
@ -90,7 +90,7 @@ static float make_float(uint64_t f, int e)
|
||||
return reinterpret_bits<float>(static_cast<uint32_t>(bits));
|
||||
}
|
||||
|
||||
static double make_double(uint64_t sign_bit, uint64_t biased_exponent, uint64_t significand)
|
||||
double make_double(uint64_t sign_bit, uint64_t biased_exponent, uint64_t significand)
|
||||
{
|
||||
assert(sign_bit == 0 || sign_bit == 1);
|
||||
assert(biased_exponent <= 0x7FF);
|
||||
@ -106,7 +106,7 @@ static double make_double(uint64_t sign_bit, uint64_t biased_exponent, uint64_t
|
||||
}
|
||||
|
||||
// ldexp -- convert f * 2^e to IEEE double precision
|
||||
static double make_double(uint64_t f, int e)
|
||||
double make_double(uint64_t f, int e)
|
||||
{
|
||||
constexpr uint64_t kHiddenBit = 0x0010000000000000;
|
||||
constexpr uint64_t kSignificandMask = 0x000FFFFFFFFFFFFF;
|
||||
@ -141,7 +141,7 @@ static double make_double(uint64_t f, int e)
|
||||
uint64_t bits = (f & kSignificandMask) | (biased_exponent << kPhysicalSignificandSize);
|
||||
return reinterpret_bits<double>(bits);
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
TEST_CASE("digit gen")
|
||||
{
|
||||
|
||||
@ -302,7 +302,7 @@ TEST_CASE("UBJSON")
|
||||
|
||||
// check individual bytes
|
||||
CHECK(result[0] == 'I');
|
||||
int16_t restored = static_cast<int16_t>(((result[1] << 8) + result[2]));
|
||||
auto restored = static_cast<int16_t>(((result[1] << 8) + result[2]));
|
||||
CHECK(restored == i);
|
||||
|
||||
// roundtrip
|
||||
@ -323,7 +323,7 @@ TEST_CASE("UBJSON")
|
||||
|
||||
// check individual bytes
|
||||
CHECK(result[0] == 'I');
|
||||
int16_t restored = static_cast<int16_t>(((result[1] << 8) + result[2]));
|
||||
auto restored = static_cast<int16_t>(((result[1] << 8) + result[2]));
|
||||
CHECK(restored == -9263);
|
||||
|
||||
// roundtrip
|
||||
@ -455,7 +455,7 @@ TEST_CASE("UBJSON")
|
||||
|
||||
// check individual bytes
|
||||
CHECK(result[0] == 'I');
|
||||
uint16_t restored = static_cast<uint16_t>(static_cast<uint8_t>(result[1]) * 256 + static_cast<uint8_t>(result[2]));
|
||||
auto restored = static_cast<uint16_t>(static_cast<uint8_t>(result[1]) * 256 + static_cast<uint8_t>(result[2]));
|
||||
CHECK(restored == i);
|
||||
|
||||
// roundtrip
|
||||
@ -583,7 +583,7 @@ TEST_CASE("UBJSON")
|
||||
|
||||
// check individual bytes
|
||||
CHECK(result[0] == 'i');
|
||||
uint8_t restored = static_cast<uint8_t>(result[1]);
|
||||
auto restored = static_cast<uint8_t>(result[1]);
|
||||
CHECK(restored == i);
|
||||
|
||||
// roundtrip
|
||||
@ -616,7 +616,7 @@ TEST_CASE("UBJSON")
|
||||
|
||||
// check individual bytes
|
||||
CHECK(result[0] == 'U');
|
||||
uint8_t restored = static_cast<uint8_t>(result[1]);
|
||||
auto restored = static_cast<uint8_t>(result[1]);
|
||||
CHECK(restored == i);
|
||||
|
||||
// roundtrip
|
||||
@ -650,7 +650,7 @@ TEST_CASE("UBJSON")
|
||||
|
||||
// check individual bytes
|
||||
CHECK(result[0] == 'I');
|
||||
uint16_t restored = static_cast<uint16_t>(static_cast<uint8_t>(result[1]) * 256 + static_cast<uint8_t>(result[2]));
|
||||
auto restored = static_cast<uint16_t>(static_cast<uint8_t>(result[1]) * 256 + static_cast<uint8_t>(result[2]));
|
||||
CHECK(restored == i);
|
||||
|
||||
// roundtrip
|
||||
@ -1535,7 +1535,7 @@ TEST_CASE("UBJSON")
|
||||
{
|
||||
SECTION("size=false type=false")
|
||||
{
|
||||
json j = json::parse("{\"a\": {\"b\": {\"c\": {}}}}");
|
||||
json j = json::parse(R"({"a": {"b": {"c": {}}}})");
|
||||
std::vector<uint8_t> expected =
|
||||
{
|
||||
'{', 'i', 1, 'a', '{', 'i', 1, 'b', '{', 'i', 1, 'c', '{', '}', '}', '}', '}'
|
||||
@ -1550,7 +1550,7 @@ TEST_CASE("UBJSON")
|
||||
|
||||
SECTION("size=true type=false")
|
||||
{
|
||||
json j = json::parse("{\"a\": {\"b\": {\"c\": {}}}}");
|
||||
json j = json::parse(R"({"a": {"b": {"c": {}}}})");
|
||||
std::vector<uint8_t> expected =
|
||||
{
|
||||
'{', '#', 'i', 1, 'i', 1, 'a', '{', '#', 'i', 1, 'i', 1, 'b', '{', '#', 'i', 1, 'i', 1, 'c', '{', '#', 'i', 0
|
||||
@ -1565,7 +1565,7 @@ TEST_CASE("UBJSON")
|
||||
|
||||
SECTION("size=true type=true")
|
||||
{
|
||||
json j = json::parse("{\"a\": {\"b\": {\"c\": {}}}}");
|
||||
json j = json::parse(R"({"a": {"b": {"c": {}}}})");
|
||||
std::vector<uint8_t> expected =
|
||||
{
|
||||
'{', '$', '{', '#', 'i', 1, 'i', 1, 'a', '$', '{', '#', 'i', 1, 'i', 1, 'b', '$', '{', '#', 'i', 1, 'i', 1, 'c', '#', 'i', 0
|
||||
@ -1624,7 +1624,7 @@ TEST_CASE("UBJSON")
|
||||
CHECK_THROWS_AS(_ = json::from_ubjson(v_ubjson), json::out_of_range&);
|
||||
|
||||
json j;
|
||||
nlohmann::detail::json_sax_dom_callback_parser<json> scp(j, [](int, json::parse_event_t, const json&)
|
||||
nlohmann::detail::json_sax_dom_callback_parser<json> scp(j, [](int /*unused*/, json::parse_event_t /*unused*/, const json& /*unused*/)
|
||||
{
|
||||
return true;
|
||||
});
|
||||
@ -2439,7 +2439,7 @@ TEST_CASE("all UBJSON first bytes")
|
||||
// check that parse_error.112 is only thrown if the
|
||||
// first byte is not in the supported set
|
||||
INFO_WITH_TEMP(e.what());
|
||||
if (std::find(supported.begin(), supported.end(), byte) == supported.end())
|
||||
if (supported.find(byte) == supported.end())
|
||||
{
|
||||
CHECK(e.id == 112);
|
||||
}
|
||||
|
||||
@ -32,7 +32,6 @@ SOFTWARE.
|
||||
#include <nlohmann/json.hpp>
|
||||
using nlohmann::json;
|
||||
|
||||
#include <array>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user