clang-format: Use AllowShortBlocksOnASingleLine for ObjC blocks, too.

llvm-svn: 220375
This commit is contained in:
Daniel Jasper 2014-10-22 09:12:44 +00:00
parent b52c69e567
commit 76284683f1
2 changed files with 29 additions and 15 deletions

View File

@ -1782,6 +1782,9 @@ bool TokenAnnotator::mustBreakBefore(const AnnotatedLine &Line,
} else if (Style.Language == FormatStyle::LK_Proto &&
Left.isNot(tok::l_brace) && Right.Type == TT_SelectorName) {
return true;
} else if (Left.Type == TT_ObjCBlockLBrace &&
!Style.AllowShortBlocksOnASingleLine) {
return true;
}
// If the last token before a '}' is a comma or a trailing comment, the

View File

@ -9154,24 +9154,35 @@ TEST_F(FormatTest, FormatsLambdas) {
}
TEST_F(FormatTest, FormatsBlocks) {
verifyFormat("int (^Block)(int, int);");
verifyFormat("int (^Block1)(int, int) = ^(int i, int j)");
verifyFormat("void (^block)(int) = ^(id test) { int i; };");
verifyFormat("void (^block)(int) = ^(int test) { int i; };");
verifyFormat("void (^block)(int) = ^id(int test) { int i; };");
verifyFormat("void (^block)(int) = ^int(int test) { int i; };");
FormatStyle ShortBlocks = getLLVMStyle();
ShortBlocks.AllowShortBlocksOnASingleLine = true;
verifyFormat("int (^Block)(int, int);", ShortBlocks);
verifyFormat("int (^Block1)(int, int) = ^(int i, int j)", ShortBlocks);
verifyFormat("void (^block)(int) = ^(id test) { int i; };", ShortBlocks);
verifyFormat("void (^block)(int) = ^(int test) { int i; };", ShortBlocks);
verifyFormat("void (^block)(int) = ^id(int test) { int i; };", ShortBlocks);
verifyFormat("void (^block)(int) = ^int(int test) { int i; };", ShortBlocks);
verifyFormat("foo(^{ bar(); });");
verifyFormat("foo(a, ^{ bar(); });");
verifyFormat("{ void (^block)(Object *x); }");
verifyFormat("foo(^{ bar(); });", ShortBlocks);
verifyFormat("foo(a, ^{ bar(); });", ShortBlocks);
verifyFormat("{ void (^block)(Object *x); }", ShortBlocks);
verifyFormat("[operation setCompletionBlock:^{ [self onOperationDone]; }];");
verifyFormat("int i = {[operation setCompletionBlock:^{ [self "
"onOperationDone]; }]};");
verifyFormat("[operation setCompletionBlock:^(int *i) { f(); }];");
verifyFormat("int a = [operation block:^int(int *i) { return 1; }];");
verifyFormat("[operation setCompletionBlock:^{\n"
" [self onOperationDone];\n"
"}];");
verifyFormat("int i = {[operation setCompletionBlock:^{\n"
" [self onOperationDone];\n"
"}]};");
verifyFormat("[operation setCompletionBlock:^(int *i) {\n"
" f();\n"
"}];");
verifyFormat("int a = [operation block:^int(int *i) {\n"
" return 1;\n"
"}];");
verifyFormat("[myObject doSomethingWith:arg1\n"
" aaa:^int(int *a) { return 1; }\n"
" aaa:^int(int *a) {\n"
" return 1;\n"
" }\n"
" bbb:f(a * bbbbbbbb)];");
verifyFormat("[operation setCompletionBlock:^{\n"