Index: clang/unittests/Format/CleanupTest.cpp =================================================================== --- clang/unittests/Format/CleanupTest.cpp +++ clang/unittests/Format/CleanupTest.cpp @@ -479,7 +479,6 @@ EXPECT_EQ(Expected, apply(Code, Replaces)); } - TEST_F(CleanUpReplacementsTest, FormatCorrectLineWhenHeadersAreInserted) { std::string Code = "\n" "int x;\n" Index: clang/unittests/Format/FormatTestCSharp.cpp =================================================================== --- clang/unittests/Format/FormatTestCSharp.cpp +++ clang/unittests/Format/FormatTestCSharp.cpp @@ -761,7 +761,8 @@ verifyFormat(R"(// class ItemFactory - where T : new() {})", Style); + where T : new() {})", + Style); verifyFormat(R"(// class Dictionary Index: clang/unittests/Format/FormatTestComments.cpp =================================================================== --- clang/unittests/Format/FormatTestComments.cpp +++ clang/unittests/Format/FormatTestComments.cpp @@ -28,11 +28,7 @@ class FormatTestComments : public ::testing::Test { protected: - enum StatusCheck { - SC_ExpectComplete, - SC_ExpectIncomplete, - SC_DoNotCheck - }; + enum StatusCheck { SC_ExpectComplete, SC_ExpectIncomplete, SC_DoNotCheck }; std::string format(llvm::StringRef Code, const FormatStyle &Style = getLLVMStyle(), @@ -649,7 +645,8 @@ "//!line 4\n" "//!line 5\n" "// line 6\n" - "//line 7", getLLVMStyleWithColumns(20))); + "//line 7", + getLLVMStyleWithColumns(20))); EXPECT_EQ("// aa bb cc dd", format("// aa bb cc dd ", @@ -1346,7 +1343,8 @@ " // section comment 3\n" " i = 4;\n" "#endif\n" - "}", getLLVMStyleWithColumns(80)); + "}", + getLLVMStyleWithColumns(80)); } TEST_F(FormatTestComments, AlignsPPElseEndifComments) { @@ -1824,14 +1822,13 @@ // Reflow the last two lines of a section that starts with a line having // different indentation. - EXPECT_EQ( - "// long\n" - "// long long long\n" - "// long long", - format("// long\n" - "// long long long long\n" - "// long", - getLLVMStyleWithColumns(20))); + EXPECT_EQ("// long\n" + "// long long long\n" + "// long long", + format("// long\n" + "// long long long long\n" + "// long", + getLLVMStyleWithColumns(20))); // Keep the block comment endling '*/' while reflowing. EXPECT_EQ("/* Long long long\n" @@ -1911,10 +1908,9 @@ EXPECT_EQ("// long long long\n" "// long\n" "// ... --- ...", - format( - "// long long long long\n" - "// ... --- ...", - getLLVMStyleWithColumns(20))); + format("// long long long long\n" + "// ... --- ...", + getLLVMStyleWithColumns(20))); // Don't reflow lines starting with '@'. EXPECT_EQ("// long long long\n" @@ -1968,10 +1964,9 @@ // characters. EXPECT_EQ("// long long long\n" "// long 'long'", - format( - "// long long long long\n" - "// 'long'", - getLLVMStyleWithColumns(20))); + format("// long long long long\n" + "// 'long'", + getLLVMStyleWithColumns(20))); // Don't reflow between separate blocks of comments. EXPECT_EQ("/* First comment\n" @@ -2420,7 +2415,7 @@ format("int aaaaaaaaaaaaaaaaaaaaaaaaaaaa =\n" " /* line 1\n" " bbbbbbbbbbbb */ bbbbbbbbbbbbbbbbbbbbbbbbbbbb;", - getLLVMStyleWithColumns(50))); + getLLVMStyleWithColumns(50))); FormatStyle NoBinPacking = getLLVMStyle(); NoBinPacking.BinPackParameters = false; @@ -2791,15 +2786,18 @@ EXPECT_EQ("/*\n" " */", format("/*\n" - "*/", getLLVMStyle())); + "*/", + getLLVMStyle())); EXPECT_EQ("/*\n" " */", format("/*\n" - " */", getLLVMStyle())); + " */", + getLLVMStyle())); EXPECT_EQ("/*\n" " */", format("/*\n" - " */", getLLVMStyle())); + " */", + getLLVMStyle())); // Align a single line. EXPECT_EQ("/*\n" @@ -2854,19 +2852,22 @@ " */", format("/*\n" "* line\n" - "*/", getLLVMStyle())); + "*/", + getLLVMStyle())); EXPECT_EQ("/*\n" " * line\n" " */", format("/*\n" " * line\n" - " */", getLLVMStyle())); + " */", + getLLVMStyle())); EXPECT_EQ("/*\n" " * line\n" " */", format("/*\n" " * line\n" - " */", getLLVMStyle())); + " */", + getLLVMStyle())); // Align two lines. EXPECT_EQ("/* line 1\n" @@ -2947,7 +2948,8 @@ " * line 2\n" " * line 3\n" "* line 4\n" - "*/", getLLVMStyle())); + "*/", + getLLVMStyle())); // Align empty or blank lines. EXPECT_EQ("/**\n" @@ -2959,7 +2961,8 @@ "* \n" " * \n" " *\n" - "*/", getLLVMStyle())); + "*/", + getLLVMStyle())); // Align while breaking and reflowing. EXPECT_EQ("/*\n" @@ -3096,7 +3099,7 @@ } TEST_F(FormatTestComments, ReflowBackslashCrash) { -// clang-format off + // clang-format off EXPECT_EQ( "// How to run:\n" "// bbbbb run \\\n" @@ -3107,7 +3110,7 @@ "// bbbbb run \\\n" "// rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr \\\n" "// -- --output_directory=\"\"")); -// clang-format on + // clang-format on } TEST_F(FormatTestComments, IndentsLongJavadocAnnotatedLines) { @@ -3143,18 +3146,18 @@ "long long long long long long long long long long long\n" " */\n", Style)); - EXPECT_EQ( - "/**\n" - " * Sentence that\n" - " * should be broken.\n" - " * @param short\n" - " * keep indentation\n" - " */\n", format( - "/**\n" - " * Sentence that should be broken.\n" - " * @param short\n" - " * keep indentation\n" - " */\n", Style20)); + EXPECT_EQ("/**\n" + " * Sentence that\n" + " * should be broken.\n" + " * @param short\n" + " * keep indentation\n" + " */\n", + format("/**\n" + " * Sentence that should be broken.\n" + " * @param short\n" + " * keep indentation\n" + " */\n", + Style20)); EXPECT_EQ("/**\n" " * @param l1 long1\n" Index: clang/unittests/Format/FormatTestJS.cpp =================================================================== --- clang/unittests/Format/FormatTestJS.cpp +++ clang/unittests/Format/FormatTestJS.cpp @@ -48,15 +48,13 @@ static void verifyFormat( llvm::StringRef Code, const FormatStyle &Style = getGoogleStyle(FormatStyle::LK_JavaScript)) { - EXPECT_EQ(Code.str(), format(Code, Style)) - << "Expected code is not stable"; + EXPECT_EQ(Code.str(), format(Code, Style)) << "Expected code is not stable"; std::string Result = format(test::messUp(Code), Style); EXPECT_EQ(Code.str(), Result) << "Formatted:\n" << Result; } static void verifyFormat( - llvm::StringRef Expected, - llvm::StringRef Code, + llvm::StringRef Expected, llvm::StringRef Code, const FormatStyle &Style = getGoogleStyle(FormatStyle::LK_JavaScript)) { EXPECT_EQ(Expected.str(), format(Expected, Style)) << "Expected code is not stable"; @@ -115,7 +113,8 @@ " * jsdoc line 1\n" " */", format("/** jsdoc line 1\n" - " */", getGoogleJSStyleWithColumns(20))); + " */", + getGoogleJSStyleWithColumns(20))); // Don't break the first line of a short single line jsdoc comment. EXPECT_EQ("/** jsdoc line 1 */", format("/** jsdoc line 1 */", getGoogleJSStyleWithColumns(20))); @@ -185,8 +184,7 @@ // Don't break the first line of a single line short jsdoc comment pragma. EXPECT_EQ("/** @returns j */", - format("/** @returns j */", - getGoogleJSStyleWithColumns(20))); + format("/** @returns j */", getGoogleJSStyleWithColumns(20))); // Break a single line long jsdoc comment pragma. EXPECT_EQ("/**\n" @@ -346,18 +344,17 @@ } TEST_F(FormatTestJS, ReservedWordsMethods) { - verifyFormat( - "class X {\n" - " delete() {\n" - " x();\n" - " }\n" - " interface() {\n" - " x();\n" - " }\n" - " let() {\n" - " x();\n" - " }\n" - "}\n"); + verifyFormat("class X {\n" + " delete() {\n" + " x();\n" + " }\n" + " interface() {\n" + " x();\n" + " }\n" + " let() {\n" + " x();\n" + " }\n" + "}\n"); verifyFormat("class KeywordNamedMethods {\n" " do() {\n" " }\n" @@ -638,25 +635,27 @@ TEST_F(FormatTestJS, NamespacesMayNotWrap) { verifyFormat("declare namespace foobarbaz {\n" - "}\n", getGoogleJSStyleWithColumns(18)); + "}\n", + getGoogleJSStyleWithColumns(18)); verifyFormat("declare module foobarbaz {\n" - "}\n", getGoogleJSStyleWithColumns(15)); + "}\n", + getGoogleJSStyleWithColumns(15)); verifyFormat("namespace foobarbaz {\n" - "}\n", getGoogleJSStyleWithColumns(10)); + "}\n", + getGoogleJSStyleWithColumns(10)); verifyFormat("module foobarbaz {\n" - "}\n", getGoogleJSStyleWithColumns(7)); + "}\n", + getGoogleJSStyleWithColumns(7)); } TEST_F(FormatTestJS, AmbientDeclarations) { FormatStyle NineCols = getGoogleJSStyleWithColumns(9); - verifyFormat( - "declare class\n" - " X {}", - NineCols); - verifyFormat( - "declare function\n" - "x();", // TODO(martinprobst): should ideally be indented. - NineCols); + verifyFormat("declare class\n" + " X {}", + NineCols); + verifyFormat("declare function\n" + "x();", // TODO(martinprobst): should ideally be indented. + NineCols); verifyFormat("declare function foo();\n" "let x = 1;\n"); verifyFormat("declare function foo(): string;\n" @@ -667,14 +666,12 @@ "let x = 1;\n"); verifyFormat("declare interface Y {}\n" "let x = 1;\n"); - verifyFormat( - "declare enum X {\n" - "}", - NineCols); - verifyFormat( - "declare let\n" - " x: number;", - NineCols); + verifyFormat("declare enum X {\n" + "}", + NineCols); + verifyFormat("declare let\n" + " x: number;", + NineCols); } TEST_F(FormatTestJS, FormatsFreestandingFunctions) { @@ -1012,7 +1009,6 @@ " a: function() { return 1; }\n" "});", Style); - } TEST_F(FormatTestJS, DontWrapEmptyLiterals) { @@ -1206,15 +1202,13 @@ " x;\n" "};", Style); - verifyFormat("const arrInlineEmpty = () => {};", - Style); + verifyFormat("const arrInlineEmpty = () => {};", Style); Style.AllowShortLambdasOnASingleLine = FormatStyle::SLS_Inline; verifyFormat("const arr = () => {\n" " x;\n" "};", Style); - verifyFormat("foo(() => {});", - Style); + verifyFormat("foo(() => {});", Style); verifyFormat("const arrInlineInline = () => {};", Style); } @@ -1359,43 +1353,36 @@ "a = null\n" " return 1"); // Below "class Y {}" should ideally be on its own line. - verifyFormat( - "x = {\n" - " a: 1\n" - "} class Y {}", - " x = {a : 1}\n" - " class Y { }"); - verifyFormat( - "if (x) {\n" - "}\n" - "return 1", - "if (x) {}\n" - " return 1"); - verifyFormat( - "if (x) {\n" - "}\n" - "class X {}", - "if (x) {}\n" - " class X {}"); + verifyFormat("x = {\n" + " a: 1\n" + "} class Y {}", + " x = {a : 1}\n" + " class Y { }"); + verifyFormat("if (x) {\n" + "}\n" + "return 1", + "if (x) {}\n" + " return 1"); + verifyFormat("if (x) {\n" + "}\n" + "class X {}", + "if (x) {}\n" + " class X {}"); } TEST_F(FormatTestJS, ImportExportASI) { - verifyFormat( - "import {x} from 'y'\n" - "export function z() {}", - "import {x} from 'y'\n" - " export function z() {}"); + verifyFormat("import {x} from 'y'\n" + "export function z() {}", + "import {x} from 'y'\n" + " export function z() {}"); // Below "class Y {}" should ideally be on its own line. - verifyFormat( - "export {x} class Y {}", - " export {x}\n" - " class Y {\n}"); - verifyFormat( - "if (x) {\n" - "}\n" - "export class Y {}", - "if ( x ) { }\n" - " export class Y {}"); + verifyFormat("export {x} class Y {}", " export {x}\n" + " class Y {\n}"); + verifyFormat("if (x) {\n" + "}\n" + "export class Y {}", + "if ( x ) { }\n" + " export class Y {}"); } TEST_F(FormatTestJS, ClosureStyleCasts) { @@ -1576,8 +1563,9 @@ verifyFormat( "var someValue = (v as aaaaaaaaaaaaaaaaaaaa[])\n" " .someFunction(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);"); - verifyFormat("const xIsALongIdent:\n"" YJustBarelyFitsLinex[];", - getGoogleJSStyleWithColumns(20)); + verifyFormat("const xIsALongIdent:\n" + " YJustBarelyFitsLinex[];", + getGoogleJSStyleWithColumns(20)); verifyFormat("const x = {\n" " y: 1\n" "} as const;"); @@ -1630,10 +1618,9 @@ verifyFormat("class C {\n static x(): string {\n return 'asd';\n }\n}"); verifyFormat("class C extends P implements I {}"); verifyFormat("class C extends p.P implements i.I {}"); - verifyFormat( - "x(class {\n" - " a(): A {}\n" - "});"); + verifyFormat("x(class {\n" + " a(): A {}\n" + "});"); verifyFormat("class Test {\n" " aaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaa: aaaaaaaaaaaaaaaaaaaa):\n" " aaaaaaaaaaaaaaaaaaaaaa {}\n" @@ -1765,14 +1752,12 @@ const FormatStyle &Style = getGoogleJSStyleWithColumns(20); verifyFormat("type LongTypeIsReallyUnreasonablyLong =\n" " string;\n", - "type LongTypeIsReallyUnreasonablyLong = string;\n", + "type LongTypeIsReallyUnreasonablyLong = string;\n", Style); + verifyFormat("interface AbstractStrategyFactoryProvider {\n" + " a: number\n" + "}\n", + "interface AbstractStrategyFactoryProvider { a: number }\n", Style); - verifyFormat( - "interface AbstractStrategyFactoryProvider {\n" - " a: number\n" - "}\n", - "interface AbstractStrategyFactoryProvider { a: number }\n", - Style); } TEST_F(FormatTestJS, RemoveEmptyLinesInArrowFunctions) { @@ -1912,11 +1897,11 @@ TEST_F(FormatTestJS, TemplateStrings) { // Keeps any whitespace/indentation within the template string. verifyFormat("var x = `hello\n" - " ${name}\n" - " !`;", - "var x = `hello\n" - " ${ name }\n" - " !`;"); + " ${name}\n" + " !`;", + "var x = `hello\n" + " ${ name }\n" + " !`;"); verifyFormat("var x =\n" " `hello ${world}` >= some();", @@ -1926,18 +1911,18 @@ verifyFormat("var x = `hellö ${wörld}` >= söme();", getGoogleJSStyleWithColumns(35)); // Fits due to UTF-8. verifyFormat("var x = `hello\n" - " ${world}` >=\n" - " some();", - "var x =\n" - " `hello\n" - " ${world}` >= some();", - getGoogleJSStyleWithColumns(21)); // Barely doesn't fit. + " ${world}` >=\n" + " some();", + "var x =\n" + " `hello\n" + " ${world}` >= some();", + getGoogleJSStyleWithColumns(21)); // Barely doesn't fit. verifyFormat("var x = `hello\n" - " ${world}` >= some();", - "var x =\n" - " `hello\n" - " ${world}` >= some();", - getGoogleJSStyleWithColumns(22)); // Barely fits. + " ${world}` >= some();", + "var x =\n" + " `hello\n" + " ${world}` >= some();", + getGoogleJSStyleWithColumns(22)); // Barely fits. verifyFormat("var x =\n" " `h`;", @@ -1956,18 +1941,17 @@ // Make sure template strings get a proper ColumnWidth assigned, even if they // are first token in line. - verifyFormat( - "var a = aaaaaaaaaaaaaaaaaaaaaaaaaaaa ||\n" - " `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa`;"); + verifyFormat("var a = aaaaaaaaaaaaaaaaaaaaaaaaaaaa ||\n" + " `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa`;"); // Two template strings. verifyFormat("var x = `hello` == `hello`;"); // Comments in template strings. verifyFormat("var x = `//a`;\n" - "var y;", - "var x =\n `//a`;\n" - "var y ;"); + "var y;", + "var x =\n `//a`;\n" + "var y ;"); verifyFormat("var x = `/*a`;\n" "var y;", "var x =\n `/*a`;\n" @@ -2207,16 +2191,15 @@ " * @see http://very/very/long/url/is/long\n" " */", getGoogleJSStyleWithColumns(20)); - verifyFormat( - "/**\n" - " * @param This is a\n" - " * long comment\n" - " * but no type\n" - " */", - "/**\n" - " * @param This is a long comment but no type\n" - " */", - getGoogleJSStyleWithColumns(20)); + verifyFormat("/**\n" + " * @param This is a\n" + " * long comment\n" + " * but no type\n" + " */", + "/**\n" + " * @param This is a long comment but no type\n" + " */", + getGoogleJSStyleWithColumns(20)); // Break and reindent @param line and reflow unrelated lines. EXPECT_EQ("{\n" " /**\n" @@ -2277,12 +2260,11 @@ verifyFormat("var x = 'foo';", "var x = \"foo\";"); verifyFormat("var x = 'fo\\'o\\'';", "var x = \"fo'o'\";"); verifyFormat("var x = 'fo\\'o\\'';", "var x = \"fo\\'o'\";"); - verifyFormat( - "var x =\n" - " 'foo\\'';", - // Code below is 15 chars wide, doesn't fit into the line with the - // \ escape added. - "var x = \"foo'\";", getGoogleJSStyleWithColumns(15)); + verifyFormat("var x =\n" + " 'foo\\'';", + // Code below is 15 chars wide, doesn't fit into the line with + // the \ escape added. + "var x = \"foo'\";", getGoogleJSStyleWithColumns(15)); // Removes no-longer needed \ escape from ". verifyFormat("var x = 'fo\"o';", "var x = \"fo\\\"o\";"); // Code below fits into 15 chars *after* removing the \ escape. @@ -2343,18 +2325,16 @@ verifyFormat("let x = foo[0]!;\n"); verifyFormat("let x = (foo)!;\n"); verifyFormat("let x = x(foo!);\n"); - verifyFormat( - "a.aaaaaa(a.a!).then(\n" - " x => x(x));\n", - getGoogleJSStyleWithColumns(20)); + verifyFormat("a.aaaaaa(a.a!).then(\n" + " x => x(x));\n", + getGoogleJSStyleWithColumns(20)); verifyFormat("let x = foo! - 1;\n"); verifyFormat("let x = {foo: 1}!;\n"); - verifyFormat( - "let x = hello.foo()!\n" - " .foo()!\n" - " .foo()!\n" - " .foo()!;\n", - getGoogleJSStyleWithColumns(20)); + verifyFormat("let x = hello.foo()!\n" + " .foo()!\n" + " .foo()!\n" + " .foo()!;\n", + getGoogleJSStyleWithColumns(20)); verifyFormat("let x = namespace!;\n"); verifyFormat("return !!x;\n"); } @@ -2447,7 +2427,8 @@ verifyFormat("import {x} from 'x'; // from some location", getGoogleJSStyleWithColumns(25)); verifyFormat("// taze: x from 'location'", getGoogleJSStyleWithColumns(10)); - verifyFormat("/// ", getGoogleJSStyleWithColumns(10)); + verifyFormat("/// ", + getGoogleJSStyleWithColumns(10)); } TEST_F(FormatTestJS, Exponentiation) { @@ -2462,36 +2443,42 @@ " [\n" " 1,\n" " ],\n" - "];", FourSpaces); + "];", + FourSpaces); verifyFormat("var l = [\n" " {\n" " 1: 1,\n" " },\n" - "];", FourSpaces); + "];", + FourSpaces); verifyFormat("someFunction(\n" " p1,\n" " [\n" " 1,\n" " ],\n" - ");", FourSpaces); + ");", + FourSpaces); verifyFormat("someFunction(\n" " p1,\n" " {\n" " 1: 1,\n" " },\n" - ");", FourSpaces); + ");", + FourSpaces); verifyFormat("var o = {\n" " 1: 1,\n" " 2: {\n" " 3: 3,\n" " },\n" - "};", FourSpaces); + "};", + FourSpaces); verifyFormat("var o = {\n" " 1: 1,\n" " 2: [\n" " 3,\n" " ],\n" - "};", FourSpaces); + "};", + FourSpaces); } TEST_F(FormatTestJS, BackslashesInComments) { Index: clang/unittests/Format/FormatTestJava.cpp =================================================================== --- clang/unittests/Format/FormatTestJava.cpp +++ clang/unittests/Format/FormatTestJava.cpp @@ -337,12 +337,12 @@ "List list;"); verifyFormat( - "@Test\n" - "@Feature({\"Android-TabSwitcher\"})\n" - "@CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE})\n" - "@Features.EnableFeatures({FEATURE})\n" - "public void test(@Foo.bar(\"baz\") @Quux.Qoob int theFirstParaaaaam,\n" - " @Foo.bar(\"baz\") @Quux.Qoob int theSecondParaaaaaaaaaaaaaaaam) {}"); + "@Test\n" + "@Feature({\"Android-TabSwitcher\"})\n" + "@CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE})\n" + "@Features.EnableFeatures({FEATURE})\n" + "public void test(@Foo.bar(\"baz\") @Quux.Qoob int theFirstParaaaaam,\n" + " @Foo.bar(\"baz\") @Quux.Qoob int theSecondParaaaaaaaaaaaaaaaam) {}"); } TEST_F(FormatTestJava, Generics) { @@ -460,19 +460,18 @@ } TEST_F(FormatTestJava, MethodReference) { - EXPECT_EQ( - "private void foo() {\n" - " f(this::methodReference);\n" - " f(C.super::methodReference);\n" - " Consumer c = System.out::println;\n" - " Iface mRef = Ty::meth;\n" - "}", - format("private void foo() {\n" - " f(this ::methodReference);\n" - " f(C.super ::methodReference);\n" - " Consumer c = System.out ::println;\n" - " Iface mRef = Ty :: meth;\n" - "}")); + EXPECT_EQ("private void foo() {\n" + " f(this::methodReference);\n" + " f(C.super::methodReference);\n" + " Consumer c = System.out::println;\n" + " Iface mRef = Ty::meth;\n" + "}", + format("private void foo() {\n" + " f(this ::methodReference);\n" + " f(C.super ::methodReference);\n" + " Consumer c = System.out ::println;\n" + " Iface mRef = Ty :: meth;\n" + "}")); } TEST_F(FormatTestJava, CppKeywords) { @@ -575,16 +574,15 @@ } TEST_F(FormatTestJava, RetainsLogicalShifts) { - verifyFormat("void f() {\n" - " int a = 1;\n" - " a >>>= 1;\n" - "}"); - verifyFormat("void f() {\n" - " int a = 1;\n" - " a = a >>> 1;\n" - "}"); + verifyFormat("void f() {\n" + " int a = 1;\n" + " a >>>= 1;\n" + "}"); + verifyFormat("void f() {\n" + " int a = 1;\n" + " a = a >>> 1;\n" + "}"); } - -} // end namespace tooling +} // namespace format } // end namespace clang Index: clang/unittests/Format/FormatTestObjC.cpp =================================================================== --- clang/unittests/Format/FormatTestObjC.cpp +++ clang/unittests/Format/FormatTestObjC.cpp @@ -31,11 +31,7 @@ Style.Language = FormatStyle::LK_ObjC; } - enum StatusCheck { - SC_ExpectComplete, - SC_ExpectIncomplete, - SC_DoNotCheck - }; + enum StatusCheck { SC_ExpectComplete, SC_ExpectIncomplete, SC_DoNotCheck }; std::string format(llvm::StringRef Code, StatusCheck CheckComplete = SC_ExpectComplete) { @@ -69,24 +65,28 @@ }; TEST(FormatTestObjCStyle, DetectsObjCInHeaders) { - auto Style = getStyle("LLVM", "a.h", "none", "@interface\n" - "- (id)init;"); + auto Style = getStyle("LLVM", "a.h", "none", + "@interface\n" + "- (id)init;"); ASSERT_TRUE((bool)Style); EXPECT_EQ(FormatStyle::LK_ObjC, Style->Language); - Style = getStyle("LLVM", "a.h", "none", "@interface\n" - "+ (id)init;"); + Style = getStyle("LLVM", "a.h", "none", + "@interface\n" + "+ (id)init;"); ASSERT_TRUE((bool)Style); EXPECT_EQ(FormatStyle::LK_ObjC, Style->Language); - Style = getStyle("LLVM", "a.h", "none", "@interface\n" - "@end\n" - "//comment"); + Style = getStyle("LLVM", "a.h", "none", + "@interface\n" + "@end\n" + "//comment"); ASSERT_TRUE((bool)Style); EXPECT_EQ(FormatStyle::LK_ObjC, Style->Language); - Style = getStyle("LLVM", "a.h", "none", "@interface\n" - "@end //comment"); + Style = getStyle("LLVM", "a.h", "none", + "@interface\n" + "@end //comment"); ASSERT_TRUE((bool)Style); EXPECT_EQ(FormatStyle::LK_ObjC, Style->Language); @@ -113,13 +113,12 @@ ASSERT_TRUE((bool)Style); EXPECT_EQ(FormatStyle::LK_Cpp, Style->Language); - Style = - getStyle("{}", "a.h", "none", "typedef NS_ENUM(int, Foo) {};\n"); + Style = getStyle("{}", "a.h", "none", "typedef NS_ENUM(int, Foo) {};\n"); ASSERT_TRUE((bool)Style); EXPECT_EQ(FormatStyle::LK_ObjC, Style->Language); - Style = getStyle("{}", "a.h", "none", - "typedef NS_CLOSED_ENUM(int, Foo) {};\n"); + Style = + getStyle("{}", "a.h", "none", "typedef NS_CLOSED_ENUM(int, Foo) {};\n"); ASSERT_TRUE((bool)Style); EXPECT_EQ(FormatStyle::LK_ObjC, Style->Language); @@ -603,7 +602,7 @@ " bbb:(d)cccc;"); verifyFormat("- (void)drawRectOn:(id)surface ofSize:(aaa)height:(bbb)width;"); - // BraceWrapping AfterFunction is respected for ObjC methods + // BraceWrapping AfterFunction is respected for ObjC methods Style = getGoogleStyle(FormatStyle::LK_ObjC); Style.BreakBeforeBraces = FormatStyle::BS_Custom; Style.BraceWrapping.AfterFunction = true; @@ -946,14 +945,16 @@ verifyFormat("[self performSelector:@selector(loadAccessories)\n" " withObjectOnMainThread:nil\n" " waitUntilDone:false];"); - verifyFormat("[aaaaaaaaaaaaaaaaaaaaaaaaa\n" - " performSelectorOnMainThread:@selector(loadAccessories)\n" - " withObject:nil\n" - " waitUntilDone:false];"); - verifyFormat("[self // force wrapping\n" - " performSelectorOnMainThread:@selector(loadAccessories)\n" - " withObject:nil\n" - " waitUntilDone:false];"); + verifyFormat( + "[aaaaaaaaaaaaaaaaaaaaaaaaa\n" + " performSelectorOnMainThread:@selector(loadAccessories)\n" + " withObject:nil\n" + " waitUntilDone:false];"); + verifyFormat( + "[self // force wrapping\n" + " performSelectorOnMainThread:@selector(loadAccessories)\n" + " withObject:nil\n" + " waitUntilDone:false];"); } TEST_F(FormatTestObjC, ObjCAt) { @@ -1374,7 +1375,7 @@ // verifyFormat("x = ([a foo:bar] >> b->c == 'd');"); } -TEST_F(FormatTestObjC, DisambiguatesCallsFromStructuredBindings) { +TEST_F(FormatTestObjC, DisambiguatesCallsFromStructuredBindings) { verifyFormat("int f() {\n" " if (a && [f arg])\n" " return 0;\n" Index: clang/unittests/Format/FormatTestProto.cpp =================================================================== --- clang/unittests/Format/FormatTestProto.cpp +++ clang/unittests/Format/FormatTestProto.cpp @@ -667,6 +667,5 @@ "}"); } - -} // end namespace tooling +} // namespace format } // end namespace clang Index: clang/unittests/Format/FormatTestRawStrings.cpp =================================================================== --- clang/unittests/Format/FormatTestRawStrings.cpp +++ clang/unittests/Format/FormatTestRawStrings.cpp @@ -140,7 +140,9 @@ FormatStyle Style = getGoogleStyle(FormatStyle::LK_Cpp); EXPECT_EQ(0, parseConfiguration("---\n" "Language: Cpp\n" - "BasedOnStyle: Google", &Style).value()); + "BasedOnStyle: Google", + &Style) + .value()); Style.RawStringFormats = {{ FormatStyle::LK_Cpp, {"cpp"}, @@ -178,26 +180,18 @@ } TEST_F(FormatTestRawStrings, ReformatsShortRawStringsOnSingleLine) { - expect_eq( - R"test(P p = TP(R"pb()pb");)test", - format( - R"test(P p = TP(R"pb( )pb");)test", - getRawStringPbStyleWithColumns(40))); - expect_eq( - R"test(P p = TP(R"pb(item_1: 1)pb");)test", - format( - R"test(P p = TP(R"pb(item_1:1)pb");)test", - getRawStringPbStyleWithColumns(40))); - expect_eq( - R"test(P p = TP(R"pb(item_1: 1)pb");)test", - format( - R"test(P p = TP(R"pb( item_1 : 1 )pb");)test", - getRawStringPbStyleWithColumns(40))); - expect_eq( - R"test(P p = TP(R"pb(item_1: 1 item_2: 2)pb");)test", - format( - R"test(P p = TP(R"pb(item_1:1 item_2:2)pb");)test", - getRawStringPbStyleWithColumns(40))); + expect_eq(R"test(P p = TP(R"pb()pb");)test", + format(R"test(P p = TP(R"pb( )pb");)test", + getRawStringPbStyleWithColumns(40))); + expect_eq(R"test(P p = TP(R"pb(item_1: 1)pb");)test", + format(R"test(P p = TP(R"pb(item_1:1)pb");)test", + getRawStringPbStyleWithColumns(40))); + expect_eq(R"test(P p = TP(R"pb(item_1: 1)pb");)test", + format(R"test(P p = TP(R"pb( item_1 : 1 )pb");)test", + getRawStringPbStyleWithColumns(40))); + expect_eq(R"test(P p = TP(R"pb(item_1: 1 item_2: 2)pb");)test", + format(R"test(P p = TP(R"pb(item_1:1 item_2:2)pb");)test", + getRawStringPbStyleWithColumns(40))); // Merge two short lines into one. expect_eq(R"test( std::string s = R"pb( @@ -219,10 +213,10 @@ expect_eq(R"test( P p = TP(R"pb(item_1 < 1 > item_2: { 2 })pb");)test", - format( - R"test( + format( + R"test( P p = TP(R"pb(item_1<1> item_2:{2})pb");)test", - getRawStringPbStyleWithColumns(40))); + getRawStringPbStyleWithColumns(40))); } TEST_F(FormatTestRawStrings, BreaksRawStringsExceedingColumnLimit) { @@ -247,9 +241,9 @@ P p = TP(R"pb(item_1 < 1 > item_2: < 2 > item_3 {})pb");)test", - format(R"test( + format(R"test( P p = TP(R"pb(item_1<1> item_2:<2> item_3{ })pb");)test", - getRawStringPbStyleWithColumns(40))); + getRawStringPbStyleWithColumns(40))); expect_eq( R"test( @@ -552,7 +546,6 @@ format(R"test( ASSERT_TRUE(ParseFromString(R"pb(item_1: 1 item_2: 2)pb"), ptr);)test", getRawStringPbStyleWithColumns(40))); - } TEST_F(FormatTestRawStrings, RawStringsInOperands) { @@ -683,7 +676,6 @@ auto S=(count<3)?R"pb(item_1:1)pb":R"pb(item_2:2,item_3:3)pb"; )test", getRawStringPbStyleWithColumns(40))); - } TEST_F(FormatTestRawStrings, PrefixAndSuffixAlignment) { @@ -770,8 +762,7 @@ TEST_F(FormatTestRawStrings, FormatsRawStringsWithEnclosingFunctionName) { FormatStyle Style = getRawStringPbStyleWithColumns(40); - Style.RawStringFormats[0].EnclosingFunctions.push_back( - "PARSE_TEXT_PROTO"); + Style.RawStringFormats[0].EnclosingFunctions.push_back("PARSE_TEXT_PROTO"); Style.RawStringFormats[0].EnclosingFunctions.push_back("ParseTextProto"); expect_eq(R"test(a = PARSE_TEXT_PROTO(R"(key: value)");)test", format(R"test(a = PARSE_TEXT_PROTO(R"(key:value)");)test", Style)); @@ -816,7 +807,8 @@ xxxxxxxaaaaax wwwwwww = _Verxrrrrrrrr(PARSE_TEXT_PROTO(R"pb( Category: aaaaaaaaaaaaaaaaaaaaaaaaaa )pb")); -)test", Style)); +)test", + Style)); // The '(' in R"pb is at column 61, break. expect_eq(R"test( xxxxxxxaaaaax wwwwwww = @@ -828,14 +820,15 @@ xxxxxxxaaaaax wwwwwww = _Verxrrrrrrrrr(PARSE_TEXT_PROTO(R"pb( Category: aaaaaaaaaaaaaaaaaaaaaaaaaa )pb")); -)test", Style)); +)test", + Style)); } TEST_F(FormatTestRawStrings, KeepsRBraceFolloedByMoreLBracesOnSameLine) { FormatStyle Style = getRawStringPbStyleWithColumns(80); expect_eq( - R"test( + R"test( int f() { if (1) { TTTTTTTTTTTTTTTTTTTTT s = PARSE_TEXT_PROTO(R"pb( @@ -849,8 +842,8 @@ } } )test", - format( - R"test( + format( + R"test( int f() { if (1) { TTTTTTTTTTTTTTTTTTTTT s = PARSE_TEXT_PROTO(R"pb( @@ -862,14 +855,13 @@ } } )test", - Style)); + Style)); } TEST_F(FormatTestRawStrings, DoNotFormatUnrecognizedDelimitersInRecognizedFunctions) { FormatStyle Style = getRawStringPbStyleWithColumns(60); - Style.RawStringFormats[0].EnclosingFunctions.push_back( - "EqualsProto"); + Style.RawStringFormats[0].EnclosingFunctions.push_back("EqualsProto"); // EqualsProto is a recognized function, but the Raw delimiter is // unrecognized. Do not touch the string in this case, since it might be // special. @@ -933,7 +925,7 @@ } )test", Style)); - + expect_eq(R"test( int f() { int a = g(x, @@ -978,7 +970,8 @@ int f() { int a = g(R"pb(key: 1)pb", 2); -})test", Style)); +})test", + Style)); } TEST_F(FormatTestRawStrings, IndentsLastParamAfterNewline) { Index: clang/unittests/Format/FormatTestSelective.cpp =================================================================== --- clang/unittests/Format/FormatTestSelective.cpp +++ clang/unittests/Format/FormatTestSelective.cpp @@ -122,7 +122,8 @@ "int b;", format("int a; // comment\n" "// comment 2\n" - "int b;", 28, 0)); + "int b;", + 28, 0)); EXPECT_EQ("int aaaaaa; // comment\n" "int b;\n" "int c; // unrelated comment", @@ -585,14 +586,13 @@ TEST_F(FormatTestSelective, SelectivelyRequoteJavaScript) { Style = getGoogleStyle(FormatStyle::LK_JavaScript); - EXPECT_EQ( - "var x = \"a\";\n" - "var x = 'a';\n" - "var x = \"a\";", - format("var x = \"a\";\n" - "var x = \"a\";\n" - "var x = \"a\";", - 20, 0)); + EXPECT_EQ("var x = \"a\";\n" + "var x = 'a';\n" + "var x = \"a\";", + format("var x = \"a\";\n" + "var x = \"a\";\n" + "var x = \"a\";", + 20, 0)); } TEST_F(FormatTestSelective, KeepsIndentAfterCommentSectionImport) { Index: clang/unittests/Format/FormatTestTextProto.cpp =================================================================== --- clang/unittests/Format/FormatTestTextProto.cpp +++ clang/unittests/Format/FormatTestTextProto.cpp @@ -199,7 +199,7 @@ "field_c: {}"); verifyFormat("field_a < field_b: 1 >,\n" - "msg_fid: < fiel_b: 123 >,\n" + "msg_fid: < fiel_b: 123 >,\n" "field_c <>"); verifyFormat("field_a < field_b: 1 >\n" @@ -450,14 +450,16 @@ " bbbbbbbbbbbbbb] { key: value }"); // These go over the column limit intentionally, since the alternative // [aa..a\n] is worse. - verifyFormat("[aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa] {\n" - " key: value\n" - "}"); - verifyFormat("[aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa] {\n" - " [type.type] {\n" - " keyyyyyyyyyyyyyy: valuuuuuuuuuuuuuuuuuuuuuuuuue\n" - " }\n" - "}"); + verifyFormat( + "[aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa] {\n" + " key: value\n" + "}"); + verifyFormat( + "[aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa] {\n" + " [type.type] {\n" + " keyyyyyyyyyyyyyy: valuuuuuuuuuuuuuuuuuuuuuuuuue\n" + " }\n" + "}"); verifyFormat("[aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/\n" " bbbbbbb] {\n" " [type.type] {\n" @@ -517,8 +519,7 @@ " 'long'\n" " ]\n" "}\n" - "key: value" - ); + "key: value"); FormatStyle Style = getGoogleStyle(FormatStyle::LK_TextProto); Style.ColumnLimit = 60; // To make writing tests easier. Style.Cpp11BracedListStyle = true; @@ -555,7 +556,8 @@ " key: value\n" " key: value\n" " }\n" - "}", Style); + "}", + Style); } TEST_F(FormatTestTextProto, BreaksAfterBraceFollowedByClosingBraceOnNextLine) { @@ -734,5 +736,5 @@ "}"); } -} // end namespace tooling +} // namespace format } // end namespace clang Index: clang/unittests/Format/NamespaceEndCommentsFixerTest.cpp =================================================================== --- clang/unittests/Format/NamespaceEndCommentsFixerTest.cpp +++ clang/unittests/Format/NamespaceEndCommentsFixerTest.cpp @@ -423,8 +423,7 @@ TEST_F(NamespaceEndCommentsFixerTest, DoesNotAddEndCommentForShortNamespace) { EXPECT_EQ("namespace {}", fixNamespaceEndComments("namespace {}")); EXPECT_EQ("namespace A {}", fixNamespaceEndComments("namespace A {}")); - EXPECT_EQ("namespace A { a }", - fixNamespaceEndComments("namespace A { a }")); + EXPECT_EQ("namespace A { a }", fixNamespaceEndComments("namespace A { a }")); EXPECT_EQ("namespace A { a };", fixNamespaceEndComments("namespace A { a };")); } Index: clang/unittests/Format/SortIncludesTest.cpp =================================================================== --- clang/unittests/Format/SortIncludesTest.cpp +++ clang/unittests/Format/SortIncludesTest.cpp @@ -38,8 +38,7 @@ return *Result; } - std::string sort(StringRef Code, - StringRef FileName = "input.cpp", + std::string sort(StringRef Code, StringRef FileName = "input.cpp", unsigned ExpectedNumRanges = 1) { return sort(Code, GetCodeRange(Code), FileName, ExpectedNumRanges); } @@ -227,7 +226,8 @@ "#include \n" "#include \n" "#include \n" - "/* clang-format onwards */\n", "input.h", 2)); + "/* clang-format onwards */\n", + "input.h", 2)); } TEST_F(SortIncludesTest, IncludeSortingCanBeDisabled) { @@ -291,7 +291,8 @@ sort("#include \"a.h\"\n" "#include \"c.h\"\n" "\n" - "#include \"b.h\"\n", "input.h", 0)); + "#include \"b.h\"\n", + "input.h", 0)); } TEST_F(SortIncludesTest, SortsAllBlocksWhenMerging) { @@ -762,7 +763,8 @@ sort("", "input.h", 0)); + "-->", + "input.h", 0)); } TEST_F(SortIncludesTest, DoNotOutputReplacementsForSortedBlocksWithRegrouping) { Index: clang/unittests/Format/UsingDeclarationsSorterTest.cpp =================================================================== --- clang/unittests/Format/UsingDeclarationsSorterTest.cpp +++ clang/unittests/Format/UsingDeclarationsSorterTest.cpp @@ -343,7 +343,8 @@ {tooling::Range(19, 1)})); } -TEST_F(UsingDeclarationsSorterTest, SortsUsingDeclarationsWithLeadingkComments) { +TEST_F(UsingDeclarationsSorterTest, + SortsUsingDeclarationsWithLeadingkComments) { EXPECT_EQ("/* comment */ using a;\n" "/* comment */ using b;", sortUsingDeclarations("/* comment */ using b;\n" @@ -366,7 +367,6 @@ "using e;\n" "using a;\n" "using e;")); - } } // end namespace