🚨 fix warnings from Clang-Tidy
This commit is contained in:
parent
0a27d1cf59
commit
cb28e76aa4
@ -152,7 +152,7 @@ class alt_string
|
||||
private:
|
||||
std::string str_impl {};
|
||||
|
||||
friend bool ::operator<(const char*, const alt_string&);
|
||||
friend bool ::operator<(const char* /*op1*/, const alt_string& /*op2*/);
|
||||
};
|
||||
|
||||
void int_to_string(alt_string& target, std::size_t value)
|
||||
@ -233,24 +233,24 @@ TEST_CASE("alternative string type")
|
||||
|
||||
SECTION("parse")
|
||||
{
|
||||
auto doc = alt_json::parse("{\"foo\": \"bar\"}");
|
||||
auto doc = alt_json::parse(R"({"foo": "bar"})");
|
||||
alt_string dump = doc.dump();
|
||||
CHECK(dump == R"({"foo":"bar"})");
|
||||
}
|
||||
|
||||
SECTION("items")
|
||||
{
|
||||
auto doc = alt_json::parse("{\"foo\": \"bar\"}");
|
||||
auto doc = alt_json::parse(R"({"foo": "bar"})");
|
||||
|
||||
for ( auto item : doc.items() )
|
||||
for (const auto& item : doc.items())
|
||||
{
|
||||
CHECK( item.key() == "foo" );
|
||||
CHECK( item.value() == "bar" );
|
||||
CHECK(item.key() == "foo");
|
||||
CHECK(item.value() == "bar");
|
||||
}
|
||||
|
||||
auto doc_array = alt_json::parse("[\"foo\", \"bar\"]");
|
||||
auto doc_array = alt_json::parse(R"(["foo", "bar"])");
|
||||
|
||||
for ( auto item : doc_array.items() )
|
||||
for (const auto& item : doc_array.items())
|
||||
{
|
||||
if (item.key() == "0" )
|
||||
{
|
||||
@ -258,11 +258,11 @@ TEST_CASE("alternative string type")
|
||||
}
|
||||
else if (item.key() == "1" )
|
||||
{
|
||||
CHECK( item.value() == "bar" );
|
||||
CHECK(item.value() == "bar");
|
||||
}
|
||||
else
|
||||
{
|
||||
CHECK( false );
|
||||
CHECK(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -683,42 +683,42 @@ class SaxCountdown
|
||||
return events_left-- > 0;
|
||||
}
|
||||
|
||||
bool boolean(bool)
|
||||
bool boolean(bool /*unused*/)
|
||||
{
|
||||
return events_left-- > 0;
|
||||
}
|
||||
|
||||
bool number_integer(json::number_integer_t)
|
||||
bool number_integer(json::number_integer_t /*unused*/)
|
||||
{
|
||||
return events_left-- > 0;
|
||||
}
|
||||
|
||||
bool number_unsigned(json::number_unsigned_t)
|
||||
bool number_unsigned(json::number_unsigned_t /*unused*/)
|
||||
{
|
||||
return events_left-- > 0;
|
||||
}
|
||||
|
||||
bool number_float(json::number_float_t, const std::string&)
|
||||
bool number_float(json::number_float_t /*unused*/, const std::string& /*unused*/)
|
||||
{
|
||||
return events_left-- > 0;
|
||||
}
|
||||
|
||||
bool string(std::string&)
|
||||
bool string(std::string& /*unused*/)
|
||||
{
|
||||
return events_left-- > 0;
|
||||
}
|
||||
|
||||
bool binary(std::vector<std::uint8_t>&)
|
||||
bool binary(std::vector<std::uint8_t>& /*unused*/)
|
||||
{
|
||||
return events_left-- > 0;
|
||||
}
|
||||
|
||||
bool start_object(std::size_t)
|
||||
bool start_object(std::size_t /*unused*/)
|
||||
{
|
||||
return events_left-- > 0;
|
||||
}
|
||||
|
||||
bool key(std::string&)
|
||||
bool key(std::string& /*unused*/)
|
||||
{
|
||||
return events_left-- > 0;
|
||||
}
|
||||
@ -728,7 +728,7 @@ class SaxCountdown
|
||||
return events_left-- > 0;
|
||||
}
|
||||
|
||||
bool start_array(std::size_t)
|
||||
bool start_array(std::size_t /*unused*/)
|
||||
{
|
||||
return events_left-- > 0;
|
||||
}
|
||||
@ -738,7 +738,7 @@ class SaxCountdown
|
||||
return events_left-- > 0;
|
||||
}
|
||||
|
||||
bool parse_error(std::size_t, const std::string&, const json::exception&)
|
||||
bool parse_error(std::size_t /*unused*/, const std::string& /*unused*/, const json::exception& /*unused*/)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@ -746,7 +746,7 @@ class SaxCountdown
|
||||
private:
|
||||
int events_left = 0;
|
||||
};
|
||||
}
|
||||
} // namespace
|
||||
|
||||
TEST_CASE("Incomplete BSON Input")
|
||||
{
|
||||
|
||||
@ -41,7 +41,7 @@ bool f(A a, B b, U u = U())
|
||||
{
|
||||
return u(a, b);
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
TEST_CASE("lexicographical comparison operators")
|
||||
{
|
||||
@ -143,10 +143,10 @@ TEST_CASE("lexicographical comparison operators")
|
||||
|
||||
// comparison with discarded elements
|
||||
json j_discarded(json::value_t::discarded);
|
||||
for (size_t i = 0; i < j_values.size(); ++i)
|
||||
for (const auto& v : j_values)
|
||||
{
|
||||
CHECK( (j_values[i] == j_discarded) == false);
|
||||
CHECK( (j_discarded == j_values[i]) == false);
|
||||
CHECK( (v == j_discarded) == false);
|
||||
CHECK( (j_discarded == v) == false);
|
||||
CHECK( (j_discarded == j_discarded) == false);
|
||||
}
|
||||
|
||||
|
||||
@ -188,19 +188,19 @@ TEST_CASE("other constructors and destructor")
|
||||
{
|
||||
SECTION("object")
|
||||
{
|
||||
auto j = new json {{"foo", 1}, {"bar", false}};
|
||||
auto* j = new json {{"foo", 1}, {"bar", false}};
|
||||
delete j;
|
||||
}
|
||||
|
||||
SECTION("array")
|
||||
{
|
||||
auto j = new json {"foo", 1, 1u, false, 23.42};
|
||||
auto* j = new json {"foo", 1, 1u, false, 23.42};
|
||||
delete j;
|
||||
}
|
||||
|
||||
SECTION("string")
|
||||
{
|
||||
auto j = new json("Hello world");
|
||||
auto* j = new json("Hello world");
|
||||
delete j;
|
||||
}
|
||||
}
|
||||
|
||||
@ -37,7 +37,7 @@ using nlohmann::json;
|
||||
|
||||
namespace
|
||||
{
|
||||
void check_escaped(const char* original, const char* escaped = "", const bool ensure_ascii = false);
|
||||
void check_escaped(const char* original, const char* escaped = "", bool ensure_ascii = false);
|
||||
void check_escaped(const char* original, const char* escaped, const bool ensure_ascii)
|
||||
{
|
||||
std::stringstream ss;
|
||||
@ -45,7 +45,7 @@ void check_escaped(const char* original, const char* escaped, const bool ensure_
|
||||
s.dump_escaped(original, ensure_ascii);
|
||||
CHECK(ss.str() == escaped);
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
TEST_CASE("convenience functions")
|
||||
{
|
||||
|
||||
@ -1258,7 +1258,7 @@ TEST_CASE("JSON patch")
|
||||
|
||||
SECTION("Tests from github.com/json-patch/json-patch-tests")
|
||||
{
|
||||
for (auto filename :
|
||||
for (const auto* filename :
|
||||
{
|
||||
TEST_DATA_DIRECTORY "/json-patch-tests/spec_tests.json",
|
||||
TEST_DATA_DIRECTORY "/json-patch-tests/tests.json"
|
||||
|
||||
@ -527,7 +527,7 @@ TEST_CASE("JSON pointers")
|
||||
|
||||
SECTION("string representation")
|
||||
{
|
||||
for (auto ptr :
|
||||
for (const auto* ptr :
|
||||
{"", "/foo", "/foo/0", "/", "/a~1b", "/c%d", "/e^f", "/g|h", "/i\\j", "/k\"l", "/ ", "/m~0n"
|
||||
})
|
||||
{
|
||||
|
||||
@ -52,42 +52,42 @@ class SaxCountdown
|
||||
return events_left-- > 0;
|
||||
}
|
||||
|
||||
bool boolean(bool)
|
||||
bool boolean(bool /*unused*/)
|
||||
{
|
||||
return events_left-- > 0;
|
||||
}
|
||||
|
||||
bool number_integer(json::number_integer_t)
|
||||
bool number_integer(json::number_integer_t /*unused*/)
|
||||
{
|
||||
return events_left-- > 0;
|
||||
}
|
||||
|
||||
bool number_unsigned(json::number_unsigned_t)
|
||||
bool number_unsigned(json::number_unsigned_t /*unused*/)
|
||||
{
|
||||
return events_left-- > 0;
|
||||
}
|
||||
|
||||
bool number_float(json::number_float_t, const std::string&)
|
||||
bool number_float(json::number_float_t /*unused*/, const std::string& /*unused*/)
|
||||
{
|
||||
return events_left-- > 0;
|
||||
}
|
||||
|
||||
bool string(std::string&)
|
||||
bool string(std::string& /*unused*/)
|
||||
{
|
||||
return events_left-- > 0;
|
||||
}
|
||||
|
||||
bool binary(std::vector<std::uint8_t>&)
|
||||
bool binary(std::vector<std::uint8_t>& /*unused*/)
|
||||
{
|
||||
return events_left-- > 0;
|
||||
}
|
||||
|
||||
bool start_object(std::size_t)
|
||||
bool start_object(std::size_t /*unused*/)
|
||||
{
|
||||
return events_left-- > 0;
|
||||
}
|
||||
|
||||
bool key(std::string&)
|
||||
bool key(std::string& /*unused*/)
|
||||
{
|
||||
return events_left-- > 0;
|
||||
}
|
||||
@ -97,7 +97,7 @@ class SaxCountdown
|
||||
return events_left-- > 0;
|
||||
}
|
||||
|
||||
bool start_array(std::size_t)
|
||||
bool start_array(std::size_t /*unused*/)
|
||||
{
|
||||
return events_left-- > 0;
|
||||
}
|
||||
@ -107,7 +107,7 @@ class SaxCountdown
|
||||
return events_left-- > 0;
|
||||
}
|
||||
|
||||
bool parse_error(std::size_t, const std::string&, const json::exception&)
|
||||
bool parse_error(std::size_t /*unused*/, const std::string& /*unused*/, const json::exception& /*unused*/)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@ -258,7 +258,7 @@ TEST_CASE("MessagePack")
|
||||
|
||||
// check individual bytes
|
||||
CHECK(result[0] == 0xcc);
|
||||
uint8_t restored = static_cast<uint8_t>(result[1]);
|
||||
auto restored = static_cast<uint8_t>(result[1]);
|
||||
CHECK(restored == i);
|
||||
|
||||
// roundtrip
|
||||
@ -293,7 +293,7 @@ TEST_CASE("MessagePack")
|
||||
|
||||
// check individual bytes
|
||||
CHECK(result[0] == 0xcd);
|
||||
uint16_t restored = static_cast<uint16_t>(static_cast<uint8_t>(result[1]) * 256 + static_cast<uint8_t>(result[2]));
|
||||
auto restored = static_cast<uint16_t>(static_cast<uint8_t>(result[1]) * 256 + static_cast<uint8_t>(result[2]));
|
||||
CHECK(restored == i);
|
||||
|
||||
// roundtrip
|
||||
@ -436,7 +436,7 @@ TEST_CASE("MessagePack")
|
||||
const auto result = json::to_msgpack(j);
|
||||
CHECK(result == expected);
|
||||
|
||||
int16_t restored = static_cast<int16_t>((result[1] << 8) + result[2]);
|
||||
auto restored = static_cast<int16_t>((result[1] << 8) + result[2]);
|
||||
CHECK(restored == -9263);
|
||||
|
||||
// roundtrip
|
||||
@ -469,7 +469,7 @@ TEST_CASE("MessagePack")
|
||||
|
||||
// check individual bytes
|
||||
CHECK(result[0] == 0xd1);
|
||||
int16_t restored = static_cast<int16_t>((result[1] << 8) + result[2]);
|
||||
auto restored = static_cast<int16_t>((result[1] << 8) + result[2]);
|
||||
CHECK(restored == i);
|
||||
|
||||
// roundtrip
|
||||
@ -630,7 +630,7 @@ TEST_CASE("MessagePack")
|
||||
|
||||
// check individual bytes
|
||||
CHECK(result[0] == 0xcc);
|
||||
uint8_t restored = static_cast<uint8_t>(result[1]);
|
||||
auto restored = static_cast<uint8_t>(result[1]);
|
||||
CHECK(restored == i);
|
||||
|
||||
// roundtrip
|
||||
@ -664,7 +664,7 @@ TEST_CASE("MessagePack")
|
||||
|
||||
// check individual bytes
|
||||
CHECK(result[0] == 0xcd);
|
||||
uint16_t restored = static_cast<uint16_t>(static_cast<uint8_t>(result[1]) * 256 + static_cast<uint8_t>(result[2]));
|
||||
auto restored = static_cast<uint16_t>(static_cast<uint8_t>(result[1]) * 256 + static_cast<uint8_t>(result[2]));
|
||||
CHECK(restored == i);
|
||||
|
||||
// roundtrip
|
||||
@ -1088,7 +1088,7 @@ TEST_CASE("MessagePack")
|
||||
|
||||
SECTION("{\"a\": {\"b\": {\"c\": {}}}}")
|
||||
{
|
||||
json j = json::parse("{\"a\": {\"b\": {\"c\": {}}}}");
|
||||
json j = json::parse(R"({"a": {"b": {"c": {}}}})");
|
||||
std::vector<uint8_t> expected =
|
||||
{
|
||||
0x81, 0xa1, 0x61, 0x81, 0xa1, 0x62, 0x81, 0xa1, 0x63, 0x80
|
||||
@ -1870,7 +1870,7 @@ TEST_CASE("MessagePack roundtrips" * doctest::skip())
|
||||
// parse MessagePack file
|
||||
auto packed = utils::read_binary_file(filename + ".msgpack");
|
||||
|
||||
if (!exclude_packed.count(filename))
|
||||
if (exclude_packed.count(filename) == 0u)
|
||||
{
|
||||
{
|
||||
INFO_WITH_TEMP(filename + ": output adapters: std::vector<uint8_t>");
|
||||
|
||||
@ -49,6 +49,7 @@ TEST_CASE("ordered_map")
|
||||
std::map<std::string, std::string> m {{"eins", "one"}, {"zwei", "two"}, {"drei", "three"}};
|
||||
ordered_map<std::string, std::string> om(m.begin(), m.end());
|
||||
const auto com = om;
|
||||
om.clear(); // silence a warning by forbidding having "const auto& com = om;"
|
||||
CHECK(com.size() == 3);
|
||||
}
|
||||
}
|
||||
|
||||
@ -52,7 +52,7 @@ TEST_CASE("README" * doctest::skip())
|
||||
{
|
||||
{
|
||||
// redirect std::cout for the README file
|
||||
auto old_cout_buffer = std::cout.rdbuf();
|
||||
auto* old_cout_buffer = std::cout.rdbuf();
|
||||
std::ostringstream new_stream;
|
||||
std::cout.rdbuf(new_stream.rdbuf());
|
||||
{
|
||||
|
||||
@ -56,11 +56,11 @@ TEST_CASE("reference access")
|
||||
json value = {{"one", 1}, {"two", 2}};
|
||||
|
||||
// check if references are returned correctly
|
||||
test_type& p1 = value.get_ref<test_type&>();
|
||||
auto& p1 = value.get_ref<test_type&>();
|
||||
CHECK(&p1 == value.get_ptr<test_type*>());
|
||||
CHECK(p1 == value.get<test_type>());
|
||||
|
||||
const test_type& p2 = value.get_ref<const test_type&>();
|
||||
const auto& p2 = value.get_ref<const test_type&>();
|
||||
CHECK(&p2 == value.get_ptr<const test_type*>());
|
||||
CHECK(p2 == value.get<test_type>());
|
||||
|
||||
@ -95,7 +95,7 @@ TEST_CASE("reference access")
|
||||
// test_type& p1 = value.get_ref<test_type&>();
|
||||
|
||||
// check if references are returned correctly
|
||||
const test_type& p2 = value.get_ref<const test_type&>();
|
||||
const auto& p2 = value.get_ref<const test_type&>();
|
||||
CHECK(&p2 == value.get_ptr<const test_type*>());
|
||||
CHECK(p2 == value.get<test_type>());
|
||||
}
|
||||
@ -106,11 +106,11 @@ TEST_CASE("reference access")
|
||||
json value = {1, 2, 3, 4};
|
||||
|
||||
// check if references are returned correctly
|
||||
test_type& p1 = value.get_ref<test_type&>();
|
||||
auto& p1 = value.get_ref<test_type&>();
|
||||
CHECK(&p1 == value.get_ptr<test_type*>());
|
||||
CHECK(p1 == value.get<test_type>());
|
||||
|
||||
const test_type& p2 = value.get_ref<const test_type&>();
|
||||
const auto& p2 = value.get_ref<const test_type&>();
|
||||
CHECK(&p2 == value.get_ptr<const test_type*>());
|
||||
CHECK(p2 == value.get<test_type>());
|
||||
|
||||
@ -142,11 +142,11 @@ TEST_CASE("reference access")
|
||||
json value = "hello";
|
||||
|
||||
// check if references are returned correctly
|
||||
test_type& p1 = value.get_ref<test_type&>();
|
||||
auto& p1 = value.get_ref<test_type&>();
|
||||
CHECK(&p1 == value.get_ptr<test_type*>());
|
||||
CHECK(p1 == value.get<test_type>());
|
||||
|
||||
const test_type& p2 = value.get_ref<const test_type&>();
|
||||
const auto& p2 = value.get_ref<const test_type&>();
|
||||
CHECK(&p2 == value.get_ptr<const test_type*>());
|
||||
CHECK(p2 == value.get<test_type>());
|
||||
|
||||
@ -178,11 +178,11 @@ TEST_CASE("reference access")
|
||||
json value = false;
|
||||
|
||||
// check if references are returned correctly
|
||||
test_type& p1 = value.get_ref<test_type&>();
|
||||
auto& p1 = value.get_ref<test_type&>();
|
||||
CHECK(&p1 == value.get_ptr<test_type*>());
|
||||
CHECK(p1 == value.get<test_type>());
|
||||
|
||||
const test_type& p2 = value.get_ref<const test_type&>();
|
||||
const auto& p2 = value.get_ref<const test_type&>();
|
||||
CHECK(&p2 == value.get_ptr<const test_type*>());
|
||||
CHECK(p2 == value.get<test_type>());
|
||||
|
||||
@ -214,11 +214,11 @@ TEST_CASE("reference access")
|
||||
json value = -23;
|
||||
|
||||
// check if references are returned correctly
|
||||
test_type& p1 = value.get_ref<test_type&>();
|
||||
auto& p1 = value.get_ref<test_type&>();
|
||||
CHECK(&p1 == value.get_ptr<test_type*>());
|
||||
CHECK(p1 == value.get<test_type>());
|
||||
|
||||
const test_type& p2 = value.get_ref<const test_type&>();
|
||||
const auto& p2 = value.get_ref<const test_type&>();
|
||||
CHECK(&p2 == value.get_ptr<const test_type*>());
|
||||
CHECK(p2 == value.get<test_type>());
|
||||
|
||||
@ -250,11 +250,11 @@ TEST_CASE("reference access")
|
||||
json value = 23u;
|
||||
|
||||
// check if references are returned correctly
|
||||
test_type& p1 = value.get_ref<test_type&>();
|
||||
auto& p1 = value.get_ref<test_type&>();
|
||||
CHECK(&p1 == value.get_ptr<test_type*>());
|
||||
CHECK(p1 == value.get<test_type>());
|
||||
|
||||
const test_type& p2 = value.get_ref<const test_type&>();
|
||||
const auto& p2 = value.get_ref<const test_type&>();
|
||||
CHECK(&p2 == value.get_ptr<const test_type*>());
|
||||
CHECK(p2 == value.get<test_type>());
|
||||
|
||||
@ -286,11 +286,11 @@ TEST_CASE("reference access")
|
||||
json value = 42.23;
|
||||
|
||||
// check if references are returned correctly
|
||||
test_type& p1 = value.get_ref<test_type&>();
|
||||
auto& p1 = value.get_ref<test_type&>();
|
||||
CHECK(&p1 == value.get_ptr<test_type*>());
|
||||
CHECK(p1 == value.get<test_type>());
|
||||
|
||||
const test_type& p2 = value.get_ref<const test_type&>();
|
||||
const auto& p2 = value.get_ref<const test_type&>();
|
||||
CHECK(&p2 == value.get_ptr<const test_type*>());
|
||||
CHECK(p2 == value.get<test_type>());
|
||||
|
||||
|
||||
@ -122,7 +122,7 @@ struct adl_serializer<NonDefaultFromJsonStruct>
|
||||
return {};
|
||||
}
|
||||
};
|
||||
}
|
||||
} // namespace nlohmann
|
||||
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
// for #1805
|
||||
@ -139,7 +139,7 @@ TEST_CASE("regression tests 2")
|
||||
{
|
||||
SECTION("issue #1001 - Fix memory leak during parser callback")
|
||||
{
|
||||
auto geojsonExample = R"(
|
||||
const auto* geojsonExample = R"(
|
||||
{ "type": "FeatureCollection",
|
||||
"features": [
|
||||
{ "type": "Feature",
|
||||
@ -174,7 +174,7 @@ TEST_CASE("regression tests 2")
|
||||
]
|
||||
})";
|
||||
|
||||
json::parser_callback_t cb = [&](int, json::parse_event_t event, json & parsed)
|
||||
json::parser_callback_t cb = [&](int /*level*/, json::parse_event_t event, json & parsed)
|
||||
{
|
||||
// skip uninteresting events
|
||||
if (event == json::parse_event_t::value && !parsed.is_primitive())
|
||||
@ -290,7 +290,7 @@ TEST_CASE("regression tests 2")
|
||||
json dump_test;
|
||||
dump_test["1"] = std::string(length, -1);
|
||||
|
||||
std::string expected = "{\"1\":\"";
|
||||
std::string expected = R"({"1":")";
|
||||
for (int i = 0; i < length; ++i)
|
||||
{
|
||||
expected += "\\ufffd";
|
||||
@ -307,7 +307,7 @@ TEST_CASE("regression tests 2")
|
||||
json dump_test;
|
||||
dump_test["1"] = std::string(length, -2);
|
||||
|
||||
std::string expected = "{\"1\":\"";
|
||||
std::string expected = R"({"1":")";
|
||||
for (int i = 0; i < length; ++i)
|
||||
{
|
||||
expected += "\xEF\xBF\xBD";
|
||||
@ -340,9 +340,9 @@ TEST_CASE("regression tests 2")
|
||||
-54, -28, -26
|
||||
};
|
||||
std::string s;
|
||||
for (unsigned i = 0; i < sizeof(data) / sizeof(int); i++)
|
||||
for (int i : data)
|
||||
{
|
||||
s += static_cast<char>(data[i]);
|
||||
s += static_cast<char>(i);
|
||||
}
|
||||
dump_test["1"] = s;
|
||||
dump_test.dump(-1, ' ', true, nlohmann::json::error_handler_t::replace);
|
||||
|
||||
@ -38,7 +38,7 @@ using nlohmann::detail::dtoa_impl::reinterpret_bits;
|
||||
|
||||
namespace
|
||||
{
|
||||
static float make_float(uint32_t sign_bit, uint32_t biased_exponent, uint32_t significand)
|
||||
float make_float(uint32_t sign_bit, uint32_t biased_exponent, uint32_t significand)
|
||||
{
|
||||
assert(sign_bit == 0 || sign_bit == 1);
|
||||
assert(biased_exponent <= 0xFF);
|
||||
|
||||
@ -34,8 +34,10 @@ using nlohmann::json;
|
||||
|
||||
#include <array>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
|
||||
namespace udt
|
||||
{
|
||||
@ -55,40 +57,40 @@ struct age
|
||||
struct name
|
||||
{
|
||||
std::string m_val;
|
||||
name(const std::string rhs = "") : m_val(rhs) {}
|
||||
name(std::string rhs = "") : m_val(std::move(rhs)) {}
|
||||
};
|
||||
|
||||
struct address
|
||||
{
|
||||
std::string m_val;
|
||||
address(const std::string rhs = "") : m_val(rhs) {}
|
||||
address(std::string rhs = "") : m_val(std::move(rhs)) {}
|
||||
};
|
||||
|
||||
struct person
|
||||
{
|
||||
age m_age;
|
||||
name m_name;
|
||||
country m_country;
|
||||
person() : m_age(), m_name(), m_country() {}
|
||||
person(const age& a, const name& n, const country& c) : m_age(a), m_name(n), m_country(c) {}
|
||||
country m_country{};
|
||||
person() = default;
|
||||
person(const age& a, name n, const country& c) : m_age(a), m_name(std::move(n)), m_country(c) {}
|
||||
};
|
||||
|
||||
struct contact
|
||||
{
|
||||
person m_person;
|
||||
address m_address;
|
||||
contact() : m_person(), m_address() {}
|
||||
contact(const person& p, const address& a) : m_person(p), m_address(a) {}
|
||||
contact() = default;
|
||||
contact(person p, address a) : m_person(std::move(p)), m_address(std::move(a)) {}
|
||||
};
|
||||
|
||||
struct contact_book
|
||||
{
|
||||
name m_book_name;
|
||||
std::vector<contact> m_contacts;
|
||||
contact_book() : m_book_name(), m_contacts() {}
|
||||
contact_book(const name& n, const std::vector<contact>& c) : m_book_name(n), m_contacts(c) {}
|
||||
contact_book() = default;
|
||||
contact_book(name n, std::vector<contact> c) : m_book_name(std::move(n)), m_contacts(std::move(c)) {}
|
||||
};
|
||||
}
|
||||
} // namespace udt
|
||||
|
||||
// to_json methods
|
||||
namespace udt
|
||||
@ -178,7 +180,7 @@ static bool operator==(const contact_book& lhs, const contact_book& rhs)
|
||||
return std::tie(lhs.m_book_name, lhs.m_contacts) ==
|
||||
std::tie(rhs.m_book_name, rhs.m_contacts);
|
||||
}
|
||||
}
|
||||
} // namespace udt
|
||||
|
||||
// from_json methods
|
||||
namespace udt
|
||||
@ -207,7 +209,7 @@ static void from_json(const BasicJsonType& j, country& c)
|
||||
};
|
||||
|
||||
const auto it = m.find(str);
|
||||
// TODO test exceptions
|
||||
// TODO(nlohmann) test exceptions
|
||||
c = it->second;
|
||||
}
|
||||
|
||||
@ -235,7 +237,7 @@ static void from_json(const nlohmann::json& j, contact_book& cb)
|
||||
cb.m_book_name = j["name"].get<name>();
|
||||
cb.m_contacts = j["contacts"].get<std::vector<contact>>();
|
||||
}
|
||||
}
|
||||
} // namespace udt
|
||||
|
||||
TEST_CASE("basic usage" * doctest::test_suite("udt"))
|
||||
{
|
||||
@ -345,10 +347,10 @@ namespace udt
|
||||
struct legacy_type
|
||||
{
|
||||
std::string number;
|
||||
legacy_type() : number() {}
|
||||
legacy_type(const std::string& n) : number(n) {}
|
||||
legacy_type() = default;
|
||||
legacy_type(std::string n) : number(std::move(n)) {}
|
||||
};
|
||||
}
|
||||
} // namespace udt
|
||||
|
||||
namespace nlohmann
|
||||
{
|
||||
@ -393,7 +395,7 @@ struct adl_serializer<udt::legacy_type>
|
||||
l.number = std::to_string(j.get<int>());
|
||||
}
|
||||
};
|
||||
}
|
||||
} // namespace nlohmann
|
||||
|
||||
TEST_CASE("adl_serializer specialization" * doctest::test_suite("udt"))
|
||||
{
|
||||
@ -453,23 +455,23 @@ template <>
|
||||
struct adl_serializer<std::vector<float>>
|
||||
{
|
||||
using type = std::vector<float>;
|
||||
static void to_json(json& j, const type&)
|
||||
static void to_json(json& j, const type& /*type*/)
|
||||
{
|
||||
j = "hijacked!";
|
||||
}
|
||||
|
||||
static void from_json(const json&, type& opt)
|
||||
static void from_json(const json& /*unnamed*/, type& opt)
|
||||
{
|
||||
opt = {42.0, 42.0, 42.0};
|
||||
}
|
||||
|
||||
// preferred version
|
||||
static type from_json(const json&)
|
||||
static type from_json(const json& /*unnamed*/)
|
||||
{
|
||||
return {4.0, 5.0, 6.0};
|
||||
}
|
||||
};
|
||||
}
|
||||
} // namespace nlohmann
|
||||
|
||||
TEST_CASE("even supported types can be specialized" * doctest::test_suite("udt"))
|
||||
{
|
||||
@ -504,13 +506,11 @@ struct adl_serializer<std::unique_ptr<T>>
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
else
|
||||
{
|
||||
return std::unique_ptr<T>(new T(j.get<T>()));
|
||||
}
|
||||
|
||||
return std::unique_ptr<T>(new T(j.get<T>()));
|
||||
}
|
||||
};
|
||||
}
|
||||
} // namespace nlohmann
|
||||
|
||||
TEST_CASE("Non-copyable types" * doctest::test_suite("udt"))
|
||||
{
|
||||
@ -566,8 +566,8 @@ struct pod_serializer
|
||||
std::is_pod<U>::value && std::is_class<U>::value, int >::type = 0 >
|
||||
static void from_json(const BasicJsonType& j, U& t)
|
||||
{
|
||||
std::uint64_t value;
|
||||
// TODO The following block is no longer relevant in this serializer, make another one that shows the issue
|
||||
std::uint64_t value = 0;
|
||||
// The following block is no longer relevant in this serializer, make another one that shows the issue
|
||||
// the problem arises only when one from_json method is defined without any constraint
|
||||
//
|
||||
// Why cannot we simply use: j.get<std::uint64_t>() ?
|
||||
@ -582,7 +582,7 @@ struct pod_serializer
|
||||
// calling get calls from_json, for now, we cannot do this in custom
|
||||
// serializers
|
||||
nlohmann::from_json(j, value);
|
||||
auto bytes = static_cast<char*>(static_cast<void*>(&value));
|
||||
auto* bytes = static_cast<char*>(static_cast<void*>(&value));
|
||||
std::memcpy(&t, bytes, sizeof(value));
|
||||
}
|
||||
|
||||
@ -601,8 +601,8 @@ struct pod_serializer
|
||||
std::is_pod<U>::value && std::is_class<U>::value, int >::type = 0 >
|
||||
static void to_json(BasicJsonType& j, const T& t) noexcept
|
||||
{
|
||||
auto bytes = static_cast< const unsigned char*>(static_cast<const void*>(&t));
|
||||
std::uint64_t value;
|
||||
const auto* bytes = static_cast< const unsigned char*>(static_cast<const void*>(&t));
|
||||
std::uint64_t value = 0;
|
||||
std::memcpy(&value, bytes, sizeof(value));
|
||||
nlohmann::to_json(j, value);
|
||||
}
|
||||
@ -620,8 +620,8 @@ struct small_pod
|
||||
struct non_pod
|
||||
{
|
||||
std::string s;
|
||||
non_pod() : s() {}
|
||||
non_pod(const std::string& S) : s(S) {}
|
||||
non_pod() = default;
|
||||
non_pod(std::string S) : s(std::move(S)) {}
|
||||
};
|
||||
|
||||
template <typename BasicJsonType>
|
||||
@ -651,7 +651,7 @@ static std::ostream& operator<<(std::ostream& os, small_pod l)
|
||||
{
|
||||
return os << "begin: " << l.begin << ", middle: " << l.middle << ", end: " << l.end;
|
||||
}
|
||||
}
|
||||
} // namespace udt
|
||||
|
||||
TEST_CASE("custom serializer for pods" * doctest::test_suite("udt"))
|
||||
{
|
||||
@ -803,7 +803,7 @@ struct is_constructible_patched : std::false_type {};
|
||||
|
||||
template <typename T>
|
||||
struct is_constructible_patched<T, decltype(void(json(std::declval<T>())))> : std::true_type {};
|
||||
}
|
||||
} // namespace
|
||||
|
||||
TEST_CASE("an incomplete type does not trigger a compiler error in non-evaluated context" * doctest::test_suite("udt"))
|
||||
{
|
||||
@ -822,8 +822,8 @@ class Evil
|
||||
int m_i = 0;
|
||||
};
|
||||
|
||||
void from_json(const json&, Evil&) {}
|
||||
}
|
||||
void from_json(const json& /*unused*/, Evil& /*unused*/) {}
|
||||
} // namespace
|
||||
|
||||
TEST_CASE("Issue #924")
|
||||
{
|
||||
|
||||
@ -39,7 +39,7 @@ namespace persons
|
||||
class person_with_private_data
|
||||
{
|
||||
private:
|
||||
std::string name = "";
|
||||
std::string name;
|
||||
int age = 0;
|
||||
json metadata = nullptr;
|
||||
|
||||
@ -62,7 +62,7 @@ class person_with_private_data
|
||||
class person_without_private_data_1
|
||||
{
|
||||
public:
|
||||
std::string name = "";
|
||||
std::string name;
|
||||
int age = 0;
|
||||
json metadata = nullptr;
|
||||
|
||||
@ -84,7 +84,7 @@ class person_without_private_data_1
|
||||
class person_without_private_data_2
|
||||
{
|
||||
public:
|
||||
std::string name = "";
|
||||
std::string name;
|
||||
int age = 0;
|
||||
json metadata = nullptr;
|
||||
|
||||
|
||||
@ -168,7 +168,7 @@ void check_utf8string(bool success_expected, int byte1, int byte2 = -1, int byte
|
||||
CHECK_THROWS_AS(_ = json::parse(json_string), json::parse_error&);
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
TEST_CASE("Unicode" * doctest::skip())
|
||||
{
|
||||
@ -1159,7 +1159,7 @@ TEST_CASE("Unicode" * doctest::skip())
|
||||
|
||||
SECTION("check JSON Pointers")
|
||||
{
|
||||
for (auto s : j)
|
||||
for (const auto& s : j)
|
||||
{
|
||||
// skip non-string JSON values
|
||||
if (!s.is_string())
|
||||
@ -1176,7 +1176,7 @@ TEST_CASE("Unicode" * doctest::skip())
|
||||
}
|
||||
|
||||
// JSON Pointers must begin with "/"
|
||||
ptr = "/" + ptr;
|
||||
ptr.insert(0, "/");
|
||||
|
||||
CHECK_NOTHROW(json::json_pointer("/" + ptr));
|
||||
|
||||
@ -1256,7 +1256,7 @@ void roundtrip(bool success_expected, const std::string& s)
|
||||
CHECK_THROWS_AS(_ = json::parse(ps), json::parse_error&);
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
TEST_CASE("Markus Kuhn's UTF-8 decoder capability and stress test")
|
||||
{
|
||||
|
||||
@ -51,7 +51,7 @@ bool u32string_is_utf32()
|
||||
{
|
||||
return (std::u32string(U"💩") == std::u32string(U"\U0001F4A9"));
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
TEST_CASE("wide strings")
|
||||
{
|
||||
|
||||
Loading…
Reference in New Issue
Block a user