summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/text/qstringapisymmetry/tst_qstringapisymmetry.cpp
diff options
context:
space:
mode:
authorEdward Welbourne <edward.welbourne@qt.io>2022-10-05 13:44:02 +0200
committerEdward Welbourne <edward.welbourne@qt.io>2022-10-17 15:53:32 +0200
commit5b70546c17043e8a761b10884b3d8d952053ddc2 (patch)
treeff0ece28d67e713d4229e26c3cf0711a233e2b4d /tests/auto/corelib/text/qstringapisymmetry/tst_qstringapisymmetry.cpp
parent781bd075a64dcde893680c1dd1d5a82e2bf02791 (diff)
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 <marc.mutz@qt.io>
Diffstat (limited to 'tests/auto/corelib/text/qstringapisymmetry/tst_qstringapisymmetry.cpp')
-rw-r--r--tests/auto/corelib/text/qstringapisymmetry/tst_qstringapisymmetry.cpp18
1 files 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<QString>("unicode");
QTest::addColumn<QAnyStringView>("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<const char> escaped(QTest::toString(unicode));
- QTest::addRow("%s", escaped.data()) << unicode << QAnyStringView(str);
- }
+ auto row = [&](QLatin1StringView spaces) {
+ const QString unicode = spaces + str + spaces;
+ const QScopedArrayPointer<const char> 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));
}
};