namespace clang {
namespace format {
-FormatStyle getGoogleStyle() {
- return getGoogleStyle(FormatStyle::LK_Cpp);
-}
+FormatStyle getGoogleStyle() { return getGoogleStyle(FormatStyle::LK_Cpp); }
class FormatTest : public ::testing::Test {
protected:
return Result;
}
- 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);
}
// This might not strictly be correct, but is likely good in all practical
// cases.
- EXPECT_EQ("int b;\nint a;",
- format("int b;int a;", 7, 0, getLLVMStyle()));
+ EXPECT_EQ("int b;\nint a;", format("int b;int a;", 7, 0, getLLVMStyle()));
}
TEST_F(FormatTest, RemovesWhitespaceWhenTriggeredOnEmptyLine) {
}
TEST_F(FormatTest, RecognizesBinaryOperatorKeywords) {
- verifyFormat("x = (a) and (b);");
- verifyFormat("x = (a) or (b);");
- verifyFormat("x = (a) bitand (b);");
- verifyFormat("x = (a) bitor (b);");
- verifyFormat("x = (a) not_eq (b);");
- verifyFormat("x = (a) and_eq (b);");
- verifyFormat("x = (a) or_eq (b);");
- verifyFormat("x = (a) xor (b);");
+ verifyFormat("x = (a) and (b);");
+ verifyFormat("x = (a) or (b);");
+ verifyFormat("x = (a) bitand (b);");
+ verifyFormat("x = (a) bitor (b);");
+ verifyFormat("x = (a) not_eq (b);");
+ verifyFormat("x = (a) and_eq (b);");
+ verifyFormat("x = (a) or_eq (b);");
+ verifyFormat("x = (a) xor (b);");
}
//===----------------------------------------------------------------------===//
" switch (x) { \\\n"
" case a: \\\n"
" foo = b; \\\n"
- " }", getLLVMStyleWithColumns(20));
+ " }",
+ getLLVMStyleWithColumns(20));
verifyFormat("#define OPERATION_CASE(name) \\\n"
" case OP_name: \\\n"
" return operations::Operation##name\n",
" // at start\n"
"}"));
- verifyFormat(
- "#define A \\\n"
- " int i; /* iiiiiiiiiiiiiiiiiiiii */ \\\n"
- " int jjjjjjjjjjjjjjjjjjjjjjjj; /* */",
- getLLVMStyleWithColumns(60));
+ verifyFormat("#define A \\\n"
+ " int i; /* iiiiiiiiiiiiiiiiiiiii */ \\\n"
+ " int jjjjjjjjjjjjjjjjjjjjjjjj; /* */",
+ getLLVMStyleWithColumns(60));
verifyFormat(
"#define A \\\n"
" int i; /* iiiiiiiiiiiiiiiiiiiii */ \\\n"
" c);",
format("SomeFunction(a,\n"
" b,\n"
- " // comment\n"
+ " // comment\n"
" c);"));
EXPECT_EQ("SomeFunction(a, b, // comment (unclear relation)\n"
" c);",
EXPECT_EQ("// a b c d\n"
"// e f g\n"
"// h i j k",
- format("// a b c d e f g h i j k",
- getLLVMStyleWithColumns(10)));
- EXPECT_EQ("// a b c d\n"
- "// e f g\n"
- "// h i j k",
- format("\\\n// a b c d e f g h i j k",
- getLLVMStyleWithColumns(10)));
+ format("// a b c d e f g h i j k", getLLVMStyleWithColumns(10)));
+ EXPECT_EQ(
+ "// a b c d\n"
+ "// e f g\n"
+ "// h i j k",
+ format("\\\n// a b c d e f g h i j k", getLLVMStyleWithColumns(10)));
EXPECT_EQ("if (true) // A comment that\n"
" // doesn't fit on\n"
" // one line",
"doesn't "
"fit on one line. */",
getLLVMStyleWithColumns(20)));
- EXPECT_EQ("/* a b c d\n"
- " * e f g\n"
- " * h i j k\n"
- " */",
- format("/* a b c d e f g h i j k */",
- getLLVMStyleWithColumns(10)));
- EXPECT_EQ("/* a b c d\n"
- " * e f g\n"
- " * h i j k\n"
- " */",
- format("\\\n/* a b c d e f g h i j k */",
- getLLVMStyleWithColumns(10)));
+ EXPECT_EQ(
+ "/* a b c d\n"
+ " * e f g\n"
+ " * h i j k\n"
+ " */",
+ format("/* a b c d e f g h i j k */", getLLVMStyleWithColumns(10)));
+ EXPECT_EQ(
+ "/* a b c d\n"
+ " * e f g\n"
+ " * h i j k\n"
+ " */",
+ format("\\\n/* a b c d e f g h i j k */", getLLVMStyleWithColumns(10)));
EXPECT_EQ("/*\n"
"This is a long\n"
"comment that doesn't\n"
"This is a long "
"comment that doesn't "
"fit on one line. \n"
- "*/", getLLVMStyleWithColumns(20)));
+ "*/",
+ getLLVMStyleWithColumns(20)));
EXPECT_EQ("/*\n"
" * This is a long\n"
" * comment that\n"
" comment that "
" doesn't fit on "
" one line. \n"
- " */", getLLVMStyleWithColumns(20)));
+ " */",
+ getLLVMStyleWithColumns(20)));
EXPECT_EQ("/*\n"
" * This_is_a_comment_with_words_that_dont_fit_on_one_line\n"
" * so_it_should_be_broken\n"
" doesn't fit on one"
" line 1234567890\n"
"*/\n"
- "}", getLLVMStyleWithColumns(20)));
+ "}",
+ getLLVMStyleWithColumns(20)));
EXPECT_EQ("{\n"
" /*\n"
" * This i s\n"
" fit on one l i"
" n e\n"
" */\n"
- "}", getLLVMStyleWithColumns(20)));
+ "}",
+ getLLVMStyleWithColumns(20)));
EXPECT_EQ("/*\n"
" * This is a long\n"
" * comment that\n"
" */",
format(" /*\n"
" * This is a long comment that doesn't fit on one line\n"
- " */", getLLVMStyleWithColumns(20)));
+ " */",
+ getLLVMStyleWithColumns(20)));
EXPECT_EQ("{\n"
" if (something) /* This is a\n"
" long\n"
"#endif\n"
"Five\n"
"};"));
-
}
//===----------------------------------------------------------------------===//
TEST_F(FormatTest, StaticInitializers) {
verifyFormat("static SomeClass SC = {1, 'a'};");
- verifyFormat(
- "static SomeClass WithALoooooooooooooooooooongName = {\n"
- " 100000000, \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\"};");
+ verifyFormat("static SomeClass WithALoooooooooooooooooooongName = {\n"
+ " 100000000, "
+ "\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\"};");
// Here, everything other than the "}" would fit on a line.
verifyFormat("static int LooooooooooooooooooooooooongVariable[1] = {\n"
" {kGlobalRef, OK_CODE, NULL, NULL, NULL},\n"
" {kGlobalRef, CANCELLED_CODE, NULL, NULL, NULL},\n"
" {kGlobalRef, UNKNOWN_CODE, NULL, NULL, NULL}};");
- verifyFormat(
- "CGRect cg_rect = {{rect.fLeft, rect.fTop},\n"
- " {rect.fRight - rect.fLeft, rect.fBottom - rect.fTop}};");
+ verifyFormat("CGRect cg_rect = {{rect.fLeft, rect.fTop},\n"
+ " {rect.fRight - rect.fLeft, rect.fBottom - "
+ "rect.fTop}};");
verifyFormat(
"SomeArrayOfSomeType a = {\n"
" {{1, 2, 3}},\n"
" {{1, 2, 3}}};");
- verifyFormat(
- "struct {\n"
- " unsigned bit;\n"
- " const char *const name;\n"
- "} kBitsToOs[] = {{kOsMac, \"Mac\"},\n"
- " {kOsWin, \"Windows\"},\n"
- " {kOsLinux, \"Linux\"},\n"
- " {kOsCrOS, \"Chrome OS\"}};");
- verifyFormat(
- "struct {\n"
- " unsigned bit;\n"
- " const char *const name;\n"
- "} kBitsToOs[] = {\n"
- " {kOsMac, \"Mac\"},\n"
- " {kOsWin, \"Windows\"},\n"
- " {kOsLinux, \"Linux\"},\n"
- " {kOsCrOS, \"Chrome OS\"},\n"
- "};");
+ verifyFormat("struct {\n"
+ " unsigned bit;\n"
+ " const char *const name;\n"
+ "} kBitsToOs[] = {{kOsMac, \"Mac\"},\n"
+ " {kOsWin, \"Windows\"},\n"
+ " {kOsLinux, \"Linux\"},\n"
+ " {kOsCrOS, \"Chrome OS\"}};");
+ verifyFormat("struct {\n"
+ " unsigned bit;\n"
+ " const char *const name;\n"
+ "} kBitsToOs[] = {\n"
+ " {kOsMac, \"Mac\"},\n"
+ " {kOsWin, \"Windows\"},\n"
+ " {kOsLinux, \"Linux\"},\n"
+ " {kOsCrOS, \"Chrome OS\"},\n"
+ "};");
}
TEST_F(FormatTest, FormatsSmallMacroDefinitionsInSingleLine) {
"void f( );\n"
"}"));
// Only if the identifier contains at least 5 characters.
- EXPECT_EQ("HTTP f();",
- format("HTTP\nf();"));
- EXPECT_EQ("MACRO\nf();",
- format("MACRO\nf();"));
+ EXPECT_EQ("HTTP f();", format("HTTP\nf();"));
+ EXPECT_EQ("MACRO\nf();", format("MACRO\nf();"));
// Only if everything is upper case.
EXPECT_EQ("class A : public QObject {\n"
" Q_Object A() {}\n"
"<< SomeThing;"));
verifyFormat("VISIT_GL_CALL(GenBuffers, void, (GLsizei n, GLuint* buffers), "
- "(n, buffers))\n", getChromiumStyle(FormatStyle::LK_Cpp));
+ "(n, buffers))\n",
+ getChromiumStyle(FormatStyle::LK_Cpp));
}
TEST_F(FormatTest, MacroCallsWithoutTrailingSemicolon) {
" A(X x)\n"
" try : t(0) {} catch (...) {}\n"
"};"));
- EXPECT_EQ(
- "class SomeClass {\n"
- "public:\n"
- " SomeClass() EXCLUSIVE_LOCK_FUNCTION(mu_);\n"
- "};",
- format("class SomeClass {\n"
- "public:\n"
- " SomeClass()\n"
- " EXCLUSIVE_LOCK_FUNCTION(mu_);\n"
- "};"));
- EXPECT_EQ(
- "class SomeClass {\n"
- "public:\n"
- " SomeClass()\n"
- " EXCLUSIVE_LOCK_FUNCTION(mu_);\n"
- "};",
- format("class SomeClass {\n"
- "public:\n"
- " SomeClass()\n"
- " EXCLUSIVE_LOCK_FUNCTION(mu_);\n"
- "};", getLLVMStyleWithColumns(40)));
+ EXPECT_EQ("class SomeClass {\n"
+ "public:\n"
+ " SomeClass() EXCLUSIVE_LOCK_FUNCTION(mu_);\n"
+ "};",
+ format("class SomeClass {\n"
+ "public:\n"
+ " SomeClass()\n"
+ " EXCLUSIVE_LOCK_FUNCTION(mu_);\n"
+ "};"));
+ EXPECT_EQ("class SomeClass {\n"
+ "public:\n"
+ " SomeClass()\n"
+ " EXCLUSIVE_LOCK_FUNCTION(mu_);\n"
+ "};",
+ format("class SomeClass {\n"
+ "public:\n"
+ " SomeClass()\n"
+ " EXCLUSIVE_LOCK_FUNCTION(mu_);\n"
+ "};",
+ getLLVMStyleWithColumns(40)));
}
TEST_F(FormatTest, LayoutMacroDefinitionsStatementsSpanningBlocks) {
verifyFormat("#define A \\\n"
" f({ \\\n"
" g(); \\\n"
- " });", getLLVMStyleWithColumns(11));
+ " });",
+ getLLVMStyleWithColumns(11));
}
TEST_F(FormatTest, IndentPreprocessorDirectivesAtZero) {
getLLVMStyleWithColumns(28));
verifyFormat("#if 1\n"
"int i;");
- verifyFormat(
- "#if 1\n"
- "#endif\n"
- "#if 1\n"
- "#else\n"
- "#endif\n");
+ verifyFormat("#if 1\n"
+ "#endif\n"
+ "#if 1\n"
+ "#else\n"
+ "#endif\n");
verifyFormat("DEBUG({\n"
" return aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +\n"
" aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa;\n"
TEST_F(FormatTest, FormatsJoinedLinesOnSubsequentRuns) {
FormatStyle SingleLine = getLLVMStyle();
SingleLine.AllowShortIfStatementsOnASingleLine = true;
- verifyFormat(
- "#if 0\n"
- "#elif 1\n"
- "#endif\n"
- "void foo() {\n"
- " if (test) foo2();\n"
- "}",
- SingleLine);
+ verifyFormat("#if 0\n"
+ "#elif 1\n"
+ "#endif\n"
+ "void foo() {\n"
+ " if (test) foo2();\n"
+ "}",
+ SingleLine);
}
TEST_F(FormatTest, LayoutBlockInsideParens) {
" int j;\n"
"});");
verifyFormat(
- "Aaa(\n" // FIXME: There shouldn't be a linebreak here.
+ "Aaa(\n" // FIXME: There shouldn't be a linebreak here.
" {\n"
" int i; // break\n"
" },\n"
"}");
// Even explicit parentheses stress the precedence enough to make the
// additional break unnecessary.
- verifyFormat(
- "if ((aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +\n"
- " aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) == 5) {\n"
- "}");
+ verifyFormat("if ((aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +\n"
+ " aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) == 5) {\n"
+ "}");
// This cases is borderline, but with the indentation it is still readable.
verifyFormat(
"if (aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(\n"
// If the LHS is a binary expression, we should still use the additional break
// as otherwise the formatting hides the operator precedence.
- verifyFormat(
- "if (aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +\n"
- " aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ==\n"
- " 5) {\n"
- "}");
+ verifyFormat("if (aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +\n"
+ " aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ==\n"
+ " 5) {\n"
+ "}");
FormatStyle OnePerLine = getLLVMStyle();
OnePerLine.BinPackParameters = false;
" // comment\n"
" + b;",
Style);
- verifyFormat("int aaaaaa = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n"
- " * bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\n"
- " + cc;",
- Style);
+ verifyFormat(
+ "int aaaaaa = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n"
+ " * bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\n"
+ " + cc;",
+ Style);
// Forced by comments.
verifyFormat(
FormatStyle Style = getLLVMStyle();
Style.AlignOperands = false;
Style.BreakBeforeBinaryOperators = FormatStyle::BOS_NonAssignment;
- verifyFormat(
- "bool value = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n"
- " + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n"
- " + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n"
- " == aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n"
- " * bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\n"
- " + bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\n"
- " && aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n"
- " * aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n"
- " > ccccccccccccccccccccccccccccccccccccccccc;",
- Style);
+ verifyFormat("bool value = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n"
+ " + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n"
+ " + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n"
+ " == aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n"
+ " * bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\n"
+ " + bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\n"
+ " && aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n"
+ " * aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n"
+ " > ccccccccccccccccccccccccccccccccccccccccc;",
+ Style);
verifyFormat("int aaaaaa = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n"
" * bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\n"
// 1) break amongst arguments.
verifyFormat("Aaaaaaaaaaaaaa bbbbbbbbbbbbbb(Cccccccccccccc cccccccccccccc,\n"
" Cccccccccccccc cccccccccccccc);");
- verifyFormat(
- "template <class TemplateIt>\n"
- "SomeReturnType SomeFunction(TemplateIt begin, TemplateIt end,\n"
- " TemplateIt *stop) {}");
+ verifyFormat("template <class TemplateIt>\n"
+ "SomeReturnType SomeFunction(TemplateIt begin, TemplateIt end,\n"
+ " TemplateIt *stop) {}");
// 2) break after return type.
verifyFormat(
verifyFormat("void aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(\n"
" aaaaaaaaaaaaaaaaaaaaaaaaa* const aaaaaaaaaaaa) {}",
Style);
- verifyFormat(
- "void aaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa*\n"
- " aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) {}",
- Style);
+ verifyFormat("void aaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa*\n"
+ " aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) {}",
+ Style);
}
TEST_F(FormatTest, TrailingReturnType) {
verifyFormat(
"aaaaaa(aaa, new Aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(\n"
" aaaaaaaaaaaaaaaaaaaaaaaaaaaaa));");
- verifyFormat(
- "aaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +\n"
- " aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,\n"
- " aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);");
+ verifyFormat("aaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +\n"
+ " aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,\n"
+ " aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);");
// Indent consistently independent of call expression.
verifyFormat("aaaaaaaaaaa(bbbbbbbbbbbbbbbbbbbbbbbbb.ccccccccccccccccc(\n"
}
TEST_F(FormatTest, FormatsBuilderPattern) {
- verifyFormat(
- "return llvm::StringSwitch<Reference::Kind>(name)\n"
- " .StartsWith(\".eh_frame_hdr\", ORDER_EH_FRAMEHDR)\n"
- " .StartsWith(\".eh_frame\", ORDER_EH_FRAME)\n"
- " .StartsWith(\".init\", ORDER_INIT)\n"
- " .StartsWith(\".fini\", ORDER_FINI)\n"
- " .StartsWith(\".hash\", ORDER_HASH)\n"
- " .Default(ORDER_TEXT);\n");
+ verifyFormat("return llvm::StringSwitch<Reference::Kind>(name)\n"
+ " .StartsWith(\".eh_frame_hdr\", ORDER_EH_FRAMEHDR)\n"
+ " .StartsWith(\".eh_frame\", ORDER_EH_FRAME)\n"
+ " .StartsWith(\".init\", ORDER_INIT)\n"
+ " .StartsWith(\".fini\", ORDER_FINI)\n"
+ " .StartsWith(\".hash\", ORDER_HASH)\n"
+ " .Default(ORDER_TEXT);\n");
verifyFormat("return aaaaaaaaaaaaaaaaa->aaaaa().aaaaaaaaaaaaa().aaaaaa() <\n"
" aaaaaaaaaaaaaaa->aaaaa().aaaaaaaaaaaaa().aaaaaa();");
" aaaaaaaaaaaaaaaaaaaaa));");
FormatStyle Style = getLLVMStyle();
Style.AlignAfterOpenBracket = false;
- verifyFormat(
- "void aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(\n"
- " aaaaaaaaaaa aaaaaaaa, aaaaaaaaa aaaaaaa) {}",
- Style);
- verifyFormat(
- "SomeLongVariableName->someVeryLongFunctionName(\n"
- " aaaaaaaaaaa aaaaaaaaa, aaaaaaaaaaa aaaaaaaaa);",
- Style);
- verifyFormat(
- "SomeLongVariableName->someFunction(\n"
- " foooooooo(aaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaaa));",
- Style);
+ verifyFormat("void aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(\n"
+ " aaaaaaaaaaa aaaaaaaa, aaaaaaaaa aaaaaaa) {}",
+ Style);
+ verifyFormat("SomeLongVariableName->someVeryLongFunctionName(\n"
+ " aaaaaaaaaaa aaaaaaaaa, aaaaaaaaaaa aaaaaaaaa);",
+ Style);
+ verifyFormat("SomeLongVariableName->someFunction(\n"
+ " foooooooo(aaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaaa));",
+ Style);
verifyFormat(
"void aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(aaaaaaaaaaa aaaaaaaa,\n"
" aaaaaaaaa aaaaaaa, aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) {}",
" // comment\n"
" ? aaaa\n"
" : bbbb;");
- verifyFormat(
- "unsigned Indent =\n"
- " format(TheLine.First, IndentForLevel[TheLine.Level] >= 0\n"
- " ? IndentForLevel[TheLine.Level]\n"
- " : TheLine * 2,\n"
- " TheLine.InPPDirective, PreviousEndOfLineColumn);",
- getLLVMStyleWithColumns(70));
+ verifyFormat("unsigned Indent =\n"
+ " format(TheLine.First, IndentForLevel[TheLine.Level] >= 0\n"
+ " ? IndentForLevel[TheLine.Level]\n"
+ " : TheLine * 2,\n"
+ " TheLine.InPPDirective, PreviousEndOfLineColumn);",
+ getLLVMStyleWithColumns(70));
verifyFormat("bool aaaaaa = aaaaaaaaaaaaa //\n"
" ? aaaaaaaaaaaaaaa\n"
" : bbbbbbbbbbbbbbb //\n"
" *aaaaaaaaaaaaaaaaaaaaaaaaaaaaa = aaaaaaaaaaaaaaaaaaa,\n"
" *b = bbbbbbbbbbbbbbbbbbb;",
Style);
- verifyFormat(
- "aaaaaaaaa *a = aaaaaaaaaaaaaaaaaaa, *b = bbbbbbbbbbbbbbbbbbb,\n"
- " *b = bbbbbbbbbbbbbbbbbbb, *d = ddddddddddddddddddd;",
- Style);
+ verifyFormat("aaaaaaaaa *a = aaaaaaaaaaaaaaaaaaa, *b = bbbbbbbbbbbbbbbbbbb,\n"
+ " *b = bbbbbbbbbbbbbbbbbbb, *d = ddddddddddddddddddd;",
+ Style);
}
TEST_F(FormatTest, ConditionalExpressionsInBrackets) {
FormatStyle AfterType = getLLVMStyle();
AfterType.AlwaysBreakAfterDefinitionReturnType = true;
verifyFormat("const char *\n"
- "f(void) {\n" // Break here.
+ "f(void) {\n" // Break here.
" return \"\";\n"
"}\n"
- "const char *bar(void);\n", // No break here.
+ "const char *bar(void);\n", // No break here.
AfterType);
verifyFormat("template <class T>\n"
"T *\n"
- "f(T &c) {\n" // Break here.
+ "f(T &c) {\n" // Break here.
" return NULL;\n"
"}\n"
- "template <class T> T *f(T &c);\n", // No break here.
+ "template <class T> T *f(T &c);\n", // No break here.
AfterType);
AfterType.BreakBeforeBraces = FormatStyle::BS_Stroustrup;
verifyFormat("const char *\n"
- "f(void)\n" // Break here.
+ "f(void)\n" // Break here.
"{\n"
" return \"\";\n"
"}\n"
- "const char *bar(void);\n", // No break here.
+ "const char *bar(void);\n", // No break here.
AfterType);
verifyFormat("template <class T>\n"
- "T *\n" // Problem here: no line break
- "f(T &c)\n" // Break here.
+ "T *\n" // Problem here: no line break
+ "f(T &c)\n" // Break here.
"{\n"
" return NULL;\n"
"}\n"
- "template <class T> T *f(T &c);\n", // No break here.
+ "template <class T> T *f(T &c);\n", // No break here.
AfterType);
}
"llvm::errs() << \"a: \" << aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(\n"
" aaaaaaaaaaaaaaaaaaaaaaaaaaaa,\n"
" aaaaaaaaaaaaaaaaaaaaaaaaaaaa);");
- verifyFormat(
- "llvm::errs() << aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(\n"
- " aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,\n"
- " aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa)\n"
- " << bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb;");
+ verifyFormat("llvm::errs() << aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(\n"
+ " aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,\n"
+ " aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa)\n"
+ " << bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb;");
verifyFormat(
"llvm::errs() << aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(\n"
" aaaaaaaaaaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaaaaaaaaaa);");
" aaaaaaaaaaaaaaaaaaaaaaaaa(\n"
" aaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaa)->aaaaaaaaa());\n"
"}");
- verifyFormat(
- "aaaaa(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,\n"
- " aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa)\n"
- " .aaaaaaaaaaaaaaa(aa(aaaaaaaaaaaaaaaaaaaaaaaaaaa,\n"
- " aaaaaaaaaaaaaaaaaaaaaaaaaaa,\n"
- " aaaaaaaaaaaaaaaaaaaaaaaaaaa));");
+ verifyFormat("aaaaa(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,\n"
+ " aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa)\n"
+ " .aaaaaaaaaaaaaaa(aa(aaaaaaaaaaaaaaaaaaaaaaaaaaa,\n"
+ " aaaaaaaaaaaaaaaaaaaaaaaaaaa,\n"
+ " aaaaaaaaaaaaaaaaaaaaaaaaaaa));");
verifyFormat("if (aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n"
" .aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n"
" .aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n"
EXPECT_EQ("A() : b(0) {}", format("A():b(0){}", NoColumnLimit));
EXPECT_EQ("class C {\n"
" A() : b(0) {}\n"
- "};", format("class C{A():b(0){}};", NoColumnLimit));
+ "};",
+ format("class C{A():b(0){}};", NoColumnLimit));
EXPECT_EQ("A()\n"
" : b(0) {\n"
"}",
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.
verifyFormat("- (void)aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa:\n"
verifyGoogleFormat("- (void)setDelegate:(id<Protocol>)delegate;");
// FIXME: In LLVM style, there should be a space in front of a '<' for ObjC
// protocol lists (but not for template classes):
- //verifyFormat("- (void)setDelegate:(id <Protocol>)delegate;");
+ // verifyFormat("- (void)setDelegate:(id <Protocol>)delegate;");
verifyFormat("- (int (*)())foo:(int (*)())f;");
verifyGoogleFormat("- (int (*)())foo:(int (*)())foo;");
verifyFormat("int a = &[foo bar:baz];");
verifyFormat("int a = *[foo bar:baz];");
// FIXME: Make casts work, without breaking f()[4].
- //verifyFormat("int a = (int)[foo bar:baz];");
- //verifyFormat("return (int)[foo bar:baz];");
- //verifyFormat("(void)[foo bar:baz];");
+ // verifyFormat("int a = (int)[foo bar:baz];");
+ // verifyFormat("return (int)[foo bar:baz];");
+ // verifyFormat("(void)[foo bar:baz];");
verifyFormat("return (MyType *)[self.tableView cellForRowAtIndexPath:cell];");
// Binary operators.
verifyFormat(
"NSDictionary *settings = @{AVEncoderKey : @(AVAudioQualityMax)};");
- verifyFormat(
- "NSDictionary *d = @{\n"
- " @\"nam\" : NSUserNam(),\n"
- " @\"dte\" : [NSDate date],\n"
- " @\"processInfo\" : [NSProcessInfo processInfo]\n"
- "};");
+ verifyFormat("NSDictionary *d = @{\n"
+ " @\"nam\" : NSUserNam(),\n"
+ " @\"dte\" : [NSDate date],\n"
+ " @\"processInfo\" : [NSProcessInfo processInfo]\n"
+ "};");
verifyFormat(
"@{\n"
" NSFontAttributeNameeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee : "
"};");
// We should try to be robust in case someone forgets the "@".
- verifyFormat(
- "NSDictionary *d = {\n"
- " @\"nam\" : NSUserNam(),\n"
- " @\"dte\" : [NSDate date],\n"
- " @\"processInfo\" : [NSProcessInfo processInfo]\n"
- "};");
+ verifyFormat("NSDictionary *d = {\n"
+ " @\"nam\" : NSUserNam(),\n"
+ " @\"dte\" : [NSDate date],\n"
+ " @\"processInfo\" : [NSProcessInfo processInfo]\n"
+ "};");
verifyFormat("NSMutableDictionary *dictionary =\n"
" [NSMutableDictionary dictionaryWithDictionary:@{\n"
" aaaaaaaaaaaaaaaaaaaaa : aaaaaaaaaaaaa,\n"
"loooooooooooooooooooong);",
getLLVMStyleWithColumns(20)));
- EXPECT_EQ("f(g(\"long string \"\n"
- " \"literal\"),\n"
- " b);",
- format("f(g(\"long string literal\"), b);",
- getLLVMStyleWithColumns(20)));
+ EXPECT_EQ(
+ "f(g(\"long string \"\n"
+ " \"literal\"),\n"
+ " b);",
+ format("f(g(\"long string literal\"), b);", getLLVMStyleWithColumns(20)));
EXPECT_EQ("f(g(\"long string \"\n"
" \"literal\",\n"
" a),\n"
" aaaaaaaaaaaaaaaaaaaa,\n"
" aaaaaa(\"aaa aaaaa aaa aaa aaaaa aaa aaaaa aaa aaa aaaaaa\"));");
- EXPECT_EQ(
- "\"splitmea\"\n"
- "\"trandomp\"\n"
- "\"oint\"",
- format("\"splitmeatrandompoint\"", getLLVMStyleWithColumns(10)));
+ EXPECT_EQ("\"splitmea\"\n"
+ "\"trandomp\"\n"
+ "\"oint\"",
+ format("\"splitmeatrandompoint\"", getLLVMStyleWithColumns(10)));
- EXPECT_EQ(
- "\"split/\"\n"
- "\"pathat/\"\n"
- "\"slashes\"",
- format("\"split/pathat/slashes\"", getLLVMStyleWithColumns(10)));
+ EXPECT_EQ("\"split/\"\n"
+ "\"pathat/\"\n"
+ "\"slashes\"",
+ format("\"split/pathat/slashes\"", getLLVMStyleWithColumns(10)));
- EXPECT_EQ(
- "\"split/\"\n"
- "\"pathat/\"\n"
- "\"slashes\"",
- format("\"split/pathat/slashes\"", getLLVMStyleWithColumns(10)));
+ EXPECT_EQ("\"split/\"\n"
+ "\"pathat/\"\n"
+ "\"slashes\"",
+ format("\"split/pathat/slashes\"", getLLVMStyleWithColumns(10)));
EXPECT_EQ("\"split at \"\n"
"\"spaces/at/\"\n"
"\"slashes.at.any$\"\n"
FormatStyle AlignLeft = getLLVMStyleWithColumns(12);
AlignLeft.AlignEscapedNewlinesLeft = true;
- EXPECT_EQ(
- "#define A \\\n"
- " \"some \" \\\n"
- " \"text \" \\\n"
- " \"other\";",
- format("#define A \"some text other\";", AlignLeft));
+ EXPECT_EQ("#define A \\\n"
+ " \"some \" \\\n"
+ " \"text \" \\\n"
+ " \"other\";",
+ format("#define A \"some text other\";", AlignLeft));
}
TEST_F(FormatTest, BreaksStringLiteralsWithTabs) {
format("#define x(_a) printf(\"foo\"_a);", Style));
}
-TEST_F(FormatTest, UnderstandsCpp1y) {
- verifyFormat("int bi{1'000'000};");
-}
+TEST_F(FormatTest, UnderstandsCpp1y) { verifyFormat("int bi{1'000'000};"); }
TEST_F(FormatTest, BreakStringLiteralsBeforeUnbreakableTokenSequence) {
EXPECT_EQ("someFunction(\"aaabbbcccd\"\n"
}
TEST_F(FormatTest, DoNotBreakStringLiteralsInEscapeSequence) {
- EXPECT_EQ("\"\\a\"",
- format("\"\\a\"", getLLVMStyleWithColumns(3)));
- EXPECT_EQ("\"\\\"",
- format("\"\\\"", getLLVMStyleWithColumns(2)));
+ EXPECT_EQ("\"\\a\"", format("\"\\a\"", getLLVMStyleWithColumns(3)));
+ EXPECT_EQ("\"\\\"", format("\"\\\"", getLLVMStyleWithColumns(2)));
EXPECT_EQ("\"test\"\n"
"\"\\n\"",
format("\"test\\n\"", getLLVMStyleWithColumns(7)));
EXPECT_EQ("\"\\\\\\\\\"\n"
"\"\\n\"",
format("\"\\\\\\\\\\n\"", getLLVMStyleWithColumns(7)));
- EXPECT_EQ("\"\\uff01\"",
- format("\"\\uff01\"", getLLVMStyleWithColumns(7)));
+ EXPECT_EQ("\"\\uff01\"", format("\"\\uff01\"", getLLVMStyleWithColumns(7)));
EXPECT_EQ("\"\\uff01\"\n"
"\"test\"",
format("\"\\uff01test\"", getLLVMStyleWithColumns(8)));
Tab));
EXPECT_EQ("/* some\n"
" comment */",
- format(" \t \t /* some\n"
- " \t \t comment */",
- Tab));
+ format(" \t \t /* some\n"
+ " \t \t comment */",
+ Tab));
EXPECT_EQ("int a; /* some\n"
" comment */",
- format(" \t \t int a; /* some\n"
- " \t \t comment */",
- Tab));
+ format(" \t \t int a; /* some\n"
+ " \t \t comment */",
+ Tab));
EXPECT_EQ("int a; /* some\n"
"comment */",
- format(" \t \t int\ta; /* some\n"
- " \t \t comment */",
- Tab));
+ format(" \t \t int\ta; /* some\n"
+ " \t \t comment */",
+ Tab));
EXPECT_EQ("f(\"\t\t\"); /* some\n"
" comment */",
- format(" \t \t f(\"\t\t\"); /* some\n"
- " \t \t comment */",
- Tab));
+ format(" \t \t f(\"\t\t\"); /* some\n"
+ " \t \t comment */",
+ Tab));
EXPECT_EQ("{\n"
" /*\n"
" * Comment\n"
NoSpace.SpaceBeforeParens = FormatStyle::SBPO_Never;
verifyFormat("while(true)\n"
- " continue;", NoSpace);
+ " continue;",
+ NoSpace);
verifyFormat("for(;;)\n"
- " continue;", NoSpace);
+ " continue;",
+ NoSpace);
verifyFormat("if(true)\n"
" f();\n"
"else if(true)\n"
- " f();", NoSpace);
+ " f();",
+ NoSpace);
verifyFormat("do {\n"
" do_something();\n"
- "} while(something());", NoSpace);
+ "} while(something());",
+ NoSpace);
verifyFormat("switch(x) {\n"
"default:\n"
" break;\n"
- "}", NoSpace);
+ "}",
+ NoSpace);
verifyFormat("auto i = std::make_unique<int>(5);", NoSpace);
verifyFormat("size_t x = sizeof(x);", NoSpace);
verifyFormat("auto f(int x) -> decltype(x);", NoSpace);
verifyFormat("call();", Spaces);
verifyFormat("std::function<void( int, int )> callback;", Spaces);
verifyFormat("while ( (bool)1 )\n"
- " continue;", Spaces);
+ " continue;",
+ Spaces);
verifyFormat("for ( ;; )\n"
- " continue;", Spaces);
+ " continue;",
+ Spaces);
verifyFormat("if ( true )\n"
" f();\n"
"else if ( true )\n"
- " f();", Spaces);
+ " f();",
+ Spaces);
verifyFormat("do {\n"
" do_something( (int)i );\n"
- "} while ( something() );", Spaces);
+ "} while ( something() );",
+ Spaces);
verifyFormat("switch ( x ) {\n"
"default:\n"
" break;\n"
- "}", Spaces);
+ "}",
+ Spaces);
Spaces.SpacesInParentheses = false;
Spaces.SpacesInCStyleCastParentheses = true;
verifyFormat("#define x (( int )-1)", Spaces);
// Run the first set of tests again with:
- Spaces.SpacesInParentheses = false,
- Spaces.SpaceInEmptyParentheses = true;
+ Spaces.SpacesInParentheses = false, Spaces.SpaceInEmptyParentheses = true;
Spaces.SpacesInCStyleCastParentheses = true;
verifyFormat("call(x, y, z);", Spaces);
verifyFormat("call( );", Spaces);
verifyFormat("std::function<void(int, int)> callback;", Spaces);
verifyFormat("while (( bool )1)\n"
- " continue;", Spaces);
+ " continue;",
+ Spaces);
verifyFormat("for (;;)\n"
- " continue;", Spaces);
+ " continue;",
+ Spaces);
verifyFormat("if (true)\n"
" f( );\n"
"else if (true)\n"
- " f( );", Spaces);
+ " f( );",
+ Spaces);
verifyFormat("do {\n"
" do_something(( int )i);\n"
- "} while (something( ));", Spaces);
+ "} while (something( ));",
+ Spaces);
verifyFormat("switch (x) {\n"
"default:\n"
" break;\n"
- "}", Spaces);
+ "}",
+ Spaces);
// Run the first set of tests again with:
Spaces.SpaceAfterCStyleCast = true;
verifyFormat("a or_eq 8;", Spaces);
}
+TEST_F(FormatTest, AlignConsecutiveAssignments) {
+ FormatStyle Alignment = getLLVMStyle();
+ Alignment.AlignConsecutiveAssignments = false;
+ verifyFormat("int a = 5;\n"
+ "int oneTwoThree = 123;",
+ Alignment);
+ verifyFormat("int a = 5;\n"
+ "int oneTwoThree = 123;",
+ Alignment);
+
+ Alignment.AlignConsecutiveAssignments = true;
+ verifyFormat("int a = 5;\n"
+ "int oneTwoThree = 123;",
+ Alignment);
+ verifyFormat("int a = method();\n"
+ "int oneTwoThree = 133;",
+ Alignment);
+ verifyFormat("a &= 5;\n"
+ "bcd *= 5;\n"
+ "ghtyf += 5;\n"
+ "dvfvdb -= 5;\n"
+ "a /= 5;\n"
+ "vdsvsv %= 5;\n"
+ "sfdbddfbdfbb ^= 5;\n"
+ "dvsdsv |= 5;\n"
+ "int dsvvdvsdvvv = 123;",
+ Alignment);
+ verifyFormat("int i = 1, j = 10;\n"
+ "something = 2000;",
+ Alignment);
+ verifyFormat("something = 2000;\n"
+ "int i = 1, j = 10;\n",
+ Alignment);
+ verifyFormat("something = 2000;\n"
+ "another = 911;\n"
+ "int i = 1, j = 10;\n"
+ "oneMore = 1;\n"
+ "i = 2;",
+ Alignment);
+ verifyFormat("int a = 5;\n"
+ "int one = 1;\n"
+ "method();\n"
+ "int oneTwoThree = 123;\n"
+ "int oneTwo = 12;",
+ Alignment);
+ verifyFormat("int oneTwoThree = 123; // comment\n"
+ "int oneTwo = 12; // comment",
+ Alignment);
+ EXPECT_EQ("int a = 5;\n"
+ "\n"
+ "int oneTwoThree = 123;",
+ format("int a = 5;\n"
+ "\n"
+ "int oneTwoThree= 123;",
+ Alignment));
+ EXPECT_EQ("int a = 5;\n"
+ "int one = 1;\n"
+ "\n"
+ "int oneTwoThree = 123;",
+ format("int a = 5;\n"
+ "int one = 1;\n"
+ "\n"
+ "int oneTwoThree = 123;",
+ Alignment));
+ EXPECT_EQ("int a = 5;\n"
+ "int one = 1;\n"
+ "\n"
+ "int oneTwoThree = 123;\n"
+ "int oneTwo = 12;",
+ format("int a = 5;\n"
+ "int one = 1;\n"
+ "\n"
+ "int oneTwoThree = 123;\n"
+ "int oneTwo = 12;",
+ Alignment));
+ Alignment.AlignEscapedNewlinesLeft = true;
+ verifyFormat("#define A \\\n"
+ " int aaaa = 12; \\\n"
+ " int b = 23; \\\n"
+ " int ccc = 234; \\\n"
+ " int dddddddddd = 2345;",
+ Alignment);
+ Alignment.AlignEscapedNewlinesLeft = false;
+ verifyFormat("#define A "
+ " \\\n"
+ " int aaaa = 12; "
+ " \\\n"
+ " int b = 23; "
+ " \\\n"
+ " int ccc = 234; "
+ " \\\n"
+ " int dddddddddd = 2345;",
+ Alignment);
+ verifyFormat("void SomeFunction(int parameter = 1, int i = 2, int j = 3, int "
+ "k = 4, int l = 5,\n"
+ " int m = 6) {\n"
+ " int j = 10;\n"
+ " otherThing = 1;\n"
+ "}",
+ Alignment);
+ verifyFormat("void SomeFunction(int parameter = 0) {\n"
+ " int i = 1;\n"
+ " int j = 2;\n"
+ " int big = 10000;\n"
+ "}",
+ Alignment);
+ verifyFormat("class C {\n"
+ "public:\n"
+ " int i = 1;\n"
+ " virtual void f() = 0;\n"
+ "};",
+ Alignment);
+ verifyFormat("int i = 1;\n"
+ "if (SomeType t = getSomething()) {\n"
+ "}\n"
+ "int j = 2;\n"
+ "int big = 10000;",
+ Alignment);
+ verifyFormat("int j = 7;\n"
+ "for (int k = 0; k < N; ++k) {\n"
+ "}\n"
+ "int j = 2;\n"
+ "int big = 10000;\n"
+ "}",
+ Alignment);
+ Alignment.BreakBeforeBinaryOperators = FormatStyle::BOS_All;
+ verifyFormat("int i = 1;\n"
+ "LooooooooooongType loooooooooooooooooooooongVariable\n"
+ " = someLooooooooooooooooongFunction();\n"
+ "int j = 2;",
+ Alignment);
+ Alignment.BreakBeforeBinaryOperators = FormatStyle::BOS_None;
+ verifyFormat("int i = 1;\n"
+ "LooooooooooongType loooooooooooooooooooooongVariable =\n"
+ " someLooooooooooooooooongFunction();\n"
+ "int j = 2;",
+ Alignment);
+ // FIXME: Should align all three assignments
+ verifyFormat(
+ "int i = 1;\n"
+ "SomeType a = SomeFunction(looooooooooooooooooooooongParameterA,\n"
+ " loooooooooooooooooooooongParameterB);\n"
+ "int j = 2;",
+ Alignment);
+}
+
TEST_F(FormatTest, LinuxBraceBreaking) {
FormatStyle LinuxBraceStyle = getLLVMStyle();
LinuxBraceStyle.BreakBeforeBraces = FormatStyle::BS_Linux;
#define EXPECT_ALL_STYLES_EQUAL(Styles) \
for (size_t i = 1; i < Styles.size(); ++i) \
- EXPECT_EQ(Styles[0], Styles[i]) << "Style #" << i << " of " \
- << Styles.size() \
- << " differs from Style #0"
+ EXPECT_EQ(Styles[0], Styles[i]) << "Style #" << i << " of " << Styles.size() \
+ << " differs from Style #0"
TEST_F(FormatTest, GetsPredefinedStyleByName) {
SmallVector<FormatStyle, 3> Styles;
CHECK_PARSE_BOOL(AlignEscapedNewlinesLeft);
CHECK_PARSE_BOOL(AlignOperands);
CHECK_PARSE_BOOL(AlignTrailingComments);
+ CHECK_PARSE_BOOL(AlignConsecutiveAssignments);
CHECK_PARSE_BOOL(AllowAllParametersOfDeclarationOnNextLine);
CHECK_PARSE_BOOL(AllowShortBlocksOnASingleLine);
CHECK_PARSE_BOOL(AllowShortCaseLabelsOnASingleLine);
Style.BreakBeforeTernaryOperators = true;
EXPECT_EQ(0, parseConfiguration("---\n"
- "BasedOnStyle: Google\n"
- "---\n"
- "Language: JavaScript\n"
- "IndentWidth: 76\n"
- "...\n", &Style).value());
+ "BasedOnStyle: Google\n"
+ "---\n"
+ "Language: JavaScript\n"
+ "IndentWidth: 76\n"
+ "...\n",
+ &Style).value());
EXPECT_FALSE(Style.BreakBeforeTernaryOperators);
EXPECT_EQ(76u, Style.IndentWidth);
EXPECT_EQ(FormatStyle::LK_JavaScript, Style.Language);
getLLVMStyleWithColumns(31));
verifyFormat("// Однажды в студёную зимнюю пору...",
getLLVMStyleWithColumns(36));
- verifyFormat("// 一 二 三 四 五 六 七 八 九 十",
- getLLVMStyleWithColumns(32));
+ verifyFormat("// 一 二 三 四 五 六 七 八 九 十", getLLVMStyleWithColumns(32));
verifyFormat("/* Однажды в студёную зимнюю пору... */",
getLLVMStyleWithColumns(39));
verifyFormat("/* 一 二 三 四 五 六 七 八 九 十 */",
EXPECT_EQ("\"aaaaaaaÄ\"\n"
"\"\xc2\x8d\";",
format("\"aaaaaaaÄ\xc2\x8d\";", getLLVMStyleWithColumns(10)));
+ EXPECT_EQ("\"Однажды, в \"\n"
+ "\"студёную \"\n"
+ "\"зимнюю \"\n"
+ "\"пору,\"",
+ format("\"Однажды, в студёную зимнюю пору,\"",
+ getLLVMStyleWithColumns(13)));
EXPECT_EQ(
- "\"Однажды, в \"\n"
- "\"студёную \"\n"
- "\"зимнюю \"\n"
- "\"пору,\"",
- format("\"Однажды, в студёную зимнюю пору,\"",
- getLLVMStyleWithColumns(13)));
- EXPECT_EQ("\"一 二 三 \"\n"
- "\"四 五六 \"\n"
- "\"七 八 九 \"\n"
- "\"十\"",
- format("\"一 二 三 四 五六 七 八 九 十\"",
- getLLVMStyleWithColumns(11)));
+ "\"一 二 三 \"\n"
+ "\"四 五六 \"\n"
+ "\"七 八 九 \"\n"
+ "\"十\"",
+ format("\"一 二 三 四 五六 七 八 九 十\"", getLLVMStyleWithColumns(11)));
EXPECT_EQ("\"一\t二 \"\n"
"\"\t三 \"\n"
"\"四 五\t六 \"\n"
getLLVMStyleWithColumns(11)));
}
-
TEST_F(FormatTest, HandlesDoubleWidthCharsInMultiLineStrings) {
EXPECT_EQ("const char *sssss =\n"
" \"一二三四五六七八\\\n"
Style);
// Wrap before binary operators.
- EXPECT_EQ(
- "void f()\n"
- "{\n"
- " if (aaaaaaaaaaaaaaaa\n"
- " && bbbbbbbbbbbbbbbbbbbbbbbb\n"
- " && (cccccccccccccccccccccccccc || dddddddddddddddddddd))\n"
- " return;\n"
- "}",
- format(
- "void f() {\n"
- "if (aaaaaaaaaaaaaaaa\n"
- "&& bbbbbbbbbbbbbbbbbbbbbbbb\n"
- "&& (cccccccccccccccccccccccccc || dddddddddddddddddddd))\n"
- "return;\n"
- "}",
- Style));
+ EXPECT_EQ("void f()\n"
+ "{\n"
+ " if (aaaaaaaaaaaaaaaa\n"
+ " && bbbbbbbbbbbbbbbbbbbbbbbb\n"
+ " && (cccccccccccccccccccccccccc || dddddddddddddddddddd))\n"
+ " return;\n"
+ "}",
+ format("void f() {\n"
+ "if (aaaaaaaaaaaaaaaa\n"
+ "&& bbbbbbbbbbbbbbbbbbbbbbbb\n"
+ "&& (cccccccccccccccccccccccccc || dddddddddddddddddddd))\n"
+ "return;\n"
+ "}",
+ Style));
// Allow functions on a single line.
verifyFormat("void f() { return; }", Style);
" , b(b)\n"
" , c(c)\n"
"{\n"
- "}", Style);
+ "}",
+ Style);
verifyFormat("SomeClass::Constructor()\n"
" : a(a)\n"
"{\n"
verifyFormat("f<<<1, 1>>>();");
verifyFormat("f<<<1, 1, 1, s>>>();");
verifyFormat("f<<<a, b, c, d>>>();");
- EXPECT_EQ("f<<<1, 1>>>();",
- format("f <<< 1, 1 >>> ();"));
+ EXPECT_EQ("f<<<1, 1>>>();", format("f <<< 1, 1 >>> ();"));
verifyFormat("f<param><<<1, 1>>>();");
verifyFormat("f<1><<<1, 1>>>();");
- EXPECT_EQ("f<param><<<1, 1>>>();",
- format("f< param > <<< 1, 1 >>> ();"));
+ EXPECT_EQ("f<param><<<1, 1>>>();", format("f< param > <<< 1, 1 >>> ();"));
verifyFormat("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
"aaaaaaaaaaa<<<\n 1, 1>>>();");
}
" int k;"));
}
-TEST_F(FormatTest, DoNotCrashOnInvalidInput) {
- format("? ) =");
-}
+TEST_F(FormatTest, DoNotCrashOnInvalidInput) { format("? ) ="); }
} // end namespace tooling
} // end namespace clang