From 69d6a508d3d5f99ef706f5d73a5533681ef64096 Mon Sep 17 00:00:00 2001 From: Christian Kamm Date: Thu, 1 Dec 2011 15:00:29 +0100 Subject: QmlJS indenter: Fix braceless switch/try/with bindings. Change-Id: Iee25f3f9ec38b1b7fc2697f390386c9a60cb8347 Reviewed-by: Roberto Raggi --- .../qmlcodeformatter/tst_qmlcodeformatter.cpp | 122 ++++++++++++++++++--- 1 file changed, 107 insertions(+), 15 deletions(-) (limited to 'tests') diff --git a/tests/auto/qml/qmleditor/qmlcodeformatter/tst_qmlcodeformatter.cpp b/tests/auto/qml/qmleditor/qmlcodeformatter/tst_qmlcodeformatter.cpp index c3a0b35e0d..46c7b0ae68 100644 --- a/tests/auto/qml/qmleditor/qmlcodeformatter/tst_qmlcodeformatter.cpp +++ b/tests/auto/qml/qmleditor/qmlcodeformatter/tst_qmlcodeformatter.cpp @@ -61,6 +61,11 @@ private Q_SLOTS: void ifBinding1(); void ifBinding2(); void ifBinding3(); + void withBinding(); + void tryBinding1(); + void tryBinding2(); + void tryBinding3(); + void switchBinding(); void ifStatementWithoutBraces1(); void ifStatementWithoutBraces2(); void ifStatementWithoutBraces3(); @@ -98,7 +103,6 @@ private Q_SLOTS: void labelledStatements3(); void json1(); void multilineTernaryInProperty(); - void bug1(); void multilineString(); void bug1(); }; @@ -538,6 +542,108 @@ void tst_QMLCodeFormatter::ifBinding3() checkIndent(data); } +void tst_QMLCodeFormatter::withBinding() +{ + QList data; + data << Line("Rectangle {") + << Line(" foo: with(pos) { x }") + << Line(" foo: with(pos) {") + << Line(" x") + << Line(" }") + << Line(" foo: 12") + << Line("}") + ; + checkIndent(data); +} + +void tst_QMLCodeFormatter::tryBinding1() +{ + QList data; + data << Line("Rectangle {") + << Line(" foo: try { x } finally { y }") + << Line(" foo: try {") + << Line(" x") + << Line(" } finally {") + << Line(" y") + << Line(" }") + << Line(" foo: try {") + << Line(" x") + << Line(" }") + << Line(" finally {") + << Line(" y") + << Line(" }") + << Line(" foo: 12") + << Line("}") + ; + checkIndent(data); +} + +void tst_QMLCodeFormatter::tryBinding2() +{ + QList data; + data << Line("Rectangle {") + << Line(" foo: try { x } catch (x) { y }") + << Line(" foo: try {") + << Line(" x") + << Line(" } catch (e) {") + << Line(" e") + << Line(" }") + << Line(" foo: try {") + << Line(" x") + << Line(" }") + << Line(" catch (e) {") + << Line(" e") + << Line(" }") + << Line(" foo: 12") + << Line("}") + ; + checkIndent(data); +} + +void tst_QMLCodeFormatter::tryBinding3() +{ + QList data; + data << Line("Rectangle {") + << Line(" foo: try { x } catch (x) { y } finally { z }") + << Line(" foo: try {") + << Line(" x") + << Line(" } catch (e) {") + << Line(" e") + << Line(" } finally {") + << Line(" z") + << Line(" }") + << Line(" foo: try {") + << Line(" x") + << Line(" }") + << Line(" catch (e) {") + << Line(" e") + << Line(" }") + << Line(" finally {") + << Line(" z") + << Line(" }") + << Line(" foo: 12") + << Line("}") + ; + checkIndent(data); +} + +void tst_QMLCodeFormatter::switchBinding() +{ + QList data; + data << Line("Rectangle {") + << Line(" foo: switch (a) {") + << Line(" case 1:") + << Line(" x; break") + << Line(" case 2:") + << Line(" case 3:") + << Line(" return y") + << Line(" }") + << Line(" foo: 12") + << Line("}") + ; + checkIndent(data); +} + void tst_QMLCodeFormatter::ifStatementWithoutBraces1() { QList data; @@ -1301,20 +1407,6 @@ void tst_QMLCodeFormatter::multilineTernaryInProperty() checkIndent(data); } -void tst_QMLCodeFormatter::bug1() -{ - QList data; - data << Line("Item {") - << Line(" x: {") - << Line(" if (a==a) {}") - << Line(" else (b==b) {}") - << Line(" foo()") - << Line(" }") - << Line("}") - ; - checkIndent(data); -} - void tst_QMLCodeFormatter::multilineString() { QList data; -- cgit v1.2.1