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 <simon.hausmann@qt.io>
This commit is contained in:
parent
f8ee8e4e8b
commit
1ac3dd0e7a
|
@ -0,0 +1,31 @@
|
|||
export function runTest(libraryUnderTest) {
|
||||
let state1 = state(libraryUnderTest);
|
||||
try { modifyFromOutside(libraryUnderTest); } catch (e) {}
|
||||
let state2 = state(libraryUnderTest);
|
||||
try { modifyFromInside(libraryUnderTest); } catch (e) {}
|
||||
let state3 = state(libraryUnderTest);
|
||||
return state1 + " " + state2 + " " + state3;
|
||||
}
|
||||
|
||||
function stringify(value) {
|
||||
let s = "?";
|
||||
if (value !== undefined)
|
||||
s = value.toString();
|
||||
return s;
|
||||
}
|
||||
|
||||
function state(libraryUnderTest) {
|
||||
return (stringify(libraryUnderTest.varValue) +
|
||||
stringify(libraryUnderTest.letValue) +
|
||||
stringify(libraryUnderTest.constValue));
|
||||
}
|
||||
|
||||
function modifyFromOutside(libraryUnderTest) {
|
||||
++libraryUnderTest.varValue;
|
||||
++libraryUnderTest.letValue;
|
||||
++libraryUnderTest.constValue;
|
||||
}
|
||||
|
||||
function modifyFromInside(libraryUnderTest) {
|
||||
libraryUnderTest.incrementAll();
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
export var varValue = 0;
|
||||
export let letValue = 0;
|
||||
export const constValue = 0;
|
||||
export function incrementAll() {
|
||||
++varValue;
|
||||
++letValue;
|
||||
++constValue;
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
import QtQuick 2.0
|
||||
import "importLexicalVariables.mjs" as TestRunner
|
||||
import "importLexicalVariables_module.mjs" as LibraryUnderTest
|
||||
|
||||
QtObject {
|
||||
id: root
|
||||
function runTest() {
|
||||
return TestRunner.runTest(LibraryUnderTest);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
.pragma library
|
||||
var varValue = 0;
|
||||
let letValue = 0;
|
||||
const constValue = 0;
|
||||
function incrementAll() {
|
||||
++varValue;
|
||||
++letValue;
|
||||
++constValue;
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
import QtQuick 2.0
|
||||
import "importLexicalVariables.mjs" as TestRunner
|
||||
import "importLexicalVariables_pragmaLibrary.js" as LibraryUnderTest
|
||||
|
||||
QtObject {
|
||||
id: root
|
||||
function runTest() {
|
||||
return TestRunner.runTest(LibraryUnderTest);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
var varValue = 0;
|
||||
let letValue = 0;
|
||||
const constValue = 0;
|
||||
function incrementAll() {
|
||||
++varValue;
|
||||
++letValue;
|
||||
++constValue;
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
import QtQuick 2.0
|
||||
import "importLexicalVariables.mjs" as TestRunner
|
||||
import "importLexicalVariables_script.js" as LibraryUnderTest
|
||||
|
||||
QtObject {
|
||||
id: root
|
||||
function runTest() {
|
||||
return TestRunner.runTest(LibraryUnderTest);
|
||||
}
|
||||
}
|
|
@ -357,6 +357,8 @@ private slots:
|
|||
void jumpStrictNotEqualUndefined();
|
||||
void removeBindingsWithNoDependencies();
|
||||
void temporaryDeadZone();
|
||||
void importLexicalVariables_data();
|
||||
void importLexicalVariables();
|
||||
|
||||
private:
|
||||
// static void propertyVarWeakRefCallback(v8::Persistent<v8::Value> object, void* parameter);
|
||||
|
@ -8812,6 +8814,38 @@ void tst_qqmlecmascript::temporaryDeadZone()
|
|||
QVERIFY(v.isError());
|
||||
}
|
||||
|
||||
void tst_qqmlecmascript::importLexicalVariables_data()
|
||||
{
|
||||
QTest::addColumn<QUrl>("testFile");
|
||||
QTest::addColumn<QString>("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<QObject> 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"
|
||||
|
|
Loading…
Reference in New Issue