// constructs.
State.Column = Line.Level * 2 + 2;
} else if (Current.Tok.is(tok::string_literal) &&
- Previous.Tok.is(tok::string_literal)) {
+ Previous.Tok.is(tok::string_literal)) {
State.Column = State.Column - Previous.TokenLength;
} else if (Current.Tok.is(tok::lessless) &&
State.FirstLessLess[ParenLevel] != 0) {
unsigned Spaces, unsigned WhitespaceStartColumn) {
std::string NewLineText;
if (NewLines > 0) {
- unsigned Offset =
- std::min<int>(Style.ColumnLimit - 1, WhitespaceStartColumn);
+ unsigned Offset = std::min<int>(Style.ColumnLimit - 1,
+ WhitespaceStartColumn);
for (unsigned i = 0; i < NewLines; ++i) {
NewLineText += std::string(Style.ColumnLimit - Offset - 1, ' ');
NewLineText += "\\\n";
Offset = 0;
}
}
- Replaces.insert(tooling::Replacement(
- SourceMgr, Tok.WhiteSpaceStart, Tok.WhiteSpaceLength,
- NewLineText + std::string(Spaces, ' ')));
+ Replaces.insert(tooling::Replacement(SourceMgr, Tok.WhiteSpaceStart,
+ Tok.WhiteSpaceLength, NewLineText +
+ std::string(Spaces, ' ')));
}
/// \brief Add a new line and the required indent before the first Token
if (!Token.WhiteSpaceStart.isValid() || StructuralError)
return SourceMgr.getSpellingColumnNumber(Token.Tok.getLocation()) - 1;
- unsigned Newlines =
- std::min(Token.NewlinesBefore, Style.MaxEmptyLinesToKeep + 1);
+ unsigned Newlines = std::min(Token.NewlinesBefore,
+ Style.MaxEmptyLinesToKeep + 1);
if (Newlines == 0 && !Token.IsFirst)
Newlines = 1;
unsigned Indent = Line.Level * 2;
// Consume and record whitespace until we find a significant token.
while (FormatTok.Tok.is(tok::unknown)) {
FormatTok.NewlinesBefore += Text.count('\n');
- FormatTok.HasUnescapedNewline =
- Text.count("\\\n") != FormatTok.NewlinesBefore;
+ FormatTok.HasUnescapedNewline = Text.count("\\\n") !=
+ FormatTok.NewlinesBefore;
FormatTok.WhiteSpaceLength += FormatTok.Tok.getLength();
if (FormatTok.Tok.is(tok::eof))
for (std::vector<UnwrappedLine>::iterator I = UnwrappedLines.begin(),
E = UnwrappedLines.end();
I != E; ++I)
- PreviousEndOfLineColumn =
- formatUnwrappedLine(*I, PreviousEndOfLineColumn);
+ PreviousEndOfLineColumn = formatUnwrappedLine(*I,
+ PreviousEndOfLineColumn);
return Replaces;
}
unsigned formatUnwrappedLine(const UnwrappedLine &TheLine,
unsigned PreviousEndOfLineColumn) {
if (TheLine.Tokens.empty())
- return 0; // FIXME: Find out how this can ever happen.
+ return 0; // FIXME: Find out how this can ever happen.
- CharSourceRange LineRange =
- CharSourceRange::getTokenRange(TheLine.Tokens.front().Tok.getLocation(),
- TheLine.Tokens.back().Tok.getLocation());
+ CharSourceRange LineRange = CharSourceRange::getTokenRange(
+ TheLine.Tokens.front().Tok.getLocation(),
+ TheLine.Tokens.back().Tok.getLocation());
for (unsigned i = 0, e = Ranges.size(); i != e; ++i) {
if (SourceMgr.isBeforeInTranslationUnit(LineRange.getEnd(),
return formatter.format();
}
-} // namespace format
-} // namespace clang
+} // namespace format
+} // namespace clang
LangOpts.CPlusPlus = 1;
LangOpts.CPlusPlus11 = 1;
Lexer Lex(ID, Context.Sources.getBuffer(ID), Context.Sources, LangOpts);
- tooling::Replacements Replace =
- reformat(Style, Lex, Context.Sources, Ranges);
+ tooling::Replacements Replace = reformat(Style, Lex, Context.Sources,
+ Ranges);
EXPECT_TRUE(applyAllReplacements(Replace, Context.Rewrite));
return Context.getRewrittenText(ID);
}
verifyFormat("Method(f1(f2, f3()));");
}
-
//===----------------------------------------------------------------------===//
// Tests for control statements.
//===----------------------------------------------------------------------===//
"some_other_code();");
}
-
//===----------------------------------------------------------------------===//
// Tests for comments.
//===----------------------------------------------------------------------===//
verifyFormat("f(/*test=*/ true);");
}
-
//===----------------------------------------------------------------------===//
// Tests for classes, namespaces, etc.
//===----------------------------------------------------------------------===//
}
TEST_F(FormatTest, DoesNotBreakPureVirtualFunctionDefinition) {
- verifyFormat(
- "virtual void write(ELFWriter *writerrr,\n"
- " OwningPtr<FileOutputBuffer> &buffer) = 0;");
+ verifyFormat("virtual void write(ELFWriter *writerrr,\n"
+ " OwningPtr<FileOutputBuffer> &buffer) = 0;");
}
TEST_F(FormatTest, BreaksOnHashWhenDirectiveIsInvalid) {
}
TEST_F(FormatTest, EscapedNewlineAtStartOfTokenInMacroDefinition) {
- EXPECT_EQ("#define A \\\n int i; \\\n int j;",
- format("#define A \\\nint i;\\\n int j;",
- getLLVMStyleWithColumns(11)));
+ EXPECT_EQ(
+ "#define A \\\n int i; \\\n int j;",
+ format("#define A \\\nint i;\\\n int j;", getLLVMStyleWithColumns(11)));
}
TEST_F(FormatTest, CalculateSpaceOnConsecutiveLinesInMacro) {
" aaaaaaaaaaaaaaaaaaaaaaaaa || aaaaaaaaaaaaaaaaaaaaaaa ||\n"
" (aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);");
- verifyFormat(
- "{\n {\n {\n"
- " Annotation.SpaceRequiredBefore =\n"
- " Line.Tokens[i - 1].Tok.isNot(tok::l_paren) &&\n"
- " Line.Tokens[i - 1].Tok.isNot(tok::l_square);\n"
- " }\n }\n}");
+ verifyFormat("{\n {\n {\n"
+ " Annotation.SpaceRequiredBefore =\n"
+ " Line.Tokens[i - 1].Tok.isNot(tok::l_paren) &&\n"
+ " Line.Tokens[i - 1].Tok.isNot(tok::l_square);\n"
+ " }\n }\n}");
}
TEST_F(FormatTest, BreaksAccordingToOperatorPrecedence) {
verifyFormat(
"if (aaaaaaaaaaaaaaaaaaaaaaaaa ||\n"
" bbbbbbbbbbbbbbbbbbbbbbbbb && ccccccccccccccccccccccccc) {\n}");
- verifyFormat(
- "if (aaaaaaaaaaaaaaaaaaaaaaaaa && bbbbbbbbbbbbbbbbbbbbbbbbb ||\n"
- " ccccccccccccccccccccccccc) {\n}");
- verifyFormat(
- "if (aaaaaaaaaaaaaaaaaaaaaaaaa || bbbbbbbbbbbbbbbbbbbbbbbbb ||\n"
- " ccccccccccccccccccccccccc) {\n}");
+ verifyFormat("if (aaaaaaaaaaaaaaaaaaaaaaaaa && bbbbbbbbbbbbbbbbbbbbbbbbb ||\n"
+ " ccccccccccccccccccccccccc) {\n}");
+ verifyFormat("if (aaaaaaaaaaaaaaaaaaaaaaaaa || bbbbbbbbbbbbbbbbbbbbbbbbb ||\n"
+ " ccccccccccccccccccccccccc) {\n}");
verifyFormat(
"if ((aaaaaaaaaaaaaaaaaaaaaaaaa || bbbbbbbbbbbbbbbbbbbbbbbbb) &&\n"
" ccccccccccccccccccccccccc) {\n}");
}
TEST_F(FormatTest, DoesNotBreakBeforePointerOrReference) {
- verifyFormat(
- "int *someFunction(int LoooooooooooooooongParam1,\n"
- " int LoooooooooooooooongParam2) {\n}");
+ verifyFormat("int *someFunction(int LoooooooooooooooongParam1,\n"
+ " int LoooooooooooooooongParam2) {\n}");
verifyFormat(
"TypeSpecDecl *TypeSpecDecl::Create(ASTContext &C, DeclContext *DC,\n"
" SourceLocation L, IdentifierIn *II,\n"
EXPECT_EQ("#import \"string.h\"\n", format("#import \"string.h\"\n"));
}
-
//===----------------------------------------------------------------------===//
// Error recovery tests.
//===----------------------------------------------------------------------===//
verifyFormat("- (void)sendAction:(SEL)aSelector to:(BOOL)anObject;");
EXPECT_EQ("- (NSUInteger)indexOfObject:(id)anObject;",
format("-(NSUInteger)indexOfObject:(id)anObject;"));
- EXPECT_EQ("- (NSInteger)Mthod1;",
- format("-(NSInteger)Mthod1;"));
+ EXPECT_EQ("- (NSInteger)Mthod1;", format("-(NSInteger)Mthod1;"));
EXPECT_EQ("+ (id)Mthod2;", format("+(id)Mthod2;"));
EXPECT_EQ("- (NSInteger)Method3:(id)anObject;",
format("-(NSInteger)Method3:(id)anObject;"));
format("-(NSInteger)Method5:(id)anObject:(id)AnotherObject;"));
EXPECT_EQ("- (id)Method6:(id)A:(id)B:(id)C:(id)D;",
format("- (id)Method6:(id)A:(id)B:(id)C:(id)D;"));
- EXPECT_EQ("- (void)sendAction:(SEL)aSelector to:(id)anObject forAllCells:(BOOL)flag;",
- format("- (void)sendAction:(SEL)aSelector to:(id)anObject forAllCells:(BOOL)flag;"));
+ EXPECT_EQ(
+ "- (void)sendAction:(SEL)aSelector to:(id)anObject forAllCells:(BOOL)flag;",
+ format("- (void)sendAction:(SEL)aSelector to:(id)anObject forAllCells:(BOOL)flag;"));
// Very long objectiveC method declaration.
- EXPECT_EQ("- (NSUInteger)indexOfObject:(id)anObject inRange:(NSRange)range\n "
- "outRange:(NSRange)out_range outRange1:(NSRange)out_range1\n "
- "outRange2:(NSRange)out_range2 outRange3:(NSRange)out_range3\n "
- "outRange4:(NSRange)out_range4 outRange5:(NSRange)out_range5\n "
- "outRange6:(NSRange)out_range6 outRange7:(NSRange)out_range7\n "
- "outRange8:(NSRange)out_range8 outRange9:(NSRange)out_range9;",
-
- format("- (NSUInteger)indexOfObject:(id)anObject inRange:(NSRange)range "
- "outRange:(NSRange) out_range outRange1:(NSRange) out_range1 "
- "outRange2:(NSRange) out_range2 outRange3:(NSRange) out_range3 "
- "outRange4:(NSRange) out_range4 outRange5:(NSRange) out_range5 "
- "outRange6:(NSRange) out_range6 outRange7:(NSRange) out_range7 "
- "outRange8:(NSRange) out_range8 outRange9:(NSRange) out_range9;"));
-}
-
-} // end namespace tooling
-} // end namespace clang
+ EXPECT_EQ(
+ "- (NSUInteger)indexOfObject:(id)anObject inRange:(NSRange)range\n "
+ "outRange:(NSRange)out_range outRange1:(NSRange)out_range1\n "
+ "outRange2:(NSRange)out_range2 outRange3:(NSRange)out_range3\n "
+ "outRange4:(NSRange)out_range4 outRange5:(NSRange)out_range5\n "
+ "outRange6:(NSRange)out_range6 outRange7:(NSRange)out_range7\n "
+ "outRange8:(NSRange)out_range8 outRange9:(NSRange)out_range9;",
+ format(
+ "- (NSUInteger)indexOfObject:(id)anObject inRange:(NSRange)range "
+ "outRange:(NSRange) out_range outRange1:(NSRange) out_range1 "
+ "outRange2:(NSRange) out_range2 outRange3:(NSRange) out_range3 "
+ "outRange4:(NSRange) out_range4 outRange5:(NSRange) out_range5 "
+ "outRange6:(NSRange) out_range6 outRange7:(NSRange) out_range7 "
+ "outRange8:(NSRange) out_range8 outRange9:(NSRange) out_range9;"));
+}
+
+} // end namespace tooling
+} // end namespace clang