[clang] 1dd31eb - [clang-format][NFC] Refactor unit tests for "LambdaBodyIndentation: OuterScope"
Owen Pan via cfe-commits
cfe-commits at lists.llvm.org
Sat Apr 1 19:36:06 PDT 2023
Author: Jon Phillips
Date: 2023-04-01T19:35:49-07:00
New Revision: 1dd31ebe5418d9581f152dcb6cbc4aed66ac9472
URL: https://github.com/llvm/llvm-project/commit/1dd31ebe5418d9581f152dcb6cbc4aed66ac9472
DIFF: https://github.com/llvm/llvm-project/commit/1dd31ebe5418d9581f152dcb6cbc4aed66ac9472.diff
LOG: [clang-format][NFC] Refactor unit tests for "LambdaBodyIndentation: OuterScope"
Differential Revision: https://reviews.llvm.org/D146995
Added:
Modified:
clang/unittests/Format/FormatTest.cpp
Removed:
################################################################################
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index 1c960eb28ef9..8d009d6a33a4 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -21956,51 +21956,59 @@ TEST_F(FormatTest, FormatsLambdas) {
LLVMWithBeforeLambdaBody);
// Lambdas with
diff erent indentation styles.
- Style = getLLVMStyleWithColumns(100);
- EXPECT_EQ("SomeResult doSomething(SomeObject promise) {\n"
- " return promise.then(\n"
- " [this, &someVariable, someObject = "
- "std::mv(s)](std::vector<int> 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<int> 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<int> 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<int> 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.
More information about the cfe-commits
mailing list