blob: 4f5331e56c907f1e6bca744d60ea0994ecf10f59 [file] [log] [blame]
Bram Moolenaar071d4272004-06-13 20:20:40 +00001/* vim: set cin ts=4 sw=4 : */
2
3Test for 'cindent'
4
5STARTTEST
6:so small.vim
Bram Moolenaar8c8de832008-06-24 22:58:06 +00007:set nocompatible viminfo+=nviminfo modeline
Bram Moolenaar071d4272004-06-13 20:20:40 +00008:edit " read modeline
9/start of AUTO
10=/end of AUTO
11ENDTEST
12
Bram Moolenaar9e54a0e2006-04-14 20:42:25 +000013/* start of AUTO matically checked vim: set ts=4 : */
Bram Moolenaar071d4272004-06-13 20:20:40 +000014{
15 if (test)
16 cmd1;
17 cmd2;
18}
19
20{
21 if (test)
22 cmd1;
23 else
24 cmd2;
25}
26
27{
28 if (test)
29 {
30 cmd1;
31 cmd2;
32 }
33}
34
35{
36 if (test)
37 {
38 cmd1;
39 else
40 }
41}
42
43{
44 while (this)
45 if (test)
46 cmd1;
47 cmd2;
48}
49
50{
51 while (this)
52 if (test)
53 cmd1;
54 else
55 cmd2;
56}
57
58{
59 if (test)
60 {
61 cmd;
62 }
63
64 if (test)
65 cmd;
66}
67
68{
69 if (test) {
70 cmd;
71 }
72
73 if (test) cmd;
74}
75
76{
77 cmd1;
78 for (blah)
79 while (this)
80 if (test)
81 cmd2;
82 cmd3;
83}
84
85{
86 cmd1;
87 for (blah)
88 while (this)
89 if (test)
90 cmd2;
91 cmd3;
92
93 if (test)
94 {
95 cmd1;
96 cmd2;
97 cmd3;
98 }
99}
100
101
102/* Test for 'cindent' do/while mixed with if/else: */
103
104{
105 do
106 if (asdf)
107 asdfasd;
108 while (cond);
109
110 do
111 if (asdf)
112 while (asdf)
113 asdf;
114 while (asdf);
115}
116
117/* Test for 'cindent' with two ) on a continuation line */
118{
119 if (asdfasdf;asldkfj asdlkfj as;ldkfj sal;d
120 aal;sdkjf ( ;asldfkja;sldfk
121 al;sdjfka ;slkdf ) sa;ldkjfsa dlk;)
122 line up here;
123}
124
125
126/* C++ tests: */
127
128// foo() these three lines should remain in column 0
129// {
130// }
131
132/* Test for continuation and unterminated lines: */
133{
134 i = 99 + 14325 +
135 21345 +
136 21345 +
137 21345 + ( 21345 +
138 21345) +
139 2345 +
140 1234;
141 c = 1;
142}
143
144/*
145 testje for indent with empty line
146
147 here */
148
149{
150 if (testing &&
151 not a joke ||
152 line up here)
153 hay;
154 if (testing &&
155 (not a joke || testing
156 )line up here)
157 hay;
158 if (testing &&
159 (not a joke || testing
160 line up here))
161 hay;
162}
163
164
165{
166 switch (c)
167 {
168 case xx:
169 do
170 if (asdf)
171 do
172 asdfasdf;
173 while (asdf);
174 else
175 asdfasdf;
176 while (cond);
177 case yy:
178 case xx:
179 case zz:
180 testing;
181 }
182}
183
184{
185 if (cond) {
186 foo;
187 }
188 else
189 {
190 bar;
191 }
192}
193
194{
195 if (alskdfj ;alsdkfjal;skdjf (;sadlkfsa ;dlkf j;alksdfj ;alskdjf
196 alsdkfj (asldk;fj
197 awith cino=(0 ;lf this one goes to below the paren with ==
198 ;laksjfd ;lsakdjf ;alskdf asd)
199 asdfasdf;)))
200 asdfasdf;
201}
202
203 int
204func(a, b)
205 int a;
206 int c;
207{
208 if (c1 && (c2 ||
209 c3))
210 foo;
211 if (c1 &&
212 (c2 || c3)
213 )
214}
215
216{
217 while (asd)
218 {
219 if (asdf)
220 if (test)
221 if (that)
222 {
223 if (asdf)
224 do
225 cdasd;
226 while (as
227 df);
228 }
229 else
230 if (asdf)
231 asdf;
232 else
233 asdf;
234 asdf;
235 }
236}
237
238{
239 s = "/*"; b = ';'
240 s = "/*"; b = ';';
241 a = b;
242}
243
244{
245 switch (a)
246 {
247 case a:
248 switch (t)
249 {
250 case 1:
251 cmd;
252 break;
253 case 2:
254 cmd;
255 break;
256 }
257 cmd;
258 break;
259 case b:
260 {
261 int i;
262 cmd;
263 }
264 break;
265 case c: {
266 int i;
267 cmd;
268 }
269 case d: if (cond &&
270 test) { /* this line doesn't work right */
271 int i;
272 cmd;
273 }
274 break;
275 }
276}
277
278{
279 if (!(vim_strchr(p_cpo, CPO_BUFOPTGLOB) != NULL && entering) &&
280 (bp_to->b_p_initialized ||
281 (!entering && vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
282 return;
283label :
284 asdf = asdf ?
285 asdf : asdf;
286 asdf = asdf ?
287 asdf: asdf;
288}
289
290/* Special Comments : This function has the added complexity (compared */
291/* : to addtolist) of having to check for a detail */
292/* : texture and add that to the list first. */
293
294char *(array[100]) = {
295 "testje",
296 "foo",
297 "bar",
298}
299
300enum soppie
301{
Bram Moolenaara5285652011-12-14 20:05:21 +0100302yes = 0,
303no,
304maybe
Bram Moolenaar071d4272004-06-13 20:20:40 +0000305};
306
307typedef enum soppie
308{
Bram Moolenaara5285652011-12-14 20:05:21 +0100309yes = 0,
310no,
311maybe
Bram Moolenaar071d4272004-06-13 20:20:40 +0000312};
313
Bram Moolenaara5285652011-12-14 20:05:21 +0100314static enum
315{
316yes = 0,
317no,
318maybe
319} soppie;
320
Bram Moolenaard999db22013-03-07 13:21:32 +0100321public static enum
322{
323yes = 0,
324no,
325maybe
326} soppie;
327
328static private enum
329{
330yes = 0,
331no,
332maybe
333} soppie;
334
Bram Moolenaar071d4272004-06-13 20:20:40 +0000335{
336 int a,
337 b;
338}
339
340{
341 struct Type
342 {
343 int i;
344 char *str;
345 } var[] =
346 {
347 0, "zero",
348 1, "one",
349 2, "two",
350 3, "three"
351 };
352
353 float matrix[3][3] =
354 {
355 {
356 0,
357 1,
358 2
359 },
360 {
361 3,
362 4,
363 5
364 },
365 {
366 6,
367 7,
368 8
369 }
370 };
371}
372
373{
374 /* blah ( blah */
375 /* where does this go? */
376
377 /* blah ( blah */
378 cmd;
379
380 func(arg1,
381 /* comment */
382 arg2);
383 a;
384 {
385 b;
386 {
387 c; /* Hey, NOW it indents?! */
388 }
389 }
390
391 {
392 func(arg1,
393 arg2,
394 arg3);
395 /* Hey, what am I doing here? Is this coz of the ","? */
396 }
397}
398
399main ()
400{
401 if (cond)
402 {
403 a = b;
404 }
405 if (cond) {
406 a = c;
407 }
408 if (cond)
409 a = d;
410 return;
411}
412
413{
414 case 2: if (asdf &&
415 asdfasdf)
416 aasdf;
417 a = 9;
418 case 3: if (asdf)
419 aasdf;
420 a = 9;
421 case 4: x = 1;
422 y = 2;
423
424label: if (asdf)
425 here;
426
427label: if (asdf &&
428 asdfasdf)
429 {
430 }
431
432label: if (asdf &&
433 asdfasdf) {
434 there;
435 }
436
437label: if (asdf &&
438 asdfasdf)
439 there;
440}
441
442{
443 /*
444 hello with ":set comments= cino=c5"
445 */
446
447 /*
448 hello with ":set comments= cino="
449 */
450}
451
452
453{
454 if (a < b) {
455 a = a + 1;
456 } else
457 a = a + 2;
458
459 if (a)
460 do {
461 testing;
462 } while (asdfasdf);
463 a = b + 1;
464 asdfasdf
465}
466
Bram Moolenaar04d17ae2014-08-06 17:44:14 +0200467{
468for ( int i = 0;
469 i < 10; i++ )
470{
471}
472 i = 0;
473}
474
Bram Moolenaar071d4272004-06-13 20:20:40 +0000475class bob
476{
477 int foo() {return 1;}
478 int bar;
479}
480
481main()
482{
483while(1)
484if (foo)
485{
486bar;
487}
488else {
489asdf;
490}
491misplacedline;
492}
493
494{
495 if (clipboard.state == SELECT_DONE
496 && ((row == clipboard.start.lnum
497 && col >= clipboard.start.col)
498 || row > clipboard.start.lnum))
499}
500
501{
502if (1) {i += 4;}
503where_am_i;
504return 0;
505}
506
507{
508{
509} // sdf(asdf
510if (asdf)
511asd;
512}
513
514{
515label1:
516label2:
517}
518
519{
520int fooRet = foo(pBar1, false /*fKB*/,
521 true /*fPTB*/, 3 /*nT*/, false /*fDF*/);
522f() {
523for ( i = 0;
524 i < m;
525 /* c */ i++ ) {
526a = b;
527}
528}
529}
530
531{
532 f1(/*comment*/);
533 f2();
534}
535
536{
537do {
538if (foo) {
539} else
540;
541} while (foo);
542foo(); // was wrong
543}
544
545int x; // no extra indent because of the ;
546void func()
547{
548}
549
550char *tab[] = {"aaa",
551 "};", /* }; */ NULL}
552 int indented;
553{}
554
555char *a[] = {"aaa", "bbb",
556 "ccc", NULL};
557// here
558
559char *tab[] = {"aaa",
560 "xx", /* xx */}; /* asdf */
561int not_indented;
562
563{
564 do {
565 switch (bla)
566 {
567 case 1: if (foo)
568 bar;
569 }
570 } while (boo);
571 wrong;
572}
573
574int foo,
575 bar;
576int foo;
577
578#if defined(foo) \
579 && defined(bar)
580char * xx = "asdf\
581 foo\
582 bor";
583int x;
584
585char *foo = "asdf\
586 asdf\
587 asdf",
588 *bar;
589
590void f()
591{
592#if defined(foo) \
593 && defined(bar)
594char *foo = "asdf\
595 asdf\
596 asdf",
597 *bar;
598 {
599 int i;
600char *foo = "asdf\
601 asdf\
602 asdf",
603 *bar;
604 }
605#endif
606}
607#endif
608
609int y; // comment
610 // comment
611
612 // comment
613
614{
615 Constructor(int a,
616 int b ) : BaseClass(a)
617 {
618 }
619}
620
621void foo()
622{
623 char one,
624 two;
625 struct bla piet,
626 jan;
627 enum foo kees,
628 jannie;
629 static unsigned sdf,
630 krap;
631 unsigned int piet,
632 jan;
633 int
634 kees,
635 jan;
636}
637
638{
639 t(int f,
640 int d); // )
641 d();
642}
643
644Constructor::Constructor(int a,
645 int b
646 ) :
647 BaseClass(a,
648 b,
649 c),
650 mMember(b),
651{
652}
653
654Constructor::Constructor(int a,
655 int b ) :
656 BaseClass(a)
657{
658}
659
660Constructor::Constructor(int a,
661 int b ) /*x*/ : /*x*/ BaseClass(a),
662 member(b)
663{
664}
665
666class CAbc :
667 public BaseClass1,
668 protected BaseClass2
669{
670 int Test() { return FALSE; }
671 int Test1() { return TRUE; }
672
673 CAbc(int a, int b ) :
674 BaseClass(a)
675 {
676 switch(xxx)
677 {
678 case abc:
679 asdf();
680 break;
681
682 case 999:
683 baer();
684 break;
685 }
686 }
687
688public: // <-- this was incoreectly indented before!!
689 void testfall();
690protected:
691 void testfall();
692};
693
694class CAbc : public BaseClass1,
695 protected BaseClass2
696{
697};
698
699static struct
700{
701 int a;
702 int b;
703} variable[COUNT] =
704{
705 {
706 123,
707 456
708 },
709 {
710 123,
711 456
712 }
713};
714
715static struct
716{
717 int a;
718 int b;
719} variable[COUNT] =
720{
721 { 123, 456 },
722 { 123, 456 }
723};
724
725void asdf() /* ind_maxparen may cause trouble here */
726{
727 if ((0
728 && 1
729 && 1
730 && 1
731 && 1
732 && 1
733 && 1
734 && 1
735 && 1
736 && 1
737 && 1
738 && 1
739 && 1
740 && 1
741 && 1
742 && 1
743 && 1
744 && 1
745 && 1
746 && 1
747 && 1
748 && 1
749 && 1
750 && 1
751 && 1
752 && 1)) break;
753}
754
Bram Moolenaar18144c82006-04-12 21:52:12 +0000755foo()
756{
757 a = cond ? foo() : asdf
758 + asdf;
759
760 a = cond ?
761 foo() : asdf
762 + asdf;
763}
764
765int main(void)
766{
767 if (a)
768 if (b)
769 2;
770 else 3;
771 next_line_of_code();
772}
773
Bram Moolenaar7fc904b2006-04-13 20:37:35 +0000774barry()
775{
776 Foo::Foo (int one,
777 int two)
778 : something(4)
779 {}
780}
781
782barry()
783{
784 Foo::Foo (int one, int two)
785 : something(4)
786 {}
787}
788
789Constructor::Constructor(int a,
790 int b
791 ) :
792 BaseClass(a,
793 b,
794 c),
795 mMember(b)
796{
797}
Bram Moolenaar9e54a0e2006-04-14 20:42:25 +0000798 int main ()
799 {
800 if (lala)
801 do
802 ++(*lolo);
803 while (lili
804 && lele);
805 lulu;
806 }
Bram Moolenaar7fc904b2006-04-13 20:37:35 +0000807
Bram Moolenaar9e54a0e2006-04-14 20:42:25 +0000808int main ()
809{
810switch (c)
811{
812case 'c': if (cond)
813{
814}
815}
816}
817
818main()
819{
820 (void) MyFancyFuasdfadsfnction(
821 argument);
822}
823
824main()
825{
826 char foo[] = "/*";
827 /* as
828 df */
829 hello
830}
Bram Moolenaared38b0a2011-05-25 15:16:18 +0200831
832/* valid namespaces with normal indent */
833namespace
834{
835{
836 111111111111;
837}
838}
839namespace /* test */
840{
841 11111111111111111;
842}
843namespace // test
844{
845 111111111111111111;
846}
847namespace
848{
849 111111111111111111;
850}
851namespace test
852{
853 111111111111111111;
854}
855namespace{
856 111111111111111111;
857}
858namespace test{
859 111111111111111111;
860}
861namespace {
862 111111111111111111;
863}
864namespace test {
865 111111111111111111;
866namespace test2 {
867 22222222222222222;
868}
869}
870
871/* invalid namespaces use block indent */
872namespace test test2 {
873 111111111111111111111;
874}
875namespace11111111111 {
876 111111111111;
877}
878namespace() {
879 1111111111111;
880}
881namespace()
882{
883 111111111111111111;
884}
885namespace test test2
886{
887 1111111111111111111;
888}
889namespace111111111
890{
891 111111111111111111;
892}
893
Bram Moolenaarf7bb86d2015-07-28 21:17:36 +0200894void getstring() {
895/* Raw strings */
896const char* s = R"(
897 test {
898 # comment
899 field: 123
900 }
901 )";
902 }
903
904void getstring() {
905const char* s = R"foo(
906 test {
907 # comment
908 field: 123
909 }
910 )foo";
911 }
912
Bram Moolenaar071d4272004-06-13 20:20:40 +0000913/* end of AUTO */
914
915STARTTEST
916:set tw=0 wm=60 columns=80 noai fo=croq
917/serious/e
918a about life, the universe, and the rest
919ENDTEST
920
921{
922
923/* this is
924 * a real serious important big
925 * comment
926 */
927 /* insert " about life, the universe, and the rest" after "serious" */
928}
929
930STARTTEST
931:set nocin
932/comments
933joabout life/happens
934jothere/below
935oline/this
936Ohello
937ENDTEST
938
939{
940 /*
941 * Testing for comments, without 'cin' set
942 */
943
944/*
945* what happens here?
946*/
947
948 /*
949 the end of the comment, try inserting a line below */
950
951 /* how about
952 this one */
953}
954
955STARTTEST
956:set cin
957/vec2
958==
959ENDTEST
960
961{
962 var = this + that + vec[0] * vec[0]
963 + vec[1] * vec[1]
964 + vec2[2] * vec[2];
965}
966
967STARTTEST
968:set cin
969:set cino=}4
970/testing1
971k2==/testing2
972k2==
973ENDTEST
974
975{
976 asdf asdflkajds f;
977 if (tes & ting) {
978 asdf asdf asdf ;
979 asdfa sdf asdf;
980 }
981 testing1;
982 if (tes & ting)
983 {
984 asdf asdf asdf ;
985 asdfa sdf asdf;
986 }
987 testing2;
988}
989
990STARTTEST
991:set cin
992:set cino=(0,)20
993/main
994=][
995ENDTEST
996
997main ( int first_par, /*
998 * Comment for
999 * first par
1000 */
1001 int second_par /*
1002 * Comment for
1003 * second par
1004 */
1005 )
1006{
1007 func( first_par, /*
1008 * Comment for
1009 * first par
1010 */
1011 second_par /*
1012 * Comment for
1013 * second par
1014 */
1015 );
1016
1017}
1018
1019STARTTEST
1020:set cin
Bram Moolenaar48d27922012-06-13 13:40:48 +02001021:set cino=es,n0s
1022/main
1023=][
1024ENDTEST
1025
1026main(void)
1027{
1028 /* Make sure that cino=X0s is not parsed like cino=Xs. */
1029 if (cond)
1030 foo();
1031 else
1032 {
1033 bar();
1034 }
1035}
1036
1037STARTTEST
1038:set cin
Bram Moolenaar071d4272004-06-13 20:20:40 +00001039:set cino=
1040]]=][
1041ENDTEST
1042
1043{
1044 do
1045 {
1046 if ()
1047 {
1048 if ()
1049 asdf;
1050 else
1051 asdf;
1052 }
1053 } while ();
1054 cmd; /* this should go under the } */
1055}
1056
1057STARTTEST
1058]]=][
1059ENDTEST
1060
1061void f()
1062{
1063 if ( k() ) {
1064 l();
1065
1066 } else { /* Start (two words) end */
1067 m();
1068 }
1069
1070 n();
1071}
1072
1073STARTTEST
1074:set cino={s,e-s
1075]]=][
1076ENDTEST
1077
1078void f()
1079{
1080 if ( k() )
1081 {
1082 l();
1083 } else { /* Start (two words) end */
1084 m();
1085 }
1086 n(); /* should be under the if () */
1087}
1088
1089STARTTEST
1090:set cino={s,fs
1091]]=/ foo
1092ENDTEST
1093
1094void bar(void)
1095{
1096 static array[2][2] =
1097 {
1098 { 1, 2 },
1099 { 3, 4 },
1100 }
1101
1102 while (a)
1103 {
1104 foo(&a);
1105 }
1106
1107 {
1108 int a;
1109 {
1110 a = a + 1;
1111 }
1112 }
1113 b = a;
1114 }
1115
1116void func(void)
1117 {
1118 a = 1;
1119 {
1120 b = 2;
1121 }
1122 c = 3;
1123 d = 4;
1124 }
1125/* foo */
1126
1127STARTTEST
1128:set cino=
1129/while
1130ohere
1131ENDTEST
1132
1133a()
1134{
1135 do {
1136 a = a +
1137 a;
1138 } while ( a ); /* add text under this line */
1139 if ( a )
1140 a;
1141}
1142
1143STARTTEST
1144:set cino= com=
1145/comment
1146olabel2: b(); label3 /* post */: /* pre */ label4: f(/*com*/); if (/*com*/) cmd();
1147ENDTEST
1148
1149a()
1150{
1151label1:
1152 /* hmm */
1153 // comment
1154}
1155
1156STARTTEST
1157:set comments& comments^=s:/*,m:**,ex:*/
1158/simple
1159=5j
1160ENDTEST
1161
1162/*
1163 * A simple comment
1164 */
1165
1166/*
1167 ** A different comment
1168 */
1169
1170STARTTEST
1171:set cino=c0
1172:set comments& comments-=s1:/* comments^=s0:/*
11732kdd]]=][
1174ENDTEST
1175
1176void f()
1177{
1178
1179 /*********
1180 A comment.
1181*********/
1182}
1183
1184STARTTEST
1185:set cino=c0,C1
1186:set comments& comments-=s1:/* comments^=s0:/*
11872kdd]]=][
1188ENDTEST
1189
1190void f()
1191{
1192
1193 /*********
1194 A comment.
1195*********/
1196}
1197
1198STARTTEST
1199:set cino=
1200]]=][
1201ENDTEST
1202
1203void f()
1204{
1205 c = c1 &&
1206 (
1207 c2 ||
1208 c3
1209 ) && c4;
1210}
1211
1212STARTTEST
1213:set cino=(s
12142kdd]]=][
1215ENDTEST
1216
1217void f()
1218{
1219 c = c1 &&
1220 (
1221 c2 ||
1222 c3
1223 ) && c4;
1224}
1225
1226STARTTEST
1227:set cino=(s,U1
12282kdd]]=][
1229ENDTEST
1230
1231void f()
1232{
1233 c = c1 &&
1234 (
1235 c2 ||
1236 c3
1237 ) && c4;
1238}
1239
1240STARTTEST
1241:set cino=(0
12422kdd]]=][
1243ENDTEST
1244
1245void f()
1246{
1247 if ( c1
1248 && ( c2
1249 || c3))
1250 foo;
1251}
1252
1253STARTTEST
1254:set cino=(0,w1
12552kdd]]=][
1256ENDTEST
1257
1258void f()
1259{
1260 if ( c1
1261 && ( c2
1262 || c3))
1263 foo;
1264}
1265
1266STARTTEST
1267:set cino=(s
12682kdd]]=][
1269ENDTEST
1270
1271void f()
1272{
1273 c = c1 && (
1274 c2 ||
1275 c3
1276 ) && c4;
1277 if (
1278 c1 && c2
1279 )
1280 foo;
1281}
1282
1283STARTTEST
1284:set cino=(s,m1
12852kdd]]=][
1286ENDTEST
1287
1288void f()
1289{
1290 c = c1 && (
1291 c2 ||
1292 c3
1293 ) && c4;
1294 if (
1295 c1 && c2
1296 )
1297 foo;
1298}
1299
1300STARTTEST
1301:set cino=b1
13022kdd]]=][
1303ENDTEST
1304
1305void f()
1306{
1307 switch (x)
1308 {
1309 case 1:
1310 a = b;
1311 break;
1312 default:
1313 a = 0;
1314 break;
1315 }
1316}
1317
1318STARTTEST
1319:set cino=(0,W5
13202kdd]]=][
1321ENDTEST
1322
1323void f()
1324{
1325 invokeme(
1326 argu,
1327 ment);
1328 invokeme(
1329 argu,
1330 ment
1331 );
1332 invokeme(argu,
1333 ment
1334 );
1335}
1336
1337STARTTEST
1338:set cino=/6
13392kdd]]=][
1340ENDTEST
1341
1342void f()
1343{
1344 statement;
1345 // comment 1
1346 // comment 2
1347}
1348
1349STARTTEST
1350:set cino=
13512kdd]]/comment 1/+1
1352==
1353ENDTEST
1354
1355void f()
1356{
1357 statement;
1358 // comment 1
1359 // comment 2
1360}
1361
1362STARTTEST
1363:set cino=g0
13642kdd]]=][
1365ENDTEST
1366
1367class CAbc
1368{
1369 int Test() { return FALSE; }
1370
1371public: // comment
1372 void testfall();
1373protected:
1374 void testfall();
1375};
1376
1377STARTTEST
Bram Moolenaare79d1532011-10-04 18:03:47 +02001378:set cino=(0,gs,hs
13792kdd]]=][
1380ENDTEST
1381
1382class Foo : public Bar
1383{
1384public:
1385virtual void method1(void) = 0;
1386virtual void method2(int arg1,
1387int arg2,
1388int arg3) = 0;
1389};
1390
1391STARTTEST
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00001392:set cino=+20
13932kdd]]=][
1394ENDTEST
1395
1396 void
1397foo()
1398{
1399 if (a)
1400 {
1401 } else
1402 asdf;
1403}
1404
1405STARTTEST
Bram Moolenaar071d4272004-06-13 20:20:40 +00001406:set cino=(0,W2s
14072kdd]]=][
1408ENDTEST
1409
1410{
1411 averylongfunctionnamelongfunctionnameaverylongfunctionname()->asd(
1412 asdasdf,
1413 func(asdf,
1414 asdfadsf),
1415 asdfasdf
1416 );
1417
1418 /* those are ugly, but consequent */
1419
1420 func()->asd(asdasdf,
1421 averylongfunctionname(
1422 abc,
1423 dec)->averylongfunctionname(
1424 asdfadsf,
1425 asdfasdf,
1426 asdfasdf,
1427 ),
1428 func(asdfadf,
1429 asdfasdf
1430 ),
1431 asdasdf
1432 );
1433
1434 averylongfunctionnameaverylongfunctionnameavery()->asd(fasdf(
1435 abc,
1436 dec)->asdfasdfasdf(
1437 asdfadsf,
1438 asdfasdf,
1439 asdfasdf,
1440 ),
1441 func(asdfadf,
1442 asdfasdf),
1443 asdasdf
1444 );
1445}
1446
1447STARTTEST
Bram Moolenaar9e54a0e2006-04-14 20:42:25 +00001448:set cino=M1
14492kdd]]=][
1450ENDTEST
1451
1452int main ()
1453{
1454 if (cond1 &&
1455 cond2
1456 )
1457 foo;
1458}
1459
1460STARTTEST
Bram Moolenaar8d2d71d2011-04-28 13:02:09 +02001461:set cino=(0,ts
Bram Moolenaar9f4fe7c2014-07-03 22:57:55 +020014622kdd2j=][
Bram Moolenaar8d2d71d2011-04-28 13:02:09 +02001463ENDTEST
1464
1465void func(int a
1466#if defined(FOO)
1467 , int b
1468 , int c
1469#endif
1470 )
1471{
1472}
1473
1474STARTTEST
1475:set cino=(0
Bram Moolenaar9f4fe7c2014-07-03 22:57:55 +020014762kdd2j=][
Bram Moolenaar8d2d71d2011-04-28 13:02:09 +02001477ENDTEST
1478
1479void
1480func(int a
1481#if defined(FOO)
1482 , int b
1483 , int c
1484#endif
1485 )
1486{
1487}
1488
1489STARTTEST
Bram Moolenaar4ae06c12011-05-10 11:39:19 +02001490:set cino&
Bram Moolenaar9f4fe7c2014-07-03 22:57:55 +020014912kdd2j=7][
Bram Moolenaar4ae06c12011-05-10 11:39:19 +02001492ENDTEST
1493
1494void func(void)
1495{
1496 if(x==y)
1497 if(y==z)
1498 foo=1;
1499 else { bar=1;
1500 baz=2;
1501 }
1502 printf("Foo!\n");
1503}
1504
Bram Moolenaar496f9512011-05-19 16:35:09 +02001505void func1(void)
1506{
1507 char* tab[] = {"foo", "bar",
1508 "baz", "quux",
1509 "this line used", "to be indented incorrectly"};
1510 foo();
1511}
1512
1513void func2(void)
1514{
1515 int tab[] =
1516 {1, 2,
1517 3, 4,
1518 5, 6};
1519
1520 printf("This line used to be indented incorrectly.\n");
1521}
1522
Bram Moolenaar3388bb42011-11-30 17:20:23 +01001523int foo[]
1524#ifdef BAR
1525
1526= { 1, 2, 3,
1527 4, 5, 6 }
1528
1529#endif
1530;
1531 int baz;
1532
Bram Moolenaar496f9512011-05-19 16:35:09 +02001533void func3(void)
1534{
1535 int tab[] = {
1536 1, 2,
1537 3, 4,
1538 5, 6};
1539
Bram Moolenaarc367faa2011-12-14 20:21:35 +01001540printf("Don't you dare indent this line incorrectly!\n");
1541}
1542
1543void
1544func4(a, b,
1545 c)
1546int a;
1547int b;
1548int c;
1549{
1550}
1551
1552void
1553func5(
1554 int a,
1555 int b)
1556{
1557}
1558
1559void
1560func6(
1561 int a)
1562{
Bram Moolenaar496f9512011-05-19 16:35:09 +02001563}
1564
Bram Moolenaar4ae06c12011-05-10 11:39:19 +02001565STARTTEST
Bram Moolenaaraede6ce2011-05-10 11:56:30 +02001566:set cino&
Bram Moolenaar50f42ca2011-07-15 14:12:30 +02001567:set cino+=l1
Bram Moolenaar9f4fe7c2014-07-03 22:57:55 +020015682kdd2j=][
Bram Moolenaar50f42ca2011-07-15 14:12:30 +02001569ENDTEST
1570
1571void func(void)
1572{
1573 int tab[] =
1574 {
1575 1, 2, 3,
1576 4, 5, 6};
1577
1578 printf("Indent this line correctly!\n");
1579
1580 switch (foo)
1581 {
1582 case bar:
1583 printf("bar");
1584 break;
1585 case baz: {
1586 printf("baz");
1587 break;
1588 }
1589 case quux:
1590printf("But don't break the indentation of this instruction\n");
1591break;
1592 }
1593}
1594
1595STARTTEST
1596:set cino&
Bram Moolenaar9f4fe7c2014-07-03 22:57:55 +020015972kdd2j=][
Bram Moolenaaraede6ce2011-05-10 11:56:30 +02001598ENDTEST
1599
1600void func(void)
1601{
1602 cout << "a"
1603 << "b"
1604 << ") :"
1605 << "c";
1606}
1607
1608STARTTEST
Bram Moolenaara4271d52011-05-10 13:38:27 +02001609:set com=s1:/*,m:*,ex:*/
1610]]3jofoo();
1611ENDTEST
1612
1613void func(void)
1614{
1615 /*
1616 * This is a comment.
1617 */
1618}
1619
1620STARTTEST
Bram Moolenaar334adf02011-05-25 13:34:04 +02001621:set cino&
Bram Moolenaar9f4fe7c2014-07-03 22:57:55 +020016222kdd2j=][
Bram Moolenaar334adf02011-05-25 13:34:04 +02001623ENDTEST
1624
1625void func(void)
1626{
1627 for (int i = 0; i < 10; ++i)
1628 if (i & 1) {
1629 foo(1);
1630 } else
1631 foo(0);
1632baz();
1633}
1634
1635STARTTEST
Bram Moolenaar3675fa02012-04-05 17:17:42 +02001636:set cino=k2s,(0
16372kdd3j=][
1638ENDTEST
1639
1640void func(void)
1641{
1642 if (condition1
1643 && condition2)
1644 action();
1645 function(argument1
1646 && argument2);
1647
1648 if (c1 && (c2 ||
1649 c3))
1650 foo;
1651 if (c1 &&
1652 (c2 || c3))
1653 {
1654 }
1655
1656 if ( c1
1657 && ( c2
1658 || c3))
1659 foo;
1660 func( c1
1661 && ( c2
1662 || c3))
1663 foo;
1664}
1665
1666STARTTEST
1667:set cino=k2s,(s
16682kdd3j=][
1669ENDTEST
1670
1671void func(void)
1672{
1673 if (condition1
1674 && condition2)
1675 action();
1676 function(argument1
1677 && argument2);
1678
1679 if (c1 && (c2 ||
1680 c3))
1681 foo;
1682 if (c1 &&
1683 (c2 || c3))
1684 {
1685 }
1686
1687 if ( c1
1688 && ( c2
1689 || c3))
1690 foo;
1691 func( c1
1692 && ( c2
1693 || c3))
1694 foo;
1695}
1696
1697STARTTEST
1698:set cino=k2s,(s,U1
16992kdd3j=][
1700ENDTEST
1701
1702void func(void)
1703{
1704 if (condition1
1705 && condition2)
1706 action();
1707 function(argument1
1708 && argument2);
1709
1710 if (c1 && (c2 ||
1711 c3))
1712 foo;
1713 if (c1 &&
1714 (c2 || c3))
1715 {
1716 }
1717 if (c123456789
1718 && (c22345
1719 || c3))
1720 printf("foo\n");
1721
1722 c = c1 &&
1723 (
1724 c2 ||
1725 c3
1726 ) && c4;
1727}
1728
1729STARTTEST
1730:set cino=k2s,(0,W4
17312kdd3j=][
1732ENDTEST
1733
1734void func(void)
1735{
1736 if (condition1
1737 && condition2)
1738 action();
1739 function(argument1
1740 && argument2);
1741
1742 if (c1 && (c2 ||
1743 c3))
1744 foo;
1745 if (c1 &&
1746 (c2 || c3))
1747 {
1748 }
1749 if (c123456789
1750 && (c22345
1751 || c3))
1752 printf("foo\n");
1753
1754 if ( c1
1755 && ( c2
1756 || c3))
1757 foo;
1758
1759 a_long_line(
1760 argument,
1761 argument);
1762 a_short_line(argument,
1763 argument);
1764}
1765
1766STARTTEST
1767:set cino=k2s,u2
17682kdd3j=][
1769ENDTEST
1770
1771void func(void)
1772{
1773 if (condition1
1774 && condition2)
1775 action();
1776 function(argument1
1777 && argument2);
1778
1779 if (c1 && (c2 ||
1780 c3))
1781 foo;
1782 if (c1 &&
1783 (c2 || c3))
1784 {
1785 }
1786 if (c123456789
1787 && (c22345
1788 || c3))
1789 printf("foo\n");
1790}
1791
1792STARTTEST
1793:set cino=k2s,(0,w1
17942kdd3j=][
1795ENDTEST
1796
1797void func(void)
1798{
1799 if (condition1
1800 && condition2)
1801 action();
1802 function(argument1
1803 && argument2);
1804
1805 if (c1 && (c2 ||
1806 c3))
1807 foo;
1808 if (c1 &&
1809 (c2 || c3))
1810 {
1811 }
1812 if (c123456789
1813 && (c22345
1814 || c3))
1815 printf("foo\n");
1816
1817 if ( c1
1818 && ( c2
1819 || c3))
1820 foo;
1821 func( c1
1822 && ( c2
1823 || c3))
1824 foo;
1825}
1826
1827STARTTEST
1828:set cino=k2,(s
18292kdd3j=][
1830ENDTEST
1831
1832void func(void)
1833{
1834 if (condition1
1835 && condition2)
1836 action();
1837 function(argument1
1838 && argument2);
1839
1840 if (c1 && (c2 ||
1841 c3))
1842 foo;
1843 if (c1 &&
1844 (c2 || c3))
1845 {
1846 }
1847}
1848
1849STARTTEST
Bram Moolenaared38b0a2011-05-25 15:16:18 +02001850:set cino=N-s
Bram Moolenaar6ec154b2011-06-12 21:51:08 +02001851/^NAMESPACESTART
Bram Moolenaared38b0a2011-05-25 15:16:18 +02001852=/^NAMESPACEEND
1853ENDTEST
1854
Bram Moolenaar6ec154b2011-06-12 21:51:08 +02001855NAMESPACESTART
Bram Moolenaared38b0a2011-05-25 15:16:18 +02001856/* valid namespaces with normal indent */
1857namespace
1858{
1859 {
1860 111111111111;
1861}
1862}
1863namespace /* test */
1864{
1865 11111111111111111;
1866}
1867namespace // test
1868{
1869 111111111111111111;
1870}
1871namespace
1872{
1873 111111111111111111;
1874}
1875namespace test
1876{
1877 111111111111111111;
1878}
1879namespace{
1880 111111111111111111;
1881}
1882namespace test{
1883 111111111111111111;
1884}
1885namespace {
1886 111111111111111111;
1887}
1888namespace test {
1889 111111111111111111;
1890namespace test2 {
1891 22222222222222222;
1892}
1893}
1894
1895/* invalid namespaces use block indent */
1896namespace test test2 {
1897 111111111111111111111;
1898}
1899namespace11111111111 {
1900 111111111111;
1901}
1902namespace() {
1903 1111111111111;
1904}
1905namespace()
1906{
1907 111111111111111111;
1908}
1909namespace test test2
1910{
1911 1111111111111111111;
1912}
1913namespace111111111
1914{
1915 111111111111111111;
1916}
1917NAMESPACEEND
1918
1919
1920STARTTEST
Bram Moolenaar76f7fd32011-07-20 15:09:43 +02001921:set cino=j1,J1
Bram Moolenaar6ec154b2011-06-12 21:51:08 +02001922/^JSSTART
1923=/^JSEND
1924ENDTEST
1925
1926JSSTART
1927var bar = {
1928foo: {
1929that: this,
1930some: ok,
1931},
1932"bar":{
1933a : 2,
1934b: "123abc",
1935x: 4,
1936"y": 5
1937}
1938}
1939JSEND
1940
1941STARTTEST
Bram Moolenaar76f7fd32011-07-20 15:09:43 +02001942:set cino=j1,J1
1943/^JSSTART
1944=/^JSEND
1945ENDTEST
1946
1947JSSTART
1948var foo = [
Bram Moolenaar9f4fe7c2014-07-03 22:57:55 +020019491,
Bram Moolenaar76f7fd32011-07-20 15:09:43 +020019502,
19513
Bram Moolenaar9f4fe7c2014-07-03 22:57:55 +02001952];
Bram Moolenaar76f7fd32011-07-20 15:09:43 +02001953JSEND
1954
1955STARTTEST
1956:set cino=j1,J1
1957/^JSSTART
1958=/^JSEND
1959ENDTEST
1960
1961JSSTART
1962function bar() {
1963var foo = [
19641,
19652,
19663
Bram Moolenaar9f4fe7c2014-07-03 22:57:55 +02001967];
Bram Moolenaar76f7fd32011-07-20 15:09:43 +02001968}
1969JSEND
1970
1971STARTTEST
1972:set cino=j1,J1
1973/^JSSTART
1974=/^JSEND
1975ENDTEST
1976
1977JSSTART
1978(function($){
1979
Bram Moolenaar81439a62014-07-02 18:27:48 +02001980if (cond &&
1981cond) {
1982stmt;
1983}
Bram Moolenaar9f4fe7c2014-07-03 22:57:55 +02001984window.something.left =
1985(width - 50 + offset) + "px";
Bram Moolenaar76f7fd32011-07-20 15:09:43 +02001986var class_name='myclass';
1987
1988function private_method() {
1989}
1990
1991var public_method={
1992method: function(options,args){
1993private_method();
1994}
1995}
1996
1997function init(options) {
1998
1999$(this).data(class_name+'_public',$.extend({},{
2000foo: 'bar',
Bram Moolenaar9f4fe7c2014-07-03 22:57:55 +02002001bar: 2,
2002foobar: [
20031,
20042,
20053
Bram Moolenaar76f7fd32011-07-20 15:09:43 +02002006],
Bram Moolenaar9f4fe7c2014-07-03 22:57:55 +02002007callback: function(){
2008return true;
2009}
Bram Moolenaar76f7fd32011-07-20 15:09:43 +02002010}, options||{}));
2011}
2012
2013$.fn[class_name]=function() {
2014
2015var _arguments=arguments;
2016return this.each(function(){
2017
2018var options=$(this).data(class_name+'_public');
2019if (!options) {
2020init.apply(this,_arguments);
2021
2022} else {
2023var method=public_method[_arguments[0]];
2024
2025if (typeof(method)!='function') {
2026console.log(class_name+' has no method "'+_arguments[0]+'"');
2027return false;
2028}
2029_arguments[0]=options;
2030method.apply(this,_arguments);
2031}
2032});
2033}
2034
2035})(jQuery);
2036JSEND
2037
2038STARTTEST
2039:set cino=j1,J1
2040/^JSSTART
2041=/^JSEND
2042ENDTEST
2043
2044JSSTART
2045function init(options) {
2046$(this).data(class_name+'_public',$.extend({},{
2047foo: 'bar',
2048bar: 2,
2049foobar: [
Bram Moolenaar9f4fe7c2014-07-03 22:57:55 +020020501,
20512,
20523
Bram Moolenaar76f7fd32011-07-20 15:09:43 +02002053],
2054callback: function(){
2055return true;
2056}
2057}, options||{}));
2058}
2059JSEND
2060
2061STARTTEST
2062:set cino=j1,J1
2063/^JSSTART
2064=/^JSEND
2065ENDTEST
2066
2067JSSTART
2068(function($){
2069function init(options) {
2070$(this).data(class_name+'_public',$.extend({},{
2071foo: 'bar',
Bram Moolenaar9f4fe7c2014-07-03 22:57:55 +02002072bar: 2,
2073foobar: [
20741,
20752,
20763
Bram Moolenaar76f7fd32011-07-20 15:09:43 +02002077],
Bram Moolenaar9f4fe7c2014-07-03 22:57:55 +02002078callback: function(){
2079return true;
2080}
Bram Moolenaar76f7fd32011-07-20 15:09:43 +02002081}, options||{}));
2082}
2083})(jQuery);
2084JSEND
2085
2086STARTTEST
Bram Moolenaardcefba92015-03-20 19:06:06 +01002087:set cino=j1,J1,+2
2088/^JSSTART
2089=/^JSEND
2090ENDTEST
2091
2092JSSTART
2093// Results of JavaScript indent
2094// 1
2095(function(){
2096var a = [
2097'a',
2098'b',
2099'c',
2100'd',
2101'e',
2102'f',
2103'g',
2104'h',
2105'i'
2106];
2107}())
2108
2109// 2
2110(function(){
2111var a = [
21120 +
21135 *
21149 *
2115'a',
2116'b',
21170 +
21185 *
21199 *
2120'c',
2121'd',
2122'e',
2123'f',
2124'g',
2125'h',
2126'i'
2127];
2128}())
2129
2130// 3
2131(function(){
2132var a = [
21330 +
2134// comment 1
21355 *
2136/* comment 2 */
21379 *
2138'a',
2139'b',
21400 +
21415 *
21429 *
2143'c',
2144'd',
2145'e',
2146'f',
2147'g',
2148'h',
2149'i'
2150];
2151}())
2152
2153// 4
2154{
2155var a = [
21560,
21571
2158];
2159var b;
2160var c;
2161}
2162
2163// 5
2164{
2165var a = [
2166[
21670
2168],
21692,
21703
2171];
2172}
2173
2174// 6
2175{
2176var a = [
2177[
21780,
21791
2180],
21812,
21823
2183];
2184}
2185
2186// 7
2187{
2188var a = [
2189// [
21900,
2191// 1
2192// ],
21932,
21943
2195];
2196}
2197
2198// 8
2199var x = [
2200(function(){
2201var a,
2202b,
2203c,
2204d,
2205e,
2206f,
2207g,
2208h,
2209i;
2210})
2211];
2212
2213// 9
2214var a = [
22150 +
22165 *
22179 *
2218'a',
2219'b',
22200 +
22215 *
22229 *
2223'c',
2224'd',
2225'e',
2226'f',
2227'g',
2228'h',
2229'i'
2230];
2231
2232// 10
2233var a,
2234b,
2235c,
2236d,
2237e,
2238f,
2239g,
2240h,
2241i;
2242JSEND
2243
2244STARTTEST
Bram Moolenaar071d4272004-06-13 20:20:40 +00002245:g/^STARTTEST/.,/^ENDTEST/d
2246:1;/start of AUTO/,$wq! test.out
2247ENDTEST