summaryrefslogtreecommitdiffstats
path: root/clang/unittests/Format/FormatTestComments.cpp
diff options
context:
space:
mode:
authorKrasimir Georgiev <krasimir@google.com>2017-02-16 12:39:31 +0000
committerKrasimir Georgiev <krasimir@google.com>2017-02-16 12:39:31 +0000
commitbb99a36dc0047a4527a825eb24005bc040a09484 (patch)
tree1b8e6fc14187177b25dc2c440b2370518c930202 /clang/unittests/Format/FormatTestComments.cpp
parent58984e7087bc530ac2fae06b3ef15a4f1bc118f9 (diff)
downloadbcm5719-llvm-bb99a36dc0047a4527a825eb24005bc040a09484.tar.gz
bcm5719-llvm-bb99a36dc0047a4527a825eb24005bc040a09484.zip
[clang-format] Align block comment decorations
Summary: This patch implements block comment decoration alignment. source: ``` /* line 1 * line 2 */ ``` result before: ``` /* line 1 * line 2 */ ``` result after: ``` /* line 1 * line 2 */ ``` Reviewers: djasper, bkramer, klimek Reviewed By: klimek Subscribers: mprobst, cfe-commits, klimek Differential Revision: https://reviews.llvm.org/D29943 llvm-svn: 295312
Diffstat (limited to 'clang/unittests/Format/FormatTestComments.cpp')
-rw-r--r--clang/unittests/Format/FormatTestComments.cpp202
1 files changed, 195 insertions, 7 deletions
diff --git a/clang/unittests/Format/FormatTestComments.cpp b/clang/unittests/Format/FormatTestComments.cpp
index f5fddaa6a58..049851793c0 100644
--- a/clang/unittests/Format/FormatTestComments.cpp
+++ b/clang/unittests/Format/FormatTestComments.cpp
@@ -937,11 +937,11 @@ TEST_F(FormatTestComments, SplitsLongLinesInComments) {
getLLVMStyleWithColumns(20)));
EXPECT_EQ("/* some comment\n"
- " * a comment\n"
- "* that we break\n"
- " * another comment\n"
- "* we have to break\n"
- "* a left comment\n"
+ " * a comment that\n"
+ " * we break another\n"
+ " * comment we have\n"
+ " * to break a left\n"
+ " * comment\n"
" */",
format(" /* some comment\n"
" * a comment that we break\n"
@@ -1856,10 +1856,10 @@ TEST_F(FormatTestComments, BlockComments) {
getLLVMStyleWithColumns(15)));
EXPECT_EQ("/*\n**\n*/", format("/*\n**\n*/"));
EXPECT_EQ("/*\n"
- "*\n"
+ " *\n"
" * aaaaaa\n"
" * aaaaaa\n"
- "*/",
+ " */",
format("/*\n"
"*\n"
" * aaaaaa aaaaaa\n"
@@ -2164,6 +2164,194 @@ TEST_F(FormatTestComments, AlignTrailingComments) {
" long b;",
getLLVMStyleWithColumns(80)));
}
+
+TEST_F(FormatTestComments, AlignsBlockCommentDecorations) {
+ EXPECT_EQ("/*\n"
+ " */",
+ format("/*\n"
+ "*/", getLLVMStyle()));
+ EXPECT_EQ("/*\n"
+ " */",
+ format("/*\n"
+ " */", getLLVMStyle()));
+ EXPECT_EQ("/*\n"
+ " */",
+ format("/*\n"
+ " */", getLLVMStyle()));
+
+ // Align a single line.
+ EXPECT_EQ("/*\n"
+ " * line */",
+ format("/*\n"
+ "* line */",
+ getLLVMStyle()));
+ EXPECT_EQ("/*\n"
+ " * line */",
+ format("/*\n"
+ " * line */",
+ getLLVMStyle()));
+ EXPECT_EQ("/*\n"
+ " * line */",
+ format("/*\n"
+ " * line */",
+ getLLVMStyle()));
+ EXPECT_EQ("/*\n"
+ " * line */",
+ format("/*\n"
+ " * line */",
+ getLLVMStyle()));
+ EXPECT_EQ("/**\n"
+ " * line */",
+ format("/**\n"
+ "* line */",
+ getLLVMStyle()));
+ EXPECT_EQ("/**\n"
+ " * line */",
+ format("/**\n"
+ " * line */",
+ getLLVMStyle()));
+ EXPECT_EQ("/**\n"
+ " * line */",
+ format("/**\n"
+ " * line */",
+ getLLVMStyle()));
+ EXPECT_EQ("/**\n"
+ " * line */",
+ format("/**\n"
+ " * line */",
+ getLLVMStyle()));
+ EXPECT_EQ("/**\n"
+ " * line */",
+ format("/**\n"
+ " * line */",
+ getLLVMStyle()));
+
+ // Align the end '*/' after a line.
+ EXPECT_EQ("/*\n"
+ " * line\n"
+ " */",
+ format("/*\n"
+ "* line\n"
+ "*/", getLLVMStyle()));
+ EXPECT_EQ("/*\n"
+ " * line\n"
+ " */",
+ format("/*\n"
+ " * line\n"
+ " */", getLLVMStyle()));
+ EXPECT_EQ("/*\n"
+ " * line\n"
+ " */",
+ format("/*\n"
+ " * line\n"
+ " */", getLLVMStyle()));
+
+ // Align two lines.
+ EXPECT_EQ("/* line 1\n"
+ " * line 2 */",
+ format("/* line 1\n"
+ " * line 2 */",
+ getLLVMStyle()));
+ EXPECT_EQ("/* line 1\n"
+ " * line 2 */",
+ format("/* line 1\n"
+ "* line 2 */",
+ getLLVMStyle()));
+ EXPECT_EQ("/* line 1\n"
+ " * line 2 */",
+ format("/* line 1\n"
+ " * line 2 */",
+ getLLVMStyle()));
+ EXPECT_EQ("/* line 1\n"
+ " * line 2 */",
+ format("/* line 1\n"
+ " * line 2 */",
+ getLLVMStyle()));
+ EXPECT_EQ("/* line 1\n"
+ " * line 2 */",
+ format("/* line 1\n"
+ " * line 2 */",
+ getLLVMStyle()));
+ EXPECT_EQ("int i; /* line 1\n"
+ " * line 2 */",
+ format("int i; /* line 1\n"
+ "* line 2 */",
+ getLLVMStyle()));
+ EXPECT_EQ("int i; /* line 1\n"
+ " * line 2 */",
+ format("int i; /* line 1\n"
+ " * line 2 */",
+ getLLVMStyle()));
+ EXPECT_EQ("int i; /* line 1\n"
+ " * line 2 */",
+ format("int i; /* line 1\n"
+ " * line 2 */",
+ getLLVMStyle()));
+
+ // Align several lines.
+ EXPECT_EQ("/* line 1\n"
+ " * line 2\n"
+ " * line 3 */",
+ format("/* line 1\n"
+ " * line 2\n"
+ "* line 3 */",
+ getLLVMStyle()));
+ EXPECT_EQ("/* line 1\n"
+ " * line 2\n"
+ " * line 3 */",
+ format("/* line 1\n"
+ " * line 2\n"
+ "* line 3 */",
+ getLLVMStyle()));
+ EXPECT_EQ("/*\n"
+ "** line 1\n"
+ "** line 2\n"
+ "*/",
+ format("/*\n"
+ "** line 1\n"
+ " ** line 2\n"
+ "*/",
+ getLLVMStyle()));
+
+ // Align with different indent after the decorations.
+ EXPECT_EQ("/*\n"
+ " * line 1\n"
+ " * line 2\n"
+ " * line 3\n"
+ " * line 4\n"
+ " */",
+ format("/*\n"
+ "* line 1\n"
+ " * line 2\n"
+ " * line 3\n"
+ "* line 4\n"
+ "*/", getLLVMStyle()));
+
+ // Align empty or blank lines.
+ EXPECT_EQ("/**\n"
+ " *\n"
+ " *\n"
+ " *\n"
+ " */",
+ format("/**\n"
+ "* \n"
+ " * \n"
+ " *\n"
+ "*/", getLLVMStyle()));
+
+ // Align while breaking and reflowing.
+ EXPECT_EQ("/*\n"
+ " * long long long\n"
+ " * long long\n"
+ " *\n"
+ " * long */",
+ format("/*\n"
+ " * long long long long\n"
+ " * long\n"
+ " *\n"
+ "* long */",
+ getLLVMStyleWithColumns(20)));
+}
} // end namespace
} // end namespace format
} // end namespace clang
OpenPOWER on IntegriCloud