From 1ac3dd0e7adbca0e18daac10ef5e104ca1e5fe87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCri=20Valdmann?= Date: Fri, 28 Sep 2018 14:02:04 +0200 Subject: Add test for importing let/const variables from scripts Try to import let/const variables from JS scripts into QML. Task-number: QTBUG-69408 Change-Id: Ie58cbc8cd9f8a47f5a077f95b07b5f9e1524707a Reviewed-by: Simon Hausmann --- .../auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp | 34 ++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp') diff --git a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp index cf3eecff6d..8f388fcac6 100644 --- a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp +++ b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp @@ -357,6 +357,8 @@ private slots: void jumpStrictNotEqualUndefined(); void removeBindingsWithNoDependencies(); void temporaryDeadZone(); + void importLexicalVariables_data(); + void importLexicalVariables(); private: // static void propertyVarWeakRefCallback(v8::Persistent object, void* parameter); @@ -8812,6 +8814,38 @@ void tst_qqmlecmascript::temporaryDeadZone() QVERIFY(v.isError()); } +void tst_qqmlecmascript::importLexicalVariables_data() +{ + QTest::addColumn("testFile"); + QTest::addColumn("expected"); + + QTest::newRow("script") + << testFileUrl("importLexicalVariables_script.qml") + << QStringLiteral("0?? 1?? 2??"); + QTest::newRow("pragmaLibrary") + << testFileUrl("importLexicalVariables_pragmaLibrary.qml") + << QStringLiteral("0?? 1?? 2??"); + QTest::newRow("module") + << testFileUrl("importLexicalVariables_module.qml") + << QStringLiteral("000 000 110"); +} + +void tst_qqmlecmascript::importLexicalVariables() +{ + QFETCH(QUrl, testFile); + QFETCH(QString, expected); + + QQmlEngine engine; + QQmlComponent component(&engine, testFile); + QScopedPointer object(component.create()); + QVERIFY(object != nullptr); + QVERIFY(!component.isError()); + + QVariant result; + QMetaObject::invokeMethod(object.data(), "runTest", Qt::DirectConnection, Q_RETURN_ARG(QVariant, result)); + QCOMPARE(result, QVariant(expected)); +} + QTEST_MAIN(tst_qqmlecmascript) #include "tst_qqmlecmascript.moc" -- cgit v1.2.3