diff options
author | Alexander Kornienko <alexfh@google.com> | 2013-03-19 17:41:36 +0000 |
---|---|---|
committer | Alexander Kornienko <alexfh@google.com> | 2013-03-19 17:41:36 +0000 |
commit | 052685c170fcc4fa057c68a44425e6d9b945a167 (patch) | |
tree | 818d25ab200b421c960353b04855339062db57e9 /unittests/Format/FormatTest.cpp | |
parent | 8eecaaa16e6356ad9b9c9463847d328c4d3948db (diff) |
Split long lines in multi-line comments.
Summary: This is implementation for /* */ comments only.
Reviewers: djasper, klimek
Reviewed By: djasper
CC: cfe-commits
Differential Revision: http://llvm-reviews.chandlerc.com/D547
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@177415 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests/Format/FormatTest.cpp')
-rw-r--r-- | unittests/Format/FormatTest.cpp | 128 |
1 files changed, 128 insertions, 0 deletions
diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index e6ae81da5c..a3afbee916 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -651,6 +651,134 @@ TEST_F(FormatTest, AlignsMultiLineComments) { " */")); } +TEST_F(FormatTest, SplitsLongLinesInComments) { + EXPECT_EQ("/* This is a long\n" + "comment that doesn't\n" + "fit on one line. */", + format("/* " + "This is a long " + "comment that doesn't " + "fit on one line. */", + getLLVMStyleWithColumns(20))); + EXPECT_EQ("/*\n" + "This is a long\n" + "comment that doesn't\n" + "fit on one line.\n" + "*/", + format("/*\n" + "This is a long " + "comment that doesn't " + "fit on one line. \n" + "*/", getLLVMStyleWithColumns(20))); + EXPECT_EQ("/*\n" + " * This is a long\n" + " * comment that\n" + " * doesn't fit on\n" + " * one line.\n" + " */", + format("/*\n" + " * This is a long " + " comment that " + " doesn't fit on " + " one line. \n" + " */", getLLVMStyleWithColumns(20))); + EXPECT_EQ("/*\n" + " * This_is_a_comment_with_words_that_dont_fit_on_one_line\n" + " * so_it_should_be_broken\n" + " * wherever_a_space_occurs\n" + " */", + format("/*\n" + " * This_is_a_comment_with_words_that_dont_fit_on_one_line " + " so_it_should_be_broken " + " wherever_a_space_occurs \n" + " */", + getLLVMStyleWithColumns(20))); + EXPECT_EQ("/*\n" + " * This_comment_can_not_be_broken_into_lines\n" + " */", + format("/*\n" + " * This_comment_can_not_be_broken_into_lines\n" + " */", + getLLVMStyleWithColumns(20))); + EXPECT_EQ("{\n" + " /*\n" + " This is another\n" + " long comment that\n" + " doesn't fit on one\n" + " line 1234567890\n" + " */\n" + "}", + format("{\n" + "/*\n" + "This is another " + " long comment that " + " doesn't fit on one" + " line 1234567890\n" + "*/\n" + "}", getLLVMStyleWithColumns(20))); + EXPECT_EQ("{\n" + " /*\n" + " * This i s\n" + " * another comment\n" + " * t hat doesn' t\n" + " * fit on one l i\n" + " * n e\n" + " */\n" + "}", + format("{\n" + "/*\n" + " * This i s" + " another comment" + " t hat doesn' t" + " fit on one l i" + " n e\n" + " */\n" + "}", getLLVMStyleWithColumns(20))); + EXPECT_EQ("/*\n" + " * This is a long\n" + " * comment that\n" + " * doesn't fit on\n" + " * one line\n" + " */", + format(" /*\n" + " * This is a long comment that doesn't fit on one line\n" + " */", getLLVMStyleWithColumns(20))); +} + +TEST_F(FormatTest, SplitsLongLinesInCommentsInPreprocessor) { + EXPECT_EQ("#define X \\\n" + // FIXME: Backslash should be added here. + " /*\n" + " Macro comment \\\n" + " with a long \\\n" + " line \\\n" + // FIXME: We should look at the length of the last line of the token + // instead of the full token's length. + //" */ \\\n" + " */\\\n" + " A + B", + format("#define X \\\n" + " /*\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" + // FIXME: We should look at the length of the last line of the token + // instead of the full token's length. + //"*/ \\\n" + "*/\\\n" + " A + B", + format("#define X \\\n" + " /* Macro comment with a long line */ \\\n" + " A + B", + getLLVMStyleWithColumns(20))); +} + TEST_F(FormatTest, CommentsInStaticInitializers) { EXPECT_EQ( "static SomeType type = { aaaaaaaaaaaaaaaaaaaa, /* comment */\n" |