ClangFormat: Fix list declaration

Fixed list declaration indentation.
Fixed function declaration with parameters on the new line.
Added tests for both cases.

Fixes: QTCREATORBUG-25011
Change-Id: Ida4f6ec4f407c5e5b015dc2c0afff110262d9645
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
Artem Sokolovskii
2022-07-05 16:38:51 +02:00
parent 5817bdf87d
commit 17693bc415
3 changed files with 106 additions and 15 deletions

View File

@@ -655,4 +655,74 @@ void ClangFormatTest::testClassIndentStructure()
(std::vector<QString>{"class test {", " Q_OBJECT", "public:", "};"}));
}
void ClangFormatTest::testIndentInitializeVector()
{
insertLines({
"class Test {",
"public:",
" Test();",
"};",
"",
"Test::Test()",
"{",
" QVector<int> list = {",
" 1,",
" 2,",
" 3,",
" };",
" QVector<int> list_2 = {",
" 1,",
" 2,",
" 3,",
" };",
"}",
"",
"int main()",
"{",
"}"
});
m_indenter->indent(*m_cursor, QChar::Null, TextEditor::TabSettings());
QCOMPARE(documentLines(),
(std::vector<QString>{
"class Test {",
"public:",
" Test();",
"};",
"",
"Test::Test()",
"{",
" QVector<int> list = {",
" 1,",
" 2,",
" 3,",
" };",
" QVector<int> list_2 = {",
" 1,",
" 2,",
" 3,",
" };",
"}",
"",
"int main()",
"{",
"}"
}));
}
void ClangFormatTest::testIndentFunctionArgumentOnNewLine()
{
insertLines(
{"Bar foo(",
"a,",
")"
});
m_indenter->indentBlock(m_doc->findBlockByNumber(1), QChar::Null, TextEditor::TabSettings());
QCOMPARE(documentLines(),
(std::vector<QString>{
"Bar foo(",
" a,",
")"
}));
}
} // namespace ClangFormat::Internal