diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -21914,51 +21914,59 @@ LLVMWithBeforeLambdaBody); // Lambdas with different indentation styles. - Style = getLLVMStyleWithColumns(100); - EXPECT_EQ("SomeResult doSomething(SomeObject promise) {\n" - " return promise.then(\n" - " [this, &someVariable, someObject = " - "std::mv(s)](std::vector evaluated) mutable {\n" - " return someObject.startAsyncAction().then(\n" - " [this, &someVariable](AsyncActionResult result) " - "mutable { result.processMore(); });\n" - " });\n" - "}\n", - format("SomeResult doSomething(SomeObject promise) {\n" - " return promise.then([this, &someVariable, someObject = " - "std::mv(s)](std::vector evaluated) mutable {\n" - " return someObject.startAsyncAction().then([this, " - "&someVariable](AsyncActionResult result) mutable {\n" - " result.processMore();\n" - " });\n" - " });\n" - "}\n", - Style)); + Style = getLLVMStyleWithColumns(60); + verifyFormat("Result doSomething(Promise promise) {\n" + " return promise.then(\n" + " [this, obj = std::move(s)](int bar) mutable {\n" + " return someObject.startAsyncAction().then(\n" + " [this, &obj](Result result) mutable {\n" + " result.processMore();\n" + " });\n" + " });\n" + "}\n", + Style); Style.LambdaBodyIndentation = FormatStyle::LBI_OuterScope; - verifyFormat("test() {\n" - " ([]() -> {\n" + verifyFormat("Result doSomething(Promise promise) {\n" + " return promise.then(\n" + " [this, obj = std::move(s)](int bar) mutable {\n" + " return obj.startAsyncAction().then(\n" + " [this, &obj](Result result) mutable {\n" + " result.processMore();\n" + " });\n" + " });\n" + "}\n", + Style); + verifyFormat("Result doSomething(Promise promise) {\n" + " return promise.then([this, obj = std::move(s)] {\n" + " return obj.startAsyncAction().then(\n" + " [this, &obj](Result result) mutable {\n" + " result.processMore();\n" + " });\n" + " });\n" + "}\n", + Style); + verifyFormat("void test() {\n" + " ([]() -> auto {\n" " int b = 32;\n" " return 3;\n" " }).foo();\n" "}", Style); - verifyFormat("test() {\n" - " []() -> {\n" + verifyFormat("void test() {\n" + " []() -> auto {\n" " int b = 32;\n" " return 3;\n" " }\n" "}", Style); verifyFormat("std::sort(v.begin(), v.end(),\n" - " [](const auto &someLongArgumentName, const auto " - "&someOtherLongArgumentName) {\n" - " return someLongArgumentName.someMemberVariable < " - "someOtherLongArgumentName.someMemberVariable;\n" - "});", + " [](const auto &foo, const auto &bar) {\n" + " return foo.baz < bar.baz;\n" + "});\n", Style); - verifyFormat("test() {\n" + verifyFormat("void test() {\n" " (\n" - " []() -> {\n" + " []() -> auto {\n" " int b = 32;\n" " return 3;\n" " },\n" @@ -21966,8 +21974,8 @@ " .foo();\n" "}", Style); - verifyFormat("test() {\n" - " ([]() -> {\n" + verifyFormat("void test() {\n" + " ([]() -> auto {\n" " int b = 32;\n" " return 3;\n" " })\n" @@ -21975,51 +21983,14 @@ " .bar();\n" "}", Style); - EXPECT_EQ("SomeResult doSomething(SomeObject promise) {\n" - " return promise.then(\n" - " [this, &someVariable, someObject = " - "std::mv(s)](std::vector evaluated) mutable {\n" - " return someObject.startAsyncAction().then(\n" - " [this, &someVariable](AsyncActionResult result) mutable { " - "result.processMore(); });\n" - " });\n" - "}\n", - format("SomeResult doSomething(SomeObject promise) {\n" - " return promise.then([this, &someVariable, someObject = " - "std::mv(s)](std::vector evaluated) mutable {\n" - " return someObject.startAsyncAction().then([this, " - "&someVariable](AsyncActionResult result) mutable {\n" - " result.processMore();\n" - " });\n" - " });\n" - "}\n", - Style)); - EXPECT_EQ("SomeResult doSomething(SomeObject promise) {\n" - " return promise.then([this, &someVariable] {\n" - " return someObject.startAsyncAction().then(\n" - " [this, &someVariable](AsyncActionResult result) mutable { " - "result.processMore(); });\n" - " });\n" - "}\n", - format("SomeResult doSomething(SomeObject promise) {\n" - " return promise.then([this, &someVariable] {\n" - " return someObject.startAsyncAction().then([this, " - "&someVariable](AsyncActionResult result) mutable {\n" - " result.processMore();\n" - " });\n" - " });\n" - "}\n", - Style)); Style = getGoogleStyle(); Style.LambdaBodyIndentation = FormatStyle::LBI_OuterScope; - EXPECT_EQ("#define A \\\n" - " [] { \\\n" - " xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx( \\\n" - " xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx); \\\n" - " }", - format("#define A [] { xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx( \\\n" - "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx); }", - Style)); + verifyFormat("#define A \\\n" + " [] { \\\n" + " xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx( \\\n" + " xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx); \\\n" + " }", + Style); // TODO: The current formatting has a minor issue that's not worth fixing // right now whereby the closing brace is indented relative to the signature // instead of being aligned. This only happens with macros.