aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml/qmlformat
diff options
context:
space:
mode:
authorSemih Yavuz <semih.yavuz@qt.io>2023-07-31 15:12:01 +0200
committerSemih Yavuz <semih.yavuz@qt.io>2023-08-01 14:06:18 +0200
commit115916f217b0dc299b8df298f5c9c30369f561f8 (patch)
tree532480f530550042c2aa3ee1ce8022af564a7346 /tests/auto/qml/qmlformat
parent26bc3ab5b0c0b3d43a3d8e43fb84e248b25401f2 (diff)
qmlformat: fix formatting of object destructuring
The following issues are fixed: - [1]Incorrect detection of the property name as a string literal and thus writing out them with quotation marks - [2] Duplication of property name when a scoped variable is used as property key - [3] Writing out additional brackets during deconstruction - [4] Incorrect formatting when a default is assigned to a lhs variable like [a = 24, b] = array - [5] Automatic addition of "" characters into the object keys - [6] Automatic addition of assignment operator, instead only add it when there is a pending initializer Also, add the colon token location which was missing in the pattern property rules. Remove it from a couple of rules that was giving incorrect result. We require the location information of the colon token to be correct when formatting. A few of tst_qmlformat and tst_reformatter tests are adapted to the above mentioned changes [1], [2], [5]. [ChangeLog][qmlformat][Important Behavior Changes] qmlformat will no longer add "" characters automatically in the object keys unless the object key is actually a string literal. Also, using a scoped variable as the property key will no longer result in the duplication of the property name. Pick-to: 6.6 Fixes: QTBUG-108275 Fixes: QTBUG-114839 Change-Id: I272d41d13df34ff5877f3efebe43c80255dd7c2b Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'tests/auto/qml/qmlformat')
-rw-r--r--tests/auto/qml/qmlformat/data/objectDestructuring.formatted.qml72
-rw-r--r--tests/auto/qml/qmlformat/data/objectDestructuring.qml45
-rw-r--r--tests/auto/qml/qmlformat/data/propertyNames.formatted.qml6
-rw-r--r--tests/auto/qml/qmlformat/tst_qmlformat.cpp3
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()