[GlobalISel] Add G_ABDS and G_ABDU instructions (#118122)
[llvm-project.git] / clang / unittests / Format / NamespaceEndCommentsFixerTest.cpp
blob2c45ad1cbe1c8e1685f576d69ff3b26bf1f27deb
1 //===- NamespaceEndCommentsFixerTest.cpp - Formatting unit tests ----------===//
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 //===----------------------------------------------------------------------===//
9 #include "clang/Format/Format.h"
11 #include "llvm/Support/Debug.h"
12 #include "gtest/gtest.h"
14 #define DEBUG_TYPE "namespace-end-comments-fixer-test"
16 namespace clang {
17 namespace format {
18 namespace {
20 class NamespaceEndCommentsFixerTest : public testing::Test {
21 protected:
22 std::string
23 fixNamespaceEndComments(StringRef Code,
24 const std::vector<tooling::Range> &Ranges,
25 const FormatStyle &Style = getLLVMStyle()) {
26 LLVM_DEBUG(llvm::errs() << "---\n");
27 LLVM_DEBUG(llvm::errs() << Code << "\n\n");
28 tooling::Replacements Replaces =
29 format::fixNamespaceEndComments(Style, Code, Ranges, "<stdin>");
30 auto Result = applyAllReplacements(Code, Replaces);
31 EXPECT_TRUE(static_cast<bool>(Result));
32 LLVM_DEBUG(llvm::errs() << "\n" << *Result << "\n\n");
33 return *Result;
36 std::string
37 fixNamespaceEndComments(StringRef Code,
38 const FormatStyle &Style = getLLVMStyle()) {
39 return fixNamespaceEndComments(
40 Code,
41 /*Ranges=*/{1, tooling::Range(0, Code.size())}, Style);
44 bool isFormatted(StringRef Code, const std::vector<tooling::Range> &Ranges,
45 const FormatStyle &Style = getLLVMStyle()) const {
46 return format::fixNamespaceEndComments(Style, Code, Ranges, "<stdin>")
47 .empty();
50 bool isFormatted(StringRef Code,
51 const FormatStyle &Style = getLLVMStyle()) const {
52 return isFormatted(Code, {1, tooling::Range(0, Code.size())}, Style);
56 TEST_F(NamespaceEndCommentsFixerTest, AddsEndComment) {
57 EXPECT_EQ("namespace {\n"
58 "int i;\n"
59 "int j;\n"
60 "} // namespace",
61 fixNamespaceEndComments("namespace {\n"
62 "int i;\n"
63 "int j;\n"
64 "}"));
66 EXPECT_EQ("namespace {\n"
67 "int i;\n"
68 "int j;\n"
69 "} // namespace",
70 fixNamespaceEndComments("namespace {\n"
71 "int i;\n"
72 "int j;\n"
73 "}"));
74 EXPECT_EQ("namespace A {\n"
75 "int i;\n"
76 "int j;\n"
77 "} // namespace A",
78 fixNamespaceEndComments("namespace A {\n"
79 "int i;\n"
80 "int j;\n"
81 "}"));
82 EXPECT_EQ("#define M(x) x##x\n"
83 "namespace M(x) {\n"
84 "int i;\n"
85 "int j;\n"
86 "} // namespace M(x)",
87 fixNamespaceEndComments("#define M(x) x##x\n"
88 "namespace M(x) {\n"
89 "int i;\n"
90 "int j;\n"
91 "}"));
92 EXPECT_EQ("#define M(x) x##x\n"
93 "namespace A::M(x) {\n"
94 "int i;\n"
95 "int j;\n"
96 "} // namespace A::M(x)",
97 fixNamespaceEndComments("#define M(x) x##x\n"
98 "namespace A::M(x) {\n"
99 "int i;\n"
100 "int j;\n"
101 "}"));
102 EXPECT_EQ("#define M(x) x##x\n"
103 "namespace M(x)::A {\n"
104 "int i;\n"
105 "int j;\n"
106 "} // namespace M(x)::A",
107 fixNamespaceEndComments("#define M(x) x##x\n"
108 "namespace M(x)::A {\n"
109 "int i;\n"
110 "int j;\n"
111 "}"));
112 EXPECT_EQ("#define M(x) x##x\n"
113 "namespace A::inline M(x)::B {\n"
114 "int i;\n"
115 "int j;\n"
116 "} // namespace A::inline M(x)::B",
117 fixNamespaceEndComments("#define M(x) x##x\n"
118 "namespace A::inline M(x)::B {\n"
119 "int i;\n"
120 "int j;\n"
121 "}"));
122 EXPECT_EQ("#define M(x) x##x\n"
123 "namespace [[deprecated(\"foo\")]] A::inline M(x)::A {\n"
124 "int i;\n"
125 "int j;\n"
126 "} // namespace A::inline M(x)::A",
127 fixNamespaceEndComments(
128 "#define M(x) x##x\n"
129 "namespace [[deprecated(\"foo\")]] A::inline M(x)::A {\n"
130 "int i;\n"
131 "int j;\n"
132 "}"));
133 EXPECT_EQ(
134 "namespace /* comment */ [[deprecated(\"foo\")]] /* comment */ A {\n"
135 "int i;\n"
136 "int j;\n"
137 "} // namespace A",
138 fixNamespaceEndComments(
139 "namespace /* comment */ [[deprecated(\"foo\")]] /* comment */ A {\n"
140 "int i;\n"
141 "int j;\n"
142 "}"));
143 EXPECT_EQ("namespace /* comment */ [[deprecated(\"foo\")]] A {\n"
144 "int i;\n"
145 "int j;\n"
146 "} // namespace A",
147 fixNamespaceEndComments(
148 "namespace /* comment */ [[deprecated(\"foo\")]] A {\n"
149 "int i;\n"
150 "int j;\n"
151 "}"));
152 EXPECT_EQ(
153 "#define M(x) x##x\n"
154 "namespace /* comment */ [[deprecated(\"foo\")]] /* comment */ M(x) {\n"
155 "int i;\n"
156 "int j;\n"
157 "} // namespace M(x)",
158 fixNamespaceEndComments("#define M(x) x##x\n"
159 "namespace /* comment */ "
160 "[[deprecated(\"foo\")]] /* comment */ M(x) {\n"
161 "int i;\n"
162 "int j;\n"
163 "}"));
164 EXPECT_EQ("#define M(x) x##x\n"
165 "namespace /* comment */ [[deprecated(\"foo\")]] /* comment */ "
166 "A::M(x) {\n"
167 "int i;\n"
168 "int j;\n"
169 "} // namespace A::M(x)",
170 fixNamespaceEndComments(
171 "#define M(x) x##x\n"
172 "namespace /* comment */ "
173 "[[deprecated(\"foo\")]] /* comment */ A::M(x) {\n"
174 "int i;\n"
175 "int j;\n"
176 "}"));
177 EXPECT_EQ("#define M(x) x##x\n"
178 "namespace /* comment */ [[deprecated(\"foo\")]] /* comment */ "
179 "M(x) /* comment */ {\n"
180 "int i;\n"
181 "int j;\n"
182 "} // namespace M(x)",
183 fixNamespaceEndComments(
184 "#define M(x) x##x\n"
185 "namespace /* comment */ [[deprecated(\"foo\")]] /* comment "
186 "*/ M(x) /* comment */ {\n"
187 "int i;\n"
188 "int j;\n"
189 "}"));
190 EXPECT_EQ("#define M(x) x##x\n"
191 "namespace /* comment */ [[deprecated(\"foo\")]] /* comment */ "
192 "A::M(x) /* comment */ {\n"
193 "int i;\n"
194 "int j;\n"
195 "} // namespace A::M(x)",
196 fixNamespaceEndComments(
197 "#define M(x) x##x\n"
198 "namespace /* comment */ [[deprecated(\"foo\")]] /* comment "
199 "*/ A::M(x) /* comment */ {\n"
200 "int i;\n"
201 "int j;\n"
202 "}"));
203 EXPECT_EQ("#define M(x) x##x\n"
204 "namespace A M(x) {\n"
205 "int i;\n"
206 "int j;\n"
207 "} // namespace A M(x)",
208 fixNamespaceEndComments("#define M(x) x##x\n"
209 "namespace A M(x) {\n"
210 "int i;\n"
211 "int j;\n"
212 "}"));
213 EXPECT_EQ(
214 "#define B __attribute__((availability(macos, introduced=10.15)))\n"
215 "namespace A B {\n"
216 "int i;\n"
217 "int j;\n"
218 "} // namespace A B",
219 fixNamespaceEndComments(
220 "#define B __attribute__((availability(macos, introduced=10.15)))\n"
221 "namespace A B {\n"
222 "int i;\n"
223 "int j;\n"
224 "}"));
225 EXPECT_EQ("#define M(x) x##x\n"
226 "namespace A::B M(x) {\n"
227 "int i;\n"
228 "int j;\n"
229 "} // namespace A::B",
230 fixNamespaceEndComments("#define M(x) x##x\n"
231 "namespace A::B M(x) {\n"
232 "int i;\n"
233 "int j;\n"
234 "}"));
235 EXPECT_EQ(
236 "namespace A __attribute__((availability(macos, introduced=10.15))) {\n"
237 "int i;\n"
238 "int j;\n"
239 "} // namespace A",
240 fixNamespaceEndComments(
241 "namespace A __attribute__((availability(macos, introduced=10.15))) "
242 "{\n"
243 "int i;\n"
244 "int j;\n"
245 "}"));
246 EXPECT_EQ("inline namespace A {\n"
247 "int i;\n"
248 "int j;\n"
249 "} // namespace A",
250 fixNamespaceEndComments("inline namespace A {\n"
251 "int i;\n"
252 "int j;\n"
253 "}"));
255 EXPECT_EQ("namespace [[deprecated(\"foo\")]] A::B {\n"
256 "int i;\n"
257 "int j;\n"
258 "} // namespace A::B",
259 fixNamespaceEndComments("namespace [[deprecated(\"foo\")]] A::B {\n"
260 "int i;\n"
261 "int j;\n"
262 "}"));
264 EXPECT_EQ("namespace [[deprecated(\"foo\")]] A::inline B::inline C {\n"
265 "int i;\n"
266 "int j;\n"
267 "} // namespace A::inline B::inline C",
268 fixNamespaceEndComments(
269 "namespace [[deprecated(\"foo\")]] A::inline B::inline C {\n"
270 "int i;\n"
271 "int j;\n"
272 "}"));
274 EXPECT_EQ("namespace DEPRECATED A::B {\n"
275 "int i;\n"
276 "int j;\n"
277 "} // namespace A::B",
278 fixNamespaceEndComments("namespace DEPRECATED A::B {\n"
279 "int i;\n"
280 "int j;\n"
281 "}"));
283 EXPECT_EQ("inline namespace [[deprecated]] A {\n"
284 "int i;\n"
285 "int j;\n"
286 "} // namespace A",
287 fixNamespaceEndComments("inline namespace [[deprecated]] A {\n"
288 "int i;\n"
289 "int j;\n"
290 "}"));
292 EXPECT_EQ("namespace ::A {\n"
293 "int i;\n"
294 "int j;\n"
295 "} // namespace ::A",
296 fixNamespaceEndComments("namespace ::A {\n"
297 "int i;\n"
298 "int j;\n"
299 "}"));
300 EXPECT_EQ("namespace ::A::B {\n"
301 "int i;\n"
302 "int j;\n"
303 "} // namespace ::A::B",
304 fixNamespaceEndComments("namespace ::A::B {\n"
305 "int i;\n"
306 "int j;\n"
307 "}"));
308 EXPECT_EQ("namespace /**/::/**/A/**/::/**/B/**/ {\n"
309 "int i;\n"
310 "int j;\n"
311 "} // namespace ::A::B",
312 fixNamespaceEndComments("namespace /**/::/**/A/**/::/**/B/**/ {\n"
313 "int i;\n"
314 "int j;\n"
315 "}"));
316 EXPECT_EQ("namespace A {\n"
317 "namespace B {\n"
318 "int i;\n"
319 "}\n"
320 "} // namespace A",
321 fixNamespaceEndComments("namespace A {\n"
322 "namespace B {\n"
323 "int i;\n"
324 "}\n"
325 "}"));
326 EXPECT_EQ("namespace A {\n"
327 "namespace B {\n"
328 "int i;\n"
329 "int j;\n"
330 "} // namespace B\n"
331 "} // namespace A",
332 fixNamespaceEndComments("namespace A {\n"
333 "namespace B {\n"
334 "int i;\n"
335 "int j;\n"
336 "}\n"
337 "}"));
338 EXPECT_EQ("namespace A {\n"
339 "int a;\n"
340 "int b;\n"
341 "} // namespace A\n"
342 "namespace B {\n"
343 "int b;\n"
344 "int a;\n"
345 "} // namespace B",
346 fixNamespaceEndComments("namespace A {\n"
347 "int a;\n"
348 "int b;\n"
349 "}\n"
350 "namespace B {\n"
351 "int b;\n"
352 "int a;\n"
353 "}"));
354 EXPECT_EQ("namespace A {\n"
355 "int a1;\n"
356 "int a2;\n"
357 "} // namespace A\n"
358 "namespace A {\n"
359 "int a2;\n"
360 "int a1;\n"
361 "} // namespace A",
362 fixNamespaceEndComments("namespace A {\n"
363 "int a1;\n"
364 "int a2;\n"
365 "}\n"
366 "namespace A {\n"
367 "int a2;\n"
368 "int a1;\n"
369 "}"));
370 EXPECT_EQ("namespace A {\n"
371 "int a;\n"
372 "int b;\n"
373 "} // namespace A\n"
374 "// comment about b\n"
375 "int b;",
376 fixNamespaceEndComments("namespace A {\n"
377 "int a;\n"
378 "int b;\n"
379 "}\n"
380 "// comment about b\n"
381 "int b;"));
383 EXPECT_EQ("namespace A {\n"
384 "namespace B {\n"
385 "namespace C {\n"
386 "namespace D {\n"
387 "}\n"
388 "} // namespace C\n"
389 "} // namespace B\n"
390 "} // namespace A",
391 fixNamespaceEndComments("namespace A {\n"
392 "namespace B {\n"
393 "namespace C {\n"
394 "namespace D {\n"
395 "}\n"
396 "}\n"
397 "}\n"
398 "}"));
400 // Add comment for namespaces which will be 'compacted'
401 FormatStyle CompactNamespacesStyle = getLLVMStyle();
402 CompactNamespacesStyle.CompactNamespaces = true;
403 EXPECT_EQ("namespace out { namespace in {\n"
404 "int i;\n"
405 "int j;\n"
406 "}} // namespace out::in",
407 fixNamespaceEndComments("namespace out { namespace in {\n"
408 "int i;\n"
409 "int j;\n"
410 "}}",
411 CompactNamespacesStyle));
412 EXPECT_EQ("namespace out {\n"
413 "namespace in {\n"
414 "int i;\n"
415 "int j;\n"
416 "}\n"
417 "} // namespace out::in",
418 fixNamespaceEndComments("namespace out {\n"
419 "namespace in {\n"
420 "int i;\n"
421 "int j;\n"
422 "}\n"
423 "}",
424 CompactNamespacesStyle));
425 EXPECT_EQ("namespace out { namespace in {\n"
426 "int i;\n"
427 "int j;\n"
428 "};} // namespace out::in",
429 fixNamespaceEndComments("namespace out { namespace in {\n"
430 "int i;\n"
431 "int j;\n"
432 "};}",
433 CompactNamespacesStyle));
434 EXPECT_EQ("namespace out { namespace {\n"
435 "int i;\n"
436 "int j;\n"
437 "}} // namespace out",
438 fixNamespaceEndComments("namespace out { namespace {\n"
439 "int i;\n"
440 "int j;\n"
441 "}}",
442 CompactNamespacesStyle));
444 // Adds an end comment after a semicolon.
445 EXPECT_EQ("namespace {\n"
446 "int i;\n"
447 "int j;\n"
448 "}; // namespace",
449 fixNamespaceEndComments("namespace {\n"
450 "int i;\n"
451 "int j;\n"
452 "};"));
453 EXPECT_EQ("namespace A {\n"
454 "int i;\n"
455 "int j;\n"
456 "}; // namespace A",
457 fixNamespaceEndComments("namespace A {\n"
458 "int i;\n"
459 "int j;\n"
460 "};"));
461 EXPECT_EQ("namespace A {\n"
462 "int i;\n"
463 "int j;\n"
464 "}; // namespace A\n"
465 "// unrelated",
466 fixNamespaceEndComments("namespace A {\n"
467 "int i;\n"
468 "int j;\n"
469 "};\n"
470 "// unrelated"));
473 TEST_F(NamespaceEndCommentsFixerTest, WorksForObjCpp) {
474 FormatStyle ObjCppStyle = getLLVMStyle();
475 ObjCppStyle.Language = FormatStyle::LK_ObjC;
476 EXPECT_EQ("namespace {\n"
477 "int i;\n"
478 "int j;\n"
479 "} // namespace",
480 fixNamespaceEndComments("namespace {\n"
481 "int i;\n"
482 "int j;\n"
483 "}",
484 ObjCppStyle));
487 TEST_F(NamespaceEndCommentsFixerTest, AddsMacroEndComment) {
488 FormatStyle Style = getLLVMStyle();
489 Style.NamespaceMacros.push_back("TESTSUITE");
491 EXPECT_EQ("TESTSUITE() {\n"
492 "int i;\n"
493 "int j;\n"
494 "} // TESTSUITE()",
495 fixNamespaceEndComments("TESTSUITE() {\n"
496 "int i;\n"
497 "int j;\n"
498 "}",
499 Style));
501 EXPECT_EQ("TESTSUITE(A) {\n"
502 "int i;\n"
503 "int j;\n"
504 "} // TESTSUITE(A)",
505 fixNamespaceEndComments("TESTSUITE(A) {\n"
506 "int i;\n"
507 "int j;\n"
508 "}",
509 Style));
510 EXPECT_EQ("inline TESTSUITE(A) {\n"
511 "int i;\n"
512 "int j;\n"
513 "} // TESTSUITE(A)",
514 fixNamespaceEndComments("inline TESTSUITE(A) {\n"
515 "int i;\n"
516 "int j;\n"
517 "}",
518 Style));
519 EXPECT_EQ("TESTSUITE(::A) {\n"
520 "int i;\n"
521 "int j;\n"
522 "} // TESTSUITE(::A)",
523 fixNamespaceEndComments("TESTSUITE(::A) {\n"
524 "int i;\n"
525 "int j;\n"
526 "}",
527 Style));
528 EXPECT_EQ("TESTSUITE(::A::B) {\n"
529 "int i;\n"
530 "int j;\n"
531 "} // TESTSUITE(::A::B)",
532 fixNamespaceEndComments("TESTSUITE(::A::B) {\n"
533 "int i;\n"
534 "int j;\n"
535 "}",
536 Style));
537 EXPECT_EQ("TESTSUITE(/**/::/**/A/**/::/**/B/**/) {\n"
538 "int i;\n"
539 "int j;\n"
540 "} // TESTSUITE(::A::B)",
541 fixNamespaceEndComments("TESTSUITE(/**/::/**/A/**/::/**/B/**/) {\n"
542 "int i;\n"
543 "int j;\n"
544 "}",
545 Style));
546 EXPECT_EQ("TESTSUITE(A, B) {\n"
547 "int i;\n"
548 "int j;\n"
549 "} // TESTSUITE(A)",
550 fixNamespaceEndComments("TESTSUITE(A, B) {\n"
551 "int i;\n"
552 "int j;\n"
553 "}",
554 Style));
555 EXPECT_EQ("TESTSUITE(\"Test1\") {\n"
556 "int i;\n"
557 "int j;\n"
558 "} // TESTSUITE(\"Test1\")",
559 fixNamespaceEndComments("TESTSUITE(\"Test1\") {\n"
560 "int i;\n"
561 "int j;\n"
562 "}",
563 Style));
566 TEST_F(NamespaceEndCommentsFixerTest, AddsNewlineIfNeeded) {
567 EXPECT_EQ("namespace A {\n"
568 "int i;\n"
569 "int j;\n"
570 "} // namespace A\n"
571 " int k;",
572 fixNamespaceEndComments("namespace A {\n"
573 "int i;\n"
574 "int j;\n"
575 "} int k;"));
576 EXPECT_EQ("namespace {\n"
577 "int i;\n"
578 "int j;\n"
579 "} // namespace\n"
580 " int k;",
581 fixNamespaceEndComments("namespace {\n"
582 "int i;\n"
583 "int j;\n"
584 "} int k;"));
585 EXPECT_EQ("namespace A {\n"
586 "int i;\n"
587 "int j;\n"
588 "} // namespace A\n"
589 " namespace B {\n"
590 "int j;\n"
591 "int k;\n"
592 "} // namespace B",
593 fixNamespaceEndComments("namespace A {\n"
594 "int i;\n"
595 "int j;\n"
596 "} namespace B {\n"
597 "int j;\n"
598 "int k;\n"
599 "}"));
600 EXPECT_EQ("namespace {\n"
601 "int i;\n"
602 "int j;\n"
603 "}; // namespace\n"
604 "int k;",
605 fixNamespaceEndComments("namespace {\n"
606 "int i;\n"
607 "int j;\n"
608 "};int k;"));
609 EXPECT_EQ("namespace {\n"
610 "int i;\n"
611 "int j;\n"
612 "}; // namespace\n"
613 ";",
614 fixNamespaceEndComments("namespace {\n"
615 "int i;\n"
616 "int j;\n"
617 "};;"));
620 TEST_F(NamespaceEndCommentsFixerTest, DoesNotAddEndCommentForShortNamespace) {
621 EXPECT_EQ("namespace {}", fixNamespaceEndComments("namespace {}"));
622 EXPECT_EQ("namespace A {}", fixNamespaceEndComments("namespace A {}"));
623 EXPECT_EQ("namespace A { a }", fixNamespaceEndComments("namespace A { a }"));
624 EXPECT_EQ("namespace A { a };",
625 fixNamespaceEndComments("namespace A { a };"));
628 TEST_F(NamespaceEndCommentsFixerTest, DoesNotAddCommentAfterUnaffectedRBrace) {
629 EXPECT_EQ("namespace A {\n"
630 "int i;\n"
631 "}",
632 fixNamespaceEndComments("namespace A {\n"
633 "int i;\n"
634 "}",
635 // The range (16, 3) spans the 'int' above.
636 /*Ranges=*/{1, tooling::Range(16, 3)}));
637 EXPECT_EQ("namespace A {\n"
638 "int i;\n"
639 "};",
640 fixNamespaceEndComments("namespace A {\n"
641 "int i;\n"
642 "};",
643 // The range (16, 3) spans the 'int' above.
644 /*Ranges=*/{1, tooling::Range(16, 3)}));
647 TEST_F(NamespaceEndCommentsFixerTest,
648 DoesNotAddCommentAfterRBraceInPPDirective) {
649 EXPECT_EQ("#define SAD \\\n"
650 "namespace A { \\\n"
651 "int i; \\\n"
652 "}",
653 fixNamespaceEndComments("#define SAD \\\n"
654 "namespace A { \\\n"
655 "int i; \\\n"
656 "}"));
659 TEST_F(NamespaceEndCommentsFixerTest, KeepsValidEndComment) {
660 EXPECT_TRUE(isFormatted("namespace {\n"
661 "int i;\n"
662 "} // end anonymous namespace"));
663 EXPECT_TRUE(isFormatted("namespace A {\n"
664 "int i;\n"
665 "} /* end of namespace A */"));
666 EXPECT_TRUE(isFormatted("namespace A {\n"
667 "int i;\n"
668 "} // namespace A"));
669 EXPECT_TRUE(isFormatted("namespace A::B {\n"
670 "int i;\n"
671 "} // end namespace A::B"));
672 EXPECT_TRUE(isFormatted("namespace A {\n"
673 "int i;\n"
674 "}; // end namespace A"));
675 EXPECT_TRUE(isFormatted("namespace {\n"
676 "int i;\n"
677 "}; /* unnamed namespace */"));
678 EXPECT_TRUE(isFormatted("namespace a::inline b {\n"
679 "int c;\n"
680 "}; // namespace a::inline b"));
683 TEST_F(NamespaceEndCommentsFixerTest, KeepsValidMacroEndComment) {
684 FormatStyle Style = getLLVMStyle();
685 Style.NamespaceMacros.push_back("TESTSUITE");
687 EXPECT_TRUE(isFormatted("TESTSUITE() {\n"
688 "int i;\n"
689 "} // end anonymous TESTSUITE()",
690 Style));
691 EXPECT_TRUE(isFormatted("TESTSUITE(A) {\n"
692 "int i;\n"
693 "} /* end of TESTSUITE(A) */",
694 Style));
695 EXPECT_TRUE(isFormatted("TESTSUITE(A) {\n"
696 "int i;\n"
697 "} // TESTSUITE(A)",
698 Style));
699 EXPECT_TRUE(isFormatted("TESTSUITE(A::B) {\n"
700 "int i;\n"
701 "} // end TESTSUITE(A::B)",
702 Style));
703 EXPECT_TRUE(isFormatted("TESTSUITE(A) {\n"
704 "int i;\n"
705 "}; // end TESTSUITE(A)",
706 Style));
707 EXPECT_TRUE(isFormatted("TESTSUITE() {\n"
708 "int i;\n"
709 "}; /* unnamed TESTSUITE() */",
710 Style));
711 EXPECT_TRUE(isFormatted("TESTSUITE(\"foo\") {\n"
712 "int i;\n"
713 "} // TESTSUITE(\"foo\")",
714 Style));
717 TEST_F(NamespaceEndCommentsFixerTest, UpdatesInvalidEndLineComment) {
718 EXPECT_EQ("namespace {\n"
719 "int i;\n"
720 "} // namespace",
721 fixNamespaceEndComments("namespace {\n"
722 "int i;\n"
723 "} // namespace A"));
724 EXPECT_EQ("namespace A {\n"
725 "int i;\n"
726 "} // namespace A",
727 fixNamespaceEndComments("namespace A {\n"
728 "int i;\n"
729 "} // namespace"));
730 EXPECT_EQ("namespace A {\n"
731 "int i;\n"
732 "} // namespace A",
733 fixNamespaceEndComments("namespace A {\n"
734 "int i;\n"
735 "} //"));
736 EXPECT_EQ("namespace A {\n"
737 "int i;\n"
738 "}; // namespace A",
739 fixNamespaceEndComments("namespace A {\n"
740 "int i;\n"
741 "}; //"));
743 EXPECT_EQ("namespace A {\n"
744 "int i;\n"
745 "} // namespace A",
746 fixNamespaceEndComments("namespace A {\n"
747 "int i;\n"
748 "} // banamespace A"));
749 EXPECT_EQ("namespace A {\n"
750 "int i;\n"
751 "}; // namespace A",
752 fixNamespaceEndComments("namespace A {\n"
753 "int i;\n"
754 "}; // banamespace A"));
755 // Updates invalid line comments even for short namespaces.
756 EXPECT_EQ("namespace A {} // namespace A",
757 fixNamespaceEndComments("namespace A {} // namespace"));
758 EXPECT_EQ("namespace A {}; // namespace A",
759 fixNamespaceEndComments("namespace A {}; // namespace"));
761 // Update invalid comments for compacted namespaces.
762 FormatStyle CompactNamespacesStyle = getLLVMStyle();
763 CompactNamespacesStyle.CompactNamespaces = true;
764 EXPECT_EQ("namespace out { namespace in {\n"
765 "}} // namespace out::in",
766 fixNamespaceEndComments("namespace out { namespace in {\n"
767 "}} // namespace out",
768 CompactNamespacesStyle));
769 EXPECT_EQ("namespace out { namespace in {\n"
770 "}} // namespace out::in",
771 fixNamespaceEndComments("namespace out { namespace in {\n"
772 "}} // namespace in",
773 CompactNamespacesStyle));
774 EXPECT_EQ("namespace out { namespace in {\n"
775 "}\n"
776 "} // namespace out::in",
777 fixNamespaceEndComments("namespace out { namespace in {\n"
778 "}// banamespace in\n"
779 "} // namespace out",
780 CompactNamespacesStyle));
781 EXPECT_EQ("namespace out { namespace {\n"
782 "}} // namespace out",
783 fixNamespaceEndComments("namespace out { namespace {\n"
784 "}} // namespace out::",
785 CompactNamespacesStyle));
788 TEST_F(NamespaceEndCommentsFixerTest, UpdatesInvalidMacroEndLineComment) {
789 FormatStyle Style = getLLVMStyle();
790 Style.NamespaceMacros.push_back("TESTSUITE");
792 EXPECT_EQ("TESTSUITE() {\n"
793 "int i;\n"
794 "} // TESTSUITE()",
795 fixNamespaceEndComments("TESTSUITE() {\n"
796 "int i;\n"
797 "} // TESTSUITE(A)",
798 Style));
799 EXPECT_EQ("TESTSUITE(A) {\n"
800 "int i;\n"
801 "} // TESTSUITE(A)",
802 fixNamespaceEndComments("TESTSUITE(A) {\n"
803 "int i;\n"
804 "} // TESTSUITE()",
805 Style));
806 EXPECT_EQ("TESTSUITE(A) {\n"
807 "int i;\n"
808 "} // TESTSUITE(A)",
809 fixNamespaceEndComments("TESTSUITE(A) {\n"
810 "int i;\n"
811 "} //",
812 Style));
813 EXPECT_EQ("TESTSUITE(A) {\n"
814 "int i;\n"
815 "}; // TESTSUITE(A)",
816 fixNamespaceEndComments("TESTSUITE(A) {\n"
817 "int i;\n"
818 "}; //",
819 Style));
820 EXPECT_EQ("TESTSUITE(A) {\n"
821 "int i;\n"
822 "} // TESTSUITE(A)",
823 fixNamespaceEndComments("TESTSUITE(A) {\n"
824 "int i;\n"
825 "} // TESTSUITE A",
826 Style));
827 EXPECT_EQ("TESTSUITE() {\n"
828 "int i;\n"
829 "} // TESTSUITE()",
830 fixNamespaceEndComments("TESTSUITE() {\n"
831 "int i;\n"
832 "} // TESTSUITE",
833 Style));
834 EXPECT_EQ("TESTSUITE(A) {\n"
835 "int i;\n"
836 "} // TESTSUITE(A)",
837 fixNamespaceEndComments("TESTSUITE(A) {\n"
838 "int i;\n"
839 "} // TOASTSUITE(A)",
840 Style));
841 EXPECT_EQ("TESTSUITE(A) {\n"
842 "int i;\n"
843 "}; // TESTSUITE(A)",
844 fixNamespaceEndComments("TESTSUITE(A) {\n"
845 "int i;\n"
846 "}; // TOASTSUITE(A)",
847 Style));
848 // Updates invalid line comments even for short namespaces.
849 EXPECT_EQ("TESTSUITE(A) {} // TESTSUITE(A)",
850 fixNamespaceEndComments("TESTSUITE(A) {} // TESTSUITE()", Style));
851 EXPECT_EQ("TESTSUITE(A) {}; // TESTSUITE(A)",
852 fixNamespaceEndComments("TESTSUITE(A) {}; // TESTSUITE()", Style));
854 // Update invalid comments for compacted namespaces.
855 FormatStyle CompactNamespacesStyle = getLLVMStyle();
856 CompactNamespacesStyle.CompactNamespaces = true;
857 CompactNamespacesStyle.NamespaceMacros.push_back("TESTSUITE");
859 EXPECT_EQ("TESTSUITE(out) { TESTSUITE(in) {\n"
860 "}} // TESTSUITE(out::in)",
861 fixNamespaceEndComments("TESTSUITE(out) { TESTSUITE(in) {\n"
862 "}} // TESTSUITE(out)",
863 CompactNamespacesStyle));
864 EXPECT_EQ("TESTSUITE(out) { TESTSUITE(in) {\n"
865 "}} // TESTSUITE(out::in)",
866 fixNamespaceEndComments("TESTSUITE(out) { TESTSUITE(in) {\n"
867 "}} // TESTSUITE(in)",
868 CompactNamespacesStyle));
869 EXPECT_EQ("TESTSUITE(out) { TESTSUITE(in) {\n"
870 "}\n"
871 "} // TESTSUITE(out::in)",
872 fixNamespaceEndComments("TESTSUITE(out) { TESTSUITE(in) {\n"
873 "}// TAOSTSUITE(in)\n"
874 "} // TESTSUITE(out)",
875 CompactNamespacesStyle));
878 TEST_F(NamespaceEndCommentsFixerTest, UpdatesInvalidEndBlockComment) {
879 EXPECT_EQ("namespace {\n"
880 "int i;\n"
881 "} // namespace",
882 fixNamespaceEndComments("namespace {\n"
883 "int i;\n"
884 "} /* namespace A */"));
885 EXPECT_EQ("namespace A {\n"
886 "int i;\n"
887 "} // namespace A",
888 fixNamespaceEndComments("namespace A {\n"
889 "int i;\n"
890 "} /* end namespace */"));
891 EXPECT_EQ("namespace A {\n"
892 "int i;\n"
893 "} // namespace A",
894 fixNamespaceEndComments("namespace A {\n"
895 "int i;\n"
896 "} /**/"));
897 EXPECT_EQ("namespace A {\n"
898 "int i;\n"
899 "} // namespace A",
900 fixNamespaceEndComments("namespace A {\n"
901 "int i;\n"
902 "} /* end unnamed namespace */"));
903 EXPECT_EQ("namespace A {\n"
904 "int i;\n"
905 "} // namespace A",
906 fixNamespaceEndComments("namespace A {\n"
907 "int i;\n"
908 "} /* banamespace A */"));
909 EXPECT_EQ("namespace A {\n"
910 "int i;\n"
911 "}; // namespace A",
912 fixNamespaceEndComments("namespace A {\n"
913 "int i;\n"
914 "}; /* banamespace A */"));
915 EXPECT_EQ("namespace A {} // namespace A",
916 fixNamespaceEndComments("namespace A {} /**/"));
917 EXPECT_EQ("namespace A {}; // namespace A",
918 fixNamespaceEndComments("namespace A {}; /**/"));
921 TEST_F(NamespaceEndCommentsFixerTest, UpdatesInvalidMacroEndBlockComment) {
922 FormatStyle Style = getLLVMStyle();
923 Style.NamespaceMacros.push_back("TESTSUITE");
925 EXPECT_EQ("TESTSUITE() {\n"
926 "int i;\n"
927 "} // TESTSUITE()",
928 fixNamespaceEndComments("TESTSUITE() {\n"
929 "int i;\n"
930 "} /* TESTSUITE(A) */",
931 Style));
932 EXPECT_EQ("TESTSUITE(A) {\n"
933 "int i;\n"
934 "} // TESTSUITE(A)",
935 fixNamespaceEndComments("TESTSUITE(A) {\n"
936 "int i;\n"
937 "} /* end TESTSUITE() */",
938 Style));
939 EXPECT_EQ("TESTSUITE(A) {\n"
940 "int i;\n"
941 "} // TESTSUITE(A)",
942 fixNamespaceEndComments("TESTSUITE(A) {\n"
943 "int i;\n"
944 "} /**/",
945 Style));
946 EXPECT_EQ("TESTSUITE(A) {\n"
947 "int i;\n"
948 "} // TESTSUITE(A)",
949 fixNamespaceEndComments("TESTSUITE(A) {\n"
950 "int i;\n"
951 "} /* end unnamed TESTSUITE() */",
952 Style));
953 EXPECT_EQ("TESTSUITE(A) {\n"
954 "int i;\n"
955 "} // TESTSUITE(A)",
956 fixNamespaceEndComments("TESTSUITE(A) {\n"
957 "int i;\n"
958 "} /* TOASTSUITE(A) */",
959 Style));
960 EXPECT_EQ("TESTSUITE(A) {\n"
961 "int i;\n"
962 "}; // TESTSUITE(A)",
963 fixNamespaceEndComments("TESTSUITE(A) {\n"
964 "int i;\n"
965 "}; /* TAOSTSUITE(A) */",
966 Style));
967 EXPECT_EQ("TESTSUITE(A) {} // TESTSUITE(A)",
968 fixNamespaceEndComments("TESTSUITE(A) {} /**/", Style));
969 EXPECT_EQ("TESTSUITE(A) {}; // TESTSUITE(A)",
970 fixNamespaceEndComments("TESTSUITE(A) {}; /**/", Style));
973 TEST_F(NamespaceEndCommentsFixerTest,
974 DoesNotAddEndCommentForNamespacesControlledByMacros) {
975 EXPECT_EQ("#ifdef 1\n"
976 "namespace A {\n"
977 "#elseif\n"
978 "namespace B {\n"
979 "#endif\n"
980 "int i;\n"
981 "}\n"
982 "}",
983 fixNamespaceEndComments("#ifdef 1\n"
984 "namespace A {\n"
985 "#elseif\n"
986 "namespace B {\n"
987 "#endif\n"
988 "int i;\n"
989 "}\n"
990 "}"));
993 TEST_F(NamespaceEndCommentsFixerTest, AddsEndCommentForNamespacesAroundMacros) {
994 // Conditional blocks around are fine
995 EXPECT_EQ("namespace A {\n"
996 "#if 1\n"
997 "int i;\n"
998 "#endif\n"
999 "} // namespace A",
1000 fixNamespaceEndComments("namespace A {\n"
1001 "#if 1\n"
1002 "int i;\n"
1003 "#endif\n"
1004 "}"));
1005 EXPECT_EQ("#if 1\n"
1006 "#endif\n"
1007 "namespace A {\n"
1008 "int i;\n"
1009 "int j;\n"
1010 "} // namespace A",
1011 fixNamespaceEndComments("#if 1\n"
1012 "#endif\n"
1013 "namespace A {\n"
1014 "int i;\n"
1015 "int j;\n"
1016 "}"));
1017 EXPECT_EQ("namespace A {\n"
1018 "int i;\n"
1019 "int j;\n"
1020 "} // namespace A\n"
1021 "#if 1\n"
1022 "#endif",
1023 fixNamespaceEndComments("namespace A {\n"
1024 "int i;\n"
1025 "int j;\n"
1026 "}\n"
1027 "#if 1\n"
1028 "#endif"));
1029 EXPECT_EQ("#if 1\n"
1030 "namespace A {\n"
1031 "int i;\n"
1032 "int j;\n"
1033 "} // namespace A\n"
1034 "#endif",
1035 fixNamespaceEndComments("#if 1\n"
1036 "namespace A {\n"
1037 "int i;\n"
1038 "int j;\n"
1039 "}\n"
1040 "#endif"));
1042 // Macro definition has no impact
1043 EXPECT_EQ("namespace A {\n"
1044 "#define FOO\n"
1045 "int i;\n"
1046 "} // namespace A",
1047 fixNamespaceEndComments("namespace A {\n"
1048 "#define FOO\n"
1049 "int i;\n"
1050 "}"));
1051 EXPECT_EQ("#define FOO\n"
1052 "namespace A {\n"
1053 "int i;\n"
1054 "int j;\n"
1055 "} // namespace A",
1056 fixNamespaceEndComments("#define FOO\n"
1057 "namespace A {\n"
1058 "int i;\n"
1059 "int j;\n"
1060 "}"));
1061 EXPECT_EQ("namespace A {\n"
1062 "int i;\n"
1063 "int j;\n"
1064 "} // namespace A\n"
1065 "#define FOO",
1066 fixNamespaceEndComments("namespace A {\n"
1067 "int i;\n"
1068 "int j;\n"
1069 "}\n"
1070 "#define FOO"));
1072 // No replacement if open & close in different conditional blocks
1073 EXPECT_EQ("#if 1\n"
1074 "namespace A {\n"
1075 "#endif\n"
1076 "int i;\n"
1077 "int j;\n"
1078 "#if 1\n"
1079 "}\n"
1080 "#endif",
1081 fixNamespaceEndComments("#if 1\n"
1082 "namespace A {\n"
1083 "#endif\n"
1084 "int i;\n"
1085 "int j;\n"
1086 "#if 1\n"
1087 "}\n"
1088 "#endif"));
1089 EXPECT_EQ("#ifdef A\n"
1090 "namespace A {\n"
1091 "#endif\n"
1092 "int i;\n"
1093 "int j;\n"
1094 "#ifdef B\n"
1095 "}\n"
1096 "#endif",
1097 fixNamespaceEndComments("#ifdef A\n"
1098 "namespace A {\n"
1099 "#endif\n"
1100 "int i;\n"
1101 "int j;\n"
1102 "#ifdef B\n"
1103 "}\n"
1104 "#endif"));
1106 // No replacement inside unreachable conditional block
1107 EXPECT_EQ("#if 0\n"
1108 "namespace A {\n"
1109 "int i;\n"
1110 "int j;\n"
1111 "}\n"
1112 "#endif",
1113 fixNamespaceEndComments("#if 0\n"
1114 "namespace A {\n"
1115 "int i;\n"
1116 "int j;\n"
1117 "}\n"
1118 "#endif"));
1121 TEST_F(NamespaceEndCommentsFixerTest,
1122 DoesNotAddEndCommentForNamespacesInMacroDeclarations) {
1123 EXPECT_EQ("#ifdef 1\n"
1124 "namespace A {\n"
1125 "#elseif\n"
1126 "namespace B {\n"
1127 "#endif\n"
1128 "int i;\n"
1129 "}\n"
1130 "}",
1131 fixNamespaceEndComments("#ifdef 1\n"
1132 "namespace A {\n"
1133 "#elseif\n"
1134 "namespace B {\n"
1135 "#endif\n"
1136 "int i;\n"
1137 "}\n"
1138 "}"));
1139 EXPECT_EQ("namespace {\n"
1140 "int i;\n"
1141 "int j;\n"
1142 "} // namespace\n"
1143 "#if A\n"
1144 "int i;\n"
1145 "#else\n"
1146 "int j;\n"
1147 "#endif",
1148 fixNamespaceEndComments("namespace {\n"
1149 "int i;\n"
1150 "int j;\n"
1151 "}\n"
1152 "#if A\n"
1153 "int i;\n"
1154 "#else\n"
1155 "int j;\n"
1156 "#endif"));
1157 EXPECT_EQ("#if A\n"
1158 "namespace A {\n"
1159 "#else\n"
1160 "namespace B {\n"
1161 "#endif\n"
1162 "int i;\n"
1163 "int j;\n"
1164 "}",
1165 fixNamespaceEndComments("#if A\n"
1166 "namespace A {\n"
1167 "#else\n"
1168 "namespace B {\n"
1169 "#endif\n"
1170 "int i;\n"
1171 "int j;\n"
1172 "}"));
1173 EXPECT_EQ("#if A\n"
1174 "namespace A {\n"
1175 "#else\n"
1176 "namespace B {\n"
1177 "#endif\n"
1178 "int i;\n"
1179 "int j;\n"
1180 "} // namespace A",
1181 fixNamespaceEndComments("#if A\n"
1182 "namespace A {\n"
1183 "#else\n"
1184 "namespace B {\n"
1185 "#endif\n"
1186 "int i;\n"
1187 "int j;\n"
1188 "} // namespace A"));
1189 EXPECT_EQ("#if A\n"
1190 "namespace A {\n"
1191 "#else\n"
1192 "namespace B {\n"
1193 "#endif\n"
1194 "int i;\n"
1195 "int j;\n"
1196 "} // namespace B",
1197 fixNamespaceEndComments("#if A\n"
1198 "namespace A {\n"
1199 "#else\n"
1200 "namespace B {\n"
1201 "#endif\n"
1202 "int i;\n"
1203 "int j;\n"
1204 "} // namespace B"));
1205 EXPECT_EQ("namespace A\n"
1206 "int i;\n"
1207 "int j;\n"
1208 "#if A\n"
1209 "}\n"
1210 "#else\n"
1211 "}\n"
1212 "#endif",
1213 fixNamespaceEndComments("namespace A\n"
1214 "int i;\n"
1215 "int j;\n"
1216 "#if A\n"
1217 "}\n"
1218 "#else\n"
1219 "}\n"
1220 "#endif"));
1221 EXPECT_EQ("namespace A\n"
1222 "int i;\n"
1223 "int j;\n"
1224 "#if A\n"
1225 "} // namespace A\n"
1226 "#else\n"
1227 "} // namespace A\n"
1228 "#endif",
1229 fixNamespaceEndComments("namespace A\n"
1230 "int i;\n"
1231 "int j;\n"
1232 "#if A\n"
1233 "} // namespace A\n"
1234 "#else\n"
1235 "} // namespace A\n"
1236 "#endif"));
1239 TEST_F(NamespaceEndCommentsFixerTest,
1240 DoesNotAddEndCommentForUnbalancedRBracesAfterNamespaceEnd) {
1241 EXPECT_EQ("namespace {\n"
1242 "int i;\n"
1243 "} // namespace\n"
1244 "}",
1245 fixNamespaceEndComments("namespace {\n"
1246 "int i;\n"
1247 "} // namespace\n"
1248 "}"));
1251 TEST_F(NamespaceEndCommentsFixerTest, HandlesInlineAtEndOfLine_PR32438) {
1252 EXPECT_EQ("template <int> struct a {};\n"
1253 "struct a<bool{}> b() {\n"
1254 "}\n"
1255 "#define c inline\n"
1256 "void d() {\n"
1257 "}",
1258 fixNamespaceEndComments("template <int> struct a {};\n"
1259 "struct a<bool{}> b() {\n"
1260 "}\n"
1261 "#define c inline\n"
1262 "void d() {\n"
1263 "}"));
1266 TEST_F(NamespaceEndCommentsFixerTest, IgnoreUnbalanced) {
1267 EXPECT_EQ("namespace A {\n"
1268 "class Foo {\n"
1269 "}\n"
1270 "} // namespace A",
1271 fixNamespaceEndComments("namespace A {\n"
1272 "class Foo {\n"
1273 "}\n"
1274 "}"));
1275 EXPECT_EQ("namespace A {\n"
1276 "class Foo {\n"
1277 "}",
1278 fixNamespaceEndComments("namespace A {\n"
1279 "class Foo {\n"
1280 "}"));
1282 EXPECT_EQ("namespace A {\n"
1283 "class Foo {\n"
1284 "}\n"
1285 "}\n"
1286 "}",
1287 fixNamespaceEndComments("namespace A {\n"
1288 "class Foo {\n"
1289 "}\n"
1290 "}\n"
1291 "}"));
1294 using ShortNamespaceLinesTest = NamespaceEndCommentsFixerTest;
1296 TEST_F(ShortNamespaceLinesTest, ZeroUnwrappedLines) {
1297 auto Style = getLLVMStyle();
1298 Style.ShortNamespaceLines = 0u;
1300 EXPECT_EQ("namespace OneLinerNamespace {}",
1301 fixNamespaceEndComments("namespace OneLinerNamespace {}", Style));
1302 EXPECT_EQ("namespace ShortNamespace {\n"
1303 "}",
1304 fixNamespaceEndComments("namespace ShortNamespace {\n"
1305 "}",
1306 Style));
1307 EXPECT_EQ("namespace LongNamespace {\n"
1308 "int i;\n"
1309 "} // namespace LongNamespace",
1310 fixNamespaceEndComments("namespace LongNamespace {\n"
1311 "int i;\n"
1312 "}",
1313 Style));
1316 TEST_F(ShortNamespaceLinesTest, OneUnwrappedLine) {
1317 constexpr auto DefaultUnwrappedLines = 1u;
1318 auto const Style = getLLVMStyle();
1320 EXPECT_EQ(DefaultUnwrappedLines, Style.ShortNamespaceLines);
1321 EXPECT_EQ("namespace ShortNamespace {\n"
1322 "int i;\n"
1323 "}",
1324 fixNamespaceEndComments("namespace ShortNamespace {\n"
1325 "int i;\n"
1326 "}"));
1327 EXPECT_EQ("namespace LongNamespace {\n"
1328 "int i;\n"
1329 "int j;\n"
1330 "} // namespace LongNamespace",
1331 fixNamespaceEndComments("namespace LongNamespace {\n"
1332 "int i;\n"
1333 "int j;\n"
1334 "}"));
1337 TEST_F(ShortNamespaceLinesTest, MultipleUnwrappedLine) {
1338 auto Style = getLLVMStyle();
1339 Style.ShortNamespaceLines = 2u;
1341 EXPECT_EQ("namespace ShortNamespace {\n"
1342 "int i;\n"
1343 "int j;\n"
1344 "}",
1345 fixNamespaceEndComments("namespace ShortNamespace {\n"
1346 "int i;\n"
1347 "int j;\n"
1348 "}",
1349 Style));
1350 EXPECT_EQ("namespace LongNamespace {\n"
1351 "int i;\n"
1352 "int j;\n"
1353 "int k;\n"
1354 "} // namespace LongNamespace",
1355 fixNamespaceEndComments("namespace LongNamespace {\n"
1356 "int i;\n"
1357 "int j;\n"
1358 "int k;\n"
1359 "}",
1360 Style));
1362 // The namespace body has 5 unwrapped/annotated lines.
1363 const std::string NestedLambdas{"namespace foo {\n"
1364 "auto bar = [] {\n" // line 1
1365 " int i;\n" // line 2
1366 " return [] {\n" // line 3
1367 " int j;" // line 4
1368 " return 0;\n" // line 5
1369 " };\n" // part of line 3
1370 "};\n" // part of line 1
1371 "}"};
1372 Style.ShortNamespaceLines = 4;
1373 EXPECT_EQ(NestedLambdas + " // namespace foo",
1374 fixNamespaceEndComments(NestedLambdas, Style));
1375 ++Style.ShortNamespaceLines;
1376 EXPECT_EQ(NestedLambdas, fixNamespaceEndComments(NestedLambdas, Style));
1379 TEST_F(ShortNamespaceLinesTest, NamespaceAlias) {
1380 auto Style = getLLVMStyle();
1382 EXPECT_EQ("namespace n = nn;\n"
1383 "{\n"
1384 " int i;\n"
1385 " int j;\n"
1386 "}",
1387 fixNamespaceEndComments("namespace n = nn;\n"
1388 "{\n"
1389 " int i;\n"
1390 " int j;\n"
1391 "}",
1392 Style));
1394 EXPECT_EQ("namespace n = nn; // comment\n"
1395 "{\n"
1396 " int i;\n"
1397 " int j;\n"
1398 "}",
1399 fixNamespaceEndComments("namespace n = nn; // comment\n"
1400 "{\n"
1401 " int i;\n"
1402 " int j;\n"
1403 "}",
1404 Style));
1406 EXPECT_EQ("namespace n = nn; /* comment */\n"
1407 "{\n"
1408 " int i;\n"
1409 " int j;\n"
1410 "}",
1411 fixNamespaceEndComments("namespace n = nn; /* comment */\n"
1412 "{\n"
1413 " int i;\n"
1414 " int j;\n"
1415 "}",
1416 Style));
1418 EXPECT_EQ(
1419 "namespace n = nn; /* comment */ /* comment2 */\n"
1420 "{\n"
1421 " int i;\n"
1422 " int j;\n"
1423 "}",
1424 fixNamespaceEndComments("namespace n = nn; /* comment */ /* comment2 */\n"
1425 "{\n"
1426 " int i;\n"
1427 " int j;\n"
1428 "}",
1429 Style));
1431 EXPECT_EQ("namespace n = nn; {\n"
1432 " int i;\n"
1433 " int j;\n"
1434 "}",
1435 fixNamespaceEndComments("namespace n = nn; {\n"
1436 " int i;\n"
1437 " int j;\n"
1438 "}",
1439 Style));
1440 EXPECT_EQ("int foo;\n"
1441 "namespace n\n"
1442 "{\n"
1443 " int i;\n"
1444 " int j;\n"
1445 "} // namespace n",
1446 fixNamespaceEndComments("int foo;\n"
1447 "namespace n\n"
1448 "{\n"
1449 " int i;\n"
1450 " int j;\n"
1451 "}",
1452 Style));
1454 } // end namespace
1455 } // end namespace format
1456 } // end namespace clang