diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index f5794ffac1a4a..9ef59a8a35d9c 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -19,7 +19,7 @@ class FormatTest : public test::FormatTestBase {}; TEST_F(FormatTest, MessUp) { EXPECT_EQ("1 2 3", messUp("1 2 3")); - EXPECT_EQ("1 2 3\n", messUp("1\n2\n3\n")); + EXPECT_EQ("1 2 3", messUp("1\n2\n3")); EXPECT_EQ("a\n//b\nc", messUp("a\n//b\nc")); EXPECT_EQ("a\n#b\nc", messUp("a\n#b\nc")); EXPECT_EQ("a\n#b c d\ne", messUp("a\n#b\\\nc\\\nd\ne")); @@ -88,10 +88,10 @@ TEST_F(FormatTest, OnlyGeneratesNecessaryReplacements) { EXPECT_EQ(0, ReplacementCount); EXPECT_EQ("/*\r\n" "\r\n" - "*/\r\n", + "*/", format("/*\r\n" "\r\n" - "*/\r\n")); + "*/")); EXPECT_EQ(0, ReplacementCount); } @@ -229,7 +229,7 @@ TEST_F(FormatTest, RemovesEmptyLines) { "class AA {};\n" "\n" "} // namespace b\n" - "} // namespace a\n", + "} // namespace a", format("namespace a\n" "{\n" "namespace b\n" @@ -240,7 +240,7 @@ TEST_F(FormatTest, RemovesEmptyLines) { "\n" "\n" "}\n" - "}\n", + "}", CustomStyle)); EXPECT_EQ("namespace A /* comment */\n" "{\n" @@ -594,7 +594,7 @@ TEST_F(FormatTest, FormatIfWithoutCompoundStatement) { AllowsMergedIf); verifyFormat("if (a) // Can't merge this\n" - " f();\n", + " f();", AllowsMergedIf); verifyFormat("if (a) /* still don't merge */\n" " f();", @@ -630,7 +630,7 @@ TEST_F(FormatTest, FormatIfWithoutCompoundStatement) { AllowsMergedIf); verifyFormat("MYIF (a) // Can't merge this\n" - " f();\n", + " f();", AllowsMergedIf); verifyFormat("MYIF (a) /* still don't merge */\n" " f();", @@ -780,7 +780,7 @@ TEST_F(FormatTest, FormatIfWithoutCompoundStatementButElseWith) { verifyFormat("if (a)\n" " f();\n" "else\n" - " g();\n", + " g();", AllowsMergedIf); verifyFormat("if (a) g();", AllowsMergedIf); @@ -864,7 +864,7 @@ TEST_F(FormatTest, FormatIfWithoutCompoundStatementButElseWith) { verifyFormat("MYIF (a)\n" " f();\n" "else\n" - " g();\n", + " g();", AllowsMergedIf); verifyFormat("MYIF (a) g();", AllowsMergedIf); @@ -1862,9 +1862,9 @@ TEST_F(FormatTest, UnderstandsMacros) { " N " " \\\n" " {\n" - "#define BBB }\n", + "#define BBB }", Style); - // verifyFormat("#define AAA N { //\n", Style); + // verifyFormat("#define AAA N { //", Style); verifyFormat("MACRO(return)"); verifyFormat("MACRO(co_await)"); @@ -2400,13 +2400,13 @@ TEST_F(FormatTest, ForEachLoops) { verifyFormat("#define foreach(x, y)\n" "#define Q_FOREACH(x, y)\n" "#define BOOST_FOREACH(x, y)\n" - "#define UNKNOWN_FOREACH(x, y)\n"); + "#define UNKNOWN_FOREACH(x, y)"); // Not as function-like macros. verifyFormat("#define foreach (x, y)\n" "#define Q_FOREACH (x, y)\n" "#define BOOST_FOREACH (x, y)\n" - "#define UNKNOWN_FOREACH (x, y)\n"); + "#define UNKNOWN_FOREACH (x, y)"); // handle microsoft non standard extension verifyFormat("for each (char c in x->MyStringProperty)"); @@ -2509,7 +2509,7 @@ TEST_F(FormatTest, FormatsSwitchStatement) { getLLVMStyleWithColumns(20)); verifyFormat("#define OPERATION_CASE(name) \\\n" " case OP_name: \\\n" - " return operations::Operation##name\n", + " return operations::Operation##name", getLLVMStyleWithColumns(40)); verifyFormat("switch (x) {\n" "case 1:;\n" @@ -2540,7 +2540,7 @@ TEST_F(FormatTest, FormatsSwitchStatement) { verifyGoogleFormat("#define OPERATION_CASE(name) \\\n" " case OP_name: \\\n" - " return operations::Operation##name\n"); + " return operations::Operation##name"); verifyGoogleFormat("Operation codeToOperation(OperationCode OpCode) {\n" " // Get the correction operation class.\n" " switch (OpCode) {\n" @@ -3418,7 +3418,7 @@ TEST_F(FormatTest, UnderstandsAccessSpecifiers) { verifyFormat("std::vector testVec = {private};"); verifyFormat("private.p = 1;"); verifyFormat("void function(private...){};"); - verifyFormat("if (private && public)\n"); + verifyFormat("if (private && public)"); verifyFormat("private &= true;"); verifyFormat("int x = private * public;"); verifyFormat("public *= private;"); @@ -3431,16 +3431,16 @@ TEST_F(FormatTest, UnderstandsAccessSpecifiers) { verifyFormat("private--;"); verifyFormat("--private;"); verifyFormat("public -= 1;"); - verifyFormat("if (!private && !public)\n"); + verifyFormat("if (!private && !public)"); verifyFormat("public != private;"); verifyFormat("int x = public / private;"); verifyFormat("public /= 2;"); verifyFormat("public = public % 2;"); verifyFormat("public %= 2;"); - verifyFormat("if (public < private)\n"); + verifyFormat("if (public < private)"); verifyFormat("public << private;"); verifyFormat("public <<= private;"); - verifyFormat("if (public > private)\n"); + verifyFormat("if (public > private)"); verifyFormat("public >> private;"); verifyFormat("public >>= private;"); verifyFormat("public ^ private;"); @@ -3448,7 +3448,7 @@ TEST_F(FormatTest, UnderstandsAccessSpecifiers) { verifyFormat("public | private;"); verifyFormat("public |= private;"); verifyFormat("auto x = private ? 1 : 2;"); - verifyFormat("if (public == private)\n"); + verifyFormat("if (public == private)"); verifyFormat("void foo(public, private)"); verifyFormat("public::foo();"); @@ -4097,92 +4097,92 @@ TEST_F(FormatTest, FormatsNamespaces) { " void f() {\n" " return;\n" " }\n" - "} // namespace\n", + "} // namespace", ShortInlineFunctions); verifyFormat("namespace { /* comment */\n" " void f() {\n" " return;\n" " }\n" - "} // namespace\n", + "} // namespace", ShortInlineFunctions); verifyFormat("namespace { // comment\n" " void f() {\n" " return;\n" " }\n" - "} // namespace\n", + "} // namespace", ShortInlineFunctions); verifyFormat("namespace {\n" " int some_int;\n" " void f() {\n" " return;\n" " }\n" - "} // namespace\n", + "} // namespace", ShortInlineFunctions); verifyFormat("namespace interface {\n" " void f() {\n" " return;\n" " }\n" - "} // namespace interface\n", + "} // namespace interface", ShortInlineFunctions); verifyFormat("namespace {\n" " class X {\n" " void f() { return; }\n" " };\n" - "} // namespace\n", + "} // namespace", ShortInlineFunctions); verifyFormat("namespace {\n" " class X { /* comment */\n" " void f() { return; }\n" " };\n" - "} // namespace\n", + "} // namespace", ShortInlineFunctions); verifyFormat("namespace {\n" " class X { // comment\n" " void f() { return; }\n" " };\n" - "} // namespace\n", + "} // namespace", ShortInlineFunctions); verifyFormat("namespace {\n" " struct X {\n" " void f() { return; }\n" " };\n" - "} // namespace\n", + "} // namespace", ShortInlineFunctions); verifyFormat("namespace {\n" " union X {\n" " void f() { return; }\n" " };\n" - "} // namespace\n", + "} // namespace", ShortInlineFunctions); verifyFormat("extern \"C\" {\n" "void f() {\n" " return;\n" "}\n" - "} // namespace\n", + "} // namespace", ShortInlineFunctions); verifyFormat("namespace {\n" " class X {\n" " void f() { return; }\n" " } x;\n" - "} // namespace\n", + "} // namespace", ShortInlineFunctions); verifyFormat("namespace {\n" " [[nodiscard]] class X {\n" " void f() { return; }\n" " };\n" - "} // namespace\n", + "} // namespace", ShortInlineFunctions); verifyFormat("namespace {\n" " static class X {\n" " void f() { return; }\n" " } x;\n" - "} // namespace\n", + "} // namespace", ShortInlineFunctions); verifyFormat("namespace {\n" " constexpr class X {\n" " void f() { return; }\n" " } x;\n" - "} // namespace\n", + "} // namespace", ShortInlineFunctions); ShortInlineFunctions.IndentExternBlock = FormatStyle::IEBS_Indent; @@ -4190,7 +4190,7 @@ TEST_F(FormatTest, FormatsNamespaces) { " void f() {\n" " return;\n" " }\n" - "} // namespace\n", + "} // namespace", ShortInlineFunctions); Style.NamespaceIndentation = FormatStyle::NI_Inner; @@ -4213,7 +4213,7 @@ TEST_F(FormatTest, FormatsNamespaces) { "concept a_concept = X<>;\n" "namespace B {\n" "struct b_struct {};\n" - "} // namespace B\n", + "} // namespace B", Style); verifyFormat("template \n" "constexpr void foo()\n" @@ -4221,7 +4221,7 @@ TEST_F(FormatTest, FormatsNamespaces) { "{}\n" "namespace ns {\n" "void foo() {}\n" - "} // namespace ns\n", + "} // namespace ns", Style); } @@ -4377,11 +4377,11 @@ TEST_F(FormatTest, FormatsCompactNamespaces) { Style)); EXPECT_EQ("namespace A { namespace B { namespace C {\n" - "}}} // namespace A::B::C\n", + "}}} // namespace A::B::C", format("namespace A { namespace B {\n" "namespace C {\n" "}} // namespace B::C\n" - "} // namespace A\n", + "} // namespace A", Style)); Style.ColumnLimit = 40; @@ -4708,21 +4708,21 @@ TEST_F(FormatTest, FormatTryCatch) { " } catch (...) {\n" " throw;\n" " }\n" - "};\n"); + "};"); verifyFormat("class A {\n" " int a;\n" " A() try : a(0), b{1} {\n" " } catch (...) {\n" " throw;\n" " }\n" - "};\n"); + "};"); verifyFormat("class A {\n" " int a;\n" " A() try : a(0), b{1}, c{2} {\n" " } catch (...) {\n" " throw;\n" " }\n" - "};\n"); + "};"); verifyFormat("class A {\n" " int a;\n" " A() try : a(0), b{1}, c{2} {\n" @@ -4731,7 +4731,7 @@ TEST_F(FormatTest, FormatTryCatch) { " } catch (...) {\n" " throw;\n" " }\n" - "};\n"); + "};"); // Incomplete try-catch blocks. verifyIncompleteFormat("try {} catch ("); @@ -4803,7 +4803,7 @@ TEST_F(FormatTest, FormatSEHTryCatch) { " __try {\n" " } __finally {\n" " }\n" - "});\n"); + "});"); } TEST_F(FormatTest, IncompleteTryCatchBlocks) { @@ -4963,32 +4963,32 @@ TEST_F(FormatTest, BracedInitializerIndentWidth) { verifyFormat("enum class {\n" " One,\n" " Two,\n" - "};\n", + "};", Style); verifyFormat("class Foo {\n" " Foo() {}\n" " void bar();\n" - "};\n", + "};", Style); verifyFormat("void foo() {\n" " auto bar = baz;\n" " return baz;\n" - "};\n", + "};", Style); verifyFormat("auto foo = [&] {\n" " auto bar = baz;\n" " return baz;\n" - "};\n", + "};", Style); verifyFormat("{\n" " auto bar = baz;\n" " return baz;\n" - "};\n", + "};", Style); // Non-brace initialization is unaffected by BracedInitializerIndentWidth. verifyFormat("SomeClass clazz(\n" " \"xxxxxxxxxxxxxxxxxx\", \"yyyyyyyyyyyyyyyyyy\",\n" - " \"zzzzzzzzzzzzzzzzzz\");\n", + " \"zzzzzzzzzzzzzzzzzz\");", Style); // The following types of initialization are all affected by @@ -4998,7 +4998,7 @@ TEST_F(FormatTest, BracedInitializerIndentWidth) { Style); verifyFormat("SomeStruct s{\n" " \"xxxxxxxxxxxxxxxx\", \"yyyyyyyyyyyyyyyy\",\n" - " \"zzzzzzzzzzzzzzzz\"};\n", + " \"zzzzzzzzzzzzzzzz\"};", Style); // Designated initializers. verifyFormat("int LooooooooooooooooooooooooongVariable[2] = {\n" @@ -5007,26 +5007,26 @@ TEST_F(FormatTest, BracedInitializerIndentWidth) { verifyFormat("SomeStruct s{\n" " .foo = \"xxxxxxxxxxxxx\",\n" " .bar = \"yyyyyyyyyyyyy\",\n" - " .baz = \"zzzzzzzzzzzzz\"};\n", + " .baz = \"zzzzzzzzzzzzz\"};", Style); // List initialization. verifyFormat("SomeStruct s{\n" " \"xxxxxxxxxxxxx\",\n" " \"yyyyyyyyyyyyy\",\n" " \"zzzzzzzzzzzzz\",\n" - "};\n", + "};", Style); verifyFormat("SomeStruct{\n" " \"xxxxxxxxxxxxx\",\n" " \"yyyyyyyyyyyyy\",\n" " \"zzzzzzzzzzzzz\",\n" - "};\n", + "};", Style); verifyFormat("new SomeStruct{\n" " \"xxxxxxxxxxxxx\",\n" " \"yyyyyyyyyyyyy\",\n" " \"zzzzzzzzzzzzz\",\n" - "};\n", + "};", Style); // Member initializer. verifyFormat("class SomeClass {\n" @@ -5035,61 +5035,61 @@ TEST_F(FormatTest, BracedInitializerIndentWidth) { " \"yyyyyyyyyyyyy\",\n" " \"zzzzzzzzzzzzz\",\n" " };\n" - "};\n", + "};", Style); // Constructor member initializer. verifyFormat("SomeClass::SomeClass : strct{\n" " \"xxxxxxxxxxxxx\",\n" " \"yyyyyyyyyyyyy\",\n" " \"zzzzzzzzzzzzz\",\n" - " } {}\n", + " } {}", Style); // Copy initialization. verifyFormat("SomeStruct s = SomeStruct{\n" " \"xxxxxxxxxxxxx\",\n" " \"yyyyyyyyyyyyy\",\n" " \"zzzzzzzzzzzzz\",\n" - "};\n", + "};", Style); // Copy list initialization. verifyFormat("SomeStruct s = {\n" " \"xxxxxxxxxxxxx\",\n" " \"yyyyyyyyyyyyy\",\n" " \"zzzzzzzzzzzzz\",\n" - "};\n", + "};", Style); // Assignment operand initialization. verifyFormat("s = {\n" " \"xxxxxxxxxxxxx\",\n" " \"yyyyyyyyyyyyy\",\n" " \"zzzzzzzzzzzzz\",\n" - "};\n", + "};", Style); // Returned object initialization. verifyFormat("return {\n" " \"xxxxxxxxxxxxx\",\n" " \"yyyyyyyyyyyyy\",\n" " \"zzzzzzzzzzzzz\",\n" - "};\n", + "};", Style); // Initializer list. verifyFormat("auto initializerList = {\n" " \"xxxxxxxxxxxxx\",\n" " \"yyyyyyyyyyyyy\",\n" " \"zzzzzzzzzzzzz\",\n" - "};\n", + "};", Style); // Function parameter initialization. verifyFormat("func({\n" " \"xxxxxxxxxxxxx\",\n" " \"yyyyyyyyyyyyy\",\n" " \"zzzzzzzzzzzzz\",\n" - "});\n", + "});", Style); // Nested init lists. verifyFormat("SomeStruct s = {\n" " {{init1, init2, init3, init4, init5},\n" - " {init1, init2, init3, init4, init5}}};\n", + " {init1, init2, init3, init4, init5}}};", Style); verifyFormat("SomeStruct s = {\n" " {{\n" @@ -5099,7 +5099,7 @@ TEST_F(FormatTest, BracedInitializerIndentWidth) { " .init4 = 4,\n" " .init5 = 5,\n" " },\n" - " {init1, init2, init3, init4, init5}}};\n", + " {init1, init2, init3, init4, init5}}};", Style); verifyFormat("SomeArrayT a[3] = {\n" " {\n" @@ -5134,12 +5134,12 @@ TEST_F(FormatTest, BracedInitializerIndentWidth) { // Aligning after open braces unaffected by BracedInitializerIndentWidth. Style.AlignAfterOpenBracket = FormatStyle::BAS_Align; verifyFormat("SomeStruct s{\"xxxxxxxxxxxxx\", \"yyyyyyyyyyyyy\",\n" - " \"zzzzzzzzzzzzz\"};\n", + " \"zzzzzzzzzzzzz\"};", Style); } TEST_F(FormatTest, NestedStaticInitializers) { - verifyFormat("static A x = {{{}}};\n"); + verifyFormat("static A x = {{{}}};"); verifyFormat("static A x = {{{init1, init2, init3, init4},\n" " {init1, init2, init3, init4}}};", getLLVMStyleWithColumns(50)); @@ -5234,10 +5234,10 @@ TEST_F(FormatTest, LayoutUnknownPPDirective) { } 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("#line 42 \"test\"", + format("# \\\n line \\\n 42 \\\n \"test\"")); + EXPECT_EQ("#define A B", format("# \\\n define \\\n A \\\n B", + getLLVMStyleWithColumns(12))); } TEST_F(FormatTest, EndOfFileEndsPPDirective) { @@ -5278,7 +5278,7 @@ TEST_F(FormatTest, IndentsPPDirectiveWithPPIndentWidth) { "#endif\n" "void bar() {\n" " int y = 0;\n" - "}\n", + "}", style); style.IndentPPDirectives = FormatStyle::PPDIS_AfterHash; @@ -5290,7 +5290,7 @@ TEST_F(FormatTest, IndentsPPDirectiveWithPPIndentWidth) { "#endif\n" "void bar() {\n" " int y = 0;\n" - "}\n", + "}", style); style.IndentPPDirectives = FormatStyle::PPDIS_BeforeHash; @@ -5302,7 +5302,7 @@ TEST_F(FormatTest, IndentsPPDirectiveWithPPIndentWidth) { "#endif\n" "void bar() {\n" " int y = 0;\n" - "}\n", + "}", style); verifyFormat("#if 1\n" " // some comments\n" @@ -5552,13 +5552,13 @@ TEST_F(FormatTest, HandlePreprocessorDirectiveContext) { "#define A( \\\n" " A, B)\n" "#include \"b.h\"\n" - "// somecomment\n", + "// somecomment", format(" // somecomment\n" " #include \"a.h\"\n" "#define A(A,\\\n" " B)\n" " #include \"b.h\"\n" - " // somecomment\n", + " // somecomment", getLLVMStyleWithColumns(13))); } @@ -5650,7 +5650,7 @@ TEST_F(FormatTest, MacroDefinitionsWithIncompleteCode) { verifyIncompleteFormat("#define A :"); verifyFormat("#define SOMECASES \\\n" " case 1: \\\n" - " case 2\n", + " case 2", getLLVMStyleWithColumns(20)); verifyFormat("#define MACRO(a) \\\n" " if (a) \\\n" @@ -5755,7 +5755,7 @@ TEST_F(FormatTest, MacrosWithoutTrailingSemicolon) { "<< SomeThing;")); verifyFormat("VISIT_GL_CALL(GenBuffers, void, (GLsizei n, GLuint* buffers), " - "(n, buffers))\n", + "(n, buffers))", getChromiumStyle(FormatStyle::LK_Cpp)); // See PR41483 @@ -5823,7 +5823,7 @@ TEST_F(FormatTest, MacroCallsWithoutTrailingSemicolon) { " f(x)[y].z();\n" " LOG(INFO) << x;\n" " ifstream(x) >> x;\n" - "}\n", + "}", format("int q() {\n" " f(x)\n;\n" " f(x)\n {}\n" @@ -5844,7 +5844,7 @@ TEST_F(FormatTest, MacroCallsWithoutTrailingSemicolon) { " f(x)\n[y].z();\n" " LOG(INFO)\n << x;\n" " ifstream(x)\n >> x;\n" - "}\n")); + "}")); EXPECT_EQ("int q() {\n" " F(x)\n" " if (1) {\n" @@ -5859,7 +5859,7 @@ TEST_F(FormatTest, MacroCallsWithoutTrailingSemicolon) { " Q();\n" " } catch (...) {\n" " }\n" - "}\n", + "}", format("int q() {\n" "F(x)\n" "if (1) {}\n" @@ -5869,7 +5869,7 @@ TEST_F(FormatTest, MacroCallsWithoutTrailingSemicolon) { "G(x);\n" "F(x)\n" "try { Q(); } catch (...) {}\n" - "}\n")); + "}")); EXPECT_EQ("class A {\n" " A() : t(0) {}\n" " A(int i) noexcept() : {}\n" @@ -6056,7 +6056,7 @@ TEST_F(FormatTest, IndentPreprocessorDirectives) { verifyFormat("#ifndef HEADER_H\n" "#define HEADER_H\n" "code();\n" - "#endif\n", + "#endif", Style); // Include guards don't have #else. verifyFormat("#ifndef NOT_GUARD\n" @@ -6074,7 +6074,7 @@ TEST_F(FormatTest, IndentPreprocessorDirectives) { // Non-identifier #define after potential include guard. verifyFormat("#ifndef FOO\n" "# define 1\n" - "#endif\n", + "#endif", Style); // #if closes past last non-preprocessor line. verifyFormat("#ifndef FOO\n" @@ -6083,7 +6083,7 @@ TEST_F(FormatTest, IndentPreprocessorDirectives) { "int i;\n" "# define A 0\n" "#endif\n" - "#endif\n", + "#endif", Style); // Don't crash if there is an #elif directive without a condition. verifyFormat("#if 1\n" @@ -6508,10 +6508,10 @@ TEST_F(FormatTest, EscapedNewlines) { AlignLeft.AlignEscapedNewlines = FormatStyle::ENAS_Left; EXPECT_EQ("#define MACRO(x) \\\n" "private: \\\n" - " int x(int a);\n", + " int x(int a);", format("#define MACRO(x) \\\n" "private: \\\n" - " int x(int a);\n", + " int x(int a);", AlignLeft)); // CRLF line endings @@ -6523,10 +6523,10 @@ TEST_F(FormatTest, EscapedNewlines) { verifyNoChange(""); EXPECT_EQ("#define MACRO(x) \\\r\n" "private: \\\r\n" - " int x(int a);\r\n", + " int x(int a);", format("#define MACRO(x) \\\r\n" "private: \\\r\n" - " int x(int a);\r\n", + " int x(int a);", AlignLeft)); FormatStyle DontAlign = getLLVMStyle(); @@ -6570,13 +6570,13 @@ TEST_F(FormatTest, MixingPreprocessorDirectivesAndNormalCode) { " aLoooooooooooooooooooooooongFuuuuuuuuuuuuuunctiooooooooo)\n" "\n" "AlooooooooooooooooooooooooooooooooooooooongCaaaaaaaaaal(\n" - " aLooooooooooooooooooooooonPaaaaaaaaaaaaaaaaaaaaarmmmm);\n", + " aLooooooooooooooooooooooonPaaaaaaaaaaaaaaaaaaaaarmmmm);", format(" #define ALooooooooooooooooooooooooooooooooooooooongMacro(" "\\\n" "aLoooooooooooooooooooooooongFuuuuuuuuuuuuuunctiooooooooo)\n" " \n" " AlooooooooooooooooooooooooooooooooooooooongCaaaaaaaaaal(\n" - " aLooooooooooooooooooooooonPaaaaaaaaaaaaaaaaaaaaarmmmm);\n")); + " aLooooooooooooooooooooooonPaaaaaaaaaaaaaaaaaaaaarmmmm);")); } TEST_F(FormatTest, LayoutStatementsAroundPreprocessorDirectives) { @@ -6638,7 +6638,7 @@ TEST_F(FormatTest, LayoutStatementsAroundPreprocessorDirectives) { "#endif\n" "#if 1\n" "#else\n" - "#endif\n"); + "#endif"); verifyFormat("DEBUG({\n" " return aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +\n" " aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa;\n" @@ -7329,7 +7329,7 @@ TEST_F(FormatTest, NoOperandAlignment) { Style); verifyFormat("int a = aa\n" " + bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\n" - " * cccccccccccccccccccccccccccccccccccc;\n", + " * cccccccccccccccccccccccccccccccccccc;", Style); Style.AlignAfterOpenBracket = FormatStyle::BAS_DontAlign; @@ -8361,10 +8361,10 @@ TEST_F(FormatTest, DontBreakBeforeQualifiedOperator) { } TEST_F(FormatTest, TrailingReturnType) { - verifyFormat("auto foo() -> int;\n"); + verifyFormat("auto foo() -> int;"); // correct trailing return type spacing - verifyFormat("auto operator->() -> int;\n"); - verifyFormat("auto operator++(int) -> int;\n"); + verifyFormat("auto operator->() -> int;"); + verifyFormat("auto operator++(int) -> int;"); verifyFormat("struct S {\n" " auto bar() const -> int;\n" @@ -8748,7 +8748,7 @@ TEST_F(FormatTest, FormatsBuilderPattern) { " .StartsWith(\".init\", ORDER_INIT)\n" " .StartsWith(\".fini\", ORDER_FINI)\n" " .StartsWith(\".hash\", ORDER_HASH)\n" - " .Default(ORDER_TEXT);\n"); + " .Default(ORDER_TEXT);"); verifyFormat("return aaaaaaaaaaaaaaaaa->aaaaa().aaaaaaaaaaaaa().aaaaaa() <\n" " aaaaaaaaaaaaaaa->aaaaa().aaaaaaaaaaaaa().aaaaaa();"); @@ -8931,7 +8931,7 @@ TEST_F(FormatTest, BreaksAfterAssignments) { verifyFormat( "unsigned Cost =\n" " TTI.getMemoryOpCost(I->getOpcode(), VectorTy, SI->getAlignment(),\n" - " SI->getPointerAddressSpaceee());\n"); + " SI->getPointerAddressSpaceee());"); verifyFormat( "CharSourceRange LineRange = CharSourceRange::getTokenRange(\n" " Line.Tokens.front().Tok.getLo(), Line.Tokens.back().Tok.getLoc());"); @@ -9274,7 +9274,7 @@ TEST_F(FormatTest, BreaksConditionalExpressions) { " // comment\n" " ? a = b\n" " : a\n" - " : a;\n"); + " : a;"); verifyFormat("return a != b\n" " // comment\n" " ? a\n" @@ -9343,7 +9343,7 @@ TEST_F(FormatTest, BreaksConditionalExpressions) { "return aaaaaaaaa ? 1111111111111111\n" " : bbbbbbbbbbbbbb ? 2222222222222222\n" " : a + (aaaaaaaaaaaaa ? bbbbbbbbbbbbbbbbbb\n" - " : dddddddddddddddddd)\n", + " : dddddddddddddddddd)", Style); verifyFormat( "return aaaaaaaaaaaaaaaa ? 1111111111111111\n" @@ -9408,7 +9408,7 @@ TEST_F(FormatTest, BreaksConditionalExpressions) { // unnecessary. verifyFormat("int x = aaaaaaaaaaaaaaa ? aaaaaaaaaaaaaaaaaa :\n" " bbbb ? cccccccccccccccccc :\n" - " ddddd;\n", + " ddddd;", Style); EXPECT_EQ( @@ -9597,7 +9597,7 @@ TEST_F(FormatTest, BreaksConditionalExpressionsAfterOperator) { "return aaaaaaaaa ? 1111111111111111 :\n" " bbbbbbbbbbbbbbbb ? 2222222222222222 :\n" " a + (aaaaaaaaaaaaa ? bbbbbbbbbbbbbbbbbb :\n" - " dddddddddddddddddd)\n", + " dddddddddddddddddd)", Style); verifyFormat( "return aaaaaaaaaaaaaaaa ? 1111111111111111 :\n" @@ -9780,7 +9780,7 @@ TEST_F(FormatTest, ReturnTypeBreakingStyle) { " int g();\n" "};\n" "int f() { return 1; }\n" - "int g();\n", + "int g();", Style); // All declarations and definitions should have the return type moved to its @@ -9803,7 +9803,7 @@ TEST_F(FormatTest, ReturnTypeBreakingStyle) { " return 1;\n" "}\n" "int\n" - "g();\n", + "g();", Style); // Top-level definitions, and no kinds of declarations should have the @@ -9817,7 +9817,7 @@ TEST_F(FormatTest, ReturnTypeBreakingStyle) { "f() {\n" " return 1;\n" "}\n" - "int g();\n", + "int g();", Style); // Top-level definitions and declarations should have the return type moved @@ -9832,7 +9832,7 @@ TEST_F(FormatTest, ReturnTypeBreakingStyle) { " return 1;\n" "}\n" "int\n" - "g();\n", + "g();", Style); // All definitions should have the return type moved to its own line, but no @@ -9849,20 +9849,20 @@ TEST_F(FormatTest, ReturnTypeBreakingStyle) { "f() {\n" " return 1;\n" "}\n" - "int g();\n", + "int g();", Style); verifyFormat("const char *\n" "f(void) {\n" // Break here. " return \"\";\n" "}\n" - "const char *bar(void);\n", // No break here. + "const char *bar(void);", // No break here. Style); verifyFormat("template \n" "T *\n" "f(T &c) {\n" // Break here. " return NULL;\n" "}\n" - "template T *f(T &c);\n", // No break here. + "template T *f(T &c);", // No break here. Style); verifyFormat("class C {\n" " int\n" @@ -9873,7 +9873,7 @@ TEST_F(FormatTest, ReturnTypeBreakingStyle) { " operator()() {\n" " return 1;\n" " }\n" - "};\n", + "};", Style); verifyFormat("void\n" "A::operator()() {}\n" @@ -9906,7 +9906,7 @@ TEST_F(FormatTest, ReturnTypeBreakingStyle) { "void\n" "A::operator &() {}\n" "void\n" - "A::operator void **() {}\n", + "A::operator void **() {}", Style); verifyFormat("constexpr auto\n" "operator()() const -> reference {}\n" @@ -9935,7 +9935,7 @@ TEST_F(FormatTest, ReturnTypeBreakingStyle) { "constexpr auto\n" "operator!() const -> reference {}\n" "constexpr auto\n" - "operator[]() const -> reference {}\n", + "operator[]() const -> reference {}", Style); verifyFormat("void *operator new(std::size_t s);", // No break here. Style); @@ -9951,7 +9951,7 @@ TEST_F(FormatTest, ReturnTypeBreakingStyle) { "{\n" " return \"\";\n" "}\n" - "const char *bar(void);\n", // No break here. + "const char *bar(void);", // No break here. Style); verifyFormat("template \n" "T *\n" // Problem here: no line break @@ -9959,43 +9959,43 @@ TEST_F(FormatTest, ReturnTypeBreakingStyle) { "{\n" " return NULL;\n" "}\n" - "template T *f(T &c);\n", // No break here. + "template T *f(T &c);", // No break here. Style); verifyFormat("int\n" "foo(A a)\n" "{\n" " return a;\n" - "}\n", + "}", Style); verifyFormat("int\n" "foo(A<8> a)\n" "{\n" " return a;\n" - "}\n", + "}", Style); verifyFormat("int\n" "foo(A, 8> a)\n" "{\n" " return a;\n" - "}\n", + "}", Style); verifyFormat("int\n" "foo(A, bool> a)\n" "{\n" " return a;\n" - "}\n", + "}", Style); verifyFormat("int\n" "foo(A, bool> a)\n" "{\n" " return a;\n" - "}\n", + "}", Style); verifyFormat("int\n" "foo(A, 8> a)\n" "{\n" " return a;\n" - "}\n", + "}", Style); Style.BreakBeforeBraces = FormatStyle::BS_Custom; @@ -10087,19 +10087,19 @@ TEST_F(FormatTest, ReturnTypeBreakingStyle) { verifyFormat("void\n" "foo (int a, /*abc*/ int b) // def\n" "{\n" - "}\n", + "}", Style); verifyFormat("void\n" "foo (int a, /* abc */ int b) /* def */\n" "{\n" - "}\n", + "}", Style); // Definitions that should not break after return type - verifyFormat("void foo (int a, int b); // def\n", Style); - verifyFormat("void foo (int a, int b); /* def */\n", Style); - verifyFormat("void foo (int a, int b);\n", Style); + verifyFormat("void foo (int a, int b); // def", Style); + verifyFormat("void foo (int a, int b); /* def */", Style); + verifyFormat("void foo (int a, int b);", Style); } TEST_F(FormatTest, AlwaysBreakBeforeMultilineStrings) { @@ -10403,7 +10403,7 @@ TEST_F(FormatTest, WrapsAtFunctionCallsIfNecessary) { verifyFormat( "aaaaaaaaaaa->aaaaaaaaa(\n" " aaaaaaaaaaaaaaaaaaaaaaaaa,\n" - " aaaaaaaaaaaaaaaaaa->aaaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaa));\n"); + " aaaaaaaaaaaaaaaaaa->aaaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaa));"); verifyFormat( "aaaaaaaaaaaaaaaaaaaaaaaaa(\n" @@ -11251,9 +11251,9 @@ TEST_F(FormatTest, UnderstandsNewAndDelete) { verifyFormat("void operator delete(void *ptr) noexcept;"); EXPECT_EQ("void new(link p);\n" - "void delete(link p);\n", + "void delete(link p);", format("void new (link p);\n" - "void delete (link p);\n")); + "void delete (link p);")); } TEST_F(FormatTest, UnderstandsUsesOfStarAndAmp) { @@ -11712,7 +11712,7 @@ TEST_F(FormatTest, UnderstandsAttributes) { FormatStyle AfterType = getLLVMStyle(); AfterType.AlwaysBreakAfterReturnType = FormatStyle::RTBS_All; verifyFormat("__attribute__((nodebug)) void\n" - "foo() {}\n", + "foo() {}", AfterType); verifyFormat("__unused void\n" "foo() {}", @@ -11816,7 +11816,7 @@ TEST_F(FormatTest, UnderstandsSquareAttributes) { // Make sure we do not mistake attributes for array subscripts. verifyFormat("int a() {}\n" - "[[unused]] int b() {}\n"); + "[[unused]] int b() {}"); verifyFormat("NSArray *arr;\n" "arr[[Foo() bar]];"); @@ -11836,7 +11836,7 @@ TEST_F(FormatTest, UnderstandsSquareAttributes) { MultiLineFunctions.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_None; verifyFormat("[[unused]] int b() {\n" " return 42;\n" - "}\n", + "}", MultiLineFunctions); } @@ -12300,7 +12300,7 @@ TEST_F(FormatTest, FormatsAccessModifiers) { "\n" "protected:\n" " int j;\n" - "};\n", + "};", Style); verifyFormat("struct foo {\n" "private:\n" @@ -12311,7 +12311,7 @@ TEST_F(FormatTest, FormatsAccessModifiers) { "\n" "protected:\n" " int j;\n" - "};\n", + "};", "struct foo {\n" "private:\n" " void f() {}\n" @@ -12319,7 +12319,7 @@ TEST_F(FormatTest, FormatsAccessModifiers) { " int i;\n" "protected:\n" " int j;\n" - "};\n", + "};", Style); verifyFormat("struct foo { /* comment */\n" "private:\n" @@ -12327,7 +12327,7 @@ TEST_F(FormatTest, FormatsAccessModifiers) { " // comment\n" "private:\n" " int j;\n" - "};\n", + "};", Style); verifyFormat("struct foo {\n" "#ifdef FOO\n" @@ -12338,7 +12338,7 @@ TEST_F(FormatTest, FormatsAccessModifiers) { "private:\n" "#endif\n" " int j;\n" - "};\n", + "};", Style); Style.EmptyLineBeforeAccessModifier = FormatStyle::ELBAMS_Never; verifyFormat("struct foo {\n" @@ -12348,7 +12348,7 @@ TEST_F(FormatTest, FormatsAccessModifiers) { " int i;\n" "protected:\n" " int j;\n" - "};\n", + "};", Style); verifyFormat("struct foo {\n" "private:\n" @@ -12357,7 +12357,7 @@ TEST_F(FormatTest, FormatsAccessModifiers) { " int i;\n" "protected:\n" " int j;\n" - "};\n", + "};", "struct foo {\n" "\n" "private:\n" @@ -12368,7 +12368,7 @@ TEST_F(FormatTest, FormatsAccessModifiers) { "\n" "protected:\n" " int j;\n" - "};\n", + "};", Style); verifyFormat("struct foo { /* comment */\n" "private:\n" @@ -12376,7 +12376,7 @@ TEST_F(FormatTest, FormatsAccessModifiers) { " // comment\n" "private:\n" " int j;\n" - "};\n", + "};", "struct foo { /* comment */\n" "\n" "private:\n" @@ -12385,7 +12385,7 @@ TEST_F(FormatTest, FormatsAccessModifiers) { "\n" "private:\n" " int j;\n" - "};\n", + "};", Style); verifyFormat("struct foo {\n" "#ifdef FOO\n" @@ -12396,7 +12396,7 @@ TEST_F(FormatTest, FormatsAccessModifiers) { "private:\n" "#endif\n" " int j;\n" - "};\n", + "};", "struct foo {\n" "#ifdef FOO\n" "#endif\n" @@ -12408,7 +12408,7 @@ TEST_F(FormatTest, FormatsAccessModifiers) { "private:\n" "#endif\n" " int j;\n" - "};\n", + "};", Style); Style.EmptyLineBeforeAccessModifier = FormatStyle::ELBAMS_Always; verifyFormat("struct foo {\n" @@ -12420,7 +12420,7 @@ TEST_F(FormatTest, FormatsAccessModifiers) { "\n" "protected:\n" " int j;\n" - "};\n", + "};", Style); verifyFormat("struct foo {\n" "private:\n" @@ -12431,7 +12431,7 @@ TEST_F(FormatTest, FormatsAccessModifiers) { "\n" "protected:\n" " int j;\n" - "};\n", + "};", "struct foo {\n" "private:\n" " void f() {}\n" @@ -12439,7 +12439,7 @@ TEST_F(FormatTest, FormatsAccessModifiers) { " int i;\n" "protected:\n" " int j;\n" - "};\n", + "};", Style); verifyFormat("struct foo { /* comment */\n" "private:\n" @@ -12448,7 +12448,7 @@ TEST_F(FormatTest, FormatsAccessModifiers) { "\n" "private:\n" " int j;\n" - "};\n", + "};", Style); verifyFormat("struct foo {\n" "#ifdef FOO\n" @@ -12461,7 +12461,7 @@ TEST_F(FormatTest, FormatsAccessModifiers) { "private:\n" "#endif\n" " int j;\n" - "};\n", + "};", "struct foo {\n" "#ifdef FOO\n" "#endif\n" @@ -12471,7 +12471,7 @@ TEST_F(FormatTest, FormatsAccessModifiers) { "private:\n" "#endif\n" " int j;\n" - "};\n", + "};", Style); Style.EmptyLineBeforeAccessModifier = FormatStyle::ELBAMS_Leave; EXPECT_EQ("struct foo {\n" @@ -12484,7 +12484,7 @@ TEST_F(FormatTest, FormatsAccessModifiers) { "\n" "protected:\n" " int j;\n" - "};\n", + "};", format("struct foo {\n" "\n" "private:\n" @@ -12495,7 +12495,7 @@ TEST_F(FormatTest, FormatsAccessModifiers) { "\n" "protected:\n" " int j;\n" - "};\n", + "};", Style)); verifyFormat("struct foo {\n" "private:\n" @@ -12504,7 +12504,7 @@ TEST_F(FormatTest, FormatsAccessModifiers) { " int i;\n" "protected:\n" " int j;\n" - "};\n", + "};", Style); EXPECT_EQ("struct foo { /* comment */\n" "\n" @@ -12514,7 +12514,7 @@ TEST_F(FormatTest, FormatsAccessModifiers) { "\n" "private:\n" " int j;\n" - "};\n", + "};", format("struct foo { /* comment */\n" "\n" "private:\n" @@ -12523,7 +12523,7 @@ TEST_F(FormatTest, FormatsAccessModifiers) { "\n" "private:\n" " int j;\n" - "};\n", + "};", Style)); verifyFormat("struct foo { /* comment */\n" "private:\n" @@ -12531,7 +12531,7 @@ TEST_F(FormatTest, FormatsAccessModifiers) { " // comment\n" "private:\n" " int j;\n" - "};\n", + "};", Style); EXPECT_EQ("struct foo {\n" "#ifdef FOO\n" @@ -12544,7 +12544,7 @@ TEST_F(FormatTest, FormatsAccessModifiers) { "private:\n" "#endif\n" " int j;\n" - "};\n", + "};", format("struct foo {\n" "#ifdef FOO\n" "#endif\n" @@ -12556,7 +12556,7 @@ TEST_F(FormatTest, FormatsAccessModifiers) { "private:\n" "#endif\n" " int j;\n" - "};\n", + "};", Style)); verifyFormat("struct foo {\n" "#ifdef FOO\n" @@ -12567,7 +12567,7 @@ TEST_F(FormatTest, FormatsAccessModifiers) { "private:\n" "#endif\n" " int j;\n" - "};\n", + "};", Style); FormatStyle NoEmptyLines = getLLVMStyle(); @@ -12582,7 +12582,7 @@ TEST_F(FormatTest, FormatsAccessModifiers) { "public:\n" "protected:\n" " int j;\n" - "};\n", + "};", NoEmptyLines); NoEmptyLines.EmptyLineBeforeAccessModifier = FormatStyle::ELBAMS_Never; @@ -12594,7 +12594,7 @@ TEST_F(FormatTest, FormatsAccessModifiers) { "public:\n" "protected:\n" " int j;\n" - "};\n", + "};", NoEmptyLines); NoEmptyLines.EmptyLineBeforeAccessModifier = FormatStyle::ELBAMS_Always; @@ -12609,7 +12609,7 @@ TEST_F(FormatTest, FormatsAccessModifiers) { "\n" "protected:\n" " int j;\n" - "};\n", + "};", NoEmptyLines); } @@ -12626,7 +12626,7 @@ TEST_F(FormatTest, FormatsAfterAccessModifiers) { "\n" "protected:\n" " int j;\n" - "};\n", + "};", Style); // Check if lines are removed. @@ -12639,7 +12639,7 @@ TEST_F(FormatTest, FormatsAfterAccessModifiers) { "\n" "protected:\n" " int j;\n" - "};\n", + "};", "struct foo {\n" "private:\n" "\n" @@ -12652,7 +12652,7 @@ TEST_F(FormatTest, FormatsAfterAccessModifiers) { "protected:\n" "\n" " int j;\n" - "};\n", + "};", Style); Style.EmptyLineAfterAccessModifier = FormatStyle::ELAAMS_Always; @@ -12668,7 +12668,7 @@ TEST_F(FormatTest, FormatsAfterAccessModifiers) { "protected:\n" "\n" " int j;\n" - "};\n", + "};", Style); // Check if lines are added. @@ -12684,7 +12684,7 @@ TEST_F(FormatTest, FormatsAfterAccessModifiers) { "protected:\n" "\n" " int j;\n" - "};\n", + "};", "struct foo {\n" "private:\n" " void f() {}\n" @@ -12694,7 +12694,7 @@ TEST_F(FormatTest, FormatsAfterAccessModifiers) { "\n" "protected:\n" " int j;\n" - "};\n", + "};", Style); // Leave tests rely on the code layout, test::messUp can not be used. @@ -12709,7 +12709,7 @@ TEST_F(FormatTest, FormatsAfterAccessModifiers) { "\n" "protected:\n" " int j;\n" - "};\n", + "};", Style); // Check if MaxEmptyLinesToKeep is respected. @@ -12722,7 +12722,7 @@ TEST_F(FormatTest, FormatsAfterAccessModifiers) { "\n" "protected:\n" " int j;\n" - "};\n", + "};", format("struct foo {\n" "private:\n" "\n\n\n" @@ -12735,7 +12735,7 @@ TEST_F(FormatTest, FormatsAfterAccessModifiers) { "protected:\n" "\n\n\n" " int j;\n" - "};\n", + "};", Style)); Style.MaxEmptyLinesToKeep = 1u; @@ -12751,7 +12751,7 @@ TEST_F(FormatTest, FormatsAfterAccessModifiers) { "protected:\n" "\n" " int j;\n" - "};\n", + "};", format("struct foo {\n" "private:\n" "\n" @@ -12764,7 +12764,7 @@ TEST_F(FormatTest, FormatsAfterAccessModifiers) { "protected:\n" "\n" " int j;\n" - "};\n", + "};", Style)); // Check if no lines are kept. EXPECT_EQ("struct foo {\n" @@ -12776,7 +12776,7 @@ TEST_F(FormatTest, FormatsAfterAccessModifiers) { "\n" "protected:\n" " int j;\n" - "};\n", + "};", format("struct foo {\n" "private:\n" " void f() {}\n" @@ -12786,7 +12786,7 @@ TEST_F(FormatTest, FormatsAfterAccessModifiers) { "\n" "protected:\n" " int j;\n" - "};\n", + "};", Style)); // Check if MaxEmptyLinesToKeep is respected. EXPECT_EQ("struct foo {\n" @@ -12801,7 +12801,7 @@ TEST_F(FormatTest, FormatsAfterAccessModifiers) { "protected:\n" "\n" " int j;\n" - "};\n", + "};", format("struct foo {\n" "private:\n" "\n\n\n" @@ -12814,7 +12814,7 @@ TEST_F(FormatTest, FormatsAfterAccessModifiers) { "protected:\n" "\n\n\n" " int j;\n" - "};\n", + "};", Style)); Style.MaxEmptyLinesToKeep = 10u; @@ -12830,7 +12830,7 @@ TEST_F(FormatTest, FormatsAfterAccessModifiers) { "protected:\n" "\n\n\n" " int j;\n" - "};\n", + "};", format("struct foo {\n" "private:\n" "\n\n\n" @@ -12843,7 +12843,7 @@ TEST_F(FormatTest, FormatsAfterAccessModifiers) { "protected:\n" "\n\n\n" " int j;\n" - "};\n", + "};", Style)); // Test with comments. @@ -12855,7 +12855,7 @@ TEST_F(FormatTest, FormatsAfterAccessModifiers) { "\n" "private: /* comment */\n" " int i;\n" - "};\n", + "};", Style); verifyFormat("struct foo {\n" "private:\n" @@ -12864,7 +12864,7 @@ TEST_F(FormatTest, FormatsAfterAccessModifiers) { "\n" "private: /* comment */\n" " int i;\n" - "};\n", + "};", "struct foo {\n" "private:\n" "\n" @@ -12874,7 +12874,7 @@ TEST_F(FormatTest, FormatsAfterAccessModifiers) { "private: /* comment */\n" "\n" " int i;\n" - "};\n", + "};", Style); Style.EmptyLineAfterAccessModifier = FormatStyle::ELAAMS_Always; @@ -12887,7 +12887,7 @@ TEST_F(FormatTest, FormatsAfterAccessModifiers) { "private: /* comment */\n" "\n" " int i;\n" - "};\n", + "};", "struct foo {\n" "private:\n" " // comment\n" @@ -12895,7 +12895,7 @@ TEST_F(FormatTest, FormatsAfterAccessModifiers) { "\n" "private: /* comment */\n" " int i;\n" - "};\n", + "};", Style); verifyFormat("struct foo {\n" "private:\n" @@ -12906,7 +12906,7 @@ TEST_F(FormatTest, FormatsAfterAccessModifiers) { "private: /* comment */\n" "\n" " int i;\n" - "};\n", + "};", Style); // Test with preprocessor defines. @@ -12916,21 +12916,21 @@ TEST_F(FormatTest, FormatsAfterAccessModifiers) { "#ifdef FOO\n" "#endif\n" " void f() {}\n" - "};\n", + "};", Style); verifyFormat("struct foo {\n" "private:\n" "#ifdef FOO\n" "#endif\n" " void f() {}\n" - "};\n", + "};", "struct foo {\n" "private:\n" "\n" "#ifdef FOO\n" "#endif\n" " void f() {}\n" - "};\n", + "};", Style); verifyNoChange("struct foo {\n" "#ifdef FOO\n" @@ -12998,13 +12998,13 @@ TEST_F(FormatTest, FormatsAfterAccessModifiers) { "#ifdef FOO\n" "#endif\n" " void f() {}\n" - "};\n", + "};", "struct foo {\n" "private:\n" "#ifdef FOO\n" "#endif\n" " void f() {}\n" - "};\n", + "};", Style); verifyFormat("struct foo {\n" "private:\n" @@ -13012,7 +13012,7 @@ TEST_F(FormatTest, FormatsAfterAccessModifiers) { "#ifdef FOO\n" "#endif\n" " void f() {}\n" - "};\n", + "};", Style); } @@ -13026,7 +13026,7 @@ TEST_F(FormatTest, FormatsAfterAndBeforeAccessModifiersInteraction) { "private:\n" "\n" "protected:\n" - "};\n", + "};", Style); Style.MaxEmptyLinesToKeep = 10u; @@ -13036,12 +13036,12 @@ TEST_F(FormatTest, FormatsAfterAndBeforeAccessModifiersInteraction) { verifyFormat("struct foo {\n" "private:\n" "protected:\n" - "};\n", + "};", "struct foo {\n" "private:\n" "\n\n\n" "protected:\n" - "};\n", + "};", Style); // Leave tests rely on the code layout, test::messUp can not be used. @@ -13052,36 +13052,36 @@ TEST_F(FormatTest, FormatsAfterAndBeforeAccessModifiersInteraction) { "private:\n" "\n\n\n" "protected:\n" - "};\n", + "};", format("struct foo {\n" "private:\n" "\n\n\n" "protected:\n" - "};\n", + "};", Style)); Style.MaxEmptyLinesToKeep = 3u; EXPECT_EQ("struct foo {\n" "private:\n" "\n\n\n" "protected:\n" - "};\n", + "};", format("struct foo {\n" "private:\n" "\n\n\n" "protected:\n" - "};\n", + "};", Style)); Style.MaxEmptyLinesToKeep = 1u; EXPECT_EQ("struct foo {\n" "private:\n" "\n\n\n" "protected:\n" - "};\n", + "};", format("struct foo {\n" "private:\n" "\n\n\n" "protected:\n" - "};\n", + "};", Style)); // Based on new lines in original document and not // on the setting. @@ -13094,12 +13094,12 @@ TEST_F(FormatTest, FormatsAfterAndBeforeAccessModifiersInteraction) { "private:\n" "\n\n\n" "protected:\n" - "};\n", + "};", format("struct foo {\n" "private:\n" "\n\n\n" "protected:\n" - "};\n", + "};", Style)); Style.EmptyLineBeforeAccessModifier = FormatStyle::ELBAMS_Leave; @@ -13109,12 +13109,12 @@ TEST_F(FormatTest, FormatsAfterAndBeforeAccessModifiersInteraction) { "private:\n" "\n\n\n" "protected:\n" - "};\n", + "};", format("struct foo {\n" "private:\n" "\n\n\n" "protected:\n" - "};\n", + "};", Style)); Style.EmptyLineBeforeAccessModifier = FormatStyle::ELBAMS_Leave; @@ -13123,12 +13123,12 @@ TEST_F(FormatTest, FormatsAfterAndBeforeAccessModifiersInteraction) { "private:\n" "\n\n\n" "protected:\n" - "};\n", + "};", format("struct foo {\n" "private:\n" "\n\n\n" "protected:\n" - "};\n", + "};", Style)); // test::messUp removes all new lines which changes // the logic. @@ -13137,12 +13137,12 @@ TEST_F(FormatTest, FormatsAfterAndBeforeAccessModifiersInteraction) { verifyFormat("struct foo {\n" "private:\n" "protected:\n" - "};\n", + "};", "struct foo {\n" "private:\n" "\n\n\n" "protected:\n" - "};\n", + "};", Style); Style.EmptyLineBeforeAccessModifier = FormatStyle::ELBAMS_Always; @@ -13151,12 +13151,12 @@ TEST_F(FormatTest, FormatsAfterAndBeforeAccessModifiersInteraction) { "private:\n" "\n\n\n" "protected:\n" - "};\n", + "};", format("struct foo {\n" "private:\n" "\n\n\n" "protected:\n" - "};\n", + "};", Style)); // test::messUp removes all new lines which changes // the logic. @@ -13165,12 +13165,12 @@ TEST_F(FormatTest, FormatsAfterAndBeforeAccessModifiersInteraction) { verifyFormat("struct foo {\n" "private:\n" "protected:\n" - "};\n", + "};", "struct foo {\n" "private:\n" "\n\n\n" "protected:\n" - "};\n", + "};", Style); Style.EmptyLineBeforeAccessModifier = FormatStyle::ELBAMS_LogicalBlock; @@ -13178,12 +13178,12 @@ TEST_F(FormatTest, FormatsAfterAndBeforeAccessModifiersInteraction) { verifyFormat("struct foo {\n" "private:\n" "protected:\n" - "};\n", + "};", "struct foo {\n" "private:\n" "\n\n\n" "protected:\n" - "};\n", + "};", Style); Style.EmptyLineBeforeAccessModifier = FormatStyle::ELBAMS_LogicalBlock; @@ -13191,12 +13191,12 @@ TEST_F(FormatTest, FormatsAfterAndBeforeAccessModifiersInteraction) { verifyFormat("struct foo {\n" "private:\n" "protected:\n" - "};\n", + "};", "struct foo {\n" "private:\n" "\n\n\n" "protected:\n" - "};\n", + "};", Style); Style.EmptyLineBeforeAccessModifier = FormatStyle::ELBAMS_LogicalBlock; @@ -13204,12 +13204,12 @@ TEST_F(FormatTest, FormatsAfterAndBeforeAccessModifiersInteraction) { verifyFormat("struct foo {\n" "private:\n" "protected:\n" - "};\n", + "};", "struct foo {\n" "private:\n" "\n\n\n" "protected:\n" - "};\n", + "};", Style); } @@ -13265,7 +13265,7 @@ TEST_F(FormatTest, HandlesIncludeDirectives) { "#include \"abc.h\" // this is included for ABC\n" "#include \"some long include\" // with a comment\n" "#include \"some very long include path\"\n" - "#include \n", + "#include ", getLLVMStyleWithColumns(35)); EXPECT_EQ("#include \"a.h\"", format("#include \"a.h\"")); EXPECT_EQ("#include ", format("#include")); @@ -13358,7 +13358,7 @@ TEST_F(FormatTest, IndentationWithinColumnLimitNotPossible) { getLLVMStyleWithColumns(20)); verifyFormat("function(\n" " ShortArgument,\n" - " LoooooooooooongArgument);\n", + " LoooooooooooongArgument);", getLLVMStyleWithColumns(20)); } @@ -13424,20 +13424,20 @@ TEST_F(FormatTest, DoesNotTouchUnwrappedLinesWithErrors) { } TEST_F(FormatTest, IncorrectCodeErrorDetection) { - EXPECT_EQ("{\n {}\n", format("{\n{\n}\n")); - EXPECT_EQ("{\n {}\n", format("{\n {\n}\n")); - EXPECT_EQ("{\n {}\n", format("{\n {\n }\n")); - EXPECT_EQ("{\n {}\n}\n}\n", format("{\n {\n }\n }\n}\n")); + EXPECT_EQ("{\n {}", format("{\n{\n}")); + EXPECT_EQ("{\n {}", format("{\n {\n}")); + EXPECT_EQ("{\n {}", format("{\n {\n }")); + EXPECT_EQ("{\n {}\n}\n}", format("{\n {\n }\n }\n}")); EXPECT_EQ("{\n" " {\n" " breakme(\n" " qwe);\n" - " }\n", + " }", format("{\n" " {\n" " breakme(qwe);\n" - "}\n", + "}", getLLVMStyleWithColumns(10))); } @@ -14249,23 +14249,23 @@ TEST_F(FormatTest, SplitEmptyFunction) { Style.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_Inline; verifyFormat("class Foo {\n" " int f() {}\n" - "};\n", + "};", Style); verifyFormat("class Foo {\n" " int f() { return 0; }\n" - "};\n", + "};", Style); verifyFormat("class Foo {\n" " int aaaaaaaaaaaaaa(int bbbbbbbbbbbbbb)\n" " {}\n" - "};\n", + "};", Style); verifyFormat("class Foo {\n" " int aaaaaaaaaaaaaa(int bbbbbbbbbbbbbb)\n" " {\n" " return 0;\n" " }\n" - "};\n", + "};", Style); Style.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_All; @@ -14634,17 +14634,16 @@ TEST_F(FormatTest, UnderstandContextOfRecordTypeKeywords) { verifyFormat("if (true)\n" " class X x;\n" "else\n" - " f();\n"); + " f();"); // This is simply incomplete. Formatting is not important, but must not crash. verifyFormat("class A:"); } TEST_F(FormatTest, DoNotInterfereWithErrorAndWarning) { - verifyNoChange("#error Leave all white!!!!! space* alone!\n"); - EXPECT_EQ( - "#warning Leave all white!!!!! space* alone!\n", - format("#warning Leave all white!!!!! space* alone!\n")); + verifyNoChange("#error Leave all white!!!!! space* alone!"); + EXPECT_EQ("#warning Leave all white!!!!! space* alone!", + format("#warning Leave all white!!!!! space* alone!")); EXPECT_EQ("#error 1", format(" # error 1")); EXPECT_EQ("#warning 1", format(" # warning 1")); } @@ -14771,8 +14770,8 @@ TEST_F(FormatTest, SkipsDeeplyNestedLines) { ", 1), 1), 1), 1), 1), 1), 1), 1), 1), 1)\n" ", 1), 1), 1), 1), 1), 1), 1), 1), 1), 1);\n"); // Deeply nested part is untouched, rest is formatted. - EXPECT_EQ(std::string("int i;\n") + Code + "int j;\n", - format(std::string("int i;\n") + Code + "int j;\n", + EXPECT_EQ(std::string("int i;") + Code + "int j;", + format(std::string("int i;") + Code + "int j;", getLLVMStyle(), SC_ExpectIncomplete)); } @@ -15457,7 +15456,7 @@ TEST_F(FormatTest, ConfigurableUseOfTab) { "\t}", Tab); verifyFormat("int a;\t // x\n" - "int bbbbbbbb; // x\n", + "int bbbbbbbb; // x", Tab); FormatStyle TabAlignment = Tab; @@ -16999,7 +16998,7 @@ TEST_F(FormatTest, ConfigurableSpacesInSquareBrackets) { verifyFormat("int i = a[ a ][ a ]->f();", Spaces); verifyFormat("int i = (*b)[ a ]->f();", Spaces); // Lambdas. - verifyFormat("int c = []() -> int { return 2; }();\n", Spaces); + verifyFormat("int c = []() -> int { return 2; }();", Spaces); verifyFormat("return [ i, args... ] {};", Spaces); verifyFormat("int foo = [ &bar ]() {};", Spaces); verifyFormat("int foo = [ = ]() {};", Spaces); @@ -17022,7 +17021,7 @@ TEST_F(FormatTest, ConfigurableSpaceBeforeBrackets) { FormatStyle Space = getLLVMStyle(); Space.SpaceBeforeSquareBrackets = true; - verifyFormat("int c = []() -> int { return 2; }();\n", Space); + verifyFormat("int c = []() -> int { return 2; }();", Space); verifyFormat("return [i, args...] {};", Space); verifyFormat("int a [5];", Space); @@ -17502,7 +17501,7 @@ TEST_F(FormatTest, AlignConsecutiveMacros) { "#define B \\\n" " \"QQQQQQQQQQQQQ\" \\\n" " \"FFFFFFFFFFFFF\" \\\n" - " \"LLLLLLLL\"\n", + " \"LLLLLLLL\"", Style); Style.AlignConsecutiveMacros.Enabled = true; @@ -17514,7 +17513,7 @@ TEST_F(FormatTest, AlignConsecutiveMacros) { "#define B \\\n" " \"QQQQQQQQQQQQQ\" \\\n" " \"FFFFFFFFFFFFF\" \\\n" - " \"LLLLLLLL\"\n", + " \"LLLLLLLL\"", Style); // Test across comments @@ -17987,7 +17986,7 @@ TEST_F(FormatTest, AlignConsecutiveAssignmentsAcrossEmptyLinesAndComments) { "something = 2000;", Alignment); verifyFormat("something = 2000;\n" - "int i = 1, j = 10;\n", + "int i = 1, j = 10;", Alignment); verifyFormat("something = 2000;\n" "another = 911;\n" @@ -18003,7 +18002,7 @@ TEST_F(FormatTest, AlignConsecutiveAssignmentsAcrossEmptyLinesAndComments) { Alignment); verifyFormat("int oneTwoThree = 123;\n" "int oneTwo = 12;\n" - "method();\n", + "method();", Alignment); verifyFormat("int oneTwoThree = 123; // comment\n" "int oneTwo = 12; // comment", @@ -18018,7 +18017,7 @@ TEST_F(FormatTest, AlignConsecutiveAssignmentsAcrossEmptyLinesAndComments) { "#if B\n" "#else\n" "int a = 12;\n" - "#endif\n", + "#endif", Alignment); verifyFormat("enum foo {\n" "#if A\n" @@ -18029,7 +18028,7 @@ TEST_F(FormatTest, AlignConsecutiveAssignmentsAcrossEmptyLinesAndComments) { "#else\n" " a = 12;\n" "#endif\n" - "};\n", + "};", Alignment); */ @@ -18249,31 +18248,31 @@ TEST_F(FormatTest, AlignConsecutiveAssignmentsAcrossEmptyLinesAndComments) { verifyFormat("template \n" - "auto foo() {}\n", + "auto foo() {}", Alignment); verifyFormat("int a, b = 1;\n" "int c = 2;\n" - "int dd = 3;\n", + "int dd = 3;", Alignment); verifyFormat("int aa = ((1 > 2) ? 3 : 4);\n" - "float b[1][] = {{3.f}};\n", + "float b[1][] = {{3.f}};", Alignment); verifyFormat("for (int i = 0; i < 1; i++)\n" - " int x = 1;\n", + " int x = 1;", Alignment); verifyFormat("for (i = 0; i < 1; i++)\n" " x = 1;\n" - "y = 1;\n", + "y = 1;", Alignment); Alignment.ReflowComments = true; Alignment.ColumnLimit = 50; EXPECT_EQ("int x = 0;\n" "int yy = 1; /// specificlennospace\n" - "int zzz = 2;\n", + "int zzz = 2;", format("int x = 0;\n" "int yy = 1; ///specificlennospace\n" - "int zzz = 2;\n", + "int zzz = 2;", Alignment)); } @@ -18329,78 +18328,78 @@ TEST_F(FormatTest, AlignCompoundAssignments) { EXPECT_EQ("a += 5;\n" "one = 1;\n" "\n" - "oneTwoThree = 123;\n", + "oneTwoThree = 123;", format("a += 5;\n" "one = 1;\n" "\n" - "oneTwoThree = 123;\n", + "oneTwoThree = 123;", Alignment)); EXPECT_EQ("a += 5;\n" "one = 1;\n" "//\n" - "oneTwoThree = 123;\n", + "oneTwoThree = 123;", format("a += 5;\n" "one = 1;\n" "//\n" - "oneTwoThree = 123;\n", + "oneTwoThree = 123;", Alignment)); Alignment.AlignConsecutiveAssignments.AcrossEmptyLines = true; EXPECT_EQ("a += 5;\n" "one = 1;\n" "\n" - "oneTwoThree = 123;\n", + "oneTwoThree = 123;", format("a += 5;\n" "one = 1;\n" "\n" - "oneTwoThree = 123;\n", + "oneTwoThree = 123;", Alignment)); EXPECT_EQ("a += 5;\n" "one = 1;\n" "//\n" - "oneTwoThree = 123;\n", + "oneTwoThree = 123;", format("a += 5;\n" "one = 1;\n" "//\n" - "oneTwoThree = 123;\n", + "oneTwoThree = 123;", Alignment)); Alignment.AlignConsecutiveAssignments.AcrossEmptyLines = false; Alignment.AlignConsecutiveAssignments.AcrossComments = true; EXPECT_EQ("a += 5;\n" "one = 1;\n" "\n" - "oneTwoThree = 123;\n", + "oneTwoThree = 123;", format("a += 5;\n" "one = 1;\n" "\n" - "oneTwoThree = 123;\n", + "oneTwoThree = 123;", Alignment)); EXPECT_EQ("a += 5;\n" "one = 1;\n" "//\n" - "oneTwoThree = 123;\n", + "oneTwoThree = 123;", format("a += 5;\n" "one = 1;\n" "//\n" - "oneTwoThree = 123;\n", + "oneTwoThree = 123;", Alignment)); Alignment.AlignConsecutiveAssignments.AcrossEmptyLines = true; EXPECT_EQ("a += 5;\n" "one >>= 1;\n" "\n" - "oneTwoThree = 123;\n", + "oneTwoThree = 123;", format("a += 5;\n" "one >>= 1;\n" "\n" - "oneTwoThree = 123;\n", + "oneTwoThree = 123;", Alignment)); EXPECT_EQ("a += 5;\n" "one = 1;\n" "//\n" - "oneTwoThree <<= 123;\n", + "oneTwoThree <<= 123;", format("a += 5;\n" "one = 1;\n" "//\n" - "oneTwoThree <<= 123;\n", + "oneTwoThree <<= 123;", Alignment)); } @@ -18436,7 +18435,7 @@ TEST_F(FormatTest, AlignConsecutiveAssignments) { "something = 2000;", Alignment); verifyFormat("something = 2000;\n" - "int i = 1, j = 10;\n", + "int i = 1, j = 10;", Alignment); verifyFormat("something = 2000;\n" "another = 911;\n" @@ -18452,7 +18451,7 @@ TEST_F(FormatTest, AlignConsecutiveAssignments) { Alignment); verifyFormat("int oneTwoThree = 123;\n" "int oneTwo = 12;\n" - "method();\n", + "method();", Alignment); verifyFormat("int oneTwoThree = 123; // comment\n" "int oneTwo = 12; // comment", @@ -18501,7 +18500,7 @@ TEST_F(FormatTest, AlignConsecutiveAssignments) { " void f() = delete;\n" " SSSSSSSSSSSSSSSSSSSSSSSSSSSS &operator=(\n" " const SSSSSSSSSSSSSSSSSSSSSSSSSSSS &other) = delete;\n" - "};\n", + "};", AlignmentWithPenalty); // Bug 25167 @@ -18513,7 +18512,7 @@ TEST_F(FormatTest, AlignConsecutiveAssignments) { "#if B\n" "#else\n" "int a = 12;\n" - "#endif\n", + "#endif", Alignment); verifyFormat("enum foo {\n" "#if A\n" @@ -18524,7 +18523,7 @@ TEST_F(FormatTest, AlignConsecutiveAssignments) { "#else\n" " a = 12;\n" "#endif\n" - "};\n", + "};", Alignment); */ @@ -18647,31 +18646,31 @@ TEST_F(FormatTest, AlignConsecutiveAssignments) { verifyFormat("template \n" - "auto foo() {}\n", + "auto foo() {}", Alignment); verifyFormat("int a, b = 1;\n" "int c = 2;\n" - "int dd = 3;\n", + "int dd = 3;", Alignment); verifyFormat("int aa = ((1 > 2) ? 3 : 4);\n" - "float b[1][] = {{3.f}};\n", + "float b[1][] = {{3.f}};", Alignment); verifyFormat("for (int i = 0; i < 1; i++)\n" - " int x = 1;\n", + " int x = 1;", Alignment); verifyFormat("for (i = 0; i < 1; i++)\n" " x = 1;\n" - "y = 1;\n", + "y = 1;", Alignment); EXPECT_EQ(Alignment.ReflowComments, true); Alignment.ColumnLimit = 50; EXPECT_EQ("int x = 0;\n" "int yy = 1; /// specificlennospace\n" - "int zzz = 2;\n", + "int zzz = 2;", format("int x = 0;\n" "int yy = 1; ///specificlennospace\n" - "int zzz = 2;\n", + "int zzz = 2;", Alignment)); verifyFormat("auto aaaaaaaaaaaaaaaaaaaaa = {};\n" @@ -18808,7 +18807,7 @@ TEST_F(FormatTest, AlignConsecutiveDeclarations) { "something = 2000;", Alignment); verifyFormat("something = 2000;\n" - "int i = 1, j = 10;\n", + "int i = 1, j = 10;", Alignment); verifyFormat("float something = 2000;\n" "double another = 911;\n" @@ -18929,24 +18928,24 @@ TEST_F(FormatTest, AlignConsecutiveDeclarations) { // Make sure that scope is correctly tracked, in the absence of braces verifyFormat("for (int i = 0; i < n; i++)\n" " j = i;\n" - "double x = 1;\n", + "double x = 1;", Alignment); verifyFormat("if (int i = 0)\n" " j = i;\n" - "double x = 1;\n", + "double x = 1;", Alignment); // Ensure operator[] and operator() are comprehended verifyFormat("struct test {\n" " long long int foo();\n" " int operator[](int a);\n" " double bar();\n" - "};\n", + "};", Alignment); verifyFormat("struct test {\n" " long long int foo();\n" " int operator()(int a);\n" " double bar();\n" - "};\n", + "};", Alignment); // http://llvm.org/PR52914 verifyFormat("char *a[] = {\"a\", // comment\n" @@ -19010,7 +19009,7 @@ TEST_F(FormatTest, AlignConsecutiveDeclarations) { verifyFormat("int *a;\n" "int **b;\n" "int ***c;\n" - "int foobar;\n", + "int foobar;", Alignment); // PAS_Left @@ -19070,7 +19069,7 @@ TEST_F(FormatTest, AlignConsecutiveDeclarations) { verifyFormat("int* a;\n" "int** b;\n" "int*** c;\n" - "int foobar;\n", + "int foobar;", AlignmentLeft); // PAS_Middle @@ -19130,7 +19129,7 @@ TEST_F(FormatTest, AlignConsecutiveDeclarations) { verifyFormat("int * a;\n" "int * b;\n" "int *** c;\n" - "int foobar;\n", + "int foobar;", AlignmentMiddle); Alignment.AlignConsecutiveAssignments.Enabled = false; @@ -19244,22 +19243,22 @@ TEST_F(FormatTest, AlignConsecutiveDeclarations) { verifyFormat( "template \n" - "auto foo() {}\n", + "auto foo() {}", Alignment); verifyFormat("float a, b = 1;\n" "int c = 2;\n" - "int dd = 3;\n", + "int dd = 3;", Alignment); verifyFormat("int aa = ((1 > 2) ? 3 : 4);\n" - "float b[1][] = {{3.f}};\n", + "float b[1][] = {{3.f}};", Alignment); Alignment.AlignConsecutiveAssignments.Enabled = true; verifyFormat("float a, b = 1;\n" "int c = 2;\n" - "int dd = 3;\n", + "int dd = 3;", Alignment); verifyFormat("int aa = ((1 > 2) ? 3 : 4);\n" - "float b[1][] = {{3.f}};\n", + "float b[1][] = {{3.f}};", Alignment); Alignment.AlignConsecutiveAssignments.Enabled = false; @@ -19276,7 +19275,7 @@ TEST_F(FormatTest, AlignConsecutiveDeclarations) { "void bar(ino_t a,\n" " int b,\n" " uint32_t *c,\n" - " bool d) {}\n", + " bool d) {}", Alignment); Alignment.BinPackParameters = true; Alignment.ColumnLimit = 80; @@ -19287,7 +19286,7 @@ TEST_F(FormatTest, AlignConsecutiveDeclarations) { "auto found = range::find_if(vsProducts, [&](auto * aProduct) {\n" " static const Version verVs2017;\n" " return true;\n" - "});\n", + "});", Alignment); Alignment.PointerAlignment = FormatStyle::PAS_Right; @@ -19813,11 +19812,11 @@ TEST_F(FormatTest, LinuxBraceBreaking) { "struct B {\n" " int x;\n" "};\n" - "} // namespace a\n", + "} // namespace a", LinuxBraceStyle); verifyFormat("enum X {\n" " Y = 0,\n" - "}\n", + "}", LinuxBraceStyle); verifyFormat("struct S {\n" " int Type;\n" @@ -19829,7 +19828,7 @@ TEST_F(FormatTest, LinuxBraceBreaking) { " {\n" " MyFavoriteType Value;\n" " } Class;\n" - "}\n", + "}", LinuxBraceStyle); } @@ -19860,7 +19859,7 @@ TEST_F(FormatTest, MozillaBraceBreaking) { "{\n" " int x;\n" "};\n" - "}\n", + "}", MozillaBraceStyle); verifyFormat("struct S\n" "{\n" @@ -19874,7 +19873,7 @@ TEST_F(FormatTest, MozillaBraceBreaking) { " {\n" " MyFavoriteType Value;\n" " } Class;\n" - "}\n", + "}", MozillaBraceStyle); } @@ -19895,7 +19894,7 @@ TEST_F(FormatTest, StroustrupBraceBreaking) { "struct B {\n" " int x;\n" "};\n" - "} // namespace a\n", + "} // namespace a", StroustrupBraceStyle); verifyFormat("void foo()\n" @@ -19906,7 +19905,7 @@ TEST_F(FormatTest, StroustrupBraceBreaking) { " else {\n" " b();\n" " }\n" - "}\n", + "}", StroustrupBraceStyle); verifyFormat("#ifdef _DEBUG\n" @@ -19948,12 +19947,12 @@ TEST_F(FormatTest, AllmanBraceBreaking) { "{\n" "void f();\n" "void g();\n" - "} // namespace a\n", + "} // namespace a", format("namespace a\n" "{\n" "void f();\n" "void g();\n" - "}\n", + "}", AllmanBraceStyle)); verifyFormat("namespace a\n" @@ -19994,7 +19993,7 @@ TEST_F(FormatTest, AllmanBraceBreaking) { " {\n" " c();\n" " }\n" - "}\n", + "}", AllmanBraceStyle); verifyFormat("void f()\n" @@ -20011,7 +20010,7 @@ TEST_F(FormatTest, AllmanBraceBreaking) { " {\n" " c();\n" " } while (false)\n" - "}\n", + "}", AllmanBraceStyle); verifyFormat("void f(int a)\n" @@ -20031,18 +20030,18 @@ TEST_F(FormatTest, AllmanBraceBreaking) { " default:\n" " break;\n" " }\n" - "}\n", + "}", AllmanBraceStyle); verifyFormat("enum X\n" "{\n" " Y = 0,\n" - "}\n", + "}", AllmanBraceStyle); verifyFormat("enum X\n" "{\n" " Y = 0\n" - "}\n", + "}", AllmanBraceStyle); verifyFormat("@interface BSApplicationController ()\n" @@ -20050,7 +20049,7 @@ TEST_F(FormatTest, AllmanBraceBreaking) { "@private\n" " id _extraIvar;\n" "}\n" - "@end\n", + "@end", AllmanBraceStyle); verifyFormat("#ifdef _DEBUG\n" @@ -20185,7 +20184,7 @@ TEST_F(FormatTest, AllmanBraceBreaking) { " {\n" " return;\n" " }\n" - "}\n", + "}", BreakBeforeBraceShortIfs); verifyFormat("void f(bool b)\n" "{\n" @@ -20193,7 +20192,7 @@ TEST_F(FormatTest, AllmanBraceBreaking) { " {\n" " return;\n" " }\n" - "}\n", + "}", BreakBeforeBraceShortIfs); verifyFormat("void f(bool b)\n" "{\n" @@ -20201,22 +20200,22 @@ TEST_F(FormatTest, AllmanBraceBreaking) { " {\n" " return;\n" " }\n" - "}\n", + "}", BreakBeforeBraceShortIfs); verifyFormat("void f(bool b)\n" "{\n" " if (b) return;\n" - "}\n", + "}", BreakBeforeBraceShortIfs); verifyFormat("void f(bool b)\n" "{\n" " if constexpr (b) return;\n" - "}\n", + "}", BreakBeforeBraceShortIfs); verifyFormat("void f(bool b)\n" "{\n" " if CONSTEXPR (b) return;\n" - "}\n", + "}", BreakBeforeBraceShortIfs); verifyFormat("void f(bool b)\n" "{\n" @@ -20224,7 +20223,7 @@ TEST_F(FormatTest, AllmanBraceBreaking) { " {\n" " return;\n" " }\n" - "}\n", + "}", BreakBeforeBraceShortIfs); } @@ -20257,7 +20256,7 @@ TEST_F(FormatTest, WhitesmithsBraceBreaking) { " F\n" " }\n" " };\n" - " } // namespace B\n", + " } // namespace B", WhitesmithsBraceStyle); */ @@ -20383,7 +20382,7 @@ TEST_F(FormatTest, WhitesmithsBraceBreaking) { " {\n" " c();\n" " }\n" - " }\n", + " }", WhitesmithsBraceStyle); verifyFormat("void f()\n" @@ -20400,7 +20399,7 @@ TEST_F(FormatTest, WhitesmithsBraceBreaking) { " {\n" " c();\n" " } while (false)\n" - " }\n", + " }", WhitesmithsBraceStyle); WhitesmithsBraceStyle.IndentCaseLabels = true; @@ -20413,7 +20412,7 @@ TEST_F(FormatTest, WhitesmithsBraceBreaking) { " }\n" " break;\n" " }\n" - " }\n", + " }", WhitesmithsBraceStyle); verifyFormat("void switchTest2(int a)\n" @@ -20433,7 +20432,7 @@ TEST_F(FormatTest, WhitesmithsBraceBreaking) { " default:\n" " break;\n" " }\n" - " }\n", + " }", WhitesmithsBraceStyle); verifyFormat("void switchTest3(int a)\n" @@ -20451,7 +20450,7 @@ TEST_F(FormatTest, WhitesmithsBraceBreaking) { " }\n" " break;\n" " }\n" - " }\n", + " }", WhitesmithsBraceStyle); WhitesmithsBraceStyle.IndentCaseLabels = false; @@ -20465,7 +20464,7 @@ TEST_F(FormatTest, WhitesmithsBraceBreaking) { " }\n" " break;\n" " }\n" - " }\n", + " }", WhitesmithsBraceStyle); verifyFormat("void switchTest5(int a)\n" @@ -20486,7 +20485,7 @@ TEST_F(FormatTest, WhitesmithsBraceBreaking) { " default:\n" " break;\n" " }\n" - " }\n", + " }", WhitesmithsBraceStyle); verifyFormat("void switchTest6(int a)\n" @@ -20504,25 +20503,25 @@ TEST_F(FormatTest, WhitesmithsBraceBreaking) { " }\n" " break;\n" " }\n" - " }\n", + " }", WhitesmithsBraceStyle); verifyFormat("enum X\n" " {\n" " Y = 0, // testing\n" - " }\n", + " }", WhitesmithsBraceStyle); verifyFormat("enum X\n" " {\n" " Y = 0\n" - " }\n", + " }", WhitesmithsBraceStyle); verifyFormat("enum X\n" " {\n" " Y = 0,\n" " Z = 1\n" - " };\n", + " };", WhitesmithsBraceStyle); verifyFormat("@interface BSApplicationController ()\n" @@ -20530,7 +20529,7 @@ TEST_F(FormatTest, WhitesmithsBraceBreaking) { "@private\n" " id _extraIvar;\n" " }\n" - "@end\n", + "@end", WhitesmithsBraceStyle); verifyFormat("#ifdef _DEBUG\n" @@ -20603,12 +20602,12 @@ TEST_F(FormatTest, WhitesmithsBraceBreaking) { " {\n" " return;\n" " }\n" - " }\n", + " }", BreakBeforeBraceShortIfs); verifyFormat("void f(bool b)\n" " {\n" " if (b) return;\n" - " }\n", + " }", BreakBeforeBraceShortIfs); verifyFormat("void f(bool b)\n" " {\n" @@ -20616,7 +20615,7 @@ TEST_F(FormatTest, WhitesmithsBraceBreaking) { " {\n" " return;\n" " }\n" - " }\n", + " }", BreakBeforeBraceShortIfs); } @@ -20658,7 +20657,7 @@ TEST_F(FormatTest, GNUBraceBreaking) { " {\n" " c();\n" " }\n" - "}\n", + "}", GNUBraceStyle); verifyFormat("void f()\n" @@ -20676,7 +20675,7 @@ TEST_F(FormatTest, GNUBraceBreaking) { " c();\n" " }\n" " while (false);\n" - "}\n", + "}", GNUBraceStyle); verifyFormat("void f(int a)\n" @@ -20696,13 +20695,13 @@ TEST_F(FormatTest, GNUBraceBreaking) { " default:\n" " break;\n" " }\n" - "}\n", + "}", GNUBraceStyle); verifyFormat("enum X\n" "{\n" " Y = 0,\n" - "}\n", + "}", GNUBraceStyle); verifyFormat("@interface BSApplicationController ()\n" @@ -20710,7 +20709,7 @@ TEST_F(FormatTest, GNUBraceBreaking) { "@private\n" " id _extraIvar;\n" "}\n" - "@end\n", + "@end", GNUBraceStyle); verifyFormat("#ifdef _DEBUG\n" @@ -20768,7 +20767,7 @@ TEST_F(FormatTest, WebKitBraceBreaking) { "struct B {\n" " int x;\n" "};\n" - "}\n", + "}", WebKitBraceStyle); verifyFormat("struct S {\n" " int Type;\n" @@ -20779,7 +20778,7 @@ TEST_F(FormatTest, WebKitBraceBreaking) { " class C {\n" " MyFavoriteType Value;\n" " } Class;\n" - "};\n", + "};", WebKitBraceStyle); } @@ -20788,7 +20787,7 @@ TEST_F(FormatTest, CatchExceptionReferenceBinding) { " try {\n" " } catch (const Exception &e) {\n" " }\n" - "}\n"); + "}"); } TEST_F(FormatTest, CatchAlignArrayOfStructuresRightAlignment) { @@ -20800,14 +20799,14 @@ TEST_F(FormatTest, CatchAlignArrayOfStructuresRightAlignment) { " {56, 23, \"hello\"},\n" " {-1, 93463, \"world\"},\n" " { 7, 5, \"!!\"}\n" - "};\n", + "};", Style); verifyFormat("struct test demo[] = {\n" " {56, 23, \"hello\"}, // first line\n" " {-1, 93463, \"world\"}, // second line\n" " { 7, 5, \"!!\"} // third line\n" - "};\n", + "};", Style); verifyFormat("struct test demo[4] = {\n" @@ -20815,42 +20814,42 @@ TEST_F(FormatTest, CatchAlignArrayOfStructuresRightAlignment) { " { -1, 93463, 22, \"my\"}, // second line\n" " { 7, 5, 1, \"goodness\"} // third line\n" " {234, 5, 1, \"gracious\"} // fourth line\n" - "};\n", + "};", Style); verifyFormat("struct test demo[3] = {\n" " {56, 23, \"hello\"},\n" " {-1, 93463, \"world\"},\n" " { 7, 5, \"!!\"}\n" - "};\n", + "};", Style); verifyFormat("struct test demo[3] = {\n" " {int{56}, 23, \"hello\"},\n" " {int{-1}, 93463, \"world\"},\n" " { int{7}, 5, \"!!\"}\n" - "};\n", + "};", Style); verifyFormat("struct test demo[] = {\n" " {56, 23, \"hello\"},\n" " {-1, 93463, \"world\"},\n" " { 7, 5, \"!!\"},\n" - "};\n", + "};", Style); verifyFormat("test demo[] = {\n" " {56, 23, \"hello\"},\n" " {-1, 93463, \"world\"},\n" " { 7, 5, \"!!\"},\n" - "};\n", + "};", Style); verifyFormat("demo = std::array{\n" " test{56, 23, \"hello\"},\n" " test{-1, 93463, \"world\"},\n" " test{ 7, 5, \"!!\"},\n" - "};\n", + "};", Style); verifyFormat("test demo[] = {\n" @@ -20859,7 +20858,7 @@ TEST_F(FormatTest, CatchAlignArrayOfStructuresRightAlignment) { " {-1, 93463, \"world\"},\n" "#endif\n" " { 7, 5, \"!!\"}\n" - "};\n", + "};", Style); verifyFormat( @@ -20869,7 +20868,7 @@ TEST_F(FormatTest, CatchAlignArrayOfStructuresRightAlignment) { " \"just world, ought to be split over multiple lines\"},\n" " {-1, 93463, \"world\"},\n" " {56, 5, \"!!\"}\n" - "};\n", + "};", Style); verifyFormat("return GradForUnaryCwise(g, {\n" @@ -20877,7 +20876,7 @@ TEST_F(FormatTest, CatchAlignArrayOfStructuresRightAlignment) { " {\"x\", \"dy\"}},\n" " { {\"dx\"}, \"Mul\", {\"dy\"" ", \"sign\"}},\n" - "});\n", + "});", Style); Style.ColumnLimit = 0; @@ -20900,21 +20899,21 @@ TEST_F(FormatTest, CatchAlignArrayOfStructuresRightAlignment) { " {56, 23, /* a comment */ \"hello\"},\n" " {-1, 93463, \"world\"},\n" " { 7, 5, \"!!\"}\n" - "};\n", + "};", Style); verifyFormat("test demo[] = {\n" " {56, 23, \"hello\"},\n" " {-1, 93463, \"world\" /* comment here */},\n" " { 7, 5, \"!!\"}\n" - "};\n", + "};", Style); verifyFormat("test demo[] = {\n" " {56, /* a comment */ 23, \"hello\"},\n" " {-1, 93463, \"world\"},\n" " { 7, 5, \"!!\"}\n" - "};\n", + "};", Style); Style.ColumnLimit = 20; @@ -21003,7 +21002,7 @@ TEST_F(FormatTest, CatchAlignArrayOfStructuresRightAlignment) { " { -1, 93463, 22, \"my\"}, // second line\n" " { 7, 5, 1, \"goodness\"} // third line\n" " {234, 5, 1, \"gracious\"} // fourth line\n" - "};\n", + "};", Style); EXPECT_EQ( "test demo[] = {\n" @@ -21027,64 +21026,64 @@ TEST_F(FormatTest, CatchAlignArrayOfStructuresLeftAlignment) { verifyFormat("auto foo = Items{\n" " Section{0, bar(), },\n" " Section{1, boo() }\n" - "};\n", + "};", Style); */ verifyFormat("auto foo = Items{\n" " Section{\n" " 0, bar(),\n" " }\n" - "};\n", + "};", Style); verifyFormat("struct test demo[] = {\n" " {56, 23, \"hello\"},\n" " {-1, 93463, \"world\"},\n" " {7, 5, \"!!\" }\n" - "};\n", + "};", Style); verifyFormat("struct test demo[] = {\n" " {56, 23, \"hello\"}, // first line\n" " {-1, 93463, \"world\"}, // second line\n" " {7, 5, \"!!\" } // third line\n" - "};\n", + "};", Style); verifyFormat("struct test demo[4] = {\n" " {56, 23, 21, \"oh\" }, // first line\n" " {-1, 93463, 22, \"my\" }, // second line\n" " {7, 5, 1, \"goodness\"} // third line\n" " {234, 5, 1, \"gracious\"} // fourth line\n" - "};\n", + "};", Style); verifyFormat("struct test demo[3] = {\n" " {56, 23, \"hello\"},\n" " {-1, 93463, \"world\"},\n" " {7, 5, \"!!\" }\n" - "};\n", + "};", Style); verifyFormat("struct test demo[3] = {\n" " {int{56}, 23, \"hello\"},\n" " {int{-1}, 93463, \"world\"},\n" " {int{7}, 5, \"!!\" }\n" - "};\n", + "};", Style); verifyFormat("struct test demo[] = {\n" " {56, 23, \"hello\"},\n" " {-1, 93463, \"world\"},\n" " {7, 5, \"!!\" },\n" - "};\n", + "};", Style); verifyFormat("test demo[] = {\n" " {56, 23, \"hello\"},\n" " {-1, 93463, \"world\"},\n" " {7, 5, \"!!\" },\n" - "};\n", + "};", Style); verifyFormat("demo = std::array{\n" " test{56, 23, \"hello\"},\n" " test{-1, 93463, \"world\"},\n" " test{7, 5, \"!!\" },\n" - "};\n", + "};", Style); verifyFormat("test demo[] = {\n" " {56, 23, \"hello\"},\n" @@ -21092,7 +21091,7 @@ TEST_F(FormatTest, CatchAlignArrayOfStructuresLeftAlignment) { " {-1, 93463, \"world\"},\n" "#endif\n" " {7, 5, \"!!\" }\n" - "};\n", + "};", Style); verifyFormat( "test demo[] = {\n" @@ -21101,7 +21100,7 @@ TEST_F(FormatTest, CatchAlignArrayOfStructuresLeftAlignment) { " \"just world, ought to be split over multiple lines\"},\n" " {-1, 93463, \"world\" },\n" " {56, 5, \"!!\" }\n" - "};\n", + "};", Style); verifyFormat("return GradForUnaryCwise(g, {\n" @@ -21109,7 +21108,7 @@ TEST_F(FormatTest, CatchAlignArrayOfStructuresLeftAlignment) { "\"dy\"} },\n" " {{\"dx\"}, \"Mul\", " "{\"dy\", \"sign\"}},\n" - "});\n", + "});", Style); Style.ColumnLimit = 0; @@ -21132,21 +21131,21 @@ TEST_F(FormatTest, CatchAlignArrayOfStructuresLeftAlignment) { " {56, 23, /* a comment */ \"hello\"},\n" " {-1, 93463, \"world\" },\n" " {7, 5, \"!!\" }\n" - "};\n", + "};", Style); verifyFormat("test demo[] = {\n" " {56, 23, \"hello\" },\n" " {-1, 93463, \"world\" /* comment here */},\n" " {7, 5, \"!!\" }\n" - "};\n", + "};", Style); verifyFormat("test demo[] = {\n" " {56, /* a comment */ 23, \"hello\"},\n" " {-1, 93463, \"world\"},\n" " {7, 5, \"!!\" }\n" - "};\n", + "};", Style); Style.ColumnLimit = 20; @@ -21338,38 +21337,38 @@ TEST_F(FormatTest, OptimizeBreakPenaltyVsExcess) { Style)); EXPECT_EQ("// foo bar baz bazfoo\n" - "// foo bar foo bar\n", + "// foo bar foo bar", format("// foo bar baz bazfoo\n" - "// foo bar foo bar\n", + "// foo bar foo bar", Style)); EXPECT_EQ("// foo bar baz bazfoo\n" - "// foo bar foo bar\n", + "// foo bar foo bar", format("// foo bar baz bazfoo\n" - "// foo bar foo bar\n", + "// foo bar foo bar", Style)); // FIXME: Optimally, we'd keep bazfoo on the first line and reflow bar to the // next one. EXPECT_EQ("// foo bar baz bazfoo\n" - "// bar foo bar\n", + "// bar foo bar", format("// foo bar baz bazfoo bar\n" - "// foo bar\n", + "// foo bar", Style)); EXPECT_EQ("// foo bar baz bazfoo\n" "// foo bar baz bazfoo\n" - "// bar foo bar\n", + "// bar foo bar", format("// foo bar baz bazfoo\n" "// foo bar baz bazfoo bar\n" - "// foo bar\n", + "// foo bar", Style)); EXPECT_EQ("// foo bar baz bazfoo\n" "// foo bar baz bazfoo\n" - "// bar foo bar\n", + "// bar foo bar", format("// foo bar baz bazfoo\n" "// foo bar baz bazfoo bar\n" - "// foo bar\n", + "// foo bar", Style)); // Make sure we do not keep protruding characters if strict mode reflow is @@ -21378,8 +21377,8 @@ TEST_F(FormatTest, OptimizeBreakPenaltyVsExcess) { EXPECT_EQ( "// foo foo foo foo\n" "// foo foo foo foo\n" - "// foo foo foo foo\n", - format("// foo foo foo foo foo foo foo foo foo foo foo foo\n", Style)); + "// foo foo foo foo", + format("// foo foo foo foo foo foo foo foo foo foo foo foo", Style)); EXPECT_EQ("int a = /* long block\n" " comment */\n" @@ -21673,7 +21672,7 @@ TEST_F(FormatTest, BreakConstructorInitializersBeforeComma) { Style.ConstructorInitializerIndentWidth = 4; verifyFormat("SomeClass::Constructor() : aaaaaaaa(aaaaaaaa) {}", Style); verifyFormat( - "SomeClass::Constructor() : aaaaa(aaaaa), aaaaa(aaaaa), aaaaa(aaaaa)\n", + "SomeClass::Constructor() : aaaaa(aaaaa), aaaaa(aaaaa), aaaaa(aaaaa)", Style); verifyFormat( "SomeClass::Constructor()\n" @@ -21684,7 +21683,7 @@ TEST_F(FormatTest, BreakConstructorInitializersBeforeComma) { " : aaaaaaaa(aaaaaaaa) {}", Style); verifyFormat("SomeClass::Constructor()\n" - " : aaaaa(aaaaa), aaaaa(aaaaa), aaaaa(aaaaa)\n", + " : aaaaa(aaaaa), aaaaa(aaaaa), aaaaa(aaaaa)", Style); verifyFormat( "SomeClass::Constructor()\n" @@ -21952,31 +21951,31 @@ TEST_F(FormatTest, FormatsWithWebKitStyle) { } TEST_F(FormatTest, FormatsLambdas) { - verifyFormat("int c = [b]() mutable { return [&b] { return b++; }(); }();\n"); - verifyFormat( - "int c = [b]() mutable noexcept { return [&b] { return b++; }(); }();\n"); - verifyFormat("int c = [&] { [=] { return b++; }(); }();\n"); - verifyFormat("int c = [&, &a, a] { [=, c, &d] { return b++; }(); }();\n"); - verifyFormat("int c = [&a, &a, a] { [=, a, b, &c] { return b++; }(); }();\n"); - verifyFormat("auto c = {[&a, &a, a] { [=, a, b, &c] { return b++; }(); }}\n"); - verifyFormat("auto c = {[&a, &a, a] { [=, a, b, &c] {}(); }}\n"); - verifyFormat("auto c = [a = [b = 42] {}] {};\n"); - verifyFormat("auto c = [a = &i + 10, b = [] {}] {};\n"); + verifyFormat("int c = [b]() mutable { return [&b] { return b++; }(); }();"); + verifyFormat( + "int c = [b]() mutable noexcept { return [&b] { return b++; }(); }();"); + verifyFormat("int c = [&] { [=] { return b++; }(); }();"); + verifyFormat("int c = [&, &a, a] { [=, c, &d] { return b++; }(); }();"); + verifyFormat("int c = [&a, &a, a] { [=, a, b, &c] { return b++; }(); }();"); + verifyFormat("auto c = {[&a, &a, a] { [=, a, b, &c] { return b++; }(); }}"); + verifyFormat("auto c = {[&a, &a, a] { [=, a, b, &c] {}(); }}"); + verifyFormat("auto c = [a = [b = 42] {}] {};"); + verifyFormat("auto c = [a = &i + 10, b = [] {}] {};"); verifyFormat("int x = f(*+[] {});"); verifyFormat("void f() {\n" " other(x.begin(), x.end(), [&](int, int) { return 1; });\n" - "}\n"); + "}"); verifyFormat("void f() {\n" " other(x.begin(), //\n" " x.end(), //\n" " [&](int, int) { return 1; });\n" - "}\n"); + "}"); verifyFormat("void f() {\n" " other.other.other.other.other(\n" " x.begin(), x.end(),\n" " [something, rather](int, int, int, int, int, int, int) { " "return 1; });\n" - "}\n"); + "}"); verifyFormat( "void f() {\n" " other.other.other.other.other(\n" @@ -21984,7 +21983,7 @@ TEST_F(FormatTest, FormatsLambdas) { " [something, rather](int, int, int, int, int, int, int) {\n" " //\n" " });\n" - "}\n"); + "}"); verifyFormat("SomeFunction([]() { // A cool function...\n" " return 43;\n" "});"); @@ -22046,9 +22045,9 @@ TEST_F(FormatTest, FormatsLambdas) { " aaaaa aaaaaaaaa);"); // Lambdas with return types. - verifyFormat("int c = []() -> int { return 2; }();\n"); - verifyFormat("int c = []() -> int * { return 2; }();\n"); - verifyFormat("int c = []() -> vector { return {2}; }();\n"); + verifyFormat("int c = []() -> int { return 2; }();"); + verifyFormat("int c = []() -> int * { return 2; }();"); + verifyFormat("int c = []() -> vector { return {2}; }();"); verifyFormat("Foo([]() -> std::vector { return {2}; }());"); verifyFormat("foo([]() noexcept -> int {});"); verifyGoogleFormat("auto a = [&b, c](D* d) -> D* {};"); @@ -22185,37 +22184,37 @@ TEST_F(FormatTest, FormatsLambdas) { // Lambdas with explicit template argument lists. verifyFormat( - "auto L = []