Commit e5cbb56f authored by Christian Kamm's avatar Christian Kamm
Browse files

C++ indenter: Fix for statement indentation and add test.

parent 7167bddd
......@@ -1062,7 +1062,7 @@ void QtStyleCodeFormatter::onEnter(int newState, int *indentDepth, int *savedInd
case if_statement:
case return_statement:
if (firstToken)
*savedIndentDepth = tokenPosition;
*indentDepth = *savedIndentDepth = tokenPosition;
*paddingDepth = 2*m_indentSize;
break;
......@@ -1144,6 +1144,9 @@ void QtStyleCodeFormatter::onEnter(int newState, int *indentDepth, int *savedInd
}
case substatement_open:
// undo parent continuation indent
*savedPaddingDepth = 0;
if (firstToken) {
*savedIndentDepth = tokenPosition;
*indentDepth = *savedIndentDepth;
......@@ -1192,8 +1195,8 @@ void QtStyleCodeFormatter::onEnter(int newState, int *indentDepth, int *savedInd
case substatement:
// undo the continuation indent of the parent
*indentDepth = parentState.savedIndentDepth;
*savedIndentDepth = *indentDepth;
*savedPaddingDepth = 0;
break;
case maybe_else: {
......@@ -1207,7 +1210,7 @@ void QtStyleCodeFormatter::onEnter(int newState, int *indentDepth, int *savedInd
} break;
case for_statement_paren_open:
*indentDepth = tokenPosition + 1;
*paddingDepth = tokenPosition + 1 - *indentDepth;
break;
case multiline_comment_start:
......@@ -1397,6 +1400,7 @@ bool QtStyleCodeFormatter::shouldClearPaddingOnEnter(int state)
case return_statement:
case block_open:
case substatement_open:
case substatement:
return true;
}
return false;
......
......@@ -47,6 +47,7 @@ private Q_SLOTS:
void streamOp();
void blockStmtInIf();
void nestedInitializer();
void forStatement();
};
struct Line {
......@@ -904,6 +905,40 @@ void tst_CodeFormatter::nestedInitializer()
checkIndent(data);
}
void tst_CodeFormatter::forStatement()
{
QList<Line> data;
data
<< Line("void foo()")
<< Line("{")
<< Line(" for (a; b; c)")
<< Line(" bar();")
<< Line(" for (a; b; c) {")
<< Line(" bar();")
<< Line(" }")
<< Line(" for (a; b; c)")
<< Line(" {")
<< Line(" bar();")
<< Line(" }")
<< Line(" for (a;")
<< Line(" ~ b;")
<< Line(" ~ c)")
<< Line(" bar();")
<< Line(" for (a;")
<< Line(" ~ b;")
<< Line(" ~ c) {")
<< Line(" bar();")
<< Line(" }")
<< Line(" for (a;")
<< Line(" ~ b;")
<< Line(" ~ c)")
<< Line(" {")
<< Line(" bar();")
<< Line(" }")
;
checkIndent(data);
}
QTEST_APPLESS_MAIN(tst_CodeFormatter)
#include "tst_codeformatter.moc"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment