clang-format: [Proto] Use more compact format for text-formatted options

Before:
  enum Type {
    UNKNOWN = 0 [(some_options) = {
      a: aa,
      b: bb
    }];
  };

After:
  enum Type {
    UNKNOWN = 0 [(some_options) = {a: aa, b: bb}];
  };

llvm-svn: 273553
This commit is contained in:
Daniel Jasper 2016-06-23 09:40:19 +00:00
parent e6ca7b6a6b
commit 7f3b99fca7
2 changed files with 5 additions and 8 deletions

View File

@ -2332,9 +2332,6 @@ bool TokenAnnotator::mustBreakBefore(const AnnotatedLine &Line,
return (Line.startsWith(tok::kw_enum) && Style.BraceWrapping.AfterEnum) ||
(Line.startsWith(tok::kw_class) && Style.BraceWrapping.AfterClass) ||
(Line.startsWith(tok::kw_struct) && Style.BraceWrapping.AfterStruct);
if (Style.Language == FormatStyle::LK_Proto && Left.isNot(tok::l_brace) &&
Right.is(TT_SelectorName))
return true;
if (Left.is(TT_ObjCBlockLBrace) && !Style.AllowShortBlocksOnASingleLine)
return true;

View File

@ -73,9 +73,12 @@ TEST_F(FormatTestProto, FormatsEnums) {
" TYPE_A = 1;\n"
" TYPE_B = 2;\n"
"};");
verifyFormat("enum Type {\n"
" UNKNOWN = 0 [(some_options) = {a: aa, b: bb}];\n"
"};");
verifyFormat("enum Type {\n"
" UNKNOWN = 0 [(some_options) = {\n"
" a: aa,\n"
" a: aa, // wrap\n"
" b: bb\n"
" }];\n"
"};");
@ -153,10 +156,7 @@ TEST_F(FormatTestProto, FormatsOptions) {
" field_a: OK\n"
" field_b: \"OK\"\n"
" field_c: \"OK\"\n"
" msg_field: {\n"
" field_d: 123\n"
" field_e: OK\n"
" }\n"
" msg_field: {field_d: 123 field_e: OK}\n"
"};");
verifyFormat("option (MyProto.options) = {\n"
" field_a: OK // Comment\n"