C++ indenter: Fix for GNU and Whitesmiths style switch statement.

Task-number: QTCREATORBUG-2994
This commit is contained in:
Christian Kamm
2010-11-04 14:07:58 +01:00
parent 338a349dff
commit d2468a4491
2 changed files with 82 additions and 5 deletions

View File

@@ -54,6 +54,8 @@ private Q_SLOTS:
void macrosNoSemicolon2();
void renamedNamespace();
void cpp0xFor();
void gnuStyleSwitch();
void whitesmithsStyleSwitch();
};
struct Line {
@@ -820,6 +822,9 @@ void tst_CodeFormatter::gnuStyle()
<< Line(" if (b) {")
<< Line(" fpp;")
<< Line(" }")
<< Line(" {")
<< Line(" foo;")
<< Line(" }")
<< Line(" }")
<< Line("};")
;
@@ -840,6 +845,9 @@ void tst_CodeFormatter::whitesmithsStyle()
<< Line(" if (b) {")
<< Line(" fpp;")
<< Line(" }")
<< Line(" {")
<< Line(" foo;")
<< Line(" }")
<< Line(" }")
<< Line(" };")
;
@@ -1034,6 +1042,62 @@ void tst_CodeFormatter::cpp0xFor()
checkIndent(data);
}
void tst_CodeFormatter::gnuStyleSwitch()
{
QList<Line> data;
data << Line("void foo()")
<< Line("{")
<< Line(" switch (a)")
<< Line(" {")
<< Line(" case 1:")
<< Line(" foo;")
<< Line(" break;")
<< Line(" case 2: {")
<< Line(" bar;")
<< Line(" continue;")
<< Line(" }")
<< Line(" case 3:")
<< Line(" {")
<< Line(" bar;")
<< Line(" continue;")
<< Line(" }")
<< Line(" case 4:")
<< Line(" case 5:")
<< Line(" ;")
<< Line(" }")
<< Line("}")
;
checkIndent(data, 1);
}
void tst_CodeFormatter::whitesmithsStyleSwitch()
{
QList<Line> data;
data << Line("void foo()")
<< Line(" {")
<< Line(" switch (a)")
<< Line(" {")
<< Line(" case 1:")
<< Line(" foo;")
<< Line(" break;")
<< Line(" case 2: {")
<< Line(" bar;")
<< Line(" continue;")
<< Line(" }")
<< Line(" case 3:")
<< Line(" {")
<< Line(" bar;")
<< Line(" continue;")
<< Line(" }")
<< Line(" case 4:")
<< Line(" case 5:")
<< Line(" ;")
<< Line(" }")
<< Line(" }")
;
checkIndent(data, 2);
}
QTEST_APPLESS_MAIN(tst_CodeFormatter)
#include "tst_codeformatter.moc"