Skip to content

Commit e58b1d6

Browse files
committed
Avoid escaped literals in the counted-iterator diagnostics list
clang-tidy reads "[\"\\ud834\"]" as a literal better written raw, and the two literals written next to each other in "[\"a\x01""b\"]" as a missing comma. The concatenation was there to stop the hex escape swallowing the following character; build those documents from explicit bytes instead and use raw strings elsewhere. The byte sequences are unchanged. Signed-off-by: Niels Lohmann <mail@nlohmann.me>
1 parent 5edfcca commit e58b1d6

1 file changed

Lines changed: 21 additions & 6 deletions

File tree

tests/src/unit-user_defined_input.cpp

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -266,13 +266,28 @@ TEST_CASE("std::counted_iterator reaches the contiguous fast paths")
266266
// already-consumed input (supports_seek), a path a sized sentinel only
267267
// reaches now; check a few that include the "last read" text. Parsing
268268
// invalid input aborts when exceptions are off, hence the guard.
269-
for (const char* doc :
270-
{"1\nx", "truX", "[tru]", "\"abc", "[\"\\ud834\"]", "[\"a\x01""b\"]",
271-
"[\"\xc3\x28\"]", "[1e]", "[\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaX"
272-
})
269+
// Raw strings and explicit bytes: an escaped literal and two literals
270+
// written next to each other both read as mistakes to static analysis.
271+
const auto byte = [](int value)
273272
{
274-
CAPTURE(doc);
275-
const std::string text = doc;
273+
return std::string(1, static_cast<char>(value));
274+
};
275+
const std::vector<std::string> diagnostic_docs =
276+
{
277+
"1\nx",
278+
"truX",
279+
"[tru]",
280+
R"("abc)",
281+
R"(["\ud834"])",
282+
R"(["a)" + byte(0x01) + R"(b"])",
283+
R"([")" + byte(0xC3) + byte(0x28) + R"("])",
284+
"[1e]",
285+
R"(["aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaX)"
286+
};
287+
288+
for (const auto& text : diagnostic_docs)
289+
{
290+
CAPTURE(text);
276291
const std::counted_iterator<const char*> it(text.data(), static_cast<std::iter_difference_t<const char*>>(text.size()));
277292
std::string counted_message;
278293
std::string string_message;

0 commit comments

Comments
 (0)