CharSourceRange::getCharRange(Start, Start.getLocWithOffset(Length)));
Lexer Lex(ID, Context.Sources.getBuffer(ID), Context.Sources,
getFormattingLangOpts());
- tooling::Replacements Replace = reformat(Style, Lex, Context.Sources,
- Ranges,
- new IgnoringDiagConsumer());
+ tooling::Replacements Replace = reformat(
+ Style, Lex, Context.Sources, Ranges, new IgnoringDiagConsumer());
ReplacementCount = Replace.size();
EXPECT_TRUE(applyAllReplacements(Replace, Context.Rewrite));
DEBUG(llvm::errs() << "\n" << Context.getRewrittenText(ID) << "\n\n");
return Context.getRewrittenText(ID);
}
- std::string format(llvm::StringRef Code,
- const FormatStyle &Style = getLLVMStyle()) {
+ std::string
+ format(llvm::StringRef Code, const FormatStyle &Style = getLLVMStyle()) {
return format(Code, 0, Code.size(), Style);
}
MessedUp[i - 1] = '\n';
InComment = true;
} else if (MessedUp[i] == '#' && (JustReplacedNewline || i == 0)) {
- if (i != 0) MessedUp[i - 1] = '\n';
+ if (i != 0)
+ MessedUp[i - 1] = '\n';
InPreprocessorDirective = true;
} else if (MessedUp[i] == '\\' && MessedUp[i + 1] == '\n') {
MessedUp[i] = ' ';
TEST_F(FormatTest, OnlyGeneratesNecessaryReplacements) {
EXPECT_EQ("if (a) {\n"
" f();\n"
- "}", format("if(a){f();}"));
+ "}",
+ format("if(a){f();}"));
EXPECT_EQ(4, ReplacementCount);
EXPECT_EQ("if (a) {\n"
" f();\n"
- "}", format("if (a) {\n"
- " f();\n"
- "}"));
+ "}",
+ format("if (a) {\n"
+ " f();\n"
+ "}"));
EXPECT_EQ(0, ReplacementCount);
}
AllowsMergedIf.AllowShortIfStatementsOnASingleLine = true;
verifyFormat("if (a)\n"
" // comment\n"
- " f();", AllowsMergedIf);
+ " f();",
+ AllowsMergedIf);
verifyFormat("if (a) // Can't merge this\n"
- " f();\n", AllowsMergedIf);
+ " f();\n",
+ AllowsMergedIf);
verifyFormat("if (a) /* still don't merge */\n"
- " f();", AllowsMergedIf);
+ " f();",
+ AllowsMergedIf);
verifyFormat("if (a) { // Never merge this\n"
" f();\n"
- "}", AllowsMergedIf);
+ "}",
+ AllowsMergedIf);
verifyFormat("if (a) { /* Never merge this */\n"
" f();\n"
- "}", AllowsMergedIf);
+ "}",
+ AllowsMergedIf);
AllowsMergedIf.ColumnLimit = 14;
verifyFormat("if (a) return;", AllowsMergedIf);
verifyFormat("if (aaaaaaaaa)\n"
- " return;", AllowsMergedIf);
+ " return;",
+ AllowsMergedIf);
AllowsMergedIf.ColumnLimit = 13;
verifyFormat("if (a)\n return;", AllowsMergedIf);
verifyFormat(
"for (MachineFun::iterator IIII = PrevIt, EEEE = F.end(); IIII != EEEE;\n"
" ++IIIII) {\n}");
- verifyFormat(
- "for (aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaa =\n"
- " aaaaaaaaaaaaaaaa.aaaaaaaaaaaaaaa;\n"
- " aaaaaaaaaaa != aaaaaaaaaaaaaaaaaaa; ++aaaaaaaaaaa) {\n}");
+ verifyFormat("for (aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaa =\n"
+ " aaaaaaaaaaaaaaaa.aaaaaaaaaaaaaaa;\n"
+ " aaaaaaaaaaa != aaaaaaaaaaaaaaaaaaa; ++aaaaaaaaaaa) {\n}");
// FIXME: Not sure whether we want extra identation in line 3 here:
verifyFormat(
"}");
verifyFormat("switch (test)\n"
" ;");
-
+
// FIXME: Improve formatting of case labels in macros.
verifyFormat("#define SOMECASES \\\n"
"case 1: \\\n"
- " case 2\n", getLLVMStyleWithColumns(20));
+ " case 2\n",
+ getLLVMStyleWithColumns(20));
verifyGoogleFormat("switch (x) {\n"
" case 1:\n"
" aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa || aaaaaaaaaaaaaaaaaaaaaaaaaaaaa;");
verifyFormat("int aaaa; // aaaaa\n"
- "int aa; // aaaaaaa", getLLVMStyleWithColumns(20));
+ "int aa; // aaaaaaa",
+ getLLVMStyleWithColumns(20));
EXPECT_EQ("void f() { // This does something ..\n"
"}\n"
"};");
}
-TEST_F(FormatTest, FormatsExternC) {
- verifyFormat("extern \"C\" {\nint a;");
-}
+TEST_F(FormatTest, FormatsExternC) { verifyFormat("extern \"C\" {\nint a;"); }
TEST_F(FormatTest, FormatTryCatch) {
// FIXME: Handle try-catch explicitly in the UnwrappedLineParser, then we'll
TEST_F(FormatTest, NestedStaticInitializers) {
verifyFormat("static A x = { { {} } };\n");
- verifyFormat(
- "static A x = { { { init1, init2, init3, init4 },\n"
- " { init1, init2, init3, init4 } } };");
+ verifyFormat("static A x = { { { init1, init2, init3, init4 },\n"
+ " { init1, init2, init3, init4 } } };");
- verifyFormat(
- "somes Status::global_reps[3] = {\n"
- " { kGlobalRef, OK_CODE, NULL, NULL, NULL },\n"
- " { kGlobalRef, CANCELLED_CODE, NULL, NULL, NULL },\n"
- " { kGlobalRef, UNKNOWN_CODE, NULL, NULL, NULL }\n"
- "};");
- verifyGoogleFormat(
- "somes Status::global_reps[3] = {\n"
- " { kGlobalRef, OK_CODE, NULL, NULL, NULL },\n"
- " { kGlobalRef, CANCELLED_CODE, NULL, NULL, NULL },\n"
- " { kGlobalRef, UNKNOWN_CODE, NULL, NULL, NULL }\n"
- "};");
+ verifyFormat("somes Status::global_reps[3] = {\n"
+ " { kGlobalRef, OK_CODE, NULL, NULL, NULL },\n"
+ " { kGlobalRef, CANCELLED_CODE, NULL, NULL, NULL },\n"
+ " { kGlobalRef, UNKNOWN_CODE, NULL, NULL, NULL }\n"
+ "};");
+ verifyGoogleFormat("somes Status::global_reps[3] = {\n"
+ " { kGlobalRef, OK_CODE, NULL, NULL, NULL },\n"
+ " { kGlobalRef, CANCELLED_CODE, NULL, NULL, NULL },\n"
+ " { kGlobalRef, UNKNOWN_CODE, NULL, NULL, NULL }\n"
+ "};");
verifyFormat(
"CGRect cg_rect = { { rect.fLeft, rect.fTop },\n"
" { rect.fRight - rect.fLeft, rect.fBottom - rect.fTop"
// FIXME: We might at some point want to handle this similar to parameter
// lists, where we have an option to put each on a single line.
- verifyFormat("struct {\n"
- " unsigned bit;\n"
- " const char *const name;\n"
- "} kBitsToOs[] = { { kOsMac, \"Mac\" }, { kOsWin, \"Windows\" },\n"
- " { kOsLinux, \"Linux\" }, { kOsCrOS, \"Chrome OS\" } };");
+ verifyFormat(
+ "struct {\n"
+ " unsigned bit;\n"
+ " const char *const name;\n"
+ "} kBitsToOs[] = { { kOsMac, \"Mac\" }, { kOsWin, \"Windows\" },\n"
+ " { kOsLinux, \"Linux\" }, { kOsCrOS, \"Chrome OS\" } };");
}
TEST_F(FormatTest, FormatsSmallMacroDefinitionsInSingleLine) {
TEST_F(FormatTest, UnescapedEndOfLineEndsPPDirective) {
EXPECT_EQ("#line 42 \"test\"\n",
format("# \\\n line \\\n 42 \\\n \"test\"\n"));
- EXPECT_EQ("#define A B\n",
- format("# \\\n define \\\n A \\\n B\n",
- getLLVMStyleWithColumns(12)));
+ EXPECT_EQ("#define A B\n", format("# \\\n define \\\n A \\\n B\n",
+ getLLVMStyleWithColumns(12)));
}
TEST_F(FormatTest, EndOfFileEndsPPDirective) {
EXPECT_EQ("#line 42 \"test\"",
format("# \\\n line \\\n 42 \\\n \"test\""));
- EXPECT_EQ("#define A B",
- format("# \\\n define \\\n A \\\n B"));
+ EXPECT_EQ("#define A B", format("# \\\n define \\\n A \\\n B"));
}
TEST_F(FormatTest, IndentsPPDirectiveInReducedSpace) {
verifyFormat("#define Something Other", getLLVMStyleWithColumns(24));
verifyFormat("#define Something \\\n"
- " Other", getLLVMStyleWithColumns(23));
+ " Other",
+ getLLVMStyleWithColumns(23));
}
TEST_F(FormatTest, HandlePreprocessorDirectiveContext) {
"#define A(A,\\\n"
" B)\n"
" #include \"b.h\"\n"
- " // some comment\n", getLLVMStyleWithColumns(13)));
+ " // some comment\n",
+ getLLVMStyleWithColumns(13)));
}
-TEST_F(FormatTest, LayoutSingleHash) {
- EXPECT_EQ("#\na;", format("#\na;"));
-}
+TEST_F(FormatTest, LayoutSingleHash) { EXPECT_EQ("#\na;", format("#\na;")); }
TEST_F(FormatTest, LayoutCodeInMacroDefinitions) {
EXPECT_EQ("#define A \\\n"
" c; \\\n"
" e;\n"
- "f;", format("#define A c; e;\n"
- "f;", getLLVMStyleWithColumns(14)));
+ "f;",
+ format("#define A c; e;\n"
+ "f;",
+ getLLVMStyleWithColumns(14)));
}
-TEST_F(FormatTest, LayoutRemainingTokens) {
- EXPECT_EQ("{}", format("{}"));
-}
+TEST_F(FormatTest, LayoutRemainingTokens) { EXPECT_EQ("{}", format("{}")); }
TEST_F(FormatTest, LayoutSingleUnwrappedLineInMacro) {
EXPECT_EQ("# define A\\\n b;",
TEST_F(FormatTest, MacroDefinitionInsideStatement) {
EXPECT_EQ("int x,\n"
"#define A\n"
- " y;", format("int x,\n#define A\ny;"));
+ " y;",
+ format("int x,\n#define A\ny;"));
}
TEST_F(FormatTest, HashInMacroDefinition) {
verifyFormat("#define A \\\n"
" { \\\n"
" f(#c);\\\n"
- " }", getLLVMStyleWithColumns(11));
+ " }",
+ getLLVMStyleWithColumns(11));
verifyFormat("#define A(X) \\\n"
- " void function##X()", getLLVMStyleWithColumns(22));
+ " void function##X()",
+ getLLVMStyleWithColumns(22));
verifyFormat("#define A(a, b, c) \\\n"
- " void a##b##c()", getLLVMStyleWithColumns(22));
+ " void a##b##c()",
+ getLLVMStyleWithColumns(22));
verifyFormat("#define A void # ## #", getLLVMStyleWithColumns(22));
}
TEST_F(FormatTest, EmptyLinesInMacroDefinitions) {
EXPECT_EQ("#define A b;", format("#define A \\\n"
" \\\n"
- " b;", getLLVMStyleWithColumns(25)));
+ " b;",
+ getLLVMStyleWithColumns(25)));
EXPECT_EQ("#define A \\\n"
" \\\n"
" a; \\\n"
- " b;", format("#define A \\\n"
- " \\\n"
- " a; \\\n"
- " b;", getLLVMStyleWithColumns(11)));
+ " b;",
+ format("#define A \\\n"
+ " \\\n"
+ " a; \\\n"
+ " b;",
+ getLLVMStyleWithColumns(11)));
EXPECT_EQ("#define A \\\n"
" a; \\\n"
" \\\n"
- " b;", format("#define A \\\n"
- " a; \\\n"
- " \\\n"
- " b;", getLLVMStyleWithColumns(11)));
+ " b;",
+ format("#define A \\\n"
+ " a; \\\n"
+ " \\\n"
+ " b;",
+ getLLVMStyleWithColumns(11)));
}
TEST_F(FormatTest, IndentPreprocessorDirectivesAtZero) {
verifyFormat("#define A \\\n"
" int v( \\\n"
" a); \\\n"
- " int i;", getLLVMStyleWithColumns(11));
+ " int i;",
+ getLLVMStyleWithColumns(11));
}
TEST_F(FormatTest, MixingPreprocessorDirectivesAndNormalCode) {
"#define A\n"
" a;",
format("int\n#define A\na;"));
- verifyFormat(
- "functionCallTo(\n"
- " someOtherFunction(\n"
- " withSomeParameters, whichInSequence,\n"
- " areLongerThanALine(andAnotherCall,\n"
- "#define A B\n"
- " withMoreParamters,\n"
- " whichStronglyInfluenceTheLayout),\n"
- " andMoreParameters), trailing);",
- getLLVMStyleWithColumns(69));
+ verifyFormat("functionCallTo(\n"
+ " someOtherFunction(\n"
+ " withSomeParameters, whichInSequence,\n"
+ " areLongerThanALine(andAnotherCall,\n"
+ "#define A B\n"
+ " withMoreParamters,\n"
+ " whichStronglyInfluenceTheLayout),\n"
+ " andMoreParameters), trailing);",
+ getLLVMStyleWithColumns(69));
}
TEST_F(FormatTest, LayoutBlockInsideParens) {
EXPECT_EQ("functionCall({\n"
" int i;\n"
- "});", format(" functionCall ( {int i;} );"));
+ "});",
+ format(" functionCall ( {int i;} );"));
}
TEST_F(FormatTest, LayoutBlockInsideStatement) {
EXPECT_EQ("SOME_MACRO { int i; }\n"
- "int i;", format(" SOME_MACRO {int i;} int i;"));
+ "int i;",
+ format(" SOME_MACRO {int i;} int i;"));
}
TEST_F(FormatTest, LayoutNestedBlocks) {
verifyFormat("SomeClass::Constructor()\n"
" : aaaaaaaaaaaaa(aaaaaaaaaaaaaa),\n"
" aaaaaaaaaaaaa(aaaaaaaaaaaaaa),\n"
- " aaaaaaaaaaaaa(aaaaaaaaaaaaaa) {\n}", OnePerLine);
+ " aaaaaaaaaaaaa(aaaaaaaaaaaaaa) {\n}",
+ OnePerLine);
verifyFormat("SomeClass::Constructor()\n"
" : aaaaaaaaaaaaa(aaaaaaaaaaaaaa), // Some comment\n"
" aaaaaaaaaaaaa(aaaaaaaaaaaaaa),\n"
- " aaaaaaaaaaaaa(aaaaaaaaaaaaaa) {\n}", OnePerLine);
+ " aaaaaaaaaaaaa(aaaaaaaaaaaaaa) {\n}",
+ OnePerLine);
verifyFormat("MyClass::MyClass(int var)\n"
" : some_var_(var), // 4 space indent\n"
" some_other_var_(var + 1) { // lined up\n"
- "}", OnePerLine);
+ "}",
+ OnePerLine);
// This test takes VERY long when memoization is broken.
std::string input = "Constructor()\n"
" .aaaaaaaaaaaaaaaaaa();");
verifyGoogleFormat("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(\n"
" aaaaaaaaaa, aaaaaaaaaa, aaaaaaaaaa, aaaaaaaaaaa);");
-
+
verifyGoogleFormat(
"aaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaaaaa + aaaaaaaaaaaaaaaaaaaaaaaaa,\n"
" aaaaaaaaaaaa,\n"
"void f() {\n"
" aaaaaaaaaaaaaaaaaaaaaaa(aaaaaaaaa, aaaaaaaaa, aaaaaaaaaaaaaaaaaaaaa)\n"
" .aaaaaaa();\n"
- "}", Style);
+ "}",
+ Style);
}
TEST_F(FormatTest, FormatsBuilderPattern) {
verifyFormat(
"int Result = (aaaaaaaaaaaaaaaaaaaaaaaaa + aaaaaaaaaaaaaaaaaaaaaaaaa +\n"
" aaaaaaaaaaaaaaaaaaaaaaaaa);");
- verifyFormat(
- "double LooooooooooooooooooooooooongResult =\n"
- " aaaaaaaaaaaaaaaaaaaaaaaa + aaaaaaaaaaaaaaaaaaaaaaaa +\n"
- " aaaaaaaaaaaaaaaaaaaaaaaa;");
+ verifyFormat("double LooooooooooooooooooooooooongResult =\n"
+ " aaaaaaaaaaaaaaaaaaaaaaaa + aaaaaaaaaaaaaaaaaaaaaaaa +\n"
+ " aaaaaaaaaaaaaaaaaaaaaaaa;");
}
TEST_F(FormatTest, AlignsAfterReturn) {
" format(TheLine.First, IndentForLevel[TheLine.Level] >= 0\n"
" ? IndentForLevel[TheLine.Level]\n"
" : TheLine * 2, TheLine.InPPDirective,\n"
- " PreviousEndOfLineColumn);", getLLVMStyleWithColumns(70));
+ " PreviousEndOfLineColumn);",
+ getLLVMStyleWithColumns(70));
}
"looooooooooooooooooooooooongFunction(\n"
" \"short literal\"\n"
" \"looooooooooooooooooooooooooooooooooooooooooooooooong literal\");");
+ verifyFormat("someFunction(\"Always break between multi-line\"\n"
+ " \" string literals\",\n"
+ " and, other, parameters);");
}
TEST_F(FormatTest, AlignsPipes) {
" aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) {\n"
"}");
- verifyFormat(
- "if (int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa =\n"
- " 100000000 + 10000000) {\n}");
+ verifyFormat("if (int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa =\n"
+ " 100000000 + 10000000) {\n}");
}
TEST_F(FormatTest, WrapsAtFunctionCallsIfNecessary) {
verifyFormat(
"template <typename T>\n"
"using comment_to_xml_conversion = comment_to_xml_conversion<T, int>;");
- verifyFormat(
- "template <typename T>\n"
- "void f(int Paaaaaaaaaaaaaaaaaaaaaaaaaaaaaaram1,\n"
- " int Paaaaaaaaaaaaaaaaaaaaaaaaaaaaaaram2);");
+ verifyFormat("template <typename T>\n"
+ "void f(int Paaaaaaaaaaaaaaaaaaaaaaaaaaaaaaram1,\n"
+ " int Paaaaaaaaaaaaaaaaaaaaaaaaaaaaaaram2);");
verifyFormat(
"template <typename T>\n"
"void looooooooooooooooooooongFunction(int Paaaaaaaaaaaaaaaaaaaaram1,\n"
"aaaaaaaaaaaaaaaaaaaaaaaa<aaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaa>(\n"
" aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);");
- verifyFormat(
- "a<aaaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaa>(\n"
- " a(aaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaa));");
+ verifyFormat("a<aaaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaa>(\n"
+ " a(aaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaa));");
}
TEST_F(FormatTest, WrapsAtNestedNameSpecifiers) {
EXPECT_EQ("int *a;\n"
"int *a;\n"
- "int *a;", format("int *a;\n"
- "int* a;\n"
- "int *a;", getGoogleStyle()));
+ "int *a;",
+ format("int *a;\n"
+ "int* a;\n"
+ "int *a;",
+ getGoogleStyle()));
EXPECT_EQ("int* a;\n"
"int* a;\n"
- "int* a;", format("int* a;\n"
- "int* a;\n"
- "int *a;", getGoogleStyle()));
+ "int* a;",
+ format("int* a;\n"
+ "int* a;\n"
+ "int *a;",
+ getGoogleStyle()));
EXPECT_EQ("int *a;\n"
"int *a;\n"
- "int *a;", format("int *a;\n"
- "int * a;\n"
- "int * a;", getGoogleStyle()));
+ "int *a;",
+ format("int *a;\n"
+ "int * a;\n"
+ "int * a;",
+ getGoogleStyle()));
}
TEST_F(FormatTest, FormatsBinaryOperatorsPrecedingEquals) {
verifyFormat("void f() {\n"
" x[aaaaaaaaa -\n"
" b] = 23;\n"
- "}", getLLVMStyleWithColumns(15));
+ "}",
+ getLLVMStyleWithColumns(15));
}
TEST_F(FormatTest, FormatsCasts) {
EXPECT_EQ("void f() {\n"
" if (a)\n"
" return\n"
- "}", format("void f ( ) { if ( a ) return }"));
+ "}",
+ format("void f ( ) { if ( a ) return }"));
EXPECT_EQ("namespace N { void f() }", format("namespace N { void f() }"));
EXPECT_EQ("namespace N {\n"
"void f() {}\n"
"void g()\n"
- "}", format("namespace N { void f( ) { } void g( ) }"));
+ "}",
+ format("namespace N { void f( ) { } void g( ) }"));
}
TEST_F(FormatTest, IndentationWithinColumnLimitNotPossible) {
verifyFormat("int aaaaaaaa =\n"
" // Overly long comment\n"
- " b;", getLLVMStyleWithColumns(20));
+ " b;",
+ getLLVMStyleWithColumns(20));
verifyFormat("function(\n"
" ShortArgument,\n"
- " LoooooooooooongArgument);\n", getLLVMStyleWithColumns(20));
+ " LoooooooooooongArgument);\n",
+ getLLVMStyleWithColumns(20));
}
TEST_F(FormatTest, IncorrectAccessSpecifier) {
"B { int x; }");
}
-TEST_F(FormatTest, IncorrectCodeUnbalancedBraces) {
- verifyFormat("{");
-}
+TEST_F(FormatTest, IncorrectCodeUnbalancedBraces) { verifyFormat("{"); }
TEST_F(FormatTest, IncorrectCodeDoNoWhile) {
verifyFormat("do {\n}");
" {\n"
" breakme(\n"
" qwe);\n"
- "}\n", format("{\n"
- " {\n"
- " breakme(qwe);\n"
- "}\n", getLLVMStyleWithColumns(10)));
+ "}\n",
+ format("{\n"
+ " {\n"
+ " breakme(qwe);\n"
+ "}\n",
+ getLLVMStyleWithColumns(10)));
}
TEST_F(FormatTest, LayoutCallsInsideBraceInitializers) {
- verifyFormat(
- "int x = {\n"
- " avariable,\n"
- " b(alongervariable)\n"
- "};", getLLVMStyleWithColumns(25));
+ verifyFormat("int x = {\n"
+ " avariable,\n"
+ " b(alongervariable)\n"
+ "};",
+ getLLVMStyleWithColumns(25));
}
TEST_F(FormatTest, LayoutBraceInitializersInReturnStatement) {
FormatStyle ShortMergedIf = AllowsMergedIf;
ShortMergedIf.ColumnLimit = 25;
verifyFormat("#define A \\\n"
- " if (true) return 42;", ShortMergedIf);
+ " if (true) return 42;",
+ ShortMergedIf);
verifyFormat("#define A \\\n"
" f(); \\\n"
" if (true)\n"
- "#define B", ShortMergedIf);
+ "#define B",
+ ShortMergedIf);
verifyFormat("#define A \\\n"
" f(); \\\n"
" if (true)\n"
- "g();", ShortMergedIf);
+ "g();",
+ ShortMergedIf);
verifyFormat("{\n"
"#ifdef A\n"
" // Comment\n"
" if (true) continue;\n"
"#endif\n"
" // Comment\n"
- " if (true) continue;", ShortMergedIf);
+ " if (true) continue;",
+ ShortMergedIf);
}
TEST_F(FormatTest, BlockCommentsInControlLoops) {
TEST_F(FormatTest, BlockComments) {
EXPECT_EQ("/* */ /* */ /* */\n/* */ /* */ /* */",
format("/* *//* */ /* */\n/* *//* */ /* */"));
- EXPECT_EQ("/* */ a /* */ b;",
- format(" /* */ a/* */ b;"));
+ EXPECT_EQ("/* */ a /* */ b;", format(" /* */ a/* */ b;"));
EXPECT_EQ("#define A /* */\\\n"
" b\n"
"/* */\n"
" parameter);",
format("#define A /* */ b\n"
"/* */\n"
- "someCall(parameter);", getLLVMStyleWithColumns(15)));
+ "someCall(parameter);",
+ getLLVMStyleWithColumns(15)));
EXPECT_EQ("#define A\n"
"/* */ someCall(\n"
" parameter);",
format("#define A\n"
- "/* */someCall(parameter);", getLLVMStyleWithColumns(15)));
+ "/* */someCall(parameter);",
+ getLLVMStyleWithColumns(15)));
EXPECT_EQ("someFunction(1, /* comment 1 */\n"
" 2, /* comment 2 */\n"
format("someFunction (1, /* comment 1 */\n"
" 2, /* comment 2 */ \n"
" 3, /* comment 3 */\n"
- "aaaa, bbbb );", getGoogleStyle()));
+ "aaaa, bbbb );",
+ getGoogleStyle()));
verifyFormat(
"bool aaaaaaaaaaaaa = /* comment: */ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ||\n"
" aaaaaaaaaaaaaaaaaaaaaaaaaaaa;");
" someCall();",
format("#define A { \\\n"
" /* one line */ \\\n"
- " someCall();", getLLVMStyleWithColumns(20)));
+ " someCall();",
+ getLLVMStyleWithColumns(20)));
EXPECT_EQ("#define A \\\n"
" { \\\n"
" /* previous */ \\\n"
format("#define A { \\\n"
" /* previous */ \\\n"
" /* one line */ \\\n"
- " someCall();", getLLVMStyleWithColumns(20)));
+ " someCall();",
+ getLLVMStyleWithColumns(20)));
}
TEST_F(FormatTest, IndentLineCommentsInStartOfBlockAtEndOfFile) {
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;"));
+ format(
+ "- (void)sendAction:(SEL)aSelector to:(id)anObject forAllCells:(BOOL)flag;"));
// Very long objectiveC method declaration.
verifyFormat("- (NSUInteger)indexOfObject:(id)anObject\n"
"NSDictionary *masses = @{ @\"H\" : @1.0078, @\"He\" : @4.0026 };");
verifyFormat(
"NSDictionary *settings = @{ AVEncoderKey : @(AVAudioQualityMax) };");
-
+
// FIXME: Nested and multi-line array and dictionary literals need more work.
verifyFormat(
"NSDictionary *d = @{ @\"nam\" : NSUserNam(), @\"dte\" : [NSDate date],\n"
"a;\n"
"b;\n"
"}\n"
- "}", format("{\n"
- "{\n"
- "a;\n"
- " b;\n"
- "}\n"
- "}", 13, 2, getLLVMStyle()));
+ "}",
+ format("{\n"
+ "{\n"
+ "a;\n"
+ " b;\n"
+ "}\n"
+ "}",
+ 13, 2, getLLVMStyle()));
EXPECT_EQ("{\n"
"{\n"
" a;\n"
"b;\n"
"}\n"
- "}", format("{\n"
- "{\n"
- " a;\n"
- "b;\n"
- "}\n"
- "}", 9, 2, getLLVMStyle()));
+ "}",
+ format("{\n"
+ "{\n"
+ " a;\n"
+ "b;\n"
+ "}\n"
+ "}",
+ 9, 2, getLLVMStyle()));
EXPECT_EQ("{\n"
"{\n"
"public:\n"
" b;\n"
"}\n"
- "}", format("{\n"
- "{\n"
- "public:\n"
- " b;\n"
- "}\n"
- "}", 17, 2, getLLVMStyle()));
+ "}",
+ format("{\n"
+ "{\n"
+ "public:\n"
+ " b;\n"
+ "}\n"
+ "}",
+ 17, 2, getLLVMStyle()));
EXPECT_EQ("{\n"
"{\n"
"a;\n"
"{\n"
" b;\n"
"}\n"
- "}", format("{\n"
- "{\n"
- "a;\n"
- "}\n"
- "{\n"
- " b;\n"
- "}\n"
- "}", 22, 2, getLLVMStyle()));
+ "}",
+ format("{\n"
+ "{\n"
+ "a;\n"
+ "}\n"
+ "{\n"
+ " b;\n"
+ "}\n"
+ "}",
+ 22, 2, getLLVMStyle()));
EXPECT_EQ(" {\n"
" a;\n"
- " }", format(" {\n"
- "a;\n"
- " }", 4, 2, getLLVMStyle()));
+ " }",
+ format(" {\n"
+ "a;\n"
+ " }",
+ 4, 2, getLLVMStyle()));
EXPECT_EQ("void f() {}\n"
- "void g() {}", format("void f() {}\n"
- "void g() {}", 13, 0, getLLVMStyle()));
+ "void g() {}",
+ format("void f() {}\n"
+ "void g() {}",
+ 13, 0, getLLVMStyle()));
}
} // end namespace tooling