diff options
author | Lars Knoll <lars.knoll@qt.io> | 2020-04-02 09:57:13 +0200 |
---|---|---|
committer | Lars Knoll <lars.knoll@qt.io> | 2020-04-03 21:01:49 +0200 |
commit | 55be24d6b6e66bd54168021f5a467ba4da73b2c6 (patch) | |
tree | 07f3165aebbe539dc506e78f1f4040471d32ab62 /tests/auto | |
parent | e1bc9db85149b89feb73f1690fd218de498b8b27 (diff) |
Remove QRegExp from qml autotests
QRegExp will get removed in Qt6. Clean up by removing dependencies
on QRegExp in the autotests.
Change-Id: I8ef8561ba30b98b61cd9ed52907b48c5969f2c49
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'tests/auto')
-rw-r--r-- | tests/auto/qml/debugger/shared/qqmldebugprocess.cpp | 7 | ||||
-rw-r--r-- | tests/auto/qml/qjsengine/tst_qjsengine.cpp | 124 | ||||
-rw-r--r-- | tests/auto/qml/qjsvalue/tst_qjsvalue.cpp | 44 | ||||
-rw-r--r-- | tests/auto/qml/qjsvalue/tst_qjsvalue.h | 1 | ||||
-rw-r--r-- | tests/auto/qml/qqmlecmascript/data/regExp.2.qml | 7 | ||||
-rw-r--r-- | tests/auto/qml/qqmlecmascript/data/regExp.qml | 7 | ||||
-rw-r--r-- | tests/auto/qml/qqmlecmascript/testtypes.h | 5 | ||||
-rw-r--r-- | tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp | 17 | ||||
-rw-r--r-- | tests/auto/qml/qquickworkerscript/tst_qquickworkerscript.cpp | 14 |
9 files changed, 20 insertions, 206 deletions
diff --git a/tests/auto/qml/debugger/shared/qqmldebugprocess.cpp b/tests/auto/qml/debugger/shared/qqmldebugprocess.cpp index 956e97e7ba..d2ac7f3772 100644 --- a/tests/auto/qml/debugger/shared/qqmldebugprocess.cpp +++ b/tests/auto/qml/debugger/shared/qqmldebugprocess.cpp @@ -31,6 +31,7 @@ #include <QtCore/qdebug.h> #include <QtCore/qfileinfo.h> #include <QtCore/qdir.h> +#include <QtCore/qregularexpression.h> QQmlDebugProcess::QQmlDebugProcess(const QString &executable, QObject *parent) : QObject(parent) @@ -194,9 +195,9 @@ void QQmlDebugProcess::processAppOutput() m_outputBuffer = m_outputBuffer.right(m_outputBuffer.size() - nlIndex - 1); if (line.contains("QML Debugger:")) { - const QRegExp portRx("Waiting for connection on port (\\d+)"); - if (portRx.indexIn(line) != -1) { - m_port = portRx.cap(1).toInt(); + auto portRx = QRegularExpression("Waiting for connection on port (\\d+)").match(line); + if (portRx.hasMatch()) { + m_port = portRx.captured(1).toInt(); m_timer.stop(); m_state = SessionStarted; m_eventLoop.quit(); diff --git a/tests/auto/qml/qjsengine/tst_qjsengine.cpp b/tests/auto/qml/qjsengine/tst_qjsengine.cpp index 1d859021ad..8c30e64a15 100644 --- a/tests/auto/qml/qjsengine/tst_qjsengine.cpp +++ b/tests/auto/qml/qjsengine/tst_qjsengine.cpp @@ -97,7 +97,6 @@ private slots: void valueConversion_QVariant(); void valueConversion_basic2(); void valueConversion_dateTime(); - void valueConversion_regExp(); void valueConversion_RegularExpression(); void castWithMultipleInheritance(); void collectGarbage(); @@ -138,8 +137,6 @@ private slots: void arrayConcat(); void recursiveBoundFunctions(); - void qRegExpInport_data(); - void qRegExpInport(); void qRegularExpressionImport_data(); void qRegularExpressionImport(); void qRegularExpressionExport_data(); @@ -574,7 +571,6 @@ void tst_QJSEngine::toScriptValuenotroundtripped_data() QTest::newRow("QList<QPoint>") << QVariant::fromValue(QList<QPointF>() << QPointF(42.24, 24.42) << QPointF(42.24, 24.42)) << QVariant(QVariantList() << QPointF(42.24, 24.42) << QPointF(42.24, 24.42)); QTest::newRow("QVector<QPoint>") << QVariant::fromValue(QVector<QPointF>() << QPointF(42.24, 24.42) << QPointF(42.24, 24.42)) << QVariant(QVariantList() << QPointF(42.24, 24.42) << QPointF(42.24, 24.42)); QTest::newRow("VoidStar") << QVariant(int(QMetaType::VoidStar), nullptr) << QVariant(int(QMetaType::Nullptr), nullptr); - QTest::newRow("qregex") << QVariant(QRegExp(".*", Qt::CaseSensitive, QRegExp::RegExp2)) << QVariant(QRegularExpression(".*")); } // This is almost the same as toScriptValue, but the inputs don't roundtrip to @@ -633,27 +629,22 @@ void tst_QJSEngine::newVariant_valueOfEnum() void tst_QJSEngine::newRegExp() { QJSEngine eng; - QJSValue rexps[] = { - eng.toScriptValue(QRegularExpression("foo")), - eng.toScriptValue(QRegExp("foo")) - }; - for (const auto &rexp : rexps) { - QVERIFY(!rexp.isUndefined()); - QCOMPARE(rexp.isRegExp(), true); - QCOMPARE(rexp.isObject(), true); - QCOMPARE(rexp.isCallable(), false); - // prototype should be RegExp.prototype - QVERIFY(!rexp.prototype().isUndefined()); - QCOMPARE(rexp.prototype().isObject(), true); - // Get [[Class]] internal property of RegExp Prototype Object. - // See ECMA-262 Section 8.6.2, "Object Internal Properties and Methods". - // See ECMA-262 Section 15.10.6, "Properties of the RegExp Prototype Object". - QJSValue r = eng.evaluate("Object.prototype.toString.call(RegExp.prototype)"); - QCOMPARE(r.toString(), QString::fromLatin1("[object Object]")); - QCOMPARE(rexp.prototype().strictlyEquals(eng.evaluate("RegExp.prototype")), true); + QJSValue rexp = eng.toScriptValue(QRegularExpression("foo")); + QVERIFY(!rexp.isUndefined()); + QCOMPARE(rexp.isRegExp(), true); + QCOMPARE(rexp.isObject(), true); + QCOMPARE(rexp.isCallable(), false); + // prototype should be RegExp.prototype + QVERIFY(!rexp.prototype().isUndefined()); + QCOMPARE(rexp.prototype().isObject(), true); + // Get [[Class]] internal property of RegExp Prototype Object. + // See ECMA-262 Section 8.6.2, "Object Internal Properties and Methods". + // See ECMA-262 Section 15.10.6, "Properties of the RegExp Prototype Object". + QJSValue r = eng.evaluate("Object.prototype.toString.call(RegExp.prototype)"); + QCOMPARE(r.toString(), QString::fromLatin1("[object Object]")); + QCOMPARE(rexp.prototype().strictlyEquals(eng.evaluate("RegExp.prototype")), true); - QCOMPARE(qjsvalue_cast<QRegExp>(rexp).pattern(), QRegExp("foo").pattern()); - } + QCOMPARE(qjsvalue_cast<QRegularExpression>(rexp).pattern(), QRegularExpression("foo").pattern()); } void tst_QJSEngine::jsRegExp() @@ -1687,36 +1678,6 @@ void tst_QJSEngine::valueConversion_dateTime() } } -void tst_QJSEngine::valueConversion_regExp() -{ - QJSEngine eng; - { - QRegExp in = QRegExp("foo"); - QJSValue val = eng.toScriptValue(in); - QVERIFY(val.isRegExp()); - QRegExp out = qjsvalue_cast<QRegExp>(val); - QEXPECT_FAIL("", "QTBUG-6136: JSC-based back-end doesn't preserve QRegExp::patternSyntax (always uses RegExp2)", Continue); - QCOMPARE(out.patternSyntax(), in.patternSyntax()); - QCOMPARE(out.pattern(), in.pattern()); - QCOMPARE(out.caseSensitivity(), in.caseSensitivity()); - QCOMPARE(out.isMinimal(), in.isMinimal()); - } - { - QRegExp in = QRegExp("foo", Qt::CaseSensitive, QRegExp::RegExp2); - QJSValue val = eng.toScriptValue(in); - QVERIFY(val.isRegExp()); - QCOMPARE(qjsvalue_cast<QRegExp>(val), in); - } - { - QRegExp in = QRegExp("foo"); - in.setMinimal(true); - QJSValue val = eng.toScriptValue(in); - QVERIFY(val.isRegExp()); - QEXPECT_FAIL("", "QTBUG-6136: JSC-based back-end doesn't preserve QRegExp::minimal (always false)", Continue); - QCOMPARE(qjsvalue_cast<QRegExp>(val).isMinimal(), in.isMinimal()); - } -} - void tst_QJSEngine::valueConversion_RegularExpression() { QJSEngine eng; @@ -3086,8 +3047,6 @@ void tst_QJSEngine::reentrancy_objectCreation() { QJSValue r1 = eng1.evaluate("new RegExp('foo', 'gim')"); QJSValue r2 = eng2.evaluate("new RegExp('foo', 'gim')"); - QCOMPARE(qjsvalue_cast<QRegExp>(r1), qjsvalue_cast<QRegExp>(r2)); - QCOMPARE(qjsvalue_cast<QRegExp>(r2), qjsvalue_cast<QRegExp>(r1)); QCOMPARE(qjsvalue_cast<QRegularExpression>(r1), qjsvalue_cast<QRegularExpression>(r2)); QCOMPARE(qjsvalue_cast<QRegularExpression>(r2), qjsvalue_cast<QRegularExpression>(r1)); } @@ -3232,59 +3191,6 @@ void tst_QJSEngine::recursiveBoundFunctions() QCOMPARE(v.toInt(), 59); } -static QRegExp minimal(QRegExp r) { r.setMinimal(true); return r; } - -void tst_QJSEngine::qRegExpInport_data() -{ - QTest::addColumn<QRegExp>("rx"); - QTest::addColumn<QString>("string"); - QTest::addColumn<QString>("matched"); - - QTest::newRow("normal") << QRegExp("(test|foo)") << "test _ foo _ test _ Foo"; - QTest::newRow("normal2") << QRegExp("(Test|Foo)") << "test _ foo _ test _ Foo"; - QTest::newRow("case insensitive)") << QRegExp("(test|foo)", Qt::CaseInsensitive) << "test _ foo _ test _ Foo"; - QTest::newRow("case insensitive2)") << QRegExp("(Test|Foo)", Qt::CaseInsensitive) << "test _ foo _ test _ Foo"; - QTest::newRow("b(a*)(b*)") << QRegExp("b(a*)(b*)", Qt::CaseInsensitive) << "aaabbBbaAabaAaababaaabbaaab"; - QTest::newRow("greedy") << QRegExp("a*(a*)", Qt::CaseInsensitive, QRegExp::RegExp2) << "aaaabaaba"; - QTest::newRow("willcard") << QRegExp("*.txt", Qt::CaseSensitive, QRegExp::Wildcard) << "file.txt"; - QTest::newRow("willcard 2") << QRegExp("a?b.txt", Qt::CaseSensitive, QRegExp::Wildcard) << "ab.txt abb.rtc acb.txt"; - QTest::newRow("slash") << QRegExp("g/.*/s", Qt::CaseInsensitive, QRegExp::RegExp2) << "string/string/string"; - QTest::newRow("slash2") << QRegExp("g / .* / s", Qt::CaseInsensitive, QRegExp::RegExp2) << "string / string / string"; - QTest::newRow("fixed") << QRegExp("a*aa.a(ba)*a\\ba", Qt::CaseInsensitive, QRegExp::FixedString) << "aa*aa.a(ba)*a\\ba"; - QTest::newRow("fixed insensitive") << QRegExp("A*A", Qt::CaseInsensitive, QRegExp::FixedString) << "a*A A*a A*A a*a"; - QTest::newRow("fixed sensitive") << QRegExp("A*A", Qt::CaseSensitive, QRegExp::FixedString) << "a*A A*a A*A a*a"; - QTest::newRow("html") << QRegExp("<b>(.*)</b>", Qt::CaseSensitive, QRegExp::RegExp2) << "<b>bold</b><i>italic</i><b>bold</b>"; - QTest::newRow("html minimal") << minimal(QRegExp("<b>(.*)</b>", Qt::CaseSensitive, QRegExp::RegExp2)) << "<b>bold</b><i>italic</i><b>bold</b>"; - QTest::newRow("aaa") << QRegExp("a{2,5}") << "aAaAaaaaaAa"; - QTest::newRow("aaa minimal") << minimal(QRegExp("a{2,5}")) << "aAaAaaaaaAa"; - QTest::newRow("minimal") << minimal(QRegExp(".*\\} [*8]")) << "}?} ?} *"; - QTest::newRow(".? minimal") << minimal(QRegExp(".?")) << ".?"; - QTest::newRow(".+ minimal") << minimal(QRegExp(".+")) << ".+"; - QTest::newRow("[.?] minimal") << minimal(QRegExp("[.?]")) << ".?"; - QTest::newRow("[.+] minimal") << minimal(QRegExp("[.+]")) << ".+"; -} - -void tst_QJSEngine::qRegExpInport() -{ - QFETCH(QRegExp, rx); - QFETCH(QString, string); - - QJSEngine eng; - QJSValue rexp; - rexp = eng.toScriptValue(rx); - - QCOMPARE(rexp.isRegExp(), true); - QCOMPARE(rexp.isCallable(), false); - - QJSValue func = eng.evaluate("(function(string, regexp) { return string.match(regexp); })"); - QJSValue result = func.call(QJSValueList() << string << rexp); - - rx.indexIn(string); - for (int i = 0; i <= rx.captureCount(); i++) { - QCOMPARE(result.property(i).toString(), rx.cap(i)); - } -} - void tst_QJSEngine::qRegularExpressionImport_data() { QTest::addColumn<QRegularExpression>("rx"); diff --git a/tests/auto/qml/qjsvalue/tst_qjsvalue.cpp b/tests/auto/qml/qjsvalue/tst_qjsvalue.cpp index 85c29957b4..2420aea9b8 100644 --- a/tests/auto/qml/qjsvalue/tst_qjsvalue.cpp +++ b/tests/auto/qml/qjsvalue/tst_qjsvalue.cpp @@ -1076,20 +1076,6 @@ void tst_QJSValue::toVariant() } { - QRegExp rx = QRegExp("[0-9a-z]+", Qt::CaseSensitive, QRegExp::RegExp2); - QJSValue rxObject = eng.toScriptValue(rx); - QVERIFY(rxObject.isRegExp()); - QVariant var = rxObject.toVariant(); - - // We can't roundtrip a QRegExp this way, as toVariant() has no information on whether we - // want QRegExp or QRegularExpression. It will always create a QRegularExpression. - QCOMPARE(var.userType(), QMetaType::QRegularExpression); - QRegularExpression result = var.toRegularExpression(); - QCOMPARE(result.pattern(), rx.pattern()); - QCOMPARE(result.patternOptions() & QRegularExpression::CaseInsensitiveOption, 0); - } - - { QRegularExpression rx = QRegularExpression("[0-9a-z]+"); QJSValue rxObject = eng.toScriptValue(rx); QVERIFY(rxObject.isRegExp()); @@ -1236,36 +1222,6 @@ void tst_QJSValue::toDateTime() QVERIFY(!eng.toScriptValue(QVariant()).toDateTime().isValid()); } -void tst_QJSValue::toRegExp() -{ - QJSEngine eng; - { - QRegExp rx = qjsvalue_cast<QRegExp>(eng.evaluate("/foo/")); - QVERIFY(rx.isValid()); - QCOMPARE(rx.patternSyntax(), QRegExp::RegExp2); - QCOMPARE(rx.pattern(), QString::fromLatin1("foo")); - QCOMPARE(rx.caseSensitivity(), Qt::CaseSensitive); - QVERIFY(!rx.isMinimal()); - } - { - QRegExp rx = qjsvalue_cast<QRegExp>(eng.evaluate("/bar/gi")); - QVERIFY(rx.isValid()); - QCOMPARE(rx.patternSyntax(), QRegExp::RegExp2); - QCOMPARE(rx.pattern(), QString::fromLatin1("bar")); - QCOMPARE(rx.caseSensitivity(), Qt::CaseInsensitive); - QVERIFY(!rx.isMinimal()); - } - - QVERIFY(qjsvalue_cast<QRegExp>(eng.evaluate("[]")).isEmpty()); - QVERIFY(qjsvalue_cast<QRegExp>(eng.evaluate("{}")).isEmpty()); - QVERIFY(qjsvalue_cast<QRegExp>(eng.globalObject()).isEmpty()); - QVERIFY(qjsvalue_cast<QRegExp>(QJSValue()).isEmpty()); - QVERIFY(qjsvalue_cast<QRegExp>(QJSValue(123)).isEmpty()); - QVERIFY(qjsvalue_cast<QRegExp>(QJSValue(false)).isEmpty()); - QVERIFY(qjsvalue_cast<QRegExp>(eng.evaluate("null")).isEmpty()); - QVERIFY(qjsvalue_cast<QRegExp>(eng.toScriptValue(QVariant())).isEmpty()); -} - void tst_QJSValue::toRegularExpression() { QJSEngine eng; diff --git a/tests/auto/qml/qjsvalue/tst_qjsvalue.h b/tests/auto/qml/qjsvalue/tst_qjsvalue.h index d85b9a0552..63558bbbca 100644 --- a/tests/auto/qml/qjsvalue/tst_qjsvalue.h +++ b/tests/auto/qml/qjsvalue/tst_qjsvalue.h @@ -73,7 +73,6 @@ private slots: void toQObject_nonQObject(); void toQObject(); void toDateTime(); - void toRegExp(); void toRegularExpression(); void isArray_data(); void isArray(); diff --git a/tests/auto/qml/qqmlecmascript/data/regExp.2.qml b/tests/auto/qml/qqmlecmascript/data/regExp.2.qml deleted file mode 100644 index 68cca5733b..0000000000 --- a/tests/auto/qml/qqmlecmascript/data/regExp.2.qml +++ /dev/null @@ -1,7 +0,0 @@ -import Qt.test 1.0 - -MyQmlObject{ - id: obj - objectName: "obj" - regExp: "[a-zA-z]" -} diff --git a/tests/auto/qml/qqmlecmascript/data/regExp.qml b/tests/auto/qml/qqmlecmascript/data/regExp.qml deleted file mode 100644 index 0dc404b5db..0000000000 --- a/tests/auto/qml/qqmlecmascript/data/regExp.qml +++ /dev/null @@ -1,7 +0,0 @@ -import Qt.test 1.0 - -MyQmlObject{ - id: obj - objectName: "obj" - regExp: /[a-zA-z]/ -} diff --git a/tests/auto/qml/qqmlecmascript/testtypes.h b/tests/auto/qml/qqmlecmascript/testtypes.h index 415e884eb8..b999c670a8 100644 --- a/tests/auto/qml/qqmlecmascript/testtypes.h +++ b/tests/auto/qml/qqmlecmascript/testtypes.h @@ -100,7 +100,6 @@ 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 regularExpression READ regularExpression WRITE setRegularExpression) Q_PROPERTY(int nonscriptable READ nonscriptable WRITE setNonscriptable SCRIPTABLE false) Q_PROPERTY(int intProperty READ intProperty WRITE setIntProperty NOTIFY intChanged) @@ -168,9 +167,6 @@ public: void setResettableProperty(int v) { m_resetProperty = v; } void resetProperty() { m_resetProperty = 13; } - QRegExp regExp() { return m_regExp; } - void setRegExp(const QRegExp ®Exp) { m_regExp = regExp; } - QRegularExpression regularExpression() { return m_regularExpression; } void setRegularExpression(const QRegularExpression ®ularExpression) { @@ -276,7 +272,6 @@ private: QList<QObject *> m_objectQList; int m_value; int m_resetProperty; - QRegExp m_regExp; QRegularExpression m_regularExpression; QVariant m_variant; QJSValue m_qjsvalue; diff --git a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp index fc50c2a09f..94a51f7f7b 100644 --- a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp +++ b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp @@ -2529,14 +2529,6 @@ void tst_qqmlecmascript::regExpBug() //QTBUG-9367 { - QQmlComponent component(&engine, testFileUrl("regExp.qml")); - MyQmlObject *object = qobject_cast<MyQmlObject*>(component.create()); - QVERIFY(object != nullptr); - QCOMPARE(object->regExp().pattern(), QLatin1String("[a-zA-z]")); - delete object; - } - - { QQmlComponent component(&engine, testFileUrl("regularExpression.qml")); QScopedPointer<MyQmlObject> object(qobject_cast<MyQmlObject*>(component.create())); QVERIFY(!object.isNull()); @@ -2545,15 +2537,6 @@ void tst_qqmlecmascript::regExpBug() //QTBUG-23068 { - QString err = QString(QLatin1String("%1:6 Invalid property assignment: regular expression expected; use /pattern/ syntax\n")).arg(testFileUrl("regExp.2.qml").toString()); - QQmlComponent component(&engine, testFileUrl("regExp.2.qml")); - QTest::ignoreMessage(QtWarningMsg, "QQmlComponent: Component is not ready"); - MyQmlObject *object = qobject_cast<MyQmlObject*>(component.create()); - QVERIFY(!object); - QCOMPARE(component.errorString(), err); - } - - { const QString err = QString::fromLatin1("%1:6 Invalid property assignment: " "regular expression expected; " "use /pattern/ syntax\n") diff --git a/tests/auto/qml/qquickworkerscript/tst_qquickworkerscript.cpp b/tests/auto/qml/qquickworkerscript/tst_qquickworkerscript.cpp index 2f79f7157f..b093dcaf07 100644 --- a/tests/auto/qml/qquickworkerscript/tst_qquickworkerscript.cpp +++ b/tests/auto/qml/qquickworkerscript/tst_qquickworkerscript.cpp @@ -138,17 +138,7 @@ void tst_QQuickWorkerScript::messaging() if (response.userType() == qMetaTypeId<QJSValue>()) response = response.value<QJSValue>().toVariant(); - if (value.type() == QMetaType::QRegExp && response.type() == QMetaType::QRegularExpression) { - // toVariant() doesn't know if we want QRegExp or QRegularExpression. It always creates - // a QRegularExpression from a JavaScript regular expression. - const QRegularExpression responseRegExp = response.toRegularExpression(); - const QRegExp valueRegExp = value.toRegExp(); - QCOMPARE(responseRegExp.pattern(), valueRegExp.pattern()); - QCOMPARE(bool(responseRegExp.patternOptions() & QRegularExpression::CaseInsensitiveOption), - bool(valueRegExp.caseSensitivity() == Qt::CaseInsensitive)); - } else { - QCOMPARE(response, value); - } + QCOMPARE(response, value); qApp->processEvents(); delete worker; @@ -165,8 +155,6 @@ void tst_QQuickWorkerScript::messaging_data() QTest::newRow("string") << QVariant::fromValue(QString("More cheeeese, Gromit!")); QTest::newRow("variant list") << QVariant::fromValue((QVariantList() << "a" << "b" << "c")); QTest::newRow("date time") << QVariant::fromValue(QDateTime::currentDateTime()); - QTest::newRow("regexp") << QVariant::fromValue(QRegExp("^\\d\\d?$", Qt::CaseInsensitive, - QRegExp::RegExp2)); QTest::newRow("regularexpression") << QVariant::fromValue(QRegularExpression( "^\\d\\d?$", QRegularExpression::CaseInsensitiveOption)); QTest::newRow("url") << QVariant::fromValue(QUrl("http://example.com/foo/bar")); |