summaryrefslogtreecommitdiffstats
path: root/tests/auto/widgets/widgets/qplaintextedit
diff options
context:
space:
mode:
authorChristian Loose <christian.loose@hamburg.de>2014-01-27 12:27:38 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-01-31 21:51:35 +0100
commitf40c28f91514356155a42f44f9eb69c7faa83eec (patch)
tree9d9c66652dd2294378e9cb2bbe1aeaca7861ea5f /tests/auto/widgets/widgets/qplaintextedit
parent17678bee8912b33219bbc1e4e5ce2b82f61744b2 (diff)
Q(Plain)TextEdit: Add find() overload with QRegExp
Add overloads to the find() methods in QPlainTextEdit and QTextEdit that find the next occurrence matching the passed regular expression. These are convenience methods that eliminate the need to use the document() method and the need to handle the QTextCursor return value. [ChangeLog][QtWidgets][QPlainTextEdit] Added find method overload using QRegExp [ChangeLog][QtWidgets][QTextEdit] Added find method overload using QRegExp Change-Id: Ia6139b771e3ae4ca02e4b8ea7fde19e5dc71b9d8 Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
Diffstat (limited to 'tests/auto/widgets/widgets/qplaintextedit')
-rw-r--r--tests/auto/widgets/widgets/qplaintextedit/tst_qplaintextedit.cpp44
1 files changed, 44 insertions, 0 deletions
diff --git a/tests/auto/widgets/widgets/qplaintextedit/tst_qplaintextedit.cpp b/tests/auto/widgets/widgets/qplaintextedit/tst_qplaintextedit.cpp
index 11c4e238ec..61eb390fd3 100644
--- a/tests/auto/widgets/widgets/qplaintextedit/tst_qplaintextedit.cpp
+++ b/tests/auto/widgets/widgets/qplaintextedit/tst_qplaintextedit.cpp
@@ -149,6 +149,11 @@ private slots:
void insertAndScrollToBottom();
void inputMethodQueryImHints_data();
void inputMethodQueryImHints();
+#ifndef QT_NO_REGEXP
+ void findWithRegExp();
+ void findBackwardWithRegExp();
+ void findWithRegExpReturnsFalseIfNoMoreResults();
+#endif
private:
void createSelection();
@@ -1523,5 +1528,44 @@ void tst_QPlainTextEdit::inputMethodQueryImHints()
QCOMPARE(static_cast<Qt::InputMethodHints>(value.toInt()), hints);
}
+#ifndef QT_NO_REGEXP
+void tst_QPlainTextEdit::findWithRegExp()
+{
+ ed->setPlainText(QStringLiteral("arbitrary text"));
+ QRegExp rx("\\w{2}xt");
+
+ bool found = ed->find(rx);
+
+ QVERIFY(found == true);
+ QCOMPARE(ed->textCursor().selectedText(), QStringLiteral("text"));
+}
+
+void tst_QPlainTextEdit::findBackwardWithRegExp()
+{
+ ed->setPlainText(QStringLiteral("arbitrary text"));
+ QTextCursor cursor = ed->textCursor();
+ cursor.movePosition(QTextCursor::End);
+ ed->setTextCursor(cursor);
+ QRegExp rx("a\\w*t");
+
+ bool found = ed->find(rx, QTextDocument::FindBackward);
+
+ QVERIFY(found == true);
+ QCOMPARE(ed->textCursor().selectedText(), QStringLiteral("arbit"));
+}
+
+void tst_QPlainTextEdit::findWithRegExpReturnsFalseIfNoMoreResults()
+{
+ ed->setPlainText(QStringLiteral("arbitrary text"));
+ QRegExp rx("t.xt");
+ ed->find(rx);
+
+ bool found = ed->find(rx);
+
+ QVERIFY(found == false);
+ QCOMPARE(ed->textCursor().selectedText(), QStringLiteral("text"));
+}
+#endif
+
QTEST_MAIN(tst_QPlainTextEdit)
#include "tst_qplaintextedit.moc"