blob: 89831183483eb165217295bc92678d2e779ae703 [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
7:set nocompatible viminfo+=nviminfo
8:edit " read modeline
9/start of AUTO
10=/end of AUTO
11ENDTEST
12
13/* start of AUTO matically checked */
14{
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{
302 yes = 0,
303 no,
304 maybe
305};
306
307typedef enum soppie
308{
309 yes = 0,
310 no,
311 maybe
312};
313
314{
315 int a,
316 b;
317}
318
319{
320 struct Type
321 {
322 int i;
323 char *str;
324 } var[] =
325 {
326 0, "zero",
327 1, "one",
328 2, "two",
329 3, "three"
330 };
331
332 float matrix[3][3] =
333 {
334 {
335 0,
336 1,
337 2
338 },
339 {
340 3,
341 4,
342 5
343 },
344 {
345 6,
346 7,
347 8
348 }
349 };
350}
351
352{
353 /* blah ( blah */
354 /* where does this go? */
355
356 /* blah ( blah */
357 cmd;
358
359 func(arg1,
360 /* comment */
361 arg2);
362 a;
363 {
364 b;
365 {
366 c; /* Hey, NOW it indents?! */
367 }
368 }
369
370 {
371 func(arg1,
372 arg2,
373 arg3);
374 /* Hey, what am I doing here? Is this coz of the ","? */
375 }
376}
377
378main ()
379{
380 if (cond)
381 {
382 a = b;
383 }
384 if (cond) {
385 a = c;
386 }
387 if (cond)
388 a = d;
389 return;
390}
391
392{
393 case 2: if (asdf &&
394 asdfasdf)
395 aasdf;
396 a = 9;
397 case 3: if (asdf)
398 aasdf;
399 a = 9;
400 case 4: x = 1;
401 y = 2;
402
403label: if (asdf)
404 here;
405
406label: if (asdf &&
407 asdfasdf)
408 {
409 }
410
411label: if (asdf &&
412 asdfasdf) {
413 there;
414 }
415
416label: if (asdf &&
417 asdfasdf)
418 there;
419}
420
421{
422 /*
423 hello with ":set comments= cino=c5"
424 */
425
426 /*
427 hello with ":set comments= cino="
428 */
429}
430
431
432{
433 if (a < b) {
434 a = a + 1;
435 } else
436 a = a + 2;
437
438 if (a)
439 do {
440 testing;
441 } while (asdfasdf);
442 a = b + 1;
443 asdfasdf
444}
445
446class bob
447{
448 int foo() {return 1;}
449 int bar;
450}
451
452main()
453{
454while(1)
455if (foo)
456{
457bar;
458}
459else {
460asdf;
461}
462misplacedline;
463}
464
465{
466 if (clipboard.state == SELECT_DONE
467 && ((row == clipboard.start.lnum
468 && col >= clipboard.start.col)
469 || row > clipboard.start.lnum))
470}
471
472{
473if (1) {i += 4;}
474where_am_i;
475return 0;
476}
477
478{
479{
480} // sdf(asdf
481if (asdf)
482asd;
483}
484
485{
486label1:
487label2:
488}
489
490{
491int fooRet = foo(pBar1, false /*fKB*/,
492 true /*fPTB*/, 3 /*nT*/, false /*fDF*/);
493f() {
494for ( i = 0;
495 i < m;
496 /* c */ i++ ) {
497a = b;
498}
499}
500}
501
502{
503 f1(/*comment*/);
504 f2();
505}
506
507{
508do {
509if (foo) {
510} else
511;
512} while (foo);
513foo(); // was wrong
514}
515
516int x; // no extra indent because of the ;
517void func()
518{
519}
520
521char *tab[] = {"aaa",
522 "};", /* }; */ NULL}
523 int indented;
524{}
525
526char *a[] = {"aaa", "bbb",
527 "ccc", NULL};
528// here
529
530char *tab[] = {"aaa",
531 "xx", /* xx */}; /* asdf */
532int not_indented;
533
534{
535 do {
536 switch (bla)
537 {
538 case 1: if (foo)
539 bar;
540 }
541 } while (boo);
542 wrong;
543}
544
545int foo,
546 bar;
547int foo;
548
549#if defined(foo) \
550 && defined(bar)
551char * xx = "asdf\
552 foo\
553 bor";
554int x;
555
556char *foo = "asdf\
557 asdf\
558 asdf",
559 *bar;
560
561void f()
562{
563#if defined(foo) \
564 && defined(bar)
565char *foo = "asdf\
566 asdf\
567 asdf",
568 *bar;
569 {
570 int i;
571char *foo = "asdf\
572 asdf\
573 asdf",
574 *bar;
575 }
576#endif
577}
578#endif
579
580int y; // comment
581 // comment
582
583 // comment
584
585{
586 Constructor(int a,
587 int b ) : BaseClass(a)
588 {
589 }
590}
591
592void foo()
593{
594 char one,
595 two;
596 struct bla piet,
597 jan;
598 enum foo kees,
599 jannie;
600 static unsigned sdf,
601 krap;
602 unsigned int piet,
603 jan;
604 int
605 kees,
606 jan;
607}
608
609{
610 t(int f,
611 int d); // )
612 d();
613}
614
615Constructor::Constructor(int a,
616 int b
617 ) :
618 BaseClass(a,
619 b,
620 c),
621 mMember(b),
622{
623}
624
625Constructor::Constructor(int a,
626 int b ) :
627 BaseClass(a)
628{
629}
630
631Constructor::Constructor(int a,
632 int b ) /*x*/ : /*x*/ BaseClass(a),
633 member(b)
634{
635}
636
637class CAbc :
638 public BaseClass1,
639 protected BaseClass2
640{
641 int Test() { return FALSE; }
642 int Test1() { return TRUE; }
643
644 CAbc(int a, int b ) :
645 BaseClass(a)
646 {
647 switch(xxx)
648 {
649 case abc:
650 asdf();
651 break;
652
653 case 999:
654 baer();
655 break;
656 }
657 }
658
659public: // <-- this was incoreectly indented before!!
660 void testfall();
661protected:
662 void testfall();
663};
664
665class CAbc : public BaseClass1,
666 protected BaseClass2
667{
668};
669
670static struct
671{
672 int a;
673 int b;
674} variable[COUNT] =
675{
676 {
677 123,
678 456
679 },
680 {
681 123,
682 456
683 }
684};
685
686static struct
687{
688 int a;
689 int b;
690} variable[COUNT] =
691{
692 { 123, 456 },
693 { 123, 456 }
694};
695
696void asdf() /* ind_maxparen may cause trouble here */
697{
698 if ((0
699 && 1
700 && 1
701 && 1
702 && 1
703 && 1
704 && 1
705 && 1
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)) break;
724}
725
Bram Moolenaar18144c82006-04-12 21:52:12 +0000726foo()
727{
728 a = cond ? foo() : asdf
729 + asdf;
730
731 a = cond ?
732 foo() : asdf
733 + asdf;
734}
735
736int main(void)
737{
738 if (a)
739 if (b)
740 2;
741 else 3;
742 next_line_of_code();
743}
744
Bram Moolenaar7fc904b2006-04-13 20:37:35 +0000745barry()
746{
747 Foo::Foo (int one,
748 int two)
749 : something(4)
750 {}
751}
752
753barry()
754{
755 Foo::Foo (int one, int two)
756 : something(4)
757 {}
758}
759
760Constructor::Constructor(int a,
761 int b
762 ) :
763 BaseClass(a,
764 b,
765 c),
766 mMember(b)
767{
768}
769
Bram Moolenaar071d4272004-06-13 20:20:40 +0000770/* end of AUTO */
771
772STARTTEST
773:set tw=0 wm=60 columns=80 noai fo=croq
774/serious/e
775a about life, the universe, and the rest
776ENDTEST
777
778{
779
780/* this is
781 * a real serious important big
782 * comment
783 */
784 /* insert " about life, the universe, and the rest" after "serious" */
785}
786
787STARTTEST
788:set nocin
789/comments
790joabout life/happens
791jothere/below
792oline/this
793Ohello
794ENDTEST
795
796{
797 /*
798 * Testing for comments, without 'cin' set
799 */
800
801/*
802* what happens here?
803*/
804
805 /*
806 the end of the comment, try inserting a line below */
807
808 /* how about
809 this one */
810}
811
812STARTTEST
813:set cin
814/vec2
815==
816ENDTEST
817
818{
819 var = this + that + vec[0] * vec[0]
820 + vec[1] * vec[1]
821 + vec2[2] * vec[2];
822}
823
824STARTTEST
825:set cin
826:set cino=}4
827/testing1
828k2==/testing2
829k2==
830ENDTEST
831
832{
833 asdf asdflkajds f;
834 if (tes & ting) {
835 asdf asdf asdf ;
836 asdfa sdf asdf;
837 }
838 testing1;
839 if (tes & ting)
840 {
841 asdf asdf asdf ;
842 asdfa sdf asdf;
843 }
844 testing2;
845}
846
847STARTTEST
848:set cin
849:set cino=(0,)20
850/main
851=][
852ENDTEST
853
854main ( int first_par, /*
855 * Comment for
856 * first par
857 */
858 int second_par /*
859 * Comment for
860 * second par
861 */
862 )
863{
864 func( first_par, /*
865 * Comment for
866 * first par
867 */
868 second_par /*
869 * Comment for
870 * second par
871 */
872 );
873
874}
875
876STARTTEST
877:set cin
878:set cino=
879]]=][
880ENDTEST
881
882{
883 do
884 {
885 if ()
886 {
887 if ()
888 asdf;
889 else
890 asdf;
891 }
892 } while ();
893 cmd; /* this should go under the } */
894}
895
896STARTTEST
897]]=][
898ENDTEST
899
900void f()
901{
902 if ( k() ) {
903 l();
904
905 } else { /* Start (two words) end */
906 m();
907 }
908
909 n();
910}
911
912STARTTEST
913:set cino={s,e-s
914]]=][
915ENDTEST
916
917void f()
918{
919 if ( k() )
920 {
921 l();
922 } else { /* Start (two words) end */
923 m();
924 }
925 n(); /* should be under the if () */
926}
927
928STARTTEST
929:set cino={s,fs
930]]=/ foo
931ENDTEST
932
933void bar(void)
934{
935 static array[2][2] =
936 {
937 { 1, 2 },
938 { 3, 4 },
939 }
940
941 while (a)
942 {
943 foo(&a);
944 }
945
946 {
947 int a;
948 {
949 a = a + 1;
950 }
951 }
952 b = a;
953 }
954
955void func(void)
956 {
957 a = 1;
958 {
959 b = 2;
960 }
961 c = 3;
962 d = 4;
963 }
964/* foo */
965
966STARTTEST
967:set cino=
968/while
969ohere
970ENDTEST
971
972a()
973{
974 do {
975 a = a +
976 a;
977 } while ( a ); /* add text under this line */
978 if ( a )
979 a;
980}
981
982STARTTEST
983:set cino= com=
984/comment
985olabel2: b(); label3 /* post */: /* pre */ label4: f(/*com*/); if (/*com*/) cmd();
986ENDTEST
987
988a()
989{
990label1:
991 /* hmm */
992 // comment
993}
994
995STARTTEST
996:set comments& comments^=s:/*,m:**,ex:*/
997/simple
998=5j
999ENDTEST
1000
1001/*
1002 * A simple comment
1003 */
1004
1005/*
1006 ** A different comment
1007 */
1008
1009STARTTEST
1010:set cino=c0
1011:set comments& comments-=s1:/* comments^=s0:/*
10122kdd]]=][
1013ENDTEST
1014
1015void f()
1016{
1017
1018 /*********
1019 A comment.
1020*********/
1021}
1022
1023STARTTEST
1024:set cino=c0,C1
1025:set comments& comments-=s1:/* comments^=s0:/*
10262kdd]]=][
1027ENDTEST
1028
1029void f()
1030{
1031
1032 /*********
1033 A comment.
1034*********/
1035}
1036
1037STARTTEST
1038:set cino=
1039]]=][
1040ENDTEST
1041
1042void f()
1043{
1044 c = c1 &&
1045 (
1046 c2 ||
1047 c3
1048 ) && c4;
1049}
1050
1051STARTTEST
1052:set cino=(s
10532kdd]]=][
1054ENDTEST
1055
1056void f()
1057{
1058 c = c1 &&
1059 (
1060 c2 ||
1061 c3
1062 ) && c4;
1063}
1064
1065STARTTEST
1066:set cino=(s,U1
10672kdd]]=][
1068ENDTEST
1069
1070void f()
1071{
1072 c = c1 &&
1073 (
1074 c2 ||
1075 c3
1076 ) && c4;
1077}
1078
1079STARTTEST
1080:set cino=(0
10812kdd]]=][
1082ENDTEST
1083
1084void f()
1085{
1086 if ( c1
1087 && ( c2
1088 || c3))
1089 foo;
1090}
1091
1092STARTTEST
1093:set cino=(0,w1
10942kdd]]=][
1095ENDTEST
1096
1097void f()
1098{
1099 if ( c1
1100 && ( c2
1101 || c3))
1102 foo;
1103}
1104
1105STARTTEST
1106:set cino=(s
11072kdd]]=][
1108ENDTEST
1109
1110void f()
1111{
1112 c = c1 && (
1113 c2 ||
1114 c3
1115 ) && c4;
1116 if (
1117 c1 && c2
1118 )
1119 foo;
1120}
1121
1122STARTTEST
1123:set cino=(s,m1
11242kdd]]=][
1125ENDTEST
1126
1127void f()
1128{
1129 c = c1 && (
1130 c2 ||
1131 c3
1132 ) && c4;
1133 if (
1134 c1 && c2
1135 )
1136 foo;
1137}
1138
1139STARTTEST
1140:set cino=b1
11412kdd]]=][
1142ENDTEST
1143
1144void f()
1145{
1146 switch (x)
1147 {
1148 case 1:
1149 a = b;
1150 break;
1151 default:
1152 a = 0;
1153 break;
1154 }
1155}
1156
1157STARTTEST
1158:set cino=(0,W5
11592kdd]]=][
1160ENDTEST
1161
1162void f()
1163{
1164 invokeme(
1165 argu,
1166 ment);
1167 invokeme(
1168 argu,
1169 ment
1170 );
1171 invokeme(argu,
1172 ment
1173 );
1174}
1175
1176STARTTEST
1177:set cino=/6
11782kdd]]=][
1179ENDTEST
1180
1181void f()
1182{
1183 statement;
1184 // comment 1
1185 // comment 2
1186}
1187
1188STARTTEST
1189:set cino=
11902kdd]]/comment 1/+1
1191==
1192ENDTEST
1193
1194void f()
1195{
1196 statement;
1197 // comment 1
1198 // comment 2
1199}
1200
1201STARTTEST
1202:set cino=g0
12032kdd]]=][
1204ENDTEST
1205
1206class CAbc
1207{
1208 int Test() { return FALSE; }
1209
1210public: // comment
1211 void testfall();
1212protected:
1213 void testfall();
1214};
1215
1216STARTTEST
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00001217:set cino=+20
12182kdd]]=][
1219ENDTEST
1220
1221 void
1222foo()
1223{
1224 if (a)
1225 {
1226 } else
1227 asdf;
1228}
1229
1230STARTTEST
Bram Moolenaar071d4272004-06-13 20:20:40 +00001231:set cino=(0,W2s
12322kdd]]=][
1233ENDTEST
1234
1235{
1236 averylongfunctionnamelongfunctionnameaverylongfunctionname()->asd(
1237 asdasdf,
1238 func(asdf,
1239 asdfadsf),
1240 asdfasdf
1241 );
1242
1243 /* those are ugly, but consequent */
1244
1245 func()->asd(asdasdf,
1246 averylongfunctionname(
1247 abc,
1248 dec)->averylongfunctionname(
1249 asdfadsf,
1250 asdfasdf,
1251 asdfasdf,
1252 ),
1253 func(asdfadf,
1254 asdfasdf
1255 ),
1256 asdasdf
1257 );
1258
1259 averylongfunctionnameaverylongfunctionnameavery()->asd(fasdf(
1260 abc,
1261 dec)->asdfasdfasdf(
1262 asdfadsf,
1263 asdfasdf,
1264 asdfasdf,
1265 ),
1266 func(asdfadf,
1267 asdfasdf),
1268 asdasdf
1269 );
1270}
1271
1272STARTTEST
1273:g/^STARTTEST/.,/^ENDTEST/d
1274:1;/start of AUTO/,$wq! test.out
1275ENDTEST