Fix test lints that are red on develop (effc++, clang-tidy) (#5946)

- unit-bson: initialize the SAX recorder's member (-Weffc++)
- unit-json_patch: build the reference document independently instead of
  copying it (performance-unnecessary-copy-initialization)
- unit-json_view_builder: use node_kind::link instead of an out-of-range
  enum cast (clang-analyzer-optin.core.EnumCastOutOfRange)

Signed-off-by: Niels Lohmann <mail@nlohmann.me>
This commit is contained in:
Niels Lohmann
2026-10-27 17:25:18 +01:00
committed by GitHub
parent eb8f675bc9
commit 8617d9c94c
3 changed files with 11 additions and 6 deletions
+1 -1
View File
@@ -1311,7 +1311,7 @@ TEST_CASE("BSON declared document size bounds the content")
// records the events that a SAX parser receives
struct recorder : nlohmann::json_sax<json>
{
std::string events;
std::string events {};
bool null() override
{
+8 -3
View File
@@ -2178,8 +2178,13 @@ TEST_CASE("JSON patch - behavior documented in the API reference")
SECTION("patch() has the strong guarantee")
{
const json doc = R"({"a": [1, 2], "o": {"k": "v"}})"_json;
const json before = doc;
// independent values, so that the comparison below checks the untouched document
const auto make_doc = []
{
return R"({"a": [1, 2], "o": {"k": "v"}})"_json;
};
const json doc = make_doc();
const json before = make_doc();
const std::vector<json> failing =
{
@@ -2202,7 +2207,7 @@ TEST_CASE("JSON patch - behavior documented in the API reference")
CHECK_THROWS_AS(doc.patch(patch), json::exception&);
CHECK(doc == before);
json copy = doc;
json copy = make_doc();
CHECK_THROWS_AS(copy.patch(patch), json::exception&);
CHECK(copy == before);
}
+2 -2
View File
@@ -592,7 +592,7 @@ TEST_CASE("json_view node integer bits")
})
{
CAPTURE(v)
n.kind = static_cast<nlohmann::detail::view::node_kind>(0x5A);
n.kind = nlohmann::detail::view::node_kind::link;
n.flags = 0xA5;
n.extra = 0x1234;
n.off = 0x89ABCDEFu;
@@ -601,7 +601,7 @@ TEST_CASE("json_view node integer bits")
CHECK(n.len == static_cast<std::uint32_t>(v));
CHECK(n.next == static_cast<std::uint32_t>(v >> 32));
// the other fields are untouched
CHECK(static_cast<std::uint8_t>(n.kind) == 0x5A);
CHECK(n.kind == nlohmann::detail::view::node_kind::link);
CHECK(n.flags == 0xA5);
CHECK(n.extra == 0x1234);
CHECK(n.off == 0x89ABCDEFu);