1 //===- unittest/Format/FormatTestRawStrings.cpp - Formatting unit tests ---===//
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
7 //===----------------------------------------------------------------------===//
9 #include "clang/Format/Format.h"
11 #include "../Tooling/ReplacementTest.h"
12 #include "FormatTestUtils.h"
14 #include "llvm/Support/Debug.h"
15 #include "llvm/Support/MemoryBuffer.h"
16 #include "gtest/gtest.h"
18 #define DEBUG_TYPE "format-test"
24 class FormatTestRawStrings
: public testing::Test
{
26 enum StatusCheck
{ SC_ExpectComplete
, SC_ExpectIncomplete
, SC_DoNotCheck
};
28 std::string
format(StringRef Code
, const FormatStyle
&Style
= getLLVMStyle(),
29 StatusCheck CheckComplete
= SC_ExpectComplete
) {
30 LLVM_DEBUG(llvm::errs() << "---\n");
31 LLVM_DEBUG(llvm::errs() << Code
<< "\n\n");
32 std::vector
<tooling::Range
> Ranges(1, tooling::Range(0, Code
.size()));
33 FormattingAttemptStatus Status
;
34 tooling::Replacements Replaces
=
35 reformat(Style
, Code
, Ranges
, "<stdin>", &Status
);
36 if (CheckComplete
!= SC_DoNotCheck
) {
37 bool ExpectedCompleteFormat
= CheckComplete
== SC_ExpectComplete
;
38 EXPECT_EQ(ExpectedCompleteFormat
, Status
.FormatComplete
)
41 ReplacementCount
= Replaces
.size();
42 auto Result
= applyAllReplacements(Code
, Replaces
);
43 EXPECT_TRUE(static_cast<bool>(Result
));
44 LLVM_DEBUG(llvm::errs() << "\n" << *Result
<< "\n\n");
48 FormatStyle
getStyleWithColumns(FormatStyle Style
, unsigned ColumnLimit
) {
49 Style
.ColumnLimit
= ColumnLimit
;
53 FormatStyle
getLLVMStyleWithColumns(unsigned ColumnLimit
) {
54 return getStyleWithColumns(getLLVMStyle(), ColumnLimit
);
59 FormatStyle
getRawStringPbStyleWithColumns(unsigned ColumnLimit
) {
60 FormatStyle Style
= getLLVMStyle();
61 Style
.ColumnLimit
= ColumnLimit
;
62 Style
.RawStringFormats
= {
64 /*Language=*/FormatStyle::LK_TextProto
,
65 /*Delimiters=*/{"pb"},
66 /*EnclosingFunctions=*/{},
67 /*CanonicalDelimiter=*/"",
68 /*BasedOnStyle=*/"google",
74 FormatStyle
getRawStringLLVMCppStyleBasedOn(std::string BasedOnStyle
) {
75 FormatStyle Style
= getLLVMStyle();
76 Style
.RawStringFormats
= {
78 /*Language=*/FormatStyle::LK_Cpp
,
79 /*Delimiters=*/{"cpp"},
80 /*EnclosingFunctions=*/{},
81 /*CanonicalDelimiter=*/"",
88 FormatStyle
getRawStringGoogleCppStyleBasedOn(std::string BasedOnStyle
) {
89 FormatStyle Style
= getGoogleStyle(FormatStyle::LK_Cpp
);
90 Style
.RawStringFormats
= {
92 /*Language=*/FormatStyle::LK_Cpp
,
93 /*Delimiters=*/{"cpp"},
94 /*EnclosingFunctions=*/{},
95 /*CanonicalDelimiter=*/"",
102 // Gcc 4.8 doesn't support raw string literals in macros, which breaks some
103 // build bots. We use this function instead.
104 void expect_eq(const std::string Expected
, const std::string Actual
) {
105 EXPECT_EQ(Expected
, Actual
);
109 TEST_F(FormatTestRawStrings
, ReformatsAccordingToBaseStyle
) {
110 // llvm style puts '*' on the right.
111 // google style puts '*' on the left.
113 // Use the llvm style if the raw string style has no BasedOnStyle.
114 expect_eq(R
"test(int *i = R"cpp(int *p
= nullptr;)cpp
")test",
115 format(R
"test(int * i = R"cpp(int * p
= nullptr;)cpp
")test",
116 getRawStringLLVMCppStyleBasedOn("")));
118 // Use the google style if the raw string style has BasedOnStyle=google.
119 expect_eq(R
"test(int *i = R"cpp(int* p
= nullptr;)cpp
")test",
120 format(R
"test(int * i = R"cpp(int * p
= nullptr;)cpp
")test",
121 getRawStringLLVMCppStyleBasedOn("google")));
123 // Use the llvm style if the raw string style has no BasedOnStyle=llvm.
124 expect_eq(R
"test(int* i = R"cpp(int *p
= nullptr;)cpp
")test",
125 format(R
"test(int * i = R"cpp(int * p
= nullptr;)cpp
")test",
126 getRawStringGoogleCppStyleBasedOn("llvm")));
129 TEST_F(FormatTestRawStrings
, UsesConfigurationOverBaseStyle
) {
130 // llvm style puts '*' on the right.
131 // google style puts '*' on the left.
133 // Uses the configured google style inside raw strings even if BasedOnStyle in
134 // the raw string format is llvm.
135 FormatStyle Style
= getGoogleStyle(FormatStyle::LK_Cpp
);
136 EXPECT_EQ(0, parseConfiguration("---\n"
138 "BasedOnStyle: Google",
141 Style
.RawStringFormats
= {{
145 /*CanonicalDelimiter=*/"",
146 /*BasedOnStyle=*/"llvm",
148 expect_eq(R
"test(int* i = R"cpp(int* j
= 0;)cpp
";)test",
149 format(R
"test(int * i = R"cpp(int * j
= 0;)cpp
";)test", Style
));
152 TEST_F(FormatTestRawStrings
, MatchesDelimitersCaseSensitively
) {
153 // Don't touch the 'PB' raw string, format the 'pb' raw string.
156 t = R"pb(item
: 1)pb
";)test",
159 t = R"pb(item
:1)pb
";)test",
160 getRawStringPbStyleWithColumns(40)));
163 TEST_F(FormatTestRawStrings
, RespectsClangFormatOff
) {
166 s = R"pb(item
: 1)pb
";
168 t = R"pb(item
: 1)pb
";)test",
171 s = R"pb(item
: 1)pb
";
173 t = R"pb(item
: 1)pb
";)test",
174 getRawStringPbStyleWithColumns(40)));
177 TEST_F(FormatTestRawStrings
, ReformatsShortRawStringsOnSingleLine
) {
178 expect_eq(R
"test(P p = TP(R"pb()pb
");)test",
179 format(R
"test(P p = TP(R"pb( )pb
");)test",
180 getRawStringPbStyleWithColumns(40)));
181 expect_eq(R
"test(P p = TP(R"pb(item_1
: 1)pb
");)test",
182 format(R
"test(P p = TP(R"pb(item_1
:1)pb
");)test",
183 getRawStringPbStyleWithColumns(40)));
184 expect_eq(R
"test(P p = TP(R"pb(item_1
: 1)pb
");)test",
185 format(R
"test(P p = TP(R"pb( item_1
: 1 )pb
");)test",
186 getRawStringPbStyleWithColumns(40)));
187 expect_eq(R
"test(P p = TP(R"pb(item_1
: 1 item_2
: 2)pb
");)test",
188 format(R
"test(P p = TP(R"pb(item_1
:1 item_2
:2)pb
");)test",
189 getRawStringPbStyleWithColumns(40)));
190 // Merge two short lines into one.
192 std::string s = R"pb(
197 std::string s = R"pb(
202 getRawStringPbStyleWithColumns(40)));
205 TEST_F(FormatTestRawStrings
, BreaksShortRawStringsWhenNeeded
) {
206 // The raw string contains multiple submessage entries, so break for
209 P p = TP(R"pb(item_1
< 1 >
210 item_2
: { 2 })pb
");)test",
213 P p = TP(R"pb(item_1
<1> item_2
:{2})pb
");)test",
214 getRawStringPbStyleWithColumns(40)));
217 TEST_F(FormatTestRawStrings
, BreaksRawStringsExceedingColumnLimit
) {
219 P p = TPPPPPPPPPPPPPPP(
220 R"pb(item_1
: 1, item_2
: 2)pb
");)test",
222 P p = TPPPPPPPPPPPPPPP(R"pb(item_1
: 1, item_2
: 2)pb
");)test",
223 getRawStringPbStyleWithColumns(40)));
230 item_3
: 3)pb
");)test",
232 P p = TPPPPPPPPPPPPPPP(R"pb(item_1
: 1, item_2
: 2, item_3
: 3)pb
");)test",
233 getRawStringPbStyleWithColumns(40)));
236 P p = TP(R"pb(item_1
< 1 >
238 item_3
{})pb
");)test",
240 P p = TP(R"pb(item_1
<1> item_2
:<2> item_3
{ })pb
");)test",
241 getRawStringPbStyleWithColumns(40)));
245 P p = TP(R"pb(item_1
: 1,
248 item_4
: 4)pb
");)test",
251 P p = TP(R"pb(item_1
: 1, item_2
: 2, item_3
: 3, item_4
: 4)pb
");)test",
252 getRawStringPbStyleWithColumns(40)));
255 P p = TPPPPPPPPPPPPPPP(
259 item_4
: { 4 })pb
");)test",
261 P p = TPPPPPPPPPPPPPPP(R"pb(item_1
<1>, item_2
: {2}, item_3
: <3>, item_4
:{4})pb
");)test",
262 getRawStringPbStyleWithColumns(40)));
264 // Breaks before a short raw string exceeding the column limit.
266 FFFFFFFFFFFFFFFFFFFFFFFFFFF(
268 P p = TPPPPPPPPPPPPPPPPPPPP(
270 auto TPPPPPPPPPPPPPPPPPPPP =
272 P p = TPPPPPPPPPPPPPPPPPPPP(
273 R"pb(i
: 1, j
: 2)pb
");
276 FFFFFFFFFFFFFFFFFFFFFFFFFFFFFF(
278 P p = TPPPPPPPPPPPPPPPPPPPP(
280 auto TPPPPPPPPPPPPPPPPPPPP =
283 P p = TPPPPPPPPPPPPPPPPPPPP(
284 R"pb(i
: 1, j
: 2)pb
");
288 FFFFFFFFFFFFFFFFFFFFFFFFFFF(R"pb(key
:1)pb
");
289 P p = TPPPPPPPPPPPPPPPPPPPP(R"pb(key
:2)pb
");
290 auto TPPPPPPPPPPPPPPPPPPPP = R"pb(key
:3)pb
";
291 P p = TPPPPPPPPPPPPPPPPPPPP(R"pb(i
: 1, j
:2)pb
");
294 FFFFFFFFFFFFFFFFFFFFFFFFFFFFFF(R"pb(key
:1)pb
");
295 P p = TPPPPPPPPPPPPPPPPPPPP(R"pb(key
:2)pb
");
296 auto TPPPPPPPPPPPPPPPPPPPP = R"pb(key
:3)pb
";
298 P p = TPPPPPPPPPPPPPPPPPPPP(R"pb(i
: 1, j
:2)pb
");
301 getRawStringPbStyleWithColumns(40)));
304 TEST_F(FormatTestRawStrings
, FormatsRawStringArguments
) {
306 P p = TP(R"pb(key
{ 1 })pb
", param_2);)test",
308 P p = TP(R"pb(key
{1})pb
",param_2);)test",
309 getRawStringPbStyleWithColumns(40)));
312 PPPPPPPPPPPPP(R"pb(keykeyk
)pb
",
315 PPPPPPPPPPPPP(R"pb(keykeyk
)pb
", param_2);)test",
316 getRawStringPbStyleWithColumns(40)));
320 R"pb(item
: { i
: 1, s
: 's' }
321 item
: { i
: 2, s
: 't' })pb
");)test",
323 P p = TP(R"pb(item
: {i
: 1, s
: 's'} item
: {i
: 2, s
: 't'})pb
");)test",
324 getRawStringPbStyleWithColumns(40)));
327 R"pb(key
: "value")pb
",
328 R"pb(key2
: "value")pb
");)test",
330 FFFFFFFFFFFFFFFFFFF(R"pb(key
: "value")pb
", R"pb(key2
: "value")pb
");)test",
331 getRawStringPbStyleWithColumns(40)));
333 // Formats the first out of two arguments.
335 FFFFFFFF(R"pb(key
: 1)pb
", argument2);
338 f(R"pb(key
: 1)pb
", argument2);
341 return g(R"pb(key
: 1)pb
",
343 return g(R"pb(key
: 1)pb
", "172893");
347 FFFFFFFF(R"pb(key
:1)pb
", argument2);
349 const s = f(R"pb(key
:1)pb
", argument2);
352 return g(R"pb(key
:1)pb
", 132789237);
353 return g(R"pb(key
:1)pb
", "172893");
356 getRawStringPbStyleWithColumns(40)));
358 // Formats the second out of two arguments.
360 FFFFFFFF(argument1, R"pb(key
: 2)pb
");
363 f(argument1, R"pb(key
: 2)pb
");
368 return g(17283122, R"pb(key
: 2)pb
");
372 FFFFFFFF(argument1, R"pb(key
:2)pb
");
374 const s = f(argument1, R"pb(key
:2)pb
");
377 return g(12784137, R"pb(key
:2)pb
");
378 return g(17283122, R"pb(key
:2)pb
");
381 getRawStringPbStyleWithColumns(40)));
383 // Formats two short raw string arguments.
385 FFFFF(R"pb(key
: 1)pb
", R"pb(key
: 2)pb
");)test",
387 FFFFF(R"pb(key
:1)pb
", R"pb(key
:2)pb
");)test",
388 getRawStringPbStyleWithColumns(40)));
389 // TODO(krasimir): The original source code fits on one line, so the
390 // non-optimizing formatter is chosen. But after the formatting in protos is
391 // made, the code doesn't fit on one line anymore and further formatting
394 // Should we disable raw string formatting for the non-optimizing formatter?
396 FFFFFFF(R"pb(key
: 1)pb
", R"pb(key
: 2)pb
");)test",
398 FFFFFFF(R"pb(key
:1)pb
", R"pb(key
:2)pb
");)test",
399 getRawStringPbStyleWithColumns(40)));
401 // Formats two short raw string arguments, puts second on newline.
403 FFFFFFFF(R"pb(key
: 1)pb
",
404 R"pb(key
: 2)pb
");)test",
406 FFFFFFFF(R"pb(key
:1)pb
", R"pb(key
:2)pb
");)test",
407 getRawStringPbStyleWithColumns(40)));
409 // Formats both arguments.
411 FFFFFFFF(R"pb(key
: 1)pb
",
414 const s = f(R"pb(key
: 1)pb
",
418 return g(R"pb(key
: 1)pb
",
420 return g(R"pb(k1
)pb
", R"pb(k2
)pb
");
424 FFFFFFFF(R"pb(key
:1)pb
", R"pb(key
:2)pb
");
426 const s = f(R"pb(key
:1)pb
", R"pb(key
:2)pb
");
429 return g(R"pb(key
:1)pb
", R"pb(key
:2)pb
");
430 return g(R"pb( k1
)pb
", R"pb( k2
)pb
");
433 getRawStringPbStyleWithColumns(40)));
436 TEST_F(FormatTestRawStrings
, RawStringStartingWithNewlines
) {
438 std::string s = R"pb(
443 std::string s = R"pb(
447 getRawStringPbStyleWithColumns(40)));
450 std::string s = R"pb(
456 std::string s = R"pb(
461 getRawStringPbStyleWithColumns(40)));
464 std::string s = R"pb(
469 std::string s = R"pb(
474 getRawStringPbStyleWithColumns(40)));
477 std::string s = R"pb(
483 std::string s = R"pb(
487 getRawStringPbStyleWithColumns(40)));
490 std::string s = R"pb(
492 title
: "Alice's Adventures"
493 author
: "Lewis Caroll"
497 author
: "J. M. Barrie"
502 std::string s = R"pb(
503 book
{ title
: "Alice's Adventures" author
: "Lewis Caroll" }
504 book
{ title
: "Peter Pan" author
: "J. M. Barrie" }
507 getRawStringPbStyleWithColumns(40)));
510 TEST_F(FormatTestRawStrings
, BreaksBeforeRawStrings
) {
513 ParseFromString(R"pb(item_1
: 1)pb
"),
516 ASSERT_TRUE(ParseFromString(R"pb(item_1
: 1)pb
"), ptr);)test",
517 getRawStringPbStyleWithColumns(40)));
520 ASSERT_TRUE(toolong::ParseFromString(
524 ASSERT_TRUE(toolong::ParseFromString(R"pb(item_1
: 1)pb
"), ptr);)test",
525 getRawStringPbStyleWithColumns(40)));
528 ASSERT_TRUE(ParseFromString(
533 ASSERT_TRUE(ParseFromString(R"pb(item_1
: 1, item_2
: 2)pb
"), ptr);)test",
534 getRawStringPbStyleWithColumns(40)));
539 R"pb(item_1
: 1 item_2
: 2)pb
"),
542 ASSERT_TRUE(ParseFromString(R"pb(item_1
: 1 item_2
: 2)pb
"), ptr);)test",
543 getRawStringPbStyleWithColumns(40)));
546 TEST_F(FormatTestRawStrings
, RawStringsInOperands
) {
547 // Formats the raw string first operand of a binary operator expression.
548 expect_eq(R
"test(auto S = R"pb(item_1
: 1)pb
" + rest;)test",
549 format(R
"test(auto S = R"pb(item_1
:1)pb
" + rest;)test",
550 getRawStringPbStyleWithColumns(40)));
553 auto S = R"pb(item_1
: 1, item_2
: 2)pb
" +
556 auto S = R"pb(item_1
:1,item_2
:2)pb
"+rest;)test",
557 getRawStringPbStyleWithColumns(40)));
561 R"pb(item_1
: 1 item_2
: 2)pb
" + rest;)test",
563 auto S = R"pb(item_1
:1 item_2
:2)pb
"+rest;)test",
564 getRawStringPbStyleWithColumns(40)));
566 // `rest` fits on the line after )pb", but forced on newline since the raw
567 // string literal is multiline.
569 auto S = R"pb(item_1
: 1,
574 auto S = R"pb(item_1
:1,item_2
:2,item_3
:3)pb
"+rest;)test",
575 getRawStringPbStyleWithColumns(40)));
578 auto S = R"pb(item_1
: 1,
583 auto S = R"pb(item_1
:1,item_2
:2,item_3
:3)pb
"+longlongrest;)test",
584 getRawStringPbStyleWithColumns(40)));
586 // Formats the raw string second operand of a binary operator expression.
587 expect_eq(R
"test(auto S = first + R"pb(item_1
: 1)pb
";)test",
588 format(R
"test(auto S = first + R"pb(item_1
:1)pb
";)test",
589 getRawStringPbStyleWithColumns(40)));
592 auto S = first + R"pb(item_1
: 1,
593 item_2
: 2)pb
";)test",
595 auto S = first+R"pb(item_1
:1,item_2
:2)pb
";)test",
596 getRawStringPbStyleWithColumns(40)));
599 auto S = first + R"pb(item_1
: 1
600 item_2
: 2)pb
";)test",
602 auto S = first+R"pb(item_1
:1 item_2
:2)pb
";)test",
603 getRawStringPbStyleWithColumns(40)));
606 auto S = R"pb(item_1
: 1,
611 auto S = R"pb(item_1
:1,item_2
:2,item_3
:3)pb
"+rest;)test",
612 getRawStringPbStyleWithColumns(40)));
615 auto S = R"pb(item_1
: 1,
620 auto S = R"pb(item_1
:1,item_2
:2,item_3
:3)pb
"+longlongrest;)test",
621 getRawStringPbStyleWithColumns(40)));
623 // Formats the raw string operands in expressions.
625 auto S = R"pb(item_1
: 1)pb
" +
629 auto S=R"pb(item_1
:1)pb
"+R"pb(item_2
:2)pb
";
631 getRawStringPbStyleWithColumns(40)));
634 auto S = R"pb(item_1
: 1)pb
" +
639 auto S=R"pb(item_1
:1)pb
"+R"pb(item_2
:2)pb
"+R"pb(item_3
:3)pb
";
641 getRawStringPbStyleWithColumns(40)));
646 : R"pb(item_2
: 2)pb
";
649 auto S=(count<3)?R"pb(item_1
:1)pb
":R"pb(item_2
:2)pb
";
651 getRawStringPbStyleWithColumns(40)));
656 ? R"pb(item_1
: 1, item_2
: 2)pb
"
657 : R"pb(item_3
: 3)pb
";
660 auto S=(count<3)?R"pb(item_1
:1,item_2
:2)pb
":R"pb(item_3
:3)pb
";
662 getRawStringPbStyleWithColumns(40)));
668 : R"pb(item_2
: 2, item_3
: 3)pb
";
671 auto S=(count<3)?R"pb(item_1
:1)pb
":R"pb(item_2
:2,item_3
:3)pb
";
673 getRawStringPbStyleWithColumns(40)));
676 TEST_F(FormatTestRawStrings
, PrefixAndSuffixAlignment
) {
677 // Keep the suffix at the end of line if not on newline.
692 getRawStringPbStyleWithColumns(20)));
694 // Align the suffix with the surrounding indent if the prefix is not on
695 // a line of its own.
710 getRawStringPbStyleWithColumns(20)));
712 // Align the prefix with the suffix if both the prefix and suffix are on a
713 // line of their own.
730 getRawStringPbStyleWithColumns(20)));
733 TEST_F(FormatTestRawStrings
, EstimatesPenalty
) {
734 // The penalty for characters exceeding the column limit in the raw string
735 // forces 'hh' to be put on a newline.
744 ff(gggggg, hh(R"pb(key
{
749 getRawStringPbStyleWithColumns(20)));
752 TEST_F(FormatTestRawStrings
, DontFormatNonRawStrings
) {
753 expect_eq(R
"test(a = R"pb(key
:value
)";)test",
754 format(R
"test(a = R"pb(key
:value
)";)test",
755 getRawStringPbStyleWithColumns(20)));
758 TEST_F(FormatTestRawStrings
, FormatsRawStringsWithEnclosingFunctionName
) {
759 FormatStyle Style
= getRawStringPbStyleWithColumns(40);
760 Style
.RawStringFormats
[0].EnclosingFunctions
.push_back("PARSE_TEXT_PROTO");
761 Style
.RawStringFormats
[0].EnclosingFunctions
.push_back("ParseTextProto");
762 expect_eq(R
"test(a = PARSE_TEXT_PROTO(R"(key
: value
)");)test",
763 format(R
"test(a = PARSE_TEXT_PROTO(R"(key
:value
)");)test", Style
));
766 a = PARSE_TEXT_PROTO /**/ (
767 /**/ R"(key
: value
)");)test",
769 a = PARSE_TEXT_PROTO/**/(/**/R"(key
:value
)");)test",
773 a = ParseTextProto<ProtoType>(
774 R"(key
: value
)");)test",
776 a = ParseTextProto<ProtoType>(R"(key
:value
)");)test",
780 TEST_F(FormatTestRawStrings
, UpdatesToCanonicalDelimiters
) {
781 FormatStyle Style
= getRawStringPbStyleWithColumns(35);
782 Style
.RawStringFormats
[0].CanonicalDelimiter
= "proto";
783 Style
.RawStringFormats
[0].EnclosingFunctions
.push_back("PARSE_TEXT_PROTO");
785 expect_eq(R
"test(a = R"proto(key
: value
)proto
";)test",
786 format(R
"test(a = R"pb(key
:value
)pb
";)test", Style
));
788 expect_eq(R
"test(PARSE_TEXT_PROTO(R"proto(key
: value
)proto
");)test",
789 format(R
"test(PARSE_TEXT_PROTO(R"(key
:value
)");)test", Style
));
791 // Don't update to canonical delimiter if it occurs as a raw string suffix in
792 // the raw string content.
793 expect_eq(R
"test(a = R"pb(key
: ")proto")pb
";)test",
794 format(R
"test(a = R"pb(key
:")proto")pb
";)test", Style
));
797 TEST_F(FormatTestRawStrings
, PenalizesPrefixExcessChars
) {
798 FormatStyle Style
= getRawStringPbStyleWithColumns(60);
800 // The '(' in R"pb is at column 60, no break.
802 xxxxxxxaaaaax wwwwwww = _Verxrrrrrrrr(PARSE_TEXT_PROTO(R"pb(
803 Category
: aaaaaaaaaaaaaaaaaaaaaaaaaa
807 xxxxxxxaaaaax wwwwwww = _Verxrrrrrrrr(PARSE_TEXT_PROTO(R"pb(
808 Category
: aaaaaaaaaaaaaaaaaaaaaaaaaa
812 // The '(' in R"pb is at column 61, break.
814 xxxxxxxaaaaax wwwwwww =
815 _Verxrrrrrrrrr(PARSE_TEXT_PROTO(R"pb(
816 Category
: aaaaaaaaaaaaaaaaaaaaaaaaaa
820 xxxxxxxaaaaax wwwwwww = _Verxrrrrrrrrr(PARSE_TEXT_PROTO(R"pb(
821 Category
: aaaaaaaaaaaaaaaaaaaaaaaaaa
827 TEST_F(FormatTestRawStrings
, KeepsRBraceFolloedByMoreLBracesOnSameLine
) {
828 FormatStyle Style
= getRawStringPbStyleWithColumns(80);
834 TTTTTTTTTTTTTTTTTTTTT s = PARSE_TEXT_PROTO(R"pb(
837 [cccccccccc
.pppppppppppppp
.TTTTTTTTTTTTTTTTTTTT
] { field_1
: "123_1" }
838 [cccccccccc
.pppppppppppppp
.TTTTTTTTTTTTTTTTTTTT
] { field_2
: "123_2" }
849 TTTTTTTTTTTTTTTTTTTTT s = PARSE_TEXT_PROTO(R"pb(
852 [cccccccccc
.pppppppppppppp
.TTTTTTTTTTTTTTTTTTTT
] { field_1
: "123_1" }
853 [cccccccccc
.pppppppppppppp
.TTTTTTTTTTTTTTTTTTTT
] { field_2
: "123_2" }}}
861 TEST_F(FormatTestRawStrings
,
862 DoNotFormatUnrecognizedDelimitersInRecognizedFunctions
) {
863 FormatStyle Style
= getRawStringPbStyleWithColumns(60);
864 Style
.RawStringFormats
[0].EnclosingFunctions
.push_back("EqualsProto");
865 // EqualsProto is a recognized function, but the Raw delimiter is
866 // unrecognized. Do not touch the string in this case, since it might be
870 aaaaaaaaa(bbbbbbbbb, EqualsProto(R"Raw(
878 aaaaaaaaa(bbbbbbbbb, EqualsProto(R"Raw(
887 TEST_F(FormatTestRawStrings
,
888 BreaksBeforeNextParamAfterMultilineRawStringParam
) {
889 FormatStyle Style
= getRawStringPbStyleWithColumns(60);
909 // Breaks after a parent of a multiline param.
949 // Breaks if formatting introduces a multiline raw string.
952 int a = g(x, R"pb(key1
: value111111111
953 key2
: value2222222222
)pb
",
959 int a = g(x, R"pb(key1
: value111111111 key2
: value2222222222
)pb
", 3, 4);
963 // Does not force a break after an original multiline param that is
964 // reformatterd as on single line.
967 int a = g(R"pb(key
: 1)pb
", 2);
977 TEST_F(FormatTestRawStrings
, IndentsLastParamAfterNewline
) {
978 FormatStyle Style
= getRawStringPbStyleWithColumns(60);
980 fffffffffffffffffffff("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
",
985 fffffffffffffffffffff("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
",
992 } // end namespace format
993 } // end namespace clang