blob: abb7750f82a37b713928b87e9cfa0f9e20543ad8 [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 Moolenaar071d4272004-06-13 20:20:40 +0000321{
322 int a,
323 b;
324}
325
326{
327 struct Type
328 {
329 int i;
330 char *str;
331 } var[] =
332 {
333 0, "zero",
334 1, "one",
335 2, "two",
336 3, "three"
337 };
338
339 float matrix[3][3] =
340 {
341 {
342 0,
343 1,
344 2
345 },
346 {
347 3,
348 4,
349 5
350 },
351 {
352 6,
353 7,
354 8
355 }
356 };
357}
358
359{
360 /* blah ( blah */
361 /* where does this go? */
362
363 /* blah ( blah */
364 cmd;
365
366 func(arg1,
367 /* comment */
368 arg2);
369 a;
370 {
371 b;
372 {
373 c; /* Hey, NOW it indents?! */
374 }
375 }
376
377 {
378 func(arg1,
379 arg2,
380 arg3);
381 /* Hey, what am I doing here? Is this coz of the ","? */
382 }
383}
384
385main ()
386{
387 if (cond)
388 {
389 a = b;
390 }
391 if (cond) {
392 a = c;
393 }
394 if (cond)
395 a = d;
396 return;
397}
398
399{
400 case 2: if (asdf &&
401 asdfasdf)
402 aasdf;
403 a = 9;
404 case 3: if (asdf)
405 aasdf;
406 a = 9;
407 case 4: x = 1;
408 y = 2;
409
410label: if (asdf)
411 here;
412
413label: if (asdf &&
414 asdfasdf)
415 {
416 }
417
418label: if (asdf &&
419 asdfasdf) {
420 there;
421 }
422
423label: if (asdf &&
424 asdfasdf)
425 there;
426}
427
428{
429 /*
430 hello with ":set comments= cino=c5"
431 */
432
433 /*
434 hello with ":set comments= cino="
435 */
436}
437
438
439{
440 if (a < b) {
441 a = a + 1;
442 } else
443 a = a + 2;
444
445 if (a)
446 do {
447 testing;
448 } while (asdfasdf);
449 a = b + 1;
450 asdfasdf
451}
452
453class bob
454{
455 int foo() {return 1;}
456 int bar;
457}
458
459main()
460{
461while(1)
462if (foo)
463{
464bar;
465}
466else {
467asdf;
468}
469misplacedline;
470}
471
472{
473 if (clipboard.state == SELECT_DONE
474 && ((row == clipboard.start.lnum
475 && col >= clipboard.start.col)
476 || row > clipboard.start.lnum))
477}
478
479{
480if (1) {i += 4;}
481where_am_i;
482return 0;
483}
484
485{
486{
487} // sdf(asdf
488if (asdf)
489asd;
490}
491
492{
493label1:
494label2:
495}
496
497{
498int fooRet = foo(pBar1, false /*fKB*/,
499 true /*fPTB*/, 3 /*nT*/, false /*fDF*/);
500f() {
501for ( i = 0;
502 i < m;
503 /* c */ i++ ) {
504a = b;
505}
506}
507}
508
509{
510 f1(/*comment*/);
511 f2();
512}
513
514{
515do {
516if (foo) {
517} else
518;
519} while (foo);
520foo(); // was wrong
521}
522
523int x; // no extra indent because of the ;
524void func()
525{
526}
527
528char *tab[] = {"aaa",
529 "};", /* }; */ NULL}
530 int indented;
531{}
532
533char *a[] = {"aaa", "bbb",
534 "ccc", NULL};
535// here
536
537char *tab[] = {"aaa",
538 "xx", /* xx */}; /* asdf */
539int not_indented;
540
541{
542 do {
543 switch (bla)
544 {
545 case 1: if (foo)
546 bar;
547 }
548 } while (boo);
549 wrong;
550}
551
552int foo,
553 bar;
554int foo;
555
556#if defined(foo) \
557 && defined(bar)
558char * xx = "asdf\
559 foo\
560 bor";
561int x;
562
563char *foo = "asdf\
564 asdf\
565 asdf",
566 *bar;
567
568void f()
569{
570#if defined(foo) \
571 && defined(bar)
572char *foo = "asdf\
573 asdf\
574 asdf",
575 *bar;
576 {
577 int i;
578char *foo = "asdf\
579 asdf\
580 asdf",
581 *bar;
582 }
583#endif
584}
585#endif
586
587int y; // comment
588 // comment
589
590 // comment
591
592{
593 Constructor(int a,
594 int b ) : BaseClass(a)
595 {
596 }
597}
598
599void foo()
600{
601 char one,
602 two;
603 struct bla piet,
604 jan;
605 enum foo kees,
606 jannie;
607 static unsigned sdf,
608 krap;
609 unsigned int piet,
610 jan;
611 int
612 kees,
613 jan;
614}
615
616{
617 t(int f,
618 int d); // )
619 d();
620}
621
622Constructor::Constructor(int a,
623 int b
624 ) :
625 BaseClass(a,
626 b,
627 c),
628 mMember(b),
629{
630}
631
632Constructor::Constructor(int a,
633 int b ) :
634 BaseClass(a)
635{
636}
637
638Constructor::Constructor(int a,
639 int b ) /*x*/ : /*x*/ BaseClass(a),
640 member(b)
641{
642}
643
644class CAbc :
645 public BaseClass1,
646 protected BaseClass2
647{
648 int Test() { return FALSE; }
649 int Test1() { return TRUE; }
650
651 CAbc(int a, int b ) :
652 BaseClass(a)
653 {
654 switch(xxx)
655 {
656 case abc:
657 asdf();
658 break;
659
660 case 999:
661 baer();
662 break;
663 }
664 }
665
666public: // <-- this was incoreectly indented before!!
667 void testfall();
668protected:
669 void testfall();
670};
671
672class CAbc : public BaseClass1,
673 protected BaseClass2
674{
675};
676
677static struct
678{
679 int a;
680 int b;
681} variable[COUNT] =
682{
683 {
684 123,
685 456
686 },
687 {
688 123,
689 456
690 }
691};
692
693static struct
694{
695 int a;
696 int b;
697} variable[COUNT] =
698{
699 { 123, 456 },
700 { 123, 456 }
701};
702
703void asdf() /* ind_maxparen may cause trouble here */
704{
705 if ((0
706 && 1
707 && 1
708 && 1
709 && 1
710 && 1
711 && 1
712 && 1
713 && 1
714 && 1
715 && 1
716 && 1
717 && 1
718 && 1
719 && 1
720 && 1
721 && 1
722 && 1
723 && 1
724 && 1
725 && 1
726 && 1
727 && 1
728 && 1
729 && 1
730 && 1)) break;
731}
732
Bram Moolenaar18144c82006-04-12 21:52:12 +0000733foo()
734{
735 a = cond ? foo() : asdf
736 + asdf;
737
738 a = cond ?
739 foo() : asdf
740 + asdf;
741}
742
743int main(void)
744{
745 if (a)
746 if (b)
747 2;
748 else 3;
749 next_line_of_code();
750}
751
Bram Moolenaar7fc904b2006-04-13 20:37:35 +0000752barry()
753{
754 Foo::Foo (int one,
755 int two)
756 : something(4)
757 {}
758}
759
760barry()
761{
762 Foo::Foo (int one, int two)
763 : something(4)
764 {}
765}
766
767Constructor::Constructor(int a,
768 int b
769 ) :
770 BaseClass(a,
771 b,
772 c),
773 mMember(b)
774{
775}
Bram Moolenaar9e54a0e2006-04-14 20:42:25 +0000776 int main ()
777 {
778 if (lala)
779 do
780 ++(*lolo);
781 while (lili
782 && lele);
783 lulu;
784 }
Bram Moolenaar7fc904b2006-04-13 20:37:35 +0000785
Bram Moolenaar9e54a0e2006-04-14 20:42:25 +0000786int main ()
787{
788switch (c)
789{
790case 'c': if (cond)
791{
792}
793}
794}
795
796main()
797{
798 (void) MyFancyFuasdfadsfnction(
799 argument);
800}
801
802main()
803{
804 char foo[] = "/*";
805 /* as
806 df */
807 hello
808}
Bram Moolenaared38b0a2011-05-25 15:16:18 +0200809
810/* valid namespaces with normal indent */
811namespace
812{
813{
814 111111111111;
815}
816}
817namespace /* test */
818{
819 11111111111111111;
820}
821namespace // test
822{
823 111111111111111111;
824}
825namespace
826{
827 111111111111111111;
828}
829namespace test
830{
831 111111111111111111;
832}
833namespace{
834 111111111111111111;
835}
836namespace test{
837 111111111111111111;
838}
839namespace {
840 111111111111111111;
841}
842namespace test {
843 111111111111111111;
844namespace test2 {
845 22222222222222222;
846}
847}
848
849/* invalid namespaces use block indent */
850namespace test test2 {
851 111111111111111111111;
852}
853namespace11111111111 {
854 111111111111;
855}
856namespace() {
857 1111111111111;
858}
859namespace()
860{
861 111111111111111111;
862}
863namespace test test2
864{
865 1111111111111111111;
866}
867namespace111111111
868{
869 111111111111111111;
870}
871
Bram Moolenaar071d4272004-06-13 20:20:40 +0000872/* end of AUTO */
873
874STARTTEST
875:set tw=0 wm=60 columns=80 noai fo=croq
876/serious/e
877a about life, the universe, and the rest
878ENDTEST
879
880{
881
882/* this is
883 * a real serious important big
884 * comment
885 */
886 /* insert " about life, the universe, and the rest" after "serious" */
887}
888
889STARTTEST
890:set nocin
891/comments
892joabout life/happens
893jothere/below
894oline/this
895Ohello
896ENDTEST
897
898{
899 /*
900 * Testing for comments, without 'cin' set
901 */
902
903/*
904* what happens here?
905*/
906
907 /*
908 the end of the comment, try inserting a line below */
909
910 /* how about
911 this one */
912}
913
914STARTTEST
915:set cin
916/vec2
917==
918ENDTEST
919
920{
921 var = this + that + vec[0] * vec[0]
922 + vec[1] * vec[1]
923 + vec2[2] * vec[2];
924}
925
926STARTTEST
927:set cin
928:set cino=}4
929/testing1
930k2==/testing2
931k2==
932ENDTEST
933
934{
935 asdf asdflkajds f;
936 if (tes & ting) {
937 asdf asdf asdf ;
938 asdfa sdf asdf;
939 }
940 testing1;
941 if (tes & ting)
942 {
943 asdf asdf asdf ;
944 asdfa sdf asdf;
945 }
946 testing2;
947}
948
949STARTTEST
950:set cin
951:set cino=(0,)20
952/main
953=][
954ENDTEST
955
956main ( int first_par, /*
957 * Comment for
958 * first par
959 */
960 int second_par /*
961 * Comment for
962 * second par
963 */
964 )
965{
966 func( first_par, /*
967 * Comment for
968 * first par
969 */
970 second_par /*
971 * Comment for
972 * second par
973 */
974 );
975
976}
977
978STARTTEST
979:set cin
Bram Moolenaar48d27922012-06-13 13:40:48 +0200980:set cino=es,n0s
981/main
982=][
983ENDTEST
984
985main(void)
986{
987 /* Make sure that cino=X0s is not parsed like cino=Xs. */
988 if (cond)
989 foo();
990 else
991 {
992 bar();
993 }
994}
995
996STARTTEST
997:set cin
Bram Moolenaar071d4272004-06-13 20:20:40 +0000998:set cino=
999]]=][
1000ENDTEST
1001
1002{
1003 do
1004 {
1005 if ()
1006 {
1007 if ()
1008 asdf;
1009 else
1010 asdf;
1011 }
1012 } while ();
1013 cmd; /* this should go under the } */
1014}
1015
1016STARTTEST
1017]]=][
1018ENDTEST
1019
1020void f()
1021{
1022 if ( k() ) {
1023 l();
1024
1025 } else { /* Start (two words) end */
1026 m();
1027 }
1028
1029 n();
1030}
1031
1032STARTTEST
1033:set cino={s,e-s
1034]]=][
1035ENDTEST
1036
1037void f()
1038{
1039 if ( k() )
1040 {
1041 l();
1042 } else { /* Start (two words) end */
1043 m();
1044 }
1045 n(); /* should be under the if () */
1046}
1047
1048STARTTEST
1049:set cino={s,fs
1050]]=/ foo
1051ENDTEST
1052
1053void bar(void)
1054{
1055 static array[2][2] =
1056 {
1057 { 1, 2 },
1058 { 3, 4 },
1059 }
1060
1061 while (a)
1062 {
1063 foo(&a);
1064 }
1065
1066 {
1067 int a;
1068 {
1069 a = a + 1;
1070 }
1071 }
1072 b = a;
1073 }
1074
1075void func(void)
1076 {
1077 a = 1;
1078 {
1079 b = 2;
1080 }
1081 c = 3;
1082 d = 4;
1083 }
1084/* foo */
1085
1086STARTTEST
1087:set cino=
1088/while
1089ohere
1090ENDTEST
1091
1092a()
1093{
1094 do {
1095 a = a +
1096 a;
1097 } while ( a ); /* add text under this line */
1098 if ( a )
1099 a;
1100}
1101
1102STARTTEST
1103:set cino= com=
1104/comment
1105olabel2: b(); label3 /* post */: /* pre */ label4: f(/*com*/); if (/*com*/) cmd();
1106ENDTEST
1107
1108a()
1109{
1110label1:
1111 /* hmm */
1112 // comment
1113}
1114
1115STARTTEST
1116:set comments& comments^=s:/*,m:**,ex:*/
1117/simple
1118=5j
1119ENDTEST
1120
1121/*
1122 * A simple comment
1123 */
1124
1125/*
1126 ** A different comment
1127 */
1128
1129STARTTEST
1130:set cino=c0
1131:set comments& comments-=s1:/* comments^=s0:/*
11322kdd]]=][
1133ENDTEST
1134
1135void f()
1136{
1137
1138 /*********
1139 A comment.
1140*********/
1141}
1142
1143STARTTEST
1144:set cino=c0,C1
1145:set comments& comments-=s1:/* comments^=s0:/*
11462kdd]]=][
1147ENDTEST
1148
1149void f()
1150{
1151
1152 /*********
1153 A comment.
1154*********/
1155}
1156
1157STARTTEST
1158:set cino=
1159]]=][
1160ENDTEST
1161
1162void f()
1163{
1164 c = c1 &&
1165 (
1166 c2 ||
1167 c3
1168 ) && c4;
1169}
1170
1171STARTTEST
1172:set cino=(s
11732kdd]]=][
1174ENDTEST
1175
1176void f()
1177{
1178 c = c1 &&
1179 (
1180 c2 ||
1181 c3
1182 ) && c4;
1183}
1184
1185STARTTEST
1186:set cino=(s,U1
11872kdd]]=][
1188ENDTEST
1189
1190void f()
1191{
1192 c = c1 &&
1193 (
1194 c2 ||
1195 c3
1196 ) && c4;
1197}
1198
1199STARTTEST
1200:set cino=(0
12012kdd]]=][
1202ENDTEST
1203
1204void f()
1205{
1206 if ( c1
1207 && ( c2
1208 || c3))
1209 foo;
1210}
1211
1212STARTTEST
1213:set cino=(0,w1
12142kdd]]=][
1215ENDTEST
1216
1217void f()
1218{
1219 if ( c1
1220 && ( c2
1221 || c3))
1222 foo;
1223}
1224
1225STARTTEST
1226:set cino=(s
12272kdd]]=][
1228ENDTEST
1229
1230void f()
1231{
1232 c = c1 && (
1233 c2 ||
1234 c3
1235 ) && c4;
1236 if (
1237 c1 && c2
1238 )
1239 foo;
1240}
1241
1242STARTTEST
1243:set cino=(s,m1
12442kdd]]=][
1245ENDTEST
1246
1247void f()
1248{
1249 c = c1 && (
1250 c2 ||
1251 c3
1252 ) && c4;
1253 if (
1254 c1 && c2
1255 )
1256 foo;
1257}
1258
1259STARTTEST
1260:set cino=b1
12612kdd]]=][
1262ENDTEST
1263
1264void f()
1265{
1266 switch (x)
1267 {
1268 case 1:
1269 a = b;
1270 break;
1271 default:
1272 a = 0;
1273 break;
1274 }
1275}
1276
1277STARTTEST
1278:set cino=(0,W5
12792kdd]]=][
1280ENDTEST
1281
1282void f()
1283{
1284 invokeme(
1285 argu,
1286 ment);
1287 invokeme(
1288 argu,
1289 ment
1290 );
1291 invokeme(argu,
1292 ment
1293 );
1294}
1295
1296STARTTEST
1297:set cino=/6
12982kdd]]=][
1299ENDTEST
1300
1301void f()
1302{
1303 statement;
1304 // comment 1
1305 // comment 2
1306}
1307
1308STARTTEST
1309:set cino=
13102kdd]]/comment 1/+1
1311==
1312ENDTEST
1313
1314void f()
1315{
1316 statement;
1317 // comment 1
1318 // comment 2
1319}
1320
1321STARTTEST
1322:set cino=g0
13232kdd]]=][
1324ENDTEST
1325
1326class CAbc
1327{
1328 int Test() { return FALSE; }
1329
1330public: // comment
1331 void testfall();
1332protected:
1333 void testfall();
1334};
1335
1336STARTTEST
Bram Moolenaare79d1532011-10-04 18:03:47 +02001337:set cino=(0,gs,hs
13382kdd]]=][
1339ENDTEST
1340
1341class Foo : public Bar
1342{
1343public:
1344virtual void method1(void) = 0;
1345virtual void method2(int arg1,
1346int arg2,
1347int arg3) = 0;
1348};
1349
1350STARTTEST
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00001351:set cino=+20
13522kdd]]=][
1353ENDTEST
1354
1355 void
1356foo()
1357{
1358 if (a)
1359 {
1360 } else
1361 asdf;
1362}
1363
1364STARTTEST
Bram Moolenaar071d4272004-06-13 20:20:40 +00001365:set cino=(0,W2s
13662kdd]]=][
1367ENDTEST
1368
1369{
1370 averylongfunctionnamelongfunctionnameaverylongfunctionname()->asd(
1371 asdasdf,
1372 func(asdf,
1373 asdfadsf),
1374 asdfasdf
1375 );
1376
1377 /* those are ugly, but consequent */
1378
1379 func()->asd(asdasdf,
1380 averylongfunctionname(
1381 abc,
1382 dec)->averylongfunctionname(
1383 asdfadsf,
1384 asdfasdf,
1385 asdfasdf,
1386 ),
1387 func(asdfadf,
1388 asdfasdf
1389 ),
1390 asdasdf
1391 );
1392
1393 averylongfunctionnameaverylongfunctionnameavery()->asd(fasdf(
1394 abc,
1395 dec)->asdfasdfasdf(
1396 asdfadsf,
1397 asdfasdf,
1398 asdfasdf,
1399 ),
1400 func(asdfadf,
1401 asdfasdf),
1402 asdasdf
1403 );
1404}
1405
1406STARTTEST
Bram Moolenaar9e54a0e2006-04-14 20:42:25 +00001407:set cino=M1
14082kdd]]=][
1409ENDTEST
1410
1411int main ()
1412{
1413 if (cond1 &&
1414 cond2
1415 )
1416 foo;
1417}
1418
1419STARTTEST
Bram Moolenaar8d2d71d2011-04-28 13:02:09 +02001420:set cino=(0,ts
14212kdd=][
1422ENDTEST
1423
1424void func(int a
1425#if defined(FOO)
1426 , int b
1427 , int c
1428#endif
1429 )
1430{
1431}
1432
1433STARTTEST
1434:set cino=(0
14352kdd=][
1436ENDTEST
1437
1438void
1439func(int a
1440#if defined(FOO)
1441 , int b
1442 , int c
1443#endif
1444 )
1445{
1446}
1447
1448STARTTEST
Bram Moolenaar4ae06c12011-05-10 11:39:19 +02001449:set cino&
Bram Moolenaarc367faa2011-12-14 20:21:35 +010014502kdd=7][
Bram Moolenaar4ae06c12011-05-10 11:39:19 +02001451ENDTEST
1452
1453void func(void)
1454{
1455 if(x==y)
1456 if(y==z)
1457 foo=1;
1458 else { bar=1;
1459 baz=2;
1460 }
1461 printf("Foo!\n");
1462}
1463
Bram Moolenaar496f9512011-05-19 16:35:09 +02001464void func1(void)
1465{
1466 char* tab[] = {"foo", "bar",
1467 "baz", "quux",
1468 "this line used", "to be indented incorrectly"};
1469 foo();
1470}
1471
1472void func2(void)
1473{
1474 int tab[] =
1475 {1, 2,
1476 3, 4,
1477 5, 6};
1478
1479 printf("This line used to be indented incorrectly.\n");
1480}
1481
Bram Moolenaar3388bb42011-11-30 17:20:23 +01001482int foo[]
1483#ifdef BAR
1484
1485= { 1, 2, 3,
1486 4, 5, 6 }
1487
1488#endif
1489;
1490 int baz;
1491
Bram Moolenaar496f9512011-05-19 16:35:09 +02001492void func3(void)
1493{
1494 int tab[] = {
1495 1, 2,
1496 3, 4,
1497 5, 6};
1498
Bram Moolenaarc367faa2011-12-14 20:21:35 +01001499printf("Don't you dare indent this line incorrectly!\n");
1500}
1501
1502void
1503func4(a, b,
1504 c)
1505int a;
1506int b;
1507int c;
1508{
1509}
1510
1511void
1512func5(
1513 int a,
1514 int b)
1515{
1516}
1517
1518void
1519func6(
1520 int a)
1521{
Bram Moolenaar496f9512011-05-19 16:35:09 +02001522}
1523
Bram Moolenaar4ae06c12011-05-10 11:39:19 +02001524STARTTEST
Bram Moolenaaraede6ce2011-05-10 11:56:30 +02001525:set cino&
Bram Moolenaar50f42ca2011-07-15 14:12:30 +02001526:set cino+=l1
15272kdd=][
1528ENDTEST
1529
1530void func(void)
1531{
1532 int tab[] =
1533 {
1534 1, 2, 3,
1535 4, 5, 6};
1536
1537 printf("Indent this line correctly!\n");
1538
1539 switch (foo)
1540 {
1541 case bar:
1542 printf("bar");
1543 break;
1544 case baz: {
1545 printf("baz");
1546 break;
1547 }
1548 case quux:
1549printf("But don't break the indentation of this instruction\n");
1550break;
1551 }
1552}
1553
1554STARTTEST
1555:set cino&
Bram Moolenaaraede6ce2011-05-10 11:56:30 +020015562kdd=][
1557ENDTEST
1558
1559void func(void)
1560{
1561 cout << "a"
1562 << "b"
1563 << ") :"
1564 << "c";
1565}
1566
1567STARTTEST
Bram Moolenaara4271d52011-05-10 13:38:27 +02001568:set com=s1:/*,m:*,ex:*/
1569]]3jofoo();
1570ENDTEST
1571
1572void func(void)
1573{
1574 /*
1575 * This is a comment.
1576 */
1577}
1578
1579STARTTEST
Bram Moolenaar334adf02011-05-25 13:34:04 +02001580:set cino&
15812kdd=][
1582ENDTEST
1583
1584void func(void)
1585{
1586 for (int i = 0; i < 10; ++i)
1587 if (i & 1) {
1588 foo(1);
1589 } else
1590 foo(0);
1591baz();
1592}
1593
1594STARTTEST
Bram Moolenaar3675fa02012-04-05 17:17:42 +02001595:set cino=k2s,(0
15962kdd3j=][
1597ENDTEST
1598
1599void func(void)
1600{
1601 if (condition1
1602 && condition2)
1603 action();
1604 function(argument1
1605 && argument2);
1606
1607 if (c1 && (c2 ||
1608 c3))
1609 foo;
1610 if (c1 &&
1611 (c2 || c3))
1612 {
1613 }
1614
1615 if ( c1
1616 && ( c2
1617 || c3))
1618 foo;
1619 func( c1
1620 && ( c2
1621 || c3))
1622 foo;
1623}
1624
1625STARTTEST
1626:set cino=k2s,(s
16272kdd3j=][
1628ENDTEST
1629
1630void func(void)
1631{
1632 if (condition1
1633 && condition2)
1634 action();
1635 function(argument1
1636 && argument2);
1637
1638 if (c1 && (c2 ||
1639 c3))
1640 foo;
1641 if (c1 &&
1642 (c2 || c3))
1643 {
1644 }
1645
1646 if ( c1
1647 && ( c2
1648 || c3))
1649 foo;
1650 func( c1
1651 && ( c2
1652 || c3))
1653 foo;
1654}
1655
1656STARTTEST
1657:set cino=k2s,(s,U1
16582kdd3j=][
1659ENDTEST
1660
1661void func(void)
1662{
1663 if (condition1
1664 && condition2)
1665 action();
1666 function(argument1
1667 && argument2);
1668
1669 if (c1 && (c2 ||
1670 c3))
1671 foo;
1672 if (c1 &&
1673 (c2 || c3))
1674 {
1675 }
1676 if (c123456789
1677 && (c22345
1678 || c3))
1679 printf("foo\n");
1680
1681 c = c1 &&
1682 (
1683 c2 ||
1684 c3
1685 ) && c4;
1686}
1687
1688STARTTEST
1689:set cino=k2s,(0,W4
16902kdd3j=][
1691ENDTEST
1692
1693void func(void)
1694{
1695 if (condition1
1696 && condition2)
1697 action();
1698 function(argument1
1699 && argument2);
1700
1701 if (c1 && (c2 ||
1702 c3))
1703 foo;
1704 if (c1 &&
1705 (c2 || c3))
1706 {
1707 }
1708 if (c123456789
1709 && (c22345
1710 || c3))
1711 printf("foo\n");
1712
1713 if ( c1
1714 && ( c2
1715 || c3))
1716 foo;
1717
1718 a_long_line(
1719 argument,
1720 argument);
1721 a_short_line(argument,
1722 argument);
1723}
1724
1725STARTTEST
1726:set cino=k2s,u2
17272kdd3j=][
1728ENDTEST
1729
1730void func(void)
1731{
1732 if (condition1
1733 && condition2)
1734 action();
1735 function(argument1
1736 && argument2);
1737
1738 if (c1 && (c2 ||
1739 c3))
1740 foo;
1741 if (c1 &&
1742 (c2 || c3))
1743 {
1744 }
1745 if (c123456789
1746 && (c22345
1747 || c3))
1748 printf("foo\n");
1749}
1750
1751STARTTEST
1752:set cino=k2s,(0,w1
17532kdd3j=][
1754ENDTEST
1755
1756void func(void)
1757{
1758 if (condition1
1759 && condition2)
1760 action();
1761 function(argument1
1762 && argument2);
1763
1764 if (c1 && (c2 ||
1765 c3))
1766 foo;
1767 if (c1 &&
1768 (c2 || c3))
1769 {
1770 }
1771 if (c123456789
1772 && (c22345
1773 || c3))
1774 printf("foo\n");
1775
1776 if ( c1
1777 && ( c2
1778 || c3))
1779 foo;
1780 func( c1
1781 && ( c2
1782 || c3))
1783 foo;
1784}
1785
1786STARTTEST
1787:set cino=k2,(s
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}
1807
1808STARTTEST
Bram Moolenaared38b0a2011-05-25 15:16:18 +02001809:set cino=N-s
Bram Moolenaar6ec154b2011-06-12 21:51:08 +02001810/^NAMESPACESTART
Bram Moolenaared38b0a2011-05-25 15:16:18 +02001811=/^NAMESPACEEND
1812ENDTEST
1813
Bram Moolenaar6ec154b2011-06-12 21:51:08 +02001814NAMESPACESTART
Bram Moolenaared38b0a2011-05-25 15:16:18 +02001815/* valid namespaces with normal indent */
1816namespace
1817{
1818 {
1819 111111111111;
1820}
1821}
1822namespace /* test */
1823{
1824 11111111111111111;
1825}
1826namespace // test
1827{
1828 111111111111111111;
1829}
1830namespace
1831{
1832 111111111111111111;
1833}
1834namespace test
1835{
1836 111111111111111111;
1837}
1838namespace{
1839 111111111111111111;
1840}
1841namespace test{
1842 111111111111111111;
1843}
1844namespace {
1845 111111111111111111;
1846}
1847namespace test {
1848 111111111111111111;
1849namespace test2 {
1850 22222222222222222;
1851}
1852}
1853
1854/* invalid namespaces use block indent */
1855namespace test test2 {
1856 111111111111111111111;
1857}
1858namespace11111111111 {
1859 111111111111;
1860}
1861namespace() {
1862 1111111111111;
1863}
1864namespace()
1865{
1866 111111111111111111;
1867}
1868namespace test test2
1869{
1870 1111111111111111111;
1871}
1872namespace111111111
1873{
1874 111111111111111111;
1875}
1876NAMESPACEEND
1877
1878
1879STARTTEST
Bram Moolenaar76f7fd32011-07-20 15:09:43 +02001880:set cino=j1,J1
Bram Moolenaar6ec154b2011-06-12 21:51:08 +02001881/^JSSTART
1882=/^JSEND
1883ENDTEST
1884
1885JSSTART
1886var bar = {
1887foo: {
1888that: this,
1889some: ok,
1890},
1891"bar":{
1892a : 2,
1893b: "123abc",
1894x: 4,
1895"y": 5
1896}
1897}
1898JSEND
1899
1900STARTTEST
Bram Moolenaar76f7fd32011-07-20 15:09:43 +02001901:set cino=j1,J1
1902/^JSSTART
1903=/^JSEND
1904ENDTEST
1905
1906JSSTART
1907var foo = [
19081, // indent 8 more
19092,
19103
1911]; // indent 8 less
1912JSEND
1913
1914STARTTEST
1915:set cino=j1,J1
1916/^JSSTART
1917=/^JSEND
1918ENDTEST
1919
1920JSSTART
1921function bar() {
1922var foo = [
19231,
19242,
19253
1926]; // indent 16 less
1927}
1928JSEND
1929
1930STARTTEST
1931:set cino=j1,J1
1932/^JSSTART
1933=/^JSEND
1934ENDTEST
1935
1936JSSTART
1937(function($){
1938
1939var class_name='myclass';
1940
1941function private_method() {
1942}
1943
1944var public_method={
1945method: function(options,args){
1946private_method();
1947}
1948}
1949
1950function init(options) {
1951
1952$(this).data(class_name+'_public',$.extend({},{
1953foo: 'bar',
1954bar: 2, // indent 8 more
1955foobar: [ // indent 8 more
19561, // indent 8 more
19572, // indent 16 more
19583 // indent 16 more
1959],
1960callback: function(){ // indent 8 more
1961return true; // indent 8 more
1962} // indent 8 more
1963}, options||{}));
1964}
1965
1966$.fn[class_name]=function() {
1967
1968var _arguments=arguments;
1969return this.each(function(){
1970
1971var options=$(this).data(class_name+'_public');
1972if (!options) {
1973init.apply(this,_arguments);
1974
1975} else {
1976var method=public_method[_arguments[0]];
1977
1978if (typeof(method)!='function') {
1979console.log(class_name+' has no method "'+_arguments[0]+'"');
1980return false;
1981}
1982_arguments[0]=options;
1983method.apply(this,_arguments);
1984}
1985});
1986}
1987
1988})(jQuery);
1989JSEND
1990
1991STARTTEST
1992:set cino=j1,J1
1993/^JSSTART
1994=/^JSEND
1995ENDTEST
1996
1997JSSTART
1998function init(options) {
1999$(this).data(class_name+'_public',$.extend({},{
2000foo: 'bar',
2001bar: 2,
2002foobar: [
20031, // indent 8 more
20042, // indent 8 more
20053 // indent 8 more
2006],
2007callback: function(){
2008return true;
2009}
2010}, options||{}));
2011}
2012JSEND
2013
2014STARTTEST
2015:set cino=j1,J1
2016/^JSSTART
2017=/^JSEND
2018ENDTEST
2019
2020JSSTART
2021(function($){
2022function init(options) {
2023$(this).data(class_name+'_public',$.extend({},{
2024foo: 'bar',
2025bar: 2, // indent 8 more
2026foobar: [ // indent 8 more
20271, // indent 8 more
20282, // indent 16 more
20293 // indent 16 more
2030],
2031callback: function(){ // indent 8 more
2032return true; // indent 8 more
2033} // indent 8 more
2034}, options||{}));
2035}
2036})(jQuery);
2037JSEND
2038
2039STARTTEST
Bram Moolenaar071d4272004-06-13 20:20:40 +00002040:g/^STARTTEST/.,/^ENDTEST/d
2041:1;/start of AUTO/,$wq! test.out
2042ENDTEST