summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib
diff options
context:
space:
mode:
authorGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>2021-08-23 20:28:44 +0200
committerGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>2021-08-26 07:08:34 +0200
commitf0c2c987e3e7eb046303892b1eee4f848759923a (patch)
tree5665f9fbe969ebf17988a8ea984051e4cd3f47c7 /tests/auto/corelib
parenta2abb0145174a8ed82572a06e537f550a6777b08 (diff)
QBA(V)/QS(V)::lastIndexOf: fix the search of 1-char needles
When a needle has length 1 (because it's a QChar/char16_t, or because it's a string-like of length 1) then an ad-hoc search algorithm is used. This algorithm had a off-by-one, by not allowing to match at the last position of a haystack (in case `from` was `haystack.size()`). That is inconsistent with the general search of substring needles (and what QByteArray does). Fix that case and amend wrong tests. This in turn unveiled the fact that the algorithm was unable to cope with 0-length haystacks (whops), so fix that as well. Drive-by, add a similar fix for QByteArray. Amends 6cee204d56205e250b0675c9c6d4dd8a2367f3c4. Pick-to: 6.2 Change-Id: I6b3effc4ecd74bcbcd33dd2e550da2df7bf05ae3 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Diffstat (limited to 'tests/auto/corelib')
-rw-r--r--tests/auto/corelib/text/qstring/tst_qstring.cpp2
-rw-r--r--tests/auto/corelib/text/qstringapisymmetry/tst_qstringapisymmetry.cpp6
2 files changed, 4 insertions, 4 deletions
diff --git a/tests/auto/corelib/text/qstring/tst_qstring.cpp b/tests/auto/corelib/text/qstring/tst_qstring.cpp
index 7ad218be96..c2a7b93c7d 100644
--- a/tests/auto/corelib/text/qstring/tst_qstring.cpp
+++ b/tests/auto/corelib/text/qstring/tst_qstring.cpp
@@ -1723,7 +1723,7 @@ void tst_QString::lastIndexOf_data()
QTest::newRow("10") << a << "G" << -1 << int(a.size())-1 << true;
QTest::newRow("11") << a << "G" << int(a.size())-1 << int(a.size())-1 << true;
- QTest::newRow("12") << a << "G" << int(a.size()) << -1 << true;
+ QTest::newRow("12") << a << "G" << int(a.size()) << int(a.size())-1 << true;
QTest::newRow("13") << a << "A" << 0 << 0 << true;
QTest::newRow("14") << a << "A" << -1*int(a.size()) << 0 << true;
diff --git a/tests/auto/corelib/text/qstringapisymmetry/tst_qstringapisymmetry.cpp b/tests/auto/corelib/text/qstringapisymmetry/tst_qstringapisymmetry.cpp
index 88ccc8d3bf..3447af88eb 100644
--- a/tests/auto/corelib/text/qstringapisymmetry/tst_qstringapisymmetry.cpp
+++ b/tests/auto/corelib/text/qstringapisymmetry/tst_qstringapisymmetry.cpp
@@ -2561,7 +2561,7 @@ void tst_QStringApiSymmetry::lastIndexOf_data(bool rhsHasVariableLength)
}
#define ROW(h, n, st, cs, cis) \
- QTest::addRow("haystack: %s, needle: %s", #h, #n) << h << QLatin1String(#h) \
+ QTest::addRow("haystack: %s, needle: %s, start %d", #h, #n, st) << h << QLatin1String(#h) \
<< n << QLatin1String(#n) \
<< qsizetype(st) << qsizetype(cs) << qsizetype(cis)
@@ -2578,8 +2578,8 @@ void tst_QStringApiSymmetry::lastIndexOf_data(bool rhsHasVariableLength)
ROW(ABCDEFGHIEfGEFG, g, 14, -1, 14);
ROW(ABCDEFGHIEfGEFG, G, 13, 11, 11);
ROW(ABCDEFGHIEfGEFG, g, 13, -1, 11);
- ROW(ABCDEFGHIEfGEFG, G, 15, -1, -1);
- ROW(ABCDEFGHIEfGEFG, g, 15, -1, -1);
+ ROW(ABCDEFGHIEfGEFG, G, 15, 14, 14);
+ ROW(ABCDEFGHIEfGEFG, g, 15, -1, 14);
ROW(ABCDEFGHIEfGEFG, B, 14, 1, 1);
ROW(ABCDEFGHIEfGEFG, b, 14, -1, 1);
ROW(ABCDEFGHIEfGEFG, B, -1, 1, 1);