Lines Matching full:n

28   verifyFormat("// line 1\n"
29 "// line 2\n"
35 EXPECT_EQ("// comment\n"
37 format("//comment\n"
40 verifyFormat("void f() {\n"
41 " // Doesn't do anything\n"
43 verifyFormat("SomeObject\n"
44 " // Calling someFunction on SomeObject\n"
46 verifyFormat("auto result = SomeObject\n"
47 " // Calling someFunction on SomeObject\n"
49 verifyFormat("void f(int i, // some comment (probably for i)\n"
50 " int j, // some comment (probably for j)\n"
52 verifyFormat("void f(int i,\n"
53 " // some comment (probably for j)\n"
54 " int j,\n"
55 " // some comment (probably for k)\n"
58 verifyFormat("int i // This is a fancy variable\n"
61 verifyFormat("// Leading comment.\n"
63 verifyFormat("int a; // Trailing comment\n"
64 " // on 2\n"
65 " // or 3 lines.\n"
67 verifyFormat("int a; // Trailing comment\n"
68 "\n"
69 "// Leading comment.\n"
71 verifyFormat("int a; // Comment.\n"
72 " // More details.\n"
75 "int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa; // comment\n"
76 "int bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb; // comment\n"
77 "int cccccccccccccccccccccccccccccc; // comment\n"
78 "int ddd; // looooooooooooooooooooooooong comment\n"
79 "int aaaaaaaaaaaaaaaaaaaaaaa; // comment\n"
80 "int bbbbbbbbbbbbbbbbbbbbb; // comment\n"
83 verifyFormat("#include \"a\" // comment\n"
85 verifyFormat("#include <a> // comment\n"
87 EXPECT_EQ("#include \"a\" // comment\n"
89 format("#include \\\n"
90 " \"a\" // comment\n"
93 verifyFormat("enum E {\n"
94 " // comment\n"
95 " VAL_A, // comment\n"
96 " VAL_B\n"
99 EXPECT_EQ("enum A {\n"
100 " // line a\n"
101 " a,\n"
102 " b, // line b\n"
103 "\n"
104 " // line c\n"
105 " c\n"
107 format("enum A {\n"
108 " // line a\n"
109 " a,\n"
110 " b, // line b\n"
111 "\n"
112 " // line c\n"
113 " c\n"
116 EXPECT_EQ("enum A {\n"
117 " a, // line 1\n"
118 " // line 2\n"
120 format("enum A {\n"
121 " a, // line 1\n"
122 " // line 2\n"
125 EXPECT_EQ("enum A {\n"
126 " a, // line 1\n"
127 " // line 2\n"
129 format("enum A {\n"
130 " a, // line 1\n"
131 " // line 2\n"
134 EXPECT_EQ("enum A {\n"
135 " a, // line 1\n"
136 " // line 2\n"
137 " b\n"
139 format("enum A {\n"
140 " a, // line 1\n"
141 " // line 2\n"
142 " b\n"
145 EXPECT_EQ("enum A {\n"
146 " a, // line 1\n"
147 " // line 2\n"
148 " b\n"
150 format("enum A {\n"
151 " a, // line 1\n"
152 " // line 2\n"
153 " b\n"
157 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa =\n"
159 verifyFormat("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa =\n"
160 " // Comment inside a statement.\n"
162 verifyFormat("SomeFunction(a,\n"
163 " // comment\n"
165 verifyFormat("SomeFunction(a, a,\n"
166 " // comment\n"
169 "bool aaaaaaaaaaaaa = // comment\n"
170 " aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa || aaaaaaaaaaaaaaaaaaaaaaaaaaaa ||\n"
173 verifyFormat("int aaaa; // aaaaa\n"
177 EXPECT_EQ("void f() { // This does something ..\n"
178 "}\n"
180 format("void f() { // This does something ..\n"
181 " }\n"
183 EXPECT_EQ("class C {\n"
184 " void f() { // This does something ..\n"
185 " } // awesome..\n"
186 "\n"
187 " int a; // This is unrelated\n"
189 format("class C{void f() { // This does something ..\n"
190 " } // awesome..\n"
191 " \n"
192 "int a; // This is unrelated\n"
196 format("int i;\\\n// single line trailing comment"));
200 verifyFormat("someFunction(anotherFunction( // Force break.\n"
205 verifyFormat("const char *test[] = {\n"
206 " // A\n"
207 " \"aaaa\",\n"
208 " // B\n"
211 "aaaaaaaaaaaaaaaaaaaaaaaaaa(\n"
213 EXPECT_EQ("D(a, {\n"
214 " // test\n"
215 " int a;\n"
217 format("D(a, {\n"
218 "// test\n"
219 "int a;\n"
222 EXPECT_EQ("lineWith(); // comment\n"
223 "// at start\n"
225 format("lineWith(); // comment\n"
226 "// at start\n"
228 EXPECT_EQ("lineWith(); // comment\n"
229 "/*\n"
230 " * at start */\n"
232 format("lineWith(); // comment\n"
233 "/*\n"
234 " * at start */\n"
236 EXPECT_EQ("lineWith(); // comment\n"
237 " // at start\n"
239 format("lineWith(); // comment\n"
240 " // at start\n"
243 EXPECT_EQ("lineWith(); // comment\n"
244 "// at start\n"
246 format("lineWith(); // comment\n"
247 "// at start\n"
249 EXPECT_EQ("lineWith();\n"
250 "// at start\n"
252 format("lineWith();\n"
253 " // at start\n"
255 EXPECT_EQ("// first\n"
256 "// at start\n"
258 format("// first\n"
259 " // at start\n"
261 EXPECT_EQ("f();\n"
262 "// first\n"
263 "// at start\n"
265 format("f();\n"
266 "// first\n"
267 " // at start\n"
269 verifyFormat("f(); // comment\n"
270 "// first\n"
271 "// at start\n"
273 EXPECT_EQ("f(); // comment\n"
274 "// first\n"
275 "// at start\n"
277 format("f(); // comment\n"
278 "// first\n"
279 " // at start\n"
281 EXPECT_EQ("f(); // comment\n"
282 " // first\n"
283 "// at start\n"
285 format("f(); // comment\n"
286 " // first\n"
287 "// at start\n"
289 EXPECT_EQ("void f() {\n"
290 " lineWith(); // comment\n"
291 " // at start\n"
293 format("void f() {\n"
294 " lineWith(); // comment\n"
295 " // at start\n"
297 EXPECT_EQ("int xy; // a\n"
299 format("int xy; // a\n"
301 EXPECT_EQ("int xy; // a\n"
303 format("int xy; // a\n"
307 verifyFormat("#define A \\\n"
308 " int i; /* iiiiiiiiiiiiiiiiiiiii */ \\\n"
312 "#define A \\\n"
313 " int i; /* iiiiiiiiiiiiiiiiiiiii */ \\\n"
317 verifyFormat("if ( // This is some comment\n"
318 " x + 3) {\n"
320 EXPECT_EQ("if ( // This is some comment\n"
321 " // spanning two lines\n"
322 " x + 3) {\n"
324 format("if( // This is some comment\n"
325 " // spanning two lines\n"
326 " x + 3) {\n"
329 verifyNoCrash("/\\\n/");
330 verifyNoCrash("/\\\n* */");
332 verifyNoCrash(StringRef("/*\\\0\n/", 6));
336 EXPECT_EQ("SomeFunction(a,\n"
337 " b, // comment\n"
339 format("SomeFunction(a,\n"
340 " b, // comment\n"
342 EXPECT_EQ("SomeFunction(a, b,\n"
343 " // comment\n"
345 format("SomeFunction(a,\n"
346 " b,\n"
347 " // comment\n"
349 EXPECT_EQ("SomeFunction(a, b, // comment (unclear relation)\n"
351 format("SomeFunction(a, b, // comment (unclear relation)\n"
353 EXPECT_EQ("SomeFunction(a, // comment\n"
354 " b,\n"
356 format("SomeFunction(a, // comment\n"
357 " b,\n"
359 EXPECT_EQ("aaaaaaaaaa(aaaa(aaaa,\n"
360 " aaaa), //\n"
362 format("aaaaaaaaaa(aaaa(aaaa,\n"
363 "aaaa), //\n"
368 verifyFormat("int SomeFunction(a,\n"
369 " b, // comment\n"
370 " c,\n"
373 verifyFormat("int SomeFunction(a,\n"
374 " b,\n"
375 " // comment\n"
385 EXPECT_EQ("// comment\\\n", format("// comment\\\n \t \v \f "));
386 EXPECT_EQ("// comment \\\n", format("// comment \\\n \t \v \f "));
392 verifyFormat("fooooooooooooooooooooooooooooo(\n"
393 " /*qq_=*/move(q), [this, b](bar<void(uint32_t)> b) {},\n"
396 EXPECT_EQ("f(aaaaaaaaaaaaaaaaaaaaaaaaa, /* Trailing comment for aa... */\n"
398 format("f(aaaaaaaaaaaaaaaaaaaaaaaaa , \\\n"
399 "/* Trailing comment for aa... */\n"
402 "f(aaaaaaaaaaaaaaaaaaaaaaaaa,\n"
404 format("f(aaaaaaaaaaaaaaaaaaaaaaaaa , \n"
408 "void aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(\n"
409 " aaaaaaaaaaaaaaaaaa,\n"
411 "void aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(\n"
412 " aaaaaaaaaaaaaaaaaa ,\n"
413 " aaaaaaaaaaaaaaaaaa) { /*aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa*/\n"
416 verifyFormat("f(/* aaaaaaaaaaaaaaaaaa = */\n"
420 "int aaaaaaaaaaaaa(/* 1st */ int bbbbbbbbbb, /* 2nd */ int ccccccccccc,\n"
425 verifyFormat("aaaaaaaa(/* parameter 1 */ aaaaaa,\n"
426 " /* parameter 2 */ aaaaaa,\n"
427 " /* parameter 3 */ aaaaaa,\n"
431 verifyFormat("int aaaaaaaaaaaaa(/* 1st */ int bbbbbbbbbb,\n"
432 " /* 2nd */ int ccccccccccc,\n"
437 verifyFormat("int a(/* 1st */ int b,\n"
442 verifyGoogleFormat("#define A \\\n"
443 " int i; /*a*/ \\\n"
448 EXPECT_EQ("/*\n"
449 " * Really multi-line\n"
450 " * comment.\n"
451 " */\n"
453 format(" /*\n"
454 " * Really multi-line\n"
455 " * comment.\n"
456 " */\n"
458 EXPECT_EQ("class C {\n"
459 " /*\n"
460 " * Another multi-line\n"
461 " * comment.\n"
462 " */\n"
463 " void f() {}\n"
465 format("class C {\n"
466 "/*\n"
467 " * Another multi-line\n"
468 " * comment.\n"
469 " */\n"
470 "void f() {}\n"
472 EXPECT_EQ("/*\n"
473 " 1. This is a comment with non-trivial formatting.\n"
474 " 1.1. We have to indent/outdent all lines equally\n"
475 " 1.1.1. to keep the formatting.\n"
477 format(" /*\n"
478 " 1. This is a comment with non-trivial formatting.\n"
479 " 1.1. We have to indent/outdent all lines equally\n"
480 " 1.1.1. to keep the formatting.\n"
482 EXPECT_EQ("/*\n"
483 "Don't try to outdent if there's not enough indentation.\n"
485 format(" /*\n"
486 " Don't try to outdent if there's not enough indentation.\n"
489 EXPECT_EQ("int i; /* Comment with empty...\n"
490 " *\n"
492 format("int i; /* Comment with empty...\n"
493 " *\n"
495 EXPECT_EQ("int foobar = 0; /* comment */\n"
496 "int bar = 0; /* multiline\n"
497 " comment 1 */\n"
498 "int baz = 0; /* multiline\n"
499 " comment 2 */\n"
500 "int bzz = 0; /* multiline\n"
502 format("int foobar = 0; /* comment */\n"
503 "int bar = 0; /* multiline\n"
504 " comment 1 */\n"
505 "int baz = 0; /* multiline\n"
506 " comment 2 */\n"
507 "int bzz = 0; /* multiline\n"
509 EXPECT_EQ("int foobar = 0; /* comment */\n"
510 "int bar = 0; /* multiline\n"
511 " comment */\n"
512 "int baz = 0; /* multiline\n"
514 format("int foobar = 0; /* comment */\n"
515 "int bar = 0; /* multiline\n"
516 "comment */\n"
517 "int baz = 0; /* multiline\n"
526 verifyNoChange("/* aaaaaaaaa aaaaaaaaaa aaaaaaaaaa\n"
529 verifyNoChange("/* aaaaaaaaa aaaaaaaaaa aaaaaaaaaa\n"
532 verifyNoChange("/* aaaaaaaaa aaaaaaaaaa aaaaaaaaaa\n"
542 verifyNoChange("/* aaaaaaaaa aaaaaaaaaa aaaaaaaaaa\n"
545 verifyNoChange("/* aaaaaaaaa aaaaaaaaaa aaaaaaaaaa\n"
548 verifyFormat("/* aaaaaaaaa aaaaaaaaaa aaaaaaaaaa\n"
550 "/* aaaaaaaaa aaaaaaaaaa aaaaaaaaaa\n"
556 EXPECT_EQ("double *x; /* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n"
558 format("double *x; /* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n"
561 "void ffffffffffff(\n"
562 " int aaaaaaaa, int bbbbbbbb,\n"
563 " int cccccccccccc) { /*\n"
564 " aaaaaaaaaa\n"
565 " aaaaaaaaaaaaa\n"
566 " bbbbbbbbbbbbbb\n"
567 " bbbbbbbbbb\n"
568 " */\n"
570 format("void ffffffffffff(int aaaaaaaa, int bbbbbbbb, int cccccccccccc)\n"
571 "{ /*\n"
572 " aaaaaaaaaa aaaaaaaaaaaaa\n"
573 " bbbbbbbbbbbbbb bbbbbbbbbb\n"
574 " */\n"
580 EXPECT_EQ("void ffffffffff(\n"
587 EXPECT_EQ("// A comment that\n"
588 "// doesn't fit on\n"
592 EXPECT_EQ("/// A comment that\n"
593 "/// doesn't fit on\n"
597 EXPECT_EQ("//! A comment that\n"
598 "//! doesn't fit on\n"
602 EXPECT_EQ("// a b c d\n"
603 "// e f g\n"
607 "// a b c d\n"
608 "// e f g\n"
610 format("\\\n// a b c d e f g h i j k", getLLVMStyleWithColumns(10)));
611 EXPECT_EQ("if (true) // A comment that\n"
612 " // doesn't fit on\n"
618 EXPECT_EQ("// Add leading\n"
621 EXPECT_EQ("/// Add leading\n"
624 EXPECT_EQ("//! Add leading\n"
628 EXPECT_EQ("// Even if it makes the line exceed the column\n"
633 EXPECT_EQ("/// line 1\n"
635 format("/// line 1\n"
638 EXPECT_EQ("/// line 1\n"
639 "/// line 2\n"
640 "//! line 3\n"
641 "//! line 4\n"
642 "//! line 5\n"
643 "// line 6\n"
645 format("///line 1\n"
646 "///line 2\n"
647 "//! line 3\n"
648 "//!line 4\n"
649 "//!line 5\n"
650 "// line 6\n"
658 EXPECT_EQ("// A comment before\n"
659 "// a macro\n"
660 "// definition\n"
662 format("// A comment before a macro definition\n"
665 EXPECT_EQ("void ffffff(\n"
666 " int aaaaaaaaa, // wwww\n"
667 " int bbbbbbbbbb, // xxxxxxx\n"
668 " // yyyyyyyyyy\n"
670 format("void ffffff(\n"
671 " int aaaaaaaaa, // wwww\n"
672 " int bbbbbbbbbb, // xxxxxxx yyyyyyyyyy\n"
678 "#define XXX // a b c d\n"
682 "#define XXX // q w e r\n"
685 EXPECT_EQ("{\n"
686 " //\n"
687 " //\\\n"
688 " // long 1 2 3 4 5\n"
690 format("{\n"
691 " //\n"
692 " //\\\n"
693 " // long 1 2 3 4 5\n"
696 EXPECT_EQ("{\n"
697 " //\n"
698 " //\\\n"
699 " // long 1 2 3 4 5\n"
700 " // 6\n"
702 format("{\n"
703 " //\n"
704 " //\\\n"
705 " // long 1 2 3 4 5 6\n"
709 EXPECT_EQ("//: A comment that\n"
710 "//: doesn't fit on\n"
716 "//\t\t\t\tofMap(message.velocity, 0, 127, 0, ofGetWidth()\n"
722 EXPECT_EQ("// A comment\n"
723 "// that doesn't\n"
724 "// fit on one\n"
728 EXPECT_EQ("/// A comment\n"
729 "/// that doesn't\n"
730 "/// fit on one\n"
737 EXPECT_EQ("// aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\\\n"
738 "// aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\\\n"
740 format("// aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\\\n"
741 "// aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\\\n"
743 EXPECT_EQ("int a; // AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\\\n"
744 " // AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\\\n"
746 format("int a; // AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\\\n"
747 " // AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\\\n"
752 EXPECT_EQ("double\n"
753 " a; // AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\\\n"
754 " // AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\\\n"
756 format("double a; // AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\\\n"
757 " // AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\\\n"
766 "// aaaaaaaaaa\n"
770 "// aaaaaaaaa\n"
774 "// aaaaaaaaa\n"
792 EXPECT_EQ("if (xxx ==\n"
793 " yyy && // aaaaaaaaaaaa bbbbbbbbb\n"
794 " zzz)\n"
796 format("if (xxx == yyy && // aaaaaaaaaaaa bbbbbbbbb\n"
799 EXPECT_EQ("if (xxxxxxxxxx ==\n"
800 " yyy && // aaaaaa bbbbbbbb cccc\n"
801 " zzz)\n"
803 format("if (xxxxxxxxxx == yyy && // aaaaaa bbbbbbbb cccc\n"
806 EXPECT_EQ("if (xxxxxxxxxx &&\n"
807 " yyy || // aaaaaa bbbbbbbb cccc\n"
808 " zzz)\n"
810 format("if (xxxxxxxxxx && yyy || // aaaaaa bbbbbbbb cccc\n"
813 EXPECT_EQ("fffffffff(\n"
814 " &xxx, // aaaaaaaaaaaa bbbbbbbbbbb\n"
816 format("fffffffff(&xxx, // aaaaaaaaaaaa bbbbbbbbbbb\n"
822 EXPECT_EQ("#define A(x) /* \\\n"
823 " a comment \\\n"
824 " inside */ \\\n"
826 format("#define A(x) /* \\\n"
827 " a comment \\\n"
828 " inside */ \\\n"
831 EXPECT_EQ("#define A( \\\n"
832 " x) /* \\\n"
833 " a comment \\\n"
834 " inside */ \\\n"
836 format("#define A( \\\n"
837 " x) /* \\\n"
838 " a comment \\\n"
839 " inside */ \\\n"
845 EXPECT_EQ("namespace {}\n// Test\n#define A",
846 format("namespace {}\n // Test\n#define A"));
847 EXPECT_EQ("namespace {}\n/* Test */\n#define A",
848 format("namespace {}\n /* Test */\n#define A"));
849 EXPECT_EQ("namespace {}\n/* Test */ #define A",
850 format("namespace {}\n /* Test */ #define A"));
856 EXPECT_EQ("void f() {\n"
857 " int i;\n"
858 " /* comment */\n"
859 "#ifdef A\n"
860 " int j;\n"
862 format("void f() {\n"
863 " int i;\n"
864 " /* comment */\n"
865 "#ifdef A\n"
866 " int j;\n"
869 EXPECT_EQ("void f() {\n"
870 " int i;\n"
871 " /* comment */\n"
872 "\n"
873 "#ifdef A\n"
874 " int j;\n"
876 format("void f() {\n"
877 " int i;\n"
878 " /* comment */\n"
879 "\n"
880 "#ifdef A\n"
881 " int j;\n"
884 EXPECT_EQ("int f(int i) {\n"
885 " if (true) {\n"
886 " ++i;\n"
887 " }\n"
888 " // comment\n"
889 "#ifdef A\n"
890 " int j;\n"
891 "#endif\n"
893 format("int f(int i) {\n"
894 " if (true) {\n"
895 " ++i;\n"
896 " }\n"
897 " // comment\n"
898 "#ifdef A\n"
899 "int j;\n"
900 "#endif\n"
903 EXPECT_EQ("int f(int i) {\n"
904 " if (true) {\n"
905 " i++;\n"
906 " } else {\n"
907 " // comment in else\n"
908 "#ifdef A\n"
909 " j++;\n"
910 "#endif\n"
911 " }\n"
913 format("int f(int i) {\n"
914 " if (true) {\n"
915 " i++;\n"
916 " } else {\n"
917 " // comment in else\n"
918 "#ifdef A\n"
919 " j++;\n"
920 "#endif\n"
921 " }\n"
924 EXPECT_EQ("int f(int i) {\n"
925 " if (true) {\n"
926 " i++;\n"
927 " } else {\n"
928 " /* comment in else */\n"
929 "#ifdef A\n"
930 " j++;\n"
931 "#endif\n"
932 " }\n"
934 format("int f(int i) {\n"
935 " if (true) {\n"
936 " i++;\n"
937 " } else {\n"
938 " /* comment in else */\n"
939 "#ifdef A\n"
940 " j++;\n"
941 "#endif\n"
942 " }\n"
947 EXPECT_EQ("void f() {\n"
948 " int i;\n"
949 " /* comment */\n"
950 "\n"
951 "#ifdef A\n"
952 " int j;\n"
954 format("void f() {\n"
955 " int i;\n"
956 "/* comment */\n"
957 "\n"
958 "#ifdef A\n"
959 " int j;\n"
962 EXPECT_EQ("void f() {\n"
963 " int i;\n"
964 " return i;\n"
965 "}\n"
966 "// comment\n"
967 "\n"
968 "#ifdef A\n"
969 "int i;\n"
971 format("void f() {\n"
972 " int i;\n"
973 " return i;\n"
974 "}\n"
975 "// comment\n"
976 "\n"
977 "#ifdef A\n"
978 "int i;\n"
981 EXPECT_EQ("int f(int i) {\n"
982 " if (true) {\n"
983 " ++i;\n"
984 " }\n"
985 " // comment\n"
986 "\n"
987 "#ifdef A\n"
988 " int j;\n"
989 "#endif\n"
991 format("int f(int i) {\n"
992 " if (true) {\n"
993 " ++i;\n"
994 " }\n"
995 " // comment\n"
996 "\n"
997 "#ifdef A\n"
998 " int j;\n"
999 "#endif\n"
1002 EXPECT_EQ("int f(int i) {\n"
1003 " if (true) {\n"
1004 " i++;\n"
1005 " } else {\n"
1006 " // comment in else\n"
1007 "\n"
1008 "#ifdef A\n"
1009 " j++;\n"
1010 "#endif\n"
1011 " }\n"
1013 format("int f(int i) {\n"
1014 " if (true) {\n"
1015 " i++;\n"
1016 " } else {\n"
1017 "// comment in else\n"
1018 "\n"
1019 "#ifdef A\n"
1020 " j++;\n"
1021 "#endif\n"
1022 " }\n"
1025 EXPECT_EQ("int f(int i) {\n"
1026 " if (true) {\n"
1027 " i++;\n"
1028 " } else {\n"
1029 " /* comment in else */\n"
1030 "\n"
1031 "#ifdef A\n"
1032 " j++;\n"
1033 "#endif\n"
1034 " }\n"
1036 format("int f(int i) {\n"
1037 " if (true) {\n"
1038 " i++;\n"
1039 " } else {\n"
1040 "/* comment in else */\n"
1041 "\n"
1042 "#ifdef A\n"
1043 " j++;\n"
1044 "#endif\n"
1045 " }\n"
1051 EXPECT_EQ("void f() {\n"
1052 " int i;\n"
1053 "/* comment */\n"
1054 "#ifdef A\n"
1055 " int j;\n"
1057 format("void f() {\n"
1058 " int i;\n"
1059 "/* comment */\n"
1060 "#ifdef A\n"
1061 " int j;\n"
1064 EXPECT_EQ("int f(int i) {\n"
1065 " if (true) {\n"
1066 " ++i;\n"
1067 " }\n"
1068 "// comment\n"
1069 "#ifdef A\n"
1070 " int j;\n"
1071 "#endif\n"
1073 format("int f(int i) {\n"
1074 " if (true) {\n"
1075 " ++i;\n"
1076 " }\n"
1077 "// comment\n"
1078 "#ifdef A\n"
1079 " int j;\n"
1080 "#endif\n"
1083 EXPECT_EQ("int f(int i) {\n"
1084 " if (true) {\n"
1085 " i++;\n"
1086 " } else {\n"
1087 "// comment in else\n"
1088 "#ifdef A\n"
1089 " j++;\n"
1090 "#endif\n"
1091 " }\n"
1093 format("int f(int i) {\n"
1094 " if (true) {\n"
1095 " i++;\n"
1096 " } else {\n"
1097 " // comment in else\n"
1098 " #ifdef A\n"
1099 " j++;\n"
1100 "#endif\n"
1101 " }\n"
1104 EXPECT_EQ("int f(int i) {\n"
1105 " if (true) {\n"
1106 " i++;\n"
1107 " } else {\n"
1108 "/* comment in else */\n"
1109 "#ifdef A\n"
1110 " j++;\n"
1111 "#endif\n"
1112 " }\n"
1114 format("int f(int i) {\n"
1115 " if (true) {\n"
1116 " i++;\n"
1117 " } else {\n"
1118 " /* comment in else */\n"
1119 " #ifdef A\n"
1120 " j++;\n"
1121 "#endif\n"
1122 " }\n"
1125 const StringRef Code("void func() {\n"
1126 " // clang-format off\n"
1127 " #define KV(value) #value, value\n"
1128 " // clang-format on\n"
1134 verifyFormat("#ifdef FOO\n"
1135 " // Foo\n"
1136 " #define Foo foo\n"
1137 "#else\n"
1138 " // Bar\n"
1139 " #define Bar bar\n"
1145 verifyFormat("{\n"
1146 " if (a)\n"
1147 " f(); // comment\n"
1148 "#define A\n"
1151 verifyFormat("{\n"
1152 " while (a)\n"
1153 " f();\n"
1154 "// comment\n"
1155 "#define A\n"
1158 verifyNoChange("{\n"
1159 " if (a)\n"
1160 " f();\n"
1161 " // comment\n"
1162 "#define A\n"
1165 verifyNoChange("{\n"
1166 " while (a)\n"
1167 " if (b)\n"
1168 " f();\n"
1169 " // comment\n"
1170 "#define A\n"
1177 EXPECT_EQ("/* This is a long\n"
1178 " * comment that\n"
1179 " * doesn't fit on\n"
1188 "/* a b c d\n"
1189 " * e f g\n"
1190 " * h i j k\n"
1194 "/* a b c d\n"
1195 " * e f g\n"
1196 " * h i j k\n"
1198 format("\\\n/* a b c d e f g h i j k */", getLLVMStyleWithColumns(10)));
1199 EXPECT_EQ("/*\n"
1200 "This is a long\n"
1201 "comment that doesn't\n"
1202 "fit on one line.\n"
1204 format("/*\n"
1207 "fit on one line. \n"
1210 EXPECT_EQ("/*\n"
1211 " * This is a long\n"
1212 " * comment that\n"
1213 " * doesn't fit on\n"
1214 " * one line.\n"
1216 format("/* \n"
1220 " one line. \n"
1223 EXPECT_EQ("/*\n"
1224 " * This_is_a_comment_with_words_that_dont_fit_on_one_line\n"
1225 " * so_it_should_be_broken\n"
1226 " * wherever_a_space_occurs\n"
1228 format("/*\n"
1231 " wherever_a_space_occurs \n"
1234 EXPECT_EQ("/*\n"
1235 " * This_comment_can_not_be_broken_into_lines\n"
1237 format("/*\n"
1238 " * This_comment_can_not_be_broken_into_lines\n"
1241 EXPECT_EQ("{\n"
1242 " /*\n"
1243 " This is another\n"
1244 " long comment that\n"
1245 " doesn't fit on one\n"
1246 " line 1234567890\n"
1247 " */\n"
1249 format("{\n"
1250 "/*\n"
1254 " line 1234567890\n"
1255 "*/\n"
1258 EXPECT_EQ("{\n"
1259 " /*\n"
1260 " * This i s\n"
1261 " * another comment\n"
1262 " * t hat doesn' t\n"
1263 " * fit on one l i\n"
1264 " * n e\n"
1265 " */\n"
1267 format("{\n"
1268 "/*\n"
1273 " n e\n"
1274 " */\n"
1277 EXPECT_EQ("/*\n"
1278 " * This is a long\n"
1279 " * comment that\n"
1280 " * doesn't fit on\n"
1281 " * one line\n"
1283 format(" /*\n"
1284 " * This is a long comment that doesn't fit on one line\n"
1287 EXPECT_EQ("{\n"
1288 " if (something) /* This is a\n"
1289 " long\n"
1290 " comment */\n"
1291 " ;\n"
1293 format("{\n"
1294 " if (something) /* This is a long comment */\n"
1295 " ;\n"
1299 EXPECT_EQ("/* A comment before\n"
1300 " * a macro\n"
1301 " * definition */\n"
1303 format("/* A comment before a macro definition */\n"
1307 EXPECT_EQ("/* some comment\n"
1308 " * a comment that\n"
1309 " * we break another\n"
1310 " * comment we have\n"
1311 " * to break a left\n"
1312 " * comment\n"
1314 format(" /* some comment\n"
1315 " * a comment that we break\n"
1316 " * another comment we have to break\n"
1317 "* a left comment\n"
1321 EXPECT_EQ("/**\n"
1322 " * multiline block\n"
1323 " * comment\n"
1324 " *\n"
1326 format("/**\n"
1327 " * multiline block comment\n"
1328 " *\n"
1337 EXPECT_EQ("/*\n"
1338 "\n"
1339 "\n"
1341 format(" /* \n"
1342 " \n"
1343 " \n"
1350 EXPECT_EQ("/* aaa aaa\n"
1353 EXPECT_EQ("/* aaa aaa\n"
1359 EXPECT_EQ("#define X \\\n"
1360 " /* \\\n"
1361 " Test \\\n"
1362 " Macro comment \\\n"
1363 " with a long \\\n"
1364 " line \\\n"
1365 " */ \\\n"
1367 format("#define X \\\n"
1368 " /*\n"
1369 " Test\n"
1370 " Macro comment with a long line\n"
1371 " */ \\\n"
1374 EXPECT_EQ("#define X \\\n"
1375 " /* Macro comment \\\n"
1376 " with a long \\\n"
1377 " line */ \\\n"
1379 format("#define X \\\n"
1380 " /* Macro comment with a long\n"
1381 " line */ \\\n"
1384 EXPECT_EQ("#define X \\\n"
1385 " /* Macro comment \\\n"
1386 " * with a long \\\n"
1387 " * line */ \\\n"
1389 format("#define X \\\n"
1390 " /* Macro comment with a long line */ \\\n"
1396 verifyFormat("#ifdef A // line about A\n"
1397 "// section comment\n"
1400 verifyFormat("#ifdef A // line 1 about A\n"
1401 " // line 2 about A\n"
1402 "// section comment\n"
1405 EXPECT_EQ("#ifdef A // line 1 about A\n"
1406 " // line 2 about A\n"
1407 "// section comment\n"
1409 format("#ifdef A // line 1 about A\n"
1410 " // line 2 about A\n"
1411 "// section comment\n"
1414 verifyFormat("int f() {\n"
1415 " int i;\n"
1416 "#ifdef A // comment about A\n"
1417 " // section comment 1\n"
1418 " // section comment 2\n"
1419 " i = 2;\n"
1420 "#else // comment about #else\n"
1421 " // section comment 3\n"
1422 " i = 4;\n"
1423 "#endif\n"
1429 verifyFormat("#if A\n"
1430 "#else // A\n"
1431 "int iiii;\n"
1434 verifyFormat("#if A\n"
1435 "#else // A\n"
1436 "int iiii; // CC\n"
1439 EXPECT_EQ("#if A\n"
1440 "#else // A1\n"
1441 " // A2\n"
1442 "int ii;\n"
1444 format("#if A\n"
1445 "#else // A1\n"
1446 " // A2\n"
1447 "int ii;\n"
1454 "static SomeType type = {aaaaaaaaaaaaaaaaaaaa, /* comment */\n"
1455 " aaaaaaaaaaaaaaaaaaaa /* comment */,\n"
1456 " /* comment */ aaaaaaaaaaaaaaaaaaaa,\n"
1457 " aaaaaaaaaaaaaaaaaaaa, // comment\n"
1459 format("static SomeType type = { aaaaaaaaaaaaaaaaaaaa , /* comment */\n"
1460 " aaaaaaaaaaaaaaaaaaaa /* comment */ ,\n"
1461 " /* comment */ aaaaaaaaaaaaaaaaaaaa ,\n"
1462 " aaaaaaaaaaaaaaaaaaaa , // comment\n"
1464 verifyFormat("static SomeType type = {aaaaaaaaaaa, // comment for aa...\n"
1466 verifyFormat("static SomeType type = {aaaaaaaaaaa,\n"
1467 " // comment for bb....\n"
1470 "static SomeType type = {aaaaaaaaaaa, // comment for aa...\n"
1472 verifyGoogleFormat("static SomeType type = {aaaaaaaaaaa,\n"
1473 " // comment for bb....\n"
1476 verifyFormat("S s = {{a, b, c}, // Group #1\n"
1477 " {d, e, f}, // Group #2\n"
1479 verifyFormat("S s = {{// Group #1\n"
1480 " a, b, c},\n"
1481 " {// Group #2\n"
1482 " d, e, f},\n"
1483 " {// Group #3\n"
1486 EXPECT_EQ("S s = {\n"
1487 " // Some comment\n"
1488 " a,\n"
1489 "\n"
1490 " // Comment after empty line\n"
1492 format("S s = {\n"
1493 " // Some comment\n"
1494 " a,\n"
1495 " \n"
1496 " // Comment after empty line\n"
1497 " b\n"
1499 EXPECT_EQ("S s = {\n"
1500 " /* Some comment */\n"
1501 " a,\n"
1502 "\n"
1503 " /* Comment after empty line */\n"
1505 format("S s = {\n"
1506 " /* Some comment */\n"
1507 " a,\n"
1508 " \n"
1509 " /* Comment after empty line */\n"
1510 " b\n"
1512 verifyFormat("const uint8_t aaaaaaaaaaaaaaaaaaaaaa[0] = {\n"
1513 " 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // comment\n"
1514 " 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // comment\n"
1519 EXPECT_EQ("if (true) { // comment about branch\n"
1520 " // comment about f\n"
1521 " f();\n"
1523 format("if (true) { // comment about branch\n"
1524 " // comment about f\n"
1525 " f();\n"
1528 EXPECT_EQ("if (1) { // if line 1\n"
1529 " // if line 2\n"
1530 " // if line 3\n"
1531 " // f line 1\n"
1532 " // f line 2\n"
1533 " f();\n"
1534 "} else { // else line 1\n"
1535 " // else line 2\n"
1536 " // else line 3\n"
1537 " // g line 1\n"
1538 " g();\n"
1540 format("if (1) { // if line 1\n"
1541 " // if line 2\n"
1542 " // if line 3\n"
1543 " // f line 1\n"
1544 " // f line 2\n"
1545 " f();\n"
1546 "} else { // else line 1\n"
1547 " // else line 2\n"
1548 " // else line 3\n"
1549 " // g line 1\n"
1550 " g();\n"
1552 EXPECT_EQ("do { // line 1\n"
1553 " // line 2\n"
1554 " // line 3\n"
1555 " f();\n"
1557 format("do { // line 1\n"
1558 " // line 2\n"
1559 " // line 3\n"
1560 " f();\n"
1563 EXPECT_EQ("while (a < b) { // line 1\n"
1564 " // line 2\n"
1565 " // line 3\n"
1566 " f();\n"
1568 format("while (a < b) {// line 1\n"
1569 " // line 2\n"
1570 " // line 3\n"
1571 " f();\n"
1578 EXPECT_EQ("// long long long\n"
1580 format("// long long long long\n"
1585 EXPECT_EQ("// long long long\n"
1587 format("// long long long long\n"
1592 EXPECT_EQ("// long long long\n"
1593 "// long long\n"
1595 format("// long long long long\n"
1600 EXPECT_EQ("// long long long\n"
1601 "// long\n"
1603 format("// long long long long\n"
1608 verifyFormat("// long\n"
1609 "// long long long lo\n"
1610 "// long long long lo\n"
1615 EXPECT_EQ("/// long long long\n"
1617 format("/// long long long long\n"
1620 EXPECT_EQ("//! long long long\n"
1622 format("//! long long long long\n"
1625 EXPECT_EQ("/* long long long\n"
1627 format("/* long long long long\n"
1630 EXPECT_EQ("///< long long long\n"
1632 format("///< long long long long\n"
1635 EXPECT_EQ("//!< long long long\n"
1637 format("//!< long long long long\n"
1642 EXPECT_EQ("/* long long long\n"
1643 " * long long long\n"
1645 format("/* long long long long\n"
1646 " * long long\n"
1651 EXPECT_EQ("/* long long long\n"
1653 format("/* long long long long\n"
1658 EXPECT_EQ("/* long long long\n"
1660 format("/* long long long long\n"
1661 " * long\n"
1667 EXPECT_EQ("/* long long long\n"
1668 " * long long longg\n"
1670 format("/* long long long long\n"
1671 " * long\n"
1676 EXPECT_EQ("{\n"
1677 " /*\n"
1678 " * long long long\n"
1679 " * long long long\n"
1680 " * long long long\n"
1681 " */\n"
1683 format("{\n"
1684 "/*\n"
1685 " * long long long long\n"
1686 " * long\n"
1687 " * long long long long\n"
1688 " */\n"
1694 EXPECT_EQ("/* long long long\n"
1700 EXPECT_EQ("int i; /* long long\n"
1705 EXPECT_EQ("// long long long\n"
1707 format("// long long long lon\n"
1713 EXPECT_EQ("// long long long\n"
1714 "// long\n"
1715 "// long long\n"
1717 format("// long long long long\n"
1718 "// long long\n"
1724 EXPECT_EQ("// long long long\n"
1725 "// long long long\n"
1727 format("// long long long long long long long long\n"
1733 EXPECT_EQ("// long long long\n"
1734 "// lon1 lon2 lon2\n"
1736 format("// long long long lon1\n"
1737 "// lon2 lon2 lon2\n"
1742 EXPECT_EQ("// long long long\n"
1743 "// lon1 lon2 lon2\n"
1744 "// lon2 lon2 lon2\n"
1746 format("// long long long lon1\n"
1751 EXPECT_EQ("// long long long", format("// long long\n"
1759 EXPECT_EQ("// long long long\n"
1761 format("// long long long long \n"
1770 EXPECT_EQ("/* long\n"
1775 EXPECT_EQ("{\n"
1776 " // long long long\n"
1777 " // long long\n"
1778 " int i; /* long lon\n"
1779 " g long\n"
1780 " */\n"
1782 format("{\n"
1783 " // long long long long\n"
1784 " // long\n"
1785 " int i; /* long lon g\n"
1786 " long */\n"
1791 EXPECT_EQ("// long long long\n"
1792 "// long long\n"
1794 format("// long long long long\n"
1795 "// long\n"
1798 EXPECT_EQ("// long long long\n"
1799 "// longng long long\n"
1801 format("// long long long longng\n"
1802 "// long long long\n"
1807 EXPECT_EQ("int a; // Trailing\n"
1808 " // comment on\n"
1809 " // 2 or 3\n"
1811 format("int a; // Trailing comment\n"
1812 " // on 2\n"
1813 " // or 3\n"
1816 EXPECT_EQ("/// This long line\n"
1818 format("/// This long line gets\n"
1821 EXPECT_EQ("//! This long line\n"
1823 format(" //! This long line gets\n"
1826 EXPECT_EQ("/* This long line\n"
1827 " * gets reflown.\n"
1829 format("/* This long line gets\n"
1830 " * reflown.\n"
1835 EXPECT_EQ("{\n"
1836 " // long long long\n"
1837 " // lo long\n"
1839 format("{\n"
1840 "// long long long lo\n"
1841 "// long\n"
1846 EXPECT_EQ("/*\n"
1847 " * Reflow the end of\n"
1848 " * line by 11 22 33\n"
1849 " * 4.\n"
1851 format("/*\n"
1852 " * Reflow the end of line\n"
1853 " * by\n"
1854 " * 11\n"
1855 " * 22\n"
1856 " * 33\n"
1857 " * 4.\n"
1860 EXPECT_EQ("/// First line gets\n"
1861 "/// broken. Second\n"
1862 "/// line gets\n"
1863 "/// reflown and\n"
1864 "/// broken. Third\n"
1866 format("/// First line gets broken.\n"
1867 "/// Second line gets reflown and broken.\n"
1870 EXPECT_EQ("int i; // first long\n"
1871 " // long snd\n"
1873 format("int i; // first long long\n"
1876 EXPECT_EQ("{\n"
1877 " // first long line\n"
1878 " // line second\n"
1879 " // long line line\n"
1880 " // third long line\n"
1881 " // line\n"
1883 format("{\n"
1884 " // first long line line\n"
1885 " // second long line line\n"
1886 " // third long line line\n"
1889 EXPECT_EQ("int i; /* first line\n"
1890 " * second\n"
1891 " * line third\n"
1892 " * line\n"
1894 format("int i; /* first line\n"
1895 " * second line\n"
1896 " * third line\n"
1902 EXPECT_EQ("// long\n"
1903 "// long long long\n"
1905 format("// long\n"
1906 "// long long long long\n"
1911 EXPECT_EQ("/* Long long long\n"
1913 format("/* Long long long line\n"
1918 EXPECT_EQ("/* First comment\n"
1919 " * block will */\n"
1920 "/* Snd\n"
1922 format("/* First comment block\n"
1923 " * will */\n"
1924 "/* Snd\n"
1929 EXPECT_EQ("int i; // This long\n"
1930 " // line gets\n"
1931 " // broken.\n"
1932 " //\n"
1934 format("int i; // This long line gets broken.\n"
1935 " // \n"
1938 EXPECT_EQ("{\n"
1939 " /// long long long\n"
1940 " /// long long\n"
1941 " ///\n"
1942 " /// long\n"
1944 format("{\n"
1945 " /// long long long long\n"
1946 " /// long\n"
1947 " ///\n"
1948 " /// long\n"
1951 EXPECT_EQ("//! long long long\n"
1952 "//! long\n"
1953 "\n"
1955 format("//! long long long long\n"
1956 "\n"
1959 EXPECT_EQ("/* long long long\n"
1960 " long\n"
1961 "\n"
1963 format("/* long long long long\n"
1964 "\n"
1967 EXPECT_EQ("/* long long long\n"
1968 " * long\n"
1969 " *\n"
1971 format("/* long long long long\n"
1972 " *\n"
1977 EXPECT_EQ("// long long long\n"
1978 "// long\n"
1980 format("// long long long long\n"
1985 EXPECT_EQ("// long long long\n"
1986 "// long\n"
1988 format("// long long long long\n"
1993 EXPECT_EQ("// long long long\n"
1994 "// long\n"
1996 format("// long long long long\n"
2001 verifyFormat("// long long long\n"
2002 "// long\n"
2004 "// long long long long\n"
2009 EXPECT_EQ("// long long long\n"
2010 "// long\n"
2012 format("// long long long long\n"
2017 EXPECT_EQ("// long long long\n"
2018 "// long\n"
2020 format("// long long long long\n"
2025 EXPECT_EQ("// long long long\n"
2026 "// long\n"
2028 format("// long long long long\n"
2033 EXPECT_EQ("// long long long\n"
2034 "// long\n"
2036 format("// long long long long\n"
2039 EXPECT_EQ("/* long long long\n"
2040 " * long\n"
2041 " * IWYU pragma:\n"
2043 format("/* long long long long\n"
2044 " * IWYU pragma:\n"
2050 EXPECT_EQ("// long long long\n"
2052 format("// long long long long\n"
2057 EXPECT_EQ("/* First comment\n"
2058 " * block will */\n"
2059 "/* Snd\n"
2061 format("/* First comment block\n"
2062 " * will */\n"
2063 "/* Snd\n"
2068 EXPECT_EQ("// long long long\n"
2069 "// long\n"
2071 format("// long long long long\n"
2076 EXPECT_EQ("// - long long long\n"
2077 "// long\n"
2079 format("// - long long long long\n"
2082 EXPECT_EQ("// * long long long\n"
2083 "// long\n"
2085 format("// * long long long long\n"
2088 EXPECT_EQ("// + long long long\n"
2089 "// long\n"
2091 format("// + long long long long\n"
2094 EXPECT_EQ("// 1. long long long\n"
2095 "// long\n"
2097 format("// 1. long long long long\n"
2100 EXPECT_EQ("// -# long long long\n"
2101 "// long\n"
2103 format("// -# long long long long\n"
2107 EXPECT_EQ("// - long long long\n"
2108 "// long long long\n"
2110 format("// - long long long long\n"
2111 "// long long\n"
2114 EXPECT_EQ("// - long long long\n"
2115 "// long long long\n"
2116 "// long\n"
2118 format("// - long long long long\n"
2119 "// long long long\n"
2124 EXPECT_EQ("// long long long\n"
2126 format("// long long long long\n"
2132 EXPECT_EQ("// long long\n"
2134 format("// long long long 10.\n"
2139 verifyFormat("#include <t> // l l l\n"
2144 EXPECT_EQ("#include \"t\" /* l l l\n"
2146 format("#include \"t\" /* l l l\n"
2151 EXPECT_EQ("int i; // long long\n"
2152 " // long\n"
2153 "int j; // long long\n"
2155 format("int i; // long long long\n"
2161 EXPECT_EQ("int i; // trigger\n"
2162 " // reflow\n"
2164 format("int i; // trigger reflow\n"
2169 EXPECT_EQ("a = f(/* looooooooong\n"
2170 " * long long\n"
2171 " */\n"
2173 format("a = f(/* looooooooong long\n* long\n*/ a);",
2177 EXPECT_EQ("a = f(/* loooooong\n"
2178 " * long long\n"
2179 " */\n"
2181 format("a = f(/* loooooong long\n* long\n*/ a);",
2199 EXPECT_EQ("// some text that\n"
2201 format("// some text that reflows\n"
2206 EXPECT_EQ("// some text that\n"
2208 format("// some text that reflows\n"
2216 EXPECT_EQ("// some text that\n"
2217 "// reflows\n"
2219 format("// some text that reflows\n"
2224 EXPECT_EQ("// some text that\n"
2225 "// reflows\n"
2227 format("// some text that reflows\n"
2234 EXPECT_EQ("// some text\n"
2236 format("// some text that\n"
2239 EXPECT_EQ("// some text\n"
2241 format("// some text that\n"
2244 EXPECT_EQ("/* some text\n"
2245 " * that re flows\n"
2247 format("/* some text that\n"
2248 "* re flows\n"
2254 EXPECT_EQ("// some text\n"
2255 "// that\n"
2257 format("// some text that\n"
2263 EXPECT_EQ("// some text that\n"
2264 "// does re flow\n"
2266 format("// some text that does\n"
2272 EXPECT_EQ("#if 0\n"
2273 "}{)(&*(^%%#%@! fsadj f;ldjs ,:;| <<<>>>][)(][\n"
2274 "#endif\n"
2276 format("#if 0\n"
2277 "}{)(&*(^%%#%@! fsadj f;ldjs ,:;| <<<>>>][)(][\n"
2278 "#endif\n"
2280 EXPECT_EQ("#if false\n"
2281 "void f( ) { }\n"
2282 "#endif\n"
2284 format("#if false\n"
2285 "void f( ) { }\n"
2286 "#endif\n"
2288 EXPECT_EQ("enum E {\n"
2289 " One,\n"
2290 " Two,\n"
2291 "#if 0\n"
2292 "Three,\n"
2293 " Four,\n"
2294 "#endif\n"
2295 " Five\n"
2297 format("enum E {\n"
2298 " One,Two,\n"
2299 "#if 0\n"
2300 "Three,\n"
2301 " Four,\n"
2302 "#endif\n"
2304 EXPECT_EQ("enum F {\n"
2305 " One,\n"
2306 "#if 1\n"
2307 " Two,\n"
2308 "#if 0\n"
2309 "Three,\n"
2310 " Four,\n"
2311 "#endif\n"
2312 " Five\n"
2313 "#endif\n"
2315 format("enum F {\n"
2316 "One,\n"
2317 "#if 1\n"
2318 "Two,\n"
2319 "#if 0\n"
2320 "Three,\n"
2321 " Four,\n"
2322 "#endif\n"
2323 "Five\n"
2324 "#endif\n"
2326 EXPECT_EQ("enum G {\n"
2327 " One,\n"
2328 "#if 0\n"
2329 "Two,\n"
2330 "#else\n"
2331 " Three,\n"
2332 "#endif\n"
2333 " Four\n"
2335 format("enum G {\n"
2336 "One,\n"
2337 "#if 0\n"
2338 "Two,\n"
2339 "#else\n"
2340 "Three,\n"
2341 "#endif\n"
2342 "Four\n"
2344 EXPECT_EQ("enum H {\n"
2345 " One,\n"
2346 "#if 0\n"
2347 "#ifdef Q\n"
2348 "Two,\n"
2349 "#else\n"
2350 "Three,\n"
2351 "#endif\n"
2352 "#endif\n"
2353 " Four\n"
2355 format("enum H {\n"
2356 "One,\n"
2357 "#if 0\n"
2358 "#ifdef Q\n"
2359 "Two,\n"
2360 "#else\n"
2361 "Three,\n"
2362 "#endif\n"
2363 "#endif\n"
2364 "Four\n"
2366 EXPECT_EQ("enum I {\n"
2367 " One,\n"
2368 "#if /* test */ 0 || 1\n"
2369 "Two,\n"
2370 "Three,\n"
2371 "#endif\n"
2372 " Four\n"
2374 format("enum I {\n"
2375 "One,\n"
2376 "#if /* test */ 0 || 1\n"
2377 "Two,\n"
2378 "Three,\n"
2379 "#endif\n"
2380 "Four\n"
2382 EXPECT_EQ("enum J {\n"
2383 " One,\n"
2384 "#if 0\n"
2385 "#if 0\n"
2386 "Two,\n"
2387 "#else\n"
2388 "Three,\n"
2389 "#endif\n"
2390 "Four,\n"
2391 "#endif\n"
2392 " Five\n"
2394 format("enum J {\n"
2395 "One,\n"
2396 "#if 0\n"
2397 "#if 0\n"
2398 "Two,\n"
2399 "#else\n"
2400 "Three,\n"
2401 "#endif\n"
2402 "Four,\n"
2403 "#endif\n"
2404 "Five\n"
2408 EXPECT_EQ("#ifdef SWIG\n"
2409 "}{)(&*(^%%#%@! fsadj f;ldjs ,:;| <<<>>>][)(][\n"
2410 "#endif\n"
2412 format("#ifdef SWIG\n"
2413 "}{)(&*(^%%#%@! fsadj f;ldjs ,:;| <<<>>>][)(][\n"
2414 "#endif\n"
2416 EXPECT_EQ("#ifndef SWIG\n"
2417 "void f() {}\n"
2419 format("#ifndef SWIG\n"
2420 "void f( ) { }\n"
2427 "yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy\n"
2428 "zzzzzz\n"
2431 "yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy zzzzzz\n"
2436 verifyFormat("if (0) /* a comment in a strange place */ {\n"
2437 " f();\n"
2439 verifyFormat("if (0) /* a comment in a strange place */ {\n"
2440 " f();\n"
2441 "} /* another comment */ else /* comment #3 */ {\n"
2442 " g();\n"
2444 verifyFormat("while (0) /* a comment in a strange place */ {\n"
2445 " f();\n"
2447 verifyFormat("for (;;) /* a comment in a strange place */ {\n"
2448 " f();\n"
2450 verifyFormat("do /* a comment in a strange place */ {\n"
2451 " f();\n"
2456 EXPECT_EQ("/* */ /* */ /* */\n/* */ /* */ /* */",
2457 format("/* *//* */ /* */\n/* *//* */ /* */"));
2459 EXPECT_EQ("#define A /*123*/ \\\n"
2460 " b\n"
2461 "/* */\n"
2462 "someCall(\n"
2464 format("#define A /*123*/ b\n"
2465 "/* */\n"
2469 EXPECT_EQ("#define A\n"
2470 "/* */ someCall(\n"
2472 format("#define A\n"
2475 verifyNoChange("/*\n**\n*/");
2476 EXPECT_EQ("/*\n"
2477 " *\n"
2478 " * aaaaaa\n"
2479 " * aaaaaa\n"
2481 format("/*\n"
2482 "*\n"
2483 " * aaaaaa aaaaaa\n"
2486 EXPECT_EQ("/*\n"
2487 "**\n"
2488 "* aaaaaa\n"
2489 "*aaaaaa\n"
2491 format("/*\n"
2492 "**\n"
2493 "* aaaaaa aaaaaa\n"
2496 EXPECT_EQ("int aaaaaaaaaaaaaaaaaaaaaaaaaaaa =\n"
2497 " /* line 1\n"
2498 " bbbbbbbbbbbb */\n"
2500 format("int aaaaaaaaaaaaaaaaaaaaaaaaaaaa =\n"
2501 " /* line 1\n"
2507 EXPECT_EQ("someFunction(1, /* comment 1 */\n"
2508 " 2, /* comment 2 */\n"
2509 " 3, /* comment 3 */\n"
2510 " aaaa,\n"
2512 format("someFunction (1, /* comment 1 */\n"
2513 " 2, /* comment 2 */ \n"
2514 " 3, /* comment 3 */\n"
2518 "bool aaaaaaaaaaaaa = /* comment: */ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ||\n"
2521 "bool aaaaaaaaaaaaa = /* trailing comment */\n"
2522 " aaaaaaaaaaaaaaaaaaaaaaaaaaa || aaaaaaaaaaaaaaaaaaaaaaaaa ||\n"
2525 "bool aaaaaaaaaaaaa = /* trailing comment */\n"
2526 " aaaaaaaaaaaaaaaaaaaaaaaaaaa||aaaaaaaaaaaaaaaaaaaaaaaaa ||\n"
2529 "int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa; /* comment */\n"
2530 "int bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb; /* comment */\n"
2532 format("int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa; /* comment */\n"
2533 "int bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb; /* comment */\n"
2538 EXPECT_EQ("/*\n"
2539 " **\n"
2541 format("/*\n"
2542 " **\n"
2544 EXPECT_EQ("/*\n"
2545 " *q\n"
2547 format("/*\n"
2548 " *q\n"
2550 EXPECT_EQ("/*\n"
2551 " * q\n"
2553 format("/*\n"
2554 " * q\n"
2556 EXPECT_EQ("/*\n"
2558 format("/*\n"
2560 EXPECT_EQ("/*\n"
2562 format("/*\n"
2567 EXPECT_EQ("#define A \\\n"
2568 " { \\\n"
2569 " /* one line */ \\\n"
2571 format("#define A { \\\n"
2572 " /* one line */ \\\n"
2575 EXPECT_EQ("#define A \\\n"
2576 " { \\\n"
2577 " /* previous */ \\\n"
2578 " /* one line */ \\\n"
2580 format("#define A { \\\n"
2581 " /* previous */ \\\n"
2582 " /* one line */ \\\n"
2588 EXPECT_EQ("a = {\n"
2589 " 1111 /* */\n"
2591 format("a = {1111 /* */\n"
2594 EXPECT_EQ("a = {\n"
2595 " 1111 /* */\n"
2597 format("a = {1111 /* */\n"
2600 EXPECT_EQ("a = {\n"
2601 " 1111 /* a\n"
2602 " */\n"
2604 format("a = {1111 /* a */\n"
2610 EXPECT_EQ("a = f(/* long\n"
2611 " long */\n"
2614 EXPECT_EQ("a = f(\n"
2615 " /* long\n"
2616 " long */\n"
2620 EXPECT_EQ("a = f(/* long\n"
2621 " long\n"
2622 " */\n"
2624 format("a = f(/* long\n"
2625 " long\n"
2629 EXPECT_EQ("a = f(/* long\n"
2630 " long\n"
2631 " */\n"
2633 format("a = f(/* long\n"
2634 " long\n"
2638 EXPECT_EQ("a = f(/* long\n"
2639 " long\n"
2640 " */\n"
2642 format("a = f(/* long\n"
2643 " long\n"
2648 "a = f(a,\n"
2649 " /* long\n"
2650 " long */\n"
2655 "a = f(\n"
2656 " a,\n"
2657 " /* long\n"
2658 " long */\n"
2662 EXPECT_EQ("a = f(a,\n"
2663 " /* long\n"
2664 " long */\n"
2668 EXPECT_EQ("a = f(\n"
2669 " a,\n"
2670 " /* long\n"
2671 " long */\n"
2678 verifyFormat("{\n"
2679 " // a\n"
2684 EXPECT_EQ("#define MACRO(V) \\\n"
2685 " V(Rt2) /* one more char */ \\\n"
2686 " V(Rs) /* than here */ \\\n"
2687 "/* comment 3 */\n",
2688 format("#define MACRO(V)\\\n"
2689 "V(Rt2) /* one more char */ \\\n"
2690 "V(Rs) /* than here */ \\\n"
2691 "/* comment 3 */\n",
2693 EXPECT_EQ("int i = f(abc, // line 1\n"
2694 " d, // line 2\n"
2695 " // line 3\n"
2697 format("int i = f(abc, // line 1\n"
2698 " d, // line 2\n"
2699 " // line 3\n"
2704 EXPECT_EQ("int ab; // line\n"
2705 "int a; // long\n"
2707 format("int ab; // line\n"
2710 EXPECT_EQ("int ab; // line\n"
2711 "int a; // long\n"
2712 " // long\n"
2714 format("int ab; // line\n"
2715 "int a; // long long\n"
2718 EXPECT_EQ("int ab; // line\n"
2719 "int a; // long\n"
2720 " // long\n"
2722 format("int ab; // line\n"
2723 "int a; // long long\n"
2726 EXPECT_EQ("int ab; // line\n"
2727 "int a; // long\n"
2728 " // long\n"
2729 "\n"
2731 format("int ab; // line\n"
2732 "int a; // long long\n"
2733 "\n"
2739 EXPECT_EQ("int i, j; // line 1\n"
2740 "int k; // line longg\n"
2742 format("int i, j; // line 1\n"
2747 EXPECT_EQ("int i, j; // line 1\n"
2749 format("int i, j; // line 1\n"
2755 EXPECT_EQ("class A {\n"
2756 "public: // public comment\n"
2757 " // comment about a\n"
2758 " int a;\n"
2760 format("class A {\n"
2761 "public: // public comment\n"
2762 " // comment about a\n"
2763 " int a;\n"
2766 EXPECT_EQ("class A {\n"
2767 "public: // public comment 1\n"
2768 " // public comment 2\n"
2769 " // comment 1 about a\n"
2770 " // comment 2 about a\n"
2771 " int a;\n"
2773 format("class A {\n"
2774 "public: // public comment 1\n"
2775 " // public comment 2\n"
2776 " // comment 1 about a\n"
2777 " // comment 2 about a\n"
2778 " int a;\n"
2781 EXPECT_EQ("int f(int n) { // comment line 1 on f\n"
2782 " // comment line 2 on f\n"
2783 " // comment line 1 before return\n"
2784 " // comment line 2 before return\n"
2785 " return n; // comment line 1 on return\n"
2786 " // comment line 2 on return\n"
2787 " // comment line 1 after return\n"
2789 format("int f(int n) { // comment line 1 on f\n"
2790 " // comment line 2 on f\n"
2791 " // comment line 1 before return\n"
2792 " // comment line 2 before return\n"
2793 " return n; // comment line 1 on return\n"
2794 " // comment line 2 on return\n"
2795 " // comment line 1 after return\n"
2798 EXPECT_EQ("int f(int n) {\n"
2799 " switch (n) { // comment line 1 on switch\n"
2800 " // comment line 2 on switch\n"
2801 " // comment line 1 before case 1\n"
2802 " // comment line 2 before case 1\n"
2803 " case 1: // comment line 1 on case 1\n"
2804 " // comment line 2 on case 1\n"
2805 " // comment line 1 before return 1\n"
2806 " // comment line 2 before return 1\n"
2807 " return 1; // comment line 1 on return 1\n"
2808 " // comment line 2 on return 1\n"
2809 " // comment line 1 before default\n"
2810 " // comment line 2 before default\n"
2811 " default: // comment line 1 on default\n"
2812 " // comment line 2 on default\n"
2813 " // comment line 1 before return 2\n"
2814 " return 2 * f(n - 1); // comment line 1 on return 2\n"
2815 " // comment line 2 on return 2\n"
2816 " // comment line 1 after return\n"
2817 " // comment line 2 after return\n"
2818 " }\n"
2820 format("int f(int n) {\n"
2821 " switch (n) { // comment line 1 on switch\n"
2822 " // comment line 2 on switch\n"
2823 " // comment line 1 before case 1\n"
2824 " // comment line 2 before case 1\n"
2825 " case 1: // comment line 1 on case 1\n"
2826 " // comment line 2 on case 1\n"
2827 " // comment line 1 before return 1\n"
2828 " // comment line 2 before return 1\n"
2829 " return 1; // comment line 1 on return 1\n"
2830 " // comment line 2 on return 1\n"
2831 " // comment line 1 before default\n"
2832 " // comment line 2 before default\n"
2833 " default: // comment line 1 on default\n"
2834 " // comment line 2 on default\n"
2835 " // comment line 1 before return 2\n"
2836 " return 2 * f(n - 1); // comment line 1 on return 2\n"
2837 " // comment line 2 on return 2\n"
2838 " // comment line 1 after return\n"
2839 " // comment line 2 after return\n"
2840 " }\n"
2847 EXPECT_EQ("int a; // line about a\n"
2849 format("int a; // line about a\n"
2852 EXPECT_EQ("int a; // line about a\n"
2853 "// line about b\n"
2855 format("int a; // line about a\n"
2856 " // line about b\n"
2859 EXPECT_EQ("int a; // line about a\n"
2860 "// line 1 about b\n"
2861 "// line 2 about b\n"
2863 format("int a; // line about a\n"
2864 " // line 1 about b\n"
2865 " // line 2 about b\n"
2872 "#if FOO\n"
2873 "#else\n"
2874 "long a; // Line about a\n"
2875 "#endif\n"
2876 "#if BAR\n"
2877 "#else\n"
2878 "long b_long_name; // Line about b\n"
2880 format("#if FOO\n"
2881 "#else\n"
2882 "long a; // Line about a\n" // Previous (bad) behavior
2883 "#endif\n"
2884 "#if BAR\n"
2885 "#else\n"
2886 "long b_long_name; // Line about b\n"
2892 "namespace m {\n\n"
2893 "#define FOO_GLOBAL 0 // Global scope.\n"
2894 "#define FOO_LINKLOCAL 1 // Link-local scope.\n"
2895 "#define FOO_SITELOCAL 2 // Site-local scope (deprecated).\n"
2896 "#define FOO_UNIQUELOCAL 3 // Unique local\n"
2897 "#define FOO_NODELOCAL 4 // Loopback\n\n"
2899 format("namespace m {\n\n"
2900 "#define FOO_GLOBAL 0 // Global scope.\n"
2901 "#define FOO_LINKLOCAL 1 // Link-local scope.\n"
2902 "#define FOO_SITELOCAL 2 // Site-local scope (deprecated).\n"
2903 "#define FOO_UNIQUELOCAL 3 // Unique local\n"
2904 "#define FOO_NODELOCAL 4 // Loopback\n\n"
2909 verifyFormat("/* */ //\n"
2911 verifyFormat("/**/ //\n"
2919 verifyFormat("#include \"a.h\" // simple\n"
2920 "\n"
2924 verifyFormat("#include \"a.h\" // align across\n"
2925 "\n"
2926 "#include \"aa.h\" // two empty lines\n"
2927 "\n"
2931 verifyFormat("#include \"a.h\" // align\n"
2932 "#include \"aa.h\" // comment\n"
2933 "#include \"aaa.h\" // blocks\n"
2934 "\n"
2935 "#include \"aaaa.h\" // across\n"
2936 "#include \"aaaaa.h\" // one\n"
2940 verifyFormat("#include \"a.h\" // align trailing comments\n"
2941 "#include \"a.h\"\n"
2945 verifyFormat("#include \"a.h\" // align across\n"
2946 "#include \"a.h\"\n"
2947 "#include \"aa.h\" // two lines without comment\n"
2948 "#include \"a.h\"\n"
2952 verifyFormat("#include \"a.h\" // align\n"
2953 "#include \"aa.h\" // comment\n"
2954 "#include \"aaa.h\" // blocks\n"
2955 "#include \"a.h\"\n"
2956 "#include \"aaaa.h\" // across\n"
2957 "#include \"aaaaa.h\" // a line without\n"
2966 EXPECT_EQ("#include \"a.h\" // comment\n"
2967 "\n"
2968 "\n"
2969 "\n"
2970 "#include \"ab.h\" // comment\n"
2971 "\n"
2972 "\n"
2974 format("#include \"a.h\" // comment\n"
2975 "\n"
2976 "\n"
2977 "\n"
2978 "#include \"ab.h\" // comment\n"
2979 "\n"
2980 "\n"
2989 EXPECT_EQ("int ab; // line\n"
2990 "int a; // long\n"
2991 " // long\n"
2992 "\n"
2994 format("int ab; // line\n"
2995 "int a; // long long\n"
2996 "\n"
3001 EXPECT_EQ("int ab; // line\n"
3002 "\n"
3003 "int a; // long\n"
3005 format("int ab; // line\n"
3006 "\n"
3011 EXPECT_EQ("int foo = 12345; // comment\n"
3012 "int bar =\n"
3013 " 1234; // This is a very\n"
3014 " // long comment\n"
3015 " // which is wrapped\n"
3016 " // arround.\n"
3017 "\n"
3018 "int x = 2; // Is this still\n"
3020 format("int foo = 12345; // comment\n"
3021 "int bar = 1234; // This is a very long comment\n"
3022 " // which is wrapped arround.\n"
3023 "\n"
3028 EXPECT_EQ("int foo = 12345; // comment\n"
3029 "int bar =\n"
3030 " 1234; // This is a very long\n"
3031 " // comment which is\n"
3032 " // wrapped arround.\n"
3033 "\n"
3034 "int x =\n"
3036 format("int foo = 12345; // comment\n"
3037 "int bar = 1234; // This is a very long comment\n"
3038 " // which is wrapped arround.\n"
3039 "\n"
3044 EXPECT_EQ("int foo = 12345; // comment\n"
3045 "int bar =\n"
3046 " 1234; // This is a very long comment\n"
3047 " // which is wrapped arround.\n"
3048 "\n"
3050 format("int foo = 12345; // comment\n"
3051 "int bar = 1234; // This is a very long comment\n"
3052 " // which is wrapped arround.\n"
3053 "\n"
3058 EXPECT_EQ("int foo = 12345; // comment\n"
3059 "int bar =\n"
3060 " 1234; // This is a very long comment\n"
3061 " // which is wrapped arround.\n"
3062 "\n"
3064 format("int foo = 12345; // comment\n"
3065 "int bar = 1234; // This is a very long comment\n"
3066 " // which is wrapped arround.\n"
3067 "\n"
3072 EXPECT_EQ("int a; // line about a\n"
3073 "\n"
3074 "// line about b\n"
3076 format("int a; // line about a\n"
3077 "\n"
3078 " // line about b\n"
3083 EXPECT_EQ("int a; // line about a\n"
3084 "\n"
3085 "// line 1 about b\n"
3086 "// line 2 about b\n"
3088 format("int a; // line about a\n"
3089 "\n"
3090 " // line 1 about b\n"
3091 " // line 2 about b\n"
3100 EXPECT_EQ("int a;// do not touch\n"
3101 "int b; // any comments\n"
3102 "int c; // comment\n"
3104 format("int a;// do not touch\n"
3105 "int b; // any comments\n"
3106 "int c; // comment\n"
3110 EXPECT_EQ("int a; // do not touch\n"
3111 "int b; // any comments\n"
3112 "int c; // comment\n"
3114 format("int a; // do not touch\n"
3115 "int b; // any comments\n"
3116 "int c; // comment\n"
3120 EXPECT_EQ("// do not touch\n"
3121 "int a; // any comments\n"
3122 "\n"
3123 " // comment\n"
3124 "// comment\n"
3125 "\n"
3127 format("// do not touch\n"
3128 "int a; // any comments\n"
3129 "\n"
3130 " // comment\n"
3131 "// comment\n"
3132 "\n"
3136 EXPECT_EQ("// do not touch\n"
3137 "int a; // any comments\n"
3138 "\n"
3139 " // comment\n"
3140 "// comment\n"
3141 "\n"
3143 format("// do not touch\n"
3144 "int a; // any comments\n"
3145 "\n"
3146 "\n"
3147 " // comment\n"
3148 "// comment\n"
3149 "\n"
3150 "\n"
3154 verifyFormat("namespace ns {\n"
3155 "int i;\n"
3156 "int j;\n"
3158 "namespace ns {\n"
3159 "int i;\n"
3160 "int j;\n"
3165 verifyNoChange("#define FOO \\\n"
3166 " /* foo(); */ \\\n"
3172 EXPECT_EQ("// do not touch\n"
3173 "int a; // any comments\n"
3174 "\n"
3175 "\n"
3176 " // comment\n"
3177 "// comment\n"
3178 "\n"
3180 format("// do not touch\n"
3181 "int a; // any comments\n"
3182 "\n"
3183 "\n"
3184 " // comment\n"
3185 "// comment\n"
3186 "\n"
3193 EXPECT_EQ("int foo = 12345; // comment\n"
3194 "int bar =\n"
3195 " 1234; // This is a very long\n"
3196 " // comment which is\n"
3198 format("int foo = 12345; // comment\n"
3199 "int bar = 1234; // This is a very long comment\n"
3207 verifyNoChange("{\n"
3208 "\t// f\n"
3209 "\tf();\n"
3210 "\n"
3211 "\t// g\n"
3212 "\tg();\n"
3213 "\t{\n"
3214 "\t\t// h(); // h\n"
3215 "\t\tfoo(); // foo\n"
3216 "\t}\n"
3227 StringRef Input = "namespace A {\n"
3228 " TESTSUITE(B) {\n"
3229 " namespace C {\n"
3230 " namespace D { //\n"
3231 " } // namespace D\n"
3232 " std::string Foo = Bar; // Comment\n"
3233 " std::string BazString = Baz; // C2\n"
3234 " } // namespace C\n"
3235 " }\n"
3240 verifyFormat("namespace A {\n"
3241 " TESTSUITE(B) {\n"
3242 " namespace C {\n"
3243 " namespace D { //\n"
3244 " } // namespace D\n"
3245 " std::string Foo = Bar; // Comment\n"
3246 " std::string BazString = Baz; // C2\n"
3247 " } // namespace C\n"
3248 " } // TESTSUITE(B)\n"
3253 verifyFormat("namespace A {\n"
3254 " TESTSUITE(B) {\n"
3255 " namespace C {\n"
3256 " namespace D { //\n"
3257 " } // namespace D\n"
3258 " std::string Foo = Bar; // Comment\n"
3259 " std::string BazString = Baz; // C2\n"
3260 " } // namespace C\n"
3261 " } // TESTSUITE(B)\n"
3266 verifyFormat("namespace A {\n"
3267 " TESTSUITE(B) {\n"
3268 " namespace C {\n"
3269 " namespace D { //\n"
3270 " } // namespace D\n"
3271 " std::string Foo = Bar; // Comment\n"
3272 " std::string BazString = Baz; // C2\n"
3273 " } // namespace C\n"
3274 " } // TESTSUITE(B)\n"
3280 verifyFormat("namespace A {\n"
3281 " TESTSUITE(B) {\n"
3282 " namespace C {\n"
3283 " namespace D { //\n"
3284 " } // namespace D\n"
3285 " std::string Foo = Bar; // Comment\n"
3286 " std::string BazString = Baz; // C2\n"
3287 " } // namespace C\n"
3288 " }\n"
3293 verifyFormat("namespace A {\n"
3294 " TESTSUITE(B) {\n"
3295 " namespace C {\n"
3296 " namespace D { //\n"
3297 " } // namespace D\n"
3298 " std::string Foo = Bar; // Comment\n"
3299 " std::string BazString = Baz; // C2\n"
3300 " } // namespace C\n"
3301 " }\n"
3306 verifyFormat("namespace A {\n"
3307 " TESTSUITE(B) {\n"
3308 " namespace C {\n"
3309 " namespace D { //\n"
3310 " } // namespace D\n"
3311 " std::string Foo = Bar; // Comment\n"
3312 " std::string BazString = Baz; // C2\n"
3313 " } // namespace C\n"
3314 " }\n"
3320 Input = "namespace A {\n"
3321 " int Foo;\n"
3322 " int Bar;\n"
3323 "}\n"
3326 verifyFormat("namespace A {\n"
3327 " int Foo;\n"
3328 " int Bar;\n"
3329 "} // namespace A\n"
3338 verifyFormat("if (foo) {\n"
3339 " int aLongVariable; // with comment\n"
3340 " int f; // aligned\n"
3341 "} // not aligned\n"
3342 "int bar; // new align\n"
3345 verifyFormat("if (foo) {\n"
3346 " // something\n"
3347 "} else {\n"
3348 " int aLongVariable; // with comment\n"
3349 " int f; // aligned\n"
3350 "} // not aligned\n"
3351 "int bar; // new align\n"
3354 verifyFormat("if (foo) {\n"
3355 " // something\n"
3356 "} else if (foo) {\n"
3357 " int aLongVariable; // with comment\n"
3358 " int f; // aligned\n"
3359 "} // not aligned\n"
3360 "int bar; // new align\n"
3363 verifyFormat("while (foo) {\n"
3364 " int aLongVariable; // with comment\n"
3365 " int f; // aligned\n"
3366 "} // not aligned\n"
3367 "int bar; // new align\n"
3370 verifyFormat("for (;;) {\n"
3371 " int aLongVariable; // with comment\n"
3372 " int f; // aligned\n"
3373 "} // not aligned\n"
3374 "int bar; // new align\n"
3377 verifyFormat("do {\n"
3378 " int aLongVariable; // with comment\n"
3379 " int f; // aligned\n"
3380 "} while (foo); // not aligned\n"
3381 "int bar; // new align\n"
3384 verifyFormat("do\n"
3385 " int aLongVariable; // with comment\n"
3386 "while (foo); // not aigned\n"
3387 "int bar; // new align\n"
3390 verifyFormat("do\n"
3391 " int aLongVariable; // with comment\n"
3392 "/**/ while (foo); // not aigned\n"
3393 "int bar; // new align\n"
3396 verifyFormat("switch (foo) {\n"
3397 "case 7: {\n"
3398 " int aLongVariable; // with comment\n"
3399 " int f; // aligned\n"
3400 "} // case not aligned\n"
3401 "} // switch also not aligned\n"
3402 "int bar; // new align\n"
3405 verifyFormat("switch (foo) {\n"
3406 "default: {\n"
3407 " int aLongVariable; // with comment\n"
3408 " int f; // aligned\n"
3409 "} // case not aligned\n"
3410 "} // switch also not aligned\n"
3411 "int bar; // new align\n"
3414 verifyFormat("class C {\n"
3415 " int aLongVariable; // with comment\n"
3416 " int f; // aligned\n"
3417 "}; // not aligned\n"
3418 "int bar; // new align\n"
3421 verifyFormat("struct S {\n"
3422 " int aLongVariable; // with comment\n"
3423 " int f; // aligned\n"
3424 "}; // not aligned\n"
3425 "int bar; // new align\n"
3428 verifyFormat("union U {\n"
3429 " int aLongVariable; // with comment\n"
3430 " int f; // aligned\n"
3431 "}; // not aligned\n"
3432 "int bar; // new align\n"
3435 verifyFormat("enum E {\n"
3436 " aLongVariable, // with comment\n"
3437 " f // aligned\n"
3438 "}; // not aligned\n"
3439 "int bar; // new align\n"
3442 verifyFormat("void foo() {\n"
3443 " {\n"
3444 " int aLongVariable; // with comment\n"
3445 " int f; // aligned\n"
3446 " } // not aligned\n"
3447 " int bar; // new align\n"
3448 " int foobar; // group\n"
3451 verifyFormat("auto longLambda = [] { // comment\n"
3452 " int aLongVariable; // with comment\n"
3453 " int f; // aligned\n"
3454 "}; // not aligned\n"
3455 "int bar; // new align\n"
3456 "int foobar; // group\n"
3459 verifyFormat("auto longLambdaResult = [] { // comment\n"
3460 " int aLongVariable; // with comment\n"
3461 " int f; // aligned\n"
3462 "}(); // not aligned\n"
3463 "int bar; // new align\n"
3464 "int foobar; // group\n"
3468 "auto longLambdaResult = [](auto I, auto J) { // comment\n"
3469 " int aLongVariable; // with comment\n"
3470 " int f; // aligned\n"
3471 "}(\"Input\", 5); // not aligned\n"
3472 "int bar; // new align\n"
3473 "int foobar; // group\n"
3476 verifyFormat("enum E1 { V1, V2 }; // Aligned\n"
3479 verifyFormat("class C {\n"
3480 " int aLongVariable; // with comment\n"
3481 " int f; // aligned\n"
3482 "} /* middle comment */; // not aligned\n"
3483 "int bar; // new align\n"
3488 EXPECT_EQ("/*\n"
3490 format("/*\n"
3492 EXPECT_EQ("/*\n"
3494 format("/*\n"
3496 EXPECT_EQ("/*\n"
3498 format("/*\n"
3502 EXPECT_EQ("/*\n"
3504 format("/*\n"
3506 EXPECT_EQ("/*\n"
3508 format("/*\n"
3510 EXPECT_EQ("/*\n"
3512 format("/*\n"
3514 EXPECT_EQ("/*\n"
3516 format("/*\n"
3518 EXPECT_EQ("/**\n"
3520 format("/**\n"
3522 EXPECT_EQ("/**\n"
3524 format("/**\n"
3526 EXPECT_EQ("/**\n"
3528 format("/**\n"
3530 EXPECT_EQ("/**\n"
3532 format("/**\n"
3534 EXPECT_EQ("/**\n"
3536 format("/**\n"
3540 EXPECT_EQ("/*\n"
3541 " * line\n"
3543 format("/*\n"
3544 "* line\n"
3546 EXPECT_EQ("/*\n"
3547 " * line\n"
3549 format("/*\n"
3550 " * line\n"
3552 EXPECT_EQ("/*\n"
3553 " * line\n"
3555 format("/*\n"
3556 " * line\n"
3560 EXPECT_EQ("/* line 1\n"
3562 format("/* line 1\n"
3564 EXPECT_EQ("/* line 1\n"
3566 format("/* line 1\n"
3568 EXPECT_EQ("/* line 1\n"
3570 format("/* line 1\n"
3572 EXPECT_EQ("/* line 1\n"
3574 format("/* line 1\n"
3576 EXPECT_EQ("/* line 1\n"
3578 format("/* line 1\n"
3580 EXPECT_EQ("int i; /* line 1\n"
3582 format("int i; /* line 1\n"
3584 EXPECT_EQ("int i; /* line 1\n"
3586 format("int i; /* line 1\n"
3588 EXPECT_EQ("int i; /* line 1\n"
3590 format("int i; /* line 1\n"
3594 EXPECT_EQ("/* line 1\n"
3595 " * line 2\n"
3597 format("/* line 1\n"
3598 " * line 2\n"
3600 EXPECT_EQ("/* line 1\n"
3601 " * line 2\n"
3603 format("/* line 1\n"
3604 " * line 2\n"
3606 EXPECT_EQ("/*\n"
3607 "** line 1\n"
3608 "** line 2\n"
3610 format("/*\n"
3611 "** line 1\n"
3612 " ** line 2\n"
3616 EXPECT_EQ("/*\n"
3617 " * line 1\n"
3618 " * line 2\n"
3619 " * line 3\n"
3620 " * line 4\n"
3622 format("/*\n"
3623 "* line 1\n"
3624 " * line 2\n"
3625 " * line 3\n"
3626 "* line 4\n"
3630 EXPECT_EQ("/**\n"
3631 " *\n"
3632 " *\n"
3633 " *\n"
3635 format("/**\n"
3636 "* \n"
3637 " * \n"
3638 " *\n"
3642 EXPECT_EQ("/*\n"
3643 " * long long long\n"
3644 " * long long\n"
3645 " *\n"
3647 format("/*\n"
3648 " * long long long long\n"
3649 " * long\n"
3650 " *\n"
3661 "/* */ /*\n"
3662 " * a\n"
3665 "/* */ /*\n"
3666 " * a b\n"
3676 verifyFormat("const /** comment comment comment */ A =\n"
3680 EXPECT_EQ("const /** comment comment comment\n"
3681 " comment */\n"
3683 format("const /** comment comment comment comment */\n"
3690 EXPECT_EQ("# comment\n"
3692 format("#comment\n"
3695 EXPECT_EQ("# comment\n"
3697 format("# comment\n"
3701 EXPECT_EQ("# comment comment\n"
3702 "# comment\n"
3704 format("# comment comment comment\n"
3708 EXPECT_EQ("data {\n"
3709 " # comment comment\n"
3710 " # comment\n"
3711 " key: value\n"
3713 format("data {\n"
3714 "# comment comment comment\n"
3717 EXPECT_EQ("data {\n"
3718 " # comment comment\n"
3719 " # comment\n"
3720 " key: value\n"
3722 format("data {# comment comment comment\n"
3726 EXPECT_EQ("# comment comment\n"
3727 "# comment comment\n"
3729 format("# comment comment comment\n"
3730 "# comment\n"
3734 EXPECT_EQ("k: val # comment\n"
3735 " # comment\n"
3737 format("k:val#comment comment\n"
3740 EXPECT_EQ("id {\n"
3741 " k: val # comment\n"
3742 " # comment\n"
3743 " # line line\n"
3744 " a: 1\n"
3746 format("id {k:val#comment comment\n"
3747 "# line line\n"
3751 EXPECT_EQ("k: val # commen1\n"
3752 " # commen2\n"
3753 " # commen3\n"
3754 "# commen4\n"
3755 "a: 1 # commen5\n"
3756 " # commen6\n"
3758 format("k:val#commen1 commen2\n"
3759 " #commen3\n"
3760 "# commen4\n"
3761 "a:1#commen5 commen6\n"
3770 verifyFormat("int a =\n"
3778 "// How to run:\n"
3779 "// bbbbb run \\\n"
3780 "// rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr\n"
3783 "// How to run:\n"
3784 "// bbbbb run \\\n"
3785 "// rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr \\\n"
3796 "/**\n"
3797 " * @param x long long long long long long long long long\n"
3798 " * long\n"
3800 format("/**\n"
3801 " * @param x long long long long long long long long long long\n"
3804 EXPECT_EQ("/**\n"
3805 " * @param x long long long long long long long long long\n"
3806 " * long long long long long long long long long long\n"
3808 format("/**\n"
3810 "long long long long long long long long long long\n"
3813 EXPECT_EQ("/**\n"
3814 " * @param x long long long long long long long long long\n"
3815 " * long long long long long long long long long long\n"
3816 " * long\n"
3818 format("/**\n"
3820 "long long long long long long long long long long long\n"
3823 EXPECT_EQ("/**\n"
3824 " * Sentence that\n"
3825 " * should be broken.\n"
3826 " * @param short\n"
3827 " * keep indentation\n"
3829 format("/**\n"
3830 " * Sentence that should be broken.\n"
3831 " * @param short\n"
3832 " * keep indentation\n"
3836 EXPECT_EQ("/**\n"
3837 " * @param l1 long1\n"
3838 " * to break\n"
3839 " * @param l2 long2\n"
3840 " * to break\n"
3842 format("/**\n"
3843 " * @param l1 long1 to break\n"
3844 " * @param l2 long2 to break\n"
3848 EXPECT_EQ("/**\n"
3849 " * @param xx to\n"
3850 " * break\n"
3851 " * no reflow\n"
3853 format("/**\n"
3854 " * @param xx to break\n"
3855 " * no reflow\n"
3859 EXPECT_EQ("/**\n"
3860 " * @param xx to\n"
3861 " * break yes\n"
3862 " * reflow\n"
3864 format("/**\n"
3865 " * @param xx to break\n"
3866 " * yes reflow\n"
3872 EXPECT_EQ("/**\n"
3873 " * @param l1 long1\n"
3874 " * to break\n"
3876 format("/**\n"
3877 " * @param l1 long1 to break\n"
3880 EXPECT_EQ("/**\n"
3881 " * @param {l1 long1\n"
3882 " * to break}\n"
3884 format("/**\n"
3885 " * @param {l1 long1 to break}\n"
3892 StringRef NoTextInComment = " // \n"
3893 "\n"
3894 "void foo() {// \n"
3895 "// \n"
3898 EXPECT_EQ("//\n"
3899 "\n"
3900 "void foo() { //\n"
3901 " //\n"
3907 EXPECT_EQ("//\n"
3908 "\n"
3909 "void foo() { //\n"
3910 " //\n"
3916 EXPECT_EQ("//\n"
3917 "\n"
3918 "void foo() { //\n"
3919 " //\n"
3925 "//Free comment without space\n"
3926 "\n"
3927 "// Free comment with 3 spaces\n"
3928 "\n"
3929 "///Free Doxygen without space\n"
3930 "\n"
3931 "/// Free Doxygen with 3 spaces\n"
3932 "\n"
3933 "//? A nice dragon\n"
3934 "\n"
3935 "//\t abccba\n"
3936 "\n"
3937 "//\\t deffed\n"
3938 "\n"
3939 "// ? Another nice dragon\n"
3940 "\n"
3941 "// \t Three leading spaces following tab\n"
3942 "\n"
3943 "// \\t Three leading spaces following backslash\n"
3944 "\n"
3945 "/// A Doxygen Comment with a nested list:\n"
3946 "/// - Foo\n"
3947 "/// - Bar\n"
3948 "/// - Baz\n"
3949 "/// - End\n"
3950 "/// of the inner list\n"
3951 "/// .\n"
3952 "/// .\n"
3953 "\n"
3954 "namespace Foo {\n"
3955 "bool bar(bool b) {\n"
3956 " bool ret1 = true; ///<Doxygenstyle without space\n"
3957 " bool ret2 = true; ///< Doxygenstyle with 3 spaces\n"
3958 " if (b) {\n"
3959 " //Foo\n"
3960 "\n"
3961 " // In function comment\n"
3962 " ret2 = false;\n"
3963 " } // End of if\n"
3964 "\n"
3965 "// if (ret1) {\n" // Commented out at the beginning of the line
3966 "// return ret2;\n"
3967 "// }\n"
3968 "\n"
3969 " //if (ret1) {\n" // Commtented out at the beginning of the content
3970 " // return ret2;\n"
3971 " //}\n"
3972 "\n"
3973 " return ret1 && ret2;\n"
3974 "}\n"
3975 "}\n"
3976 "\n"
3977 "namespace Bar {\n"
3978 "int foo();\n"
3979 "} // namespace Bar\n"
3980 "//@Nothing added because of the non ascii char\n"
3981 "\n"
3982 "//@ Nothing removed because of the non ascii char\n"
3983 "\n"
3984 "// Comment to move to the left\n"
3985 "//But not this?\n"
3986 "// @but this\n"
3987 "\n"
3988 "//Comment to move to the right\n"
3989 "//@ this stays\n"
3990 "\n"
3991 "//} will not move\n"
3992 "\n"
3993 "//vv will only move\n"
3996 EXPECT_EQ("// Free comment without space\n"
3997 "\n"
3998 "// Free comment with 3 spaces\n"
3999 "\n"
4000 "/// Free Doxygen without space\n"
4001 "\n"
4002 "/// Free Doxygen with 3 spaces\n"
4003 "\n"
4004 "// ? A nice dragon\n"
4005 "\n"
4006 "//\t abccba\n"
4007 "\n"
4008 "//\\t deffed\n"
4009 "\n"
4010 "// ? Another nice dragon\n"
4011 "\n"
4012 "// \t Three leading spaces following tab\n"
4013 "\n"
4014 "// \\t Three leading spaces following backslash\n"
4015 "\n"
4016 "/// A Doxygen Comment with a nested list:\n"
4017 "/// - Foo\n"
4018 "/// - Bar\n"
4019 "/// - Baz\n"
4020 "/// - End\n"
4021 "/// of the inner list\n"
4022 "/// .\n"
4023 "/// .\n"
4024 "\n"
4025 "namespace Foo {\n"
4026 "bool bar(bool b) {\n"
4027 " bool ret1 = true; ///< Doxygenstyle without space\n"
4028 " bool ret2 = true; ///< Doxygenstyle with 3 spaces\n"
4029 " if (b) {\n"
4030 " // Foo\n"
4031 "\n"
4032 " // In function comment\n"
4033 " ret2 = false;\n"
4034 " } // End of if\n"
4035 "\n"
4036 " // if (ret1) {\n"
4037 " // return ret2;\n"
4038 " // }\n"
4039 "\n"
4040 " // if (ret1) {\n"
4041 " // return ret2;\n"
4042 " // }\n"
4043 "\n"
4044 " return ret1 && ret2;\n"
4045 "}\n"
4046 "} // namespace Foo\n"
4047 "\n"
4048 "namespace Bar {\n"
4049 "int foo();\n"
4050 "} // namespace Bar\n"
4051 "//@Nothing added because of the non ascii char\n"
4052 "\n"
4053 "//@ Nothing removed because of the non ascii char\n"
4054 "\n"
4055 "// Comment to move to the left\n"
4056 "// But not this?\n"
4057 "// @but this\n"
4058 "\n"
4059 "// Comment to move to the right\n"
4060 "//@ this stays\n"
4061 "\n"
4062 "//} will not move\n"
4063 "\n"
4064 "// vv will only move\n"
4070 EXPECT_EQ("//Free comment without space\n"
4071 "\n"
4072 "//Free comment with 3 spaces\n"
4073 "\n"
4074 "///Free Doxygen without space\n"
4075 "\n"
4076 "///Free Doxygen with 3 spaces\n"
4077 "\n"
4078 "//? A nice dragon\n"
4079 "\n"
4080 "//\t abccba\n"
4081 "\n"
4082 "//\\t deffed\n"
4083 "\n"
4084 "//? Another nice dragon\n"
4085 "\n"
4086 "//\t Three leading spaces following tab\n"
4087 "\n"
4088 "//\\t Three leading spaces following backslash\n"
4089 "\n"
4090 "///A Doxygen Comment with a nested list:\n"
4091 "///- Foo\n"
4092 "///- Bar\n"
4093 "/// - Baz\n" // Here we keep the relative indentation
4094 "/// - End\n"
4095 "/// of the inner list\n"
4096 "/// .\n"
4097 "///.\n"
4098 "\n"
4099 "namespace Foo {\n"
4100 "bool bar(bool b) {\n"
4101 " bool ret1 = true; ///<Doxygenstyle without space\n"
4102 " bool ret2 = true; ///<Doxygenstyle with 3 spaces\n"
4103 " if (b) {\n"
4104 " //Foo\n"
4105 "\n"
4106 " //In function comment\n"
4107 " ret2 = false;\n"
4108 " } //End of if\n"
4109 "\n"
4110 " //if (ret1) {\n"
4111 " // return ret2;\n"
4112 " //}\n"
4113 "\n"
4114 " //if (ret1) {\n"
4115 " // return ret2;\n"
4116 " //}\n"
4117 "\n"
4118 " return ret1 && ret2;\n"
4119 "}\n"
4120 "} //namespace Foo\n"
4121 "\n"
4122 "namespace Bar {\n"
4123 "int foo();\n"
4124 "} //namespace Bar\n"
4125 "//@Nothing added because of the non ascii char\n"
4126 "\n"
4127 "//@ Nothing removed because of the non ascii char\n"
4128 "\n"
4129 "//Comment to move to the left\n"
4130 "//But not this?\n"
4131 "//@but this\n"
4132 "\n"
4133 "//Comment to move to the right\n"
4134 "//@ this stays\n"
4135 "\n"
4136 "//} will not move\n"
4137 "\n"
4138 "//vv will only move\n"
4143 EXPECT_EQ("// Free comment without space\n"
4144 "\n"
4145 "// Free comment with 3 spaces\n"
4146 "\n"
4147 "/// Free Doxygen without space\n"
4148 "\n"
4149 "/// Free Doxygen with 3 spaces\n"
4150 "\n"
4151 "// ? A nice dragon\n"
4152 "\n"
4153 "//\t abccba\n"
4154 "\n"
4155 "//\\t deffed\n"
4156 "\n"
4157 "// ? Another nice dragon\n"
4158 "\n"
4159 "// \t Three leading spaces following tab\n"
4160 "\n"
4161 "// \\t Three leading spaces following backslash\n"
4162 "\n"
4163 "/// A Doxygen Comment with a nested list:\n"
4164 "/// - Foo\n"
4165 "/// - Bar\n"
4166 "/// - Baz\n"
4167 "/// - End\n"
4168 "/// of the inner list\n"
4169 "/// .\n"
4170 "/// .\n"
4171 "\n"
4172 "namespace Foo {\n"
4173 "bool bar(bool b) {\n"
4174 " bool ret1 = true; ///< Doxygenstyle without space\n"
4175 " bool ret2 = true; ///< Doxygenstyle with 3 spaces\n"
4176 " if (b) {\n"
4177 " // Foo\n"
4178 "\n"
4179 " // In function comment\n"
4180 " ret2 = false;\n"
4181 " } // End of if\n"
4182 "\n"
4183 " // if (ret1) {\n"
4184 " // return ret2;\n"
4185 " // }\n"
4186 "\n"
4187 " // if (ret1) {\n"
4188 " // return ret2;\n"
4189 " // }\n"
4190 "\n"
4191 " return ret1 && ret2;\n"
4192 "}\n"
4193 "} // namespace Foo\n"
4194 "\n"
4195 "namespace Bar {\n"
4196 "int foo();\n"
4197 "} // namespace Bar\n"
4198 "//@Nothing added because of the non ascii char\n"
4199 "\n"
4200 "//@ Nothing removed because of the non ascii char\n"
4201 "\n"
4202 "// Comment to move to the left\n"
4203 "// But not this?\n"
4204 "// @but this\n"
4205 "\n"
4206 "// Comment to move to the right\n"
4207 "//@ this stays\n"
4208 "\n"
4209 "//} will not move\n"
4210 "\n"
4211 "// vv will only move\n"
4216 StringRef WrapCode = "//Lorem ipsum dolor sit amet\n"
4217 "\n"
4218 "// Lorem ipsum dolor sit amet\n"
4219 "\n"
4220 "void f() {//Hello World\n"
4223 EXPECT_EQ("// Lorem ipsum dolor\n"
4224 "// sit amet\n"
4225 "\n"
4226 "// Lorem ipsum\n"
4227 "// dolor sit amet\n"
4228 "\n"
4229 "void f() { // Hello\n"
4230 " // World\n"
4235 EXPECT_EQ("//Lorem ipsum dolor\n"
4236 "//sit amet\n"
4237 "\n"
4238 "//Lorem ipsum\n"
4239 "//dolor sit amet\n"
4240 "\n"
4241 "void f() { //Hello\n"
4242 " //World\n"
4247 EXPECT_EQ("// Lorem ipsum dolor\n"
4248 "// sit amet\n"
4249 "\n"
4250 "// Lorem ipsum\n"
4251 "// dolor sit amet\n"
4252 "\n"
4253 "void f() { // Hello\n"
4254 " // World\n"
4257 EXPECT_EQ("// x\n"
4259 format("// x\n"
4263 "// loooooooooooooooooooooooooooooong\n"
4264 "// commentcomments\n"
4266 format("// loooooooooooooooooooooooooooooong commentcomments\n"
4271 EXPECT_EQ("// Lorem ipsum\n"
4272 "// dolor sit amet\n"
4273 "\n"
4274 "// Lorem ipsum\n"
4275 "// dolor sit\n"
4276 "// amet\n"
4277 "\n"
4278 "void f() { // Hello\n"
4279 " // World\n"
4285 "than the ColumnLimit, what now?\n"
4286 "\n"
4287 "// Comment\n"
4288 "\n"
4290 "lines, please. Thank you very much!\n"
4291 "\n"
4292 "// A comment with\n"
4293 "// some indentation that has to be split.\n"
4296 "than the ColumnLimit, what now?\n"
4297 "\n"
4298 "// Comment\n"
4299 "\n"
4300 "// This is a text to\n"
4301 "// split in multiple\n"
4302 "// lines, please.\n"
4303 "// Thank you very\n"
4304 "// much!\n"
4305 "\n"
4306 "// A comment with\n"
4307 "// some\n"
4308 "// indentation\n"
4309 "// that has to be\n"
4310 "// split.\n"
4315 EXPECT_EQ("//This are more\n"
4316 "//spaces than the\n"
4317 "//ColumnLimit, what\n"
4318 "//now?\n"
4319 "\n"
4320 "//Comment\n"
4321 "\n"
4322 "//This is a text to\n"
4323 "//split in multiple\n"
4324 "//lines, please.\n"
4325 "//Thank you very\n"
4326 "//much!\n"
4327 "\n"
4328 "//A comment with\n"
4329 "// some indentation\n"
4330 "// that has to be\n"
4331 "// split.\n"
4336 EXPECT_EQ("// This are more\n"
4337 "// spaces than the\n"
4338 "// ColumnLimit,\n"
4339 "// what now?\n"
4340 "\n"
4341 "// Comment\n"
4342 "\n"
4343 "// This is a text\n"
4344 "// to split in\n"
4345 "// multiple lines,\n"
4346 "// please. Thank\n"
4347 "// you very much!\n"
4348 "\n"
4349 "// A comment with\n"
4350 "// some\n"
4351 "// indentation\n"
4352 "// that has to\n"
4353 "// be split.\n"
4359 "ColumnLimit, what now?\n"
4360 "\n"
4361 "// Comment\n"
4362 "\n"
4364 "multiple lines, please. Thank you very much!\n"
4365 "\n"
4366 "// A comment with\n"
4368 "split.\n"
4373 EXPECT_EQ("// A Comment to be\n"
4374 "// moved\n"
4375 "// with indent\n"
4376 "\n"
4377 "// A Comment to be\n"
4378 "// moved\n"
4379 "// with indent\n"
4380 "\n"
4381 "// A Comment to be\n"
4382 "// moved\n"
4383 "// with indent\n"
4384 "\n"
4385 "// A Comment to be\n"
4386 "// moved\n"
4387 "// with indent\n"
4388 "\n"
4389 "// A Comment to\n"
4390 "// be moved\n"
4391 "// with indent\n"
4392 "\n"
4393 "// A Comment to\n"
4394 "// be moved\n"
4395 "// with indent\n"
4396 "\n"
4397 "// A Comment to\n"
4398 "// be moved\n"
4400 format("//A Comment to be moved\n"
4401 "// with indent\n"
4402 "\n"
4403 "// A Comment to be moved\n"
4404 "// with indent\n"
4405 "\n"
4406 "// A Comment to be moved\n"
4407 "// with indent\n"
4408 "\n"
4409 "// A Comment to be moved\n"
4410 "// with indent\n"
4411 "\n"
4412 "// A Comment to be moved\n"
4413 "// with indent\n"
4414 "\n"
4415 "// A Comment to be moved\n"
4416 "// with indent\n"
4417 "\n"
4418 "// A Comment to be moved\n"
4423 EXPECT_EQ("int i; // A Comment to be\n"
4424 " // moved\n"
4425 " // with indent\n"
4426 "\n"
4427 "int i; // A Comment to be\n"
4428 " // moved\n"
4429 " // with indent\n"
4430 "\n"
4431 "int i; // A Comment to be\n"
4432 " // moved\n"
4433 " // with indent\n"
4434 "\n"
4435 "int i; // A Comment to be\n"
4436 " // moved\n"
4437 " // with indent\n"
4438 "\n"
4439 "int i; // A Comment to be\n"
4440 " // moved\n"
4441 " // with indent\n"
4442 "\n"
4443 "int i; // A Comment to be\n"
4444 " // moved\n"
4445 " // with indent\n"
4446 "\n"
4447 "int i; // A Comment to be\n"
4448 " // moved\n"
4450 format("int i;//A Comment to be moved\n"
4451 " // with indent\n"
4452 "\n"
4453 "int i;// A Comment to be moved\n"
4454 " // with indent\n"
4455 "\n"
4456 "int i;// A Comment to be moved\n"
4457 " // with indent\n"
4458 "\n"
4459 "int i;// A Comment to be moved\n"
4460 " // with indent\n"
4461 "\n"
4462 "int i;// A Comment to be moved\n"
4463 " // with indent\n"
4464 "\n"
4465 "int i;// A Comment to be moved\n"
4466 " // with indent\n"
4467 "\n"
4468 "int i;// A Comment to be moved\n"
4473 EXPECT_EQ("// Free comment without space\n"
4474 "\n"
4475 "// Free comment with 3 spaces\n"
4476 "\n"
4477 "/// Free Doxygen without space\n"
4478 "\n"
4479 "/// Free Doxygen with 3 spaces\n"
4480 "\n"
4481 "// ? A nice dragon\n"
4482 "\n"
4483 "//\t abccba\n"
4484 "\n"
4485 "//\\t deffed\n"
4486 "\n"
4487 "// ? Another nice dragon\n"
4488 "\n"
4489 "// \t Three leading spaces following tab\n"
4490 "\n"
4491 "// \\t Three leading spaces following backslash\n"
4492 "\n"
4493 "/// A Doxygen Comment with a nested list:\n"
4494 "/// - Foo\n"
4495 "/// - Bar\n"
4496 "/// - Baz\n"
4497 "/// - End\n"
4498 "/// of the inner list\n"
4499 "/// .\n"
4500 "/// .\n"
4501 "\n"
4502 "namespace Foo {\n"
4503 "bool bar(bool b) {\n"
4504 " bool ret1 = true; ///< Doxygenstyle without space\n"
4505 " bool ret2 = true; ///< Doxygenstyle with 3 spaces\n"
4506 " if (b) {\n"
4507 " // Foo\n"
4508 "\n"
4509 " // In function comment\n"
4510 " ret2 = false;\n"
4511 " } // End of if\n"
4512 "\n"
4513 " // if (ret1) {\n"
4514 " // return ret2;\n"
4515 " // }\n"
4516 "\n"
4517 " // if (ret1) {\n"
4518 " // return ret2;\n"
4519 " // }\n"
4520 "\n"
4521 " return ret1 && ret2;\n"
4522 "}\n"
4523 "} // namespace Foo\n"
4524 "\n"
4525 "namespace Bar {\n"
4526 "int foo();\n"
4527 "} // namespace Bar\n"
4528 "//@Nothing added because of the non ascii char\n"
4529 "\n"
4530 "//@ Nothing removed because of the non ascii char\n"
4531 "\n"
4532 "// Comment to move to the left\n"
4533 "// But not this?\n"
4534 "// @but this\n"
4535 "\n"
4536 "// Comment to move to the right\n"
4537 "//@ this stays\n"
4538 "\n"
4539 "//} will not move\n"
4540 "\n"
4541 "// vv will only move\n"
4546 EXPECT_EQ("//Free comment without space\n"
4547 "\n"
4548 "//Free comment with 3 spaces\n"
4549 "\n"
4550 "///Free Doxygen without space\n"
4551 "\n"
4552 "///Free Doxygen with 3 spaces\n"
4553 "\n"
4554 "//? A nice dragon\n"
4555 "\n"
4556 "//\t abccba\n"
4557 "\n"
4558 "//\\t deffed\n"
4559 "\n"
4560 "//? Another nice dragon\n"
4561 "\n"
4562 "//\t Three leading spaces following tab\n"
4563 "\n"
4564 "//\\t Three leading spaces following backslash\n"
4565 "\n"
4566 "///A Doxygen Comment with a nested list:\n"
4567 "///- Foo\n"
4568 "///- Bar\n"
4569 "/// - Baz\n" // Here we keep the relative indentation
4570 "/// - End\n"
4571 "/// of the inner list\n"
4572 "/// .\n"
4573 "///.\n"
4574 "\n"
4575 "namespace Foo {\n"
4576 "bool bar(bool b) {\n"
4577 " bool ret1 = true; ///<Doxygenstyle without space\n"
4578 " bool ret2 = true; ///<Doxygenstyle with 3 spaces\n"
4579 " if (b) {\n"
4580 " //Foo\n"
4581 "\n"
4582 " //In function comment\n"
4583 " ret2 = false;\n"
4584 " } //End of if\n"
4585 "\n"
4586 " //if (ret1) {\n"
4587 " // return ret2;\n"
4588 " //}\n"
4589 "\n"
4590 " //if (ret1) {\n"
4591 " // return ret2;\n"
4592 " //}\n"
4593 "\n"
4594 " return ret1 && ret2;\n"
4595 "}\n"
4596 "} //namespace Foo\n"
4597 "\n"
4598 "namespace Bar {\n"
4599 "int foo();\n"
4600 "} //namespace Bar\n"
4601 "//@Nothing added because of the non ascii char\n"
4602 "\n"
4603 "//@ Nothing removed because of the non ascii char\n"
4604 "\n"
4605 "//Comment to move to the left\n"
4606 "//But not this?\n"
4607 "//@but this\n"
4608 "\n"
4609 "//Comment to move to the right\n"
4610 "//@ this stays\n"
4611 "\n"
4612 "//} will not move\n"
4613 "\n"
4614 "//vv will only move\n"
4619 EXPECT_EQ("// Free comment without space\n"
4620 "\n"
4621 "// Free comment with 3 spaces\n"
4622 "\n"
4623 "/// Free Doxygen without space\n"
4624 "\n"
4625 "/// Free Doxygen with 3 spaces\n"
4626 "\n"
4627 "// ? A nice dragon\n"
4628 "\n"
4629 "//\t abccba\n"
4630 "\n"
4631 "//\\t deffed\n"
4632 "\n"
4633 "// ? Another nice dragon\n"
4634 "\n"
4635 "// \t Three leading spaces following tab\n"
4636 "\n"
4637 "// \\t Three leading spaces following backslash\n"
4638 "\n"
4639 "/// A Doxygen Comment with a nested list:\n"
4640 "/// - Foo\n"
4641 "/// - Bar\n"
4642 "/// - Baz\n"
4643 "/// - End\n"
4644 "/// of the inner list\n"
4645 "/// .\n"
4646 "/// .\n"
4647 "\n"
4648 "namespace Foo {\n"
4649 "bool bar(bool b) {\n"
4650 " bool ret1 = true; ///< Doxygenstyle without space\n"
4651 " bool ret2 = true; ///< Doxygenstyle with 3 spaces\n"
4652 " if (b) {\n"
4653 " // Foo\n"
4654 "\n"
4655 " // In function comment\n"
4656 " ret2 = false;\n"
4657 " } // End of if\n"
4658 "\n"
4659 " // if (ret1) {\n"
4660 " // return ret2;\n"
4661 " // }\n"
4662 "\n"
4663 " // if (ret1) {\n"
4664 " // return ret2;\n"
4665 " // }\n"
4666 "\n"
4667 " return ret1 && ret2;\n"
4668 "}\n"
4669 "} // namespace Foo\n"
4670 "\n"
4671 "namespace Bar {\n"
4672 "int foo();\n"
4673 "} // namespace Bar\n"
4674 "//@Nothing added because of the non ascii char\n"
4675 "\n"
4676 "//@ Nothing removed because of the non ascii char\n"
4677 "\n"
4678 "// Comment to move to the left\n"
4679 "// But not this?\n"
4680 "// @but this\n"
4681 "\n"
4682 "// Comment to move to the right\n"
4683 "//@ this stays\n"
4684 "\n"
4685 "//} will not move\n"
4686 "\n"
4687 "// vv will only move\n"