}
if (Current.UnbreakableTailLength >= getColumnLimit())
return 0;
- unsigned RemainingSpace = getColumnLimit() - Current.UnbreakableTailLength;
+ unsigned RemainingSpace = getColumnLimit() - Current.UnbreakableTailLength;
bool BreakInserted = false;
unsigned Penalty = 0;
- unsigned PositionAfterLastLineInToken = 0;
+ unsigned RemainingTokenColumns = 0;
for (unsigned LineIndex = 0, EndIndex = Token->getLineCount();
LineIndex != EndIndex; ++LineIndex) {
if (!DryRun)
Token->replaceWhitespaceBefore(LineIndex, Whitespaces);
unsigned TailOffset = 0;
- unsigned RemainingTokenColumns = Token->getLineLengthAfterSplit(
+ RemainingTokenColumns = Token->getLineLengthAfterSplit(
LineIndex, TailOffset, StringRef::npos);
while (RemainingTokenColumns > RemainingSpace) {
BreakableToken::Split Split =
RemainingTokenColumns = NewRemainingTokenColumns;
BreakInserted = true;
}
- PositionAfterLastLineInToken = RemainingTokenColumns;
}
+ State.Column = RemainingTokenColumns;
+
if (BreakInserted) {
- State.Column = PositionAfterLastLineInToken;
// If we break the token inside a parameter list, we need to break before
// the next parameter on all levels, so that the next parameter is clearly
// visible. Line comments already introduce a break.
getLLVMStyleWithColumns(33)));
}
-TEST_F(FormatTest, UnderstandsMultiLineComments) {
+TEST_F(FormatTest, UnderstandsBlockComments) {
verifyFormat("f(/*test=*/ true);");
EXPECT_EQ(
"f(aaaaaaaaaaaaaaaaaaaaaaaaa, /* Trailing comment for aa... */\n"
NoBinPacking);
}
-TEST_F(FormatTest, AlignsMultiLineComments) {
+TEST_F(FormatTest, AlignsBlockComments) {
EXPECT_EQ("/*\n"
" * Really multi-line\n"
" * comment.\n"
" * line. */"));
}
+TEST_F(FormatTest, CorrectlyHandlesLengthOfBlockComments) {
+ EXPECT_EQ("double *x; /* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n"
+ " aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa */",
+ format("double *x; /* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n"
+ " aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa */"));
+}
+
TEST_F(FormatTest, SplitsLongCxxComments) {
EXPECT_EQ("// A comment that\n"
"// doesn't fit on\n"
}
TEST_F(FormatTest, MultiLineCommentsInDefines) {
- // FIXME: The line breaks are still suboptimal (current guess
- // is that this is due to the token length being misused), but
- // the comment handling is correct.
- EXPECT_EQ("#define A( \\\n"
- " x) /* \\\n"
- "a comment \\\n"
- "inside */ \\\n"
+ EXPECT_EQ("#define A(x) /* \\\n"
+ " a comment \\\n"
+ " inside */ \\\n"
" f();",
format("#define A(x) /* \\\n"
" a comment \\\n"
" inside */ \\\n"
" f();",
getLLVMStyleWithColumns(17)));
- EXPECT_EQ("#define A(x) /* \\\n"
- " a \\\n"
- " comment \\\n"
- " inside \\\n"
- " */ \\\n"
+ EXPECT_EQ("#define A( \\\n"
+ " x) /* \\\n"
+ " a comment \\\n"
+ " inside */ \\\n"
" f();",
format("#define A( \\\n"
" x) /* \\\n"