struct OptimizationParameters {
unsigned PenaltyIndentLevel;
unsigned PenaltyLevelDecrease;
+ unsigned PenaltyExcessCharacter;
};
class UnwrappedLineFormatter {
Replaces(Replaces), StructuralError(StructuralError) {
Parameters.PenaltyIndentLevel = 15;
Parameters.PenaltyLevelDecrease = 30;
+ Parameters.PenaltyExcessCharacter = 1000000;
}
/// \brief Formats an \c UnwrappedLine.
return 3;
}
+ unsigned getColumnLimit() {
+ return Style.ColumnLimit - (Line.InPPDirective ? 1 : 0);
+ }
+
/// \brief Calculate the number of lines needed to format the remaining part
/// of the unwrapped line.
///
addTokenToState(NewLine, true, State);
- // Exceeding column limit is bad.
- if (State.Column > Style.ColumnLimit - (Line.InPPDirective ? 1 : 0))
- return UINT_MAX;
+ // Exceeding column limit is bad, assign penalty.
+ if (State.Column > getColumnLimit()) {
+ unsigned ExcessCharacters = State.Column - getColumnLimit();
+ CurrentPenalty += Parameters.PenaltyExcessCharacter * ExcessCharacters;
+ }
if (StopAt <= CurrentPenalty)
return UINT_MAX;
// Error recovery tests.
//===----------------------------------------------------------------------===//
+TEST_F(FormatTest, IndentationWithinColumnLimitNotPossible) {
+ verifyFormat("int aaaaaaaa =\n"
+ " // Overly long comment\n"
+ " b;", getLLVMStyleWithColumns(20));
+ verifyFormat("function(\n"
+ " ShortArgument,\n"
+ " LoooooooooooongArgument);\n", getLLVMStyleWithColumns(20));
+}
+
TEST_F(FormatTest, IncorrectAccessSpecifier) {
verifyFormat("public:");
verifyFormat("class A {\n"