clang-format: Keep '{' of dict literals on the same line in Allman style

Before:
  void f()
  {
    [object
        someMethod:@
        { @"a" : @"b" }];
  }

After:
  void f()
  {
    [object someMethod:@{ @"a" : @"b" }];
  }

This fixes llvm.org/PR19854.

llvm-svn: 209615
This commit is contained in:
Daniel Jasper 2014-05-26 07:24:34 +00:00
parent 10743a9e6d
commit ba1b6bb667
2 changed files with 12 additions and 4 deletions

View File

@ -1596,7 +1596,7 @@ bool TokenAnnotator::mustBreakBefore(const AnnotatedLine &Line,
!Style.ConstructorInitializerAllOnOneLineOrOnePerLine) {
return true;
} else if (Right.is(tok::l_brace) && Right.BlockKind == BK_Block &&
Right.Type != TT_ObjCBlockLBrace) {
Right.Type != TT_ObjCBlockLBrace && Right.Type != TT_DictLiteral) {
return Style.BreakBeforeBraces == FormatStyle::BS_Allman ||
Style.BreakBeforeBraces == FormatStyle::BS_GNU;
} else if (Right.is(tok::string_literal) &&

View File

@ -7698,15 +7698,23 @@ TEST_F(FormatTest, AllmanBraceBreaking) {
"#endif",
BreakBeforeBrace);
// This shouldn't affect ObjC blocks.
// This shouldn't affect ObjC blocks..
verifyFormat("[self doSomeThingWithACompletionHandler:^{\n"
" // ...\n"
" int i;\n"
"}];");
"}];",
BreakBeforeBrace);
verifyFormat("void (^block)(void) = ^{\n"
" // ...\n"
" int i;\n"
"};");
"};",
BreakBeforeBrace);
// .. or dict literals.
verifyFormat("void f()\n"
"{\n"
" [object someMethod:@{ @\"a\" : @\"b\" }];\n"
"}",
BreakBeforeBrace);
BreakBeforeBrace.ColumnLimit = 19;
verifyFormat("void f() { int i; }", BreakBeforeBrace);