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