r323860 - [clang-format] Adds space around braces in text protos
Krasimir Georgiev via cfe-commits
cfe-commits at lists.llvm.org
Wed Jan 31 02:14:10 PST 2018
Author: krasimir
Date: Wed Jan 31 02:14:10 2018
New Revision: 323860
URL: http://llvm.org/viewvc/llvm-project?rev=323860&view=rev
Log:
[clang-format] Adds space around braces in text protos
Summary:
This patch modifies the text proto Google style to add spaces around braces.
I investigated using something different than Cpp11BracedListStyle, but it turns out it's what we want and also the java and js styles also depend on that.
Reviewers: djasper
Reviewed By: djasper
Subscribers: klimek, cfe-commits
Differential Revision: https://reviews.llvm.org/D42685
Modified:
cfe/trunk/lib/Format/Format.cpp
cfe/trunk/unittests/Format/FormatTestProto.cpp
cfe/trunk/unittests/Format/FormatTestRawStrings.cpp
cfe/trunk/unittests/Format/FormatTestTextProto.cpp
Modified: cfe/trunk/lib/Format/Format.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=323860&r1=323859&r2=323860&view=diff
==============================================================================
--- cfe/trunk/lib/Format/Format.cpp (original)
+++ cfe/trunk/lib/Format/Format.cpp Wed Jan 31 02:14:10 2018
@@ -750,6 +750,7 @@ FormatStyle getGoogleStyle(FormatStyle::
} else if (Language == FormatStyle::LK_Proto) {
GoogleStyle.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_None;
GoogleStyle.SpacesInContainerLiterals = false;
+ GoogleStyle.Cpp11BracedListStyle = false;
} else if (Language == FormatStyle::LK_ObjC) {
GoogleStyle.ColumnLimit = 100;
}
Modified: cfe/trunk/unittests/Format/FormatTestProto.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestProto.cpp?rev=323860&r1=323859&r2=323860&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTestProto.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestProto.cpp Wed Jan 31 02:14:10 2018
@@ -97,7 +97,7 @@ TEST_F(FormatTestProto, FormatsEnums) {
" TYPE_B = 2;\n"
"};");
verifyFormat("enum Type {\n"
- " UNKNOWN = 0 [(some_options) = {a: aa, b: bb}];\n"
+ " UNKNOWN = 0 [(some_options) = { a: aa, b: bb }];\n"
"};");
verifyFormat("enum Type {\n"
" UNKNOWN = 0 [(some_options) = {\n"
@@ -121,7 +121,7 @@ TEST_F(FormatTestProto, MessageFieldAttr
verifyFormat("optional LongMessageType long_proto_field = 1\n"
" [default = REALLY_REALLY_LONG_CONSTANT_VALUE];");
verifyFormat("repeated double value = 1\n"
- " [(aaaaaaa.aaaaaaaaa) = {aaaaaaaaaaaaaaaaa: AAAAAAAA}];");
+ " [(aaaaaaa.aaaaaaaaa) = { aaaaaaaaaaaaaaaaa: AAAAAAAA }];");
verifyFormat("repeated double value = 1 [(aaaaaaa.aaaaaaaaa) = {\n"
" aaaaaaaaaaaaaaaa: AAAAAAAAAA,\n"
" bbbbbbbbbbbbbbbb: BBBBBBBBBB\n"
@@ -183,27 +183,27 @@ TEST_F(FormatTestProto, FormatsOptions)
" field_a: OK\n"
" field_b: \"OK\"\n"
" field_c: \"OK\"\n"
- " msg_field: {field_d: 123}\n"
+ " msg_field: { field_d: 123 }\n"
"};");
verifyFormat("option (MyProto.options) = {\n"
" field_a: OK\n"
" field_b: \"OK\"\n"
" field_c: \"OK\"\n"
- " msg_field: {field_d: 123 field_e: OK}\n"
+ " msg_field: { field_d: 123 field_e: OK }\n"
"};");
verifyFormat("option (MyProto.options) = {\n"
" field_a: OK // Comment\n"
" field_b: \"OK\"\n"
" field_c: \"OK\"\n"
- " msg_field: {field_d: 123}\n"
+ " msg_field: { field_d: 123 }\n"
"};");
verifyFormat("option (MyProto.options) = {\n"
" field_c: \"OK\"\n"
- " msg_field {field_d: 123}\n"
+ " msg_field { field_d: 123 }\n"
"};");
verifyFormat("option (MyProto.options) = {\n"
" field_a: OK\n"
- " field_b {field_c: OK}\n"
+ " field_b { field_c: OK }\n"
" field_d: OKOKOK\n"
" field_e: OK\n"
"}");
@@ -247,7 +247,7 @@ TEST_F(FormatTestProto, FormatsOptions)
verifyFormat("option (MyProto.options) = <\n"
" field_a: \"OK\"\n"
- " msg_field: {field_b: OK}\n"
+ " msg_field: { field_b: OK }\n"
" field_g: OK\n"
" field_g: OK\n"
" field_g: OK\n"
@@ -359,7 +359,7 @@ TEST_F(FormatTestProto, FormatsOptions)
verifyFormat("option (MyProto.options) = <\n"
" data1 <key1: value1>\n"
- " data2 {key2: value2}\n"
+ " data2 { key2: value2 }\n"
">;");
verifyFormat("option (MyProto.options) = <\n"
@@ -372,7 +372,7 @@ TEST_F(FormatTestProto, FormatsOptions)
" app_id: 'com.javax.swing.salsa.latino'\n"
" head_id: 1\n"
" headheadheadheadheadhead_id: 1\n"
- " product_data {product {1}}\n"
+ " product_data { product { 1 } }\n"
"};");
}
Modified: cfe/trunk/unittests/Format/FormatTestRawStrings.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestRawStrings.cpp?rev=323860&r1=323859&r2=323860&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTestRawStrings.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestRawStrings.cpp Wed Jan 31 02:14:10 2018
@@ -186,7 +186,7 @@ TEST_F(FormatTestRawStrings, ReformatsSh
R"test(P p = TP(R"pb(item_1:1 item_2:2)pb");)test",
getRawStringPbStyleWithColumns(40)));
expect_eq(
- R"test(P p = TP(R"pb(item_1 <1> item_2: {2})pb");)test",
+ R"test(P p = TP(R"pb(item_1 <1> item_2: { 2 })pb");)test",
format(
R"test(P p = TP(R"pb(item_1<1> item_2:{2})pb");)test",
getRawStringPbStyleWithColumns(40)));
@@ -246,9 +246,9 @@ P p = TP(R"pb(item_1: 1, item_2: 2, item
expect_eq(R"test(
P p = TPPPPPPPPPPPPPPP(
R"pb(item_1 <1>,
- item_2: {2},
+ item_2: { 2 },
item_3: <3>,
- item_4: {4})pb");)test",
+ item_4: { 4 })pb");)test",
format(R"test(
P p = TPPPPPPPPPPPPPPP(R"pb(item_1<1>, item_2: {2}, item_3: <3>, item_4:{4})pb");)test",
getRawStringPbStyleWithColumns(40)));
@@ -295,7 +295,7 @@ int f(string s) {
TEST_F(FormatTestRawStrings, FormatsRawStringArguments) {
expect_eq(R"test(
-P p = TP(R"pb(key {1})pb", param_2);)test",
+P p = TP(R"pb(key { 1 })pb", param_2);)test",
format(R"test(
P p = TP(R"pb(key{1})pb",param_2);)test",
getRawStringPbStyleWithColumns(40)));
@@ -308,9 +308,9 @@ PPPPPPPPPPPPP(R"pb(keykeyk)pb", param_2)
getRawStringPbStyleWithColumns(40)));
expect_eq(R"test(
-P p =
- TP(R"pb(item: {i: 1, s: 's'}
- item: {i: 2, s: 't'})pb");)test",
+P p = TP(
+ R"pb(item: { i: 1, s: 's' }
+ item: { i: 2, s: 't' })pb");)test",
format(R"test(
P p = TP(R"pb(item: {i: 1, s: 's'} item: {i: 2, s: 't'})pb");)test",
getRawStringPbStyleWithColumns(40)));
Modified: cfe/trunk/unittests/Format/FormatTestTextProto.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestTextProto.cpp?rev=323860&r1=323859&r2=323860&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTestTextProto.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestTextProto.cpp Wed Jan 31 02:14:10 2018
@@ -49,9 +49,9 @@ TEST_F(FormatTestTextProto, KeepsTopLeve
TEST_F(FormatTestTextProto, SupportsMessageFields) {
verifyFormat("msg_field: {}");
- verifyFormat("msg_field: {field_a: A}");
+ verifyFormat("msg_field: { field_a: A }");
- verifyFormat("msg_field: {field_a: \"OK\" field_b: 123}");
+ verifyFormat("msg_field: { field_a: \"OK\" field_b: 123 }");
verifyFormat("msg_field: {\n"
" field_a: 1\n"
@@ -63,9 +63,9 @@ TEST_F(FormatTestTextProto, SupportsMess
verifyFormat("msg_field {}");
- verifyFormat("msg_field {field_a: A}");
+ verifyFormat("msg_field { field_a: A }");
- verifyFormat("msg_field {field_a: \"OK\" field_b: 123}");
+ verifyFormat("msg_field { field_a: \"OK\" field_b: 123 }");
verifyFormat("msg_field {\n"
" field_a: 1\n"
@@ -78,11 +78,11 @@ TEST_F(FormatTestTextProto, SupportsMess
" field_h: 1234.567e-89\n"
"}");
- verifyFormat("msg_field: {msg_field {field_a: 1}}");
+ verifyFormat("msg_field: { msg_field { field_a: 1 } }");
verifyFormat("id: \"ala.bala\"\n"
- "item {type: ITEM_A rank: 1 score: 90.0}\n"
- "item {type: ITEM_B rank: 2 score: 70.5}\n"
+ "item { type: ITEM_A rank: 1 score: 90.0 }\n"
+ "item { type: ITEM_B rank: 2 score: 70.5 }\n"
"item {\n"
" type: ITEM_A\n"
" rank: 3\n"
@@ -102,24 +102,24 @@ TEST_F(FormatTestTextProto, AvoidsTopLev
verifyFormat("field_a: OK\n"
"field_b: \"OK\"\n"
"field_c: \"OK\"\n"
- "msg_field: {field_d: 123}\n"
+ "msg_field: { field_d: 123 }\n"
"field_e: OK\n"
"field_f: OK");
verifyFormat("field_a: OK\n"
"field_b: \"OK\"\n"
"field_c: \"OK\"\n"
- "msg_field: {field_d: 123 field_e: OK}");
+ "msg_field: { field_d: 123 field_e: OK }");
verifyFormat("a: {\n"
" field_a: OK\n"
- " field_b {field_c: OK}\n"
+ " field_b { field_c: OK }\n"
" field_d: OKOKOK\n"
" field_e: OK\n"
"}");
verifyFormat("field_a: OK,\n"
- "field_b {field_c: OK},\n"
+ "field_b { field_c: OK },\n"
"field_d: OKOKOK,\n"
"field_e: OK");
}
@@ -150,10 +150,10 @@ TEST_F(FormatTestTextProto, SupportsAngl
verifyFormat("msg_field: <field_a <field_b: <>>>");
verifyFormat("msg_field <field_a: OK, field_b: \"OK\">");
verifyFormat("msg_field <field_a: OK field_b: <>, field_c: OK>");
- verifyFormat("msg_field <field_a {field_b: 1}, field_c: <field_d: 2>>");
+ verifyFormat("msg_field <field_a { field_b: 1 }, field_c: <field_d: 2>>");
verifyFormat("msg_field: <field_a: OK, field_b: \"OK\">");
verifyFormat("msg_field: <field_a: OK field_b: <>, field_c: OK>");
- verifyFormat("msg_field: <field_a {field_b: 1}, field_c: <field_d: 2>>");
+ verifyFormat("msg_field: <field_a { field_b: 1 }, field_c: <field_d: 2>>");
verifyFormat("field_a: \"OK\", msg_field: <field_b: 123>, field_c: {}");
verifyFormat("field_a <field_b: 1>, msg_field: <field_b: 123>, field_c <>");
verifyFormat("field_a <field_b: 1> msg_field: <field_b: 123> field_c <>");
@@ -200,7 +200,7 @@ TEST_F(FormatTestTextProto, SupportsAngl
verifyFormat("msg_field: <\n"
" field_a: \"OK\"\n"
- " msg_field: {field_b: OK}\n"
+ " msg_field: { field_b: OK }\n"
" field_g: OK\n"
" field_g: OK\n"
" field_g: OK\n"
@@ -226,7 +226,7 @@ TEST_F(FormatTestTextProto, SupportsAngl
" field_b2: ok,\n"
" field_b3: <\n"
" field_x {} // Comment\n"
- " field_y: {field_z: 1}\n"
+ " field_y: { field_z: 1 }\n"
" field_w: ok\n"
" >\n"
" field {\n"
@@ -258,7 +258,7 @@ TEST_F(FormatTestTextProto, SupportsAngl
verifyFormat("app_id: 'com.javax.swing.salsa.latino'\n"
"head_id: 1\n"
"data <key: value>\n"
- "data {key: value}");
+ "data { key: value }");
verifyFormat("app {\n"
" app_id: 'com.javax.swing.salsa.latino'\n"
@@ -274,11 +274,11 @@ TEST_F(FormatTestTextProto, SupportsAngl
verifyFormat("app_id: 'com.javax.swing.salsa.latino'\n"
"headheadheadheadheadhead_id: 1\n"
- "product_data {product {1}}");
+ "product_data { product { 1 } }");
verifyFormat("app_id: 'com.javax.swing.salsa.latino'\n"
"headheadheadheadheadhead_id: 1\n"
- "product_data <product {1}>");
+ "product_data <product { 1 }>");
verifyFormat("app_id: 'com.javax.swing.salsa.latino'\n"
"headheadheadheadheadhead_id: 1\n"
@@ -287,11 +287,11 @@ TEST_F(FormatTestTextProto, SupportsAngl
verifyFormat("app <\n"
" app_id: 'com.javax.swing.salsa.latino'\n"
" headheadheadheadheadhead_id: 1\n"
- " product_data <product {1}>\n"
+ " product_data <product { 1 }>\n"
">");
verifyFormat("dcccwrnfioeruvginerurneitinfo {\n"
- " exte3nsionrnfvui {key: value}\n"
+ " exte3nsionrnfvui { key: value }\n"
"}");
}
More information about the cfe-commits
mailing list