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(llvm::StringRef Code
,
29 const FormatStyle
&Style
= getLLVMStyle(),
30 StatusCheck CheckComplete
= SC_ExpectComplete
) {
31 LLVM_DEBUG(llvm::errs() << "---\n");
32 LLVM_DEBUG(llvm::errs() << Code
<< "\n\n");
33 std::vector
<tooling::Range
> Ranges(1, tooling::Range(0, Code
.size()));
34 FormattingAttemptStatus Status
;
35 tooling::Replacements Replaces
=
36 reformat(Style
, Code
, Ranges
, "<stdin>", &Status
);
37 if (CheckComplete
!= SC_DoNotCheck
) {
38 bool ExpectedCompleteFormat
= CheckComplete
== SC_ExpectComplete
;
39 EXPECT_EQ(ExpectedCompleteFormat
, Status
.FormatComplete
)
42 ReplacementCount
= Replaces
.size();
43 auto Result
= applyAllReplacements(Code
, Replaces
);
44 EXPECT_TRUE(static_cast<bool>(Result
));
45 LLVM_DEBUG(llvm::errs() << "\n" << *Result
<< "\n\n");
49 FormatStyle
getStyleWithColumns(FormatStyle Style
, unsigned ColumnLimit
) {
50 Style
.ColumnLimit
= ColumnLimit
;
54 FormatStyle
getLLVMStyleWithColumns(unsigned ColumnLimit
) {
55 return getStyleWithColumns(getLLVMStyle(), ColumnLimit
);
60 FormatStyle
getRawStringPbStyleWithColumns(unsigned ColumnLimit
) {
61 FormatStyle Style
= getLLVMStyle();
62 Style
.ColumnLimit
= ColumnLimit
;
63 Style
.RawStringFormats
= {
65 /*Language=*/FormatStyle::LK_TextProto
,
66 /*Delimiters=*/{"pb"},
67 /*EnclosingFunctions=*/{},
68 /*CanonicalDelimiter=*/"",
69 /*BasedOnStyle=*/"google",
75 FormatStyle
getRawStringLLVMCppStyleBasedOn(std::string BasedOnStyle
) {
76 FormatStyle Style
= getLLVMStyle();
77 Style
.RawStringFormats
= {
79 /*Language=*/FormatStyle::LK_Cpp
,
80 /*Delimiters=*/{"cpp"},
81 /*EnclosingFunctions=*/{},
82 /*CanonicalDelimiter=*/"",
89 FormatStyle
getRawStringGoogleCppStyleBasedOn(std::string BasedOnStyle
) {
90 FormatStyle Style
= getGoogleStyle(FormatStyle::LK_Cpp
);
91 Style
.RawStringFormats
= {
93 /*Language=*/FormatStyle::LK_Cpp
,
94 /*Delimiters=*/{"cpp"},
95 /*EnclosingFunctions=*/{},
96 /*CanonicalDelimiter=*/"",
103 // Gcc 4.8 doesn't support raw string literals in macros, which breaks some
104 // build bots. We use this function instead.
105 void expect_eq(const std::string Expected
, const std::string Actual
) {
106 EXPECT_EQ(Expected
, Actual
);
110 TEST_F(FormatTestRawStrings
, ReformatsAccordingToBaseStyle
) {
111 // llvm style puts '*' on the right.
112 // google style puts '*' on the left.
114 // Use the llvm style if the raw string style has no BasedOnStyle.
115 expect_eq(R
"test(int *i = R"cpp(int *p
= nullptr;)cpp
")test",
116 format(R
"test(int * i = R"cpp(int * p
= nullptr;)cpp
")test",
117 getRawStringLLVMCppStyleBasedOn("")));
119 // Use the google style if the raw string style has BasedOnStyle=google.
120 expect_eq(R
"test(int *i = R"cpp(int* p
= nullptr;)cpp
")test",
121 format(R
"test(int * i = R"cpp(int * p
= nullptr;)cpp
")test",
122 getRawStringLLVMCppStyleBasedOn("google")));
124 // Use the llvm style if the raw string style has no BasedOnStyle=llvm.
125 expect_eq(R
"test(int* i = R"cpp(int *p
= nullptr;)cpp
")test",
126 format(R
"test(int * i = R"cpp(int * p
= nullptr;)cpp
")test",
127 getRawStringGoogleCppStyleBasedOn("llvm")));
130 TEST_F(FormatTestRawStrings
, UsesConfigurationOverBaseStyle
) {
131 // llvm style puts '*' on the right.
132 // google style puts '*' on the left.
134 // Uses the configured google style inside raw strings even if BasedOnStyle in
135 // the raw string format is llvm.
136 FormatStyle Style
= getGoogleStyle(FormatStyle::LK_Cpp
);
137 EXPECT_EQ(0, parseConfiguration("---\n"
139 "BasedOnStyle: Google",
142 Style
.RawStringFormats
= {{
146 /*CanonicalDelimiter=*/"",
147 /*BasedOnStyle=*/"llvm",
149 expect_eq(R
"test(int* i = R"cpp(int* j
= 0;)cpp
";)test",
150 format(R
"test(int * i = R"cpp(int * j
= 0;)cpp
";)test", Style
));
153 TEST_F(FormatTestRawStrings
, MatchesDelimitersCaseSensitively
) {
154 // Don't touch the 'PB' raw string, format the 'pb' raw string.
157 t = R"pb(item
: 1)pb
";)test",
160 t = R"pb(item
:1)pb
";)test",
161 getRawStringPbStyleWithColumns(40)));
164 TEST_F(FormatTestRawStrings
, RespectsClangFormatOff
) {
167 s = R"pb(item
: 1)pb
";
169 t = R"pb(item
: 1)pb
";)test",
172 s = R"pb(item
: 1)pb
";
174 t = R"pb(item
: 1)pb
";)test",
175 getRawStringPbStyleWithColumns(40)));
178 TEST_F(FormatTestRawStrings
, ReformatsShortRawStringsOnSingleLine
) {
179 expect_eq(R
"test(P p = TP(R"pb()pb
");)test",
180 format(R
"test(P p = TP(R"pb( )pb
");)test",
181 getRawStringPbStyleWithColumns(40)));
182 expect_eq(R
"test(P p = TP(R"pb(item_1
: 1)pb
");)test",
183 format(R
"test(P p = TP(R"pb(item_1
:1)pb
");)test",
184 getRawStringPbStyleWithColumns(40)));
185 expect_eq(R
"test(P p = TP(R"pb(item_1
: 1)pb
");)test",
186 format(R
"test(P p = TP(R"pb( item_1
: 1 )pb
");)test",
187 getRawStringPbStyleWithColumns(40)));
188 expect_eq(R
"test(P p = TP(R"pb(item_1
: 1 item_2
: 2)pb
");)test",
189 format(R
"test(P p = TP(R"pb(item_1
:1 item_2
:2)pb
");)test",
190 getRawStringPbStyleWithColumns(40)));
191 // Merge two short lines into one.
193 std::string s = R"pb(
198 std::string s = R"pb(
203 getRawStringPbStyleWithColumns(40)));
206 TEST_F(FormatTestRawStrings
, BreaksShortRawStringsWhenNeeded
) {
207 // The raw string contains multiple submessage entries, so break for
210 P p = TP(R"pb(item_1
< 1 >
211 item_2
: { 2 })pb
");)test",
214 P p = TP(R"pb(item_1
<1> item_2
:{2})pb
");)test",
215 getRawStringPbStyleWithColumns(40)));
218 TEST_F(FormatTestRawStrings
, BreaksRawStringsExceedingColumnLimit
) {
220 P p = TPPPPPPPPPPPPPPP(
221 R"pb(item_1
: 1, item_2
: 2)pb
");)test",
223 P p = TPPPPPPPPPPPPPPP(R"pb(item_1
: 1, item_2
: 2)pb
");)test",
224 getRawStringPbStyleWithColumns(40)));
231 item_3
: 3)pb
");)test",
233 P p = TPPPPPPPPPPPPPPP(R"pb(item_1
: 1, item_2
: 2, item_3
: 3)pb
");)test",
234 getRawStringPbStyleWithColumns(40)));
237 P p = TP(R"pb(item_1
< 1 >
239 item_3
{})pb
");)test",
241 P p = TP(R"pb(item_1
<1> item_2
:<2> item_3
{ })pb
");)test",
242 getRawStringPbStyleWithColumns(40)));
246 P p = TP(R"pb(item_1
: 1,
249 item_4
: 4)pb
");)test",
252 P p = TP(R"pb(item_1
: 1, item_2
: 2, item_3
: 3, item_4
: 4)pb
");)test",
253 getRawStringPbStyleWithColumns(40)));
256 P p = TPPPPPPPPPPPPPPP(
260 item_4
: { 4 })pb
");)test",
262 P p = TPPPPPPPPPPPPPPP(R"pb(item_1
<1>, item_2
: {2}, item_3
: <3>, item_4
:{4})pb
");)test",
263 getRawStringPbStyleWithColumns(40)));
265 // Breaks before a short raw string exceeding the column limit.
267 FFFFFFFFFFFFFFFFFFFFFFFFFFF(
269 P p = TPPPPPPPPPPPPPPPPPPPP(
271 auto TPPPPPPPPPPPPPPPPPPPP =
273 P p = TPPPPPPPPPPPPPPPPPPPP(
274 R"pb(i
: 1, j
: 2)pb
");
277 FFFFFFFFFFFFFFFFFFFFFFFFFFFFFF(
279 P p = TPPPPPPPPPPPPPPPPPPPP(
281 auto TPPPPPPPPPPPPPPPPPPPP =
284 P p = TPPPPPPPPPPPPPPPPPPPP(
285 R"pb(i
: 1, j
: 2)pb
");
289 FFFFFFFFFFFFFFFFFFFFFFFFFFF(R"pb(key
:1)pb
");
290 P p = TPPPPPPPPPPPPPPPPPPPP(R"pb(key
:2)pb
");
291 auto TPPPPPPPPPPPPPPPPPPPP = R"pb(key
:3)pb
";
292 P p = TPPPPPPPPPPPPPPPPPPPP(R"pb(i
: 1, j
:2)pb
");
295 FFFFFFFFFFFFFFFFFFFFFFFFFFFFFF(R"pb(key
:1)pb
");
296 P p = TPPPPPPPPPPPPPPPPPPPP(R"pb(key
:2)pb
");
297 auto TPPPPPPPPPPPPPPPPPPPP = R"pb(key
:3)pb
";
299 P p = TPPPPPPPPPPPPPPPPPPPP(R"pb(i
: 1, j
:2)pb
");
302 getRawStringPbStyleWithColumns(40)));
305 TEST_F(FormatTestRawStrings
, FormatsRawStringArguments
) {
307 P p = TP(R"pb(key
{ 1 })pb
", param_2);)test",
309 P p = TP(R"pb(key
{1})pb
",param_2);)test",
310 getRawStringPbStyleWithColumns(40)));
313 PPPPPPPPPPPPP(R"pb(keykeyk
)pb
",
316 PPPPPPPPPPPPP(R"pb(keykeyk
)pb
", param_2);)test",
317 getRawStringPbStyleWithColumns(40)));
321 R"pb(item
: { i
: 1, s
: 's' }
322 item
: { i
: 2, s
: 't' })pb
");)test",
324 P p = TP(R"pb(item
: {i
: 1, s
: 's'} item
: {i
: 2, s
: 't'})pb
");)test",
325 getRawStringPbStyleWithColumns(40)));
328 R"pb(key
: "value")pb
",
329 R"pb(key2
: "value")pb
");)test",
331 FFFFFFFFFFFFFFFFFFF(R"pb(key
: "value")pb
", R"pb(key2
: "value")pb
");)test",
332 getRawStringPbStyleWithColumns(40)));
334 // Formats the first out of two arguments.
336 FFFFFFFF(R"pb(key
: 1)pb
", argument2);
339 f(R"pb(key
: 1)pb
", argument2);
342 return g(R"pb(key
: 1)pb
",
344 return g(R"pb(key
: 1)pb
", "172893");
348 FFFFFFFF(R"pb(key
:1)pb
", argument2);
350 const s = f(R"pb(key
:1)pb
", argument2);
353 return g(R"pb(key
:1)pb
", 132789237);
354 return g(R"pb(key
:1)pb
", "172893");
357 getRawStringPbStyleWithColumns(40)));
359 // Formats the second out of two arguments.
361 FFFFFFFF(argument1, R"pb(key
: 2)pb
");
364 f(argument1, R"pb(key
: 2)pb
");
369 return g(17283122, R"pb(key
: 2)pb
");
373 FFFFFFFF(argument1, R"pb(key
:2)pb
");
375 const s = f(argument1, R"pb(key
:2)pb
");
378 return g(12784137, R"pb(key
:2)pb
");
379 return g(17283122, R"pb(key
:2)pb
");
382 getRawStringPbStyleWithColumns(40)));
384 // Formats two short raw string arguments.
386 FFFFF(R"pb(key
: 1)pb
", R"pb(key
: 2)pb
");)test",
388 FFFFF(R"pb(key
:1)pb
", R"pb(key
:2)pb
");)test",
389 getRawStringPbStyleWithColumns(40)));
390 // TODO(krasimir): The original source code fits on one line, so the
391 // non-optimizing formatter is chosen. But after the formatting in protos is
392 // made, the code doesn't fit on one line anymore and further formatting
395 // Should we disable raw string formatting for the non-optimizing formatter?
397 FFFFFFF(R"pb(key
: 1)pb
", R"pb(key
: 2)pb
");)test",
399 FFFFFFF(R"pb(key
:1)pb
", R"pb(key
:2)pb
");)test",
400 getRawStringPbStyleWithColumns(40)));
402 // Formats two short raw string arguments, puts second on newline.
404 FFFFFFFF(R"pb(key
: 1)pb
",
405 R"pb(key
: 2)pb
");)test",
407 FFFFFFFF(R"pb(key
:1)pb
", R"pb(key
:2)pb
");)test",
408 getRawStringPbStyleWithColumns(40)));
410 // Formats both arguments.
412 FFFFFFFF(R"pb(key
: 1)pb
",
415 const s = f(R"pb(key
: 1)pb
",
419 return g(R"pb(key
: 1)pb
",
421 return g(R"pb(k1
)pb
", R"pb(k2
)pb
");
425 FFFFFFFF(R"pb(key
:1)pb
", R"pb(key
:2)pb
");
427 const s = f(R"pb(key
:1)pb
", R"pb(key
:2)pb
");
430 return g(R"pb(key
:1)pb
", R"pb(key
:2)pb
");
431 return g(R"pb( k1
)pb
", R"pb( k2
)pb
");
434 getRawStringPbStyleWithColumns(40)));
437 TEST_F(FormatTestRawStrings
, RawStringStartingWithNewlines
) {
439 std::string s = R"pb(
444 std::string s = R"pb(
448 getRawStringPbStyleWithColumns(40)));
451 std::string s = R"pb(
457 std::string s = R"pb(
462 getRawStringPbStyleWithColumns(40)));
465 std::string s = R"pb(
470 std::string s = R"pb(
475 getRawStringPbStyleWithColumns(40)));
478 std::string s = R"pb(
484 std::string s = R"pb(
488 getRawStringPbStyleWithColumns(40)));
491 std::string s = R"pb(
493 title
: "Alice's Adventures"
494 author
: "Lewis Caroll"
498 author
: "J. M. Barrie"
503 std::string s = R"pb(
504 book
{ title
: "Alice's Adventures" author
: "Lewis Caroll" }
505 book
{ title
: "Peter Pan" author
: "J. M. Barrie" }
508 getRawStringPbStyleWithColumns(40)));
511 TEST_F(FormatTestRawStrings
, BreaksBeforeRawStrings
) {
514 ParseFromString(R"pb(item_1
: 1)pb
"),
517 ASSERT_TRUE(ParseFromString(R"pb(item_1
: 1)pb
"), ptr);)test",
518 getRawStringPbStyleWithColumns(40)));
521 ASSERT_TRUE(toolong::ParseFromString(
525 ASSERT_TRUE(toolong::ParseFromString(R"pb(item_1
: 1)pb
"), ptr);)test",
526 getRawStringPbStyleWithColumns(40)));
529 ASSERT_TRUE(ParseFromString(
534 ASSERT_TRUE(ParseFromString(R"pb(item_1
: 1, item_2
: 2)pb
"), ptr);)test",
535 getRawStringPbStyleWithColumns(40)));
540 R"pb(item_1
: 1 item_2
: 2)pb
"),
543 ASSERT_TRUE(ParseFromString(R"pb(item_1
: 1 item_2
: 2)pb
"), ptr);)test",
544 getRawStringPbStyleWithColumns(40)));
547 TEST_F(FormatTestRawStrings
, RawStringsInOperands
) {
548 // Formats the raw string first operand of a binary operator expression.
549 expect_eq(R
"test(auto S = R"pb(item_1
: 1)pb
" + rest;)test",
550 format(R
"test(auto S = R"pb(item_1
:1)pb
" + rest;)test",
551 getRawStringPbStyleWithColumns(40)));
554 auto S = R"pb(item_1
: 1, item_2
: 2)pb
" +
557 auto S = R"pb(item_1
:1,item_2
:2)pb
"+rest;)test",
558 getRawStringPbStyleWithColumns(40)));
562 R"pb(item_1
: 1 item_2
: 2)pb
" + rest;)test",
564 auto S = R"pb(item_1
:1 item_2
:2)pb
"+rest;)test",
565 getRawStringPbStyleWithColumns(40)));
567 // `rest` fits on the line after )pb", but forced on newline since the raw
568 // string literal is multiline.
570 auto S = R"pb(item_1
: 1,
575 auto S = R"pb(item_1
:1,item_2
:2,item_3
:3)pb
"+rest;)test",
576 getRawStringPbStyleWithColumns(40)));
579 auto S = R"pb(item_1
: 1,
584 auto S = R"pb(item_1
:1,item_2
:2,item_3
:3)pb
"+longlongrest;)test",
585 getRawStringPbStyleWithColumns(40)));
587 // Formats the raw string second operand of a binary operator expression.
588 expect_eq(R
"test(auto S = first + R"pb(item_1
: 1)pb
";)test",
589 format(R
"test(auto S = first + R"pb(item_1
:1)pb
";)test",
590 getRawStringPbStyleWithColumns(40)));
593 auto S = first + R"pb(item_1
: 1,
594 item_2
: 2)pb
";)test",
596 auto S = first+R"pb(item_1
:1,item_2
:2)pb
";)test",
597 getRawStringPbStyleWithColumns(40)));
600 auto S = first + R"pb(item_1
: 1
601 item_2
: 2)pb
";)test",
603 auto S = first+R"pb(item_1
:1 item_2
:2)pb
";)test",
604 getRawStringPbStyleWithColumns(40)));
607 auto S = R"pb(item_1
: 1,
612 auto S = R"pb(item_1
:1,item_2
:2,item_3
:3)pb
"+rest;)test",
613 getRawStringPbStyleWithColumns(40)));
616 auto S = R"pb(item_1
: 1,
621 auto S = R"pb(item_1
:1,item_2
:2,item_3
:3)pb
"+longlongrest;)test",
622 getRawStringPbStyleWithColumns(40)));
624 // Formats the raw string operands in expressions.
626 auto S = R"pb(item_1
: 1)pb
" +
630 auto S=R"pb(item_1
:1)pb
"+R"pb(item_2
:2)pb
";
632 getRawStringPbStyleWithColumns(40)));
635 auto S = R"pb(item_1
: 1)pb
" +
640 auto S=R"pb(item_1
:1)pb
"+R"pb(item_2
:2)pb
"+R"pb(item_3
:3)pb
";
642 getRawStringPbStyleWithColumns(40)));
647 : R"pb(item_2
: 2)pb
";
650 auto S=(count<3)?R"pb(item_1
:1)pb
":R"pb(item_2
:2)pb
";
652 getRawStringPbStyleWithColumns(40)));
657 ? R"pb(item_1
: 1, item_2
: 2)pb
"
658 : R"pb(item_3
: 3)pb
";
661 auto S=(count<3)?R"pb(item_1
:1,item_2
:2)pb
":R"pb(item_3
:3)pb
";
663 getRawStringPbStyleWithColumns(40)));
669 : R"pb(item_2
: 2, item_3
: 3)pb
";
672 auto S=(count<3)?R"pb(item_1
:1)pb
":R"pb(item_2
:2,item_3
:3)pb
";
674 getRawStringPbStyleWithColumns(40)));
677 TEST_F(FormatTestRawStrings
, PrefixAndSuffixAlignment
) {
678 // Keep the suffix at the end of line if not on newline.
693 getRawStringPbStyleWithColumns(20)));
695 // Align the suffix with the surrounding indent if the prefix is not on
696 // a line of its own.
711 getRawStringPbStyleWithColumns(20)));
713 // Align the prefix with the suffix if both the prefix and suffix are on a
714 // line of their own.
731 getRawStringPbStyleWithColumns(20)));
734 TEST_F(FormatTestRawStrings
, EstimatesPenalty
) {
735 // The penalty for characters exceeding the column limit in the raw string
736 // forces 'hh' to be put on a newline.
745 ff(gggggg, hh(R"pb(key
{
750 getRawStringPbStyleWithColumns(20)));
753 TEST_F(FormatTestRawStrings
, DontFormatNonRawStrings
) {
754 expect_eq(R
"test(a = R"pb(key
:value
)";)test",
755 format(R
"test(a = R"pb(key
:value
)";)test",
756 getRawStringPbStyleWithColumns(20)));
759 TEST_F(FormatTestRawStrings
, FormatsRawStringsWithEnclosingFunctionName
) {
760 FormatStyle Style
= getRawStringPbStyleWithColumns(40);
761 Style
.RawStringFormats
[0].EnclosingFunctions
.push_back("PARSE_TEXT_PROTO");
762 Style
.RawStringFormats
[0].EnclosingFunctions
.push_back("ParseTextProto");
763 expect_eq(R
"test(a = PARSE_TEXT_PROTO(R"(key
: value
)");)test",
764 format(R
"test(a = PARSE_TEXT_PROTO(R"(key
:value
)");)test", Style
));
767 a = PARSE_TEXT_PROTO /**/ (
768 /**/ R"(key
: value
)");)test",
770 a = PARSE_TEXT_PROTO/**/(/**/R"(key
:value
)");)test",
774 a = ParseTextProto<ProtoType>(
775 R"(key
: value
)");)test",
777 a = ParseTextProto<ProtoType>(R"(key
:value
)");)test",
781 TEST_F(FormatTestRawStrings
, UpdatesToCanonicalDelimiters
) {
782 FormatStyle Style
= getRawStringPbStyleWithColumns(35);
783 Style
.RawStringFormats
[0].CanonicalDelimiter
= "proto";
784 Style
.RawStringFormats
[0].EnclosingFunctions
.push_back("PARSE_TEXT_PROTO");
786 expect_eq(R
"test(a = R"proto(key
: value
)proto
";)test",
787 format(R
"test(a = R"pb(key
:value
)pb
";)test", Style
));
789 expect_eq(R
"test(PARSE_TEXT_PROTO(R"proto(key
: value
)proto
");)test",
790 format(R
"test(PARSE_TEXT_PROTO(R"(key
:value
)");)test", Style
));
792 // Don't update to canonical delimiter if it occurs as a raw string suffix in
793 // the raw string content.
794 expect_eq(R
"test(a = R"pb(key
: ")proto")pb
";)test",
795 format(R
"test(a = R"pb(key
:")proto")pb
";)test", Style
));
798 TEST_F(FormatTestRawStrings
, PenalizesPrefixExcessChars
) {
799 FormatStyle Style
= getRawStringPbStyleWithColumns(60);
801 // The '(' in R"pb is at column 60, no break.
803 xxxxxxxaaaaax wwwwwww = _Verxrrrrrrrr(PARSE_TEXT_PROTO(R"pb(
804 Category
: aaaaaaaaaaaaaaaaaaaaaaaaaa
808 xxxxxxxaaaaax wwwwwww = _Verxrrrrrrrr(PARSE_TEXT_PROTO(R"pb(
809 Category
: aaaaaaaaaaaaaaaaaaaaaaaaaa
813 // The '(' in R"pb is at column 61, break.
815 xxxxxxxaaaaax wwwwwww =
816 _Verxrrrrrrrrr(PARSE_TEXT_PROTO(R"pb(
817 Category
: aaaaaaaaaaaaaaaaaaaaaaaaaa
821 xxxxxxxaaaaax wwwwwww = _Verxrrrrrrrrr(PARSE_TEXT_PROTO(R"pb(
822 Category
: aaaaaaaaaaaaaaaaaaaaaaaaaa
828 TEST_F(FormatTestRawStrings
, KeepsRBraceFolloedByMoreLBracesOnSameLine
) {
829 FormatStyle Style
= getRawStringPbStyleWithColumns(80);
835 TTTTTTTTTTTTTTTTTTTTT s = PARSE_TEXT_PROTO(R"pb(
838 [cccccccccc
.pppppppppppppp
.TTTTTTTTTTTTTTTTTTTT
] { field_1
: "123_1" }
839 [cccccccccc
.pppppppppppppp
.TTTTTTTTTTTTTTTTTTTT
] { field_2
: "123_2" }
850 TTTTTTTTTTTTTTTTTTTTT s = PARSE_TEXT_PROTO(R"pb(
853 [cccccccccc
.pppppppppppppp
.TTTTTTTTTTTTTTTTTTTT
] { field_1
: "123_1" }
854 [cccccccccc
.pppppppppppppp
.TTTTTTTTTTTTTTTTTTTT
] { field_2
: "123_2" }}}
862 TEST_F(FormatTestRawStrings
,
863 DoNotFormatUnrecognizedDelimitersInRecognizedFunctions
) {
864 FormatStyle Style
= getRawStringPbStyleWithColumns(60);
865 Style
.RawStringFormats
[0].EnclosingFunctions
.push_back("EqualsProto");
866 // EqualsProto is a recognized function, but the Raw delimiter is
867 // unrecognized. Do not touch the string in this case, since it might be
871 aaaaaaaaa(bbbbbbbbb, EqualsProto(R"Raw(
879 aaaaaaaaa(bbbbbbbbb, EqualsProto(R"Raw(
888 TEST_F(FormatTestRawStrings
,
889 BreaksBeforeNextParamAfterMultilineRawStringParam
) {
890 FormatStyle Style
= getRawStringPbStyleWithColumns(60);
910 // Breaks after a parent of a multiline param.
950 // Breaks if formatting introduces a multiline raw string.
953 int a = g(x, R"pb(key1
: value111111111
954 key2
: value2222222222
)pb
",
960 int a = g(x, R"pb(key1
: value111111111 key2
: value2222222222
)pb
", 3, 4);
964 // Does not force a break after an original multiline param that is
965 // reformatterd as on single line.
968 int a = g(R"pb(key
: 1)pb
", 2);
978 TEST_F(FormatTestRawStrings
, IndentsLastParamAfterNewline
) {
979 FormatStyle Style
= getRawStringPbStyleWithColumns(60);
981 fffffffffffffffffffff("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
",
986 fffffffffffffffffffff("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
",
993 } // end namespace format
994 } // end namespace clang