summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/tools/qregularexpression
diff options
context:
space:
mode:
authorGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>2012-12-16 15:05:19 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-01-07 16:11:19 +0100
commit998899cf3a2501d3bf30ad06ce47a2cf81e1d60b (patch)
tree141fb19b0b2114d7690e366bfaf49e6c68e84fac /tests/auto/corelib/tools/qregularexpression
parentbc5a2336ab9a681411a81a53d8639b4b79f80073 (diff)
Introduce QRegularExpression::NoMatch match type
This match type doesn't do any match at all; it's only necessary to properly introduce default constructors for QRegularExpressionMatch and QRegularExpressionMatchIterator (since they return the match type that created them). Change-Id: Ibfe92459c7fdd23129cf3afe073cd443c461ddeb Reviewed-by: Lars Knoll <lars.knoll@digia.com>
Diffstat (limited to 'tests/auto/corelib/tools/qregularexpression')
-rw-r--r--tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.cpp88
1 files changed, 67 insertions, 21 deletions
diff --git a/tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.cpp b/tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.cpp
index 8cb43a677d..8b91d1c35d 100644
--- a/tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.cpp
+++ b/tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.cpp
@@ -127,8 +127,6 @@ bool operator!=(const Match &m, const QRegularExpressionMatch &rem)
bool operator==(const QRegularExpressionMatchIterator &iterator, const QList<Match> &expectedMatchList)
{
QRegularExpressionMatchIterator i = iterator;
- if (i.isValid() != (!expectedMatchList.isEmpty()))
- return false;
foreach (const Match &expectedMatch, expectedMatchList)
{
@@ -694,15 +692,31 @@ void tst_QRegularExpression::normalMatch()
QFETCH(QRegularExpression::MatchOptions, matchOptions);
QFETCH(Match, match);
- QRegularExpressionMatch m = regexp.match(subject, offset, QRegularExpression::NormalMatch, matchOptions);
- consistencyCheck(m);
- QVERIFY(m == match);
- QCOMPARE(m.regularExpression(), regexp);
- QCOMPARE(m.matchType(), QRegularExpression::NormalMatch);
- QCOMPARE(m.matchOptions(), matchOptions);
+ {
+ QRegularExpressionMatch m = regexp.match(subject, offset, QRegularExpression::NormalMatch, matchOptions);
+ consistencyCheck(m);
+ QVERIFY(m == match);
+ QCOMPARE(m.regularExpression(), regexp);
+ QCOMPARE(m.matchType(), QRegularExpression::NormalMatch);
+ QCOMPARE(m.matchOptions(), matchOptions);
+ }
+ {
+ // ignore the expected results provided by the match object --
+ // we'll never get any result when testing the NoMatch type.
+ // Just check the validity of the match here.
+ Match realMatch;
+ realMatch.clear();
+ realMatch.isValid = match.isValid;
+
+ QRegularExpressionMatch m = regexp.match(subject, offset, QRegularExpression::NoMatch, matchOptions);
+ consistencyCheck(m);
+ QVERIFY(m == realMatch);
+ QCOMPARE(m.regularExpression(), regexp);
+ QCOMPARE(m.matchType(), QRegularExpression::NoMatch);
+ QCOMPARE(m.matchOptions(), matchOptions);
+ }
}
-
void tst_QRegularExpression::partialMatch_data()
{
QTest::addColumn<QRegularExpression>("regexp");
@@ -956,12 +970,29 @@ void tst_QRegularExpression::partialMatch()
QFETCH(QRegularExpression::MatchOptions, matchOptions);
QFETCH(Match, match);
- QRegularExpressionMatch m = regexp.match(subject, offset, matchType, matchOptions);
- consistencyCheck(m);
- QVERIFY(m == match);
- QCOMPARE(m.regularExpression(), regexp);
- QCOMPARE(m.matchType(), matchType);
- QCOMPARE(m.matchOptions(), matchOptions);
+ {
+ QRegularExpressionMatch m = regexp.match(subject, offset, matchType, matchOptions);
+ consistencyCheck(m);
+ QVERIFY(m == match);
+ QCOMPARE(m.regularExpression(), regexp);
+ QCOMPARE(m.matchType(), matchType);
+ QCOMPARE(m.matchOptions(), matchOptions);
+ }
+ {
+ // ignore the expected results provided by the match object --
+ // we'll never get any result when testing the NoMatch type.
+ // Just check the validity of the match here.
+ Match realMatch;
+ realMatch.clear();
+ realMatch.isValid = match.isValid;
+
+ QRegularExpressionMatch m = regexp.match(subject, offset, QRegularExpression::NoMatch, matchOptions);
+ consistencyCheck(m);
+ QVERIFY(m == realMatch);
+ QCOMPARE(m.regularExpression(), regexp);
+ QCOMPARE(m.matchType(), QRegularExpression::NoMatch);
+ QCOMPARE(m.matchOptions(), matchOptions);
+ }
}
void tst_QRegularExpression::globalMatch_data()
@@ -1230,13 +1261,28 @@ void tst_QRegularExpression::globalMatch()
QFETCH(QRegularExpression::MatchType, matchType);
QFETCH(QRegularExpression::MatchOptions, matchOptions);
QFETCH(QList<Match>, matchList);
+ {
+ QRegularExpressionMatchIterator iterator = regexp.globalMatch(subject, offset, matchType, matchOptions);
+ consistencyCheck(iterator);
+ QVERIFY(iterator == matchList);
+ QCOMPARE(iterator.regularExpression(), regexp);
+ QCOMPARE(iterator.matchType(), matchType);
+ QCOMPARE(iterator.matchOptions(), matchOptions);
+ }
+ {
+ // ignore the expected results provided by the match object --
+ // we'll never get any result when testing the NoMatch type.
+ // Just check the validity of the match here.
+ QList<Match> realMatchList;
+
+ QRegularExpressionMatchIterator iterator = regexp.globalMatch(subject, offset, QRegularExpression::NoMatch, matchOptions);
+ consistencyCheck(iterator);
+ QVERIFY(iterator == realMatchList);
+ QCOMPARE(iterator.regularExpression(), regexp);
+ QCOMPARE(iterator.matchType(), QRegularExpression::NoMatch);
+ QCOMPARE(iterator.matchOptions(), matchOptions);
+ }
- QRegularExpressionMatchIterator iterator = regexp.globalMatch(subject, offset, matchType, matchOptions);
- consistencyCheck(iterator);
- QVERIFY(iterator == matchList);
- QCOMPARE(iterator.regularExpression(), regexp);
- QCOMPARE(iterator.matchType(), matchType);
- QCOMPARE(iterator.matchOptions(), matchOptions);
}
void tst_QRegularExpression::serialize_data()