diff options
| author | Daniel Jasper <djasper@google.com> | 2013-12-19 21:41:37 +0000 |
|---|---|---|
| committer | Daniel Jasper <djasper@google.com> | 2013-12-19 21:41:37 +0000 |
| commit | 5a611397a2ffdc9f1988e63a6490b0cd64267d65 (patch) | |
| tree | 61bc0f6d0c5102e24f65e9c40a548a7d33d9f2da /clang/unittests/Format/FormatTest.cpp | |
| parent | 5c6c62f7fc89840201c8a7767f78867025b98f90 (diff) | |
| download | bcm5719-llvm-5a611397a2ffdc9f1988e63a6490b0cd64267d65.tar.gz bcm5719-llvm-5a611397a2ffdc9f1988e63a6490b0cd64267d65.zip | |
clang-format: Add special case for leading comments in braced lists.
A comment following the "{" of a braced list seems to almost always
refer to the first element of the list and thus should be aligned
to it.
Before (with Cpp11 braced list style):
SomeFunction({ // Comment 1
"first entry",
// Comment 2
"second entry"});
After:
SomeFunction({// Comment 1
"first entry",
// Comment 2
"second entry"});
llvm-svn: 197725
Diffstat (limited to 'clang/unittests/Format/FormatTest.cpp')
| -rw-r--r-- | clang/unittests/Format/FormatTest.cpp | 44 |
1 files changed, 36 insertions, 8 deletions
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index a56333d7783..cdf2f94cf3f 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -4771,12 +4771,12 @@ TEST_F(FormatTest, LayoutCxx11ConstructorBraceInitializers) { verifyFormat("DoSomethingWithVector({} /* No data */);"); verifyFormat("DoSomethingWithVector({ {} /* No data */ }, { { 1, 2 } });"); verifyFormat( - "someFunction(OtherParam, BracedList{\n" - " // comment 1 (Forcing interesting break)\n" - " param1, param2,\n" - " // comment 2\n" - " param3, param4\n" - " });"); + "someFunction(OtherParam,\n" + " BracedList{ // comment 1 (Forcing interesting break)\n" + " param1, param2,\n" + " // comment 2\n" + " param3, param4 });", + getLLVMStyleWithColumns(75)); verifyFormat( "std::this_thread::sleep_for(\n" " std::chrono::nanoseconds{ std::chrono::seconds{ 1 } } / 5);"); @@ -4808,11 +4808,39 @@ TEST_F(FormatTest, LayoutCxx11ConstructorBraceInitializers) { " T member = {arg1, arg2};\n" "};", NoSpaces); + + // FIXME: The alignment of these trailing comments might be bad. Then again, + // this might be utterly useless in real code. verifyFormat("Constructor::Constructor()\n" - " : some_value{ //\n" - " aaaaaaa //\n" + " : some_value{ //\n" + " aaaaaaa //\n" " } {}", NoSpaces); + + // In braced lists, the first comment is always assumed to belong to the + // first element. Thus, it can be moved to the next or previous line as + // appropriate. + EXPECT_EQ("function({// First element:\n" + " 1,\n" + " // Second element:\n" + " 2});", + format("function({\n" + " // First element:\n" + " 1,\n" + " // Second element:\n" + " 2});", + NoSpaces)); + NoSpaces.ColumnLimit = 30; + EXPECT_EQ( + "std::vector<int> MyNumbers{\n" + " // First element:\n" + " 1,\n" + " // Second element:\n" + " 2};", + format("std::vector<int> MyNumbers{// First element:\n" + " 1,\n" + " // Second element:\n" + " 2};", NoSpaces)); } TEST_F(FormatTest, FormatsBracedListsInColumnLayout) { |

