summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorIvan Donchevskii <ivan.donchevskii@qt.io>2019-02-19 12:46:38 +0100
committerIvan Donchevskii <ivan.donchevskii@qt.io>2019-02-19 12:47:22 +0000
commitbe65a57935badcc19f844b36ccf1456f2000a96d (patch)
tree5e5a893e6f3b83035dc137bd7cb6fe882afa277d /tests
parent08e1fbbbfa8760e94922d69ab7397af64370081a (diff)
downloadqt-creator-be65a57935badcc19f844b36ccf1456f2000a96d.tar.gz
ClangFormat: Fix unit-tests
Amends dcf763c7ee. Change the logic in empty lines modification to properly indent all empty lines. Change-Id: Id945cf66915dfd192216660543594a7905426761 Reviewed-by: Marco Bubke <marco.bubke@qt.io>
Diffstat (limited to 'tests')
-rw-r--r--tests/unit/unittest/clangformat-test.cpp52
1 files changed, 43 insertions, 9 deletions
diff --git a/tests/unit/unittest/clangformat-test.cpp b/tests/unit/unittest/clangformat-test.cpp
index ea702f71a6..c0ff7dcd2c 100644
--- a/tests/unit/unittest/clangformat-test.cpp
+++ b/tests/unit/unittest/clangformat-test.cpp
@@ -331,6 +331,40 @@ TEST_F(ClangFormat, NoExtraIndentAfterBraceInitialization)
"return 0;"));
}
+TEST_F(ClangFormat, IndentMultipleEmptyLines)
+{
+ insertLines({"{",
+ "",
+ "",
+ "",
+ "}"});
+
+ indenter.indent(cursor, QChar::Null, TextEditor::TabSettings());
+
+ ASSERT_THAT(documentLines(), ElementsAre("{",
+ " ",
+ " ",
+ " ",
+ "}"));
+}
+
+TEST_F(ClangFormat, IndentEmptyLineAndKeepPreviousEmptyLines)
+{
+ insertLines({"{",
+ " ",
+ " ",
+ "",
+ "}"});
+
+ indenter.indentBlock(doc.findBlockByNumber(3), QChar::Null, TextEditor::TabSettings());
+
+ ASSERT_THAT(documentLines(), ElementsAre("{",
+ " ",
+ " ",
+ " ",
+ "}"));
+}
+
TEST_F(ClangFormat, IndentFunctionBodyAndFormatBeforeIt)
{
insertLines({"int foo(int a, int b,",
@@ -469,7 +503,7 @@ TEST_F(ClangFormat, FormatBasicFile)
"int a;",
"}"});
- indenter.format(cursor);
+ indenter.format({{1, 4}});
ASSERT_THAT(documentLines(), ElementsAre("int main()",
"{",
@@ -484,7 +518,7 @@ TEST_F(ClangFormat, FormatEmptyLine)
"",
"}"});
- indenter.format(cursor);
+ indenter.format({{1, 4}});
ASSERT_THAT(documentLines(), ElementsAre("int main() {}"));
}
@@ -495,7 +529,7 @@ TEST_F(ClangFormat, FormatLambda)
"",
"});"});
- indenter.format(cursor);
+ indenter.format({{1, 3}});
ASSERT_THAT(documentLines(), ElementsAre("int b = foo([]() {",
"",
@@ -508,7 +542,7 @@ TEST_F(ClangFormat, FormatInitializerListInArguments)
"args,",
"{1, 2});"});
- indenter.format(cursor);
+ indenter.format({{1, 3}});
ASSERT_THAT(documentLines(), ElementsAre("foo(arg1, args, {1, 2});"));
}
@@ -520,7 +554,7 @@ TEST_F(ClangFormat, FormatFunctionArgumentLambdaWithScope)
"",
"});"});
- indenter.format(cursor);
+ indenter.format({{1, 4}});
ASSERT_THAT(documentLines(),
ElementsAre("foo([]() {",
@@ -535,7 +569,7 @@ TEST_F(ClangFormat, FormatScopeAsFunctionArgument)
"",
"});"});
- indenter.format(cursor);
+ indenter.format({{1, 4}});
ASSERT_THAT(documentLines(),
ElementsAre("foo({",
@@ -548,7 +582,7 @@ TEST_F(ClangFormat, FormatStructuredBinding)
insertLines({"auto [a,",
"b] = c;"});
- indenter.format(cursor);
+ indenter.format({{1, 2}});
ASSERT_THAT(documentLines(), ElementsAre("auto [a, b] = c;"));
}
@@ -558,7 +592,7 @@ TEST_F(ClangFormat, FormatStringLiteralContinuation)
insertLines({"foo(bar, \"foo\"",
"\"bar\");"});
- indenter.format(cursor);
+ indenter.format({{1, 2}});
ASSERT_THAT(documentLines(), ElementsAre("foo(bar,",
" \"foo\"",
@@ -571,7 +605,7 @@ TEST_F(ClangFormat, FormatTemplateparameters)
"B,",
"C>"});
- indenter.format(cursor);
+ indenter.format({{1, 3}});
ASSERT_THAT(documentLines(), ElementsAre("using Alias = Template<A, B, C>"));
}