diff --git a/tests/src/fuzzer-driver_afl.cpp b/tests/src/fuzzer-driver_afl.cpp index 2fe65b919..354a51207 100644 --- a/tests/src/fuzzer-driver_afl.cpp +++ b/tests/src/fuzzer-driver_afl.cpp @@ -26,7 +26,7 @@ int main() #endif // copy stdin to byte vector std::vector vec; - char c; + char c = 0; while (std::cin.get(c)) { vec.push_back(static_cast(c)); diff --git a/tests/src/fuzzer-parse_bjdata.cpp b/tests/src/fuzzer-parse_bjdata.cpp index abecead44..7f0b1b300 100644 --- a/tests/src/fuzzer-parse_bjdata.cpp +++ b/tests/src/fuzzer-parse_bjdata.cpp @@ -37,24 +37,24 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) try { // step 1: parse input - std::vector vec1(data, data + size); - json j1 = json::from_bjdata(vec1); + std::vector const vec1(data, data + size); + json const j1 = json::from_bjdata(vec1); try { // step 2.1: round trip without adding size annotations to container types - std::vector vec2 = json::to_bjdata(j1, false, false); + std::vector const vec2 = json::to_bjdata(j1, false, false); // step 2.2: round trip with adding size annotations but without adding type annonations to container types - std::vector vec3 = json::to_bjdata(j1, true, false); + std::vector const vec3 = json::to_bjdata(j1, true, false); // step 2.3: round trip with adding size as well as type annotations to container types - std::vector vec4 = json::to_bjdata(j1, true, true); + std::vector const vec4 = json::to_bjdata(j1, true, true); // parse serialization - json j2 = json::from_bjdata(vec2); - json j3 = json::from_bjdata(vec3); - json j4 = json::from_bjdata(vec4); + json const j2 = json::from_bjdata(vec2); + json const j3 = json::from_bjdata(vec3); + json const j4 = json::from_bjdata(vec4); // serializations must match assert(json::to_bjdata(j2, false, false) == vec2); diff --git a/tests/src/fuzzer-parse_bson.cpp b/tests/src/fuzzer-parse_bson.cpp index 56e677c3f..c4fa2cd4a 100644 --- a/tests/src/fuzzer-parse_bson.cpp +++ b/tests/src/fuzzer-parse_bson.cpp @@ -31,8 +31,8 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) try { // step 1: parse input - std::vector vec1(data, data + size); - json j1 = json::from_bson(vec1); + std::vector const vec1(data, data + size); + json const j1 = json::from_bson(vec1); if (j1.is_discarded()) { @@ -42,10 +42,10 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) try { // step 2: round trip - std::vector vec2 = json::to_bson(j1); + std::vector const vec2 = json::to_bson(j1); // parse serialization - json j2 = json::from_bson(vec2); + json const j2 = json::from_bson(vec2); // serializations must match assert(json::to_bson(j2) == vec2); diff --git a/tests/src/fuzzer-parse_cbor.cpp b/tests/src/fuzzer-parse_cbor.cpp index 3e05e0ad0..c9b4a38c7 100644 --- a/tests/src/fuzzer-parse_cbor.cpp +++ b/tests/src/fuzzer-parse_cbor.cpp @@ -31,16 +31,16 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) try { // step 1: parse input - std::vector vec1(data, data + size); - json j1 = json::from_cbor(vec1); + std::vector const vec1(data, data + size); + json const j1 = json::from_cbor(vec1); try { // step 2: round trip - std::vector vec2 = json::to_cbor(j1); + std::vector const vec2 = json::to_cbor(j1); // parse serialization - json j2 = json::from_cbor(vec2); + json const j2 = json::from_cbor(vec2); // serializations must match assert(json::to_cbor(j2) == vec2); diff --git a/tests/src/fuzzer-parse_json.cpp b/tests/src/fuzzer-parse_json.cpp index cdad1462b..36cce5f15 100644 --- a/tests/src/fuzzer-parse_json.cpp +++ b/tests/src/fuzzer-parse_json.cpp @@ -32,20 +32,20 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) try { // step 1: parse input - json j1 = json::parse(data, data + size); + json const j1 = json::parse(data, data + size); try { // step 2: round trip // first serialization - std::string s1 = j1.dump(); + std::string const s1 = j1.dump(); // parse serialization - json j2 = json::parse(s1); + json const j2 = json::parse(s1); // second serialization - std::string s2 = j2.dump(); + std::string const s2 = j2.dump(); // serializations must match assert(s1 == s2); diff --git a/tests/src/fuzzer-parse_msgpack.cpp b/tests/src/fuzzer-parse_msgpack.cpp index 7855b42a7..d8044b943 100644 --- a/tests/src/fuzzer-parse_msgpack.cpp +++ b/tests/src/fuzzer-parse_msgpack.cpp @@ -31,16 +31,16 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) try { // step 1: parse input - std::vector vec1(data, data + size); - json j1 = json::from_msgpack(vec1); + std::vector const vec1(data, data + size); + json const j1 = json::from_msgpack(vec1); try { // step 2: round trip - std::vector vec2 = json::to_msgpack(j1); + std::vector const vec2 = json::to_msgpack(j1); // parse serialization - json j2 = json::from_msgpack(vec2); + json const j2 = json::from_msgpack(vec2); // serializations must match assert(json::to_msgpack(j2) == vec2); diff --git a/tests/src/fuzzer-parse_ubjson.cpp b/tests/src/fuzzer-parse_ubjson.cpp index a3f1e9f74..67261deb0 100644 --- a/tests/src/fuzzer-parse_ubjson.cpp +++ b/tests/src/fuzzer-parse_ubjson.cpp @@ -37,24 +37,24 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) try { // step 1: parse input - std::vector vec1(data, data + size); - json j1 = json::from_ubjson(vec1); + std::vector const vec1(data, data + size); + json const j1 = json::from_ubjson(vec1); try { // step 2.1: round trip without adding size annotations to container types - std::vector vec2 = json::to_ubjson(j1, false, false); + std::vector const vec2 = json::to_ubjson(j1, false, false); // step 2.2: round trip with adding size annotations but without adding type annonations to container types - std::vector vec3 = json::to_ubjson(j1, true, false); + std::vector const vec3 = json::to_ubjson(j1, true, false); // step 2.3: round trip with adding size as well as type annotations to container types - std::vector vec4 = json::to_ubjson(j1, true, true); + std::vector const vec4 = json::to_ubjson(j1, true, true); // parse serialization - json j2 = json::from_ubjson(vec2); - json j3 = json::from_ubjson(vec3); - json j4 = json::from_ubjson(vec4); + json const j2 = json::from_ubjson(vec2); + json const j3 = json::from_ubjson(vec3); + json const j4 = json::from_ubjson(vec4); // serializations must match assert(json::to_ubjson(j2, false, false) == vec2); diff --git a/tests/src/unit-32bit.cpp b/tests/src/unit-32bit.cpp index 3ff6277e8..30d1b029e 100644 --- a/tests/src/unit-32bit.cpp +++ b/tests/src/unit-32bit.cpp @@ -34,9 +34,9 @@ TEST_CASE_TEMPLATE_DEFINE("value_in_range_of trait", T, value_in_range_of_test) constexpr bool max_in_range = T::max_in_range; type val_min = std::numeric_limits::min(); - type val_min2 = val_min + 1; + type const val_min2 = val_min + 1; type val_max = std::numeric_limits::max(); - type val_max2 = val_max - 1; + type const val_max2 = val_max - 1; REQUIRE(CHAR_BIT == 8); @@ -108,8 +108,8 @@ TEST_CASE("BJData") { SECTION("optimized array: negative size") { - std::vector vM = {'[', '$', 'M', '#', '[', 'I', 0x00, 0x20, 'M', 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0xFF, ']'}; - std::vector vMX = {'[', '$', 'U', '#', '[', 'M', 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 'U', 0x01, ']'}; + std::vector const vM = {'[', '$', 'M', '#', '[', 'I', 0x00, 0x20, 'M', 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0xFF, ']'}; + std::vector const vMX = {'[', '$', 'U', '#', '[', 'M', 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 'U', 0x01, ']'}; json _; CHECK_THROWS_WITH_AS(_ = json::from_bjdata(vM), "[json.exception.out_of_range.408] syntax error while parsing BJData size: integer value overflow", json::out_of_range&); @@ -121,8 +121,8 @@ TEST_CASE("BJData") SECTION("optimized array: integer value overflow") { - std::vector vL = {'[', '#', 'L', 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7F}; - std::vector vM = {'[', '$', 'M', '#', '[', 'I', 0x00, 0x20, 'M', 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0xFF, ']'}; + std::vector const vL = {'[', '#', 'L', 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7F}; + std::vector const vM = {'[', '$', 'M', '#', '[', 'I', 0x00, 0x20, 'M', 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0xFF, ']'}; json _; CHECK_THROWS_WITH_AS(_ = json::from_bjdata(vL), "[json.exception.out_of_range.408] syntax error while parsing BJData size: integer value overflow", json::out_of_range&); diff --git a/tests/src/unit-byte_container_with_subtype.cpp b/tests/src/unit-byte_container_with_subtype.cpp index ba8eab27f..e18033e4e 100644 --- a/tests/src/unit-byte_container_with_subtype.cpp +++ b/tests/src/unit-byte_container_with_subtype.cpp @@ -45,7 +45,7 @@ TEST_CASE("byte_container_with_subtype") SECTION("comparisons") { - std::vector bytes = {{0xCA, 0xFE, 0xBA, 0xBE}}; + std::vector const bytes = {{0xCA, 0xFE, 0xBA, 0xBE}}; nlohmann::byte_container_with_subtype> container1; nlohmann::byte_container_with_subtype> container2({}, 42); nlohmann::byte_container_with_subtype> container3(bytes); diff --git a/tests/src/unit-capacity.cpp b/tests/src/unit-capacity.cpp index 2f644a1f0..c581b8c94 100644 --- a/tests/src/unit-capacity.cpp +++ b/tests/src/unit-capacity.cpp @@ -416,7 +416,7 @@ TEST_CASE("capacity") { SECTION("boolean") { - json j = true; + json const j = true; const json j_const = true; SECTION("result of max_size") @@ -428,7 +428,7 @@ TEST_CASE("capacity") SECTION("string") { - json j = "hello world"; + json const j = "hello world"; const json j_const = "hello world"; SECTION("result of max_size") @@ -442,7 +442,7 @@ TEST_CASE("capacity") { SECTION("empty array") { - json j = json::array(); + json const j = json::array(); const json j_const = json::array(); SECTION("result of max_size") @@ -454,7 +454,7 @@ TEST_CASE("capacity") SECTION("filled array") { - json j = {1, 2, 3}; + json const j = {1, 2, 3}; const json j_const = {1, 2, 3}; SECTION("result of max_size") @@ -469,7 +469,7 @@ TEST_CASE("capacity") { SECTION("empty object") { - json j = json::object(); + json const j = json::object(); const json j_const = json::object(); SECTION("result of max_size") @@ -481,7 +481,7 @@ TEST_CASE("capacity") SECTION("filled object") { - json j = {{"one", 1}, {"two", 2}, {"three", 3}}; + json const j = {{"one", 1}, {"two", 2}, {"three", 3}}; const json j_const = {{"one", 1}, {"two", 2}, {"three", 3}}; SECTION("result of max_size") @@ -494,7 +494,7 @@ TEST_CASE("capacity") SECTION("number (integer)") { - json j = -23; + json const j = -23; const json j_const = -23; SECTION("result of max_size") @@ -506,7 +506,7 @@ TEST_CASE("capacity") SECTION("number (unsigned)") { - json j = 23u; + json const j = 23u; const json j_const = 23u; SECTION("result of max_size") @@ -518,7 +518,7 @@ TEST_CASE("capacity") SECTION("number (float)") { - json j = 23.42; + json const j = 23.42; const json j_const = 23.42; SECTION("result of max_size") @@ -530,7 +530,7 @@ TEST_CASE("capacity") SECTION("null") { - json j = nullptr; + json const j = nullptr; const json j_const = nullptr; SECTION("result of max_size") diff --git a/tests/src/unit-class_parser.cpp b/tests/src/unit-class_parser.cpp index 0193b4b89..b8bb65406 100644 --- a/tests/src/unit-class_parser.cpp +++ b/tests/src/unit-class_parser.cpp @@ -249,11 +249,11 @@ bool accept_helper(const std::string& s) CHECK(json::parser(nlohmann::detail::input_adapter(s)).accept(false) == !el.errored); // 5. parse with simple callback - json::parser_callback_t cb = [](int /*unused*/, json::parse_event_t /*unused*/, json& /*unused*/) noexcept + json::parser_callback_t const cb = [](int /*unused*/, json::parse_event_t /*unused*/, json& /*unused*/) noexcept { return true; }; - json j_cb = json::parse(s, cb, false); + json const j_cb = json::parse(s, cb, false); const bool ok_noexcept_cb = !j_cb.is_discarded(); // 6. check if this approach came to the same result @@ -1093,7 +1093,7 @@ TEST_CASE("parser class") for (int c = 1; c < 128; ++c) { - std::string s = "\"\\u"; + std::string const s = "\"\\u"; // create a string with the iterated character at each position auto s1 = s + "000" + std::string(1, static_cast(c)) + "\""; @@ -1308,7 +1308,7 @@ TEST_CASE("parser class") for (int c = 1; c < 128; ++c) { - std::string s = "\"\\u"; + std::string const s = "\"\\u"; // create a string with the iterated character at each position const auto s1 = s + "000" + std::string(1, static_cast(c)) + "\""; @@ -1361,7 +1361,7 @@ TEST_CASE("parser class") // test case to make sure the callback is properly evaluated after reading a key { - json::parser_callback_t cb = [](int /*unused*/, json::parse_event_t event, json& /*unused*/) noexcept + json::parser_callback_t const cb = [](int /*unused*/, json::parse_event_t event, json& /*unused*/) noexcept { return event != json::parse_event_t::key; }; @@ -1417,7 +1417,7 @@ TEST_CASE("parser class") SECTION("filter everything") { - json j_object = json::parse(s_object, [](int /*unused*/, json::parse_event_t /*unused*/, const json& /*unused*/) noexcept + json const j_object = json::parse(s_object, [](int /*unused*/, json::parse_event_t /*unused*/, const json& /*unused*/) noexcept { return false; }); @@ -1425,7 +1425,7 @@ TEST_CASE("parser class") // the top-level object will be discarded, leaving a null CHECK (j_object.is_null()); - json j_array = json::parse(s_array, [](int /*unused*/, json::parse_event_t /*unused*/, const json& /*unused*/) noexcept + json const j_array = json::parse(s_array, [](int /*unused*/, json::parse_event_t /*unused*/, const json& /*unused*/) noexcept { return false; }); @@ -1574,7 +1574,7 @@ TEST_CASE("parser class") SECTION("from std::initializer_list") { - std::initializer_list v = {'t', 'r', 'u', 'e'}; + std::initializer_list const v = {'t', 'r', 'u', 'e'}; json j; json::parser(nlohmann::detail::input_adapter(std::begin(v), std::end(v))).parse(true, j); CHECK(j == json(true)); @@ -1593,7 +1593,7 @@ TEST_CASE("parser class") { SECTION("parser with callback") { - json::parser_callback_t cb = [](int /*unused*/, json::parse_event_t /*unused*/, json& /*unused*/) noexcept + json::parser_callback_t const cb = [](int /*unused*/, json::parse_event_t /*unused*/, json& /*unused*/) noexcept { return true; }; diff --git a/tests/src/unit-convenience.cpp b/tests/src/unit-convenience.cpp index d60d1a00e..59c5c13fc 100644 --- a/tests/src/unit-convenience.cpp +++ b/tests/src/unit-convenience.cpp @@ -173,9 +173,9 @@ TEST_CASE("convenience functions") using nlohmann::detail::concat; const char* expected = "Hello, world!"; - alt_string_iter hello_iter{"Hello, "}; - alt_string_data hello_data{"Hello, "}; - std::string world = "world"; + alt_string_iter const hello_iter{"Hello, "}; + alt_string_data const hello_data{"Hello, "}; + std::string const world = "world"; SECTION("std::string") { diff --git a/tests/src/unit-custom-base-class.cpp b/tests/src/unit-custom-base-class.cpp index 1803bd864..673147f90 100644 --- a/tests/src/unit-custom-base-class.cpp +++ b/tests/src/unit-custom-base-class.cpp @@ -188,7 +188,7 @@ TEST_CASE("JSON Node Metadata") value.metadata().emplace_back(1); value.metadata().emplace_back(2); - json array(10, value); + json const array(10, value); CHECK(value.metadata().size() == 2); CHECK(value.metadata().at(0) == 1); diff --git a/tests/src/unit-deserialization.cpp b/tests/src/unit-deserialization.cpp index 86640fd3f..b8e54b623 100644 --- a/tests/src/unit-deserialization.cpp +++ b/tests/src/unit-deserialization.cpp @@ -265,7 +265,7 @@ TEST_CASE("deserialization") SECTION("string_t") { - json::string_t s = R"(["foo",1,2,3,false,{"one":1}])"; + json::string_t const s = R"(["foo",1,2,3,false,{"one":1}])"; json j = json::parse(s); CHECK(json::accept(s)); CHECK(j == json({"foo", 1, 2, 3, false, {{"one", 1}}})); @@ -341,7 +341,7 @@ TEST_CASE("deserialization") SECTION("string") { - json::string_t s = R"(["foo",1,2,3,false,{"one":1})"; + json::string_t const s = R"(["foo",1,2,3,false,{"one":1})"; json _; CHECK_THROWS_WITH_AS(_ = json::parse(s), "[json.exception.parse_error.101] parse error at line 1, column 29: syntax error while parsing array - unexpected end of input; expected ']'", json::parse_error&); CHECK(!json::accept(s)); @@ -390,7 +390,7 @@ TEST_CASE("deserialization") { SECTION("from std::vector") { - std::vector v = {'t', 'r', 'u', 'e'}; + std::vector const v = {'t', 'r', 'u', 'e'}; CHECK(json::parse(v) == json(true)); CHECK(json::accept(v)); @@ -402,7 +402,7 @@ TEST_CASE("deserialization") SECTION("from std::array") { - std::array v { {'t', 'r', 'u', 'e'} }; + std::array const v { {'t', 'r', 'u', 'e'} }; CHECK(json::parse(v) == json(true)); CHECK(json::accept(v)); @@ -445,7 +445,7 @@ TEST_CASE("deserialization") SECTION("from std::string") { - std::string v = {'t', 'r', 'u', 'e'}; + std::string const v = {'t', 'r', 'u', 'e'}; CHECK(json::parse(v) == json(true)); CHECK(json::accept(v)); @@ -457,7 +457,7 @@ TEST_CASE("deserialization") SECTION("from std::initializer_list") { - std::initializer_list v = {'t', 'r', 'u', 'e'}; + std::initializer_list const v = {'t', 'r', 'u', 'e'}; CHECK(json::parse(v) == json(true)); CHECK(json::accept(v)); @@ -469,7 +469,7 @@ TEST_CASE("deserialization") SECTION("empty container") { - std::vector v; + std::vector const v; json _; CHECK_THROWS_AS(_ = json::parse(v), json::parse_error&); CHECK(!json::accept(v)); @@ -534,7 +534,7 @@ TEST_CASE("deserialization") SECTION("from std::initializer_list") { - std::initializer_list v = {'t', 'r', 'u', 'e'}; + std::initializer_list const v = {'t', 'r', 'u', 'e'}; CHECK(json::parse(std::begin(v), std::end(v)) == json(true)); CHECK(json::accept(std::begin(v), std::end(v))); @@ -1045,7 +1045,7 @@ TEST_CASE("deserialization") SECTION("SAX and early abort") { - std::string s = R"([1, ["string", 43.12], null, {"key1": true, "key2": false}])"; + std::string const s = R"([1, ["string", 43.12], null, {"key1": true, "key2": false}])"; SaxEventLogger default_logger; SaxEventLoggerExitAfterStartObject exit_after_start_object; @@ -1139,7 +1139,7 @@ TEST_CASE_TEMPLATE("deserialization of different character types (ASCII)", T, std::int16_t, std::uint16_t, std::int32_t, std::uint32_t) { - std::vector v = {'t', 'r', 'u', 'e'}; + std::vector const v = {'t', 'r', 'u', 'e'}; CHECK(json::parse(v) == json(true)); CHECK(json::accept(v)); @@ -1153,7 +1153,7 @@ TEST_CASE_TEMPLATE("deserialization of different character types (UTF-8)", T, char, unsigned char, std::uint8_t) { // a star emoji - std::vector v = {'"', static_cast(0xe2u), static_cast(0xadu), static_cast(0x90u), static_cast(0xefu), static_cast(0xb8u), static_cast(0x8fu), '"'}; + std::vector const v = {'"', static_cast(0xe2u), static_cast(0xadu), static_cast(0x90u), static_cast(0xefu), static_cast(0xb8u), static_cast(0x8fu), '"'}; CHECK(json::parse(v).dump(-1, ' ', true) == "\"\\u2b50\\ufe0f\""); CHECK(json::accept(v)); @@ -1166,7 +1166,7 @@ TEST_CASE_TEMPLATE("deserialization of different character types (UTF-16)", T, char16_t, std::uint16_t) { // a star emoji - std::vector v = {static_cast('"'), static_cast(0x2b50), static_cast(0xfe0f), static_cast('"')}; + std::vector const v = {static_cast('"'), static_cast(0x2b50), static_cast(0xfe0f), static_cast('"')}; CHECK(json::parse(v).dump(-1, ' ', true) == "\"\\u2b50\\ufe0f\""); CHECK(json::accept(v)); @@ -1179,7 +1179,7 @@ TEST_CASE_TEMPLATE("deserialization of different character types (UTF-32)", T, char32_t, std::uint32_t) { // a star emoji - std::vector v = {static_cast('"'), static_cast(0x2b50), static_cast(0xfe0f), static_cast('"')}; + std::vector const v = {static_cast('"'), static_cast(0x2b50), static_cast(0xfe0f), static_cast('"')}; CHECK(json::parse(v).dump(-1, ' ', true) == "\"\\u2b50\\ufe0f\""); CHECK(json::accept(v)); diff --git a/tests/src/unit-element_access1.cpp b/tests/src/unit-element_access1.cpp index af70b94a4..22484d309 100644 --- a/tests/src/unit-element_access1.cpp +++ b/tests/src/unit-element_access1.cpp @@ -274,13 +274,13 @@ TEST_CASE("element access 1") { { json jarray = {1, 1u, true, nullptr, "string", 42.23, json::object(), {1, 2, 3}}; - json::iterator it2 = jarray.erase(jarray.begin()); + json::iterator const it2 = jarray.erase(jarray.begin()); CHECK(jarray == json({1u, true, nullptr, "string", 42.23, json::object(), {1, 2, 3}})); CHECK(*it2 == json(1u)); } { json jarray = {1, 1u, true, nullptr, "string", 42.23, json::object(), {1, 2, 3}}; - json::const_iterator it2 = jarray.erase(jarray.cbegin()); + json::const_iterator const it2 = jarray.erase(jarray.cbegin()); CHECK(jarray == json({1u, true, nullptr, "string", 42.23, json::object(), {1, 2, 3}})); CHECK(*it2 == json(1u)); } @@ -306,13 +306,13 @@ TEST_CASE("element access 1") { { json jarray = {1, 1u, true, nullptr, "string", 42.23, json::object(), {1, 2, 3}}; - json::iterator it2 = jarray.erase(jarray.begin(), jarray.begin()); + json::iterator const it2 = jarray.erase(jarray.begin(), jarray.begin()); CHECK(jarray == json({1, 1u, true, nullptr, "string", 42.23, json::object(), {1, 2, 3}})); CHECK(*it2 == json(1)); } { json jarray = {1, 1u, true, nullptr, "string", 42.23, json::object(), {1, 2, 3}}; - json::const_iterator it2 = jarray.erase(jarray.cbegin(), jarray.cbegin()); + json::const_iterator const it2 = jarray.erase(jarray.cbegin(), jarray.cbegin()); CHECK(jarray == json({1, 1u, true, nullptr, "string", 42.23, json::object(), {1, 2, 3}})); CHECK(*it2 == json(1)); } @@ -322,15 +322,15 @@ TEST_CASE("element access 1") { { json jarray = {1, 1u, true, nullptr, "string", 42.23, json::object(), {1, 2, 3}}; - json::iterator it = jarray.begin() + 4; - json::iterator it2 = jarray.erase(it); + json::iterator const it = jarray.begin() + 4; + json::iterator const it2 = jarray.erase(it); CHECK(jarray == json({1, 1u, true, nullptr, 42.23, json::object(), {1, 2, 3}})); CHECK(*it2 == json(42.23)); } { json jarray = {1, 1u, true, nullptr, "string", 42.23, json::object(), {1, 2, 3}}; - json::const_iterator it = jarray.cbegin() + 4; - json::const_iterator it2 = jarray.erase(it); + json::const_iterator const it = jarray.cbegin() + 4; + json::const_iterator const it2 = jarray.erase(it); CHECK(jarray == json({1, 1u, true, nullptr, 42.23, json::object(), {1, 2, 3}})); CHECK(*it2 == json(42.23)); } @@ -340,13 +340,13 @@ TEST_CASE("element access 1") { { json jarray = {1, 1u, true, nullptr, "string", 42.23, json::object(), {1, 2, 3}}; - json::iterator it2 = jarray.erase(jarray.begin() + 3, jarray.begin() + 6); + json::iterator const it2 = jarray.erase(jarray.begin() + 3, jarray.begin() + 6); CHECK(jarray == json({1, 1u, true, json::object(), {1, 2, 3}})); CHECK(*it2 == json::object()); } { json jarray = {1, 1u, true, nullptr, "string", 42.23, json::object(), {1, 2, 3}}; - json::const_iterator it2 = jarray.erase(jarray.cbegin() + 3, jarray.cbegin() + 6); + json::const_iterator const it2 = jarray.erase(jarray.cbegin() + 3, jarray.cbegin() + 6); CHECK(jarray == json({1, 1u, true, json::object(), {1, 2, 3}})); CHECK(*it2 == json::object()); } @@ -369,7 +369,7 @@ TEST_CASE("element access 1") } { json jarray = {1, 1u, true, nullptr, "string", 42.23, json::object(), {1, 2, 3}}; - json jarray2 = {"foo", "bar"}; + json const jarray2 = {"foo", "bar"}; CHECK_THROWS_WITH_AS(jarray.erase(jarray2.cbegin()), "[json.exception.invalid_iterator.202] iterator does not fit current value", json::invalid_iterator&); diff --git a/tests/src/unit-inspection.cpp b/tests/src/unit-inspection.cpp index 312292585..ab938b614 100644 --- a/tests/src/unit-inspection.cpp +++ b/tests/src/unit-inspection.cpp @@ -21,7 +21,7 @@ TEST_CASE("object inspection") { SECTION("object") { - json j {{"foo", 1}, {"bar", false}}; + json const j {{"foo", 1}, {"bar", false}}; CHECK(!j.is_null()); CHECK(!j.is_boolean()); CHECK(!j.is_number()); @@ -39,7 +39,7 @@ TEST_CASE("object inspection") SECTION("array") { - json j {"foo", 1, 1u, 42.23, false}; + json const j {"foo", 1, 1u, 42.23, false}; CHECK(!j.is_null()); CHECK(!j.is_boolean()); CHECK(!j.is_number()); @@ -57,7 +57,7 @@ TEST_CASE("object inspection") SECTION("null") { - json j(nullptr); + json const j(nullptr); CHECK(j.is_null()); CHECK(!j.is_boolean()); CHECK(!j.is_number()); @@ -75,7 +75,7 @@ TEST_CASE("object inspection") SECTION("boolean") { - json j(true); + json const j(true); CHECK(!j.is_null()); CHECK(j.is_boolean()); CHECK(!j.is_number()); @@ -93,7 +93,7 @@ TEST_CASE("object inspection") SECTION("string") { - json j("Hello world"); + json const j("Hello world"); CHECK(!j.is_null()); CHECK(!j.is_boolean()); CHECK(!j.is_number()); @@ -111,7 +111,7 @@ TEST_CASE("object inspection") SECTION("number (integer)") { - json j(42); + json const j(42); CHECK(!j.is_null()); CHECK(!j.is_boolean()); CHECK(j.is_number()); @@ -129,7 +129,7 @@ TEST_CASE("object inspection") SECTION("number (unsigned)") { - json j(42u); + json const j(42u); CHECK(!j.is_null()); CHECK(!j.is_boolean()); CHECK(j.is_number()); @@ -147,7 +147,7 @@ TEST_CASE("object inspection") SECTION("number (floating-point)") { - json j(42.23); + json const j(42.23); CHECK(!j.is_null()); CHECK(!j.is_boolean()); CHECK(j.is_number()); @@ -165,7 +165,7 @@ TEST_CASE("object inspection") SECTION("binary") { - json j(json::value_t::binary); + json const j(json::value_t::binary); CHECK(!j.is_null()); CHECK(!j.is_boolean()); CHECK(!j.is_number()); @@ -183,7 +183,7 @@ TEST_CASE("object inspection") SECTION("discarded") { - json j(json::value_t::discarded); + json const j(json::value_t::discarded); CHECK(!j.is_null()); CHECK(!j.is_boolean()); CHECK(!j.is_number()); @@ -202,7 +202,7 @@ TEST_CASE("object inspection") SECTION("serialization") { - json j {{"object", json::object()}, {"array", {1, 2, 3, 4}}, {"number", 42}, {"boolean", false}, {"null", nullptr}, {"string", "Hello world"} }; + json const j {{"object", json::object()}, {"array", {1, 2, 3, 4}}, {"number", 42}, {"boolean", false}, {"null", nullptr}, {"string", "Hello world"} }; SECTION("no indent / indent=-1") { @@ -288,7 +288,7 @@ TEST_CASE("object inspection") std::ifstream f_escaped(TEST_DATA_DIRECTORY "/json_nlohmann_tests/all_unicode_ascii.json"); std::ifstream f_unescaped(TEST_DATA_DIRECTORY "/json_nlohmann_tests/all_unicode.json"); - json value = json::parse(f_unescaped); + json const value = json::parse(f_unescaped); std::string text = value.dump(4, ' ', true); std::string expected((std::istreambuf_iterator(f_escaped)), @@ -299,7 +299,7 @@ TEST_CASE("object inspection") SECTION("serialization of discarded element") { - json j_discarded(json::value_t::discarded); + json const j_discarded(json::value_t::discarded); CHECK(j_discarded.dump() == ""); } @@ -315,7 +315,7 @@ TEST_CASE("object inspection") ss.str(std::string()); // use stringstream for JSON serialization - json j_number = 3.14159265358979; + json const j_number = 3.14159265358979; ss << j_number; // check that precision has been overridden during serialization @@ -332,9 +332,9 @@ TEST_CASE("object inspection") {"3.141592653589793", "1000000000000000010E5" }) { - json j1 = json::parse(s); + json const j1 = json::parse(s); std::string s1 = j1.dump(); - json j2 = json::parse(s1); + json const j2 = json::parse(s1); std::string s2 = j2.dump(); CHECK(s1 == s2); } @@ -344,49 +344,49 @@ TEST_CASE("object inspection") { SECTION("null") { - json j = nullptr; + json const j = nullptr; CHECK(j.type() == json::value_t::null); } SECTION("object") { - json j = {{"foo", "bar"}}; + json const j = {{"foo", "bar"}}; CHECK(j.type() == json::value_t::object); } SECTION("array") { - json j = {1, 2, 3, 4}; + json const j = {1, 2, 3, 4}; CHECK(j.type() == json::value_t::array); } SECTION("boolean") { - json j = true; + json const j = true; CHECK(j.type() == json::value_t::boolean); } SECTION("string") { - json j = "Hello world"; + json const j = "Hello world"; CHECK(j.type() == json::value_t::string); } SECTION("number (integer)") { - json j = 23; + json const j = 23; CHECK(j.type() == json::value_t::number_integer); } SECTION("number (unsigned)") { - json j = 23u; + json const j = 23u; CHECK(j.type() == json::value_t::number_unsigned); } SECTION("number (floating-point)") { - json j = 42.23; + json const j = 42.23; CHECK(j.type() == json::value_t::number_float); } } @@ -395,63 +395,63 @@ TEST_CASE("object inspection") { SECTION("null") { - json j = nullptr; + json const j = nullptr; json::value_t t = j; CHECK(t == j.type()); } SECTION("object") { - json j = {{"foo", "bar"}}; + json const j = {{"foo", "bar"}}; json::value_t t = j; CHECK(t == j.type()); } SECTION("array") { - json j = {1, 2, 3, 4}; + json const j = {1, 2, 3, 4}; json::value_t t = j; CHECK(t == j.type()); } SECTION("boolean") { - json j = true; + json const j = true; json::value_t t = j; CHECK(t == j.type()); } SECTION("string") { - json j = "Hello world"; + json const j = "Hello world"; json::value_t t = j; CHECK(t == j.type()); } SECTION("number (integer)") { - json j = 23; + json const j = 23; json::value_t t = j; CHECK(t == j.type()); } SECTION("number (unsigned)") { - json j = 23u; + json const j = 23u; json::value_t t = j; CHECK(t == j.type()); } SECTION("number (floating-point)") { - json j = 42.23; + json const j = 42.23; json::value_t t = j; CHECK(t == j.type()); } SECTION("binary") { - json j = json::binary({}); + json const j = json::binary({}); json::value_t t = j; CHECK(t == j.type()); } diff --git a/tests/src/unit-json_patch.cpp b/tests/src/unit-json_patch.cpp index d1a994b93..8efe33ee0 100644 --- a/tests/src/unit-json_patch.cpp +++ b/tests/src/unit-json_patch.cpp @@ -35,13 +35,13 @@ TEST_CASE("JSON patch") SECTION("4.1 add") { - json patch1 = R"([{ "op": "add", "path": "/a/b", "value": [ "foo", "bar" ] }])"_json; + json const patch1 = R"([{ "op": "add", "path": "/a/b", "value": [ "foo", "bar" ] }])"_json; // However, the object itself or an array containing it does need // to exist, and it remains an error for that not to be the case. // For example, an "add" with a target location of "/a/b" starting // with this document - json doc1 = R"({ "a": { "foo": 1 } })"_json; + json const doc1 = R"({ "a": { "foo": 1 } })"_json; // is not an error, because "a" exists, and "b" will be added to // its value. @@ -57,13 +57,13 @@ TEST_CASE("JSON patch") CHECK(doc1.patch(patch1) == doc1_ans); // It is an error in this document: - json doc2 = R"({ "q": { "bar": 2 } })"_json; + json const doc2 = R"({ "q": { "bar": 2 } })"_json; // because "a" does not exist. CHECK_THROWS_WITH_AS(doc2.patch(patch1), "[json.exception.out_of_range.403] key 'a' not found", json::out_of_range&); - json doc3 = R"({ "a": {} })"_json; - json patch2 = R"([{ "op": "add", "path": "/a/b/c", "value": 1 }])"_json; + json const doc3 = R"({ "a": {} })"_json; + json const patch2 = R"([{ "op": "add", "path": "/a/b/c", "value": 1 }])"_json; // should cause an error because "b" does not exist in doc3 #if JSON_DIAGNOSTICS @@ -77,20 +77,20 @@ TEST_CASE("JSON patch") { // If removing an element from an array, any elements above the // specified index are shifted one position to the left. - json doc = {1, 2, 3, 4}; - json patch = {{{"op", "remove"}, {"path", "/1"}}}; + json const doc = {1, 2, 3, 4}; + json const patch = {{{"op", "remove"}, {"path", "/1"}}}; CHECK(doc.patch(patch) == json({1, 3, 4})); } SECTION("A.1. Adding an Object Member") { // An example target JSON document: - json doc = R"( + json const doc = R"( { "foo": "bar"} )"_json; // A JSON Patch document: - json patch = R"( + json const patch = R"( [ { "op": "add", "path": "/baz", "value": "qux" } ] @@ -114,12 +114,12 @@ TEST_CASE("JSON patch") SECTION("A.2. Adding an Array Element") { // An example target JSON document: - json doc = R"( + json const doc = R"( { "foo": [ "bar", "baz" ] } )"_json; // A JSON Patch document: - json patch = R"( + json const patch = R"( [ { "op": "add", "path": "/foo/1", "value": "qux" } ] @@ -140,7 +140,7 @@ TEST_CASE("JSON patch") SECTION("A.3. Removing an Object Member") { // An example target JSON document: - json doc = R"( + json const doc = R"( { "baz": "qux", "foo": "bar" @@ -148,7 +148,7 @@ TEST_CASE("JSON patch") )"_json; // A JSON Patch document: - json patch = R"( + json const patch = R"( [ { "op": "remove", "path": "/baz" } ] @@ -169,12 +169,12 @@ TEST_CASE("JSON patch") SECTION("A.4. Removing an Array Element") { // An example target JSON document: - json doc = R"( + json const doc = R"( { "foo": [ "bar", "qux", "baz" ] } )"_json; // A JSON Patch document: - json patch = R"( + json const patch = R"( [ { "op": "remove", "path": "/foo/1" } ] @@ -195,7 +195,7 @@ TEST_CASE("JSON patch") SECTION("A.5. Replacing a Value") { // An example target JSON document: - json doc = R"( + json const doc = R"( { "baz": "qux", "foo": "bar" @@ -203,7 +203,7 @@ TEST_CASE("JSON patch") )"_json; // A JSON Patch document: - json patch = R"( + json const patch = R"( [ { "op": "replace", "path": "/baz", "value": "boo" } ] @@ -226,7 +226,7 @@ TEST_CASE("JSON patch") SECTION("A.6. Moving a Value") { // An example target JSON document: - json doc = R"( + json const doc = R"( { "foo": { "bar": "baz", @@ -239,7 +239,7 @@ TEST_CASE("JSON patch") )"_json; // A JSON Patch document: - json patch = R"( + json const patch = R"( [ { "op": "move", "from": "/foo/waldo", "path": "/qux/thud" } ] @@ -268,12 +268,12 @@ TEST_CASE("JSON patch") SECTION("A.7. Moving a Value") { // An example target JSON document: - json doc = R"( + json const doc = R"( { "foo": [ "all", "grass", "cows", "eat" ] } )"_json; // A JSON Patch document: - json patch = R"( + json const patch = R"( [ { "op": "move", "from": "/foo/1", "path": "/foo/3" } ] @@ -302,7 +302,7 @@ TEST_CASE("JSON patch") )"_json; // A JSON Patch document that will result in successful evaluation: - json patch = R"( + json const patch = R"( [ { "op": "test", "path": "/baz", "value": "qux" }, { "op": "test", "path": "/foo/1", "value": 2 } @@ -318,7 +318,7 @@ TEST_CASE("JSON patch") SECTION("A.9. Testing a Value: Error") { // An example target JSON document: - json doc = R"( + json const doc = R"( { "baz": "qux" } )"_json; @@ -341,12 +341,12 @@ TEST_CASE("JSON patch") SECTION("A.10. Adding a Nested Member Object") { // An example target JSON document: - json doc = R"( + json const doc = R"( { "foo": "bar" } )"_json; // A JSON Patch document: - json patch = R"( + json const patch = R"( [ { "op": "add", "path": "/child", "value": { "grandchild": { } } } ] @@ -373,12 +373,12 @@ TEST_CASE("JSON patch") SECTION("A.11. Ignoring Unrecognized Elements") { // An example target JSON document: - json doc = R"( + json const doc = R"( { "foo": "bar" } )"_json; // A JSON Patch document: - json patch = R"( + json const patch = R"( [ { "op": "add", "path": "/baz", "value": "qux", "xyz": 123 } ] @@ -401,12 +401,12 @@ TEST_CASE("JSON patch") SECTION("A.12. Adding to a Nonexistent Target") { // An example target JSON document: - json doc = R"( + json const doc = R"( { "foo": "bar" } )"_json; // A JSON Patch document: - json patch = R"( + json const patch = R"( [ { "op": "add", "path": "/baz/bat", "value": "qux" } ] @@ -427,7 +427,7 @@ TEST_CASE("JSON patch") SECTION("A.14. Escape Ordering") { // An example target JSON document: - json doc = R"( + json const doc = R"( { "/": 9, "~1": 10 @@ -435,7 +435,7 @@ TEST_CASE("JSON patch") )"_json; // A JSON Patch document: - json patch = R"( + json const patch = R"( [ {"op": "test", "path": "/~01", "value": 10} ] @@ -458,7 +458,7 @@ TEST_CASE("JSON patch") SECTION("A.15. Comparing Strings and Numbers") { // An example target JSON document: - json doc = R"( + json const doc = R"( { "/": 9, "~1": 10 @@ -484,12 +484,12 @@ TEST_CASE("JSON patch") SECTION("A.16. Adding an Array Value") { // An example target JSON document: - json doc = R"( + json const doc = R"( { "foo": ["bar"] } )"_json; // A JSON Patch document: - json patch = R"( + json const patch = R"( [ { "op": "add", "path": "/foo/-", "value": ["abc", "def"] } ] @@ -519,10 +519,10 @@ TEST_CASE("JSON patch") // document. // An example target JSON document: - json doc = 17; + json const doc = 17; // A JSON Patch document: - json patch = R"( + json const patch = R"( [ { "op": "add", "path": "", "value": [1,2,3] } ] @@ -545,10 +545,10 @@ TEST_CASE("JSON patch") // exactly the number of elements in the array which is legal. // An example target JSON document: - json doc = {0, 1, 2}; + json const doc = {0, 1, 2}; // A JSON Patch document: - json patch = R"( + json const patch = R"( [ { "op": "add", "path": "/3", "value": 3 } ] @@ -568,7 +568,7 @@ TEST_CASE("JSON patch") SECTION("copy") { // An example target JSON document: - json doc = R"( + json const doc = R"( { "foo": { "bar": "baz", @@ -581,7 +581,7 @@ TEST_CASE("JSON patch") )"_json; // A JSON Patch document: - json patch = R"( + json const patch = R"( [ { "op": "copy", "from": "/foo/waldo", "path": "/qux/thud" } ] @@ -610,8 +610,8 @@ TEST_CASE("JSON patch") SECTION("replace") { - json j = "string"; - json patch = {{{"op", "replace"}, {"path", ""}, {"value", 1}}}; + json const j = "string"; + json const patch = {{{"op", "replace"}, {"path", ""}, {"value", 1}}}; CHECK(j.patch(patch) == json(1)); } @@ -619,12 +619,12 @@ TEST_CASE("JSON patch") { { // a JSON patch - json p1 = R"( + json const p1 = R"( [{"op": "add", "path": "/GB", "value": "London"}] )"_json; // a JSON value - json source = R"( + json const source = R"( {"D": "Berlin", "F": "Paris"} )"_json; @@ -665,15 +665,15 @@ TEST_CASE("JSON patch") { SECTION("not an array") { - json j; - json patch = {{"op", "add"}, {"path", ""}, {"value", 1}}; + json const j; + json const patch = {{"op", "add"}, {"path", ""}, {"value", 1}}; CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.104] parse error: JSON patch must be an array of objects", json::parse_error&); } SECTION("not an array of objects") { - json j; - json patch = {"op", "add", "path", "", "value", 1}; + json const j; + json const patch = {"op", "add", "path", "", "value", 1}; #if JSON_DIAGNOSTICS CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.104] parse error: (/0) JSON patch must be an array of objects", json::parse_error&); #else @@ -683,8 +683,8 @@ TEST_CASE("JSON patch") SECTION("missing 'op'") { - json j; - json patch = {{{"foo", "bar"}}}; + json const j; + json const patch = {{{"foo", "bar"}}}; #if JSON_DIAGNOSTICS CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: (/0) operation must have member 'op'", json::parse_error&); #else @@ -694,8 +694,8 @@ TEST_CASE("JSON patch") SECTION("non-string 'op'") { - json j; - json patch = {{{"op", 1}}}; + json const j; + json const patch = {{{"op", 1}}}; #if JSON_DIAGNOSTICS CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: (/0) operation must have string member 'op'", json::parse_error&); #else @@ -705,8 +705,8 @@ TEST_CASE("JSON patch") SECTION("invalid operation") { - json j; - json patch = {{{"op", "foo"}, {"path", ""}}}; + json const j; + json const patch = {{{"op", "foo"}, {"path", ""}}}; #if JSON_DIAGNOSTICS CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: (/0) operation value 'foo' is invalid", json::parse_error&); #else @@ -719,8 +719,8 @@ TEST_CASE("JSON patch") { SECTION("missing 'path'") { - json j; - json patch = {{{"op", "add"}}}; + json const j; + json const patch = {{{"op", "add"}}}; #if JSON_DIAGNOSTICS CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: (/0) operation 'add' must have member 'path'", json::parse_error&); #else @@ -730,8 +730,8 @@ TEST_CASE("JSON patch") SECTION("non-string 'path'") { - json j; - json patch = {{{"op", "add"}, {"path", 1}}}; + json const j; + json const patch = {{{"op", "add"}, {"path", 1}}}; #if JSON_DIAGNOSTICS CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: (/0) operation 'add' must have string member 'path'", json::parse_error&); #else @@ -741,8 +741,8 @@ TEST_CASE("JSON patch") SECTION("missing 'value'") { - json j; - json patch = {{{"op", "add"}, {"path", ""}}}; + json const j; + json const patch = {{{"op", "add"}, {"path", ""}}}; #if JSON_DIAGNOSTICS CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: (/0) operation 'add' must have member 'value'", json::parse_error&); #else @@ -752,8 +752,8 @@ TEST_CASE("JSON patch") SECTION("invalid array index") { - json j = {1, 2}; - json patch = {{{"op", "add"}, {"path", "/4"}, {"value", 4}}}; + json const j = {1, 2}; + json const patch = {{{"op", "add"}, {"path", "/4"}, {"value", 4}}}; CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.out_of_range.401] array index 4 is out of range", json::out_of_range&); } } @@ -762,8 +762,8 @@ TEST_CASE("JSON patch") { SECTION("missing 'path'") { - json j; - json patch = {{{"op", "remove"}}}; + json const j; + json const patch = {{{"op", "remove"}}}; #if JSON_DIAGNOSTICS CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: (/0) operation 'remove' must have member 'path'", json::parse_error&); #else @@ -773,8 +773,8 @@ TEST_CASE("JSON patch") SECTION("non-string 'path'") { - json j; - json patch = {{{"op", "remove"}, {"path", 1}}}; + json const j; + json const patch = {{{"op", "remove"}, {"path", 1}}}; #if JSON_DIAGNOSTICS CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: (/0) operation 'remove' must have string member 'path'", json::parse_error&); #else @@ -784,22 +784,22 @@ TEST_CASE("JSON patch") SECTION("nonexisting target location (array)") { - json j = {1, 2, 3}; - json patch = {{{"op", "remove"}, {"path", "/17"}}}; + json const j = {1, 2, 3}; + json const patch = {{{"op", "remove"}, {"path", "/17"}}}; CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.out_of_range.401] array index 17 is out of range", json::out_of_range&); } SECTION("nonexisting target location (object)") { - json j = {{"foo", 1}, {"bar", 2}}; - json patch = {{{"op", "remove"}, {"path", "/baz"}}}; + json const j = {{"foo", 1}, {"bar", 2}}; + json const patch = {{{"op", "remove"}, {"path", "/baz"}}}; CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.out_of_range.403] key 'baz' not found", json::out_of_range&); } SECTION("root element as target location") { - json j = "string"; - json patch = {{{"op", "remove"}, {"path", ""}}}; + json const j = "string"; + json const patch = {{{"op", "remove"}, {"path", ""}}}; CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.out_of_range.405] JSON pointer has no parent", json::out_of_range&); } } @@ -808,8 +808,8 @@ TEST_CASE("JSON patch") { SECTION("missing 'path'") { - json j; - json patch = {{{"op", "replace"}}}; + json const j; + json const patch = {{{"op", "replace"}}}; #if JSON_DIAGNOSTICS CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: (/0) operation 'replace' must have member 'path'", json::parse_error&); #else @@ -819,8 +819,8 @@ TEST_CASE("JSON patch") SECTION("non-string 'path'") { - json j; - json patch = {{{"op", "replace"}, {"path", 1}}}; + json const j; + json const patch = {{{"op", "replace"}, {"path", 1}}}; #if JSON_DIAGNOSTICS CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: (/0) operation 'replace' must have string member 'path'", json::parse_error&); #else @@ -830,8 +830,8 @@ TEST_CASE("JSON patch") SECTION("missing 'value'") { - json j; - json patch = {{{"op", "replace"}, {"path", ""}}}; + json const j; + json const patch = {{{"op", "replace"}, {"path", ""}}}; #if JSON_DIAGNOSTICS CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: (/0) operation 'replace' must have member 'value'", json::parse_error&); #else @@ -841,15 +841,15 @@ TEST_CASE("JSON patch") SECTION("nonexisting target location (array)") { - json j = {1, 2, 3}; - json patch = {{{"op", "replace"}, {"path", "/17"}, {"value", 19}}}; + json const j = {1, 2, 3}; + json const patch = {{{"op", "replace"}, {"path", "/17"}, {"value", 19}}}; CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.out_of_range.401] array index 17 is out of range", json::out_of_range&); } SECTION("nonexisting target location (object)") { - json j = {{"foo", 1}, {"bar", 2}}; - json patch = {{{"op", "replace"}, {"path", "/baz"}, {"value", 3}}}; + json const j = {{"foo", 1}, {"bar", 2}}; + json const patch = {{{"op", "replace"}, {"path", "/baz"}, {"value", 3}}}; CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.out_of_range.403] key 'baz' not found", json::out_of_range&); } } @@ -858,8 +858,8 @@ TEST_CASE("JSON patch") { SECTION("missing 'path'") { - json j; - json patch = {{{"op", "move"}}}; + json const j; + json const patch = {{{"op", "move"}}}; #if JSON_DIAGNOSTICS CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: (/0) operation 'move' must have member 'path'", json::parse_error&); #else @@ -869,8 +869,8 @@ TEST_CASE("JSON patch") SECTION("non-string 'path'") { - json j; - json patch = {{{"op", "move"}, {"path", 1}}}; + json const j; + json const patch = {{{"op", "move"}, {"path", 1}}}; #if JSON_DIAGNOSTICS CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: (/0) operation 'move' must have string member 'path'", json::parse_error&); #else @@ -880,8 +880,8 @@ TEST_CASE("JSON patch") SECTION("missing 'from'") { - json j; - json patch = {{{"op", "move"}, {"path", ""}}}; + json const j; + json const patch = {{{"op", "move"}, {"path", ""}}}; CHECK_THROWS_AS(j.patch(patch), json::parse_error&); #if JSON_DIAGNOSTICS CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: (/0) operation 'move' must have member 'from'", json::parse_error&); @@ -892,8 +892,8 @@ TEST_CASE("JSON patch") SECTION("non-string 'from'") { - json j; - json patch = {{{"op", "move"}, {"path", ""}, {"from", 1}}}; + json const j; + json const patch = {{{"op", "move"}, {"path", ""}, {"from", 1}}}; CHECK_THROWS_AS(j.patch(patch), json::parse_error&); #if JSON_DIAGNOSTICS CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: (/0) operation 'move' must have string member 'from'", json::parse_error&); @@ -904,15 +904,15 @@ TEST_CASE("JSON patch") SECTION("nonexisting from location (array)") { - json j = {1, 2, 3}; - json patch = {{{"op", "move"}, {"path", "/0"}, {"from", "/5"}}}; + json const j = {1, 2, 3}; + json const patch = {{{"op", "move"}, {"path", "/0"}, {"from", "/5"}}}; CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.out_of_range.401] array index 5 is out of range", json::out_of_range&); } SECTION("nonexisting from location (object)") { - json j = {{"foo", 1}, {"bar", 2}}; - json patch = {{{"op", "move"}, {"path", "/baz"}, {"from", "/baz"}}}; + json const j = {{"foo", 1}, {"bar", 2}}; + json const patch = {{{"op", "move"}, {"path", "/baz"}, {"from", "/baz"}}}; CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.out_of_range.403] key 'baz' not found", json::out_of_range&); } } @@ -921,8 +921,8 @@ TEST_CASE("JSON patch") { SECTION("missing 'path'") { - json j; - json patch = {{{"op", "copy"}}}; + json const j; + json const patch = {{{"op", "copy"}}}; #if JSON_DIAGNOSTICS CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: (/0) operation 'copy' must have member 'path'", json::parse_error&); #else @@ -932,8 +932,8 @@ TEST_CASE("JSON patch") SECTION("non-string 'path'") { - json j; - json patch = {{{"op", "copy"}, {"path", 1}}}; + json const j; + json const patch = {{{"op", "copy"}, {"path", 1}}}; #if JSON_DIAGNOSTICS CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: (/0) operation 'copy' must have string member 'path'", json::parse_error&); #else @@ -943,8 +943,8 @@ TEST_CASE("JSON patch") SECTION("missing 'from'") { - json j; - json patch = {{{"op", "copy"}, {"path", ""}}}; + json const j; + json const patch = {{{"op", "copy"}, {"path", ""}}}; #if JSON_DIAGNOSTICS CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: (/0) operation 'copy' must have member 'from'", json::parse_error&); #else @@ -954,8 +954,8 @@ TEST_CASE("JSON patch") SECTION("non-string 'from'") { - json j; - json patch = {{{"op", "copy"}, {"path", ""}, {"from", 1}}}; + json const j; + json const patch = {{{"op", "copy"}, {"path", ""}, {"from", 1}}}; #if JSON_DIAGNOSTICS CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: (/0) operation 'copy' must have string member 'from'", json::parse_error&); #else @@ -965,15 +965,15 @@ TEST_CASE("JSON patch") SECTION("nonexisting from location (array)") { - json j = {1, 2, 3}; - json patch = {{{"op", "copy"}, {"path", "/0"}, {"from", "/5"}}}; + json const j = {1, 2, 3}; + json const patch = {{{"op", "copy"}, {"path", "/0"}, {"from", "/5"}}}; CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.out_of_range.401] array index 5 is out of range", json::out_of_range&); } SECTION("nonexisting from location (object)") { - json j = {{"foo", 1}, {"bar", 2}}; - json patch = {{{"op", "copy"}, {"path", "/fob"}, {"from", "/baz"}}}; + json const j = {{"foo", 1}, {"bar", 2}}; + json const patch = {{{"op", "copy"}, {"path", "/fob"}, {"from", "/baz"}}}; CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.out_of_range.403] key 'baz' not found", json::out_of_range&); } } @@ -982,8 +982,8 @@ TEST_CASE("JSON patch") { SECTION("missing 'path'") { - json j; - json patch = {{{"op", "test"}}}; + json const j; + json const patch = {{{"op", "test"}}}; #if JSON_DIAGNOSTICS CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: (/0) operation 'test' must have member 'path'", json::parse_error&); #else @@ -993,8 +993,8 @@ TEST_CASE("JSON patch") SECTION("non-string 'path'") { - json j; - json patch = {{{"op", "test"}, {"path", 1}}}; + json const j; + json const patch = {{{"op", "test"}, {"path", 1}}}; #if JSON_DIAGNOSTICS CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: (/0) operation 'test' must have string member 'path'", json::parse_error&); #else @@ -1004,8 +1004,8 @@ TEST_CASE("JSON patch") SECTION("missing 'value'") { - json j; - json patch = {{{"op", "test"}, {"path", ""}}}; + json const j; + json const patch = {{{"op", "test"}, {"path", ""}}}; #if JSON_DIAGNOSTICS CHECK_THROWS_WITH_AS(j.patch(patch), "[json.exception.parse_error.105] parse error: (/0) operation 'test' must have member 'value'", json::parse_error&); #else @@ -1020,7 +1020,7 @@ TEST_CASE("JSON patch") SECTION("Simple Example") { // The original document - json doc = R"( + json const doc = R"( { "baz": "qux", "foo": "bar" @@ -1028,7 +1028,7 @@ TEST_CASE("JSON patch") )"_json; // The patch - json patch = R"( + json const patch = R"( [ { "op": "replace", "path": "/baz", "value": "boo" }, { "op": "add", "path": "/hello", "value": ["world"] }, @@ -1054,7 +1054,7 @@ TEST_CASE("JSON patch") SECTION("Operations") { // The original document - json doc = R"( + json const doc = R"( { "biscuits": [ {"name":"Digestive"}, @@ -1066,7 +1066,7 @@ TEST_CASE("JSON patch") SECTION("add") { // The patch - json patch = R"( + json const patch = R"( [ {"op": "add", "path": "/biscuits/1", "value": {"name": "Ginger Nut"}} ] @@ -1093,7 +1093,7 @@ TEST_CASE("JSON patch") SECTION("remove") { // The patch - json patch = R"( + json const patch = R"( [ {"op": "remove", "path": "/biscuits"} ] @@ -1114,7 +1114,7 @@ TEST_CASE("JSON patch") SECTION("replace") { // The patch - json patch = R"( + json const patch = R"( [ {"op": "replace", "path": "/biscuits/0/name", "value": "Chocolate Digestive"} ] @@ -1140,7 +1140,7 @@ TEST_CASE("JSON patch") SECTION("copy") { // The patch - json patch = R"( + json const patch = R"( [ {"op": "copy", "from": "/biscuits/0", "path": "/best_biscuit"} ] @@ -1169,7 +1169,7 @@ TEST_CASE("JSON patch") SECTION("move") { // The patch - json patch = R"( + json const patch = R"( [ {"op": "move", "from": "/biscuits", "path": "/cookies"} ] @@ -1290,7 +1290,7 @@ TEST_CASE("JSON patch") { CAPTURE(filename) std::ifstream f(filename); - json suite = json::parse(f); + json const suite = json::parse(f); for (const auto& test : suite) { diff --git a/tests/src/unit-json_pointer.cpp b/tests/src/unit-json_pointer.cpp index 703289721..185d8a0a5 100644 --- a/tests/src/unit-json_pointer.cpp +++ b/tests/src/unit-json_pointer.cpp @@ -40,7 +40,7 @@ TEST_CASE("JSON pointers") SECTION("array index error") { json v = {1, 2, 3, 4}; - json::json_pointer ptr("/10e"); + json::json_pointer const const ptr("/10e"); CHECK_THROWS_WITH_AS(v[ptr], "[json.exception.out_of_range.404] unresolved reference token '10e'", json::out_of_range&); } @@ -311,8 +311,8 @@ TEST_CASE("JSON pointers") { auto too_large_index = std::to_string((std::numeric_limits::max)()) + "1"; - json::json_pointer jp(std::string("/") + too_large_index); - std::string throw_msg = std::string("[json.exception.out_of_range.404] unresolved reference token '") + too_large_index + "'"; + json::json_pointer const 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&); CHECK_THROWS_WITH_AS(j_const[jp] == 1, throw_msg.c_str(), json::out_of_range&); @@ -326,8 +326,8 @@ TEST_CASE("JSON pointers") { auto size_type_max_uul = static_cast((std::numeric_limits::max)()); auto too_large_index = std::to_string(size_type_max_uul); - json::json_pointer jp(std::string("/") + too_large_index); - std::string throw_msg = std::string("[json.exception.out_of_range.410] array index ") + too_large_index + " exceeds size_type"; + json::json_pointer const 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&); CHECK_THROWS_WITH_AS(j_const[jp] == 1, throw_msg.c_str(), json::out_of_range&); @@ -455,7 +455,7 @@ TEST_CASE("JSON pointers") #endif // error for conflicting values - json j_error = {{"", 42}, {"/foo", 17}}; + json const j_error = {{"", 42}, {"/foo", 17}}; CHECK_THROWS_WITH_AS(j_error.unflatten(), "[json.exception.type_error.313] invalid value to unflatten", json::type_error&); @@ -473,9 +473,9 @@ TEST_CASE("JSON pointers") CHECK(j_string.flatten().unflatten() == j_string); // roundtrip for empty structured values (will be unflattened to null) - json j_array(json::value_t::array); + json const j_array(json::value_t::array); CHECK(j_array.flatten().unflatten() == json()); - json j_object(json::value_t::object); + json const j_object(json::value_t::object); CHECK(j_object.flatten().unflatten() == json()); } @@ -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 ptr(ptr_str); + json::json_pointer const const ptr(ptr_str); std::stringstream ss; ss << ptr; CHECK(ptr.to_string() == ptr_str); @@ -742,7 +742,7 @@ TEST_CASE("JSON pointers") CHECK(std::is_same::value); CHECK(std::is_same::value); - std::string ptr_string{"/foo/0"}; + std::string const ptr_string{"/foo/0"}; json_ptr_str ptr{ptr_string}; json_ptr_j ptr_j{ptr_string}; json_ptr_oj ptr_oj{ptr_string}; diff --git a/tests/src/unit-merge_patch.cpp b/tests/src/unit-merge_patch.cpp index cc87bee91..480d4a5ec 100644 --- a/tests/src/unit-merge_patch.cpp +++ b/tests/src/unit-merge_patch.cpp @@ -28,7 +28,7 @@ TEST_CASE("JSON Merge Patch") } })"_json; - json patch = R"({ + json const patch = R"({ "a": "z", "c": { "f": null @@ -61,7 +61,7 @@ TEST_CASE("JSON Merge Patch") "content": "This will be unchanged" })"_json; - json patch = R"({ + json const patch = R"({ "title": "Hello!", "phoneNumber": "+01-123-456-7890", "author": { @@ -93,7 +93,7 @@ TEST_CASE("JSON Merge Patch") SECTION("Example 1") { json original = R"({"a":"b"})"_json; - json patch = R"({"a":"c"})"_json; + json const patch = R"({"a":"c"})"_json; json result = R"({"a":"c"})"_json; original.merge_patch(patch); @@ -103,7 +103,7 @@ TEST_CASE("JSON Merge Patch") SECTION("Example 2") { json original = R"({"a":"b"})"_json; - json patch = R"({"b":"c"})"_json; + json const patch = R"({"b":"c"})"_json; json result = R"({"a":"b", "b":"c"})"_json; original.merge_patch(patch); @@ -113,7 +113,7 @@ TEST_CASE("JSON Merge Patch") SECTION("Example 3") { json original = R"({"a":"b"})"_json; - json patch = R"({"a":null})"_json; + json const patch = R"({"a":null})"_json; json result = R"({})"_json; original.merge_patch(patch); @@ -123,7 +123,7 @@ TEST_CASE("JSON Merge Patch") SECTION("Example 4") { json original = R"({"a":"b","b":"c"})"_json; - json patch = R"({"a":null})"_json; + json const patch = R"({"a":null})"_json; json result = R"({"b":"c"})"_json; original.merge_patch(patch); @@ -133,7 +133,7 @@ TEST_CASE("JSON Merge Patch") SECTION("Example 5") { json original = R"({"a":["b"]})"_json; - json patch = R"({"a":"c"})"_json; + json const patch = R"({"a":"c"})"_json; json result = R"({"a":"c"})"_json; original.merge_patch(patch); @@ -143,7 +143,7 @@ TEST_CASE("JSON Merge Patch") SECTION("Example 6") { json original = R"({"a":"c"})"_json; - json patch = R"({"a":["b"]})"_json; + json const patch = R"({"a":["b"]})"_json; json result = R"({"a":["b"]})"_json; original.merge_patch(patch); @@ -153,7 +153,7 @@ TEST_CASE("JSON Merge Patch") SECTION("Example 7") { json original = R"({"a":{"b": "c"}})"_json; - json patch = R"({"a":{"b":"d","c":null}})"_json; + json const patch = R"({"a":{"b":"d","c":null}})"_json; json result = R"({"a": {"b": "d"}})"_json; original.merge_patch(patch); @@ -163,7 +163,7 @@ TEST_CASE("JSON Merge Patch") SECTION("Example 8") { json original = R"({"a":[{"b":"c"}]})"_json; - json patch = R"({"a":[1]})"_json; + json const patch = R"({"a":[1]})"_json; json result = R"({"a":[1]})"_json; original.merge_patch(patch); @@ -173,7 +173,7 @@ TEST_CASE("JSON Merge Patch") SECTION("Example 9") { json original = R"(["a","b"])"_json; - json patch = R"(["c","d"])"_json; + json const patch = R"(["c","d"])"_json; json result = R"(["c","d"])"_json; original.merge_patch(patch); @@ -183,7 +183,7 @@ TEST_CASE("JSON Merge Patch") SECTION("Example 10") { json original = R"({"a":"b"})"_json; - json patch = R"(["c"])"_json; + json const patch = R"(["c"])"_json; json result = R"(["c"])"_json; original.merge_patch(patch); @@ -193,7 +193,7 @@ TEST_CASE("JSON Merge Patch") SECTION("Example 11") { json original = R"({"a":"foo"})"_json; - json patch = R"(null)"_json; + json const patch = R"(null)"_json; json result = R"(null)"_json; original.merge_patch(patch); @@ -203,7 +203,7 @@ TEST_CASE("JSON Merge Patch") SECTION("Example 12") { json original = R"({"a":"foo"})"_json; - json patch = R"("bar")"_json; + json const patch = R"("bar")"_json; json result = R"("bar")"_json; original.merge_patch(patch); @@ -213,7 +213,7 @@ TEST_CASE("JSON Merge Patch") SECTION("Example 13") { json original = R"({"e":null})"_json; - json patch = R"({"a":1})"_json; + json const patch = R"({"a":1})"_json; json result = R"({"e":null,"a":1})"_json; original.merge_patch(patch); @@ -223,7 +223,7 @@ TEST_CASE("JSON Merge Patch") SECTION("Example 14") { json original = R"([1,2])"_json; - json patch = R"({"a":"b","c":null})"_json; + json const patch = R"({"a":"b","c":null})"_json; json result = R"({"a":"b"})"_json; original.merge_patch(patch); @@ -233,7 +233,7 @@ TEST_CASE("JSON Merge Patch") SECTION("Example 15") { json original = R"({})"_json; - json patch = R"({"a":{"bb":{"ccc":null}}})"_json; + json const patch = R"({"a":{"bb":{"ccc":null}}})"_json; json result = R"({"a":{"bb":{}}})"_json; original.merge_patch(patch); diff --git a/tests/src/unit-modifiers.cpp b/tests/src/unit-modifiers.cpp index fa4d17b5b..5687622f0 100644 --- a/tests/src/unit-modifiers.cpp +++ b/tests/src/unit-modifiers.cpp @@ -19,7 +19,7 @@ TEST_CASE("modifiers") SECTION("boolean") { json j = true; - json k = j; + json const k = j; j.clear(); CHECK(j == json(json::value_t::boolean)); @@ -29,7 +29,7 @@ TEST_CASE("modifiers") SECTION("string") { json j = "hello world"; - json k = j; + json const k = j; j.clear(); CHECK(j == json(json::value_t::string)); @@ -41,7 +41,7 @@ TEST_CASE("modifiers") SECTION("empty array") { json j = json::array(); - json k = j; + json const k = j; j.clear(); CHECK(j.empty()); @@ -52,7 +52,7 @@ TEST_CASE("modifiers") SECTION("filled array") { json j = {1, 2, 3}; - json k = j; + json const k = j; j.clear(); CHECK(j.empty()); @@ -66,7 +66,7 @@ TEST_CASE("modifiers") SECTION("empty object") { json j = json::object(); - json k = j; + json const k = j; j.clear(); CHECK(j.empty()); @@ -77,7 +77,7 @@ TEST_CASE("modifiers") SECTION("filled object") { json j = {{"one", 1}, {"two", 2}, {"three", 3}}; - json k = j; + json const k = j; j.clear(); CHECK(j.empty()); @@ -91,7 +91,7 @@ TEST_CASE("modifiers") SECTION("empty binary") { json j = json::binary({}); - json k = j; + json const k = j; j.clear(); CHECK(!j.empty()); @@ -102,7 +102,7 @@ TEST_CASE("modifiers") SECTION("filled binary") { json j = json::binary({1, 2, 3, 4, 5}); - json k = j; + json const k = j; j.clear(); CHECK(!j.empty()); @@ -114,7 +114,7 @@ TEST_CASE("modifiers") SECTION("number (integer)") { json j = 23; - json k = j; + json const k = j; j.clear(); CHECK(j == json(json::value_t::number_integer)); @@ -124,7 +124,7 @@ TEST_CASE("modifiers") SECTION("number (unsigned)") { json j = 23u; - json k = j; + json const k = j; j.clear(); CHECK(j == json(json::value_t::number_integer)); @@ -134,7 +134,7 @@ TEST_CASE("modifiers") SECTION("number (float)") { json j = 23.42; - json k = j; + json const k = j; j.clear(); CHECK(j == json(json::value_t::number_float)); @@ -144,7 +144,7 @@ TEST_CASE("modifiers") SECTION("null") { json j = nullptr; - json k = j; + json const k = j; j.clear(); CHECK(j == json(json::value_t::null)); @@ -187,7 +187,7 @@ TEST_CASE("modifiers") SECTION("null") { json j; - json k(1); + json const k(1); j.push_back(k); j.push_back(k); CHECK(j.type() == json::value_t::array); @@ -197,7 +197,7 @@ TEST_CASE("modifiers") SECTION("array") { json j = {1, 2, 3}; - json k("Hello"); + json const k("Hello"); j.push_back(k); CHECK(j.type() == json::value_t::array); CHECK(j == json({1, 2, 3, "Hello"})); @@ -206,7 +206,7 @@ TEST_CASE("modifiers") SECTION("other type") { json j = 1; - json k("Hello"); + json const k("Hello"); CHECK_THROWS_WITH_AS(j.push_back(k), "[json.exception.type_error.308] cannot use push_back() with number", json::type_error&); } } @@ -238,7 +238,7 @@ TEST_CASE("modifiers") SECTION("other type") { json j = 1; - json k("Hello"); + json const k("Hello"); CHECK_THROWS_WITH_AS(j.push_back(json::object_t::value_type({"one", 1})), "[json.exception.type_error.308] cannot use push_back() with number", json::type_error&); } } @@ -415,7 +415,7 @@ TEST_CASE("modifiers") SECTION("null") { json j; - json k(1); + json const k(1); j += k; j += k; CHECK(j.type() == json::value_t::array); @@ -425,7 +425,7 @@ TEST_CASE("modifiers") SECTION("array") { json j = {1, 2, 3}; - json k("Hello"); + json const k("Hello"); j += k; CHECK(j.type() == json::value_t::array); CHECK(j == json({1, 2, 3, "Hello"})); @@ -434,7 +434,7 @@ TEST_CASE("modifiers") SECTION("other type") { json j = 1; - json k("Hello"); + json const k("Hello"); CHECK_THROWS_WITH_AS(j += k, "[json.exception.type_error.308] cannot use push_back() with number", json::type_error&); } } @@ -466,7 +466,7 @@ TEST_CASE("modifiers") SECTION("other type") { json j = 1; - json k("Hello"); + json const k("Hello"); CHECK_THROWS_WITH_AS(j += json::object_t::value_type({"one", 1}), "[json.exception.type_error.308] cannot use push_back() with number", json::type_error&); } } @@ -663,7 +663,7 @@ TEST_CASE("modifiers") SECTION("invalid iterators") { - json j_other_array2 = {"first", "second"}; + json const j_other_array2 = {"first", "second"}; CHECK_THROWS_WITH_AS(j_array.insert(j_object2.begin(), j_object2.end()), "[json.exception.type_error.309] cannot use insert() with array", json::type_error&); CHECK_THROWS_WITH_AS(j_object1.insert(j_object1.begin(), j_object2.end()), "[json.exception.invalid_iterator.210] iterators do not fit", json::invalid_iterator&); @@ -774,7 +774,7 @@ TEST_CASE("modifiers") SECTION("invalid iterators") { - json j_other_array2 = {"first", "second"}; + json const j_other_array2 = {"first", "second"}; CHECK_THROWS_WITH_AS(j_array.update(j_object2.begin(), j_object2.end()), "[json.exception.type_error.312] cannot use update() with array", json::type_error&); CHECK_THROWS_WITH_AS(j_object1.update(j_object1.begin(), j_object2.end()), "[json.exception.invalid_iterator.210] iterators do not fit", json::invalid_iterator&); @@ -790,7 +790,7 @@ TEST_CASE("modifiers") SECTION("extend object") { json j1 = {{"string", "s"}, {"numbers", {{"one", 1}}}}; - json j2 = {{"string", "t"}, {"numbers", {{"two", 2}}}}; + json const j2 = {{"string", "t"}, {"numbers", {{"two", 2}}}}; j1.update(j2, true); CHECK(j1 == json({{"string", "t"}, {"numbers", {{"one", 1}, {"two", 2}}}})); } @@ -798,7 +798,7 @@ TEST_CASE("modifiers") SECTION("replace object") { json j1 = {{"string", "s"}, {"numbers", {{"one", 1}}}}; - json j2 = {{"string", "t"}, {"numbers", 1}}; + json const j2 = {{"string", "t"}, {"numbers", 1}}; j1.update(j2, true); CHECK(j1 == json({{"string", "t"}, {"numbers", 1}})); } diff --git a/tests/src/unit-msgpack.cpp b/tests/src/unit-msgpack.cpp index 0f7aab8da..d0111dcad 100644 --- a/tests/src/unit-msgpack.cpp +++ b/tests/src/unit-msgpack.cpp @@ -106,7 +106,7 @@ TEST_CASE("MessagePack") 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_msgpack(j); CHECK(result.empty()); } @@ -1150,7 +1150,7 @@ TEST_CASE("MessagePack") // create JSON value with byte array containing of N * 'x' const auto s = std::vector(N, 'x'); json j = json::binary(s); - std::uint8_t subtype = 42; + std::uint8_t const subtype = 42; j.get_binary().set_subtype(subtype); // create expected byte vector @@ -1225,7 +1225,7 @@ TEST_CASE("MessagePack") // create JSON value with string containing of N * 'x' const auto s = std::vector(N, 'x'); json j = json::binary(s); - std::uint8_t subtype = 42; + std::uint8_t const subtype = 42; j.get_binary().set_subtype(subtype); // create expected byte vector (hack: create string first) @@ -1261,7 +1261,7 @@ TEST_CASE("MessagePack") // create JSON value with string containing of N * 'x' const auto s = std::vector(N, 'x'); json j = json::binary(s); - std::uint8_t subtype = 42; + std::uint8_t const subtype = 42; j.get_binary().set_subtype(subtype); // create expected byte vector (hack: create string first) @@ -1398,7 +1398,7 @@ TEST_CASE("MessagePack") SECTION("from float32") { auto given = std::vector({0xca, 0x41, 0xc8, 0x00, 0x01}); - json j = json::from_msgpack(given); + json const j = json::from_msgpack(given); CHECK(j.get() == Approx(25.0000019073486)); } @@ -1511,7 +1511,7 @@ TEST_CASE("MessagePack") SECTION("strict mode") { - std::vector vec = {0xc0, 0xc0}; + std::vector const vec = {0xc0, 0xc0}; SECTION("non-strict mode") { const auto result = json::from_msgpack(vec, false); @@ -1531,21 +1531,21 @@ TEST_CASE("MessagePack") { SECTION("start_array(len)") { - std::vector v = {0x93, 0x01, 0x02, 0x03}; + std::vector const v = {0x93, 0x01, 0x02, 0x03}; SaxCountdown scp(0); CHECK(!json::sax_parse(v, &scp, json::input_format_t::msgpack)); } SECTION("start_object(len)") { - std::vector v = {0x81, 0xa3, 0x66, 0x6F, 0x6F, 0xc2}; + std::vector const v = {0x81, 0xa3, 0x66, 0x6F, 0x6F, 0xc2}; SaxCountdown scp(0); CHECK(!json::sax_parse(v, &scp, json::input_format_t::msgpack)); } SECTION("key()") { - std::vector v = {0x81, 0xa3, 0x66, 0x6F, 0x6F, 0xc2}; + std::vector const v = {0x81, 0xa3, 0x66, 0x6F, 0x6F, 0xc2}; SaxCountdown scp(1); CHECK(!json::sax_parse(v, &scp, json::input_format_t::msgpack)); } @@ -1557,7 +1557,7 @@ TEST_CASE("single MessagePack 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); @@ -1817,7 +1817,7 @@ TEST_CASE("MessagePack 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 MessagePack file auto packed = utils::read_binary_file(filename + ".msgpack"); diff --git a/tests/src/unit-ordered_json.cpp b/tests/src/unit-ordered_json.cpp index c8f425b4c..4e853cc3c 100644 --- a/tests/src/unit-ordered_json.cpp +++ b/tests/src/unit-ordered_json.cpp @@ -46,7 +46,7 @@ TEST_CASE("ordered_json") CHECK(oj.dump() == "{\"element3\":3,\"element2\":2}"); // There are no dup keys cause constructor calls emplace... - json multi {{"z", 1}, {"m", 2}, {"m", 3}, {"y", 4}, {"m", 5}}; + json const multi {{"z", 1}, {"m", 2}, {"m", 3}, {"y", 4}, {"m", 5}}; CHECK(multi.size() == 3); CHECK(multi.dump() == "{\"m\":2,\"y\":4,\"z\":1}"); diff --git a/tests/src/unit-ordered_map.cpp b/tests/src/unit-ordered_map.cpp index f9e6302b6..57692c3d8 100644 --- a/tests/src/unit-ordered_map.cpp +++ b/tests/src/unit-ordered_map.cpp @@ -19,7 +19,7 @@ TEST_CASE("ordered_map") SECTION("constructor from iterator range") { std::map m {{"eins", "one"}, {"zwei", "two"}, {"drei", "three"}}; - ordered_map om(m.begin(), m.end()); + ordered_map const om(m.begin(), m.end()); CHECK(om.size() == 3); } @@ -281,8 +281,8 @@ TEST_CASE("ordered_map") SECTION("const value_type&") { - ordered_map::value_type vt1 {"eins", "1"}; - ordered_map::value_type vt4 {"vier", "four"}; + ordered_map::value_type const vt1 {"eins", "1"}; + ordered_map::value_type const vt4 {"vier", "four"}; auto res1 = om.insert(vt1); CHECK(res1.first == om.begin()); diff --git a/tests/src/unit-readme.cpp b/tests/src/unit-readme.cpp index 1c2061459..504466d66 100644 --- a/tests/src/unit-readme.cpp +++ b/tests/src/unit-readme.cpp @@ -33,7 +33,7 @@ TEST_CASE("README" * doctest::skip()) { // redirect std::cout for the README file auto* old_cout_buffer = std::cout.rdbuf(); - std::ostringstream new_stream; + std::ostringstream const new_stream; std::cout.rdbuf(new_stream.rdbuf()); { // create an empty structure (null) @@ -61,7 +61,7 @@ TEST_CASE("README" * doctest::skip()) j["object"] = { {"currency", "USD"}, {"value", 42.99} }; // instead, you could also write (which looks very similar to the JSON above) - json j2 = + json const j2 = { {"pi", 3.141}, {"happy", true}, @@ -84,13 +84,13 @@ TEST_CASE("README" * doctest::skip()) { // ways to express the empty array [] - json empty_array_implicit = {{}}; + json const empty_array_implicit = {{}}; CHECK(empty_array_implicit.is_array()); - json empty_array_explicit = json::array(); + json const empty_array_explicit = json::array(); CHECK(empty_array_explicit.is_array()); // a way to express the empty object {} - json empty_object_explicit = json::object(); + json const empty_object_explicit = json::object(); CHECK(empty_object_explicit.is_object()); // a way to express an _array_ of key/value pairs [["currency", "USD"], ["value", 42.99]] @@ -103,7 +103,7 @@ TEST_CASE("README" * doctest::skip()) { // create object from string literal - json j = "{ \"happy\": true, \"pi\": 3.141 }"_json; // NOLINT(modernize-raw-string-literal) + json const j = "{ \"happy\": true, \"pi\": 3.141 }"_json; // NOLINT(modernize-raw-string-literal) // or even nicer with a raw string literal auto j2 = R"({ @@ -115,7 +115,7 @@ TEST_CASE("README" * doctest::skip()) auto j3 = json::parse(R"({"happy": true, "pi": 3.141})"); // explicit conversion to string - std::string s = j.dump(); // {\"happy\":true,\"pi\":3.141} + std::string const s = j.dump(); // {\"happy\":true,\"pi\":3.141} // serialization with pretty printing // pass in the amount of spaces to indent @@ -178,82 +178,82 @@ TEST_CASE("README" * doctest::skip()) } { - std::vector c_vector {1, 2, 3, 4}; - json j_vec(c_vector); + std::vector const c_vector {1, 2, 3, 4}; + json const j_vec(c_vector); // [1, 2, 3, 4] - std::deque c_deque {1.2f, 2.3f, 3.4f, 5.6f}; - json j_deque(c_deque); + std::deque const c_deque {1.2f, 2.3f, 3.4f, 5.6f}; + json const j_deque(c_deque); // [1.2, 2.3, 3.4, 5.6] - std::list c_list {true, true, false, true}; - json j_list(c_list); + std::list const c_list {true, true, false, true}; + json const j_list(c_list); // [true, true, false, true] - std::forward_list c_flist {12345678909876, 23456789098765, 34567890987654, 45678909876543}; - json j_flist(c_flist); + std::forward_list const c_flist {12345678909876, 23456789098765, 34567890987654, 45678909876543}; + json const j_flist(c_flist); // [12345678909876, 23456789098765, 34567890987654, 45678909876543] - std::array c_array {{1, 2, 3, 4}}; - json j_array(c_array); + std::array const c_array {{1, 2, 3, 4}}; + json const j_array(c_array); // [1, 2, 3, 4] - std::set c_set {"one", "two", "three", "four", "one"}; - json j_set(c_set); // only one entry for "one" is used + std::set const c_set {"one", "two", "three", "four", "one"}; + json const j_set(c_set); // only one entry for "one" is used // ["four", "one", "three", "two"] - std::unordered_set c_uset {"one", "two", "three", "four", "one"}; - json j_uset(c_uset); // only one entry for "one" is used + std::unordered_set const c_uset {"one", "two", "three", "four", "one"}; + json const j_uset(c_uset); // only one entry for "one" is used // maybe ["two", "three", "four", "one"] - std::multiset c_mset {"one", "two", "one", "four"}; - json j_mset(c_mset); // both entries for "one" are used + std::multiset const c_mset {"one", "two", "one", "four"}; + json const j_mset(c_mset); // both entries for "one" are used // maybe ["one", "two", "one", "four"] - std::unordered_multiset c_umset {"one", "two", "one", "four"}; - json j_umset(c_umset); // both entries for "one" are used + std::unordered_multiset const c_umset {"one", "two", "one", "four"}; + json const j_umset(c_umset); // both entries for "one" are used // maybe ["one", "two", "one", "four"] } { - std::map c_map { {"one", 1}, {"two", 2}, {"three", 3} }; - json j_map(c_map); + std::map const c_map { {"one", 1}, {"two", 2}, {"three", 3} }; + json const j_map(c_map); // {"one": 1, "two": 2, "three": 3} - std::unordered_map c_umap { {"one", 1.2f}, {"two", 2.3f}, {"three", 3.4f} }; - json j_umap(c_umap); + std::unordered_map const c_umap { {"one", 1.2f}, {"two", 2.3f}, {"three", 3.4f} }; + json const j_umap(c_umap); // {"one": 1.2, "two": 2.3, "three": 3.4} - std::multimap c_mmap { {"one", true}, {"two", true}, {"three", false}, {"three", true} }; - json j_mmap(c_mmap); // only one entry for key "three" is used + std::multimap const c_mmap { {"one", true}, {"two", true}, {"three", false}, {"three", true} }; + json const j_mmap(c_mmap); // only one entry for key "three" is used // maybe {"one": true, "two": true, "three": true} - std::unordered_multimap c_ummap { {"one", true}, {"two", true}, {"three", false}, {"three", true} }; - json j_ummap(c_ummap); // only one entry for key "three" is used + std::unordered_multimap const c_ummap { {"one", true}, {"two", true}, {"three", false}, {"three", true} }; + json const j_ummap(c_ummap); // only one entry for key "three" is used // maybe {"one": true, "two": true, "three": true} } { // strings - std::string s1 = "Hello, world!"; - json js = s1; + std::string const s1 = "Hello, world!"; + json const js = s1; auto s2 = js.get(); // Booleans - bool b1 = true; - json jb = b1; + bool const b1 = true; + json const jb = b1; bool b2{jb}; CHECK(b2 == true); // numbers - int i = 42; - json jn = i; + int const i = 42; + json const jn = i; double f{jn}; CHECK(f == 42); // etc. - std::string vs = js.get(); + std::string const vs = js.get(); bool vb = jb.get(); CHECK(vb == true); int vi = jn.get(); @@ -274,14 +274,14 @@ TEST_CASE("README" * doctest::skip()) // "two" // a JSON patch (RFC 6902) - json j_patch = R"([ + json const j_patch = R"([ { "op": "replace", "path": "/baz", "value": "boo" }, { "op": "add", "path": "/hello", "value": ["world"] }, { "op": "remove", "path": "/foo"} ])"_json; // apply the patch - json j_result = j_original.patch(j_patch); + json const j_result = j_original.patch(j_patch); // { // "baz": "boo", // "hello": ["world"] diff --git a/tests/src/unit-udt.cpp b/tests/src/unit-udt.cpp index c95de4199..a0260f59d 100644 --- a/tests/src/unit-udt.cpp +++ b/tests/src/unit-udt.cpp @@ -418,15 +418,15 @@ TEST_CASE("adl_serializer specialization" * doctest::test_suite("udt")) { SECTION("to_json") { - udt::legacy_type lt{"4242"}; + udt::legacy_type const lt{"4242"}; - json j = lt; + json const j = lt; CHECK(j.get() == 4242); } SECTION("from_json") { - json j = 4242; + json const j = 4242; auto lt = j.get(); CHECK(lt.number == "4242"); } @@ -459,7 +459,7 @@ struct adl_serializer> TEST_CASE("even supported types can be specialized" * doctest::test_suite("udt")) { - json j = std::vector {1.0, 2.0, 3.0}; + json const j = std::vector {1.0, 2.0, 3.0}; CHECK(j.dump() == R"("hijacked!")"); auto f = j.get>(); // the single argument from_json method is preferred @@ -644,14 +644,14 @@ TEST_CASE("custom serializer for pods" * doctest::test_suite("udt")) std::int64_t, std::uint64_t, double, std::allocator, pod_serializer>; auto p = udt::small_pod{42, '/', 42}; - custom_json j = p; + custom_json const j = p; auto p2 = j.get(); CHECK(p == p2); auto np = udt::non_pod{{"non-pod"}}; - custom_json j2 = np; + custom_json const j2 = np; auto np2 = j2.get(); CHECK(np == np2); } @@ -681,8 +681,8 @@ TEST_CASE("custom serializer that does adl by default" * doctest::test_suite("ud { auto me = udt::person{{23}, {"theo"}, udt::country::france}; - json j = me; - custom_json cj = me; + json const j = me; + custom_json const cj = me; CHECK(j.dump() == cj.dump()); @@ -694,21 +694,21 @@ TEST_CASE("different basic_json types conversions") { SECTION("null") { - json j; + json const j; custom_json cj = j; CHECK(cj == nullptr); } SECTION("boolean") { - json j = true; + json const j = true; custom_json cj = j; CHECK(cj == true); } SECTION("discarded") { - json j(json::value_t::discarded); + json const j(json::value_t::discarded); custom_json cj; CHECK_NOTHROW(cj = j); CHECK(cj.type() == custom_json::value_t::discarded); @@ -716,35 +716,35 @@ TEST_CASE("different basic_json types conversions") SECTION("array") { - json j = {1, 2, 3}; - custom_json cj = j; + json const j = {1, 2, 3}; + custom_json const cj = j; CHECK((cj == std::vector {1, 2, 3})); } SECTION("integer") { - json j = 42; + json const j = 42; custom_json cj = j; CHECK(cj == 42); } SECTION("float") { - json j = 42.0; + json const j = 42.0; custom_json cj = j; CHECK(cj == 42.0); } SECTION("unsigned") { - json j = 42u; + json const j = 42u; custom_json cj = j; CHECK(cj == 42u); } SECTION("string") { - json j = "forty-two"; + json const j = "forty-two"; custom_json cj = j; CHECK(cj == "forty-two"); } @@ -761,7 +761,7 @@ TEST_CASE("different basic_json types conversions") SECTION("object") { - json j = {{"forty", "two"}}; + json const j = {{"forty", "two"}}; custom_json cj = j; auto m = j.get>(); CHECK(cj == m); @@ -769,7 +769,7 @@ TEST_CASE("different basic_json types conversions") SECTION("get") { - json j = 42; + json const j = 42; custom_json cj = j.get(); CHECK(cj == 42); } @@ -857,8 +857,8 @@ class no_iterator_type TEST_CASE("compatible array type, without iterator type alias") { - no_iterator_type vec{1, 2, 3}; - json j = vec; + no_iterator_type const vec{1, 2, 3}; + json const j = vec; } DOCTEST_GCC_SUPPRESS_WARNING_POP diff --git a/tests/src/unit-udt_macro.cpp b/tests/src/unit-udt_macro.cpp index e52412bf9..ac9d9d2e8 100644 --- a/tests/src/unit-udt_macro.cpp +++ b/tests/src/unit-udt_macro.cpp @@ -349,7 +349,7 @@ TEST_CASE_TEMPLATE("Serialization/deserialization of classes with 26 public/priv { { T obj1; - nlohmann::json j = obj1; //via json object + nlohmann::json const j = obj1; //via json object T obj2; j.get_to(obj2); bool ok = (obj1 == obj2); @@ -358,9 +358,9 @@ TEST_CASE_TEMPLATE("Serialization/deserialization of classes with 26 public/priv { T obj1; - nlohmann::json j1 = obj1; //via json string - std::string s = j1.dump(); - nlohmann::json j2 = nlohmann::json::parse(s); + nlohmann::json const j1 = obj1; //via json string + std::string const s = j1.dump(); + nlohmann::json const j2 = nlohmann::json::parse(s); T obj2; j2.get_to(obj2); bool ok = (obj1 == obj2); @@ -369,9 +369,9 @@ TEST_CASE_TEMPLATE("Serialization/deserialization of classes with 26 public/priv { T obj1; - nlohmann::json j1 = obj1; //via msgpack - std::vector buf = nlohmann::json::to_msgpack(j1); - nlohmann::json j2 = nlohmann::json::from_msgpack(buf); + nlohmann::json const j1 = obj1; //via msgpack + std::vector const buf = nlohmann::json::to_msgpack(j1); + nlohmann::json const j2 = nlohmann::json::from_msgpack(buf); T obj2; j2.get_to(obj2); bool ok = (obj1 == obj2); @@ -380,9 +380,9 @@ TEST_CASE_TEMPLATE("Serialization/deserialization of classes with 26 public/priv { T obj1; - nlohmann::json j1 = obj1; //via bson - std::vector buf = nlohmann::json::to_bson(j1); - nlohmann::json j2 = nlohmann::json::from_bson(buf); + nlohmann::json const j1 = obj1; //via bson + std::vector const buf = nlohmann::json::to_bson(j1); + nlohmann::json const j2 = nlohmann::json::from_bson(buf); T obj2; j2.get_to(obj2); bool ok = (obj1 == obj2); @@ -391,9 +391,9 @@ TEST_CASE_TEMPLATE("Serialization/deserialization of classes with 26 public/priv { T obj1; - nlohmann::json j1 = obj1; //via cbor - std::vector buf = nlohmann::json::to_cbor(j1); - nlohmann::json j2 = nlohmann::json::from_cbor(buf); + nlohmann::json const j1 = obj1; //via cbor + std::vector const buf = nlohmann::json::to_cbor(j1); + nlohmann::json const j2 = nlohmann::json::from_cbor(buf); T obj2; j2.get_to(obj2); bool ok = (obj1 == obj2); @@ -402,9 +402,9 @@ TEST_CASE_TEMPLATE("Serialization/deserialization of classes with 26 public/priv { T obj1; - nlohmann::json j1 = obj1; //via ubjson - std::vector buf = nlohmann::json::to_ubjson(j1); - nlohmann::json j2 = nlohmann::json::from_ubjson(buf); + nlohmann::json const j1 = obj1; //via ubjson + std::vector const buf = nlohmann::json::to_ubjson(j1); + nlohmann::json const j2 = nlohmann::json::from_ubjson(buf); T obj2; j2.get_to(obj2); bool ok = (obj1 == obj2);