summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>2020-12-07 19:03:10 +0100
committerGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>2020-12-10 23:38:06 +0000
commitbe0301b42fcfa7ae21fef54f88995f2b0b1c573f (patch)
tree22fd93d022278d7197f582b50e185403c4d3743a /tests
parent1aa32ec1599c7102c4760440d4adb6a903358ca3 (diff)
QString: fix count(QRegularExpression)
There is an off by one in the implementation of count(): a match must be attempted even at the very end of the string, because a 0-length match can happen there. While at it, improve the documentation on the counter-intuitive behavior of count(), which doesn't merely count how many times a regexp matches into a string using ordinary global matching. [ChangeLog][QtCore][QString] Fixed a corner case when using QString::count(QRegularExpression), causing an empty in the last position not to be accounted for in the returned result. Change-Id: I064497839a96979abfbac2d0a96546ce160bbc46 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> (cherry picked from commit 7c3208c97d2ad2c046908e144325c4ddb1e54876)
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/corelib/text/qstring/tst_qstring.cpp1
1 files changed, 1 insertions, 0 deletions
diff --git a/tests/auto/corelib/text/qstring/tst_qstring.cpp b/tests/auto/corelib/text/qstring/tst_qstring.cpp
index ce091f6688..4c4a8f0416 100644
--- a/tests/auto/corelib/text/qstring/tst_qstring.cpp
+++ b/tests/auto/corelib/text/qstring/tst_qstring.cpp
@@ -1765,6 +1765,7 @@ void tst_QString::count()
QCOMPARE(a.count( "", Qt::CaseInsensitive), 16);
QCOMPARE(a.count(QRegExp("[FG][HI]")),1);
QCOMPARE(a.count(QRegExp("[G][HE]")),2);
+ QCOMPARE(a.count(QRegularExpression("")), 16);
QCOMPARE(a.count(QRegularExpression("[FG][HI]")), 1);
QCOMPARE(a.count(QRegularExpression("[G][HE]")), 2);
QTest::ignoreMessage(QtWarningMsg, "QString::count: invalid QRegularExpression object");