forked from qt-creator/qt-creator
ClangFormat: Tweak dummy text for consecutive empty lines
If empty lines follow each other it makes sense to use the empty comment as dummy text for all but the last one of them. This prevents increasing indentation lengths after if (foo) when there are multiple new empty lines inserted. Change-Id: I4c948161b674b3af0a131bfb85e7a45a80ed3fb0 Reviewed-by: Marco Bubke <marco.bubke@qt.io>
This commit is contained in:
@@ -119,14 +119,14 @@ TEST_F(ClangFormat, IndentBasicFile)
|
||||
|
||||
TEST_F(ClangFormat, IndentEmptyLine)
|
||||
{
|
||||
insertLines({"int main",
|
||||
insertLines({"int main()",
|
||||
"{",
|
||||
"",
|
||||
"}"});
|
||||
|
||||
indenter.indent(cursor, QChar::Null, TextEditor::TabSettings());
|
||||
|
||||
ASSERT_THAT(documentLines(), ElementsAre("int main",
|
||||
ASSERT_THAT(documentLines(), ElementsAre("int main()",
|
||||
"{",
|
||||
" ",
|
||||
"}"));
|
||||
@@ -441,6 +441,56 @@ TEST_F(ClangFormat, DoNotIndentClosingBraceAfterSemicolon)
|
||||
"}"));
|
||||
}
|
||||
|
||||
TEST_F(ClangFormat, SameIndentAfterSecondNewLineAfterIf)
|
||||
{
|
||||
insertLines({"if (a)",
|
||||
" ",
|
||||
""});
|
||||
|
||||
indenter.indentBlock(doc.findBlockByNumber(2), QChar::Null, TextEditor::TabSettings());
|
||||
|
||||
ASSERT_THAT(documentLines(), ElementsAre("if (a)",
|
||||
" ",
|
||||
" "));
|
||||
}
|
||||
|
||||
TEST_F(ClangFormat, IndentAfterNewLineInsideIfWithFunctionCall)
|
||||
{
|
||||
insertLines({"if (foo()",
|
||||
")"});
|
||||
|
||||
indenter.indentBlock(doc.findBlockByNumber(1), QChar::Null, TextEditor::TabSettings());
|
||||
|
||||
ASSERT_THAT(documentLines(), ElementsAre("if (foo()",
|
||||
" )"));
|
||||
}
|
||||
|
||||
TEST_F(ClangFormat, SameIndentAfterSecondNewLineInsideIfWithFunctionCall)
|
||||
{
|
||||
insertLines({"if (foo()",
|
||||
" ",
|
||||
")"});
|
||||
|
||||
indenter.indentBlock(doc.findBlockByNumber(2), QChar::Null, TextEditor::TabSettings());
|
||||
|
||||
ASSERT_THAT(documentLines(), ElementsAre("if (foo()",
|
||||
" ",
|
||||
" )"));
|
||||
}
|
||||
|
||||
TEST_F(ClangFormat, SameIndentsOnNewLinesAfterComments)
|
||||
{
|
||||
insertLines({"namespace {} //comment",
|
||||
"",
|
||||
""});
|
||||
|
||||
indenter.indentBlock(doc.findBlockByNumber(2), QChar::Null, TextEditor::TabSettings());
|
||||
|
||||
ASSERT_THAT(documentLines(), ElementsAre("namespace {} //comment",
|
||||
"",
|
||||
""));
|
||||
}
|
||||
|
||||
TEST_F(ClangFormat, IndentFunctionBodyButNotFormatBeforeIt)
|
||||
{
|
||||
insertLines({"int foo(int a, int b,",
|
||||
|
||||
Reference in New Issue
Block a user