forked from OSchip/llvm-project
Correctly determine ranges for clang-format.
We have been assuming that CharSourceRange::getTokenRange() by itself expands a range until the end of a token, but in fact it only sets IsTokenRange to true. Thus, we have so far only considered the first character of the last token to belong to an unwrapped line. This did not really manifest in symptoms as all edit integrations expand ranges to fully lines. llvm-svn: 181778
This commit is contained in:
parent
eb9af29426
commit
cdd0662b4e
|
@ -1473,9 +1473,9 @@ private:
|
|||
bool touchesLine(const AnnotatedLine &TheLine) {
|
||||
const FormatToken *First = &TheLine.First.FormatTok;
|
||||
const FormatToken *Last = &TheLine.Last->FormatTok;
|
||||
CharSourceRange LineRange = CharSourceRange::getTokenRange(
|
||||
CharSourceRange LineRange = CharSourceRange::getCharRange(
|
||||
First->WhiteSpaceStart.getLocWithOffset(First->LastNewlineOffset),
|
||||
Last->Tok.getLocation());
|
||||
Last->Tok.getLocation().getLocWithOffset(Last->TokenLength - 1));
|
||||
return touchesRanges(LineRange);
|
||||
}
|
||||
|
||||
|
|
|
@ -218,7 +218,7 @@ TEST_F(FormatTest, ReformatsMovedLines) {
|
|||
// Tests for control statements.
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
TEST_F(FormatTest, FormatIfWithoutCompountStatement) {
|
||||
TEST_F(FormatTest, FormatIfWithoutCompoundStatement) {
|
||||
verifyFormat("if (true)\n f();\ng();");
|
||||
verifyFormat("if (a)\n if (b)\n if (c)\n g();\nh();");
|
||||
verifyFormat("if (a)\n if (b) {\n f();\n }\ng();");
|
||||
|
@ -246,6 +246,8 @@ TEST_F(FormatTest, FormatIfWithoutCompountStatement) {
|
|||
AllowsMergedIf);
|
||||
|
||||
EXPECT_EQ("if (a) return;", format("if(a)\nreturn;", 7, 1, AllowsMergedIf));
|
||||
EXPECT_EQ("if (a) return; // comment",
|
||||
format("if(a)\nreturn; // comment", 20, 1, AllowsMergedIf));
|
||||
|
||||
AllowsMergedIf.ColumnLimit = 14;
|
||||
verifyFormat("if (a) return;", AllowsMergedIf);
|
||||
|
|
Loading…
Reference in New Issue