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:
Ivan Donchevskii
2019-03-06 14:05:31 +01:00
parent 35b0b44b21
commit 7e5e99d551
3 changed files with 59 additions and 22 deletions

View File

@@ -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()",