summaryrefslogtreecommitdiffstats
path: root/tests/auto/gui/text
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@qt.io>2020-03-27 13:41:02 +0100
committerLars Knoll <lars.knoll@qt.io>2020-04-01 10:29:26 +0200
commitef0f1429aeeecc7f897d102f80a992fc31e327a7 (patch)
tree2fceb779e36aee3f3a96c8dad1429d29ddf45aba /tests/auto/gui/text
parent70beac08afaec0ef0c4ef2e72ebfc007acba7d56 (diff)
Remove QRegExp based API and QRegExp usage from QTextDocument
Change-Id: Ib5cc2d747f215a483585b703f9b4f6415e0d59f7 Reviewed-by: Samuel Gaist <samuel.gaist@idiap.ch>
Diffstat (limited to 'tests/auto/gui/text')
-rw-r--r--tests/auto/gui/text/qtextdocument/tst_qtextdocument.cpp99
1 files changed, 24 insertions, 75 deletions
diff --git a/tests/auto/gui/text/qtextdocument/tst_qtextdocument.cpp b/tests/auto/gui/text/qtextdocument/tst_qtextdocument.cpp
index 10a627bb82..71456fbd09 100644
--- a/tests/auto/gui/text/qtextdocument/tst_qtextdocument.cpp
+++ b/tests/auto/gui/text/qtextdocument/tst_qtextdocument.cpp
@@ -70,8 +70,6 @@ private slots:
void find_data();
void find();
void find2();
- void findWithRegExp_data();
- void findWithRegExp();
void findWithRegularExpression_data();
void findWithRegularExpression();
void findMultiple();
@@ -380,39 +378,8 @@ void tst_QTextDocument::find()
}
//search using a regular expression
- QRegExp expr(needle);
- expr.setPatternSyntax(QRegExp::FixedString);
+ QRegularExpression expr(QRegularExpression::escape(needle));
QTextDocument::FindFlags flg(flags);
- expr.setCaseSensitivity((flg & QTextDocument::FindCaseSensitively) ? Qt::CaseSensitive : Qt::CaseInsensitive);
- cursor = doc->find(expr, from, flg);
-
- if (anchor != -1) {
- QCOMPARE(cursor.anchor(), anchor);
- QCOMPARE(cursor.position(), position);
- } else {
- QVERIFY(cursor.isNull());
- }
-}
-
-void tst_QTextDocument::findWithRegExp_data()
-{
- buildRegExpData();
-}
-
-void tst_QTextDocument::findWithRegExp()
-{
- 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
- QRegExp expr(needle);
- QTextDocument::FindFlags flg(flags);
- expr.setCaseSensitivity((flg & QTextDocument::FindCaseSensitively) ? Qt::CaseSensitive : Qt::CaseInsensitive);
cursor = doc->find(expr, from, flg);
if (anchor != -1) {
@@ -482,26 +449,6 @@ void tst_QTextDocument::findMultiple()
QCOMPARE(cursor.selectionStart(), text.indexOf("bar"));
QCOMPARE(cursor.selectionEnd(), cursor.selectionStart() + 3);
-
- QRegExp expr("bar");
- expr.setPatternSyntax(QRegExp::FixedString);
-
- cursor.movePosition(QTextCursor::End);
- cursor = doc->find(expr, cursor, QTextDocument::FindBackward);
- QCOMPARE(cursor.selectionStart(), text.lastIndexOf("bar"));
- QCOMPARE(cursor.selectionEnd(), cursor.selectionStart() + 3);
- cursor = doc->find(expr, cursor, QTextDocument::FindBackward);
- QCOMPARE(cursor.selectionStart(), text.indexOf("bar"));
- QCOMPARE(cursor.selectionEnd(), cursor.selectionStart() + 3);
-
- cursor.movePosition(QTextCursor::Start);
- cursor = doc->find(expr, cursor);
- QCOMPARE(cursor.selectionStart(), text.indexOf("bar"));
- QCOMPARE(cursor.selectionEnd(), cursor.selectionStart() + 3);
- cursor = doc->find(expr, cursor);
- QCOMPARE(cursor.selectionStart(), text.lastIndexOf("bar"));
- QCOMPARE(cursor.selectionEnd(), cursor.selectionStart() + 3);
-
QRegularExpression regularExpression("bar");
cursor.movePosition(QTextCursor::End);
@@ -1863,7 +1810,7 @@ void tst_QTextDocument::setFragmentMarkersInHtmlExport()
QTextDocumentFragment fragment(cursor);
QString expected = htmlHead;
- expected.replace(QRegExp("<body.*>"), QString("<body>"));
+ expected.replace(QRegularExpression("<body.*>"), QString("<body>"));
expected += QString("<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><!--StartFragment-->Test<span style=\" color:#00ff00;\">Blah</span><!--EndFragment--></p>") + htmlTail;
QCOMPARE(fragment.toHtml(), expected);
}
@@ -1883,7 +1830,7 @@ void tst_QTextDocument::setFragmentMarkersInHtmlExport()
QTextDocumentFragment fragment(cursor);
QString expected = htmlHead;
- expected.replace(QRegExp("<body.*>"), QString("<body>"));
+ expected.replace(QRegularExpression("<body.*>"), QString("<body>"));
expected += QString("<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><!--StartFragment-->Test<!--EndFragment--></p>") + htmlTail;
QCOMPARE(fragment.toHtml(), expected);
}
@@ -2024,8 +1971,9 @@ void tst_QTextDocument::capitalizationHtmlInExport()
{
doc->setPlainText("Test");
- QRegExp re(".*span style=\"(.*)\">Test.*");
- QVERIFY(re.exactMatch(doc->toHtml()) == false); // no span
+ QRegularExpression re(".*span style=\"(.*)\">Test.*");
+ QCOMPARE(re.captureCount(), 1);
+ QVERIFY(!re.match(doc->toHtml()).hasMatch()); // no span
QTextCursor cursor(doc);
cursor.setPosition(4, QTextCursor::KeepAnchor);
@@ -2034,23 +1982,23 @@ void tst_QTextDocument::capitalizationHtmlInExport()
cursor.mergeCharFormat(cf);
const QString smallcaps = doc->toHtml();
- QVERIFY(re.exactMatch(doc->toHtml()));
- QCOMPARE(re.captureCount(), 1);
- QCOMPARE(re.cap(1).trimmed(), QString("font-variant:small-caps;"));
+ auto match = re.match(doc->toHtml());
+ QVERIFY(match.hasMatch());
+ QCOMPARE(match.captured(1).trimmed(), QString("font-variant:small-caps;"));
cf.setFontCapitalization(QFont::AllUppercase);
cursor.mergeCharFormat(cf);
const QString uppercase = doc->toHtml();
- QVERIFY(re.exactMatch(doc->toHtml()));
- QCOMPARE(re.captureCount(), 1);
- QCOMPARE(re.cap(1).trimmed(), QString("text-transform:uppercase;"));
+ match = re.match(doc->toHtml());
+ QVERIFY(match.hasMatch());
+ QCOMPARE(match.captured(1).trimmed(), QString("text-transform:uppercase;"));
cf.setFontCapitalization(QFont::AllLowercase);
cursor.mergeCharFormat(cf);
const QString lowercase = doc->toHtml();
- QVERIFY(re.exactMatch(doc->toHtml()));
- QCOMPARE(re.captureCount(), 1);
- QCOMPARE(re.cap(1).trimmed(), QString("text-transform:lowercase;"));
+ match = re.match(doc->toHtml());
+ QVERIFY(match.hasMatch());
+ QCOMPARE(match.captured(1).trimmed(), QString("text-transform:lowercase;"));
doc->setHtml(smallcaps);
cursor.setPosition(1);
@@ -2065,8 +2013,9 @@ void tst_QTextDocument::wordspacingHtmlExport()
{
doc->setPlainText("Test");
- QRegExp re(".*span style=\"(.*)\">Test.*");
- QVERIFY(re.exactMatch(doc->toHtml()) == false); // no span
+ QRegularExpression re(".*span style=\"(.*)\">Test.*");
+ QCOMPARE(re.captureCount(), 1);
+ QVERIFY(!re.match(doc->toHtml()).hasMatch()); // no span
QTextCursor cursor(doc);
cursor.setPosition(4, QTextCursor::KeepAnchor);
@@ -2074,16 +2023,16 @@ void tst_QTextDocument::wordspacingHtmlExport()
cf.setFontWordSpacing(4);
cursor.mergeCharFormat(cf);
- QVERIFY(re.exactMatch(doc->toHtml()));
- QCOMPARE(re.captureCount(), 1);
- QCOMPARE(re.cap(1).trimmed(), QString("word-spacing:4px;"));
+ auto match = re.match(doc->toHtml());
+ QVERIFY(match.hasMatch());
+ QCOMPARE(match.captured(1).trimmed(), QString("word-spacing:4px;"));
cf.setFontWordSpacing(-8.5);
cursor.mergeCharFormat(cf);
- QVERIFY(re.exactMatch(doc->toHtml()));
- QCOMPARE(re.captureCount(), 1);
- QCOMPARE(re.cap(1).trimmed(), QString("word-spacing:-8.5px;"));
+ match = re.match(doc->toHtml());
+ QVERIFY(match.hasMatch());
+ QCOMPARE(match.captured(1).trimmed(), QString("word-spacing:-8.5px;"));
}
class CursorPosSignalSpy : public QObject