From: Jon Phillips Date: Sun, 2 Apr 2023 02:21:41 +0000 (-0700) Subject: [clang-format][NFC] Refactor unit tests for "LambdaBodyIndentation: OuterScope" X-Git-Tag: upstream/17.0.6~12950 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=1dd31ebe5418d9581f152dcb6cbc4aed66ac9472;p=platform%2Fupstream%2Fllvm.git [clang-format][NFC] Refactor unit tests for "LambdaBodyIndentation: OuterScope" Differential Revision: https://reviews.llvm.org/D146995 --- diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index 1c960eb..8d009d6 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -21956,51 +21956,59 @@ TEST_F(FormatTest, FormatsLambdas) { 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" @@ -22008,8 +22016,8 @@ TEST_F(FormatTest, FormatsLambdas) { " .foo();\n" "}", Style); - verifyFormat("test() {\n" - " ([]() -> {\n" + verifyFormat("void test() {\n" + " ([]() -> auto {\n" " int b = 32;\n" " return 3;\n" " })\n" @@ -22017,51 +22025,14 @@ TEST_F(FormatTest, FormatsLambdas) { " .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.