# Conflicts:

#	.github/workflows/macos.yml
#	include/nlohmann/detail/input/parser.hpp
#	include/nlohmann/detail/meta/std_fs.hpp
#	include/nlohmann/json.hpp
#	single_include/nlohmann/json.hpp
This commit is contained in:
Niels Lohmann
2024-11-16 23:23:05 +01:00
parent 9561a122a3
commit 5e9bf559b1
33 changed files with 430 additions and 188 deletions
+1 -1
View File
@@ -23,7 +23,7 @@ struct trait_test_arg
static constexpr bool max_in_range = MaxInRange;
};
TEST_CASE_TEMPLATE_DEFINE("value_in_range_of trait", T, value_in_range_of_test)
TEST_CASE_TEMPLATE_DEFINE("value_in_range_of trait", T, value_in_range_of_test) // NOLINT(readability-math-missing-parentheses)
{
using nlohmann::detail::value_in_range_of;
+5 -5
View File
@@ -109,7 +109,7 @@ struct trait_test_arg
static constexpr bool max_in_range = MaxInRange;
};
TEST_CASE_TEMPLATE_DEFINE("value_in_range_of trait", T, value_in_range_of_test)
TEST_CASE_TEMPLATE_DEFINE("value_in_range_of trait", T, value_in_range_of_test) // NOLINT(readability-math-missing-parentheses)
{
using nlohmann::detail::value_in_range_of;
@@ -573,7 +573,7 @@ TEST_CASE("BJData")
// check individual bytes
CHECK(result[0] == 'I');
auto const restored = static_cast<uint16_t>(static_cast<uint8_t>(result[2]) * 256 + static_cast<uint8_t>(result[1]));
auto const restored = static_cast<uint16_t>((static_cast<uint8_t>(result[2]) * 256) + static_cast<uint8_t>(result[1]));
CHECK(restored == i);
// roundtrip
@@ -613,7 +613,7 @@ TEST_CASE("BJData")
// check individual bytes
CHECK(result[0] == 'u');
auto const restored = static_cast<uint16_t>(static_cast<uint8_t>(result[2]) * 256 + static_cast<uint8_t>(result[1]));
auto const restored = static_cast<uint16_t>((static_cast<uint8_t>(result[2]) * 256) + static_cast<uint8_t>(result[1]));
CHECK(restored == i);
// roundtrip
@@ -905,7 +905,7 @@ TEST_CASE("BJData")
// check individual bytes
CHECK(result[0] == 'I');
auto const restored = static_cast<uint16_t>(static_cast<uint8_t>(result[2]) * 256 + static_cast<uint8_t>(result[1]));
auto const restored = static_cast<uint16_t>((static_cast<uint8_t>(result[2]) * 256) + static_cast<uint8_t>(result[1]));
CHECK(restored == i);
// roundtrip
@@ -944,7 +944,7 @@ TEST_CASE("BJData")
// check individual bytes
CHECK(result[0] == 'u');
auto const restored = static_cast<uint16_t>(static_cast<uint8_t>(result[2]) * 256 + static_cast<uint8_t>(result[1]));
auto const restored = static_cast<uint16_t>((static_cast<uint8_t>(result[2]) * 256) + static_cast<uint8_t>(result[1]));
CHECK(restored == i);
// roundtrip
+4 -5
View File
@@ -14,7 +14,6 @@ using nlohmann::json;
#include <fstream>
#include <sstream>
#include <iomanip>
#include <iostream>
#include <limits>
#include <set>
#include "make_test_data_available.hpp"
@@ -317,7 +316,7 @@ TEST_CASE("CBOR")
// check individual bytes
CHECK(result[0] == 0x39);
const auto restored = static_cast<uint16_t>(static_cast<uint8_t>(result[1]) * 256 + static_cast<uint8_t>(result[2]));
const auto restored = static_cast<uint16_t>((static_cast<uint8_t>(result[1]) * 256) + static_cast<uint8_t>(result[2]));
CHECK(restored == positive);
CHECK(-1 - restored == i);
@@ -505,7 +504,7 @@ TEST_CASE("CBOR")
// check individual bytes
CHECK(result[0] == 0x19);
const auto restored = static_cast<uint16_t>(static_cast<uint8_t>(result[1]) * 256 + static_cast<uint8_t>(result[2]));
const auto restored = static_cast<uint16_t>((static_cast<uint8_t>(result[1]) * 256) + static_cast<uint8_t>(result[2]));
CHECK(restored == i);
// roundtrip
@@ -744,7 +743,7 @@ TEST_CASE("CBOR")
// check individual bytes
CHECK(result[0] == 0x19);
const auto restored = static_cast<uint16_t>(static_cast<uint8_t>(result[1]) * 256 + static_cast<uint8_t>(result[2]));
const auto restored = static_cast<uint16_t>((static_cast<uint8_t>(result[1]) * 256) + static_cast<uint8_t>(result[2]));
CHECK(restored == i);
// roundtrip
@@ -990,7 +989,7 @@ TEST_CASE("CBOR")
{
0xfa, 0xff, 0x7f, 0xff, 0xff
};
// the same with lowest float
// the same with the lowest float
const auto result = json::to_cbor(j);
CHECK(result == expected);
// roundtrip
+1 -1
View File
@@ -23,7 +23,7 @@ json::lexer::token_type scan_string(const char* s, const bool ignore_comments)
}
} // namespace
std::string get_error_message(const char* s, bool ignore_comments = false);
std::string get_error_message(const char* s, bool ignore_comments = false); // NOLINT(misc-use-internal-linkage)
std::string get_error_message(const char* s, const bool ignore_comments)
{
auto ia = nlohmann::detail::input_adapter(s);
+91 -1
View File
@@ -28,10 +28,30 @@ using nlohmann::json;
#include <unordered_set>
#include <valarray>
// NLOHMANN_JSON_SERIALIZE_ENUM uses a static std::pair
DOCTEST_CLANG_SUPPRESS_WARNING_PUSH
DOCTEST_CLANG_SUPPRESS_WARNING("-Wexit-time-destructors")
#if (defined(__cplusplus) && __cplusplus >= 201703L) || (defined(_HAS_CXX17) && _HAS_CXX17 == 1) // fix for issue #464
#define JSON_HAS_CPP_17
#define JSON_HAS_CPP_14
#elif (defined(__cplusplus) && __cplusplus >= 201402L) || (defined(_HAS_CXX14) && _HAS_CXX14 == 1)
#define JSON_HAS_CPP_14
#endif
#ifdef JSON_HAS_CPP_17
#if __has_include(<optional>)
#include <optional>
#elif __has_include(<experimental/optional>)
#include <experimental/optional>
#endif
#endif
#if defined(JSON_HAS_CPP_17)
#include <string_view>
#endif
TEST_CASE("value conversion")
{
SECTION("get an object (explicit)")
@@ -153,6 +173,7 @@ TEST_CASE("value conversion")
}
#if JSON_USE_IMPLICIT_CONVERSIONS
SECTION("get an object (implicit)")
{
const json::object_t o_reference = {{"object", json::object()},
@@ -1513,7 +1534,7 @@ NLOHMANN_JSON_SERIALIZE_ENUM(cards,
{cards::karo, "karo"}
})
enum TaskState
enum TaskState // NOLINT(cert-int09-c,readability-enum-initial-value)
{
TS_STOPPED = 0,
TS_RUNNING = 1,
@@ -1569,4 +1590,73 @@ TEST_CASE("JSON to enum mapping")
}
}
#ifdef JSON_HAS_CPP_17
#ifndef JSON_USE_IMPLICIT_CONVERSIONS
TEST_CASE("std::optional")
{
SECTION("null")
{
json j_null;
std::optional<std::string> opt_null;
CHECK(json(opt_null) == j_null);
CHECK(j_null.get<std::optional<std::string>>() == std::nullopt);
}
SECTION("string")
{
json j_string = "string";
std::optional<std::string> opt_string = "string";
CHECK(json(opt_string) == j_string);
CHECK(std::optional<std::string>(j_string) == opt_string);
}
SECTION("bool")
{
json j_bool = true;
std::optional<bool> opt_bool = true;
CHECK(json(opt_bool) == j_bool);
CHECK(std::optional<bool>(j_bool) == opt_bool);
}
SECTION("number")
{
json j_number = 1;
std::optional<int> opt_int = 1;
CHECK(json(opt_int) == j_number);
CHECK(j_number.get<std::optional<int>>() == opt_int);
}
SECTION("array")
{
json j_array = {1, 2, nullptr};
std::vector<std::optional<int>> opt_array = {{1, 2, std::nullopt}};
CHECK(json(opt_array) == j_array);
CHECK(j_array.get<std::vector<std::optional<int>>>() == opt_array);
}
SECTION("object")
{
json j_object = {{"one", 1}, {"two", 2}, {"zero", nullptr}};
std::map<std::string, std::optional<int>> opt_object {{"one", 1}, {"two", 2}, {"zero", std::nullopt}};
CHECK(json(opt_object) == j_object);
CHECK(std::map<std::string, std::optional<int>>(j_object) == opt_object);
}
}
#endif
#endif
#ifdef JSON_HAS_CPP_17
#undef JSON_HAS_CPP_17
#endif
#ifdef JSON_HAS_CPP_14
#undef JSON_HAS_CPP_14
#endif
DOCTEST_CLANG_SUPPRESS_WARNING_POP
+4 -4
View File
@@ -1131,7 +1131,7 @@ TEST_CASE("deserialization")
}
}
TEST_CASE_TEMPLATE("deserialization of different character types (ASCII)", T,
TEST_CASE_TEMPLATE("deserialization of different character types (ASCII)", T, // NOLINT(readability-math-missing-parentheses)
char, unsigned char, signed char,
wchar_t,
char16_t, char32_t,
@@ -1149,7 +1149,7 @@ TEST_CASE_TEMPLATE("deserialization of different character types (ASCII)", T,
CHECK(l.events == std::vector<std::string>({"boolean(true)"}));
}
TEST_CASE_TEMPLATE("deserialization of different character types (UTF-8)", T,
TEST_CASE_TEMPLATE("deserialization of different character types (UTF-8)", T, // NOLINT(readability-math-missing-parentheses)
char, unsigned char, std::uint8_t)
{
// a star emoji
@@ -1162,7 +1162,7 @@ TEST_CASE_TEMPLATE("deserialization of different character types (UTF-8)", T,
CHECK(l.events.size() == 1);
}
TEST_CASE_TEMPLATE("deserialization of different character types (UTF-16)", T,
TEST_CASE_TEMPLATE("deserialization of different character types (UTF-16)", T, // NOLINT(readability-math-missing-parentheses)
char16_t, std::uint16_t)
{
// a star emoji
@@ -1175,7 +1175,7 @@ TEST_CASE_TEMPLATE("deserialization of different character types (UTF-16)", T,
CHECK(l.events.size() == 1);
}
TEST_CASE_TEMPLATE("deserialization of different character types (UTF-32)", T,
TEST_CASE_TEMPLATE("deserialization of different character types (UTF-32)", T, // NOLINT(readability-math-missing-parentheses)
char32_t, std::uint32_t)
{
// a star emoji
+14 -14
View File
@@ -55,7 +55,7 @@ TEST_CASE("element access 1")
SECTION("null")
{
json j_nonarray(json::value_t::null);
const json j_nonarray_const(j_nonarray);
const json j_nonarray_const(j_nonarray); // NOLINT(performance-unnecessary-copy-initialization)
CHECK_THROWS_WITH_AS(j_nonarray.at(0), "[json.exception.type_error.304] cannot use at() with null", json::type_error&);
CHECK_THROWS_WITH_AS(j_nonarray_const.at(0), "[json.exception.type_error.304] cannot use at() with null", json::type_error&);
@@ -64,7 +64,7 @@ TEST_CASE("element access 1")
SECTION("boolean")
{
json j_nonarray(json::value_t::boolean);
const json j_nonarray_const(j_nonarray);
const json j_nonarray_const(j_nonarray); // NOLINT(performance-unnecessary-copy-initialization)
CHECK_THROWS_WITH_AS(j_nonarray.at(0), "[json.exception.type_error.304] cannot use at() with boolean", json::type_error&);
CHECK_THROWS_WITH_AS(j_nonarray_const.at(0), "[json.exception.type_error.304] cannot use at() with boolean", json::type_error&);
@@ -73,7 +73,7 @@ TEST_CASE("element access 1")
SECTION("string")
{
json j_nonarray(json::value_t::string);
const json j_nonarray_const(j_nonarray);
const json j_nonarray_const(j_nonarray); // NOLINT(performance-unnecessary-copy-initialization)
CHECK_THROWS_WITH_AS(j_nonarray.at(0), "[json.exception.type_error.304] cannot use at() with string", json::type_error&);
CHECK_THROWS_WITH_AS(j_nonarray_const.at(0), "[json.exception.type_error.304] cannot use at() with string", json::type_error&);
@@ -82,7 +82,7 @@ TEST_CASE("element access 1")
SECTION("object")
{
json j_nonarray(json::value_t::object);
const json j_nonarray_const(j_nonarray);
const json j_nonarray_const(j_nonarray); // NOLINT(performance-unnecessary-copy-initialization)
CHECK_THROWS_WITH_AS(j_nonarray.at(0), "[json.exception.type_error.304] cannot use at() with object", json::type_error&);
CHECK_THROWS_WITH_AS(j_nonarray_const.at(0), "[json.exception.type_error.304] cannot use at() with object", json::type_error&);
@@ -91,7 +91,7 @@ TEST_CASE("element access 1")
SECTION("number (integer)")
{
json j_nonarray(json::value_t::number_integer);
const json j_nonarray_const(j_nonarray);
const json j_nonarray_const(j_nonarray); // NOLINT(performance-unnecessary-copy-initialization)
CHECK_THROWS_WITH_AS(j_nonarray.at(0), "[json.exception.type_error.304] cannot use at() with number", json::type_error&);
CHECK_THROWS_WITH_AS(j_nonarray_const.at(0), "[json.exception.type_error.304] cannot use at() with number", json::type_error&);
@@ -100,7 +100,7 @@ TEST_CASE("element access 1")
SECTION("number (unsigned)")
{
json j_nonarray(json::value_t::number_unsigned);
const json j_nonarray_const(j_nonarray);
const json j_nonarray_const(j_nonarray); // NOLINT(performance-unnecessary-copy-initialization)
CHECK_THROWS_WITH_AS(j_nonarray.at(0), "[json.exception.type_error.304] cannot use at() with number", json::type_error&);
CHECK_THROWS_WITH_AS(j_nonarray_const.at(0), "[json.exception.type_error.304] cannot use at() with number", json::type_error&);
@@ -109,7 +109,7 @@ TEST_CASE("element access 1")
SECTION("number (floating-point)")
{
json j_nonarray(json::value_t::number_float);
const json j_nonarray_const(j_nonarray);
const json j_nonarray_const(j_nonarray); // NOLINT(performance-unnecessary-copy-initialization)
CHECK_THROWS_WITH_AS(j_nonarray.at(0), "[json.exception.type_error.304] cannot use at() with number", json::type_error&);
CHECK_THROWS_WITH_AS(j_nonarray_const.at(0), "[json.exception.type_error.304] cannot use at() with number", json::type_error&);
@@ -155,7 +155,7 @@ TEST_CASE("element access 1")
SECTION("standard tests")
{
json j_nonarray(json::value_t::null);
const json j_nonarray_const(j_nonarray);
const json j_nonarray_const(j_nonarray); // NOLINT(performance-unnecessary-copy-initialization)
CHECK_NOTHROW(j_nonarray[0]);
CHECK_THROWS_WITH_AS(j_nonarray_const[0], "[json.exception.type_error.305] cannot use operator[] with a numeric argument with null", json::type_error&);
}
@@ -171,7 +171,7 @@ TEST_CASE("element access 1")
SECTION("boolean")
{
json j_nonarray(json::value_t::boolean);
const json j_nonarray_const(j_nonarray);
const json j_nonarray_const(j_nonarray); // NOLINT(performance-unnecessary-copy-initialization)
CHECK_THROWS_WITH_AS(j_nonarray[0], "[json.exception.type_error.305] cannot use operator[] with a numeric argument with boolean", json::type_error&);
CHECK_THROWS_WITH_AS(j_nonarray_const[0], "[json.exception.type_error.305] cannot use operator[] with a numeric argument with boolean", json::type_error&);
}
@@ -179,7 +179,7 @@ TEST_CASE("element access 1")
SECTION("string")
{
json j_nonarray(json::value_t::string);
const json j_nonarray_const(j_nonarray);
const json j_nonarray_const(j_nonarray); // NOLINT(performance-unnecessary-copy-initialization)
CHECK_THROWS_WITH_AS(j_nonarray[0], "[json.exception.type_error.305] cannot use operator[] with a numeric argument with string", json::type_error&);
CHECK_THROWS_WITH_AS(j_nonarray_const[0], "[json.exception.type_error.305] cannot use operator[] with a numeric argument with string", json::type_error&);
}
@@ -187,7 +187,7 @@ TEST_CASE("element access 1")
SECTION("object")
{
json j_nonarray(json::value_t::object);
const json j_nonarray_const(j_nonarray);
const json j_nonarray_const(j_nonarray); // NOLINT(performance-unnecessary-copy-initialization)
CHECK_THROWS_WITH_AS(j_nonarray[0], "[json.exception.type_error.305] cannot use operator[] with a numeric argument with object", json::type_error&);
CHECK_THROWS_WITH_AS(j_nonarray_const[0], "[json.exception.type_error.305] cannot use operator[] with a numeric argument with object", json::type_error&);
}
@@ -195,7 +195,7 @@ TEST_CASE("element access 1")
SECTION("number (integer)")
{
json j_nonarray(json::value_t::number_integer);
const json j_nonarray_const(j_nonarray);
const json j_nonarray_const(j_nonarray); // NOLINT(performance-unnecessary-copy-initialization)
CHECK_THROWS_WITH_AS(j_nonarray[0], "[json.exception.type_error.305] cannot use operator[] with a numeric argument with number", json::type_error&);
CHECK_THROWS_WITH_AS(j_nonarray_const[0], "[json.exception.type_error.305] cannot use operator[] with a numeric argument with number", json::type_error&);
}
@@ -203,7 +203,7 @@ TEST_CASE("element access 1")
SECTION("number (unsigned)")
{
json j_nonarray(json::value_t::number_unsigned);
const json j_nonarray_const(j_nonarray);
const json j_nonarray_const(j_nonarray); // NOLINT(performance-unnecessary-copy-initialization)
CHECK_THROWS_WITH_AS(j_nonarray[0], "[json.exception.type_error.305] cannot use operator[] with a numeric argument with number", json::type_error&);
CHECK_THROWS_WITH_AS(j_nonarray_const[0], "[json.exception.type_error.305] cannot use operator[] with a numeric argument with number", json::type_error&);
}
@@ -211,7 +211,7 @@ TEST_CASE("element access 1")
SECTION("number (floating-point)")
{
json j_nonarray(json::value_t::number_float);
const json j_nonarray_const(j_nonarray);
const json j_nonarray_const(j_nonarray); // NOLINT(performance-unnecessary-copy-initialization)
CHECK_THROWS_WITH_AS(j_nonarray[0], "[json.exception.type_error.305] cannot use operator[] with a numeric argument with number", json::type_error&);
CHECK_THROWS_WITH_AS(j_nonarray_const[0], "[json.exception.type_error.305] cannot use operator[] with a numeric argument with number", json::type_error&);
}
+10 -10
View File
@@ -17,7 +17,7 @@
// build test with C++14
// JSON_HAS_CPP_14
TEST_CASE_TEMPLATE("element access 2", Json, nlohmann::json, nlohmann::ordered_json)
TEST_CASE_TEMPLATE("element access 2", Json, nlohmann::json, nlohmann::ordered_json) // NOLINT(readability-math-missing-parentheses)
{
SECTION("object")
{
@@ -88,7 +88,7 @@ TEST_CASE_TEMPLATE("element access 2", Json, nlohmann::json, nlohmann::ordered_j
SECTION("null")
{
Json j_nonobject(Json::value_t::null);
const Json j_nonobject_const(j_nonobject);
const Json j_nonobject_const(j_nonobject); // NOLINT(performance-unnecessary-copy-initialization)
CHECK_THROWS_WITH_AS(j_nonobject.at("foo"), "[json.exception.type_error.304] cannot use at() with null", typename Json::type_error&);
CHECK_THROWS_WITH_AS(j_nonobject_const.at("foo"), "[json.exception.type_error.304] cannot use at() with null", typename Json::type_error&);
@@ -101,7 +101,7 @@ TEST_CASE_TEMPLATE("element access 2", Json, nlohmann::json, nlohmann::ordered_j
SECTION("boolean")
{
Json j_nonobject(Json::value_t::boolean);
const Json j_nonobject_const(j_nonobject);
const Json j_nonobject_const(j_nonobject); // NOLINT(performance-unnecessary-copy-initialization)
CHECK_THROWS_WITH_AS(j_nonobject.at("foo"), "[json.exception.type_error.304] cannot use at() with boolean", typename Json::type_error&);
CHECK_THROWS_WITH_AS(j_nonobject_const.at("foo"), "[json.exception.type_error.304] cannot use at() with boolean", typename Json::type_error&);
@@ -114,7 +114,7 @@ TEST_CASE_TEMPLATE("element access 2", Json, nlohmann::json, nlohmann::ordered_j
SECTION("string")
{
Json j_nonobject(Json::value_t::string);
const Json j_nonobject_const(j_nonobject);
const Json j_nonobject_const(j_nonobject); // NOLINT(performance-unnecessary-copy-initialization)
CHECK_THROWS_WITH_AS(j_nonobject.at("foo"), "[json.exception.type_error.304] cannot use at() with string", typename Json::type_error&);
CHECK_THROWS_WITH_AS(j_nonobject_const.at("foo"), "[json.exception.type_error.304] cannot use at() with string", typename Json::type_error&);
@@ -127,7 +127,7 @@ TEST_CASE_TEMPLATE("element access 2", Json, nlohmann::json, nlohmann::ordered_j
SECTION("array")
{
Json j_nonobject(Json::value_t::array);
const Json j_nonobject_const(j_nonobject);
const Json j_nonobject_const(j_nonobject); // NOLINT(performance-unnecessary-copy-initialization)
CHECK_THROWS_WITH_AS(j_nonobject.at("foo"), "[json.exception.type_error.304] cannot use at() with array", typename Json::type_error&);
CHECK_THROWS_WITH_AS(j_nonobject_const.at("foo"), "[json.exception.type_error.304] cannot use at() with array", typename Json::type_error&);
@@ -140,7 +140,7 @@ TEST_CASE_TEMPLATE("element access 2", Json, nlohmann::json, nlohmann::ordered_j
SECTION("number (integer)")
{
Json j_nonobject(Json::value_t::number_integer);
const Json j_nonobject_const(j_nonobject);
const Json j_nonobject_const(j_nonobject); // NOLINT(performance-unnecessary-copy-initialization)
CHECK_THROWS_WITH_AS(j_nonobject.at("foo"), "[json.exception.type_error.304] cannot use at() with number", typename Json::type_error&);
CHECK_THROWS_WITH_AS(j_nonobject_const.at("foo"), "[json.exception.type_error.304] cannot use at() with number", typename Json::type_error&);
@@ -153,7 +153,7 @@ TEST_CASE_TEMPLATE("element access 2", Json, nlohmann::json, nlohmann::ordered_j
SECTION("number (unsigned)")
{
Json j_nonobject(Json::value_t::number_unsigned);
const Json j_nonobject_const(j_nonobject);
const Json j_nonobject_const(j_nonobject); // NOLINT(performance-unnecessary-copy-initialization)
CHECK_THROWS_WITH_AS(j_nonobject.at("foo"), "[json.exception.type_error.304] cannot use at() with number", typename Json::type_error&);
CHECK_THROWS_WITH_AS(j_nonobject_const.at("foo"), "[json.exception.type_error.304] cannot use at() with number", typename Json::type_error&);
@@ -166,7 +166,7 @@ TEST_CASE_TEMPLATE("element access 2", Json, nlohmann::json, nlohmann::ordered_j
SECTION("number (floating-point)")
{
Json j_nonobject(Json::value_t::number_float);
const Json j_nonobject_const(j_nonobject);
const Json j_nonobject_const(j_nonobject); // NOLINT(performance-unnecessary-copy-initialization)
CHECK_THROWS_WITH_AS(j_nonobject.at("foo"), "[json.exception.type_error.304] cannot use at() with number", typename Json::type_error&);
CHECK_THROWS_WITH_AS(j_nonobject_const.at("foo"), "[json.exception.type_error.304] cannot use at() with number", typename Json::type_error&);
@@ -1461,7 +1461,7 @@ TEST_CASE_TEMPLATE("element access 2", Json, nlohmann::json, nlohmann::ordered_j
}
#if !defined(JSON_NOEXCEPTION)
TEST_CASE_TEMPLATE("element access 2 (throwing tests)", Json, nlohmann::json, nlohmann::ordered_json)
TEST_CASE_TEMPLATE("element access 2 (throwing tests)", Json, nlohmann::json, nlohmann::ordered_json) // NOLINT(readability-math-missing-parentheses)
{
SECTION("object")
{
@@ -1497,7 +1497,7 @@ TEST_CASE_TEMPLATE("element access 2 (throwing tests)", Json, nlohmann::json, nl
#endif
// TODO(falbrechtskirchinger) merge with the other test case; clean up
TEST_CASE_TEMPLATE("element access 2 (additional value() tests)", Json, nlohmann::json, nlohmann::ordered_json)
TEST_CASE_TEMPLATE("element access 2 (additional value() tests)", Json, nlohmann::json, nlohmann::ordered_json) // NOLINT(readability-math-missing-parentheses)
{
using string_t = typename Json::string_t;
using number_integer_t = typename Json::number_integer_t;
+1 -1
View File
@@ -1305,7 +1305,7 @@ TEST_CASE("JSON patch")
const auto& doc = test["doc"];
const auto& patch = test["patch"];
if (test.count("error") == 0)
if (test.count("error") == 0) // NOLINT(readability-container-contains)
{
// if an expected value is given, use it; use doc otherwise
const auto& expected = test.value("expected", doc);
+2 -2
View File
@@ -281,7 +281,7 @@ TEST_CASE("MessagePack")
// check individual bytes
CHECK(result[0] == 0xcd);
auto const restored = static_cast<uint16_t>(static_cast<uint8_t>(result[1]) * 256 + static_cast<uint8_t>(result[2]));
auto const restored = static_cast<uint16_t>((static_cast<uint8_t>(result[1]) * 256) + static_cast<uint8_t>(result[2]));
CHECK(restored == i);
// roundtrip
@@ -671,7 +671,7 @@ TEST_CASE("MessagePack")
// check individual bytes
CHECK(result[0] == 0xcd);
auto const restored = static_cast<uint16_t>(static_cast<uint8_t>(result[1]) * 256 + static_cast<uint8_t>(result[2]));
auto const restored = static_cast<uint16_t>((static_cast<uint8_t>(result[1]) * 256) + static_cast<uint8_t>(result[2]));
CHECK(restored == i);
// roundtrip
+1 -1
View File
@@ -171,7 +171,7 @@ TEST_CASE("README" * doctest::skip())
// find an entry
CHECK(o.find("foo") != o.end());
if (o.find("foo") != o.end())
if (o.find("foo") != o.end()) // NOLINT(readability-container-contains)
{
// there is an entry with key "foo"
}
+5 -5
View File
@@ -94,14 +94,14 @@ struct Data
std::string b{}; // NOLINT(readability-redundant-member-init)
};
void from_json(const json& j, Data& data);
void from_json(const json& j, Data& data); // NOLINT(misc-use-internal-linkage)
void from_json(const json& j, Data& data)
{
j["a"].get_to(data.a);
j["b"].get_to(data.b);
}
bool operator==(Data const& lhs, Data const& rhs);
bool operator==(Data const& lhs, Data const& rhs); // NOLINT(misc-use-internal-linkage)
bool operator==(Data const& lhs, Data const& rhs)
{
return lhs.a == rhs.a && lhs.b == rhs.b;
@@ -221,7 +221,7 @@ class FooBar
Foo foo{}; // NOLINT(readability-redundant-member-init)
};
inline void from_json(const nlohmann::json& j, FooBar& fb)
inline void from_json(const nlohmann::json& j, FooBar& fb) // NOLINT(misc-use-internal-linkage)
{
j.at("value").get_to(fb.foo.value);
}
@@ -249,7 +249,7 @@ struct for_3171_derived : public for_3171_base
explicit for_3171_derived(const std::string& /*unused*/) { }
};
inline void from_json(const json& j, for_3171_base& tb)
inline void from_json(const json& j, for_3171_base& tb) // NOLINT(misc-use-internal-linkage)
{
tb._from_json(j);
}
@@ -264,7 +264,7 @@ struct for_3312
std::string name;
};
inline void from_json(const json& j, for_3312& obj)
inline void from_json(const json& j, for_3312& obj) // NOLINT(misc-use-internal-linkage)
{
j.at("name").get_to(obj.name);
}
+1 -1
View File
@@ -165,7 +165,7 @@ TEST_CASE("serialization")
}
}
TEST_CASE_TEMPLATE("serialization for extreme integer values", T, int32_t, uint32_t, int64_t, uint64_t)
TEST_CASE_TEMPLATE("serialization for extreme integer values", T, int32_t, uint32_t, int64_t, uint64_t) // NOLINT(readability-math-missing-parentheses)
{
SECTION("minimum")
{
+2 -2
View File
@@ -163,7 +163,7 @@ TEST_CASE("compliance tests from nativejson-benchmark")
TEST_DOUBLE("[2.2250738585072012e-308]",
2.2250738585072014e-308);
// More closer to normal/subnormal boundary
// Closer to normal/subnormal boundary
// boundary = 2^-1022 - 2^-1075 = 2.225073858507201136057409796709131975934819546351645648... ¡Á 10^-308
TEST_DOUBLE("[2.22507385850720113605740979670913197593481954635164564e-308]",
2.2250738585072009e-308);
@@ -312,7 +312,7 @@ TEST_CASE("test suite from json-test-suite")
{
SECTION("read all sample.json")
{
// read a file with all unicode characters stored as single-character
// read a file with all Unicode characters stored as single-character
// strings in a JSON array
std::ifstream f(TEST_DATA_DIRECTORY "/json_testsuite/sample.json");
json j;
+2 -2
View File
@@ -450,7 +450,7 @@ TEST_CASE("UBJSON")
// check individual bytes
CHECK(result[0] == 'I');
auto const restored = static_cast<uint16_t>(static_cast<uint8_t>(result[1]) * 256 + static_cast<uint8_t>(result[2]));
auto const restored = static_cast<uint16_t>((static_cast<uint8_t>(result[1]) * 256) + static_cast<uint8_t>(result[2]));
CHECK(restored == i);
// roundtrip
@@ -655,7 +655,7 @@ TEST_CASE("UBJSON")
// check individual bytes
CHECK(result[0] == 'I');
auto const restored = static_cast<uint16_t>(static_cast<uint8_t>(result[1]) * 256 + static_cast<uint8_t>(result[2]));
auto const restored = static_cast<uint16_t>((static_cast<uint8_t>(result[1]) * 256) + static_cast<uint8_t>(result[2]));
CHECK(restored == i);
// roundtrip
+6 -6
View File
@@ -442,7 +442,7 @@ NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_ONLY_SERIALIZE(person_without_default_constru
} // namespace persons
TEST_CASE_TEMPLATE("Serialization/deserialization via NLOHMANN_DEFINE_TYPE_INTRUSIVE and NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE", T,
TEST_CASE_TEMPLATE("Serialization/deserialization via NLOHMANN_DEFINE_TYPE_INTRUSIVE and NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE", T, // NOLINT(readability-math-missing-parentheses)
persons::person_with_private_data,
persons::person_without_private_data_1,
persons::person_without_private_data_2)
@@ -498,7 +498,7 @@ TEST_CASE_TEMPLATE("Serialization/deserialization via NLOHMANN_DEFINE_DERIVED_TY
}
}
TEST_CASE_TEMPLATE("Serialization/deserialization via NLOHMANN_DEFINE_DERIVED_TYPE_INTRUSIVE and NLOHMANN_DEFINE_DERIVED_TYPE_NON_INTRUSIVE", T,
TEST_CASE_TEMPLATE("Serialization/deserialization via NLOHMANN_DEFINE_DERIVED_TYPE_INTRUSIVE and NLOHMANN_DEFINE_DERIVED_TYPE_NON_INTRUSIVE", T, // NOLINT(readability-math-missing-parentheses)
persons::derived_person_with_private_data,
persons::derived_person_without_private_data_1,
persons::derived_person_without_private_data_2)
@@ -524,7 +524,7 @@ TEST_CASE_TEMPLATE("Serialization/deserialization via NLOHMANN_DEFINE_DERIVED_TY
}
}
TEST_CASE_TEMPLATE("Serialization/deserialization via NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT and NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT", T,
TEST_CASE_TEMPLATE("Serialization/deserialization via NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT and NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT", T, // NOLINT(readability-math-missing-parentheses)
persons::person_with_private_data_2,
persons::person_without_private_data_3)
{
@@ -558,7 +558,7 @@ TEST_CASE_TEMPLATE("Serialization/deserialization via NLOHMANN_DEFINE_TYPE_INTRU
}
}
TEST_CASE_TEMPLATE("Serialization/deserialization via NLOHMANN_DEFINE_DERIVED_TYPE_INTRUSIVE_WITH_DEFAULT and NLOHMANN_DEFINE_DERIVED_TYPE_NON_INTRUSIVE_WITH_DEFAULT", T,
TEST_CASE_TEMPLATE("Serialization/deserialization via NLOHMANN_DEFINE_DERIVED_TYPE_INTRUSIVE_WITH_DEFAULT and NLOHMANN_DEFINE_DERIVED_TYPE_NON_INTRUSIVE_WITH_DEFAULT", T, // NOLINT(readability-math-missing-parentheses)
persons::derived_person_with_private_data_2,
persons::derived_person_without_private_data_3)
{
@@ -594,7 +594,7 @@ TEST_CASE_TEMPLATE("Serialization/deserialization via NLOHMANN_DEFINE_DERIVED_TY
}
}
TEST_CASE_TEMPLATE("Serialization/deserialization of classes with 26 public/private member variables via NLOHMANN_DEFINE_TYPE_INTRUSIVE and NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE", T,
TEST_CASE_TEMPLATE("Serialization/deserialization of classes with 26 public/private member variables via NLOHMANN_DEFINE_TYPE_INTRUSIVE and NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE", T, // NOLINT(readability-math-missing-parentheses)
persons::person_with_private_alphabet,
persons::person_with_public_alphabet)
{
@@ -666,7 +666,7 @@ TEST_CASE_TEMPLATE("Serialization/deserialization of classes with 26 public/priv
}
}
TEST_CASE_TEMPLATE("Serialization of non-default-constructible classes via NLOHMANN_DEFINE_TYPE_INTRUSIVE_ONLY_SERIALIZE and NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_ONLY_SERIALIZE", T,
TEST_CASE_TEMPLATE("Serialization of non-default-constructible classes via NLOHMANN_DEFINE_TYPE_INTRUSIVE_ONLY_SERIALIZE and NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_ONLY_SERIALIZE", T, // NOLINT(readability-math-missing-parentheses)
persons::person_without_default_constructor_1,
persons::person_without_default_constructor_2)
{
+1 -1
View File
@@ -155,7 +155,7 @@ TEST_CASE("Unicode (1/5)" * doctest::skip())
SECTION("read all unicode characters")
{
// read a file with all unicode characters stored as single-character
// read a file with all Unicode characters stored as single-character
// strings in a JSON array
std::ifstream f(TEST_DATA_DIRECTORY "/json_nlohmann_tests/all_unicode.json");
json j;