forked from OSchip/llvm-project
[clang-format] Add space between a message field key and the opening bracket in proto messages
Summary: This patch updates the formatting of message fields of type `a{...}` to `a {...}` for proto messages. Reviewers: djasper Reviewed By: djasper Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D35015 llvm-svn: 307261
This commit is contained in:
parent
761e5b9310
commit
47f21ef2af
|
@ -2301,6 +2301,8 @@ bool TokenAnnotator::spaceRequiredBefore(const AnnotatedLine &Line,
|
|||
if (Right.is(tok::l_paren) &&
|
||||
Left.isOneOf(Keywords.kw_returns, Keywords.kw_option))
|
||||
return true;
|
||||
if (Right.isOneOf(tok::l_brace, tok::less) && Left.is(TT_SelectorName))
|
||||
return true;
|
||||
} else if (Style.Language == FormatStyle::LK_JavaScript) {
|
||||
if (Left.is(TT_JsFatArrow))
|
||||
return true;
|
||||
|
|
|
@ -199,11 +199,11 @@ TEST_F(FormatTestProto, FormatsOptions) {
|
|||
"};");
|
||||
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"
|
||||
"}");
|
||||
|
@ -216,7 +216,7 @@ TEST_F(FormatTestProto, FormatsOptions) {
|
|||
|
||||
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"
|
||||
"}");
|
||||
|
@ -255,7 +255,7 @@ TEST_F(FormatTestProto, FormatsOptions) {
|
|||
|
||||
verifyFormat("option (MyProto.options) = <\n"
|
||||
" field_a: \"OK\"\n"
|
||||
" msg_field<\n"
|
||||
" msg_field <\n"
|
||||
" field_b: OK\n"
|
||||
" field_c: OK\n"
|
||||
" field_d: OK\n"
|
||||
|
@ -267,7 +267,7 @@ TEST_F(FormatTestProto, FormatsOptions) {
|
|||
|
||||
verifyFormat("option (MyProto.options) = <\n"
|
||||
" field_a: \"OK\"\n"
|
||||
" msg_field<\n"
|
||||
" msg_field <\n"
|
||||
" field_b: OK,\n"
|
||||
" field_c: OK,\n"
|
||||
" field_d: OK,\n"
|
||||
|
@ -303,7 +303,7 @@ TEST_F(FormatTestProto, FormatsOptions) {
|
|||
|
||||
verifyFormat("option (MyProto.options) = <\n"
|
||||
" field_a: \"OK\"\n"
|
||||
" msg_field{\n"
|
||||
" msg_field {\n"
|
||||
" field_b: OK\n"
|
||||
" field_c: OK\n"
|
||||
" field_d: OK\n"
|
||||
|
@ -315,7 +315,7 @@ TEST_F(FormatTestProto, FormatsOptions) {
|
|||
|
||||
verifyFormat("option (MyProto.options) = {\n"
|
||||
" field_a: \"OK\"\n"
|
||||
" msg_field<\n"
|
||||
" msg_field <\n"
|
||||
" field_b: OK\n"
|
||||
" field_c: OK\n"
|
||||
" field_d: OK\n"
|
||||
|
@ -339,18 +339,18 @@ TEST_F(FormatTestProto, FormatsOptions) {
|
|||
|
||||
verifyFormat("option (MyProto.options) = <\n"
|
||||
" field_a: \"OK\"\n"
|
||||
" msg_field{\n"
|
||||
" msg_field {\n"
|
||||
" field_b: OK\n"
|
||||
" field_c: OK\n"
|
||||
" field_d: OK\n"
|
||||
" msg_field<\n"
|
||||
" msg_field <\n"
|
||||
" field_A: 1\n"
|
||||
" field_B: 2\n"
|
||||
" field_C: 3\n"
|
||||
" field_D: 4\n"
|
||||
" field_E: 5\n"
|
||||
" >\n"
|
||||
" msg_field<field_A: 1 field_B: 2 field_C: 3 field_D: 4>\n"
|
||||
" msg_field <field_A: 1 field_B: 2 field_C: 3 field_D: 4>\n"
|
||||
" field_e: OK\n"
|
||||
" field_f: OK\n"
|
||||
" }\n"
|
||||
|
|
|
@ -61,13 +61,13 @@ TEST_F(FormatTestTextProto, SupportsMessageFields) {
|
|||
" field_e: 23\n"
|
||||
"}");
|
||||
|
||||
verifyFormat("msg_field{}");
|
||||
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"
|
||||
verifyFormat("msg_field {\n"
|
||||
" field_a: 1\n"
|
||||
" field_b: OK\n"
|
||||
" field_c: \"OK\"\n"
|
||||
|
@ -78,12 +78,12 @@ TEST_F(FormatTestTextProto, SupportsMessageFields) {
|
|||
" 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{\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"
|
||||
" score: 20.0\n"
|
||||
|
@ -113,13 +113,13 @@ TEST_F(FormatTestTextProto, AvoidsTopLevelBinPacking) {
|
|||
|
||||
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");
|
||||
}
|
||||
|
@ -134,33 +134,33 @@ TEST_F(FormatTestTextProto, AddsNewlinesAfterTrailingComments) {
|
|||
"}");
|
||||
|
||||
verifyFormat("field_a: OK\n"
|
||||
"msg_field{\n"
|
||||
"msg_field {\n"
|
||||
" field_b: OK // Comment\n"
|
||||
"}");
|
||||
}
|
||||
|
||||
TEST_F(FormatTestTextProto, SupportsAngleBracketMessageFields) {
|
||||
// Single-line tests
|
||||
verifyFormat("msg_field<>");
|
||||
verifyFormat("msg_field <>");
|
||||
verifyFormat("msg_field: <>");
|
||||
verifyFormat("msg_field<field_a: OK>");
|
||||
verifyFormat("msg_field <field_a: OK>");
|
||||
verifyFormat("msg_field: <field_a: 123>");
|
||||
verifyFormat("msg_field<field_a<>>");
|
||||
verifyFormat("msg_field<field_a<field_b<>>>");
|
||||
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 <>>");
|
||||
verifyFormat("msg_field <field_a <field_b <>>>");
|
||||
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: 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<>");
|
||||
verifyFormat("field<field<field: <>>, field<>> field: <field: 1>");
|
||||
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 <>");
|
||||
verifyFormat("field <field <field: <>>, field <>> field: <field: 1>");
|
||||
|
||||
// Multiple lines tests
|
||||
verifyFormat("msg_field<\n"
|
||||
verifyFormat("msg_field <\n"
|
||||
" field_a: OK\n"
|
||||
" field_b: \"OK\"\n"
|
||||
" field_c: 1\n"
|
||||
|
@ -175,25 +175,25 @@ TEST_F(FormatTestTextProto, SupportsAngleBracketMessageFields) {
|
|||
"msg_field: <field_d: 12>");
|
||||
|
||||
verifyFormat("field_a: OK,\n"
|
||||
"field_b<field_c: OK>,\n"
|
||||
"field_b <field_c: OK>,\n"
|
||||
"field_d: <12.5>,\n"
|
||||
"field_e: OK");
|
||||
|
||||
verifyFormat("field_a: OK\n"
|
||||
"field_b<field_c: OK>\n"
|
||||
"field_b <field_c: OK>\n"
|
||||
"field_d: <12.5>\n"
|
||||
"field_e: OKOKOK");
|
||||
|
||||
verifyFormat("msg_field<\n"
|
||||
verifyFormat("msg_field <\n"
|
||||
" field_a: OK,\n"
|
||||
" field_b<field_c: OK>,\n"
|
||||
" field_b <field_c: OK>,\n"
|
||||
" field_d: <12.5>,\n"
|
||||
" field_e: OK\n"
|
||||
">");
|
||||
|
||||
verifyFormat("msg_field<\n"
|
||||
verifyFormat("msg_field <\n"
|
||||
" field_a: <field: OK>,\n"
|
||||
" field_b<field_c: OK>,\n"
|
||||
" field_b <field_c: OK>,\n"
|
||||
" field_d: <12.5>,\n"
|
||||
" field_e: OK,\n"
|
||||
">");
|
||||
|
@ -206,7 +206,7 @@ TEST_F(FormatTestTextProto, SupportsAngleBracketMessageFields) {
|
|||
" field_g: OK\n"
|
||||
">");
|
||||
|
||||
verifyFormat("field_a{\n"
|
||||
verifyFormat("field_a {\n"
|
||||
" field_d: ok\n"
|
||||
" field_b: <field_c: 1>\n"
|
||||
" field_d: ok\n"
|
||||
|
@ -221,16 +221,16 @@ TEST_F(FormatTestTextProto, SupportsAngleBracketMessageFields) {
|
|||
"}");
|
||||
|
||||
verifyFormat("field_a: <f1: 1, f2: <>>\n"
|
||||
"field_b<\n"
|
||||
"field_b <\n"
|
||||
" field_b1: <>\n"
|
||||
" field_b2: ok,\n"
|
||||
" field_b3: <\n"
|
||||
" field_x{} // Comment\n"
|
||||
" field_x {} // Comment\n"
|
||||
" field_y: {field_z: 1}\n"
|
||||
" field_w: ok\n"
|
||||
" >\n"
|
||||
" field{\n"
|
||||
" field_x<> // Comment\n"
|
||||
" field {\n"
|
||||
" field_x <> // Comment\n"
|
||||
" field_y: <field_z: 1>\n"
|
||||
" field_w: ok\n"
|
||||
" msg_field: <\n"
|
||||
|
@ -244,8 +244,7 @@ TEST_F(FormatTestTextProto, SupportsAngleBracketMessageFields) {
|
|||
" }\n"
|
||||
">\n"
|
||||
"field: OK,\n"
|
||||
"field_c<field<field<>>>");
|
||||
"field_c <field <field <>>>");
|
||||
}
|
||||
|
||||
} // end namespace tooling
|
||||
} // end namespace clang
|
||||
|
|
Loading…
Reference in New Issue