summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorGiuseppe D'Angelo <dangelog@gmail.com>2012-02-26 22:37:45 +0000
committerQt by Nokia <qt-info@nokia.com>2012-03-08 22:00:53 +0100
commit824cc9492144dff2494645319854cb68ba5570c6 (patch)
tree9dda541412826c98e0c8b39c7ed0671977391d56 /tests
parentb5431419923e8f00e2d8a4a75a20f75f66241842 (diff)
QRegularExpression: minor fix to captureIndexForName
Although passing a null pointer to pcre16_get_stringnumber for the compiled pattern should simply make it error out, it's actually an undocumented behaviour, so let's stay safe and add an explicit check. Tests for this codepath are added. Change-Id: Ifd9c87874f6812ba487104ec1a5bbc83c3b16761 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.cpp58
-rw-r--r--tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.h2
2 files changed, 59 insertions, 1 deletions
diff --git a/tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.cpp b/tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.cpp
index 38b82ecf77..a4c04d6207 100644
--- a/tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.cpp
+++ b/tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.cpp
@@ -95,8 +95,13 @@ bool operator==(const QRegularExpressionMatch &rem, const Match &m)
}
Q_FOREACH (const QString &name, m.namedCaptured.keys()) {
- if (rem.captured(name) != m.namedCaptured.value(name))
+ QString remCaptured = rem.captured(name);
+ QString mCaptured = m.namedCaptured.value(name);
+ if (remCaptured != mCaptured
+ || remCaptured.isNull() != mCaptured.isNull()
+ || remCaptured.isEmpty() != mCaptured.isEmpty()) {
return false;
+ }
}
}
@@ -571,6 +576,32 @@ void tst_QRegularExpression::normalMatch_data()
<< QRegularExpression::MatchOptions(QRegularExpression::NoMatchOption)
<< m;
+ // non existing names for capturing groups
+ m.clear();
+ m.isValid = true; m.hasMatch = true;
+ m.captured << "a string" << "a" << "string";
+ m.namedCaptured["article"] = "a";
+ m.namedCaptured["noun"] = "string";
+ m.namedCaptured["nonexisting1"] = QString();
+ m.namedCaptured["nonexisting2"] = QString();
+ m.namedCaptured["nonexisting3"] = QString();
+ QTest::newRow("match10") << QRegularExpression("(?<article>\\w+) (?<noun>\\w+)")
+ << "a string"
+ << 0
+ << QRegularExpression::MatchOptions(QRegularExpression::NoMatchOption)
+ << m;
+
+ m.clear();
+ m.isValid = true; m.hasMatch = true;
+ m.captured << "" << "";
+ m.namedCaptured["digits"] = ""; // empty VS null
+ m.namedCaptured["nonexisting"] = QString();
+ QTest::newRow("match11") << QRegularExpression("(?<digits>\\d*)")
+ << "abcde"
+ << 0
+ << QRegularExpression::MatchOptions(QRegularExpression::NoMatchOption)
+ << m;
+
// ***
m.clear();
@@ -1223,3 +1254,28 @@ void tst_QRegularExpression::pcreJitStackUsage()
consistencyCheck(match);
}
}
+
+void tst_QRegularExpression::regularExpressionMatch_data()
+{
+ QTest::addColumn<QString>("pattern");
+ QTest::addColumn<QString>("subject");
+
+ QTest::newRow("validity01") << "(?<digits>\\d+)" << "1234 abcd";
+ QTest::newRow("validity02") << "(?<digits>\\d+) (?<alpha>\\w+)" << "1234 abcd";
+}
+
+void tst_QRegularExpression::regularExpressionMatch()
+{
+ QFETCH(QString, pattern);
+ QFETCH(QString, subject);
+
+ QRegularExpression re(pattern);
+ QVERIFY(re.isValid());
+ QRegularExpressionMatch match = re.match(subject);
+ consistencyCheck(match);
+ QCOMPARE(match.captured("non-existing").isNull(), true);
+ QTest::ignoreMessage(QtWarningMsg, "QRegularExpressionMatch::captured: empty capturing group name passed");
+ QCOMPARE(match.captured("").isNull(), true);
+ QTest::ignoreMessage(QtWarningMsg, "QRegularExpressionMatch::captured: empty capturing group name passed");
+ QCOMPARE(match.captured(QString()).isNull(), true);
+}
diff --git a/tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.h b/tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.h
index fd8bdfa3af..72a19199fd 100644
--- a/tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.h
+++ b/tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.h
@@ -73,6 +73,8 @@ private slots:
void captureCount();
void pcreJitStackUsage_data();
void pcreJitStackUsage();
+ void regularExpressionMatch_data();
+ void regularExpressionMatch();
private:
void provideRegularExpressions();