diff options
Diffstat (limited to 'tests/auto/qregexp')
-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----"; |