diff options
author | MaĆra Canal <mairacanal@riseup.net> | 2022-12-01 15:55:58 -0800 |
---|---|---|
committer | Owen Pan <owenpiano@gmail.com> | 2022-12-01 16:07:06 -0800 |
commit | ad83bead3d42082f858d810a5b9f43ed096a6e3c (patch) | |
tree | 20433a77703300cff13f18fbc4ac25a61936c802 /clang/unittests/Format/FormatTestComments.cpp | |
parent | 2b234ce3f07caea605df730ca0b33f22c419582f (diff) | |
download | llvm-ad83bead3d42082f858d810a5b9f43ed096a6e3c.zip llvm-ad83bead3d42082f858d810a5b9f43ed096a6e3c.tar.gz llvm-ad83bead3d42082f858d810a5b9f43ed096a6e3c.tar.bz2 |
[clang-format] Don't move comments if AlignTrailingComments: Leave
For comments that start after a new line, currently, the comments are
being indented. This happens because the OriginalWhitespaceRange
considers newlines on the range. Therefore, when AlignTrailingComments:
Kind: Leave, deduct the number of newlines before the token to calculate
the number of spaces for trailing comments.
Fixes #59203.
Differential Revision: https://reviews.llvm.org/D139029
Diffstat (limited to 'clang/unittests/Format/FormatTestComments.cpp')
-rw-r--r-- | clang/unittests/Format/FormatTestComments.cpp | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/clang/unittests/Format/FormatTestComments.cpp b/clang/unittests/Format/FormatTestComments.cpp index 524bf87..3336ee4 100644 --- a/clang/unittests/Format/FormatTestComments.cpp +++ b/clang/unittests/Format/FormatTestComments.cpp @@ -3062,6 +3062,61 @@ TEST_F(FormatTestComments, AlignTrailingCommentsLeave) { "int d;// comment\n", Style)); + EXPECT_EQ("// do not touch\n" + "int a; // any comments\n" + "\n" + " // comment\n" + "// comment\n" + "\n" + "// comment", + format("// do not touch\n" + "int a; // any comments\n" + "\n" + " // comment\n" + "// comment\n" + "\n" + "// comment", + Style)); + + EXPECT_EQ("// do not touch\n" + "int a; // any comments\n" + "\n" + " // comment\n" + "// comment\n" + "\n" + "// comment", + format("// do not touch\n" + "int a; // any comments\n" + "\n" + "\n" + " // comment\n" + "// comment\n" + "\n" + "\n" + "// comment", + Style)); + + // Allow to keep 2 empty lines + Style.MaxEmptyLinesToKeep = 2; + EXPECT_EQ("// do not touch\n" + "int a; // any comments\n" + "\n" + "\n" + " // comment\n" + "// comment\n" + "\n" + "// comment", + format("// do not touch\n" + "int a; // any comments\n" + "\n" + "\n" + " // comment\n" + "// comment\n" + "\n" + "// comment", + Style)); + Style.MaxEmptyLinesToKeep = 1; + // Just format comments normally when leaving exceeds the column limit Style.ColumnLimit = 35; EXPECT_EQ("int foo = 12345; // comment\n" |