diff options
7 files changed, 26 insertions, 3 deletions
diff --git a/tests/auto/qml/qmlformat/data/Example1.formatted.nosort.qml b/tests/auto/qml/qmlformat/data/Example1.formatted.nosort.qml index 34d58cf571..fdc0b1f68c 100644 --- a/tests/auto/qml/qmlformat/data/Example1.formatted.nosort.qml +++ b/tests/auto/qml/qmlformat/data/Example1.formatted.nosort.qml @@ -97,7 +97,6 @@ Item { console.log("other thing"); else console.log("false"); - if (x == 50) { console.log("true"); } else if (x == 50) { diff --git a/tests/auto/qml/qmlformat/data/Example1.formatted.qml b/tests/auto/qml/qmlformat/data/Example1.formatted.qml index b06734eb0b..5f12517781 100644 --- a/tests/auto/qml/qmlformat/data/Example1.formatted.qml +++ b/tests/auto/qml/qmlformat/data/Example1.formatted.qml @@ -97,7 +97,6 @@ Item { console.log("other thing"); else console.log("false"); - if (x == 50) { console.log("true"); } else if (x == 50) { diff --git a/tests/auto/qml/qmlformat/data/IfBlocks.formatted.qml b/tests/auto/qml/qmlformat/data/IfBlocks.formatted.qml index b8e77ec23a..b26361d5bf 100644 --- a/tests/auto/qml/qmlformat/data/IfBlocks.formatted.qml +++ b/tests/auto/qml/qmlformat/data/IfBlocks.formatted.qml @@ -24,7 +24,6 @@ Item { console.log("bar"); else console.log("baz"); - //// The following if blocks should HAVE braces // Single branch, braces if (true) { diff --git a/tests/auto/qml/qmlformat/data/QtBug85003.formatted.qml b/tests/auto/qml/qmlformat/data/QtBug85003.formatted.qml new file mode 100644 index 0000000000..ee42b39571 --- /dev/null +++ b/tests/auto/qml/qmlformat/data/QtBug85003.formatted.qml @@ -0,0 +1,8 @@ +Item { + Component.onCompleted: { + if (3 < 2) + console.log("Foo"); + else + console.log("Bar"); + } +} diff --git a/tests/auto/qml/qmlformat/data/QtBug85003.qml b/tests/auto/qml/qmlformat/data/QtBug85003.qml new file mode 100644 index 0000000000..5d039cb9ca --- /dev/null +++ b/tests/auto/qml/qmlformat/data/QtBug85003.qml @@ -0,0 +1,6 @@ +Item { + Component.onCompleted: + { + if (3 < 2) console.log("Foo"); else { console.log("Bar"); } + } +} diff --git a/tests/auto/qml/qmlformat/tst_qmlformat.cpp b/tests/auto/qml/qmlformat/tst_qmlformat.cpp index 7690f78e9d..ecb53b295f 100644 --- a/tests/auto/qml/qmlformat/tst_qmlformat.cpp +++ b/tests/auto/qml/qmlformat/tst_qmlformat.cpp @@ -55,6 +55,8 @@ private Q_SLOTS: void testLargeBindings(); void testInlineComponents(); + void testQtbug85003(); + #if !defined(QTEST_CROSS_COMPILED) // sources not available when cross compiled void testExample(); void testExample_data(); @@ -255,6 +257,12 @@ void TestQmlformat::testLineEndings() QVERIFY(!unixContents.contains("\r")); } +void TestQmlformat::testQtbug85003() +{ + QCOMPARE(runQmlformat(testFile("QtBug85003.qml"), false, true), + readTestFile("QtBug85003.formatted.qml")); +} + #if !defined(QTEST_CROSS_COMPILED) // sources not available when cross compiled void TestQmlformat::testExample_data() { diff --git a/tools/qmlformat/dumpastvisitor.cpp b/tools/qmlformat/dumpastvisitor.cpp index 3ad66bc6a1..9f49fe0090 100644 --- a/tools/qmlformat/dumpastvisitor.cpp +++ b/tools/qmlformat/dumpastvisitor.cpp @@ -692,6 +692,10 @@ QString DumpAstVisitor::parseStatement(Statement *statement, bool blockHasNext, result += formatLine("else", false); if (ifFalseBlock) { + // Blocks generate an extra newline that we don't want here. + if (!m_blockNeededBraces && ifFalse.endsWith(QLatin1String("\n"))) + ifFalse.chop(1); + result += " " + ifFalse; } else { result += "\n"; |