diff options
Diffstat (limited to 'tests/unit/unittest')
-rw-r--r-- | tests/unit/unittest/clangformat-test.cpp | 154 |
1 files changed, 154 insertions, 0 deletions
diff --git a/tests/unit/unittest/clangformat-test.cpp b/tests/unit/unittest/clangformat-test.cpp index ad2c8bf3e3..44217b9876 100644 --- a/tests/unit/unittest/clangformat-test.cpp +++ b/tests/unit/unittest/clangformat-test.cpp @@ -404,6 +404,39 @@ TEST_F(ClangFormat, IndentEmptyLineInsideParantheses) " && b)")); } +TEST_F(ClangFormat, IndentInsideIf) +{ + insertLines({"if (a && b", + ")"}); + + indenter.indentBlock(doc.findBlockByNumber(1), QChar::Null, TextEditor::TabSettings()); + + ASSERT_THAT(documentLines(), ElementsAre("if (a && b", + " )")); +} + +TEST_F(ClangFormat, IndentInsideIf2) +{ + insertLines({"if (a && b &&", + ")"}); + + indenter.indentBlock(doc.findBlockByNumber(1), QChar::Null, TextEditor::TabSettings()); + + ASSERT_THAT(documentLines(), ElementsAre("if (a && b &&", + " )")); +} + +TEST_F(ClangFormat, IndentInsideIf3) +{ + insertLines({"if (a || b", + ")"}); + + indenter.indentBlock(doc.findBlockByNumber(1), QChar::Null, TextEditor::TabSettings()); + + ASSERT_THAT(documentLines(), ElementsAre("if (a || b", + " )")); +} + TEST_F(ClangFormat, EmptyLineInInitializerList) { insertLines({"Bar foo{a,", @@ -441,6 +474,31 @@ TEST_F(ClangFormat, DoNotIndentClosingBraceAfterSemicolon) "}")); } +TEST_F(ClangFormat, IndentAfterIf) +{ + insertLines({"if (a)", + ""}); + + indenter.indentBlock(doc.findBlockByNumber(1), QChar::Null, TextEditor::TabSettings()); + + ASSERT_THAT(documentLines(), ElementsAre("if (a)", + " ")); +} + +TEST_F(ClangFormat, IndentAfterElse) +{ + insertLines({"if (a)", + " foo();", + "else", + ""}); + indenter.indentBlock(doc.findBlockByNumber(3), QChar::Null, TextEditor::TabSettings()); + + ASSERT_THAT(documentLines(), ElementsAre("if (a)", + " foo();", + "else", + " ")); +} + TEST_F(ClangFormat, SameIndentAfterSecondNewLineAfterIf) { insertLines({"if (a)", @@ -504,6 +562,102 @@ TEST_F(ClangFormat, SameIndentsOnNewLinesAfterComments) "")); } +TEST_F(ClangFormat, IndentAfterEmptyLineAfterAngledIncludeDirective) +{ + insertLines({"#include <string>", + "", + "using namespace std;"}); + + indenter.indentBlock(doc.findBlockByNumber(2), QChar::Null, TextEditor::TabSettings()); + + ASSERT_THAT(documentLines(), ElementsAre("#include <string>", + "", + "using namespace std;")); +} + +TEST_F(ClangFormat, IndentAfterEmptyLineAfterQuotedIncludeDirective) +{ + insertLines({"#include \"foo.h\"", + "", + "using namespace std;"}); + + indenter.indentBlock(doc.findBlockByNumber(2), QChar::Null, TextEditor::TabSettings()); + + ASSERT_THAT(documentLines(), ElementsAre("#include \"foo.h\"", + "", + "using namespace std;")); +} + +TEST_F(ClangFormat, IndentAfterLineComment) +{ + insertLines({"int foo()", + "{", + " // Comment", + " ", + " if (", + "}"}); + + indenter.indentBlock(doc.findBlockByNumber(4), '(', TextEditor::TabSettings()); + + ASSERT_THAT(documentLines(), ElementsAre("int foo()", + "{", + " // Comment", + " ", + " if (", + "}")); +} + +TEST_F(ClangFormat, IndentAfterBlockComment) +{ + insertLines({"int foo()", + "{", + " bar(); /* Comment */", + " ", + " if (", + "}"}); + + indenter.indentBlock(doc.findBlockByNumber(4), '(', TextEditor::TabSettings()); + + ASSERT_THAT(documentLines(), ElementsAre("int foo()", + "{", + " bar(); /* Comment */", + " ", + " if (", + "}")); +} + +TEST_F(ClangFormat, IndentAfterIfdef) +{ + insertLines({"int foo()", + "{", + "#ifdef FOO", + "#endif", + " ", + " if (", + "}"}); + + indenter.indentBlock(doc.findBlockByNumber(5), '(', TextEditor::TabSettings()); + + ASSERT_THAT(documentLines(), ElementsAre("int foo()", + "{", + "#ifdef FOO", + "#endif", + " ", + " if (", + "}")); +} + +TEST_F(ClangFormat, IndentAfterEmptyLineInTheFileBeginning) +{ + insertLines({"", + "void foo()"}); + + indenter.indentBlock(doc.findBlockByNumber(1), ')', TextEditor::TabSettings()); + + ASSERT_THAT(documentLines(), ElementsAre("", + "void foo()")); +} + TEST_F(ClangFormat, IndentFunctionBodyButNotFormatBeforeIt) { insertLines({"int foo(int a, int b,", |