summaryrefslogtreecommitdiffstats
path: root/clang/unittests/Format/FormatTest.cpp
diff options
context:
space:
mode:
authorDaniel Jasper <djasper@google.com>2013-01-17 12:53:34 +0000
committerDaniel Jasper <djasper@google.com>2013-01-17 12:53:34 +0000
commit11cb81cd6ffc6f500280798a22069167821f427f (patch)
treeb02efbb4d8ad0bbfebf57776372baa812785b09e /clang/unittests/Format/FormatTest.cpp
parente528f67c142b963e1e70d47c5629b29d56d95d9d (diff)
downloadbcm5719-llvm-11cb81cd6ffc6f500280798a22069167821f427f.tar.gz
bcm5719-llvm-11cb81cd6ffc6f500280798a22069167821f427f.zip
Improve handling of comments in static initializers.
Also adding more tests. We can now keep the formatting of something like: static SomeType type = { aaaaaaaaaaaaaaaaaaaa, /* comment */ aaaaaaaaaaaaaaaaaaaa /* comment */, /* comment */ aaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaa, // comment aaaaaaaaaaaaaaaaaaaa }; Note that the comment in the first line is handled like a trailing line comment as that is likely what the user intended. llvm-svn: 172711
Diffstat (limited to 'clang/unittests/Format/FormatTest.cpp')
-rw-r--r--clang/unittests/Format/FormatTest.cpp38
1 files changed, 38 insertions, 0 deletions
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index bd0fcbcf2cc..190eabab38f 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -359,6 +359,44 @@ TEST_F(FormatTest, UnderstandsSingleLineComments) {
TEST_F(FormatTest, UnderstandsMultiLineComments) {
verifyFormat("f(/*test=*/ true);");
+ EXPECT_EQ(
+ "f(aaaaaaaaaaaaaaaaaaaaaaaaa, /* Trailing comment for aa... */\n"
+ " bbbbbbbbbbbbbbbbbbbbbbbbb);",
+ format("f(aaaaaaaaaaaaaaaaaaaaaaaaa , /* Trailing comment for aa... */\n"
+ " bbbbbbbbbbbbbbbbbbbbbbbbb);"));
+ EXPECT_EQ(
+ "f(aaaaaaaaaaaaaaaaaaaaaaaaa,\n"
+ " /* Leading comment for bb... */ bbbbbbbbbbbbbbbbbbbbbbbbb);",
+ format("f(aaaaaaaaaaaaaaaaaaaaaaaaa , \n"
+ "/* Leading comment for bb... */ bbbbbbbbbbbbbbbbbbbbbbbbb);"));
+}
+
+TEST_F(FormatTest, CommentsInStaticInitializers) {
+ EXPECT_EQ(
+ "static SomeType type = { aaaaaaaaaaaaaaaaaaaa, /* comment */\n"
+ " aaaaaaaaaaaaaaaaaaaa /* comment */,\n"
+ " /* comment */ aaaaaaaaaaaaaaaaaaaa,\n"
+ " aaaaaaaaaaaaaaaaaaaa, // comment\n"
+ " aaaaaaaaaaaaaaaaaaaa };",
+ format("static SomeType type = { aaaaaaaaaaaaaaaaaaaa , /* comment */\n"
+ " aaaaaaaaaaaaaaaaaaaa /* comment */ ,\n"
+ " /* comment */ aaaaaaaaaaaaaaaaaaaa ,\n"
+ " aaaaaaaaaaaaaaaaaaaa , // comment\n"
+ " aaaaaaaaaaaaaaaaaaaa };"));
+ verifyFormat("static SomeType type = { aaaaaaaaaaa, // comment for aa...\n"
+ " bbbbbbbbbbb, ccccccccccc };");
+ verifyFormat("static SomeType type = { aaaaaaaaaaa,\n"
+ " // comment for bb....\n"
+ " bbbbbbbbbbb, ccccccccccc };");
+ verifyGoogleFormat(
+ "static SomeType type = { aaaaaaaaaaa, // comment for aa...\n"
+ " bbbbbbbbbbb,\n"
+ " ccccccccccc };");
+ verifyGoogleFormat("static SomeType type = { aaaaaaaaaaa,\n"
+ " // comment for bb....\n"
+ " bbbbbbbbbbb,\n"
+ " ccccccccccc };");
+
}
//===----------------------------------------------------------------------===//
OpenPOWER on IntegriCloud