From 5b70546c17043e8a761b10884b3d8d952053ddc2 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Wed, 5 Oct 2022 13:44:02 +0200 Subject: [PATCH] tst_QStringApiSymmetry: avoid repetition in trimmed_data() Enclosing one string in each substring of another does not need to repeat the empty substring of the latter. Extracting the empty substring from different positions doesn't get different results. In the process, tidy up the code a bit. Change-Id: Ic66febbdadeaac0c466f4f1174d831a991d31e20 Reviewed-by: Marc Mutz --- .../tst_qstringapisymmetry.cpp | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/tests/auto/corelib/text/qstringapisymmetry/tst_qstringapisymmetry.cpp b/tests/auto/corelib/text/qstringapisymmetry/tst_qstringapisymmetry.cpp index 4c8e45f17e..235a1493dc 100644 --- a/tests/auto/corelib/text/qstringapisymmetry/tst_qstringapisymmetry.cpp +++ b/tests/auto/corelib/text/qstringapisymmetry/tst_qstringapisymmetry.cpp @@ -2466,18 +2466,20 @@ void tst_QStringApiSymmetry::trimmed_data() QTest::addColumn("unicode"); QTest::addColumn("result"); - const auto latin1Whitespace = QLatin1String(" \r\n\t\f\v"); + const auto latin1Whitespace = QLatin1StringView(" \r\n\t\f\v"); QTest::addRow("null") << QString() << QAnyStringView(); auto add = [latin1Whitespace](const QString &str) { - // run through all substrings of latin1Whitespace - for (int len = 0; len < latin1Whitespace.size(); ++len) { - for (int pos = 0; pos < latin1Whitespace.size() - len; ++pos) { - const QString unicode = latin1Whitespace.mid(pos, len) + str + latin1Whitespace.mid(pos, len); - const QScopedArrayPointer escaped(QTest::toString(unicode)); - QTest::addRow("%s", escaped.data()) << unicode << QAnyStringView(str); - } + auto row = [&](QLatin1StringView spaces) { + const QString unicode = spaces + str + spaces; + const QScopedArrayPointer escaped(QTest::toString(unicode)); + QTest::addRow("%s", escaped.data()) << unicode << QAnyStringView(str); + }; + row({}); // The len = 0 case of the following. + for (qsizetype len = 1; len < latin1Whitespace.size(); ++len) { + for (qsizetype pos = 0; pos < latin1Whitespace.size() - len; ++pos) + row (latin1Whitespace.mid(pos, len)); } };