forked from qt-creator/qt-creator
ClangFormat: Add whitespace unit-tests and fix bugs
Check that extra whitespace does not prevent the indentation and that indentation is the same for the consecutive empty lines. Change-Id: I04aa12c4cd31aaf07daf9320c98d2eea7afcc9a8 Reviewed-by: Marco Bubke <marco.bubke@qt.io>
This commit is contained in:
@@ -72,6 +72,7 @@ protected:
|
||||
|
||||
void insertLines(const std::vector<QString> &lines)
|
||||
{
|
||||
doc.clear();
|
||||
cursor.setPosition(0);
|
||||
for (size_t lineNumber = 1; lineNumber <= lines.size(); ++lineNumber) {
|
||||
if (lineNumber > 1)
|
||||
@@ -379,6 +380,17 @@ TEST_F(ClangFormat, IndentOnElectricCharacterButNotRemoveEmptyLinesBefore)
|
||||
"}"));
|
||||
}
|
||||
|
||||
TEST_F(ClangFormat, IndentAfterExtraSpaceInpreviousLine)
|
||||
{
|
||||
insertLines({"if (a ",
|
||||
"&& b)"});
|
||||
|
||||
indenter.indentBlock(doc.findBlockByNumber(1), QChar::Null, TextEditor::TabSettings());
|
||||
|
||||
ASSERT_THAT(documentLines(), ElementsAre("if (a",
|
||||
" && b)"));
|
||||
}
|
||||
|
||||
TEST_F(ClangFormat, IndentFunctionBodyButNotFormatBeforeIt)
|
||||
{
|
||||
insertLines({"int foo(int a, int b,",
|
||||
@@ -520,6 +532,24 @@ TEST_F(ClangFormat, OnlyIndentClosingParenthesis)
|
||||
" )"));
|
||||
}
|
||||
|
||||
TEST_F(ClangFormat, EquallyIndentInsideParenthesis)
|
||||
{
|
||||
insertLines({"if (a",
|
||||
")"});
|
||||
extendedIndenter.indentBlock(doc.findBlockByNumber(1), QChar::Null, TextEditor::TabSettings());
|
||||
auto linesAfterFirstLineBreak = documentLines();
|
||||
insertLines({"if (a",
|
||||
" ",
|
||||
")"});
|
||||
extendedIndenter.indentBlock(doc.findBlockByNumber(2), QChar::Null, TextEditor::TabSettings());
|
||||
|
||||
ASSERT_THAT(linesAfterFirstLineBreak, ElementsAre("if (a",
|
||||
" )"));
|
||||
ASSERT_THAT(documentLines(), ElementsAre("if (a",
|
||||
" ",
|
||||
" )"));
|
||||
}
|
||||
|
||||
TEST_F(ClangFormat, FormatBasicFile)
|
||||
{
|
||||
insertLines({"int main()",
|
||||
|
||||
Reference in New Issue
Block a user