summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/text/qstringapisymmetry/tst_qstringapisymmetry.cpp
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@qt.io>2021-12-01 17:37:59 +0100
committerMarc Mutz <marc.mutz@qt.io>2021-12-02 16:05:33 +0000
commitecc307ff41884d04ffc71d70968891f7903e22f3 (patch)
treec5db1b83c8aae575c852dc83b62d6afa34494852 /tests/auto/corelib/text/qstringapisymmetry/tst_qstringapisymmetry.cpp
parent093a62a69ad530cb3ffefafbcff9ea28ed3dd134 (diff)
QString et al: fix lastIndexOf() API asymmetry
Commit 6cee204d56205e250b0675c9c6d4dd8a2367f3c4 introduced overloads of lastIndexOf() which drop the 'from' argument, inadvertently fixing QTBUG-80694, but failed to provide the new overloads for all existing lastIndexOf() overloads, making the fix for QTBUG-80694 incomplete. This patch completes the fix, by adding the missing overloads (for char-likes) and also adds the missing (non-regex) tests to tst_qstringapisymmetry. Also amends 1c164ec7f21a78025475c561a70b94d1e3dd6bb6. Fixes: QTBUG-80694 Change-Id: Ib4b3d597d658ce2edf01a2bce0d711ecea593d6e Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'tests/auto/corelib/text/qstringapisymmetry/tst_qstringapisymmetry.cpp')
-rw-r--r--tests/auto/corelib/text/qstringapisymmetry/tst_qstringapisymmetry.cpp16
1 files changed, 16 insertions, 0 deletions
diff --git a/tests/auto/corelib/text/qstringapisymmetry/tst_qstringapisymmetry.cpp b/tests/auto/corelib/text/qstringapisymmetry/tst_qstringapisymmetry.cpp
index a64811cea4..c1795791c5 100644
--- a/tests/auto/corelib/text/qstringapisymmetry/tst_qstringapisymmetry.cpp
+++ b/tests/auto/corelib/text/qstringapisymmetry/tst_qstringapisymmetry.cpp
@@ -913,6 +913,15 @@ private Q_SLOTS:
void isValidUtf8_QUtf8StringView() { isValidUtf8_impl<QUtf8StringView>(); }
};
+namespace help {
+
+template <typename T> constexpr qsizetype size(const T &s) { return qsizetype(s.size()); }
+
+template <> constexpr qsizetype size(const QChar&) { return 1; }
+template <> constexpr qsizetype size(const QLatin1Char&) { return 1; }
+template <> constexpr qsizetype size(const char16_t&) { return 1; }
+} // namespace help
+
namespace {
void overload_s_a(const QString &) {}
@@ -2638,6 +2647,13 @@ void tst_QStringApiSymmetry::lastIndexOf_impl() const
QCOMPARE(haystack.lastIndexOf(needle, startpos, Qt::CaseSensitive), size_type(resultCS));
QCOMPARE(haystack.lastIndexOf(needle, startpos, Qt::CaseInsensitive), size_type(resultCIS));
+ if (startpos == haystack.size() ||
+ (startpos == -1 && help::size(needle) > 0)) { // -1 skips past-the-end-match w/empty needle
+ // check that calls without an explicit 'from' argument work, too:
+ QCOMPARE(haystack.lastIndexOf(needle), size_type(resultCS));
+ QCOMPARE(haystack.lastIndexOf(needle, Qt::CaseSensitive), size_type(resultCS));
+ QCOMPARE(haystack.lastIndexOf(needle, Qt::CaseInsensitive), size_type(resultCIS));
+ }
}
void tst_QStringApiSymmetry::indexOf_contains_lastIndexOf_count_regexp_data()