blob: 67fc131de0fa07f3fd471b8dbfe4f22882d03ffe [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
980:set cino=
981]]=][
982ENDTEST
983
984{
985 do
986 {
987 if ()
988 {
989 if ()
990 asdf;
991 else
992 asdf;
993 }
994 } while ();
995 cmd; /* this should go under the } */
996}
997
998STARTTEST
999]]=][
1000ENDTEST
1001
1002void f()
1003{
1004 if ( k() ) {
1005 l();
1006
1007 } else { /* Start (two words) end */
1008 m();
1009 }
1010
1011 n();
1012}
1013
1014STARTTEST
1015:set cino={s,e-s
1016]]=][
1017ENDTEST
1018
1019void f()
1020{
1021 if ( k() )
1022 {
1023 l();
1024 } else { /* Start (two words) end */
1025 m();
1026 }
1027 n(); /* should be under the if () */
1028}
1029
1030STARTTEST
1031:set cino={s,fs
1032]]=/ foo
1033ENDTEST
1034
1035void bar(void)
1036{
1037 static array[2][2] =
1038 {
1039 { 1, 2 },
1040 { 3, 4 },
1041 }
1042
1043 while (a)
1044 {
1045 foo(&a);
1046 }
1047
1048 {
1049 int a;
1050 {
1051 a = a + 1;
1052 }
1053 }
1054 b = a;
1055 }
1056
1057void func(void)
1058 {
1059 a = 1;
1060 {
1061 b = 2;
1062 }
1063 c = 3;
1064 d = 4;
1065 }
1066/* foo */
1067
1068STARTTEST
1069:set cino=
1070/while
1071ohere
1072ENDTEST
1073
1074a()
1075{
1076 do {
1077 a = a +
1078 a;
1079 } while ( a ); /* add text under this line */
1080 if ( a )
1081 a;
1082}
1083
1084STARTTEST
1085:set cino= com=
1086/comment
1087olabel2: b(); label3 /* post */: /* pre */ label4: f(/*com*/); if (/*com*/) cmd();
1088ENDTEST
1089
1090a()
1091{
1092label1:
1093 /* hmm */
1094 // comment
1095}
1096
1097STARTTEST
1098:set comments& comments^=s:/*,m:**,ex:*/
1099/simple
1100=5j
1101ENDTEST
1102
1103/*
1104 * A simple comment
1105 */
1106
1107/*
1108 ** A different comment
1109 */
1110
1111STARTTEST
1112:set cino=c0
1113:set comments& comments-=s1:/* comments^=s0:/*
11142kdd]]=][
1115ENDTEST
1116
1117void f()
1118{
1119
1120 /*********
1121 A comment.
1122*********/
1123}
1124
1125STARTTEST
1126:set cino=c0,C1
1127:set comments& comments-=s1:/* comments^=s0:/*
11282kdd]]=][
1129ENDTEST
1130
1131void f()
1132{
1133
1134 /*********
1135 A comment.
1136*********/
1137}
1138
1139STARTTEST
1140:set cino=
1141]]=][
1142ENDTEST
1143
1144void f()
1145{
1146 c = c1 &&
1147 (
1148 c2 ||
1149 c3
1150 ) && c4;
1151}
1152
1153STARTTEST
1154:set cino=(s
11552kdd]]=][
1156ENDTEST
1157
1158void f()
1159{
1160 c = c1 &&
1161 (
1162 c2 ||
1163 c3
1164 ) && c4;
1165}
1166
1167STARTTEST
1168:set cino=(s,U1
11692kdd]]=][
1170ENDTEST
1171
1172void f()
1173{
1174 c = c1 &&
1175 (
1176 c2 ||
1177 c3
1178 ) && c4;
1179}
1180
1181STARTTEST
1182:set cino=(0
11832kdd]]=][
1184ENDTEST
1185
1186void f()
1187{
1188 if ( c1
1189 && ( c2
1190 || c3))
1191 foo;
1192}
1193
1194STARTTEST
1195:set cino=(0,w1
11962kdd]]=][
1197ENDTEST
1198
1199void f()
1200{
1201 if ( c1
1202 && ( c2
1203 || c3))
1204 foo;
1205}
1206
1207STARTTEST
1208:set cino=(s
12092kdd]]=][
1210ENDTEST
1211
1212void f()
1213{
1214 c = c1 && (
1215 c2 ||
1216 c3
1217 ) && c4;
1218 if (
1219 c1 && c2
1220 )
1221 foo;
1222}
1223
1224STARTTEST
1225:set cino=(s,m1
12262kdd]]=][
1227ENDTEST
1228
1229void f()
1230{
1231 c = c1 && (
1232 c2 ||
1233 c3
1234 ) && c4;
1235 if (
1236 c1 && c2
1237 )
1238 foo;
1239}
1240
1241STARTTEST
1242:set cino=b1
12432kdd]]=][
1244ENDTEST
1245
1246void f()
1247{
1248 switch (x)
1249 {
1250 case 1:
1251 a = b;
1252 break;
1253 default:
1254 a = 0;
1255 break;
1256 }
1257}
1258
1259STARTTEST
1260:set cino=(0,W5
12612kdd]]=][
1262ENDTEST
1263
1264void f()
1265{
1266 invokeme(
1267 argu,
1268 ment);
1269 invokeme(
1270 argu,
1271 ment
1272 );
1273 invokeme(argu,
1274 ment
1275 );
1276}
1277
1278STARTTEST
1279:set cino=/6
12802kdd]]=][
1281ENDTEST
1282
1283void f()
1284{
1285 statement;
1286 // comment 1
1287 // comment 2
1288}
1289
1290STARTTEST
1291:set cino=
12922kdd]]/comment 1/+1
1293==
1294ENDTEST
1295
1296void f()
1297{
1298 statement;
1299 // comment 1
1300 // comment 2
1301}
1302
1303STARTTEST
1304:set cino=g0
13052kdd]]=][
1306ENDTEST
1307
1308class CAbc
1309{
1310 int Test() { return FALSE; }
1311
1312public: // comment
1313 void testfall();
1314protected:
1315 void testfall();
1316};
1317
1318STARTTEST
Bram Moolenaare79d1532011-10-04 18:03:47 +02001319:set cino=(0,gs,hs
13202kdd]]=][
1321ENDTEST
1322
1323class Foo : public Bar
1324{
1325public:
1326virtual void method1(void) = 0;
1327virtual void method2(int arg1,
1328int arg2,
1329int arg3) = 0;
1330};
1331
1332STARTTEST
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00001333:set cino=+20
13342kdd]]=][
1335ENDTEST
1336
1337 void
1338foo()
1339{
1340 if (a)
1341 {
1342 } else
1343 asdf;
1344}
1345
1346STARTTEST
Bram Moolenaar071d4272004-06-13 20:20:40 +00001347:set cino=(0,W2s
13482kdd]]=][
1349ENDTEST
1350
1351{
1352 averylongfunctionnamelongfunctionnameaverylongfunctionname()->asd(
1353 asdasdf,
1354 func(asdf,
1355 asdfadsf),
1356 asdfasdf
1357 );
1358
1359 /* those are ugly, but consequent */
1360
1361 func()->asd(asdasdf,
1362 averylongfunctionname(
1363 abc,
1364 dec)->averylongfunctionname(
1365 asdfadsf,
1366 asdfasdf,
1367 asdfasdf,
1368 ),
1369 func(asdfadf,
1370 asdfasdf
1371 ),
1372 asdasdf
1373 );
1374
1375 averylongfunctionnameaverylongfunctionnameavery()->asd(fasdf(
1376 abc,
1377 dec)->asdfasdfasdf(
1378 asdfadsf,
1379 asdfasdf,
1380 asdfasdf,
1381 ),
1382 func(asdfadf,
1383 asdfasdf),
1384 asdasdf
1385 );
1386}
1387
1388STARTTEST
Bram Moolenaar9e54a0e2006-04-14 20:42:25 +00001389:set cino=M1
13902kdd]]=][
1391ENDTEST
1392
1393int main ()
1394{
1395 if (cond1 &&
1396 cond2
1397 )
1398 foo;
1399}
1400
1401STARTTEST
Bram Moolenaar8d2d71d2011-04-28 13:02:09 +02001402:set cino=(0,ts
14032kdd=][
1404ENDTEST
1405
1406void func(int a
1407#if defined(FOO)
1408 , int b
1409 , int c
1410#endif
1411 )
1412{
1413}
1414
1415STARTTEST
1416:set cino=(0
14172kdd=][
1418ENDTEST
1419
1420void
1421func(int a
1422#if defined(FOO)
1423 , int b
1424 , int c
1425#endif
1426 )
1427{
1428}
1429
1430STARTTEST
Bram Moolenaar4ae06c12011-05-10 11:39:19 +02001431:set cino&
Bram Moolenaarc367faa2011-12-14 20:21:35 +010014322kdd=7][
Bram Moolenaar4ae06c12011-05-10 11:39:19 +02001433ENDTEST
1434
1435void func(void)
1436{
1437 if(x==y)
1438 if(y==z)
1439 foo=1;
1440 else { bar=1;
1441 baz=2;
1442 }
1443 printf("Foo!\n");
1444}
1445
Bram Moolenaar496f9512011-05-19 16:35:09 +02001446void func1(void)
1447{
1448 char* tab[] = {"foo", "bar",
1449 "baz", "quux",
1450 "this line used", "to be indented incorrectly"};
1451 foo();
1452}
1453
1454void func2(void)
1455{
1456 int tab[] =
1457 {1, 2,
1458 3, 4,
1459 5, 6};
1460
1461 printf("This line used to be indented incorrectly.\n");
1462}
1463
Bram Moolenaar3388bb42011-11-30 17:20:23 +01001464int foo[]
1465#ifdef BAR
1466
1467= { 1, 2, 3,
1468 4, 5, 6 }
1469
1470#endif
1471;
1472 int baz;
1473
Bram Moolenaar496f9512011-05-19 16:35:09 +02001474void func3(void)
1475{
1476 int tab[] = {
1477 1, 2,
1478 3, 4,
1479 5, 6};
1480
Bram Moolenaarc367faa2011-12-14 20:21:35 +01001481printf("Don't you dare indent this line incorrectly!\n");
1482}
1483
1484void
1485func4(a, b,
1486 c)
1487int a;
1488int b;
1489int c;
1490{
1491}
1492
1493void
1494func5(
1495 int a,
1496 int b)
1497{
1498}
1499
1500void
1501func6(
1502 int a)
1503{
Bram Moolenaar496f9512011-05-19 16:35:09 +02001504}
1505
Bram Moolenaar4ae06c12011-05-10 11:39:19 +02001506STARTTEST
Bram Moolenaaraede6ce2011-05-10 11:56:30 +02001507:set cino&
Bram Moolenaar50f42ca2011-07-15 14:12:30 +02001508:set cino+=l1
15092kdd=][
1510ENDTEST
1511
1512void func(void)
1513{
1514 int tab[] =
1515 {
1516 1, 2, 3,
1517 4, 5, 6};
1518
1519 printf("Indent this line correctly!\n");
1520
1521 switch (foo)
1522 {
1523 case bar:
1524 printf("bar");
1525 break;
1526 case baz: {
1527 printf("baz");
1528 break;
1529 }
1530 case quux:
1531printf("But don't break the indentation of this instruction\n");
1532break;
1533 }
1534}
1535
1536STARTTEST
1537:set cino&
Bram Moolenaaraede6ce2011-05-10 11:56:30 +020015382kdd=][
1539ENDTEST
1540
1541void func(void)
1542{
1543 cout << "a"
1544 << "b"
1545 << ") :"
1546 << "c";
1547}
1548
1549STARTTEST
Bram Moolenaara4271d52011-05-10 13:38:27 +02001550:set com=s1:/*,m:*,ex:*/
1551]]3jofoo();
1552ENDTEST
1553
1554void func(void)
1555{
1556 /*
1557 * This is a comment.
1558 */
1559}
1560
1561STARTTEST
Bram Moolenaar334adf02011-05-25 13:34:04 +02001562:set cino&
15632kdd=][
1564ENDTEST
1565
1566void func(void)
1567{
1568 for (int i = 0; i < 10; ++i)
1569 if (i & 1) {
1570 foo(1);
1571 } else
1572 foo(0);
1573baz();
1574}
1575
1576STARTTEST
Bram Moolenaar3675fa02012-04-05 17:17:42 +02001577:set cino=k2s,(0
15782kdd3j=][
1579ENDTEST
1580
1581void func(void)
1582{
1583 if (condition1
1584 && condition2)
1585 action();
1586 function(argument1
1587 && argument2);
1588
1589 if (c1 && (c2 ||
1590 c3))
1591 foo;
1592 if (c1 &&
1593 (c2 || c3))
1594 {
1595 }
1596
1597 if ( c1
1598 && ( c2
1599 || c3))
1600 foo;
1601 func( c1
1602 && ( c2
1603 || c3))
1604 foo;
1605}
1606
1607STARTTEST
1608:set cino=k2s,(s
16092kdd3j=][
1610ENDTEST
1611
1612void func(void)
1613{
1614 if (condition1
1615 && condition2)
1616 action();
1617 function(argument1
1618 && argument2);
1619
1620 if (c1 && (c2 ||
1621 c3))
1622 foo;
1623 if (c1 &&
1624 (c2 || c3))
1625 {
1626 }
1627
1628 if ( c1
1629 && ( c2
1630 || c3))
1631 foo;
1632 func( c1
1633 && ( c2
1634 || c3))
1635 foo;
1636}
1637
1638STARTTEST
1639:set cino=k2s,(s,U1
16402kdd3j=][
1641ENDTEST
1642
1643void func(void)
1644{
1645 if (condition1
1646 && condition2)
1647 action();
1648 function(argument1
1649 && argument2);
1650
1651 if (c1 && (c2 ||
1652 c3))
1653 foo;
1654 if (c1 &&
1655 (c2 || c3))
1656 {
1657 }
1658 if (c123456789
1659 && (c22345
1660 || c3))
1661 printf("foo\n");
1662
1663 c = c1 &&
1664 (
1665 c2 ||
1666 c3
1667 ) && c4;
1668}
1669
1670STARTTEST
1671:set cino=k2s,(0,W4
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 if ( c1
1696 && ( c2
1697 || c3))
1698 foo;
1699
1700 a_long_line(
1701 argument,
1702 argument);
1703 a_short_line(argument,
1704 argument);
1705}
1706
1707STARTTEST
1708:set cino=k2s,u2
17092kdd3j=][
1710ENDTEST
1711
1712void func(void)
1713{
1714 if (condition1
1715 && condition2)
1716 action();
1717 function(argument1
1718 && argument2);
1719
1720 if (c1 && (c2 ||
1721 c3))
1722 foo;
1723 if (c1 &&
1724 (c2 || c3))
1725 {
1726 }
1727 if (c123456789
1728 && (c22345
1729 || c3))
1730 printf("foo\n");
1731}
1732
1733STARTTEST
1734:set cino=k2s,(0,w1
17352kdd3j=][
1736ENDTEST
1737
1738void func(void)
1739{
1740 if (condition1
1741 && condition2)
1742 action();
1743 function(argument1
1744 && argument2);
1745
1746 if (c1 && (c2 ||
1747 c3))
1748 foo;
1749 if (c1 &&
1750 (c2 || c3))
1751 {
1752 }
1753 if (c123456789
1754 && (c22345
1755 || c3))
1756 printf("foo\n");
1757
1758 if ( c1
1759 && ( c2
1760 || c3))
1761 foo;
1762 func( c1
1763 && ( c2
1764 || c3))
1765 foo;
1766}
1767
1768STARTTEST
1769:set cino=k2,(s
17702kdd3j=][
1771ENDTEST
1772
1773void func(void)
1774{
1775 if (condition1
1776 && condition2)
1777 action();
1778 function(argument1
1779 && argument2);
1780
1781 if (c1 && (c2 ||
1782 c3))
1783 foo;
1784 if (c1 &&
1785 (c2 || c3))
1786 {
1787 }
1788}
1789
1790STARTTEST
Bram Moolenaared38b0a2011-05-25 15:16:18 +02001791:set cino=N-s
Bram Moolenaar6ec154b2011-06-12 21:51:08 +02001792/^NAMESPACESTART
Bram Moolenaared38b0a2011-05-25 15:16:18 +02001793=/^NAMESPACEEND
1794ENDTEST
1795
Bram Moolenaar6ec154b2011-06-12 21:51:08 +02001796NAMESPACESTART
Bram Moolenaared38b0a2011-05-25 15:16:18 +02001797/* valid namespaces with normal indent */
1798namespace
1799{
1800 {
1801 111111111111;
1802}
1803}
1804namespace /* test */
1805{
1806 11111111111111111;
1807}
1808namespace // test
1809{
1810 111111111111111111;
1811}
1812namespace
1813{
1814 111111111111111111;
1815}
1816namespace test
1817{
1818 111111111111111111;
1819}
1820namespace{
1821 111111111111111111;
1822}
1823namespace test{
1824 111111111111111111;
1825}
1826namespace {
1827 111111111111111111;
1828}
1829namespace test {
1830 111111111111111111;
1831namespace test2 {
1832 22222222222222222;
1833}
1834}
1835
1836/* invalid namespaces use block indent */
1837namespace test test2 {
1838 111111111111111111111;
1839}
1840namespace11111111111 {
1841 111111111111;
1842}
1843namespace() {
1844 1111111111111;
1845}
1846namespace()
1847{
1848 111111111111111111;
1849}
1850namespace test test2
1851{
1852 1111111111111111111;
1853}
1854namespace111111111
1855{
1856 111111111111111111;
1857}
1858NAMESPACEEND
1859
1860
1861STARTTEST
Bram Moolenaar76f7fd32011-07-20 15:09:43 +02001862:set cino=j1,J1
Bram Moolenaar6ec154b2011-06-12 21:51:08 +02001863/^JSSTART
1864=/^JSEND
1865ENDTEST
1866
1867JSSTART
1868var bar = {
1869foo: {
1870that: this,
1871some: ok,
1872},
1873"bar":{
1874a : 2,
1875b: "123abc",
1876x: 4,
1877"y": 5
1878}
1879}
1880JSEND
1881
1882STARTTEST
Bram Moolenaar76f7fd32011-07-20 15:09:43 +02001883:set cino=j1,J1
1884/^JSSTART
1885=/^JSEND
1886ENDTEST
1887
1888JSSTART
1889var foo = [
18901, // indent 8 more
18912,
18923
1893]; // indent 8 less
1894JSEND
1895
1896STARTTEST
1897:set cino=j1,J1
1898/^JSSTART
1899=/^JSEND
1900ENDTEST
1901
1902JSSTART
1903function bar() {
1904var foo = [
19051,
19062,
19073
1908]; // indent 16 less
1909}
1910JSEND
1911
1912STARTTEST
1913:set cino=j1,J1
1914/^JSSTART
1915=/^JSEND
1916ENDTEST
1917
1918JSSTART
1919(function($){
1920
1921var class_name='myclass';
1922
1923function private_method() {
1924}
1925
1926var public_method={
1927method: function(options,args){
1928private_method();
1929}
1930}
1931
1932function init(options) {
1933
1934$(this).data(class_name+'_public',$.extend({},{
1935foo: 'bar',
1936bar: 2, // indent 8 more
1937foobar: [ // indent 8 more
19381, // indent 8 more
19392, // indent 16 more
19403 // indent 16 more
1941],
1942callback: function(){ // indent 8 more
1943return true; // indent 8 more
1944} // indent 8 more
1945}, options||{}));
1946}
1947
1948$.fn[class_name]=function() {
1949
1950var _arguments=arguments;
1951return this.each(function(){
1952
1953var options=$(this).data(class_name+'_public');
1954if (!options) {
1955init.apply(this,_arguments);
1956
1957} else {
1958var method=public_method[_arguments[0]];
1959
1960if (typeof(method)!='function') {
1961console.log(class_name+' has no method "'+_arguments[0]+'"');
1962return false;
1963}
1964_arguments[0]=options;
1965method.apply(this,_arguments);
1966}
1967});
1968}
1969
1970})(jQuery);
1971JSEND
1972
1973STARTTEST
1974:set cino=j1,J1
1975/^JSSTART
1976=/^JSEND
1977ENDTEST
1978
1979JSSTART
1980function init(options) {
1981$(this).data(class_name+'_public',$.extend({},{
1982foo: 'bar',
1983bar: 2,
1984foobar: [
19851, // indent 8 more
19862, // indent 8 more
19873 // indent 8 more
1988],
1989callback: function(){
1990return true;
1991}
1992}, options||{}));
1993}
1994JSEND
1995
1996STARTTEST
1997:set cino=j1,J1
1998/^JSSTART
1999=/^JSEND
2000ENDTEST
2001
2002JSSTART
2003(function($){
2004function init(options) {
2005$(this).data(class_name+'_public',$.extend({},{
2006foo: 'bar',
2007bar: 2, // indent 8 more
2008foobar: [ // indent 8 more
20091, // indent 8 more
20102, // indent 16 more
20113 // indent 16 more
2012],
2013callback: function(){ // indent 8 more
2014return true; // indent 8 more
2015} // indent 8 more
2016}, options||{}));
2017}
2018})(jQuery);
2019JSEND
2020
2021STARTTEST
Bram Moolenaar071d4272004-06-13 20:20:40 +00002022:g/^STARTTEST/.,/^ENDTEST/d
2023:1;/start of AUTO/,$wq! test.out
2024ENDTEST