diff options
author | Samuel Gaist <samuel.gaist@edeltech.ch> | 2014-08-27 23:14:59 +0200 |
---|---|---|
committer | Samuel Gaist <samuel.gaist@edeltech.ch> | 2014-09-15 09:35:47 +0200 |
commit | 4066a6a893dcaa1258e4801fe9e8d2d7624e37f7 (patch) | |
tree | 5c0f84f5c06e6b6ae98d2dd1c10b942c35928642 /tests/auto/gui/text/qtextdocument | |
parent | 4e8720d413ceca288408ae34bc726f768ca467c6 (diff) |
Add QRegularExpression support to QTextDocument
Currently QTextDocuement only provides find using QRegExp. This patch
aims to add support for QRegularExpression.
[ChangeLog][QtGui][QTextDocument] Support for searching with a
QRegularExpression in a document has been added.
Change-Id: I6dba10545b83995d093407038a821fe54db3d261
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
Diffstat (limited to 'tests/auto/gui/text/qtextdocument')
-rw-r--r-- | tests/auto/gui/text/qtextdocument/tst_qtextdocument.cpp | 65 |
1 files changed, 50 insertions, 15 deletions
diff --git a/tests/auto/gui/text/qtextdocument/tst_qtextdocument.cpp b/tests/auto/gui/text/qtextdocument/tst_qtextdocument.cpp index 59c951332e..1c74eaa19a 100644 --- a/tests/auto/gui/text/qtextdocument/tst_qtextdocument.cpp +++ b/tests/auto/gui/text/qtextdocument/tst_qtextdocument.cpp @@ -86,6 +86,8 @@ private slots: void find2(); void findWithRegExp_data(); void findWithRegExp(); + void findWithRegularExpression_data(); + void findWithRegularExpression(); void findMultiple(); void basicIsModifiedChecks(); void moreIsModified(); @@ -196,6 +198,7 @@ private slots: private: void backgroundImage_checkExpectedHtml(const QTextDocument &doc); + void buildRegExpData(); QTextDocument *doc; QTextCursor cursor; @@ -352,21 +355,7 @@ void tst_QTextDocument::find() void tst_QTextDocument::findWithRegExp_data() { - QTest::addColumn<QString>("haystack"); - QTest::addColumn<QString>("needle"); - QTest::addColumn<int>("flags"); - QTest::addColumn<int>("from"); - QTest::addColumn<int>("anchor"); - QTest::addColumn<int>("position"); - - // match integers 0 to 99 - QTest::newRow("1") << "23" << "^\\d\\d?$" << int(QTextDocument::FindCaseSensitively) << 0 << 0 << 2; - // match ampersands but not & - QTest::newRow("2") << "His & hers & theirs" << "&(?!amp;)"<< int(QTextDocument::FindCaseSensitively) << 0 << 15 << 16; - //backward search - QTest::newRow("3") << QString::fromLatin1("HelloBlahWorld Blah Hah") - << "h" << int(QTextDocument::FindBackward) << 18 << 8 << 9; - + buildRegExpData(); } void tst_QTextDocument::findWithRegExp() @@ -393,6 +382,34 @@ void tst_QTextDocument::findWithRegExp() } } +void tst_QTextDocument::findWithRegularExpression_data() +{ + buildRegExpData(); +} + +void tst_QTextDocument::findWithRegularExpression() +{ + QFETCH(QString, haystack); + QFETCH(QString, needle); + QFETCH(int, flags); + QFETCH(int, from); + QFETCH(int, anchor); + QFETCH(int, position); + + cursor.insertText(haystack); + //search using a regular expression + QRegularExpression expr(needle); + QTextDocument::FindFlags flg(flags); + cursor = doc->find(expr, from, flg); + + if (anchor != -1) { + QCOMPARE(cursor.anchor(), anchor); + QCOMPARE(cursor.position(), position); + } else { + QVERIFY(cursor.isNull()); + } +} + void tst_QTextDocument::find2() { doc->setPlainText("aaa"); @@ -2602,6 +2619,24 @@ void tst_QTextDocument::backgroundImage_checkExpectedHtml(const QTextDocument &d QCOMPARE(doc.toHtml(), expectedHtml); } +void tst_QTextDocument::buildRegExpData() +{ + QTest::addColumn<QString>("haystack"); + QTest::addColumn<QString>("needle"); + QTest::addColumn<int>("flags"); + QTest::addColumn<int>("from"); + QTest::addColumn<int>("anchor"); + QTest::addColumn<int>("position"); + + // match integers 0 to 99 + QTest::newRow("1") << "23" << "^\\d\\d?$" << int(QTextDocument::FindCaseSensitively) << 0 << 0 << 2; + // match ampersands but not & + QTest::newRow("2") << "His & hers & theirs" << "&(?!amp;)"<< int(QTextDocument::FindCaseSensitively) << 0 << 15 << 16; + //backward search + QTest::newRow("3") << QString::fromLatin1("HelloBlahWorld Blah Hah") + << "h" << int(QTextDocument::FindBackward) << 18 << 8 << 9; +} + void tst_QTextDocument::backgroundImage_toHtml() { CREATE_DOC_AND_CURSOR(); |