summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorChristian Kamm <christian.d.kamm@nokia.com>2010-07-05 12:56:37 +0200
committerChristian Kamm <christian.d.kamm@nokia.com>2010-07-05 13:49:12 +0200
commit19db6c98267d6afd4e27d727d5582541947ec43b (patch)
treedb7dea90189f53a63968f8cbc7064ea255978611 /tests
parent3100fc0b7edc7670ac9a95a2715b80a6d4a3be21 (diff)
downloadqt-creator-19db6c98267d6afd4e27d727d5582541947ec43b.tar.gz
C++ indenter: Make building custom styles easier, fix style issues.
Keep more information by using enter() instead of turnInto() when moving from a *_start to *_open.
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/cplusplus/codeformatter/tst_codeformatter.cpp57
1 files changed, 55 insertions, 2 deletions
diff --git a/tests/auto/cplusplus/codeformatter/tst_codeformatter.cpp b/tests/auto/cplusplus/codeformatter/tst_codeformatter.cpp
index 7082c21b94..8e9b5d3fec 100644
--- a/tests/auto/cplusplus/codeformatter/tst_codeformatter.cpp
+++ b/tests/auto/cplusplus/codeformatter/tst_codeformatter.cpp
@@ -40,6 +40,8 @@ private Q_SLOTS:
void memberInitializer();
void templates();
void operatorOverloads();
+ void gnuStyle();
+ void whitesmithsStyle();
};
struct Line {
@@ -73,12 +75,19 @@ QString concatLines(QList<Line> lines)
return result;
}
-void checkIndent(QList<Line> data)
+void checkIndent(QList<Line> data, int style = 0)
{
QString text = concatLines(data);
QTextDocument document(text);
QtStyleCodeFormatter formatter;
- formatter.setDocument(&document);
+ if (style == 1) {// gnu
+ formatter.setIndentSubstatementBraces(true);
+ } else if (style == 2) { // whitesmiths
+ formatter.setIndentSubstatementStatements(false);
+ formatter.setIndentSubstatementBraces(true);
+ formatter.setIndentDeclarationMembers(false);
+ formatter.setIndentDeclarationBraces(true);
+ }
int i = 0;
foreach (const Line &l, data) {
@@ -594,6 +603,10 @@ void tst_CodeFormatter::braceList()
<< Line("void foo () {")
<< Line(" int[] a = { foo, bar, ")
<< Line(" car };")
+ << Line(" int[] a = {")
+ << Line(" a, b,")
+ << Line(" c")
+ << Line(" };")
<< Line(" int k;")
;
checkIndent(data);
@@ -689,6 +702,46 @@ void tst_CodeFormatter::operatorOverloads()
checkIndent(data);
}
+void tst_CodeFormatter::gnuStyle()
+{
+ QList<Line> data;
+ data << Line("struct S")
+ << Line("{")
+ << Line(" void foo()")
+ << Line(" {")
+ << Line(" if (a)")
+ << Line(" {")
+ << Line(" fpp;")
+ << Line(" }")
+ << Line(" if (b) {")
+ << Line(" fpp;")
+ << Line(" }")
+ << Line(" }")
+ << Line("};")
+ ;
+ checkIndent(data, 1);
+}
+
+void tst_CodeFormatter::whitesmithsStyle()
+{
+ QList<Line> data;
+ data << Line("struct S")
+ << Line(" {")
+ << Line(" void foo()")
+ << Line(" {")
+ << Line(" if (a)")
+ << Line(" {")
+ << Line(" fpp;")
+ << Line(" }")
+ << Line(" if (b) {")
+ << Line(" fpp;")
+ << Line(" }")
+ << Line(" }")
+ << Line(" };")
+ ;
+ checkIndent(data, 2);
+}
+
QTEST_APPLESS_MAIN(tst_CodeFormatter)
#include "tst_codeformatter.moc"