blob: e8648d382ce216b7566e3c96f905f73660c887f7 [file] [log] [blame]
Bram Moolenaar071d4272004-06-13 20:20:40 +00001/* vim: set cin ts=4 sw=4 : */
2
3Test for 'cindent'
4
5STARTTEST
6:so small.vim
Bram Moolenaar8c8de832008-06-24 22:58:06 +00007:set nocompatible viminfo+=nviminfo modeline
Bram Moolenaar071d4272004-06-13 20:20:40 +00008:edit " read modeline
9/start of AUTO
10=/end of AUTO
11ENDTEST
12
Bram Moolenaar9e54a0e2006-04-14 20:42:25 +000013/* start of AUTO matically checked vim: set ts=4 : */
Bram Moolenaar071d4272004-06-13 20:20:40 +000014{
15 if (test)
16 cmd1;
17 cmd2;
18}
19
20{
21 if (test)
22 cmd1;
23 else
24 cmd2;
25}
26
27{
28 if (test)
29 {
30 cmd1;
31 cmd2;
32 }
33}
34
35{
36 if (test)
37 {
38 cmd1;
39 else
40 }
41}
42
43{
44 while (this)
45 if (test)
46 cmd1;
47 cmd2;
48}
49
50{
51 while (this)
52 if (test)
53 cmd1;
54 else
55 cmd2;
56}
57
58{
59 if (test)
60 {
61 cmd;
62 }
63
64 if (test)
65 cmd;
66}
67
68{
69 if (test) {
70 cmd;
71 }
72
73 if (test) cmd;
74}
75
76{
77 cmd1;
78 for (blah)
79 while (this)
80 if (test)
81 cmd2;
82 cmd3;
83}
84
85{
86 cmd1;
87 for (blah)
88 while (this)
89 if (test)
90 cmd2;
91 cmd3;
92
93 if (test)
94 {
95 cmd1;
96 cmd2;
97 cmd3;
98 }
99}
100
101
102/* Test for 'cindent' do/while mixed with if/else: */
103
104{
105 do
106 if (asdf)
107 asdfasd;
108 while (cond);
109
110 do
111 if (asdf)
112 while (asdf)
113 asdf;
114 while (asdf);
115}
116
117/* Test for 'cindent' with two ) on a continuation line */
118{
119 if (asdfasdf;asldkfj asdlkfj as;ldkfj sal;d
120 aal;sdkjf ( ;asldfkja;sldfk
121 al;sdjfka ;slkdf ) sa;ldkjfsa dlk;)
122 line up here;
123}
124
125
126/* C++ tests: */
127
128// foo() these three lines should remain in column 0
129// {
130// }
131
132/* Test for continuation and unterminated lines: */
133{
134 i = 99 + 14325 +
135 21345 +
136 21345 +
137 21345 + ( 21345 +
138 21345) +
139 2345 +
140 1234;
141 c = 1;
142}
143
144/*
145 testje for indent with empty line
146
147 here */
148
149{
150 if (testing &&
151 not a joke ||
152 line up here)
153 hay;
154 if (testing &&
155 (not a joke || testing
156 )line up here)
157 hay;
158 if (testing &&
159 (not a joke || testing
160 line up here))
161 hay;
162}
163
164
165{
166 switch (c)
167 {
168 case xx:
169 do
170 if (asdf)
171 do
172 asdfasdf;
173 while (asdf);
174 else
175 asdfasdf;
176 while (cond);
177 case yy:
178 case xx:
179 case zz:
180 testing;
181 }
182}
183
184{
185 if (cond) {
186 foo;
187 }
188 else
189 {
190 bar;
191 }
192}
193
194{
195 if (alskdfj ;alsdkfjal;skdjf (;sadlkfsa ;dlkf j;alksdfj ;alskdjf
196 alsdkfj (asldk;fj
197 awith cino=(0 ;lf this one goes to below the paren with ==
198 ;laksjfd ;lsakdjf ;alskdf asd)
199 asdfasdf;)))
200 asdfasdf;
201}
202
203 int
204func(a, b)
205 int a;
206 int c;
207{
208 if (c1 && (c2 ||
209 c3))
210 foo;
211 if (c1 &&
212 (c2 || c3)
213 )
214}
215
216{
217 while (asd)
218 {
219 if (asdf)
220 if (test)
221 if (that)
222 {
223 if (asdf)
224 do
225 cdasd;
226 while (as
227 df);
228 }
229 else
230 if (asdf)
231 asdf;
232 else
233 asdf;
234 asdf;
235 }
236}
237
238{
239 s = "/*"; b = ';'
240 s = "/*"; b = ';';
241 a = b;
242}
243
244{
245 switch (a)
246 {
247 case a:
248 switch (t)
249 {
250 case 1:
251 cmd;
252 break;
253 case 2:
254 cmd;
255 break;
256 }
257 cmd;
258 break;
259 case b:
260 {
261 int i;
262 cmd;
263 }
264 break;
265 case c: {
266 int i;
267 cmd;
268 }
269 case d: if (cond &&
270 test) { /* this line doesn't work right */
271 int i;
272 cmd;
273 }
274 break;
275 }
276}
277
278{
279 if (!(vim_strchr(p_cpo, CPO_BUFOPTGLOB) != NULL && entering) &&
280 (bp_to->b_p_initialized ||
281 (!entering && vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
282 return;
283label :
284 asdf = asdf ?
285 asdf : asdf;
286 asdf = asdf ?
287 asdf: asdf;
288}
289
290/* Special Comments : This function has the added complexity (compared */
291/* : to addtolist) of having to check for a detail */
292/* : texture and add that to the list first. */
293
294char *(array[100]) = {
295 "testje",
296 "foo",
297 "bar",
298}
299
300enum soppie
301{
Bram Moolenaara5285652011-12-14 20:05:21 +0100302yes = 0,
303no,
304maybe
Bram Moolenaar071d4272004-06-13 20:20:40 +0000305};
306
307typedef enum soppie
308{
Bram Moolenaara5285652011-12-14 20:05:21 +0100309yes = 0,
310no,
311maybe
Bram Moolenaar071d4272004-06-13 20:20:40 +0000312};
313
Bram Moolenaara5285652011-12-14 20:05:21 +0100314static enum
315{
316yes = 0,
317no,
318maybe
319} soppie;
320
Bram Moolenaard999db22013-03-07 13:21:32 +0100321public static enum
322{
323yes = 0,
324no,
325maybe
326} soppie;
327
328static private enum
329{
330yes = 0,
331no,
332maybe
333} soppie;
334
Bram Moolenaar071d4272004-06-13 20:20:40 +0000335{
336 int a,
337 b;
338}
339
340{
341 struct Type
342 {
343 int i;
344 char *str;
345 } var[] =
346 {
347 0, "zero",
348 1, "one",
349 2, "two",
350 3, "three"
351 };
352
353 float matrix[3][3] =
354 {
355 {
356 0,
357 1,
358 2
359 },
360 {
361 3,
362 4,
363 5
364 },
365 {
366 6,
367 7,
368 8
369 }
370 };
371}
372
373{
374 /* blah ( blah */
375 /* where does this go? */
376
377 /* blah ( blah */
378 cmd;
379
380 func(arg1,
381 /* comment */
382 arg2);
383 a;
384 {
385 b;
386 {
387 c; /* Hey, NOW it indents?! */
388 }
389 }
390
391 {
392 func(arg1,
393 arg2,
394 arg3);
395 /* Hey, what am I doing here? Is this coz of the ","? */
396 }
397}
398
399main ()
400{
401 if (cond)
402 {
403 a = b;
404 }
405 if (cond) {
406 a = c;
407 }
408 if (cond)
409 a = d;
410 return;
411}
412
413{
414 case 2: if (asdf &&
415 asdfasdf)
416 aasdf;
417 a = 9;
418 case 3: if (asdf)
419 aasdf;
420 a = 9;
421 case 4: x = 1;
422 y = 2;
423
424label: if (asdf)
425 here;
426
427label: if (asdf &&
428 asdfasdf)
429 {
430 }
431
432label: if (asdf &&
433 asdfasdf) {
434 there;
435 }
436
437label: if (asdf &&
438 asdfasdf)
439 there;
440}
441
442{
443 /*
444 hello with ":set comments= cino=c5"
445 */
446
447 /*
448 hello with ":set comments= cino="
449 */
450}
451
452
453{
454 if (a < b) {
455 a = a + 1;
456 } else
457 a = a + 2;
458
459 if (a)
460 do {
461 testing;
462 } while (asdfasdf);
463 a = b + 1;
464 asdfasdf
465}
466
Bram Moolenaar04d17ae2014-08-06 17:44:14 +0200467{
468for ( int i = 0;
469 i < 10; i++ )
470{
471}
472 i = 0;
473}
474
Bram Moolenaar071d4272004-06-13 20:20:40 +0000475class bob
476{
477 int foo() {return 1;}
478 int bar;
479}
480
481main()
482{
483while(1)
484if (foo)
485{
486bar;
487}
488else {
489asdf;
490}
491misplacedline;
492}
493
494{
495 if (clipboard.state == SELECT_DONE
496 && ((row == clipboard.start.lnum
497 && col >= clipboard.start.col)
498 || row > clipboard.start.lnum))
499}
500
501{
502if (1) {i += 4;}
503where_am_i;
504return 0;
505}
506
507{
508{
509} // sdf(asdf
510if (asdf)
511asd;
512}
513
514{
515label1:
516label2:
517}
518
519{
520int fooRet = foo(pBar1, false /*fKB*/,
521 true /*fPTB*/, 3 /*nT*/, false /*fDF*/);
522f() {
523for ( i = 0;
524 i < m;
525 /* c */ i++ ) {
526a = b;
527}
528}
529}
530
531{
532 f1(/*comment*/);
533 f2();
534}
535
536{
537do {
538if (foo) {
539} else
540;
541} while (foo);
542foo(); // was wrong
543}
544
545int x; // no extra indent because of the ;
546void func()
547{
548}
549
550char *tab[] = {"aaa",
551 "};", /* }; */ NULL}
552 int indented;
553{}
554
555char *a[] = {"aaa", "bbb",
556 "ccc", NULL};
557// here
558
559char *tab[] = {"aaa",
560 "xx", /* xx */}; /* asdf */
561int not_indented;
562
563{
564 do {
565 switch (bla)
566 {
567 case 1: if (foo)
568 bar;
569 }
570 } while (boo);
571 wrong;
572}
573
574int foo,
575 bar;
576int foo;
577
578#if defined(foo) \
579 && defined(bar)
580char * xx = "asdf\
581 foo\
582 bor";
583int x;
584
585char *foo = "asdf\
586 asdf\
587 asdf",
588 *bar;
589
590void f()
591{
592#if defined(foo) \
593 && defined(bar)
594char *foo = "asdf\
595 asdf\
596 asdf",
597 *bar;
598 {
599 int i;
600char *foo = "asdf\
601 asdf\
602 asdf",
603 *bar;
604 }
605#endif
606}
607#endif
608
609int y; // comment
610 // comment
611
612 // comment
613
614{
615 Constructor(int a,
616 int b ) : BaseClass(a)
617 {
618 }
619}
620
621void foo()
622{
623 char one,
624 two;
625 struct bla piet,
626 jan;
627 enum foo kees,
628 jannie;
629 static unsigned sdf,
630 krap;
631 unsigned int piet,
632 jan;
633 int
634 kees,
635 jan;
636}
637
638{
639 t(int f,
640 int d); // )
641 d();
642}
643
644Constructor::Constructor(int a,
645 int b
646 ) :
647 BaseClass(a,
648 b,
649 c),
650 mMember(b),
651{
652}
653
654Constructor::Constructor(int a,
655 int b ) :
656 BaseClass(a)
657{
658}
659
660Constructor::Constructor(int a,
661 int b ) /*x*/ : /*x*/ BaseClass(a),
662 member(b)
663{
664}
665
Bram Moolenaare01f4f82015-11-10 14:06:53 +0100666A::A(int a, int b)
667: aa(a),
668bb(b),
669cc(c)
670{
671}
672
Bram Moolenaar071d4272004-06-13 20:20:40 +0000673class CAbc :
674 public BaseClass1,
675 protected BaseClass2
676{
677 int Test() { return FALSE; }
678 int Test1() { return TRUE; }
679
680 CAbc(int a, int b ) :
681 BaseClass(a)
682 {
683 switch(xxx)
684 {
685 case abc:
686 asdf();
687 break;
688
689 case 999:
690 baer();
691 break;
692 }
693 }
694
695public: // <-- this was incoreectly indented before!!
696 void testfall();
697protected:
698 void testfall();
699};
700
701class CAbc : public BaseClass1,
702 protected BaseClass2
703{
704};
705
706static struct
707{
708 int a;
709 int b;
710} variable[COUNT] =
711{
712 {
713 123,
714 456
715 },
716 {
717 123,
718 456
719 }
720};
721
722static struct
723{
724 int a;
725 int b;
726} variable[COUNT] =
727{
728 { 123, 456 },
729 { 123, 456 }
730};
731
732void asdf() /* ind_maxparen may cause trouble here */
733{
734 if ((0
735 && 1
736 && 1
737 && 1
738 && 1
739 && 1
740 && 1
741 && 1
742 && 1
743 && 1
744 && 1
745 && 1
746 && 1
747 && 1
748 && 1
749 && 1
750 && 1
751 && 1
752 && 1
753 && 1
754 && 1
755 && 1
756 && 1
757 && 1
758 && 1
759 && 1)) break;
760}
761
Bram Moolenaar18144c82006-04-12 21:52:12 +0000762foo()
763{
764 a = cond ? foo() : asdf
765 + asdf;
766
767 a = cond ?
768 foo() : asdf
769 + asdf;
770}
771
772int main(void)
773{
774 if (a)
775 if (b)
776 2;
777 else 3;
778 next_line_of_code();
779}
780
Bram Moolenaar7fc904b2006-04-13 20:37:35 +0000781barry()
782{
783 Foo::Foo (int one,
784 int two)
785 : something(4)
786 {}
787}
788
789barry()
790{
791 Foo::Foo (int one, int two)
792 : something(4)
793 {}
794}
795
796Constructor::Constructor(int a,
797 int b
798 ) :
799 BaseClass(a,
800 b,
801 c),
802 mMember(b)
803{
804}
Bram Moolenaar9e54a0e2006-04-14 20:42:25 +0000805 int main ()
806 {
807 if (lala)
808 do
809 ++(*lolo);
810 while (lili
811 && lele);
812 lulu;
813 }
Bram Moolenaar7fc904b2006-04-13 20:37:35 +0000814
Bram Moolenaar9e54a0e2006-04-14 20:42:25 +0000815int main ()
816{
817switch (c)
818{
819case 'c': if (cond)
820{
821}
822}
823}
824
825main()
826{
827 (void) MyFancyFuasdfadsfnction(
828 argument);
829}
830
831main()
832{
833 char foo[] = "/*";
834 /* as
835 df */
836 hello
837}
Bram Moolenaared38b0a2011-05-25 15:16:18 +0200838
839/* valid namespaces with normal indent */
840namespace
841{
842{
843 111111111111;
844}
845}
846namespace /* test */
847{
848 11111111111111111;
849}
850namespace // test
851{
852 111111111111111111;
853}
854namespace
855{
856 111111111111111111;
857}
858namespace test
859{
860 111111111111111111;
861}
862namespace{
863 111111111111111111;
864}
865namespace test{
866 111111111111111111;
867}
868namespace {
869 111111111111111111;
870}
871namespace test {
872 111111111111111111;
873namespace test2 {
874 22222222222222222;
875}
876}
877
878/* invalid namespaces use block indent */
879namespace test test2 {
880 111111111111111111111;
881}
882namespace11111111111 {
883 111111111111;
884}
885namespace() {
886 1111111111111;
887}
888namespace()
889{
890 111111111111111111;
891}
892namespace test test2
893{
894 1111111111111111111;
895}
896namespace111111111
897{
898 111111111111111111;
899}
900
Bram Moolenaarf7bb86d2015-07-28 21:17:36 +0200901void getstring() {
902/* Raw strings */
903const char* s = R"(
904 test {
905 # comment
906 field: 123
907 }
908 )";
909 }
910
911void getstring() {
912const char* s = R"foo(
913 test {
914 # comment
915 field: 123
916 }
917 )foo";
918 }
919
Bram Moolenaar089af182015-10-07 11:41:49 +0200920{
921int a[4] = {
922[0] = 0,
923[1] = 1,
924[2] = 2,
925[3] = 3,
926};
927}
928
929{
930a = b[2]
931+ 3;
932}
933
934{
935if (1)
936/* aaaaa
937* bbbbb
938*/
939a = 1;
940}
941
Bram Moolenaard1b15de2015-10-13 16:13:39 +0200942void func()
943{
944switch (foo)
945{
946case (bar):
947if (baz())
948quux();
949break;
950case (shmoo):
951if (!bar)
952{
953}
954case (foo1):
955switch (bar)
956{
957case baz:
958baz_f();
959break;
960}
961break;
962default:
963baz();
964baz();
965break;
966}
967}
968
Bram Moolenaar071d4272004-06-13 20:20:40 +0000969/* end of AUTO */
970
971STARTTEST
972:set tw=0 wm=60 columns=80 noai fo=croq
973/serious/e
974a about life, the universe, and the rest
975ENDTEST
976
977{
978
979/* this is
980 * a real serious important big
981 * comment
982 */
983 /* insert " about life, the universe, and the rest" after "serious" */
984}
985
986STARTTEST
987:set nocin
988/comments
989joabout life/happens
990jothere/below
991oline/this
992Ohello
993ENDTEST
994
995{
996 /*
997 * Testing for comments, without 'cin' set
998 */
999
1000/*
1001* what happens here?
1002*/
1003
1004 /*
1005 the end of the comment, try inserting a line below */
1006
1007 /* how about
1008 this one */
1009}
1010
1011STARTTEST
1012:set cin
1013/vec2
1014==
1015ENDTEST
1016
1017{
1018 var = this + that + vec[0] * vec[0]
1019 + vec[1] * vec[1]
1020 + vec2[2] * vec[2];
1021}
1022
1023STARTTEST
1024:set cin
1025:set cino=}4
1026/testing1
1027k2==/testing2
1028k2==
1029ENDTEST
1030
1031{
1032 asdf asdflkajds f;
1033 if (tes & ting) {
1034 asdf asdf asdf ;
1035 asdfa sdf asdf;
1036 }
1037 testing1;
1038 if (tes & ting)
1039 {
1040 asdf asdf asdf ;
1041 asdfa sdf asdf;
1042 }
1043 testing2;
1044}
1045
1046STARTTEST
1047:set cin
1048:set cino=(0,)20
1049/main
1050=][
1051ENDTEST
1052
1053main ( int first_par, /*
1054 * Comment for
1055 * first par
1056 */
1057 int second_par /*
1058 * Comment for
1059 * second par
1060 */
1061 )
1062{
1063 func( first_par, /*
1064 * Comment for
1065 * first par
1066 */
1067 second_par /*
1068 * Comment for
1069 * second par
1070 */
1071 );
1072
1073}
1074
1075STARTTEST
1076:set cin
Bram Moolenaar48d27922012-06-13 13:40:48 +02001077:set cino=es,n0s
1078/main
1079=][
1080ENDTEST
1081
1082main(void)
1083{
1084 /* Make sure that cino=X0s is not parsed like cino=Xs. */
1085 if (cond)
1086 foo();
1087 else
1088 {
1089 bar();
1090 }
1091}
1092
1093STARTTEST
1094:set cin
Bram Moolenaar071d4272004-06-13 20:20:40 +00001095:set cino=
1096]]=][
1097ENDTEST
1098
1099{
1100 do
1101 {
1102 if ()
1103 {
1104 if ()
1105 asdf;
1106 else
1107 asdf;
1108 }
1109 } while ();
1110 cmd; /* this should go under the } */
1111}
1112
1113STARTTEST
1114]]=][
1115ENDTEST
1116
1117void f()
1118{
1119 if ( k() ) {
1120 l();
1121
1122 } else { /* Start (two words) end */
1123 m();
1124 }
1125
1126 n();
1127}
1128
1129STARTTEST
1130:set cino={s,e-s
1131]]=][
1132ENDTEST
1133
1134void f()
1135{
1136 if ( k() )
1137 {
1138 l();
1139 } else { /* Start (two words) end */
1140 m();
1141 }
1142 n(); /* should be under the if () */
1143}
1144
1145STARTTEST
1146:set cino={s,fs
1147]]=/ foo
1148ENDTEST
1149
1150void bar(void)
1151{
1152 static array[2][2] =
1153 {
1154 { 1, 2 },
1155 { 3, 4 },
1156 }
1157
1158 while (a)
1159 {
1160 foo(&a);
1161 }
1162
1163 {
1164 int a;
1165 {
1166 a = a + 1;
1167 }
1168 }
1169 b = a;
1170 }
1171
1172void func(void)
1173 {
1174 a = 1;
1175 {
1176 b = 2;
1177 }
1178 c = 3;
1179 d = 4;
1180 }
1181/* foo */
1182
1183STARTTEST
1184:set cino=
1185/while
1186ohere
1187ENDTEST
1188
1189a()
1190{
1191 do {
1192 a = a +
1193 a;
1194 } while ( a ); /* add text under this line */
1195 if ( a )
1196 a;
1197}
1198
1199STARTTEST
1200:set cino= com=
1201/comment
1202olabel2: b(); label3 /* post */: /* pre */ label4: f(/*com*/); if (/*com*/) cmd();
1203ENDTEST
1204
1205a()
1206{
1207label1:
1208 /* hmm */
1209 // comment
1210}
1211
1212STARTTEST
1213:set comments& comments^=s:/*,m:**,ex:*/
1214/simple
1215=5j
1216ENDTEST
1217
1218/*
1219 * A simple comment
1220 */
1221
1222/*
1223 ** A different comment
1224 */
1225
1226STARTTEST
1227:set cino=c0
1228:set comments& comments-=s1:/* comments^=s0:/*
12292kdd]]=][
1230ENDTEST
1231
1232void f()
1233{
1234
1235 /*********
1236 A comment.
1237*********/
1238}
1239
1240STARTTEST
1241:set cino=c0,C1
1242:set comments& comments-=s1:/* comments^=s0:/*
12432kdd]]=][
1244ENDTEST
1245
1246void f()
1247{
1248
1249 /*********
1250 A comment.
1251*********/
1252}
1253
1254STARTTEST
1255:set cino=
1256]]=][
1257ENDTEST
1258
1259void f()
1260{
1261 c = c1 &&
1262 (
1263 c2 ||
1264 c3
1265 ) && c4;
1266}
1267
1268STARTTEST
1269:set cino=(s
12702kdd]]=][
1271ENDTEST
1272
1273void f()
1274{
1275 c = c1 &&
1276 (
1277 c2 ||
1278 c3
1279 ) && c4;
1280}
1281
1282STARTTEST
1283:set cino=(s,U1
12842kdd]]=][
1285ENDTEST
1286
1287void f()
1288{
1289 c = c1 &&
1290 (
1291 c2 ||
1292 c3
1293 ) && c4;
1294}
1295
1296STARTTEST
1297:set cino=(0
12982kdd]]=][
1299ENDTEST
1300
1301void f()
1302{
1303 if ( c1
1304 && ( c2
1305 || c3))
1306 foo;
1307}
1308
1309STARTTEST
1310:set cino=(0,w1
13112kdd]]=][
1312ENDTEST
1313
1314void f()
1315{
1316 if ( c1
1317 && ( c2
1318 || c3))
1319 foo;
1320}
1321
1322STARTTEST
1323:set cino=(s
13242kdd]]=][
1325ENDTEST
1326
1327void f()
1328{
1329 c = c1 && (
1330 c2 ||
1331 c3
1332 ) && c4;
1333 if (
1334 c1 && c2
1335 )
1336 foo;
1337}
1338
1339STARTTEST
1340:set cino=(s,m1
13412kdd]]=][
1342ENDTEST
1343
1344void f()
1345{
1346 c = c1 && (
1347 c2 ||
1348 c3
1349 ) && c4;
1350 if (
1351 c1 && c2
1352 )
1353 foo;
1354}
1355
1356STARTTEST
1357:set cino=b1
13582kdd]]=][
1359ENDTEST
1360
1361void f()
1362{
1363 switch (x)
1364 {
1365 case 1:
1366 a = b;
1367 break;
1368 default:
1369 a = 0;
1370 break;
1371 }
1372}
1373
1374STARTTEST
1375:set cino=(0,W5
13762kdd]]=][
1377ENDTEST
1378
1379void f()
1380{
1381 invokeme(
1382 argu,
1383 ment);
1384 invokeme(
1385 argu,
1386 ment
1387 );
1388 invokeme(argu,
1389 ment
1390 );
1391}
1392
1393STARTTEST
1394:set cino=/6
13952kdd]]=][
1396ENDTEST
1397
1398void f()
1399{
1400 statement;
1401 // comment 1
1402 // comment 2
1403}
1404
1405STARTTEST
1406:set cino=
14072kdd]]/comment 1/+1
1408==
1409ENDTEST
1410
1411void f()
1412{
1413 statement;
1414 // comment 1
1415 // comment 2
1416}
1417
1418STARTTEST
1419:set cino=g0
14202kdd]]=][
1421ENDTEST
1422
1423class CAbc
1424{
1425 int Test() { return FALSE; }
1426
1427public: // comment
1428 void testfall();
1429protected:
1430 void testfall();
1431};
1432
1433STARTTEST
Bram Moolenaare79d1532011-10-04 18:03:47 +02001434:set cino=(0,gs,hs
14352kdd]]=][
1436ENDTEST
1437
1438class Foo : public Bar
1439{
1440public:
1441virtual void method1(void) = 0;
1442virtual void method2(int arg1,
1443int arg2,
1444int arg3) = 0;
1445};
1446
1447STARTTEST
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00001448:set cino=+20
14492kdd]]=][
1450ENDTEST
1451
1452 void
1453foo()
1454{
1455 if (a)
1456 {
1457 } else
1458 asdf;
1459}
1460
1461STARTTEST
Bram Moolenaar071d4272004-06-13 20:20:40 +00001462:set cino=(0,W2s
14632kdd]]=][
1464ENDTEST
1465
1466{
1467 averylongfunctionnamelongfunctionnameaverylongfunctionname()->asd(
1468 asdasdf,
1469 func(asdf,
1470 asdfadsf),
1471 asdfasdf
1472 );
1473
1474 /* those are ugly, but consequent */
1475
1476 func()->asd(asdasdf,
1477 averylongfunctionname(
1478 abc,
1479 dec)->averylongfunctionname(
1480 asdfadsf,
1481 asdfasdf,
1482 asdfasdf,
1483 ),
1484 func(asdfadf,
1485 asdfasdf
1486 ),
1487 asdasdf
1488 );
1489
1490 averylongfunctionnameaverylongfunctionnameavery()->asd(fasdf(
1491 abc,
1492 dec)->asdfasdfasdf(
1493 asdfadsf,
1494 asdfasdf,
1495 asdfasdf,
1496 ),
1497 func(asdfadf,
1498 asdfasdf),
1499 asdasdf
1500 );
1501}
1502
1503STARTTEST
Bram Moolenaar9e54a0e2006-04-14 20:42:25 +00001504:set cino=M1
15052kdd]]=][
1506ENDTEST
1507
1508int main ()
1509{
1510 if (cond1 &&
1511 cond2
1512 )
1513 foo;
1514}
1515
1516STARTTEST
Bram Moolenaar8d2d71d2011-04-28 13:02:09 +02001517:set cino=(0,ts
Bram Moolenaar9f4fe7c2014-07-03 22:57:55 +020015182kdd2j=][
Bram Moolenaar8d2d71d2011-04-28 13:02:09 +02001519ENDTEST
1520
1521void func(int a
1522#if defined(FOO)
1523 , int b
1524 , int c
1525#endif
1526 )
1527{
1528}
1529
1530STARTTEST
1531:set cino=(0
Bram Moolenaar9f4fe7c2014-07-03 22:57:55 +020015322kdd2j=][
Bram Moolenaar8d2d71d2011-04-28 13:02:09 +02001533ENDTEST
1534
1535void
1536func(int a
1537#if defined(FOO)
1538 , int b
1539 , int c
1540#endif
1541 )
1542{
1543}
1544
1545STARTTEST
Bram Moolenaar4ae06c12011-05-10 11:39:19 +02001546:set cino&
Bram Moolenaar9f4fe7c2014-07-03 22:57:55 +020015472kdd2j=7][
Bram Moolenaar4ae06c12011-05-10 11:39:19 +02001548ENDTEST
1549
1550void func(void)
1551{
1552 if(x==y)
1553 if(y==z)
1554 foo=1;
1555 else { bar=1;
1556 baz=2;
1557 }
1558 printf("Foo!\n");
1559}
1560
Bram Moolenaar496f9512011-05-19 16:35:09 +02001561void func1(void)
1562{
1563 char* tab[] = {"foo", "bar",
1564 "baz", "quux",
1565 "this line used", "to be indented incorrectly"};
1566 foo();
1567}
1568
1569void func2(void)
1570{
1571 int tab[] =
1572 {1, 2,
1573 3, 4,
1574 5, 6};
1575
1576 printf("This line used to be indented incorrectly.\n");
1577}
1578
Bram Moolenaar3388bb42011-11-30 17:20:23 +01001579int foo[]
1580#ifdef BAR
1581
1582= { 1, 2, 3,
1583 4, 5, 6 }
1584
1585#endif
1586;
1587 int baz;
1588
Bram Moolenaar496f9512011-05-19 16:35:09 +02001589void func3(void)
1590{
1591 int tab[] = {
1592 1, 2,
1593 3, 4,
1594 5, 6};
1595
Bram Moolenaarc367faa2011-12-14 20:21:35 +01001596printf("Don't you dare indent this line incorrectly!\n");
1597}
1598
1599void
1600func4(a, b,
1601 c)
1602int a;
1603int b;
1604int c;
1605{
1606}
1607
1608void
1609func5(
1610 int a,
1611 int b)
1612{
1613}
1614
1615void
1616func6(
1617 int a)
1618{
Bram Moolenaar496f9512011-05-19 16:35:09 +02001619}
1620
Bram Moolenaar4ae06c12011-05-10 11:39:19 +02001621STARTTEST
Bram Moolenaaraede6ce2011-05-10 11:56:30 +02001622:set cino&
Bram Moolenaar50f42ca2011-07-15 14:12:30 +02001623:set cino+=l1
Bram Moolenaar9f4fe7c2014-07-03 22:57:55 +020016242kdd2j=][
Bram Moolenaar50f42ca2011-07-15 14:12:30 +02001625ENDTEST
1626
1627void func(void)
1628{
1629 int tab[] =
1630 {
1631 1, 2, 3,
1632 4, 5, 6};
1633
1634 printf("Indent this line correctly!\n");
1635
1636 switch (foo)
1637 {
1638 case bar:
1639 printf("bar");
1640 break;
1641 case baz: {
1642 printf("baz");
1643 break;
1644 }
1645 case quux:
1646printf("But don't break the indentation of this instruction\n");
1647break;
1648 }
1649}
1650
1651STARTTEST
1652:set cino&
Bram Moolenaar9f4fe7c2014-07-03 22:57:55 +020016532kdd2j=][
Bram Moolenaaraede6ce2011-05-10 11:56:30 +02001654ENDTEST
1655
1656void func(void)
1657{
1658 cout << "a"
1659 << "b"
1660 << ") :"
1661 << "c";
1662}
1663
1664STARTTEST
Bram Moolenaara4271d52011-05-10 13:38:27 +02001665:set com=s1:/*,m:*,ex:*/
1666]]3jofoo();
1667ENDTEST
1668
1669void func(void)
1670{
1671 /*
1672 * This is a comment.
1673 */
1674}
1675
1676STARTTEST
Bram Moolenaar334adf02011-05-25 13:34:04 +02001677:set cino&
Bram Moolenaar9f4fe7c2014-07-03 22:57:55 +020016782kdd2j=][
Bram Moolenaar334adf02011-05-25 13:34:04 +02001679ENDTEST
1680
1681void func(void)
1682{
1683 for (int i = 0; i < 10; ++i)
1684 if (i & 1) {
1685 foo(1);
1686 } else
1687 foo(0);
1688baz();
1689}
1690
1691STARTTEST
Bram Moolenaar3675fa02012-04-05 17:17:42 +02001692:set cino=k2s,(0
16932kdd3j=][
1694ENDTEST
1695
1696void func(void)
1697{
1698 if (condition1
1699 && condition2)
1700 action();
1701 function(argument1
1702 && argument2);
1703
1704 if (c1 && (c2 ||
1705 c3))
1706 foo;
1707 if (c1 &&
1708 (c2 || c3))
1709 {
1710 }
1711
1712 if ( c1
1713 && ( c2
1714 || c3))
1715 foo;
1716 func( c1
1717 && ( c2
1718 || c3))
1719 foo;
1720}
1721
1722STARTTEST
1723:set cino=k2s,(s
17242kdd3j=][
1725ENDTEST
1726
1727void func(void)
1728{
1729 if (condition1
1730 && condition2)
1731 action();
1732 function(argument1
1733 && argument2);
1734
1735 if (c1 && (c2 ||
1736 c3))
1737 foo;
1738 if (c1 &&
1739 (c2 || c3))
1740 {
1741 }
1742
1743 if ( c1
1744 && ( c2
1745 || c3))
1746 foo;
1747 func( c1
1748 && ( c2
1749 || c3))
1750 foo;
1751}
1752
1753STARTTEST
1754:set cino=k2s,(s,U1
17552kdd3j=][
1756ENDTEST
1757
1758void func(void)
1759{
1760 if (condition1
1761 && condition2)
1762 action();
1763 function(argument1
1764 && argument2);
1765
1766 if (c1 && (c2 ||
1767 c3))
1768 foo;
1769 if (c1 &&
1770 (c2 || c3))
1771 {
1772 }
1773 if (c123456789
1774 && (c22345
1775 || c3))
1776 printf("foo\n");
1777
1778 c = c1 &&
1779 (
1780 c2 ||
1781 c3
1782 ) && c4;
1783}
1784
1785STARTTEST
1786:set cino=k2s,(0,W4
17872kdd3j=][
1788ENDTEST
1789
1790void func(void)
1791{
1792 if (condition1
1793 && condition2)
1794 action();
1795 function(argument1
1796 && argument2);
1797
1798 if (c1 && (c2 ||
1799 c3))
1800 foo;
1801 if (c1 &&
1802 (c2 || c3))
1803 {
1804 }
1805 if (c123456789
1806 && (c22345
1807 || c3))
1808 printf("foo\n");
1809
1810 if ( c1
1811 && ( c2
1812 || c3))
1813 foo;
1814
1815 a_long_line(
1816 argument,
1817 argument);
1818 a_short_line(argument,
1819 argument);
1820}
1821
1822STARTTEST
1823:set cino=k2s,u2
18242kdd3j=][
1825ENDTEST
1826
1827void func(void)
1828{
1829 if (condition1
1830 && condition2)
1831 action();
1832 function(argument1
1833 && argument2);
1834
1835 if (c1 && (c2 ||
1836 c3))
1837 foo;
1838 if (c1 &&
1839 (c2 || c3))
1840 {
1841 }
1842 if (c123456789
1843 && (c22345
1844 || c3))
1845 printf("foo\n");
1846}
1847
1848STARTTEST
1849:set cino=k2s,(0,w1
18502kdd3j=][
1851ENDTEST
1852
1853void func(void)
1854{
1855 if (condition1
1856 && condition2)
1857 action();
1858 function(argument1
1859 && argument2);
1860
1861 if (c1 && (c2 ||
1862 c3))
1863 foo;
1864 if (c1 &&
1865 (c2 || c3))
1866 {
1867 }
1868 if (c123456789
1869 && (c22345
1870 || c3))
1871 printf("foo\n");
1872
1873 if ( c1
1874 && ( c2
1875 || c3))
1876 foo;
1877 func( c1
1878 && ( c2
1879 || c3))
1880 foo;
1881}
1882
1883STARTTEST
1884:set cino=k2,(s
18852kdd3j=][
1886ENDTEST
1887
1888void func(void)
1889{
1890 if (condition1
1891 && condition2)
1892 action();
1893 function(argument1
1894 && argument2);
1895
1896 if (c1 && (c2 ||
1897 c3))
1898 foo;
1899 if (c1 &&
1900 (c2 || c3))
1901 {
1902 }
1903}
1904
1905STARTTEST
Bram Moolenaared38b0a2011-05-25 15:16:18 +02001906:set cino=N-s
Bram Moolenaar6ec154b2011-06-12 21:51:08 +02001907/^NAMESPACESTART
Bram Moolenaared38b0a2011-05-25 15:16:18 +02001908=/^NAMESPACEEND
1909ENDTEST
1910
Bram Moolenaar6ec154b2011-06-12 21:51:08 +02001911NAMESPACESTART
Bram Moolenaared38b0a2011-05-25 15:16:18 +02001912/* valid namespaces with normal indent */
1913namespace
1914{
1915 {
1916 111111111111;
1917}
1918}
1919namespace /* test */
1920{
1921 11111111111111111;
1922}
1923namespace // test
1924{
1925 111111111111111111;
1926}
1927namespace
1928{
1929 111111111111111111;
1930}
1931namespace test
1932{
1933 111111111111111111;
1934}
Bram Moolenaarca8b8d62016-11-17 21:30:27 +01001935namespace test::cpp17
1936{
1937 111111111111111111;
1938}
1939namespace ::incorrectcpp17
1940{
1941 111111111111111111;
1942}
1943namespace test::incorrectcpp17::
1944{
1945 111111111111111111;
1946}
1947namespace test:incorrectcpp17
1948{
1949 111111111111111111;
1950}
1951namespace test:::incorrectcpp17
1952{
1953 111111111111111111;
1954}
Bram Moolenaared38b0a2011-05-25 15:16:18 +02001955namespace{
1956 111111111111111111;
1957}
1958namespace test{
1959 111111111111111111;
1960}
1961namespace {
1962 111111111111111111;
1963}
1964namespace test {
1965 111111111111111111;
1966namespace test2 {
1967 22222222222222222;
1968}
1969}
1970
1971/* invalid namespaces use block indent */
1972namespace test test2 {
1973 111111111111111111111;
1974}
1975namespace11111111111 {
1976 111111111111;
1977}
1978namespace() {
1979 1111111111111;
1980}
1981namespace()
1982{
1983 111111111111111111;
1984}
1985namespace test test2
1986{
1987 1111111111111111111;
1988}
1989namespace111111111
1990{
1991 111111111111111111;
1992}
1993NAMESPACEEND
1994
1995
1996STARTTEST
Bram Moolenaar76f7fd32011-07-20 15:09:43 +02001997:set cino=j1,J1
Bram Moolenaar6ec154b2011-06-12 21:51:08 +02001998/^JSSTART
1999=/^JSEND
2000ENDTEST
2001
2002JSSTART
2003var bar = {
2004foo: {
2005that: this,
2006some: ok,
2007},
2008"bar":{
2009a : 2,
2010b: "123abc",
2011x: 4,
2012"y": 5
2013}
2014}
2015JSEND
2016
2017STARTTEST
Bram Moolenaar76f7fd32011-07-20 15:09:43 +02002018:set cino=j1,J1
2019/^JSSTART
2020=/^JSEND
2021ENDTEST
2022
2023JSSTART
2024var foo = [
Bram Moolenaar9f4fe7c2014-07-03 22:57:55 +020020251,
Bram Moolenaar76f7fd32011-07-20 15:09:43 +020020262,
20273
Bram Moolenaar9f4fe7c2014-07-03 22:57:55 +02002028];
Bram Moolenaar76f7fd32011-07-20 15:09:43 +02002029JSEND
2030
2031STARTTEST
2032:set cino=j1,J1
2033/^JSSTART
2034=/^JSEND
2035ENDTEST
2036
2037JSSTART
2038function bar() {
2039var foo = [
20401,
20412,
20423
Bram Moolenaar9f4fe7c2014-07-03 22:57:55 +02002043];
Bram Moolenaar76f7fd32011-07-20 15:09:43 +02002044}
2045JSEND
2046
2047STARTTEST
2048:set cino=j1,J1
2049/^JSSTART
2050=/^JSEND
2051ENDTEST
2052
2053JSSTART
2054(function($){
2055
Bram Moolenaar81439a62014-07-02 18:27:48 +02002056if (cond &&
2057cond) {
2058stmt;
2059}
Bram Moolenaar9f4fe7c2014-07-03 22:57:55 +02002060window.something.left =
2061(width - 50 + offset) + "px";
Bram Moolenaar76f7fd32011-07-20 15:09:43 +02002062var class_name='myclass';
2063
2064function private_method() {
2065}
2066
2067var public_method={
2068method: function(options,args){
2069private_method();
2070}
2071}
2072
2073function init(options) {
2074
2075$(this).data(class_name+'_public',$.extend({},{
2076foo: 'bar',
Bram Moolenaar9f4fe7c2014-07-03 22:57:55 +02002077bar: 2,
2078foobar: [
20791,
20802,
20813
Bram Moolenaar76f7fd32011-07-20 15:09:43 +02002082],
Bram Moolenaar9f4fe7c2014-07-03 22:57:55 +02002083callback: function(){
2084return true;
2085}
Bram Moolenaar76f7fd32011-07-20 15:09:43 +02002086}, options||{}));
2087}
2088
2089$.fn[class_name]=function() {
2090
2091var _arguments=arguments;
2092return this.each(function(){
2093
2094var options=$(this).data(class_name+'_public');
2095if (!options) {
2096init.apply(this,_arguments);
2097
2098} else {
2099var method=public_method[_arguments[0]];
2100
2101if (typeof(method)!='function') {
2102console.log(class_name+' has no method "'+_arguments[0]+'"');
2103return false;
2104}
2105_arguments[0]=options;
2106method.apply(this,_arguments);
2107}
2108});
2109}
2110
2111})(jQuery);
2112JSEND
2113
2114STARTTEST
2115:set cino=j1,J1
2116/^JSSTART
2117=/^JSEND
2118ENDTEST
2119
2120JSSTART
2121function init(options) {
2122$(this).data(class_name+'_public',$.extend({},{
2123foo: 'bar',
2124bar: 2,
2125foobar: [
Bram Moolenaar9f4fe7c2014-07-03 22:57:55 +020021261,
21272,
21283
Bram Moolenaar76f7fd32011-07-20 15:09:43 +02002129],
2130callback: function(){
2131return true;
2132}
2133}, options||{}));
2134}
2135JSEND
2136
2137STARTTEST
2138:set cino=j1,J1
2139/^JSSTART
2140=/^JSEND
2141ENDTEST
2142
2143JSSTART
2144(function($){
2145function init(options) {
2146$(this).data(class_name+'_public',$.extend({},{
2147foo: 'bar',
Bram Moolenaar9f4fe7c2014-07-03 22:57:55 +02002148bar: 2,
2149foobar: [
21501,
21512,
21523
Bram Moolenaar76f7fd32011-07-20 15:09:43 +02002153],
Bram Moolenaar9f4fe7c2014-07-03 22:57:55 +02002154callback: function(){
2155return true;
2156}
Bram Moolenaar76f7fd32011-07-20 15:09:43 +02002157}, options||{}));
2158}
2159})(jQuery);
2160JSEND
2161
2162STARTTEST
Bram Moolenaardcefba92015-03-20 19:06:06 +01002163:set cino=j1,J1,+2
2164/^JSSTART
2165=/^JSEND
2166ENDTEST
2167
2168JSSTART
2169// Results of JavaScript indent
2170// 1
2171(function(){
2172var a = [
2173'a',
2174'b',
2175'c',
2176'd',
2177'e',
2178'f',
2179'g',
2180'h',
2181'i'
2182];
2183}())
2184
2185// 2
2186(function(){
2187var a = [
21880 +
21895 *
21909 *
2191'a',
2192'b',
21930 +
21945 *
21959 *
2196'c',
2197'd',
2198'e',
2199'f',
2200'g',
2201'h',
2202'i'
2203];
2204}())
2205
2206// 3
2207(function(){
2208var a = [
22090 +
2210// comment 1
22115 *
2212/* comment 2 */
22139 *
2214'a',
2215'b',
22160 +
22175 *
22189 *
2219'c',
2220'd',
2221'e',
2222'f',
2223'g',
2224'h',
2225'i'
2226];
2227}())
2228
2229// 4
2230{
2231var a = [
22320,
22331
2234];
2235var b;
2236var c;
2237}
2238
2239// 5
2240{
2241var a = [
2242[
22430
2244],
22452,
22463
2247];
2248}
2249
2250// 6
2251{
2252var a = [
2253[
22540,
22551
2256],
22572,
22583
2259];
2260}
2261
2262// 7
2263{
2264var a = [
2265// [
22660,
2267// 1
2268// ],
22692,
22703
2271];
2272}
2273
2274// 8
2275var x = [
2276(function(){
2277var a,
2278b,
2279c,
2280d,
2281e,
2282f,
2283g,
2284h,
2285i;
2286})
2287];
2288
2289// 9
2290var a = [
22910 +
22925 *
22939 *
2294'a',
2295'b',
22960 +
22975 *
22989 *
2299'c',
2300'd',
2301'e',
2302'f',
2303'g',
2304'h',
2305'i'
2306];
2307
2308// 10
2309var a,
2310b,
2311c,
2312d,
2313e,
2314f,
2315g,
2316h,
2317i;
2318JSEND
2319
2320STARTTEST
Bram Moolenaarc6aa4752017-01-07 15:39:43 +01002321:set cin cino&
2322/start of define
2323=/end of define
2324ENDTEST
2325
2326/* start of define */
2327{
2328}
2329#define AAA \
2330BBB\
2331CCC
2332
2333#define CNT \
23341 + \
23352 + \
23364
2337/* end of define */
2338
2339STARTTEST
Bram Moolenaar071d4272004-06-13 20:20:40 +00002340:g/^STARTTEST/.,/^ENDTEST/d
2341:1;/start of AUTO/,$wq! test.out
2342ENDTEST