diff options
author | Daniel Jasper <djasper@google.com> | 2013-01-17 12:53:34 +0000 |
---|---|---|
committer | Daniel Jasper <djasper@google.com> | 2013-01-17 12:53:34 +0000 |
commit | 2c6cc48a38455969b4602a2d37ce620101b7eebc (patch) | |
tree | 15949308b28238ed9158f7f444a897bcfe0a7252 /unittests/Format/FormatTest.cpp | |
parent | ee000bb236fd99f297c253206e5f110a8f49661e (diff) |
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.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172711 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests/Format/FormatTest.cpp')
-rw-r--r-- | unittests/Format/FormatTest.cpp | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index bd0fcbcf2c..190eabab38 100644 --- a/unittests/Format/FormatTest.cpp +++ b/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 };"); + } //===----------------------------------------------------------------------===// |