forked from OSchip/llvm-project
clang-format: Format line if invoked on the trailing newline.
llvm-svn: 220883
This commit is contained in:
parent
fd465fe5b5
commit
ac29eaccd2
|
@ -1962,8 +1962,7 @@ private:
|
|||
if (!IncludeLeadingNewlines)
|
||||
Start = Start.getLocWithOffset(First.LastNewlineOffset);
|
||||
SourceLocation End = Last.getStartOfNonWhitespace();
|
||||
if (Last.TokenText.size() > 0)
|
||||
End = End.getLocWithOffset(Last.TokenText.size() - 1);
|
||||
End = End.getLocWithOffset(Last.TokenText.size());
|
||||
CharSourceRange Range = CharSourceRange::getCharRange(Start, End);
|
||||
return affectsCharSourceRange(Range);
|
||||
}
|
||||
|
|
|
@ -159,9 +159,21 @@ TEST_F(FormatTest, FormatsCorrectRegionForLeadingWhitespace) {
|
|||
25, 0, getLLVMStyleWithColumns(12)));
|
||||
}
|
||||
|
||||
TEST_F(FormatTest, FormatLineWhenInvokedOnTrailingNewline) {
|
||||
EXPECT_EQ("int b;\n\nint a;",
|
||||
format("int b;\n\nint a;", 8, 0, getLLVMStyle()));
|
||||
EXPECT_EQ("int b;\n\nint a;",
|
||||
format("int b;\n\nint a;", 7, 0, getLLVMStyle()));
|
||||
|
||||
// This might not strictly be correct, but is likely good in all practical
|
||||
// cases.
|
||||
EXPECT_EQ("int b;\nint a;",
|
||||
format("int b;int a;", 7, 0, getLLVMStyle()));
|
||||
}
|
||||
|
||||
TEST_F(FormatTest, RemovesWhitespaceWhenTriggeredOnEmptyLine) {
|
||||
EXPECT_EQ("int a;\n\n int b;",
|
||||
format("int a;\n \n\n int b;", 7, 0, getLLVMStyle()));
|
||||
format("int a;\n \n\n int b;", 8, 0, getLLVMStyle()));
|
||||
EXPECT_EQ("int a;\n\n int b;",
|
||||
format("int a;\n \n\n int b;", 9, 0, getLLVMStyle()));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue