summaryrefslogtreecommitdiffstats
path: root/tests/auto/widgets/widgets/qplaintextedit/tst_qplaintextedit.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/widgets/widgets/qplaintextedit/tst_qplaintextedit.cpp')
-rw-r--r--tests/auto/widgets/widgets/qplaintextedit/tst_qplaintextedit.cpp74
1 files changed, 68 insertions, 6 deletions
diff --git a/tests/auto/widgets/widgets/qplaintextedit/tst_qplaintextedit.cpp b/tests/auto/widgets/widgets/qplaintextedit/tst_qplaintextedit.cpp
index cfa2ddc4cc..2ce75620cf 100644
--- a/tests/auto/widgets/widgets/qplaintextedit/tst_qplaintextedit.cpp
+++ b/tests/auto/widgets/widgets/qplaintextedit/tst_qplaintextedit.cpp
@@ -140,6 +140,11 @@ private slots:
void findBackwardWithRegExp();
void findWithRegExpReturnsFalseIfNoMoreResults();
#endif
+#if QT_CONFIG(regularexpression)
+ void findWithRegularExpression();
+ void findBackwardWithRegularExpression();
+ void findWithRegularExpressionReturnsFalseIfNoMoreResults();
+#endif
void layoutAfterMultiLineRemove();
void undoCommandRemovesAndReinsertsBlock();
void taskQTBUG_43562_lineCountCrash();
@@ -147,6 +152,9 @@ private slots:
void contextMenu();
#endif
void inputMethodCursorRect();
+#if QT_CONFIG(scrollbar)
+ void updateAfterChangeCenterOnScroll();
+#endif
private:
void createSelection();
@@ -201,12 +209,12 @@ void tst_QPlainTextEdit::getSetCheck()
// int QPlainTextEdit::tabStopWidth()
// void QPlainTextEdit::setTabStopWidth(int)
- obj1.setTabStopWidth(0);
- QCOMPARE(0, obj1.tabStopWidth());
- obj1.setTabStopWidth(INT_MIN);
- QCOMPARE(0, obj1.tabStopWidth()); // Makes no sense to set a negative tabstop value
- obj1.setTabStopWidth(INT_MAX);
- QCOMPARE(INT_MAX, obj1.tabStopWidth());
+ obj1.setTabStopDistance(0);
+ QCOMPARE(0, obj1.tabStopDistance());
+ obj1.setTabStopDistance(-1);
+ QCOMPARE(0, obj1.tabStopDistance()); // Makes no sense to set a negative tabstop value
+ obj1.setTabStopDistance(std::numeric_limits<qreal>::max());
+ QCOMPARE(std::numeric_limits<qreal>::max(), obj1.tabStopDistance());
}
class QtTestDocumentLayout : public QAbstractTextDocumentLayout
@@ -1579,6 +1587,45 @@ void tst_QPlainTextEdit::findWithRegExpReturnsFalseIfNoMoreResults()
}
#endif
+#if QT_CONFIG(regularexpression)
+void tst_QPlainTextEdit::findWithRegularExpression()
+{
+ ed->setPlainText(QStringLiteral("arbitrary text"));
+ QRegularExpression rx("\\w{2}xt");
+
+ bool found = ed->find(rx);
+
+ QVERIFY(found);
+ QCOMPARE(ed->textCursor().selectedText(), QStringLiteral("text"));
+}
+
+void tst_QPlainTextEdit::findBackwardWithRegularExpression()
+{
+ ed->setPlainText(QStringLiteral("arbitrary text"));
+ QTextCursor cursor = ed->textCursor();
+ cursor.movePosition(QTextCursor::End);
+ ed->setTextCursor(cursor);
+ QRegularExpression rx("a\\w*t");
+
+ bool found = ed->find(rx, QTextDocument::FindBackward);
+
+ QVERIFY(found);
+ QCOMPARE(ed->textCursor().selectedText(), QStringLiteral("arbit"));
+}
+
+void tst_QPlainTextEdit::findWithRegularExpressionReturnsFalseIfNoMoreResults()
+{
+ ed->setPlainText(QStringLiteral("arbitrary text"));
+ QRegularExpression rx("t.xt");
+ ed->find(rx);
+
+ bool found = ed->find(rx);
+
+ QVERIFY(!found);
+ QCOMPARE(ed->textCursor().selectedText(), QStringLiteral("text"));
+}
+#endif
+
void tst_QPlainTextEdit::layoutAfterMultiLineRemove()
{
ed->setVisible(true); // The widget must be visible to reproduce this bug.
@@ -1727,5 +1774,20 @@ void tst_QPlainTextEdit::inputMethodCursorRect()
QCOMPARE(cursorRectV.toRect(), cursorRect.toRect());
}
+#if QT_CONFIG(scrollbar)
+// QTBUG-64730: Verify that the scrollbar is updated after center on scroll was set
+void tst_QPlainTextEdit::updateAfterChangeCenterOnScroll()
+{
+ ed->setPlainText("Line1\nLine2Line3\nLine3");
+ ed->show();
+ ed->setCenterOnScroll(true);
+ const int maxWithCenterOnScroll = ed->verticalScrollBar()->maximum();
+ ed->setCenterOnScroll(false);
+ const int maxWithoutCenterOnScroll = ed->verticalScrollBar()->maximum();
+ QVERIFY(maxWithCenterOnScroll > maxWithoutCenterOnScroll);
+}
+
+#endif
+
QTEST_MAIN(tst_QPlainTextEdit)
#include "tst_qplaintextedit.moc"