🚨 fix Clang-Tidy warnings (#3738)

This commit is contained in:
Florian Albrechtskirchinger 2022-09-11 12:20:05 +02:00 committed by GitHub
parent 649e9c7f30
commit 6b03e77c1c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 1363 additions and 1230 deletions

View File

@ -396,7 +396,7 @@
#define NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(Type, ...) \
friend void to_json(nlohmann::json& nlohmann_json_j, const Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) } \
friend void from_json(const nlohmann::json& nlohmann_json_j, Type& nlohmann_json_t) { Type nlohmann_json_default_obj; NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_FROM_WITH_DEFAULT, __VA_ARGS__)) }
friend void from_json(const nlohmann::json& nlohmann_json_j, Type& nlohmann_json_t) { const Type nlohmann_json_default_obj; NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_FROM_WITH_DEFAULT, __VA_ARGS__)) }
/*!
@brief macro
@ -409,7 +409,7 @@
#define NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(Type, ...) \
inline void to_json(nlohmann::json& nlohmann_json_j, const Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) } \
inline void from_json(const nlohmann::json& nlohmann_json_j, Type& nlohmann_json_t) { Type nlohmann_json_default_obj; NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_FROM_WITH_DEFAULT, __VA_ARGS__)) }
inline void from_json(const nlohmann::json& nlohmann_json_j, Type& nlohmann_json_t) { const Type nlohmann_json_default_obj; NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_FROM_WITH_DEFAULT, __VA_ARGS__)) }
// inspired from https://stackoverflow.com/a/26745591

View File

@ -2748,7 +2748,7 @@ JSON_HEDLEY_DIAGNOSTIC_POP
#define NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(Type, ...) \
friend void to_json(nlohmann::json& nlohmann_json_j, const Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) } \
friend void from_json(const nlohmann::json& nlohmann_json_j, Type& nlohmann_json_t) { Type nlohmann_json_default_obj; NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_FROM_WITH_DEFAULT, __VA_ARGS__)) }
friend void from_json(const nlohmann::json& nlohmann_json_j, Type& nlohmann_json_t) { const Type nlohmann_json_default_obj; NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_FROM_WITH_DEFAULT, __VA_ARGS__)) }
/*!
@brief macro
@ -2761,7 +2761,7 @@ JSON_HEDLEY_DIAGNOSTIC_POP
#define NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(Type, ...) \
inline void to_json(nlohmann::json& nlohmann_json_j, const Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) } \
inline void from_json(const nlohmann::json& nlohmann_json_j, Type& nlohmann_json_t) { Type nlohmann_json_default_obj; NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_FROM_WITH_DEFAULT, __VA_ARGS__)) }
inline void from_json(const nlohmann::json& nlohmann_json_j, Type& nlohmann_json_t) { const Type nlohmann_json_default_obj; NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_FROM_WITH_DEFAULT, __VA_ARGS__)) }
// inspired from https://stackoverflow.com/a/26745591

View File

@ -33,9 +33,9 @@ TEST_CASE_TEMPLATE_DEFINE("value_in_range_of trait", T, value_in_range_of_test)
constexpr bool min_in_range = T::min_in_range;
constexpr bool max_in_range = T::max_in_range;
type val_min = std::numeric_limits<type>::min();
type const val_min = std::numeric_limits<type>::min();
type const val_min2 = val_min + 1;
type val_max = std::numeric_limits<type>::max();
type const val_max = std::numeric_limits<type>::max();
type const val_max2 = val_max - 1;
REQUIRE(CHAR_BIT == 8);

File diff suppressed because it is too large Load Diff

View File

@ -97,8 +97,8 @@ TEST_CASE("BSON")
{
SECTION("empty object")
{
json j = json::object();
std::vector<std::uint8_t> expected =
json const j = json::object();
std::vector<std::uint8_t> const expected =
{
0x05, 0x00, 0x00, 0x00, // size (little endian)
// no entries
@ -115,12 +115,12 @@ TEST_CASE("BSON")
SECTION("non-empty object with bool")
{
json j =
json const j =
{
{ "entry", true }
};
std::vector<std::uint8_t> expected =
std::vector<std::uint8_t> const expected =
{
0x0D, 0x00, 0x00, 0x00, // size (little endian)
0x08, // entry: boolean
@ -139,12 +139,12 @@ TEST_CASE("BSON")
SECTION("non-empty object with bool")
{
json j =
json const j =
{
{ "entry", false }
};
std::vector<std::uint8_t> expected =
std::vector<std::uint8_t> const expected =
{
0x0D, 0x00, 0x00, 0x00, // size (little endian)
0x08, // entry: boolean
@ -163,12 +163,12 @@ TEST_CASE("BSON")
SECTION("non-empty object with double")
{
json j =
json const j =
{
{ "entry", 4.2 }
};
std::vector<std::uint8_t> expected =
std::vector<std::uint8_t> const expected =
{
0x14, 0x00, 0x00, 0x00, // size (little endian)
0x01, /// entry: double
@ -187,12 +187,12 @@ TEST_CASE("BSON")
SECTION("non-empty object with string")
{
json j =
json const j =
{
{ "entry", "bsonstr" }
};
std::vector<std::uint8_t> expected =
std::vector<std::uint8_t> const expected =
{
0x18, 0x00, 0x00, 0x00, // size (little endian)
0x02, /// entry: string (UTF-8)
@ -211,12 +211,12 @@ TEST_CASE("BSON")
SECTION("non-empty object with null member")
{
json j =
json const j =
{
{ "entry", nullptr }
};
std::vector<std::uint8_t> expected =
std::vector<std::uint8_t> const expected =
{
0x0C, 0x00, 0x00, 0x00, // size (little endian)
0x0A, /// entry: null
@ -234,12 +234,12 @@ TEST_CASE("BSON")
SECTION("non-empty object with integer (32-bit) member")
{
json j =
json const j =
{
{ "entry", std::int32_t{0x12345678} }
};
std::vector<std::uint8_t> expected =
std::vector<std::uint8_t> const expected =
{
0x10, 0x00, 0x00, 0x00, // size (little endian)
0x10, /// entry: int32
@ -258,12 +258,12 @@ TEST_CASE("BSON")
SECTION("non-empty object with integer (64-bit) member")
{
json j =
json const j =
{
{ "entry", std::int64_t{0x1234567804030201} }
};
std::vector<std::uint8_t> expected =
std::vector<std::uint8_t> const expected =
{
0x14, 0x00, 0x00, 0x00, // size (little endian)
0x12, /// entry: int64
@ -282,12 +282,12 @@ TEST_CASE("BSON")
SECTION("non-empty object with negative integer (32-bit) member")
{
json j =
json const j =
{
{ "entry", std::int32_t{-1} }
};
std::vector<std::uint8_t> expected =
std::vector<std::uint8_t> const expected =
{
0x10, 0x00, 0x00, 0x00, // size (little endian)
0x10, /// entry: int32
@ -306,12 +306,12 @@ TEST_CASE("BSON")
SECTION("non-empty object with negative integer (64-bit) member")
{
json j =
json const j =
{
{ "entry", std::int64_t{-1} }
};
std::vector<std::uint8_t> expected =
std::vector<std::uint8_t> const expected =
{
0x10, 0x00, 0x00, 0x00, // size (little endian)
0x10, /// entry: int32
@ -331,12 +331,12 @@ TEST_CASE("BSON")
SECTION("non-empty object with unsigned integer (64-bit) member")
{
// directly encoding uint64 is not supported in bson (only for timestamp values)
json j =
json const j =
{
{ "entry", std::uint64_t{0x1234567804030201} }
};
std::vector<std::uint8_t> expected =
std::vector<std::uint8_t> const expected =
{
0x14, 0x00, 0x00, 0x00, // size (little endian)
0x12, /// entry: int64
@ -355,12 +355,12 @@ TEST_CASE("BSON")
SECTION("non-empty object with small unsigned integer member")
{
json j =
json const j =
{
{ "entry", std::uint64_t{0x42} }
};
std::vector<std::uint8_t> expected =
std::vector<std::uint8_t> const expected =
{
0x10, 0x00, 0x00, 0x00, // size (little endian)
0x10, /// entry: int32
@ -379,12 +379,12 @@ TEST_CASE("BSON")
SECTION("non-empty object with object member")
{
json j =
json const j =
{
{ "entry", json::object() }
};
std::vector<std::uint8_t> expected =
std::vector<std::uint8_t> const expected =
{
0x11, 0x00, 0x00, 0x00, // size (little endian)
0x03, /// entry: embedded document
@ -407,12 +407,12 @@ TEST_CASE("BSON")
SECTION("non-empty object with array member")
{
json j =
json const j =
{
{ "entry", json::array() }
};
std::vector<std::uint8_t> expected =
std::vector<std::uint8_t> const expected =
{
0x11, 0x00, 0x00, 0x00, // size (little endian)
0x04, /// entry: embedded document
@ -435,12 +435,12 @@ TEST_CASE("BSON")
SECTION("non-empty object with non-empty array member")
{
json j =
json const j =
{
{ "entry", json::array({1, 2, 3, 4, 5, 6, 7, 8}) }
};
std::vector<std::uint8_t> expected =
std::vector<std::uint8_t> const expected =
{
0x49, 0x00, 0x00, 0x00, // size (little endian)
0x04, /// entry: embedded document
@ -472,12 +472,12 @@ TEST_CASE("BSON")
{
const size_t N = 10;
const auto s = std::vector<std::uint8_t>(N, 'x');
json j =
json const j =
{
{ "entry", json::binary(s, 0) }
};
std::vector<std::uint8_t> expected =
std::vector<std::uint8_t> const expected =
{
0x1B, 0x00, 0x00, 0x00, // size (little endian)
0x05, // entry: binary
@ -502,12 +502,12 @@ TEST_CASE("BSON")
{
// an MD5 hash
const std::vector<std::uint8_t> md5hash = {0xd7, 0x7e, 0x27, 0x54, 0xbe, 0x12, 0x37, 0xfe, 0xd6, 0x0c, 0x33, 0x98, 0x30, 0x3b, 0x8d, 0xc4};
json j =
json const j =
{
{ "entry", json::binary(md5hash, 5) }
};
std::vector<std::uint8_t> expected =
std::vector<std::uint8_t> const expected =
{
0x21, 0x00, 0x00, 0x00, // size (little endian)
0x05, // entry: binary
@ -531,7 +531,7 @@ TEST_CASE("BSON")
SECTION("Some more complex document")
{
// directly encoding uint64 is not supported in bson (only for timestamp values)
json j =
json const j =
{
{"double", 42.5},
{"entry", 4.2},
@ -539,7 +539,7 @@ TEST_CASE("BSON")
{"object", {{ "string", "value" }}}
};
std::vector<std::uint8_t> expected =
std::vector<std::uint8_t> const expected =
{
/*size */ 0x4f, 0x00, 0x00, 0x00,
/*entry*/ 0x01, 'd', 'o', 'u', 'b', 'l', 'e', 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x45, 0x40,
@ -878,19 +878,19 @@ TEST_CASE("BSON numerical data")
static_cast<std::int64_t>(INT32_MIN) - 1,
};
for (auto i : numbers)
for (const auto i : numbers)
{
CAPTURE(i)
json j =
json const j =
{
{ "entry", i }
};
CHECK(j.at("entry").is_number_integer());
std::uint64_t const iu = *reinterpret_cast<std::uint64_t*>(&i);
std::vector<std::uint8_t> expected_bson =
std::uint64_t const iu = *reinterpret_cast<const std::uint64_t*>(&i);
std::vector<std::uint8_t> const expected_bson =
{
0x14u, 0x00u, 0x00u, 0x00u, // size (little endian)
0x12u, /// entry: int64
@ -950,19 +950,19 @@ TEST_CASE("BSON numerical data")
INT32_MAX
};
for (auto i : numbers)
for (const auto i : numbers)
{
CAPTURE(i)
json j =
json const j =
{
{ "entry", i }
};
CHECK(j.at("entry").is_number_integer());
std::uint32_t const iu = *reinterpret_cast<std::uint32_t*>(&i);
std::vector<std::uint8_t> expected_bson =
std::uint32_t const iu = *reinterpret_cast<const std::uint32_t*>(&i);
std::vector<std::uint8_t> const expected_bson =
{
0x10u, 0x00u, 0x00u, 0x00u, // size (little endian)
0x10u, /// entry: int32
@ -1003,19 +1003,19 @@ TEST_CASE("BSON numerical data")
static_cast<std::int64_t>(INT32_MAX) + 1,
};
for (auto i : numbers)
for (const auto i : numbers)
{
CAPTURE(i)
json j =
json const j =
{
{ "entry", i }
};
CHECK(j.at("entry").is_number_integer());
std::uint64_t const iu = *reinterpret_cast<std::uint64_t*>(&i);
std::vector<std::uint8_t> expected_bson =
std::uint64_t const iu = *reinterpret_cast<const std::uint64_t*>(&i);
std::vector<std::uint8_t> const expected_bson =
{
0x14u, 0x00u, 0x00u, 0x00u, // size (little endian)
0x12u, /// entry: int64
@ -1065,18 +1065,18 @@ TEST_CASE("BSON numerical data")
static_cast<std::uint64_t>(INT32_MAX)
};
for (auto i : numbers)
for (const auto i : numbers)
{
CAPTURE(i)
json j =
json const j =
{
{ "entry", i }
};
auto iu = i;
std::vector<std::uint8_t> expected_bson =
std::vector<std::uint8_t> const expected_bson =
{
0x10u, 0x00u, 0x00u, 0x00u, // size (little endian)
0x10u, /// entry: int32
@ -1120,18 +1120,18 @@ TEST_CASE("BSON numerical data")
static_cast<std::uint64_t>(INT64_MAX),
};
for (auto i : numbers)
for (const auto i : numbers)
{
CAPTURE(i)
json j =
json const j =
{
{ "entry", i }
};
auto iu = i;
std::vector<std::uint8_t> expected_bson =
std::vector<std::uint8_t> const expected_bson =
{
0x14u, 0x00u, 0x00u, 0x00u, // size (little endian)
0x12u, /// entry: int64
@ -1170,7 +1170,7 @@ TEST_CASE("BSON numerical data")
UINT64_MAX,
};
for (auto i : numbers)
for (const auto i : numbers)
{
CAPTURE(i)
@ -1214,7 +1214,7 @@ TEST_CASE("BSON roundtrips" * doctest::skip())
{
SECTION("reference files")
{
for (std::string filename :
for (const std::string filename :
{
TEST_DATA_DIRECTORY "/json.org/1.json",
TEST_DATA_DIRECTORY "/json.org/2.json",

View File

@ -416,8 +416,8 @@ TEST_CASE("capacity")
{
SECTION("boolean")
{
json const j = true;
const json j_const = true;
json j = true;
const json j_const(j);
SECTION("result of max_size")
{
@ -428,8 +428,8 @@ TEST_CASE("capacity")
SECTION("string")
{
json const j = "hello world";
const json j_const = "hello world";
json j = "hello world";
const json j_const(j);
SECTION("result of max_size")
{
@ -442,8 +442,8 @@ TEST_CASE("capacity")
{
SECTION("empty array")
{
json const j = json::array();
const json j_const = json::array();
json j = json::array();
const json j_const(j);
SECTION("result of max_size")
{
@ -454,8 +454,8 @@ TEST_CASE("capacity")
SECTION("filled array")
{
json const j = {1, 2, 3};
const json j_const = {1, 2, 3};
json j = {1, 2, 3};
const json j_const(j);
SECTION("result of max_size")
{
@ -469,8 +469,8 @@ TEST_CASE("capacity")
{
SECTION("empty object")
{
json const j = json::object();
const json j_const = json::object();
json j = json::object();
const json j_const(j);
SECTION("result of max_size")
{
@ -481,8 +481,8 @@ TEST_CASE("capacity")
SECTION("filled object")
{
json const j = {{"one", 1}, {"two", 2}, {"three", 3}};
const json j_const = {{"one", 1}, {"two", 2}, {"three", 3}};
json j = {{"one", 1}, {"two", 2}, {"three", 3}};
const json j_const(j);
SECTION("result of max_size")
{
@ -494,8 +494,8 @@ TEST_CASE("capacity")
SECTION("number (integer)")
{
json const j = -23;
const json j_const = -23;
json j = -23;
const json j_const(j);
SECTION("result of max_size")
{
@ -506,8 +506,8 @@ TEST_CASE("capacity")
SECTION("number (unsigned)")
{
json const j = 23u;
const json j_const = 23u;
json j = 23u;
const json j_const(j);
SECTION("result of max_size")
{
@ -518,8 +518,8 @@ TEST_CASE("capacity")
SECTION("number (float)")
{
json const j = 23.42;
const json j_const = 23.42;
json j = 23.42;
const json j_const(j);
SECTION("result of max_size")
{
@ -530,8 +530,8 @@ TEST_CASE("capacity")
SECTION("null")
{
json const j = nullptr;
const json j_const = nullptr;
json j = nullptr;
const json j_const(j);
SECTION("result of max_size")
{

File diff suppressed because it is too large Load Diff

View File

@ -27,76 +27,76 @@ TEST_CASE("constructors")
{
SECTION("null")
{
auto t = json::value_t::null;
auto const t = json::value_t::null;
json const j(t);
CHECK(j.type() == t);
}
SECTION("discarded")
{
auto t = json::value_t::discarded;
auto const t = json::value_t::discarded;
json const j(t);
CHECK(j.type() == t);
}
SECTION("object")
{
auto t = json::value_t::object;
auto const t = json::value_t::object;
json const j(t);
CHECK(j.type() == t);
}
SECTION("array")
{
auto t = json::value_t::array;
auto const t = json::value_t::array;
json const j(t);
CHECK(j.type() == t);
}
SECTION("boolean")
{
auto t = json::value_t::boolean;
json j(t);
auto const t = json::value_t::boolean;
json const j(t);
CHECK(j.type() == t);
CHECK(j == false);
}
SECTION("string")
{
auto t = json::value_t::string;
json j(t);
auto const t = json::value_t::string;
json const j(t);
CHECK(j.type() == t);
CHECK(j == "");
}
SECTION("number_integer")
{
auto t = json::value_t::number_integer;
json j(t);
auto const t = json::value_t::number_integer;
json const j(t);
CHECK(j.type() == t);
CHECK(j == 0);
}
SECTION("number_unsigned")
{
auto t = json::value_t::number_unsigned;
json j(t);
auto const t = json::value_t::number_unsigned;
json const j(t);
CHECK(j.type() == t);
CHECK(j == 0);
}
SECTION("number_float")
{
auto t = json::value_t::number_float;
json j(t);
auto const t = json::value_t::number_float;
json const j(t);
CHECK(j.type() == t);
CHECK(j == 0.0);
}
SECTION("binary")
{
auto t = json::value_t::binary;
json j(t);
auto const t = json::value_t::binary;
json const j(t);
CHECK(j.type() == t);
CHECK(j == json::binary({}));
}
@ -141,22 +141,24 @@ TEST_CASE("constructors")
{
// reference object
json::object_t const o_reference {{"a", json(1)}, {"b", json(1u)}, {"c", json(2.2)}, {"d", json(false)}, {"e", json("string")}, {"f", json()}};
json j_reference(o_reference);
json const j_reference(o_reference);
SECTION("std::map<json::string_t, json>")
{
std::map<json::string_t, json> const o {{"a", json(1)}, {"b", json(1u)}, {"c", json(2.2)}, {"d", json(false)}, {"e", json("string")}, {"f", json()}};
json j(o);
json const j(o);
CHECK(j.type() == json::value_t::object);
CHECK(j == j_reference);
}
SECTION("std::map<std::string, std::string> #600")
{
std::map<std::string, std::string> m;
m["a"] = "b";
m["c"] = "d";
m["e"] = "f";
std::map<std::string, std::string> m
{
{"a", "b"},
{"c", "d"},
{"e", "f"},
};
json const j(m);
CHECK((j.get<decltype(m)>() == m));
@ -165,7 +167,7 @@ TEST_CASE("constructors")
SECTION("std::map<const char*, json>")
{
std::map<const char*, json> const o {{"a", json(1)}, {"b", json(1u)}, {"c", json(2.2)}, {"d", json(false)}, {"e", json("string")}, {"f", json()}};
json j(o);
json const j(o);
CHECK(j.type() == json::value_t::object);
CHECK(j == j_reference);
}
@ -174,7 +176,7 @@ TEST_CASE("constructors")
SECTION("std::multimap<json::string_t, json>")
{
std::multimap<json::string_t, json> const o {{"a", json(1)}, {"b", json(1u)}, {"c", json(2.2)}, {"d", json(false)}, {"e", json("string")}, {"f", json()}};
json j(o);
json const j(o);
CHECK(j.type() == json::value_t::object);
CHECK(j == j_reference);
}
@ -182,7 +184,7 @@ TEST_CASE("constructors")
SECTION("std::unordered_map<json::string_t, json>")
{
std::unordered_map<json::string_t, json> const o {{"a", json(1)}, {"b", json(1u)}, {"c", json(2.2)}, {"d", json(false)}, {"e", json("string")}, {"f", json()}};
json j(o);
json const j(o);
CHECK(j.type() == json::value_t::object);
CHECK(j == j_reference);
}
@ -190,14 +192,14 @@ TEST_CASE("constructors")
SECTION("std::unordered_multimap<json::string_t, json>")
{
std::unordered_multimap<json::string_t, json> const o {{"a", json(1)}, {"b", json(1u)}, {"c", json(2.2)}, {"d", json(false)}, {"e", json("string")}, {"f", json()}};
json j(o);
json const j(o);
CHECK(j.type() == json::value_t::object);
CHECK(j == j_reference);
}
SECTION("associative container literal")
{
json j({{"a", json(1)}, {"b", json(1u)}, {"c", json(2.2)}, {"d", json(false)}, {"e", json("string")}, {"f", json()}});
json const j({{"a", json(1)}, {"b", json(1u)}, {"c", json(2.2)}, {"d", json(false)}, {"e", json("string")}, {"f", json()}});
CHECK(j.type() == json::value_t::object);
CHECK(j == j_reference);
}
@ -224,20 +226,20 @@ TEST_CASE("constructors")
{
// reference array
json::array_t const a_reference {json(1), json(1u), json(2.2), json(false), json("string"), json()};
json j_reference(a_reference);
json const j_reference(a_reference);
SECTION("std::list<json>")
{
std::list<json> const a {json(1), json(1u), json(2.2), json(false), json("string"), json()};
json j(a);
json const j(a);
CHECK(j.type() == json::value_t::array);
CHECK(j == j_reference);
}
SECTION("std::pair")
{
std::pair<float, std::string> p{1.0f, "string"};
json j(p);
std::pair<float, std::string> const p{1.0f, "string"};
json const j(p);
CHECK(j.type() == json::value_t::array);
CHECK(j.get<decltype(p)>() == p);
@ -248,7 +250,7 @@ TEST_CASE("constructors")
SECTION("std::pair with discarded values")
{
json j{1, 2.0, "string"};
json const j{1, 2.0, "string"};
const auto p = j.get<std::pair<int, float>>();
CHECK(p.first == j[0]);
@ -258,7 +260,7 @@ TEST_CASE("constructors")
SECTION("std::tuple")
{
const auto t = std::make_tuple(1.0, std::string{"string"}, 42, std::vector<int> {0, 1});
json j(t);
json const j(t);
CHECK(j.type() == json::value_t::array);
REQUIRE(j.size() == 4);
@ -272,7 +274,7 @@ TEST_CASE("constructors")
SECTION("std::tuple with discarded values")
{
json j{1, 2.0, "string", 42};
json const j{1, 2.0, "string", 42};
const auto t = j.get<std::tuple<int, float, std::string>>();
CHECK(std::get<0>(t) == j[0]);
@ -292,15 +294,15 @@ TEST_CASE("constructors")
SECTION("std::forward_list<json>")
{
std::forward_list<json> const a {json(1), json(1u), json(2.2), json(false), json("string"), json()};
json j(a);
json const j(a);
CHECK(j.type() == json::value_t::array);
CHECK(j == j_reference);
}
SECTION("std::array<json, 6>")
{
std::array<json, 6> a {{json(1), json(1u), json(2.2), json(false), json("string"), json()}};
json j(a);
std::array<json, 6> const a {{json(1), json(1u), json(2.2), json(false), json("string"), json()}};
json const j(a);
CHECK(j.type() == json::value_t::array);
CHECK(j == j_reference);
@ -310,8 +312,8 @@ TEST_CASE("constructors")
SECTION("std::valarray<int>")
{
std::valarray<int> va = {1, 2, 3, 4, 5};
json j(va);
std::valarray<int> const va = {1, 2, 3, 4, 5};
json const j(va);
CHECK(j.type() == json::value_t::array);
CHECK(j == json({1, 2, 3, 4, 5}));
@ -325,8 +327,8 @@ TEST_CASE("constructors")
SECTION("std::valarray<double>")
{
std::valarray<double> va = {1.2, 2.3, 3.4, 4.5, 5.6};
json j(va);
std::valarray<double> const va = {1.2, 2.3, 3.4, 4.5, 5.6};
json const j(va);
CHECK(j.type() == json::value_t::array);
CHECK(j == json({1.2, 2.3, 3.4, 4.5, 5.6}));
@ -341,7 +343,7 @@ TEST_CASE("constructors")
SECTION("std::vector<json>")
{
std::vector<json> const a {json(1), json(1u), json(2.2), json(false), json("string"), json()};
json j(a);
json const j(a);
CHECK(j.type() == json::value_t::array);
CHECK(j == j_reference);
}
@ -349,7 +351,7 @@ TEST_CASE("constructors")
SECTION("std::deque<json>")
{
std::deque<json> const a {json(1), json(1u), json(2.2), json(false), json("string"), json()};
json j(a);
json const j(a);
CHECK(j.type() == json::value_t::array);
CHECK(j == j_reference);
}
@ -372,7 +374,7 @@ TEST_CASE("constructors")
SECTION("sequence container literal")
{
json j({json(1), json(1u), json(2.2), json(false), json("string"), json()});
json const j({json(1), json(1u), json(2.2), json(false), json("string"), json()});
CHECK(j.type() == json::value_t::array);
CHECK(j == j_reference);
}
@ -399,12 +401,12 @@ TEST_CASE("constructors")
{
// reference string
json::string_t const s_reference {"Hello world"};
json j_reference(s_reference);
json const j_reference(s_reference);
SECTION("std::string")
{
std::string const s {"Hello world"};
json j(s);
json const j(s);
CHECK(j.type() == json::value_t::string);
CHECK(j == j_reference);
}
@ -412,7 +414,7 @@ TEST_CASE("constructors")
SECTION("char[]")
{
char const s[] {"Hello world"}; // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays)
json j(s);
json const j(s);
CHECK(j.type() == json::value_t::string);
CHECK(j == j_reference);
}
@ -420,14 +422,14 @@ TEST_CASE("constructors")
SECTION("const char*")
{
const char* s {"Hello world"};
json j(s);
json const j(s);
CHECK(j.type() == json::value_t::string);
CHECK(j == j_reference);
}
SECTION("string literal")
{
json j("Hello world");
json const j("Hello world");
CHECK(j.type() == json::value_t::string);
CHECK(j == j_reference);
}
@ -509,14 +511,14 @@ TEST_CASE("constructors")
{
// reference objects
json::number_integer_t const n_reference = 42;
json j_reference(n_reference);
json const j_reference(n_reference);
json::number_unsigned_t const n_unsigned_reference = 42;
json j_unsigned_reference(n_unsigned_reference);
json const j_unsigned_reference(n_unsigned_reference);
SECTION("short")
{
short const n = 42;
json j(n);
json const j(n);
CHECK(j.type() == json::value_t::number_integer);
CHECK(j == j_reference);
}
@ -524,7 +526,7 @@ TEST_CASE("constructors")
SECTION("unsigned short")
{
unsigned short const n = 42;
json j(n);
json const j(n);
CHECK(j.type() == json::value_t::number_unsigned);
CHECK(j == j_unsigned_reference);
}
@ -532,7 +534,7 @@ TEST_CASE("constructors")
SECTION("int")
{
int const n = 42;
json j(n);
json const j(n);
CHECK(j.type() == json::value_t::number_integer);
CHECK(j == j_reference);
}
@ -540,7 +542,7 @@ TEST_CASE("constructors")
SECTION("unsigned int")
{
unsigned int const n = 42;
json j(n);
json const j(n);
CHECK(j.type() == json::value_t::number_unsigned);
CHECK(j == j_unsigned_reference);
}
@ -548,7 +550,7 @@ TEST_CASE("constructors")
SECTION("long")
{
long const n = 42;
json j(n);
json const j(n);
CHECK(j.type() == json::value_t::number_integer);
CHECK(j == j_reference);
}
@ -556,7 +558,7 @@ TEST_CASE("constructors")
SECTION("unsigned long")
{
unsigned long const n = 42;
json j(n);
json const j(n);
CHECK(j.type() == json::value_t::number_unsigned);
CHECK(j == j_unsigned_reference);
}
@ -564,7 +566,7 @@ TEST_CASE("constructors")
SECTION("long long")
{
long long const n = 42;
json j(n);
json const j(n);
CHECK(j.type() == json::value_t::number_integer);
CHECK(j == j_reference);
}
@ -572,7 +574,7 @@ TEST_CASE("constructors")
SECTION("unsigned long long")
{
unsigned long long const n = 42;
json j(n);
json const j(n);
CHECK(j.type() == json::value_t::number_unsigned);
CHECK(j == j_unsigned_reference);
}
@ -580,7 +582,7 @@ TEST_CASE("constructors")
SECTION("int8_t")
{
int8_t const n = 42;
json j(n);
json const j(n);
CHECK(j.type() == json::value_t::number_integer);
CHECK(j == j_reference);
}
@ -588,7 +590,7 @@ TEST_CASE("constructors")
SECTION("int16_t")
{
int16_t const n = 42;
json j(n);
json const j(n);
CHECK(j.type() == json::value_t::number_integer);
CHECK(j == j_reference);
}
@ -596,7 +598,7 @@ TEST_CASE("constructors")
SECTION("int32_t")
{
int32_t const n = 42;
json j(n);
json const j(n);
CHECK(j.type() == json::value_t::number_integer);
CHECK(j == j_reference);
}
@ -604,7 +606,7 @@ TEST_CASE("constructors")
SECTION("int64_t")
{
int64_t const n = 42;
json j(n);
json const j(n);
CHECK(j.type() == json::value_t::number_integer);
CHECK(j == j_reference);
}
@ -612,7 +614,7 @@ TEST_CASE("constructors")
SECTION("int_fast8_t")
{
int_fast8_t const n = 42;
json j(n);
json const j(n);
CHECK(j.type() == json::value_t::number_integer);
CHECK(j == j_reference);
}
@ -620,7 +622,7 @@ TEST_CASE("constructors")
SECTION("int_fast16_t")
{
int_fast16_t const n = 42;
json j(n);
json const j(n);
CHECK(j.type() == json::value_t::number_integer);
CHECK(j == j_reference);
}
@ -628,7 +630,7 @@ TEST_CASE("constructors")
SECTION("int_fast32_t")
{
int_fast32_t const n = 42;
json j(n);
json const j(n);
CHECK(j.type() == json::value_t::number_integer);
CHECK(j == j_reference);
}
@ -636,7 +638,7 @@ TEST_CASE("constructors")
SECTION("int_fast64_t")
{
int_fast64_t const n = 42;
json j(n);
json const j(n);
CHECK(j.type() == json::value_t::number_integer);
CHECK(j == j_reference);
}
@ -644,7 +646,7 @@ TEST_CASE("constructors")
SECTION("int_least8_t")
{
int_least8_t const n = 42;
json j(n);
json const j(n);
CHECK(j.type() == json::value_t::number_integer);
CHECK(j == j_reference);
}
@ -652,7 +654,7 @@ TEST_CASE("constructors")
SECTION("int_least16_t")
{
int_least16_t const n = 42;
json j(n);
json const j(n);
CHECK(j.type() == json::value_t::number_integer);
CHECK(j == j_reference);
}
@ -660,7 +662,7 @@ TEST_CASE("constructors")
SECTION("int_least32_t")
{
int_least32_t const n = 42;
json j(n);
json const j(n);
CHECK(j.type() == json::value_t::number_integer);
CHECK(j == j_reference);
}
@ -668,7 +670,7 @@ TEST_CASE("constructors")
SECTION("int_least64_t")
{
int_least64_t const n = 42;
json j(n);
json const j(n);
CHECK(j.type() == json::value_t::number_integer);
CHECK(j == j_reference);
}
@ -676,7 +678,7 @@ TEST_CASE("constructors")
SECTION("uint8_t")
{
uint8_t const n = 42;
json j(n);
json const j(n);
CHECK(j.type() == json::value_t::number_unsigned);
CHECK(j == j_unsigned_reference);
}
@ -684,7 +686,7 @@ TEST_CASE("constructors")
SECTION("uint16_t")
{
uint16_t const n = 42;
json j(n);
json const j(n);
CHECK(j.type() == json::value_t::number_unsigned);
CHECK(j == j_unsigned_reference);
}
@ -692,7 +694,7 @@ TEST_CASE("constructors")
SECTION("uint32_t")
{
uint32_t const n = 42;
json j(n);
json const j(n);
CHECK(j.type() == json::value_t::number_unsigned);
CHECK(j == j_unsigned_reference);
}
@ -700,7 +702,7 @@ TEST_CASE("constructors")
SECTION("uint64_t")
{
uint64_t const n = 42;
json j(n);
json const j(n);
CHECK(j.type() == json::value_t::number_unsigned);
CHECK(j == j_unsigned_reference);
}
@ -708,7 +710,7 @@ TEST_CASE("constructors")
SECTION("uint_fast8_t")
{
uint_fast8_t const n = 42;
json j(n);
json const j(n);
CHECK(j.type() == json::value_t::number_unsigned);
CHECK(j == j_unsigned_reference);
}
@ -716,7 +718,7 @@ TEST_CASE("constructors")
SECTION("uint_fast16_t")
{
uint_fast16_t const n = 42;
json j(n);
json const j(n);
CHECK(j.type() == json::value_t::number_unsigned);
CHECK(j == j_unsigned_reference);
}
@ -724,7 +726,7 @@ TEST_CASE("constructors")
SECTION("uint_fast32_t")
{
uint_fast32_t const n = 42;
json j(n);
json const j(n);
CHECK(j.type() == json::value_t::number_unsigned);
CHECK(j == j_unsigned_reference);
}
@ -732,7 +734,7 @@ TEST_CASE("constructors")
SECTION("uint_fast64_t")
{
uint_fast64_t const n = 42;
json j(n);
json const j(n);
CHECK(j.type() == json::value_t::number_unsigned);
CHECK(j == j_unsigned_reference);
}
@ -740,7 +742,7 @@ TEST_CASE("constructors")
SECTION("uint_least8_t")
{
uint_least8_t const n = 42;
json j(n);
json const j(n);
CHECK(j.type() == json::value_t::number_unsigned);
CHECK(j == j_unsigned_reference);
}
@ -748,7 +750,7 @@ TEST_CASE("constructors")
SECTION("uint_least16_t")
{
uint_least16_t const n = 42;
json j(n);
json const j(n);
CHECK(j.type() == json::value_t::number_unsigned);
CHECK(j == j_unsigned_reference);
}
@ -756,7 +758,7 @@ TEST_CASE("constructors")
SECTION("uint_least32_t")
{
uint_least32_t const n = 42;
json j(n);
json const j(n);
CHECK(j.type() == json::value_t::number_unsigned);
CHECK(j == j_unsigned_reference);
}
@ -764,14 +766,14 @@ TEST_CASE("constructors")
SECTION("uint_least64_t")
{
uint_least64_t const n = 42;
json j(n);
json const j(n);
CHECK(j.type() == json::value_t::number_unsigned);
CHECK(j == j_unsigned_reference);
}
SECTION("integer literal without suffix")
{
json j(42);
json const j(42);
CHECK(j.type() == json::value_t::number_integer);
CHECK(j == j_reference);
}
@ -785,7 +787,7 @@ TEST_CASE("constructors")
SECTION("integer literal with l suffix")
{
json j(42L);
json const j(42L);
CHECK(j.type() == json::value_t::number_integer);
CHECK(j == j_reference);
}
@ -799,7 +801,7 @@ TEST_CASE("constructors")
SECTION("integer literal with ll suffix")
{
json j(42LL);
json const j(42LL);
CHECK(j.type() == json::value_t::number_integer);
CHECK(j == j_reference);
}
@ -846,12 +848,12 @@ TEST_CASE("constructors")
SECTION("infinity")
{
// infinity is stored properly, but serialized to null
json::number_float_t n(std::numeric_limits<json::number_float_t>::infinity());
json::number_float_t const n(std::numeric_limits<json::number_float_t>::infinity());
json const j(n);
CHECK(j.type() == json::value_t::number_float);
// check round trip of infinity
json::number_float_t d{j};
json::number_float_t const d{j};
CHECK(d == n);
// check that inf is serialized to null
@ -868,7 +870,7 @@ TEST_CASE("constructors")
SECTION("float")
{
float const n = 42.23f;
json j(n);
json const j(n);
CHECK(j.type() == json::value_t::number_float);
CHECK(j.m_value.number_float == Approx(j_reference.m_value.number_float));
}
@ -876,7 +878,7 @@ TEST_CASE("constructors")
SECTION("double")
{
double const n = 42.23;
json j(n);
json const j(n);
CHECK(j.type() == json::value_t::number_float);
CHECK(j.m_value.number_float == Approx(j_reference.m_value.number_float));
}
@ -884,28 +886,28 @@ TEST_CASE("constructors")
SECTION("long double")
{
long double const n = 42.23L;
json j(n);
json const j(n);
CHECK(j.type() == json::value_t::number_float);
CHECK(j.m_value.number_float == Approx(j_reference.m_value.number_float));
}
SECTION("floating-point literal without suffix")
{
json j(42.23);
json const j(42.23);
CHECK(j.type() == json::value_t::number_float);
CHECK(j.m_value.number_float == Approx(j_reference.m_value.number_float));
}
SECTION("integer literal with f suffix")
{
json j(42.23f);
json const j(42.23f);
CHECK(j.type() == json::value_t::number_float);
CHECK(j.m_value.number_float == Approx(j_reference.m_value.number_float));
}
SECTION("integer literal with l suffix")
{
json j(42.23L);
json const j(42.23L);
CHECK(j.type() == json::value_t::number_float);
CHECK(j.m_value.number_float == Approx(j_reference.m_value.number_float));
}
@ -1106,9 +1108,9 @@ TEST_CASE("constructors")
SECTION("constructor with implicit types (array)")
{
// This should break through any short string optimization in std::string
std::string source(1024, '!');
std::string const source(1024, '!');
const auto* source_addr = source.data();
json j = {std::move(source)};
json const j = {std::move(source)};
const auto* target_addr = j[0].get_ref<std::string const&>().data();
const bool success = (target_addr == source_addr);
CHECK(success);
@ -1117,9 +1119,9 @@ TEST_CASE("constructors")
SECTION("constructor with implicit types (object)")
{
// This should break through any short string optimization in std::string
std::string source(1024, '!');
std::string const source(1024, '!');
const auto* source_addr = source.data();
json j = {{"key", std::move(source)}};
json const j = {{"key", std::move(source)}};
const auto* target_addr = j["key"].get_ref<std::string const&>().data();
const bool success = (target_addr == source_addr);
CHECK(success);
@ -1128,7 +1130,7 @@ TEST_CASE("constructors")
SECTION("constructor with implicit types (object key)")
{
// This should break through any short string optimization in std::string
std::string source(1024, '!');
std::string const source(1024, '!');
const auto* source_addr = source.data();
json j = {{std::move(source), 42}};
const auto* target_addr = j.get_ref<json::object_t&>().begin()->first.data();
@ -1141,9 +1143,9 @@ TEST_CASE("constructors")
{
SECTION("constructor with implicit types (array)")
{
json::array_t source = {1, 2, 3};
json::array_t const source = {1, 2, 3};
const auto* source_addr = source.data();
json j {std::move(source)};
json const j {std::move(source)};
const auto* target_addr = j[0].get_ref<json::array_t const&>().data();
const bool success = (target_addr == source_addr);
CHECK(success);
@ -1151,9 +1153,9 @@ TEST_CASE("constructors")
SECTION("constructor with implicit types (object)")
{
json::array_t source = {1, 2, 3};
json::array_t const source = {1, 2, 3};
const auto* source_addr = source.data();
json j {{"key", std::move(source)}};
json const j {{"key", std::move(source)}};
const auto* target_addr = j["key"].get_ref<json::array_t const&>().data();
const bool success = (target_addr == source_addr);
CHECK(success);
@ -1161,9 +1163,9 @@ TEST_CASE("constructors")
SECTION("assignment with implicit types (array)")
{
json::array_t source = {1, 2, 3};
json::array_t const source = {1, 2, 3};
const auto* source_addr = source.data();
json j = {std::move(source)};
json const j = {std::move(source)};
const auto* target_addr = j[0].get_ref<json::array_t const&>().data();
const bool success = (target_addr == source_addr);
CHECK(success);
@ -1171,9 +1173,9 @@ TEST_CASE("constructors")
SECTION("assignment with implicit types (object)")
{
json::array_t source = {1, 2, 3};
json::array_t const source = {1, 2, 3};
const auto* source_addr = source.data();
json j = {{"key", std::move(source)}};
json const j = {{"key", std::move(source)}};
const auto* target_addr = j["key"].get_ref<json::array_t const&>().data();
const bool success = (target_addr == source_addr);
CHECK(success);
@ -1184,17 +1186,17 @@ TEST_CASE("constructors")
{
SECTION("constructor with implicit types (array)")
{
json::object_t source = {{"hello", "world"}};
json::object_t const source = {{"hello", "world"}};
const json* source_addr = &source.at("hello");
json j {std::move(source)};
json const j {std::move(source)};
CHECK(&(j[0].get_ref<json::object_t const&>().at("hello")) == source_addr);
}
SECTION("constructor with implicit types (object)")
{
json::object_t source = {{"hello", "world"}};
json::object_t const source = {{"hello", "world"}};
const json* source_addr = &source.at("hello");
json j {{"key", std::move(source)}};
json const j {{"key", std::move(source)}};
CHECK(&(j["key"].get_ref<json::object_t const&>().at("hello")) == source_addr);
}
@ -1208,9 +1210,9 @@ TEST_CASE("constructors")
SECTION("assignment with implicit types (object)")
{
json::object_t source = {{"hello", "world"}};
json::object_t const source = {{"hello", "world"}};
const json* source_addr = &source.at("hello");
json j = {{"key", std::move(source)}};
json const j = {{"key", std::move(source)}};
CHECK(&(j["key"].get_ref<json::object_t const&>().at("hello")) == source_addr);
}
}
@ -1219,33 +1221,33 @@ TEST_CASE("constructors")
{
SECTION("constructor with implicit types (array)")
{
json source {1, 2, 3};
json const source {1, 2, 3};
const json* source_addr = &source[0];
json j {std::move(source), {}};
json const j {std::move(source), {}};
CHECK(&j[0][0] == source_addr);
}
SECTION("constructor with implicit types (object)")
{
json source {1, 2, 3};
json const source {1, 2, 3};
const json* source_addr = &source[0];
json j {{"key", std::move(source)}};
json const j {{"key", std::move(source)}};
CHECK(&j["key"][0] == source_addr);
}
SECTION("assignment with implicit types (array)")
{
json source {1, 2, 3};
json const source {1, 2, 3};
const json* source_addr = &source[0];
json j = {std::move(source), {}};
json const j = {std::move(source), {}};
CHECK(&j[0][0] == source_addr);
}
SECTION("assignment with implicit types (object)")
{
json source {1, 2, 3};
json const source {1, 2, 3};
const json* source_addr = &source[0];
json j = {{"key", std::move(source)}};
json const j = {{"key", std::move(source)}};
CHECK(&j["key"][0] == source_addr);
}
}
@ -1264,8 +1266,8 @@ TEST_CASE("constructors")
SECTION("cnt = 1")
{
json v = {1, "foo", 34.23, {1, 2, 3}, {{"A", 1}, {"B", 2u}}};
json arr(1, v);
json const v = {1, "foo", 34.23, {1, 2, 3}, {{"A", 1}, {"B", 2u}}};
json const arr(1, v);
CHECK(arr.size() == 1);
for (auto& x : arr)
{
@ -1275,8 +1277,8 @@ TEST_CASE("constructors")
SECTION("cnt = 3")
{
json v = {1, "foo", 34.23, {1, 2, 3}, {{"A", 1}, {"B", 2u}}};
json arr(3, v);
json const v = {1, "foo", 34.23, {1, 2, 3}, {{"A", 1}, {"B", 2u}}};
json const arr(3, v);
CHECK(arr.size() == 3);
for (auto& x : arr)
{
@ -1293,12 +1295,12 @@ TEST_CASE("constructors")
{
{
json jobject = {{"a", "a"}, {"b", 1}, {"c", 17u}};
json j_new(jobject.begin(), jobject.end());
json const j_new(jobject.begin(), jobject.end());
CHECK(j_new == jobject);
}
{
json jobject = {{"a", "a"}, {"b", 1}, {"c", 17u}};
json j_new(jobject.cbegin(), jobject.cend());
json const j_new(jobject.cbegin(), jobject.cend());
CHECK(j_new == jobject);
}
}
@ -1307,20 +1309,20 @@ TEST_CASE("constructors")
{
{
json jobject = {{"a", "a"}, {"b", 1}, {"c", 17u}};
json j_new(jobject.begin(), jobject.begin());
json const j_new(jobject.begin(), jobject.begin());
CHECK(j_new == json::object());
}
{
json const jobject = {{"a", "a"}, {"b", 1}, {"c", 17u}};
json j_new(jobject.cbegin(), jobject.cbegin());
json const j_new(jobject.cbegin(), jobject.cbegin());
CHECK(j_new == json::object());
}
}
SECTION("construct from subrange")
{
json jobject = {{"a", "a"}, {"b", 1}, {"c", 17u}, {"d", false}, {"e", true}};
json j_new(jobject.find("b"), jobject.find("e"));
json const jobject = {{"a", "a"}, {"b", 1}, {"c", 17u}, {"d", false}, {"e", true}};
json const j_new(jobject.find("b"), jobject.find("e"));
CHECK(j_new == json({{"b", 1}, {"c", 17u}, {"d", false}}));
}
@ -1347,12 +1349,12 @@ TEST_CASE("constructors")
{
{
json jarray = {1, 2, 3, 4, 5};
json j_new(jarray.begin(), jarray.end());
json const j_new(jarray.begin(), jarray.end());
CHECK(j_new == jarray);
}
{
json jarray = {1, 2, 3, 4, 5};
json j_new(jarray.cbegin(), jarray.cend());
json const jarray = {1, 2, 3, 4, 5};
json const j_new(jarray.cbegin(), jarray.cend());
CHECK(j_new == jarray);
}
}
@ -1366,7 +1368,7 @@ TEST_CASE("constructors")
}
{
json const jarray = {1, 2, 3, 4, 5};
json j_new(jarray.cbegin(), jarray.cbegin());
json const j_new(jarray.cbegin(), jarray.cbegin());
CHECK(j_new == json::array());
}
}
@ -1375,12 +1377,12 @@ TEST_CASE("constructors")
{
{
json jarray = {1, 2, 3, 4, 5};
json j_new(jarray.begin() + 1, jarray.begin() + 3);
json const j_new(jarray.begin() + 1, jarray.begin() + 3);
CHECK(j_new == json({2, 3}));
}
{
json const jarray = {1, 2, 3, 4, 5};
json j_new(jarray.cbegin() + 1, jarray.cbegin() + 3);
json const j_new(jarray.cbegin() + 1, jarray.cbegin() + 3);
CHECK(j_new == json({2, 3}));
}
}
@ -1422,12 +1424,12 @@ TEST_CASE("constructors")
{
{
json j = "foo";
json j_new(j.begin(), j.end());
json const j_new(j.begin(), j.end());
CHECK(j == j_new);
}
{
json j = "bar";
json j_new(j.cbegin(), j.cend());
json const j = "bar";
json const j_new(j.cbegin(), j.cend());
CHECK(j == j_new);
}
}
@ -1436,12 +1438,12 @@ TEST_CASE("constructors")
{
{
json j = false;
json j_new(j.begin(), j.end());
json const j_new(j.begin(), j.end());
CHECK(j == j_new);
}
{
json j = true;
json j_new(j.cbegin(), j.cend());
json const j = true;
json const j_new(j.cbegin(), j.cend());
CHECK(j == j_new);
}
}
@ -1450,12 +1452,12 @@ TEST_CASE("constructors")
{
{
json j = 17;
json j_new(j.begin(), j.end());
json const j_new(j.begin(), j.end());
CHECK(j == j_new);
}
{
json j = 17;
json j_new(j.cbegin(), j.cend());
json const j = 17;
json const j_new(j.cbegin(), j.cend());
CHECK(j == j_new);
}
}
@ -1464,12 +1466,12 @@ TEST_CASE("constructors")
{
{
json j = 17u;
json j_new(j.begin(), j.end());
json const j_new(j.begin(), j.end());
CHECK(j == j_new);
}
{
json j = 17u;
json j_new(j.cbegin(), j.cend());
json const j = 17u;
json const j_new(j.cbegin(), j.cend());
CHECK(j == j_new);
}
}
@ -1478,12 +1480,12 @@ TEST_CASE("constructors")
{
{
json j = 23.42;
json j_new(j.begin(), j.end());
json const j_new(j.begin(), j.end());
CHECK(j == j_new);
}
{
json j = 23.42;
json j_new(j.cbegin(), j.cend());
json const j = 23.42;
json const j_new(j.cbegin(), j.cend());
CHECK(j == j_new);
}
}

View File

@ -40,7 +40,7 @@ TEST_CASE("JSON pointers")
SECTION("array index error")
{
json v = {1, 2, 3, 4};
json::json_pointer const const ptr("/10e");
json::json_pointer const ptr("/10e");
CHECK_THROWS_WITH_AS(v[ptr],
"[json.exception.out_of_range.404] unresolved reference token '10e'", json::out_of_range&);
}
@ -311,7 +311,7 @@ TEST_CASE("JSON pointers")
{
auto too_large_index = std::to_string((std::numeric_limits<unsigned long long>::max)()) + "1";
json::json_pointer const const jp(std::string("/") + too_large_index);
json::json_pointer const jp(std::string("/") + too_large_index);
std::string const throw_msg = std::string("[json.exception.out_of_range.404] unresolved reference token '") + too_large_index + "'";
CHECK_THROWS_WITH_AS(j[jp] = 1, throw_msg.c_str(), json::out_of_range&);
@ -326,7 +326,7 @@ TEST_CASE("JSON pointers")
{
auto size_type_max_uul = static_cast<unsigned long long>((std::numeric_limits<json::size_type>::max)());
auto too_large_index = std::to_string(size_type_max_uul);
json::json_pointer const const jp(std::string("/") + too_large_index);
json::json_pointer const jp(std::string("/") + too_large_index);
std::string const throw_msg = std::string("[json.exception.out_of_range.410] array index ") + too_large_index + " exceeds size_type";
CHECK_THROWS_WITH_AS(j[jp] = 1, throw_msg.c_str(), json::out_of_range&);
@ -485,7 +485,7 @@ TEST_CASE("JSON pointers")
{"", "/foo", "/foo/0", "/", "/a~1b", "/c%d", "/e^f", "/g|h", "/i\\j", "/k\"l", "/ ", "/m~0n"
})
{
json::json_pointer const const ptr(ptr_str);
json::json_pointer const ptr(ptr_str);
std::stringstream ss;
ss << ptr;
CHECK(ptr.to_string() == ptr_str);

View File

@ -113,8 +113,8 @@ TEST_CASE("MessagePack")
SECTION("null")
{
json j = nullptr;
std::vector<uint8_t> expected = {0xc0};
json const j = nullptr;
std::vector<uint8_t> const expected = {0xc0};
const auto result = json::to_msgpack(j);
CHECK(result == expected);
@ -127,8 +127,8 @@ TEST_CASE("MessagePack")
{
SECTION("true")
{
json j = true;
std::vector<uint8_t> expected = {0xc3};
json const j = true;
std::vector<uint8_t> const expected = {0xc3};
const auto result = json::to_msgpack(j);
CHECK(result == expected);
@ -139,8 +139,8 @@ TEST_CASE("MessagePack")
SECTION("false")
{
json j = false;
std::vector<uint8_t> expected = {0xc2};
json const j = false;
std::vector<uint8_t> const expected = {0xc2};
const auto result = json::to_msgpack(j);
CHECK(result == expected);
@ -161,14 +161,16 @@ TEST_CASE("MessagePack")
CAPTURE(i)
// create JSON value with integer number
json j = i;
json const j = i;
// check type
CHECK(j.is_number_integer());
// create expected byte vector
std::vector<uint8_t> expected;
expected.push_back(static_cast<uint8_t>(i));
std::vector<uint8_t> const expected
{
static_cast<uint8_t>(i)
};
// compare result + size
const auto result = json::to_msgpack(j);
@ -198,8 +200,7 @@ TEST_CASE("MessagePack")
CHECK(j.is_number_integer());
// create expected byte vector
std::vector<uint8_t> expected;
expected.push_back(static_cast<uint8_t>(i));
std::vector<uint8_t> const expected{static_cast<uint8_t>(i)};
// compare result + size
const auto result = json::to_msgpack(j);
@ -229,9 +230,11 @@ TEST_CASE("MessagePack")
CHECK(j.is_number_integer());
// create expected byte vector
std::vector<uint8_t> expected;
expected.push_back(0xcc);
expected.push_back(static_cast<uint8_t>(i));
std::vector<uint8_t> const expected
{
0xcc,
static_cast<uint8_t>(i),
};
// compare result + size
const auto result = json::to_msgpack(j);
@ -240,7 +243,7 @@ TEST_CASE("MessagePack")
// check individual bytes
CHECK(result[0] == 0xcc);
auto restored = static_cast<uint8_t>(result[1]);
auto const restored = static_cast<uint8_t>(result[1]);
CHECK(restored == i);
// roundtrip
@ -263,10 +266,12 @@ TEST_CASE("MessagePack")
CHECK(j.is_number_integer());
// create expected byte vector
std::vector<uint8_t> expected;
expected.push_back(0xcd);
expected.push_back(static_cast<uint8_t>((i >> 8) & 0xff));
expected.push_back(static_cast<uint8_t>(i & 0xff));
std::vector<uint8_t> const expected
{
0xcd,
static_cast<uint8_t>((i >> 8) & 0xff),
static_cast<uint8_t>(i & 0xff),
};
// compare result + size
const auto result = json::to_msgpack(j);
@ -275,7 +280,7 @@ TEST_CASE("MessagePack")
// check individual bytes
CHECK(result[0] == 0xcd);
auto restored = static_cast<uint16_t>(static_cast<uint8_t>(result[1]) * 256 + static_cast<uint8_t>(result[2]));
auto const restored = static_cast<uint16_t>(static_cast<uint8_t>(result[1]) * 256 + static_cast<uint8_t>(result[2]));
CHECK(restored == i);
// roundtrip
@ -301,12 +306,14 @@ TEST_CASE("MessagePack")
CHECK(j.is_number_integer());
// create expected byte vector
std::vector<uint8_t> expected;
expected.push_back(0xce);
expected.push_back(static_cast<uint8_t>((i >> 24) & 0xff));
expected.push_back(static_cast<uint8_t>((i >> 16) & 0xff));
expected.push_back(static_cast<uint8_t>((i >> 8) & 0xff));
expected.push_back(static_cast<uint8_t>(i & 0xff));
std::vector<uint8_t> const expected
{
0xce,
static_cast<uint8_t>((i >> 24) & 0xff),
static_cast<uint8_t>((i >> 16) & 0xff),
static_cast<uint8_t>((i >> 8) & 0xff),
static_cast<uint8_t>(i & 0xff),
};
// compare result + size
const auto result = json::to_msgpack(j);
@ -315,10 +322,10 @@ TEST_CASE("MessagePack")
// check individual bytes
CHECK(result[0] == 0xce);
uint32_t restored = (static_cast<uint32_t>(result[1]) << 030) +
(static_cast<uint32_t>(result[2]) << 020) +
(static_cast<uint32_t>(result[3]) << 010) +
static_cast<uint32_t>(result[4]);
uint32_t const restored = (static_cast<uint32_t>(result[1]) << 030) +
(static_cast<uint32_t>(result[2]) << 020) +
(static_cast<uint32_t>(result[3]) << 010) +
static_cast<uint32_t>(result[4]);
CHECK(restored == i);
// roundtrip
@ -344,16 +351,18 @@ TEST_CASE("MessagePack")
CHECK(j.is_number_integer());
// create expected byte vector
std::vector<uint8_t> expected;
expected.push_back(0xcf);
expected.push_back(static_cast<uint8_t>((i >> 070) & 0xff));
expected.push_back(static_cast<uint8_t>((i >> 060) & 0xff));
expected.push_back(static_cast<uint8_t>((i >> 050) & 0xff));
expected.push_back(static_cast<uint8_t>((i >> 040) & 0xff));
expected.push_back(static_cast<uint8_t>((i >> 030) & 0xff));
expected.push_back(static_cast<uint8_t>((i >> 020) & 0xff));
expected.push_back(static_cast<uint8_t>((i >> 010) & 0xff));
expected.push_back(static_cast<uint8_t>(i & 0xff));
std::vector<uint8_t> const expected
{
0xcf,
static_cast<uint8_t>((i >> 070) & 0xff),
static_cast<uint8_t>((i >> 060) & 0xff),
static_cast<uint8_t>((i >> 050) & 0xff),
static_cast<uint8_t>((i >> 040) & 0xff),
static_cast<uint8_t>((i >> 030) & 0xff),
static_cast<uint8_t>((i >> 020) & 0xff),
static_cast<uint8_t>((i >> 010) & 0xff),
static_cast<uint8_t>(i & 0xff),
};
// compare result + size
const auto result = json::to_msgpack(j);
@ -362,14 +371,14 @@ TEST_CASE("MessagePack")
// check individual bytes
CHECK(result[0] == 0xcf);
uint64_t restored = (static_cast<uint64_t>(result[1]) << 070) +
(static_cast<uint64_t>(result[2]) << 060) +
(static_cast<uint64_t>(result[3]) << 050) +
(static_cast<uint64_t>(result[4]) << 040) +
(static_cast<uint64_t>(result[5]) << 030) +
(static_cast<uint64_t>(result[6]) << 020) +
(static_cast<uint64_t>(result[7]) << 010) +
static_cast<uint64_t>(result[8]);
uint64_t const restored = (static_cast<uint64_t>(result[1]) << 070) +
(static_cast<uint64_t>(result[2]) << 060) +
(static_cast<uint64_t>(result[3]) << 050) +
(static_cast<uint64_t>(result[4]) << 040) +
(static_cast<uint64_t>(result[5]) << 030) +
(static_cast<uint64_t>(result[6]) << 020) +
(static_cast<uint64_t>(result[7]) << 010) +
static_cast<uint64_t>(result[8]);
CHECK(restored == i);
// roundtrip
@ -385,15 +394,17 @@ TEST_CASE("MessagePack")
CAPTURE(i)
// create JSON value with integer number
json j = i;
json const j = i;
// check type
CHECK(j.is_number_integer());
// create expected byte vector
std::vector<uint8_t> expected;
expected.push_back(0xd0);
expected.push_back(static_cast<uint8_t>(i));
std::vector<uint8_t> const expected
{
0xd0,
static_cast<uint8_t>(i),
};
// compare result + size
const auto result = json::to_msgpack(j);
@ -412,13 +423,13 @@ TEST_CASE("MessagePack")
SECTION("-9263 (int 16)")
{
json j = -9263;
std::vector<uint8_t> expected = {0xd1, 0xdb, 0xd1};
json const j = -9263;
std::vector<uint8_t> const expected = {0xd1, 0xdb, 0xd1};
const auto result = json::to_msgpack(j);
CHECK(result == expected);
auto restored = static_cast<int16_t>((result[1] << 8) + result[2]);
auto const restored = static_cast<int16_t>((result[1] << 8) + result[2]);
CHECK(restored == -9263);
// roundtrip
@ -433,16 +444,18 @@ TEST_CASE("MessagePack")
CAPTURE(i)
// create JSON value with integer number
json j = i;
json const j = i;
// check type
CHECK(j.is_number_integer());
// create expected byte vector
std::vector<uint8_t> expected;
expected.push_back(0xd1);
expected.push_back(static_cast<uint8_t>((i >> 8) & 0xff));
expected.push_back(static_cast<uint8_t>(i & 0xff));
std::vector<uint8_t> const expected
{
0xd1,
static_cast<uint8_t>((i >> 8) & 0xff),
static_cast<uint8_t>(i & 0xff),
};
// compare result + size
const auto result = json::to_msgpack(j);
@ -451,7 +464,7 @@ TEST_CASE("MessagePack")
// check individual bytes
CHECK(result[0] == 0xd1);
auto restored = static_cast<int16_t>((result[1] << 8) + result[2]);
auto const restored = static_cast<int16_t>((result[1] << 8) + result[2]);
CHECK(restored == i);
// roundtrip
@ -462,29 +475,33 @@ TEST_CASE("MessagePack")
SECTION("-32769..-2147483648")
{
std::vector<int32_t> numbers;
numbers.push_back(-32769);
numbers.push_back(-65536);
numbers.push_back(-77777);
numbers.push_back(-1048576);
numbers.push_back(-2147483648LL);
std::vector<int32_t> const numbers
{
-32769,
-65536,
-77777,
-1048576,
-2147483648LL,
};
for (auto i : numbers)
{
CAPTURE(i)
// create JSON value with integer number
json j = i;
json const j = i;
// check type
CHECK(j.is_number_integer());
// create expected byte vector
std::vector<uint8_t> expected;
expected.push_back(0xd2);
expected.push_back(static_cast<uint8_t>((i >> 24) & 0xff));
expected.push_back(static_cast<uint8_t>((i >> 16) & 0xff));
expected.push_back(static_cast<uint8_t>((i >> 8) & 0xff));
expected.push_back(static_cast<uint8_t>(i & 0xff));
std::vector<uint8_t> const expected
{
0xd2,
static_cast<uint8_t>((i >> 24) & 0xff),
static_cast<uint8_t>((i >> 16) & 0xff),
static_cast<uint8_t>((i >> 8) & 0xff),
static_cast<uint8_t>(i & 0xff),
};
// compare result + size
const auto result = json::to_msgpack(j);
@ -493,10 +510,10 @@ TEST_CASE("MessagePack")
// check individual bytes
CHECK(result[0] == 0xd2);
uint32_t restored = (static_cast<uint32_t>(result[1]) << 030) +
(static_cast<uint32_t>(result[2]) << 020) +
(static_cast<uint32_t>(result[3]) << 010) +
static_cast<uint32_t>(result[4]);
uint32_t const restored = (static_cast<uint32_t>(result[1]) << 030) +
(static_cast<uint32_t>(result[2]) << 020) +
(static_cast<uint32_t>(result[3]) << 010) +
static_cast<uint32_t>(result[4]);
CHECK(static_cast<std::int32_t>(restored) == i);
// roundtrip
@ -507,30 +524,34 @@ TEST_CASE("MessagePack")
SECTION("-9223372036854775808..-2147483649 (int 64)")
{
std::vector<int64_t> numbers;
numbers.push_back(INT64_MIN);
numbers.push_back(-2147483649LL);
std::vector<int64_t> numbers
{
INT64_MIN,
-2147483649LL,
};
for (auto i : numbers)
{
CAPTURE(i)
// create JSON value with unsigned integer number
json j = i;
json const j = i;
// check type
CHECK(j.is_number_integer());
// create expected byte vector
std::vector<uint8_t> expected;
expected.push_back(0xd3);
expected.push_back(static_cast<uint8_t>((i >> 070) & 0xff));
expected.push_back(static_cast<uint8_t>((i >> 060) & 0xff));
expected.push_back(static_cast<uint8_t>((i >> 050) & 0xff));
expected.push_back(static_cast<uint8_t>((i >> 040) & 0xff));
expected.push_back(static_cast<uint8_t>((i >> 030) & 0xff));
expected.push_back(static_cast<uint8_t>((i >> 020) & 0xff));
expected.push_back(static_cast<uint8_t>((i >> 010) & 0xff));
expected.push_back(static_cast<uint8_t>(i & 0xff));
std::vector<uint8_t> const expected
{
0xd3,
static_cast<uint8_t>((i >> 070) & 0xff),
static_cast<uint8_t>((i >> 060) & 0xff),
static_cast<uint8_t>((i >> 050) & 0xff),
static_cast<uint8_t>((i >> 040) & 0xff),
static_cast<uint8_t>((i >> 030) & 0xff),
static_cast<uint8_t>((i >> 020) & 0xff),
static_cast<uint8_t>((i >> 010) & 0xff),
static_cast<uint8_t>(i & 0xff),
};
// compare result + size
const auto result = json::to_msgpack(j);
@ -539,14 +560,14 @@ TEST_CASE("MessagePack")
// check individual bytes
CHECK(result[0] == 0xd3);
int64_t restored = (static_cast<int64_t>(result[1]) << 070) +
(static_cast<int64_t>(result[2]) << 060) +
(static_cast<int64_t>(result[3]) << 050) +
(static_cast<int64_t>(result[4]) << 040) +
(static_cast<int64_t>(result[5]) << 030) +
(static_cast<int64_t>(result[6]) << 020) +
(static_cast<int64_t>(result[7]) << 010) +
static_cast<int64_t>(result[8]);
int64_t const restored = (static_cast<int64_t>(result[1]) << 070) +
(static_cast<int64_t>(result[2]) << 060) +
(static_cast<int64_t>(result[3]) << 050) +
(static_cast<int64_t>(result[4]) << 040) +
(static_cast<int64_t>(result[5]) << 030) +
(static_cast<int64_t>(result[6]) << 020) +
(static_cast<int64_t>(result[7]) << 010) +
static_cast<int64_t>(result[8]);
CHECK(restored == i);
// roundtrip
@ -565,14 +586,13 @@ TEST_CASE("MessagePack")
CAPTURE(i)
// create JSON value with unsigned integer number
json j = i;
json const j = i;
// check type
CHECK(j.is_number_unsigned());
// create expected byte vector
std::vector<uint8_t> expected;
expected.push_back(static_cast<uint8_t>(i));
std::vector<uint8_t> const expected{static_cast<uint8_t>(i)};
// compare result + size
const auto result = json::to_msgpack(j);
@ -595,15 +615,17 @@ TEST_CASE("MessagePack")
CAPTURE(i)
// create JSON value with unsigned integer number
json j = i;
json const j = i;
// check type
CHECK(j.is_number_unsigned());
// create expected byte vector
std::vector<uint8_t> expected;
expected.push_back(0xcc);
expected.push_back(static_cast<uint8_t>(i));
std::vector<uint8_t> const expected
{
0xcc,
static_cast<uint8_t>(i),
};
// compare result + size
const auto result = json::to_msgpack(j);
@ -612,7 +634,7 @@ TEST_CASE("MessagePack")
// check individual bytes
CHECK(result[0] == 0xcc);
auto restored = static_cast<uint8_t>(result[1]);
auto const restored = static_cast<uint8_t>(result[1]);
CHECK(restored == i);
// roundtrip
@ -628,16 +650,18 @@ TEST_CASE("MessagePack")
CAPTURE(i)
// create JSON value with unsigned integer number
json j = i;
json const j = i;
// check type
CHECK(j.is_number_unsigned());
// create expected byte vector
std::vector<uint8_t> expected;
expected.push_back(0xcd);
expected.push_back(static_cast<uint8_t>((i >> 8) & 0xff));
expected.push_back(static_cast<uint8_t>(i & 0xff));
std::vector<uint8_t> const expected
{
0xcd,
static_cast<uint8_t>((i >> 8) & 0xff),
static_cast<uint8_t>(i & 0xff),
};
// compare result + size
const auto result = json::to_msgpack(j);
@ -646,7 +670,7 @@ TEST_CASE("MessagePack")
// check individual bytes
CHECK(result[0] == 0xcd);
auto restored = static_cast<uint16_t>(static_cast<uint8_t>(result[1]) * 256 + static_cast<uint8_t>(result[2]));
auto const restored = static_cast<uint16_t>(static_cast<uint8_t>(result[1]) * 256 + static_cast<uint8_t>(result[2]));
CHECK(restored == i);
// roundtrip
@ -657,7 +681,7 @@ TEST_CASE("MessagePack")
SECTION("65536..4294967295 (uint 32)")
{
for (uint32_t i :
for (const uint32_t i :
{
65536u, 77777u, 1048576u, 4294967295u
})
@ -665,18 +689,20 @@ TEST_CASE("MessagePack")
CAPTURE(i)
// create JSON value with unsigned integer number
json j = i;
json const j = i;
// check type
CHECK(j.is_number_unsigned());
// create expected byte vector
std::vector<uint8_t> expected;
expected.push_back(0xce);
expected.push_back(static_cast<uint8_t>((i >> 24) & 0xff));
expected.push_back(static_cast<uint8_t>((i >> 16) & 0xff));
expected.push_back(static_cast<uint8_t>((i >> 8) & 0xff));
expected.push_back(static_cast<uint8_t>(i & 0xff));
std::vector<uint8_t> const expected
{
0xce,
static_cast<uint8_t>((i >> 24) & 0xff),
static_cast<uint8_t>((i >> 16) & 0xff),
static_cast<uint8_t>((i >> 8) & 0xff),
static_cast<uint8_t>(i & 0xff),
};
// compare result + size
const auto result = json::to_msgpack(j);
@ -685,10 +711,10 @@ TEST_CASE("MessagePack")
// check individual bytes
CHECK(result[0] == 0xce);
uint32_t restored = (static_cast<uint32_t>(result[1]) << 030) +
(static_cast<uint32_t>(result[2]) << 020) +
(static_cast<uint32_t>(result[3]) << 010) +
static_cast<uint32_t>(result[4]);
uint32_t const restored = (static_cast<uint32_t>(result[1]) << 030) +
(static_cast<uint32_t>(result[2]) << 020) +
(static_cast<uint32_t>(result[3]) << 010) +
static_cast<uint32_t>(result[4]);
CHECK(restored == i);
// roundtrip
@ -699,7 +725,7 @@ TEST_CASE("MessagePack")
SECTION("4294967296..18446744073709551615 (uint 64)")
{
for (uint64_t i :
for (const uint64_t i :
{
4294967296LU, 18446744073709551615LU
})
@ -707,22 +733,24 @@ TEST_CASE("MessagePack")
CAPTURE(i)
// create JSON value with unsigned integer number
json j = i;
json const j = i;
// check type
CHECK(j.is_number_unsigned());
// create expected byte vector
std::vector<uint8_t> expected;
expected.push_back(0xcf);
expected.push_back(static_cast<uint8_t>((i >> 070) & 0xff));
expected.push_back(static_cast<uint8_t>((i >> 060) & 0xff));
expected.push_back(static_cast<uint8_t>((i >> 050) & 0xff));
expected.push_back(static_cast<uint8_t>((i >> 040) & 0xff));
expected.push_back(static_cast<uint8_t>((i >> 030) & 0xff));
expected.push_back(static_cast<uint8_t>((i >> 020) & 0xff));
expected.push_back(static_cast<uint8_t>((i >> 010) & 0xff));
expected.push_back(static_cast<uint8_t>(i & 0xff));
std::vector<uint8_t> const expected
{
0xcf,
static_cast<uint8_t>((i >> 070) & 0xff),
static_cast<uint8_t>((i >> 060) & 0xff),
static_cast<uint8_t>((i >> 050) & 0xff),
static_cast<uint8_t>((i >> 040) & 0xff),
static_cast<uint8_t>((i >> 030) & 0xff),
static_cast<uint8_t>((i >> 020) & 0xff),
static_cast<uint8_t>((i >> 010) & 0xff),
static_cast<uint8_t>(i & 0xff),
};
// compare result + size
const auto result = json::to_msgpack(j);
@ -731,14 +759,14 @@ TEST_CASE("MessagePack")
// check individual bytes
CHECK(result[0] == 0xcf);
uint64_t restored = (static_cast<uint64_t>(result[1]) << 070) +
(static_cast<uint64_t>(result[2]) << 060) +
(static_cast<uint64_t>(result[3]) << 050) +
(static_cast<uint64_t>(result[4]) << 040) +
(static_cast<uint64_t>(result[5]) << 030) +
(static_cast<uint64_t>(result[6]) << 020) +
(static_cast<uint64_t>(result[7]) << 010) +
static_cast<uint64_t>(result[8]);
uint64_t const restored = (static_cast<uint64_t>(result[1]) << 070) +
(static_cast<uint64_t>(result[2]) << 060) +
(static_cast<uint64_t>(result[3]) << 050) +
(static_cast<uint64_t>(result[4]) << 040) +
(static_cast<uint64_t>(result[5]) << 030) +
(static_cast<uint64_t>(result[6]) << 020) +
(static_cast<uint64_t>(result[7]) << 010) +
static_cast<uint64_t>(result[8]);
CHECK(restored == i);
// roundtrip
@ -752,9 +780,9 @@ TEST_CASE("MessagePack")
{
SECTION("3.1415925")
{
double v = 3.1415925;
json j = v;
std::vector<uint8_t> expected =
double const v = 3.1415925;
json const j = v;
std::vector<uint8_t> const expected =
{
0xcb, 0x40, 0x09, 0x21, 0xfb, 0x3f, 0xa6, 0xde, 0xfc
};
@ -769,9 +797,9 @@ TEST_CASE("MessagePack")
SECTION("1.0")
{
double v = 1.0;
json j = v;
std::vector<uint8_t> expected =
double const v = 1.0;
json const j = v;
std::vector<uint8_t> const expected =
{
0xca, 0x3f, 0x80, 0x00, 0x00
};
@ -786,9 +814,9 @@ TEST_CASE("MessagePack")
SECTION("128.128")
{
double v = 128.1280059814453125;
json j = v;
std::vector<uint8_t> expected =
double const v = 128.1280059814453125;
json const j = v;
std::vector<uint8_t> const expected =
{
0xca, 0x43, 0x00, 0x20, 0xc5
};
@ -822,7 +850,7 @@ TEST_CASE("MessagePack")
// create JSON value with string containing of N * 'x'
const auto s = std::string(N, 'x');
json j = s;
json const j = s;
// create expected byte vector
std::vector<uint8_t> expected;
@ -859,7 +887,7 @@ TEST_CASE("MessagePack")
// create JSON value with string containing of N * 'x'
const auto s = std::string(N, 'x');
json j = s;
json const j = s;
// create expected byte vector
std::vector<uint8_t> expected;
@ -894,7 +922,7 @@ TEST_CASE("MessagePack")
// create JSON value with string containing of N * 'x'
const auto s = std::string(N, 'x');
json j = s;
json const j = s;
// create expected byte vector (hack: create string first)
std::vector<uint8_t> expected(N, 'x');
@ -927,7 +955,7 @@ TEST_CASE("MessagePack")
// create JSON value with string containing of N * 'x'
const auto s = std::string(N, 'x');
json j = s;
json const j = s;
// create expected byte vector (hack: create string first)
std::vector<uint8_t> expected(N, 'x');
@ -956,8 +984,8 @@ TEST_CASE("MessagePack")
{
SECTION("empty")
{
json j = json::array();
std::vector<uint8_t> expected = {0x90};
json const j = json::array();
std::vector<uint8_t> const expected = {0x90};
const auto result = json::to_msgpack(j);
CHECK(result == expected);
@ -968,8 +996,8 @@ TEST_CASE("MessagePack")
SECTION("[null]")
{
json j = {nullptr};
std::vector<uint8_t> expected = {0x91, 0xc0};
json const j = {nullptr};
std::vector<uint8_t> const expected = {0x91, 0xc0};
const auto result = json::to_msgpack(j);
CHECK(result == expected);
@ -980,8 +1008,8 @@ TEST_CASE("MessagePack")
SECTION("[1,2,3,4,5]")
{
json j = json::parse("[1,2,3,4,5]");
std::vector<uint8_t> expected = {0x95, 0x01, 0x02, 0x03, 0x04, 0x05};
json const j = json::parse("[1,2,3,4,5]");
std::vector<uint8_t> const expected = {0x95, 0x01, 0x02, 0x03, 0x04, 0x05};
const auto result = json::to_msgpack(j);
CHECK(result == expected);
@ -992,8 +1020,8 @@ TEST_CASE("MessagePack")
SECTION("[[[[]]]]")
{
json j = json::parse("[[[[]]]]");
std::vector<uint8_t> expected = {0x91, 0x91, 0x91, 0x90};
json const j = json::parse("[[[[]]]]");
std::vector<uint8_t> const expected = {0x91, 0x91, 0x91, 0x90};
const auto result = json::to_msgpack(j);
CHECK(result == expected);
@ -1046,8 +1074,8 @@ TEST_CASE("MessagePack")
{
SECTION("empty")
{
json j = json::object();
std::vector<uint8_t> expected = {0x80};
json const j = json::object();
std::vector<uint8_t> const expected = {0x80};
const auto result = json::to_msgpack(j);
CHECK(result == expected);
@ -1058,8 +1086,8 @@ TEST_CASE("MessagePack")
SECTION("{\"\":null}")
{
json j = {{"", nullptr}};
std::vector<uint8_t> expected = {0x81, 0xa0, 0xc0};
json const j = {{"", nullptr}};
std::vector<uint8_t> const expected = {0x81, 0xa0, 0xc0};
const auto result = json::to_msgpack(j);
CHECK(result == expected);
@ -1070,8 +1098,8 @@ TEST_CASE("MessagePack")
SECTION("{\"a\": {\"b\": {\"c\": {}}}}")
{
json j = json::parse(R"({"a": {"b": {"c": {}}}})");
std::vector<uint8_t> expected =
json const j = json::parse(R"({"a": {"b": {"c": {}}}})");
std::vector<uint8_t> const expected =
{
0x81, 0xa1, 0x61, 0x81, 0xa1, 0x62, 0x81, 0xa1, 0x63, 0x80
};
@ -1085,7 +1113,7 @@ TEST_CASE("MessagePack")
SECTION("map 16")
{
json j = R"({"00": null, "01": null, "02": null, "03": null,
json const j = R"({"00": null, "01": null, "02": null, "03": null,
"04": null, "05": null, "06": null, "07": null,
"08": null, "09": null, "10": null, "11": null,
"12": null, "13": null, "14": null, "15": null})"_json;
@ -1298,7 +1326,7 @@ TEST_CASE("MessagePack")
// create JSON value with byte array containing of N * 'x'
const auto s = std::vector<uint8_t>(N, 'x');
json j = json::binary(s);
json const j = json::binary(s);
// create expected byte vector
std::vector<std::uint8_t> expected;
@ -1336,7 +1364,7 @@ TEST_CASE("MessagePack")
// create JSON value with string containing of N * 'x'
const auto s = std::vector<std::uint8_t>(N, 'x');
json j = json::binary(s);
json const j = json::binary(s);
// create expected byte vector (hack: create string first)
std::vector<std::uint8_t> expected(N, 'x');
@ -1369,7 +1397,7 @@ TEST_CASE("MessagePack")
// create JSON value with string containing of N * 'x'
const auto s = std::vector<std::uint8_t>(N, 'x');
json j = json::binary(s);
json const j = json::binary(s);
// create expected byte vector (hack: create string first)
std::vector<uint8_t> expected(N, 'x');

File diff suppressed because it is too large Load Diff

View File

@ -20,7 +20,7 @@
// doctest doesn't support THROWS_WITH for std::string out of the box (has to include <string>...)
#define CHECK_THROWS_WITH_STD_STR_IMPL(expr, str, var_name) \
do { \
std::string var_name = str; \
const std::string var_name = str; \
CHECK_THROWS_WITH(expr, var_name.c_str()); \
} while (false)
#define CHECK_THROWS_WITH_STD_STR(expr, str) \