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

source code of clang/unittests/Format/FormatTestProto.cpp