blob: a7543945c4b8a202371aac1fbbda61b7518f7063 [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
467class bob
468{
469 int foo() {return 1;}
470 int bar;
471}
472
473main()
474{
475while(1)
476if (foo)
477{
478bar;
479}
480else {
481asdf;
482}
483misplacedline;
484}
485
486{
487 if (clipboard.state == SELECT_DONE
488 && ((row == clipboard.start.lnum
489 && col >= clipboard.start.col)
490 || row > clipboard.start.lnum))
491}
492
493{
494if (1) {i += 4;}
495where_am_i;
496return 0;
497}
498
499{
500{
501} // sdf(asdf
502if (asdf)
503asd;
504}
505
506{
507label1:
508label2:
509}
510
511{
512int fooRet = foo(pBar1, false /*fKB*/,
513 true /*fPTB*/, 3 /*nT*/, false /*fDF*/);
514f() {
515for ( i = 0;
516 i < m;
517 /* c */ i++ ) {
518a = b;
519}
520}
521}
522
523{
524 f1(/*comment*/);
525 f2();
526}
527
528{
529do {
530if (foo) {
531} else
532;
533} while (foo);
534foo(); // was wrong
535}
536
537int x; // no extra indent because of the ;
538void func()
539{
540}
541
542char *tab[] = {"aaa",
543 "};", /* }; */ NULL}
544 int indented;
545{}
546
547char *a[] = {"aaa", "bbb",
548 "ccc", NULL};
549// here
550
551char *tab[] = {"aaa",
552 "xx", /* xx */}; /* asdf */
553int not_indented;
554
555{
556 do {
557 switch (bla)
558 {
559 case 1: if (foo)
560 bar;
561 }
562 } while (boo);
563 wrong;
564}
565
566int foo,
567 bar;
568int foo;
569
570#if defined(foo) \
571 && defined(bar)
572char * xx = "asdf\
573 foo\
574 bor";
575int x;
576
577char *foo = "asdf\
578 asdf\
579 asdf",
580 *bar;
581
582void f()
583{
584#if defined(foo) \
585 && defined(bar)
586char *foo = "asdf\
587 asdf\
588 asdf",
589 *bar;
590 {
591 int i;
592char *foo = "asdf\
593 asdf\
594 asdf",
595 *bar;
596 }
597#endif
598}
599#endif
600
601int y; // comment
602 // comment
603
604 // comment
605
606{
607 Constructor(int a,
608 int b ) : BaseClass(a)
609 {
610 }
611}
612
613void foo()
614{
615 char one,
616 two;
617 struct bla piet,
618 jan;
619 enum foo kees,
620 jannie;
621 static unsigned sdf,
622 krap;
623 unsigned int piet,
624 jan;
625 int
626 kees,
627 jan;
628}
629
630{
631 t(int f,
632 int d); // )
633 d();
634}
635
636Constructor::Constructor(int a,
637 int b
638 ) :
639 BaseClass(a,
640 b,
641 c),
642 mMember(b),
643{
644}
645
646Constructor::Constructor(int a,
647 int b ) :
648 BaseClass(a)
649{
650}
651
652Constructor::Constructor(int a,
653 int b ) /*x*/ : /*x*/ BaseClass(a),
654 member(b)
655{
656}
657
658class CAbc :
659 public BaseClass1,
660 protected BaseClass2
661{
662 int Test() { return FALSE; }
663 int Test1() { return TRUE; }
664
665 CAbc(int a, int b ) :
666 BaseClass(a)
667 {
668 switch(xxx)
669 {
670 case abc:
671 asdf();
672 break;
673
674 case 999:
675 baer();
676 break;
677 }
678 }
679
680public: // <-- this was incoreectly indented before!!
681 void testfall();
682protected:
683 void testfall();
684};
685
686class CAbc : public BaseClass1,
687 protected BaseClass2
688{
689};
690
691static struct
692{
693 int a;
694 int b;
695} variable[COUNT] =
696{
697 {
698 123,
699 456
700 },
701 {
702 123,
703 456
704 }
705};
706
707static struct
708{
709 int a;
710 int b;
711} variable[COUNT] =
712{
713 { 123, 456 },
714 { 123, 456 }
715};
716
717void asdf() /* ind_maxparen may cause trouble here */
718{
719 if ((0
720 && 1
721 && 1
722 && 1
723 && 1
724 && 1
725 && 1
726 && 1
727 && 1
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)) break;
745}
746
Bram Moolenaar18144c82006-04-12 21:52:12 +0000747foo()
748{
749 a = cond ? foo() : asdf
750 + asdf;
751
752 a = cond ?
753 foo() : asdf
754 + asdf;
755}
756
757int main(void)
758{
759 if (a)
760 if (b)
761 2;
762 else 3;
763 next_line_of_code();
764}
765
Bram Moolenaar7fc904b2006-04-13 20:37:35 +0000766barry()
767{
768 Foo::Foo (int one,
769 int two)
770 : something(4)
771 {}
772}
773
774barry()
775{
776 Foo::Foo (int one, int two)
777 : something(4)
778 {}
779}
780
781Constructor::Constructor(int a,
782 int b
783 ) :
784 BaseClass(a,
785 b,
786 c),
787 mMember(b)
788{
789}
Bram Moolenaar9e54a0e2006-04-14 20:42:25 +0000790 int main ()
791 {
792 if (lala)
793 do
794 ++(*lolo);
795 while (lili
796 && lele);
797 lulu;
798 }
Bram Moolenaar7fc904b2006-04-13 20:37:35 +0000799
Bram Moolenaar9e54a0e2006-04-14 20:42:25 +0000800int main ()
801{
802switch (c)
803{
804case 'c': if (cond)
805{
806}
807}
808}
809
810main()
811{
812 (void) MyFancyFuasdfadsfnction(
813 argument);
814}
815
816main()
817{
818 char foo[] = "/*";
819 /* as
820 df */
821 hello
822}
Bram Moolenaared38b0a2011-05-25 15:16:18 +0200823
824/* valid namespaces with normal indent */
825namespace
826{
827{
828 111111111111;
829}
830}
831namespace /* test */
832{
833 11111111111111111;
834}
835namespace // test
836{
837 111111111111111111;
838}
839namespace
840{
841 111111111111111111;
842}
843namespace test
844{
845 111111111111111111;
846}
847namespace{
848 111111111111111111;
849}
850namespace test{
851 111111111111111111;
852}
853namespace {
854 111111111111111111;
855}
856namespace test {
857 111111111111111111;
858namespace test2 {
859 22222222222222222;
860}
861}
862
863/* invalid namespaces use block indent */
864namespace test test2 {
865 111111111111111111111;
866}
867namespace11111111111 {
868 111111111111;
869}
870namespace() {
871 1111111111111;
872}
873namespace()
874{
875 111111111111111111;
876}
877namespace test test2
878{
879 1111111111111111111;
880}
881namespace111111111
882{
883 111111111111111111;
884}
885
Bram Moolenaar071d4272004-06-13 20:20:40 +0000886/* end of AUTO */
887
888STARTTEST
889:set tw=0 wm=60 columns=80 noai fo=croq
890/serious/e
891a about life, the universe, and the rest
892ENDTEST
893
894{
895
896/* this is
897 * a real serious important big
898 * comment
899 */
900 /* insert " about life, the universe, and the rest" after "serious" */
901}
902
903STARTTEST
904:set nocin
905/comments
906joabout life/happens
907jothere/below
908oline/this
909Ohello
910ENDTEST
911
912{
913 /*
914 * Testing for comments, without 'cin' set
915 */
916
917/*
918* what happens here?
919*/
920
921 /*
922 the end of the comment, try inserting a line below */
923
924 /* how about
925 this one */
926}
927
928STARTTEST
929:set cin
930/vec2
931==
932ENDTEST
933
934{
935 var = this + that + vec[0] * vec[0]
936 + vec[1] * vec[1]
937 + vec2[2] * vec[2];
938}
939
940STARTTEST
941:set cin
942:set cino=}4
943/testing1
944k2==/testing2
945k2==
946ENDTEST
947
948{
949 asdf asdflkajds f;
950 if (tes & ting) {
951 asdf asdf asdf ;
952 asdfa sdf asdf;
953 }
954 testing1;
955 if (tes & ting)
956 {
957 asdf asdf asdf ;
958 asdfa sdf asdf;
959 }
960 testing2;
961}
962
963STARTTEST
964:set cin
965:set cino=(0,)20
966/main
967=][
968ENDTEST
969
970main ( int first_par, /*
971 * Comment for
972 * first par
973 */
974 int second_par /*
975 * Comment for
976 * second par
977 */
978 )
979{
980 func( first_par, /*
981 * Comment for
982 * first par
983 */
984 second_par /*
985 * Comment for
986 * second par
987 */
988 );
989
990}
991
992STARTTEST
993:set cin
Bram Moolenaar48d27922012-06-13 13:40:48 +0200994:set cino=es,n0s
995/main
996=][
997ENDTEST
998
999main(void)
1000{
1001 /* Make sure that cino=X0s is not parsed like cino=Xs. */
1002 if (cond)
1003 foo();
1004 else
1005 {
1006 bar();
1007 }
1008}
1009
1010STARTTEST
1011:set cin
Bram Moolenaar071d4272004-06-13 20:20:40 +00001012:set cino=
1013]]=][
1014ENDTEST
1015
1016{
1017 do
1018 {
1019 if ()
1020 {
1021 if ()
1022 asdf;
1023 else
1024 asdf;
1025 }
1026 } while ();
1027 cmd; /* this should go under the } */
1028}
1029
1030STARTTEST
1031]]=][
1032ENDTEST
1033
1034void f()
1035{
1036 if ( k() ) {
1037 l();
1038
1039 } else { /* Start (two words) end */
1040 m();
1041 }
1042
1043 n();
1044}
1045
1046STARTTEST
1047:set cino={s,e-s
1048]]=][
1049ENDTEST
1050
1051void f()
1052{
1053 if ( k() )
1054 {
1055 l();
1056 } else { /* Start (two words) end */
1057 m();
1058 }
1059 n(); /* should be under the if () */
1060}
1061
1062STARTTEST
1063:set cino={s,fs
1064]]=/ foo
1065ENDTEST
1066
1067void bar(void)
1068{
1069 static array[2][2] =
1070 {
1071 { 1, 2 },
1072 { 3, 4 },
1073 }
1074
1075 while (a)
1076 {
1077 foo(&a);
1078 }
1079
1080 {
1081 int a;
1082 {
1083 a = a + 1;
1084 }
1085 }
1086 b = a;
1087 }
1088
1089void func(void)
1090 {
1091 a = 1;
1092 {
1093 b = 2;
1094 }
1095 c = 3;
1096 d = 4;
1097 }
1098/* foo */
1099
1100STARTTEST
1101:set cino=
1102/while
1103ohere
1104ENDTEST
1105
1106a()
1107{
1108 do {
1109 a = a +
1110 a;
1111 } while ( a ); /* add text under this line */
1112 if ( a )
1113 a;
1114}
1115
1116STARTTEST
1117:set cino= com=
1118/comment
1119olabel2: b(); label3 /* post */: /* pre */ label4: f(/*com*/); if (/*com*/) cmd();
1120ENDTEST
1121
1122a()
1123{
1124label1:
1125 /* hmm */
1126 // comment
1127}
1128
1129STARTTEST
1130:set comments& comments^=s:/*,m:**,ex:*/
1131/simple
1132=5j
1133ENDTEST
1134
1135/*
1136 * A simple comment
1137 */
1138
1139/*
1140 ** A different comment
1141 */
1142
1143STARTTEST
1144:set cino=c0
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=c0,C1
1159:set comments& comments-=s1:/* comments^=s0:/*
11602kdd]]=][
1161ENDTEST
1162
1163void f()
1164{
1165
1166 /*********
1167 A comment.
1168*********/
1169}
1170
1171STARTTEST
1172:set cino=
1173]]=][
1174ENDTEST
1175
1176void f()
1177{
1178 c = c1 &&
1179 (
1180 c2 ||
1181 c3
1182 ) && c4;
1183}
1184
1185STARTTEST
1186:set cino=(s
11872kdd]]=][
1188ENDTEST
1189
1190void f()
1191{
1192 c = c1 &&
1193 (
1194 c2 ||
1195 c3
1196 ) && c4;
1197}
1198
1199STARTTEST
1200:set cino=(s,U1
12012kdd]]=][
1202ENDTEST
1203
1204void f()
1205{
1206 c = c1 &&
1207 (
1208 c2 ||
1209 c3
1210 ) && c4;
1211}
1212
1213STARTTEST
1214:set cino=(0
12152kdd]]=][
1216ENDTEST
1217
1218void f()
1219{
1220 if ( c1
1221 && ( c2
1222 || c3))
1223 foo;
1224}
1225
1226STARTTEST
1227:set cino=(0,w1
12282kdd]]=][
1229ENDTEST
1230
1231void f()
1232{
1233 if ( c1
1234 && ( c2
1235 || c3))
1236 foo;
1237}
1238
1239STARTTEST
1240:set cino=(s
12412kdd]]=][
1242ENDTEST
1243
1244void f()
1245{
1246 c = c1 && (
1247 c2 ||
1248 c3
1249 ) && c4;
1250 if (
1251 c1 && c2
1252 )
1253 foo;
1254}
1255
1256STARTTEST
1257:set cino=(s,m1
12582kdd]]=][
1259ENDTEST
1260
1261void f()
1262{
1263 c = c1 && (
1264 c2 ||
1265 c3
1266 ) && c4;
1267 if (
1268 c1 && c2
1269 )
1270 foo;
1271}
1272
1273STARTTEST
1274:set cino=b1
12752kdd]]=][
1276ENDTEST
1277
1278void f()
1279{
1280 switch (x)
1281 {
1282 case 1:
1283 a = b;
1284 break;
1285 default:
1286 a = 0;
1287 break;
1288 }
1289}
1290
1291STARTTEST
1292:set cino=(0,W5
12932kdd]]=][
1294ENDTEST
1295
1296void f()
1297{
1298 invokeme(
1299 argu,
1300 ment);
1301 invokeme(
1302 argu,
1303 ment
1304 );
1305 invokeme(argu,
1306 ment
1307 );
1308}
1309
1310STARTTEST
1311:set cino=/6
13122kdd]]=][
1313ENDTEST
1314
1315void f()
1316{
1317 statement;
1318 // comment 1
1319 // comment 2
1320}
1321
1322STARTTEST
1323:set cino=
13242kdd]]/comment 1/+1
1325==
1326ENDTEST
1327
1328void f()
1329{
1330 statement;
1331 // comment 1
1332 // comment 2
1333}
1334
1335STARTTEST
1336:set cino=g0
13372kdd]]=][
1338ENDTEST
1339
1340class CAbc
1341{
1342 int Test() { return FALSE; }
1343
1344public: // comment
1345 void testfall();
1346protected:
1347 void testfall();
1348};
1349
1350STARTTEST
Bram Moolenaare79d1532011-10-04 18:03:47 +02001351:set cino=(0,gs,hs
13522kdd]]=][
1353ENDTEST
1354
1355class Foo : public Bar
1356{
1357public:
1358virtual void method1(void) = 0;
1359virtual void method2(int arg1,
1360int arg2,
1361int arg3) = 0;
1362};
1363
1364STARTTEST
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00001365:set cino=+20
13662kdd]]=][
1367ENDTEST
1368
1369 void
1370foo()
1371{
1372 if (a)
1373 {
1374 } else
1375 asdf;
1376}
1377
1378STARTTEST
Bram Moolenaar071d4272004-06-13 20:20:40 +00001379:set cino=(0,W2s
13802kdd]]=][
1381ENDTEST
1382
1383{
1384 averylongfunctionnamelongfunctionnameaverylongfunctionname()->asd(
1385 asdasdf,
1386 func(asdf,
1387 asdfadsf),
1388 asdfasdf
1389 );
1390
1391 /* those are ugly, but consequent */
1392
1393 func()->asd(asdasdf,
1394 averylongfunctionname(
1395 abc,
1396 dec)->averylongfunctionname(
1397 asdfadsf,
1398 asdfasdf,
1399 asdfasdf,
1400 ),
1401 func(asdfadf,
1402 asdfasdf
1403 ),
1404 asdasdf
1405 );
1406
1407 averylongfunctionnameaverylongfunctionnameavery()->asd(fasdf(
1408 abc,
1409 dec)->asdfasdfasdf(
1410 asdfadsf,
1411 asdfasdf,
1412 asdfasdf,
1413 ),
1414 func(asdfadf,
1415 asdfasdf),
1416 asdasdf
1417 );
1418}
1419
1420STARTTEST
Bram Moolenaar9e54a0e2006-04-14 20:42:25 +00001421:set cino=M1
14222kdd]]=][
1423ENDTEST
1424
1425int main ()
1426{
1427 if (cond1 &&
1428 cond2
1429 )
1430 foo;
1431}
1432
1433STARTTEST
Bram Moolenaar8d2d71d2011-04-28 13:02:09 +02001434:set cino=(0,ts
14352kdd=][
1436ENDTEST
1437
1438void func(int a
1439#if defined(FOO)
1440 , int b
1441 , int c
1442#endif
1443 )
1444{
1445}
1446
1447STARTTEST
1448:set cino=(0
14492kdd=][
1450ENDTEST
1451
1452void
1453func(int a
1454#if defined(FOO)
1455 , int b
1456 , int c
1457#endif
1458 )
1459{
1460}
1461
1462STARTTEST
Bram Moolenaar4ae06c12011-05-10 11:39:19 +02001463:set cino&
Bram Moolenaarc367faa2011-12-14 20:21:35 +010014642kdd=7][
Bram Moolenaar4ae06c12011-05-10 11:39:19 +02001465ENDTEST
1466
1467void func(void)
1468{
1469 if(x==y)
1470 if(y==z)
1471 foo=1;
1472 else { bar=1;
1473 baz=2;
1474 }
1475 printf("Foo!\n");
1476}
1477
Bram Moolenaar496f9512011-05-19 16:35:09 +02001478void func1(void)
1479{
1480 char* tab[] = {"foo", "bar",
1481 "baz", "quux",
1482 "this line used", "to be indented incorrectly"};
1483 foo();
1484}
1485
1486void func2(void)
1487{
1488 int tab[] =
1489 {1, 2,
1490 3, 4,
1491 5, 6};
1492
1493 printf("This line used to be indented incorrectly.\n");
1494}
1495
Bram Moolenaar3388bb42011-11-30 17:20:23 +01001496int foo[]
1497#ifdef BAR
1498
1499= { 1, 2, 3,
1500 4, 5, 6 }
1501
1502#endif
1503;
1504 int baz;
1505
Bram Moolenaar496f9512011-05-19 16:35:09 +02001506void func3(void)
1507{
1508 int tab[] = {
1509 1, 2,
1510 3, 4,
1511 5, 6};
1512
Bram Moolenaarc367faa2011-12-14 20:21:35 +01001513printf("Don't you dare indent this line incorrectly!\n");
1514}
1515
1516void
1517func4(a, b,
1518 c)
1519int a;
1520int b;
1521int c;
1522{
1523}
1524
1525void
1526func5(
1527 int a,
1528 int b)
1529{
1530}
1531
1532void
1533func6(
1534 int a)
1535{
Bram Moolenaar496f9512011-05-19 16:35:09 +02001536}
1537
Bram Moolenaar4ae06c12011-05-10 11:39:19 +02001538STARTTEST
Bram Moolenaaraede6ce2011-05-10 11:56:30 +02001539:set cino&
Bram Moolenaar50f42ca2011-07-15 14:12:30 +02001540:set cino+=l1
15412kdd=][
1542ENDTEST
1543
1544void func(void)
1545{
1546 int tab[] =
1547 {
1548 1, 2, 3,
1549 4, 5, 6};
1550
1551 printf("Indent this line correctly!\n");
1552
1553 switch (foo)
1554 {
1555 case bar:
1556 printf("bar");
1557 break;
1558 case baz: {
1559 printf("baz");
1560 break;
1561 }
1562 case quux:
1563printf("But don't break the indentation of this instruction\n");
1564break;
1565 }
1566}
1567
1568STARTTEST
1569:set cino&
Bram Moolenaaraede6ce2011-05-10 11:56:30 +020015702kdd=][
1571ENDTEST
1572
1573void func(void)
1574{
1575 cout << "a"
1576 << "b"
1577 << ") :"
1578 << "c";
1579}
1580
1581STARTTEST
Bram Moolenaara4271d52011-05-10 13:38:27 +02001582:set com=s1:/*,m:*,ex:*/
1583]]3jofoo();
1584ENDTEST
1585
1586void func(void)
1587{
1588 /*
1589 * This is a comment.
1590 */
1591}
1592
1593STARTTEST
Bram Moolenaar334adf02011-05-25 13:34:04 +02001594:set cino&
15952kdd=][
1596ENDTEST
1597
1598void func(void)
1599{
1600 for (int i = 0; i < 10; ++i)
1601 if (i & 1) {
1602 foo(1);
1603 } else
1604 foo(0);
1605baz();
1606}
1607
1608STARTTEST
Bram Moolenaar3675fa02012-04-05 17:17:42 +02001609:set cino=k2s,(0
16102kdd3j=][
1611ENDTEST
1612
1613void func(void)
1614{
1615 if (condition1
1616 && condition2)
1617 action();
1618 function(argument1
1619 && argument2);
1620
1621 if (c1 && (c2 ||
1622 c3))
1623 foo;
1624 if (c1 &&
1625 (c2 || c3))
1626 {
1627 }
1628
1629 if ( c1
1630 && ( c2
1631 || c3))
1632 foo;
1633 func( c1
1634 && ( c2
1635 || c3))
1636 foo;
1637}
1638
1639STARTTEST
1640:set cino=k2s,(s
16412kdd3j=][
1642ENDTEST
1643
1644void func(void)
1645{
1646 if (condition1
1647 && condition2)
1648 action();
1649 function(argument1
1650 && argument2);
1651
1652 if (c1 && (c2 ||
1653 c3))
1654 foo;
1655 if (c1 &&
1656 (c2 || c3))
1657 {
1658 }
1659
1660 if ( c1
1661 && ( c2
1662 || c3))
1663 foo;
1664 func( c1
1665 && ( c2
1666 || c3))
1667 foo;
1668}
1669
1670STARTTEST
1671:set cino=k2s,(s,U1
16722kdd3j=][
1673ENDTEST
1674
1675void func(void)
1676{
1677 if (condition1
1678 && condition2)
1679 action();
1680 function(argument1
1681 && argument2);
1682
1683 if (c1 && (c2 ||
1684 c3))
1685 foo;
1686 if (c1 &&
1687 (c2 || c3))
1688 {
1689 }
1690 if (c123456789
1691 && (c22345
1692 || c3))
1693 printf("foo\n");
1694
1695 c = c1 &&
1696 (
1697 c2 ||
1698 c3
1699 ) && c4;
1700}
1701
1702STARTTEST
1703:set cino=k2s,(0,W4
17042kdd3j=][
1705ENDTEST
1706
1707void func(void)
1708{
1709 if (condition1
1710 && condition2)
1711 action();
1712 function(argument1
1713 && argument2);
1714
1715 if (c1 && (c2 ||
1716 c3))
1717 foo;
1718 if (c1 &&
1719 (c2 || c3))
1720 {
1721 }
1722 if (c123456789
1723 && (c22345
1724 || c3))
1725 printf("foo\n");
1726
1727 if ( c1
1728 && ( c2
1729 || c3))
1730 foo;
1731
1732 a_long_line(
1733 argument,
1734 argument);
1735 a_short_line(argument,
1736 argument);
1737}
1738
1739STARTTEST
1740:set cino=k2s,u2
17412kdd3j=][
1742ENDTEST
1743
1744void func(void)
1745{
1746 if (condition1
1747 && condition2)
1748 action();
1749 function(argument1
1750 && argument2);
1751
1752 if (c1 && (c2 ||
1753 c3))
1754 foo;
1755 if (c1 &&
1756 (c2 || c3))
1757 {
1758 }
1759 if (c123456789
1760 && (c22345
1761 || c3))
1762 printf("foo\n");
1763}
1764
1765STARTTEST
1766:set cino=k2s,(0,w1
17672kdd3j=][
1768ENDTEST
1769
1770void func(void)
1771{
1772 if (condition1
1773 && condition2)
1774 action();
1775 function(argument1
1776 && argument2);
1777
1778 if (c1 && (c2 ||
1779 c3))
1780 foo;
1781 if (c1 &&
1782 (c2 || c3))
1783 {
1784 }
1785 if (c123456789
1786 && (c22345
1787 || c3))
1788 printf("foo\n");
1789
1790 if ( c1
1791 && ( c2
1792 || c3))
1793 foo;
1794 func( c1
1795 && ( c2
1796 || c3))
1797 foo;
1798}
1799
1800STARTTEST
1801:set cino=k2,(s
18022kdd3j=][
1803ENDTEST
1804
1805void func(void)
1806{
1807 if (condition1
1808 && condition2)
1809 action();
1810 function(argument1
1811 && argument2);
1812
1813 if (c1 && (c2 ||
1814 c3))
1815 foo;
1816 if (c1 &&
1817 (c2 || c3))
1818 {
1819 }
1820}
1821
1822STARTTEST
Bram Moolenaared38b0a2011-05-25 15:16:18 +02001823:set cino=N-s
Bram Moolenaar6ec154b2011-06-12 21:51:08 +02001824/^NAMESPACESTART
Bram Moolenaared38b0a2011-05-25 15:16:18 +02001825=/^NAMESPACEEND
1826ENDTEST
1827
Bram Moolenaar6ec154b2011-06-12 21:51:08 +02001828NAMESPACESTART
Bram Moolenaared38b0a2011-05-25 15:16:18 +02001829/* valid namespaces with normal indent */
1830namespace
1831{
1832 {
1833 111111111111;
1834}
1835}
1836namespace /* test */
1837{
1838 11111111111111111;
1839}
1840namespace // test
1841{
1842 111111111111111111;
1843}
1844namespace
1845{
1846 111111111111111111;
1847}
1848namespace test
1849{
1850 111111111111111111;
1851}
1852namespace{
1853 111111111111111111;
1854}
1855namespace test{
1856 111111111111111111;
1857}
1858namespace {
1859 111111111111111111;
1860}
1861namespace test {
1862 111111111111111111;
1863namespace test2 {
1864 22222222222222222;
1865}
1866}
1867
1868/* invalid namespaces use block indent */
1869namespace test test2 {
1870 111111111111111111111;
1871}
1872namespace11111111111 {
1873 111111111111;
1874}
1875namespace() {
1876 1111111111111;
1877}
1878namespace()
1879{
1880 111111111111111111;
1881}
1882namespace test test2
1883{
1884 1111111111111111111;
1885}
1886namespace111111111
1887{
1888 111111111111111111;
1889}
1890NAMESPACEEND
1891
1892
1893STARTTEST
Bram Moolenaar76f7fd32011-07-20 15:09:43 +02001894:set cino=j1,J1
Bram Moolenaar6ec154b2011-06-12 21:51:08 +02001895/^JSSTART
1896=/^JSEND
1897ENDTEST
1898
1899JSSTART
1900var bar = {
1901foo: {
1902that: this,
1903some: ok,
1904},
1905"bar":{
1906a : 2,
1907b: "123abc",
1908x: 4,
1909"y": 5
1910}
1911}
1912JSEND
1913
1914STARTTEST
Bram Moolenaar76f7fd32011-07-20 15:09:43 +02001915:set cino=j1,J1
1916/^JSSTART
1917=/^JSEND
1918ENDTEST
1919
1920JSSTART
1921var foo = [
19221, // indent 8 more
19232,
19243
1925]; // indent 8 less
1926JSEND
1927
1928STARTTEST
1929:set cino=j1,J1
1930/^JSSTART
1931=/^JSEND
1932ENDTEST
1933
1934JSSTART
1935function bar() {
1936var foo = [
19371,
19382,
19393
1940]; // indent 16 less
1941}
1942JSEND
1943
1944STARTTEST
1945:set cino=j1,J1
1946/^JSSTART
1947=/^JSEND
1948ENDTEST
1949
1950JSSTART
1951(function($){
1952
1953var class_name='myclass';
1954
1955function private_method() {
1956}
1957
1958var public_method={
1959method: function(options,args){
1960private_method();
1961}
1962}
1963
1964function init(options) {
1965
1966$(this).data(class_name+'_public',$.extend({},{
1967foo: 'bar',
1968bar: 2, // indent 8 more
1969foobar: [ // indent 8 more
19701, // indent 8 more
19712, // indent 16 more
19723 // indent 16 more
1973],
1974callback: function(){ // indent 8 more
1975return true; // indent 8 more
1976} // indent 8 more
1977}, options||{}));
1978}
1979
1980$.fn[class_name]=function() {
1981
1982var _arguments=arguments;
1983return this.each(function(){
1984
1985var options=$(this).data(class_name+'_public');
1986if (!options) {
1987init.apply(this,_arguments);
1988
1989} else {
1990var method=public_method[_arguments[0]];
1991
1992if (typeof(method)!='function') {
1993console.log(class_name+' has no method "'+_arguments[0]+'"');
1994return false;
1995}
1996_arguments[0]=options;
1997method.apply(this,_arguments);
1998}
1999});
2000}
2001
2002})(jQuery);
2003JSEND
2004
2005STARTTEST
2006:set cino=j1,J1
2007/^JSSTART
2008=/^JSEND
2009ENDTEST
2010
2011JSSTART
2012function init(options) {
2013$(this).data(class_name+'_public',$.extend({},{
2014foo: 'bar',
2015bar: 2,
2016foobar: [
20171, // indent 8 more
20182, // indent 8 more
20193 // indent 8 more
2020],
2021callback: function(){
2022return true;
2023}
2024}, options||{}));
2025}
2026JSEND
2027
2028STARTTEST
2029:set cino=j1,J1
2030/^JSSTART
2031=/^JSEND
2032ENDTEST
2033
2034JSSTART
2035(function($){
2036function init(options) {
2037$(this).data(class_name+'_public',$.extend({},{
2038foo: 'bar',
2039bar: 2, // indent 8 more
2040foobar: [ // indent 8 more
20411, // indent 8 more
20422, // indent 16 more
20433 // indent 16 more
2044],
2045callback: function(){ // indent 8 more
2046return true; // indent 8 more
2047} // indent 8 more
2048}, options||{}));
2049}
2050})(jQuery);
2051JSEND
2052
2053STARTTEST
Bram Moolenaar071d4272004-06-13 20:20:40 +00002054:g/^STARTTEST/.,/^ENDTEST/d
2055:1;/start of AUTO/,$wq! test.out
2056ENDTEST