summaryrefslogtreecommitdiffstats
path: root/clang/unittests/Format
diff options
context:
space:
mode:
authorMitchell Balan <mitchell@stellarscience.com>2020-01-06 09:21:41 -0500
committerMitchell Balan <mitchell@stellarscience.com>2020-01-06 09:21:41 -0500
commitd45aafa2fbcf66f3dafdc7c5e0a0ce3709914cbc (patch)
treeafa25c852bd5b4db55025aaa116b9f027ee4764d /clang/unittests/Format
parentde735247c8b638efa8ce5783ac8c7c2e0b7cf3eb (diff)
downloadbcm5719-llvm-d45aafa2fbcf66f3dafdc7c5e0a0ce3709914cbc.tar.gz
bcm5719-llvm-d45aafa2fbcf66f3dafdc7c5e0a0ce3709914cbc.zip
[clang-format] fix conflict between FormatStyle::BWACS_MultiLine and BeforeCatch/BeforeElse
Summary: Found a bug introduced with BraceWrappingFlags AfterControlStatement MultiLine. This feature conflicts with the existing BeforeCatch and BeforeElse flags. For example, our team uses BeforeElse. if (foo || bar) { doSomething(); } else { doSomethingElse(); } If we enable MultiLine (which we'd really love to do) we expect it to work like this: if (foo || bar) { doSomething(); } else { doSomethingElse(); } What we actually get is: if (foo || bar) { doSomething(); } else { doSomethingElse(); } Reviewers: MyDeveloperDay, Bouska, mitchell-stellar Patch by: pastey Subscribers: Bouska, cfe-commits Tags: clang Differential Revision: https://reviews.llvm.org/D71939
Diffstat (limited to 'clang/unittests/Format')
-rw-r--r--clang/unittests/Format/FormatTest.cpp37
1 files changed, 36 insertions, 1 deletions
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index 069542683c0..2d67b9759d7 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -1565,6 +1565,41 @@ TEST_F(FormatTest, MultiLineControlStatements) {
" baz();\n"
"}",
format("try{foo();}catch(Exception&bar){baz();}", Style));
+ Style.ColumnLimit =
+ 40; // to concentrate at brace wrapping, not line wrap due to column limit
+ EXPECT_EQ("try {\n"
+ " foo();\n"
+ "} catch (Exception &bar) {\n"
+ " baz();\n"
+ "}",
+ format("try{foo();}catch(Exception&bar){baz();}", Style));
+ Style.ColumnLimit =
+ 20; // to concentrate at brace wrapping, not line wrap due to column limit
+
+ Style.BraceWrapping.BeforeElse = true;
+ EXPECT_EQ(
+ "if (foo) {\n"
+ " bar();\n"
+ "}\n"
+ "else if (baz ||\n"
+ " quux)\n"
+ "{\n"
+ " foobar();\n"
+ "}\n"
+ "else {\n"
+ " barbaz();\n"
+ "}",
+ format("if(foo){bar();}else if(baz||quux){foobar();}else{barbaz();}",
+ Style));
+
+ Style.BraceWrapping.BeforeCatch = true;
+ EXPECT_EQ("try {\n"
+ " foo();\n"
+ "}\n"
+ "catch (...) {\n"
+ " baz();\n"
+ "}",
+ format("try{foo();}catch(...){baz();}", Style));
}
//===----------------------------------------------------------------------===//
@@ -14881,7 +14916,7 @@ TEST_F(FormatTest, AmbersandInLamda) {
verifyFormat("auto lambda = [&a = a]() { a = 2; };", AlignStyle);
}
- TEST_F(FormatTest, SpacesInConditionalStatement) {
+TEST_F(FormatTest, SpacesInConditionalStatement) {
FormatStyle Spaces = getLLVMStyle();
Spaces.SpacesInConditionalStatement = true;
verifyFormat("for ( int i = 0; i; i++ )\n continue;", Spaces);
OpenPOWER on IntegriCloud