blob: 646fbb35c3516eb82f6b7f2ed5a3e820dab7c074 [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
Bram Moolenaar38a3d6c2017-03-11 18:42:56 +0100973:set tw=0 noai fo=croq
974:let &wm = &columns - 20
Bram Moolenaar071d4272004-06-13 20:20:40 +0000975/serious/e
976a about life, the universe, and the rest
977ENDTEST
978
979{
980
981/* this is
982 * a real serious important big
983 * comment
984 */
985 /* insert " about life, the universe, and the rest" after "serious" */
986}
987
988STARTTEST
989:set nocin
990/comments
991joabout life/happens
992jothere/below
993oline/this
994Ohello
995ENDTEST
996
997{
998 /*
999 * Testing for comments, without 'cin' set
1000 */
1001
1002/*
1003* what happens here?
1004*/
1005
1006 /*
1007 the end of the comment, try inserting a line below */
1008
1009 /* how about
1010 this one */
1011}
1012
1013STARTTEST
1014:set cin
1015/vec2
1016==
1017ENDTEST
1018
1019{
1020 var = this + that + vec[0] * vec[0]
1021 + vec[1] * vec[1]
1022 + vec2[2] * vec[2];
1023}
1024
1025STARTTEST
1026:set cin
1027:set cino=}4
1028/testing1
1029k2==/testing2
1030k2==
1031ENDTEST
1032
1033{
1034 asdf asdflkajds f;
1035 if (tes & ting) {
1036 asdf asdf asdf ;
1037 asdfa sdf asdf;
1038 }
1039 testing1;
1040 if (tes & ting)
1041 {
1042 asdf asdf asdf ;
1043 asdfa sdf asdf;
1044 }
1045 testing2;
1046}
1047
1048STARTTEST
1049:set cin
1050:set cino=(0,)20
1051/main
1052=][
1053ENDTEST
1054
1055main ( int first_par, /*
1056 * Comment for
1057 * first par
1058 */
1059 int second_par /*
1060 * Comment for
1061 * second par
1062 */
1063 )
1064{
1065 func( first_par, /*
1066 * Comment for
1067 * first par
1068 */
1069 second_par /*
1070 * Comment for
1071 * second par
1072 */
1073 );
1074
1075}
1076
1077STARTTEST
1078:set cin
Bram Moolenaar48d27922012-06-13 13:40:48 +02001079:set cino=es,n0s
1080/main
1081=][
1082ENDTEST
1083
1084main(void)
1085{
1086 /* Make sure that cino=X0s is not parsed like cino=Xs. */
1087 if (cond)
1088 foo();
1089 else
1090 {
1091 bar();
1092 }
1093}
1094
1095STARTTEST
1096:set cin
Bram Moolenaar071d4272004-06-13 20:20:40 +00001097:set cino=
1098]]=][
1099ENDTEST
1100
1101{
1102 do
1103 {
1104 if ()
1105 {
1106 if ()
1107 asdf;
1108 else
1109 asdf;
1110 }
1111 } while ();
1112 cmd; /* this should go under the } */
1113}
1114
1115STARTTEST
1116]]=][
1117ENDTEST
1118
1119void f()
1120{
1121 if ( k() ) {
1122 l();
1123
1124 } else { /* Start (two words) end */
1125 m();
1126 }
1127
1128 n();
1129}
1130
1131STARTTEST
1132:set cino={s,e-s
1133]]=][
1134ENDTEST
1135
1136void f()
1137{
1138 if ( k() )
1139 {
1140 l();
1141 } else { /* Start (two words) end */
1142 m();
1143 }
1144 n(); /* should be under the if () */
1145}
1146
1147STARTTEST
1148:set cino={s,fs
1149]]=/ foo
1150ENDTEST
1151
1152void bar(void)
1153{
1154 static array[2][2] =
1155 {
1156 { 1, 2 },
1157 { 3, 4 },
1158 }
1159
1160 while (a)
1161 {
1162 foo(&a);
1163 }
1164
1165 {
1166 int a;
1167 {
1168 a = a + 1;
1169 }
1170 }
1171 b = a;
1172 }
1173
1174void func(void)
1175 {
1176 a = 1;
1177 {
1178 b = 2;
1179 }
1180 c = 3;
1181 d = 4;
1182 }
1183/* foo */
1184
1185STARTTEST
1186:set cino=
1187/while
1188ohere
1189ENDTEST
1190
1191a()
1192{
1193 do {
1194 a = a +
1195 a;
1196 } while ( a ); /* add text under this line */
1197 if ( a )
1198 a;
1199}
1200
1201STARTTEST
1202:set cino= com=
1203/comment
1204olabel2: b(); label3 /* post */: /* pre */ label4: f(/*com*/); if (/*com*/) cmd();
1205ENDTEST
1206
1207a()
1208{
1209label1:
1210 /* hmm */
1211 // comment
1212}
1213
1214STARTTEST
1215:set comments& comments^=s:/*,m:**,ex:*/
1216/simple
1217=5j
1218ENDTEST
1219
1220/*
1221 * A simple comment
1222 */
1223
1224/*
1225 ** A different comment
1226 */
1227
1228STARTTEST
1229:set cino=c0
1230:set comments& comments-=s1:/* comments^=s0:/*
12312kdd]]=][
1232ENDTEST
1233
1234void f()
1235{
1236
1237 /*********
1238 A comment.
1239*********/
1240}
1241
1242STARTTEST
1243:set cino=c0,C1
1244:set comments& comments-=s1:/* comments^=s0:/*
12452kdd]]=][
1246ENDTEST
1247
1248void f()
1249{
1250
1251 /*********
1252 A comment.
1253*********/
1254}
1255
1256STARTTEST
1257:set cino=
1258]]=][
1259ENDTEST
1260
1261void f()
1262{
1263 c = c1 &&
1264 (
1265 c2 ||
1266 c3
1267 ) && c4;
1268}
1269
1270STARTTEST
1271:set cino=(s
12722kdd]]=][
1273ENDTEST
1274
1275void f()
1276{
1277 c = c1 &&
1278 (
1279 c2 ||
1280 c3
1281 ) && c4;
1282}
1283
1284STARTTEST
1285:set cino=(s,U1
12862kdd]]=][
1287ENDTEST
1288
1289void f()
1290{
1291 c = c1 &&
1292 (
1293 c2 ||
1294 c3
1295 ) && c4;
1296}
1297
1298STARTTEST
1299:set cino=(0
13002kdd]]=][
1301ENDTEST
1302
1303void f()
1304{
1305 if ( c1
1306 && ( c2
1307 || c3))
1308 foo;
1309}
1310
1311STARTTEST
1312:set cino=(0,w1
13132kdd]]=][
1314ENDTEST
1315
1316void f()
1317{
1318 if ( c1
1319 && ( c2
1320 || c3))
1321 foo;
1322}
1323
1324STARTTEST
1325:set cino=(s
13262kdd]]=][
1327ENDTEST
1328
1329void f()
1330{
1331 c = c1 && (
1332 c2 ||
1333 c3
1334 ) && c4;
1335 if (
1336 c1 && c2
1337 )
1338 foo;
1339}
1340
1341STARTTEST
1342:set cino=(s,m1
13432kdd]]=][
1344ENDTEST
1345
1346void f()
1347{
1348 c = c1 && (
1349 c2 ||
1350 c3
1351 ) && c4;
1352 if (
1353 c1 && c2
1354 )
1355 foo;
1356}
1357
1358STARTTEST
1359:set cino=b1
13602kdd]]=][
1361ENDTEST
1362
1363void f()
1364{
1365 switch (x)
1366 {
1367 case 1:
1368 a = b;
1369 break;
1370 default:
1371 a = 0;
1372 break;
1373 }
1374}
1375
1376STARTTEST
1377:set cino=(0,W5
13782kdd]]=][
1379ENDTEST
1380
1381void f()
1382{
1383 invokeme(
1384 argu,
1385 ment);
1386 invokeme(
1387 argu,
1388 ment
1389 );
1390 invokeme(argu,
1391 ment
1392 );
1393}
1394
1395STARTTEST
1396:set cino=/6
13972kdd]]=][
1398ENDTEST
1399
1400void f()
1401{
1402 statement;
1403 // comment 1
1404 // comment 2
1405}
1406
1407STARTTEST
1408:set cino=
14092kdd]]/comment 1/+1
1410==
1411ENDTEST
1412
1413void f()
1414{
1415 statement;
1416 // comment 1
1417 // comment 2
1418}
1419
1420STARTTEST
1421:set cino=g0
14222kdd]]=][
1423ENDTEST
1424
1425class CAbc
1426{
1427 int Test() { return FALSE; }
1428
1429public: // comment
1430 void testfall();
1431protected:
1432 void testfall();
1433};
1434
1435STARTTEST
Bram Moolenaare79d1532011-10-04 18:03:47 +02001436:set cino=(0,gs,hs
14372kdd]]=][
1438ENDTEST
1439
1440class Foo : public Bar
1441{
1442public:
1443virtual void method1(void) = 0;
1444virtual void method2(int arg1,
1445int arg2,
1446int arg3) = 0;
1447};
1448
1449STARTTEST
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00001450:set cino=+20
14512kdd]]=][
1452ENDTEST
1453
1454 void
1455foo()
1456{
1457 if (a)
1458 {
1459 } else
1460 asdf;
1461}
1462
1463STARTTEST
Bram Moolenaar071d4272004-06-13 20:20:40 +00001464:set cino=(0,W2s
14652kdd]]=][
1466ENDTEST
1467
1468{
1469 averylongfunctionnamelongfunctionnameaverylongfunctionname()->asd(
1470 asdasdf,
1471 func(asdf,
1472 asdfadsf),
1473 asdfasdf
1474 );
1475
1476 /* those are ugly, but consequent */
1477
1478 func()->asd(asdasdf,
1479 averylongfunctionname(
1480 abc,
1481 dec)->averylongfunctionname(
1482 asdfadsf,
1483 asdfasdf,
1484 asdfasdf,
1485 ),
1486 func(asdfadf,
1487 asdfasdf
1488 ),
1489 asdasdf
1490 );
1491
1492 averylongfunctionnameaverylongfunctionnameavery()->asd(fasdf(
1493 abc,
1494 dec)->asdfasdfasdf(
1495 asdfadsf,
1496 asdfasdf,
1497 asdfasdf,
1498 ),
1499 func(asdfadf,
1500 asdfasdf),
1501 asdasdf
1502 );
1503}
1504
1505STARTTEST
Bram Moolenaar9e54a0e2006-04-14 20:42:25 +00001506:set cino=M1
15072kdd]]=][
1508ENDTEST
1509
1510int main ()
1511{
1512 if (cond1 &&
1513 cond2
1514 )
1515 foo;
1516}
1517
1518STARTTEST
Bram Moolenaar8d2d71d2011-04-28 13:02:09 +02001519:set cino=(0,ts
Bram Moolenaar9f4fe7c2014-07-03 22:57:55 +020015202kdd2j=][
Bram Moolenaar8d2d71d2011-04-28 13:02:09 +02001521ENDTEST
1522
1523void func(int a
1524#if defined(FOO)
1525 , int b
1526 , int c
1527#endif
1528 )
1529{
1530}
1531
1532STARTTEST
1533:set cino=(0
Bram Moolenaar9f4fe7c2014-07-03 22:57:55 +020015342kdd2j=][
Bram Moolenaar8d2d71d2011-04-28 13:02:09 +02001535ENDTEST
1536
1537void
1538func(int a
1539#if defined(FOO)
1540 , int b
1541 , int c
1542#endif
1543 )
1544{
1545}
1546
1547STARTTEST
Bram Moolenaar4ae06c12011-05-10 11:39:19 +02001548:set cino&
Bram Moolenaar9f4fe7c2014-07-03 22:57:55 +020015492kdd2j=7][
Bram Moolenaar4ae06c12011-05-10 11:39:19 +02001550ENDTEST
1551
1552void func(void)
1553{
1554 if(x==y)
1555 if(y==z)
1556 foo=1;
1557 else { bar=1;
1558 baz=2;
1559 }
1560 printf("Foo!\n");
1561}
1562
Bram Moolenaar496f9512011-05-19 16:35:09 +02001563void func1(void)
1564{
1565 char* tab[] = {"foo", "bar",
1566 "baz", "quux",
1567 "this line used", "to be indented incorrectly"};
1568 foo();
1569}
1570
1571void func2(void)
1572{
1573 int tab[] =
1574 {1, 2,
1575 3, 4,
1576 5, 6};
1577
1578 printf("This line used to be indented incorrectly.\n");
1579}
1580
Bram Moolenaar3388bb42011-11-30 17:20:23 +01001581int foo[]
1582#ifdef BAR
1583
1584= { 1, 2, 3,
1585 4, 5, 6 }
1586
1587#endif
1588;
1589 int baz;
1590
Bram Moolenaar496f9512011-05-19 16:35:09 +02001591void func3(void)
1592{
1593 int tab[] = {
1594 1, 2,
1595 3, 4,
1596 5, 6};
1597
Bram Moolenaarc367faa2011-12-14 20:21:35 +01001598printf("Don't you dare indent this line incorrectly!\n");
1599}
1600
1601void
1602func4(a, b,
1603 c)
1604int a;
1605int b;
1606int c;
1607{
1608}
1609
1610void
1611func5(
1612 int a,
1613 int b)
1614{
1615}
1616
1617void
1618func6(
1619 int a)
1620{
Bram Moolenaar496f9512011-05-19 16:35:09 +02001621}
1622
Bram Moolenaar4ae06c12011-05-10 11:39:19 +02001623STARTTEST
Bram Moolenaaraede6ce2011-05-10 11:56:30 +02001624:set cino&
Bram Moolenaar50f42ca2011-07-15 14:12:30 +02001625:set cino+=l1
Bram Moolenaar9f4fe7c2014-07-03 22:57:55 +020016262kdd2j=][
Bram Moolenaar50f42ca2011-07-15 14:12:30 +02001627ENDTEST
1628
1629void func(void)
1630{
1631 int tab[] =
1632 {
1633 1, 2, 3,
1634 4, 5, 6};
1635
1636 printf("Indent this line correctly!\n");
1637
1638 switch (foo)
1639 {
1640 case bar:
1641 printf("bar");
1642 break;
1643 case baz: {
1644 printf("baz");
1645 break;
1646 }
1647 case quux:
1648printf("But don't break the indentation of this instruction\n");
1649break;
1650 }
1651}
1652
1653STARTTEST
1654:set cino&
Bram Moolenaar9f4fe7c2014-07-03 22:57:55 +020016552kdd2j=][
Bram Moolenaaraede6ce2011-05-10 11:56:30 +02001656ENDTEST
1657
1658void func(void)
1659{
1660 cout << "a"
1661 << "b"
1662 << ") :"
1663 << "c";
1664}
1665
1666STARTTEST
Bram Moolenaara4271d52011-05-10 13:38:27 +02001667:set com=s1:/*,m:*,ex:*/
1668]]3jofoo();
1669ENDTEST
1670
1671void func(void)
1672{
1673 /*
1674 * This is a comment.
1675 */
1676}
1677
1678STARTTEST
Bram Moolenaar334adf02011-05-25 13:34:04 +02001679:set cino&
Bram Moolenaar9f4fe7c2014-07-03 22:57:55 +020016802kdd2j=][
Bram Moolenaar334adf02011-05-25 13:34:04 +02001681ENDTEST
1682
1683void func(void)
1684{
1685 for (int i = 0; i < 10; ++i)
1686 if (i & 1) {
1687 foo(1);
1688 } else
1689 foo(0);
1690baz();
1691}
1692
1693STARTTEST
Bram Moolenaar3675fa02012-04-05 17:17:42 +02001694:set cino=k2s,(0
16952kdd3j=][
1696ENDTEST
1697
1698void func(void)
1699{
1700 if (condition1
1701 && condition2)
1702 action();
1703 function(argument1
1704 && argument2);
1705
1706 if (c1 && (c2 ||
1707 c3))
1708 foo;
1709 if (c1 &&
1710 (c2 || c3))
1711 {
1712 }
1713
1714 if ( c1
1715 && ( c2
1716 || c3))
1717 foo;
1718 func( c1
1719 && ( c2
1720 || c3))
1721 foo;
1722}
1723
1724STARTTEST
1725:set cino=k2s,(s
17262kdd3j=][
1727ENDTEST
1728
1729void func(void)
1730{
1731 if (condition1
1732 && condition2)
1733 action();
1734 function(argument1
1735 && argument2);
1736
1737 if (c1 && (c2 ||
1738 c3))
1739 foo;
1740 if (c1 &&
1741 (c2 || c3))
1742 {
1743 }
1744
1745 if ( c1
1746 && ( c2
1747 || c3))
1748 foo;
1749 func( c1
1750 && ( c2
1751 || c3))
1752 foo;
1753}
1754
1755STARTTEST
1756:set cino=k2s,(s,U1
17572kdd3j=][
1758ENDTEST
1759
1760void func(void)
1761{
1762 if (condition1
1763 && condition2)
1764 action();
1765 function(argument1
1766 && argument2);
1767
1768 if (c1 && (c2 ||
1769 c3))
1770 foo;
1771 if (c1 &&
1772 (c2 || c3))
1773 {
1774 }
1775 if (c123456789
1776 && (c22345
1777 || c3))
1778 printf("foo\n");
1779
1780 c = c1 &&
1781 (
1782 c2 ||
1783 c3
1784 ) && c4;
1785}
1786
1787STARTTEST
1788:set cino=k2s,(0,W4
17892kdd3j=][
1790ENDTEST
1791
1792void func(void)
1793{
1794 if (condition1
1795 && condition2)
1796 action();
1797 function(argument1
1798 && argument2);
1799
1800 if (c1 && (c2 ||
1801 c3))
1802 foo;
1803 if (c1 &&
1804 (c2 || c3))
1805 {
1806 }
1807 if (c123456789
1808 && (c22345
1809 || c3))
1810 printf("foo\n");
1811
1812 if ( c1
1813 && ( c2
1814 || c3))
1815 foo;
1816
1817 a_long_line(
1818 argument,
1819 argument);
1820 a_short_line(argument,
1821 argument);
1822}
1823
1824STARTTEST
1825:set cino=k2s,u2
18262kdd3j=][
1827ENDTEST
1828
1829void func(void)
1830{
1831 if (condition1
1832 && condition2)
1833 action();
1834 function(argument1
1835 && argument2);
1836
1837 if (c1 && (c2 ||
1838 c3))
1839 foo;
1840 if (c1 &&
1841 (c2 || c3))
1842 {
1843 }
1844 if (c123456789
1845 && (c22345
1846 || c3))
1847 printf("foo\n");
1848}
1849
1850STARTTEST
1851:set cino=k2s,(0,w1
18522kdd3j=][
1853ENDTEST
1854
1855void func(void)
1856{
1857 if (condition1
1858 && condition2)
1859 action();
1860 function(argument1
1861 && argument2);
1862
1863 if (c1 && (c2 ||
1864 c3))
1865 foo;
1866 if (c1 &&
1867 (c2 || c3))
1868 {
1869 }
1870 if (c123456789
1871 && (c22345
1872 || c3))
1873 printf("foo\n");
1874
1875 if ( c1
1876 && ( c2
1877 || c3))
1878 foo;
1879 func( c1
1880 && ( c2
1881 || c3))
1882 foo;
1883}
1884
1885STARTTEST
1886:set cino=k2,(s
18872kdd3j=][
1888ENDTEST
1889
1890void func(void)
1891{
1892 if (condition1
1893 && condition2)
1894 action();
1895 function(argument1
1896 && argument2);
1897
1898 if (c1 && (c2 ||
1899 c3))
1900 foo;
1901 if (c1 &&
1902 (c2 || c3))
1903 {
1904 }
1905}
1906
1907STARTTEST
Bram Moolenaared38b0a2011-05-25 15:16:18 +02001908:set cino=N-s
Bram Moolenaar6ec154b2011-06-12 21:51:08 +02001909/^NAMESPACESTART
Bram Moolenaared38b0a2011-05-25 15:16:18 +02001910=/^NAMESPACEEND
1911ENDTEST
1912
Bram Moolenaar6ec154b2011-06-12 21:51:08 +02001913NAMESPACESTART
Bram Moolenaared38b0a2011-05-25 15:16:18 +02001914/* valid namespaces with normal indent */
1915namespace
1916{
1917 {
1918 111111111111;
1919}
1920}
1921namespace /* test */
1922{
1923 11111111111111111;
1924}
1925namespace // test
1926{
1927 111111111111111111;
1928}
1929namespace
1930{
1931 111111111111111111;
1932}
1933namespace test
1934{
1935 111111111111111111;
1936}
Bram Moolenaarca8b8d62016-11-17 21:30:27 +01001937namespace test::cpp17
1938{
1939 111111111111111111;
1940}
1941namespace ::incorrectcpp17
1942{
1943 111111111111111111;
1944}
1945namespace test::incorrectcpp17::
1946{
1947 111111111111111111;
1948}
1949namespace test:incorrectcpp17
1950{
1951 111111111111111111;
1952}
1953namespace test:::incorrectcpp17
1954{
1955 111111111111111111;
1956}
Bram Moolenaared38b0a2011-05-25 15:16:18 +02001957namespace{
1958 111111111111111111;
1959}
1960namespace test{
1961 111111111111111111;
1962}
1963namespace {
1964 111111111111111111;
1965}
1966namespace test {
1967 111111111111111111;
1968namespace test2 {
1969 22222222222222222;
1970}
1971}
1972
1973/* invalid namespaces use block indent */
1974namespace test test2 {
1975 111111111111111111111;
1976}
1977namespace11111111111 {
1978 111111111111;
1979}
1980namespace() {
1981 1111111111111;
1982}
1983namespace()
1984{
1985 111111111111111111;
1986}
1987namespace test test2
1988{
1989 1111111111111111111;
1990}
1991namespace111111111
1992{
1993 111111111111111111;
1994}
1995NAMESPACEEND
1996
1997
1998STARTTEST
Bram Moolenaar76f7fd32011-07-20 15:09:43 +02001999:set cino=j1,J1
Bram Moolenaar6ec154b2011-06-12 21:51:08 +02002000/^JSSTART
2001=/^JSEND
2002ENDTEST
2003
2004JSSTART
2005var bar = {
2006foo: {
2007that: this,
2008some: ok,
2009},
2010"bar":{
2011a : 2,
2012b: "123abc",
2013x: 4,
2014"y": 5
2015}
2016}
2017JSEND
2018
2019STARTTEST
Bram Moolenaar76f7fd32011-07-20 15:09:43 +02002020:set cino=j1,J1
2021/^JSSTART
2022=/^JSEND
2023ENDTEST
2024
2025JSSTART
2026var foo = [
Bram Moolenaar9f4fe7c2014-07-03 22:57:55 +020020271,
Bram Moolenaar76f7fd32011-07-20 15:09:43 +020020282,
20293
Bram Moolenaar9f4fe7c2014-07-03 22:57:55 +02002030];
Bram Moolenaar76f7fd32011-07-20 15:09:43 +02002031JSEND
2032
2033STARTTEST
2034:set cino=j1,J1
2035/^JSSTART
2036=/^JSEND
2037ENDTEST
2038
2039JSSTART
2040function bar() {
2041var foo = [
20421,
20432,
20443
Bram Moolenaar9f4fe7c2014-07-03 22:57:55 +02002045];
Bram Moolenaar76f7fd32011-07-20 15:09:43 +02002046}
2047JSEND
2048
2049STARTTEST
2050:set cino=j1,J1
2051/^JSSTART
2052=/^JSEND
2053ENDTEST
2054
2055JSSTART
2056(function($){
2057
Bram Moolenaar81439a62014-07-02 18:27:48 +02002058if (cond &&
2059cond) {
2060stmt;
2061}
Bram Moolenaar9f4fe7c2014-07-03 22:57:55 +02002062window.something.left =
2063(width - 50 + offset) + "px";
Bram Moolenaar76f7fd32011-07-20 15:09:43 +02002064var class_name='myclass';
2065
2066function private_method() {
2067}
2068
2069var public_method={
2070method: function(options,args){
2071private_method();
2072}
2073}
2074
2075function init(options) {
2076
2077$(this).data(class_name+'_public',$.extend({},{
2078foo: 'bar',
Bram Moolenaar9f4fe7c2014-07-03 22:57:55 +02002079bar: 2,
2080foobar: [
20811,
20822,
20833
Bram Moolenaar76f7fd32011-07-20 15:09:43 +02002084],
Bram Moolenaar9f4fe7c2014-07-03 22:57:55 +02002085callback: function(){
2086return true;
2087}
Bram Moolenaar76f7fd32011-07-20 15:09:43 +02002088}, options||{}));
2089}
2090
2091$.fn[class_name]=function() {
2092
2093var _arguments=arguments;
2094return this.each(function(){
2095
2096var options=$(this).data(class_name+'_public');
2097if (!options) {
2098init.apply(this,_arguments);
2099
2100} else {
2101var method=public_method[_arguments[0]];
2102
2103if (typeof(method)!='function') {
2104console.log(class_name+' has no method "'+_arguments[0]+'"');
2105return false;
2106}
2107_arguments[0]=options;
2108method.apply(this,_arguments);
2109}
2110});
2111}
2112
2113})(jQuery);
2114JSEND
2115
2116STARTTEST
2117:set cino=j1,J1
2118/^JSSTART
2119=/^JSEND
2120ENDTEST
2121
2122JSSTART
2123function init(options) {
2124$(this).data(class_name+'_public',$.extend({},{
2125foo: 'bar',
2126bar: 2,
2127foobar: [
Bram Moolenaar9f4fe7c2014-07-03 22:57:55 +020021281,
21292,
21303
Bram Moolenaar76f7fd32011-07-20 15:09:43 +02002131],
2132callback: function(){
2133return true;
2134}
2135}, options||{}));
2136}
2137JSEND
2138
2139STARTTEST
2140:set cino=j1,J1
2141/^JSSTART
2142=/^JSEND
2143ENDTEST
2144
2145JSSTART
2146(function($){
2147function init(options) {
2148$(this).data(class_name+'_public',$.extend({},{
2149foo: 'bar',
Bram Moolenaar9f4fe7c2014-07-03 22:57:55 +02002150bar: 2,
2151foobar: [
21521,
21532,
21543
Bram Moolenaar76f7fd32011-07-20 15:09:43 +02002155],
Bram Moolenaar9f4fe7c2014-07-03 22:57:55 +02002156callback: function(){
2157return true;
2158}
Bram Moolenaar76f7fd32011-07-20 15:09:43 +02002159}, options||{}));
2160}
2161})(jQuery);
2162JSEND
2163
2164STARTTEST
Bram Moolenaardcefba92015-03-20 19:06:06 +01002165:set cino=j1,J1,+2
2166/^JSSTART
2167=/^JSEND
2168ENDTEST
2169
2170JSSTART
2171// Results of JavaScript indent
2172// 1
2173(function(){
2174var a = [
2175'a',
2176'b',
2177'c',
2178'd',
2179'e',
2180'f',
2181'g',
2182'h',
2183'i'
2184];
2185}())
2186
2187// 2
2188(function(){
2189var a = [
21900 +
21915 *
21929 *
2193'a',
2194'b',
21950 +
21965 *
21979 *
2198'c',
2199'd',
2200'e',
2201'f',
2202'g',
2203'h',
2204'i'
2205];
2206}())
2207
2208// 3
2209(function(){
2210var a = [
22110 +
2212// comment 1
22135 *
2214/* comment 2 */
22159 *
2216'a',
2217'b',
22180 +
22195 *
22209 *
2221'c',
2222'd',
2223'e',
2224'f',
2225'g',
2226'h',
2227'i'
2228];
2229}())
2230
2231// 4
2232{
2233var a = [
22340,
22351
2236];
2237var b;
2238var c;
2239}
2240
2241// 5
2242{
2243var a = [
2244[
22450
2246],
22472,
22483
2249];
2250}
2251
2252// 6
2253{
2254var a = [
2255[
22560,
22571
2258],
22592,
22603
2261];
2262}
2263
2264// 7
2265{
2266var a = [
2267// [
22680,
2269// 1
2270// ],
22712,
22723
2273];
2274}
2275
2276// 8
2277var x = [
2278(function(){
2279var a,
2280b,
2281c,
2282d,
2283e,
2284f,
2285g,
2286h,
2287i;
2288})
2289];
2290
2291// 9
2292var a = [
22930 +
22945 *
22959 *
2296'a',
2297'b',
22980 +
22995 *
23009 *
2301'c',
2302'd',
2303'e',
2304'f',
2305'g',
2306'h',
2307'i'
2308];
2309
2310// 10
2311var a,
2312b,
2313c,
2314d,
2315e,
2316f,
2317g,
2318h,
2319i;
2320JSEND
2321
2322STARTTEST
Bram Moolenaarc6aa4752017-01-07 15:39:43 +01002323:set cin cino&
2324/start of define
2325=/end of define
2326ENDTEST
2327
2328/* start of define */
2329{
2330}
2331#define AAA \
2332BBB\
2333CCC
2334
2335#define CNT \
23361 + \
23372 + \
23384
2339/* end of define */
2340
2341STARTTEST
Bram Moolenaarf8c53d32017-11-12 15:36:38 +01002342:set cin cino&
2343/a = second
2344ox
2345ENDTEST
2346
2347{
2348 a = second/*bug*/*line;
2349}
2350
2351STARTTEST
Bram Moolenaar071d4272004-06-13 20:20:40 +00002352:g/^STARTTEST/.,/^ENDTEST/d
2353:1;/start of AUTO/,$wq! test.out
2354ENDTEST