aboutsummaryrefslogtreecommitdiff
path: root/unittests
diff options
context:
space:
mode:
authorAlexander Kornienko <alexfh@google.com>2013-03-21 12:28:10 +0000
committerAlexander Kornienko <alexfh@google.com>2013-03-21 12:28:10 +0000
commit7c22cf340995ab9107810aa39a190db3e0332294 (patch)
tree75dcab5e4f68aa37529d0310f6b3c2d62312ffa5 /unittests
parent3656c612efe4889da0174ffa6a621a2d59fc3ecb (diff)
Better block comment formatting.
Summary: 1. When splitting one-line block comment, use indentation and *s. 2. Remove trailing whitespace from all lines of a comment, not only the ones being splitted. 3. Add backslashes for all lines if a comment is used insed a preprocessor directive. Reviewers: djasper Reviewed By: djasper CC: cfe-commits, klimek Differential Revision: http://llvm-reviews.chandlerc.com/D557 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@177635 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests')
-rw-r--r--unittests/Format/FormatTest.cpp51
1 files changed, 38 insertions, 13 deletions
diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp
index 4caffd911b..29988d35c4 100644
--- a/unittests/Format/FormatTest.cpp
+++ b/unittests/Format/FormatTest.cpp
@@ -667,11 +667,14 @@ TEST_F(FormatTest, AlignsMultiLineComments) {
TEST_F(FormatTest, SplitsLongLinesInComments) {
EXPECT_EQ("/* This is a long\n"
- "comment that doesn't\n"
- "fit on one line. */",
+ " * comment that\n"
+ " * doesn't\n"
+ " * fit on one line.\n"
+ " */",
format("/* "
"This is a long "
- "comment that doesn't "
+ "comment that "
+ "doesn't "
"fit on one line. */",
getLLVMStyleWithColumns(20)));
EXPECT_EQ("/*\n"
@@ -690,7 +693,7 @@ TEST_F(FormatTest, SplitsLongLinesInComments) {
" * doesn't fit on\n"
" * one line.\n"
" */",
- format("/*\n"
+ format("/* \n"
" * This is a long "
" comment that "
" doesn't fit on "
@@ -757,12 +760,22 @@ TEST_F(FormatTest, SplitsLongLinesInComments) {
format(" /*\n"
" * This is a long comment that doesn't fit on one line\n"
" */", getLLVMStyleWithColumns(20)));
+ EXPECT_EQ("{\n"
+ " if (something) /* This is a\n"
+ "long comment */\n"
+ " ;\n"
+ "}",
+ format("{\n"
+ " if (something) /* This is a long comment */\n"
+ " ;\n"
+ "}",
+ getLLVMStyleWithColumns(30)));
}
TEST_F(FormatTest, SplitsLongLinesInCommentsInPreprocessor) {
EXPECT_EQ("#define X \\\n"
- // FIXME: Backslash should be added here.
- " /*\n"
+ " /* \\\n"
+ " Test \\\n"
" Macro comment \\\n"
" with a long \\\n"
" line \\\n"
@@ -773,19 +786,31 @@ TEST_F(FormatTest, SplitsLongLinesInCommentsInPreprocessor) {
" A + B",
format("#define X \\\n"
" /*\n"
+ " Test\n"
" Macro comment with a long line\n"
" */ \\\n"
" A + B",
getLLVMStyleWithColumns(20)));
EXPECT_EQ("#define X \\\n"
" /* Macro comment \\\n"
- // FIXME: Indent comment continuations when the comment is a first
- // token in a line.
- "with a long line \\\n"
+ " with a long \\\n"
+ // FIXME: We should look at the length of the last line of the token
+ // instead of the full token's length.
+ //" line */ \\\n"
+ " line */\\\n"
+ " A + B",
+ format("#define X \\\n"
+ " /* Macro comment with a long\n"
+ " line */ \\\n"
+ " A + B",
+ getLLVMStyleWithColumns(20)));
+ EXPECT_EQ("#define X \\\n"
+ " /* Macro comment \\\n"
+ " * with a long \\\n"
// FIXME: We should look at the length of the last line of the token
// instead of the full token's length.
- //"*/ \\\n"
- "*/\\\n"
+ //" * line */ \\\n"
+ " * line */\\\n"
" A + B",
format("#define X \\\n"
" /* Macro comment with a long line */ \\\n"
@@ -2627,12 +2652,12 @@ TEST_F(FormatTest, BlockComments) {
EXPECT_EQ("/* */ /* */ /* */\n/* */ /* */ /* */",
format("/* *//* */ /* */\n/* *//* */ /* */"));
EXPECT_EQ("/* */ a /* */ b;", format(" /* */ a/* */ b;"));
- EXPECT_EQ("#define A /* */\\\n"
+ EXPECT_EQ("#define A /*123*/\\\n"
" b\n"
"/* */\n"
"someCall(\n"
" parameter);",
- format("#define A /* */ b\n"
+ format("#define A /*123*/ b\n"
"/* */\n"
"someCall(parameter);",
getLLVMStyleWithColumns(15)));