1 //===- unittest/Format/FormatTestProto.cpp --------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8
9 #include "FormatTestUtils.h"
10 #include "clang/Format/Format.h"
11 #include "llvm/Support/Debug.h"
12 #include "gtest/gtest.h"
13
14 #define DEBUG_TYPE "format-test"
15
16 namespace clang {
17 namespace format {
18
19 class FormatTestProto : public ::testing::Test {
20 protected:
format(llvm::StringRef Code,unsigned Offset,unsigned Length,const FormatStyle & Style)21 static std::string format(llvm::StringRef Code, unsigned Offset,
22 unsigned Length, const FormatStyle &Style) {
23 LLVM_DEBUG(llvm::errs() << "---\n");
24 LLVM_DEBUG(llvm::errs() << Code << "\n\n");
25 std::vector<tooling::Range> Ranges(1, tooling::Range(Offset, Length));
26 tooling::Replacements Replaces = reformat(Style, Code, Ranges);
27 auto Result = applyAllReplacements(Code, Replaces);
28 EXPECT_TRUE(static_cast<bool>(Result));
29 LLVM_DEBUG(llvm::errs() << "\n" << *Result << "\n\n");
30 return *Result;
31 }
32
format(llvm::StringRef Code)33 static std::string format(llvm::StringRef Code) {
34 FormatStyle Style = getGoogleStyle(FormatStyle::LK_Proto);
35 Style.ColumnLimit = 60; // To make writing tests easier.
36 return format(Code, 0, Code.size(), Style);
37 }
38
verifyFormat(llvm::StringRef Code)39 static void verifyFormat(llvm::StringRef Code) {
40 EXPECT_EQ(Code.str(), format(Code)) << "Expected code is not stable";
41 EXPECT_EQ(Code.str(), format(test::messUp(Code)));
42 }
43 };
44
TEST_F(FormatTestProto,FormatsMessages)45 TEST_F(FormatTestProto, FormatsMessages) {
46 verifyFormat("message SomeMessage {\n"
47 " required int32 field1 = 1;\n"
48 "}");
49 verifyFormat("message SomeMessage {\n"
50 " required .absolute.Reference field1 = 1;\n"
51 "}");
52 verifyFormat("message SomeMessage {\n"
53 " required int32 field1 = 1;\n"
54 " optional string field2 = 2 [default = \"2\"]\n"
55 "}");
56
57 verifyFormat("message SomeMessage {\n"
58 " optional really.really.long.qualified.type.aaa.aaaaaaa\n"
59 " fiiiiiiiiiiiiiiiiiiiiiiiiield = 1;\n"
60 " optional\n"
61 " really.really.long.qualified.type.aaa.aaaaaaa.aaaaaaaa\n"
62 " another_fiiiiiiiiiiiiiiiiiiiiield = 2;\n"
63 "}");
64 verifyFormat("message SomeMessage {\n"
65 " map<string, Project> projects = 1;\n"
66 " optional map<string, int32> size_projects = 2;\n"
67 " map<int, really.really.really.long.qualified.type.nameeee>\n"
68 " projects = 3;\n"
69 " map<int, really.really.really.really.long.qualified.type\n"
70 " .nameeee> projects = 4;\n"
71 " map<int,\n"
72 " reallyreallyreallyreallyreallyreallyreallylongname>\n"
73 " projects = 5;\n"
74 " map<int, Project>\n"
75 " longlonglonglonglonglonglonglonglonglongonglon = 6;\n"
76 " map<releleallyreallyreallyreallyreallyreallyreallylongname,\n"
77 " int> projects = 7;\n"
78 " map<releleallyreallyreallyreallyreallyreallyreallylongname,\n"
79 " releleallyreallyreallyreallyreallyreallyreallylongname>\n"
80 " releleallyreallyreallyreallyreallyreallyreallylongnam =\n"
81 " 8;\n"
82 " map<relele.llyreal.yreallyr.allyreally.eallyreal\n"
83 " .sauenirylongname,\n"
84 " really.really.really.really.long.qualified.type\n"
85 " .nameeee> projects = 9;\n"
86 "}");
87 }
88
TEST_F(FormatTestProto,KeywordsInOtherLanguages)89 TEST_F(FormatTestProto, KeywordsInOtherLanguages) {
90 verifyFormat("optional string operator = 1;");
91 }
92
TEST_F(FormatTestProto,FormatsEnums)93 TEST_F(FormatTestProto, FormatsEnums) {
94 verifyFormat("enum Type {\n"
95 " UNKNOWN = 0;\n"
96 " TYPE_A = 1;\n"
97 " TYPE_B = 2;\n"
98 "};");
99 verifyFormat("enum Type {\n"
100 " UNKNOWN = 0 [(some_options) = { a: aa, b: bb }];\n"
101 "};");
102 verifyFormat("enum Type {\n"
103 " UNKNOWN = 0 [(some_options) = {\n"
104 " a: aa, // wrap\n"
105 " b: bb\n"
106 " }];\n"
107 "};");
108 }
109
TEST_F(FormatTestProto,EnumAsFieldName)110 TEST_F(FormatTestProto, EnumAsFieldName) {
111 verifyFormat("message SomeMessage {\n"
112 " required int32 enum = 1;\n"
113 "}");
114 }
115
TEST_F(FormatTestProto,UnderstandsReturns)116 TEST_F(FormatTestProto, UnderstandsReturns) {
117 verifyFormat("rpc Search(SearchRequest) returns (SearchResponse);");
118 }
119
TEST_F(FormatTestProto,MessageFieldAttributes)120 TEST_F(FormatTestProto, MessageFieldAttributes) {
121 verifyFormat("optional string test = 1 [default = \"test\"];");
122 verifyFormat("optional bool a = 1 [default = true, deprecated = true];");
123 verifyFormat("optional LongMessageType long_proto_field = 1 [\n"
124 " default = REALLY_REALLY_LONG_CONSTANT_VALUE,\n"
125 " deprecated = true\n"
126 "];");
127 verifyFormat("optional LongMessageType long_proto_field = 1\n"
128 " [default = REALLY_REALLY_LONG_CONSTANT_VALUE];");
129 verifyFormat("repeated double value = 1\n"
130 " [(aaaaaaa.aaaaaaaaa) = { aaaaaaaaaaaaaaaaa: AAAAAAAA }];");
131 verifyFormat("repeated double value = 1 [(aaaaaaa.aaaaaaaaa) = {\n"
132 " aaaaaaaaaaaaaaaa: AAAAAAAAAA,\n"
133 " bbbbbbbbbbbbbbbb: BBBBBBBBBB\n"
134 "}];");
135 verifyFormat("repeated double value = 1 [(aaaaaaa.aaaaaaaaa) = {\n"
136 " aaaaaaaaaaaaaaaa: AAAAAAAAAA\n"
137 " bbbbbbbbbbbbbbbb: BBBBBBBBBB\n"
138 "}];");
139 verifyFormat("repeated double value = 1 [\n"
140 " (aaaaaaa.aaaaaaaaa) = {\n"
141 " aaaaaaaaaaaaaaaa: AAAAAAAAAA\n"
142 " bbbbbbbbbbbbbbbb: BBBBBBBBBB\n"
143 " },\n"
144 " (bbbbbbb.bbbbbbbbb) = {\n"
145 " aaaaaaaaaaaaaaaa: AAAAAAAAAA\n"
146 " bbbbbbbbbbbbbbbb: BBBBBBBBBB\n"
147 " }\n"
148 "];");
149 verifyFormat("repeated double value = 1 [(aaaaaaa.aaaaaaaaa) = {\n"
150 " type: \"AAAAAAAAAA\"\n"
151 " is: \"AAAAAAAAAA\"\n"
152 " or: \"BBBBBBBBBB\"\n"
153 "}];");
154 verifyFormat("repeated double value = 1 [(aaaaaaa.aaaaaaaaa) = {\n"
155 " aaaaaaaaaaaaaaaa: AAAAAAAAAA,\n"
156 " bbbbbbb: BBBB,\n"
157 " bbbb: BBB\n"
158 "}];");
159 verifyFormat("optional AAA aaa = 1 [\n"
160 " foo = {\n"
161 " key: 'a' //\n"
162 " },\n"
163 " bar = {\n"
164 " key: 'a' //\n"
165 " }\n"
166 "];");
167 verifyFormat("optional string test = 1 [default = \"test\"\n"
168 " \"test\"];");
169 verifyFormat("optional Aaaaaaaa aaaaaaaa = 12 [\n"
170 " (aaa) = aaaa,\n"
171 " (bbbbbbbbbbbbbbbbbbbbbbbbbb) = {\n"
172 " aaaaaaaaaaaaaaaaa: true,\n"
173 " aaaaaaaaaaaaaaaa: true\n"
174 " }\n"
175 "];");
176 verifyFormat("extensions 20 [(proto2.type) = 'Aaaa.bbbb'];");
177 verifyFormat("extensions 20\n"
178 " [(proto3.type) = 'Aaaa.bbbb', (aaa.Aaa) = 'aaa.bbb'];");
179 verifyFormat("extensions 123 [\n"
180 " (aaa) = aaaa,\n"
181 " (bbbbbbbbbbbbbbbbbbbbbbbbbb) = {\n"
182 " aaaaaaaaaaaaaaaaa: true,\n"
183 " aaaaaaaaaaaaaaaa: true\n"
184 " }\n"
185 "];");
186 }
187
TEST_F(FormatTestProto,DoesntWrapFileOptions)188 TEST_F(FormatTestProto, DoesntWrapFileOptions) {
189 EXPECT_EQ(
190 "option java_package = "
191 "\"some.really.long.package.that.exceeds.the.column.limit\";",
192 format("option java_package = "
193 "\"some.really.long.package.that.exceeds.the.column.limit\";"));
194 }
195
TEST_F(FormatTestProto,TrailingCommentAfterFileOption)196 TEST_F(FormatTestProto, TrailingCommentAfterFileOption) {
197 verifyFormat("option java_package = \"foo.pkg\"; // comment\n");
198 }
199
TEST_F(FormatTestProto,FormatsOptions)200 TEST_F(FormatTestProto, FormatsOptions) {
201 verifyFormat("option (MyProto.options) = {\n"
202 " field_a: OK\n"
203 " field_b: \"OK\"\n"
204 " field_c: \"OK\"\n"
205 " msg_field: { field_d: 123 }\n"
206 "};");
207 verifyFormat("option (MyProto.options) = {\n"
208 " field_a: OK\n"
209 " field_b: \"OK\"\n"
210 " field_c: \"OK\"\n"
211 " msg_field: { field_d: 123 field_e: OK }\n"
212 "};");
213 verifyFormat("option (MyProto.options) = {\n"
214 " field_a: OK // Comment\n"
215 " field_b: \"OK\"\n"
216 " field_c: \"OK\"\n"
217 " msg_field: { field_d: 123 }\n"
218 "};");
219 verifyFormat("option (MyProto.options) = {\n"
220 " field_c: \"OK\"\n"
221 " msg_field { field_d: 123 }\n"
222 "};");
223 verifyFormat("option (MyProto.options) = {\n"
224 " field_a: OK\n"
225 " field_b { field_c: OK }\n"
226 " field_d: OKOKOK\n"
227 " field_e: OK\n"
228 "}");
229
230 // Support syntax with <> instead of {}.
231 verifyFormat("option (MyProto.options) = {\n"
232 " field_c: \"OK\",\n"
233 " msg_field: < field_d: 123 >\n"
234 " empty: <>\n"
235 " empty <>\n"
236 "};");
237
238 verifyFormat("option (MyProto.options) = {\n"
239 " field_a: OK\n"
240 " field_b < field_c: OK >\n"
241 " field_d: OKOKOK\n"
242 " field_e: OK\n"
243 "}");
244
245 verifyFormat("option (MyProto.options) = {\n"
246 " msg_field: <>\n"
247 " field_c: \"OK\",\n"
248 " msg_field: < field_d: 123 >\n"
249 " field_e: OK\n"
250 " msg_field: < field_d: 12 >\n"
251 "};");
252
253 verifyFormat("option (MyProto.options) = <\n"
254 " field_a: OK\n"
255 " field_b: \"OK\"\n"
256 " field_c: 1\n"
257 " field_d: 12.5\n"
258 " field_e: OK\n"
259 ">;");
260
261 verifyFormat("option (MyProto.options) = <\n"
262 " field_a: OK,\n"
263 " field_b: \"OK\",\n"
264 " field_c: 1,\n"
265 " field_d: 12.5,\n"
266 " field_e: OK,\n"
267 ">;");
268
269 verifyFormat("option (MyProto.options) = <\n"
270 " field_a: \"OK\"\n"
271 " msg_field: { field_b: OK }\n"
272 " field_g: OK\n"
273 " field_g: OK\n"
274 " field_g: OK\n"
275 ">;");
276
277 verifyFormat("option (MyProto.options) = <\n"
278 " field_a: \"OK\"\n"
279 " msg_field <\n"
280 " field_b: OK\n"
281 " field_c: OK\n"
282 " field_d: OK\n"
283 " field_e: OK\n"
284 " field_f: OK\n"
285 " >\n"
286 " field_g: OK\n"
287 ">;");
288
289 verifyFormat("option (MyProto.options) = <\n"
290 " field_a: \"OK\"\n"
291 " msg_field <\n"
292 " field_b: OK,\n"
293 " field_c: OK,\n"
294 " field_d: OK,\n"
295 " field_e: OK,\n"
296 " field_f: OK\n"
297 " >\n"
298 " field_g: OK\n"
299 ">;");
300
301 verifyFormat("option (MyProto.options) = <\n"
302 " field_a: \"OK\"\n"
303 " msg_field: <\n"
304 " field_b: OK\n"
305 " field_c: OK\n"
306 " field_d: OK\n"
307 " field_e: OK\n"
308 " field_f: OK\n"
309 " >\n"
310 " field_g: OK\n"
311 ">;");
312
313 verifyFormat("option (MyProto.options) = <\n"
314 " field_a: \"OK\"\n"
315 " msg_field: {\n"
316 " field_b: OK\n"
317 " field_c: OK\n"
318 " field_d: OK\n"
319 " field_e: OK\n"
320 " field_f: OK\n"
321 " }\n"
322 " field_g: OK\n"
323 ">;");
324
325 verifyFormat("option (MyProto.options) = <\n"
326 " field_a: \"OK\"\n"
327 " msg_field {\n"
328 " field_b: OK\n"
329 " field_c: OK\n"
330 " field_d: OK\n"
331 " field_e: OK\n"
332 " field_f: OK\n"
333 " }\n"
334 " field_g: OK\n"
335 ">;");
336
337 verifyFormat("option (MyProto.options) = {\n"
338 " field_a: \"OK\"\n"
339 " msg_field <\n"
340 " field_b: OK\n"
341 " field_c: OK\n"
342 " field_d: OK\n"
343 " field_e: OK\n"
344 " field_f: OK\n"
345 " >\n"
346 " field_g: OK\n"
347 "};");
348
349 verifyFormat("option (MyProto.options) = {\n"
350 " field_a: \"OK\"\n"
351 " msg_field: <\n"
352 " field_b: OK\n"
353 " field_c: OK\n"
354 " field_d: OK\n"
355 " field_e: OK\n"
356 " field_f: OK\n"
357 " >\n"
358 " field_g: OK\n"
359 "};");
360
361 verifyFormat("option (MyProto.options) = <\n"
362 " field_a: \"OK\"\n"
363 " msg_field {\n"
364 " field_b: OK\n"
365 " field_c: OK\n"
366 " field_d: OK\n"
367 " msg_field <\n"
368 " field_A: 1\n"
369 " field_B: 2\n"
370 " field_C: 3\n"
371 " field_D: 4\n"
372 " field_E: 5\n"
373 " >\n"
374 " msg_field < field_A: 1 field_B: 2 field_C: 3 f_D: 4 >\n"
375 " field_e: OK\n"
376 " field_f: OK\n"
377 " }\n"
378 " field_g: OK\n"
379 ">;");
380
381 verifyFormat("option (MyProto.options) = <\n"
382 " data1 < key1: value1 >\n"
383 " data2 { key2: value2 }\n"
384 ">;");
385
386 verifyFormat("option (MyProto.options) = <\n"
387 " app_id: 'com.javax.swing.salsa.latino'\n"
388 " head_id: 1\n"
389 " data < key: value >\n"
390 ">;");
391
392 verifyFormat("option (MyProto.options) = {\n"
393 " app_id: 'com.javax.swing.salsa.latino'\n"
394 " head_id: 1\n"
395 " headheadheadheadheadhead_id: 1\n"
396 " product_data { product { 1 } }\n"
397 "};");
398 }
399
TEST_F(FormatTestProto,DoesntWrapPackageStatements)400 TEST_F(FormatTestProto, DoesntWrapPackageStatements) {
401 verifyFormat(
402 "package"
403 " some.really.long.package.that.exceeds.the.column.limit00000000;");
404 }
405
TEST_F(FormatTestProto,TrailingCommentAfterPackage)406 TEST_F(FormatTestProto, TrailingCommentAfterPackage) {
407 verifyFormat("package foo.pkg; // comment\n");
408 }
409
TEST_F(FormatTestProto,FormatsService)410 TEST_F(FormatTestProto, FormatsService) {
411 verifyFormat("service SearchService {\n"
412 " rpc Search(SearchRequest) returns (SearchResponse) {\n"
413 " option foo = true;\n"
414 " }\n"
415 "};");
416 }
417
TEST_F(FormatTestProto,ExtendingMessage)418 TEST_F(FormatTestProto, ExtendingMessage) {
419 verifyFormat("extend .foo.Bar {}");
420 }
421
TEST_F(FormatTestProto,FormatsImports)422 TEST_F(FormatTestProto, FormatsImports) {
423 verifyFormat("import \"a.proto\";\n"
424 "import \"b.proto\";\n"
425 "// comment\n"
426 "message A {}");
427
428 verifyFormat("import public \"a.proto\";\n"
429 "import \"b.proto\";\n"
430 "// comment\n"
431 "message A {}");
432
433 // Missing semicolons should not confuse clang-format.
434 verifyFormat("import \"a.proto\"\n"
435 "import \"b.proto\"\n"
436 "// comment\n"
437 "message A {}");
438 }
439
TEST_F(FormatTestProto,KeepsLongStringLiteralsOnSameLine)440 TEST_F(FormatTestProto, KeepsLongStringLiteralsOnSameLine) {
441 verifyFormat(
442 "option (MyProto.options) = {\n"
443 " foo: {\n"
444 " text: \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaasaaaaaaaa\"\n"
445 " }\n"
446 "}");
447 }
448
TEST_F(FormatTestProto,FormatsOptionsExtensions)449 TEST_F(FormatTestProto, FormatsOptionsExtensions) {
450 verifyFormat("option (MyProto.options) = {\n"
451 " msg_field: { field_d: 123 }\n"
452 " [ext.t/u] { key: value }\n"
453 " key: value\n"
454 " [t.u/v] <\n"
455 " [ext] { key: value }\n"
456 " >\n"
457 "};");
458 }
459
TEST_F(FormatTestProto,SpacesAroundPercents)460 TEST_F(FormatTestProto, SpacesAroundPercents) {
461 verifyFormat("option (MyProto.options) = {\n"
462 " key: %lld\n"
463 " key: 0x%04x\n"
464 " key: \"%d %d\"\n"
465 "};");
466 }
467
TEST_F(FormatTestProto,FormatsRepeatedListInitializersInOptions)468 TEST_F(FormatTestProto, FormatsRepeatedListInitializersInOptions) {
469 verifyFormat("option (MyProto.options) = {\n"
470 " key: item\n"
471 " keys: [\n"
472 " 'ala',\n"
473 " 'bala',\n"
474 " 'porto',\n"
475 " 'kala',\n"
476 " 'too',\n"
477 " 'long',\n"
478 " 'long',\n"
479 " 'long'\n"
480 " ]\n"
481 " key: [ item ]\n"
482 " msg {\n"
483 " key: item\n"
484 " keys: [\n"
485 " 'ala',\n"
486 " 'bala',\n"
487 " 'porto',\n"
488 " 'kala',\n"
489 " 'too',\n"
490 " 'long',\n"
491 " 'long'\n"
492 " ]\n"
493 " }\n"
494 " key: value\n"
495 "};");
496 }
497
TEST_F(FormatTestProto,AcceptsOperatorAsKeyInOptions)498 TEST_F(FormatTestProto, AcceptsOperatorAsKeyInOptions) {
499 verifyFormat("option (MyProto.options) = {\n"
500 " bbbbbbbbb: <\n"
501 " ccccccccccccccccccccccc: <\n"
502 " operator: 1\n"
503 " operator: 2\n"
504 " operator: 3\n"
505 " operator { key: value }\n"
506 " >\n"
507 " >\n"
508 "};");
509 }
510
TEST_F(FormatTestProto,BreaksEntriesOfSubmessagesContainingSubmessages)511 TEST_F(FormatTestProto, BreaksEntriesOfSubmessagesContainingSubmessages) {
512 FormatStyle Style = getGoogleStyle(FormatStyle::LK_TextProto);
513 Style.ColumnLimit = 60;
514 // The column limit allows for the keys submessage to be put on 1 line, but we
515 // break it since it contains a submessage an another entry.
516 verifyFormat("option (MyProto.options) = {\n"
517 " key: valueeeeeeee\n"
518 " keys: {\n"
519 " item: 'aaaaaaaaaaaaaaaa'\n"
520 " sub <>\n"
521 " }\n"
522 "}");
523 verifyFormat("option (MyProto.options) = {\n"
524 " key: valueeeeeeee\n"
525 " keys: {\n"
526 " item: 'aaaaaaaaaaaaaaaa'\n"
527 " sub {}\n"
528 " }\n"
529 "}");
530 verifyFormat("option (MyProto.options) = {\n"
531 " key: valueeeeeeee\n"
532 " keys: {\n"
533 " sub {}\n"
534 " sub: <>\n"
535 " sub: []\n"
536 " }\n"
537 "}");
538 verifyFormat("option (MyProto.options) = {\n"
539 " key: valueeeeeeee\n"
540 " keys: {\n"
541 " item: 'aaaaaaaaaaa'\n"
542 " sub { msg: 1 }\n"
543 " }\n"
544 "}");
545 verifyFormat("option (MyProto.options) = {\n"
546 " key: valueeeeeeee\n"
547 " keys: {\n"
548 " item: 'aaaaaaaaaaa'\n"
549 " sub: { msg: 1 }\n"
550 " }\n"
551 "}");
552 verifyFormat("option (MyProto.options) = {\n"
553 " key: valueeeeeeee\n"
554 " keys: {\n"
555 " item: 'aaaaaaaaaaa'\n"
556 " sub < msg: 1 >\n"
557 " }\n"
558 "}");
559 verifyFormat("option (MyProto.options) = {\n"
560 " key: valueeeeeeee\n"
561 " keys: {\n"
562 " item: 'aaaaaaaaaaa'\n"
563 " sub: [ msg: 1 ]\n"
564 " }\n"
565 "}");
566 verifyFormat("option (MyProto.options) = {\n"
567 " key: valueeeeeeee\n"
568 " keys: <\n"
569 " item: 'aaaaaaaaaaa'\n"
570 " sub: [ 1, 2 ]\n"
571 " >\n"
572 "}");
573 verifyFormat("option (MyProto.options) = {\n"
574 " key: valueeeeeeee\n"
575 " keys: {\n"
576 " sub {}\n"
577 " item: 'aaaaaaaaaaaaaaaa'\n"
578 " }\n"
579 "}");
580 verifyFormat("option (MyProto.options) = {\n"
581 " key: valueeeeeeee\n"
582 " keys: {\n"
583 " sub: []\n"
584 " item: 'aaaaaaaaaaaaaaaa'\n"
585 " }\n"
586 "}");
587 verifyFormat("option (MyProto.options) = {\n"
588 " key: valueeeeeeee\n"
589 " keys: {\n"
590 " sub <>\n"
591 " item: 'aaaaaaaaaaaaaaaa'\n"
592 " }\n"
593 "}");
594 verifyFormat("option (MyProto.options) = {\n"
595 " key: valueeeeeeee\n"
596 " keys: {\n"
597 " sub { key: value }\n"
598 " item: 'aaaaaaaaaaaaaaaa'\n"
599 " }\n"
600 "}");
601 verifyFormat("option (MyProto.options) = {\n"
602 " key: valueeeeeeee\n"
603 " keys: {\n"
604 " sub: [ 1, 2 ]\n"
605 " item: 'aaaaaaaaaaaaaaaa'\n"
606 " }\n"
607 "}");
608 verifyFormat("option (MyProto.options) = {\n"
609 " key: valueeeeeeee\n"
610 " keys: {\n"
611 " sub < sub_2: {} >\n"
612 " item: 'aaaaaaaaaaaaaaaa'\n"
613 " }\n"
614 "}");
615 verifyFormat("option (MyProto.options) = {\n"
616 " key: valueeeeeeee\n"
617 " keys: {\n"
618 " item: data\n"
619 " sub: [ 1, 2 ]\n"
620 " item: 'aaaaaaaaaaaaaaaa'\n"
621 " }\n"
622 "}");
623 verifyFormat("option (MyProto.options) = {\n"
624 " key: valueeeeeeee\n"
625 " keys: {\n"
626 " item: data\n"
627 " sub < sub_2: {} >\n"
628 " item: 'aaaaaaaaaaaaaaaa'\n"
629 " }\n"
630 "}");
631 verifyFormat("option (MyProto.options) = {\n"
632 " sub: {\n"
633 " key: valueeeeeeee\n"
634 " keys: {\n"
635 " sub: [ 1, 2 ]\n"
636 " item: 'aaaaaaaaaaaaaaaa'\n"
637 " }\n"
638 " }\n"
639 "}");
640 }
641
TEST_F(FormatTestProto,PreventBreaksBetweenKeyAndSubmessages)642 TEST_F(FormatTestProto, PreventBreaksBetweenKeyAndSubmessages) {
643 verifyFormat("option (MyProto.options) = {\n"
644 " submessage: {\n"
645 " key: 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'\n"
646 " }\n"
647 "}");
648 verifyFormat("option (MyProto.options) = {\n"
649 " submessage {\n"
650 " key: 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'\n"
651 " }\n"
652 "}");
653 verifyFormat("option (MyProto.options) = {\n"
654 " submessage: <\n"
655 " key: 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'\n"
656 " >\n"
657 "}");
658 verifyFormat("option (MyProto.options) = {\n"
659 " submessage <\n"
660 " key: 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'\n"
661 " >\n"
662 "}");
663 verifyFormat("option (MyProto.options) = {\n"
664 " repeatedd: [\n"
665 " 'eyaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'\n"
666 " ]\n"
667 "}");
668 }
669
670 } // namespace format
671 } // end namespace clang
672