diff options
author | Orgad Shaneh <orgad.shaneh@audiocodes.com> | 2019-04-07 20:40:29 +0300 |
---|---|---|
committer | Orgad Shaneh <orgad.shaneh@audiocodes.com> | 2019-04-07 23:13:17 +0300 |
commit | 39ba01da711c07c43abe8aeacedd98990874ba82 (patch) | |
tree | 4a1c8853bd8db754fbf57eac5fff21b7e7342c8a /tests/unit/unittest/clangformat-test.cpp | |
parent | a33386e014db5fdf65903654e9b1ae542ee36c0f (diff) | |
parent | 5273ef2a8aa3c8d268b107edc770b53e1aed7803 (diff) |
Merge remote-tracking branch 'origin/4.9'
Change-Id: I7d1912cd5c4d824fd40d3454c5f1bb796f2c21d8
Diffstat (limited to 'tests/unit/unittest/clangformat-test.cpp')
-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,", |