Satisfy clang-tidy in the new bulk scanner tests

- give the helper lambdas an explicit std::string return type and return
  braced initializer lists (modernize-return-braced-init-list)
- replace the C-style array of test cases with a std::vector
  (modernize-avoid-c-arrays)
- silence pro-type-member-init on the two brace-initialized aggregates;
  default member initializers would stop them being aggregates in C++11

Signed-off-by: Niels Lohmann <mail@nlohmann.me>
This commit is contained in:
Niels Lohmann
2026-08-20 04:09:58 +02:00
parent a5e94f4e8b
commit 5edfccadf0
2 changed files with 21 additions and 17 deletions

View File

@@ -19,6 +19,8 @@
using nlohmann::json;
#include <list>
#include <string> // string
#include <vector> // vector
#if defined(__cpp_lib_concepts) && defined(JSON_HAS_CPP_20)
#include <iterator>
@@ -333,7 +335,7 @@ TEST_CASE("std::counted_iterator bulk scanning stops at the counted end")
// input: the bulk scanners must never look at the bytes behind it, even
// though they are readable. Each case is compared against parsing the
// equivalent prefix as a std::string.
const auto via_counted = [](const std::string & buf, std::size_t n)
const auto via_counted = [](const std::string & buf, std::size_t n) -> std::string
{
const std::counted_iterator<const char*> first(buf.data(), static_cast<std::iter_difference_t<const char*>>(n));
try
@@ -343,10 +345,10 @@ TEST_CASE("std::counted_iterator bulk scanning stops at the counted end")
}
catch (const json::parse_error& e)
{
return std::string(e.what());
return {e.what()};
}
};
const auto via_prefix = [](const std::string & buf, std::size_t n)
const auto via_prefix = [](const std::string & buf, std::size_t n) -> std::string
{
try
{
@@ -355,16 +357,16 @@ TEST_CASE("std::counted_iterator bulk scanning stops at the counted end")
}
catch (const json::parse_error& e)
{
return std::string(e.what());
return {e.what()};
}
};
struct testcase
struct testcase // NOLINT(cppcoreguidelines-pro-type-member-init,hicpp-member-init)
{
const char* buffer;
std::size_t count;
};
const testcase cases[] =
const std::vector<testcase> cases =
{
{"[\"abc\"]____TRAILING____", 7}, // exact fit, tail hidden
{"[\"abcdefghijklmnop\"]____", 8}, // cut inside a string