diff options
author | Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> | 2014-09-02 09:10:20 +0200 |
---|---|---|
committer | Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> | 2014-09-02 16:52:02 +0200 |
commit | 8530aaf1c825949b8cd1d6987a130135aa627c3b (patch) | |
tree | c133d3dce13301cdcc36da35318509a4db38ed78 /tests/auto/corelib/tools/qregularexpression | |
parent | 648587fbdc840209272211ec609c70ac056d0744 (diff) |
QRegularExpression: strenghten tests of matching at an offset
Instead of simply doing a match against a string S at offset O > 0
(and checking the result), test that the results never change when matching
against the substring starting at (O - i) at offset i, 0 <= i <= O.
Change-Id: Ib7fd648ca0a36b93d145267ebfb792c46ca4e4f5
Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
Diffstat (limited to 'tests/auto/corelib/tools/qregularexpression')
-rw-r--r-- | tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.cpp | 90 |
1 files changed, 58 insertions, 32 deletions
diff --git a/tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.cpp b/tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.cpp index 2814573863..520e668ce2 100644 --- a/tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.cpp +++ b/tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.cpp @@ -610,6 +610,7 @@ void tst_QRegularExpression::normalMatch_data() QTest::addColumn<Match>("match"); Match m; + int offset = 0; m.clear(); m.isValid = true; m.hasMatch = true; @@ -661,20 +662,28 @@ void tst_QRegularExpression::normalMatch_data() m.clear(); m.isValid = true; m.hasMatch = true; m.captured << "c123def" << "c12" << "3" << "def"; - QTest::newRow("match06") << QRegularExpression("(\\w*)(\\d+)(\\w*)") - << "abc123def" - << 2 - << QRegularExpression::MatchOptions(QRegularExpression::NoMatchOption) - << m; + offset = 2; + for (int i = 0; i <= offset; ++i) { + QTest::newRow(QStringLiteral("match06-offset%1").arg(i).toUtf8().constData()) + << QRegularExpression("(\\w*)(\\d+)(\\w*)") + << QStringLiteral("abc123def").mid(offset - i) + << i + << QRegularExpression::MatchOptions(QRegularExpression::NoMatchOption) + << m; + } m.clear(); m.isValid = true; m.hasMatch = true; m.captured << QString(""); - QTest::newRow("match07") << QRegularExpression("\\w*") - << "abc123def" - << 9 - << QRegularExpression::MatchOptions(QRegularExpression::NoMatchOption) - << m; + offset = 9; + for (int i = 0; i <= offset; ++i) { + QTest::newRow(QStringLiteral("match07-offset%1").arg(i).toUtf8().constData()) + << QRegularExpression("\\w*") + << QStringLiteral("abc123def").mid(offset - i) + << i + << QRegularExpression::MatchOptions(QRegularExpression::NoMatchOption) + << m; + } m.clear(); m.isValid = true; m.hasMatch = true; @@ -732,19 +741,27 @@ void tst_QRegularExpression::normalMatch_data() m.clear(); m.isValid = true; - QTest::newRow("nomatch02") << QRegularExpression("(\\w+) (\\w+)") - << "a string" - << 1 - << QRegularExpression::MatchOptions(QRegularExpression::NoMatchOption) - << m; + offset = 1; + for (int i = 0; i <= offset; ++i) { + QTest::newRow(QStringLiteral("nomatch02-offset%1").arg(i).toUtf8().constData()) + << QRegularExpression("(\\w+) (\\w+)") + << QStringLiteral("a string").mid(offset - i) + << i + << QRegularExpression::MatchOptions(QRegularExpression::NoMatchOption) + << m; + } m.clear(); m.isValid = true; - QTest::newRow("nomatch03") << QRegularExpression("\\w+") - << "abc123def" - << 9 - << QRegularExpression::MatchOptions(QRegularExpression::NoMatchOption) - << m; + offset = 9; + for (int i = 0; i <= offset; ++i) { + QTest::newRow(QStringLiteral("nomatch03-offset%1").arg(i).toUtf8().constData()) + << QRegularExpression("\\w+") + << QStringLiteral("abc123def").mid(offset - i) + << i + << QRegularExpression::MatchOptions(QRegularExpression::NoMatchOption) + << m; + } // *** @@ -832,6 +849,7 @@ void tst_QRegularExpression::partialMatch_data() QTest::addColumn<Match>("match"); Match m; + int offset = 0; m.clear(); m.isValid = true; m.hasPartialMatch = true; @@ -906,12 +924,16 @@ void tst_QRegularExpression::partialMatch_data() m.clear(); m.isValid = true; m.hasPartialMatch = true; m.captured << "def"; - QTest::newRow("softmatch08") << QRegularExpression("abc\\w+X|defY") - << "abcdef" - << 1 - << QRegularExpression::PartialPreferCompleteMatch - << QRegularExpression::MatchOptions(QRegularExpression::NoMatchOption) - << m; + offset = 1; + for (int i = 0; i <= offset; ++i) { + QTest::newRow(QStringLiteral("softmatch08-offset%1").arg(i).toUtf8().constData()) + << QRegularExpression("abc\\w+X|defY") + << QStringLiteral("abcdef").mid(offset - i) + << i + << QRegularExpression::PartialPreferCompleteMatch + << QRegularExpression::MatchOptions(QRegularExpression::NoMatchOption) + << m; + } // *** @@ -988,12 +1010,16 @@ void tst_QRegularExpression::partialMatch_data() m.clear(); m.isValid = true; m.hasPartialMatch = true; m.captured << "def"; - QTest::newRow("hardmatch08") << QRegularExpression("abc\\w+X|defY") - << "abcdef" - << 1 - << QRegularExpression::PartialPreferFirstMatch - << QRegularExpression::MatchOptions(QRegularExpression::NoMatchOption) - << m; + offset = 1; + for (int i = 0; i <= offset; ++i) { + QTest::newRow(QStringLiteral("hardmatch08-offset%1").arg(i).toUtf8().constData()) + << QRegularExpression("abc\\w+X|defY") + << QStringLiteral("abcdef").mid(offset - i) + << i + << QRegularExpression::PartialPreferFirstMatch + << QRegularExpression::MatchOptions(QRegularExpression::NoMatchOption) + << m; + } m.clear(); m.isValid = true; m.hasPartialMatch = true; |