diff options
author | Benjamin Poulain <benjamin.poulain@nokia.com> | 2009-09-16 18:46:10 (GMT) |
---|---|---|
committer | Benjamin Poulain <benjamin.poulain@nokia.com> | 2009-09-17 07:37:17 (GMT) |
commit | e7c36fc2e420f1cee4370020b9f50bb5a6dfe92a (patch) | |
tree | c3053cb018572650bf839195c5cc19092034dd71 /tests | |
parent | dfcf988a3f0c88f96e202482e5d363d880b9d6d2 (diff) | |
download | Qt-e7c36fc2e420f1cee4370020b9f50bb5a6dfe92a.zip Qt-e7c36fc2e420f1cee4370020b9f50bb5a6dfe92a.tar.gz Qt-e7c36fc2e420f1cee4370020b9f50bb5a6dfe92a.tar.bz2 |
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')
-rw-r--r-- | tests/auto/qregexp/tst_qregexp.cpp | 75 |
1 files changed, 74 insertions, 1 deletions
diff --git a/tests/auto/qregexp/tst_qregexp.cpp b/tests/auto/qregexp/tst_qregexp.cpp index 7496ec6..86d831e 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----"; |