diff options
author | Maximilian Goldstein <max.goldstein@qt.io> | 2020-01-17 14:28:09 +0100 |
---|---|---|
committer | Maximilian Goldstein <max.goldstein@qt.io> | 2020-01-30 08:24:40 +0100 |
commit | e080f48f905be597b1a645f1641b2b06553df6a2 (patch) | |
tree | eef0b5d503cf94ed217eab5008dff076e8833113 /tests | |
parent | 78a69fa05e3b2af6ed640692d81e2b1c355fe525 (diff) |
qmlformat: Support even more language features
Adds support (among other things) for:
- Pragmas
- Type annotations
- get / set properties
- Some previously unsupported escape sequences (\b,\v...)
- Calling methods on numeric literals
Also now checks whether the dumped code is still parsable.
Change-Id: Ia142a7c0b3e608115e79c1d98a62b682dce4eec9
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'tests')
5 files changed, 65 insertions, 6 deletions
diff --git a/tests/auto/qml/qmlformat/data/Example1.formatted.nosort.qml b/tests/auto/qml/qmlformat/data/Example1.formatted.nosort.qml index 080cec438e..34d58cf571 100644 --- a/tests/auto/qml/qmlformat/data/Example1.formatted.nosort.qml +++ b/tests/auto/qml/qmlformat/data/Example1.formatted.nosort.qml @@ -91,11 +91,11 @@ Item { x = 100; break; } - if (x == 50) + if (x == 50) console.log("true"); - else if (x == 50) + else if (x == 50) console.log("other thing"); - else + else console.log("false"); if (x == 50) { @@ -132,6 +132,7 @@ Item { Rectangle { } ] + Text { required property string batman @@ -143,6 +144,7 @@ Item { // This comment is related to the property animation PropertyAnimation on x { id: foo + x: 3 y: x + 3 } diff --git a/tests/auto/qml/qmlformat/data/Example1.formatted.qml b/tests/auto/qml/qmlformat/data/Example1.formatted.qml index 4b65b9add6..b06734eb0b 100644 --- a/tests/auto/qml/qmlformat/data/Example1.formatted.qml +++ b/tests/auto/qml/qmlformat/data/Example1.formatted.qml @@ -91,11 +91,11 @@ Item { x = 100; break; } - if (x == 50) + if (x == 50) console.log("true"); - else if (x == 50) + else if (x == 50) console.log("other thing"); - else + else console.log("false"); if (x == 50) { @@ -132,6 +132,7 @@ Item { Rectangle { } ] + Text { required property string batman @@ -143,6 +144,7 @@ Item { // This comment is related to the property animation PropertyAnimation on x { id: foo + x: 3 y: x + 3 } diff --git a/tests/auto/qml/qmlformat/data/readOnlyProps.formatted.qml b/tests/auto/qml/qmlformat/data/readOnlyProps.formatted.qml new file mode 100644 index 0000000000..6e7cc31dcf --- /dev/null +++ b/tests/auto/qml/qmlformat/data/readOnlyProps.formatted.qml @@ -0,0 +1,29 @@ +import QtQuick 2.0 + +QtObject { + // Testing UiObjectBinding + readonly property Item + item: Item { + id: test + + signal foo() + } + // End comment + + // Testing UiArrayBinding + readonly property list<Item> array: [ + Item { + id: test1 + + signal foo() + }, + Item { + id: test2 + + signal bar() + } + ] + // Testing UiScriptBinding + readonly property int script: Math.sin(Math.PI) + property bool normalProperty: true +} diff --git a/tests/auto/qml/qmlformat/data/readOnlyProps.qml b/tests/auto/qml/qmlformat/data/readOnlyProps.qml new file mode 100644 index 0000000000..8a32dd131e --- /dev/null +++ b/tests/auto/qml/qmlformat/data/readOnlyProps.qml @@ -0,0 +1,15 @@ +import QtQuick 2.0 + +QtObject { + // Testing UiObjectBinding + readonly property Item item: Item { id: test; signal foo() } + // End comment + + // Testing UiArrayBinding + readonly property list<Item> array: [ Item { id: test1; signal foo() }, Item { id: test2; signal bar() } ] + + // Testing UiScriptBinding + readonly property int script: Math.sin(Math.PI) + + property bool normalProperty: true +} diff --git a/tests/auto/qml/qmlformat/tst_qmlformat.cpp b/tests/auto/qml/qmlformat/tst_qmlformat.cpp index 95c8e88f21..3201fa5ace 100644 --- a/tests/auto/qml/qmlformat/tst_qmlformat.cpp +++ b/tests/auto/qml/qmlformat/tst_qmlformat.cpp @@ -42,6 +42,7 @@ private Q_SLOTS: void testFormat(); void testFormatNoSort(); + void testReadOnlyProps(); #if !defined(QTEST_CROSS_COMPILED) // sources not available when cross compiled void testExample(); @@ -120,6 +121,11 @@ void TestQmlformat::initTestCase() m_invalidFiles << "tests/auto/qml/qqmllanguage/data/nullishCoalescing_RHS_Or.qml"; m_invalidFiles << "tests/auto/qml/qqmllanguage/data/typeAnnotations.2.qml"; m_invalidFiles << "tests/auto/qml/qqmlparser/data/disallowedtypeannotations/qmlnestedfunction.qml"; + + // These files rely on exact formatting + m_invalidFiles << "tests/auto/qml/qqmlecmascript/data/incrDecrSemicolon1.qml"; + m_invalidFiles << "tests/auto/qml/qqmlecmascript/data/incrDecrSemicolon_error1.qml"; + m_invalidFiles << "tests/auto/qml/qqmlecmascript/data/incrDecrSemicolon2.qml"; } QStringList TestQmlformat::findFiles(const QDir &d) @@ -178,6 +184,11 @@ void TestQmlformat::testFormatNoSort() QCOMPARE(runQmlformat(testFile("Example1.qml"), false, true), readTestFile("Example1.formatted.nosort.qml")); } +void TestQmlformat::testReadOnlyProps() +{ + QCOMPARE(runQmlformat(testFile("readOnlyProps.qml"), false, true), readTestFile("readOnlyProps.formatted.qml")); +} + #if !defined(QTEST_CROSS_COMPILED) // sources not available when cross compiled void TestQmlformat::testExample_data() { |