summaryrefslogtreecommitdiffstats
path: root/tests/auto/qregexp
diff options
context:
space:
mode:
authorBenjamin Poulain <benjamin.poulain@nokia.com>2009-09-16 20:46:10 +0200
committerBenjamin Poulain <benjamin.poulain@nokia.com>2009-09-17 09:37:17 +0200
commite7c36fc2e420f1cee4370020b9f50bb5a6dfe92a (patch)
treec3053cb018572650bf839195c5cc19092034dd71 /tests/auto/qregexp
parentdfcf988a3f0c88f96e202482e5d363d880b9d6d2 (diff)
Add a new wildcard mode similar to bash in QRegExp
It is not possible to escape a wildcard character in the Wildcard mode of QRegExp. This follows the kind of wildcard of the CLI of Windows The new WildCardUnix follows the escaping of a unix's bash. Task-number: 241346 Reviewed-by: Olivier Goffart Reviewed-by: Matthew Cattell
Diffstat (limited to 'tests/auto/qregexp')
-rw-r--r--tests/auto/qregexp/tst_qregexp.cpp75
1 files changed, 74 insertions, 1 deletions
diff --git a/tests/auto/qregexp/tst_qregexp.cpp b/tests/auto/qregexp/tst_qregexp.cpp
index 7496ec685c..86d831e8ad 100644
--- a/tests/auto/qregexp/tst_qregexp.cpp
+++ b/tests/auto/qregexp/tst_qregexp.cpp
@@ -70,6 +70,10 @@ private slots:
void matchedLength();
void wildcard_data();
void wildcard();
+ void testEscapingWildcard_data();
+ void testEscapingWildcard();
+ void testInvalidWildcard_data();
+ void testInvalidWildcard();
void caretAnchoredOptimization();
void isEmpty();
void prepareEngineOptimization();
@@ -909,10 +913,79 @@ void tst_QRegExp::wildcard()
QFETCH( int, foundIndex );
QRegExp r( rxp );
- r.setPatternSyntax(QRegExp::Wildcard);
+ r.setPatternSyntax(QRegExp::WildcardUnix);
QCOMPARE( r.indexIn( string ), foundIndex );
}
+void tst_QRegExp::testEscapingWildcard_data(){
+ QTest::addColumn<QString>("pattern");
+ QTest::addColumn<QString>("teststring");
+ QTest::addColumn<bool>("isMatching");
+
+ QTest::newRow("[ Not escaped") << "[Qt;" << "[Qt;" << false;
+ QTest::newRow("[ Escaped") << "\\[Qt;" << "[Qt;" << true;
+
+ QTest::newRow("] Not escaped") << "]Ik;" << "]Ik;" << false;
+ QTest::newRow("] Escaped") << "\\]Ip;" << "]Ip;" << true;
+
+ QTest::newRow("? Not escaped valid") << "?Ou:" << ".Ou:" << true;
+ QTest::newRow("? Not escaped invalid") << "?Tr;" << "Tr;" << false;
+ QTest::newRow("? Escaped") << "\\?O;" << "?O;" << true;
+
+ QTest::newRow("[] not escaped") << "[lL]" << "l" << true;
+ QTest::newRow("case [[]") << "[[abc]" << "[" << true;
+ QTest::newRow("case []abc] match ]") << "[]abc]" << "]" << true;
+ QTest::newRow("case []abc] match a") << "[]abc]" << "a" << true;
+ QTest::newRow("case [abc] match a") << "[abc]" << "a" << true;
+ QTest::newRow("case []] don't match [") << "[]abc]" << "[" << false;
+ QTest::newRow("case [^]abc] match d") << "[^]abc]" << "d" << true;
+ QTest::newRow("case [^]abc] don't match ]") << "[^]abc]" << "]" << false;
+
+ QTest::newRow("* Not escaped with char") << "*Te;" << "12345Te;" << true;
+ QTest::newRow("* Not escaped without char") << "*Ch;" << "Ch;" << true;
+ QTest::newRow("* Not escaped invalid") << "*Ro;" << "o;" << false;
+ QTest::newRow("* Escaped") << "\\[Cks;" << "[Cks;" << true;
+
+ QTest::newRow("a true '\\' in input") << "\\Qt;" << "\\Qt;" << true;
+ QTest::newRow("two true '\\' in input") << "\\\\Qt;" << "\\\\Qt;" << true;
+ QTest::newRow("a '\\' at the end") << "\\\\Qt;" << "\\\\Qt;" << true;
+
+}
+void tst_QRegExp::testEscapingWildcard(){
+ QFETCH(QString, pattern);
+
+ QRegExp re(pattern);
+ re.setPatternSyntax(QRegExp::WildcardUnix);
+
+ QFETCH(QString, teststring);
+ QFETCH(bool, isMatching);
+ QCOMPARE(re.exactMatch(teststring), isMatching);
+}
+
+void tst_QRegExp::testInvalidWildcard_data(){
+ QTest::addColumn<QString>("pattern");
+ QTest::addColumn<bool>("isValid");
+
+ QTest::newRow("valid []") << "[abc]" << true;
+ QTest::newRow("invalid [") << "[abc" << false;
+ QTest::newRow("ending [") << "abc[" << false;
+ QTest::newRow("ending ]") << "abc]" << false;
+ QTest::newRow("ending [^") << "abc[^" << false;
+ QTest::newRow("ending [\\") << "abc[\\" << false;
+ QTest::newRow("ending []") << "abc[]" << false;
+ QTest::newRow("ending [[") << "abc[[" << false;
+
+}
+void tst_QRegExp::testInvalidWildcard(){
+ QFETCH(QString, pattern);
+
+ QRegExp re(pattern);
+ re.setPatternSyntax(QRegExp::Wildcard);
+
+ QFETCH(bool, isValid);
+ QCOMPARE(re.isValid(), isValid);
+}
+
void tst_QRegExp::caretAnchoredOptimization()
{
QString s = "---babnana----";