summaryrefslogtreecommitdiffstats
path: root/clang/unittests/Format/FormatTestComments.cpp
diff options
context:
space:
mode:
authorKrasimir Georgiev <krasimir@google.com>2017-07-21 10:26:13 +0000
committerKrasimir Georgiev <krasimir@google.com>2017-07-21 10:26:13 +0000
commit06451fa1a22d3b285c56668f80ec52207a4aa6fd (patch)
treeaf8d06d7178bf5268b10f3283dd49e27801467ef /clang/unittests/Format/FormatTestComments.cpp
parent84cbd8e75081edb07c6f53a59c709df0524f393d (diff)
downloadbcm5719-llvm-06451fa1a22d3b285c56668f80ec52207a4aa6fd.tar.gz
bcm5719-llvm-06451fa1a22d3b285c56668f80ec52207a4aa6fd.zip
[clang-format] Fix comment levels between '}' and PPDirective
Summary: This fixes a regression exposed by r307795 in which the level of a comment line between '}' and a preprocessor directive is incorrectly set as the level of the line before the '}'. In effect, this: ``` int f(int i) { int j = i; return i + j; } // comment #ifdef A #endif ``` was formatted as: ``` int f(int i) { int j = i; return i + j; } // comment #ifdef A #endif ``` Reviewers: djasper Reviewed By: djasper Subscribers: cfe-commits, klimek Differential Revision: https://reviews.llvm.org/D35485 llvm-svn: 308725
Diffstat (limited to 'clang/unittests/Format/FormatTestComments.cpp')
-rw-r--r--clang/unittests/Format/FormatTestComments.cpp78
1 files changed, 78 insertions, 0 deletions
diff --git a/clang/unittests/Format/FormatTestComments.cpp b/clang/unittests/Format/FormatTestComments.cpp
index 7916e65e511..7d2ec839638 100644
--- a/clang/unittests/Format/FormatTestComments.cpp
+++ b/clang/unittests/Format/FormatTestComments.cpp
@@ -836,6 +836,25 @@ TEST_F(FormatTestComments, KeepsLevelOfCommentBeforePPDirective) {
" int j;\n"
"}"));
+ EXPECT_EQ("int f(int i) {\n"
+ " if (true) {\n"
+ " ++i;\n"
+ " }\n"
+ " // comment\n"
+ "#ifdef A\n"
+ " int j;\n"
+ "#endif\n"
+ "}",
+ format("int f(int i) {\n"
+ " if (true) {\n"
+ " ++i;\n"
+ " }\n"
+ " // comment\n"
+ "#ifdef A\n"
+ "int j;\n"
+ "#endif\n"
+ "}"));
+
// Keep the current level if there is an empty line between the comment and
// the preprocessor directive.
EXPECT_EQ("void f() {\n"
@@ -853,6 +872,46 @@ TEST_F(FormatTestComments, KeepsLevelOfCommentBeforePPDirective) {
" int j;\n"
"}"));
+ EXPECT_EQ("void f() {\n"
+ " int i;\n"
+ " return i;\n"
+ "}\n"
+ "// comment\n"
+ "\n"
+ "#ifdef A\n"
+ "int i;\n"
+ "#endif // A",
+ format("void f() {\n"
+ " int i;\n"
+ " return i;\n"
+ "}\n"
+ "// comment\n"
+ "\n"
+ "#ifdef A\n"
+ "int i;\n"
+ "#endif // A"));
+
+ EXPECT_EQ("int f(int i) {\n"
+ " if (true) {\n"
+ " ++i;\n"
+ " }\n"
+ " // comment\n"
+ "\n"
+ "#ifdef A\n"
+ " int j;\n"
+ "#endif\n"
+ "}",
+ format("int f(int i) {\n"
+ " if (true) {\n"
+ " ++i;\n"
+ " }\n"
+ " // comment\n"
+ "\n"
+ "#ifdef A\n"
+ " int j;\n"
+ "#endif\n"
+ "}"));
+
// Align with the preprocessor directive if the comment was originally aligned
// with the preprocessor directive.
EXPECT_EQ("void f() {\n"
@@ -867,6 +926,25 @@ TEST_F(FormatTestComments, KeepsLevelOfCommentBeforePPDirective) {
"#ifdef A\n"
" int j;\n"
"}"));
+
+ EXPECT_EQ("int f(int i) {\n"
+ " if (true) {\n"
+ " ++i;\n"
+ " }\n"
+ "// comment\n"
+ "#ifdef A\n"
+ " int j;\n"
+ "#endif\n"
+ "}",
+ format("int f(int i) {\n"
+ " if (true) {\n"
+ " ++i;\n"
+ " }\n"
+ "// comment\n"
+ "#ifdef A\n"
+ " int j;\n"
+ "#endif\n"
+ "}"));
}
TEST_F(FormatTestComments, SplitsLongLinesInComments) {
OpenPOWER on IntegriCloud