aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@qt.io>2020-04-02 11:00:06 +0200
committerLars Knoll <lars.knoll@qt.io>2020-04-03 21:01:53 +0200
commitcc6c5ae70b1389ed86301bbfc156628e1d3abbcd (patch)
tree41238618977b44c67c796fb34078d6c3084d5e55
parent55be24d6b6e66bd54168021f5a467ba4da73b2c6 (diff)
Port the remaining tests from QRegExp to QRegularExpression
Change-Id: If258701759c5da206948407feccd94e323af6b36 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
-rw-r--r--tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp24
-rw-r--r--tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp12
-rw-r--r--tests/auto/quick/scenegraph/tst_scenegraph.cpp34
-rw-r--r--tests/benchmarks/qml/holistic/testtypes.h10
-rw-r--r--tests/benchmarks/qml/js/qjsengine/tst_qjsengine.cpp3
-rw-r--r--tests/benchmarks/qml/js/qjsvalue/tst_qjsvalue.cpp3
6 files changed, 47 insertions, 39 deletions
diff --git a/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp b/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp
index 8ea2ce3bfb..1c4ca246c7 100644
--- a/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp
+++ b/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp
@@ -44,6 +44,7 @@
#include <QFontMetrics>
#include <QtQuick/QQuickView>
#include <QDir>
+#include <QRegularExpression>
#include <QInputMethod>
#include <QClipboard>
#include <QMimeData>
@@ -394,7 +395,7 @@ void tst_qquicktextedit::text()
QVERIFY(textEditObject != nullptr);
QString expected = richText.at(i);
- expected.replace(QRegExp("\\\\(.)"),"\\1");
+ expected.replace(QRegularExpression("\\\\(.)"),"\\1");
QCOMPARE(textEditObject->text(), expected);
QCOMPARE(textEditObject->length(), expected.length());
}
@@ -410,8 +411,9 @@ void tst_qquicktextedit::text()
QString actual = textEditObject->text();
QString expected = standard.at(i);
- actual.remove(QRegExp(".*<body[^>]*>"));
- actual.remove(QRegExp("(<[^>]*>)+"));
+ actual.remove("\n");
+ actual.remove(QRegularExpression(".*<body[^>]*>"));
+ actual.remove(QRegularExpression("(<[^>]*>)+"));
expected.remove("\n");
QCOMPARE(actual.simplified(), expected);
QCOMPARE(textEditObject->length(), expected.length());
@@ -427,9 +429,10 @@ void tst_qquicktextedit::text()
QVERIFY(textEditObject != nullptr);
QString actual = textEditObject->text();
QString expected = richText.at(i);
- actual.replace(QRegExp(".*<body[^>]*>"),"");
- actual.replace(QRegExp("(<[^>]*>)+"),"<>");
- expected.replace(QRegExp("(<[^>]*>)+"),"<>");
+ actual.remove("\n");
+ actual.replace(QRegularExpression(".*<body[^>]*>"),"");
+ actual.replace(QRegularExpression("(<[^>]*>)+"),"<>");
+ expected.replace(QRegularExpression("(<[^>]*>)+"),"<>");
QCOMPARE(actual.simplified(),expected.simplified());
expected.replace("<>", " ");
@@ -458,9 +461,10 @@ void tst_qquicktextedit::text()
QVERIFY(textEditObject != nullptr);
QString actual = textEditObject->text();
QString expected = richText.at(i);
- actual.replace(QRegExp(".*<body[^>]*>"),"");
- actual.replace(QRegExp("(<[^>]*>)+"),"<>");
- expected.replace(QRegExp("(<[^>]*>)+"),"<>");
+ actual.remove("\n");
+ actual.replace(QRegularExpression(".*<body[^>]*>"),"");
+ actual.replace(QRegularExpression("(<[^>]*>)+"),"<>");
+ expected.replace(QRegularExpression("(<[^>]*>)+"),"<>");
QCOMPARE(actual.simplified(),expected.simplified());
expected.replace("<>", " ");
@@ -4221,7 +4225,7 @@ void tst_qquicktextedit::getFormattedText()
if (textFormat == QQuickTextEdit::RichText
|| (textFormat == QQuickTextEdit::AutoText && Qt::mightBeRichText(text))) {
- QVERIFY(textEdit->getFormattedText(start, end).contains(QRegExp(expectedText)));
+ QVERIFY(textEdit->getFormattedText(start, end).contains(QRegularExpression(expectedText)));
} else {
QCOMPARE(textEdit->getFormattedText(start, end), expectedText);
}
diff --git a/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp b/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp
index 18b7903eeb..d6f2b6ef6a 100644
--- a/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp
+++ b/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp
@@ -6021,17 +6021,17 @@ void tst_qquicktextinput::QTBUG_19956_regexp()
input->setFocus(true);
QVERIFY(input->hasActiveFocus());
- window.rootObject()->setProperty("regexvalue", QRegExp("abc"));
- QCOMPARE(window.rootObject()->property("regexvalue").toRegExp(), QRegExp("abc"));
+ window.rootObject()->setProperty("regexvalue", QRegularExpression("abc"));
+ QCOMPARE(window.rootObject()->property("regexvalue").toRegularExpression(), QRegularExpression("abc"));
QCOMPARE(window.rootObject()->property("text").toString(), QString("abc"));
QVERIFY(window.rootObject()->property("acceptableInput").toBool());
- window.rootObject()->setProperty("regexvalue", QRegExp("abcd"));
- QCOMPARE(window.rootObject()->property("regexvalue").toRegExp(), QRegExp("abcd"));
+ window.rootObject()->setProperty("regexvalue", QRegularExpression("abcd"));
+ QCOMPARE(window.rootObject()->property("regexvalue").toRegularExpression(), QRegularExpression("abcd"));
QVERIFY(!window.rootObject()->property("acceptableInput").toBool());
- window.rootObject()->setProperty("regexvalue", QRegExp("abc"));
- QCOMPARE(window.rootObject()->property("regexvalue").toRegExp(), QRegExp("abc"));
+ window.rootObject()->setProperty("regexvalue", QRegularExpression("abc"));
+ QCOMPARE(window.rootObject()->property("regexvalue").toRegularExpression(), QRegularExpression("abc"));
QVERIFY(window.rootObject()->property("acceptableInput").toBool());
}
diff --git a/tests/auto/quick/scenegraph/tst_scenegraph.cpp b/tests/auto/quick/scenegraph/tst_scenegraph.cpp
index 12f7efb7d5..c026888f6c 100644
--- a/tests/auto/quick/scenegraph/tst_scenegraph.cpp
+++ b/tests/auto/quick/scenegraph/tst_scenegraph.cpp
@@ -342,13 +342,13 @@ struct Sample {
qreal tolerance;
};
-static Sample sample_from_regexp(QRegExp *re) {
- return Sample(re->cap(1).toInt(),
- re->cap(2).toInt(),
- re->cap(3).toFloat(),
- re->cap(4).toFloat(),
- re->cap(5).toFloat(),
- re->cap(6).toFloat()
+static Sample sample_from_regexp(QRegularExpressionMatch *match) {
+ return Sample(match->captured(1).toInt(),
+ match->captured(2).toInt(),
+ match->captured(3).toFloat(),
+ match->captured(4).toFloat(),
+ match->captured(5).toFloat(),
+ match->captured(6).toFloat()
);
}
@@ -406,10 +406,10 @@ void tst_SceneGraph::render_data()
if (!m_brokenMipmapSupport)
files << "render_Mipmap.qml";
- QRegExp sampleCount("#samples: *(\\d+)");
+ QRegularExpression sampleCount("#samples: *(\\d+)");
// X:int Y:int R:float G:float B:float Error:float
- QRegExp baseSamples("#base: *(\\d+) *(\\d+) *(\\d\\.\\d+) *(\\d\\.\\d+) *(\\d\\.\\d+) *(\\d\\.\\d+)");
- QRegExp finalSamples("#final: *(\\d+) *(\\d+) *(\\d\\.\\d+) *(\\d\\.\\d+) *(\\d\\.\\d+) *(\\d\\.\\d+)");
+ QRegularExpression baseSamples("#base: *(\\d+) *(\\d+) *(\\d\\.\\d+) *(\\d\\.\\d+) *(\\d\\.\\d+) *(\\d\\.\\d+)");
+ QRegularExpression finalSamples("#final: *(\\d+) *(\\d+) *(\\d\\.\\d+) *(\\d\\.\\d+) *(\\d\\.\\d+) *(\\d\\.\\d+)");
foreach (QString fileName, files) {
QFile file(testFile(fileName));
@@ -421,8 +421,9 @@ void tst_SceneGraph::render_data()
int samples = -1;
foreach (QString line, contents) {
- if (sampleCount.indexIn(line) >= 0) {
- samples = sampleCount.cap(1).toInt();
+ auto match = sampleCount.match(line);
+ if (match.hasMatch()) {
+ samples = match.captured(1).toInt();
break;
}
}
@@ -431,10 +432,11 @@ void tst_SceneGraph::render_data()
QList<Sample> baseStage, finalStage;
foreach (QString line, contents) {
- if (baseSamples.indexIn(line) >= 0)
- baseStage << sample_from_regexp(&baseSamples);
- else if (finalSamples.indexIn(line) >= 0)
- finalStage << sample_from_regexp(&finalSamples);
+ auto match = baseSamples.match(line);
+ if (match.hasMatch())
+ baseStage << sample_from_regexp(&match);
+ else if ((match = finalSamples.match(line)).hasMatch())
+ finalStage << sample_from_regexp(&match);
}
if (baseStage.size() + finalStage.size() != samples)
diff --git a/tests/benchmarks/qml/holistic/testtypes.h b/tests/benchmarks/qml/holistic/testtypes.h
index 55f094ae7e..9d187f35ff 100644
--- a/tests/benchmarks/qml/holistic/testtypes.h
+++ b/tests/benchmarks/qml/holistic/testtypes.h
@@ -43,7 +43,7 @@
#include <QtQml/qjsvalue.h>
#include <QtQml/qqmlscriptstring.h>
#include <QtQml/qqmlcomponent.h>
-#include <QtCore/qregexp.h>
+#include <QtCore/qregularexpression.h>
class MyQmlAttachedObject : public QObject
{
@@ -80,7 +80,7 @@ class MyQmlObject : public QObject
Q_PROPERTY(QObject *objectProperty READ objectProperty WRITE setObjectProperty NOTIFY objectChanged)
Q_PROPERTY(QQmlListProperty<QObject> objectListProperty READ objectListProperty CONSTANT)
Q_PROPERTY(int resettableProperty READ resettableProperty WRITE setResettableProperty RESET resetProperty)
- Q_PROPERTY(QRegExp regExp READ regExp WRITE setRegExp)
+ Q_PROPERTY(QRegularExpression regExp READ regExp WRITE setRegExp)
Q_PROPERTY(int nonscriptable READ nonscriptable WRITE setNonscriptable SCRIPTABLE false)
public:
@@ -130,8 +130,8 @@ public:
void setResettableProperty(int v) { m_resetProperty = v; }
void resetProperty() { m_resetProperty = 13; }
- QRegExp regExp() { return m_regExp; }
- void setRegExp(const QRegExp &regExp) { m_regExp = regExp; }
+ QRegularExpression regExp() { return m_regExp; }
+ void setRegExp(const QRegularExpression &regExp) { m_regExp = regExp; }
int console() const { return 11; }
@@ -173,7 +173,7 @@ private:
QList<QObject *> m_objectQList;
int m_value;
int m_resetProperty;
- QRegExp m_regExp;
+ QRegularExpression m_regExp;
QVariant m_variant;
};
diff --git a/tests/benchmarks/qml/js/qjsengine/tst_qjsengine.cpp b/tests/benchmarks/qml/js/qjsengine/tst_qjsengine.cpp
index cb23d6edbd..dc9d31008f 100644
--- a/tests/benchmarks/qml/js/qjsengine/tst_qjsengine.cpp
+++ b/tests/benchmarks/qml/js/qjsengine/tst_qjsengine.cpp
@@ -29,6 +29,7 @@
#include <qtest.h>
#include <QtQml/qjsvalue.h>
#include <QtQml/qjsengine.h>
+#include <QtCore/qregularexpression.h>
class tst_QJSEngine : public QObject
{
@@ -346,7 +347,7 @@ void tst_QJSEngine::newFunction()
void tst_QJSEngine::newRegExp()
{
newEngine();
- QRegExp re = QRegExp("foo");
+ QRegularExpression re("foo");
QBENCHMARK {
m_engine->toScriptValue(re);
}
diff --git a/tests/benchmarks/qml/js/qjsvalue/tst_qjsvalue.cpp b/tests/benchmarks/qml/js/qjsvalue/tst_qjsvalue.cpp
index 7488d613e5..ec120b9384 100644
--- a/tests/benchmarks/qml/js/qjsvalue/tst_qjsvalue.cpp
+++ b/tests/benchmarks/qml/js/qjsvalue/tst_qjsvalue.cpp
@@ -29,6 +29,7 @@
#include <qtest.h>
#include <QtQml/qjsvalue.h>
#include <QtQml/qjsengine.h>
+#include <QtCore/qregularexpression.h>
class tst_QJSValue : public QObject
{
@@ -645,7 +646,7 @@ void tst_QJSValue::toRegExp()
{
QFETCH(QJSValue, val);
QBENCHMARK {
- qjsvalue_cast<QRegExp>(val);
+ qjsvalue_cast<QRegularExpression>(val);
}
}