summaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
authorSamuel Gaist <samuel.gaist@idiap.ch>2019-06-18 00:07:54 +0200
committerSamuel Gaist <samuel.gaist@idiap.ch>2019-10-16 21:53:30 +0200
commitc222a9283d94ad1e29334bb2fba0beef7cc716c7 (patch)
tree20a72a144a7006cc737cdb1e74a5663c41c5d5cd /tests/auto
parent85ed676dff68b4d5cfa62112d758d80fb050594c (diff)
QAbstractItemModel: implement QRegularExpression support for match
This is part of the migration of qtbase from QRexExp to QRegularExpression. [ChangeLog][QtCore][QAbstractItemModel] The match() method now supports the new Qt::RegularExpression match flag value. This will allow users to use either a string or a fully configured QRegularExpression when doing searches. In the second case, the case sensitivity flag will be ignored if passed. Task-number: QTBUG-72587 Change-Id: I07c8d72a661c48b7f4fcf13ef8e95980bcdcb998 Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/corelib/itemmodels/qabstractitemmodel/tst_qabstractitemmodel.cpp28
1 files changed, 28 insertions, 0 deletions
diff --git a/tests/auto/corelib/itemmodels/qabstractitemmodel/tst_qabstractitemmodel.cpp b/tests/auto/corelib/itemmodels/qabstractitemmodel/tst_qabstractitemmodel.cpp
index f305edb2c5..9fab36deaa 100644
--- a/tests/auto/corelib/itemmodels/qabstractitemmodel/tst_qabstractitemmodel.cpp
+++ b/tests/auto/corelib/itemmodels/qabstractitemmodel/tst_qabstractitemmodel.cpp
@@ -458,6 +458,34 @@ void tst_QAbstractItemModel::match()
res = model.match(start, Qt::DisplayRole, QVariant("bat"), -1,
Qt::MatchFixedString | Qt::MatchCaseSensitive);
QCOMPARE(res.count(), 1);
+
+ res = model.match(start, Qt::DisplayRole, QVariant(".*O.*"), -1,
+ Qt::MatchRegularExpression);
+ QCOMPARE(res.count(), 2);
+ res = model.match(start, Qt::DisplayRole, QVariant(".*O.*"), -1,
+ Qt::MatchRegularExpression | Qt::MatchCaseSensitive);
+ QCOMPARE(res.count(), 0);
+
+ res = model.match(start, Qt::DisplayRole, QVariant(QRegularExpression(".*O.*")),
+ -1, Qt::MatchRegularExpression);
+ QCOMPARE(res.count(), 0);
+ res = model.match(start,
+ Qt::DisplayRole,
+ QVariant(QRegularExpression(".*O.*",
+ QRegularExpression::CaseInsensitiveOption)),
+ -1,
+ Qt::MatchRegularExpression);
+ QCOMPARE(res.count(), 2);
+
+ // Ensure that the case sensitivity is properly ignored when passing a
+ // QRegularExpression object.
+ res = model.match(start,
+ Qt::DisplayRole,
+ QVariant(QRegularExpression(".*O.*",
+ QRegularExpression::CaseInsensitiveOption)),
+ -1,
+ Qt::MatchRegularExpression | Qt::MatchCaseSensitive);
+ QCOMPARE(res.count(), 2);
}
typedef QPair<int, int> Position;