From ecc307ff41884d04ffc71d70968891f7903e22f3 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Wed, 1 Dec 2021 17:37:59 +0100 Subject: 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 --- .../text/qstringapisymmetry/tst_qstringapisymmetry.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'tests/auto/corelib/text/qstringapisymmetry/tst_qstringapisymmetry.cpp') 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(); } }; +namespace help { + +template 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() -- cgit v1.2.3