diff options
Diffstat (limited to 'tests/auto/qml/qmlformat')
4 files changed, 123 insertions, 3 deletions
diff --git a/tests/auto/qml/qmlformat/data/objectDestructuring.formatted.qml b/tests/auto/qml/qmlformat/data/objectDestructuring.formatted.qml new file mode 100644 index 0000000000..b10751dcdf --- /dev/null +++ b/tests/auto/qml/qmlformat/data/objectDestructuring.formatted.qml @@ -0,0 +1,72 @@ +import QtQml + +QtObject { + + Component.onCompleted: { + set1(); + } + + function set1() { + const array = [1, 2, 3, 4]; + const [a, b] = [1, 2]; + const [aa, , bb] = array; + const [aaa = 23, bbb] = array; + const [a1, b1, ...rest1] = array; + const [a2, , b2, ...rest2] = array; + const [a3, b3, ...{ + pop, + push + }] = array; + const [a4, b4, ...[c, d]] = array; + const obj = { + _a: 1, + _b: 2 + }; + const { + a5, + b5 + } = obj; + const { + a6: a_, + b6: b1_ + } = obj; + const { + a7: a11 = 4, + b11 = 34, + c1: b111, + d1 + } = obj; + let key = a; + const { + [key]: a___ + } = obj; + } + + function set2() { + // declare first + let a, b, a1, b1, c, d, rest, pop, push; + const array = [1, 2, 3, 4]; + [a, b] = array; + [a, , b] = array; + [a = aDefault, b] = array; + [a, b, ...rest] = array; + [a, , b, ...rest] = array; + [a, b, ...{ + pop, + push + }] = array; + [a, b, ...[c, d]] = array; + const obj = { + _a: 1, + _b: 2 + }; + ({ + a, + b + } = obj); // brackets are required + ({ + a: a1, + b: b1 + } = obj); + } +} diff --git a/tests/auto/qml/qmlformat/data/objectDestructuring.qml b/tests/auto/qml/qmlformat/data/objectDestructuring.qml new file mode 100644 index 0000000000..2d377985aa --- /dev/null +++ b/tests/auto/qml/qmlformat/data/objectDestructuring.qml @@ -0,0 +1,45 @@ +import QtQml + +QtObject { + + + Component.onCompleted: { + set1(); + } + + function set1() { + const array = [1,2,3,4]; + const [a, b] = [1,2]; + const [aa, , bb] = array; + const [aaa = 23, bbb] = array; + const [a1, b1, ...rest1] = array; + const [a2, , b2, ...rest2] = array; + const [a3, b3, ...{ pop, push }] = array; + const [a4, b4, ...[c, d]] = array; + + const obj = {_a:1,_b:2}; + const { a5, b5 } = obj; + const { a6: a_, b6: b1_ } = obj; + const { a7: a11 = 4, b11 = 34, c1: b111, d1 } = obj; + let key = a; + const { [key]: a___ } = obj; + } + + function set2() { + // declare first + let a, b, a1, b1, c, d, rest, pop, push; + const array = [1,2,3,4]; + [a, b] = array; + [a, , b] = array; + [a = aDefault, b] = array; + [a, b, ...rest] = array; + [a, , b, ...rest] = array; + [a, b, ...{ pop, push }] = array; + [a, b, ...[c, d]] = array; + + const obj = {_a:1,_b:2}; + ({ a, b } = obj); // brackets are required + ({ a: a1, b: b1 } = obj); + + } +} diff --git a/tests/auto/qml/qmlformat/data/propertyNames.formatted.qml b/tests/auto/qml/qmlformat/data/propertyNames.formatted.qml index 94b5877957..9214014889 100644 --- a/tests/auto/qml/qmlformat/data/propertyNames.formatted.qml +++ b/tests/auto/qml/qmlformat/data/propertyNames.formatted.qml @@ -3,11 +3,11 @@ Item { var copiedItem = "copied value"; var computedItem = "computedName"; var obj = { - "identifierName": "identifier value", + identifierName: "identifier value", "string name": "string value", - "Infinity": "numeric value", + Infinity: "numeric value", [computedItem]: "computed value", - "copiedItem": copiedItem + copiedItem }; } } diff --git a/tests/auto/qml/qmlformat/tst_qmlformat.cpp b/tests/auto/qml/qmlformat/tst_qmlformat.cpp index e8eeb9835d..a45ae07d16 100644 --- a/tests/auto/qml/qmlformat/tst_qmlformat.cpp +++ b/tests/auto/qml/qmlformat/tst_qmlformat.cpp @@ -335,6 +335,9 @@ void TestQmlformat::testFormat_data() QTest::newRow("pragmaValueList") << "pragma.qml" << "pragma.formatted.qml" << QStringList{} << RunOption::OnCopy; + QTest::newRow("objectDestructuring") + << "objectDestructuring.qml" + << "objectDestructuring.formatted.qml" << QStringList{} << RunOption::OnCopy; } void TestQmlformat::testFormat() |