diff --git a/.clang-tidy b/.clang-tidy index f9ea0b33a..0739c7b33 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -6,6 +6,7 @@ Checks: '*, -bugprone-easily-swappable-parameters, -cert-err58-cpp, -concurrency-mt-unsafe, + -cppcoreguidelines-avoid-const-or-ref-data-members, -cppcoreguidelines-avoid-goto, -cppcoreguidelines-avoid-magic-numbers, -cppcoreguidelines-avoid-non-const-global-variables, diff --git a/.github/workflows/ubuntu.yml b/.github/workflows/ubuntu.yml index 16065fb86..47bd3371d 100644 --- a/.github/workflows/ubuntu.yml +++ b/.github/workflows/ubuntu.yml @@ -73,7 +73,7 @@ jobs: target: [ci_clang_tidy, ci_test_clang_sanitizer, ci_clang_analyze] steps: - name: Install git - run: apt-get update ; apt-get install -y git + run: apt-get update ; apt-get install -y git clang-tools - uses: actions/checkout@v3 - name: Get latest CMake and ninja uses: lukka/get-cmake@latest diff --git a/include/nlohmann/detail/exceptions.hpp b/include/nlohmann/detail/exceptions.hpp index 9f82d7f06..09ce54155 100644 --- a/include/nlohmann/detail/exceptions.hpp +++ b/include/nlohmann/detail/exceptions.hpp @@ -149,17 +149,17 @@ class parse_error : public exception template::value, int> = 0> static parse_error create(int id_, const position_t& pos, const std::string& what_arg, BasicJsonContext context) { - std::string w = concat(exception::name("parse_error", id_), "parse error", - position_string(pos), ": ", exception::diagnostics(context), what_arg); + const std::string w = concat(exception::name("parse_error", id_), "parse error", + position_string(pos), ": ", exception::diagnostics(context), what_arg); return {id_, pos.chars_read_total, w.c_str()}; } template::value, int> = 0> static parse_error create(int id_, std::size_t byte_, const std::string& what_arg, BasicJsonContext context) { - std::string w = concat(exception::name("parse_error", id_), "parse error", - (byte_ != 0 ? (concat(" at byte ", std::to_string(byte_))) : ""), - ": ", exception::diagnostics(context), what_arg); + const std::string w = concat(exception::name("parse_error", id_), "parse error", + (byte_ != 0 ? (concat(" at byte ", std::to_string(byte_))) : ""), + ": ", exception::diagnostics(context), what_arg); return {id_, byte_, w.c_str()}; } @@ -193,7 +193,7 @@ class invalid_iterator : public exception template::value, int> = 0> static invalid_iterator create(int id_, const std::string& what_arg, BasicJsonContext context) { - std::string w = concat(exception::name("invalid_iterator", id_), exception::diagnostics(context), what_arg); + const std::string w = concat(exception::name("invalid_iterator", id_), exception::diagnostics(context), what_arg); return {id_, w.c_str()}; } @@ -211,7 +211,7 @@ class type_error : public exception template::value, int> = 0> static type_error create(int id_, const std::string& what_arg, BasicJsonContext context) { - std::string w = concat(exception::name("type_error", id_), exception::diagnostics(context), what_arg); + const std::string w = concat(exception::name("type_error", id_), exception::diagnostics(context), what_arg); return {id_, w.c_str()}; } @@ -228,7 +228,7 @@ class out_of_range : public exception template::value, int> = 0> static out_of_range create(int id_, const std::string& what_arg, BasicJsonContext context) { - std::string w = concat(exception::name("out_of_range", id_), exception::diagnostics(context), what_arg); + const std::string w = concat(exception::name("out_of_range", id_), exception::diagnostics(context), what_arg); return {id_, w.c_str()}; } @@ -245,7 +245,7 @@ class other_error : public exception template::value, int> = 0> static other_error create(int id_, const std::string& what_arg, BasicJsonContext context) { - std::string w = concat(exception::name("other_error", id_), exception::diagnostics(context), what_arg); + const std::string w = concat(exception::name("other_error", id_), exception::diagnostics(context), what_arg); return {id_, w.c_str()}; } diff --git a/include/nlohmann/detail/input/binary_reader.hpp b/include/nlohmann/detail/input/binary_reader.hpp index 634615d35..1fb1c052b 100644 --- a/include/nlohmann/detail/input/binary_reader.hpp +++ b/include/nlohmann/detail/input/binary_reader.hpp @@ -330,7 +330,7 @@ class binary_reader { std::array cr{{}}; static_cast((std::snprintf)(cr.data(), cr.size(), "%.2hhX", static_cast(element_type))); // NOLINT(cppcoreguidelines-pro-type-vararg,hicpp-vararg) - std::string cr_str{cr.data()}; + const std::string cr_str{cr.data()}; return sax->parse_error(element_type_parse_position, cr_str, parse_error::create(114, element_type_parse_position, concat("Unsupported BSON record type 0x", cr_str), nullptr)); } @@ -2265,7 +2265,7 @@ class binary_reader exception_message(input_format, concat("expected '#' after type information; last byte: 0x", last_token), "size"), nullptr)); } - bool is_error = get_ubjson_size_value(result.first, is_ndarray); + const bool is_error = get_ubjson_size_value(result.first, is_ndarray); if (input_format == input_format_t::bjdata && is_ndarray) { if (inside_ndarray) @@ -2280,7 +2280,7 @@ class binary_reader if (current == '#') { - bool is_error = get_ubjson_size_value(result.first, is_ndarray); + const bool is_error = get_ubjson_size_value(result.first, is_ndarray); if (input_format == input_format_t::bjdata && is_ndarray) { return sax->parse_error(chars_read, get_token_string(), parse_error::create(112, chars_read, diff --git a/include/nlohmann/detail/json_pointer.hpp b/include/nlohmann/detail/json_pointer.hpp index 3f69bcdf1..84d92c12f 100644 --- a/include/nlohmann/detail/json_pointer.hpp +++ b/include/nlohmann/detail/json_pointer.hpp @@ -230,7 +230,7 @@ class json_pointer const char* p = s.c_str(); char* p_end = nullptr; errno = 0; // strtoull doesn't reset errno - unsigned long long res = std::strtoull(p, &p_end, 10); // NOLINT(runtime/int) + const unsigned long long res = std::strtoull(p, &p_end, 10); // NOLINT(runtime/int) if (p == p_end // invalid input or empty string || errno == ERANGE // out of range || JSON_HEDLEY_UNLIKELY(static_cast(p_end - p) != s.size())) // incomplete read diff --git a/include/nlohmann/detail/macro_scope.hpp b/include/nlohmann/detail/macro_scope.hpp index 3ecf7a4c6..2870a4f1d 100644 --- a/include/nlohmann/detail/macro_scope.hpp +++ b/include/nlohmann/detail/macro_scope.hpp @@ -396,7 +396,7 @@ #define NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(Type, ...) \ friend void to_json(nlohmann::json& nlohmann_json_j, const Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) } \ - friend void from_json(const nlohmann::json& nlohmann_json_j, Type& nlohmann_json_t) { Type nlohmann_json_default_obj; NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_FROM_WITH_DEFAULT, __VA_ARGS__)) } + friend void from_json(const nlohmann::json& nlohmann_json_j, Type& nlohmann_json_t) { const Type nlohmann_json_default_obj{}; NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_FROM_WITH_DEFAULT, __VA_ARGS__)) } /*! @brief macro @@ -409,7 +409,7 @@ #define NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(Type, ...) \ inline void to_json(nlohmann::json& nlohmann_json_j, const Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) } \ - inline void from_json(const nlohmann::json& nlohmann_json_j, Type& nlohmann_json_t) { Type nlohmann_json_default_obj; NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_FROM_WITH_DEFAULT, __VA_ARGS__)) } + inline void from_json(const nlohmann::json& nlohmann_json_j, Type& nlohmann_json_t) { const Type nlohmann_json_default_obj{}; NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_FROM_WITH_DEFAULT, __VA_ARGS__)) } // inspired from https://stackoverflow.com/a/26745591 diff --git a/include/nlohmann/detail/output/binary_writer.hpp b/include/nlohmann/detail/output/binary_writer.hpp index 9423635f0..dfe757f0a 100644 --- a/include/nlohmann/detail/output/binary_writer.hpp +++ b/include/nlohmann/detail/output/binary_writer.hpp @@ -661,18 +661,18 @@ class binary_writer } else if (N <= (std::numeric_limits::max)()) { - std::uint8_t output_type = use_ext - ? 0xC8 // ext 16 - : 0xC5; // bin 16 + const std::uint8_t output_type = use_ext + ? 0xC8 // ext 16 + : 0xC5; // bin 16 oa->write_character(to_char_type(output_type)); write_number(static_cast(N)); } else if (N <= (std::numeric_limits::max)()) { - std::uint8_t output_type = use_ext - ? 0xC9 // ext 32 - : 0xC6; // bin 32 + const std::uint8_t output_type = use_ext + ? 0xC9 // ext 32 + : 0xC6; // bin 32 oa->write_character(to_char_type(output_type)); write_number(static_cast(N)); @@ -1258,8 +1258,8 @@ class binary_writer */ static std::size_t calc_bson_object_size(const typename BasicJsonType::object_t& value) { - std::size_t document_size = std::accumulate(value.begin(), value.end(), static_cast(0), - [](size_t result, const typename BasicJsonType::object_t::value_type & el) + const std::size_t document_size = std::accumulate(value.begin(), value.end(), static_cast(0), + [](size_t result, const typename BasicJsonType::object_t::value_type & el) { return result += calc_bson_element_size(el.first, el.second); }); diff --git a/include/nlohmann/detail/output/serializer.hpp b/include/nlohmann/detail/output/serializer.hpp index 500fc55ec..a7dab5cd6 100644 --- a/include/nlohmann/detail/output/serializer.hpp +++ b/include/nlohmann/detail/output/serializer.hpp @@ -926,7 +926,7 @@ class serializer ? (byte & 0x3fu) | (codep << 6u) : (0xFFu >> type) & (byte); - std::size_t index = 256u + static_cast(state) * 16u + static_cast(type); + const std::size_t index = 256u + static_cast(state) * 16u + static_cast(type); JSON_ASSERT(index < 400); state = utf8d[index]; return state; diff --git a/include/nlohmann/json.hpp b/include/nlohmann/json.hpp index 8a3cfdbf9..b1c23f7d7 100644 --- a/include/nlohmann/json.hpp +++ b/include/nlohmann/json.hpp @@ -4718,7 +4718,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec } // make sure the top element of the pointer exists - json_pointer top_pointer = ptr.top(); + json_pointer const top_pointer = ptr.top(); if (top_pointer != ptr) { result.at(top_pointer); @@ -4880,7 +4880,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec json_pointer from_ptr(from_path); // the "from" location must exist - use at() - basic_json v = result.at(from_ptr); + basic_json const v = result.at(from_ptr); // The move operation is functionally identical to a // "remove" operation on the "from" location, followed @@ -4897,7 +4897,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec const json_pointer from_ptr(from_path); // the "from" location must exist - use at() - basic_json v = result.at(from_ptr); + basic_json const v = result.at(from_ptr); // The copy is functionally identical to an "add" // operation at the target location using the value diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index 03bdb113e..efac6d2d2 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -2748,7 +2748,7 @@ JSON_HEDLEY_DIAGNOSTIC_POP #define NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(Type, ...) \ friend void to_json(nlohmann::json& nlohmann_json_j, const Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) } \ - friend void from_json(const nlohmann::json& nlohmann_json_j, Type& nlohmann_json_t) { Type nlohmann_json_default_obj; NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_FROM_WITH_DEFAULT, __VA_ARGS__)) } + friend void from_json(const nlohmann::json& nlohmann_json_j, Type& nlohmann_json_t) { const Type nlohmann_json_default_obj{}; NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_FROM_WITH_DEFAULT, __VA_ARGS__)) } /*! @brief macro @@ -2761,7 +2761,7 @@ JSON_HEDLEY_DIAGNOSTIC_POP #define NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(Type, ...) \ inline void to_json(nlohmann::json& nlohmann_json_j, const Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) } \ - inline void from_json(const nlohmann::json& nlohmann_json_j, Type& nlohmann_json_t) { Type nlohmann_json_default_obj; NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_FROM_WITH_DEFAULT, __VA_ARGS__)) } + inline void from_json(const nlohmann::json& nlohmann_json_j, Type& nlohmann_json_t) { const Type nlohmann_json_default_obj{}; NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_FROM_WITH_DEFAULT, __VA_ARGS__)) } // inspired from https://stackoverflow.com/a/26745591 @@ -4414,17 +4414,17 @@ class parse_error : public exception template::value, int> = 0> static parse_error create(int id_, const position_t& pos, const std::string& what_arg, BasicJsonContext context) { - std::string w = concat(exception::name("parse_error", id_), "parse error", - position_string(pos), ": ", exception::diagnostics(context), what_arg); + const std::string w = concat(exception::name("parse_error", id_), "parse error", + position_string(pos), ": ", exception::diagnostics(context), what_arg); return {id_, pos.chars_read_total, w.c_str()}; } template::value, int> = 0> static parse_error create(int id_, std::size_t byte_, const std::string& what_arg, BasicJsonContext context) { - std::string w = concat(exception::name("parse_error", id_), "parse error", - (byte_ != 0 ? (concat(" at byte ", std::to_string(byte_))) : ""), - ": ", exception::diagnostics(context), what_arg); + const std::string w = concat(exception::name("parse_error", id_), "parse error", + (byte_ != 0 ? (concat(" at byte ", std::to_string(byte_))) : ""), + ": ", exception::diagnostics(context), what_arg); return {id_, byte_, w.c_str()}; } @@ -4458,7 +4458,7 @@ class invalid_iterator : public exception template::value, int> = 0> static invalid_iterator create(int id_, const std::string& what_arg, BasicJsonContext context) { - std::string w = concat(exception::name("invalid_iterator", id_), exception::diagnostics(context), what_arg); + const std::string w = concat(exception::name("invalid_iterator", id_), exception::diagnostics(context), what_arg); return {id_, w.c_str()}; } @@ -4476,7 +4476,7 @@ class type_error : public exception template::value, int> = 0> static type_error create(int id_, const std::string& what_arg, BasicJsonContext context) { - std::string w = concat(exception::name("type_error", id_), exception::diagnostics(context), what_arg); + const std::string w = concat(exception::name("type_error", id_), exception::diagnostics(context), what_arg); return {id_, w.c_str()}; } @@ -4493,7 +4493,7 @@ class out_of_range : public exception template::value, int> = 0> static out_of_range create(int id_, const std::string& what_arg, BasicJsonContext context) { - std::string w = concat(exception::name("out_of_range", id_), exception::diagnostics(context), what_arg); + const std::string w = concat(exception::name("out_of_range", id_), exception::diagnostics(context), what_arg); return {id_, w.c_str()}; } @@ -4510,7 +4510,7 @@ class other_error : public exception template::value, int> = 0> static other_error create(int id_, const std::string& what_arg, BasicJsonContext context) { - std::string w = concat(exception::name("other_error", id_), exception::diagnostics(context), what_arg); + const std::string w = concat(exception::name("other_error", id_), exception::diagnostics(context), what_arg); return {id_, w.c_str()}; } @@ -9408,7 +9408,7 @@ class binary_reader { std::array cr{{}}; static_cast((std::snprintf)(cr.data(), cr.size(), "%.2hhX", static_cast(element_type))); // NOLINT(cppcoreguidelines-pro-type-vararg,hicpp-vararg) - std::string cr_str{cr.data()}; + const std::string cr_str{cr.data()}; return sax->parse_error(element_type_parse_position, cr_str, parse_error::create(114, element_type_parse_position, concat("Unsupported BSON record type 0x", cr_str), nullptr)); } @@ -11343,7 +11343,7 @@ class binary_reader exception_message(input_format, concat("expected '#' after type information; last byte: 0x", last_token), "size"), nullptr)); } - bool is_error = get_ubjson_size_value(result.first, is_ndarray); + const bool is_error = get_ubjson_size_value(result.first, is_ndarray); if (input_format == input_format_t::bjdata && is_ndarray) { if (inside_ndarray) @@ -11358,7 +11358,7 @@ class binary_reader if (current == '#') { - bool is_error = get_ubjson_size_value(result.first, is_ndarray); + const bool is_error = get_ubjson_size_value(result.first, is_ndarray); if (input_format == input_format_t::bjdata && is_ndarray) { return sax->parse_error(chars_read, get_token_string(), parse_error::create(112, chars_read, @@ -13949,7 +13949,7 @@ class json_pointer const char* p = s.c_str(); char* p_end = nullptr; errno = 0; // strtoull doesn't reset errno - unsigned long long res = std::strtoull(p, &p_end, 10); // NOLINT(runtime/int) + const unsigned long long res = std::strtoull(p, &p_end, 10); // NOLINT(runtime/int) if (p == p_end // invalid input or empty string || errno == ERANGE // out of range || JSON_HEDLEY_UNLIKELY(static_cast(p_end - p) != s.size())) // incomplete read @@ -15614,18 +15614,18 @@ class binary_writer } else if (N <= (std::numeric_limits::max)()) { - std::uint8_t output_type = use_ext - ? 0xC8 // ext 16 - : 0xC5; // bin 16 + const std::uint8_t output_type = use_ext + ? 0xC8 // ext 16 + : 0xC5; // bin 16 oa->write_character(to_char_type(output_type)); write_number(static_cast(N)); } else if (N <= (std::numeric_limits::max)()) { - std::uint8_t output_type = use_ext - ? 0xC9 // ext 32 - : 0xC6; // bin 32 + const std::uint8_t output_type = use_ext + ? 0xC9 // ext 32 + : 0xC6; // bin 32 oa->write_character(to_char_type(output_type)); write_number(static_cast(N)); @@ -16211,8 +16211,8 @@ class binary_writer */ static std::size_t calc_bson_object_size(const typename BasicJsonType::object_t& value) { - std::size_t document_size = std::accumulate(value.begin(), value.end(), static_cast(0), - [](size_t result, const typename BasicJsonType::object_t::value_type & el) + const std::size_t document_size = std::accumulate(value.begin(), value.end(), static_cast(0), + [](size_t result, const typename BasicJsonType::object_t::value_type & el) { return result += calc_bson_element_size(el.first, el.second); }); @@ -18848,7 +18848,7 @@ class serializer ? (byte & 0x3fu) | (codep << 6u) : (0xFFu >> type) & (byte); - std::size_t index = 256u + static_cast(state) * 16u + static_cast(type); + const std::size_t index = 256u + static_cast(state) * 16u + static_cast(type); JSON_ASSERT(index < 400); state = utf8d[index]; return state; @@ -23934,7 +23934,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec } // make sure the top element of the pointer exists - json_pointer top_pointer = ptr.top(); + json_pointer const top_pointer = ptr.top(); if (top_pointer != ptr) { result.at(top_pointer); @@ -24096,7 +24096,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec json_pointer from_ptr(from_path); // the "from" location must exist - use at() - basic_json v = result.at(from_ptr); + basic_json const v = result.at(from_ptr); // The move operation is functionally identical to a // "remove" operation on the "from" location, followed @@ -24113,7 +24113,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec const json_pointer from_ptr(from_path); // the "from" location must exist - use at() - basic_json v = result.at(from_ptr); + basic_json const v = result.at(from_ptr); // The copy is functionally identical to an "add" // operation at the target location using the value diff --git a/tests/abi/config/custom.cpp b/tests/abi/config/custom.cpp index a004fcca2..87d3aa6ea 100644 --- a/tests/abi/config/custom.cpp +++ b/tests/abi/config/custom.cpp @@ -25,7 +25,7 @@ TEST_CASE("custom namespace") std::string expected = "nlohmann::basic_json"; // fallback for Clang - std::string ns{STRINGIZE(NLOHMANN_JSON_NAMESPACE) "::basic_json"}; + const std::string ns{STRINGIZE(NLOHMANN_JSON_NAMESPACE) "::basic_json"}; CHECK(namespace_name(ns) == expected); } diff --git a/tests/abi/config/default.cpp b/tests/abi/config/default.cpp index 908314acf..51bf0c3bb 100644 --- a/tests/abi/config/default.cpp +++ b/tests/abi/config/default.cpp @@ -33,7 +33,7 @@ TEST_CASE("default namespace") expected += "_" STRINGIZE(NLOHMANN_JSON_VERSION_PATCH) "::basic_json"; // fallback for Clang - std::string ns{STRINGIZE(NLOHMANN_JSON_NAMESPACE) "::basic_json"}; + const std::string ns{STRINGIZE(NLOHMANN_JSON_NAMESPACE) "::basic_json"}; CHECK(namespace_name(ns) == expected); } diff --git a/tests/abi/config/noversion.cpp b/tests/abi/config/noversion.cpp index d4fcb3f46..e6b4f7721 100644 --- a/tests/abi/config/noversion.cpp +++ b/tests/abi/config/noversion.cpp @@ -32,7 +32,7 @@ TEST_CASE("default namespace without version component") expected += "::basic_json"; // fallback for Clang - std::string ns{STRINGIZE(NLOHMANN_JSON_NAMESPACE) "::basic_json"}; + const std::string ns{STRINGIZE(NLOHMANN_JSON_NAMESPACE) "::basic_json"}; CHECK(namespace_name(ns) == expected); } 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/make_test_data_available.hpp b/tests/src/make_test_data_available.hpp index 83b926621..26f2bc146 100644 --- a/tests/src/make_test_data_available.hpp +++ b/tests/src/make_test_data_available.hpp @@ -18,7 +18,7 @@ namespace utils inline bool check_testsuite_downloaded() { - std::unique_ptr file(std::fopen(TEST_DATA_DIRECTORY "/README.md", "r"), &std::fclose); + const std::unique_ptr file(std::fopen(TEST_DATA_DIRECTORY "/README.md", "r"), &std::fclose); return file != nullptr; } diff --git a/tests/src/unit-32bit.cpp b/tests/src/unit-32bit.cpp index 3ff6277e8..d3f9c3ef7 100644 --- a/tests/src/unit-32bit.cpp +++ b/tests/src/unit-32bit.cpp @@ -33,10 +33,10 @@ TEST_CASE_TEMPLATE_DEFINE("value_in_range_of trait", T, value_in_range_of_test) constexpr bool min_in_range = T::min_in_range; constexpr bool max_in_range = T::max_in_range; - type val_min = std::numeric_limits::min(); - type val_min2 = val_min + 1; - type val_max = std::numeric_limits::max(); - type val_max2 = val_max - 1; + type const val_min = std::numeric_limits::min(); + type const val_min2 = val_min + 1; + type const val_max = std::numeric_limits::max(); + 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-allocator.cpp b/tests/src/unit-allocator.cpp index c6b77ed66..76e3b03f1 100644 --- a/tests/src/unit-allocator.cpp +++ b/tests/src/unit-allocator.cpp @@ -159,7 +159,7 @@ TEST_CASE("controlled bad_alloc") SECTION("json_value(const string_t&)") { next_construct_fails = false; - my_json::string_t v("foo"); + const my_json::string_t v("foo"); CHECK_NOTHROW(my_allocator_clean_up(my_json::json_value(v).string)); next_construct_fails = true; CHECK_THROWS_AS(my_json::json_value(v), std::bad_alloc&); @@ -172,7 +172,7 @@ TEST_CASE("controlled bad_alloc") SECTION("basic_json(const CompatibleObjectType&)") { next_construct_fails = false; - std::map v {{"foo", "bar"}}; + const std::map v {{"foo", "bar"}}; CHECK_NOTHROW(my_json(v)); next_construct_fails = true; CHECK_THROWS_AS(my_json(v), std::bad_alloc&); @@ -182,7 +182,7 @@ TEST_CASE("controlled bad_alloc") SECTION("basic_json(const CompatibleArrayType&)") { next_construct_fails = false; - std::vector v {"foo", "bar", "baz"}; + const std::vector v {"foo", "bar", "baz"}; CHECK_NOTHROW(my_json(v)); next_construct_fails = true; CHECK_THROWS_AS(my_json(v), std::bad_alloc&); @@ -201,7 +201,7 @@ TEST_CASE("controlled bad_alloc") SECTION("basic_json(const typename string_t::value_type*)") { next_construct_fails = false; - std::string s("foo"); + const std::string s("foo"); CHECK_NOTHROW(my_json(s)); next_construct_fails = true; CHECK_THROWS_AS(my_json(s), std::bad_alloc&); diff --git a/tests/src/unit-alt-string.cpp b/tests/src/unit-alt-string.cpp index 609b5d159..291c0ad5f 100644 --- a/tests/src/unit-alt-string.cpp +++ b/tests/src/unit-alt-string.cpp @@ -148,7 +148,7 @@ class alt_string alt_string substr(std::size_t pos = 0, std::size_t count = npos) const { - std::string s = str_impl.substr(pos, count); + const std::string s = str_impl.substr(pos, count); return {s.data(), s.size()}; } diff --git a/tests/src/unit-assert_macro.cpp b/tests/src/unit-assert_macro.cpp index 7189119c0..35e99f3d4 100644 --- a/tests/src/unit-assert_macro.cpp +++ b/tests/src/unit-assert_macro.cpp @@ -32,7 +32,7 @@ TEST_CASE("JSON_ASSERT(x)") assert_counter = 0; CHECK(assert_counter == 0); - json::iterator it; + const json::iterator it{}; json j; // in case assertions do not abort execution, an exception is thrown diff --git a/tests/src/unit-binary_formats.cpp b/tests/src/unit-binary_formats.cpp index 463360ad5..ca6a7abfa 100644 --- a/tests/src/unit-binary_formats.cpp +++ b/tests/src/unit-binary_formats.cpp @@ -19,7 +19,7 @@ TEST_CASE("Binary Formats" * doctest::skip()) SECTION("canada.json") { const auto* filename = TEST_DATA_DIRECTORY "/nativejson-benchmark/canada.json"; - json j = json::parse(std::ifstream(filename)); + const json j = json::parse(std::ifstream(filename)); const auto json_size = j.dump().size(); const auto bjdata_1_size = json::to_bjdata(j).size(); @@ -58,7 +58,7 @@ TEST_CASE("Binary Formats" * doctest::skip()) SECTION("twitter.json") { const auto* filename = TEST_DATA_DIRECTORY "/nativejson-benchmark/twitter.json"; - json j = json::parse(std::ifstream(filename)); + const json j = json::parse(std::ifstream(filename)); const auto json_size = j.dump().size(); const auto bjdata_1_size = json::to_bjdata(j).size(); @@ -97,7 +97,7 @@ TEST_CASE("Binary Formats" * doctest::skip()) SECTION("citm_catalog.json") { const auto* filename = TEST_DATA_DIRECTORY "/nativejson-benchmark/citm_catalog.json"; - json j = json::parse(std::ifstream(filename)); + const json j = json::parse(std::ifstream(filename)); const auto json_size = j.dump().size(); const auto bjdata_1_size = json::to_bjdata(j).size(); @@ -175,7 +175,7 @@ TEST_CASE("Binary Formats" * doctest::skip()) SECTION("sample.json") { const auto* filename = TEST_DATA_DIRECTORY "/json_testsuite/sample.json"; - json j = json::parse(std::ifstream(filename)); + const json j = json::parse(std::ifstream(filename)); const auto json_size = j.dump().size(); const auto bjdata_1_size = json::to_bjdata(j).size(); diff --git a/tests/src/unit-bjdata.cpp b/tests/src/unit-bjdata.cpp index 41b78742b..aa27353fe 100644 --- a/tests/src/unit-bjdata.cpp +++ b/tests/src/unit-bjdata.cpp @@ -118,10 +118,10 @@ TEST_CASE_TEMPLATE_DEFINE("value_in_range_of trait", T, value_in_range_of_test) constexpr bool min_in_range = T::min_in_range; constexpr bool max_in_range = T::max_in_range; - type val_min = std::numeric_limits::min(); - type val_min2 = val_min + 1; - type val_max = std::numeric_limits::max(); - type val_max2 = val_max - 1; + type const val_min = std::numeric_limits::min(); + type const val_min2 = val_min + 1; + type const val_max = std::numeric_limits::max(); + type const val_max2 = val_max - 1; REQUIRE(CHAR_BIT == 8); @@ -209,10 +209,10 @@ TEST_CASE("BJData") { SECTION("binary_reader BJData LUT arrays are sorted") { - std::vector data; + std::vector const data; auto ia = nlohmann::detail::input_adapter(data); // NOLINTNEXTLINE(hicpp-move-const-arg,performance-move-const-arg) - nlohmann::detail::binary_reader br{std::move(ia), json::input_format_t::bjdata}; + nlohmann::detail::binary_reader const br{std::move(ia), json::input_format_t::bjdata}; CHECK(std::is_sorted(br.bjd_optimized_type_markers.begin(), br.bjd_optimized_type_markers.end())); CHECK(std::is_sorted(br.bjd_types_map.begin(), br.bjd_types_map.end())); @@ -223,15 +223,15 @@ TEST_CASE("BJData") 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_bjdata(j); CHECK(result.empty()); } SECTION("null") { - json j = nullptr; - std::vector expected = {'Z'}; + json const j = nullptr; + std::vector const expected = {'Z'}; const auto result = json::to_bjdata(j); CHECK(result == expected); @@ -244,8 +244,8 @@ TEST_CASE("BJData") { SECTION("true") { - json j = true; - std::vector expected = {'T'}; + json const j = true; + std::vector const expected = {'T'}; const auto result = json::to_bjdata(j); CHECK(result == expected); @@ -256,8 +256,8 @@ TEST_CASE("BJData") SECTION("false") { - json j = false; - std::vector expected = {'F'}; + json const j = false; + std::vector const expected = {'F'}; const auto result = json::to_bjdata(j); CHECK(result == expected); @@ -273,39 +273,43 @@ TEST_CASE("BJData") { SECTION("-9223372036854775808..-2147483649 (int64)") { - std::vector numbers; - numbers.push_back((std::numeric_limits::min)()); - numbers.push_back(-1000000000000000000LL); - numbers.push_back(-100000000000000000LL); - numbers.push_back(-10000000000000000LL); - numbers.push_back(-1000000000000000LL); - numbers.push_back(-100000000000000LL); - numbers.push_back(-10000000000000LL); - numbers.push_back(-1000000000000LL); - numbers.push_back(-100000000000LL); - numbers.push_back(-10000000000LL); - numbers.push_back(-2147483649LL); - for (auto i : numbers) + std::vector const numbers + { + (std::numeric_limits::min)(), + -1000000000000000000LL, + -100000000000000000LL, + -10000000000000000LL, + -1000000000000000LL, + -100000000000000LL, + -10000000000000LL, + -1000000000000LL, + -100000000000LL, + -10000000000LL, + -2147483649LL, + }; + for (const auto i : numbers) { CAPTURE(i) // create JSON value with integer number - json j = i; + json const j = i; // check type CHECK(j.is_number_integer()); // create expected byte vector - std::vector expected; - expected.push_back(static_cast('L')); - expected.push_back(static_cast(i & 0xff)); - expected.push_back(static_cast((i >> 8) & 0xff)); - expected.push_back(static_cast((i >> 16) & 0xff)); - expected.push_back(static_cast((i >> 24) & 0xff)); - expected.push_back(static_cast((i >> 32) & 0xff)); - expected.push_back(static_cast((i >> 40) & 0xff)); - expected.push_back(static_cast((i >> 48) & 0xff)); - expected.push_back(static_cast((i >> 56) & 0xff)); + std::vector const expected + { + static_cast('L'), + static_cast(i & 0xff), + static_cast((i >> 8) & 0xff), + static_cast((i >> 16) & 0xff), + static_cast((i >> 24) & 0xff), + static_cast((i >> 32) & 0xff), + static_cast((i >> 40) & 0xff), + static_cast((i >> 48) & 0xff), + static_cast((i >> 56) & 0xff), + }; // compare result + size const auto result = json::to_bjdata(j); @@ -314,14 +318,14 @@ TEST_CASE("BJData") // check individual bytes CHECK(result[0] == 'L'); - int64_t restored = (static_cast(result[8]) << 070) + - (static_cast(result[7]) << 060) + - (static_cast(result[6]) << 050) + - (static_cast(result[5]) << 040) + - (static_cast(result[4]) << 030) + - (static_cast(result[3]) << 020) + - (static_cast(result[2]) << 010) + - static_cast(result[1]); + int64_t const restored = (static_cast(result[8]) << 070) + + (static_cast(result[7]) << 060) + + (static_cast(result[6]) << 050) + + (static_cast(result[5]) << 040) + + (static_cast(result[4]) << 030) + + (static_cast(result[3]) << 020) + + (static_cast(result[2]) << 010) + + static_cast(result[1]); CHECK(restored == i); // roundtrip @@ -332,31 +336,35 @@ TEST_CASE("BJData") SECTION("-2147483648..-32769 (int32)") { - std::vector numbers; - numbers.push_back(-32769); - numbers.push_back(-100000); - numbers.push_back(-1000000); - numbers.push_back(-10000000); - numbers.push_back(-100000000); - numbers.push_back(-1000000000); - numbers.push_back(-2147483647 - 1); // https://stackoverflow.com/a/29356002/266378 - for (auto i : numbers) + std::vector const numbers + { + -32769, + -100000, + -1000000, + -10000000, + -100000000, + -1000000000, + -2147483647 - 1, // https://stackoverflow.com/a/29356002/266378 + }; + for (const auto i : numbers) { CAPTURE(i) // create JSON value with integer number - json j = i; + json const j = i; // check type CHECK(j.is_number_integer()); // create expected byte vector - std::vector expected; - expected.push_back(static_cast('l')); - expected.push_back(static_cast(i & 0xff)); - expected.push_back(static_cast((i >> 8) & 0xff)); - expected.push_back(static_cast((i >> 16) & 0xff)); - expected.push_back(static_cast((i >> 24) & 0xff)); + std::vector const expected + { + static_cast('l'), + static_cast(i & 0xff), + static_cast((i >> 8) & 0xff), + static_cast((i >> 16) & 0xff), + static_cast((i >> 24) & 0xff), + }; // compare result + size const auto result = json::to_bjdata(j); @@ -365,10 +373,10 @@ TEST_CASE("BJData") // check individual bytes CHECK(result[0] == 'l'); - int32_t restored = (static_cast(result[4]) << 030) + - (static_cast(result[3]) << 020) + - (static_cast(result[2]) << 010) + - static_cast(result[1]); + int32_t const restored = (static_cast(result[4]) << 030) + + (static_cast(result[3]) << 020) + + (static_cast(result[2]) << 010) + + static_cast(result[1]); CHECK(restored == i); // roundtrip @@ -384,16 +392,18 @@ TEST_CASE("BJData") CAPTURE(i) // create JSON value with integer number - json j = i; + json const j = i; // check type CHECK(j.is_number_integer()); // create expected byte vector - std::vector expected; - expected.push_back(static_cast('I')); - expected.push_back(static_cast(i & 0xff)); - expected.push_back(static_cast((i >> 8) & 0xff)); + std::vector const expected + { + static_cast('I'), + static_cast(i & 0xff), + static_cast((i >> 8) & 0xff), + }; // compare result + size const auto result = json::to_bjdata(j); @@ -402,7 +412,7 @@ TEST_CASE("BJData") // check individual bytes CHECK(result[0] == 'I'); - auto restored = static_cast(((result[2] << 8) + result[1])); + auto const restored = static_cast(((result[2] << 8) + result[1])); CHECK(restored == i); // roundtrip @@ -413,8 +423,8 @@ TEST_CASE("BJData") SECTION("-9263 (int16)") { - json j = -9263; - std::vector expected = {'I', 0xd1, 0xdb}; + json const j = -9263; + std::vector const expected = {'I', 0xd1, 0xdb}; // compare result + size const auto result = json::to_bjdata(j); @@ -423,7 +433,7 @@ TEST_CASE("BJData") // check individual bytes CHECK(result[0] == 'I'); - auto restored = static_cast(((result[2] << 8) + result[1])); + auto const restored = static_cast(((result[2] << 8) + result[1])); CHECK(restored == -9263); // roundtrip @@ -438,15 +448,17 @@ TEST_CASE("BJData") CAPTURE(i) // create JSON value with integer number - json j = i; + json const j = i; // check type CHECK(j.is_number_integer()); // create expected byte vector - std::vector expected; - expected.push_back('i'); - expected.push_back(static_cast(i)); + std::vector const expected + { + 'i', + static_cast(i), + }; // compare result + size const auto result = json::to_bjdata(j); @@ -477,9 +489,11 @@ TEST_CASE("BJData") CHECK(j.is_number_integer()); // create expected byte vector - std::vector expected; - expected.push_back(static_cast('i')); - expected.push_back(static_cast(i)); + std::vector const expected + { + static_cast('i'), + static_cast(i), + }; // compare result + size const auto result = json::to_bjdata(j); @@ -510,9 +524,11 @@ TEST_CASE("BJData") CHECK(j.is_number_integer()); // create expected byte vector - std::vector expected; - expected.push_back(static_cast('U')); - expected.push_back(static_cast(i)); + std::vector const expected + { + static_cast('U'), + static_cast(i), + }; // compare result + size const auto result = json::to_bjdata(j); @@ -543,10 +559,12 @@ TEST_CASE("BJData") CHECK(j.is_number_integer()); // create expected byte vector - std::vector expected; - expected.push_back(static_cast('I')); - expected.push_back(static_cast(i & 0xff)); - expected.push_back(static_cast((i >> 8) & 0xff)); + std::vector const expected + { + static_cast('I'), + static_cast(i & 0xff), + static_cast((i >> 8) & 0xff), + }; // compare result + size const auto result = json::to_bjdata(j); @@ -555,7 +573,7 @@ TEST_CASE("BJData") // check individual bytes CHECK(result[0] == 'I'); - auto restored = static_cast(static_cast(result[2]) * 256 + static_cast(result[1])); + auto const restored = static_cast(static_cast(result[2]) * 256 + static_cast(result[1])); CHECK(restored == i); // roundtrip @@ -566,7 +584,7 @@ TEST_CASE("BJData") SECTION("32768..65535 (uint16)") { - for (uint32_t i : + for (const uint32_t i : { 32768u, 55555u, 65535u }) @@ -581,10 +599,12 @@ TEST_CASE("BJData") CHECK(j.is_number_integer()); // create expected byte vector - std::vector expected; - expected.push_back(static_cast('u')); - expected.push_back(static_cast(i & 0xff)); - expected.push_back(static_cast((i >> 8) & 0xff)); + std::vector const expected + { + static_cast('u'), + static_cast(i & 0xff), + static_cast((i >> 8) & 0xff), + }; // compare result + size const auto result = json::to_bjdata(j); @@ -593,7 +613,7 @@ TEST_CASE("BJData") // check individual bytes CHECK(result[0] == 'u'); - auto restored = static_cast(static_cast(result[2]) * 256 + static_cast(result[1])); + auto const restored = static_cast(static_cast(result[2]) * 256 + static_cast(result[1])); CHECK(restored == i); // roundtrip @@ -604,7 +624,7 @@ TEST_CASE("BJData") SECTION("65536..2147483647 (int32)") { - for (uint32_t i : + for (const uint32_t i : { 65536u, 77777u, 2147483647u }) @@ -619,12 +639,14 @@ TEST_CASE("BJData") CHECK(j.is_number_integer()); // create expected byte vector - std::vector expected; - expected.push_back('l'); - expected.push_back(static_cast(i & 0xff)); - expected.push_back(static_cast((i >> 8) & 0xff)); - expected.push_back(static_cast((i >> 16) & 0xff)); - expected.push_back(static_cast((i >> 24) & 0xff)); + std::vector const expected + { + 'l', + static_cast(i & 0xff), + static_cast((i >> 8) & 0xff), + static_cast((i >> 16) & 0xff), + static_cast((i >> 24) & 0xff), + }; // compare result + size const auto result = json::to_bjdata(j); @@ -633,10 +655,10 @@ TEST_CASE("BJData") // check individual bytes CHECK(result[0] == 'l'); - uint32_t restored = (static_cast(result[4]) << 030) + - (static_cast(result[3]) << 020) + - (static_cast(result[2]) << 010) + - static_cast(result[1]); + uint32_t const restored = (static_cast(result[4]) << 030) + + (static_cast(result[3]) << 020) + + (static_cast(result[2]) << 010) + + static_cast(result[1]); CHECK(restored == i); // roundtrip @@ -647,7 +669,7 @@ TEST_CASE("BJData") SECTION("2147483648..4294967295 (uint32)") { - for (uint32_t i : + for (const uint32_t i : { 2147483648u, 3333333333u, 4294967295u }) @@ -662,12 +684,14 @@ TEST_CASE("BJData") CHECK(j.is_number_integer()); // create expected byte vector - std::vector expected; - expected.push_back('m'); - expected.push_back(static_cast(i & 0xff)); - expected.push_back(static_cast((i >> 8) & 0xff)); - expected.push_back(static_cast((i >> 16) & 0xff)); - expected.push_back(static_cast((i >> 24) & 0xff)); + std::vector const expected + { + 'm', + static_cast(i & 0xff), + static_cast((i >> 8) & 0xff), + static_cast((i >> 16) & 0xff), + static_cast((i >> 24) & 0xff), + }; // compare result + size const auto result = json::to_bjdata(j); @@ -676,10 +700,10 @@ TEST_CASE("BJData") // check individual bytes CHECK(result[0] == 'm'); - uint32_t restored = (static_cast(result[4]) << 030) + - (static_cast(result[3]) << 020) + - (static_cast(result[2]) << 010) + - static_cast(result[1]); + uint32_t const restored = (static_cast(result[4]) << 030) + + (static_cast(result[3]) << 020) + + (static_cast(result[2]) << 010) + + static_cast(result[1]); CHECK(restored == i); // roundtrip @@ -690,8 +714,8 @@ TEST_CASE("BJData") SECTION("4294967296..9223372036854775807 (int64)") { - std::vector v = {4294967296LU, 9223372036854775807LU}; - for (uint64_t i : v) + std::vector const v = {4294967296LU, 9223372036854775807LU}; + for (const uint64_t i : v) { CAPTURE(i) @@ -703,16 +727,18 @@ TEST_CASE("BJData") CHECK(j.is_number_integer()); // create expected byte vector - std::vector expected; - expected.push_back('L'); - expected.push_back(static_cast(i & 0xff)); - expected.push_back(static_cast((i >> 010) & 0xff)); - expected.push_back(static_cast((i >> 020) & 0xff)); - expected.push_back(static_cast((i >> 030) & 0xff)); - expected.push_back(static_cast((i >> 040) & 0xff)); - expected.push_back(static_cast((i >> 050) & 0xff)); - expected.push_back(static_cast((i >> 060) & 0xff)); - expected.push_back(static_cast((i >> 070) & 0xff)); + std::vector const expected + { + 'L', + static_cast(i & 0xff), + static_cast((i >> 010) & 0xff), + static_cast((i >> 020) & 0xff), + static_cast((i >> 030) & 0xff), + static_cast((i >> 040) & 0xff), + static_cast((i >> 050) & 0xff), + static_cast((i >> 060) & 0xff), + static_cast((i >> 070) & 0xff), + }; // compare result + size const auto result = json::to_bjdata(j); @@ -721,14 +747,14 @@ TEST_CASE("BJData") // check individual bytes CHECK(result[0] == 'L'); - uint64_t restored = (static_cast(result[8]) << 070) + - (static_cast(result[7]) << 060) + - (static_cast(result[6]) << 050) + - (static_cast(result[5]) << 040) + - (static_cast(result[4]) << 030) + - (static_cast(result[3]) << 020) + - (static_cast(result[2]) << 010) + - static_cast(result[1]); + uint64_t const restored = (static_cast(result[8]) << 070) + + (static_cast(result[7]) << 060) + + (static_cast(result[6]) << 050) + + (static_cast(result[5]) << 040) + + (static_cast(result[4]) << 030) + + (static_cast(result[3]) << 020) + + (static_cast(result[2]) << 010) + + static_cast(result[1]); CHECK(restored == i); // roundtrip @@ -739,28 +765,30 @@ TEST_CASE("BJData") SECTION("9223372036854775808..18446744073709551615 (uint64)") { - std::vector v = {9223372036854775808ull, 18446744073709551615ull}; - for (uint64_t i : v) + std::vector const v = {9223372036854775808ull, 18446744073709551615ull}; + for (const uint64_t i : v) { CAPTURE(i) // create JSON value with integer number - json j = i; + json const j = i; // check type CHECK(j.is_number_unsigned()); // create expected byte vector - std::vector expected; - expected.push_back('M'); - expected.push_back(static_cast(i & 0xff)); - expected.push_back(static_cast((i >> 010) & 0xff)); - expected.push_back(static_cast((i >> 020) & 0xff)); - expected.push_back(static_cast((i >> 030) & 0xff)); - expected.push_back(static_cast((i >> 040) & 0xff)); - expected.push_back(static_cast((i >> 050) & 0xff)); - expected.push_back(static_cast((i >> 060) & 0xff)); - expected.push_back(static_cast((i >> 070) & 0xff)); + std::vector const expected + { + 'M', + static_cast(i & 0xff), + static_cast((i >> 010) & 0xff), + static_cast((i >> 020) & 0xff), + static_cast((i >> 030) & 0xff), + static_cast((i >> 040) & 0xff), + static_cast((i >> 050) & 0xff), + static_cast((i >> 060) & 0xff), + static_cast((i >> 070) & 0xff), + }; // compare result + size const auto result = json::to_bjdata(j); @@ -769,14 +797,14 @@ TEST_CASE("BJData") // check individual bytes CHECK(result[0] == 'M'); - uint64_t restored = (static_cast(result[8]) << 070) + - (static_cast(result[7]) << 060) + - (static_cast(result[6]) << 050) + - (static_cast(result[5]) << 040) + - (static_cast(result[4]) << 030) + - (static_cast(result[3]) << 020) + - (static_cast(result[2]) << 010) + - static_cast(result[1]); + uint64_t const restored = (static_cast(result[8]) << 070) + + (static_cast(result[7]) << 060) + + (static_cast(result[6]) << 050) + + (static_cast(result[5]) << 040) + + (static_cast(result[4]) << 030) + + (static_cast(result[3]) << 020) + + (static_cast(result[2]) << 010) + + static_cast(result[1]); CHECK(restored == i); // roundtrip @@ -795,15 +823,13 @@ TEST_CASE("BJData") CAPTURE(i) // create JSON value with unsigned integer number - json j = i; + json const j = i; // check type CHECK(j.is_number_unsigned()); // create expected byte vector - std::vector expected; - expected.push_back('i'); - expected.push_back(static_cast(i)); + std::vector const expected{'i', static_cast(i)}; // compare result + size const auto result = json::to_bjdata(j); @@ -812,7 +838,7 @@ TEST_CASE("BJData") // check individual bytes CHECK(result[0] == 'i'); - auto restored = static_cast(result[1]); + auto const restored = static_cast(result[1]); CHECK(restored == i); // roundtrip @@ -828,15 +854,13 @@ TEST_CASE("BJData") CAPTURE(i) // create JSON value with unsigned integer number - json j = i; + json const j = i; // check type CHECK(j.is_number_unsigned()); // create expected byte vector - std::vector expected; - expected.push_back('U'); - expected.push_back(static_cast(i)); + std::vector const expected{'U', static_cast(i)}; // compare result + size const auto result = json::to_bjdata(j); @@ -845,7 +869,7 @@ TEST_CASE("BJData") // check individual bytes CHECK(result[0] == 'U'); - auto restored = static_cast(result[1]); + auto const restored = static_cast(result[1]); CHECK(restored == i); // roundtrip @@ -861,16 +885,18 @@ TEST_CASE("BJData") CAPTURE(i) // create JSON value with unsigned integer number - json j = i; + json const j = i; // check type CHECK(j.is_number_unsigned()); // create expected byte vector - std::vector expected; - expected.push_back('I'); - expected.push_back(static_cast(i & 0xff)); - expected.push_back(static_cast((i >> 8) & 0xff)); + std::vector const expected + { + 'I', + static_cast(i & 0xff), + static_cast((i >> 8) & 0xff), + }; // compare result + size const auto result = json::to_bjdata(j); @@ -879,7 +905,7 @@ TEST_CASE("BJData") // check individual bytes CHECK(result[0] == 'I'); - auto restored = static_cast(static_cast(result[2]) * 256 + static_cast(result[1])); + auto const restored = static_cast(static_cast(result[2]) * 256 + static_cast(result[1])); CHECK(restored == i); // roundtrip @@ -890,7 +916,7 @@ TEST_CASE("BJData") SECTION("32768..65535 (uint16)") { - for (uint32_t i : + for (const uint32_t i : { 32768u, 55555u, 65535u }) @@ -898,16 +924,18 @@ TEST_CASE("BJData") CAPTURE(i) // create JSON value with unsigned integer number - json j = i; + json const j = i; // check type CHECK(j.is_number_unsigned()); // create expected byte vector - std::vector expected; - expected.push_back('u'); - expected.push_back(static_cast(i & 0xff)); - expected.push_back(static_cast((i >> 8) & 0xff)); + std::vector const expected + { + 'u', + static_cast(i & 0xff), + static_cast((i >> 8) & 0xff), + }; // compare result + size const auto result = json::to_bjdata(j); @@ -916,7 +944,7 @@ TEST_CASE("BJData") // check individual bytes CHECK(result[0] == 'u'); - auto restored = static_cast(static_cast(result[2]) * 256 + static_cast(result[1])); + auto const restored = static_cast(static_cast(result[2]) * 256 + static_cast(result[1])); CHECK(restored == i); // roundtrip @@ -926,7 +954,7 @@ TEST_CASE("BJData") } SECTION("65536..2147483647 (int32)") { - for (uint32_t i : + for (const uint32_t i : { 65536u, 77777u, 2147483647u }) @@ -934,18 +962,20 @@ TEST_CASE("BJData") CAPTURE(i) // create JSON value with unsigned integer number - json j = i; + json const j = i; // check type CHECK(j.is_number_unsigned()); // create expected byte vector - std::vector expected; - expected.push_back('l'); - expected.push_back(static_cast(i & 0xff)); - expected.push_back(static_cast((i >> 8) & 0xff)); - expected.push_back(static_cast((i >> 16) & 0xff)); - expected.push_back(static_cast((i >> 24) & 0xff)); + std::vector const expected + { + 'l', + static_cast(i & 0xff), + static_cast((i >> 8) & 0xff), + static_cast((i >> 16) & 0xff), + static_cast((i >> 24) & 0xff), + }; // compare result + size const auto result = json::to_bjdata(j); @@ -954,10 +984,10 @@ TEST_CASE("BJData") // check individual bytes CHECK(result[0] == 'l'); - uint32_t restored = (static_cast(result[4]) << 030) + - (static_cast(result[3]) << 020) + - (static_cast(result[2]) << 010) + - static_cast(result[1]); + uint32_t const restored = (static_cast(result[4]) << 030) + + (static_cast(result[3]) << 020) + + (static_cast(result[2]) << 010) + + static_cast(result[1]); CHECK(restored == i); // roundtrip @@ -968,7 +998,7 @@ TEST_CASE("BJData") SECTION("2147483648..4294967295 (uint32)") { - for (uint32_t i : + for (const uint32_t i : { 2147483648u, 3333333333u, 4294967295u }) @@ -976,18 +1006,20 @@ TEST_CASE("BJData") CAPTURE(i) // create JSON value with unsigned integer number - json j = i; + json const j = i; // check type CHECK(j.is_number_unsigned()); // create expected byte vector - std::vector expected; - expected.push_back('m'); - expected.push_back(static_cast(i & 0xff)); - expected.push_back(static_cast((i >> 8) & 0xff)); - expected.push_back(static_cast((i >> 16) & 0xff)); - expected.push_back(static_cast((i >> 24) & 0xff)); + std::vector const expected + { + 'm', + static_cast(i & 0xff), + static_cast((i >> 8) & 0xff), + static_cast((i >> 16) & 0xff), + static_cast((i >> 24) & 0xff), + }; // compare result + size const auto result = json::to_bjdata(j); @@ -996,10 +1028,10 @@ TEST_CASE("BJData") // check individual bytes CHECK(result[0] == 'm'); - uint32_t restored = (static_cast(result[4]) << 030) + - (static_cast(result[3]) << 020) + - (static_cast(result[2]) << 010) + - static_cast(result[1]); + uint32_t const restored = (static_cast(result[4]) << 030) + + (static_cast(result[3]) << 020) + + (static_cast(result[2]) << 010) + + static_cast(result[1]); CHECK(restored == i); // roundtrip @@ -1010,28 +1042,30 @@ TEST_CASE("BJData") SECTION("4294967296..9223372036854775807 (int64)") { - std::vector v = {4294967296ul, 9223372036854775807ul}; - for (uint64_t i : v) + std::vector const v = {4294967296ul, 9223372036854775807ul}; + for (const uint64_t i : v) { CAPTURE(i) // create JSON value with integer number - json j = i; + json const j = i; // check type CHECK(j.is_number_unsigned()); // create expected byte vector - std::vector expected; - expected.push_back('L'); - expected.push_back(static_cast(i & 0xff)); - expected.push_back(static_cast((i >> 010) & 0xff)); - expected.push_back(static_cast((i >> 020) & 0xff)); - expected.push_back(static_cast((i >> 030) & 0xff)); - expected.push_back(static_cast((i >> 040) & 0xff)); - expected.push_back(static_cast((i >> 050) & 0xff)); - expected.push_back(static_cast((i >> 060) & 0xff)); - expected.push_back(static_cast((i >> 070) & 0xff)); + std::vector const expected + { + 'L', + static_cast(i & 0xff), + static_cast((i >> 010) & 0xff), + static_cast((i >> 020) & 0xff), + static_cast((i >> 030) & 0xff), + static_cast((i >> 040) & 0xff), + static_cast((i >> 050) & 0xff), + static_cast((i >> 060) & 0xff), + static_cast((i >> 070) & 0xff), + }; // compare result + size const auto result = json::to_bjdata(j); @@ -1040,14 +1074,14 @@ TEST_CASE("BJData") // check individual bytes CHECK(result[0] == 'L'); - uint64_t restored = (static_cast(result[8]) << 070) + - (static_cast(result[7]) << 060) + - (static_cast(result[6]) << 050) + - (static_cast(result[5]) << 040) + - (static_cast(result[4]) << 030) + - (static_cast(result[3]) << 020) + - (static_cast(result[2]) << 010) + - static_cast(result[1]); + uint64_t const restored = (static_cast(result[8]) << 070) + + (static_cast(result[7]) << 060) + + (static_cast(result[6]) << 050) + + (static_cast(result[5]) << 040) + + (static_cast(result[4]) << 030) + + (static_cast(result[3]) << 020) + + (static_cast(result[2]) << 010) + + static_cast(result[1]); CHECK(restored == i); // roundtrip @@ -1058,28 +1092,30 @@ TEST_CASE("BJData") SECTION("9223372036854775808..18446744073709551615 (uint64)") { - std::vector v = {9223372036854775808ull, 18446744073709551615ull}; - for (uint64_t i : v) + std::vector const v = {9223372036854775808ull, 18446744073709551615ull}; + for (const uint64_t i : v) { CAPTURE(i) // create JSON value with integer number - json j = i; + json const j = i; // check type CHECK(j.is_number_unsigned()); // create expected byte vector - std::vector expected; - expected.push_back('M'); - expected.push_back(static_cast(i & 0xff)); - expected.push_back(static_cast((i >> 010) & 0xff)); - expected.push_back(static_cast((i >> 020) & 0xff)); - expected.push_back(static_cast((i >> 030) & 0xff)); - expected.push_back(static_cast((i >> 040) & 0xff)); - expected.push_back(static_cast((i >> 050) & 0xff)); - expected.push_back(static_cast((i >> 060) & 0xff)); - expected.push_back(static_cast((i >> 070) & 0xff)); + std::vector const expected + { + 'M', + static_cast(i & 0xff), + static_cast((i >> 010) & 0xff), + static_cast((i >> 020) & 0xff), + static_cast((i >> 030) & 0xff), + static_cast((i >> 040) & 0xff), + static_cast((i >> 050) & 0xff), + static_cast((i >> 060) & 0xff), + static_cast((i >> 070) & 0xff), + }; // compare result + size const auto result = json::to_bjdata(j); @@ -1088,14 +1124,14 @@ TEST_CASE("BJData") // check individual bytes CHECK(result[0] == 'M'); - uint64_t restored = (static_cast(result[8]) << 070) + - (static_cast(result[7]) << 060) + - (static_cast(result[6]) << 050) + - (static_cast(result[5]) << 040) + - (static_cast(result[4]) << 030) + - (static_cast(result[3]) << 020) + - (static_cast(result[2]) << 010) + - static_cast(result[1]); + uint64_t const restored = (static_cast(result[8]) << 070) + + (static_cast(result[7]) << 060) + + (static_cast(result[6]) << 050) + + (static_cast(result[5]) << 040) + + (static_cast(result[4]) << 030) + + (static_cast(result[3]) << 020) + + (static_cast(result[2]) << 010) + + static_cast(result[1]); CHECK(restored == i); // roundtrip @@ -1109,8 +1145,8 @@ TEST_CASE("BJData") SECTION("3.1415925") { double v = 3.1415925; - json j = v; - std::vector expected = + json const j = v; + std::vector const expected = { 'D', 0xfc, 0xde, 0xa6, 0x3f, 0xfb, 0x21, 0x09, 0x40 }; @@ -1140,7 +1176,7 @@ TEST_CASE("BJData") SECTION("no byte follows") { json _; - std::vector vec0 = {'h'}; + std::vector const vec0 = {'h'}; CHECK_THROWS_WITH_AS(_ = json::from_bjdata(vec0), "[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing BJData number: unexpected end of input", json::parse_error&); CHECK(json::from_bjdata(vec0, true, false).is_discarded()); } @@ -1148,7 +1184,7 @@ TEST_CASE("BJData") SECTION("only one byte follows") { json _; - std::vector vec1 = {'h', 0x00}; + std::vector const vec1 = {'h', 0x00}; CHECK_THROWS_WITH_AS(_ = json::from_bjdata(vec1), "[json.exception.parse_error.110] parse error at byte 3: syntax error while parsing BJData number: unexpected end of input", json::parse_error&); CHECK(json::from_bjdata(vec1, true, false).is_discarded()); } @@ -1161,21 +1197,21 @@ TEST_CASE("BJData") { SECTION("0 (0 00000 0000000000)") { - json j = json::from_bjdata(std::vector({'h', 0x00, 0x00})); + json const j = json::from_bjdata(std::vector({'h', 0x00, 0x00})); json::number_float_t d{j}; CHECK(d == 0.0); } SECTION("-0 (1 00000 0000000000)") { - json j = json::from_bjdata(std::vector({'h', 0x00, 0x80})); + json const j = json::from_bjdata(std::vector({'h', 0x00, 0x80})); json::number_float_t d{j}; CHECK(d == -0.0); } SECTION("2**-24 (0 00000 0000000001)") { - json j = json::from_bjdata(std::vector({'h', 0x01, 0x00})); + json const j = json::from_bjdata(std::vector({'h', 0x01, 0x00})); json::number_float_t d{j}; CHECK(d == std::pow(2.0, -24.0)); } @@ -1185,7 +1221,7 @@ TEST_CASE("BJData") { SECTION("infinity (0 11111 0000000000)") { - json j = json::from_bjdata(std::vector({'h', 0x00, 0x7c})); + json const j = json::from_bjdata(std::vector({'h', 0x00, 0x7c})); json::number_float_t d{j}; CHECK(d == std::numeric_limits::infinity()); CHECK(j.dump() == "null"); @@ -1193,7 +1229,7 @@ TEST_CASE("BJData") SECTION("-infinity (1 11111 0000000000)") { - json j = json::from_bjdata(std::vector({'h', 0x00, 0xfc})); + json const j = json::from_bjdata(std::vector({'h', 0x00, 0xfc})); json::number_float_t d{j}; CHECK(d == -std::numeric_limits::infinity()); CHECK(j.dump() == "null"); @@ -1204,21 +1240,21 @@ TEST_CASE("BJData") { SECTION("1 (0 01111 0000000000)") { - json j = json::from_bjdata(std::vector({'h', 0x00, 0x3c})); + json const j = json::from_bjdata(std::vector({'h', 0x00, 0x3c})); json::number_float_t d{j}; CHECK(d == 1); } SECTION("-2 (1 10000 0000000000)") { - json j = json::from_bjdata(std::vector({'h', 0x00, 0xc0})); + json const j = json::from_bjdata(std::vector({'h', 0x00, 0xc0})); json::number_float_t d{j}; CHECK(d == -2); } SECTION("65504 (0 11110 1111111111)") { - json j = json::from_bjdata(std::vector({'h', 0xff, 0x7b})); + json const j = json::from_bjdata(std::vector({'h', 0xff, 0x7b})); json::number_float_t d{j}; CHECK(d == 65504); } @@ -1226,16 +1262,16 @@ TEST_CASE("BJData") SECTION("infinity") { - json j = json::from_bjdata(std::vector({'h', 0x00, 0x7c})); - json::number_float_t d{j}; + json const j = json::from_bjdata(std::vector({'h', 0x00, 0x7c})); + json::number_float_t const d{j}; CHECK_FALSE(std::isfinite(d)); CHECK(j.dump() == "null"); } SECTION("NaN") { - json j = json::from_bjdata(std::vector({'h', 0x00, 0x7e })); - json::number_float_t d{j}; + json const j = json::from_bjdata(std::vector({'h', 0x00, 0x7e })); + json::number_float_t const d{j}; CHECK(std::isnan(d)); CHECK(j.dump() == "null"); } @@ -1245,7 +1281,7 @@ TEST_CASE("BJData") { SECTION("unsigned integer number") { - std::vector vec = {'H', 'i', 0x14, '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0'}; + std::vector const vec = {'H', 'i', 0x14, '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0'}; const auto j = json::from_bjdata(vec); CHECK(j.is_number_unsigned()); CHECK(j.dump() == "12345678901234567890"); @@ -1253,7 +1289,7 @@ TEST_CASE("BJData") SECTION("signed integer number") { - std::vector vec = {'H', 'i', 0x13, '-', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '1', '2', '3', '4', '5', '6', '7', '8'}; + std::vector const vec = {'H', 'i', 0x13, '-', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '1', '2', '3', '4', '5', '6', '7', '8'}; const auto j = json::from_bjdata(vec); CHECK(j.is_number_integer()); CHECK(j.dump() == "-123456789012345678"); @@ -1261,7 +1297,7 @@ TEST_CASE("BJData") SECTION("floating-point number") { - std::vector vec = {'H', 'i', 0x16, '3', '.', '1', '4', '1', '5', '9', '2', '6', '5', '3', '5', '8', '9', '7', '9', '3', '2', '3', '8', '4', '6'}; + std::vector const vec = {'H', 'i', 0x16, '3', '.', '1', '4', '1', '5', '9', '2', '6', '5', '3', '5', '8', '9', '7', '9', '3', '2', '3', '8', '4', '6'}; const auto j = json::from_bjdata(vec); CHECK(j.is_number_float()); CHECK(j.dump() == "3.141592653589793"); @@ -1270,18 +1306,18 @@ TEST_CASE("BJData") SECTION("errors") { // error while parsing length - std::vector vec0 = {'H', 'i'}; + std::vector const vec0 = {'H', 'i'}; CHECK(json::from_bjdata(vec0, true, false).is_discarded()); // error while parsing string - std::vector vec1 = {'H', 'i', '1'}; + std::vector const vec1 = {'H', 'i', '1'}; CHECK(json::from_bjdata(vec1, true, false).is_discarded()); json _; - std::vector vec2 = {'H', 'i', 2, '1', 'A', '3'}; + std::vector const vec2 = {'H', 'i', 2, '1', 'A', '3'}; CHECK_THROWS_WITH_AS(_ = json::from_bjdata(vec2), "[json.exception.parse_error.115] parse error at byte 5: syntax error while parsing BJData high-precision number: invalid number text: 1A", json::parse_error); - std::vector vec3 = {'H', 'i', 2, '1', '.'}; + std::vector const vec3 = {'H', 'i', 2, '1', '.'}; CHECK_THROWS_WITH_AS(_ = json::from_bjdata(vec3), "[json.exception.parse_error.115] parse error at byte 5: syntax error while parsing BJData high-precision number: invalid number text: 1.", json::parse_error); - std::vector vec4 = {'H', 2, '1', '0'}; + std::vector const vec4 = {'H', 2, '1', '0'}; CHECK_THROWS_WITH_AS(_ = json::from_bjdata(vec4), "[json.exception.parse_error.113] parse error at byte 2: syntax error while parsing BJData size: expected length type specification (U, i, u, I, m, l, M, L) after '#'; last byte: 0x02", json::parse_error); } } @@ -1297,7 +1333,7 @@ TEST_CASE("BJData") // create JSON value with string containing of N * 'x' const auto s = std::string(N, 'x'); - json j = s; + json const j = s; // create expected byte vector std::vector expected; @@ -1333,7 +1369,7 @@ TEST_CASE("BJData") // create JSON value with string containing of N * 'x' const auto s = std::string(N, 'x'); - json j = s; + json const j = s; // create expected byte vector std::vector expected; @@ -1360,7 +1396,7 @@ TEST_CASE("BJData") SECTION("N = 256..32767") { - for (size_t N : + for (const size_t N : { 256u, 999u, 1025u, 3333u, 2048u, 32767u }) @@ -1369,7 +1405,7 @@ TEST_CASE("BJData") // create JSON value with string containing of N * 'x' const auto s = std::string(N, 'x'); - json j = s; + json const j = s; // create expected byte vector (hack: create string first) std::vector expected(N, 'x'); @@ -1394,7 +1430,7 @@ TEST_CASE("BJData") SECTION("N = 32768..65535") { - for (size_t N : + for (const size_t N : { 32768u, 55555u, 65535u }) @@ -1403,7 +1439,7 @@ TEST_CASE("BJData") // create JSON value with string containing of N * 'x' const auto s = std::string(N, 'x'); - json j = s; + json const j = s; // create expected byte vector (hack: create string first) std::vector expected(N, 'x'); @@ -1428,7 +1464,7 @@ TEST_CASE("BJData") SECTION("N = 65536..2147483647") { - for (size_t N : + for (const size_t N : { 65536u, 77777u, 1048576u }) @@ -1437,7 +1473,7 @@ TEST_CASE("BJData") // create JSON value with string containing of N * 'x' const auto s = std::string(N, 'x'); - json j = s; + json const j = s; // create expected byte vector (hack: create string first) std::vector expected(N, 'x'); @@ -1474,7 +1510,7 @@ TEST_CASE("BJData") // create JSON value with byte array containing of N * 'x' const auto s = std::vector(N, 'x'); - json j = json::binary(s); + json const j = json::binary(s); // create expected byte vector std::vector expected; @@ -1525,7 +1561,7 @@ TEST_CASE("BJData") // create JSON value with byte array containing of N * 'x' const auto s = std::vector(N, 'x'); - json j = json::binary(s); + json const j = json::binary(s); // create expected byte vector std::vector expected; @@ -1556,7 +1592,7 @@ TEST_CASE("BJData") SECTION("N = 256..32767") { - for (std::size_t N : + for (const std::size_t N : { 256u, 999u, 1025u, 3333u, 2048u, 32767u }) @@ -1565,7 +1601,7 @@ TEST_CASE("BJData") // create JSON value with byte array containing of N * 'x' const auto s = std::vector(N, 'x'); - json j = json::binary(s); + json const j = json::binary(s); // create expected byte vector std::vector expected(N + 7, 'x'); @@ -1593,7 +1629,7 @@ TEST_CASE("BJData") SECTION("N = 32768..65535") { - for (std::size_t N : + for (const std::size_t N : { 32768u, 55555u, 65535u }) @@ -1602,7 +1638,7 @@ TEST_CASE("BJData") // create JSON value with byte array containing of N * 'x' const auto s = std::vector(N, 'x'); - json j = json::binary(s); + json const j = json::binary(s); // create expected byte vector std::vector expected(N + 7, 'x'); @@ -1630,7 +1666,7 @@ TEST_CASE("BJData") SECTION("N = 65536..2147483647") { - for (std::size_t N : + for (const std::size_t N : { 65536u, 77777u, 1048576u }) @@ -1639,7 +1675,7 @@ TEST_CASE("BJData") // create JSON value with byte array containing of N * 'x' const auto s = std::vector(N, 'x'); - json j = json::binary(s); + json const j = json::binary(s); // create expected byte vector std::vector expected(N + 9, 'x'); @@ -1671,7 +1707,7 @@ TEST_CASE("BJData") { const std::size_t N = 10; const auto s = std::vector(N, 'x'); - json j = json::binary(s); + json const j = json::binary(s); SECTION("No Count No Type") { @@ -1731,8 +1767,8 @@ TEST_CASE("BJData") { SECTION("size=false type=false") { - json j = json::array(); - std::vector expected = {'[', ']'}; + json const j = json::array(); + std::vector const expected = {'[', ']'}; const auto result = json::to_bjdata(j); CHECK(result == expected); @@ -1743,8 +1779,8 @@ TEST_CASE("BJData") SECTION("size=true type=false") { - json j = json::array(); - std::vector expected = {'[', '#', 'i', 0}; + json const j = json::array(); + std::vector const expected = {'[', '#', 'i', 0}; const auto result = json::to_bjdata(j, true); CHECK(result == expected); @@ -1755,8 +1791,8 @@ TEST_CASE("BJData") SECTION("size=true type=true") { - json j = json::array(); - std::vector expected = {'[', '#', 'i', 0}; + json const j = json::array(); + std::vector const expected = {'[', '#', 'i', 0}; const auto result = json::to_bjdata(j, true, true); CHECK(result == expected); @@ -1770,8 +1806,8 @@ TEST_CASE("BJData") { SECTION("size=false type=false") { - json j = {nullptr}; - std::vector expected = {'[', 'Z', ']'}; + json const j = {nullptr}; + std::vector const expected = {'[', 'Z', ']'}; const auto result = json::to_bjdata(j); CHECK(result == expected); @@ -1782,8 +1818,8 @@ TEST_CASE("BJData") SECTION("size=true type=false") { - json j = {nullptr}; - std::vector expected = {'[', '#', 'i', 1, 'Z'}; + json const j = {nullptr}; + std::vector const expected = {'[', '#', 'i', 1, 'Z'}; const auto result = json::to_bjdata(j, true); CHECK(result == expected); @@ -1794,8 +1830,8 @@ TEST_CASE("BJData") SECTION("size=true type=true") { - json j = {nullptr}; - std::vector expected = {'[', '#', 'i', 1, 'Z'}; + json const j = {nullptr}; + std::vector const expected = {'[', '#', 'i', 1, 'Z'}; const auto result = json::to_bjdata(j, true, true); CHECK(result == expected); @@ -1809,8 +1845,8 @@ TEST_CASE("BJData") { SECTION("size=false type=false") { - json j = json::parse("[1,2,3,4,5]"); - std::vector expected = {'[', 'i', 1, 'i', 2, 'i', 3, 'i', 4, 'i', 5, ']'}; + json const j = json::parse("[1,2,3,4,5]"); + std::vector const expected = {'[', 'i', 1, 'i', 2, 'i', 3, 'i', 4, 'i', 5, ']'}; const auto result = json::to_bjdata(j); CHECK(result == expected); @@ -1821,8 +1857,8 @@ TEST_CASE("BJData") SECTION("size=true type=false") { - json j = json::parse("[1,2,3,4,5]"); - std::vector expected = {'[', '#', 'i', 5, 'i', 1, 'i', 2, 'i', 3, 'i', 4, 'i', 5}; + json const j = json::parse("[1,2,3,4,5]"); + std::vector const expected = {'[', '#', 'i', 5, 'i', 1, 'i', 2, 'i', 3, 'i', 4, 'i', 5}; const auto result = json::to_bjdata(j, true); CHECK(result == expected); @@ -1833,8 +1869,8 @@ TEST_CASE("BJData") SECTION("size=true type=true") { - json j = json::parse("[1,2,3,4,5]"); - std::vector expected = {'[', '$', 'i', '#', 'i', 5, 1, 2, 3, 4, 5}; + json const j = json::parse("[1,2,3,4,5]"); + std::vector const expected = {'[', '$', 'i', '#', 'i', 5, 1, 2, 3, 4, 5}; const auto result = json::to_bjdata(j, true, true); CHECK(result == expected); @@ -1848,8 +1884,8 @@ TEST_CASE("BJData") { SECTION("size=false type=false") { - json j = json::parse("[[[[]]]]"); - std::vector expected = {'[', '[', '[', '[', ']', ']', ']', ']'}; + json const j = json::parse("[[[[]]]]"); + std::vector const expected = {'[', '[', '[', '[', ']', ']', ']', ']'}; const auto result = json::to_bjdata(j); CHECK(result == expected); @@ -1860,8 +1896,8 @@ TEST_CASE("BJData") SECTION("size=true type=false") { - json j = json::parse("[[[[]]]]"); - std::vector expected = {'[', '#', 'i', 1, '[', '#', 'i', 1, '[', '#', 'i', 1, '[', '#', 'i', 0}; + json const j = json::parse("[[[[]]]]"); + std::vector const expected = {'[', '#', 'i', 1, '[', '#', 'i', 1, '[', '#', 'i', 1, '[', '#', 'i', 0}; const auto result = json::to_bjdata(j, true); CHECK(result == expected); @@ -1872,8 +1908,8 @@ TEST_CASE("BJData") SECTION("size=true type=true") { - json j = json::parse("[[[[]]]]"); - std::vector expected = {'[', '#', 'i', 1, '[', '#', 'i', 1, '[', '#', 'i', 1, '[', '#', 'i', 0}; + json const j = json::parse("[[[[]]]]"); + std::vector const expected = {'[', '#', 'i', 1, '[', '#', 'i', 1, '[', '#', 'i', 1, '[', '#', 'i', 0}; const auto result = json::to_bjdata(j, true, true); CHECK(result == expected); @@ -1994,8 +2030,8 @@ TEST_CASE("BJData") { SECTION("size=false type=false") { - json j = json::object(); - std::vector expected = {'{', '}'}; + json const j = json::object(); + std::vector const expected = {'{', '}'}; const auto result = json::to_bjdata(j); CHECK(result == expected); @@ -2006,8 +2042,8 @@ TEST_CASE("BJData") SECTION("size=true type=false") { - json j = json::object(); - std::vector expected = {'{', '#', 'i', 0}; + json const j = json::object(); + std::vector const expected = {'{', '#', 'i', 0}; const auto result = json::to_bjdata(j, true); CHECK(result == expected); @@ -2018,8 +2054,8 @@ TEST_CASE("BJData") SECTION("size=true type=true") { - json j = json::object(); - std::vector expected = {'{', '#', 'i', 0}; + json const j = json::object(); + std::vector const expected = {'{', '#', 'i', 0}; const auto result = json::to_bjdata(j, true, true); CHECK(result == expected); @@ -2033,8 +2069,8 @@ TEST_CASE("BJData") { SECTION("size=false type=false") { - json j = {{"", nullptr}}; - std::vector expected = {'{', 'i', 0, 'Z', '}'}; + json const j = {{"", nullptr}}; + std::vector const expected = {'{', 'i', 0, 'Z', '}'}; const auto result = json::to_bjdata(j); CHECK(result == expected); @@ -2045,8 +2081,8 @@ TEST_CASE("BJData") SECTION("size=true type=false") { - json j = {{"", nullptr}}; - std::vector expected = {'{', '#', 'i', 1, 'i', 0, 'Z'}; + json const j = {{"", nullptr}}; + std::vector const expected = {'{', '#', 'i', 1, 'i', 0, 'Z'}; const auto result = json::to_bjdata(j, true); CHECK(result == expected); @@ -2060,8 +2096,8 @@ TEST_CASE("BJData") { SECTION("size=false type=false") { - json j = json::parse(R"({"a": {"b": {"c": {}}}})"); - std::vector expected = + json const j = json::parse(R"({"a": {"b": {"c": {}}}})"); + std::vector const expected = { '{', 'i', 1, 'a', '{', 'i', 1, 'b', '{', 'i', 1, 'c', '{', '}', '}', '}', '}' }; @@ -2075,8 +2111,8 @@ TEST_CASE("BJData") SECTION("size=true type=false") { - json j = json::parse(R"({"a": {"b": {"c": {}}}})"); - std::vector expected = + json const j = json::parse(R"({"a": {"b": {"c": {}}}})"); + std::vector const expected = { '{', '#', 'i', 1, 'i', 1, 'a', '{', '#', 'i', 1, 'i', 1, 'b', '{', '#', 'i', 1, 'i', 1, 'c', '{', '#', 'i', 0 }; @@ -2090,8 +2126,8 @@ TEST_CASE("BJData") SECTION("size=true type=true ignore object type marker") { - json j = json::parse(R"({"a": {"b": {"c": {}}}})"); - std::vector expected = + json const j = json::parse(R"({"a": {"b": {"c": {}}}})"); + std::vector const expected = { '{', '#', 'i', 1, 'i', 1, 'a', '{', '#', 'i', 1, 'i', 1, 'b', '{', '#', 'i', 1, 'i', 1, 'c', '{', '#', 'i', 0 }; @@ -2110,7 +2146,7 @@ TEST_CASE("BJData") { SECTION("strict mode") { - std::vector vec = {'Z', 'Z'}; + std::vector const vec = {'Z', 'Z'}; SECTION("non-strict mode") { const auto result = json::from_bjdata(vec, false); @@ -2130,98 +2166,98 @@ TEST_CASE("BJData") { SECTION("start_array()") { - std::vector v = {'[', 'T', 'F', ']'}; + std::vector const v = {'[', 'T', 'F', ']'}; SaxCountdown scp(0); CHECK_FALSE(json::sax_parse(v, &scp, json::input_format_t::bjdata)); } SECTION("start_object()") { - std::vector v = {'{', 'i', 3, 'f', 'o', 'o', 'F', '}'}; + std::vector const v = {'{', 'i', 3, 'f', 'o', 'o', 'F', '}'}; SaxCountdown scp(0); CHECK_FALSE(json::sax_parse(v, &scp, json::input_format_t::bjdata)); } SECTION("key() in object") { - std::vector v = {'{', 'i', 3, 'f', 'o', 'o', 'F', '}'}; + std::vector const v = {'{', 'i', 3, 'f', 'o', 'o', 'F', '}'}; SaxCountdown scp(1); CHECK_FALSE(json::sax_parse(v, &scp, json::input_format_t::bjdata)); } SECTION("start_array(len)") { - std::vector v = {'[', '#', 'i', '2', 'T', 'F'}; + std::vector const v = {'[', '#', 'i', '2', 'T', 'F'}; SaxCountdown scp(0); CHECK_FALSE(json::sax_parse(v, &scp, json::input_format_t::bjdata)); } SECTION("start_object(len)") { - std::vector v = {'{', '#', 'i', '1', 3, 'f', 'o', 'o', 'F'}; + std::vector const v = {'{', '#', 'i', '1', 3, 'f', 'o', 'o', 'F'}; SaxCountdown scp(0); CHECK_FALSE(json::sax_parse(v, &scp, json::input_format_t::bjdata)); } SECTION("key() in object with length") { - std::vector v = {'{', 'i', 3, 'f', 'o', 'o', 'F', '}'}; + std::vector const v = {'{', 'i', 3, 'f', 'o', 'o', 'F', '}'}; SaxCountdown scp(1); CHECK_FALSE(json::sax_parse(v, &scp, json::input_format_t::bjdata)); } SECTION("start_array() in ndarray _ArraySize_") { - std::vector v = {'[', '$', 'i', '#', '[', '$', 'i', '#', 'i', 2, 2, 1, 1, 2}; + std::vector const v = {'[', '$', 'i', '#', '[', '$', 'i', '#', 'i', 2, 2, 1, 1, 2}; SaxCountdown scp(2); CHECK_FALSE(json::sax_parse(v, &scp, json::input_format_t::bjdata)); } SECTION("number_integer() in ndarray _ArraySize_") { - std::vector v = {'[', '$', 'U', '#', '[', '$', 'i', '#', 'i', 2, 2, 1, 1, 2}; + std::vector const v = {'[', '$', 'U', '#', '[', '$', 'i', '#', 'i', 2, 2, 1, 1, 2}; SaxCountdown scp(3); CHECK_FALSE(json::sax_parse(v, &scp, json::input_format_t::bjdata)); } SECTION("key() in ndarray _ArrayType_") { - std::vector v = {'[', '$', 'U', '#', '[', '$', 'U', '#', 'i', 2, 2, 2, 1, 2, 3, 4}; + std::vector const v = {'[', '$', 'U', '#', '[', '$', 'U', '#', 'i', 2, 2, 2, 1, 2, 3, 4}; SaxCountdown scp(6); CHECK_FALSE(json::sax_parse(v, &scp, json::input_format_t::bjdata)); } SECTION("string() in ndarray _ArrayType_") { - std::vector v = {'[', '$', 'U', '#', '[', '$', 'U', '#', 'i', 2, 2, 2, 1, 2, 3, 4}; + std::vector const v = {'[', '$', 'U', '#', '[', '$', 'U', '#', 'i', 2, 2, 2, 1, 2, 3, 4}; SaxCountdown scp(7); CHECK_FALSE(json::sax_parse(v, &scp, json::input_format_t::bjdata)); } SECTION("key() in ndarray _ArrayData_") { - std::vector v = {'[', '$', 'U', '#', '[', '$', 'U', '#', 'i', 2, 2, 2, 1, 2, 3, 4}; + std::vector const v = {'[', '$', 'U', '#', '[', '$', 'U', '#', 'i', 2, 2, 2, 1, 2, 3, 4}; SaxCountdown scp(8); CHECK_FALSE(json::sax_parse(v, &scp, json::input_format_t::bjdata)); } SECTION("string() in ndarray _ArrayData_") { - std::vector v = {'[', '$', 'U', '#', '[', '$', 'U', '#', 'i', 2, 2, 2, 1, 2, 3, 4}; + std::vector const v = {'[', '$', 'U', '#', '[', '$', 'U', '#', 'i', 2, 2, 2, 1, 2, 3, 4}; SaxCountdown scp(9); CHECK_FALSE(json::sax_parse(v, &scp, json::input_format_t::bjdata)); } SECTION("string() in ndarray _ArrayType_") { - std::vector v = {'[', '$', 'U', '#', '[', '$', 'i', '#', 'i', 2, 3, 2, 6, 5, 4, 3, 2, 1}; + std::vector const v = {'[', '$', 'U', '#', '[', '$', 'i', '#', 'i', 2, 3, 2, 6, 5, 4, 3, 2, 1}; SaxCountdown scp(11); CHECK_FALSE(json::sax_parse(v, &scp, json::input_format_t::bjdata)); } SECTION("start_array() in ndarray _ArrayData_") { - std::vector v = {'[', '$', 'U', '#', '[', 'i', 2, 'i', 3, ']', 6, 5, 4, 3, 2, 1}; + std::vector const v = {'[', '$', 'U', '#', '[', 'i', 2, 'i', 3, ']', 6, 5, 4, 3, 2, 1}; SaxCountdown scp(13); CHECK_FALSE(json::sax_parse(v, &scp, json::input_format_t::bjdata)); } @@ -2233,13 +2269,13 @@ TEST_CASE("BJData") { // create a single-character string for all number types std::vector s_i = {'S', 'i', 1, 'a'}; - std::vector s_U = {'S', 'U', 1, 'a'}; - std::vector s_I = {'S', 'I', 1, 0, 'a'}; - std::vector s_u = {'S', 'u', 1, 0, 'a'}; - std::vector s_l = {'S', 'l', 1, 0, 0, 0, 'a'}; - std::vector s_m = {'S', 'm', 1, 0, 0, 0, 'a'}; - std::vector s_L = {'S', 'L', 1, 0, 0, 0, 0, 0, 0, 0, 'a'}; - std::vector s_M = {'S', 'M', 1, 0, 0, 0, 0, 0, 0, 0, 'a'}; + std::vector const s_U = {'S', 'U', 1, 'a'}; + std::vector const s_I = {'S', 'I', 1, 0, 'a'}; + std::vector const s_u = {'S', 'u', 1, 0, 'a'}; + std::vector const s_l = {'S', 'l', 1, 0, 0, 0, 'a'}; + std::vector const s_m = {'S', 'm', 1, 0, 0, 0, 'a'}; + std::vector const s_L = {'S', 'L', 1, 0, 0, 0, 0, 0, 0, 0, 'a'}; + std::vector const s_M = {'S', 'M', 1, 0, 0, 0, 0, 0, 0, 0, 'a'}; // check if string is parsed correctly to "a" CHECK(json::from_bjdata(s_i) == "a"); @@ -2267,11 +2303,11 @@ TEST_CASE("BJData") SECTION("float") { // float32 - std::vector v_d = {'d', 0xd0, 0x0f, 0x49, 0x40}; + std::vector const v_d = {'d', 0xd0, 0x0f, 0x49, 0x40}; CHECK(json::from_bjdata(v_d) == 3.14159f); // float64 - std::vector v_D = {'D', 0x6e, 0x86, 0x1b, 0xf0, 0xf9, 0x21, 0x09, 0x40}; + std::vector const v_D = {'D', 0x6e, 0x86, 0x1b, 0xf0, 0xf9, 0x21, 0x09, 0x40}; CHECK(json::from_bjdata(v_D) == 3.14159); // float32 is serialized as float64 as the library does not support float32 @@ -2284,21 +2320,21 @@ TEST_CASE("BJData") SECTION("optimized version (length only)") { // create vector with two elements of the same type - std::vector v_TU = {'[', '#', 'U', 2, 'T', 'T'}; - std::vector v_T = {'[', '#', 'i', 2, 'T', 'T'}; - std::vector v_F = {'[', '#', 'i', 2, 'F', 'F'}; - std::vector v_Z = {'[', '#', 'i', 2, 'Z', 'Z'}; - std::vector v_i = {'[', '#', 'i', 2, 'i', 0x7F, 'i', 0x7F}; - std::vector v_U = {'[', '#', 'i', 2, 'U', 0xFF, 'U', 0xFF}; - std::vector v_I = {'[', '#', 'i', 2, 'I', 0xFF, 0x7F, 'I', 0xFF, 0x7F}; - std::vector v_u = {'[', '#', 'i', 2, 'u', 0x0F, 0xA7, 'u', 0x0F, 0xA7}; - std::vector v_l = {'[', '#', 'i', 2, 'l', 0xFF, 0xFF, 0xFF, 0x7F, 'l', 0xFF, 0xFF, 0xFF, 0x7F}; - std::vector v_m = {'[', '#', 'i', 2, 'm', 0xFF, 0xC9, 0x9A, 0xBB, 'm', 0xFF, 0xC9, 0x9A, 0xBB}; - std::vector v_L = {'[', '#', 'i', 2, 'L', 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 'L', 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F}; - std::vector v_M = {'[', '#', 'i', 2, 'M', 0xFF, 0xFF, 0x63, 0xA7, 0xB3, 0xB6, 0xE0, 0x8D, 'M', 0xFF, 0xFF, 0x63, 0xA7, 0xB3, 0xB6, 0xE0, 0x8D}; - std::vector v_D = {'[', '#', 'i', 2, 'D', 0x4a, 0xd8, 0x12, 0x4d, 0xfb, 0x21, 0x09, 0x40, 'D', 0x4a, 0xd8, 0x12, 0x4d, 0xfb, 0x21, 0x09, 0x40}; - std::vector v_S = {'[', '#', 'i', 2, 'S', 'i', 1, 'a', 'S', 'i', 1, 'a'}; - std::vector v_C = {'[', '#', 'i', 2, 'C', 'a', 'C', 'a'}; + std::vector const v_TU = {'[', '#', 'U', 2, 'T', 'T'}; + std::vector const v_T = {'[', '#', 'i', 2, 'T', 'T'}; + std::vector const v_F = {'[', '#', 'i', 2, 'F', 'F'}; + std::vector const v_Z = {'[', '#', 'i', 2, 'Z', 'Z'}; + std::vector const v_i = {'[', '#', 'i', 2, 'i', 0x7F, 'i', 0x7F}; + std::vector const v_U = {'[', '#', 'i', 2, 'U', 0xFF, 'U', 0xFF}; + std::vector const v_I = {'[', '#', 'i', 2, 'I', 0xFF, 0x7F, 'I', 0xFF, 0x7F}; + std::vector const v_u = {'[', '#', 'i', 2, 'u', 0x0F, 0xA7, 'u', 0x0F, 0xA7}; + std::vector const v_l = {'[', '#', 'i', 2, 'l', 0xFF, 0xFF, 0xFF, 0x7F, 'l', 0xFF, 0xFF, 0xFF, 0x7F}; + std::vector const v_m = {'[', '#', 'i', 2, 'm', 0xFF, 0xC9, 0x9A, 0xBB, 'm', 0xFF, 0xC9, 0x9A, 0xBB}; + std::vector const v_L = {'[', '#', 'i', 2, 'L', 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 'L', 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F}; + std::vector const v_M = {'[', '#', 'i', 2, 'M', 0xFF, 0xFF, 0x63, 0xA7, 0xB3, 0xB6, 0xE0, 0x8D, 'M', 0xFF, 0xFF, 0x63, 0xA7, 0xB3, 0xB6, 0xE0, 0x8D}; + std::vector const v_D = {'[', '#', 'i', 2, 'D', 0x4a, 0xd8, 0x12, 0x4d, 0xfb, 0x21, 0x09, 0x40, 'D', 0x4a, 0xd8, 0x12, 0x4d, 0xfb, 0x21, 0x09, 0x40}; + std::vector const v_S = {'[', '#', 'i', 2, 'S', 'i', 1, 'a', 'S', 'i', 1, 'a'}; + std::vector const v_C = {'[', '#', 'i', 2, 'C', 'a', 'C', 'a'}; // check if vector is parsed correctly CHECK(json::from_bjdata(v_TU) == json({true, true})); @@ -2337,17 +2373,17 @@ TEST_CASE("BJData") SECTION("optimized version (type and length)") { // create vector with two elements of the same type - std::vector v_i = {'[', '$', 'i', '#', 'i', 2, 0x7F, 0x7F}; - std::vector v_U = {'[', '$', 'U', '#', 'i', 2, 0xFF, 0xFF}; - std::vector v_I = {'[', '$', 'I', '#', 'i', 2, 0xFF, 0x7F, 0xFF, 0x7F}; - std::vector v_u = {'[', '$', 'u', '#', 'i', 2, 0x0F, 0xA7, 0x0F, 0xA7}; - std::vector v_l = {'[', '$', 'l', '#', 'i', 2, 0xFF, 0xFF, 0xFF, 0x7F, 0xFF, 0xFF, 0xFF, 0x7F}; - std::vector v_m = {'[', '$', 'm', '#', 'i', 2, 0xFF, 0xC9, 0x9A, 0xBB, 0xFF, 0xC9, 0x9A, 0xBB}; - std::vector v_L = {'[', '$', 'L', '#', 'i', 2, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F}; - std::vector v_M = {'[', '$', 'M', '#', 'i', 2, 0xFF, 0xFF, 0x63, 0xA7, 0xB3, 0xB6, 0xE0, 0x8D, 0xFF, 0xFF, 0x63, 0xA7, 0xB3, 0xB6, 0xE0, 0x8D}; - std::vector v_D = {'[', '$', 'D', '#', 'i', 2, 0x4a, 0xd8, 0x12, 0x4d, 0xfb, 0x21, 0x09, 0x40, 0x4a, 0xd8, 0x12, 0x4d, 0xfb, 0x21, 0x09, 0x40}; - std::vector v_S = {'[', '#', 'i', 2, 'S', 'i', 1, 'a', 'S', 'i', 1, 'a'}; - std::vector v_C = {'[', '$', 'C', '#', 'i', 2, 'a', 'a'}; + std::vector const v_i = {'[', '$', 'i', '#', 'i', 2, 0x7F, 0x7F}; + std::vector const v_U = {'[', '$', 'U', '#', 'i', 2, 0xFF, 0xFF}; + std::vector const v_I = {'[', '$', 'I', '#', 'i', 2, 0xFF, 0x7F, 0xFF, 0x7F}; + std::vector const v_u = {'[', '$', 'u', '#', 'i', 2, 0x0F, 0xA7, 0x0F, 0xA7}; + std::vector const v_l = {'[', '$', 'l', '#', 'i', 2, 0xFF, 0xFF, 0xFF, 0x7F, 0xFF, 0xFF, 0xFF, 0x7F}; + std::vector const v_m = {'[', '$', 'm', '#', 'i', 2, 0xFF, 0xC9, 0x9A, 0xBB, 0xFF, 0xC9, 0x9A, 0xBB}; + std::vector const v_L = {'[', '$', 'L', '#', 'i', 2, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F}; + std::vector const v_M = {'[', '$', 'M', '#', 'i', 2, 0xFF, 0xFF, 0x63, 0xA7, 0xB3, 0xB6, 0xE0, 0x8D, 0xFF, 0xFF, 0x63, 0xA7, 0xB3, 0xB6, 0xE0, 0x8D}; + std::vector const v_D = {'[', '$', 'D', '#', 'i', 2, 0x4a, 0xd8, 0x12, 0x4d, 0xfb, 0x21, 0x09, 0x40, 0x4a, 0xd8, 0x12, 0x4d, 0xfb, 0x21, 0x09, 0x40}; + std::vector const v_S = {'[', '#', 'i', 2, 'S', 'i', 1, 'a', 'S', 'i', 1, 'a'}; + std::vector const v_C = {'[', '$', 'C', '#', 'i', 2, 'a', 'a'}; // check if vector is parsed correctly CHECK(json::from_bjdata(v_i) == json({127, 127})); @@ -2363,7 +2399,7 @@ TEST_CASE("BJData") CHECK(json::from_bjdata(v_C) == json({"a", "a"})); // roundtrip: output should be optimized - std::vector v_empty = {'[', '#', 'i', 0}; + std::vector const v_empty = {'[', '#', 'i', 0}; CHECK(json::to_bjdata(json::from_bjdata(v_i), true, true) == v_i); CHECK(json::to_bjdata(json::from_bjdata(v_U), true, true) == v_U); CHECK(json::to_bjdata(json::from_bjdata(v_I), true, true) == v_I); @@ -2380,19 +2416,19 @@ TEST_CASE("BJData") SECTION("optimized ndarray (type and vector-size as optimized 1D array)") { // create vector with two elements of the same type - std::vector v_0 = {'[', '$', 'i', '#', '[', '$', 'i', '#', 'i', 1, 0}; - std::vector v_1 = {'[', '$', 'i', '#', '[', '$', 'i', '#', 'i', 1, 2, 0x7F, 0x7F}; - std::vector v_i = {'[', '$', 'i', '#', '[', '$', 'i', '#', 'i', 2, 1, 2, 0x7F, 0x7F}; - std::vector v_U = {'[', '$', 'U', '#', '[', '$', 'i', '#', 'i', 2, 1, 2, 0xFF, 0xFF}; - std::vector v_I = {'[', '$', 'I', '#', '[', '$', 'i', '#', 'i', 2, 1, 2, 0xFF, 0x7F, 0xFF, 0x7F}; - std::vector v_u = {'[', '$', 'u', '#', '[', '$', 'i', '#', 'i', 2, 1, 2, 0x0F, 0xA7, 0x0F, 0xA7}; - std::vector v_l = {'[', '$', 'l', '#', '[', '$', 'i', '#', 'i', 2, 1, 2, 0xFF, 0xFF, 0xFF, 0x7F, 0xFF, 0xFF, 0xFF, 0x7F}; - std::vector v_m = {'[', '$', 'm', '#', '[', '$', 'i', '#', 'i', 2, 1, 2, 0xFF, 0xC9, 0x9A, 0xBB, 0xFF, 0xC9, 0x9A, 0xBB}; - std::vector v_L = {'[', '$', 'L', '#', '[', '$', 'i', '#', 'i', 2, 1, 2, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F}; - std::vector v_M = {'[', '$', 'M', '#', '[', '$', 'i', '#', 'i', 2, 1, 2, 0xFF, 0xFF, 0x63, 0xA7, 0xB3, 0xB6, 0xE0, 0x8D, 0xFF, 0xFF, 0x63, 0xA7, 0xB3, 0xB6, 0xE0, 0x8D}; - std::vector v_D = {'[', '$', 'D', '#', '[', '$', 'i', '#', 'i', 2, 1, 2, 0x4a, 0xd8, 0x12, 0x4d, 0xfb, 0x21, 0x09, 0x40, 0x4a, 0xd8, 0x12, 0x4d, 0xfb, 0x21, 0x09, 0x40}; - std::vector v_S = {'[', '#', '[', '$', 'i', '#', 'i', 2, 1, 2, 'S', 'i', 1, 'a', 'S', 'i', 1, 'a'}; - std::vector v_C = {'[', '$', 'C', '#', '[', '$', 'i', '#', 'i', 2, 1, 2, 'a', 'a'}; + std::vector const v_0 = {'[', '$', 'i', '#', '[', '$', 'i', '#', 'i', 1, 0}; + std::vector const v_1 = {'[', '$', 'i', '#', '[', '$', 'i', '#', 'i', 1, 2, 0x7F, 0x7F}; + std::vector const v_i = {'[', '$', 'i', '#', '[', '$', 'i', '#', 'i', 2, 1, 2, 0x7F, 0x7F}; + std::vector const v_U = {'[', '$', 'U', '#', '[', '$', 'i', '#', 'i', 2, 1, 2, 0xFF, 0xFF}; + std::vector const v_I = {'[', '$', 'I', '#', '[', '$', 'i', '#', 'i', 2, 1, 2, 0xFF, 0x7F, 0xFF, 0x7F}; + std::vector const v_u = {'[', '$', 'u', '#', '[', '$', 'i', '#', 'i', 2, 1, 2, 0x0F, 0xA7, 0x0F, 0xA7}; + std::vector const v_l = {'[', '$', 'l', '#', '[', '$', 'i', '#', 'i', 2, 1, 2, 0xFF, 0xFF, 0xFF, 0x7F, 0xFF, 0xFF, 0xFF, 0x7F}; + std::vector const v_m = {'[', '$', 'm', '#', '[', '$', 'i', '#', 'i', 2, 1, 2, 0xFF, 0xC9, 0x9A, 0xBB, 0xFF, 0xC9, 0x9A, 0xBB}; + std::vector const v_L = {'[', '$', 'L', '#', '[', '$', 'i', '#', 'i', 2, 1, 2, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F}; + std::vector const v_M = {'[', '$', 'M', '#', '[', '$', 'i', '#', 'i', 2, 1, 2, 0xFF, 0xFF, 0x63, 0xA7, 0xB3, 0xB6, 0xE0, 0x8D, 0xFF, 0xFF, 0x63, 0xA7, 0xB3, 0xB6, 0xE0, 0x8D}; + std::vector const v_D = {'[', '$', 'D', '#', '[', '$', 'i', '#', 'i', 2, 1, 2, 0x4a, 0xd8, 0x12, 0x4d, 0xfb, 0x21, 0x09, 0x40, 0x4a, 0xd8, 0x12, 0x4d, 0xfb, 0x21, 0x09, 0x40}; + std::vector const v_S = {'[', '#', '[', '$', 'i', '#', 'i', 2, 1, 2, 'S', 'i', 1, 'a', 'S', 'i', 1, 'a'}; + std::vector const v_C = {'[', '$', 'C', '#', '[', '$', 'i', '#', 'i', 2, 1, 2, 'a', 'a'}; // check if vector is parsed correctly CHECK(json::from_bjdata(v_0) == json::array()); @@ -2413,18 +2449,18 @@ TEST_CASE("BJData") SECTION("optimized ndarray (type and vector-size ndarray with JData annotations)") { // create vector with 0, 1, 2 elements of the same type - std::vector v_e = {'[', '$', 'U', '#', '[', '$', 'i', '#', 'i', 2, 2, 1, 0xFE, 0xFF}; - std::vector v_U = {'[', '$', 'U', '#', '[', '$', 'i', '#', 'i', 2, 2, 3, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06}; - std::vector v_i = {'[', '$', 'i', '#', '[', '$', 'i', '#', 'i', 2, 2, 3, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06}; - std::vector v_u = {'[', '$', 'u', '#', '[', '$', 'i', '#', 'i', 2, 2, 3, 0x01, 0x00, 0x02, 0x00, 0x03, 0x00, 0x04, 0x00, 0x05, 0x00, 0x06, 0x00}; - std::vector v_I = {'[', '$', 'I', '#', '[', '$', 'i', '#', 'i', 2, 2, 3, 0x01, 0x00, 0x02, 0x00, 0x03, 0x00, 0x04, 0x00, 0x05, 0x00, 0x06, 0x00}; - std::vector v_m = {'[', '$', 'm', '#', '[', '$', 'i', '#', 'i', 2, 2, 3, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00}; - std::vector v_l = {'[', '$', 'l', '#', '[', '$', 'i', '#', 'i', 2, 2, 3, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00}; - std::vector v_M = {'[', '$', 'M', '#', '[', '$', 'i', '#', 'i', 2, 2, 3, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; - std::vector v_L = {'[', '$', 'L', '#', '[', '$', 'i', '#', 'i', 2, 2, 3, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; - std::vector v_d = {'[', '$', 'd', '#', '[', '$', 'i', '#', 'i', 2, 2, 3, 0x00, 0x00, 0x80, 0x3F, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x40, 0x40, 0x00, 0x00, 0x80, 0x40, 0x00, 0x00, 0xA0, 0x40, 0x00, 0x00, 0xC0, 0x40}; - std::vector v_D = {'[', '$', 'D', '#', '[', '$', 'i', '#', 'i', 2, 2, 3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x3F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x40}; - std::vector v_C = {'[', '$', 'C', '#', '[', '$', 'i', '#', 'i', 2, 2, 3, 'a', 'b', 'c', 'd', 'e', 'f'}; + std::vector const v_e = {'[', '$', 'U', '#', '[', '$', 'i', '#', 'i', 2, 2, 1, 0xFE, 0xFF}; + std::vector const v_U = {'[', '$', 'U', '#', '[', '$', 'i', '#', 'i', 2, 2, 3, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06}; + std::vector const v_i = {'[', '$', 'i', '#', '[', '$', 'i', '#', 'i', 2, 2, 3, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06}; + std::vector const v_u = {'[', '$', 'u', '#', '[', '$', 'i', '#', 'i', 2, 2, 3, 0x01, 0x00, 0x02, 0x00, 0x03, 0x00, 0x04, 0x00, 0x05, 0x00, 0x06, 0x00}; + std::vector const v_I = {'[', '$', 'I', '#', '[', '$', 'i', '#', 'i', 2, 2, 3, 0x01, 0x00, 0x02, 0x00, 0x03, 0x00, 0x04, 0x00, 0x05, 0x00, 0x06, 0x00}; + std::vector const v_m = {'[', '$', 'm', '#', '[', '$', 'i', '#', 'i', 2, 2, 3, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00}; + std::vector const v_l = {'[', '$', 'l', '#', '[', '$', 'i', '#', 'i', 2, 2, 3, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00}; + std::vector const v_M = {'[', '$', 'M', '#', '[', '$', 'i', '#', 'i', 2, 2, 3, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; + std::vector const v_L = {'[', '$', 'L', '#', '[', '$', 'i', '#', 'i', 2, 2, 3, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; + std::vector const v_d = {'[', '$', 'd', '#', '[', '$', 'i', '#', 'i', 2, 2, 3, 0x00, 0x00, 0x80, 0x3F, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x40, 0x40, 0x00, 0x00, 0x80, 0x40, 0x00, 0x00, 0xA0, 0x40, 0x00, 0x00, 0xC0, 0x40}; + std::vector const v_D = {'[', '$', 'D', '#', '[', '$', 'i', '#', 'i', 2, 2, 3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x3F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x40}; + std::vector const v_C = {'[', '$', 'C', '#', '[', '$', 'i', '#', 'i', 2, 2, 3, 'a', 'b', 'c', 'd', 'e', 'f'}; // check if vector is parsed correctly CHECK(json::from_bjdata(v_e) == json({{"_ArrayData_", {254, 255}}, {"_ArraySize_", {2, 1}}, {"_ArrayType_", "uint8"}})); @@ -2459,20 +2495,20 @@ TEST_CASE("BJData") SECTION("optimized ndarray (type and vector-size as 1D array)") { // create vector with two elements of the same type - std::vector v_0 = {'[', '$', 'i', '#', '[', ']'}; - std::vector v_E = {'[', '$', 'i', '#', '[', 'i', 2, 'i', 0, ']'}; - std::vector v_i = {'[', '$', 'i', '#', '[', 'i', 1, 'i', 2, ']', 0x7F, 0x7F}; - std::vector v_U = {'[', '$', 'U', '#', '[', 'i', 1, 'i', 2, ']', 0xFF, 0xFF}; - std::vector v_I = {'[', '$', 'I', '#', '[', 'i', 1, 'i', 2, ']', 0xFF, 0x7F, 0xFF, 0x7F}; - std::vector v_u = {'[', '$', 'u', '#', '[', 'i', 1, 'i', 2, ']', 0x0F, 0xA7, 0x0F, 0xA7}; - std::vector v_l = {'[', '$', 'l', '#', '[', 'i', 1, 'i', 2, ']', 0xFF, 0xFF, 0xFF, 0x7F, 0xFF, 0xFF, 0xFF, 0x7F}; - std::vector v_m = {'[', '$', 'm', '#', '[', 'i', 1, 'i', 2, ']', 0xFF, 0xC9, 0x9A, 0xBB, 0xFF, 0xC9, 0x9A, 0xBB}; - std::vector v_L = {'[', '$', 'L', '#', '[', 'i', 1, 'i', 2, ']', 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F}; - std::vector v_M = {'[', '$', 'M', '#', '[', 'i', 1, 'i', 2, ']', 0xFF, 0xFF, 0x63, 0xA7, 0xB3, 0xB6, 0xE0, 0x8D, 0xFF, 0xFF, 0x63, 0xA7, 0xB3, 0xB6, 0xE0, 0x8D}; - std::vector v_D = {'[', '$', 'D', '#', '[', 'i', 1, 'i', 2, ']', 0x4a, 0xd8, 0x12, 0x4d, 0xfb, 0x21, 0x09, 0x40, 0x4a, 0xd8, 0x12, 0x4d, 0xfb, 0x21, 0x09, 0x40}; - std::vector v_S = {'[', '#', '[', 'i', 1, 'i', 2, ']', 'S', 'i', 1, 'a', 'S', 'i', 1, 'a'}; - std::vector v_C = {'[', '$', 'C', '#', '[', 'i', 1, 'i', 2, ']', 'a', 'a'}; - std::vector v_R = {'[', '#', '[', 'i', 2, ']', 'i', 6, 'U', 7}; + std::vector const v_0 = {'[', '$', 'i', '#', '[', ']'}; + std::vector const v_E = {'[', '$', 'i', '#', '[', 'i', 2, 'i', 0, ']'}; + std::vector const v_i = {'[', '$', 'i', '#', '[', 'i', 1, 'i', 2, ']', 0x7F, 0x7F}; + std::vector const v_U = {'[', '$', 'U', '#', '[', 'i', 1, 'i', 2, ']', 0xFF, 0xFF}; + std::vector const v_I = {'[', '$', 'I', '#', '[', 'i', 1, 'i', 2, ']', 0xFF, 0x7F, 0xFF, 0x7F}; + std::vector const v_u = {'[', '$', 'u', '#', '[', 'i', 1, 'i', 2, ']', 0x0F, 0xA7, 0x0F, 0xA7}; + std::vector const v_l = {'[', '$', 'l', '#', '[', 'i', 1, 'i', 2, ']', 0xFF, 0xFF, 0xFF, 0x7F, 0xFF, 0xFF, 0xFF, 0x7F}; + std::vector const v_m = {'[', '$', 'm', '#', '[', 'i', 1, 'i', 2, ']', 0xFF, 0xC9, 0x9A, 0xBB, 0xFF, 0xC9, 0x9A, 0xBB}; + std::vector const v_L = {'[', '$', 'L', '#', '[', 'i', 1, 'i', 2, ']', 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F}; + std::vector const v_M = {'[', '$', 'M', '#', '[', 'i', 1, 'i', 2, ']', 0xFF, 0xFF, 0x63, 0xA7, 0xB3, 0xB6, 0xE0, 0x8D, 0xFF, 0xFF, 0x63, 0xA7, 0xB3, 0xB6, 0xE0, 0x8D}; + std::vector const v_D = {'[', '$', 'D', '#', '[', 'i', 1, 'i', 2, ']', 0x4a, 0xd8, 0x12, 0x4d, 0xfb, 0x21, 0x09, 0x40, 0x4a, 0xd8, 0x12, 0x4d, 0xfb, 0x21, 0x09, 0x40}; + std::vector const v_S = {'[', '#', '[', 'i', 1, 'i', 2, ']', 'S', 'i', 1, 'a', 'S', 'i', 1, 'a'}; + std::vector const v_C = {'[', '$', 'C', '#', '[', 'i', 1, 'i', 2, ']', 'a', 'a'}; + std::vector const v_R = {'[', '#', '[', 'i', 2, ']', 'i', 6, 'U', 7}; // check if vector is parsed correctly CHECK(json::from_bjdata(v_0) == json::array()); @@ -2494,17 +2530,17 @@ TEST_CASE("BJData") SECTION("optimized ndarray (type and vector-size as size-optimized array)") { // create vector with two elements of the same type - std::vector v_i = {'[', '$', 'i', '#', '[', '#', 'i', 2, 'i', 1, 'i', 2, 0x7F, 0x7F}; - std::vector v_U = {'[', '$', 'U', '#', '[', '#', 'i', 2, 'i', 1, 'i', 2, 0xFF, 0xFF}; - std::vector v_I = {'[', '$', 'I', '#', '[', '#', 'i', 2, 'i', 1, 'i', 2, 0xFF, 0x7F, 0xFF, 0x7F}; - std::vector v_u = {'[', '$', 'u', '#', '[', '#', 'i', 2, 'i', 1, 'i', 2, 0x0F, 0xA7, 0x0F, 0xA7}; - std::vector v_l = {'[', '$', 'l', '#', '[', '#', 'i', 2, 'i', 1, 'i', 2, 0xFF, 0xFF, 0xFF, 0x7F, 0xFF, 0xFF, 0xFF, 0x7F}; - std::vector v_m = {'[', '$', 'm', '#', '[', '#', 'i', 2, 'i', 1, 'i', 2, 0xFF, 0xC9, 0x9A, 0xBB, 0xFF, 0xC9, 0x9A, 0xBB}; - std::vector v_L = {'[', '$', 'L', '#', '[', '#', 'i', 2, 'i', 1, 'i', 2, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F}; - std::vector v_M = {'[', '$', 'M', '#', '[', '#', 'i', 2, 'i', 1, 'i', 2, 0xFF, 0xFF, 0x63, 0xA7, 0xB3, 0xB6, 0xE0, 0x8D, 0xFF, 0xFF, 0x63, 0xA7, 0xB3, 0xB6, 0xE0, 0x8D}; - std::vector v_D = {'[', '$', 'D', '#', '[', '#', 'i', 2, 'i', 1, 'i', 2, 0x4a, 0xd8, 0x12, 0x4d, 0xfb, 0x21, 0x09, 0x40, 0x4a, 0xd8, 0x12, 0x4d, 0xfb, 0x21, 0x09, 0x40}; - std::vector v_S = {'[', '#', '[', '#', 'i', 2, 'i', 1, 'i', 2, 'S', 'i', 1, 'a', 'S', 'i', 1, 'a'}; - std::vector v_C = {'[', '$', 'C', '#', '[', '#', 'i', 2, 'i', 1, 'i', 2, 'a', 'a'}; + std::vector const v_i = {'[', '$', 'i', '#', '[', '#', 'i', 2, 'i', 1, 'i', 2, 0x7F, 0x7F}; + std::vector const v_U = {'[', '$', 'U', '#', '[', '#', 'i', 2, 'i', 1, 'i', 2, 0xFF, 0xFF}; + std::vector const v_I = {'[', '$', 'I', '#', '[', '#', 'i', 2, 'i', 1, 'i', 2, 0xFF, 0x7F, 0xFF, 0x7F}; + std::vector const v_u = {'[', '$', 'u', '#', '[', '#', 'i', 2, 'i', 1, 'i', 2, 0x0F, 0xA7, 0x0F, 0xA7}; + std::vector const v_l = {'[', '$', 'l', '#', '[', '#', 'i', 2, 'i', 1, 'i', 2, 0xFF, 0xFF, 0xFF, 0x7F, 0xFF, 0xFF, 0xFF, 0x7F}; + std::vector const v_m = {'[', '$', 'm', '#', '[', '#', 'i', 2, 'i', 1, 'i', 2, 0xFF, 0xC9, 0x9A, 0xBB, 0xFF, 0xC9, 0x9A, 0xBB}; + std::vector const v_L = {'[', '$', 'L', '#', '[', '#', 'i', 2, 'i', 1, 'i', 2, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F}; + std::vector const v_M = {'[', '$', 'M', '#', '[', '#', 'i', 2, 'i', 1, 'i', 2, 0xFF, 0xFF, 0x63, 0xA7, 0xB3, 0xB6, 0xE0, 0x8D, 0xFF, 0xFF, 0x63, 0xA7, 0xB3, 0xB6, 0xE0, 0x8D}; + std::vector const v_D = {'[', '$', 'D', '#', '[', '#', 'i', 2, 'i', 1, 'i', 2, 0x4a, 0xd8, 0x12, 0x4d, 0xfb, 0x21, 0x09, 0x40, 0x4a, 0xd8, 0x12, 0x4d, 0xfb, 0x21, 0x09, 0x40}; + std::vector const v_S = {'[', '#', '[', '#', 'i', 2, 'i', 1, 'i', 2, 'S', 'i', 1, 'a', 'S', 'i', 1, 'a'}; + std::vector const v_C = {'[', '$', 'C', '#', '[', '#', 'i', 2, 'i', 1, 'i', 2, 'a', 'a'}; // check if vector is parsed correctly CHECK(json::from_bjdata(v_i) == json({127, 127})); @@ -2546,14 +2582,14 @@ TEST_CASE("BJData") { SECTION("eof after C byte") { - std::vector v = {'C'}; + std::vector const v = {'C'}; json _; CHECK_THROWS_WITH_AS(_ = json::from_bjdata(v), "[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing BJData char: unexpected end of input", json::parse_error&); } SECTION("byte out of range") { - std::vector v = {'C', 130}; + std::vector const v = {'C', 130}; json _; CHECK_THROWS_WITH(_ = json::from_bjdata(v), "[json.exception.parse_error.113] parse error at byte 2: syntax error while parsing BJData char: byte after 'C' must be in range 0x00..0x7F; last byte: 0x82"); } @@ -2563,14 +2599,14 @@ TEST_CASE("BJData") { SECTION("eof after S byte") { - std::vector v = {'S'}; + std::vector const v = {'S'}; json _; CHECK_THROWS_WITH_AS(_ = json::from_bjdata(v), "[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing BJData value: unexpected end of input", json::parse_error&); } SECTION("invalid byte") { - std::vector v = {'S', '1', 'a'}; + std::vector const v = {'S', '1', 'a'}; json _; CHECK_THROWS_WITH_AS(_ = json::from_bjdata(v), "[json.exception.parse_error.113] parse error at byte 2: syntax error while parsing BJData string: expected length type specification (U, i, u, I, m, l, M, L); last byte: 0x31", json::parse_error&); } @@ -2578,9 +2614,9 @@ TEST_CASE("BJData") SECTION("parse bjdata markers in ubjson") { // create a single-character string for all number types - std::vector s_u = {'S', 'u', 1, 0, 'a'}; - std::vector s_m = {'S', 'm', 1, 0, 0, 0, 'a'}; - std::vector s_M = {'S', 'M', 1, 0, 0, 0, 0, 0, 0, 0, 'a'}; + std::vector const s_u = {'S', 'u', 1, 0, 'a'}; + std::vector const s_m = {'S', 'm', 1, 0, 0, 0, 'a'}; + std::vector const s_M = {'S', 'M', 1, 0, 0, 0, 0, 0, 0, 0, 'a'}; json _; // check if string is parsed correctly to "a" @@ -2594,25 +2630,25 @@ TEST_CASE("BJData") { SECTION("optimized array: no size following type") { - std::vector v = {'[', '$', 'i', 2}; + std::vector const v = {'[', '$', 'i', 2}; json _; CHECK_THROWS_WITH_AS(_ = json::from_bjdata(v), "[json.exception.parse_error.112] parse error at byte 4: syntax error while parsing BJData size: expected '#' after type information; last byte: 0x02", json::parse_error&); } SECTION("optimized array: negative size") { - std::vector v1 = {'[', '#', 'i', 0xF1}; - std::vector v2 = {'[', '$', 'I', '#', 'i', 0xF2}; - std::vector v3 = {'[', '$', 'I', '#', '[', 'i', 0xF4, 'i', 0x02, ']'}; - std::vector v4 = {'[', '$', 0xF6, '#', 'i', 0xF7}; - std::vector v5 = {'[', '$', 'I', '#', '[', 'i', 0xF5, 'i', 0xF1, ']'}; - std::vector v6 = {'[', '#', '[', 'i', 0xF3, 'i', 0x02, ']'}; + std::vector const v1 = {'[', '#', 'i', 0xF1}; + std::vector const v2 = {'[', '$', 'I', '#', 'i', 0xF2}; + std::vector const v3 = {'[', '$', 'I', '#', '[', 'i', 0xF4, 'i', 0x02, ']'}; + std::vector const v4 = {'[', '$', 0xF6, '#', 'i', 0xF7}; + std::vector const v5 = {'[', '$', 'I', '#', '[', 'i', 0xF5, 'i', 0xF1, ']'}; + std::vector const v6 = {'[', '#', '[', 'i', 0xF3, 'i', 0x02, ']'}; - std::vector vI = {'[', '#', 'I', 0x00, 0xF1}; - std::vector vl = {'[', '#', 'l', 0x00, 0x00, 0x00, 0xF2}; - std::vector vL = {'[', '#', 'L', 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF3}; - 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 vI = {'[', '#', 'I', 0x00, 0xF1}; + std::vector const vl = {'[', '#', 'l', 0x00, 0x00, 0x00, 0xF2}; + std::vector const vL = {'[', '#', 'L', 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF3}; + 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(v1), "[json.exception.parse_error.113] parse error at byte 4: syntax error while parsing BJData size: count in an optimized container must be positive", json::parse_error&); @@ -2659,16 +2695,13 @@ 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, ']'}; +#if SIZE_MAX == 0xffffffff + 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 _; -#if SIZE_MAX == 0xffffffff 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&); CHECK(json::from_bjdata(vL, true, false).is_discarded()); -#endif - -#if SIZE_MAX == 0xffffffff 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&); CHECK(json::from_bjdata(vM, true, false).is_discarded()); #endif @@ -2677,10 +2710,10 @@ TEST_CASE("BJData") SECTION("do not accept NTFZ markers in ndarray optimized type (with count)") { json _; - std::vector v_N = {'[', '$', 'N', '#', '[', '#', 'i', 2, 'i', 1, 'i', 2}; - std::vector v_T = {'[', '$', 'T', '#', '[', '#', 'i', 2, 'i', 1, 'i', 2}; - std::vector v_F = {'[', '$', 'F', '#', '[', '#', 'i', 2, 'i', 1, 'i', 2}; - std::vector v_Z = {'[', '$', 'Z', '#', '[', '#', 'i', 2, 'i', 1, 'i', 2}; + std::vector const v_N = {'[', '$', 'N', '#', '[', '#', 'i', 2, 'i', 1, 'i', 2}; + std::vector const v_T = {'[', '$', 'T', '#', '[', '#', 'i', 2, 'i', 1, 'i', 2}; + std::vector const v_F = {'[', '$', 'F', '#', '[', '#', 'i', 2, 'i', 1, 'i', 2}; + std::vector const v_Z = {'[', '$', 'Z', '#', '[', '#', 'i', 2, 'i', 1, 'i', 2}; CHECK_THROWS_WITH_AS(_ = json::from_bjdata(v_N), "[json.exception.parse_error.112] parse error at byte 3: syntax error while parsing BJData type: marker 0x4E is not a permitted optimized array type", json::parse_error&); CHECK(json::from_bjdata(v_N, true, false).is_discarded()); @@ -2698,10 +2731,10 @@ TEST_CASE("BJData") SECTION("do not accept NTFZ markers in ndarray optimized type (without count)") { json _; - std::vector v_N = {'[', '$', 'N', '#', '[', 'i', 1, 'i', 2, ']'}; - std::vector v_T = {'[', '$', 'T', '#', '[', 'i', 1, 'i', 2, ']'}; - std::vector v_F = {'[', '$', 'F', '#', '[', 'i', 1, 'i', 2, ']'}; - std::vector v_Z = {'[', '$', 'Z', '#', '[', 'i', 1, 'i', 2, ']'}; + std::vector const v_N = {'[', '$', 'N', '#', '[', 'i', 1, 'i', 2, ']'}; + std::vector const v_T = {'[', '$', 'T', '#', '[', 'i', 1, 'i', 2, ']'}; + std::vector const v_F = {'[', '$', 'F', '#', '[', 'i', 1, 'i', 2, ']'}; + std::vector const v_Z = {'[', '$', 'Z', '#', '[', 'i', 1, 'i', 2, ']'}; CHECK_THROWS_WITH_AS(_ = json::from_bjdata(v_N), "[json.exception.parse_error.112] parse error at byte 3: syntax error while parsing BJData type: marker 0x4E is not a permitted optimized array type", json::parse_error&); CHECK(json::from_bjdata(v_N, true, false).is_discarded()); @@ -2719,56 +2752,56 @@ TEST_CASE("BJData") SECTION("strings") { - std::vector vS = {'S'}; + std::vector const vS = {'S'}; json _; CHECK_THROWS_WITH_AS(_ = json::from_bjdata(vS), "[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing BJData value: unexpected end of input", json::parse_error&); CHECK(json::from_bjdata(vS, true, false).is_discarded()); - std::vector v = {'S', 'i', '2', 'a'}; + std::vector const v = {'S', 'i', '2', 'a'}; CHECK_THROWS_WITH_AS(_ = json::from_bjdata(v), "[json.exception.parse_error.110] parse error at byte 5: syntax error while parsing BJData string: unexpected end of input", json::parse_error&); CHECK(json::from_bjdata(v, true, false).is_discarded()); - std::vector vC = {'C'}; + std::vector const vC = {'C'}; CHECK_THROWS_WITH_AS(_ = json::from_bjdata(vC), "[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing BJData char: unexpected end of input", json::parse_error&); CHECK(json::from_bjdata(vC, true, false).is_discarded()); } SECTION("sizes") { - std::vector vU = {'[', '#', 'U'}; + std::vector const vU = {'[', '#', 'U'}; json _; CHECK_THROWS_WITH_AS(_ = json::from_bjdata(vU), "[json.exception.parse_error.110] parse error at byte 4: syntax error while parsing BJData number: unexpected end of input", json::parse_error&); CHECK(json::from_bjdata(vU, true, false).is_discarded()); - std::vector vi = {'[', '#', 'i'}; + std::vector const vi = {'[', '#', 'i'}; CHECK_THROWS_WITH_AS(_ = json::from_bjdata(vi), "[json.exception.parse_error.110] parse error at byte 4: syntax error while parsing BJData number: unexpected end of input", json::parse_error&); CHECK(json::from_bjdata(vi, true, false).is_discarded()); - std::vector vI = {'[', '#', 'I'}; + std::vector const vI = {'[', '#', 'I'}; CHECK_THROWS_WITH_AS(_ = json::from_bjdata(vI), "[json.exception.parse_error.110] parse error at byte 4: syntax error while parsing BJData number: unexpected end of input", json::parse_error&); CHECK(json::from_bjdata(vI, true, false).is_discarded()); - std::vector vu = {'[', '#', 'u'}; + std::vector const vu = {'[', '#', 'u'}; CHECK_THROWS_WITH_AS(_ = json::from_bjdata(vu), "[json.exception.parse_error.110] parse error at byte 4: syntax error while parsing BJData number: unexpected end of input", json::parse_error&); CHECK(json::from_bjdata(vu, true, false).is_discarded()); - std::vector vl = {'[', '#', 'l'}; + std::vector const vl = {'[', '#', 'l'}; CHECK_THROWS_WITH_AS(_ = json::from_bjdata(vl), "[json.exception.parse_error.110] parse error at byte 4: syntax error while parsing BJData number: unexpected end of input", json::parse_error&); CHECK(json::from_bjdata(vl, true, false).is_discarded()); - std::vector vm = {'[', '#', 'm'}; + std::vector const vm = {'[', '#', 'm'}; CHECK_THROWS_WITH_AS(_ = json::from_bjdata(vm), "[json.exception.parse_error.110] parse error at byte 4: syntax error while parsing BJData number: unexpected end of input", json::parse_error&); CHECK(json::from_bjdata(vm, true, false).is_discarded()); - std::vector vL = {'[', '#', 'L'}; + std::vector const vL = {'[', '#', 'L'}; CHECK_THROWS_WITH_AS(_ = json::from_bjdata(vL), "[json.exception.parse_error.110] parse error at byte 4: syntax error while parsing BJData number: unexpected end of input", json::parse_error&); CHECK(json::from_bjdata(vL, true, false).is_discarded()); - std::vector vM = {'[', '#', 'M'}; + std::vector const vM = {'[', '#', 'M'}; CHECK_THROWS_WITH_AS(_ = json::from_bjdata(vM), "[json.exception.parse_error.110] parse error at byte 4: syntax error while parsing BJData number: unexpected end of input", json::parse_error&); CHECK(json::from_bjdata(vM, true, false).is_discarded()); - std::vector v0 = {'[', '#', 'T', ']'}; + std::vector const v0 = {'[', '#', 'T', ']'}; CHECK_THROWS_WITH(_ = json::from_bjdata(v0), "[json.exception.parse_error.113] parse error at byte 3: syntax error while parsing BJData size: expected length type specification (U, i, u, I, m, l, M, L) after '#'; last byte: 0x54"); CHECK(json::from_bjdata(v0, true, false).is_discarded()); } @@ -2776,185 +2809,185 @@ TEST_CASE("BJData") SECTION("parse bjdata markers as array size in ubjson") { json _; - std::vector vu = {'[', '#', 'u'}; + std::vector const vu = {'[', '#', 'u'}; CHECK_THROWS_WITH_AS(_ = json::from_ubjson(vu), "[json.exception.parse_error.113] parse error at byte 3: syntax error while parsing UBJSON size: expected length type specification (U, i, I, l, L) after '#'; last byte: 0x75", json::parse_error&); CHECK(json::from_ubjson(vu, true, false).is_discarded()); - std::vector vm = {'[', '#', 'm'}; + std::vector const vm = {'[', '#', 'm'}; CHECK_THROWS_WITH_AS(_ = json::from_ubjson(vm), "[json.exception.parse_error.113] parse error at byte 3: syntax error while parsing UBJSON size: expected length type specification (U, i, I, l, L) after '#'; last byte: 0x6D", json::parse_error&); CHECK(json::from_ubjson(vm, true, false).is_discarded()); - std::vector vM = {'[', '#', 'M'}; + std::vector const vM = {'[', '#', 'M'}; CHECK_THROWS_WITH_AS(_ = json::from_ubjson(vM), "[json.exception.parse_error.113] parse error at byte 3: syntax error while parsing UBJSON size: expected length type specification (U, i, I, l, L) after '#'; last byte: 0x4D", json::parse_error&); CHECK(json::from_ubjson(vM, true, false).is_discarded()); - std::vector v0 = {'[', '#', '['}; + std::vector const v0 = {'[', '#', '['}; CHECK_THROWS_WITH_AS(_ = json::from_ubjson(v0), "[json.exception.parse_error.113] parse error at byte 3: syntax error while parsing UBJSON size: expected length type specification (U, i, I, l, L) after '#'; last byte: 0x5B", json::parse_error&); CHECK(json::from_ubjson(v0, true, false).is_discarded()); } SECTION("types") { - std::vector v0 = {'[', '$'}; + std::vector const v0 = {'[', '$'}; json _; CHECK_THROWS_WITH_AS(_ = json::from_bjdata(v0), "[json.exception.parse_error.110] parse error at byte 3: syntax error while parsing BJData type: unexpected end of input", json::parse_error&); CHECK(json::from_bjdata(v0, true, false).is_discarded()); - std::vector vi = {'[', '$', '#'}; + std::vector const vi = {'[', '$', '#'}; CHECK_THROWS_WITH_AS(_ = json::from_bjdata(vi), "[json.exception.parse_error.110] parse error at byte 4: syntax error while parsing BJData value: unexpected end of input", json::parse_error&); CHECK(json::from_bjdata(vi, true, false).is_discarded()); - std::vector vU = {'[', '$', 'U'}; + std::vector const vU = {'[', '$', 'U'}; CHECK_THROWS_WITH_AS(_ = json::from_bjdata(vU), "[json.exception.parse_error.110] parse error at byte 4: syntax error while parsing BJData value: unexpected end of input", json::parse_error&); CHECK(json::from_bjdata(vU, true, false).is_discarded()); - std::vector v1 = {'[', '$', '['}; + std::vector const v1 = {'[', '$', '['}; CHECK_THROWS_WITH_AS(_ = json::from_bjdata(v1), "[json.exception.parse_error.112] parse error at byte 3: syntax error while parsing BJData type: marker 0x5B is not a permitted optimized array type", json::parse_error&); CHECK(json::from_bjdata(v1, true, false).is_discarded()); } SECTION("arrays") { - std::vector vST = {'[', '$', 'i', '#', 'i', 2, 1}; + std::vector const vST = {'[', '$', 'i', '#', 'i', 2, 1}; json _; CHECK_THROWS_WITH_AS(_ = json::from_bjdata(vST), "[json.exception.parse_error.110] parse error at byte 8: syntax error while parsing BJData number: unexpected end of input", json::parse_error&); CHECK(json::from_bjdata(vST, true, false).is_discarded()); - std::vector vS = {'[', '#', 'i', 2, 'i', 1}; + std::vector const vS = {'[', '#', 'i', 2, 'i', 1}; CHECK_THROWS_WITH_AS(_ = json::from_bjdata(vS), "[json.exception.parse_error.110] parse error at byte 7: syntax error while parsing BJData value: unexpected end of input", json::parse_error&); CHECK(json::from_bjdata(vS, true, false).is_discarded()); - std::vector v = {'[', 'i', 2, 'i', 1}; + std::vector const v = {'[', 'i', 2, 'i', 1}; CHECK_THROWS_WITH_AS(_ = json::from_bjdata(v), "[json.exception.parse_error.110] parse error at byte 6: syntax error while parsing BJData value: unexpected end of input", json::parse_error&); CHECK(json::from_bjdata(v, true, false).is_discarded()); } SECTION("ndarrays") { - std::vector vST = {'[', '$', 'i', '#', '[', '$', 'i', '#'}; + std::vector const vST = {'[', '$', 'i', '#', '[', '$', 'i', '#'}; json _; CHECK_THROWS_WITH_AS(_ = json::from_bjdata(vST), "[json.exception.parse_error.113] parse error at byte 9: syntax error while parsing BJData size: expected length type specification (U, i, u, I, m, l, M, L) after '#'; last byte: 0xFF", json::parse_error&); CHECK(json::from_bjdata(vST, true, false).is_discarded()); - std::vector v = {'[', '$', 'i', '#', '[', '$', 'i', '#', 'i', 2, 1, 2}; + std::vector const v = {'[', '$', 'i', '#', '[', '$', 'i', '#', 'i', 2, 1, 2}; CHECK_THROWS_WITH_AS(_ = json::from_bjdata(v), "[json.exception.parse_error.110] parse error at byte 13: syntax error while parsing BJData number: unexpected end of input", json::parse_error&); CHECK(json::from_bjdata(v, true, false).is_discarded()); - std::vector vS0 = {'[', '$', 'i', '#', '[', '$', 'i', '#', 'i', 2, 1}; + std::vector const vS0 = {'[', '$', 'i', '#', '[', '$', 'i', '#', 'i', 2, 1}; CHECK_THROWS_WITH_AS(_ = json::from_bjdata(vS0), "[json.exception.parse_error.110] parse error at byte 12: syntax error while parsing BJData number: unexpected end of input", json::parse_error&); CHECK(json::from_bjdata(vS0, true, false).is_discarded()); - std::vector vS = {'[', '$', 'i', '#', '[', '#', 'i', 2, 1, 2, 1}; + std::vector const vS = {'[', '$', 'i', '#', '[', '#', 'i', 2, 1, 2, 1}; CHECK_THROWS_WITH_AS(_ = json::from_bjdata(vS), "[json.exception.parse_error.113] parse error at byte 9: syntax error while parsing BJData size: expected length type specification (U, i, u, I, m, l, M, L) after '#'; last byte: 0x01", json::parse_error&); CHECK(json::from_bjdata(vS, true, false).is_discarded()); - std::vector vT = {'[', '$', 'i', '#', '[', 'i', 2, 'i'}; + std::vector const vT = {'[', '$', 'i', '#', '[', 'i', 2, 'i'}; CHECK_THROWS_WITH_AS(_ = json::from_bjdata(vT), "[json.exception.parse_error.110] parse error at byte 9: syntax error while parsing BJData number: unexpected end of input", json::parse_error&); CHECK(json::from_bjdata(vT, true, false).is_discarded()); - std::vector vT0 = {'[', '$', 'i', '#', '[', 'i'}; + std::vector const vT0 = {'[', '$', 'i', '#', '[', 'i'}; CHECK_THROWS_WITH_AS(_ = json::from_bjdata(vT0), "[json.exception.parse_error.110] parse error at byte 7: syntax error while parsing BJData number: unexpected end of input", json::parse_error&); CHECK(json::from_bjdata(vT0, true, false).is_discarded()); - std::vector vu = {'[', '$', 'i', '#', '[', '$', 'i', '#', 'u', 1, 0}; + std::vector const vu = {'[', '$', 'i', '#', '[', '$', 'i', '#', 'u', 1, 0}; CHECK_THROWS_WITH_AS(_ = json::from_bjdata(vu), "[json.exception.parse_error.110] parse error at byte 12: syntax error while parsing BJData number: unexpected end of input", json::parse_error&); CHECK(json::from_bjdata(vu, true, false).is_discarded()); - std::vector vm = {'[', '$', 'i', '#', '[', '$', 'i', '#', 'm', 1, 0, 0, 0}; + std::vector const vm = {'[', '$', 'i', '#', '[', '$', 'i', '#', 'm', 1, 0, 0, 0}; CHECK_THROWS_WITH_AS(_ = json::from_bjdata(vm), "[json.exception.parse_error.110] parse error at byte 14: syntax error while parsing BJData number: unexpected end of input", json::parse_error&); CHECK(json::from_bjdata(vm, true, false).is_discarded()); - std::vector vM = {'[', '$', 'i', '#', '[', '$', 'i', '#', 'M', 1, 0, 0, 0, 0, 0, 0, 0}; + std::vector const vM = {'[', '$', 'i', '#', '[', '$', 'i', '#', 'M', 1, 0, 0, 0, 0, 0, 0, 0}; CHECK_THROWS_WITH_AS(_ = json::from_bjdata(vM), "[json.exception.parse_error.110] parse error at byte 18: syntax error while parsing BJData number: unexpected end of input", json::parse_error&); CHECK(json::from_bjdata(vM, true, false).is_discarded()); - std::vector vU = {'[', '$', 'U', '#', '[', '$', 'i', '#', 'i', 2, 2, 3, 1, 2, 3, 4, 5}; + std::vector const vU = {'[', '$', 'U', '#', '[', '$', 'i', '#', 'i', 2, 2, 3, 1, 2, 3, 4, 5}; CHECK_THROWS_WITH_AS(_ = json::from_bjdata(vU), "[json.exception.parse_error.110] parse error at byte 18: syntax error while parsing BJData number: unexpected end of input", json::parse_error&); CHECK(json::from_bjdata(vU, true, false).is_discarded()); - std::vector vT1 = {'[', '$', 'T', '#', '[', '$', 'i', '#', 'i', 2, 2, 3}; + std::vector const vT1 = {'[', '$', 'T', '#', '[', '$', 'i', '#', 'i', 2, 2, 3}; CHECK(json::from_bjdata(vT1, true, false).is_discarded()); - std::vector vh = {'[', '$', 'h', '#', '[', '$', 'i', '#', 'i', 2, 2, 3}; + std::vector const vh = {'[', '$', 'h', '#', '[', '$', 'i', '#', 'i', 2, 2, 3}; CHECK(json::from_bjdata(vh, true, false).is_discarded()); - std::vector vR = {'[', '$', 'i', '#', '[', 'i', 1, '[', ']', ']', 1}; + std::vector const vR = {'[', '$', 'i', '#', '[', 'i', 1, '[', ']', ']', 1}; CHECK_THROWS_WITH_AS(_ = json::from_bjdata(vR), "[json.exception.parse_error.113] parse error at byte 8: syntax error while parsing BJData size: ndarray dimentional vector is not allowed", json::parse_error&); CHECK(json::from_bjdata(vR, true, false).is_discarded()); - std::vector vRo = {'[', '$', 'i', '#', '[', 'i', 0, '{', '}', ']', 1}; + std::vector const vRo = {'[', '$', 'i', '#', '[', 'i', 0, '{', '}', ']', 1}; CHECK_THROWS_WITH_AS(_ = json::from_bjdata(vRo), "[json.exception.parse_error.113] parse error at byte 8: syntax error while parsing BJData size: expected length type specification (U, i, u, I, m, l, M, L) after '#'; last byte: 0x7B", json::parse_error&); CHECK(json::from_bjdata(vRo, true, false).is_discarded()); - std::vector vR1 = {'[', '$', 'i', '#', '[', '[', 'i', 1, ']', ']', 1}; + std::vector const vR1 = {'[', '$', 'i', '#', '[', '[', 'i', 1, ']', ']', 1}; CHECK_THROWS_WITH_AS(_ = json::from_bjdata(vR1), "[json.exception.parse_error.113] parse error at byte 6: syntax error while parsing BJData size: ndarray dimentional vector is not allowed", json::parse_error&); CHECK(json::from_bjdata(vR1, true, false).is_discarded()); - std::vector vR2 = {'[', '$', 'i', '#', '[', '#', '[', 'i', 1, ']', ']', 1}; + std::vector const vR2 = {'[', '$', 'i', '#', '[', '#', '[', 'i', 1, ']', ']', 1}; CHECK_THROWS_WITH_AS(_ = json::from_bjdata(vR2), "[json.exception.parse_error.113] parse error at byte 11: syntax error while parsing BJData size: expected length type specification (U, i, u, I, m, l, M, L) after '#'; last byte: 0x5D", json::parse_error&); CHECK(json::from_bjdata(vR2, true, false).is_discarded()); - std::vector vR3 = {'[', '#', '[', 'i', '2', 'i', 2, ']'}; + std::vector const vR3 = {'[', '#', '[', 'i', '2', 'i', 2, ']'}; CHECK_THROWS_WITH_AS(_ = json::from_bjdata(vR3), "[json.exception.parse_error.112] parse error at byte 8: syntax error while parsing BJData size: ndarray requires both type and size", json::parse_error&); CHECK(json::from_bjdata(vR3, true, false).is_discarded()); - std::vector vR4 = {'[', '$', 'i', '#', '[', '$', 'i', '#', '[', 'i', 1, ']', 1}; + std::vector const vR4 = {'[', '$', 'i', '#', '[', '$', 'i', '#', '[', 'i', 1, ']', 1}; CHECK_THROWS_WITH_AS(_ = json::from_bjdata(vR4), "[json.exception.parse_error.110] parse error at byte 14: syntax error while parsing BJData number: unexpected end of input", json::parse_error&); CHECK(json::from_bjdata(vR4, true, false).is_discarded()); - std::vector vR5 = {'[', '$', 'i', '#', '[', '[', '[', ']', ']', ']'}; + std::vector const vR5 = {'[', '$', 'i', '#', '[', '[', '[', ']', ']', ']'}; CHECK_THROWS_WITH_AS(_ = json::from_bjdata(vR5), "[json.exception.parse_error.113] parse error at byte 6: syntax error while parsing BJData size: ndarray dimentional vector is not allowed", json::parse_error&); CHECK(json::from_bjdata(vR5, true, false).is_discarded()); - std::vector vR6 = {'[', '$', 'i', '#', '[', '$', 'i', '#', '[', 'i', '2', 'i', 2, ']'}; + std::vector const vR6 = {'[', '$', 'i', '#', '[', '$', 'i', '#', '[', 'i', '2', 'i', 2, ']'}; CHECK_THROWS_WITH_AS(_ = json::from_bjdata(vR6), "[json.exception.parse_error.112] parse error at byte 14: syntax error while parsing BJData size: ndarray can not be recursive", json::parse_error&); CHECK(json::from_bjdata(vR6, true, false).is_discarded()); - std::vector vH = {'[', 'H', '[', '#', '[', '$', 'i', '#', '[', 'i', '2', 'i', 2, ']'}; + std::vector const vH = {'[', 'H', '[', '#', '[', '$', 'i', '#', '[', 'i', '2', 'i', 2, ']'}; CHECK_THROWS_WITH_AS(_ = json::from_bjdata(vH), "[json.exception.parse_error.113] parse error at byte 3: syntax error while parsing BJData size: ndarray dimentional vector is not allowed", json::parse_error&); CHECK(json::from_bjdata(vH, true, false).is_discarded()); } SECTION("objects") { - std::vector vST = {'{', '$', 'i', '#', 'i', 2, 'i', 1, 'a', 1}; + std::vector const vST = {'{', '$', 'i', '#', 'i', 2, 'i', 1, 'a', 1}; json _; CHECK_THROWS_WITH_AS(_ = json::from_bjdata(vST), "[json.exception.parse_error.110] parse error at byte 11: syntax error while parsing BJData value: unexpected end of input", json::parse_error&); CHECK(json::from_bjdata(vST, true, false).is_discarded()); - std::vector vT = {'{', '$', 'i', 'i', 1, 'a', 1}; + std::vector const vT = {'{', '$', 'i', 'i', 1, 'a', 1}; CHECK_THROWS_WITH(_ = json::from_bjdata(vT), "[json.exception.parse_error.112] parse error at byte 4: syntax error while parsing BJData size: expected '#' after type information; last byte: 0x69"); CHECK(json::from_bjdata(vT, true, false).is_discarded()); - std::vector vS = {'{', '#', 'i', 2, 'i', 1, 'a', 'i', 1}; + std::vector const vS = {'{', '#', 'i', 2, 'i', 1, 'a', 'i', 1}; CHECK_THROWS_WITH_AS(_ = json::from_bjdata(vS), "[json.exception.parse_error.110] parse error at byte 10: syntax error while parsing BJData value: unexpected end of input", json::parse_error&); CHECK(json::from_bjdata(vS, true, false).is_discarded()); - std::vector v = {'{', 'i', 1, 'a', 'i', 1}; + std::vector const v = {'{', 'i', 1, 'a', 'i', 1}; CHECK_THROWS_WITH_AS(_ = json::from_bjdata(v), "[json.exception.parse_error.110] parse error at byte 7: syntax error while parsing BJData value: unexpected end of input", json::parse_error&); CHECK(json::from_bjdata(v, true, false).is_discarded()); - std::vector v2 = {'{', 'i', 1, 'a', 'i', 1, 'i'}; + std::vector const v2 = {'{', 'i', 1, 'a', 'i', 1, 'i'}; CHECK_THROWS_WITH_AS(_ = json::from_bjdata(v2), "[json.exception.parse_error.110] parse error at byte 8: syntax error while parsing BJData number: unexpected end of input", json::parse_error&); CHECK(json::from_bjdata(v2, true, false).is_discarded()); - std::vector v3 = {'{', 'i', 1, 'a'}; + std::vector const v3 = {'{', 'i', 1, 'a'}; CHECK_THROWS_WITH_AS(_ = json::from_bjdata(v3), "[json.exception.parse_error.110] parse error at byte 5: syntax error while parsing BJData value: unexpected end of input", json::parse_error&); CHECK(json::from_bjdata(v3, true, false).is_discarded()); - std::vector vST1 = {'{', '$', 'd', '#', 'i', 2, 'i', 1, 'a'}; + std::vector const vST1 = {'{', '$', 'd', '#', 'i', 2, 'i', 1, 'a'}; CHECK_THROWS_WITH_AS(_ = json::from_bjdata(vST1), "[json.exception.parse_error.110] parse error at byte 10: syntax error while parsing BJData number: unexpected end of input", json::parse_error&); CHECK(json::from_bjdata(vST1, true, false).is_discarded()); - std::vector vST2 = {'{', '#', 'i', 2, 'i', 1, 'a'}; + std::vector const vST2 = {'{', '#', 'i', 2, 'i', 1, 'a'}; CHECK_THROWS_WITH_AS(_ = json::from_bjdata(vST2), "[json.exception.parse_error.110] parse error at byte 8: syntax error while parsing BJData value: unexpected end of input", json::parse_error&); CHECK(json::from_bjdata(vST2, true, false).is_discarded()); - std::vector vO = {'{', '#', '[', 'i', 2, 'i', 1, ']', 'i', 1, 'a', 'i', 1, 'i', 1, 'b', 'i', 2}; + std::vector const vO = {'{', '#', '[', 'i', 2, 'i', 1, ']', 'i', 1, 'a', 'i', 1, 'i', 1, 'b', 'i', 2}; CHECK_THROWS_WITH_AS(_ = json::from_bjdata(vO), "[json.exception.parse_error.112] parse error at byte 8: syntax error while parsing BJData size: ndarray requires both type and size", json::parse_error&); CHECK(json::from_bjdata(vO, true, false).is_discarded()); - std::vector vO2 = {'{', '$', 'i', '#', '[', 'i', 2, 'i', 1, ']', 'i', 1, 'a', 1, 'i', 1, 'b', 2}; + std::vector const vO2 = {'{', '$', 'i', '#', '[', 'i', 2, 'i', 1, ']', 'i', 1, 'a', 1, 'i', 1, 'b', 2}; CHECK_THROWS_WITH_AS(_ = json::from_bjdata(vO2), "[json.exception.parse_error.112] parse error at byte 10: syntax error while parsing BJData object: BJData object does not support ND-array size in optimized format", json::parse_error&); CHECK(json::from_bjdata(vO2, true, false).is_discarded()); } @@ -2966,50 +2999,50 @@ TEST_CASE("BJData") { SECTION("array of i") { - json j = {1, -1}; - std::vector expected = {'[', '$', 'i', '#', 'i', 2, 1, 0xff}; + json const j = {1, -1}; + std::vector const expected = {'[', '$', 'i', '#', 'i', 2, 1, 0xff}; CHECK(json::to_bjdata(j, true, true) == expected); } SECTION("array of U") { - json j = {200, 201}; - std::vector expected = {'[', '$', 'U', '#', 'i', 2, 0xC8, 0xC9}; + json const j = {200, 201}; + std::vector const expected = {'[', '$', 'U', '#', 'i', 2, 0xC8, 0xC9}; CHECK(json::to_bjdata(j, true, true) == expected); } SECTION("array of I") { - json j = {30000, -30000}; - std::vector expected = {'[', '$', 'I', '#', 'i', 2, 0x30, 0x75, 0xd0, 0x8a}; + json const j = {30000, -30000}; + std::vector const expected = {'[', '$', 'I', '#', 'i', 2, 0x30, 0x75, 0xd0, 0x8a}; CHECK(json::to_bjdata(j, true, true) == expected); } SECTION("array of u") { - json j = {50000, 50001}; - std::vector expected = {'[', '$', 'u', '#', 'i', 2, 0x50, 0xC3, 0x51, 0xC3}; + json const j = {50000, 50001}; + std::vector const expected = {'[', '$', 'u', '#', 'i', 2, 0x50, 0xC3, 0x51, 0xC3}; CHECK(json::to_bjdata(j, true, true) == expected); } SECTION("array of l") { - json j = {70000, -70000}; - std::vector expected = {'[', '$', 'l', '#', 'i', 2, 0x70, 0x11, 0x01, 0x00, 0x90, 0xEE, 0xFE, 0xFF}; + json const j = {70000, -70000}; + std::vector const expected = {'[', '$', 'l', '#', 'i', 2, 0x70, 0x11, 0x01, 0x00, 0x90, 0xEE, 0xFE, 0xFF}; CHECK(json::to_bjdata(j, true, true) == expected); } SECTION("array of m") { - json j = {3147483647, 3147483648}; - std::vector expected = {'[', '$', 'm', '#', 'i', 2, 0xFF, 0xC9, 0x9A, 0xBB, 0x00, 0xCA, 0x9A, 0xBB}; + json const j = {3147483647, 3147483648}; + std::vector const expected = {'[', '$', 'm', '#', 'i', 2, 0xFF, 0xC9, 0x9A, 0xBB, 0x00, 0xCA, 0x9A, 0xBB}; CHECK(json::to_bjdata(j, true, true) == expected); } SECTION("array of L") { - json j = {5000000000, -5000000000}; - std::vector expected = {'[', '$', 'L', '#', 'i', 2, 0x00, 0xF2, 0x05, 0x2A, 0x01, 0x00, 0x00, 0x00, 0x00, 0x0E, 0xFA, 0xD5, 0xFE, 0xFF, 0xFF, 0xFF}; + json const j = {5000000000, -5000000000}; + std::vector const expected = {'[', '$', 'L', '#', 'i', 2, 0x00, 0xF2, 0x05, 0x2A, 0x01, 0x00, 0x00, 0x00, 0x00, 0x0E, 0xFA, 0xD5, 0xFE, 0xFF, 0xFF, 0xFF}; CHECK(json::to_bjdata(j, true, true) == expected); } } @@ -3018,72 +3051,72 @@ TEST_CASE("BJData") { SECTION("array of i") { - json j = {1u, 2u}; - std::vector expected = {'[', '$', 'i', '#', 'i', 2, 1, 2}; - std::vector expected_size = {'[', '#', 'i', 2, 'i', 1, 'i', 2}; + json const j = {1u, 2u}; + std::vector const expected = {'[', '$', 'i', '#', 'i', 2, 1, 2}; + std::vector const expected_size = {'[', '#', 'i', 2, 'i', 1, 'i', 2}; CHECK(json::to_bjdata(j, true, true) == expected); CHECK(json::to_bjdata(j, true) == expected_size); } SECTION("array of U") { - json j = {200u, 201u}; - std::vector expected = {'[', '$', 'U', '#', 'i', 2, 0xC8, 0xC9}; - std::vector expected_size = {'[', '#', 'i', 2, 'U', 0xC8, 'U', 0xC9}; + json const j = {200u, 201u}; + std::vector const expected = {'[', '$', 'U', '#', 'i', 2, 0xC8, 0xC9}; + std::vector const expected_size = {'[', '#', 'i', 2, 'U', 0xC8, 'U', 0xC9}; CHECK(json::to_bjdata(j, true, true) == expected); CHECK(json::to_bjdata(j, true) == expected_size); } SECTION("array of I") { - json j = {30000u, 30001u}; - std::vector expected = {'[', '$', 'I', '#', 'i', 2, 0x30, 0x75, 0x31, 0x75}; - std::vector expected_size = {'[', '#', 'i', 2, 'I', 0x30, 0x75, 'I', 0x31, 0x75}; + json const j = {30000u, 30001u}; + std::vector const expected = {'[', '$', 'I', '#', 'i', 2, 0x30, 0x75, 0x31, 0x75}; + std::vector const expected_size = {'[', '#', 'i', 2, 'I', 0x30, 0x75, 'I', 0x31, 0x75}; CHECK(json::to_bjdata(j, true, true) == expected); CHECK(json::to_bjdata(j, true) == expected_size); } SECTION("array of u") { - json j = {50000u, 50001u}; - std::vector expected = {'[', '$', 'u', '#', 'i', 2, 0x50, 0xC3, 0x51, 0xC3}; - std::vector expected_size = {'[', '#', 'i', 2, 'u', 0x50, 0xC3, 'u', 0x51, 0xC3}; + json const j = {50000u, 50001u}; + std::vector const expected = {'[', '$', 'u', '#', 'i', 2, 0x50, 0xC3, 0x51, 0xC3}; + std::vector const expected_size = {'[', '#', 'i', 2, 'u', 0x50, 0xC3, 'u', 0x51, 0xC3}; CHECK(json::to_bjdata(j, true, true) == expected); CHECK(json::to_bjdata(j, true) == expected_size); } SECTION("array of l") { - json j = {70000u, 70001u}; - std::vector expected = {'[', '$', 'l', '#', 'i', 2, 0x70, 0x11, 0x01, 0x00, 0x71, 0x11, 0x01, 0x00}; - std::vector expected_size = {'[', '#', 'i', 2, 'l', 0x70, 0x11, 0x01, 0x00, 'l', 0x71, 0x11, 0x01, 0x00}; + json const j = {70000u, 70001u}; + std::vector const expected = {'[', '$', 'l', '#', 'i', 2, 0x70, 0x11, 0x01, 0x00, 0x71, 0x11, 0x01, 0x00}; + std::vector const expected_size = {'[', '#', 'i', 2, 'l', 0x70, 0x11, 0x01, 0x00, 'l', 0x71, 0x11, 0x01, 0x00}; CHECK(json::to_bjdata(j, true, true) == expected); CHECK(json::to_bjdata(j, true) == expected_size); } SECTION("array of m") { - json j = {3147483647u, 3147483648u}; - std::vector expected = {'[', '$', 'm', '#', 'i', 2, 0xFF, 0xC9, 0x9A, 0xBB, 0x00, 0xCA, 0x9A, 0xBB}; - std::vector expected_size = {'[', '#', 'i', 2, 'm', 0xFF, 0xC9, 0x9A, 0xBB, 'm', 0x00, 0xCA, 0x9A, 0xBB}; + json const j = {3147483647u, 3147483648u}; + std::vector const expected = {'[', '$', 'm', '#', 'i', 2, 0xFF, 0xC9, 0x9A, 0xBB, 0x00, 0xCA, 0x9A, 0xBB}; + std::vector const expected_size = {'[', '#', 'i', 2, 'm', 0xFF, 0xC9, 0x9A, 0xBB, 'm', 0x00, 0xCA, 0x9A, 0xBB}; CHECK(json::to_bjdata(j, true, true) == expected); CHECK(json::to_bjdata(j, true) == expected_size); } SECTION("array of L") { - json j = {5000000000u, 5000000001u}; - std::vector expected = {'[', '$', 'L', '#', 'i', 2, 0x00, 0xF2, 0x05, 0x2A, 0x01, 0x00, 0x00, 0x00, 0x01, 0xF2, 0x05, 0x2A, 0x01, 0x00, 0x00, 0x00}; - std::vector expected_size = {'[', '#', 'i', 2, 'L', 0x00, 0xF2, 0x05, 0x2A, 0x01, 0x00, 0x00, 0x00, 'L', 0x01, 0xF2, 0x05, 0x2A, 0x01, 0x00, 0x00, 0x00}; + json const j = {5000000000u, 5000000001u}; + std::vector const expected = {'[', '$', 'L', '#', 'i', 2, 0x00, 0xF2, 0x05, 0x2A, 0x01, 0x00, 0x00, 0x00, 0x01, 0xF2, 0x05, 0x2A, 0x01, 0x00, 0x00, 0x00}; + std::vector const expected_size = {'[', '#', 'i', 2, 'L', 0x00, 0xF2, 0x05, 0x2A, 0x01, 0x00, 0x00, 0x00, 'L', 0x01, 0xF2, 0x05, 0x2A, 0x01, 0x00, 0x00, 0x00}; CHECK(json::to_bjdata(j, true, true) == expected); CHECK(json::to_bjdata(j, true) == expected_size); } SECTION("array of M") { - json j = {10223372036854775807ull, 10223372036854775808ull}; - std::vector expected = {'[', '$', 'M', '#', 'i', 2, 0xFF, 0xFF, 0x63, 0xA7, 0xB3, 0xB6, 0xE0, 0x8D, 0x00, 0x00, 0x64, 0xA7, 0xB3, 0xB6, 0xE0, 0x8D}; - std::vector expected_size = {'[', '#', 'i', 2, 'M', 0xFF, 0xFF, 0x63, 0xA7, 0xB3, 0xB6, 0xE0, 0x8D, 'M', 0x00, 0x00, 0x64, 0xA7, 0xB3, 0xB6, 0xE0, 0x8D}; + json const j = {10223372036854775807ull, 10223372036854775808ull}; + std::vector const expected = {'[', '$', 'M', '#', 'i', 2, 0xFF, 0xFF, 0x63, 0xA7, 0xB3, 0xB6, 0xE0, 0x8D, 0x00, 0x00, 0x64, 0xA7, 0xB3, 0xB6, 0xE0, 0x8D}; + std::vector const expected_size = {'[', '#', 'i', 2, 'M', 0xFF, 0xFF, 0x63, 0xA7, 0xB3, 0xB6, 0xE0, 0x8D, 'M', 0x00, 0x00, 0x64, 0xA7, 0xB3, 0xB6, 0xE0, 0x8D}; CHECK(json::to_bjdata(j, true, true) == expected); CHECK(json::to_bjdata(j, true) == expected_size); } @@ -3095,7 +3128,7 @@ TEST_CASE("Universal Binary JSON Specification Examples 1") { SECTION("Null Value") { - json j = {{"passcode", nullptr}}; + json const j = {{"passcode", nullptr}}; std::vector v = {'{', 'i', 8, 'p', 'a', 's', 's', 'c', 'o', 'd', 'e', 'Z', '}'}; CHECK(json::to_bjdata(j) == v); CHECK(json::from_bjdata(v) == j); @@ -3103,15 +3136,15 @@ TEST_CASE("Universal Binary JSON Specification Examples 1") SECTION("No-Op Value") { - json j = {"foo", "bar", "baz"}; + json const j = {"foo", "bar", "baz"}; std::vector v = {'[', 'S', 'i', 3, 'f', 'o', 'o', 'S', 'i', 3, 'b', 'a', 'r', 'S', 'i', 3, 'b', 'a', 'z', ']' }; - std::vector v2 = {'[', 'S', 'i', 3, 'f', 'o', 'o', 'N', - 'S', 'i', 3, 'b', 'a', 'r', 'N', 'N', 'N', - 'S', 'i', 3, 'b', 'a', 'z', 'N', 'N', ']' - }; + std::vector const v2 = {'[', 'S', 'i', 3, 'f', 'o', 'o', 'N', + 'S', 'i', 3, 'b', 'a', 'r', 'N', 'N', 'N', + 'S', 'i', 3, 'b', 'a', 'z', 'N', 'N', ']' + }; CHECK(json::to_bjdata(j) == v); CHECK(json::from_bjdata(v) == j); CHECK(json::from_bjdata(v2) == j); @@ -3119,7 +3152,7 @@ TEST_CASE("Universal Binary JSON Specification Examples 1") SECTION("Boolean Types") { - json j = {{"authorized", true}, {"verified", false}}; + json const j = {{"authorized", true}, {"verified", false}}; std::vector v = {'{', 'i', 10, 'a', 'u', 't', 'h', 'o', 'r', 'i', 'z', 'e', 'd', 'T', 'i', 8, 'v', 'e', 'r', 'i', 'f', 'i', 'e', 'd', 'F', '}' }; @@ -3159,8 +3192,8 @@ TEST_CASE("Universal Binary JSON Specification Examples 1") SECTION("Char Type") { - json j = {{"rolecode", "a"}, {"delim", ";"}}; - std::vector v = {'{', 'i', 5, 'd', 'e', 'l', 'i', 'm', 'C', ';', 'i', 8, 'r', 'o', 'l', 'e', 'c', 'o', 'd', 'e', 'C', 'a', '}'}; + json const j = {{"rolecode", "a"}, {"delim", ";"}}; + std::vector const v = {'{', 'i', 5, 'd', 'e', 'l', 'i', 'm', 'C', ';', 'i', 8, 'r', 'o', 'l', 'e', 'c', 'o', 'd', 'e', 'C', 'a', '}'}; //CHECK(json::to_bjdata(j) == v); CHECK(json::from_bjdata(v) == j); } @@ -3169,7 +3202,7 @@ TEST_CASE("Universal Binary JSON Specification Examples 1") { SECTION("English") { - json j = "hello"; + json const j = "hello"; std::vector v = {'S', 'i', 5, 'h', 'e', 'l', 'l', 'o'}; CHECK(json::to_bjdata(j) == v); CHECK(json::from_bjdata(v) == j); @@ -3177,7 +3210,7 @@ TEST_CASE("Universal Binary JSON Specification Examples 1") SECTION("Russian") { - json j = "привет"; + json const j = "привет"; std::vector v = {'S', 'i', 12, 0xD0, 0xBF, 0xD1, 0x80, 0xD0, 0xB8, 0xD0, 0xB2, 0xD0, 0xB5, 0xD1, 0x82}; CHECK(json::to_bjdata(j) == v); CHECK(json::from_bjdata(v) == j); @@ -3185,7 +3218,7 @@ TEST_CASE("Universal Binary JSON Specification Examples 1") SECTION("Russian") { - json j = "مرحبا"; + json const j = "مرحبا"; std::vector v = {'S', 'i', 10, 0xD9, 0x85, 0xD8, 0xB1, 0xD8, 0xAD, 0xD8, 0xA8, 0xD8, 0xA7}; CHECK(json::to_bjdata(j) == v); CHECK(json::from_bjdata(v) == j); @@ -3197,7 +3230,7 @@ TEST_CASE("Universal Binary JSON Specification Examples 1") SECTION("size=false type=false") { // note the float has been replaced by a double - json j = {nullptr, true, false, 4782345193, 153.132, "ham"}; + json const j = {nullptr, true, false, 4782345193, 153.132, "ham"}; std::vector v = {'[', 'Z', 'T', 'F', 'L', 0xE9, 0xCB, 0x0C, 0x1D, 0x01, 0x00, 0x00, 0x00, 'D', 0x4e, 0x62, 0x10, 0x58, 0x39, 0x24, 0x63, 0x40, 'S', 'i', 3, 'h', 'a', 'm', ']'}; CHECK(json::to_bjdata(j) == v); CHECK(json::from_bjdata(v) == j); @@ -3206,7 +3239,7 @@ TEST_CASE("Universal Binary JSON Specification Examples 1") SECTION("size=true type=false") { // note the float has been replaced by a double - json j = {nullptr, true, false, 4782345193, 153.132, "ham"}; + json const j = {nullptr, true, false, 4782345193, 153.132, "ham"}; std::vector v = {'[', '#', 'i', 6, 'Z', 'T', 'F', 'L', 0xE9, 0xCB, 0x0C, 0x1D, 0x01, 0x00, 0x00, 0x00, 'D', 0x4e, 0x62, 0x10, 0x58, 0x39, 0x24, 0x63, 0x40, 'S', 'i', 3, 'h', 'a', 'm'}; CHECK(json::to_bjdata(j, true) == v); CHECK(json::from_bjdata(v) == j); @@ -3215,7 +3248,7 @@ TEST_CASE("Universal Binary JSON Specification Examples 1") SECTION("size=true type=true") { // note the float has been replaced by a double - json j = {nullptr, true, false, 4782345193, 153.132, "ham"}; + json const j = {nullptr, true, false, 4782345193, 153.132, "ham"}; std::vector v = {'[', '#', 'i', 6, 'Z', 'T', 'F', 'L', 0xE9, 0xCB, 0x0C, 0x1D, 0x01, 0x00, 0x00, 0x00, 'D', 0x4e, 0x62, 0x10, 0x58, 0x39, 0x24, 0x63, 0x40, 'S', 'i', 3, 'h', 'a', 'm'}; CHECK(json::to_bjdata(j, true, true) == v); CHECK(json::from_bjdata(v) == j); @@ -3302,7 +3335,7 @@ TEST_CASE("Universal Binary JSON Specification Examples 1") SECTION("No Optimization") { // note the floats have been replaced by doubles - json j = {29.97, 31.13, 67.0, 2.113, 23.888}; + json const j = {29.97, 31.13, 67.0, 2.113, 23.888}; std::vector v = {'[', 'D', 0xb8, 0x1e, 0x85, 0xeb, 0x51, 0xf8, 0x3d, 0x40, 'D', 0xe1, 0x7a, 0x14, 0xae, 0x47, 0x21, 0x3f, 0x40, @@ -3318,7 +3351,7 @@ TEST_CASE("Universal Binary JSON Specification Examples 1") SECTION("Optimized with count") { // note the floats have been replaced by doubles - json j = {29.97, 31.13, 67.0, 2.113, 23.888}; + json const j = {29.97, 31.13, 67.0, 2.113, 23.888}; std::vector v = {'[', '#', 'i', 5, 'D', 0xb8, 0x1e, 0x85, 0xeb, 0x51, 0xf8, 0x3d, 0x40, 'D', 0xe1, 0x7a, 0x14, 0xae, 0x47, 0x21, 0x3f, 0x40, @@ -3333,7 +3366,7 @@ TEST_CASE("Universal Binary JSON Specification Examples 1") SECTION("Optimized with type & count") { // note the floats have been replaced by doubles - json j = {29.97, 31.13, 67.0, 2.113, 23.888}; + json const j = {29.97, 31.13, 67.0, 2.113, 23.888}; std::vector v = {'[', '$', 'D', '#', 'i', 5, 0xb8, 0x1e, 0x85, 0xeb, 0x51, 0xf8, 0x3d, 0x40, 0xe1, 0x7a, 0x14, 0xae, 0x47, 0x21, 0x3f, 0x40, @@ -3351,7 +3384,7 @@ TEST_CASE("Universal Binary JSON Specification Examples 1") SECTION("No Optimization") { // note the floats have been replaced by doubles - json j = { {"lat", 29.976}, {"long", 31.131}, {"alt", 67.0} }; + json const j = { {"lat", 29.976}, {"long", 31.131}, {"alt", 67.0} }; std::vector v = {'{', 'i', 3, 'a', 'l', 't', 'D', 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x50, 0x40, 'i', 3, 'l', 'a', 't', 'D', 0x60, 0xe5, 0xd0, 0x22, 0xdb, 0xf9, 0x3d, 0x40, @@ -3365,7 +3398,7 @@ TEST_CASE("Universal Binary JSON Specification Examples 1") SECTION("Optimized with count") { // note the floats have been replaced by doubles - json j = { {"lat", 29.976}, {"long", 31.131}, {"alt", 67.0} }; + json const j = { {"lat", 29.976}, {"long", 31.131}, {"alt", 67.0} }; std::vector v = {'{', '#', 'i', 3, 'i', 3, 'a', 'l', 't', 'D', 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x50, 0x40, 'i', 3, 'l', 'a', 't', 'D', 0x60, 0xe5, 0xd0, 0x22, 0xdb, 0xf9, 0x3d, 0x40, @@ -3378,7 +3411,7 @@ TEST_CASE("Universal Binary JSON Specification Examples 1") SECTION("Optimized with type & count") { // note the floats have been replaced by doubles - json j = { {"lat", 29.976}, {"long", 31.131}, {"alt", 67.0} }; + json const j = { {"lat", 29.976}, {"long", 31.131}, {"alt", 67.0} }; std::vector v = {'{', '$', 'D', '#', 'i', 3, 'i', 3, 'a', 'l', 't', 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x50, 0x40, 'i', 3, 'l', 'a', 't', 0x60, 0xe5, 0xd0, 0x22, 0xdb, 0xf9, 0x3d, 0x40, @@ -3394,7 +3427,7 @@ TEST_CASE("Universal Binary JSON Specification Examples 1") SECTION("Array") { json _; - std::vector v = {'[', '$', 'N', '#', 'I', 0x00, 0x02}; + std::vector const v = {'[', '$', 'N', '#', 'I', 0x00, 0x02}; CHECK_THROWS_WITH_AS(_ = json::from_bjdata(v), "[json.exception.parse_error.112] parse error at byte 3: syntax error while parsing BJData type: marker 0x4E is not a permitted optimized array type", json::parse_error&); CHECK(json::from_bjdata(v, true, false).is_discarded()); } @@ -3402,7 +3435,7 @@ TEST_CASE("Universal Binary JSON Specification Examples 1") SECTION("Object") { json _; - std::vector v = {'{', '$', 'Z', '#', 'i', 3, 'i', 4, 'n', 'a', 'm', 'e', 'i', 8, 'p', 'a', 's', 's', 'w', 'o', 'r', 'd', 'i', 5, 'e', 'm', 'a', 'i', 'l'}; + std::vector const v = {'{', '$', 'Z', '#', 'i', 3, 'i', 4, 'n', 'a', 'm', 'e', 'i', 8, 'p', 'a', 's', 's', 'w', 'o', 'r', 'd', 'i', 5, 'e', 'm', 'a', 'i', 'l'}; CHECK_THROWS_WITH_AS(_ = json::from_bjdata(v), "[json.exception.parse_error.112] parse error at byte 3: syntax error while parsing BJData type: marker 0x5A is not a permitted optimized array type", json::parse_error&); CHECK(json::from_bjdata(v, true, false).is_discarded()); } @@ -3450,7 +3483,7 @@ TEST_CASE("BJData roundtrips" * doctest::skip()) { SECTION("input from self-generated BJData files") { - for (std::string filename : + for (const std::string filename : { TEST_DATA_DIRECTORY "/json_nlohmann_tests/all_unicode.json", TEST_DATA_DIRECTORY "/json.org/1.json", @@ -3532,7 +3565,7 @@ TEST_CASE("BJData 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 BJData file auto packed = utils::read_binary_file(filename + ".bjdata"); diff --git a/tests/src/unit-bson.cpp b/tests/src/unit-bson.cpp index a231c8cca..895b89d87 100644 --- a/tests/src/unit-bson.cpp +++ b/tests/src/unit-bson.cpp @@ -22,7 +22,7 @@ TEST_CASE("BSON") { SECTION("null") { - json j = nullptr; + json const j = nullptr; CHECK_THROWS_WITH_AS(json::to_bson(j), "[json.exception.type_error.317] to serialize to BSON, top-level type must be object, but is null", json::type_error&); } @@ -30,45 +30,45 @@ TEST_CASE("BSON") { SECTION("true") { - json j = true; + json const j = true; CHECK_THROWS_WITH_AS(json::to_bson(j), "[json.exception.type_error.317] to serialize to BSON, top-level type must be object, but is boolean", json::type_error&); } SECTION("false") { - json j = false; + json const j = false; CHECK_THROWS_WITH_AS(json::to_bson(j), "[json.exception.type_error.317] to serialize to BSON, top-level type must be object, but is boolean", json::type_error&); } } SECTION("number") { - json j = 42; + json const j = 42; CHECK_THROWS_WITH_AS(json::to_bson(j), "[json.exception.type_error.317] to serialize to BSON, top-level type must be object, but is number", json::type_error&); } SECTION("float") { - json j = 4.2; + json const j = 4.2; CHECK_THROWS_WITH_AS(json::to_bson(j), "[json.exception.type_error.317] to serialize to BSON, top-level type must be object, but is number", json::type_error&); } SECTION("string") { - json j = "not supported"; + json const j = "not supported"; CHECK_THROWS_WITH_AS(json::to_bson(j), "[json.exception.type_error.317] to serialize to BSON, top-level type must be object, but is string", json::type_error&); } SECTION("array") { - json j = std::vector {1, 2, 3, 4, 5, 6, 7}; + json const j = std::vector {1, 2, 3, 4, 5, 6, 7}; CHECK_THROWS_WITH_AS(json::to_bson(j), "[json.exception.type_error.317] to serialize to BSON, top-level type must be object, but is array", json::type_error&); } } SECTION("keys containing code-point U+0000 cannot be serialized to BSON") { - json j = + json const j = { { std::string("en\0try", 6), true } }; @@ -82,7 +82,7 @@ TEST_CASE("BSON") SECTION("string length must be at least 1") { // from https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=11175 - std::vector v = + std::vector const v = { 0x20, 0x20, 0x20, 0x20, 0x02, @@ -97,8 +97,8 @@ TEST_CASE("BSON") { SECTION("empty object") { - json j = json::object(); - std::vector expected = + json const j = json::object(); + std::vector const expected = { 0x05, 0x00, 0x00, 0x00, // size (little endian) // no entries @@ -115,12 +115,12 @@ TEST_CASE("BSON") SECTION("non-empty object with bool") { - json j = + json const j = { { "entry", true } }; - std::vector expected = + std::vector const expected = { 0x0D, 0x00, 0x00, 0x00, // size (little endian) 0x08, // entry: boolean @@ -139,12 +139,12 @@ TEST_CASE("BSON") SECTION("non-empty object with bool") { - json j = + json const j = { { "entry", false } }; - std::vector expected = + std::vector const expected = { 0x0D, 0x00, 0x00, 0x00, // size (little endian) 0x08, // entry: boolean @@ -163,12 +163,12 @@ TEST_CASE("BSON") SECTION("non-empty object with double") { - json j = + json const j = { { "entry", 4.2 } }; - std::vector expected = + std::vector const expected = { 0x14, 0x00, 0x00, 0x00, // size (little endian) 0x01, /// entry: double @@ -187,12 +187,12 @@ TEST_CASE("BSON") SECTION("non-empty object with string") { - json j = + json const j = { { "entry", "bsonstr" } }; - std::vector expected = + std::vector const expected = { 0x18, 0x00, 0x00, 0x00, // size (little endian) 0x02, /// entry: string (UTF-8) @@ -211,12 +211,12 @@ TEST_CASE("BSON") SECTION("non-empty object with null member") { - json j = + json const j = { { "entry", nullptr } }; - std::vector expected = + std::vector const expected = { 0x0C, 0x00, 0x00, 0x00, // size (little endian) 0x0A, /// entry: null @@ -234,12 +234,12 @@ TEST_CASE("BSON") SECTION("non-empty object with integer (32-bit) member") { - json j = + json const j = { { "entry", std::int32_t{0x12345678} } }; - std::vector expected = + std::vector const expected = { 0x10, 0x00, 0x00, 0x00, // size (little endian) 0x10, /// entry: int32 @@ -258,12 +258,12 @@ TEST_CASE("BSON") SECTION("non-empty object with integer (64-bit) member") { - json j = + json const j = { { "entry", std::int64_t{0x1234567804030201} } }; - std::vector expected = + std::vector const expected = { 0x14, 0x00, 0x00, 0x00, // size (little endian) 0x12, /// entry: int64 @@ -282,12 +282,12 @@ TEST_CASE("BSON") SECTION("non-empty object with negative integer (32-bit) member") { - json j = + json const j = { { "entry", std::int32_t{-1} } }; - std::vector expected = + std::vector const expected = { 0x10, 0x00, 0x00, 0x00, // size (little endian) 0x10, /// entry: int32 @@ -306,12 +306,12 @@ TEST_CASE("BSON") SECTION("non-empty object with negative integer (64-bit) member") { - json j = + json const j = { { "entry", std::int64_t{-1} } }; - std::vector expected = + std::vector const expected = { 0x10, 0x00, 0x00, 0x00, // size (little endian) 0x10, /// entry: int32 @@ -331,12 +331,12 @@ TEST_CASE("BSON") SECTION("non-empty object with unsigned integer (64-bit) member") { // directly encoding uint64 is not supported in bson (only for timestamp values) - json j = + json const j = { { "entry", std::uint64_t{0x1234567804030201} } }; - std::vector expected = + std::vector const expected = { 0x14, 0x00, 0x00, 0x00, // size (little endian) 0x12, /// entry: int64 @@ -355,12 +355,12 @@ TEST_CASE("BSON") SECTION("non-empty object with small unsigned integer member") { - json j = + json const j = { { "entry", std::uint64_t{0x42} } }; - std::vector expected = + std::vector const expected = { 0x10, 0x00, 0x00, 0x00, // size (little endian) 0x10, /// entry: int32 @@ -379,12 +379,12 @@ TEST_CASE("BSON") SECTION("non-empty object with object member") { - json j = + json const j = { { "entry", json::object() } }; - std::vector expected = + std::vector const expected = { 0x11, 0x00, 0x00, 0x00, // size (little endian) 0x03, /// entry: embedded document @@ -407,12 +407,12 @@ TEST_CASE("BSON") SECTION("non-empty object with array member") { - json j = + json const j = { { "entry", json::array() } }; - std::vector expected = + std::vector const expected = { 0x11, 0x00, 0x00, 0x00, // size (little endian) 0x04, /// entry: embedded document @@ -435,12 +435,12 @@ TEST_CASE("BSON") SECTION("non-empty object with non-empty array member") { - json j = + json const j = { { "entry", json::array({1, 2, 3, 4, 5, 6, 7, 8}) } }; - std::vector expected = + std::vector const expected = { 0x49, 0x00, 0x00, 0x00, // size (little endian) 0x04, /// entry: embedded document @@ -472,12 +472,12 @@ TEST_CASE("BSON") { const size_t N = 10; const auto s = std::vector(N, 'x'); - json j = + json const j = { { "entry", json::binary(s, 0) } }; - std::vector expected = + std::vector const expected = { 0x1B, 0x00, 0x00, 0x00, // size (little endian) 0x05, // entry: binary @@ -502,12 +502,12 @@ TEST_CASE("BSON") { // an MD5 hash const std::vector md5hash = {0xd7, 0x7e, 0x27, 0x54, 0xbe, 0x12, 0x37, 0xfe, 0xd6, 0x0c, 0x33, 0x98, 0x30, 0x3b, 0x8d, 0xc4}; - json j = + json const j = { { "entry", json::binary(md5hash, 5) } }; - std::vector expected = + std::vector const expected = { 0x21, 0x00, 0x00, 0x00, // size (little endian) 0x05, // entry: binary @@ -531,7 +531,7 @@ TEST_CASE("BSON") SECTION("Some more complex document") { // directly encoding uint64 is not supported in bson (only for timestamp values) - json j = + json const j = { {"double", 42.5}, {"entry", 4.2}, @@ -539,7 +539,7 @@ TEST_CASE("BSON") {"object", {{ "string", "value" }}} }; - std::vector expected = + std::vector const expected = { /*size */ 0x4f, 0x00, 0x00, 0x00, /*entry*/ 0x01, 'd', 'o', 'u', 'b', 'l', 'e', 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x45, 0x40, @@ -597,7 +597,7 @@ TEST_CASE("BSON input/output_adapters") {"object", {{ "string", "value" }}} }; - std::vector bson_representation = + std::vector const bson_representation = { /*size */ 0x4f, 0x00, 0x00, 0x00, /*entry*/ 0x01, 'd', 'o', 'u', 'b', 'l', 'e', 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x45, 0x40, @@ -726,7 +726,7 @@ TEST_CASE("Incomplete BSON Input") { SECTION("Incomplete BSON Input 1") { - std::vector incomplete_bson = + std::vector const incomplete_bson = { 0x0D, 0x00, 0x00, 0x00, // size (little endian) 0x08, // entry: boolean @@ -744,7 +744,7 @@ TEST_CASE("Incomplete BSON Input") SECTION("Incomplete BSON Input 2") { - std::vector incomplete_bson = + std::vector const incomplete_bson = { 0x0D, 0x00, 0x00, 0x00, // size (little endian) 0x08, // entry: boolean, unexpected EOF @@ -760,7 +760,7 @@ TEST_CASE("Incomplete BSON Input") SECTION("Incomplete BSON Input 3") { - std::vector incomplete_bson = + std::vector const incomplete_bson = { 0x41, 0x00, 0x00, 0x00, // size (little endian) 0x04, /// entry: embedded document @@ -782,7 +782,7 @@ TEST_CASE("Incomplete BSON Input") SECTION("Incomplete BSON Input 4") { - std::vector incomplete_bson = + std::vector const incomplete_bson = { 0x0D, 0x00, // size (incomplete), unexpected EOF }; @@ -799,7 +799,7 @@ TEST_CASE("Incomplete BSON Input") { SECTION("key") { - json j = {{"key", "value"}}; + json const j = {{"key", "value"}}; auto bson_vec = json::to_bson(j); SaxCountdown scp(2); CHECK(!json::sax_parse(bson_vec, &scp, json::input_format_t::bson)); @@ -807,7 +807,7 @@ TEST_CASE("Incomplete BSON Input") SECTION("array") { - json j = + json const j = { { "entry", json::array() } }; @@ -821,7 +821,7 @@ TEST_CASE("Incomplete BSON Input") TEST_CASE("Negative size of binary value") { // invalid BSON: the size of the binary value is -1 - std::vector input = + std::vector const input = { 0x21, 0x00, 0x00, 0x00, // size (little endian) 0x05, // entry: binary @@ -839,7 +839,7 @@ TEST_CASE("Negative size of binary value") TEST_CASE("Unsupported BSON input") { - std::vector bson = + std::vector const bson = { 0x0C, 0x00, 0x00, 0x00, // size (little endian) 0xFF, // entry type: Min key (not supported yet) @@ -863,7 +863,7 @@ TEST_CASE("BSON numerical data") { SECTION("std::int64_t: INT64_MIN .. INT32_MIN-1") { - std::vector numbers + std::vector const numbers { INT64_MIN, -1000000000000000000LL, @@ -878,19 +878,19 @@ TEST_CASE("BSON numerical data") static_cast(INT32_MIN) - 1, }; - for (auto i : numbers) + for (const auto i : numbers) { CAPTURE(i) - json j = + json const j = { { "entry", i } }; CHECK(j.at("entry").is_number_integer()); - std::uint64_t iu = *reinterpret_cast(&i); - std::vector expected_bson = + std::uint64_t const iu = *reinterpret_cast(&i); + std::vector const expected_bson = { 0x14u, 0x00u, 0x00u, 0x00u, // size (little endian) 0x12u, /// entry: int64 @@ -921,7 +921,7 @@ TEST_CASE("BSON numerical data") SECTION("signed std::int32_t: INT32_MIN .. INT32_MAX") { - std::vector numbers + std::vector const numbers { INT32_MIN, -2147483647L, @@ -950,19 +950,19 @@ TEST_CASE("BSON numerical data") INT32_MAX }; - for (auto i : numbers) + for (const auto i : numbers) { CAPTURE(i) - json j = + json const j = { { "entry", i } }; CHECK(j.at("entry").is_number_integer()); - std::uint32_t iu = *reinterpret_cast(&i); - std::vector expected_bson = + std::uint32_t const iu = *reinterpret_cast(&i); + std::vector const expected_bson = { 0x10u, 0x00u, 0x00u, 0x00u, // size (little endian) 0x10u, /// entry: int32 @@ -988,7 +988,7 @@ TEST_CASE("BSON numerical data") SECTION("signed std::int64_t: INT32_MAX+1 .. INT64_MAX") { - std::vector numbers + std::vector const numbers { INT64_MAX, 1000000000000000000LL, @@ -1003,19 +1003,19 @@ TEST_CASE("BSON numerical data") static_cast(INT32_MAX) + 1, }; - for (auto i : numbers) + for (const auto i : numbers) { CAPTURE(i) - json j = + json const j = { { "entry", i } }; CHECK(j.at("entry").is_number_integer()); - std::uint64_t iu = *reinterpret_cast(&i); - std::vector expected_bson = + std::uint64_t const iu = *reinterpret_cast(&i); + std::vector const expected_bson = { 0x14u, 0x00u, 0x00u, 0x00u, // size (little endian) 0x12u, /// entry: int64 @@ -1048,7 +1048,7 @@ TEST_CASE("BSON numerical data") { SECTION("unsigned std::uint64_t: 0 .. INT32_MAX") { - std::vector numbers + std::vector const numbers { 0ULL, 1ULL, @@ -1065,18 +1065,18 @@ TEST_CASE("BSON numerical data") static_cast(INT32_MAX) }; - for (auto i : numbers) + for (const auto i : numbers) { CAPTURE(i) - json j = + json const j = { { "entry", i } }; auto iu = i; - std::vector expected_bson = + std::vector const expected_bson = { 0x10u, 0x00u, 0x00u, 0x00u, // size (little endian) 0x10u, /// entry: int32 @@ -1103,7 +1103,7 @@ TEST_CASE("BSON numerical data") SECTION("unsigned std::uint64_t: INT32_MAX+1 .. INT64_MAX") { - std::vector numbers + std::vector const numbers { static_cast(INT32_MAX) + 1, 4000000000ULL, @@ -1120,18 +1120,18 @@ TEST_CASE("BSON numerical data") static_cast(INT64_MAX), }; - for (auto i : numbers) + for (const auto i : numbers) { CAPTURE(i) - json j = + json const j = { { "entry", i } }; auto iu = i; - std::vector expected_bson = + std::vector const expected_bson = { 0x14u, 0x00u, 0x00u, 0x00u, // size (little endian) 0x12u, /// entry: int64 @@ -1161,7 +1161,7 @@ TEST_CASE("BSON numerical data") SECTION("unsigned std::uint64_t: INT64_MAX+1 .. UINT64_MAX") { - std::vector numbers + std::vector const numbers { static_cast(INT64_MAX) + 1ULL, 10000000000000000000ULL, @@ -1170,18 +1170,18 @@ TEST_CASE("BSON numerical data") UINT64_MAX, }; - for (auto i : numbers) + for (const auto i : numbers) { CAPTURE(i) - json j = + json const j = { { "entry", i } }; auto iu = i; - std::vector expected_bson = + std::vector const expected_bson = { 0x14u, 0x00u, 0x00u, 0x00u, // size (little endian) 0x12u, /// entry: int64 @@ -1214,7 +1214,7 @@ TEST_CASE("BSON roundtrips" * doctest::skip()) { SECTION("reference files") { - for (std::string filename : + for (const std::string filename : { TEST_DATA_DIRECTORY "/json.org/1.json", TEST_DATA_DIRECTORY "/json.org/2.json", @@ -1274,7 +1274,7 @@ TEST_CASE("BSON 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 BSON file auto packed = utils::read_binary_file(filename + ".bson"); 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..3a22bd029 100644 --- a/tests/src/unit-capacity.cpp +++ b/tests/src/unit-capacity.cpp @@ -18,8 +18,8 @@ TEST_CASE("capacity") { SECTION("boolean") { - json j = true; - const json j_const(j); + json j = true; // NOLINT(misc-const-correctness) + const json j_const = true; SECTION("result of empty") { @@ -36,8 +36,8 @@ TEST_CASE("capacity") SECTION("string") { - json j = "hello world"; - const json j_const(j); + json j = "hello world"; // NOLINT(misc-const-correctness) + const json j_const = "hello world"; SECTION("result of empty") { @@ -56,8 +56,8 @@ TEST_CASE("capacity") { SECTION("empty array") { - json j = json::array(); - const json j_const(j); + json j = json::array(); // NOLINT(misc-const-correctness) + const json j_const = json::array(); SECTION("result of empty") { @@ -74,8 +74,8 @@ TEST_CASE("capacity") SECTION("filled array") { - json j = {1, 2, 3}; - const json j_const(j); + json j = {1, 2, 3}; // NOLINT(misc-const-correctness) + const json j_const = {1, 2, 3}; SECTION("result of empty") { @@ -95,8 +95,8 @@ TEST_CASE("capacity") { SECTION("empty object") { - json j = json::object(); - const json j_const(j); + json j = json::object(); // NOLINT(misc-const-correctness) + const json j_const = json::object(); SECTION("result of empty") { @@ -113,8 +113,8 @@ TEST_CASE("capacity") SECTION("filled object") { - json j = {{"one", 1}, {"two", 2}, {"three", 3}}; - const json j_const(j); + json j = {{"one", 1}, {"two", 2}, {"three", 3}}; // NOLINT(misc-const-correctness) + const json j_const = {{"one", 1}, {"two", 2}, {"three", 3}}; SECTION("result of empty") { @@ -132,8 +132,8 @@ TEST_CASE("capacity") SECTION("number (integer)") { - json j = -23; - const json j_const(j); + json j = -23; // NOLINT(misc-const-correctness) + const json j_const = -23; SECTION("result of empty") { @@ -150,8 +150,8 @@ TEST_CASE("capacity") SECTION("number (unsigned)") { - json j = 23u; - const json j_const(j); + json j = 23u; // NOLINT(misc-const-correctness) + const json j_const = 23u; SECTION("result of empty") { @@ -168,8 +168,8 @@ TEST_CASE("capacity") SECTION("number (float)") { - json j = 23.42; - const json j_const(j); + json j = 23.42; // NOLINT(misc-const-correctness) + const json j_const = 23.42; SECTION("result of empty") { @@ -186,8 +186,8 @@ TEST_CASE("capacity") SECTION("null") { - json j = nullptr; - const json j_const(j); + json j = nullptr; // NOLINT(misc-const-correctness) + const json j_const = nullptr; SECTION("result of empty") { @@ -207,8 +207,8 @@ TEST_CASE("capacity") { SECTION("boolean") { - json j = true; - const json j_const(j); + json j = true; // NOLINT(misc-const-correctness) + const json j_const = true; SECTION("result of size") { @@ -227,8 +227,8 @@ TEST_CASE("capacity") SECTION("string") { - json j = "hello world"; - const json j_const(j); + json j = "hello world"; // NOLINT(misc-const-correctness) + const json j_const = "hello world"; SECTION("result of size") { @@ -249,8 +249,8 @@ TEST_CASE("capacity") { SECTION("empty array") { - json j = json::array(); - const json j_const(j); + json j = json::array(); // NOLINT(misc-const-correctness) + const json j_const = json::array(); SECTION("result of size") { @@ -269,8 +269,8 @@ TEST_CASE("capacity") SECTION("filled array") { - json j = {1, 2, 3}; - const json j_const(j); + json j = {1, 2, 3}; // NOLINT(misc-const-correctness) + const json j_const = {1, 2, 3}; SECTION("result of size") { @@ -292,8 +292,8 @@ TEST_CASE("capacity") { SECTION("empty object") { - json j = json::object(); - const json j_const(j); + json j = json::object(); // NOLINT(misc-const-correctness) + const json j_const = json::object(); SECTION("result of size") { @@ -312,8 +312,8 @@ TEST_CASE("capacity") SECTION("filled object") { - json j = {{"one", 1}, {"two", 2}, {"three", 3}}; - const json j_const(j); + json j = {{"one", 1}, {"two", 2}, {"three", 3}}; // NOLINT(misc-const-correctness) + const json j_const = {{"one", 1}, {"two", 2}, {"three", 3}}; SECTION("result of size") { @@ -333,8 +333,8 @@ TEST_CASE("capacity") SECTION("number (integer)") { - json j = -23; - const json j_const(j); + json j = -23; // NOLINT(misc-const-correctness) + const json j_const = -23; SECTION("result of size") { @@ -353,8 +353,8 @@ TEST_CASE("capacity") SECTION("number (unsigned)") { - json j = 23u; - const json j_const(j); + json j = 23u; // NOLINT(misc-const-correctness) + const json j_const = 23u; SECTION("result of size") { @@ -373,8 +373,8 @@ TEST_CASE("capacity") SECTION("number (float)") { - json j = 23.42; - const json j_const(j); + json j = 23.42; // NOLINT(misc-const-correctness) + const json j_const = 23.42; SECTION("result of size") { @@ -393,8 +393,8 @@ TEST_CASE("capacity") SECTION("null") { - json j = nullptr; - const json j_const(j); + json j = nullptr; // NOLINT(misc-const-correctness) + const json j_const = nullptr; SECTION("result of size") { @@ -416,7 +416,7 @@ TEST_CASE("capacity") { SECTION("boolean") { - json j = true; + json j = true; // NOLINT(misc-const-correctness) const json j_const = true; SECTION("result of max_size") @@ -428,7 +428,7 @@ TEST_CASE("capacity") SECTION("string") { - json j = "hello world"; + json j = "hello world"; // NOLINT(misc-const-correctness) 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 j = json::array(); // NOLINT(misc-const-correctness) 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 j = {1, 2, 3}; // NOLINT(misc-const-correctness) 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 j = json::object(); // NOLINT(misc-const-correctness) 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 j = {{"one", 1}, {"two", 2}, {"three", 3}}; // NOLINT(misc-const-correctness) 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 j = -23; // NOLINT(misc-const-correctness) const json j_const = -23; SECTION("result of max_size") @@ -506,7 +506,7 @@ TEST_CASE("capacity") SECTION("number (unsigned)") { - json j = 23u; + json j = 23u; // NOLINT(misc-const-correctness) 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 j = 23.42; // NOLINT(misc-const-correctness) const json j_const = 23.42; SECTION("result of max_size") @@ -530,7 +530,7 @@ TEST_CASE("capacity") SECTION("null") { - json j = nullptr; + json j = nullptr; // NOLINT(misc-const-correctness) const json j_const = nullptr; SECTION("result of max_size") diff --git a/tests/src/unit-cbor.cpp b/tests/src/unit-cbor.cpp index ffa3e92d8..1d900b224 100644 --- a/tests/src/unit-cbor.cpp +++ b/tests/src/unit-cbor.cpp @@ -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,8 +112,8 @@ TEST_CASE("CBOR") SECTION("NaN") { // NaN value - json j = std::numeric_limits::quiet_NaN(); - std::vector expected = {0xf9, 0x7e, 0x00}; + json const j = std::numeric_limits::quiet_NaN(); + const std::vector expected = {0xf9, 0x7e, 0x00}; const auto result = json::to_cbor(j); CHECK(result == expected); } @@ -121,16 +121,16 @@ TEST_CASE("CBOR") SECTION("Infinity") { // Infinity value - json j = std::numeric_limits::infinity(); - std::vector expected = {0xf9, 0x7c, 0x00}; + json const j = std::numeric_limits::infinity(); + const std::vector expected = {0xf9, 0x7c, 0x00}; const auto result = json::to_cbor(j); CHECK(result == expected); } SECTION("null") { - json j = nullptr; - std::vector expected = {0xf6}; + const json j = nullptr; + const std::vector expected = {0xf6}; const auto result = json::to_cbor(j); CHECK(result == expected); @@ -143,8 +143,8 @@ TEST_CASE("CBOR") { SECTION("true") { - json j = true; - std::vector expected = {0xf5}; + const json j = true; + const std::vector expected = {0xf5}; const auto result = json::to_cbor(j); CHECK(result == expected); @@ -155,8 +155,8 @@ TEST_CASE("CBOR") SECTION("false") { - json j = false; - std::vector expected = {0xf4}; + const json j = false; + const std::vector expected = {0xf4}; const auto result = json::to_cbor(j); CHECK(result == expected); @@ -172,40 +172,44 @@ TEST_CASE("CBOR") { SECTION("-9223372036854775808..-4294967297") { - std::vector numbers; - numbers.push_back(INT64_MIN); - numbers.push_back(-1000000000000000000); - numbers.push_back(-100000000000000000); - numbers.push_back(-10000000000000000); - numbers.push_back(-1000000000000000); - numbers.push_back(-100000000000000); - numbers.push_back(-10000000000000); - numbers.push_back(-1000000000000); - numbers.push_back(-100000000000); - numbers.push_back(-10000000000); - numbers.push_back(-4294967297); - for (auto i : numbers) + const std::vector numbers + { + INT64_MIN, + -1000000000000000000, + -100000000000000000, + -10000000000000000, + -1000000000000000, + -100000000000000, + -10000000000000, + -1000000000000, + -100000000000, + -10000000000, + -4294967297, + }; + for (const auto i : numbers) { CAPTURE(i) // create JSON value with integer number - json j = i; + const json j = i; // check type CHECK(j.is_number_integer()); // create expected byte vector - std::vector expected; - expected.push_back(static_cast(0x3b)); - auto positive = static_cast(-1 - i); - expected.push_back(static_cast((positive >> 56) & 0xff)); - expected.push_back(static_cast((positive >> 48) & 0xff)); - expected.push_back(static_cast((positive >> 40) & 0xff)); - expected.push_back(static_cast((positive >> 32) & 0xff)); - expected.push_back(static_cast((positive >> 24) & 0xff)); - expected.push_back(static_cast((positive >> 16) & 0xff)); - expected.push_back(static_cast((positive >> 8) & 0xff)); - expected.push_back(static_cast(positive & 0xff)); + const auto positive = static_cast(-1 - i); + const std::vector expected + { + static_cast(0x3b), + static_cast((positive >> 56) & 0xff), + static_cast((positive >> 48) & 0xff), + static_cast((positive >> 40) & 0xff), + static_cast((positive >> 32) & 0xff), + static_cast((positive >> 24) & 0xff), + static_cast((positive >> 16) & 0xff), + static_cast((positive >> 8) & 0xff), + static_cast(positive & 0xff), + }; // compare result + size const auto result = json::to_cbor(j); @@ -214,14 +218,14 @@ TEST_CASE("CBOR") // check individual bytes CHECK(result[0] == 0x3b); - uint64_t restored = (static_cast(result[1]) << 070) + - (static_cast(result[2]) << 060) + - (static_cast(result[3]) << 050) + - (static_cast(result[4]) << 040) + - (static_cast(result[5]) << 030) + - (static_cast(result[6]) << 020) + - (static_cast(result[7]) << 010) + - static_cast(result[8]); + const uint64_t restored = (static_cast(result[1]) << 070) + + (static_cast(result[2]) << 060) + + (static_cast(result[3]) << 050) + + (static_cast(result[4]) << 040) + + (static_cast(result[5]) << 030) + + (static_cast(result[6]) << 020) + + (static_cast(result[7]) << 010) + + static_cast(result[8]); CHECK(restored == positive); CHECK(-1 - static_cast(restored) == i); @@ -233,32 +237,36 @@ TEST_CASE("CBOR") SECTION("-4294967296..-65537") { - std::vector numbers; - numbers.push_back(-65537); - numbers.push_back(-100000); - numbers.push_back(-1000000); - numbers.push_back(-10000000); - numbers.push_back(-100000000); - numbers.push_back(-1000000000); - numbers.push_back(-4294967296); - for (auto i : numbers) + const std::vector numbers + { + -65537, + -100000, + -1000000, + -10000000, + -100000000, + -1000000000, + -4294967296, + }; + for (const auto i : numbers) { CAPTURE(i) // create JSON value with integer number - json j = i; + const json j = i; // check type CHECK(j.is_number_integer()); // create expected byte vector - std::vector expected; - expected.push_back(static_cast(0x3a)); auto positive = static_cast(static_cast(-1 - i) & 0x00000000ffffffff); - expected.push_back(static_cast((positive >> 24) & 0xff)); - expected.push_back(static_cast((positive >> 16) & 0xff)); - expected.push_back(static_cast((positive >> 8) & 0xff)); - expected.push_back(static_cast(positive & 0xff)); + const std::vector expected + { + static_cast(0x3a), + static_cast((positive >> 24) & 0xff), + static_cast((positive >> 16) & 0xff), + static_cast((positive >> 8) & 0xff), + static_cast(positive & 0xff), + }; // compare result + size const auto result = json::to_cbor(j); @@ -267,10 +275,10 @@ TEST_CASE("CBOR") // check individual bytes CHECK(result[0] == 0x3a); - uint32_t restored = (static_cast(result[1]) << 030) + - (static_cast(result[2]) << 020) + - (static_cast(result[3]) << 010) + - static_cast(result[4]); + const uint32_t restored = (static_cast(result[1]) << 030) + + (static_cast(result[2]) << 020) + + (static_cast(result[3]) << 010) + + static_cast(result[4]); CHECK(restored == positive); CHECK(-1LL - restored == i); @@ -287,17 +295,19 @@ TEST_CASE("CBOR") CAPTURE(i) // create JSON value with integer number - json j = i; + const json j = i; // check type CHECK(j.is_number_integer()); // create expected byte vector - std::vector expected; - expected.push_back(static_cast(0x39)); - auto positive = static_cast(-1 - i); - expected.push_back(static_cast((positive >> 8) & 0xff)); - expected.push_back(static_cast(positive & 0xff)); + const auto positive = static_cast(-1 - i); + const std::vector expected + { + static_cast(0x39), + static_cast((positive >> 8) & 0xff), + static_cast(positive & 0xff), + }; // compare result + size const auto result = json::to_cbor(j); @@ -306,7 +316,7 @@ TEST_CASE("CBOR") // check individual bytes CHECK(result[0] == 0x39); - auto restored = static_cast(static_cast(result[1]) * 256 + static_cast(result[2])); + const auto restored = static_cast(static_cast(result[1]) * 256 + static_cast(result[2])); CHECK(restored == positive); CHECK(-1 - restored == i); @@ -318,13 +328,13 @@ TEST_CASE("CBOR") SECTION("-9263 (int 16)") { - json j = -9263; + const json j = -9263; std::vector expected = {0x39, 0x24, 0x2e}; const auto result = json::to_cbor(j); CHECK(result == expected); - auto restored = static_cast(-1 - ((result[1] << 8) + result[2])); + const auto restored = static_cast(-1 - ((result[1] << 8) + result[2])); CHECK(restored == -9263); // roundtrip @@ -339,15 +349,17 @@ TEST_CASE("CBOR") CAPTURE(i) // create JSON value with integer number - json j = i; + const json j = i; // check type CHECK(j.is_number_integer()); // create expected byte vector - std::vector expected; - expected.push_back(0x38); - expected.push_back(static_cast(-1 - i)); + const std::vector expected + { + 0x38, + static_cast(-1 - i), + }; // compare result + size const auto result = json::to_cbor(j); @@ -371,14 +383,16 @@ TEST_CASE("CBOR") CAPTURE(i) // create JSON value with integer number - json j = i; + const json j = i; // check type CHECK(j.is_number_integer()); // create expected byte vector - std::vector expected; - expected.push_back(static_cast(0x20 - 1 - static_cast(i))); + const std::vector expected + { + static_cast(0x20 - 1 - static_cast(i)), + }; // compare result + size const auto result = json::to_cbor(j); @@ -408,8 +422,10 @@ TEST_CASE("CBOR") CHECK(j.is_number_integer()); // create expected byte vector - std::vector expected; - expected.push_back(static_cast(i)); + const std::vector expected + { + static_cast(i), + }; // compare result + size const auto result = json::to_cbor(j); @@ -439,9 +455,11 @@ TEST_CASE("CBOR") CHECK(j.is_number_integer()); // create expected byte vector - std::vector expected; - expected.push_back(static_cast(0x18)); - expected.push_back(static_cast(i)); + const std::vector expected + { + static_cast(0x18), + static_cast(i), + }; // compare result + size const auto result = json::to_cbor(j); @@ -472,10 +490,12 @@ TEST_CASE("CBOR") CHECK(j.is_number_integer()); // create expected byte vector - std::vector expected; - expected.push_back(static_cast(0x19)); - expected.push_back(static_cast((i >> 8) & 0xff)); - expected.push_back(static_cast(i & 0xff)); + const std::vector expected + { + static_cast(0x19), + static_cast((i >> 8) & 0xff), + static_cast(i & 0xff), + }; // compare result + size const auto result = json::to_cbor(j); @@ -484,7 +504,7 @@ TEST_CASE("CBOR") // check individual bytes CHECK(result[0] == 0x19); - auto restored = static_cast(static_cast(result[1]) * 256 + static_cast(result[2])); + const auto restored = static_cast(static_cast(result[1]) * 256 + static_cast(result[2])); CHECK(restored == i); // roundtrip @@ -495,7 +515,7 @@ TEST_CASE("CBOR") SECTION("65536..4294967295") { - for (uint32_t i : + for (const uint32_t i : { 65536u, 77777u, 1048576u }) @@ -510,12 +530,14 @@ TEST_CASE("CBOR") CHECK(j.is_number_integer()); // create expected byte vector - std::vector expected; - expected.push_back(0x1a); - expected.push_back(static_cast((i >> 24) & 0xff)); - expected.push_back(static_cast((i >> 16) & 0xff)); - expected.push_back(static_cast((i >> 8) & 0xff)); - expected.push_back(static_cast(i & 0xff)); + const std::vector expected + { + 0x1a, + static_cast((i >> 24) & 0xff), + static_cast((i >> 16) & 0xff), + static_cast((i >> 8) & 0xff), + static_cast(i & 0xff), + }; // compare result + size const auto result = json::to_cbor(j); @@ -524,10 +546,10 @@ TEST_CASE("CBOR") // check individual bytes CHECK(result[0] == 0x1a); - uint32_t restored = (static_cast(result[1]) << 030) + - (static_cast(result[2]) << 020) + - (static_cast(result[3]) << 010) + - static_cast(result[4]); + const uint32_t restored = (static_cast(result[1]) << 030) + + (static_cast(result[2]) << 020) + + (static_cast(result[3]) << 010) + + static_cast(result[4]); CHECK(restored == i); // roundtrip @@ -538,7 +560,7 @@ TEST_CASE("CBOR") SECTION("4294967296..4611686018427387903") { - for (uint64_t i : + for (const uint64_t i : { 4294967296ul, 4611686018427387903ul }) @@ -553,16 +575,18 @@ TEST_CASE("CBOR") CHECK(j.is_number_integer()); // create expected byte vector - std::vector expected; - expected.push_back(0x1b); - expected.push_back(static_cast((i >> 070) & 0xff)); - expected.push_back(static_cast((i >> 060) & 0xff)); - expected.push_back(static_cast((i >> 050) & 0xff)); - expected.push_back(static_cast((i >> 040) & 0xff)); - expected.push_back(static_cast((i >> 030) & 0xff)); - expected.push_back(static_cast((i >> 020) & 0xff)); - expected.push_back(static_cast((i >> 010) & 0xff)); - expected.push_back(static_cast(i & 0xff)); + const std::vector expected + { + 0x1b, + static_cast((i >> 070) & 0xff), + static_cast((i >> 060) & 0xff), + static_cast((i >> 050) & 0xff), + static_cast((i >> 040) & 0xff), + static_cast((i >> 030) & 0xff), + static_cast((i >> 020) & 0xff), + static_cast((i >> 010) & 0xff), + static_cast(i & 0xff), + }; // compare result + size const auto result = json::to_cbor(j); @@ -571,14 +595,14 @@ TEST_CASE("CBOR") // check individual bytes CHECK(result[0] == 0x1b); - uint64_t restored = (static_cast(result[1]) << 070) + - (static_cast(result[2]) << 060) + - (static_cast(result[3]) << 050) + - (static_cast(result[4]) << 040) + - (static_cast(result[5]) << 030) + - (static_cast(result[6]) << 020) + - (static_cast(result[7]) << 010) + - static_cast(result[8]); + const uint64_t restored = (static_cast(result[1]) << 070) + + (static_cast(result[2]) << 060) + + (static_cast(result[3]) << 050) + + (static_cast(result[4]) << 040) + + (static_cast(result[5]) << 030) + + (static_cast(result[6]) << 020) + + (static_cast(result[7]) << 010) + + static_cast(result[8]); CHECK(restored == i); // roundtrip @@ -594,16 +618,18 @@ TEST_CASE("CBOR") CAPTURE(i) // create JSON value with integer number - json j = i; + const json j = i; // check type CHECK(j.is_number_integer()); // create expected byte vector - std::vector expected; - expected.push_back(0xd1); - expected.push_back(static_cast((i >> 8) & 0xff)); - expected.push_back(static_cast(i & 0xff)); + const std::vector expected + { + 0xd1, + static_cast((i >> 8) & 0xff), + static_cast(i & 0xff), + }; // compare result + size const auto result = json::to_msgpack(j); @@ -612,7 +638,7 @@ TEST_CASE("CBOR") // check individual bytes CHECK(result[0] == 0xd1); - auto restored = static_cast((result[1] << 8) + result[2]); + const auto restored = static_cast((result[1] << 8) + result[2]); CHECK(restored == i); // roundtrip @@ -630,14 +656,16 @@ TEST_CASE("CBOR") CAPTURE(i) // create JSON value with unsigned integer number - json j = i; + const json j = i; // check type CHECK(j.is_number_unsigned()); // create expected byte vector - std::vector expected; - expected.push_back(static_cast(i)); + const std::vector expected + { + static_cast(i), + }; // compare result + size const auto result = json::to_cbor(j); @@ -660,15 +688,17 @@ TEST_CASE("CBOR") CAPTURE(i) // create JSON value with unsigned integer number - json j = i; + const json j = i; // check type CHECK(j.is_number_unsigned()); // create expected byte vector - std::vector expected; - expected.push_back(0x18); - expected.push_back(static_cast(i)); + const std::vector expected + { + 0x18, + static_cast(i), + }; // compare result + size const auto result = json::to_cbor(j); @@ -677,7 +707,7 @@ TEST_CASE("CBOR") // check individual bytes CHECK(result[0] == 0x18); - auto restored = static_cast(result[1]); + const auto restored = static_cast(result[1]); CHECK(restored == i); // roundtrip @@ -693,16 +723,18 @@ TEST_CASE("CBOR") CAPTURE(i) // create JSON value with unsigned integer number - json j = i; + const json j = i; // check type CHECK(j.is_number_unsigned()); // create expected byte vector - std::vector expected; - expected.push_back(0x19); - expected.push_back(static_cast((i >> 8) & 0xff)); - expected.push_back(static_cast(i & 0xff)); + const std::vector expected + { + 0x19, + static_cast((i >> 8) & 0xff), + static_cast(i & 0xff), + }; // compare result + size const auto result = json::to_cbor(j); @@ -711,7 +743,7 @@ TEST_CASE("CBOR") // check individual bytes CHECK(result[0] == 0x19); - auto restored = static_cast(static_cast(result[1]) * 256 + static_cast(result[2])); + const auto restored = static_cast(static_cast(result[1]) * 256 + static_cast(result[2])); CHECK(restored == i); // roundtrip @@ -722,7 +754,7 @@ TEST_CASE("CBOR") SECTION("65536..4294967295 (four-byte uint32_t)") { - for (uint32_t i : + for (const uint32_t i : { 65536u, 77777u, 1048576u }) @@ -730,18 +762,20 @@ TEST_CASE("CBOR") CAPTURE(i) // create JSON value with unsigned integer number - json j = i; + const json j = i; // check type CHECK(j.is_number_unsigned()); // create expected byte vector - std::vector expected; - expected.push_back(0x1a); - expected.push_back(static_cast((i >> 24) & 0xff)); - expected.push_back(static_cast((i >> 16) & 0xff)); - expected.push_back(static_cast((i >> 8) & 0xff)); - expected.push_back(static_cast(i & 0xff)); + const std::vector expected + { + 0x1a, + static_cast((i >> 24) & 0xff), + static_cast((i >> 16) & 0xff), + static_cast((i >> 8) & 0xff), + static_cast(i & 0xff), + }; // compare result + size const auto result = json::to_cbor(j); @@ -750,10 +784,10 @@ TEST_CASE("CBOR") // check individual bytes CHECK(result[0] == 0x1a); - uint32_t restored = (static_cast(result[1]) << 030) + - (static_cast(result[2]) << 020) + - (static_cast(result[3]) << 010) + - static_cast(result[4]); + const uint32_t restored = (static_cast(result[1]) << 030) + + (static_cast(result[2]) << 020) + + (static_cast(result[3]) << 010) + + static_cast(result[4]); CHECK(restored == i); // roundtrip @@ -764,7 +798,7 @@ TEST_CASE("CBOR") SECTION("4294967296..4611686018427387903 (eight-byte uint64_t)") { - for (uint64_t i : + for (const uint64_t i : { 4294967296ul, 4611686018427387903ul }) @@ -772,22 +806,24 @@ TEST_CASE("CBOR") CAPTURE(i) // create JSON value with integer number - json j = i; + const json j = i; // check type CHECK(j.is_number_unsigned()); // create expected byte vector - std::vector expected; - expected.push_back(0x1b); - expected.push_back(static_cast((i >> 070) & 0xff)); - expected.push_back(static_cast((i >> 060) & 0xff)); - expected.push_back(static_cast((i >> 050) & 0xff)); - expected.push_back(static_cast((i >> 040) & 0xff)); - expected.push_back(static_cast((i >> 030) & 0xff)); - expected.push_back(static_cast((i >> 020) & 0xff)); - expected.push_back(static_cast((i >> 010) & 0xff)); - expected.push_back(static_cast(i & 0xff)); + const std::vector expected + { + 0x1b, + static_cast((i >> 070) & 0xff), + static_cast((i >> 060) & 0xff), + static_cast((i >> 050) & 0xff), + static_cast((i >> 040) & 0xff), + static_cast((i >> 030) & 0xff), + static_cast((i >> 020) & 0xff), + static_cast((i >> 010) & 0xff), + static_cast(i & 0xff), + }; // compare result + size const auto result = json::to_cbor(j); @@ -796,14 +832,14 @@ TEST_CASE("CBOR") // check individual bytes CHECK(result[0] == 0x1b); - uint64_t restored = (static_cast(result[1]) << 070) + - (static_cast(result[2]) << 060) + - (static_cast(result[3]) << 050) + - (static_cast(result[4]) << 040) + - (static_cast(result[5]) << 030) + - (static_cast(result[6]) << 020) + - (static_cast(result[7]) << 010) + - static_cast(result[8]); + const uint64_t restored = (static_cast(result[1]) << 070) + + (static_cast(result[2]) << 060) + + (static_cast(result[3]) << 050) + + (static_cast(result[4]) << 040) + + (static_cast(result[5]) << 030) + + (static_cast(result[6]) << 020) + + (static_cast(result[7]) << 010) + + static_cast(result[8]); CHECK(restored == i); // roundtrip @@ -818,7 +854,7 @@ TEST_CASE("CBOR") SECTION("3.1415925") { double v = 3.1415925; - json j = v; + const json j = v; std::vector expected = { 0xfb, 0x40, 0x09, 0x21, 0xfb, 0x3f, 0xa6, 0xde, 0xfc @@ -839,11 +875,11 @@ TEST_CASE("CBOR") SECTION("0.5") { double v = 0.5; - json j = v; + const json j = v; // its double-precision float binary value is // {0xfb, 0x3f, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} // but to save memory, we can store it as single-precision float. - std::vector expected = {0xfa, 0x3f, 0x00, 0x00, 0x00}; + const std::vector expected = {0xfa, 0x3f, 0x00, 0x00, 0x00}; const auto result = json::to_cbor(j); CHECK(result == expected); // roundtrip @@ -853,10 +889,10 @@ TEST_CASE("CBOR") SECTION("0.0") { double v = 0.0; - json j = v; + const json j = v; // its double-precision binary value is: // {0xfb, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} - std::vector expected = {0xfa, 0x00, 0x00, 0x00, 0x00}; + const std::vector expected = {0xfa, 0x00, 0x00, 0x00, 0x00}; const auto result = json::to_cbor(j); CHECK(result == expected); // roundtrip @@ -866,10 +902,10 @@ TEST_CASE("CBOR") SECTION("-0.0") { double v = -0.0; - json j = v; + const json j = v; // its double-precision binary value is: // {0xfb, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} - std::vector expected = {0xfa, 0x80, 0x00, 0x00, 0x00}; + const std::vector expected = {0xfa, 0x80, 0x00, 0x00, 0x00}; const auto result = json::to_cbor(j); CHECK(result == expected); // roundtrip @@ -879,10 +915,10 @@ TEST_CASE("CBOR") SECTION("100.0") { double v = 100.0; - json j = v; + const json j = v; // its double-precision binary value is: // {0xfb, 0x40, 0x59, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} - std::vector expected = {0xfa, 0x42, 0xc8, 0x00, 0x00}; + const std::vector expected = {0xfa, 0x42, 0xc8, 0x00, 0x00}; const auto result = json::to_cbor(j); CHECK(result == expected); // roundtrip @@ -892,10 +928,10 @@ TEST_CASE("CBOR") SECTION("200.0") { double v = 200.0; - json j = v; + const json j = v; // its double-precision binary value is: // {0xfb, 0x40, 0x69, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} - std::vector expected = {0xfa, 0x43, 0x48, 0x00, 0x00}; + const std::vector expected = {0xfa, 0x43, 0x48, 0x00, 0x00}; const auto result = json::to_cbor(j); CHECK(result == expected); // roundtrip @@ -905,8 +941,8 @@ TEST_CASE("CBOR") SECTION("3.40282e+38(max float)") { float v = (std::numeric_limits::max)(); - json j = v; - std::vector expected = + const json j = v; + const std::vector expected = { 0xfa, 0x7f, 0x7f, 0xff, 0xff }; @@ -919,8 +955,8 @@ TEST_CASE("CBOR") SECTION("-3.40282e+38(lowest float)") { auto v = static_cast(std::numeric_limits::lowest()); - json j = v; - std::vector expected = + const json j = v; + const std::vector expected = { 0xfa, 0xff, 0x7f, 0xff, 0xff }; @@ -933,8 +969,8 @@ TEST_CASE("CBOR") SECTION("1 + 3.40282e+38(more than max float)") { double v = static_cast((std::numeric_limits::max)()) + 0.1e+34; - json j = v; - std::vector expected = + const json j = v; + const std::vector expected = { 0xfb, 0x47, 0xf0, 0x00, 0x03, 0x04, 0xdc, 0x64, 0x49 }; @@ -948,8 +984,8 @@ TEST_CASE("CBOR") SECTION("-1 - 3.40282e+38(less than lowest float)") { double v = static_cast(std::numeric_limits::lowest()) - 1.0; - json j = v; - std::vector expected = + const json j = v; + const std::vector expected = { 0xfa, 0xff, 0x7f, 0xff, 0xff }; @@ -985,21 +1021,21 @@ TEST_CASE("CBOR") { SECTION("0 (0 00000 0000000000)") { - json j = json::from_cbor(std::vector({0xf9, 0x00, 0x00})); + json const j = json::from_cbor(std::vector({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({0xf9, 0x80, 0x00})); + json const j = json::from_cbor(std::vector({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({0xf9, 0x00, 0x01})); + json const j = json::from_cbor(std::vector({0xf9, 0x00, 0x01})); json::number_float_t d{j}; CHECK(d == std::pow(2.0, -24.0)); } @@ -1009,7 +1045,7 @@ TEST_CASE("CBOR") { SECTION("infinity (0 11111 0000000000)") { - json j = json::from_cbor(std::vector({0xf9, 0x7c, 0x00})); + json const j = json::from_cbor(std::vector({0xf9, 0x7c, 0x00})); json::number_float_t d{j}; CHECK(d == std::numeric_limits::infinity()); CHECK(j.dump() == "null"); @@ -1017,7 +1053,7 @@ TEST_CASE("CBOR") SECTION("-infinity (1 11111 0000000000)") { - json j = json::from_cbor(std::vector({0xf9, 0xfc, 0x00})); + json const j = json::from_cbor(std::vector({0xf9, 0xfc, 0x00})); json::number_float_t d{j}; CHECK(d == -std::numeric_limits::infinity()); CHECK(j.dump() == "null"); @@ -1028,21 +1064,21 @@ TEST_CASE("CBOR") { SECTION("1 (0 01111 0000000000)") { - json j = json::from_cbor(std::vector({0xf9, 0x3c, 0x00})); + json const j = json::from_cbor(std::vector({0xf9, 0x3c, 0x00})); json::number_float_t d{j}; CHECK(d == 1); } SECTION("-2 (1 10000 0000000000)") { - json j = json::from_cbor(std::vector({0xf9, 0xc0, 0x00})); + json const j = json::from_cbor(std::vector({0xf9, 0xc0, 0x00})); json::number_float_t d{j}; CHECK(d == -2); } SECTION("65504 (0 11110 1111111111)") { - json j = json::from_cbor(std::vector({0xf9, 0x7b, 0xff})); + json const j = json::from_cbor(std::vector({0xf9, 0x7b, 0xff})); json::number_float_t d{j}; CHECK(d == 65504); } @@ -1050,16 +1086,16 @@ TEST_CASE("CBOR") SECTION("infinity") { - json j = json::from_cbor(std::vector({0xf9, 0x7c, 0x00})); - json::number_float_t d{j}; + json const j = json::from_cbor(std::vector({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({0xf9, 0x7e, 0x00})); - json::number_float_t d{j}; + json const j = json::from_cbor(std::vector({0xf9, 0x7e, 0x00})); + json::number_float_t const d{j}; CHECK(std::isnan(d)); CHECK(j.dump() == "null"); } @@ -1076,7 +1112,7 @@ TEST_CASE("CBOR") // create JSON value with string containing of N * 'x' const auto s = std::string(N, 'x'); - json j = s; + const json j = s; // create expected byte vector std::vector expected; @@ -1110,10 +1146,11 @@ TEST_CASE("CBOR") // create JSON value with string containing of N * 'x' const auto s = std::string(N, 'x'); - json j = s; + const json j = s; // create expected byte vector std::vector expected; + expected.push_back(0x78); expected.push_back(static_cast(N)); for (size_t i = 0; i < N; ++i) @@ -1136,7 +1173,7 @@ TEST_CASE("CBOR") SECTION("N = 256..65535") { - for (size_t N : + for (const size_t N : { 256u, 999u, 1025u, 3333u, 2048u, 65535u }) @@ -1145,7 +1182,7 @@ TEST_CASE("CBOR") // create JSON value with string containing of N * 'x' const auto s = std::string(N, 'x'); - json j = s; + const json j = s; // create expected byte vector (hack: create string first) std::vector expected(N, 'x'); @@ -1169,7 +1206,7 @@ TEST_CASE("CBOR") SECTION("N = 65536..4294967295") { - for (size_t N : + for (const size_t N : { 65536u, 77777u, 1048576u }) @@ -1178,7 +1215,7 @@ TEST_CASE("CBOR") // create JSON value with string containing of N * 'x' const auto s = std::string(N, 'x'); - json j = s; + const json j = s; // create expected byte vector (hack: create string first) std::vector expected(N, 'x'); @@ -1207,7 +1244,7 @@ TEST_CASE("CBOR") { SECTION("empty") { - json j = json::array(); + const json j = json::array(); std::vector expected = {0x80}; const auto result = json::to_cbor(j); CHECK(result == expected); @@ -1219,8 +1256,8 @@ TEST_CASE("CBOR") SECTION("[null]") { - json j = {nullptr}; - std::vector expected = {0x81, 0xf6}; + const json j = {nullptr}; + const std::vector expected = {0x81, 0xf6}; const auto result = json::to_cbor(j); CHECK(result == expected); @@ -1231,8 +1268,8 @@ TEST_CASE("CBOR") SECTION("[1,2,3,4,5]") { - json j = json::parse("[1,2,3,4,5]"); - std::vector expected = {0x85, 0x01, 0x02, 0x03, 0x04, 0x05}; + const json j = json::parse("[1,2,3,4,5]"); + const std::vector expected = {0x85, 0x01, 0x02, 0x03, 0x04, 0x05}; const auto result = json::to_cbor(j); CHECK(result == expected); @@ -1243,8 +1280,8 @@ TEST_CASE("CBOR") SECTION("[[[[]]]]") { - json j = json::parse("[[[[]]]]"); - std::vector expected = {0x81, 0x81, 0x81, 0x80}; + const json j = json::parse("[[[[]]]]"); + const std::vector expected = {0x81, 0x81, 0x81, 0x80}; const auto result = json::to_cbor(j); CHECK(result == expected); @@ -1255,7 +1292,7 @@ TEST_CASE("CBOR") SECTION("array with uint16_t elements") { - json j(257, nullptr); + const json j(257, nullptr); std::vector expected(j.size() + 3, 0xf6); // all null expected[0] = 0x99; // array 16 bit expected[1] = 0x01; // size (0x0101), byte 0 @@ -1270,7 +1307,7 @@ TEST_CASE("CBOR") SECTION("array with uint32_t elements") { - json j(65793, nullptr); + const json j(65793, nullptr); std::vector expected(j.size() + 5, 0xf6); // all null expected[0] = 0x9a; // array 32 bit expected[1] = 0x00; // size (0x00010101), byte 0 @@ -1290,8 +1327,8 @@ TEST_CASE("CBOR") { SECTION("empty") { - json j = json::object(); - std::vector expected = {0xa0}; + const json j = json::object(); + const std::vector expected = {0xa0}; const auto result = json::to_cbor(j); CHECK(result == expected); @@ -1302,8 +1339,8 @@ TEST_CASE("CBOR") SECTION("{\"\":null}") { - json j = {{"", nullptr}}; - std::vector expected = {0xa1, 0x60, 0xf6}; + const json j = {{"", nullptr}}; + const std::vector expected = {0xa1, 0x60, 0xf6}; const auto result = json::to_cbor(j); CHECK(result == expected); @@ -1314,8 +1351,8 @@ TEST_CASE("CBOR") SECTION("{\"a\": {\"b\": {\"c\": {}}}}") { - json j = json::parse(R"({"a": {"b": {"c": {}}}})"); - std::vector expected = + const json j = json::parse(R"({"a": {"b": {"c": {}}}})"); + const std::vector expected = { 0xa1, 0x61, 0x61, 0xa1, 0x61, 0x62, 0xa1, 0x61, 0x63, 0xa0 }; @@ -1425,7 +1462,7 @@ TEST_CASE("CBOR") // create JSON value with byte array containing of N * 'x' const auto s = std::vector(N, 'x'); - json j = json::binary(s); + const json j = json::binary(s); // create expected byte vector std::vector expected; @@ -1459,7 +1496,7 @@ TEST_CASE("CBOR") // create JSON value with string containing of N * 'x' const auto s = std::vector(N, 'x'); - json j = json::binary(s); + const json j = json::binary(s); // create expected byte vector std::vector expected; @@ -1485,7 +1522,7 @@ TEST_CASE("CBOR") SECTION("N = 256..65535") { - for (size_t N : + for (const size_t N : { 256u, 999u, 1025u, 3333u, 2048u, 65535u }) @@ -1494,7 +1531,7 @@ TEST_CASE("CBOR") // create JSON value with string containing of N * 'x' const auto s = std::vector(N, 'x'); - json j = json::binary(s); + const json j = json::binary(s); // create expected byte vector (hack: create string first) std::vector expected(N, 'x'); @@ -1518,7 +1555,7 @@ TEST_CASE("CBOR") SECTION("N = 65536..4294967295") { - for (size_t N : + for (const size_t N : { 65536u, 77777u, 1048576u }) @@ -1527,7 +1564,7 @@ TEST_CASE("CBOR") // create JSON value with string containing of N * 'x' const auto s = std::vector(N, 'x'); - json j = json::binary(s); + const json j = json::binary(s); // create expected byte vector (hack: create string first) std::vector expected(N, 'x'); @@ -1553,7 +1590,7 @@ TEST_CASE("CBOR") SECTION("indefinite size") { - std::vector input = {0x5F, 0x44, 0xaa, 0xbb, 0xcc, 0xdd, 0x43, 0xee, 0xff, 0x99, 0xFF}; + std::vector 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 +1601,7 @@ TEST_CASE("CBOR") SECTION("binary in array") { // array with three empty byte strings - std::vector input = {0x83, 0x40, 0x40, 0x40}; + std::vector const input = {0x83, 0x40, 0x40, 0x40}; json _; CHECK_NOTHROW(_ = json::from_cbor(input)); } @@ -1572,7 +1609,7 @@ TEST_CASE("CBOR") SECTION("binary in object") { // object mapping "foo" to empty byte string - std::vector input = {0xA1, 0x63, 0x66, 0x6F, 0x6F, 0x40}; + std::vector const input = {0xA1, 0x63, 0x66, 0x6F, 0x6F, 0x40}; json _; CHECK_NOTHROW(_ = json::from_cbor(input)); } @@ -1580,7 +1617,7 @@ TEST_CASE("CBOR") SECTION("SAX callback with binary") { // object mapping "foo" to byte string - std::vector input = {0xA1, 0x63, 0x66, 0x6F, 0x6F, 0x41, 0x00}; + std::vector 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,37 +1643,37 @@ TEST_CASE("CBOR") { SECTION("0x5b (byte array)") { - std::vector given = {0x5b, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x01, 0x61 - }; - json j = json::from_cbor(given); + std::vector const given = {0x5b, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x01, 0x61 + }; + const json j = json::from_cbor(given); CHECK(j == json::binary(std::vector {'a'})); } SECTION("0x7b (string)") { - std::vector given = {0x7b, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x01, 0x61 - }; - json j = json::from_cbor(given); + std::vector const given = {0x7b, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x01, 0x61 + }; + const json j = json::from_cbor(given); CHECK(j == "a"); } SECTION("0x9b (array)") { - std::vector given = {0x9b, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x01, 0xf4 - }; - json j = json::from_cbor(given); + std::vector const given = {0x9b, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x01, 0xf4 + }; + const json j = json::from_cbor(given); CHECK(j == json::parse("[false]")); } SECTION("0xbb (map)") { - std::vector given = {0xbb, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x01, 0x60, 0xf4 - }; - json j = json::from_cbor(given); + std::vector const given = {0xbb, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x01, 0x60, 0xf4 + }; + const json j = json::from_cbor(given); CHECK(j == json::parse("{\"\": false}")); } } @@ -1724,7 +1761,7 @@ TEST_CASE("CBOR") SECTION("all unsupported bytes") { - for (auto byte : + for (const auto byte : { // ? 0x1c, 0x1d, 0x1e, 0x1f, @@ -1778,7 +1815,7 @@ TEST_CASE("CBOR") SECTION("strict mode") { - std::vector vec = {0xf6, 0xf6}; + std::vector const vec = {0xf6, 0xf6}; SECTION("non-strict mode") { const auto result = json::from_cbor(vec, false); @@ -1799,21 +1836,21 @@ TEST_CASE("CBOR") { SECTION("start_array(len)") { - std::vector v = {0x83, 0x01, 0x02, 0x03}; + std::vector 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 v = {0xA1, 0x63, 0x66, 0x6F, 0x6F, 0xF4}; + std::vector 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 v = {0xA1, 0x63, 0x66, 0x6F, 0x6F, 0xF4}; + std::vector const v = {0xA1, 0x63, 0x66, 0x6F, 0x6F, 0xF4}; SaxCountdown scp(1); CHECK(!json::sax_parse(v, &scp, json::input_format_t::cbor)); } @@ -1825,11 +1862,11 @@ 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); - json j1 = json::parse(f_json); + const json j1 = json::parse(f_json); // parse CBOR file auto packed = utils::read_binary_file(filename + ".cbor"); @@ -1874,7 +1911,7 @@ TEST_CASE("CBOR regressions") AFL-Fuzz. As a result, empty byte vectors and excessive lengths are detected. */ - for (std::string filename : + for (const std::string filename : { TEST_DATA_DIRECTORY "/cbor_regression/test01", TEST_DATA_DIRECTORY "/cbor_regression/test02", @@ -1910,7 +1947,7 @@ TEST_CASE("CBOR regressions") 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); @@ -1951,7 +1988,7 @@ TEST_CASE("CBOR roundtrips" * doctest::skip()) exclude_packed.insert(TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_duplicated_key.json"); exclude_packed.insert(TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_long_strings.json"); - for (std::string filename : + for (const std::string filename : { TEST_DATA_DIRECTORY "/json_nlohmann_tests/all_unicode.json", TEST_DATA_DIRECTORY "/json.org/1.json", @@ -2109,7 +2146,7 @@ TEST_CASE("CBOR roundtrips" * doctest::skip()) json j1 = json::parse(f_json); // parse CBOR file - auto packed = utils::read_binary_file(filename + ".cbor"); + const auto packed = utils::read_binary_file(filename + ".cbor"); json j2; CHECK_NOTHROW(j2 = json::from_cbor(packed)); @@ -2139,7 +2176,7 @@ TEST_CASE("CBOR roundtrips" * doctest::skip()) json j1 = json::parse(f_json); // parse CBOR file - auto packed = utils::read_binary_file(filename + ".cbor"); + const auto packed = utils::read_binary_file(filename + ".cbor"); json j2; CHECK_NOTHROW(j2 = json::from_cbor({packed.data(), packed.size()})); @@ -2151,10 +2188,10 @@ 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"); + const auto packed = utils::read_binary_file(filename + ".cbor"); if (exclude_packed.count(filename) == 0u) { @@ -2389,11 +2426,11 @@ TEST_CASE("examples from RFC 7049 Appendix A") SECTION("byte arrays") { - auto packed = utils::read_binary_file(TEST_DATA_DIRECTORY "/binary_data/cbor_binary.cbor"); + const auto packed = utils::read_binary_file(TEST_DATA_DIRECTORY "/binary_data/cbor_binary.cbor"); json j; CHECK_NOTHROW(j = json::from_cbor(packed)); - auto expected = utils::read_binary_file(TEST_DATA_DIRECTORY "/binary_data/cbor_binary.out"); + const auto expected = utils::read_binary_file(TEST_DATA_DIRECTORY "/binary_data/cbor_binary.out"); CHECK(j == json::binary(expected)); // 0xd8 @@ -2460,12 +2497,12 @@ TEST_CASE("examples from RFC 7049 Appendix A") TEST_CASE("Tagged values") { - json j = "s"; + const json j = "s"; auto v = json::to_cbor(j); SECTION("0xC6..0xD4") { - for (auto b : std::vector + for (const auto b : std::vector { 0xC6, 0xC7, 0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF, 0xD0, 0xD1, 0xD2, 0xD3, 0xD4 }) diff --git a/tests/src/unit-class_const_iterator.cpp b/tests/src/unit-class_const_iterator.cpp index 3c5ba053f..290ab0b2d 100644 --- a/tests/src/unit-class_const_iterator.cpp +++ b/tests/src/unit-class_const_iterator.cpp @@ -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; diff --git a/tests/src/unit-class_iterator.cpp b/tests/src/unit-class_iterator.cpp index 8a36c18a7..2bed4657d 100644 --- a/tests/src/unit-class_iterator.cpp +++ b/tests/src/unit-class_iterator.cpp @@ -27,26 +27,26 @@ TEST_CASE("iterator class") SECTION("null") { json j(json::value_t::null); - json::iterator it(&j); + json::iterator const it(&j); } SECTION("object") { json j(json::value_t::object); - json::iterator it(&j); + json::iterator const it(&j); } SECTION("array") { json j(json::value_t::array); - json::iterator it(&j); + json::iterator const it(&j); } } SECTION("copy assignment") { json j(json::value_t::null); - json::iterator it(&j); + json::iterator const it(&j); json::iterator it2(&j); it2 = it; } @@ -116,7 +116,7 @@ TEST_CASE("iterator class") SECTION("null") { json j(json::value_t::null); - json::iterator it = j.begin(); + json::iterator const it = j.begin(); CHECK_THROWS_WITH_AS(*it, "[json.exception.invalid_iterator.214] cannot get value", json::invalid_iterator&); } @@ -132,14 +132,14 @@ TEST_CASE("iterator class") SECTION("object") { json j({{"foo", "bar"}}); - json::iterator it = j.begin(); + json::iterator const it = j.begin(); CHECK(*it == json("bar")); } SECTION("array") { json j({1, 2, 3, 4}); - json::iterator it = j.begin(); + json::iterator const it = j.begin(); CHECK(*it == json(1)); } } @@ -149,7 +149,7 @@ TEST_CASE("iterator class") SECTION("null") { json j(json::value_t::null); - json::iterator it = j.begin(); + json::iterator const it = j.begin(); CHECK_THROWS_WITH_AS(std::string(it->type_name()), "[json.exception.invalid_iterator.214] cannot get value", json::invalid_iterator&); } @@ -165,14 +165,14 @@ TEST_CASE("iterator class") SECTION("object") { json j({{"foo", "bar"}}); - json::iterator it = j.begin(); + json::iterator const it = j.begin(); CHECK(std::string(it->type_name()) == "string"); } SECTION("array") { json j({1, 2, 3, 4}); - json::iterator it = j.begin(); + json::iterator const it = j.begin(); CHECK(std::string(it->type_name()) == "number"); } } @@ -287,7 +287,7 @@ TEST_CASE("iterator class") SECTION("null") { json j(json::value_t::null); - json::iterator it = j.end(); + json::iterator const it = j.end(); CHECK((it.m_it.primitive_iterator.m_it == 1)); } @@ -336,7 +336,7 @@ TEST_CASE("iterator class") SECTION("null") { json j(json::value_t::null); - json::iterator it = j.end(); + json::iterator const it = j.end(); CHECK((it.m_it.primitive_iterator.m_it == 1)); } 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-comparison.cpp b/tests/src/unit-comparison.cpp index b838c02f2..7f990d252 100644 --- a/tests/src/unit-comparison.cpp +++ b/tests/src/unit-comparison.cpp @@ -391,7 +391,7 @@ TEST_CASE("lexicographical comparison operators") } // compare with null pointer - json j_null; + const json j_null; CHECK((j_null != nullptr) == false); CHECK((nullptr != j_null) == false); CHECK((j_null != nullptr) == !(j_null == nullptr)); diff --git a/tests/src/unit-concepts.cpp b/tests/src/unit-concepts.cpp index 3a0c81b05..e96caba7e 100644 --- a/tests/src/unit-concepts.cpp +++ b/tests/src/unit-concepts.cpp @@ -57,7 +57,7 @@ TEST_CASE("concepts") // the expression "X u" has the post-condition "u.empty()" { - json u; + const json u; CHECK(u.empty()); } diff --git a/tests/src/unit-constructor1.cpp b/tests/src/unit-constructor1.cpp index 791fb60b3..2235ba8f0 100644 --- a/tests/src/unit-constructor1.cpp +++ b/tests/src/unit-constructor1.cpp @@ -27,76 +27,76 @@ TEST_CASE("constructors") { SECTION("null") { - auto t = json::value_t::null; - json j(t); + auto const t = json::value_t::null; + json const j(t); CHECK(j.type() == t); } SECTION("discarded") { - auto t = json::value_t::discarded; - json j(t); + auto const t = json::value_t::discarded; + json const j(t); CHECK(j.type() == t); } SECTION("object") { - auto t = json::value_t::object; - json j(t); + auto const t = json::value_t::object; + json const j(t); CHECK(j.type() == t); } SECTION("array") { - auto t = json::value_t::array; - json j(t); + auto const t = json::value_t::array; + json const j(t); CHECK(j.type() == t); } SECTION("boolean") { - auto t = json::value_t::boolean; - json j(t); + auto const t = json::value_t::boolean; + json const j(t); CHECK(j.type() == t); CHECK(j == false); } SECTION("string") { - auto t = json::value_t::string; - json j(t); + auto const t = json::value_t::string; + json const j(t); CHECK(j.type() == t); CHECK(j == ""); } SECTION("number_integer") { - auto t = json::value_t::number_integer; - json j(t); + auto const t = json::value_t::number_integer; + json const j(t); CHECK(j.type() == t); CHECK(j == 0); } SECTION("number_unsigned") { - auto t = json::value_t::number_unsigned; - json j(t); + auto const t = json::value_t::number_unsigned; + json const j(t); CHECK(j.type() == t); CHECK(j == 0); } SECTION("number_float") { - auto t = json::value_t::number_float; - json j(t); + auto const t = json::value_t::number_float; + json const j(t); CHECK(j.type() == t); CHECK(j == 0.0); } SECTION("binary") { - auto t = json::value_t::binary; - json j(t); + auto const t = json::value_t::binary; + json const j(t); CHECK(j.type() == t); CHECK(j == json::binary({})); } @@ -106,7 +106,7 @@ TEST_CASE("constructors") { SECTION("no parameter") { - json j{}; + json const j{}; CHECK(j.type() == json::value_t::null); } } @@ -115,7 +115,7 @@ TEST_CASE("constructors") { SECTION("parameter") { - json j(nullptr); + json const j(nullptr); CHECK(j.type() == json::value_t::null); } } @@ -124,15 +124,15 @@ TEST_CASE("constructors") { SECTION("empty object") { - json::object_t o; - json j(o); + json::object_t const o{}; + json const j(o); CHECK(j.type() == json::value_t::object); } SECTION("filled object") { - json::object_t o {{"a", json(1)}, {"b", json(1u)}, {"c", json(2.2)}, {"d", json(false)}, {"e", json("string")}, {"f", json()}}; - json j(o); + json::object_t const o {{"a", json(1)}, {"b", json(1u)}, {"c", json(2.2)}, {"d", json(false)}, {"e", json("string")}, {"f", json()}}; + json const j(o); CHECK(j.type() == json::value_t::object); } } @@ -140,32 +140,34 @@ TEST_CASE("constructors") SECTION("create an object (implicit)") { // reference object - json::object_t o_reference {{"a", json(1)}, {"b", json(1u)}, {"c", json(2.2)}, {"d", json(false)}, {"e", json("string")}, {"f", json()}}; - json j_reference(o_reference); + json::object_t const o_reference {{"a", json(1)}, {"b", json(1u)}, {"c", json(2.2)}, {"d", json(false)}, {"e", json("string")}, {"f", json()}}; + json const j_reference(o_reference); SECTION("std::map") { - std::map o {{"a", json(1)}, {"b", json(1u)}, {"c", json(2.2)}, {"d", json(false)}, {"e", json("string")}, {"f", json()}}; - json j(o); + std::map const o {{"a", json(1)}, {"b", json(1u)}, {"c", json(2.2)}, {"d", json(false)}, {"e", json("string")}, {"f", json()}}; + json const j(o); CHECK(j.type() == json::value_t::object); CHECK(j == j_reference); } SECTION("std::map #600") { - std::map m; - m["a"] = "b"; - m["c"] = "d"; - m["e"] = "f"; + const std::map m + { + {"a", "b"}, + {"c", "d"}, + {"e", "f"}, + }; - json j(m); + json const j(m); CHECK((j.get() == m)); } SECTION("std::map") { - std::map o {{"a", json(1)}, {"b", json(1u)}, {"c", json(2.2)}, {"d", json(false)}, {"e", json("string")}, {"f", json()}}; - json j(o); + std::map const o {{"a", json(1)}, {"b", json(1u)}, {"c", json(2.2)}, {"d", json(false)}, {"e", json("string")}, {"f", json()}}; + json const j(o); CHECK(j.type() == json::value_t::object); CHECK(j == j_reference); } @@ -173,31 +175,31 @@ TEST_CASE("constructors") SECTION("std::multimap") { - std::multimap o {{"a", json(1)}, {"b", json(1u)}, {"c", json(2.2)}, {"d", json(false)}, {"e", json("string")}, {"f", json()}}; - json j(o); + std::multimap const o {{"a", json(1)}, {"b", json(1u)}, {"c", json(2.2)}, {"d", json(false)}, {"e", json("string")}, {"f", json()}}; + json const j(o); CHECK(j.type() == json::value_t::object); CHECK(j == j_reference); } SECTION("std::unordered_map") { - std::unordered_map o {{"a", json(1)}, {"b", json(1u)}, {"c", json(2.2)}, {"d", json(false)}, {"e", json("string")}, {"f", json()}}; - json j(o); + std::unordered_map const o {{"a", json(1)}, {"b", json(1u)}, {"c", json(2.2)}, {"d", json(false)}, {"e", json("string")}, {"f", json()}}; + json const j(o); CHECK(j.type() == json::value_t::object); CHECK(j == j_reference); } SECTION("std::unordered_multimap") { - std::unordered_multimap o {{"a", json(1)}, {"b", json(1u)}, {"c", json(2.2)}, {"d", json(false)}, {"e", json("string")}, {"f", json()}}; - json j(o); + std::unordered_multimap const o {{"a", json(1)}, {"b", json(1u)}, {"c", json(2.2)}, {"d", json(false)}, {"e", json("string")}, {"f", json()}}; + json const j(o); CHECK(j.type() == json::value_t::object); CHECK(j == j_reference); } SECTION("associative container literal") { - json j({{"a", json(1)}, {"b", json(1u)}, {"c", json(2.2)}, {"d", json(false)}, {"e", json("string")}, {"f", json()}}); + json const j({{"a", json(1)}, {"b", json(1u)}, {"c", json(2.2)}, {"d", json(false)}, {"e", json("string")}, {"f", json()}}); CHECK(j.type() == json::value_t::object); CHECK(j == j_reference); } @@ -207,15 +209,15 @@ TEST_CASE("constructors") { SECTION("empty array") { - json::array_t a; - json j(a); + json::array_t const a{}; + json const j(a); CHECK(j.type() == json::value_t::array); } SECTION("filled array") { - json::array_t a {json(1), json(1u), json(2.2), json(false), json("string"), json()}; - json j(a); + json::array_t const a {json(1), json(1u), json(2.2), json(false), json("string"), json()}; + json const j(a); CHECK(j.type() == json::value_t::array); } } @@ -223,21 +225,21 @@ TEST_CASE("constructors") SECTION("create an array (implicit)") { // reference array - json::array_t a_reference {json(1), json(1u), json(2.2), json(false), json("string"), json()}; - json j_reference(a_reference); + json::array_t const a_reference {json(1), json(1u), json(2.2), json(false), json("string"), json()}; + json const j_reference(a_reference); SECTION("std::list") { - std::list a {json(1), json(1u), json(2.2), json(false), json("string"), json()}; - json j(a); + std::list const a {json(1), json(1u), json(2.2), json(false), json("string"), json()}; + json const j(a); CHECK(j.type() == json::value_t::array); CHECK(j == j_reference); } SECTION("std::pair") { - std::pair p{1.0f, "string"}; - json j(p); + std::pair const p{1.0f, "string"}; + json const j(p); CHECK(j.type() == json::value_t::array); CHECK(j.get() == p); @@ -248,7 +250,7 @@ TEST_CASE("constructors") SECTION("std::pair with discarded values") { - json j{1, 2.0, "string"}; + json const j{1, 2.0, "string"}; const auto p = j.get>(); CHECK(p.first == j[0]); @@ -258,7 +260,7 @@ TEST_CASE("constructors") SECTION("std::tuple") { const auto t = std::make_tuple(1.0, std::string{"string"}, 42, std::vector {0, 1}); - json j(t); + json const j(t); CHECK(j.type() == json::value_t::array); REQUIRE(j.size() == 4); @@ -272,7 +274,7 @@ TEST_CASE("constructors") SECTION("std::tuple with discarded values") { - json j{1, 2.0, "string", 42}; + json const j{1, 2.0, "string", 42}; const auto t = j.get>(); CHECK(std::get<0>(t) == j[0]); @@ -282,7 +284,7 @@ TEST_CASE("constructors") SECTION("std::pair/tuple/array failures") { - json j{1}; + json const j{1}; CHECK_THROWS_WITH_AS((j.get>()), "[json.exception.out_of_range.401] array index 1 is out of range", json::out_of_range&); CHECK_THROWS_WITH_AS((j.get>()), "[json.exception.out_of_range.401] array index 1 is out of range", json::out_of_range&); @@ -291,16 +293,16 @@ TEST_CASE("constructors") SECTION("std::forward_list") { - std::forward_list a {json(1), json(1u), json(2.2), json(false), json("string"), json()}; - json j(a); + std::forward_list const a {json(1), json(1u), json(2.2), json(false), json("string"), json()}; + json const j(a); CHECK(j.type() == json::value_t::array); CHECK(j == j_reference); } SECTION("std::array") { - std::array a {{json(1), json(1u), json(2.2), json(false), json("string"), json()}}; - json j(a); + std::array const a {{json(1), json(1u), json(2.2), json(false), json("string"), json()}}; + json const j(a); CHECK(j.type() == json::value_t::array); CHECK(j == j_reference); @@ -310,8 +312,8 @@ TEST_CASE("constructors") SECTION("std::valarray") { - std::valarray va = {1, 2, 3, 4, 5}; - json j(va); + std::valarray const va = {1, 2, 3, 4, 5}; + json const j(va); CHECK(j.type() == json::value_t::array); CHECK(j == json({1, 2, 3, 4, 5})); @@ -325,8 +327,8 @@ TEST_CASE("constructors") SECTION("std::valarray") { - std::valarray va = {1.2, 2.3, 3.4, 4.5, 5.6}; - json j(va); + std::valarray const va = {1.2, 2.3, 3.4, 4.5, 5.6}; + json const j(va); CHECK(j.type() == json::value_t::array); CHECK(j == json({1.2, 2.3, 3.4, 4.5, 5.6})); @@ -340,39 +342,39 @@ TEST_CASE("constructors") SECTION("std::vector") { - std::vector a {json(1), json(1u), json(2.2), json(false), json("string"), json()}; - json j(a); + std::vector const a {json(1), json(1u), json(2.2), json(false), json("string"), json()}; + json const j(a); CHECK(j.type() == json::value_t::array); CHECK(j == j_reference); } SECTION("std::deque") { - std::deque a {json(1), json(1u), json(2.2), json(false), json("string"), json()}; - json j(a); + std::deque const a {json(1), json(1u), json(2.2), json(false), json("string"), json()}; + json const j(a); CHECK(j.type() == json::value_t::array); CHECK(j == j_reference); } SECTION("std::set") { - std::set a {json(1), json(1u), json(2.2), json(false), json("string"), json()}; - json j(a); + std::set const a {json(1), json(1u), json(2.2), json(false), json("string"), json()}; + json const j(a); CHECK(j.type() == json::value_t::array); // we cannot really check for equality here } SECTION("std::unordered_set") { - std::unordered_set a {json(1), json(1u), json(2.2), json(false), json("string"), json()}; - json j(a); + std::unordered_set const a {json(1), json(1u), json(2.2), json(false), json("string"), json()}; + json const j(a); CHECK(j.type() == json::value_t::array); // we cannot really check for equality here } SECTION("sequence container literal") { - json j({json(1), json(1u), json(2.2), json(false), json("string"), json()}); + json const j({json(1), json(1u), json(2.2), json(false), json("string"), json()}); CHECK(j.type() == json::value_t::array); CHECK(j == j_reference); } @@ -382,15 +384,15 @@ TEST_CASE("constructors") { SECTION("empty string") { - json::string_t s; - json j(s); + json::string_t const s{}; + json const j(s); CHECK(j.type() == json::value_t::string); } SECTION("filled string") { - json::string_t s {"Hello world"}; - json j(s); + json::string_t const s {"Hello world"}; + json const j(s); CHECK(j.type() == json::value_t::string); } } @@ -398,21 +400,21 @@ TEST_CASE("constructors") SECTION("create a string (implicit)") { // reference string - json::string_t s_reference {"Hello world"}; - json j_reference(s_reference); + json::string_t const s_reference {"Hello world"}; + json const j_reference(s_reference); SECTION("std::string") { - std::string s {"Hello world"}; - json j(s); + std::string const s {"Hello world"}; + json const j(s); CHECK(j.type() == json::value_t::string); CHECK(j == j_reference); } SECTION("char[]") { - char s[] {"Hello world"}; // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays) - json j(s); + char const s[] {"Hello world"}; // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays) + json const j(s); CHECK(j.type() == json::value_t::string); CHECK(j == j_reference); } @@ -420,14 +422,14 @@ TEST_CASE("constructors") SECTION("const char*") { const char* s {"Hello world"}; - json j(s); + json const j(s); CHECK(j.type() == json::value_t::string); CHECK(j == j_reference); } SECTION("string literal") { - json j("Hello world"); + json const j("Hello world"); CHECK(j.type() == json::value_t::string); CHECK(j == j_reference); } @@ -437,27 +439,27 @@ TEST_CASE("constructors") { SECTION("empty boolean") { - json::boolean_t b{}; - json j(b); + json::boolean_t const b{}; + json const j(b); CHECK(j.type() == json::value_t::boolean); } SECTION("filled boolean (true)") { - json j(true); + json const j(true); CHECK(j.type() == json::value_t::boolean); } SECTION("filled boolean (false)") { - json j(false); + json const j(false); CHECK(j.type() == json::value_t::boolean); } SECTION("from std::vector::reference") { std::vector v{true}; - json j(v[0]); + json const j(v[0]); CHECK(std::is_same::reference>::value); CHECK(j.type() == json::value_t::boolean); } @@ -465,7 +467,7 @@ TEST_CASE("constructors") SECTION("from std::vector::const_reference") { const std::vector v{true}; - json j(v[0]); + json const j(v[0]); CHECK(std::is_same::const_reference>::value); CHECK(j.type() == json::value_t::boolean); } @@ -475,15 +477,15 @@ TEST_CASE("constructors") { SECTION("empty binary") { - json::binary_t b{}; - json j(b); + json::binary_t const b{}; + json const j(b); CHECK(j.type() == json::value_t::binary); } SECTION("filled binary") { - json::binary_t b({1, 2, 3}); - json j(b); + json::binary_t const b({1, 2, 3}); + json const j(b); CHECK(j.type() == json::value_t::binary); } } @@ -492,15 +494,15 @@ TEST_CASE("constructors") { SECTION("uninitialized value") { - json::number_integer_t n{}; - json j(n); + json::number_integer_t const n{}; + json const j(n); CHECK(j.type() == json::value_t::number_integer); } SECTION("initialized value") { - json::number_integer_t n(42); - json j(n); + json::number_integer_t const n(42); + json const j(n); CHECK(j.type() == json::value_t::number_integer); } } @@ -508,270 +510,270 @@ TEST_CASE("constructors") SECTION("create an integer number (implicit)") { // reference objects - json::number_integer_t n_reference = 42; - json j_reference(n_reference); - json::number_unsigned_t n_unsigned_reference = 42; - json j_unsigned_reference(n_unsigned_reference); + json::number_integer_t const n_reference = 42; + json const j_reference(n_reference); + json::number_unsigned_t const n_unsigned_reference = 42; + json const j_unsigned_reference(n_unsigned_reference); SECTION("short") { - short n = 42; - json j(n); + short const n = 42; + json const j(n); CHECK(j.type() == json::value_t::number_integer); CHECK(j == j_reference); } SECTION("unsigned short") { - unsigned short n = 42; - json j(n); + unsigned short const n = 42; + json const j(n); CHECK(j.type() == json::value_t::number_unsigned); CHECK(j == j_unsigned_reference); } SECTION("int") { - int n = 42; - json j(n); + int const n = 42; + json const j(n); CHECK(j.type() == json::value_t::number_integer); CHECK(j == j_reference); } SECTION("unsigned int") { - unsigned int n = 42; - json j(n); + unsigned int const n = 42; + json const j(n); CHECK(j.type() == json::value_t::number_unsigned); CHECK(j == j_unsigned_reference); } SECTION("long") { - long n = 42; - json j(n); + long const n = 42; + json const j(n); CHECK(j.type() == json::value_t::number_integer); CHECK(j == j_reference); } SECTION("unsigned long") { - unsigned long n = 42; - json j(n); + unsigned long const n = 42; + json const j(n); CHECK(j.type() == json::value_t::number_unsigned); CHECK(j == j_unsigned_reference); } SECTION("long long") { - long long n = 42; - json j(n); + long long const n = 42; + json const j(n); CHECK(j.type() == json::value_t::number_integer); CHECK(j == j_reference); } SECTION("unsigned long long") { - unsigned long long n = 42; - json j(n); + unsigned long long const n = 42; + json const j(n); CHECK(j.type() == json::value_t::number_unsigned); CHECK(j == j_unsigned_reference); } SECTION("int8_t") { - int8_t n = 42; - json j(n); + int8_t const n = 42; + json const j(n); CHECK(j.type() == json::value_t::number_integer); CHECK(j == j_reference); } SECTION("int16_t") { - int16_t n = 42; - json j(n); + int16_t const n = 42; + json const j(n); CHECK(j.type() == json::value_t::number_integer); CHECK(j == j_reference); } SECTION("int32_t") { - int32_t n = 42; - json j(n); + int32_t const n = 42; + json const j(n); CHECK(j.type() == json::value_t::number_integer); CHECK(j == j_reference); } SECTION("int64_t") { - int64_t n = 42; - json j(n); + int64_t const n = 42; + json const j(n); CHECK(j.type() == json::value_t::number_integer); CHECK(j == j_reference); } SECTION("int_fast8_t") { - int_fast8_t n = 42; - json j(n); + int_fast8_t const n = 42; + json const j(n); CHECK(j.type() == json::value_t::number_integer); CHECK(j == j_reference); } SECTION("int_fast16_t") { - int_fast16_t n = 42; - json j(n); + int_fast16_t const n = 42; + json const j(n); CHECK(j.type() == json::value_t::number_integer); CHECK(j == j_reference); } SECTION("int_fast32_t") { - int_fast32_t n = 42; - json j(n); + int_fast32_t const n = 42; + json const j(n); CHECK(j.type() == json::value_t::number_integer); CHECK(j == j_reference); } SECTION("int_fast64_t") { - int_fast64_t n = 42; - json j(n); + int_fast64_t const n = 42; + json const j(n); CHECK(j.type() == json::value_t::number_integer); CHECK(j == j_reference); } SECTION("int_least8_t") { - int_least8_t n = 42; - json j(n); + int_least8_t const n = 42; + json const j(n); CHECK(j.type() == json::value_t::number_integer); CHECK(j == j_reference); } SECTION("int_least16_t") { - int_least16_t n = 42; - json j(n); + int_least16_t const n = 42; + json const j(n); CHECK(j.type() == json::value_t::number_integer); CHECK(j == j_reference); } SECTION("int_least32_t") { - int_least32_t n = 42; - json j(n); + int_least32_t const n = 42; + json const j(n); CHECK(j.type() == json::value_t::number_integer); CHECK(j == j_reference); } SECTION("int_least64_t") { - int_least64_t n = 42; - json j(n); + int_least64_t const n = 42; + json const j(n); CHECK(j.type() == json::value_t::number_integer); CHECK(j == j_reference); } SECTION("uint8_t") { - uint8_t n = 42; - json j(n); + uint8_t const n = 42; + json const j(n); CHECK(j.type() == json::value_t::number_unsigned); CHECK(j == j_unsigned_reference); } SECTION("uint16_t") { - uint16_t n = 42; - json j(n); + uint16_t const n = 42; + json const j(n); CHECK(j.type() == json::value_t::number_unsigned); CHECK(j == j_unsigned_reference); } SECTION("uint32_t") { - uint32_t n = 42; - json j(n); + uint32_t const n = 42; + json const j(n); CHECK(j.type() == json::value_t::number_unsigned); CHECK(j == j_unsigned_reference); } SECTION("uint64_t") { - uint64_t n = 42; - json j(n); + uint64_t const n = 42; + json const j(n); CHECK(j.type() == json::value_t::number_unsigned); CHECK(j == j_unsigned_reference); } SECTION("uint_fast8_t") { - uint_fast8_t n = 42; - json j(n); + uint_fast8_t const n = 42; + json const j(n); CHECK(j.type() == json::value_t::number_unsigned); CHECK(j == j_unsigned_reference); } SECTION("uint_fast16_t") { - uint_fast16_t n = 42; - json j(n); + uint_fast16_t const n = 42; + json const j(n); CHECK(j.type() == json::value_t::number_unsigned); CHECK(j == j_unsigned_reference); } SECTION("uint_fast32_t") { - uint_fast32_t n = 42; - json j(n); + uint_fast32_t const n = 42; + json const j(n); CHECK(j.type() == json::value_t::number_unsigned); CHECK(j == j_unsigned_reference); } SECTION("uint_fast64_t") { - uint_fast64_t n = 42; - json j(n); + uint_fast64_t const n = 42; + json const j(n); CHECK(j.type() == json::value_t::number_unsigned); CHECK(j == j_unsigned_reference); } SECTION("uint_least8_t") { - uint_least8_t n = 42; - json j(n); + uint_least8_t const n = 42; + json const j(n); CHECK(j.type() == json::value_t::number_unsigned); CHECK(j == j_unsigned_reference); } SECTION("uint_least16_t") { - uint_least16_t n = 42; - json j(n); + uint_least16_t const n = 42; + json const j(n); CHECK(j.type() == json::value_t::number_unsigned); CHECK(j == j_unsigned_reference); } SECTION("uint_least32_t") { - uint_least32_t n = 42; - json j(n); + uint_least32_t const n = 42; + json const j(n); CHECK(j.type() == json::value_t::number_unsigned); CHECK(j == j_unsigned_reference); } SECTION("uint_least64_t") { - uint_least64_t n = 42; - json j(n); + uint_least64_t const n = 42; + json const j(n); CHECK(j.type() == json::value_t::number_unsigned); CHECK(j == j_unsigned_reference); } SECTION("integer literal without suffix") { - json j(42); + json const j(42); CHECK(j.type() == json::value_t::number_integer); CHECK(j == j_reference); } @@ -785,7 +787,7 @@ TEST_CASE("constructors") SECTION("integer literal with l suffix") { - json j(42L); + json const j(42L); CHECK(j.type() == json::value_t::number_integer); CHECK(j == j_reference); } @@ -799,7 +801,7 @@ TEST_CASE("constructors") SECTION("integer literal with ll suffix") { - json j(42LL); + json const j(42LL); CHECK(j.type() == json::value_t::number_integer); CHECK(j == j_reference); } @@ -816,27 +818,27 @@ TEST_CASE("constructors") { SECTION("uninitialized value") { - json::number_float_t n{}; - json j(n); + json::number_float_t const n{}; + json const j(n); CHECK(j.type() == json::value_t::number_float); } SECTION("initialized value") { - json::number_float_t n(42.23); - json j(n); + json::number_float_t const n(42.23); + json const j(n); CHECK(j.type() == json::value_t::number_float); } SECTION("NaN") { // NaN is stored properly, but serialized to null - json::number_float_t n(std::numeric_limits::quiet_NaN()); - json j(n); + json::number_float_t const n(std::numeric_limits::quiet_NaN()); + json const j(n); CHECK(j.type() == json::value_t::number_float); // check round trip of NaN - json::number_float_t d{j}; + json::number_float_t const d{j}; CHECK((std::isnan(d) && std::isnan(n)) == true); // check that NaN is serialized to null @@ -846,12 +848,12 @@ TEST_CASE("constructors") SECTION("infinity") { // infinity is stored properly, but serialized to null - json::number_float_t n(std::numeric_limits::infinity()); - json j(n); + json::number_float_t const n(std::numeric_limits::infinity()); + json const j(n); CHECK(j.type() == json::value_t::number_float); // check round trip of infinity - json::number_float_t d{j}; + json::number_float_t const d{j}; CHECK(d == n); // check that inf is serialized to null @@ -862,50 +864,50 @@ TEST_CASE("constructors") SECTION("create a floating-point number (implicit)") { // reference object - json::number_float_t n_reference = 42.23; - json j_reference(n_reference); + json::number_float_t const n_reference = 42.23; + json const j_reference(n_reference); SECTION("float") { - float n = 42.23f; - json j(n); + float const n = 42.23f; + json const j(n); CHECK(j.type() == json::value_t::number_float); CHECK(j.m_value.number_float == Approx(j_reference.m_value.number_float)); } SECTION("double") { - double n = 42.23; - json j(n); + double const n = 42.23; + json const j(n); CHECK(j.type() == json::value_t::number_float); CHECK(j.m_value.number_float == Approx(j_reference.m_value.number_float)); } SECTION("long double") { - long double n = 42.23L; - json j(n); + long double const n = 42.23L; + json const j(n); CHECK(j.type() == json::value_t::number_float); CHECK(j.m_value.number_float == Approx(j_reference.m_value.number_float)); } SECTION("floating-point literal without suffix") { - json j(42.23); + json const j(42.23); CHECK(j.type() == json::value_t::number_float); CHECK(j.m_value.number_float == Approx(j_reference.m_value.number_float)); } SECTION("integer literal with f suffix") { - json j(42.23f); + json const j(42.23f); CHECK(j.type() == json::value_t::number_float); CHECK(j.m_value.number_float == Approx(j_reference.m_value.number_float)); } SECTION("integer literal with l suffix") { - json j(42.23L); + json const j(42.23L); CHECK(j.type() == json::value_t::number_float); CHECK(j.m_value.number_float == Approx(j_reference.m_value.number_float)); } @@ -917,13 +919,13 @@ TEST_CASE("constructors") { SECTION("explicit") { - json j(json::initializer_list_t {}); + json const j(json::initializer_list_t {}); CHECK(j.type() == json::value_t::object); } SECTION("implicit") { - json j {}; + json const j {}; CHECK(j.type() == json::value_t::null); } } @@ -934,13 +936,13 @@ TEST_CASE("constructors") { SECTION("explicit") { - json j(json::initializer_list_t {json(json::array_t())}); + json const j(json::initializer_list_t {json(json::array_t())}); CHECK(j.type() == json::value_t::array); } SECTION("implicit") { - json j {json::array_t()}; + json const j {json::array_t()}; CHECK(j.type() == json::value_t::array); } } @@ -949,13 +951,13 @@ TEST_CASE("constructors") { SECTION("explicit") { - json j(json::initializer_list_t {json(json::object_t())}); + json const j(json::initializer_list_t {json(json::object_t())}); CHECK(j.type() == json::value_t::array); } SECTION("implicit") { - json j {json::object_t()}; + json const j {json::object_t()}; CHECK(j.type() == json::value_t::array); } } @@ -964,13 +966,13 @@ TEST_CASE("constructors") { SECTION("explicit") { - json j(json::initializer_list_t {json("Hello world")}); + json const j(json::initializer_list_t {json("Hello world")}); CHECK(j.type() == json::value_t::array); } SECTION("implicit") { - json j {"Hello world"}; + json const j {"Hello world"}; CHECK(j.type() == json::value_t::array); } } @@ -979,13 +981,13 @@ TEST_CASE("constructors") { SECTION("explicit") { - json j(json::initializer_list_t {json(true)}); + json const j(json::initializer_list_t {json(true)}); CHECK(j.type() == json::value_t::array); } SECTION("implicit") { - json j {true}; + json const j {true}; CHECK(j.type() == json::value_t::array); } } @@ -994,13 +996,13 @@ TEST_CASE("constructors") { SECTION("explicit") { - json j(json::initializer_list_t {json(1)}); + json const j(json::initializer_list_t {json(1)}); CHECK(j.type() == json::value_t::array); } SECTION("implicit") { - json j {1}; + json const j {1}; CHECK(j.type() == json::value_t::array); } } @@ -1009,13 +1011,13 @@ TEST_CASE("constructors") { SECTION("explicit") { - json j(json::initializer_list_t {json(1u)}); + json const j(json::initializer_list_t {json(1u)}); CHECK(j.type() == json::value_t::array); } SECTION("implicit") { - json j {1u}; + json const j {1u}; CHECK(j.type() == json::value_t::array); } } @@ -1024,13 +1026,13 @@ TEST_CASE("constructors") { SECTION("explicit") { - json j(json::initializer_list_t {json(42.23)}); + json const j(json::initializer_list_t {json(42.23)}); CHECK(j.type() == json::value_t::array); } SECTION("implicit") { - json j {42.23}; + json const j {42.23}; CHECK(j.type() == json::value_t::array); } } @@ -1040,13 +1042,13 @@ TEST_CASE("constructors") { SECTION("explicit") { - json j(json::initializer_list_t {1, 1u, 42.23, true, nullptr, json::object_t(), json::array_t()}); + json const j(json::initializer_list_t {1, 1u, 42.23, true, nullptr, json::object_t(), json::array_t()}); CHECK(j.type() == json::value_t::array); } SECTION("implicit") { - json j {1, 1u, 42.23, true, nullptr, json::object_t(), json::array_t()}; + json const j {1, 1u, 42.23, true, nullptr, json::object_t(), json::array_t()}; CHECK(j.type() == json::value_t::array); } } @@ -1055,13 +1057,13 @@ TEST_CASE("constructors") { SECTION("object") { - json j { {"one", 1}, {"two", 1u}, {"three", 2.2}, {"four", false} }; + json const j { {"one", 1}, {"two", 1u}, {"three", 2.2}, {"four", false} }; CHECK(j.type() == json::value_t::object); } SECTION("array") { - json j { {"one", 1}, {"two", 1u}, {"three", 2.2}, {"four", false}, 13 }; + json const j { {"one", 1}, {"two", 1u}, {"three", 2.2}, {"four", false}, 13 }; CHECK(j.type() == json::value_t::array); } } @@ -1070,13 +1072,13 @@ TEST_CASE("constructors") { SECTION("empty object") { - json j = json::object(); + json const j = json::object(); CHECK(j.type() == json::value_t::object); } SECTION("object") { - json j = json::object({ {"one", 1}, {"two", 1u}, {"three", 2.2}, {"four", false} }); + json const j = json::object({ {"one", 1}, {"two", 1u}, {"three", 2.2}, {"four", false} }); CHECK(j.type() == json::value_t::object); } @@ -1088,13 +1090,13 @@ TEST_CASE("constructors") SECTION("empty array") { - json j = json::array(); + json const j = json::array(); CHECK(j.type() == json::value_t::array); } SECTION("array") { - json j = json::array({ {"one", 1}, {"two", 1u}, {"three", 2.2}, {"four", false} }); + json const j = json::array({ {"one", 1}, {"two", 1u}, {"three", 2.2}, {"four", false} }); CHECK(j.type() == json::value_t::array); } } @@ -1153,7 +1155,7 @@ TEST_CASE("constructors") { json::array_t source = {1, 2, 3}; const auto* source_addr = source.data(); - json j {{"key", std::move(source)}}; + json const j {{"key", std::move(source)}}; const auto* target_addr = j["key"].get_ref().data(); const bool success = (target_addr == source_addr); CHECK(success); @@ -1257,17 +1259,17 @@ TEST_CASE("constructors") { SECTION("cnt = 0") { - json v = {1, "foo", 34.23, {1, 2, 3}, {{"A", 1}, {"B", 2u}}}; - json arr(0, v); + json const v = {1, "foo", 34.23, {1, 2, 3}, {{"A", 1}, {"B", 2u}}}; + json const arr(0, v); CHECK(arr.size() == 0); } SECTION("cnt = 1") { - json v = {1, "foo", 34.23, {1, 2, 3}, {{"A", 1}, {"B", 2u}}}; - json arr(1, v); + json const v = {1, "foo", 34.23, {1, 2, 3}, {{"A", 1}, {"B", 2u}}}; + json const arr(1, v); CHECK(arr.size() == 1); - for (auto& x : arr) + for (const auto& x : arr) { CHECK(x == v); } @@ -1275,10 +1277,10 @@ TEST_CASE("constructors") SECTION("cnt = 3") { - json v = {1, "foo", 34.23, {1, 2, 3}, {{"A", 1}, {"B", 2u}}}; - json arr(3, v); + json const v = {1, "foo", 34.23, {1, 2, 3}, {{"A", 1}, {"B", 2u}}}; + json const arr(3, v); CHECK(arr.size() == 3); - for (auto& x : arr) + for (const auto& x : arr) { CHECK(x == v); } @@ -1293,12 +1295,12 @@ TEST_CASE("constructors") { { json jobject = {{"a", "a"}, {"b", 1}, {"c", 17u}}; - json j_new(jobject.begin(), jobject.end()); + json const j_new(jobject.begin(), jobject.end()); CHECK(j_new == jobject); } { json jobject = {{"a", "a"}, {"b", 1}, {"c", 17u}}; - json j_new(jobject.cbegin(), jobject.cend()); + json const j_new(jobject.cbegin(), jobject.cend()); CHECK(j_new == jobject); } } @@ -1307,20 +1309,20 @@ TEST_CASE("constructors") { { json jobject = {{"a", "a"}, {"b", 1}, {"c", 17u}}; - json j_new(jobject.begin(), jobject.begin()); + json const j_new(jobject.begin(), jobject.begin()); CHECK(j_new == json::object()); } { - json jobject = {{"a", "a"}, {"b", 1}, {"c", 17u}}; - json j_new(jobject.cbegin(), jobject.cbegin()); + json const jobject = {{"a", "a"}, {"b", 1}, {"c", 17u}}; + json const j_new(jobject.cbegin(), jobject.cbegin()); CHECK(j_new == json::object()); } } SECTION("construct from subrange") { - json jobject = {{"a", "a"}, {"b", 1}, {"c", 17u}, {"d", false}, {"e", true}}; - json j_new(jobject.find("b"), jobject.find("e")); + json const jobject = {{"a", "a"}, {"b", 1}, {"c", 17u}, {"d", false}, {"e", true}}; + json const j_new(jobject.find("b"), jobject.find("e")); CHECK(j_new == json({{"b", 1}, {"c", 17u}, {"d", false}})); } @@ -1333,8 +1335,8 @@ TEST_CASE("constructors") CHECK_THROWS_WITH_AS(json(jobject2.begin(), jobject.end()), "[json.exception.invalid_iterator.201] iterators are not compatible", json::invalid_iterator&); } { - json jobject = {{"a", "a"}, {"b", 1}, {"c", 17u}, {"d", false}, {"e", true}}; - json jobject2 = {{"a", "a"}, {"b", 1}, {"c", 17u}}; + json const jobject = {{"a", "a"}, {"b", 1}, {"c", 17u}, {"d", false}, {"e", true}}; + json const jobject2 = {{"a", "a"}, {"b", 1}, {"c", 17u}}; CHECK_THROWS_WITH_AS(json(jobject.cbegin(), jobject2.cend()), "[json.exception.invalid_iterator.201] iterators are not compatible", json::invalid_iterator&); CHECK_THROWS_WITH_AS(json(jobject2.cbegin(), jobject.cend()), "[json.exception.invalid_iterator.201] iterators are not compatible", json::invalid_iterator&); } @@ -1347,12 +1349,12 @@ TEST_CASE("constructors") { { json jarray = {1, 2, 3, 4, 5}; - json j_new(jarray.begin(), jarray.end()); + json const j_new(jarray.begin(), jarray.end()); CHECK(j_new == jarray); } { - json jarray = {1, 2, 3, 4, 5}; - json j_new(jarray.cbegin(), jarray.cend()); + json const jarray = {1, 2, 3, 4, 5}; + json const j_new(jarray.cbegin(), jarray.cend()); CHECK(j_new == jarray); } } @@ -1365,8 +1367,8 @@ TEST_CASE("constructors") CHECK(j_new == json::array()); } { - json jarray = {1, 2, 3, 4, 5}; - json j_new(jarray.cbegin(), jarray.cbegin()); + json const jarray = {1, 2, 3, 4, 5}; + json const j_new(jarray.cbegin(), jarray.cbegin()); CHECK(j_new == json::array()); } } @@ -1375,12 +1377,12 @@ TEST_CASE("constructors") { { json jarray = {1, 2, 3, 4, 5}; - json j_new(jarray.begin() + 1, jarray.begin() + 3); + json const j_new(jarray.begin() + 1, jarray.begin() + 3); CHECK(j_new == json({2, 3})); } { - json jarray = {1, 2, 3, 4, 5}; - json j_new(jarray.cbegin() + 1, jarray.cbegin() + 3); + json const jarray = {1, 2, 3, 4, 5}; + json const j_new(jarray.cbegin() + 1, jarray.cbegin() + 3); CHECK(j_new == json({2, 3})); } } @@ -1394,8 +1396,8 @@ TEST_CASE("constructors") CHECK_THROWS_WITH_AS(json(jarray2.begin(), jarray.end()), "[json.exception.invalid_iterator.201] iterators are not compatible", json::invalid_iterator&); } { - json jarray = {1, 2, 3, 4}; - json jarray2 = {2, 3, 4, 5}; + json const jarray = {1, 2, 3, 4}; + json const jarray2 = {2, 3, 4, 5}; CHECK_THROWS_WITH_AS(json(jarray.cbegin(), jarray2.cend()), "[json.exception.invalid_iterator.201] iterators are not compatible", json::invalid_iterator&); CHECK_THROWS_WITH_AS(json(jarray2.cbegin(), jarray.cend()), "[json.exception.invalid_iterator.201] iterators are not compatible", json::invalid_iterator&); } @@ -1413,7 +1415,7 @@ TEST_CASE("constructors") CHECK_THROWS_WITH_AS(json(j.begin(), j.end()), "[json.exception.invalid_iterator.206] cannot construct with iterators from null", json::invalid_iterator&); } { - json j; + json const j; CHECK_THROWS_WITH_AS(json(j.cbegin(), j.cend()), "[json.exception.invalid_iterator.206] cannot construct with iterators from null", json::invalid_iterator&); } } @@ -1422,12 +1424,12 @@ TEST_CASE("constructors") { { json j = "foo"; - json j_new(j.begin(), j.end()); + json const j_new(j.begin(), j.end()); CHECK(j == j_new); } { - json j = "bar"; - json j_new(j.cbegin(), j.cend()); + json const j = "bar"; + json const j_new(j.cbegin(), j.cend()); CHECK(j == j_new); } } @@ -1436,12 +1438,12 @@ TEST_CASE("constructors") { { json j = false; - json j_new(j.begin(), j.end()); + json const j_new(j.begin(), j.end()); CHECK(j == j_new); } { - json j = true; - json j_new(j.cbegin(), j.cend()); + json const j = true; + json const j_new(j.cbegin(), j.cend()); CHECK(j == j_new); } } @@ -1450,12 +1452,12 @@ TEST_CASE("constructors") { { json j = 17; - json j_new(j.begin(), j.end()); + json const j_new(j.begin(), j.end()); CHECK(j == j_new); } { - json j = 17; - json j_new(j.cbegin(), j.cend()); + json const j = 17; + json const j_new(j.cbegin(), j.cend()); CHECK(j == j_new); } } @@ -1464,12 +1466,12 @@ TEST_CASE("constructors") { { json j = 17u; - json j_new(j.begin(), j.end()); + json const j_new(j.begin(), j.end()); CHECK(j == j_new); } { - json j = 17u; - json j_new(j.cbegin(), j.cend()); + json const j = 17u; + json const j_new(j.cbegin(), j.cend()); CHECK(j == j_new); } } @@ -1478,12 +1480,12 @@ TEST_CASE("constructors") { { json j = 23.42; - json j_new(j.begin(), j.end()); + json const j_new(j.begin(), j.end()); CHECK(j == j_new); } { - json j = 23.42; - json j_new(j.cbegin(), j.cend()); + json const j = 23.42; + json const j_new(j.cbegin(), j.cend()); CHECK(j == j_new); } } @@ -1492,12 +1494,12 @@ TEST_CASE("constructors") { { json j = json::binary({1, 2, 3}); - json j_new(j.begin(), j.end()); + json const j_new(j.begin(), j.end()); CHECK((j == j_new)); } { - json j = json::binary({1, 2, 3}); - json j_new(j.cbegin(), j.cend()); + json const j = json::binary({1, 2, 3}); + json const j_new(j.cbegin(), j.cend()); CHECK((j == j_new)); } } @@ -1513,7 +1515,7 @@ TEST_CASE("constructors") CHECK_THROWS_WITH_AS(json(j.begin(), j.begin()), "[json.exception.invalid_iterator.204] iterators out of range", json::invalid_iterator&); } { - json j = "bar"; + json const j = "bar"; CHECK_THROWS_WITH_AS(json(j.cend(), j.cend()), "[json.exception.invalid_iterator.204] iterators out of range", json::invalid_iterator&); CHECK_THROWS_WITH_AS(json(j.cbegin(), j.cbegin()), "[json.exception.invalid_iterator.204] iterators out of range", json::invalid_iterator&); } @@ -1527,7 +1529,7 @@ TEST_CASE("constructors") CHECK_THROWS_WITH_AS(json(j.begin(), j.begin()), "[json.exception.invalid_iterator.204] iterators out of range", json::invalid_iterator&); } { - json j = true; + json const j = true; CHECK_THROWS_WITH_AS(json(j.cend(), j.cend()), "[json.exception.invalid_iterator.204] iterators out of range", json::invalid_iterator&); CHECK_THROWS_WITH_AS(json(j.cbegin(), j.cbegin()), "[json.exception.invalid_iterator.204] iterators out of range", json::invalid_iterator&); } @@ -1541,7 +1543,7 @@ TEST_CASE("constructors") CHECK_THROWS_WITH_AS(json(j.begin(), j.begin()), "[json.exception.invalid_iterator.204] iterators out of range", json::invalid_iterator&); } { - json j = 17; + json const j = 17; CHECK_THROWS_WITH_AS(json(j.cend(), j.cend()), "[json.exception.invalid_iterator.204] iterators out of range", json::invalid_iterator&); CHECK_THROWS_WITH_AS(json(j.cbegin(), j.cbegin()), "[json.exception.invalid_iterator.204] iterators out of range", json::invalid_iterator&); } @@ -1555,7 +1557,7 @@ TEST_CASE("constructors") CHECK_THROWS_WITH_AS(json(j.begin(), j.begin()), "[json.exception.invalid_iterator.204] iterators out of range", json::invalid_iterator&); } { - json j = 17u; + json const j = 17u; CHECK_THROWS_WITH_AS(json(j.cend(), j.cend()), "[json.exception.invalid_iterator.204] iterators out of range", json::invalid_iterator&); CHECK_THROWS_WITH_AS(json(j.cbegin(), j.cbegin()), "[json.exception.invalid_iterator.204] iterators out of range", json::invalid_iterator&); } @@ -1569,7 +1571,7 @@ TEST_CASE("constructors") CHECK_THROWS_WITH_AS(json(j.begin(), j.begin()), "[json.exception.invalid_iterator.204] iterators out of range", json::invalid_iterator&); } { - json j = 23.42; + json const j = 23.42; CHECK_THROWS_WITH_AS(json(j.cend(), j.cend()), "[json.exception.invalid_iterator.204] iterators out of range", json::invalid_iterator&); CHECK_THROWS_WITH_AS(json(j.cbegin(), j.cbegin()), "[json.exception.invalid_iterator.204] iterators out of range", json::invalid_iterator&); } diff --git a/tests/src/unit-constructor2.cpp b/tests/src/unit-constructor2.cpp index 7932caeff..93a5daea8 100644 --- a/tests/src/unit-constructor2.cpp +++ b/tests/src/unit-constructor2.cpp @@ -83,7 +83,7 @@ TEST_CASE("other constructors and destructor") { json j {{"foo", "bar"}, {"baz", {1, 2, 3, 4}}, {"a", 42u}, {"b", 42.23}, {"c", nullptr}}; CHECK(j.type() == json::value_t::object); - json k(std::move(j)); + const json k(std::move(j)); CHECK(k.type() == json::value_t::object); CHECK(j.type() == json::value_t::null); // NOLINT: access after move is OK here } 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-conversions.cpp b/tests/src/unit-conversions.cpp index 78ed3bb3e..9c6431238 100644 --- a/tests/src/unit-conversions.cpp +++ b/tests/src/unit-conversions.cpp @@ -36,7 +36,7 @@ TEST_CASE("value conversion") { SECTION("get an object (explicit)") { - json::object_t o_reference = {{"object", json::object()}, + const json::object_t o_reference = {{"object", json::object()}, {"array", {1, 2, 3, 4}}, {"number", 42}, {"boolean", false}, @@ -47,34 +47,34 @@ TEST_CASE("value conversion") SECTION("json::object_t") { - json::object_t o = j.get(); + json::object_t const o = j.get(); CHECK(json(o) == j); } SECTION("std::map") { - std::map o = + const std::map o = j.get>(); CHECK(json(o) == j); } SECTION("std::multimap") { - std::multimap o = + const std::multimap o = j.get>(); CHECK(json(o) == j); } SECTION("std::unordered_map") { - std::unordered_map o = + const std::unordered_map o = j.get>(); CHECK(json(o) == j); } SECTION("std::unordered_multimap") { - std::unordered_multimap o = + const std::unordered_multimap o = j.get>(); CHECK(json(o) == j); } @@ -107,7 +107,7 @@ TEST_CASE("value conversion") SECTION("get an object (explicit, get_to)") { - json::object_t o_reference = {{"object", json::object()}, + const json::object_t o_reference = {{"object", json::object()}, {"array", {1, 2, 3, 4}}, {"number", 42}, {"boolean", false}, @@ -155,7 +155,7 @@ TEST_CASE("value conversion") #if JSON_USE_IMPLICIT_CONVERSIONS SECTION("get an object (implicit)") { - json::object_t o_reference = {{"object", json::object()}, + const json::object_t o_reference = {{"object", json::object()}, {"array", {1, 2, 3, 4}}, {"number", 42}, {"boolean", false}, @@ -166,31 +166,31 @@ TEST_CASE("value conversion") SECTION("json::object_t") { - json::object_t o = j; + const json::object_t o = j; CHECK(json(o) == j); } SECTION("std::map") { - std::map o = j; + const std::map o = j; CHECK(json(o) == j); } SECTION("std::multimap") { - std::multimap o = j; + const std::multimap o = j; CHECK(json(o) == j); } SECTION("std::unordered_map") { - std::unordered_map o = j; + const std::unordered_map o = j; CHECK(json(o) == j); } SECTION("std::unordered_multimap") { - std::unordered_multimap o = j; + const std::unordered_multimap o = j; CHECK(json(o) == j); } } @@ -198,25 +198,25 @@ TEST_CASE("value conversion") SECTION("get an array (explicit)") { - json::array_t a_reference{json(1), json(1u), json(2.2), - json(false), json("string"), json()}; + const json::array_t a_reference{json(1), json(1u), json(2.2), + json(false), json("string"), json()}; json j(a_reference); SECTION("json::array_t") { - json::array_t a = j.get(); + const json::array_t a = j.get(); CHECK(json(a) == j); } SECTION("std::list") { - std::list a = j.get>(); + const std::list a = j.get>(); CHECK(json(a) == j); } SECTION("std::forward_list") { - std::forward_list a = j.get>(); + const std::forward_list a = j.get>(); CHECK(json(a) == j); CHECK_THROWS_WITH_AS( @@ -226,7 +226,7 @@ TEST_CASE("value conversion") SECTION("std::vector") { - std::vector a = j.get>(); + const std::vector a = j.get>(); CHECK(json(a) == j); CHECK_THROWS_WITH_AS( @@ -237,7 +237,7 @@ TEST_CASE("value conversion") SECTION("reserve is called on containers that supports it") { // make sure all values are properly copied - json j2({1, 2, 3, 4, 5, 6, 7, 8, 9, 10}); + const json j2({1, 2, 3, 4, 5, 6, 7, 8, 9, 10}); auto v2 = j2.get>(); CHECK(v2.size() == 10); } @@ -249,8 +249,8 @@ TEST_CASE("value conversion") const char str[] = "a string"; // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays) const int nbs[] = {0, 1, 2}; // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays) - json j2 = nbs; - json j3 = str; + const json j2 = nbs; + const json j3 = str; auto v = j2.get>(); auto s = j3.get(); @@ -260,7 +260,7 @@ TEST_CASE("value conversion") SECTION("std::deque") { - std::deque a = j.get>(); + const std::deque a = j.get>(); CHECK(json(a) == j); } @@ -295,8 +295,8 @@ TEST_CASE("value conversion") SECTION("get an array (explicit, get_to)") { - json::array_t a_reference{json(1), json(1u), json(2.2), - json(false), json("string"), json()}; + const json::array_t a_reference{json(1), json(1u), json(2.2), + json(false), json("string"), json()}; json j(a_reference); SECTION("json::array_t") @@ -339,7 +339,7 @@ TEST_CASE("value conversion") const int nbs[] = {0, 1, 2}; // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays) int nbs2[] = {0, 0, 0}; // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays) - json j2 = nbs; + const json j2 = nbs; j2.get_to(nbs2); CHECK(std::equal(std::begin(nbs), std::end(nbs), std::begin(nbs2))); } @@ -355,37 +355,37 @@ TEST_CASE("value conversion") #if JSON_USE_IMPLICIT_CONVERSIONS SECTION("get an array (implicit)") { - json::array_t a_reference{json(1), json(1u), json(2.2), - json(false), json("string"), json()}; + const json::array_t a_reference{json(1), json(1u), json(2.2), + json(false), json("string"), json()}; json j(a_reference); SECTION("json::array_t") { - json::array_t a = j; + const json::array_t a = j; CHECK(json(a) == j); } SECTION("std::list") { - std::list a = j; + const std::list a = j; CHECK(json(a) == j); } SECTION("std::forward_list") { - std::forward_list a = j; + const std::forward_list a = j; CHECK(json(a) == j); } SECTION("std::vector") { - std::vector a = j; + const std::vector a = j; CHECK(json(a) == j); } SECTION("std::deque") { - std::deque a = j; + const std::deque a = j; CHECK(json(a) == j); } } @@ -393,24 +393,24 @@ TEST_CASE("value conversion") SECTION("get a string (explicit)") { - json::string_t s_reference{"Hello world"}; + const json::string_t s_reference{"Hello world"}; json j(s_reference); SECTION("string_t") { - json::string_t s = j.get(); + const json::string_t s = j.get(); CHECK(json(s) == j); } SECTION("std::string") { - std::string s = j.get(); + const std::string s = j.get(); CHECK(json(s) == j); } #if defined(JSON_HAS_CPP_17) SECTION("std::string_view") { - std::string_view s = j.get(); + std::string_view const s = j.get(); CHECK(json(s) == j); } #endif @@ -463,7 +463,7 @@ TEST_CASE("value conversion") SECTION("get a string (explicit, get_to)") { - json::string_t s_reference{"Hello world"}; + const json::string_t s_reference{"Hello world"}; json j(s_reference); SECTION("string_t") @@ -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); @@ -493,7 +493,7 @@ TEST_CASE("value conversion") SECTION("get null (explicit)") { std::nullptr_t n = nullptr; - json j(n); + const json j(n); auto n2 = j.get(); CHECK(n2 == n); @@ -517,26 +517,26 @@ TEST_CASE("value conversion") #if JSON_USE_IMPLICIT_CONVERSIONS SECTION("get a string (implicit)") { - json::string_t s_reference{"Hello world"}; + const json::string_t s_reference{"Hello world"}; json j(s_reference); SECTION("string_t") { - json::string_t s = j; + const json::string_t s = j; CHECK(json(s) == j); } #if defined(JSON_HAS_CPP_17) SECTION("std::string_view") { - std::string_view s = j.get(); + std::string_view const s = j.get(); CHECK(json(s) == j); } #endif SECTION("std::string") { - std::string s = j; + const std::string s = j; CHECK(json(s) == j); } } @@ -544,7 +544,7 @@ TEST_CASE("value conversion") SECTION("get a boolean (explicit)") { - json::boolean_t b_reference{true}; + const json::boolean_t b_reference{true}; json j(b_reference); SECTION("boolean_t") @@ -561,7 +561,7 @@ TEST_CASE("value conversion") SECTION("bool") { - bool b = j.get(); + const bool b = j.get(); CHECK(json(b) == j); } @@ -600,18 +600,18 @@ TEST_CASE("value conversion") #if JSON_USE_IMPLICIT_CONVERSIONS SECTION("get a boolean (implicit)") { - json::boolean_t b_reference{true}; + const json::boolean_t b_reference{true}; json j(b_reference); SECTION("boolean_t") { - json::boolean_t b = j; + const json::boolean_t b = j; CHECK(json(b) == j); } SECTION("bool") { - bool b = j; + const bool b = j; CHECK(json(b) == j); } } @@ -619,9 +619,9 @@ TEST_CASE("value conversion") SECTION("get an integer number (explicit)") { - json::number_integer_t n_reference{42}; + const json::number_integer_t n_reference{42}; json j(n_reference); - json::number_unsigned_t n_unsigned_reference{42u}; + const json::number_unsigned_t n_unsigned_reference{42u}; json j_unsigned(n_unsigned_reference); SECTION("number_integer_t") @@ -650,7 +650,7 @@ TEST_CASE("value conversion") SECTION("int") { - int n = j.get(); + const int n = j.get(); CHECK(json(n) == j); } @@ -662,7 +662,7 @@ TEST_CASE("value conversion") SECTION("long") { - long n = j.get(); + const long n = j.get(); CHECK(json(n) == j); } @@ -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 const b = j.get(); 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 m{{0, 1}, {1, 2}, {2, 3}}; - json j6 = m; + json const j6 = m; auto m2 = j6.get>(); 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>()), "[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>(); CHECK(m == m2); } @@ -1452,13 +1452,13 @@ TEST_CASE("value conversion") SECTION("std::unordered_map (array of pairs)") { std::unordered_map m{{0, 1}, {1, 2}, {2, 3}}; - json j6 = m; + json const j6 = m; auto m2 = j6.get>(); 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>()), "[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>(); CHECK(m == m2); } 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-diagnostics.cpp b/tests/src/unit-diagnostics.cpp index 0b8e4dbe3..4f60a0f4d 100644 --- a/tests/src/unit-diagnostics.cpp +++ b/tests/src/unit-diagnostics.cpp @@ -22,7 +22,7 @@ TEST_CASE("Better diagnostics") { SECTION("empty JSON Pointer") { - json j = 1; + json const j = 1; std::string s; CHECK_THROWS_WITH_AS(s = j.get(), "[json.exception.type_error.302] type must be string, but is number", json::type_error); } @@ -240,7 +240,7 @@ TEST_CASE("Regression tests for extended diagnostics") j_arr[5] = 5; j_arr[6] = 6; j_arr[7] = 7; - json j_arr_copy = j_arr; + json const j_arr_copy = j_arr; } } } 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-element_access2.cpp b/tests/src/unit-element_access2.cpp index 165b24b46..db20a02b1 100644 --- a/tests/src/unit-element_access2.cpp +++ b/tests/src/unit-element_access2.cpp @@ -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(key, "default") == "bar"); CHECK(j.template value(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(key, "default") == "bar"); CHECK(j.template value(key, cpstr) == "bar"); 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..7cb718811 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 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 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 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 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..8530f2ecd 100644 --- a/tests/src/unit-msgpack.cpp +++ b/tests/src/unit-msgpack.cpp @@ -106,15 +106,15 @@ 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()); } SECTION("null") { - json j = nullptr; - std::vector expected = {0xc0}; + json const j = nullptr; + std::vector const expected = {0xc0}; const auto result = json::to_msgpack(j); CHECK(result == expected); @@ -127,8 +127,8 @@ TEST_CASE("MessagePack") { SECTION("true") { - json j = true; - std::vector expected = {0xc3}; + json const j = true; + std::vector const expected = {0xc3}; const auto result = json::to_msgpack(j); CHECK(result == expected); @@ -139,8 +139,8 @@ TEST_CASE("MessagePack") SECTION("false") { - json j = false; - std::vector expected = {0xc2}; + json const j = false; + std::vector const expected = {0xc2}; const auto result = json::to_msgpack(j); CHECK(result == expected); @@ -161,14 +161,16 @@ TEST_CASE("MessagePack") CAPTURE(i) // create JSON value with integer number - json j = i; + json const j = i; // check type CHECK(j.is_number_integer()); // create expected byte vector - std::vector expected; - expected.push_back(static_cast(i)); + std::vector const expected + { + static_cast(i) + }; // compare result + size const auto result = json::to_msgpack(j); @@ -198,8 +200,7 @@ TEST_CASE("MessagePack") CHECK(j.is_number_integer()); // create expected byte vector - std::vector expected; - expected.push_back(static_cast(i)); + std::vector const expected{static_cast(i)}; // compare result + size const auto result = json::to_msgpack(j); @@ -229,9 +230,11 @@ TEST_CASE("MessagePack") CHECK(j.is_number_integer()); // create expected byte vector - std::vector expected; - expected.push_back(0xcc); - expected.push_back(static_cast(i)); + std::vector const expected + { + 0xcc, + static_cast(i), + }; // compare result + size const auto result = json::to_msgpack(j); @@ -240,7 +243,7 @@ TEST_CASE("MessagePack") // check individual bytes CHECK(result[0] == 0xcc); - auto restored = static_cast(result[1]); + auto const restored = static_cast(result[1]); CHECK(restored == i); // roundtrip @@ -263,10 +266,12 @@ TEST_CASE("MessagePack") CHECK(j.is_number_integer()); // create expected byte vector - std::vector expected; - expected.push_back(0xcd); - expected.push_back(static_cast((i >> 8) & 0xff)); - expected.push_back(static_cast(i & 0xff)); + std::vector const expected + { + 0xcd, + static_cast((i >> 8) & 0xff), + static_cast(i & 0xff), + }; // compare result + size const auto result = json::to_msgpack(j); @@ -275,7 +280,7 @@ TEST_CASE("MessagePack") // check individual bytes CHECK(result[0] == 0xcd); - auto restored = static_cast(static_cast(result[1]) * 256 + static_cast(result[2])); + auto const restored = static_cast(static_cast(result[1]) * 256 + static_cast(result[2])); CHECK(restored == i); // roundtrip @@ -301,12 +306,14 @@ TEST_CASE("MessagePack") CHECK(j.is_number_integer()); // create expected byte vector - std::vector expected; - expected.push_back(0xce); - expected.push_back(static_cast((i >> 24) & 0xff)); - expected.push_back(static_cast((i >> 16) & 0xff)); - expected.push_back(static_cast((i >> 8) & 0xff)); - expected.push_back(static_cast(i & 0xff)); + std::vector const expected + { + 0xce, + static_cast((i >> 24) & 0xff), + static_cast((i >> 16) & 0xff), + static_cast((i >> 8) & 0xff), + static_cast(i & 0xff), + }; // compare result + size const auto result = json::to_msgpack(j); @@ -315,10 +322,10 @@ TEST_CASE("MessagePack") // check individual bytes CHECK(result[0] == 0xce); - uint32_t restored = (static_cast(result[1]) << 030) + - (static_cast(result[2]) << 020) + - (static_cast(result[3]) << 010) + - static_cast(result[4]); + uint32_t const restored = (static_cast(result[1]) << 030) + + (static_cast(result[2]) << 020) + + (static_cast(result[3]) << 010) + + static_cast(result[4]); CHECK(restored == i); // roundtrip @@ -344,16 +351,18 @@ TEST_CASE("MessagePack") CHECK(j.is_number_integer()); // create expected byte vector - std::vector expected; - expected.push_back(0xcf); - expected.push_back(static_cast((i >> 070) & 0xff)); - expected.push_back(static_cast((i >> 060) & 0xff)); - expected.push_back(static_cast((i >> 050) & 0xff)); - expected.push_back(static_cast((i >> 040) & 0xff)); - expected.push_back(static_cast((i >> 030) & 0xff)); - expected.push_back(static_cast((i >> 020) & 0xff)); - expected.push_back(static_cast((i >> 010) & 0xff)); - expected.push_back(static_cast(i & 0xff)); + std::vector const expected + { + 0xcf, + static_cast((i >> 070) & 0xff), + static_cast((i >> 060) & 0xff), + static_cast((i >> 050) & 0xff), + static_cast((i >> 040) & 0xff), + static_cast((i >> 030) & 0xff), + static_cast((i >> 020) & 0xff), + static_cast((i >> 010) & 0xff), + static_cast(i & 0xff), + }; // compare result + size const auto result = json::to_msgpack(j); @@ -362,14 +371,14 @@ TEST_CASE("MessagePack") // check individual bytes CHECK(result[0] == 0xcf); - uint64_t restored = (static_cast(result[1]) << 070) + - (static_cast(result[2]) << 060) + - (static_cast(result[3]) << 050) + - (static_cast(result[4]) << 040) + - (static_cast(result[5]) << 030) + - (static_cast(result[6]) << 020) + - (static_cast(result[7]) << 010) + - static_cast(result[8]); + uint64_t const restored = (static_cast(result[1]) << 070) + + (static_cast(result[2]) << 060) + + (static_cast(result[3]) << 050) + + (static_cast(result[4]) << 040) + + (static_cast(result[5]) << 030) + + (static_cast(result[6]) << 020) + + (static_cast(result[7]) << 010) + + static_cast(result[8]); CHECK(restored == i); // roundtrip @@ -385,15 +394,17 @@ TEST_CASE("MessagePack") CAPTURE(i) // create JSON value with integer number - json j = i; + json const j = i; // check type CHECK(j.is_number_integer()); // create expected byte vector - std::vector expected; - expected.push_back(0xd0); - expected.push_back(static_cast(i)); + std::vector const expected + { + 0xd0, + static_cast(i), + }; // compare result + size const auto result = json::to_msgpack(j); @@ -412,13 +423,13 @@ TEST_CASE("MessagePack") SECTION("-9263 (int 16)") { - json j = -9263; - std::vector expected = {0xd1, 0xdb, 0xd1}; + json const j = -9263; + std::vector const expected = {0xd1, 0xdb, 0xd1}; const auto result = json::to_msgpack(j); CHECK(result == expected); - auto restored = static_cast((result[1] << 8) + result[2]); + auto const restored = static_cast((result[1] << 8) + result[2]); CHECK(restored == -9263); // roundtrip @@ -433,16 +444,18 @@ TEST_CASE("MessagePack") CAPTURE(i) // create JSON value with integer number - json j = i; + json const j = i; // check type CHECK(j.is_number_integer()); // create expected byte vector - std::vector expected; - expected.push_back(0xd1); - expected.push_back(static_cast((i >> 8) & 0xff)); - expected.push_back(static_cast(i & 0xff)); + std::vector const expected + { + 0xd1, + static_cast((i >> 8) & 0xff), + static_cast(i & 0xff), + }; // compare result + size const auto result = json::to_msgpack(j); @@ -451,7 +464,7 @@ TEST_CASE("MessagePack") // check individual bytes CHECK(result[0] == 0xd1); - auto restored = static_cast((result[1] << 8) + result[2]); + auto const restored = static_cast((result[1] << 8) + result[2]); CHECK(restored == i); // roundtrip @@ -462,29 +475,33 @@ TEST_CASE("MessagePack") SECTION("-32769..-2147483648") { - std::vector numbers; - numbers.push_back(-32769); - numbers.push_back(-65536); - numbers.push_back(-77777); - numbers.push_back(-1048576); - numbers.push_back(-2147483648LL); + std::vector const numbers + { + -32769, + -65536, + -77777, + -1048576, + -2147483648LL, + }; for (auto i : numbers) { CAPTURE(i) // create JSON value with integer number - json j = i; + json const j = i; // check type CHECK(j.is_number_integer()); // create expected byte vector - std::vector expected; - expected.push_back(0xd2); - expected.push_back(static_cast((i >> 24) & 0xff)); - expected.push_back(static_cast((i >> 16) & 0xff)); - expected.push_back(static_cast((i >> 8) & 0xff)); - expected.push_back(static_cast(i & 0xff)); + std::vector const expected + { + 0xd2, + static_cast((i >> 24) & 0xff), + static_cast((i >> 16) & 0xff), + static_cast((i >> 8) & 0xff), + static_cast(i & 0xff), + }; // compare result + size const auto result = json::to_msgpack(j); @@ -493,10 +510,10 @@ TEST_CASE("MessagePack") // check individual bytes CHECK(result[0] == 0xd2); - uint32_t restored = (static_cast(result[1]) << 030) + - (static_cast(result[2]) << 020) + - (static_cast(result[3]) << 010) + - static_cast(result[4]); + uint32_t const restored = (static_cast(result[1]) << 030) + + (static_cast(result[2]) << 020) + + (static_cast(result[3]) << 010) + + static_cast(result[4]); CHECK(static_cast(restored) == i); // roundtrip @@ -507,30 +524,34 @@ TEST_CASE("MessagePack") SECTION("-9223372036854775808..-2147483649 (int 64)") { - std::vector numbers; - numbers.push_back(INT64_MIN); - numbers.push_back(-2147483649LL); + std::vector const numbers + { + INT64_MIN, + -2147483649LL, + }; for (auto i : numbers) { CAPTURE(i) // create JSON value with unsigned integer number - json j = i; + json const j = i; // check type CHECK(j.is_number_integer()); // create expected byte vector - std::vector expected; - expected.push_back(0xd3); - expected.push_back(static_cast((i >> 070) & 0xff)); - expected.push_back(static_cast((i >> 060) & 0xff)); - expected.push_back(static_cast((i >> 050) & 0xff)); - expected.push_back(static_cast((i >> 040) & 0xff)); - expected.push_back(static_cast((i >> 030) & 0xff)); - expected.push_back(static_cast((i >> 020) & 0xff)); - expected.push_back(static_cast((i >> 010) & 0xff)); - expected.push_back(static_cast(i & 0xff)); + std::vector const expected + { + 0xd3, + static_cast((i >> 070) & 0xff), + static_cast((i >> 060) & 0xff), + static_cast((i >> 050) & 0xff), + static_cast((i >> 040) & 0xff), + static_cast((i >> 030) & 0xff), + static_cast((i >> 020) & 0xff), + static_cast((i >> 010) & 0xff), + static_cast(i & 0xff), + }; // compare result + size const auto result = json::to_msgpack(j); @@ -539,14 +560,14 @@ TEST_CASE("MessagePack") // check individual bytes CHECK(result[0] == 0xd3); - int64_t restored = (static_cast(result[1]) << 070) + - (static_cast(result[2]) << 060) + - (static_cast(result[3]) << 050) + - (static_cast(result[4]) << 040) + - (static_cast(result[5]) << 030) + - (static_cast(result[6]) << 020) + - (static_cast(result[7]) << 010) + - static_cast(result[8]); + int64_t const restored = (static_cast(result[1]) << 070) + + (static_cast(result[2]) << 060) + + (static_cast(result[3]) << 050) + + (static_cast(result[4]) << 040) + + (static_cast(result[5]) << 030) + + (static_cast(result[6]) << 020) + + (static_cast(result[7]) << 010) + + static_cast(result[8]); CHECK(restored == i); // roundtrip @@ -565,14 +586,13 @@ TEST_CASE("MessagePack") CAPTURE(i) // create JSON value with unsigned integer number - json j = i; + json const j = i; // check type CHECK(j.is_number_unsigned()); // create expected byte vector - std::vector expected; - expected.push_back(static_cast(i)); + std::vector const expected{static_cast(i)}; // compare result + size const auto result = json::to_msgpack(j); @@ -595,15 +615,17 @@ TEST_CASE("MessagePack") CAPTURE(i) // create JSON value with unsigned integer number - json j = i; + json const j = i; // check type CHECK(j.is_number_unsigned()); // create expected byte vector - std::vector expected; - expected.push_back(0xcc); - expected.push_back(static_cast(i)); + std::vector const expected + { + 0xcc, + static_cast(i), + }; // compare result + size const auto result = json::to_msgpack(j); @@ -612,7 +634,7 @@ TEST_CASE("MessagePack") // check individual bytes CHECK(result[0] == 0xcc); - auto restored = static_cast(result[1]); + auto const restored = static_cast(result[1]); CHECK(restored == i); // roundtrip @@ -628,16 +650,18 @@ TEST_CASE("MessagePack") CAPTURE(i) // create JSON value with unsigned integer number - json j = i; + json const j = i; // check type CHECK(j.is_number_unsigned()); // create expected byte vector - std::vector expected; - expected.push_back(0xcd); - expected.push_back(static_cast((i >> 8) & 0xff)); - expected.push_back(static_cast(i & 0xff)); + std::vector const expected + { + 0xcd, + static_cast((i >> 8) & 0xff), + static_cast(i & 0xff), + }; // compare result + size const auto result = json::to_msgpack(j); @@ -646,7 +670,7 @@ TEST_CASE("MessagePack") // check individual bytes CHECK(result[0] == 0xcd); - auto restored = static_cast(static_cast(result[1]) * 256 + static_cast(result[2])); + auto const restored = static_cast(static_cast(result[1]) * 256 + static_cast(result[2])); CHECK(restored == i); // roundtrip @@ -657,7 +681,7 @@ TEST_CASE("MessagePack") SECTION("65536..4294967295 (uint 32)") { - for (uint32_t i : + for (const uint32_t i : { 65536u, 77777u, 1048576u, 4294967295u }) @@ -665,18 +689,20 @@ TEST_CASE("MessagePack") CAPTURE(i) // create JSON value with unsigned integer number - json j = i; + json const j = i; // check type CHECK(j.is_number_unsigned()); // create expected byte vector - std::vector expected; - expected.push_back(0xce); - expected.push_back(static_cast((i >> 24) & 0xff)); - expected.push_back(static_cast((i >> 16) & 0xff)); - expected.push_back(static_cast((i >> 8) & 0xff)); - expected.push_back(static_cast(i & 0xff)); + std::vector const expected + { + 0xce, + static_cast((i >> 24) & 0xff), + static_cast((i >> 16) & 0xff), + static_cast((i >> 8) & 0xff), + static_cast(i & 0xff), + }; // compare result + size const auto result = json::to_msgpack(j); @@ -685,10 +711,10 @@ TEST_CASE("MessagePack") // check individual bytes CHECK(result[0] == 0xce); - uint32_t restored = (static_cast(result[1]) << 030) + - (static_cast(result[2]) << 020) + - (static_cast(result[3]) << 010) + - static_cast(result[4]); + uint32_t const restored = (static_cast(result[1]) << 030) + + (static_cast(result[2]) << 020) + + (static_cast(result[3]) << 010) + + static_cast(result[4]); CHECK(restored == i); // roundtrip @@ -699,7 +725,7 @@ TEST_CASE("MessagePack") SECTION("4294967296..18446744073709551615 (uint 64)") { - for (uint64_t i : + for (const uint64_t i : { 4294967296LU, 18446744073709551615LU }) @@ -707,22 +733,24 @@ TEST_CASE("MessagePack") CAPTURE(i) // create JSON value with unsigned integer number - json j = i; + json const j = i; // check type CHECK(j.is_number_unsigned()); // create expected byte vector - std::vector expected; - expected.push_back(0xcf); - expected.push_back(static_cast((i >> 070) & 0xff)); - expected.push_back(static_cast((i >> 060) & 0xff)); - expected.push_back(static_cast((i >> 050) & 0xff)); - expected.push_back(static_cast((i >> 040) & 0xff)); - expected.push_back(static_cast((i >> 030) & 0xff)); - expected.push_back(static_cast((i >> 020) & 0xff)); - expected.push_back(static_cast((i >> 010) & 0xff)); - expected.push_back(static_cast(i & 0xff)); + std::vector const expected + { + 0xcf, + static_cast((i >> 070) & 0xff), + static_cast((i >> 060) & 0xff), + static_cast((i >> 050) & 0xff), + static_cast((i >> 040) & 0xff), + static_cast((i >> 030) & 0xff), + static_cast((i >> 020) & 0xff), + static_cast((i >> 010) & 0xff), + static_cast(i & 0xff), + }; // compare result + size const auto result = json::to_msgpack(j); @@ -731,14 +759,14 @@ TEST_CASE("MessagePack") // check individual bytes CHECK(result[0] == 0xcf); - uint64_t restored = (static_cast(result[1]) << 070) + - (static_cast(result[2]) << 060) + - (static_cast(result[3]) << 050) + - (static_cast(result[4]) << 040) + - (static_cast(result[5]) << 030) + - (static_cast(result[6]) << 020) + - (static_cast(result[7]) << 010) + - static_cast(result[8]); + uint64_t const restored = (static_cast(result[1]) << 070) + + (static_cast(result[2]) << 060) + + (static_cast(result[3]) << 050) + + (static_cast(result[4]) << 040) + + (static_cast(result[5]) << 030) + + (static_cast(result[6]) << 020) + + (static_cast(result[7]) << 010) + + static_cast(result[8]); CHECK(restored == i); // roundtrip @@ -752,9 +780,9 @@ TEST_CASE("MessagePack") { SECTION("3.1415925") { - double v = 3.1415925; - json j = v; - std::vector expected = + double const v = 3.1415925; + json const j = v; + std::vector const expected = { 0xcb, 0x40, 0x09, 0x21, 0xfb, 0x3f, 0xa6, 0xde, 0xfc }; @@ -769,9 +797,9 @@ TEST_CASE("MessagePack") SECTION("1.0") { - double v = 1.0; - json j = v; - std::vector expected = + double const v = 1.0; + json const j = v; + std::vector const expected = { 0xca, 0x3f, 0x80, 0x00, 0x00 }; @@ -786,9 +814,9 @@ TEST_CASE("MessagePack") SECTION("128.128") { - double v = 128.1280059814453125; - json j = v; - std::vector expected = + double const v = 128.1280059814453125; + json const j = v; + std::vector const expected = { 0xca, 0x43, 0x00, 0x20, 0xc5 }; @@ -822,7 +850,7 @@ TEST_CASE("MessagePack") // create JSON value with string containing of N * 'x' const auto s = std::string(N, 'x'); - json j = s; + json const j = s; // create expected byte vector std::vector expected; @@ -859,7 +887,7 @@ TEST_CASE("MessagePack") // create JSON value with string containing of N * 'x' const auto s = std::string(N, 'x'); - json j = s; + json const j = s; // create expected byte vector std::vector expected; @@ -894,7 +922,7 @@ TEST_CASE("MessagePack") // create JSON value with string containing of N * 'x' const auto s = std::string(N, 'x'); - json j = s; + json const j = s; // create expected byte vector (hack: create string first) std::vector expected(N, 'x'); @@ -927,7 +955,7 @@ TEST_CASE("MessagePack") // create JSON value with string containing of N * 'x' const auto s = std::string(N, 'x'); - json j = s; + json const j = s; // create expected byte vector (hack: create string first) std::vector expected(N, 'x'); @@ -956,8 +984,8 @@ TEST_CASE("MessagePack") { SECTION("empty") { - json j = json::array(); - std::vector expected = {0x90}; + json const j = json::array(); + std::vector const expected = {0x90}; const auto result = json::to_msgpack(j); CHECK(result == expected); @@ -968,8 +996,8 @@ TEST_CASE("MessagePack") SECTION("[null]") { - json j = {nullptr}; - std::vector expected = {0x91, 0xc0}; + json const j = {nullptr}; + std::vector const expected = {0x91, 0xc0}; const auto result = json::to_msgpack(j); CHECK(result == expected); @@ -980,8 +1008,8 @@ TEST_CASE("MessagePack") SECTION("[1,2,3,4,5]") { - json j = json::parse("[1,2,3,4,5]"); - std::vector expected = {0x95, 0x01, 0x02, 0x03, 0x04, 0x05}; + json const j = json::parse("[1,2,3,4,5]"); + std::vector const expected = {0x95, 0x01, 0x02, 0x03, 0x04, 0x05}; const auto result = json::to_msgpack(j); CHECK(result == expected); @@ -992,8 +1020,8 @@ TEST_CASE("MessagePack") SECTION("[[[[]]]]") { - json j = json::parse("[[[[]]]]"); - std::vector expected = {0x91, 0x91, 0x91, 0x90}; + json const j = json::parse("[[[[]]]]"); + std::vector const expected = {0x91, 0x91, 0x91, 0x90}; const auto result = json::to_msgpack(j); CHECK(result == expected); @@ -1046,8 +1074,8 @@ TEST_CASE("MessagePack") { SECTION("empty") { - json j = json::object(); - std::vector expected = {0x80}; + json const j = json::object(); + std::vector const expected = {0x80}; const auto result = json::to_msgpack(j); CHECK(result == expected); @@ -1058,8 +1086,8 @@ TEST_CASE("MessagePack") SECTION("{\"\":null}") { - json j = {{"", nullptr}}; - std::vector expected = {0x81, 0xa0, 0xc0}; + json const j = {{"", nullptr}}; + std::vector const expected = {0x81, 0xa0, 0xc0}; const auto result = json::to_msgpack(j); CHECK(result == expected); @@ -1070,8 +1098,8 @@ TEST_CASE("MessagePack") SECTION("{\"a\": {\"b\": {\"c\": {}}}}") { - json j = json::parse(R"({"a": {"b": {"c": {}}}})"); - std::vector expected = + json const j = json::parse(R"({"a": {"b": {"c": {}}}})"); + std::vector const expected = { 0x81, 0xa1, 0x61, 0x81, 0xa1, 0x62, 0x81, 0xa1, 0x63, 0x80 }; @@ -1085,7 +1113,7 @@ TEST_CASE("MessagePack") SECTION("map 16") { - json j = R"({"00": null, "01": null, "02": null, "03": null, + json const j = R"({"00": null, "01": null, "02": null, "03": null, "04": null, "05": null, "06": null, "07": null, "08": null, "09": null, "10": null, "11": null, "12": null, "13": null, "14": null, "15": null})"_json; @@ -1150,7 +1178,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 +1253,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 +1289,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) @@ -1298,7 +1326,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); + json const j = json::binary(s); // create expected byte vector std::vector expected; @@ -1336,7 +1364,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); + json const j = json::binary(s); // create expected byte vector (hack: create string first) std::vector expected(N, 'x'); @@ -1369,7 +1397,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); + json const j = json::binary(s); // create expected byte vector (hack: create string first) std::vector expected(N, 'x'); @@ -1398,7 +1426,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 +1539,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 +1559,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 +1585,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 +1845,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-reference_access.cpp b/tests/src/unit-reference_access.cpp index 5f450ec2c..32a4097dd 100644 --- a/tests/src/unit-reference_access.cpp +++ b/tests/src/unit-reference_access.cpp @@ -14,7 +14,7 @@ using nlohmann::json; TEST_CASE("reference access") { // create a JSON value with different types - json json_types = + const json json_types = { {"boolean", true}, { diff --git a/tests/src/unit-regression1.cpp b/tests/src/unit-regression1.cpp index ee7f8bc12..34aed966a 100644 --- a/tests/src/unit-regression1.cpp +++ b/tests/src/unit-regression1.cpp @@ -143,27 +143,27 @@ TEST_CASE("regression tests 1") // to null), but are serialized as null. SECTION("NAN value") { - json j1 = NAN; + json const j1 = NAN; CHECK(j1.is_number_float()); - json::number_float_t f1{j1}; + json::number_float_t const f1{j1}; CHECK(std::isnan(f1)); - json j2 = static_cast(NAN); + json const j2 = static_cast(NAN); CHECK(j2.is_number_float()); - json::number_float_t f2{j2}; + json::number_float_t const f2{j2}; CHECK(std::isnan(f2)); } SECTION("infinity") { - json j1 = INFINITY; + json const j1 = INFINITY; CHECK(j1.is_number_float()); - json::number_float_t f1{j1}; + json::number_float_t const f1{j1}; CHECK(!std::isfinite(f1)); - json j2 = static_cast(INFINITY); + json const j2 = static_cast(INFINITY); CHECK(j2.is_number_float()); - json::number_float_t f2{j2}; + json::number_float_t const f2{j2}; CHECK(!std::isfinite(f2)); } } @@ -200,7 +200,7 @@ TEST_CASE("regression tests 1") fields["three"] = std::string("three \"four\""); // create another JSON object by deserializing the serialization - std::string payload = fields.dump(); + std::string const payload = fields.dump(); json parsed_fields = json::parse(payload); // check individual fields to match both objects @@ -288,7 +288,7 @@ TEST_CASE("regression tests 1") } { json a = {1, 2, 3}; - json::reverse_iterator rit = ++a.rbegin(); + json::reverse_iterator const rit = ++a.rbegin(); CHECK(*rit == json(2)); CHECK(rit.value() == json(2)); } @@ -340,8 +340,8 @@ TEST_CASE("regression tests 1") SECTION("issue #101 - binary string causes numbers to be dumped as hex") { - int64_t number = 10; - std::string bytes{"\x00" "asdf\n", 6}; + int64_t const number = 10; + std::string const bytes{"\x00" "asdf\n", 6}; json j; j["int64"] = number; j["binary string"] = bytes; @@ -352,7 +352,7 @@ TEST_CASE("regression tests 1") SECTION("issue #111 - subsequent unicode chars") { - std::string bytes{0x7, 0x7}; + std::string const bytes{0x7, 0x7}; json j; j["string"] = bytes; CHECK(j["string"] == "\u0007\u0007"); @@ -465,33 +465,33 @@ TEST_CASE("regression tests 1") // create JSON class with nonstandard float number type // float - nlohmann::basic_json j_float = + nlohmann::basic_json const j_float = 1.23e25f; CHECK(j_float.get() == 1.23e25f); // double - nlohmann::basic_json j_double = + nlohmann::basic_json const j_double = 1.23e35; CHECK(j_double.get() == 1.23e35); // long double nlohmann::basic_json - j_long_double = 1.23e45L; + const j_long_double = 1.23e45L; CHECK(j_long_double.get() == 1.23e45L); } SECTION("issue #228 - double values are serialized with commas as decimal points") { - json j1a = 2312.42; - json j1b = json::parse("2312.42"); + json const j1a = 2312.42; + json const j1b = json::parse("2312.42"); - json j2a = 2342e-2; + json const j2a = 2342e-2; //issue #230 //json j2b = json::parse("2342e-2"); - json j3a = 10E3; - json j3b = json::parse("10E3"); - json j3c = json::parse("10e3"); + json const j3a = 10E3; + json const j3b = json::parse("10E3"); + json const j3c = json::parse("10e3"); // class to create a locale that would use a comma for decimals class CommaDecimalSeparator : public std::numpunct @@ -585,7 +585,7 @@ TEST_CASE("regression tests 1") SECTION("issue #269 - diff generates incorrect patch when removing multiple array elements") { - json doc = R"( { "arr1": [1, 2, 3, 4] } )"_json; + json const doc = R"( { "arr1": [1, 2, 3, 4] } )"_json; json expected = R"( { "arr1": [1, 2] } )"_json; // check roundtrip @@ -610,7 +610,7 @@ TEST_CASE("regression tests 1") // code triggered a "warning: unused variable" warning and is left // here to avoid the warning in the future json object; - json patch = json::array(); + json const patch = json::array(); object = object.patch(patch); } @@ -837,7 +837,7 @@ TEST_CASE("regression tests 1") SECTION("second example from #529") { - std::string str = "{\n\"one\" : 1,\n\"two\" : 2\n}\n{\n\"three\" : 3\n}"; + std::string const str = "{\n\"one\" : 1,\n\"two\" : 2\n}\n{\n\"three\" : 3\n}"; { std::ofstream file("test.json"); @@ -875,23 +875,23 @@ TEST_CASE("regression tests 1") SECTION("issue #389 - Integer-overflow (OSS-Fuzz issue 267)") { // original test case - json j1 = json::parse("-9223372036854775808"); + json const j1 = json::parse("-9223372036854775808"); CHECK(j1.is_number_integer()); CHECK(j1.get() == INT64_MIN); // edge case (+1; still an integer) - json j2 = json::parse("-9223372036854775807"); + json const j2 = json::parse("-9223372036854775807"); CHECK(j2.is_number_integer()); CHECK(j2.get() == INT64_MIN + 1); // edge case (-1; overflow -> floats) - json j3 = json::parse("-9223372036854775809"); + json const j3 = json::parse("-9223372036854775809"); CHECK(j3.is_number_float()); } SECTION("issue #380 - bug in overflow detection when parsing integers") { - json j = json::parse("166020696663385964490"); + json const j = json::parse("166020696663385964490"); CHECK(j.is_number_float()); CHECK(j.get() == 166020696663385964490.0); } @@ -899,7 +899,7 @@ TEST_CASE("regression tests 1") SECTION("issue #405 - Heap-buffer-overflow (OSS-Fuzz issue 342)") { // original test case - std::vector vec {0x65, 0xf5, 0x0a, 0x48, 0x21}; + std::vector const vec {0x65, 0xf5, 0x0a, 0x48, 0x21}; json _; CHECK_THROWS_WITH_AS(_ = json::from_cbor(vec), "[json.exception.parse_error.110] parse error at byte 6: syntax error while parsing CBOR string: unexpected end of input", json::parse_error&); } @@ -909,23 +909,23 @@ TEST_CASE("regression tests 1") json _; // original test case: incomplete float64 - std::vector vec1 {0xcb, 0x8f, 0x0a}; + std::vector const vec1 {0xcb, 0x8f, 0x0a}; CHECK_THROWS_WITH_AS(_ = json::from_msgpack(vec1), "[json.exception.parse_error.110] parse error at byte 4: syntax error while parsing MessagePack number: unexpected end of input", json::parse_error&); // related test case: incomplete float32 - std::vector vec2 {0xca, 0x8f, 0x0a}; + std::vector const vec2 {0xca, 0x8f, 0x0a}; CHECK_THROWS_WITH_AS(_ = json::from_msgpack(vec2), "[json.exception.parse_error.110] parse error at byte 4: syntax error while parsing MessagePack number: unexpected end of input", json::parse_error&); // related test case: incomplete Half-Precision Float (CBOR) - std::vector vec3 {0xf9, 0x8f}; + std::vector const vec3 {0xf9, 0x8f}; CHECK_THROWS_WITH_AS(_ = json::from_cbor(vec3), "[json.exception.parse_error.110] parse error at byte 3: syntax error while parsing CBOR number: unexpected end of input", json::parse_error&); // related test case: incomplete Single-Precision Float (CBOR) - std::vector vec4 {0xfa, 0x8f, 0x0a}; + std::vector const vec4 {0xfa, 0x8f, 0x0a}; CHECK_THROWS_WITH_AS(_ = json::from_cbor(vec4), "[json.exception.parse_error.110] parse error at byte 4: syntax error while parsing CBOR number: unexpected end of input", json::parse_error&); // related test case: incomplete Double-Precision Float (CBOR) - std::vector vec5 {0xfb, 0x8f, 0x0a}; + std::vector const vec5 {0xfb, 0x8f, 0x0a}; CHECK_THROWS_WITH_AS(_ = json::from_cbor(vec5), "[json.exception.parse_error.110] parse error at byte 4: syntax error while parsing CBOR number: unexpected end of input", json::parse_error&); } @@ -934,7 +934,7 @@ TEST_CASE("regression tests 1") json _; // original test case - std::vector vec1 {0x87}; + std::vector const vec1 {0x87}; CHECK_THROWS_WITH_AS(_ = json::from_msgpack(vec1), "[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing MessagePack string: unexpected end of input", json::parse_error&); // more test cases for MessagePack @@ -946,7 +946,7 @@ TEST_CASE("regression tests 1") 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf }) { - std::vector vec(1, static_cast(b)); + std::vector const vec(1, static_cast(b)); CHECK_THROWS_AS(_ = json::from_msgpack(vec), json::parse_error&); } @@ -961,12 +961,12 @@ TEST_CASE("regression tests 1") 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7 // map }) { - std::vector vec(1, static_cast(b)); + std::vector const vec(1, static_cast(b)); CHECK_THROWS_AS(_ = json::from_cbor(vec), json::parse_error&); } // special case: empty input - std::vector vec2; + std::vector const vec2; CHECK_THROWS_WITH_AS(_ = json::from_cbor(vec2), "[json.exception.parse_error.110] parse error at byte 1: syntax error while parsing CBOR value: unexpected end of input", json::parse_error&); CHECK_THROWS_WITH_AS(_ = json::from_msgpack(vec2), "[json.exception.parse_error.110] parse error at byte 1: syntax error while parsing MessagePack value: unexpected end of input", json::parse_error&); } @@ -976,22 +976,22 @@ TEST_CASE("regression tests 1") json _; // original test case: empty UTF-8 string (indefinite length) - std::vector vec1 {0x7f}; + std::vector const vec1 {0x7f}; CHECK_THROWS_WITH_AS(_ = json::from_cbor(vec1), "[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing CBOR string: unexpected end of input", json::parse_error&); // related test case: empty array (indefinite length) - std::vector vec2 {0x9f}; + std::vector const vec2 {0x9f}; CHECK_THROWS_WITH_AS(_ = json::from_cbor(vec2), "[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing CBOR value: unexpected end of input", json::parse_error&); // related test case: empty map (indefinite length) - std::vector vec3 {0xbf}; + std::vector const vec3 {0xbf}; CHECK_THROWS_WITH_AS(_ = json::from_cbor(vec3), "[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing CBOR string: unexpected end of input", json::parse_error&); } SECTION("issue #412 - Heap-buffer-overflow (OSS-Fuzz issue 367)") { // original test case - std::vector vec + std::vector const vec { 0xab, 0x98, 0x98, 0x98, 0x98, 0x98, 0x98, 0x98, 0x98, 0x98, 0x98, 0x98, 0x98, 0x00, 0x00, 0x00, @@ -1016,15 +1016,15 @@ TEST_CASE("regression tests 1") CHECK_THROWS_WITH_AS(_ = json::from_cbor(vec), "[json.exception.parse_error.113] parse error at byte 2: syntax error while parsing CBOR string: expected length specification (0x60-0x7B) or indefinite string type (0x7F); last byte: 0x98", json::parse_error&); // related test case: nonempty UTF-8 string (indefinite length) - std::vector vec1 {0x7f, 0x61, 0x61}; + std::vector const vec1 {0x7f, 0x61, 0x61}; CHECK_THROWS_WITH_AS(_ = json::from_cbor(vec1), "[json.exception.parse_error.110] parse error at byte 4: syntax error while parsing CBOR string: unexpected end of input", json::parse_error&); // related test case: nonempty array (indefinite length) - std::vector vec2 {0x9f, 0x01}; + std::vector const vec2 {0x9f, 0x01}; CHECK_THROWS_WITH_AS(_ = json::from_cbor(vec2), "[json.exception.parse_error.110] parse error at byte 3: syntax error while parsing CBOR value: unexpected end of input", json::parse_error&); // related test case: nonempty map (indefinite length) - std::vector vec3 {0xbf, 0x61, 0x61, 0x01}; + std::vector const vec3 {0xbf, 0x61, 0x61, 0x01}; CHECK_THROWS_WITH_AS(_ = json::from_cbor(vec3), "[json.exception.parse_error.110] parse error at byte 5: syntax error while parsing CBOR string: unexpected end of input", json::parse_error&); } @@ -1049,7 +1049,7 @@ TEST_CASE("regression tests 1") SECTION("issue #416 - Use-of-uninitialized-value (OSS-Fuzz issue 377)") { // original test case - std::vector vec1 + std::vector const vec1 { 0x94, 0xfa, 0xfa, 0xfa, 0xfa, 0xfa, 0xfa, 0xfa, 0x3a, 0x96, 0x96, 0xb4, 0xb4, 0xb4, 0xb4, 0xb4, @@ -1063,7 +1063,7 @@ TEST_CASE("regression tests 1") CHECK_THROWS_WITH_AS(_ = json::from_cbor(vec1), "[json.exception.parse_error.113] parse error at byte 13: syntax error while parsing CBOR string: expected length specification (0x60-0x7B) or indefinite string type (0x7F); last byte: 0xB4", json::parse_error&); // related test case: double-precision - std::vector vec2 + std::vector const vec2 { 0x94, 0xfa, 0xfa, 0xfa, 0xfa, 0xfa, 0xfa, 0xfa, 0x3a, 0x96, 0x96, 0xb4, 0xb4, 0xb4, 0xb4, 0xb4, @@ -1077,7 +1077,7 @@ TEST_CASE("regression tests 1") SECTION("issue #452 - Heap-buffer-overflow (OSS-Fuzz issue 585)") { - std::vector vec = {'-', '0', '1', '2', '2', '7', '4'}; + std::vector const vec = {'-', '0', '1', '2', '2', '7', '4'}; json _; CHECK_THROWS_AS(_ = json::parse(vec), json::parse_error&); } @@ -1100,9 +1100,9 @@ TEST_CASE("regression tests 1") SECTION("issue #465 - roundtrip error while parsing 1000000000000000010E5") { - json j1 = json::parse("1000000000000000010E5"); + json const j1 = json::parse("1000000000000000010E5"); std::string s1 = j1.dump(); - json j2 = json::parse(s1); + json const j2 = json::parse(s1); std::string s2 = j2.dump(); CHECK(s1 == s2); } @@ -1110,15 +1110,15 @@ TEST_CASE("regression tests 1") #if JSON_USE_IMPLICIT_CONVERSIONS SECTION("issue #473 - inconsistent behavior in conversion to array type") { - json j_array = {1, 2, 3, 4}; - json j_number = 42; - json j_null = nullptr; + json const j_array = {1, 2, 3, 4}; + json const j_number = 42; + json const j_null = nullptr; SECTION("std::vector") { auto create = [](const json & j) { - std::vector v = j; + std::vector const v = j; }; CHECK_NOTHROW(create(j_array)); @@ -1130,7 +1130,7 @@ TEST_CASE("regression tests 1") { auto create = [](const json & j) { - std::list v = j; + std::list const v = j; }; CHECK_NOTHROW(create(j_array)); @@ -1142,7 +1142,7 @@ TEST_CASE("regression tests 1") { auto create = [](const json & j) { - std::forward_list v = j; + std::forward_list const v = j; }; CHECK_NOTHROW(create(j_array)); @@ -1161,7 +1161,7 @@ TEST_CASE("regression tests 1") SECTION("issue #494 - conversion from vector to json fails to build") { - std::vector boolVector = {false, true, false, false}; + std::vector const boolVector = {false, true, false, false}; json j; j["bool_vector"] = boolVector; @@ -1170,14 +1170,14 @@ TEST_CASE("regression tests 1") SECTION("issue #504 - assertion error (OSS-Fuzz 856)") { - std::vector vec1 = {0xf9, 0xff, 0xff, 0x4a, 0x3a, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x01, 0x37, 0x02, 0x38}; - json j1 = json::from_cbor(vec1, false); + std::vector const vec1 = {0xf9, 0xff, 0xff, 0x4a, 0x3a, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x01, 0x37, 0x02, 0x38}; + json const j1 = json::from_cbor(vec1, false); // step 2: round trip std::vector vec2 = json::to_cbor(j1); // parse serialization - json j2 = json::from_cbor(vec2); + json const j2 = json::from_cbor(vec2); // NaN is dumped to "null" CHECK(j2.is_number_float()); @@ -1226,7 +1226,7 @@ TEST_CASE("regression tests 1") SECTION("issue #575 - heap-buffer-overflow (OSS-Fuzz 1400)") { json _; - std::vector vec = {'"', '\\', '"', 'X', '"', '"'}; + std::vector const vec = {'"', '\\', '"', 'X', '"', '"'}; CHECK_THROWS_AS(_ = json::parse(vec), json::parse_error&); } @@ -1239,7 +1239,7 @@ TEST_CASE("regression tests 1") std::map m1 {{"key", 1}}; // create and print a JSON from the map - json j = m1; + json const j = m1; // get the map out of JSON std::map m2 = j; @@ -1254,7 +1254,7 @@ TEST_CASE("regression tests 1") std::map m1 {{"key", "val"}}; // create and print a JSON from the map - json j = m1; + json const j = m1; // get the map out of JSON std::map m2 = j; @@ -1277,7 +1277,7 @@ TEST_CASE("regression tests 1") { SECTION("original example") { - std::valarray v; + std::valarray const v; nlohmann::json j; j["test"] = v; } @@ -1364,8 +1364,8 @@ TEST_CASE("regression tests 1") SECTION("issue #838 - incorrect parse error with binary data in keys") { std::array key1 = {{ 103, 92, 117, 48, 48, 48, 55, 92, 114, 215, 126, 214, 95, 92, 34, 174, 40, 71, 38, 174, 40, 71, 38, 223, 134, 247, 127, 0 }}; - std::string key1_str(reinterpret_cast(key1.data())); - json j = key1_str; + std::string const key1_str(reinterpret_cast(key1.data())); + json const j = key1_str; CHECK_THROWS_WITH_AS(j.dump(), "[json.exception.type_error.316] invalid UTF-8 byte at index 10: 0x7E", json::type_error&); } @@ -1405,7 +1405,7 @@ TEST_CASE("regression tests 1") SECTION("issue #961 - incorrect parsing of indefinite length CBOR strings") { - std::vector v_cbor = + std::vector const v_cbor = { 0x7F, 0x64, @@ -1453,7 +1453,7 @@ TEST_CASE("regression tests 1") )"; // define parser callback - json::parser_callback_t cb = [](int /*depth*/, json::parse_event_t event, json & parsed) + json::parser_callback_t const cb = [](int /*depth*/, json::parse_event_t event, json & parsed) { // skip object elements with key "Thumbnail" return !(event == json::parse_event_t::key && parsed == json("Thumbnail")); @@ -1467,7 +1467,7 @@ TEST_CASE("regression tests 1") SECTION("issue #972 - Segmentation fault on G++ when trying to assign json string literal to custom json type") { - my_json foo = R"([1, 2, 3])"_json; + my_json const foo = R"([1, 2, 3])"_json; } SECTION("issue #977 - Assigning between different json types") @@ -1478,7 +1478,7 @@ TEST_CASE("regression tests 1") CHECK(lj.size() == 1); CHECK(lj["x"] == 3); CHECK(ff.x == 3); - nlohmann::json nj = lj; // This line works as expected + nlohmann::json const nj = lj; // This line works as expected } } diff --git a/tests/src/unit-regression2.cpp b/tests/src/unit-regression2.cpp index 503d2a4f8..308ceeef9 100644 --- a/tests/src/unit-regression2.cpp +++ b/tests/src/unit-regression2.cpp @@ -348,7 +348,7 @@ TEST_CASE("regression tests 2") ] })"; - json::parser_callback_t cb = [&](int /*level*/, json::parse_event_t event, json & parsed) noexcept + const json::parser_callback_t cb = [&](int /*level*/, json::parse_event_t event, json & parsed) noexcept { // skip uninteresting events if (event == json::parse_event_t::value && !parsed.is_primitive()) @@ -440,7 +440,7 @@ TEST_CASE("regression tests 2") SECTION("issue #1299 - compile error in from_json converting to container " "with std::pair") { - json j = + const json j = { {"1", {{"a", "testa_1"}, {"b", "testb_1"}}}, {"2", {{"a", "testa_2"}, {"b", "testb_2"}}}, @@ -501,7 +501,7 @@ TEST_CASE("regression tests 2") {109, 108, 103, 125, -122, -53, 115, 18, 3, 0, 102, 19, 1, 15, -110, 13, -3, -1, -81, 32, 2, 0, 0, 0, 0, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -80, 2, 0, 0, 96, -118, 46, -116, 46, 109, -84, -87, 108, 14, 109, -24, -83, 13, -18, -51, -83, -52, -115, 14, 6, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 64, 3, 0, 0, 0, 35, -74, -73, 55, 57, -128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 33, 0, 0, 0, -96, -54, -28, -26} }; std::string s; - for (int i : data) + for (const int i : data) { s += static_cast(i); } @@ -512,20 +512,20 @@ TEST_CASE("regression tests 2") SECTION("issue #1447 - Integer Overflow (OSS-Fuzz 12506)") { - json j = json::parse("[-9223372036854775808]"); + const json j = json::parse("[-9223372036854775808]"); CHECK(j.dump() == "[-9223372036854775808]"); } SECTION("issue #1708 - minimum value of int64_t can be outputted") { constexpr auto smallest = (std::numeric_limits::min)(); - json j = smallest; + const json j = smallest; CHECK(j.dump() == std::to_string(smallest)); } SECTION("issue #1727 - Contains with non-const lvalue json_pointer picks the wrong overload") { - json j = {{"root", {{"settings", {{"logging", true}}}}}}; + const json j = {{"root", {{"settings", {{"logging", true}}}}}}; auto jptr1 = "/root/settings/logging"_json_pointer; auto jptr2 = json::json_pointer{"/root/settings/logging"}; @@ -539,7 +539,7 @@ TEST_CASE("regression tests 2") // does not compile on ICPC when targeting C++20 #if !(defined(__INTEL_COMPILER) && __cplusplus >= 202000) { - json j; + const json j; NonDefaultFromJsonStruct x(j); NonDefaultFromJsonStruct y; CHECK(x == y); @@ -548,27 +548,27 @@ TEST_CASE("regression tests 2") auto val = nlohmann::json("one").get(); CHECK(val == for_1647::one); - json j = val; + const json j = val; } SECTION("issue #1715 - json::from_cbor does not respect allow_exceptions = false when input is string literal") { SECTION("string literal") { - json cbor = json::from_cbor("B", true, false); + const json cbor = json::from_cbor("B", true, false); CHECK(cbor.is_discarded()); } SECTION("string array") { const std::array input = {{'B', 0x00}}; - json cbor = json::from_cbor(input, true, false); + const json cbor = json::from_cbor(input, true, false); CHECK(cbor.is_discarded()); } SECTION("std::string") { - json cbor = json::from_cbor(std::string("B"), true, false); + const json cbor = json::from_cbor(std::string("B"), true, false); CHECK(cbor.is_discarded()); } } @@ -597,7 +597,7 @@ TEST_CASE("regression tests 2") SECTION("issue #2067 - cannot serialize binary data to text JSON") { const std::array data = {{0x81, 0xA4, 0x64, 0x61, 0x74, 0x61, 0xC4, 0x0F, 0x33, 0x30, 0x30, 0x32, 0x33, 0x34, 0x30, 0x31, 0x30, 0x37, 0x30, 0x35, 0x30, 0x31, 0x30}}; - json j = json::from_msgpack(data.data(), data.size()); + const json j = json::from_msgpack(data.data(), data.size()); CHECK_NOTHROW( j.dump(4, // Indent ' ', // Indent char @@ -609,15 +609,15 @@ TEST_CASE("regression tests 2") SECTION("PR #2181 - regression bug with lvalue") { // see https://github.com/nlohmann/json/pull/2181#issuecomment-653326060 - json j{{"x", "test"}}; - std::string defval = "default value"; + const json j{{"x", "test"}}; + const std::string defval = "default value"; auto val = j.value("x", defval); auto val2 = j.value("y", defval); } SECTION("issue #2293 - eof doesn't cause parsing to stop") { - std::vector data = + const std::vector data = { 0x7B, 0x6F, @@ -630,23 +630,23 @@ TEST_CASE("regression tests 2") 0x4F, 0x42 }; - json result = json::from_cbor(data, true, false); + const json result = json::from_cbor(data, true, false); CHECK(result.is_discarded()); } SECTION("issue #2315 - json.update and vectordoes not work with ordered_json") { nlohmann::ordered_json jsonAnimals = {{"animal", "dog"}}; - nlohmann::ordered_json jsonCat = {{"animal", "cat"}}; + const nlohmann::ordered_json jsonCat = {{"animal", "cat"}}; jsonAnimals.update(jsonCat); CHECK(jsonAnimals["animal"] == "cat"); auto jsonAnimals_parsed = nlohmann::ordered_json::parse(jsonAnimals.dump()); CHECK(jsonAnimals == jsonAnimals_parsed); - std::vector> intData = {std::make_pair("aaaa", 11), - std::make_pair("bbb", 222) - }; + const std::vector> intData = {std::make_pair("aaaa", 11), + std::make_pair("bbb", 222) + }; nlohmann::ordered_json jsonObj; for (const auto& data : intData) { @@ -658,8 +658,8 @@ TEST_CASE("regression tests 2") SECTION("issue #2330 - ignore_comment=true fails on multiple consecutive lines starting with comments") { - std::string ss = "//\n//\n{\n}\n"; - json j = json::parse(ss, nullptr, true, true); + const std::string ss = "//\n//\n{\n}\n"; + const json j = json::parse(ss, nullptr, true, true); CHECK(j.dump() == "{}"); } @@ -668,7 +668,7 @@ TEST_CASE("regression tests 2") { const char DATA[] = R"("Hello, world!")"; // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays) const auto s = std::as_bytes(std::span(DATA)); - json j = json::parse(s); + const json j = json::parse(s); CHECK(j.dump() == "\"Hello, world!\""); } #endif @@ -678,14 +678,14 @@ TEST_CASE("regression tests 2") SECTION("std::array") { { - json j = {7, 4}; + const json j = {7, 4}; auto arr = j.get>(); CHECK(arr[0].x == 7); CHECK(arr[1].x == 4); } { - json j = 7; + const json j = 7; CHECK_THROWS_AS((j.get>()), json::type_error); } } @@ -693,28 +693,28 @@ TEST_CASE("regression tests 2") SECTION("std::pair") { { - json j = {3, 8}; + const json j = {3, 8}; auto p = j.get>(); CHECK(p.first.x == 3); CHECK(p.second.x == 8); } { - json j = {4, 1}; + const json j = {4, 1}; auto p = j.get>(); CHECK(p.first == 4); CHECK(p.second.x == 1); } { - json j = {6, 7}; + const json j = {6, 7}; auto p = j.get>(); CHECK(p.first.x == 6); CHECK(p.second == 7); } { - json j = 7; + const json j = 7; CHECK_THROWS_AS((j.get>()), json::type_error); } } @@ -722,13 +722,13 @@ TEST_CASE("regression tests 2") SECTION("std::tuple") { { - json j = {9}; + const json j = {9}; auto t = j.get>(); CHECK(std::get<0>(t).x == 9); } { - json j = {9, 8, 7}; + const json j = {9, 8, 7}; auto t = j.get>(); CHECK(std::get<0>(t).x == 9); CHECK(std::get<1>(t) == 8); @@ -736,7 +736,7 @@ TEST_CASE("regression tests 2") } { - json j = 7; + const json j = 7; CHECK_THROWS_AS((j.get>()), json::type_error); } } @@ -747,7 +747,7 @@ TEST_CASE("regression tests 2") // the code below is expected to not leak memory { nlohmann::json o; - std::string s = "bar"; + const std::string s = "bar"; nlohmann::to_json(o["foo"], s); @@ -759,7 +759,7 @@ TEST_CASE("regression tests 2") { nlohmann::json o; - std::string s = "bar"; + const std::string s = "bar"; nlohmann::to_json(o["foo"], s); @@ -785,7 +785,7 @@ TEST_CASE("regression tests 2") SECTION("issue #2958 - Inserting in unordered json using a pointer retains the leading slash") { - std::string p = "/root"; + const std::string p = "/root"; json test1; test1[json::json_pointer(p)] = json::object(); @@ -816,7 +816,7 @@ TEST_CASE("regression tests 2") SECTION("issue #3070 - Version 3.10.3 breaks backward-compatibility with 3.10.2 ") { nlohmann::detail::std_fs::path text_path("/tmp/text.txt"); - json j(text_path); + const json j(text_path); const auto j_path = j.get(); CHECK(j_path == text_path); @@ -867,7 +867,7 @@ TEST_CASE("regression tests 2") SECTION("issue #3171 - if class is_constructible from std::string wrong from_json overload is being selected, compilation failed") { - json j{{ "str", "value"}}; + const json j{{ "str", "value"}}; // failed with: error: no match for ‘operator=’ (operand types are ‘for_3171_derived’ and ‘const nlohmann::basic_json<>::string_t’ // {aka ‘const std::__cxx11::basic_string’}) @@ -881,7 +881,7 @@ TEST_CASE("regression tests 2") SECTION("issue #3312 - Parse to custom class from unordered_json breaks on G++11.2.0 with C++20") { // see test for #3171 - ordered_json j = {{"name", "class"}}; + const ordered_json j = {{"name", "class"}}; for_3312 obj{}; j.get_to(obj); @@ -893,8 +893,8 @@ TEST_CASE("regression tests 2") #if defined(JSON_HAS_CPP_17) && JSON_USE_IMPLICIT_CONVERSIONS SECTION("issue #3428 - Error occurred when converting nlohmann::json to std::any") { - json j; - std::any a1 = j; + const json j; + const std::any a1 = j; std::any&& a2 = j; CHECK(a1.type() == typeid(j)); diff --git a/tests/src/unit-serialization.cpp b/tests/src/unit-serialization.cpp index a023d23d9..01e5bdfea 100644 --- a/tests/src/unit-serialization.cpp +++ b/tests/src/unit-serialization.cpp @@ -21,7 +21,7 @@ TEST_CASE("serialization") SECTION("no given width") { std::stringstream ss; - json j = {"foo", 1, 2, 3, false, {{"one", 1}}}; + const json j = {"foo", 1, 2, 3, false, {{"one", 1}}}; ss << j; CHECK(ss.str() == "[\"foo\",1,2,3,false,{\"one\":1}]"); } @@ -29,7 +29,7 @@ TEST_CASE("serialization") SECTION("given width") { std::stringstream ss; - json j = {"foo", 1, 2, 3, false, {{"one", 1}}}; + const json j = {"foo", 1, 2, 3, false, {{"one", 1}}}; ss << std::setw(4) << j; CHECK(ss.str() == "[\n \"foo\",\n 1,\n 2,\n 3,\n false,\n {\n \"one\": 1\n }\n]"); @@ -38,7 +38,7 @@ TEST_CASE("serialization") SECTION("given fill") { std::stringstream ss; - json j = {"foo", 1, 2, 3, false, {{"one", 1}}}; + const json j = {"foo", 1, 2, 3, false, {{"one", 1}}}; ss << std::setw(1) << std::setfill('\t') << j; CHECK(ss.str() == "[\n\t\"foo\",\n\t1,\n\t2,\n\t3,\n\tfalse,\n\t{\n\t\t\"one\": 1\n\t}\n]"); @@ -50,7 +50,7 @@ TEST_CASE("serialization") SECTION("no given width") { std::stringstream ss; - json j = {"foo", 1, 2, 3, false, {{"one", 1}}}; + const json j = {"foo", 1, 2, 3, false, {{"one", 1}}}; j >> ss; CHECK(ss.str() == "[\"foo\",1,2,3,false,{\"one\":1}]"); } @@ -58,7 +58,7 @@ TEST_CASE("serialization") SECTION("given width") { std::stringstream ss; - json j = {"foo", 1, 2, 3, false, {{"one", 1}}}; + const json j = {"foo", 1, 2, 3, false, {{"one", 1}}}; ss.width(4); j >> ss; CHECK(ss.str() == @@ -68,7 +68,7 @@ TEST_CASE("serialization") SECTION("given fill") { std::stringstream ss; - json j = {"foo", 1, 2, 3, false, {{"one", 1}}}; + const json j = {"foo", 1, 2, 3, false, {{"one", 1}}}; ss.width(1); ss.fill('\t'); j >> ss; @@ -81,7 +81,7 @@ TEST_CASE("serialization") { SECTION("invalid character") { - json j = "ä\xA9ü"; + const json j = "ä\xA9ü"; CHECK_THROWS_WITH_AS(j.dump(), "[json.exception.type_error.316] invalid UTF-8 byte at index 2: 0xA9", json::type_error&); CHECK_THROWS_WITH_AS(j.dump(1, ' ', false, json::error_handler_t::strict), "[json.exception.type_error.316] invalid UTF-8 byte at index 2: 0xA9", json::type_error&); @@ -92,7 +92,7 @@ TEST_CASE("serialization") SECTION("ending with incomplete character") { - json j = "123\xC2"; + const json j = "123\xC2"; CHECK_THROWS_WITH_AS(j.dump(), "[json.exception.type_error.316] incomplete UTF-8 string; last byte: 0xC2", json::type_error&); CHECK_THROWS_AS(j.dump(1, ' ', false, json::error_handler_t::strict), json::type_error&); @@ -103,7 +103,7 @@ TEST_CASE("serialization") SECTION("unexpected character") { - json j = "123\xF1\xB0\x34\x35\x36"; + const json j = "123\xF1\xB0\x34\x35\x36"; CHECK_THROWS_WITH_AS(j.dump(), "[json.exception.type_error.316] invalid UTF-8 byte at index 5: 0x34", json::type_error&); CHECK_THROWS_AS(j.dump(1, ' ', false, json::error_handler_t::strict), json::type_error&); @@ -120,7 +120,7 @@ TEST_CASE("serialization") auto test = [&](std::string const & input, std::string const & expected) { - json j = input; + const json j = input; CHECK(j.dump(-1, ' ', true, json::error_handler_t::replace) == "\"" + expected + "\""); }; @@ -154,7 +154,7 @@ TEST_CASE("serialization") auto test = [&](std::string const & input, std::string const & expected) { using std::to_string; - json j = input; + const json j = input; CHECK(to_string(j) == "\"" + expected + "\""); }; @@ -170,14 +170,14 @@ TEST_CASE_TEMPLATE("serialization for extreme integer values", T, int32_t, uint3 SECTION("minimum") { constexpr auto minimum = (std::numeric_limits::min)(); - json j = minimum; + const json j = minimum; CHECK(j.dump() == std::to_string(minimum)); } SECTION("maximum") { constexpr auto maximum = (std::numeric_limits::max)(); - json j = maximum; + const json j = maximum; CHECK(j.dump() == std::to_string(maximum)); } } @@ -189,15 +189,15 @@ TEST_CASE("dump with binary values") auto binary_with_subtype = json::binary({1, 2, 3, 4}, 128); auto binary_empty_with_subtype = json::binary({}, 128); - json object = {{"key", binary}}; - json object_empty = {{"key", binary_empty}}; - json object_with_subtype = {{"key", binary_with_subtype}}; - json object_empty_with_subtype = {{"key", binary_empty_with_subtype}}; + const json object = {{"key", binary}}; + const json object_empty = {{"key", binary_empty}}; + const json object_with_subtype = {{"key", binary_with_subtype}}; + const json object_empty_with_subtype = {{"key", binary_empty_with_subtype}}; - json array = {"value", 1, binary}; - json array_empty = {"value", 1, binary_empty}; - json array_with_subtype = {"value", 1, binary_with_subtype}; - json array_empty_with_subtype = {"value", 1, binary_empty_with_subtype}; + const json array = {"value", 1, binary}; + const json array_empty = {"value", 1, binary_empty}; + const json array_with_subtype = {"value", 1, binary_with_subtype}; + const json array_empty_with_subtype = {"value", 1, binary_empty_with_subtype}; SECTION("normal") { diff --git a/tests/src/unit-testsuites.cpp b/tests/src/unit-testsuites.cpp index 48cb07255..e0cc127b9 100644 --- a/tests/src/unit-testsuites.cpp +++ b/tests/src/unit-testsuites.cpp @@ -302,7 +302,7 @@ TEST_CASE("compliance tests from nativejson-benchmark") (std::istreambuf_iterator()) ); CAPTURE(json_string) - json j = json::parse(json_string); + const json j = json::parse(json_string); CHECK(j.dump() == json_string); } } @@ -363,35 +363,35 @@ TEST_CASE("json.org examples") } SECTION("FILE 1.json") { - std::unique_ptr f(std::fopen(TEST_DATA_DIRECTORY "/json.org/1.json", "r"), &std::fclose); + const std::unique_ptr f(std::fopen(TEST_DATA_DIRECTORY "/json.org/1.json", "r"), &std::fclose); json _; CHECK_NOTHROW(_ = json::parse(f.get())); } SECTION("FILE 2.json") { - std::unique_ptr f(std::fopen(TEST_DATA_DIRECTORY "/json.org/2.json", "r"), &std::fclose); + const std::unique_ptr f(std::fopen(TEST_DATA_DIRECTORY "/json.org/2.json", "r"), &std::fclose); json _; CHECK_NOTHROW(_ = json::parse(f.get())); } SECTION("FILE 3.json") { - std::unique_ptr f(std::fopen(TEST_DATA_DIRECTORY "/json.org/3.json", "r"), &std::fclose); + const std::unique_ptr f(std::fopen(TEST_DATA_DIRECTORY "/json.org/3.json", "r"), &std::fclose); json _; CHECK_NOTHROW(_ = json::parse(f.get())); } SECTION("FILE 4.json") { - std::unique_ptr f(std::fopen(TEST_DATA_DIRECTORY "/json.org/4.json", "r"), &std::fclose); + const std::unique_ptr f(std::fopen(TEST_DATA_DIRECTORY "/json.org/4.json", "r"), &std::fclose); json _; CHECK_NOTHROW(_ = json::parse(f.get())); } SECTION("FILE 5.json") { - std::unique_ptr f(std::fopen(TEST_DATA_DIRECTORY "/json.org/5.json", "r"), &std::fclose); + const std::unique_ptr f(std::fopen(TEST_DATA_DIRECTORY "/json.org/5.json", "r"), &std::fclose); json _; CHECK_NOTHROW(_ = json::parse(f.get())); } @@ -1340,12 +1340,12 @@ std::string trim(const std::string& str); // from https://stackoverflow.com/a/25829178/266378 std::string trim(const std::string& str) { - size_t first = str.find_first_not_of(' '); + const size_t first = str.find_first_not_of(' '); if (std::string::npos == first) { return str; } - size_t last = str.find_last_not_of(' '); + const size_t last = str.find_last_not_of(' '); return str.substr(first, (last - first + 1)); } } // namespace @@ -1384,7 +1384,7 @@ TEST_CASE("Big List of Naughty Strings") // check roundtrip CAPTURE(line) - json j = json::parse(line); + const json j = json::parse(line); CHECK(j.dump() == line); } } diff --git a/tests/src/unit-to_chars.cpp b/tests/src/unit-to_chars.cpp index 0d5fcd422..d9f75ea2f 100644 --- a/tests/src/unit-to_chars.cpp +++ b/tests/src/unit-to_chars.cpp @@ -61,11 +61,11 @@ float make_float(uint64_t f, int e) e--; } - uint64_t biased_exponent = (e == kDenormalExponent && (f & kHiddenBit) == 0) - ? 0 - : static_cast(e + kExponentBias); + const uint64_t biased_exponent = (e == kDenormalExponent && (f & kHiddenBit) == 0) + ? 0 + : static_cast(e + kExponentBias); - uint64_t bits = (f & kSignificandMask) | (biased_exponent << kPhysicalSignificandSize); + const uint64_t bits = (f & kSignificandMask) | (biased_exponent << kPhysicalSignificandSize); return reinterpret_bits(static_cast(bits)); } @@ -113,11 +113,11 @@ double make_double(uint64_t f, int e) e--; } - uint64_t biased_exponent = (e == kDenormalExponent && (f & kHiddenBit) == 0) - ? 0 - : static_cast(e + kExponentBias); + const uint64_t biased_exponent = (e == kDenormalExponent && (f & kHiddenBit) == 0) + ? 0 + : static_cast(e + kExponentBias); - uint64_t bits = (f & kSignificandMask) | (biased_exponent << kPhysicalSignificandSize); + const uint64_t bits = (f & kSignificandMask) | (biased_exponent << kPhysicalSignificandSize); return reinterpret_bits(bits); } } // namespace @@ -458,7 +458,7 @@ TEST_CASE("formatting") { auto check_integer = [](std::int64_t number, const std::string & expected) { - nlohmann::json j = number; + const nlohmann::json j = number; CHECK(j.dump() == expected); }; diff --git a/tests/src/unit-ubjson.cpp b/tests/src/unit-ubjson.cpp index 8045ba992..a8e04ed1b 100644 --- a/tests/src/unit-ubjson.cpp +++ b/tests/src/unit-ubjson.cpp @@ -102,14 +102,14 @@ TEST_CASE("UBJSON") 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_ubjson(j); CHECK(result.empty()); } SECTION("null") { - json j = nullptr; + json const j = nullptr; std::vector expected = {'Z'}; const auto result = json::to_ubjson(j); CHECK(result == expected); @@ -123,8 +123,8 @@ TEST_CASE("UBJSON") { SECTION("true") { - json j = true; - std::vector expected = {'T'}; + json const j = true; + std::vector const expected = {'T'}; const auto result = json::to_ubjson(j); CHECK(result == expected); @@ -135,8 +135,8 @@ TEST_CASE("UBJSON") SECTION("false") { - json j = false; - std::vector expected = {'F'}; + json const j = false; + std::vector const expected = {'F'}; const auto result = json::to_ubjson(j); CHECK(result == expected); @@ -152,39 +152,43 @@ TEST_CASE("UBJSON") { SECTION("-9223372036854775808..-2147483649 (int64)") { - std::vector numbers; - numbers.push_back((std::numeric_limits::min)()); - numbers.push_back(-1000000000000000000LL); - numbers.push_back(-100000000000000000LL); - numbers.push_back(-10000000000000000LL); - numbers.push_back(-1000000000000000LL); - numbers.push_back(-100000000000000LL); - numbers.push_back(-10000000000000LL); - numbers.push_back(-1000000000000LL); - numbers.push_back(-100000000000LL); - numbers.push_back(-10000000000LL); - numbers.push_back(-2147483649LL); + std::vector const numbers + { + (std::numeric_limits::min)(), + -1000000000000000000LL, + -100000000000000000LL, + -10000000000000000LL, + -1000000000000000LL, + -100000000000000LL, + -10000000000000LL, + -1000000000000LL, + -100000000000LL, + -10000000000LL, + -2147483649LL, + }; for (auto i : numbers) { CAPTURE(i) // create JSON value with integer number - json j = i; + json const j = i; // check type CHECK(j.is_number_integer()); // create expected byte vector - std::vector expected; - expected.push_back(static_cast('L')); - expected.push_back(static_cast((i >> 56) & 0xff)); - expected.push_back(static_cast((i >> 48) & 0xff)); - expected.push_back(static_cast((i >> 40) & 0xff)); - expected.push_back(static_cast((i >> 32) & 0xff)); - expected.push_back(static_cast((i >> 24) & 0xff)); - expected.push_back(static_cast((i >> 16) & 0xff)); - expected.push_back(static_cast((i >> 8) & 0xff)); - expected.push_back(static_cast(i & 0xff)); + std::vector const expected + { + static_cast('L'), + static_cast((i >> 56) & 0xff), + static_cast((i >> 48) & 0xff), + static_cast((i >> 40) & 0xff), + static_cast((i >> 32) & 0xff), + static_cast((i >> 24) & 0xff), + static_cast((i >> 16) & 0xff), + static_cast((i >> 8) & 0xff), + static_cast(i & 0xff), + }; // compare result + size const auto result = json::to_ubjson(j); @@ -193,14 +197,14 @@ TEST_CASE("UBJSON") // check individual bytes CHECK(result[0] == 'L'); - int64_t restored = (static_cast(result[1]) << 070) + - (static_cast(result[2]) << 060) + - (static_cast(result[3]) << 050) + - (static_cast(result[4]) << 040) + - (static_cast(result[5]) << 030) + - (static_cast(result[6]) << 020) + - (static_cast(result[7]) << 010) + - static_cast(result[8]); + int64_t const restored = (static_cast(result[1]) << 070) + + (static_cast(result[2]) << 060) + + (static_cast(result[3]) << 050) + + (static_cast(result[4]) << 040) + + (static_cast(result[5]) << 030) + + (static_cast(result[6]) << 020) + + (static_cast(result[7]) << 010) + + static_cast(result[8]); CHECK(restored == i); // roundtrip @@ -224,18 +228,20 @@ TEST_CASE("UBJSON") CAPTURE(i) // create JSON value with integer number - json j = i; + json const j = i; // check type CHECK(j.is_number_integer()); // create expected byte vector - std::vector expected; - expected.push_back(static_cast('l')); - expected.push_back(static_cast((i >> 24) & 0xff)); - expected.push_back(static_cast((i >> 16) & 0xff)); - expected.push_back(static_cast((i >> 8) & 0xff)); - expected.push_back(static_cast(i & 0xff)); + std::vector const expected + { + static_cast('l'), + static_cast((i >> 24) & 0xff), + static_cast((i >> 16) & 0xff), + static_cast((i >> 8) & 0xff), + static_cast(i & 0xff), + }; // compare result + size const auto result = json::to_ubjson(j); @@ -244,10 +250,10 @@ TEST_CASE("UBJSON") // check individual bytes CHECK(result[0] == 'l'); - int32_t restored = (static_cast(result[1]) << 030) + - (static_cast(result[2]) << 020) + - (static_cast(result[3]) << 010) + - static_cast(result[4]); + int32_t const restored = (static_cast(result[1]) << 030) + + (static_cast(result[2]) << 020) + + (static_cast(result[3]) << 010) + + static_cast(result[4]); CHECK(restored == i); // roundtrip @@ -263,16 +269,18 @@ TEST_CASE("UBJSON") CAPTURE(i) // create JSON value with integer number - json j = i; + json const j = i; // check type CHECK(j.is_number_integer()); // create expected byte vector - std::vector expected; - expected.push_back(static_cast('I')); - expected.push_back(static_cast((i >> 8) & 0xff)); - expected.push_back(static_cast(i & 0xff)); + std::vector const expected + { + static_cast('I'), + static_cast((i >> 8) & 0xff), + static_cast(i & 0xff), + }; // compare result + size const auto result = json::to_ubjson(j); @@ -281,7 +289,7 @@ TEST_CASE("UBJSON") // check individual bytes CHECK(result[0] == 'I'); - auto restored = static_cast(((result[1] << 8) + result[2])); + auto const restored = static_cast(((result[1] << 8) + result[2])); CHECK(restored == i); // roundtrip @@ -292,7 +300,7 @@ TEST_CASE("UBJSON") SECTION("-9263 (int16)") { - json j = -9263; + json const j = -9263; std::vector expected = {'I', 0xdb, 0xd1}; // compare result + size @@ -302,7 +310,7 @@ TEST_CASE("UBJSON") // check individual bytes CHECK(result[0] == 'I'); - auto restored = static_cast(((result[1] << 8) + result[2])); + auto const restored = static_cast(((result[1] << 8) + result[2])); CHECK(restored == -9263); // roundtrip @@ -317,15 +325,17 @@ TEST_CASE("UBJSON") CAPTURE(i) // create JSON value with integer number - json j = i; + json const j = i; // check type CHECK(j.is_number_integer()); // create expected byte vector - std::vector expected; - expected.push_back('i'); - expected.push_back(static_cast(i)); + std::vector const expected + { + 'i', + static_cast(i), + }; // compare result + size const auto result = json::to_ubjson(j); @@ -356,9 +366,11 @@ TEST_CASE("UBJSON") CHECK(j.is_number_integer()); // create expected byte vector - std::vector expected; - expected.push_back(static_cast('i')); - expected.push_back(static_cast(i)); + std::vector const expected + { + static_cast('i'), + static_cast(i), + }; // compare result + size const auto result = json::to_ubjson(j); @@ -389,9 +401,11 @@ TEST_CASE("UBJSON") CHECK(j.is_number_integer()); // create expected byte vector - std::vector expected; - expected.push_back(static_cast('U')); - expected.push_back(static_cast(i)); + std::vector const expected + { + static_cast('U'), + static_cast(i), + }; // compare result + size const auto result = json::to_ubjson(j); @@ -422,10 +436,12 @@ TEST_CASE("UBJSON") CHECK(j.is_number_integer()); // create expected byte vector - std::vector expected; - expected.push_back(static_cast('I')); - expected.push_back(static_cast((i >> 8) & 0xff)); - expected.push_back(static_cast(i & 0xff)); + std::vector const expected + { + static_cast('I'), + static_cast((i >> 8) & 0xff), + static_cast(i & 0xff), + }; // compare result + size const auto result = json::to_ubjson(j); @@ -434,7 +450,7 @@ TEST_CASE("UBJSON") // check individual bytes CHECK(result[0] == 'I'); - auto restored = static_cast(static_cast(result[1]) * 256 + static_cast(result[2])); + auto const restored = static_cast(static_cast(result[1]) * 256 + static_cast(result[2])); CHECK(restored == i); // roundtrip @@ -460,12 +476,14 @@ TEST_CASE("UBJSON") CHECK(j.is_number_integer()); // create expected byte vector - std::vector expected; - expected.push_back('l'); - expected.push_back(static_cast((i >> 24) & 0xff)); - expected.push_back(static_cast((i >> 16) & 0xff)); - expected.push_back(static_cast((i >> 8) & 0xff)); - expected.push_back(static_cast(i & 0xff)); + std::vector const expected + { + 'l', + static_cast((i >> 24) & 0xff), + static_cast((i >> 16) & 0xff), + static_cast((i >> 8) & 0xff), + static_cast(i & 0xff), + }; // compare result + size const auto result = json::to_ubjson(j); @@ -474,10 +492,10 @@ TEST_CASE("UBJSON") // check individual bytes CHECK(result[0] == 'l'); - uint32_t restored = (static_cast(result[1]) << 030) + - (static_cast(result[2]) << 020) + - (static_cast(result[3]) << 010) + - static_cast(result[4]); + uint32_t const restored = (static_cast(result[1]) << 030) + + (static_cast(result[2]) << 020) + + (static_cast(result[3]) << 010) + + static_cast(result[4]); CHECK(restored == i); // roundtrip @@ -488,7 +506,7 @@ TEST_CASE("UBJSON") SECTION("2147483648..9223372036854775807 (int64)") { - std::vector v = {2147483648ul, 9223372036854775807ul}; + std::vector const v = {2147483648ul, 9223372036854775807ul}; for (uint64_t i : v) { CAPTURE(i) @@ -501,16 +519,18 @@ TEST_CASE("UBJSON") CHECK(j.is_number_integer()); // create expected byte vector - std::vector expected; - expected.push_back('L'); - expected.push_back(static_cast((i >> 070) & 0xff)); - expected.push_back(static_cast((i >> 060) & 0xff)); - expected.push_back(static_cast((i >> 050) & 0xff)); - expected.push_back(static_cast((i >> 040) & 0xff)); - expected.push_back(static_cast((i >> 030) & 0xff)); - expected.push_back(static_cast((i >> 020) & 0xff)); - expected.push_back(static_cast((i >> 010) & 0xff)); - expected.push_back(static_cast(i & 0xff)); + std::vector const expected + { + 'L', + static_cast((i >> 070) & 0xff), + static_cast((i >> 060) & 0xff), + static_cast((i >> 050) & 0xff), + static_cast((i >> 040) & 0xff), + static_cast((i >> 030) & 0xff), + static_cast((i >> 020) & 0xff), + static_cast((i >> 010) & 0xff), + static_cast(i & 0xff), + }; // compare result + size const auto result = json::to_ubjson(j); @@ -519,14 +539,14 @@ TEST_CASE("UBJSON") // check individual bytes CHECK(result[0] == 'L'); - uint64_t restored = (static_cast(result[1]) << 070) + - (static_cast(result[2]) << 060) + - (static_cast(result[3]) << 050) + - (static_cast(result[4]) << 040) + - (static_cast(result[5]) << 030) + - (static_cast(result[6]) << 020) + - (static_cast(result[7]) << 010) + - static_cast(result[8]); + uint64_t const restored = (static_cast(result[1]) << 070) + + (static_cast(result[2]) << 060) + + (static_cast(result[3]) << 050) + + (static_cast(result[4]) << 040) + + (static_cast(result[5]) << 030) + + (static_cast(result[6]) << 020) + + (static_cast(result[7]) << 010) + + static_cast(result[8]); CHECK(restored == i); // roundtrip @@ -545,15 +565,17 @@ TEST_CASE("UBJSON") CAPTURE(i) // create JSON value with unsigned integer number - json j = i; + json const j = i; // check type CHECK(j.is_number_unsigned()); // create expected byte vector - std::vector expected; - expected.push_back('i'); - expected.push_back(static_cast(i)); + std::vector const expected + { + 'i', + static_cast(i), + }; // compare result + size const auto result = json::to_ubjson(j); @@ -562,7 +584,7 @@ TEST_CASE("UBJSON") // check individual bytes CHECK(result[0] == 'i'); - auto restored = static_cast(result[1]); + auto const restored = static_cast(result[1]); CHECK(restored == i); // roundtrip @@ -578,15 +600,17 @@ TEST_CASE("UBJSON") CAPTURE(i) // create JSON value with unsigned integer number - json j = i; + json const j = i; // check type CHECK(j.is_number_unsigned()); // create expected byte vector - std::vector expected; - expected.push_back('U'); - expected.push_back(static_cast(i)); + std::vector const expected + { + 'U', + static_cast(i), + }; // compare result + size const auto result = json::to_ubjson(j); @@ -595,7 +619,7 @@ TEST_CASE("UBJSON") // check individual bytes CHECK(result[0] == 'U'); - auto restored = static_cast(result[1]); + auto const restored = static_cast(result[1]); CHECK(restored == i); // roundtrip @@ -611,16 +635,18 @@ TEST_CASE("UBJSON") CAPTURE(i) // create JSON value with unsigned integer number - json j = i; + json const j = i; // check type CHECK(j.is_number_unsigned()); // create expected byte vector - std::vector expected; - expected.push_back('I'); - expected.push_back(static_cast((i >> 8) & 0xff)); - expected.push_back(static_cast(i & 0xff)); + std::vector const expected + { + 'I', + static_cast((i >> 8) & 0xff), + static_cast(i & 0xff), + }; // compare result + size const auto result = json::to_ubjson(j); @@ -629,7 +655,7 @@ TEST_CASE("UBJSON") // check individual bytes CHECK(result[0] == 'I'); - auto restored = static_cast(static_cast(result[1]) * 256 + static_cast(result[2])); + auto const restored = static_cast(static_cast(result[1]) * 256 + static_cast(result[2])); CHECK(restored == i); // roundtrip @@ -648,18 +674,20 @@ TEST_CASE("UBJSON") CAPTURE(i) // create JSON value with unsigned integer number - json j = i; + json const j = i; // check type CHECK(j.is_number_unsigned()); // create expected byte vector - std::vector expected; - expected.push_back('l'); - expected.push_back(static_cast((i >> 24) & 0xff)); - expected.push_back(static_cast((i >> 16) & 0xff)); - expected.push_back(static_cast((i >> 8) & 0xff)); - expected.push_back(static_cast(i & 0xff)); + std::vector const expected + { + 'l', + static_cast((i >> 24) & 0xff), + static_cast((i >> 16) & 0xff), + static_cast((i >> 8) & 0xff), + static_cast(i & 0xff), + }; // compare result + size const auto result = json::to_ubjson(j); @@ -668,10 +696,10 @@ TEST_CASE("UBJSON") // check individual bytes CHECK(result[0] == 'l'); - uint32_t restored = (static_cast(result[1]) << 030) + - (static_cast(result[2]) << 020) + - (static_cast(result[3]) << 010) + - static_cast(result[4]); + uint32_t const restored = (static_cast(result[1]) << 030) + + (static_cast(result[2]) << 020) + + (static_cast(result[3]) << 010) + + static_cast(result[4]); CHECK(restored == i); // roundtrip @@ -682,28 +710,30 @@ TEST_CASE("UBJSON") SECTION("2147483648..9223372036854775807 (int64)") { - std::vector v = {2147483648ul, 9223372036854775807ul}; + std::vector const v = {2147483648ul, 9223372036854775807ul}; for (uint64_t i : v) { CAPTURE(i) // create JSON value with integer number - json j = i; + json const j = i; // check type CHECK(j.is_number_unsigned()); // create expected byte vector - std::vector expected; - expected.push_back('L'); - expected.push_back(static_cast((i >> 070) & 0xff)); - expected.push_back(static_cast((i >> 060) & 0xff)); - expected.push_back(static_cast((i >> 050) & 0xff)); - expected.push_back(static_cast((i >> 040) & 0xff)); - expected.push_back(static_cast((i >> 030) & 0xff)); - expected.push_back(static_cast((i >> 020) & 0xff)); - expected.push_back(static_cast((i >> 010) & 0xff)); - expected.push_back(static_cast(i & 0xff)); + std::vector const expected + { + 'L', + static_cast((i >> 070) & 0xff), + static_cast((i >> 060) & 0xff), + static_cast((i >> 050) & 0xff), + static_cast((i >> 040) & 0xff), + static_cast((i >> 030) & 0xff), + static_cast((i >> 020) & 0xff), + static_cast((i >> 010) & 0xff), + static_cast(i & 0xff), + }; // compare result + size const auto result = json::to_ubjson(j); @@ -712,14 +742,14 @@ TEST_CASE("UBJSON") // check individual bytes CHECK(result[0] == 'L'); - uint64_t restored = (static_cast(result[1]) << 070) + - (static_cast(result[2]) << 060) + - (static_cast(result[3]) << 050) + - (static_cast(result[4]) << 040) + - (static_cast(result[5]) << 030) + - (static_cast(result[6]) << 020) + - (static_cast(result[7]) << 010) + - static_cast(result[8]); + uint64_t const restored = (static_cast(result[1]) << 070) + + (static_cast(result[2]) << 060) + + (static_cast(result[3]) << 050) + + (static_cast(result[4]) << 040) + + (static_cast(result[5]) << 030) + + (static_cast(result[6]) << 020) + + (static_cast(result[7]) << 010) + + static_cast(result[8]); CHECK(restored == i); // roundtrip @@ -734,7 +764,7 @@ TEST_CASE("UBJSON") SECTION("3.1415925") { double v = 3.1415925; - json j = v; + json const j = v; std::vector expected = { 'D', 0x40, 0x09, 0x21, 0xfb, 0x3f, 0xa6, 0xde, 0xfc @@ -753,7 +783,7 @@ TEST_CASE("UBJSON") { SECTION("unsigned integer number") { - std::vector vec = {'H', 'i', 0x14, '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0'}; + std::vector const vec = {'H', 'i', 0x14, '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0'}; const auto j = json::from_ubjson(vec); CHECK(j.is_number_unsigned()); CHECK(j.dump() == "12345678901234567890"); @@ -761,7 +791,7 @@ TEST_CASE("UBJSON") SECTION("signed integer number") { - std::vector vec = {'H', 'i', 0x13, '-', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '1', '2', '3', '4', '5', '6', '7', '8'}; + std::vector const vec = {'H', 'i', 0x13, '-', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '1', '2', '3', '4', '5', '6', '7', '8'}; const auto j = json::from_ubjson(vec); CHECK(j.is_number_integer()); CHECK(j.dump() == "-123456789012345678"); @@ -769,7 +799,7 @@ TEST_CASE("UBJSON") SECTION("floating-point number") { - std::vector vec = {'H', 'i', 0x16, '3', '.', '1', '4', '1', '5', '9', '2', '6', '5', '3', '5', '8', '9', '7', '9', '3', '2', '3', '8', '4', '6'}; + std::vector const vec = {'H', 'i', 0x16, '3', '.', '1', '4', '1', '5', '9', '2', '6', '5', '3', '5', '8', '9', '7', '9', '3', '2', '3', '8', '4', '6'}; const auto j = json::from_ubjson(vec); CHECK(j.is_number_float()); CHECK(j.dump() == "3.141592653589793"); @@ -778,25 +808,25 @@ TEST_CASE("UBJSON") SECTION("errors") { // error while parsing length - std::vector vec0 = {'H', 'i'}; + std::vector const vec0 = {'H', 'i'}; CHECK(json::from_ubjson(vec0, true, false).is_discarded()); // error while parsing string - std::vector vec1 = {'H', 'i', '1'}; + std::vector const vec1 = {'H', 'i', '1'}; CHECK(json::from_ubjson(vec1, true, false).is_discarded()); json _; - std::vector vec2 = {'H', 'i', 2, '1', 'A', '3'}; + std::vector const vec2 = {'H', 'i', 2, '1', 'A', '3'}; CHECK_THROWS_WITH_AS(_ = json::from_ubjson(vec2), "[json.exception.parse_error.115] parse error at byte 5: syntax error while parsing UBJSON high-precision number: invalid number text: 1A", json::parse_error); - std::vector vec3 = {'H', 'i', 2, '1', '.'}; + std::vector const vec3 = {'H', 'i', 2, '1', '.'}; CHECK_THROWS_WITH_AS(_ = json::from_ubjson(vec3), "[json.exception.parse_error.115] parse error at byte 5: syntax error while parsing UBJSON high-precision number: invalid number text: 1.", json::parse_error); - std::vector vec4 = {'H', 2, '1', '0'}; + std::vector const vec4 = {'H', 2, '1', '0'}; CHECK_THROWS_WITH_AS(_ = json::from_ubjson(vec4), "[json.exception.parse_error.113] parse error at byte 2: syntax error while parsing UBJSON size: expected length type specification (U, i, I, l, L) after '#'; last byte: 0x02", json::parse_error); } SECTION("serialization") { // number that does not fit int64 - json j = 11111111111111111111ULL; + json const j = 11111111111111111111ULL; CHECK(j.is_number_unsigned()); // number will be serialized to high-precision number @@ -820,7 +850,7 @@ TEST_CASE("UBJSON") // create JSON value with string containing of N * 'x' const auto s = std::string(N, 'x'); - json j = s; + json const j = s; // create expected byte vector std::vector expected; @@ -856,7 +886,7 @@ TEST_CASE("UBJSON") // create JSON value with string containing of N * 'x' const auto s = std::string(N, 'x'); - json j = s; + json const j = s; // create expected byte vector std::vector expected; @@ -892,7 +922,7 @@ TEST_CASE("UBJSON") // create JSON value with string containing of N * 'x' const auto s = std::string(N, 'x'); - json j = s; + json const j = s; // create expected byte vector (hack: create string first) std::vector expected(N, 'x'); @@ -926,7 +956,7 @@ TEST_CASE("UBJSON") // create JSON value with string containing of N * 'x' const auto s = std::string(N, 'x'); - json j = s; + json const j = s; // create expected byte vector (hack: create string first) std::vector expected(N, 'x'); @@ -962,7 +992,7 @@ TEST_CASE("UBJSON") // create JSON value with byte array containing of N * 'x' const auto s = std::vector(N, 'x'); - json j = json::binary(s); + json const j = json::binary(s); // create expected byte vector std::vector expected; @@ -1013,7 +1043,7 @@ TEST_CASE("UBJSON") // create JSON value with byte array containing of N * 'x' const auto s = std::vector(N, 'x'); - json j = json::binary(s); + json const j = json::binary(s); // create expected byte vector std::vector expected; @@ -1053,7 +1083,7 @@ TEST_CASE("UBJSON") // create JSON value with byte array containing of N * 'x' const auto s = std::vector(N, 'x'); - json j = json::binary(s); + json const j = json::binary(s); // create expected byte vector std::vector expected(N + 7, 'x'); @@ -1090,7 +1120,7 @@ TEST_CASE("UBJSON") // create JSON value with byte array containing of N * 'x' const auto s = std::vector(N, 'x'); - json j = json::binary(s); + json const j = json::binary(s); // create expected byte vector std::vector expected(N + 9, 'x'); @@ -1122,7 +1152,7 @@ TEST_CASE("UBJSON") { const std::size_t N = 10; const auto s = std::vector(N, 'x'); - json j = json::binary(s); + json const j = json::binary(s); SECTION("No Count No Type") { @@ -1183,7 +1213,7 @@ TEST_CASE("UBJSON") { SECTION("size=false type=false") { - json j = json::array(); + json const j = json::array(); std::vector expected = {'[', ']'}; const auto result = json::to_ubjson(j); CHECK(result == expected); @@ -1195,7 +1225,7 @@ TEST_CASE("UBJSON") SECTION("size=true type=false") { - json j = json::array(); + json const j = json::array(); std::vector expected = {'[', '#', 'i', 0}; const auto result = json::to_ubjson(j, true); CHECK(result == expected); @@ -1207,7 +1237,7 @@ TEST_CASE("UBJSON") SECTION("size=true type=true") { - json j = json::array(); + json const j = json::array(); std::vector expected = {'[', '#', 'i', 0}; const auto result = json::to_ubjson(j, true, true); CHECK(result == expected); @@ -1222,7 +1252,7 @@ TEST_CASE("UBJSON") { SECTION("size=false type=false") { - json j = {nullptr}; + json const j = {nullptr}; std::vector expected = {'[', 'Z', ']'}; const auto result = json::to_ubjson(j); CHECK(result == expected); @@ -1234,7 +1264,7 @@ TEST_CASE("UBJSON") SECTION("size=true type=false") { - json j = {nullptr}; + json const j = {nullptr}; std::vector expected = {'[', '#', 'i', 1, 'Z'}; const auto result = json::to_ubjson(j, true); CHECK(result == expected); @@ -1246,7 +1276,7 @@ TEST_CASE("UBJSON") SECTION("size=true type=true") { - json j = {nullptr}; + json const j = {nullptr}; std::vector expected = {'[', '$', 'Z', '#', 'i', 1}; const auto result = json::to_ubjson(j, true, true); CHECK(result == expected); @@ -1261,7 +1291,7 @@ TEST_CASE("UBJSON") { SECTION("size=false type=false") { - json j = json::parse("[1,2,3,4,5]"); + json const j = json::parse("[1,2,3,4,5]"); std::vector expected = {'[', 'i', 1, 'i', 2, 'i', 3, 'i', 4, 'i', 5, ']'}; const auto result = json::to_ubjson(j); CHECK(result == expected); @@ -1273,7 +1303,7 @@ TEST_CASE("UBJSON") SECTION("size=true type=false") { - json j = json::parse("[1,2,3,4,5]"); + json const j = json::parse("[1,2,3,4,5]"); std::vector expected = {'[', '#', 'i', 5, 'i', 1, 'i', 2, 'i', 3, 'i', 4, 'i', 5}; const auto result = json::to_ubjson(j, true); CHECK(result == expected); @@ -1285,7 +1315,7 @@ TEST_CASE("UBJSON") SECTION("size=true type=true") { - json j = json::parse("[1,2,3,4,5]"); + json const j = json::parse("[1,2,3,4,5]"); std::vector expected = {'[', '$', 'i', '#', 'i', 5, 1, 2, 3, 4, 5}; const auto result = json::to_ubjson(j, true, true); CHECK(result == expected); @@ -1300,7 +1330,7 @@ TEST_CASE("UBJSON") { SECTION("size=false type=false") { - json j = json::parse("[[[[]]]]"); + json const j = json::parse("[[[[]]]]"); std::vector expected = {'[', '[', '[', '[', ']', ']', ']', ']'}; const auto result = json::to_ubjson(j); CHECK(result == expected); @@ -1312,7 +1342,7 @@ TEST_CASE("UBJSON") SECTION("size=true type=false") { - json j = json::parse("[[[[]]]]"); + json const j = json::parse("[[[[]]]]"); std::vector expected = {'[', '#', 'i', 1, '[', '#', 'i', 1, '[', '#', 'i', 1, '[', '#', 'i', 0}; const auto result = json::to_ubjson(j, true); CHECK(result == expected); @@ -1324,7 +1354,7 @@ TEST_CASE("UBJSON") SECTION("size=true type=true") { - json j = json::parse("[[[[]]]]"); + json const j = json::parse("[[[[]]]]"); std::vector expected = {'[', '$', '[', '#', 'i', 1, '$', '[', '#', 'i', 1, '$', '[', '#', 'i', 1, '#', 'i', 0}; const auto result = json::to_ubjson(j, true, true); CHECK(result == expected); @@ -1436,7 +1466,7 @@ TEST_CASE("UBJSON") { SECTION("size=false type=false") { - json j = json::object(); + json const j = json::object(); std::vector expected = {'{', '}'}; const auto result = json::to_ubjson(j); CHECK(result == expected); @@ -1448,7 +1478,7 @@ TEST_CASE("UBJSON") SECTION("size=true type=false") { - json j = json::object(); + json const j = json::object(); std::vector expected = {'{', '#', 'i', 0}; const auto result = json::to_ubjson(j, true); CHECK(result == expected); @@ -1460,7 +1490,7 @@ TEST_CASE("UBJSON") SECTION("size=true type=true") { - json j = json::object(); + json const j = json::object(); std::vector expected = {'{', '#', 'i', 0}; const auto result = json::to_ubjson(j, true, true); CHECK(result == expected); @@ -1475,7 +1505,7 @@ TEST_CASE("UBJSON") { SECTION("size=false type=false") { - json j = {{"", nullptr}}; + json const j = {{"", nullptr}}; std::vector expected = {'{', 'i', 0, 'Z', '}'}; const auto result = json::to_ubjson(j); CHECK(result == expected); @@ -1487,7 +1517,7 @@ TEST_CASE("UBJSON") SECTION("size=true type=false") { - json j = {{"", nullptr}}; + json const j = {{"", nullptr}}; std::vector expected = {'{', '#', 'i', 1, 'i', 0, 'Z'}; const auto result = json::to_ubjson(j, true); CHECK(result == expected); @@ -1499,7 +1529,7 @@ TEST_CASE("UBJSON") SECTION("size=true type=true") { - json j = {{"", nullptr}}; + json const j = {{"", nullptr}}; std::vector expected = {'{', '$', 'Z', '#', 'i', 1, 'i', 0}; const auto result = json::to_ubjson(j, true, true); CHECK(result == expected); @@ -1514,7 +1544,7 @@ TEST_CASE("UBJSON") { SECTION("size=false type=false") { - json j = json::parse(R"({"a": {"b": {"c": {}}}})"); + json const j = json::parse(R"({"a": {"b": {"c": {}}}})"); std::vector expected = { '{', 'i', 1, 'a', '{', 'i', 1, 'b', '{', 'i', 1, 'c', '{', '}', '}', '}', '}' @@ -1529,7 +1559,7 @@ TEST_CASE("UBJSON") SECTION("size=true type=false") { - json j = json::parse(R"({"a": {"b": {"c": {}}}})"); + json const j = json::parse(R"({"a": {"b": {"c": {}}}})"); std::vector expected = { '{', '#', 'i', 1, 'i', 1, 'a', '{', '#', 'i', 1, 'i', 1, 'b', '{', '#', 'i', 1, 'i', 1, 'c', '{', '#', 'i', 0 @@ -1544,7 +1574,7 @@ TEST_CASE("UBJSON") SECTION("size=true type=true") { - json j = json::parse(R"({"a": {"b": {"c": {}}}})"); + json const j = json::parse(R"({"a": {"b": {"c": {}}}})"); std::vector expected = { '{', '$', '{', '#', 'i', 1, 'i', 1, 'a', '$', '{', '#', 'i', 1, 'i', 1, 'b', '$', '{', '#', 'i', 1, 'i', 1, 'c', '#', 'i', 0 @@ -1564,7 +1594,7 @@ TEST_CASE("UBJSON") { SECTION("strict mode") { - std::vector vec = {'Z', 'Z'}; + std::vector const vec = {'Z', 'Z'}; SECTION("non-strict mode") { const auto result = json::from_ubjson(vec, false); @@ -1582,7 +1612,7 @@ TEST_CASE("UBJSON") { SECTION("array") { - std::vector v_ubjson = {'[', '$', 'Z', '#', 'L', 0x78, 0x28, 0x00, 0x68, 0x28, 0x69, 0x69, 0x17}; + std::vector const v_ubjson = {'[', '$', 'Z', '#', 'L', 0x78, 0x28, 0x00, 0x68, 0x28, 0x69, 0x69, 0x17}; json _; CHECK_THROWS_AS(_ = json::from_ubjson(v_ubjson), json::out_of_range&); @@ -1596,7 +1626,7 @@ TEST_CASE("UBJSON") SECTION("object") { - std::vector v_ubjson = {'{', '$', 'Z', '#', 'L', 0x78, 0x28, 0x00, 0x68, 0x28, 0x69, 0x69, 0x17}; + std::vector const v_ubjson = {'{', '$', 'Z', '#', 'L', 0x78, 0x28, 0x00, 0x68, 0x28, 0x69, 0x69, 0x17}; json _; CHECK_THROWS_AS(_ = json::from_ubjson(v_ubjson), json::out_of_range&); @@ -1614,42 +1644,42 @@ TEST_CASE("UBJSON") { SECTION("start_array()") { - std::vector v = {'[', 'T', 'F', ']'}; + std::vector const v = {'[', 'T', 'F', ']'}; SaxCountdown scp(0); CHECK(!json::sax_parse(v, &scp, json::input_format_t::ubjson)); } SECTION("start_object()") { - std::vector v = {'{', 'i', 3, 'f', 'o', 'o', 'F', '}'}; + std::vector const v = {'{', 'i', 3, 'f', 'o', 'o', 'F', '}'}; SaxCountdown scp(0); CHECK(!json::sax_parse(v, &scp, json::input_format_t::ubjson)); } SECTION("key() in object") { - std::vector v = {'{', 'i', 3, 'f', 'o', 'o', 'F', '}'}; + std::vector const v = {'{', 'i', 3, 'f', 'o', 'o', 'F', '}'}; SaxCountdown scp(1); CHECK(!json::sax_parse(v, &scp, json::input_format_t::ubjson)); } SECTION("start_array(len)") { - std::vector v = {'[', '#', 'i', '2', 'T', 'F'}; + std::vector const v = {'[', '#', 'i', '2', 'T', 'F'}; SaxCountdown scp(0); CHECK(!json::sax_parse(v, &scp, json::input_format_t::ubjson)); } SECTION("start_object(len)") { - std::vector v = {'{', '#', 'i', '1', 3, 'f', 'o', 'o', 'F'}; + std::vector const v = {'{', '#', 'i', '1', 3, 'f', 'o', 'o', 'F'}; SaxCountdown scp(0); CHECK(!json::sax_parse(v, &scp, json::input_format_t::ubjson)); } SECTION("key() in object with length") { - std::vector v = {'{', 'i', 3, 'f', 'o', 'o', 'F', '}'}; + std::vector const v = {'{', 'i', 3, 'f', 'o', 'o', 'F', '}'}; SaxCountdown scp(1); CHECK(!json::sax_parse(v, &scp, json::input_format_t::ubjson)); } @@ -1661,10 +1691,10 @@ TEST_CASE("UBJSON") { // create a single-character string for all number types std::vector s_i = {'S', 'i', 1, 'a'}; - std::vector s_U = {'S', 'U', 1, 'a'}; - std::vector s_I = {'S', 'I', 0, 1, 'a'}; - std::vector s_l = {'S', 'l', 0, 0, 0, 1, 'a'}; - std::vector s_L = {'S', 'L', 0, 0, 0, 0, 0, 0, 0, 1, 'a'}; + std::vector const s_U = {'S', 'U', 1, 'a'}; + std::vector const s_I = {'S', 'I', 0, 1, 'a'}; + std::vector const s_l = {'S', 'l', 0, 0, 0, 1, 'a'}; + std::vector const s_L = {'S', 'L', 0, 0, 0, 0, 0, 0, 0, 1, 'a'}; // check if string is parsed correctly to "a" CHECK(json::from_ubjson(s_i) == "a"); @@ -1686,11 +1716,11 @@ TEST_CASE("UBJSON") SECTION("float") { // float32 - std::vector v_d = {'d', 0x40, 0x49, 0x0f, 0xd0}; + std::vector const v_d = {'d', 0x40, 0x49, 0x0f, 0xd0}; CHECK(json::from_ubjson(v_d) == 3.14159f); // float64 - std::vector v_D = {'D', 0x40, 0x09, 0x21, 0xf9, 0xf0, 0x1b, 0x86, 0x6e}; + std::vector const v_D = {'D', 0x40, 0x09, 0x21, 0xf9, 0xf0, 0x1b, 0x86, 0x6e}; CHECK(json::from_ubjson(v_D) == 3.14159); // float32 is serialized as float64 as the library does not support float32 @@ -1703,18 +1733,18 @@ TEST_CASE("UBJSON") SECTION("optimized version (length only)") { // create vector with two elements of the same type - std::vector v_TU = {'[', '#', 'U', 2, 'T', 'T'}; - std::vector v_T = {'[', '#', 'i', 2, 'T', 'T'}; - std::vector v_F = {'[', '#', 'i', 2, 'F', 'F'}; - std::vector v_Z = {'[', '#', 'i', 2, 'Z', 'Z'}; - std::vector v_i = {'[', '#', 'i', 2, 'i', 0x7F, 'i', 0x7F}; - std::vector v_U = {'[', '#', 'i', 2, 'U', 0xFF, 'U', 0xFF}; - std::vector v_I = {'[', '#', 'i', 2, 'I', 0x7F, 0xFF, 'I', 0x7F, 0xFF}; - std::vector v_l = {'[', '#', 'i', 2, 'l', 0x7F, 0xFF, 0xFF, 0xFF, 'l', 0x7F, 0xFF, 0xFF, 0xFF}; - std::vector v_L = {'[', '#', 'i', 2, 'L', 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 'L', 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; - std::vector v_D = {'[', '#', 'i', 2, 'D', 0x40, 0x09, 0x21, 0xfb, 0x4d, 0x12, 0xd8, 0x4a, 'D', 0x40, 0x09, 0x21, 0xfb, 0x4d, 0x12, 0xd8, 0x4a}; - std::vector v_S = {'[', '#', 'i', 2, 'S', 'i', 1, 'a', 'S', 'i', 1, 'a'}; - std::vector v_C = {'[', '#', 'i', 2, 'C', 'a', 'C', 'a'}; + std::vector const v_TU = {'[', '#', 'U', 2, 'T', 'T'}; + std::vector const v_T = {'[', '#', 'i', 2, 'T', 'T'}; + std::vector const v_F = {'[', '#', 'i', 2, 'F', 'F'}; + std::vector const v_Z = {'[', '#', 'i', 2, 'Z', 'Z'}; + std::vector const v_i = {'[', '#', 'i', 2, 'i', 0x7F, 'i', 0x7F}; + std::vector const v_U = {'[', '#', 'i', 2, 'U', 0xFF, 'U', 0xFF}; + std::vector const v_I = {'[', '#', 'i', 2, 'I', 0x7F, 0xFF, 'I', 0x7F, 0xFF}; + std::vector const v_l = {'[', '#', 'i', 2, 'l', 0x7F, 0xFF, 0xFF, 0xFF, 'l', 0x7F, 0xFF, 0xFF, 0xFF}; + std::vector const v_L = {'[', '#', 'i', 2, 'L', 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 'L', 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; + std::vector const v_D = {'[', '#', 'i', 2, 'D', 0x40, 0x09, 0x21, 0xfb, 0x4d, 0x12, 0xd8, 0x4a, 'D', 0x40, 0x09, 0x21, 0xfb, 0x4d, 0x12, 0xd8, 0x4a}; + std::vector const v_S = {'[', '#', 'i', 2, 'S', 'i', 1, 'a', 'S', 'i', 1, 'a'}; + std::vector const v_C = {'[', '#', 'i', 2, 'C', 'a', 'C', 'a'}; // check if vector is parsed correctly CHECK(json::from_ubjson(v_TU) == json({true, true})); @@ -1747,18 +1777,18 @@ TEST_CASE("UBJSON") SECTION("optimized version (type and length)") { // create vector with two elements of the same type - std::vector v_N = {'[', '$', 'N', '#', 'i', 2}; - std::vector v_T = {'[', '$', 'T', '#', 'i', 2}; - std::vector v_F = {'[', '$', 'F', '#', 'i', 2}; - std::vector v_Z = {'[', '$', 'Z', '#', 'i', 2}; - std::vector v_i = {'[', '$', 'i', '#', 'i', 2, 0x7F, 0x7F}; - std::vector v_U = {'[', '$', 'U', '#', 'i', 2, 0xFF, 0xFF}; - std::vector v_I = {'[', '$', 'I', '#', 'i', 2, 0x7F, 0xFF, 0x7F, 0xFF}; - std::vector v_l = {'[', '$', 'l', '#', 'i', 2, 0x7F, 0xFF, 0xFF, 0xFF, 0x7F, 0xFF, 0xFF, 0xFF}; - std::vector v_L = {'[', '$', 'L', '#', 'i', 2, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; - std::vector v_D = {'[', '$', 'D', '#', 'i', 2, 0x40, 0x09, 0x21, 0xfb, 0x4d, 0x12, 0xd8, 0x4a, 0x40, 0x09, 0x21, 0xfb, 0x4d, 0x12, 0xd8, 0x4a}; - std::vector v_S = {'[', '$', 'S', '#', 'i', 2, 'i', 1, 'a', 'i', 1, 'a'}; - std::vector v_C = {'[', '$', 'C', '#', 'i', 2, 'a', 'a'}; + std::vector const v_N = {'[', '$', 'N', '#', 'i', 2}; + std::vector const v_T = {'[', '$', 'T', '#', 'i', 2}; + std::vector const v_F = {'[', '$', 'F', '#', 'i', 2}; + std::vector const v_Z = {'[', '$', 'Z', '#', 'i', 2}; + std::vector const v_i = {'[', '$', 'i', '#', 'i', 2, 0x7F, 0x7F}; + std::vector const v_U = {'[', '$', 'U', '#', 'i', 2, 0xFF, 0xFF}; + std::vector const v_I = {'[', '$', 'I', '#', 'i', 2, 0x7F, 0xFF, 0x7F, 0xFF}; + std::vector const v_l = {'[', '$', 'l', '#', 'i', 2, 0x7F, 0xFF, 0xFF, 0xFF, 0x7F, 0xFF, 0xFF, 0xFF}; + std::vector const v_L = {'[', '$', 'L', '#', 'i', 2, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; + std::vector const v_D = {'[', '$', 'D', '#', 'i', 2, 0x40, 0x09, 0x21, 0xfb, 0x4d, 0x12, 0xd8, 0x4a, 0x40, 0x09, 0x21, 0xfb, 0x4d, 0x12, 0xd8, 0x4a}; + std::vector const v_S = {'[', '$', 'S', '#', 'i', 2, 'i', 1, 'a', 'i', 1, 'a'}; + std::vector const v_C = {'[', '$', 'C', '#', 'i', 2, 'a', 'a'}; // check if vector is parsed correctly CHECK(json::from_ubjson(v_N) == json::array()); @@ -1775,7 +1805,7 @@ TEST_CASE("UBJSON") CHECK(json::from_ubjson(v_C) == json({"a", "a"})); // roundtrip: output should be optimized - std::vector v_empty = {'[', '#', 'i', 0}; + std::vector const v_empty = {'[', '#', 'i', 0}; CHECK(json::to_ubjson(json::from_ubjson(v_N), true, true) == v_empty); CHECK(json::to_ubjson(json::from_ubjson(v_T), true, true) == v_T); CHECK(json::to_ubjson(json::from_ubjson(v_F), true, true) == v_F); @@ -1804,14 +1834,14 @@ TEST_CASE("UBJSON") { SECTION("eof after C byte") { - std::vector v = {'C'}; + std::vector const v = {'C'}; json _; CHECK_THROWS_WITH_AS(_ = json::from_ubjson(v), "[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing UBJSON char: unexpected end of input", json::parse_error&); } SECTION("byte out of range") { - std::vector v = {'C', 130}; + std::vector const v = {'C', 130}; json _; CHECK_THROWS_WITH_AS(_ = json::from_ubjson(v), "[json.exception.parse_error.113] parse error at byte 2: syntax error while parsing UBJSON char: byte after 'C' must be in range 0x00..0x7F; last byte: 0x82", json::parse_error&); } @@ -1821,14 +1851,14 @@ TEST_CASE("UBJSON") { SECTION("eof after S byte") { - std::vector v = {'S'}; + std::vector const v = {'S'}; json _; CHECK_THROWS_WITH_AS(_ = json::from_ubjson(v), "[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing UBJSON value: unexpected end of input", json::parse_error&); } SECTION("invalid byte") { - std::vector v = {'S', '1', 'a'}; + std::vector const v = {'S', '1', 'a'}; json _; CHECK_THROWS_WITH_AS(_ = json::from_ubjson(v), "[json.exception.parse_error.113] parse error at byte 2: syntax error while parsing UBJSON string: expected length type specification (U, i, I, l, L); last byte: 0x31", json::parse_error&); } @@ -1838,7 +1868,7 @@ TEST_CASE("UBJSON") { SECTION("optimized array: no size following type") { - std::vector v = {'[', '$', 'i', 2}; + std::vector const v = {'[', '$', 'i', 2}; json _; CHECK_THROWS_WITH_AS(_ = json::from_ubjson(v), "[json.exception.parse_error.112] parse error at byte 4: syntax error while parsing UBJSON size: expected '#' after type information; last byte: 0x02", json::parse_error&); } @@ -1846,112 +1876,112 @@ TEST_CASE("UBJSON") SECTION("strings") { - std::vector vS = {'S'}; + std::vector const vS = {'S'}; json _; CHECK_THROWS_WITH_AS(_ = json::from_ubjson(vS), "[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing UBJSON value: unexpected end of input", json::parse_error&); CHECK(json::from_ubjson(vS, true, false).is_discarded()); - std::vector v = {'S', 'i', '2', 'a'}; + std::vector const v = {'S', 'i', '2', 'a'}; CHECK_THROWS_WITH_AS(_ = json::from_ubjson(v), "[json.exception.parse_error.110] parse error at byte 5: syntax error while parsing UBJSON string: unexpected end of input", json::parse_error&); CHECK(json::from_ubjson(v, true, false).is_discarded()); - std::vector vC = {'C'}; + std::vector const vC = {'C'}; CHECK_THROWS_WITH_AS(_ = json::from_ubjson(vC), "[json.exception.parse_error.110] parse error at byte 2: syntax error while parsing UBJSON char: unexpected end of input", json::parse_error&); CHECK(json::from_ubjson(vC, true, false).is_discarded()); } SECTION("sizes") { - std::vector vU = {'[', '#', 'U'}; + std::vector const vU = {'[', '#', 'U'}; json _; CHECK_THROWS_WITH_AS(_ = json::from_ubjson(vU), "[json.exception.parse_error.110] parse error at byte 4: syntax error while parsing UBJSON number: unexpected end of input", json::parse_error&); CHECK(json::from_ubjson(vU, true, false).is_discarded()); - std::vector vi = {'[', '#', 'i'}; + std::vector const vi = {'[', '#', 'i'}; CHECK_THROWS_WITH_AS(_ = json::from_ubjson(vi), "[json.exception.parse_error.110] parse error at byte 4: syntax error while parsing UBJSON number: unexpected end of input", json::parse_error&); CHECK(json::from_ubjson(vi, true, false).is_discarded()); - std::vector vI = {'[', '#', 'I'}; + std::vector const vI = {'[', '#', 'I'}; CHECK_THROWS_WITH_AS(_ = json::from_ubjson(vI), "[json.exception.parse_error.110] parse error at byte 4: syntax error while parsing UBJSON number: unexpected end of input", json::parse_error&); CHECK(json::from_ubjson(vI, true, false).is_discarded()); - std::vector vl = {'[', '#', 'l'}; + std::vector const vl = {'[', '#', 'l'}; CHECK_THROWS_WITH_AS(_ = json::from_ubjson(vl), "[json.exception.parse_error.110] parse error at byte 4: syntax error while parsing UBJSON number: unexpected end of input", json::parse_error&); CHECK(json::from_ubjson(vl, true, false).is_discarded()); - std::vector vL = {'[', '#', 'L'}; + std::vector const vL = {'[', '#', 'L'}; CHECK_THROWS_WITH_AS(_ = json::from_ubjson(vL), "[json.exception.parse_error.110] parse error at byte 4: syntax error while parsing UBJSON number: unexpected end of input", json::parse_error&); CHECK(json::from_ubjson(vL, true, false).is_discarded()); - std::vector v0 = {'[', '#', 'T', ']'}; + std::vector const v0 = {'[', '#', 'T', ']'}; CHECK_THROWS_WITH_AS(_ = json::from_ubjson(v0), "[json.exception.parse_error.113] parse error at byte 3: syntax error while parsing UBJSON size: expected length type specification (U, i, I, l, L) after '#'; last byte: 0x54", json::parse_error&); CHECK(json::from_ubjson(v0, true, false).is_discarded()); } SECTION("types") { - std::vector v0 = {'[', '$'}; + std::vector const v0 = {'[', '$'}; json _; CHECK_THROWS_WITH_AS(_ = json::from_ubjson(v0), "[json.exception.parse_error.110] parse error at byte 3: syntax error while parsing UBJSON type: unexpected end of input", json::parse_error&); CHECK(json::from_ubjson(v0, true, false).is_discarded()); - std::vector vi = {'[', '$', '#'}; + std::vector const vi = {'[', '$', '#'}; CHECK_THROWS_WITH_AS(_ = json::from_ubjson(vi), "[json.exception.parse_error.110] parse error at byte 4: syntax error while parsing UBJSON value: unexpected end of input", json::parse_error&); CHECK(json::from_ubjson(vi, true, false).is_discarded()); - std::vector vT = {'[', '$', 'T'}; + std::vector const vT = {'[', '$', 'T'}; CHECK_THROWS_WITH_AS(_ = json::from_ubjson(vT), "[json.exception.parse_error.110] parse error at byte 4: syntax error while parsing UBJSON value: unexpected end of input", json::parse_error&); CHECK(json::from_ubjson(vT, true, false).is_discarded()); } SECTION("arrays") { - std::vector vST = {'[', '$', 'i', '#', 'i', 2, 1}; + std::vector const vST = {'[', '$', 'i', '#', 'i', 2, 1}; json _; CHECK_THROWS_WITH_AS(_ = json::from_ubjson(vST), "[json.exception.parse_error.110] parse error at byte 8: syntax error while parsing UBJSON number: unexpected end of input", json::parse_error&); CHECK(json::from_ubjson(vST, true, false).is_discarded()); - std::vector vS = {'[', '#', 'i', 2, 'i', 1}; + std::vector const vS = {'[', '#', 'i', 2, 'i', 1}; CHECK_THROWS_WITH_AS(_ = json::from_ubjson(vS), "[json.exception.parse_error.110] parse error at byte 7: syntax error while parsing UBJSON value: unexpected end of input", json::parse_error&); CHECK(json::from_ubjson(vS, true, false).is_discarded()); - std::vector v = {'[', 'i', 2, 'i', 1}; + std::vector const v = {'[', 'i', 2, 'i', 1}; CHECK_THROWS_WITH_AS(_ = json::from_ubjson(v), "[json.exception.parse_error.110] parse error at byte 6: syntax error while parsing UBJSON value: unexpected end of input", json::parse_error&); CHECK(json::from_ubjson(v, true, false).is_discarded()); } SECTION("objects") { - std::vector vST = {'{', '$', 'i', '#', 'i', 2, 'i', 1, 'a', 1}; + std::vector const vST = {'{', '$', 'i', '#', 'i', 2, 'i', 1, 'a', 1}; json _; CHECK_THROWS_WITH_AS(_ = json::from_ubjson(vST), "[json.exception.parse_error.110] parse error at byte 11: syntax error while parsing UBJSON value: unexpected end of input", json::parse_error&); CHECK(json::from_ubjson(vST, true, false).is_discarded()); - std::vector vT = {'{', '$', 'i', 'i', 1, 'a', 1}; + std::vector const vT = {'{', '$', 'i', 'i', 1, 'a', 1}; CHECK_THROWS_WITH_AS(_ = json::from_ubjson(vT), "[json.exception.parse_error.112] parse error at byte 4: syntax error while parsing UBJSON size: expected '#' after type information; last byte: 0x69", json::parse_error&); CHECK(json::from_ubjson(vT, true, false).is_discarded()); - std::vector vS = {'{', '#', 'i', 2, 'i', 1, 'a', 'i', 1}; + std::vector const vS = {'{', '#', 'i', 2, 'i', 1, 'a', 'i', 1}; CHECK_THROWS_WITH_AS(_ = json::from_ubjson(vS), "[json.exception.parse_error.110] parse error at byte 10: syntax error while parsing UBJSON value: unexpected end of input", json::parse_error&); CHECK(json::from_ubjson(vS, true, false).is_discarded()); - std::vector v = {'{', 'i', 1, 'a', 'i', 1}; + std::vector const v = {'{', 'i', 1, 'a', 'i', 1}; CHECK_THROWS_WITH_AS(_ = json::from_ubjson(v), "[json.exception.parse_error.110] parse error at byte 7: syntax error while parsing UBJSON value: unexpected end of input", json::parse_error&); CHECK(json::from_ubjson(v, true, false).is_discarded()); - std::vector v2 = {'{', 'i', 1, 'a', 'i', 1, 'i'}; + std::vector const v2 = {'{', 'i', 1, 'a', 'i', 1, 'i'}; CHECK_THROWS_WITH_AS(_ = json::from_ubjson(v2), "[json.exception.parse_error.110] parse error at byte 8: syntax error while parsing UBJSON number: unexpected end of input", json::parse_error&); CHECK(json::from_ubjson(v2, true, false).is_discarded()); - std::vector v3 = {'{', 'i', 1, 'a'}; + std::vector const v3 = {'{', 'i', 1, 'a'}; CHECK_THROWS_WITH_AS(_ = json::from_ubjson(v3), "[json.exception.parse_error.110] parse error at byte 5: syntax error while parsing UBJSON value: unexpected end of input", json::parse_error&); CHECK(json::from_ubjson(v3, true, false).is_discarded()); - std::vector vST1 = {'{', '$', 'd', '#', 'i', 2, 'i', 1, 'a'}; + std::vector const vST1 = {'{', '$', 'd', '#', 'i', 2, 'i', 1, 'a'}; CHECK_THROWS_WITH_AS(_ = json::from_ubjson(vST1), "[json.exception.parse_error.110] parse error at byte 10: syntax error while parsing UBJSON number: unexpected end of input", json::parse_error&); CHECK(json::from_ubjson(vST1, true, false).is_discarded()); - std::vector vST2 = {'{', '#', 'i', 2, 'i', 1, 'a'}; + std::vector const vST2 = {'{', '#', 'i', 2, 'i', 1, 'a'}; CHECK_THROWS_WITH_AS(_ = json::from_ubjson(vST2), "[json.exception.parse_error.110] parse error at byte 8: syntax error while parsing UBJSON value: unexpected end of input", json::parse_error&); CHECK(json::from_ubjson(vST2, true, false).is_discarded()); } @@ -1963,35 +1993,35 @@ TEST_CASE("UBJSON") { SECTION("array of i") { - json j = {1, -1}; + json const j = {1, -1}; std::vector expected = {'[', '$', 'i', '#', 'i', 2, 1, 0xff}; CHECK(json::to_ubjson(j, true, true) == expected); } SECTION("array of U") { - json j = {200, 201}; + json const j = {200, 201}; std::vector expected = {'[', '$', 'U', '#', 'i', 2, 0xC8, 0xC9}; CHECK(json::to_ubjson(j, true, true) == expected); } SECTION("array of I") { - json j = {30000, -30000}; + json const j = {30000, -30000}; std::vector expected = {'[', '$', 'I', '#', 'i', 2, 0x75, 0x30, 0x8a, 0xd0}; CHECK(json::to_ubjson(j, true, true) == expected); } SECTION("array of l") { - json j = {70000, -70000}; + json const j = {70000, -70000}; std::vector expected = {'[', '$', 'l', '#', 'i', 2, 0x00, 0x01, 0x11, 0x70, 0xFF, 0xFE, 0xEE, 0x90}; CHECK(json::to_ubjson(j, true, true) == expected); } SECTION("array of L") { - json j = {5000000000, -5000000000}; + json const j = {5000000000, -5000000000}; std::vector expected = {'[', '$', 'L', '#', 'i', 2, 0x00, 0x00, 0x00, 0x01, 0x2A, 0x05, 0xF2, 0x00, 0xFF, 0xFF, 0xFF, 0xFE, 0xD5, 0xFA, 0x0E, 0x00}; CHECK(json::to_ubjson(j, true, true) == expected); } @@ -2001,7 +2031,7 @@ TEST_CASE("UBJSON") { SECTION("array of i") { - json j = {1u, 2u}; + json const j = {1u, 2u}; std::vector expected = {'[', '$', 'i', '#', 'i', 2, 1, 2}; std::vector expected_size = {'[', '#', 'i', 2, 'i', 1, 'i', 2}; CHECK(json::to_ubjson(j, true, true) == expected); @@ -2010,7 +2040,7 @@ TEST_CASE("UBJSON") SECTION("array of U") { - json j = {200u, 201u}; + json const j = {200u, 201u}; std::vector expected = {'[', '$', 'U', '#', 'i', 2, 0xC8, 0xC9}; std::vector expected_size = {'[', '#', 'i', 2, 'U', 0xC8, 'U', 0xC9}; CHECK(json::to_ubjson(j, true, true) == expected); @@ -2019,7 +2049,7 @@ TEST_CASE("UBJSON") SECTION("array of I") { - json j = {30000u, 30001u}; + json const j = {30000u, 30001u}; std::vector expected = {'[', '$', 'I', '#', 'i', 2, 0x75, 0x30, 0x75, 0x31}; std::vector expected_size = {'[', '#', 'i', 2, 'I', 0x75, 0x30, 'I', 0x75, 0x31}; CHECK(json::to_ubjson(j, true, true) == expected); @@ -2028,7 +2058,7 @@ TEST_CASE("UBJSON") SECTION("array of l") { - json j = {70000u, 70001u}; + json const j = {70000u, 70001u}; std::vector expected = {'[', '$', 'l', '#', 'i', 2, 0x00, 0x01, 0x11, 0x70, 0x00, 0x01, 0x11, 0x71}; std::vector expected_size = {'[', '#', 'i', 2, 'l', 0x00, 0x01, 0x11, 0x70, 'l', 0x00, 0x01, 0x11, 0x71}; CHECK(json::to_ubjson(j, true, true) == expected); @@ -2037,7 +2067,7 @@ TEST_CASE("UBJSON") SECTION("array of L") { - json j = {5000000000u, 5000000001u}; + json const j = {5000000000u, 5000000001u}; std::vector expected = {'[', '$', 'L', '#', 'i', 2, 0x00, 0x00, 0x00, 0x01, 0x2A, 0x05, 0xF2, 0x00, 0x00, 0x00, 0x00, 0x01, 0x2A, 0x05, 0xF2, 0x01}; std::vector expected_size = {'[', '#', 'i', 2, 'L', 0x00, 0x00, 0x00, 0x01, 0x2A, 0x05, 0xF2, 0x00, 'L', 0x00, 0x00, 0x00, 0x01, 0x2A, 0x05, 0xF2, 0x01}; CHECK(json::to_ubjson(j, true, true) == expected); @@ -2047,7 +2077,7 @@ TEST_CASE("UBJSON") SECTION("discarded") { - json j = {json::value_t::discarded, json::value_t::discarded}; + json const j = {json::value_t::discarded, json::value_t::discarded}; std::vector expected = {'[', '$', 'N', '#', 'i', 2}; CHECK(json::to_ubjson(j, true, true) == expected); } @@ -2058,23 +2088,23 @@ TEST_CASE("Universal Binary JSON Specification Examples 1") { SECTION("Null Value") { - json j = {{"passcode", nullptr}}; - std::vector v = {'{', 'i', 8, 'p', 'a', 's', 's', 'c', 'o', 'd', 'e', 'Z', '}'}; + json const j = {{"passcode", nullptr}}; + std::vector const v = {'{', 'i', 8, 'p', 'a', 's', 's', 'c', 'o', 'd', 'e', 'Z', '}'}; CHECK(json::to_ubjson(j) == v); CHECK(json::from_ubjson(v) == j); } SECTION("No-Op Value") { - json j = {"foo", "bar", "baz"}; - std::vector v = {'[', 'S', 'i', 3, 'f', 'o', 'o', - 'S', 'i', 3, 'b', 'a', 'r', - 'S', 'i', 3, 'b', 'a', 'z', ']' - }; - std::vector v2 = {'[', 'S', 'i', 3, 'f', 'o', 'o', 'N', - 'S', 'i', 3, 'b', 'a', 'r', 'N', 'N', 'N', - 'S', 'i', 3, 'b', 'a', 'z', 'N', 'N', ']' - }; + json const j = {"foo", "bar", "baz"}; + std::vector const v = {'[', 'S', 'i', 3, 'f', 'o', 'o', + 'S', 'i', 3, 'b', 'a', 'r', + 'S', 'i', 3, 'b', 'a', 'z', ']' + }; + std::vector const v2 = {'[', 'S', 'i', 3, 'f', 'o', 'o', 'N', + 'S', 'i', 3, 'b', 'a', 'r', 'N', 'N', 'N', + 'S', 'i', 3, 'b', 'a', 'z', 'N', 'N', ']' + }; CHECK(json::to_ubjson(j) == v); CHECK(json::from_ubjson(v) == j); CHECK(json::from_ubjson(v2) == j); @@ -2082,17 +2112,17 @@ TEST_CASE("Universal Binary JSON Specification Examples 1") SECTION("Boolean Types") { - json j = {{"authorized", true}, {"verified", false}}; - std::vector v = {'{', 'i', 10, 'a', 'u', 't', 'h', 'o', 'r', 'i', 'z', 'e', 'd', 'T', - 'i', 8, 'v', 'e', 'r', 'i', 'f', 'i', 'e', 'd', 'F', '}' - }; + json const j = {{"authorized", true}, {"verified", false}}; + std::vector const v = {'{', 'i', 10, 'a', 'u', 't', 'h', 'o', 'r', 'i', 'z', 'e', 'd', 'T', + 'i', 8, 'v', 'e', 'r', 'i', 'f', 'i', 'e', 'd', 'F', '}' + }; CHECK(json::to_ubjson(j) == v); CHECK(json::from_ubjson(v) == j); } SECTION("Numeric Types") { - json j = + json const j = { {"int8", 16}, {"uint8", 255}, @@ -2101,23 +2131,23 @@ TEST_CASE("Universal Binary JSON Specification Examples 1") {"int64", 9223372036854775807}, {"float64", 113243.7863123} }; - std::vector v = {'{', - 'i', 7, 'f', 'l', 'o', 'a', 't', '6', '4', 'D', 0x40, 0xfb, 0xa5, 0xbc, 0x94, 0xbc, 0x34, 0xcf, - 'i', 5, 'i', 'n', 't', '1', '6', 'I', 0x7f, 0xff, - 'i', 5, 'i', 'n', 't', '3', '2', 'l', 0x7f, 0xff, 0xff, 0xff, - 'i', 5, 'i', 'n', 't', '6', '4', 'L', 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 'i', 4, 'i', 'n', 't', '8', 'i', 16, - 'i', 5, 'u', 'i', 'n', 't', '8', 'U', 0xff, - '}' - }; + std::vector const v = {'{', + 'i', 7, 'f', 'l', 'o', 'a', 't', '6', '4', 'D', 0x40, 0xfb, 0xa5, 0xbc, 0x94, 0xbc, 0x34, 0xcf, + 'i', 5, 'i', 'n', 't', '1', '6', 'I', 0x7f, 0xff, + 'i', 5, 'i', 'n', 't', '3', '2', 'l', 0x7f, 0xff, 0xff, 0xff, + 'i', 5, 'i', 'n', 't', '6', '4', 'L', 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 'i', 4, 'i', 'n', 't', '8', 'i', 16, + 'i', 5, 'u', 'i', 'n', 't', '8', 'U', 0xff, + '}' + }; CHECK(json::to_ubjson(j) == v); CHECK(json::from_ubjson(v) == j); } SECTION("Char Type") { - json j = {{"rolecode", "a"}, {"delim", ";"}}; - std::vector v = {'{', 'i', 5, 'd', 'e', 'l', 'i', 'm', 'C', ';', 'i', 8, 'r', 'o', 'l', 'e', 'c', 'o', 'd', 'e', 'C', 'a', '}'}; + json const j = {{"rolecode", "a"}, {"delim", ";"}}; + std::vector const v = {'{', 'i', 5, 'd', 'e', 'l', 'i', 'm', 'C', ';', 'i', 8, 'r', 'o', 'l', 'e', 'c', 'o', 'd', 'e', 'C', 'a', '}'}; //CHECK(json::to_ubjson(j) == v); CHECK(json::from_ubjson(v) == j); } @@ -2126,24 +2156,24 @@ TEST_CASE("Universal Binary JSON Specification Examples 1") { SECTION("English") { - json j = "hello"; - std::vector v = {'S', 'i', 5, 'h', 'e', 'l', 'l', 'o'}; + json const j = "hello"; + std::vector const v = {'S', 'i', 5, 'h', 'e', 'l', 'l', 'o'}; CHECK(json::to_ubjson(j) == v); CHECK(json::from_ubjson(v) == j); } SECTION("Russian") { - json j = "привет"; - std::vector v = {'S', 'i', 12, 0xD0, 0xBF, 0xD1, 0x80, 0xD0, 0xB8, 0xD0, 0xB2, 0xD0, 0xB5, 0xD1, 0x82}; + json const j = "привет"; + std::vector const v = {'S', 'i', 12, 0xD0, 0xBF, 0xD1, 0x80, 0xD0, 0xB8, 0xD0, 0xB2, 0xD0, 0xB5, 0xD1, 0x82}; CHECK(json::to_ubjson(j) == v); CHECK(json::from_ubjson(v) == j); } SECTION("Russian") { - json j = "مرحبا"; - std::vector v = {'S', 'i', 10, 0xD9, 0x85, 0xD8, 0xB1, 0xD8, 0xAD, 0xD8, 0xA8, 0xD8, 0xA7}; + json const j = "مرحبا"; + std::vector const v = {'S', 'i', 10, 0xD9, 0x85, 0xD8, 0xB1, 0xD8, 0xAD, 0xD8, 0xA8, 0xD8, 0xA7}; CHECK(json::to_ubjson(j) == v); CHECK(json::from_ubjson(v) == j); } @@ -2154,8 +2184,8 @@ TEST_CASE("Universal Binary JSON Specification Examples 1") SECTION("size=false type=false") { // note the float has been replaced by a double - json j = {nullptr, true, false, 4782345193, 153.132, "ham"}; - std::vector v = {'[', 'Z', 'T', 'F', 'L', 0x00, 0x00, 0x00, 0x01, 0x1D, 0x0C, 0xCB, 0xE9, 'D', 0x40, 0x63, 0x24, 0x39, 0x58, 0x10, 0x62, 0x4e, 'S', 'i', 3, 'h', 'a', 'm', ']'}; + json const j = {nullptr, true, false, 4782345193, 153.132, "ham"}; + std::vector const v = {'[', 'Z', 'T', 'F', 'L', 0x00, 0x00, 0x00, 0x01, 0x1D, 0x0C, 0xCB, 0xE9, 'D', 0x40, 0x63, 0x24, 0x39, 0x58, 0x10, 0x62, 0x4e, 'S', 'i', 3, 'h', 'a', 'm', ']'}; CHECK(json::to_ubjson(j) == v); CHECK(json::from_ubjson(v) == j); } @@ -2163,8 +2193,8 @@ TEST_CASE("Universal Binary JSON Specification Examples 1") SECTION("size=true type=false") { // note the float has been replaced by a double - json j = {nullptr, true, false, 4782345193, 153.132, "ham"}; - std::vector v = {'[', '#', 'i', 6, 'Z', 'T', 'F', 'L', 0x00, 0x00, 0x00, 0x01, 0x1D, 0x0C, 0xCB, 0xE9, 'D', 0x40, 0x63, 0x24, 0x39, 0x58, 0x10, 0x62, 0x4e, 'S', 'i', 3, 'h', 'a', 'm'}; + json const j = {nullptr, true, false, 4782345193, 153.132, "ham"}; + std::vector const v = {'[', '#', 'i', 6, 'Z', 'T', 'F', 'L', 0x00, 0x00, 0x00, 0x01, 0x1D, 0x0C, 0xCB, 0xE9, 'D', 0x40, 0x63, 0x24, 0x39, 0x58, 0x10, 0x62, 0x4e, 'S', 'i', 3, 'h', 'a', 'm'}; CHECK(json::to_ubjson(j, true) == v); CHECK(json::from_ubjson(v) == j); } @@ -2172,8 +2202,8 @@ TEST_CASE("Universal Binary JSON Specification Examples 1") SECTION("size=true type=true") { // note the float has been replaced by a double - json j = {nullptr, true, false, 4782345193, 153.132, "ham"}; - std::vector v = {'[', '#', 'i', 6, 'Z', 'T', 'F', 'L', 0x00, 0x00, 0x00, 0x01, 0x1D, 0x0C, 0xCB, 0xE9, 'D', 0x40, 0x63, 0x24, 0x39, 0x58, 0x10, 0x62, 0x4e, 'S', 'i', 3, 'h', 'a', 'm'}; + json const j = {nullptr, true, false, 4782345193, 153.132, "ham"}; + std::vector const v = {'[', '#', 'i', 6, 'Z', 'T', 'F', 'L', 0x00, 0x00, 0x00, 0x01, 0x1D, 0x0C, 0xCB, 0xE9, 'D', 0x40, 0x63, 0x24, 0x39, 0x58, 0x10, 0x62, 0x4e, 'S', 'i', 3, 'h', 'a', 'm'}; CHECK(json::to_ubjson(j, true, true) == v); CHECK(json::from_ubjson(v) == j); } @@ -2183,7 +2213,7 @@ TEST_CASE("Universal Binary JSON Specification Examples 1") { SECTION("size=false type=false") { - json j = + json const j = { { "post", { @@ -2194,20 +2224,20 @@ TEST_CASE("Universal Binary JSON Specification Examples 1") } } }; - std::vector v = {'{', 'i', 4, 'p', 'o', 's', 't', '{', - 'i', 6, 'a', 'u', 't', 'h', 'o', 'r', 'S', 'i', 6, 'r', 'k', 'a', 'l', 'l', 'a', - 'i', 4, 'b', 'o', 'd', 'y', 'S', 'i', 16, 'I', ' ', 't', 'o', 't', 'a', 'l', 'l', 'y', ' ', 'a', 'g', 'r', 'e', 'e', '!', - 'i', 2, 'i', 'd', 'I', 0x04, 0x71, - 'i', 9, 't', 'i', 'm', 'e', 's', 't', 'a', 'm', 'p', 'L', 0x00, 0x00, 0x01, 0x3D, 0xB1, 0x78, 0x66, 0x60, - '}', '}' - }; + std::vector const v = {'{', 'i', 4, 'p', 'o', 's', 't', '{', + 'i', 6, 'a', 'u', 't', 'h', 'o', 'r', 'S', 'i', 6, 'r', 'k', 'a', 'l', 'l', 'a', + 'i', 4, 'b', 'o', 'd', 'y', 'S', 'i', 16, 'I', ' ', 't', 'o', 't', 'a', 'l', 'l', 'y', ' ', 'a', 'g', 'r', 'e', 'e', '!', + 'i', 2, 'i', 'd', 'I', 0x04, 0x71, + 'i', 9, 't', 'i', 'm', 'e', 's', 't', 'a', 'm', 'p', 'L', 0x00, 0x00, 0x01, 0x3D, 0xB1, 0x78, 0x66, 0x60, + '}', '}' + }; CHECK(json::to_ubjson(j) == v); CHECK(json::from_ubjson(v) == j); } SECTION("size=true type=false") { - json j = + json const j = { { "post", { @@ -2218,19 +2248,19 @@ TEST_CASE("Universal Binary JSON Specification Examples 1") } } }; - std::vector v = {'{', '#', 'i', 1, 'i', 4, 'p', 'o', 's', 't', '{', '#', 'i', 4, - 'i', 6, 'a', 'u', 't', 'h', 'o', 'r', 'S', 'i', 6, 'r', 'k', 'a', 'l', 'l', 'a', - 'i', 4, 'b', 'o', 'd', 'y', 'S', 'i', 16, 'I', ' ', 't', 'o', 't', 'a', 'l', 'l', 'y', ' ', 'a', 'g', 'r', 'e', 'e', '!', - 'i', 2, 'i', 'd', 'I', 0x04, 0x71, - 'i', 9, 't', 'i', 'm', 'e', 's', 't', 'a', 'm', 'p', 'L', 0x00, 0x00, 0x01, 0x3D, 0xB1, 0x78, 0x66, 0x60 - }; + std::vector const v = {'{', '#', 'i', 1, 'i', 4, 'p', 'o', 's', 't', '{', '#', 'i', 4, + 'i', 6, 'a', 'u', 't', 'h', 'o', 'r', 'S', 'i', 6, 'r', 'k', 'a', 'l', 'l', 'a', + 'i', 4, 'b', 'o', 'd', 'y', 'S', 'i', 16, 'I', ' ', 't', 'o', 't', 'a', 'l', 'l', 'y', ' ', 'a', 'g', 'r', 'e', 'e', '!', + 'i', 2, 'i', 'd', 'I', 0x04, 0x71, + 'i', 9, 't', 'i', 'm', 'e', 's', 't', 'a', 'm', 'p', 'L', 0x00, 0x00, 0x01, 0x3D, 0xB1, 0x78, 0x66, 0x60 + }; CHECK(json::to_ubjson(j, true) == v); CHECK(json::from_ubjson(v) == j); } SECTION("size=true type=true") { - json j = + json const j = { { "post", { @@ -2241,12 +2271,12 @@ TEST_CASE("Universal Binary JSON Specification Examples 1") } } }; - std::vector v = {'{', '$', '{', '#', 'i', 1, 'i', 4, 'p', 'o', 's', 't', '#', 'i', 4, - 'i', 6, 'a', 'u', 't', 'h', 'o', 'r', 'S', 'i', 6, 'r', 'k', 'a', 'l', 'l', 'a', - 'i', 4, 'b', 'o', 'd', 'y', 'S', 'i', 16, 'I', ' ', 't', 'o', 't', 'a', 'l', 'l', 'y', ' ', 'a', 'g', 'r', 'e', 'e', '!', - 'i', 2, 'i', 'd', 'I', 0x04, 0x71, - 'i', 9, 't', 'i', 'm', 'e', 's', 't', 'a', 'm', 'p', 'L', 0x00, 0x00, 0x01, 0x3D, 0xB1, 0x78, 0x66, 0x60 - }; + std::vector const v = {'{', '$', '{', '#', 'i', 1, 'i', 4, 'p', 'o', 's', 't', '#', 'i', 4, + 'i', 6, 'a', 'u', 't', 'h', 'o', 'r', 'S', 'i', 6, 'r', 'k', 'a', 'l', 'l', 'a', + 'i', 4, 'b', 'o', 'd', 'y', 'S', 'i', 16, 'I', ' ', 't', 'o', 't', 'a', 'l', 'l', 'y', ' ', 'a', 'g', 'r', 'e', 'e', '!', + 'i', 2, 'i', 'd', 'I', 0x04, 0x71, + 'i', 9, 't', 'i', 'm', 'e', 's', 't', 'a', 'm', 'p', 'L', 0x00, 0x00, 0x01, 0x3D, 0xB1, 0x78, 0x66, 0x60 + }; CHECK(json::to_ubjson(j, true, true) == v); CHECK(json::from_ubjson(v) == j); } @@ -2259,15 +2289,15 @@ TEST_CASE("Universal Binary JSON Specification Examples 1") SECTION("No Optimization") { // note the floats have been replaced by doubles - json j = {29.97, 31.13, 67.0, 2.113, 23.888}; - std::vector v = {'[', - 'D', 0x40, 0x3d, 0xf8, 0x51, 0xeb, 0x85, 0x1e, 0xb8, - 'D', 0x40, 0x3f, 0x21, 0x47, 0xae, 0x14, 0x7a, 0xe1, - 'D', 0x40, 0x50, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, - 'D', 0x40, 0x00, 0xe7, 0x6c, 0x8b, 0x43, 0x95, 0x81, - 'D', 0x40, 0x37, 0xe3, 0x53, 0xf7, 0xce, 0xd9, 0x17, - ']' - }; + json const j = {29.97, 31.13, 67.0, 2.113, 23.888}; + std::vector const v = {'[', + 'D', 0x40, 0x3d, 0xf8, 0x51, 0xeb, 0x85, 0x1e, 0xb8, + 'D', 0x40, 0x3f, 0x21, 0x47, 0xae, 0x14, 0x7a, 0xe1, + 'D', 0x40, 0x50, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, + 'D', 0x40, 0x00, 0xe7, 0x6c, 0x8b, 0x43, 0x95, 0x81, + 'D', 0x40, 0x37, 0xe3, 0x53, 0xf7, 0xce, 0xd9, 0x17, + ']' + }; CHECK(json::to_ubjson(j) == v); CHECK(json::from_ubjson(v) == j); } @@ -2275,14 +2305,14 @@ TEST_CASE("Universal Binary JSON Specification Examples 1") SECTION("Optimized with count") { // note the floats have been replaced by doubles - json j = {29.97, 31.13, 67.0, 2.113, 23.888}; - std::vector v = {'[', '#', 'i', 5, - 'D', 0x40, 0x3d, 0xf8, 0x51, 0xeb, 0x85, 0x1e, 0xb8, - 'D', 0x40, 0x3f, 0x21, 0x47, 0xae, 0x14, 0x7a, 0xe1, - 'D', 0x40, 0x50, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, - 'D', 0x40, 0x00, 0xe7, 0x6c, 0x8b, 0x43, 0x95, 0x81, - 'D', 0x40, 0x37, 0xe3, 0x53, 0xf7, 0xce, 0xd9, 0x17 - }; + json const j = {29.97, 31.13, 67.0, 2.113, 23.888}; + std::vector const v = {'[', '#', 'i', 5, + 'D', 0x40, 0x3d, 0xf8, 0x51, 0xeb, 0x85, 0x1e, 0xb8, + 'D', 0x40, 0x3f, 0x21, 0x47, 0xae, 0x14, 0x7a, 0xe1, + 'D', 0x40, 0x50, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, + 'D', 0x40, 0x00, 0xe7, 0x6c, 0x8b, 0x43, 0x95, 0x81, + 'D', 0x40, 0x37, 0xe3, 0x53, 0xf7, 0xce, 0xd9, 0x17 + }; CHECK(json::to_ubjson(j, true) == v); CHECK(json::from_ubjson(v) == j); } @@ -2290,14 +2320,14 @@ TEST_CASE("Universal Binary JSON Specification Examples 1") SECTION("Optimized with type & count") { // note the floats have been replaced by doubles - json j = {29.97, 31.13, 67.0, 2.113, 23.888}; - std::vector v = {'[', '$', 'D', '#', 'i', 5, - 0x40, 0x3d, 0xf8, 0x51, 0xeb, 0x85, 0x1e, 0xb8, - 0x40, 0x3f, 0x21, 0x47, 0xae, 0x14, 0x7a, 0xe1, - 0x40, 0x50, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x40, 0x00, 0xe7, 0x6c, 0x8b, 0x43, 0x95, 0x81, - 0x40, 0x37, 0xe3, 0x53, 0xf7, 0xce, 0xd9, 0x17 - }; + json const j = {29.97, 31.13, 67.0, 2.113, 23.888}; + std::vector const v = {'[', '$', 'D', '#', 'i', 5, + 0x40, 0x3d, 0xf8, 0x51, 0xeb, 0x85, 0x1e, 0xb8, + 0x40, 0x3f, 0x21, 0x47, 0xae, 0x14, 0x7a, 0xe1, + 0x40, 0x50, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x40, 0x00, 0xe7, 0x6c, 0x8b, 0x43, 0x95, 0x81, + 0x40, 0x37, 0xe3, 0x53, 0xf7, 0xce, 0xd9, 0x17 + }; CHECK(json::to_ubjson(j, true, true) == v); CHECK(json::from_ubjson(v) == j); } @@ -2308,13 +2338,13 @@ TEST_CASE("Universal Binary JSON Specification Examples 1") SECTION("No Optimization") { // note the floats have been replaced by doubles - json j = { {"lat", 29.976}, {"long", 31.131}, {"alt", 67.0} }; - std::vector v = {'{', - 'i', 3, 'a', 'l', 't', 'D', 0x40, 0x50, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, - 'i', 3, 'l', 'a', 't', 'D', 0x40, 0x3d, 0xf9, 0xdb, 0x22, 0xd0, 0xe5, 0x60, - 'i', 4, 'l', 'o', 'n', 'g', 'D', 0x40, 0x3f, 0x21, 0x89, 0x37, 0x4b, 0xc6, 0xa8, - '}' - }; + json const j = { {"lat", 29.976}, {"long", 31.131}, {"alt", 67.0} }; + std::vector const v = {'{', + 'i', 3, 'a', 'l', 't', 'D', 0x40, 0x50, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, + 'i', 3, 'l', 'a', 't', 'D', 0x40, 0x3d, 0xf9, 0xdb, 0x22, 0xd0, 0xe5, 0x60, + 'i', 4, 'l', 'o', 'n', 'g', 'D', 0x40, 0x3f, 0x21, 0x89, 0x37, 0x4b, 0xc6, 0xa8, + '}' + }; CHECK(json::to_ubjson(j) == v); CHECK(json::from_ubjson(v) == j); } @@ -2322,12 +2352,12 @@ TEST_CASE("Universal Binary JSON Specification Examples 1") SECTION("Optimized with count") { // note the floats have been replaced by doubles - json j = { {"lat", 29.976}, {"long", 31.131}, {"alt", 67.0} }; - std::vector v = {'{', '#', 'i', 3, - 'i', 3, 'a', 'l', 't', 'D', 0x40, 0x50, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, - 'i', 3, 'l', 'a', 't', 'D', 0x40, 0x3d, 0xf9, 0xdb, 0x22, 0xd0, 0xe5, 0x60, - 'i', 4, 'l', 'o', 'n', 'g', 'D', 0x40, 0x3f, 0x21, 0x89, 0x37, 0x4b, 0xc6, 0xa8 - }; + json const j = { {"lat", 29.976}, {"long", 31.131}, {"alt", 67.0} }; + std::vector const v = {'{', '#', 'i', 3, + 'i', 3, 'a', 'l', 't', 'D', 0x40, 0x50, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, + 'i', 3, 'l', 'a', 't', 'D', 0x40, 0x3d, 0xf9, 0xdb, 0x22, 0xd0, 0xe5, 0x60, + 'i', 4, 'l', 'o', 'n', 'g', 'D', 0x40, 0x3f, 0x21, 0x89, 0x37, 0x4b, 0xc6, 0xa8 + }; CHECK(json::to_ubjson(j, true) == v); CHECK(json::from_ubjson(v) == j); } @@ -2335,12 +2365,12 @@ TEST_CASE("Universal Binary JSON Specification Examples 1") SECTION("Optimized with type & count") { // note the floats have been replaced by doubles - json j = { {"lat", 29.976}, {"long", 31.131}, {"alt", 67.0} }; - std::vector v = {'{', '$', 'D', '#', 'i', 3, - 'i', 3, 'a', 'l', 't', 0x40, 0x50, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, - 'i', 3, 'l', 'a', 't', 0x40, 0x3d, 0xf9, 0xdb, 0x22, 0xd0, 0xe5, 0x60, - 'i', 4, 'l', 'o', 'n', 'g', 0x40, 0x3f, 0x21, 0x89, 0x37, 0x4b, 0xc6, 0xa8 - }; + json const j = { {"lat", 29.976}, {"long", 31.131}, {"alt", 67.0} }; + std::vector const v = {'{', '$', 'D', '#', 'i', 3, + 'i', 3, 'a', 'l', 't', 0x40, 0x50, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, + 'i', 3, 'l', 'a', 't', 0x40, 0x3d, 0xf9, 0xdb, 0x22, 0xd0, 0xe5, 0x60, + 'i', 4, 'l', 'o', 'n', 'g', 0x40, 0x3f, 0x21, 0x89, 0x37, 0x4b, 0xc6, 0xa8 + }; CHECK(json::to_ubjson(j, true, true) == v); CHECK(json::from_ubjson(v) == j); } @@ -2350,13 +2380,13 @@ TEST_CASE("Universal Binary JSON Specification Examples 1") { SECTION("Array") { - std::vector v = {'[', '$', 'N', '#', 'I', 0x02, 0x00}; + std::vector const v = {'[', '$', 'N', '#', 'I', 0x02, 0x00}; CHECK(json::from_ubjson(v) == json::array()); } SECTION("Object") { - std::vector v = {'{', '$', 'Z', '#', 'i', 3, 'i', 4, 'n', 'a', 'm', 'e', 'i', 8, 'p', 'a', 's', 's', 'w', 'o', 'r', 'd', 'i', 5, 'e', 'm', 'a', 'i', 'l'}; + std::vector const v = {'{', '$', 'Z', '#', 'i', 3, 'i', 4, 'n', 'a', 'm', 'e', 'i', 8, 'p', 'a', 's', 's', 'w', 'o', 'r', 'd', 'i', 5, 'e', 'm', 'a', 'i', 'l'}; CHECK(json::from_ubjson(v) == json({ {"name", nullptr}, {"password", nullptr}, {"email", nullptr} })); } } @@ -2455,10 +2485,10 @@ TEST_CASE("UBJSON roundtrips" * doctest::skip()) INFO_WITH_TEMP(filename + ": std::vector"); // parse JSON file std::ifstream f_json(filename); - json j1 = json::parse(f_json); + json const j1 = json::parse(f_json); // parse UBJSON file - auto packed = utils::read_binary_file(filename + ".ubjson"); + auto const packed = utils::read_binary_file(filename + ".ubjson"); json j2; CHECK_NOTHROW(j2 = json::from_ubjson(packed)); @@ -2470,7 +2500,7 @@ TEST_CASE("UBJSON roundtrips" * doctest::skip()) INFO_WITH_TEMP(filename + ": std::ifstream"); // parse JSON file std::ifstream f_json(filename); - json j1 = json::parse(f_json); + json const j1 = json::parse(f_json); // parse UBJSON file std::ifstream f_ubjson(filename + ".ubjson", std::ios::binary); @@ -2488,7 +2518,7 @@ TEST_CASE("UBJSON roundtrips" * doctest::skip()) json j1 = json::parse(f_json); // parse UBJSON file - auto packed = utils::read_binary_file(filename + ".ubjson"); + auto const packed = utils::read_binary_file(filename + ".ubjson"); json j2; CHECK_NOTHROW(j2 = json::from_ubjson({packed.data(), packed.size()})); @@ -2500,10 +2530,10 @@ TEST_CASE("UBJSON 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 UBJSON file - auto packed = utils::read_binary_file(filename + ".ubjson"); + auto const packed = utils::read_binary_file(filename + ".ubjson"); { INFO_WITH_TEMP(filename + ": output adapters: std::vector"); 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); diff --git a/tests/src/unit-unicode1.cpp b/tests/src/unit-unicode1.cpp index 0b87cfa9d..f7a6ad197 100644 --- a/tests/src/unit-unicode1.cpp +++ b/tests/src/unit-unicode1.cpp @@ -233,9 +233,9 @@ void roundtrip(bool success_expected, const std::string& s) json _; // create JSON string value - json j = s; + const json j = s; // create JSON text - std::string ps = std::string("\"") + s + "\""; + const std::string ps = std::string("\"") + s + "\""; if (success_expected) { @@ -253,7 +253,7 @@ void roundtrip(bool success_expected, const std::string& s) CHECK_NOTHROW(_ = json::parse(j.dump())); // after roundtrip, the same string is stored - json jr = json::parse(j.dump()); + const json jr = json::parse(j.dump()); CHECK(jr.get() == s); } else diff --git a/tests/src/unit-user_defined_input.cpp b/tests/src/unit-user_defined_input.cpp index febc14c7c..576c81ea9 100644 --- a/tests/src/unit-user_defined_input.cpp +++ b/tests/src/unit-user_defined_input.cpp @@ -45,7 +45,7 @@ const char* end(const MyContainer& c) TEST_CASE("Custom container non-member begin/end") { - MyContainer data{"[1,2,3,4]"}; + const MyContainer data{"[1,2,3,4]"}; json as_json = json::parse(data); CHECK(as_json.at(0) == 1); CHECK(as_json.at(1) == 2); @@ -71,7 +71,7 @@ TEST_CASE("Custom container member begin/end") } }; - MyContainer2 data{"[1,2,3,4]"}; + const MyContainer2 data{"[1,2,3,4]"}; json as_json = json::parse(data); CHECK(as_json.at(0) == 1); CHECK(as_json.at(1) == 2); @@ -117,8 +117,8 @@ TEST_CASE("Custom iterator") CHECK(std::is_same::value); CHECK(std::is_same::value); - MyIterator begin{raw_data}; - MyIterator end{raw_data + strlen(raw_data)}; // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic) + const MyIterator begin{raw_data}; + const MyIterator end{raw_data + strlen(raw_data)}; // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic) json as_json = json::parse(begin, end); CHECK(as_json.at(0) == 1); diff --git a/tests/src/unit-wstring.cpp b/tests/src/unit-wstring.cpp index cadda8b70..42128c498 100644 --- a/tests/src/unit-wstring.cpp +++ b/tests/src/unit-wstring.cpp @@ -40,8 +40,8 @@ TEST_CASE("wide strings") { if (wstring_is_utf16()) { - std::wstring w = L"[12.2,\"Ⴥaäö💤🧢\"]"; - json j = json::parse(w); + std::wstring const w = L"[12.2,\"Ⴥaäö💤🧢\"]"; + json const j = json::parse(w); CHECK(j.dump() == "[12.2,\"Ⴥaäö💤🧢\"]"); } } @@ -50,7 +50,7 @@ TEST_CASE("wide strings") { if (wstring_is_utf16()) { - std::wstring w = L"\"\xDBFF"; + std::wstring const w = L"\"\xDBFF"; json _; CHECK_THROWS_AS(_ = json::parse(w), json::parse_error&); } @@ -60,8 +60,8 @@ TEST_CASE("wide strings") { if (u16string_is_utf16()) { - std::u16string w = u"[12.2,\"Ⴥaäö💤🧢\"]"; - json j = json::parse(w); + std::u16string const w = u"[12.2,\"Ⴥaäö💤🧢\"]"; + json const j = json::parse(w); CHECK(j.dump() == "[12.2,\"Ⴥaäö💤🧢\"]"); } } @@ -70,7 +70,7 @@ TEST_CASE("wide strings") { if (wstring_is_utf16()) { - std::u16string w = u"\"\xDBFF"; + std::u16string const w = u"\"\xDBFF"; json _; CHECK_THROWS_AS(_ = json::parse(w), json::parse_error&); } @@ -80,8 +80,8 @@ TEST_CASE("wide strings") { if (u32string_is_utf32()) { - std::u32string w = U"[12.2,\"Ⴥaäö💤🧢\"]"; - json j = json::parse(w); + std::u32string const w = U"[12.2,\"Ⴥaäö💤🧢\"]"; + json const j = json::parse(w); CHECK(j.dump() == "[12.2,\"Ⴥaäö💤🧢\"]"); } } @@ -90,7 +90,7 @@ TEST_CASE("wide strings") { if (u32string_is_utf32()) { - std::u32string w = U"\"\x110000"; + std::u32string const w = U"\"\x110000"; json _; CHECK_THROWS_AS(_ = json::parse(w), json::parse_error&); } diff --git a/tests/thirdparty/doctest/doctest_compatibility.h b/tests/thirdparty/doctest/doctest_compatibility.h index 6194e26b0..e056a824d 100644 --- a/tests/thirdparty/doctest/doctest_compatibility.h +++ b/tests/thirdparty/doctest/doctest_compatibility.h @@ -20,7 +20,7 @@ // doctest doesn't support THROWS_WITH for std::string out of the box (has to include ...) #define CHECK_THROWS_WITH_STD_STR_IMPL(expr, str, var_name) \ do { \ - std::string var_name = str; \ + const std::string var_name = str; \ CHECK_THROWS_WITH(expr, var_name.c_str()); \ } while (false) #define CHECK_THROWS_WITH_STD_STR(expr, str) \