🚨 fix Clang-Tidy warnings

This commit is contained in:
Niels Lohmann 2022-09-10 21:12:42 +02:00
parent 47550051e8
commit f844148560
No known key found for this signature in database
GPG Key ID: 7F3CEA63AE251B69
5 changed files with 377 additions and 377 deletions

File diff suppressed because it is too large Load Diff

View File

@ -104,7 +104,7 @@ TEST_CASE("CBOR")
SECTION("discarded")
{
// discarded values are not serialized
json j = json::value_t::discarded;
json const j = json::value_t::discarded;
const auto result = json::to_cbor(j);
CHECK(result.empty());
}
@ -112,7 +112,7 @@ TEST_CASE("CBOR")
SECTION("NaN")
{
// NaN value
json j = std::numeric_limits<json::number_float_t>::quiet_NaN();
json const j = std::numeric_limits<json::number_float_t>::quiet_NaN();
std::vector<uint8_t> expected = {0xf9, 0x7e, 0x00};
const auto result = json::to_cbor(j);
CHECK(result == expected);
@ -121,7 +121,7 @@ TEST_CASE("CBOR")
SECTION("Infinity")
{
// Infinity value
json j = std::numeric_limits<json::number_float_t>::infinity();
json const j = std::numeric_limits<json::number_float_t>::infinity();
std::vector<uint8_t> expected = {0xf9, 0x7c, 0x00};
const auto result = json::to_cbor(j);
CHECK(result == expected);
@ -985,21 +985,21 @@ TEST_CASE("CBOR")
{
SECTION("0 (0 00000 0000000000)")
{
json j = json::from_cbor(std::vector<uint8_t>({0xf9, 0x00, 0x00}));
json const j = json::from_cbor(std::vector<uint8_t>({0xf9, 0x00, 0x00}));
json::number_float_t d{j};
CHECK(d == 0.0);
}
SECTION("-0 (1 00000 0000000000)")
{
json j = json::from_cbor(std::vector<uint8_t>({0xf9, 0x80, 0x00}));
json const j = json::from_cbor(std::vector<uint8_t>({0xf9, 0x80, 0x00}));
json::number_float_t d{j};
CHECK(d == -0.0);
}
SECTION("2**-24 (0 00000 0000000001)")
{
json j = json::from_cbor(std::vector<uint8_t>({0xf9, 0x00, 0x01}));
json const j = json::from_cbor(std::vector<uint8_t>({0xf9, 0x00, 0x01}));
json::number_float_t d{j};
CHECK(d == std::pow(2.0, -24.0));
}
@ -1009,7 +1009,7 @@ TEST_CASE("CBOR")
{
SECTION("infinity (0 11111 0000000000)")
{
json j = json::from_cbor(std::vector<uint8_t>({0xf9, 0x7c, 0x00}));
json const j = json::from_cbor(std::vector<uint8_t>({0xf9, 0x7c, 0x00}));
json::number_float_t d{j};
CHECK(d == std::numeric_limits<json::number_float_t>::infinity());
CHECK(j.dump() == "null");
@ -1017,7 +1017,7 @@ TEST_CASE("CBOR")
SECTION("-infinity (1 11111 0000000000)")
{
json j = json::from_cbor(std::vector<uint8_t>({0xf9, 0xfc, 0x00}));
json const j = json::from_cbor(std::vector<uint8_t>({0xf9, 0xfc, 0x00}));
json::number_float_t d{j};
CHECK(d == -std::numeric_limits<json::number_float_t>::infinity());
CHECK(j.dump() == "null");
@ -1028,21 +1028,21 @@ TEST_CASE("CBOR")
{
SECTION("1 (0 01111 0000000000)")
{
json j = json::from_cbor(std::vector<uint8_t>({0xf9, 0x3c, 0x00}));
json const j = json::from_cbor(std::vector<uint8_t>({0xf9, 0x3c, 0x00}));
json::number_float_t d{j};
CHECK(d == 1);
}
SECTION("-2 (1 10000 0000000000)")
{
json j = json::from_cbor(std::vector<uint8_t>({0xf9, 0xc0, 0x00}));
json const j = json::from_cbor(std::vector<uint8_t>({0xf9, 0xc0, 0x00}));
json::number_float_t d{j};
CHECK(d == -2);
}
SECTION("65504 (0 11110 1111111111)")
{
json j = json::from_cbor(std::vector<uint8_t>({0xf9, 0x7b, 0xff}));
json const j = json::from_cbor(std::vector<uint8_t>({0xf9, 0x7b, 0xff}));
json::number_float_t d{j};
CHECK(d == 65504);
}
@ -1050,16 +1050,16 @@ TEST_CASE("CBOR")
SECTION("infinity")
{
json j = json::from_cbor(std::vector<uint8_t>({0xf9, 0x7c, 0x00}));
json::number_float_t d{j};
json const j = json::from_cbor(std::vector<uint8_t>({0xf9, 0x7c, 0x00}));
json::number_float_t const d{j};
CHECK(!std::isfinite(d));
CHECK(j.dump() == "null");
}
SECTION("NaN")
{
json j = json::from_cbor(std::vector<uint8_t>({0xf9, 0x7e, 0x00}));
json::number_float_t d{j};
json const j = json::from_cbor(std::vector<uint8_t>({0xf9, 0x7e, 0x00}));
json::number_float_t const d{j};
CHECK(std::isnan(d));
CHECK(j.dump() == "null");
}
@ -1553,7 +1553,7 @@ TEST_CASE("CBOR")
SECTION("indefinite size")
{
std::vector<std::uint8_t> input = {0x5F, 0x44, 0xaa, 0xbb, 0xcc, 0xdd, 0x43, 0xee, 0xff, 0x99, 0xFF};
std::vector<std::uint8_t> const input = {0x5F, 0x44, 0xaa, 0xbb, 0xcc, 0xdd, 0x43, 0xee, 0xff, 0x99, 0xFF};
auto j = json::from_cbor(input);
CHECK(j.is_binary());
auto k = json::binary({0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, 0x99});
@ -1564,7 +1564,7 @@ TEST_CASE("CBOR")
SECTION("binary in array")
{
// array with three empty byte strings
std::vector<std::uint8_t> input = {0x83, 0x40, 0x40, 0x40};
std::vector<std::uint8_t> const input = {0x83, 0x40, 0x40, 0x40};
json _;
CHECK_NOTHROW(_ = json::from_cbor(input));
}
@ -1572,7 +1572,7 @@ TEST_CASE("CBOR")
SECTION("binary in object")
{
// object mapping "foo" to empty byte string
std::vector<std::uint8_t> input = {0xA1, 0x63, 0x66, 0x6F, 0x6F, 0x40};
std::vector<std::uint8_t> const input = {0xA1, 0x63, 0x66, 0x6F, 0x6F, 0x40};
json _;
CHECK_NOTHROW(_ = json::from_cbor(input));
}
@ -1580,7 +1580,7 @@ TEST_CASE("CBOR")
SECTION("SAX callback with binary")
{
// object mapping "foo" to byte string
std::vector<std::uint8_t> input = {0xA1, 0x63, 0x66, 0x6F, 0x6F, 0x41, 0x00};
std::vector<std::uint8_t> const input = {0xA1, 0x63, 0x66, 0x6F, 0x6F, 0x41, 0x00};
// callback to set binary_seen to true if a binary value was seen
bool binary_seen = false;
@ -1606,7 +1606,7 @@ TEST_CASE("CBOR")
{
SECTION("0x5b (byte array)")
{
std::vector<uint8_t> given = {0x5b, 0x00, 0x00, 0x00, 0x00,
std::vector<uint8_t> const given = {0x5b, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x01, 0x61
};
json j = json::from_cbor(given);
@ -1615,7 +1615,7 @@ TEST_CASE("CBOR")
SECTION("0x7b (string)")
{
std::vector<uint8_t> given = {0x7b, 0x00, 0x00, 0x00, 0x00,
std::vector<uint8_t> const given = {0x7b, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x01, 0x61
};
json j = json::from_cbor(given);
@ -1624,7 +1624,7 @@ TEST_CASE("CBOR")
SECTION("0x9b (array)")
{
std::vector<uint8_t> given = {0x9b, 0x00, 0x00, 0x00, 0x00,
std::vector<uint8_t> const given = {0x9b, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x01, 0xf4
};
json j = json::from_cbor(given);
@ -1633,7 +1633,7 @@ TEST_CASE("CBOR")
SECTION("0xbb (map)")
{
std::vector<uint8_t> given = {0xbb, 0x00, 0x00, 0x00, 0x00,
std::vector<uint8_t> const given = {0xbb, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x01, 0x60, 0xf4
};
json j = json::from_cbor(given);
@ -1778,7 +1778,7 @@ TEST_CASE("CBOR")
SECTION("strict mode")
{
std::vector<uint8_t> vec = {0xf6, 0xf6};
std::vector<uint8_t> const vec = {0xf6, 0xf6};
SECTION("non-strict mode")
{
const auto result = json::from_cbor(vec, false);
@ -1799,21 +1799,21 @@ TEST_CASE("CBOR")
{
SECTION("start_array(len)")
{
std::vector<uint8_t> v = {0x83, 0x01, 0x02, 0x03};
std::vector<uint8_t> const v = {0x83, 0x01, 0x02, 0x03};
SaxCountdown scp(0);
CHECK(!json::sax_parse(v, &scp, json::input_format_t::cbor));
}
SECTION("start_object(len)")
{
std::vector<uint8_t> v = {0xA1, 0x63, 0x66, 0x6F, 0x6F, 0xF4};
std::vector<uint8_t> const v = {0xA1, 0x63, 0x66, 0x6F, 0x6F, 0xF4};
SaxCountdown scp(0);
CHECK(!json::sax_parse(v, &scp, json::input_format_t::cbor));
}
SECTION("key()")
{
std::vector<uint8_t> v = {0xA1, 0x63, 0x66, 0x6F, 0x6F, 0xF4};
std::vector<uint8_t> const v = {0xA1, 0x63, 0x66, 0x6F, 0x6F, 0xF4};
SaxCountdown scp(1);
CHECK(!json::sax_parse(v, &scp, json::input_format_t::cbor));
}
@ -1825,7 +1825,7 @@ TEST_CASE("single CBOR roundtrip")
{
SECTION("sample.json")
{
std::string filename = TEST_DATA_DIRECTORY "/json_testsuite/sample.json";
std::string const filename = TEST_DATA_DIRECTORY "/json_testsuite/sample.json";
// parse JSON file
std::ifstream f_json(filename);
@ -1910,7 +1910,7 @@ TEST_CASE("CBOR regressions")
try
{
// step 2: round trip
std::vector<uint8_t> vec2 = json::to_cbor(j1);
std::vector<uint8_t> const vec2 = json::to_cbor(j1);
// parse serialization
json j2 = json::from_cbor(vec2);
@ -2151,7 +2151,7 @@ TEST_CASE("CBOR roundtrips" * doctest::skip())
INFO_WITH_TEMP(filename + ": output to output adapters");
// parse JSON file
std::ifstream f_json(filename);
json j1 = json::parse(f_json);
json const j1 = json::parse(f_json);
// parse CBOR file
auto packed = utils::read_binary_file(filename + ".cbor");

View File

@ -20,27 +20,27 @@ TEST_CASE("const_iterator class")
{
SECTION("null")
{
json j(json::value_t::null);
json::const_iterator it(&j);
json const j(json::value_t::null);
json::const_iterator const it(&j);
}
SECTION("object")
{
json j(json::value_t::object);
json::const_iterator it(&j);
json const j(json::value_t::object);
json::const_iterator const it(&j);
}
SECTION("array")
{
json j(json::value_t::array);
json::const_iterator it(&j);
json const j(json::value_t::array);
json::const_iterator const it(&j);
}
}
SECTION("copy assignment")
{
json j(json::value_t::null);
json::const_iterator it(&j);
json const j(json::value_t::null);
json::const_iterator const it(&j);
json::const_iterator it2(&j);
it2 = it;
}
@ -50,14 +50,14 @@ TEST_CASE("const_iterator class")
SECTION("create from uninitialized iterator")
{
const json::iterator it {};
json::const_iterator cit(it);
json::const_iterator const cit(it);
}
SECTION("create from initialized iterator")
{
json j;
const json::iterator it = j.begin();
json::const_iterator cit(it);
json::const_iterator const cit(it);
}
}
}
@ -68,7 +68,7 @@ TEST_CASE("const_iterator class")
{
SECTION("null")
{
json j(json::value_t::null);
json const j(json::value_t::null);
json::const_iterator it(&j);
it.set_begin();
CHECK((it == j.cbegin()));
@ -76,7 +76,7 @@ TEST_CASE("const_iterator class")
SECTION("object")
{
json j(json::value_t::object);
json const j(json::value_t::object);
json::const_iterator it(&j);
it.set_begin();
CHECK((it == j.cbegin()));
@ -84,7 +84,7 @@ TEST_CASE("const_iterator class")
SECTION("array")
{
json j(json::value_t::array);
json const j(json::value_t::array);
json::const_iterator it(&j);
it.set_begin();
CHECK((it == j.cbegin()));
@ -95,7 +95,7 @@ TEST_CASE("const_iterator class")
{
SECTION("null")
{
json j(json::value_t::null);
json const j(json::value_t::null);
json::const_iterator it(&j);
it.set_end();
CHECK((it == j.cend()));
@ -103,7 +103,7 @@ TEST_CASE("const_iterator class")
SECTION("object")
{
json j(json::value_t::object);
json const j(json::value_t::object);
json::const_iterator it(&j);
it.set_end();
CHECK((it == j.cend()));
@ -111,7 +111,7 @@ TEST_CASE("const_iterator class")
SECTION("array")
{
json j(json::value_t::array);
json const j(json::value_t::array);
json::const_iterator it(&j);
it.set_end();
CHECK((it == j.cend()));
@ -125,14 +125,14 @@ TEST_CASE("const_iterator class")
{
SECTION("null")
{
json j(json::value_t::null);
json::const_iterator it = j.cbegin();
json const j(json::value_t::null);
json::const_iterator const it = j.cbegin();
CHECK_THROWS_WITH_AS(*it, "[json.exception.invalid_iterator.214] cannot get value", json::invalid_iterator&);
}
SECTION("number")
{
json j(17);
json const j(17);
json::const_iterator it = j.cbegin();
CHECK(*it == json(17));
it = j.cend();
@ -141,15 +141,15 @@ TEST_CASE("const_iterator class")
SECTION("object")
{
json j({{"foo", "bar"}});
json::const_iterator it = j.cbegin();
json const j({{"foo", "bar"}});
json::const_iterator const it = j.cbegin();
CHECK(*it == json("bar"));
}
SECTION("array")
{
json j({1, 2, 3, 4});
json::const_iterator it = j.cbegin();
json const j({1, 2, 3, 4});
json::const_iterator const it = j.cbegin();
CHECK(*it == json(1));
}
}
@ -158,14 +158,14 @@ TEST_CASE("const_iterator class")
{
SECTION("null")
{
json j(json::value_t::null);
json::const_iterator it = j.cbegin();
json const j(json::value_t::null);
json::const_iterator const it = j.cbegin();
CHECK_THROWS_WITH_AS(std::string(it->type_name()), "[json.exception.invalid_iterator.214] cannot get value", json::invalid_iterator&);
}
SECTION("number")
{
json j(17);
json const j(17);
json::const_iterator it = j.cbegin();
CHECK(std::string(it->type_name()) == "number");
it = j.cend();
@ -174,15 +174,15 @@ TEST_CASE("const_iterator class")
SECTION("object")
{
json j({{"foo", "bar"}});
json::const_iterator it = j.cbegin();
json const j({{"foo", "bar"}});
json::const_iterator const it = j.cbegin();
CHECK(std::string(it->type_name()) == "string");
}
SECTION("array")
{
json j({1, 2, 3, 4});
json::const_iterator it = j.cbegin();
json const j({1, 2, 3, 4});
json::const_iterator const it = j.cbegin();
CHECK(std::string(it->type_name()) == "number");
}
}
@ -194,7 +194,7 @@ TEST_CASE("const_iterator class")
{
SECTION("null")
{
json j(json::value_t::null);
json const j(json::value_t::null);
json::const_iterator it = j.cbegin();
CHECK((it.m_it.primitive_iterator.m_it == 1));
it++;
@ -203,7 +203,7 @@ TEST_CASE("const_iterator class")
SECTION("number")
{
json j(17);
json const j(17);
json::const_iterator it = j.cbegin();
CHECK((it.m_it.primitive_iterator.m_it == 0));
it++;
@ -214,7 +214,7 @@ TEST_CASE("const_iterator class")
SECTION("object")
{
json j({{"foo", "bar"}});
json const j({{"foo", "bar"}});
json::const_iterator it = j.cbegin();
CHECK((it.m_it.object_iterator == it.m_object->m_value.object->begin()));
it++;
@ -223,7 +223,7 @@ TEST_CASE("const_iterator class")
SECTION("array")
{
json j({1, 2, 3, 4});
json const j({1, 2, 3, 4});
json::const_iterator it = j.cbegin();
CHECK((it.m_it.array_iterator == it.m_object->m_value.array->begin()));
it++;
@ -245,7 +245,7 @@ TEST_CASE("const_iterator class")
{
SECTION("null")
{
json j(json::value_t::null);
json const j(json::value_t::null);
json::const_iterator it = j.cbegin();
CHECK((it.m_it.primitive_iterator.m_it == 1));
++it;
@ -254,7 +254,7 @@ TEST_CASE("const_iterator class")
SECTION("number")
{
json j(17);
json const j(17);
json::const_iterator it = j.cbegin();
CHECK((it.m_it.primitive_iterator.m_it == 0));
++it;
@ -265,7 +265,7 @@ TEST_CASE("const_iterator class")
SECTION("object")
{
json j({{"foo", "bar"}});
json const j({{"foo", "bar"}});
json::const_iterator it = j.cbegin();
CHECK((it.m_it.object_iterator == it.m_object->m_value.object->begin()));
++it;
@ -274,7 +274,7 @@ TEST_CASE("const_iterator class")
SECTION("array")
{
json j({1, 2, 3, 4});
json const j({1, 2, 3, 4});
json::const_iterator it = j.cbegin();
CHECK((it.m_it.array_iterator == it.m_object->m_value.array->begin()));
++it;
@ -296,14 +296,14 @@ TEST_CASE("const_iterator class")
{
SECTION("null")
{
json j(json::value_t::null);
json::const_iterator it = j.cend();
json const j(json::value_t::null);
json::const_iterator const it = j.cend();
CHECK((it.m_it.primitive_iterator.m_it == 1));
}
SECTION("number")
{
json j(17);
json const j(17);
json::const_iterator it = j.cend();
CHECK((it.m_it.primitive_iterator.m_it == 1));
it--;
@ -314,7 +314,7 @@ TEST_CASE("const_iterator class")
SECTION("object")
{
json j({{"foo", "bar"}});
json const j({{"foo", "bar"}});
json::const_iterator it = j.cend();
CHECK((it.m_it.object_iterator == it.m_object->m_value.object->end()));
it--;
@ -323,7 +323,7 @@ TEST_CASE("const_iterator class")
SECTION("array")
{
json j({1, 2, 3, 4});
json const j({1, 2, 3, 4});
json::const_iterator it = j.cend();
CHECK((it.m_it.array_iterator == it.m_object->m_value.array->end()));
it--;
@ -345,14 +345,14 @@ TEST_CASE("const_iterator class")
{
SECTION("null")
{
json j(json::value_t::null);
json::const_iterator it = j.cend();
json const j(json::value_t::null);
json::const_iterator const it = j.cend();
CHECK((it.m_it.primitive_iterator.m_it == 1));
}
SECTION("number")
{
json j(17);
json const j(17);
json::const_iterator it = j.cend();
CHECK((it.m_it.primitive_iterator.m_it == 1));
--it;
@ -363,7 +363,7 @@ TEST_CASE("const_iterator class")
SECTION("object")
{
json j({{"foo", "bar"}});
json const j({{"foo", "bar"}});
json::const_iterator it = j.cend();
CHECK((it.m_it.object_iterator == it.m_object->m_value.object->end()));
--it;
@ -372,7 +372,7 @@ TEST_CASE("const_iterator class")
SECTION("array")
{
json j({1, 2, 3, 4});
json const j({1, 2, 3, 4});
json::const_iterator it = j.cend();
CHECK((it.m_it.array_iterator == it.m_object->m_value.array->end()));
--it;

View File

@ -47,7 +47,7 @@ TEST_CASE("value conversion")
SECTION("json::object_t")
{
json::object_t o = j.get<json::object_t>();
json::object_t const const o = j.get<json::object_t>();
CHECK(json(o) == j);
}
@ -410,7 +410,7 @@ TEST_CASE("value conversion")
#if defined(JSON_HAS_CPP_17)
SECTION("std::string_view")
{
std::string_view s = j.get<std::string_view>();
std::string_view const s = j.get<std::string_view>();
CHECK(json(s) == j);
}
#endif
@ -482,7 +482,7 @@ TEST_CASE("value conversion")
#if defined(JSON_HAS_CPP_17)
SECTION("std::string_view")
{
std::string s = "previous value";
std::string const s = "previous value";
std::string_view sv = s;
j.get_to(sv);
CHECK(json(sv) == j);
@ -529,7 +529,7 @@ TEST_CASE("value conversion")
#if defined(JSON_HAS_CPP_17)
SECTION("std::string_view")
{
std::string_view s = j.get<std::string_view>();
std::string_view const s = j.get<std::string_view>();
CHECK(json(s) == j);
}
#endif
@ -857,9 +857,9 @@ TEST_CASE("value conversion")
#if JSON_USE_IMPLICIT_CONVERSIONS
SECTION("get an integer number (implicit)")
{
json::number_integer_t n_reference{42};
json::number_integer_t const n_reference{42};
json j(n_reference);
json::number_unsigned_t n_unsigned_reference{42u};
json::number_unsigned_t const n_unsigned_reference{42u};
json j_unsigned(n_unsigned_reference);
SECTION("number_integer_t")
@ -876,193 +876,193 @@ TEST_CASE("value conversion")
SECTION("short")
{
short n = j;
short const n = j;
CHECK(json(n) == j);
}
SECTION("unsigned short")
{
unsigned short n = j_unsigned;
unsigned short const n = j_unsigned;
CHECK(json(n) == j_unsigned);
}
SECTION("int")
{
int n = j;
int const n = j;
CHECK(json(n) == j);
}
SECTION("unsigned int")
{
unsigned int n = j_unsigned;
unsigned int const n = j_unsigned;
CHECK(json(n) == j_unsigned);
}
SECTION("long")
{
long n = j;
long const n = j;
CHECK(json(n) == j);
}
SECTION("unsigned long")
{
unsigned long n = j_unsigned;
unsigned long const n = j_unsigned;
CHECK(json(n) == j_unsigned);
}
SECTION("long long")
{
long long n = j;
long long const n = j;
CHECK(json(n) == j);
}
SECTION("unsigned long long")
{
unsigned long long n = j_unsigned;
unsigned long long const n = j_unsigned;
CHECK(json(n) == j_unsigned);
}
SECTION("int8_t")
{
int8_t n = j;
int8_t const n = j;
CHECK(json(n) == j);
}
SECTION("int16_t")
{
int16_t n = j;
int16_t const n = j;
CHECK(json(n) == j);
}
SECTION("int32_t")
{
int32_t n = j;
int32_t const n = j;
CHECK(json(n) == j);
}
SECTION("int64_t")
{
int64_t n = j;
int64_t const n = j;
CHECK(json(n) == j);
}
SECTION("int8_fast_t")
{
int_fast8_t n = j;
int_fast8_t const n = j;
CHECK(json(n) == j);
}
SECTION("int16_fast_t")
{
int_fast16_t n = j;
int_fast16_t const n = j;
CHECK(json(n) == j);
}
SECTION("int32_fast_t")
{
int_fast32_t n = j;
int_fast32_t const n = j;
CHECK(json(n) == j);
}
SECTION("int64_fast_t")
{
int_fast64_t n = j;
int_fast64_t const n = j;
CHECK(json(n) == j);
}
SECTION("int8_least_t")
{
int_least8_t n = j;
int_least8_t const n = j;
CHECK(json(n) == j);
}
SECTION("int16_least_t")
{
int_least16_t n = j;
int_least16_t const n = j;
CHECK(json(n) == j);
}
SECTION("int32_least_t")
{
int_least32_t n = j;
int_least32_t const n = j;
CHECK(json(n) == j);
}
SECTION("int64_least_t")
{
int_least64_t n = j;
int_least64_t const n = j;
CHECK(json(n) == j);
}
SECTION("uint8_t")
{
uint8_t n = j_unsigned;
uint8_t const n = j_unsigned;
CHECK(json(n) == j_unsigned);
}
SECTION("uint16_t")
{
uint16_t n = j_unsigned;
uint16_t const n = j_unsigned;
CHECK(json(n) == j_unsigned);
}
SECTION("uint32_t")
{
uint32_t n = j_unsigned;
uint32_t const n = j_unsigned;
CHECK(json(n) == j_unsigned);
}
SECTION("uint64_t")
{
uint64_t n = j_unsigned;
uint64_t const n = j_unsigned;
CHECK(json(n) == j_unsigned);
}
SECTION("uint8_fast_t")
{
uint_fast8_t n = j_unsigned;
uint_fast8_t const n = j_unsigned;
CHECK(json(n) == j_unsigned);
}
SECTION("uint16_fast_t")
{
uint_fast16_t n = j_unsigned;
uint_fast16_t const n = j_unsigned;
CHECK(json(n) == j_unsigned);
}
SECTION("uint32_fast_t")
{
uint_fast32_t n = j_unsigned;
uint_fast32_t const n = j_unsigned;
CHECK(json(n) == j_unsigned);
}
SECTION("uint64_fast_t")
{
uint_fast64_t n = j_unsigned;
uint_fast64_t const n = j_unsigned;
CHECK(json(n) == j_unsigned);
}
SECTION("uint8_least_t")
{
uint_least8_t n = j_unsigned;
uint_least8_t const n = j_unsigned;
CHECK(json(n) == j_unsigned);
}
SECTION("uint16_least_t")
{
uint_least16_t n = j_unsigned;
uint_least16_t const n = j_unsigned;
CHECK(json(n) == j_unsigned);
}
SECTION("uint32_least_t")
{
uint_least32_t n = j_unsigned;
uint_least32_t const n = j_unsigned;
CHECK(json(n) == j_unsigned);
}
SECTION("uint64_least_t")
{
uint_least64_t n = j_unsigned;
uint_least64_t const n = j_unsigned;
CHECK(json(n) == j_unsigned);
}
}
@ -1070,8 +1070,8 @@ TEST_CASE("value conversion")
SECTION("get a floating-point number (explicit)")
{
json::number_float_t n_reference{42.23};
json j(n_reference);
json::number_float_t const n_reference{42.23};
json const j(n_reference);
SECTION("number_float_t")
{
@ -1120,24 +1120,24 @@ TEST_CASE("value conversion")
#if JSON_USE_IMPLICIT_CONVERSIONS
SECTION("get a floating-point number (implicit)")
{
json::number_float_t n_reference{42.23};
json j(n_reference);
json::number_float_t const n_reference{42.23};
json const j(n_reference);
SECTION("number_float_t")
{
json::number_float_t n = j;
json::number_float_t const n = j;
CHECK(json(n).m_value.number_float == Approx(j.m_value.number_float));
}
SECTION("float")
{
float n = j;
float const n = j;
CHECK(json(n).m_value.number_float == Approx(j.m_value.number_float));
}
SECTION("double")
{
double n = j;
double const n = j;
CHECK(json(n).m_value.number_float == Approx(j.m_value.number_float));
}
}
@ -1145,12 +1145,12 @@ TEST_CASE("value conversion")
SECTION("get a binary value (explicit)")
{
json::binary_t n_reference{{1, 2, 3}};
json::binary_t const n_reference{{1, 2, 3}};
json j(n_reference);
SECTION("binary_t")
{
json::binary_t b = j.get<json::binary_t>();
json::binary_t const b = j.get<json::binary_t>();
CHECK(*json(b).m_value.binary == *j.m_value.binary);
}
@ -1252,12 +1252,12 @@ TEST_CASE("value conversion")
#if JSON_USE_IMPLICIT_CONVERSIONS
SECTION("get a binary value (implicit)")
{
json::binary_t n_reference{{1, 2, 3}};
json j(n_reference);
json::binary_t const n_reference{{1, 2, 3}};
json const j(n_reference);
SECTION("binary_t")
{
json::binary_t b = j;
json::binary_t const b = j;
CHECK(*json(b).m_value.binary == *j.m_value.binary);
}
}
@ -1276,11 +1276,11 @@ TEST_CASE("value conversion")
{
SECTION("object-like STL containers")
{
json j1 = {{"one", 1}, {"two", 2}, {"three", 3}};
json j2 = {{"one", 1u}, {"two", 2u}, {"three", 3u}};
json j3 = {{"one", 1.1}, {"two", 2.2}, {"three", 3.3}};
json j4 = {{"one", true}, {"two", false}, {"three", true}};
json j5 = {{"one", "eins"}, {"two", "zwei"}, {"three", "drei"}};
json const j1 = {{"one", 1}, {"two", 2}, {"three", 3}};
json const j2 = {{"one", 1u}, {"two", 2u}, {"three", 3u}};
json const j3 = {{"one", 1.1}, {"two", 2.2}, {"three", 3.3}};
json const j4 = {{"one", true}, {"two", false}, {"three", true}};
json const j5 = {{"one", "eins"}, {"two", "zwei"}, {"three", "drei"}};
SECTION("std::map")
{
@ -1331,11 +1331,11 @@ TEST_CASE("value conversion")
SECTION("array-like STL containers")
{
json j1 = {1, 2, 3, 4};
json j2 = {1u, 2u, 3u, 4u};
json j3 = {1.2, 2.3, 3.4, 4.5};
json j4 = {true, false, true};
json j5 = {"one", "two", "three"};
json const j1 = {1, 2, 3, 4};
json const j2 = {1u, 2u, 3u, 4u};
json const j3 = {1.2, 2.3, 3.4, 4.5};
json const j4 = {true, false, true};
json const j5 = {"one", "two", "three"};
SECTION("std::list")
{
@ -1427,13 +1427,13 @@ TEST_CASE("value conversion")
SECTION("std::map (array of pairs)")
{
std::map<int, int> m{{0, 1}, {1, 2}, {2, 3}};
json j6 = m;
json const j6 = m;
auto m2 = j6.get<std::map<int, int>>();
CHECK(m == m2);
json j7 = {0, 1, 2, 3};
json j8 = 2;
json const j7 = {0, 1, 2, 3};
json const j8 = 2;
CHECK_THROWS_WITH_AS((j7.get<std::map<int, int>>()),
"[json.exception.type_error.302] type must be array, "
"but is number", json::type_error&);
@ -1443,7 +1443,7 @@ TEST_CASE("value conversion")
SECTION("superfluous entries")
{
json j9 = {{0, 1, 2}, {1, 2, 3}, {2, 3, 4}};
json const j9 = {{0, 1, 2}, {1, 2, 3}, {2, 3, 4}};
m2 = j9.get<std::map<int, int>>();
CHECK(m == m2);
}
@ -1452,13 +1452,13 @@ TEST_CASE("value conversion")
SECTION("std::unordered_map (array of pairs)")
{
std::unordered_map<int, int> m{{0, 1}, {1, 2}, {2, 3}};
json j6 = m;
json const j6 = m;
auto m2 = j6.get<std::unordered_map<int, int>>();
CHECK(m == m2);
json j7 = {0, 1, 2, 3};
json j8 = 2;
json const j7 = {0, 1, 2, 3};
json const j8 = 2;
CHECK_THROWS_WITH_AS((j7.get<std::unordered_map<int, int>>()),
"[json.exception.type_error.302] type must be array, "
"but is number", json::type_error&);
@ -1468,7 +1468,7 @@ TEST_CASE("value conversion")
SECTION("superfluous entries")
{
json j9{{0, 1, 2}, {1, 2, 3}, {2, 3, 4}};
json const j9{{0, 1, 2}, {1, 2, 3}, {2, 3, 4}};
m2 = j9.get<std::unordered_map<int, int>>();
CHECK(m == m2);
}

View File

@ -469,7 +469,7 @@ TEST_CASE_TEMPLATE("element access 2", Json, nlohmann::json, nlohmann::ordered_j
}
#ifdef JSON_HAS_CPP_17
{
std::string_view key = "key";
std::string_view const key = "key";
Json j_null;
CHECK(j_null.is_null());
j_null[key] = 1;
@ -833,13 +833,13 @@ TEST_CASE_TEMPLATE("element access 2", Json, nlohmann::json, nlohmann::ordered_j
{
{
Json jobject = {{"a", "a"}, {"b", 1}, {"c", 17u}};
typename Json::iterator it2 = jobject.erase(jobject.begin());
typename Json::iterator const it2 = jobject.erase(jobject.begin());
CHECK(jobject == Json({{"b", 1}, {"c", 17u}}));
CHECK(*it2 == Json(1));
}
{
Json jobject = {{"a", "a"}, {"b", 1}, {"c", 17u}};
typename Json::const_iterator it2 = jobject.erase(jobject.cbegin());
typename Json::const_iterator const it2 = jobject.erase(jobject.cbegin());
CHECK(jobject == Json({{"b", 1}, {"c", 17u}}));
CHECK(*it2 == Json(1));
}
@ -865,13 +865,13 @@ TEST_CASE_TEMPLATE("element access 2", Json, nlohmann::json, nlohmann::ordered_j
{
{
Json jobject = {{"a", "a"}, {"b", 1}, {"c", 17u}};
typename Json::iterator it2 = jobject.erase(jobject.begin(), jobject.begin());
typename Json::iterator const it2 = jobject.erase(jobject.begin(), jobject.begin());
CHECK(jobject == Json({{"a", "a"}, {"b", 1}, {"c", 17u}}));
CHECK(*it2 == Json("a"));
}
{
Json jobject = {{"a", "a"}, {"b", 1}, {"c", 17u}};
typename Json::const_iterator it2 = jobject.erase(jobject.cbegin(), jobject.cbegin());
typename Json::const_iterator const it2 = jobject.erase(jobject.cbegin(), jobject.cbegin());
CHECK(jobject == Json({{"a", "a"}, {"b", 1}, {"c", 17u}}));
CHECK(*it2 == Json("a"));
}
@ -881,15 +881,15 @@ TEST_CASE_TEMPLATE("element access 2", Json, nlohmann::json, nlohmann::ordered_j
{
{
Json jobject = {{"a", "a"}, {"b", 1}, {"c", 17u}};
typename Json::iterator it = jobject.find("b");
typename Json::iterator it2 = jobject.erase(it);
typename Json::iterator const it = jobject.find("b");
typename Json::iterator const it2 = jobject.erase(it);
CHECK(jobject == Json({{"a", "a"}, {"c", 17u}}));
CHECK(*it2 == Json(17));
}
{
Json jobject = {{"a", "a"}, {"b", 1}, {"c", 17u}};
typename Json::const_iterator it = jobject.find("b");
typename Json::const_iterator it2 = jobject.erase(it);
typename Json::const_iterator const it = jobject.find("b");
typename Json::const_iterator const it2 = jobject.erase(it);
CHECK(jobject == Json({{"a", "a"}, {"c", 17u}}));
CHECK(*it2 == Json(17));
}
@ -899,13 +899,13 @@ TEST_CASE_TEMPLATE("element access 2", Json, nlohmann::json, nlohmann::ordered_j
{
{
Json jobject = {{"a", "a"}, {"b", 1}, {"c", 17u}, {"d", false}, {"e", true}};
typename Json::iterator it2 = jobject.erase(jobject.find("b"), jobject.find("e"));
typename Json::iterator const it2 = jobject.erase(jobject.find("b"), jobject.find("e"));
CHECK(jobject == Json({{"a", "a"}, {"e", true}}));
CHECK(*it2 == Json(true));
}
{
Json jobject = {{"a", "a"}, {"b", 1}, {"c", 17u}, {"d", false}, {"e", true}};
typename Json::const_iterator it2 = jobject.erase(jobject.find("b"), jobject.find("e"));
typename Json::const_iterator const it2 = jobject.erase(jobject.find("b"), jobject.find("e"));
CHECK(jobject == Json({{"a", "a"}, {"e", true}}));
CHECK(*it2 == Json(true));
}
@ -1509,7 +1509,7 @@ TEST_CASE_TEMPLATE("element access 2 (additional value() tests)", Json, nlohmann
const char* cpstr = "default";
const char castr[] = "default"; // NOLINT(hicpp-avoid-c-arrays,modernize-avoid-c-arrays,cppcoreguidelines-avoid-c-arrays)
string_t str = "default";
string_t const str = "default";
number_integer_t integer = 69;
std::size_t size = 69;
@ -1592,9 +1592,9 @@ TEST_CASE_TEMPLATE("element access 2 (additional value() tests)", Json, nlohmann
SECTION("string_t/object_t::key_type key")
{
string_t key = "foo";
string_t key2 = "baz";
string_t key_notfound = "bar";
string_t const key = "foo";
string_t const key2 = "baz";
string_t const key_notfound = "bar";
CHECK(j.value(key, "default") == "bar");
CHECK(j.value(key, cpstr) == "bar");
@ -1618,9 +1618,9 @@ TEST_CASE_TEMPLATE("element access 2 (additional value() tests)", Json, nlohmann
#ifdef JSON_HAS_CPP_17
SECTION("std::string_view key")
{
std::string_view key = "foo";
std::string_view key2 = "baz";
std::string_view key_notfound = "bar";
std::string_view const key = "foo";
std::string_view const key2 = "baz";
std::string_view const key_notfound = "bar";
CHECK(j.value(key, "default") == "bar");
CHECK(j.value(key, cpstr) == "bar");
@ -1730,9 +1730,9 @@ TEST_CASE_TEMPLATE("element access 2 (additional value() tests)", Json, nlohmann
SECTION("string_t/object_t::key_type key")
{
string_t key = "foo";
string_t key2 = "baz";
string_t key_notfound = "bar";
string_t const key = "foo";
string_t const key2 = "baz";
string_t const key_notfound = "bar";
CHECK(j.template value<string_t>(key, "default") == "bar");
CHECK(j.template value<string_t>(key, cpstr) == "bar");
@ -1756,9 +1756,9 @@ TEST_CASE_TEMPLATE("element access 2 (additional value() tests)", Json, nlohmann
#ifdef JSON_HAS_CPP_17
SECTION("std::string_view key")
{
std::string_view key = "foo";
std::string_view key2 = "baz";
std::string_view key_notfound = "bar";
std::string_view const key = "foo";
std::string_view const key2 = "baz";
std::string_view const key_notfound = "bar";
CHECK(j.template value<string_t>(key, "default") == "bar");
CHECK(j.template value<string_t>(key, cpstr) == "bar");