blob: 7757569e37247576b66d7c8f81a6149ca503aa4b [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
666class CAbc :
667 public BaseClass1,
668 protected BaseClass2
669{
670 int Test() { return FALSE; }
671 int Test1() { return TRUE; }
672
673 CAbc(int a, int b ) :
674 BaseClass(a)
675 {
676 switch(xxx)
677 {
678 case abc:
679 asdf();
680 break;
681
682 case 999:
683 baer();
684 break;
685 }
686 }
687
688public: // <-- this was incoreectly indented before!!
689 void testfall();
690protected:
691 void testfall();
692};
693
694class CAbc : public BaseClass1,
695 protected BaseClass2
696{
697};
698
699static struct
700{
701 int a;
702 int b;
703} variable[COUNT] =
704{
705 {
706 123,
707 456
708 },
709 {
710 123,
711 456
712 }
713};
714
715static struct
716{
717 int a;
718 int b;
719} variable[COUNT] =
720{
721 { 123, 456 },
722 { 123, 456 }
723};
724
725void asdf() /* ind_maxparen may cause trouble here */
726{
727 if ((0
728 && 1
729 && 1
730 && 1
731 && 1
732 && 1
733 && 1
734 && 1
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)) break;
753}
754
Bram Moolenaar18144c82006-04-12 21:52:12 +0000755foo()
756{
757 a = cond ? foo() : asdf
758 + asdf;
759
760 a = cond ?
761 foo() : asdf
762 + asdf;
763}
764
765int main(void)
766{
767 if (a)
768 if (b)
769 2;
770 else 3;
771 next_line_of_code();
772}
773
Bram Moolenaar7fc904b2006-04-13 20:37:35 +0000774barry()
775{
776 Foo::Foo (int one,
777 int two)
778 : something(4)
779 {}
780}
781
782barry()
783{
784 Foo::Foo (int one, int two)
785 : something(4)
786 {}
787}
788
789Constructor::Constructor(int a,
790 int b
791 ) :
792 BaseClass(a,
793 b,
794 c),
795 mMember(b)
796{
797}
Bram Moolenaar9e54a0e2006-04-14 20:42:25 +0000798 int main ()
799 {
800 if (lala)
801 do
802 ++(*lolo);
803 while (lili
804 && lele);
805 lulu;
806 }
Bram Moolenaar7fc904b2006-04-13 20:37:35 +0000807
Bram Moolenaar9e54a0e2006-04-14 20:42:25 +0000808int main ()
809{
810switch (c)
811{
812case 'c': if (cond)
813{
814}
815}
816}
817
818main()
819{
820 (void) MyFancyFuasdfadsfnction(
821 argument);
822}
823
824main()
825{
826 char foo[] = "/*";
827 /* as
828 df */
829 hello
830}
Bram Moolenaared38b0a2011-05-25 15:16:18 +0200831
832/* valid namespaces with normal indent */
833namespace
834{
835{
836 111111111111;
837}
838}
839namespace /* test */
840{
841 11111111111111111;
842}
843namespace // test
844{
845 111111111111111111;
846}
847namespace
848{
849 111111111111111111;
850}
851namespace test
852{
853 111111111111111111;
854}
855namespace{
856 111111111111111111;
857}
858namespace test{
859 111111111111111111;
860}
861namespace {
862 111111111111111111;
863}
864namespace test {
865 111111111111111111;
866namespace test2 {
867 22222222222222222;
868}
869}
870
871/* invalid namespaces use block indent */
872namespace test test2 {
873 111111111111111111111;
874}
875namespace11111111111 {
876 111111111111;
877}
878namespace() {
879 1111111111111;
880}
881namespace()
882{
883 111111111111111111;
884}
885namespace test test2
886{
887 1111111111111111111;
888}
889namespace111111111
890{
891 111111111111111111;
892}
893
Bram Moolenaar071d4272004-06-13 20:20:40 +0000894/* end of AUTO */
895
896STARTTEST
897:set tw=0 wm=60 columns=80 noai fo=croq
898/serious/e
899a about life, the universe, and the rest
900ENDTEST
901
902{
903
904/* this is
905 * a real serious important big
906 * comment
907 */
908 /* insert " about life, the universe, and the rest" after "serious" */
909}
910
911STARTTEST
912:set nocin
913/comments
914joabout life/happens
915jothere/below
916oline/this
917Ohello
918ENDTEST
919
920{
921 /*
922 * Testing for comments, without 'cin' set
923 */
924
925/*
926* what happens here?
927*/
928
929 /*
930 the end of the comment, try inserting a line below */
931
932 /* how about
933 this one */
934}
935
936STARTTEST
937:set cin
938/vec2
939==
940ENDTEST
941
942{
943 var = this + that + vec[0] * vec[0]
944 + vec[1] * vec[1]
945 + vec2[2] * vec[2];
946}
947
948STARTTEST
949:set cin
950:set cino=}4
951/testing1
952k2==/testing2
953k2==
954ENDTEST
955
956{
957 asdf asdflkajds f;
958 if (tes & ting) {
959 asdf asdf asdf ;
960 asdfa sdf asdf;
961 }
962 testing1;
963 if (tes & ting)
964 {
965 asdf asdf asdf ;
966 asdfa sdf asdf;
967 }
968 testing2;
969}
970
971STARTTEST
972:set cin
973:set cino=(0,)20
974/main
975=][
976ENDTEST
977
978main ( int first_par, /*
979 * Comment for
980 * first par
981 */
982 int second_par /*
983 * Comment for
984 * second par
985 */
986 )
987{
988 func( first_par, /*
989 * Comment for
990 * first par
991 */
992 second_par /*
993 * Comment for
994 * second par
995 */
996 );
997
998}
999
1000STARTTEST
1001:set cin
Bram Moolenaar48d27922012-06-13 13:40:48 +02001002:set cino=es,n0s
1003/main
1004=][
1005ENDTEST
1006
1007main(void)
1008{
1009 /* Make sure that cino=X0s is not parsed like cino=Xs. */
1010 if (cond)
1011 foo();
1012 else
1013 {
1014 bar();
1015 }
1016}
1017
1018STARTTEST
1019:set cin
Bram Moolenaar071d4272004-06-13 20:20:40 +00001020:set cino=
1021]]=][
1022ENDTEST
1023
1024{
1025 do
1026 {
1027 if ()
1028 {
1029 if ()
1030 asdf;
1031 else
1032 asdf;
1033 }
1034 } while ();
1035 cmd; /* this should go under the } */
1036}
1037
1038STARTTEST
1039]]=][
1040ENDTEST
1041
1042void f()
1043{
1044 if ( k() ) {
1045 l();
1046
1047 } else { /* Start (two words) end */
1048 m();
1049 }
1050
1051 n();
1052}
1053
1054STARTTEST
1055:set cino={s,e-s
1056]]=][
1057ENDTEST
1058
1059void f()
1060{
1061 if ( k() )
1062 {
1063 l();
1064 } else { /* Start (two words) end */
1065 m();
1066 }
1067 n(); /* should be under the if () */
1068}
1069
1070STARTTEST
1071:set cino={s,fs
1072]]=/ foo
1073ENDTEST
1074
1075void bar(void)
1076{
1077 static array[2][2] =
1078 {
1079 { 1, 2 },
1080 { 3, 4 },
1081 }
1082
1083 while (a)
1084 {
1085 foo(&a);
1086 }
1087
1088 {
1089 int a;
1090 {
1091 a = a + 1;
1092 }
1093 }
1094 b = a;
1095 }
1096
1097void func(void)
1098 {
1099 a = 1;
1100 {
1101 b = 2;
1102 }
1103 c = 3;
1104 d = 4;
1105 }
1106/* foo */
1107
1108STARTTEST
1109:set cino=
1110/while
1111ohere
1112ENDTEST
1113
1114a()
1115{
1116 do {
1117 a = a +
1118 a;
1119 } while ( a ); /* add text under this line */
1120 if ( a )
1121 a;
1122}
1123
1124STARTTEST
1125:set cino= com=
1126/comment
1127olabel2: b(); label3 /* post */: /* pre */ label4: f(/*com*/); if (/*com*/) cmd();
1128ENDTEST
1129
1130a()
1131{
1132label1:
1133 /* hmm */
1134 // comment
1135}
1136
1137STARTTEST
1138:set comments& comments^=s:/*,m:**,ex:*/
1139/simple
1140=5j
1141ENDTEST
1142
1143/*
1144 * A simple comment
1145 */
1146
1147/*
1148 ** A different comment
1149 */
1150
1151STARTTEST
1152:set cino=c0
1153:set comments& comments-=s1:/* comments^=s0:/*
11542kdd]]=][
1155ENDTEST
1156
1157void f()
1158{
1159
1160 /*********
1161 A comment.
1162*********/
1163}
1164
1165STARTTEST
1166:set cino=c0,C1
1167:set comments& comments-=s1:/* comments^=s0:/*
11682kdd]]=][
1169ENDTEST
1170
1171void f()
1172{
1173
1174 /*********
1175 A comment.
1176*********/
1177}
1178
1179STARTTEST
1180:set cino=
1181]]=][
1182ENDTEST
1183
1184void f()
1185{
1186 c = c1 &&
1187 (
1188 c2 ||
1189 c3
1190 ) && c4;
1191}
1192
1193STARTTEST
1194:set cino=(s
11952kdd]]=][
1196ENDTEST
1197
1198void f()
1199{
1200 c = c1 &&
1201 (
1202 c2 ||
1203 c3
1204 ) && c4;
1205}
1206
1207STARTTEST
1208:set cino=(s,U1
12092kdd]]=][
1210ENDTEST
1211
1212void f()
1213{
1214 c = c1 &&
1215 (
1216 c2 ||
1217 c3
1218 ) && c4;
1219}
1220
1221STARTTEST
1222:set cino=(0
12232kdd]]=][
1224ENDTEST
1225
1226void f()
1227{
1228 if ( c1
1229 && ( c2
1230 || c3))
1231 foo;
1232}
1233
1234STARTTEST
1235:set cino=(0,w1
12362kdd]]=][
1237ENDTEST
1238
1239void f()
1240{
1241 if ( c1
1242 && ( c2
1243 || c3))
1244 foo;
1245}
1246
1247STARTTEST
1248:set cino=(s
12492kdd]]=][
1250ENDTEST
1251
1252void f()
1253{
1254 c = c1 && (
1255 c2 ||
1256 c3
1257 ) && c4;
1258 if (
1259 c1 && c2
1260 )
1261 foo;
1262}
1263
1264STARTTEST
1265:set cino=(s,m1
12662kdd]]=][
1267ENDTEST
1268
1269void f()
1270{
1271 c = c1 && (
1272 c2 ||
1273 c3
1274 ) && c4;
1275 if (
1276 c1 && c2
1277 )
1278 foo;
1279}
1280
1281STARTTEST
1282:set cino=b1
12832kdd]]=][
1284ENDTEST
1285
1286void f()
1287{
1288 switch (x)
1289 {
1290 case 1:
1291 a = b;
1292 break;
1293 default:
1294 a = 0;
1295 break;
1296 }
1297}
1298
1299STARTTEST
1300:set cino=(0,W5
13012kdd]]=][
1302ENDTEST
1303
1304void f()
1305{
1306 invokeme(
1307 argu,
1308 ment);
1309 invokeme(
1310 argu,
1311 ment
1312 );
1313 invokeme(argu,
1314 ment
1315 );
1316}
1317
1318STARTTEST
1319:set cino=/6
13202kdd]]=][
1321ENDTEST
1322
1323void f()
1324{
1325 statement;
1326 // comment 1
1327 // comment 2
1328}
1329
1330STARTTEST
1331:set cino=
13322kdd]]/comment 1/+1
1333==
1334ENDTEST
1335
1336void f()
1337{
1338 statement;
1339 // comment 1
1340 // comment 2
1341}
1342
1343STARTTEST
1344:set cino=g0
13452kdd]]=][
1346ENDTEST
1347
1348class CAbc
1349{
1350 int Test() { return FALSE; }
1351
1352public: // comment
1353 void testfall();
1354protected:
1355 void testfall();
1356};
1357
1358STARTTEST
Bram Moolenaare79d1532011-10-04 18:03:47 +02001359:set cino=(0,gs,hs
13602kdd]]=][
1361ENDTEST
1362
1363class Foo : public Bar
1364{
1365public:
1366virtual void method1(void) = 0;
1367virtual void method2(int arg1,
1368int arg2,
1369int arg3) = 0;
1370};
1371
1372STARTTEST
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00001373:set cino=+20
13742kdd]]=][
1375ENDTEST
1376
1377 void
1378foo()
1379{
1380 if (a)
1381 {
1382 } else
1383 asdf;
1384}
1385
1386STARTTEST
Bram Moolenaar071d4272004-06-13 20:20:40 +00001387:set cino=(0,W2s
13882kdd]]=][
1389ENDTEST
1390
1391{
1392 averylongfunctionnamelongfunctionnameaverylongfunctionname()->asd(
1393 asdasdf,
1394 func(asdf,
1395 asdfadsf),
1396 asdfasdf
1397 );
1398
1399 /* those are ugly, but consequent */
1400
1401 func()->asd(asdasdf,
1402 averylongfunctionname(
1403 abc,
1404 dec)->averylongfunctionname(
1405 asdfadsf,
1406 asdfasdf,
1407 asdfasdf,
1408 ),
1409 func(asdfadf,
1410 asdfasdf
1411 ),
1412 asdasdf
1413 );
1414
1415 averylongfunctionnameaverylongfunctionnameavery()->asd(fasdf(
1416 abc,
1417 dec)->asdfasdfasdf(
1418 asdfadsf,
1419 asdfasdf,
1420 asdfasdf,
1421 ),
1422 func(asdfadf,
1423 asdfasdf),
1424 asdasdf
1425 );
1426}
1427
1428STARTTEST
Bram Moolenaar9e54a0e2006-04-14 20:42:25 +00001429:set cino=M1
14302kdd]]=][
1431ENDTEST
1432
1433int main ()
1434{
1435 if (cond1 &&
1436 cond2
1437 )
1438 foo;
1439}
1440
1441STARTTEST
Bram Moolenaar8d2d71d2011-04-28 13:02:09 +02001442:set cino=(0,ts
Bram Moolenaar9f4fe7c2014-07-03 22:57:55 +020014432kdd2j=][
Bram Moolenaar8d2d71d2011-04-28 13:02:09 +02001444ENDTEST
1445
1446void func(int a
1447#if defined(FOO)
1448 , int b
1449 , int c
1450#endif
1451 )
1452{
1453}
1454
1455STARTTEST
1456:set cino=(0
Bram Moolenaar9f4fe7c2014-07-03 22:57:55 +020014572kdd2j=][
Bram Moolenaar8d2d71d2011-04-28 13:02:09 +02001458ENDTEST
1459
1460void
1461func(int a
1462#if defined(FOO)
1463 , int b
1464 , int c
1465#endif
1466 )
1467{
1468}
1469
1470STARTTEST
Bram Moolenaar4ae06c12011-05-10 11:39:19 +02001471:set cino&
Bram Moolenaar9f4fe7c2014-07-03 22:57:55 +020014722kdd2j=7][
Bram Moolenaar4ae06c12011-05-10 11:39:19 +02001473ENDTEST
1474
1475void func(void)
1476{
1477 if(x==y)
1478 if(y==z)
1479 foo=1;
1480 else { bar=1;
1481 baz=2;
1482 }
1483 printf("Foo!\n");
1484}
1485
Bram Moolenaar496f9512011-05-19 16:35:09 +02001486void func1(void)
1487{
1488 char* tab[] = {"foo", "bar",
1489 "baz", "quux",
1490 "this line used", "to be indented incorrectly"};
1491 foo();
1492}
1493
1494void func2(void)
1495{
1496 int tab[] =
1497 {1, 2,
1498 3, 4,
1499 5, 6};
1500
1501 printf("This line used to be indented incorrectly.\n");
1502}
1503
Bram Moolenaar3388bb42011-11-30 17:20:23 +01001504int foo[]
1505#ifdef BAR
1506
1507= { 1, 2, 3,
1508 4, 5, 6 }
1509
1510#endif
1511;
1512 int baz;
1513
Bram Moolenaar496f9512011-05-19 16:35:09 +02001514void func3(void)
1515{
1516 int tab[] = {
1517 1, 2,
1518 3, 4,
1519 5, 6};
1520
Bram Moolenaarc367faa2011-12-14 20:21:35 +01001521printf("Don't you dare indent this line incorrectly!\n");
1522}
1523
1524void
1525func4(a, b,
1526 c)
1527int a;
1528int b;
1529int c;
1530{
1531}
1532
1533void
1534func5(
1535 int a,
1536 int b)
1537{
1538}
1539
1540void
1541func6(
1542 int a)
1543{
Bram Moolenaar496f9512011-05-19 16:35:09 +02001544}
1545
Bram Moolenaar4ae06c12011-05-10 11:39:19 +02001546STARTTEST
Bram Moolenaaraede6ce2011-05-10 11:56:30 +02001547:set cino&
Bram Moolenaar50f42ca2011-07-15 14:12:30 +02001548:set cino+=l1
Bram Moolenaar9f4fe7c2014-07-03 22:57:55 +020015492kdd2j=][
Bram Moolenaar50f42ca2011-07-15 14:12:30 +02001550ENDTEST
1551
1552void func(void)
1553{
1554 int tab[] =
1555 {
1556 1, 2, 3,
1557 4, 5, 6};
1558
1559 printf("Indent this line correctly!\n");
1560
1561 switch (foo)
1562 {
1563 case bar:
1564 printf("bar");
1565 break;
1566 case baz: {
1567 printf("baz");
1568 break;
1569 }
1570 case quux:
1571printf("But don't break the indentation of this instruction\n");
1572break;
1573 }
1574}
1575
1576STARTTEST
1577:set cino&
Bram Moolenaar9f4fe7c2014-07-03 22:57:55 +020015782kdd2j=][
Bram Moolenaaraede6ce2011-05-10 11:56:30 +02001579ENDTEST
1580
1581void func(void)
1582{
1583 cout << "a"
1584 << "b"
1585 << ") :"
1586 << "c";
1587}
1588
1589STARTTEST
Bram Moolenaara4271d52011-05-10 13:38:27 +02001590:set com=s1:/*,m:*,ex:*/
1591]]3jofoo();
1592ENDTEST
1593
1594void func(void)
1595{
1596 /*
1597 * This is a comment.
1598 */
1599}
1600
1601STARTTEST
Bram Moolenaar334adf02011-05-25 13:34:04 +02001602:set cino&
Bram Moolenaar9f4fe7c2014-07-03 22:57:55 +020016032kdd2j=][
Bram Moolenaar334adf02011-05-25 13:34:04 +02001604ENDTEST
1605
1606void func(void)
1607{
1608 for (int i = 0; i < 10; ++i)
1609 if (i & 1) {
1610 foo(1);
1611 } else
1612 foo(0);
1613baz();
1614}
1615
1616STARTTEST
Bram Moolenaar3675fa02012-04-05 17:17:42 +02001617:set cino=k2s,(0
16182kdd3j=][
1619ENDTEST
1620
1621void func(void)
1622{
1623 if (condition1
1624 && condition2)
1625 action();
1626 function(argument1
1627 && argument2);
1628
1629 if (c1 && (c2 ||
1630 c3))
1631 foo;
1632 if (c1 &&
1633 (c2 || c3))
1634 {
1635 }
1636
1637 if ( c1
1638 && ( c2
1639 || c3))
1640 foo;
1641 func( c1
1642 && ( c2
1643 || c3))
1644 foo;
1645}
1646
1647STARTTEST
1648:set cino=k2s,(s
16492kdd3j=][
1650ENDTEST
1651
1652void func(void)
1653{
1654 if (condition1
1655 && condition2)
1656 action();
1657 function(argument1
1658 && argument2);
1659
1660 if (c1 && (c2 ||
1661 c3))
1662 foo;
1663 if (c1 &&
1664 (c2 || c3))
1665 {
1666 }
1667
1668 if ( c1
1669 && ( c2
1670 || c3))
1671 foo;
1672 func( c1
1673 && ( c2
1674 || c3))
1675 foo;
1676}
1677
1678STARTTEST
1679:set cino=k2s,(s,U1
16802kdd3j=][
1681ENDTEST
1682
1683void func(void)
1684{
1685 if (condition1
1686 && condition2)
1687 action();
1688 function(argument1
1689 && argument2);
1690
1691 if (c1 && (c2 ||
1692 c3))
1693 foo;
1694 if (c1 &&
1695 (c2 || c3))
1696 {
1697 }
1698 if (c123456789
1699 && (c22345
1700 || c3))
1701 printf("foo\n");
1702
1703 c = c1 &&
1704 (
1705 c2 ||
1706 c3
1707 ) && c4;
1708}
1709
1710STARTTEST
1711:set cino=k2s,(0,W4
17122kdd3j=][
1713ENDTEST
1714
1715void func(void)
1716{
1717 if (condition1
1718 && condition2)
1719 action();
1720 function(argument1
1721 && argument2);
1722
1723 if (c1 && (c2 ||
1724 c3))
1725 foo;
1726 if (c1 &&
1727 (c2 || c3))
1728 {
1729 }
1730 if (c123456789
1731 && (c22345
1732 || c3))
1733 printf("foo\n");
1734
1735 if ( c1
1736 && ( c2
1737 || c3))
1738 foo;
1739
1740 a_long_line(
1741 argument,
1742 argument);
1743 a_short_line(argument,
1744 argument);
1745}
1746
1747STARTTEST
1748:set cino=k2s,u2
17492kdd3j=][
1750ENDTEST
1751
1752void func(void)
1753{
1754 if (condition1
1755 && condition2)
1756 action();
1757 function(argument1
1758 && argument2);
1759
1760 if (c1 && (c2 ||
1761 c3))
1762 foo;
1763 if (c1 &&
1764 (c2 || c3))
1765 {
1766 }
1767 if (c123456789
1768 && (c22345
1769 || c3))
1770 printf("foo\n");
1771}
1772
1773STARTTEST
1774:set cino=k2s,(0,w1
17752kdd3j=][
1776ENDTEST
1777
1778void func(void)
1779{
1780 if (condition1
1781 && condition2)
1782 action();
1783 function(argument1
1784 && argument2);
1785
1786 if (c1 && (c2 ||
1787 c3))
1788 foo;
1789 if (c1 &&
1790 (c2 || c3))
1791 {
1792 }
1793 if (c123456789
1794 && (c22345
1795 || c3))
1796 printf("foo\n");
1797
1798 if ( c1
1799 && ( c2
1800 || c3))
1801 foo;
1802 func( c1
1803 && ( c2
1804 || c3))
1805 foo;
1806}
1807
1808STARTTEST
1809:set cino=k2,(s
18102kdd3j=][
1811ENDTEST
1812
1813void func(void)
1814{
1815 if (condition1
1816 && condition2)
1817 action();
1818 function(argument1
1819 && argument2);
1820
1821 if (c1 && (c2 ||
1822 c3))
1823 foo;
1824 if (c1 &&
1825 (c2 || c3))
1826 {
1827 }
1828}
1829
1830STARTTEST
Bram Moolenaared38b0a2011-05-25 15:16:18 +02001831:set cino=N-s
Bram Moolenaar6ec154b2011-06-12 21:51:08 +02001832/^NAMESPACESTART
Bram Moolenaared38b0a2011-05-25 15:16:18 +02001833=/^NAMESPACEEND
1834ENDTEST
1835
Bram Moolenaar6ec154b2011-06-12 21:51:08 +02001836NAMESPACESTART
Bram Moolenaared38b0a2011-05-25 15:16:18 +02001837/* valid namespaces with normal indent */
1838namespace
1839{
1840 {
1841 111111111111;
1842}
1843}
1844namespace /* test */
1845{
1846 11111111111111111;
1847}
1848namespace // test
1849{
1850 111111111111111111;
1851}
1852namespace
1853{
1854 111111111111111111;
1855}
1856namespace test
1857{
1858 111111111111111111;
1859}
1860namespace{
1861 111111111111111111;
1862}
1863namespace test{
1864 111111111111111111;
1865}
1866namespace {
1867 111111111111111111;
1868}
1869namespace test {
1870 111111111111111111;
1871namespace test2 {
1872 22222222222222222;
1873}
1874}
1875
1876/* invalid namespaces use block indent */
1877namespace test test2 {
1878 111111111111111111111;
1879}
1880namespace11111111111 {
1881 111111111111;
1882}
1883namespace() {
1884 1111111111111;
1885}
1886namespace()
1887{
1888 111111111111111111;
1889}
1890namespace test test2
1891{
1892 1111111111111111111;
1893}
1894namespace111111111
1895{
1896 111111111111111111;
1897}
1898NAMESPACEEND
1899
1900
1901STARTTEST
Bram Moolenaar76f7fd32011-07-20 15:09:43 +02001902:set cino=j1,J1
Bram Moolenaar6ec154b2011-06-12 21:51:08 +02001903/^JSSTART
1904=/^JSEND
1905ENDTEST
1906
1907JSSTART
1908var bar = {
1909foo: {
1910that: this,
1911some: ok,
1912},
1913"bar":{
1914a : 2,
1915b: "123abc",
1916x: 4,
1917"y": 5
1918}
1919}
1920JSEND
1921
1922STARTTEST
Bram Moolenaar76f7fd32011-07-20 15:09:43 +02001923:set cino=j1,J1
1924/^JSSTART
1925=/^JSEND
1926ENDTEST
1927
1928JSSTART
1929var foo = [
Bram Moolenaar9f4fe7c2014-07-03 22:57:55 +020019301,
Bram Moolenaar76f7fd32011-07-20 15:09:43 +020019312,
19323
Bram Moolenaar9f4fe7c2014-07-03 22:57:55 +02001933];
Bram Moolenaar76f7fd32011-07-20 15:09:43 +02001934JSEND
1935
1936STARTTEST
1937:set cino=j1,J1
1938/^JSSTART
1939=/^JSEND
1940ENDTEST
1941
1942JSSTART
1943function bar() {
1944var foo = [
19451,
19462,
19473
Bram Moolenaar9f4fe7c2014-07-03 22:57:55 +02001948];
Bram Moolenaar76f7fd32011-07-20 15:09:43 +02001949}
1950JSEND
1951
1952STARTTEST
1953:set cino=j1,J1
1954/^JSSTART
1955=/^JSEND
1956ENDTEST
1957
1958JSSTART
1959(function($){
1960
Bram Moolenaar81439a62014-07-02 18:27:48 +02001961if (cond &&
1962cond) {
1963stmt;
1964}
Bram Moolenaar9f4fe7c2014-07-03 22:57:55 +02001965window.something.left =
1966(width - 50 + offset) + "px";
Bram Moolenaar76f7fd32011-07-20 15:09:43 +02001967var class_name='myclass';
1968
1969function private_method() {
1970}
1971
1972var public_method={
1973method: function(options,args){
1974private_method();
1975}
1976}
1977
1978function init(options) {
1979
1980$(this).data(class_name+'_public',$.extend({},{
1981foo: 'bar',
Bram Moolenaar9f4fe7c2014-07-03 22:57:55 +02001982bar: 2,
1983foobar: [
19841,
19852,
19863
Bram Moolenaar76f7fd32011-07-20 15:09:43 +02001987],
Bram Moolenaar9f4fe7c2014-07-03 22:57:55 +02001988callback: function(){
1989return true;
1990}
Bram Moolenaar76f7fd32011-07-20 15:09:43 +02001991}, options||{}));
1992}
1993
1994$.fn[class_name]=function() {
1995
1996var _arguments=arguments;
1997return this.each(function(){
1998
1999var options=$(this).data(class_name+'_public');
2000if (!options) {
2001init.apply(this,_arguments);
2002
2003} else {
2004var method=public_method[_arguments[0]];
2005
2006if (typeof(method)!='function') {
2007console.log(class_name+' has no method "'+_arguments[0]+'"');
2008return false;
2009}
2010_arguments[0]=options;
2011method.apply(this,_arguments);
2012}
2013});
2014}
2015
2016})(jQuery);
2017JSEND
2018
2019STARTTEST
2020:set cino=j1,J1
2021/^JSSTART
2022=/^JSEND
2023ENDTEST
2024
2025JSSTART
2026function init(options) {
2027$(this).data(class_name+'_public',$.extend({},{
2028foo: 'bar',
2029bar: 2,
2030foobar: [
Bram Moolenaar9f4fe7c2014-07-03 22:57:55 +020020311,
20322,
20333
Bram Moolenaar76f7fd32011-07-20 15:09:43 +02002034],
2035callback: function(){
2036return true;
2037}
2038}, options||{}));
2039}
2040JSEND
2041
2042STARTTEST
2043:set cino=j1,J1
2044/^JSSTART
2045=/^JSEND
2046ENDTEST
2047
2048JSSTART
2049(function($){
2050function init(options) {
2051$(this).data(class_name+'_public',$.extend({},{
2052foo: 'bar',
Bram Moolenaar9f4fe7c2014-07-03 22:57:55 +02002053bar: 2,
2054foobar: [
20551,
20562,
20573
Bram Moolenaar76f7fd32011-07-20 15:09:43 +02002058],
Bram Moolenaar9f4fe7c2014-07-03 22:57:55 +02002059callback: function(){
2060return true;
2061}
Bram Moolenaar76f7fd32011-07-20 15:09:43 +02002062}, options||{}));
2063}
2064})(jQuery);
2065JSEND
2066
2067STARTTEST
Bram Moolenaar071d4272004-06-13 20:20:40 +00002068:g/^STARTTEST/.,/^ENDTEST/d
2069:1;/start of AUTO/,$wq! test.out
2070ENDTEST