blob: f3d4f182f8839852e0565f22de0cd06733264943 [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 Moolenaar089af182015-10-07 11:41:49 +0200913{
914int a[4] = {
915[0] = 0,
916[1] = 1,
917[2] = 2,
918[3] = 3,
919};
920}
921
922{
923a = b[2]
924+ 3;
925}
926
927{
928if (1)
929/* aaaaa
930* bbbbb
931*/
932a = 1;
933}
934
Bram Moolenaard1b15de2015-10-13 16:13:39 +0200935void func()
936{
937switch (foo)
938{
939case (bar):
940if (baz())
941quux();
942break;
943case (shmoo):
944if (!bar)
945{
946}
947case (foo1):
948switch (bar)
949{
950case baz:
951baz_f();
952break;
953}
954break;
955default:
956baz();
957baz();
958break;
959}
960}
961
Bram Moolenaar071d4272004-06-13 20:20:40 +0000962/* end of AUTO */
963
964STARTTEST
965:set tw=0 wm=60 columns=80 noai fo=croq
966/serious/e
967a about life, the universe, and the rest
968ENDTEST
969
970{
971
972/* this is
973 * a real serious important big
974 * comment
975 */
976 /* insert " about life, the universe, and the rest" after "serious" */
977}
978
979STARTTEST
980:set nocin
981/comments
982joabout life/happens
983jothere/below
984oline/this
985Ohello
986ENDTEST
987
988{
989 /*
990 * Testing for comments, without 'cin' set
991 */
992
993/*
994* what happens here?
995*/
996
997 /*
998 the end of the comment, try inserting a line below */
999
1000 /* how about
1001 this one */
1002}
1003
1004STARTTEST
1005:set cin
1006/vec2
1007==
1008ENDTEST
1009
1010{
1011 var = this + that + vec[0] * vec[0]
1012 + vec[1] * vec[1]
1013 + vec2[2] * vec[2];
1014}
1015
1016STARTTEST
1017:set cin
1018:set cino=}4
1019/testing1
1020k2==/testing2
1021k2==
1022ENDTEST
1023
1024{
1025 asdf asdflkajds f;
1026 if (tes & ting) {
1027 asdf asdf asdf ;
1028 asdfa sdf asdf;
1029 }
1030 testing1;
1031 if (tes & ting)
1032 {
1033 asdf asdf asdf ;
1034 asdfa sdf asdf;
1035 }
1036 testing2;
1037}
1038
1039STARTTEST
1040:set cin
1041:set cino=(0,)20
1042/main
1043=][
1044ENDTEST
1045
1046main ( int first_par, /*
1047 * Comment for
1048 * first par
1049 */
1050 int second_par /*
1051 * Comment for
1052 * second par
1053 */
1054 )
1055{
1056 func( first_par, /*
1057 * Comment for
1058 * first par
1059 */
1060 second_par /*
1061 * Comment for
1062 * second par
1063 */
1064 );
1065
1066}
1067
1068STARTTEST
1069:set cin
Bram Moolenaar48d27922012-06-13 13:40:48 +02001070:set cino=es,n0s
1071/main
1072=][
1073ENDTEST
1074
1075main(void)
1076{
1077 /* Make sure that cino=X0s is not parsed like cino=Xs. */
1078 if (cond)
1079 foo();
1080 else
1081 {
1082 bar();
1083 }
1084}
1085
1086STARTTEST
1087:set cin
Bram Moolenaar071d4272004-06-13 20:20:40 +00001088:set cino=
1089]]=][
1090ENDTEST
1091
1092{
1093 do
1094 {
1095 if ()
1096 {
1097 if ()
1098 asdf;
1099 else
1100 asdf;
1101 }
1102 } while ();
1103 cmd; /* this should go under the } */
1104}
1105
1106STARTTEST
1107]]=][
1108ENDTEST
1109
1110void f()
1111{
1112 if ( k() ) {
1113 l();
1114
1115 } else { /* Start (two words) end */
1116 m();
1117 }
1118
1119 n();
1120}
1121
1122STARTTEST
1123:set cino={s,e-s
1124]]=][
1125ENDTEST
1126
1127void f()
1128{
1129 if ( k() )
1130 {
1131 l();
1132 } else { /* Start (two words) end */
1133 m();
1134 }
1135 n(); /* should be under the if () */
1136}
1137
1138STARTTEST
1139:set cino={s,fs
1140]]=/ foo
1141ENDTEST
1142
1143void bar(void)
1144{
1145 static array[2][2] =
1146 {
1147 { 1, 2 },
1148 { 3, 4 },
1149 }
1150
1151 while (a)
1152 {
1153 foo(&a);
1154 }
1155
1156 {
1157 int a;
1158 {
1159 a = a + 1;
1160 }
1161 }
1162 b = a;
1163 }
1164
1165void func(void)
1166 {
1167 a = 1;
1168 {
1169 b = 2;
1170 }
1171 c = 3;
1172 d = 4;
1173 }
1174/* foo */
1175
1176STARTTEST
1177:set cino=
1178/while
1179ohere
1180ENDTEST
1181
1182a()
1183{
1184 do {
1185 a = a +
1186 a;
1187 } while ( a ); /* add text under this line */
1188 if ( a )
1189 a;
1190}
1191
1192STARTTEST
1193:set cino= com=
1194/comment
1195olabel2: b(); label3 /* post */: /* pre */ label4: f(/*com*/); if (/*com*/) cmd();
1196ENDTEST
1197
1198a()
1199{
1200label1:
1201 /* hmm */
1202 // comment
1203}
1204
1205STARTTEST
1206:set comments& comments^=s:/*,m:**,ex:*/
1207/simple
1208=5j
1209ENDTEST
1210
1211/*
1212 * A simple comment
1213 */
1214
1215/*
1216 ** A different comment
1217 */
1218
1219STARTTEST
1220:set cino=c0
1221:set comments& comments-=s1:/* comments^=s0:/*
12222kdd]]=][
1223ENDTEST
1224
1225void f()
1226{
1227
1228 /*********
1229 A comment.
1230*********/
1231}
1232
1233STARTTEST
1234:set cino=c0,C1
1235:set comments& comments-=s1:/* comments^=s0:/*
12362kdd]]=][
1237ENDTEST
1238
1239void f()
1240{
1241
1242 /*********
1243 A comment.
1244*********/
1245}
1246
1247STARTTEST
1248:set cino=
1249]]=][
1250ENDTEST
1251
1252void f()
1253{
1254 c = c1 &&
1255 (
1256 c2 ||
1257 c3
1258 ) && c4;
1259}
1260
1261STARTTEST
1262:set cino=(s
12632kdd]]=][
1264ENDTEST
1265
1266void f()
1267{
1268 c = c1 &&
1269 (
1270 c2 ||
1271 c3
1272 ) && c4;
1273}
1274
1275STARTTEST
1276:set cino=(s,U1
12772kdd]]=][
1278ENDTEST
1279
1280void f()
1281{
1282 c = c1 &&
1283 (
1284 c2 ||
1285 c3
1286 ) && c4;
1287}
1288
1289STARTTEST
1290:set cino=(0
12912kdd]]=][
1292ENDTEST
1293
1294void f()
1295{
1296 if ( c1
1297 && ( c2
1298 || c3))
1299 foo;
1300}
1301
1302STARTTEST
1303:set cino=(0,w1
13042kdd]]=][
1305ENDTEST
1306
1307void f()
1308{
1309 if ( c1
1310 && ( c2
1311 || c3))
1312 foo;
1313}
1314
1315STARTTEST
1316:set cino=(s
13172kdd]]=][
1318ENDTEST
1319
1320void f()
1321{
1322 c = c1 && (
1323 c2 ||
1324 c3
1325 ) && c4;
1326 if (
1327 c1 && c2
1328 )
1329 foo;
1330}
1331
1332STARTTEST
1333:set cino=(s,m1
13342kdd]]=][
1335ENDTEST
1336
1337void f()
1338{
1339 c = c1 && (
1340 c2 ||
1341 c3
1342 ) && c4;
1343 if (
1344 c1 && c2
1345 )
1346 foo;
1347}
1348
1349STARTTEST
1350:set cino=b1
13512kdd]]=][
1352ENDTEST
1353
1354void f()
1355{
1356 switch (x)
1357 {
1358 case 1:
1359 a = b;
1360 break;
1361 default:
1362 a = 0;
1363 break;
1364 }
1365}
1366
1367STARTTEST
1368:set cino=(0,W5
13692kdd]]=][
1370ENDTEST
1371
1372void f()
1373{
1374 invokeme(
1375 argu,
1376 ment);
1377 invokeme(
1378 argu,
1379 ment
1380 );
1381 invokeme(argu,
1382 ment
1383 );
1384}
1385
1386STARTTEST
1387:set cino=/6
13882kdd]]=][
1389ENDTEST
1390
1391void f()
1392{
1393 statement;
1394 // comment 1
1395 // comment 2
1396}
1397
1398STARTTEST
1399:set cino=
14002kdd]]/comment 1/+1
1401==
1402ENDTEST
1403
1404void f()
1405{
1406 statement;
1407 // comment 1
1408 // comment 2
1409}
1410
1411STARTTEST
1412:set cino=g0
14132kdd]]=][
1414ENDTEST
1415
1416class CAbc
1417{
1418 int Test() { return FALSE; }
1419
1420public: // comment
1421 void testfall();
1422protected:
1423 void testfall();
1424};
1425
1426STARTTEST
Bram Moolenaare79d1532011-10-04 18:03:47 +02001427:set cino=(0,gs,hs
14282kdd]]=][
1429ENDTEST
1430
1431class Foo : public Bar
1432{
1433public:
1434virtual void method1(void) = 0;
1435virtual void method2(int arg1,
1436int arg2,
1437int arg3) = 0;
1438};
1439
1440STARTTEST
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00001441:set cino=+20
14422kdd]]=][
1443ENDTEST
1444
1445 void
1446foo()
1447{
1448 if (a)
1449 {
1450 } else
1451 asdf;
1452}
1453
1454STARTTEST
Bram Moolenaar071d4272004-06-13 20:20:40 +00001455:set cino=(0,W2s
14562kdd]]=][
1457ENDTEST
1458
1459{
1460 averylongfunctionnamelongfunctionnameaverylongfunctionname()->asd(
1461 asdasdf,
1462 func(asdf,
1463 asdfadsf),
1464 asdfasdf
1465 );
1466
1467 /* those are ugly, but consequent */
1468
1469 func()->asd(asdasdf,
1470 averylongfunctionname(
1471 abc,
1472 dec)->averylongfunctionname(
1473 asdfadsf,
1474 asdfasdf,
1475 asdfasdf,
1476 ),
1477 func(asdfadf,
1478 asdfasdf
1479 ),
1480 asdasdf
1481 );
1482
1483 averylongfunctionnameaverylongfunctionnameavery()->asd(fasdf(
1484 abc,
1485 dec)->asdfasdfasdf(
1486 asdfadsf,
1487 asdfasdf,
1488 asdfasdf,
1489 ),
1490 func(asdfadf,
1491 asdfasdf),
1492 asdasdf
1493 );
1494}
1495
1496STARTTEST
Bram Moolenaar9e54a0e2006-04-14 20:42:25 +00001497:set cino=M1
14982kdd]]=][
1499ENDTEST
1500
1501int main ()
1502{
1503 if (cond1 &&
1504 cond2
1505 )
1506 foo;
1507}
1508
1509STARTTEST
Bram Moolenaar8d2d71d2011-04-28 13:02:09 +02001510:set cino=(0,ts
Bram Moolenaar9f4fe7c2014-07-03 22:57:55 +020015112kdd2j=][
Bram Moolenaar8d2d71d2011-04-28 13:02:09 +02001512ENDTEST
1513
1514void func(int a
1515#if defined(FOO)
1516 , int b
1517 , int c
1518#endif
1519 )
1520{
1521}
1522
1523STARTTEST
1524:set cino=(0
Bram Moolenaar9f4fe7c2014-07-03 22:57:55 +020015252kdd2j=][
Bram Moolenaar8d2d71d2011-04-28 13:02:09 +02001526ENDTEST
1527
1528void
1529func(int a
1530#if defined(FOO)
1531 , int b
1532 , int c
1533#endif
1534 )
1535{
1536}
1537
1538STARTTEST
Bram Moolenaar4ae06c12011-05-10 11:39:19 +02001539:set cino&
Bram Moolenaar9f4fe7c2014-07-03 22:57:55 +020015402kdd2j=7][
Bram Moolenaar4ae06c12011-05-10 11:39:19 +02001541ENDTEST
1542
1543void func(void)
1544{
1545 if(x==y)
1546 if(y==z)
1547 foo=1;
1548 else { bar=1;
1549 baz=2;
1550 }
1551 printf("Foo!\n");
1552}
1553
Bram Moolenaar496f9512011-05-19 16:35:09 +02001554void func1(void)
1555{
1556 char* tab[] = {"foo", "bar",
1557 "baz", "quux",
1558 "this line used", "to be indented incorrectly"};
1559 foo();
1560}
1561
1562void func2(void)
1563{
1564 int tab[] =
1565 {1, 2,
1566 3, 4,
1567 5, 6};
1568
1569 printf("This line used to be indented incorrectly.\n");
1570}
1571
Bram Moolenaar3388bb42011-11-30 17:20:23 +01001572int foo[]
1573#ifdef BAR
1574
1575= { 1, 2, 3,
1576 4, 5, 6 }
1577
1578#endif
1579;
1580 int baz;
1581
Bram Moolenaar496f9512011-05-19 16:35:09 +02001582void func3(void)
1583{
1584 int tab[] = {
1585 1, 2,
1586 3, 4,
1587 5, 6};
1588
Bram Moolenaarc367faa2011-12-14 20:21:35 +01001589printf("Don't you dare indent this line incorrectly!\n");
1590}
1591
1592void
1593func4(a, b,
1594 c)
1595int a;
1596int b;
1597int c;
1598{
1599}
1600
1601void
1602func5(
1603 int a,
1604 int b)
1605{
1606}
1607
1608void
1609func6(
1610 int a)
1611{
Bram Moolenaar496f9512011-05-19 16:35:09 +02001612}
1613
Bram Moolenaar4ae06c12011-05-10 11:39:19 +02001614STARTTEST
Bram Moolenaaraede6ce2011-05-10 11:56:30 +02001615:set cino&
Bram Moolenaar50f42ca2011-07-15 14:12:30 +02001616:set cino+=l1
Bram Moolenaar9f4fe7c2014-07-03 22:57:55 +020016172kdd2j=][
Bram Moolenaar50f42ca2011-07-15 14:12:30 +02001618ENDTEST
1619
1620void func(void)
1621{
1622 int tab[] =
1623 {
1624 1, 2, 3,
1625 4, 5, 6};
1626
1627 printf("Indent this line correctly!\n");
1628
1629 switch (foo)
1630 {
1631 case bar:
1632 printf("bar");
1633 break;
1634 case baz: {
1635 printf("baz");
1636 break;
1637 }
1638 case quux:
1639printf("But don't break the indentation of this instruction\n");
1640break;
1641 }
1642}
1643
1644STARTTEST
1645:set cino&
Bram Moolenaar9f4fe7c2014-07-03 22:57:55 +020016462kdd2j=][
Bram Moolenaaraede6ce2011-05-10 11:56:30 +02001647ENDTEST
1648
1649void func(void)
1650{
1651 cout << "a"
1652 << "b"
1653 << ") :"
1654 << "c";
1655}
1656
1657STARTTEST
Bram Moolenaara4271d52011-05-10 13:38:27 +02001658:set com=s1:/*,m:*,ex:*/
1659]]3jofoo();
1660ENDTEST
1661
1662void func(void)
1663{
1664 /*
1665 * This is a comment.
1666 */
1667}
1668
1669STARTTEST
Bram Moolenaar334adf02011-05-25 13:34:04 +02001670:set cino&
Bram Moolenaar9f4fe7c2014-07-03 22:57:55 +020016712kdd2j=][
Bram Moolenaar334adf02011-05-25 13:34:04 +02001672ENDTEST
1673
1674void func(void)
1675{
1676 for (int i = 0; i < 10; ++i)
1677 if (i & 1) {
1678 foo(1);
1679 } else
1680 foo(0);
1681baz();
1682}
1683
1684STARTTEST
Bram Moolenaar3675fa02012-04-05 17:17:42 +02001685:set cino=k2s,(0
16862kdd3j=][
1687ENDTEST
1688
1689void func(void)
1690{
1691 if (condition1
1692 && condition2)
1693 action();
1694 function(argument1
1695 && argument2);
1696
1697 if (c1 && (c2 ||
1698 c3))
1699 foo;
1700 if (c1 &&
1701 (c2 || c3))
1702 {
1703 }
1704
1705 if ( c1
1706 && ( c2
1707 || c3))
1708 foo;
1709 func( c1
1710 && ( c2
1711 || c3))
1712 foo;
1713}
1714
1715STARTTEST
1716:set cino=k2s,(s
17172kdd3j=][
1718ENDTEST
1719
1720void func(void)
1721{
1722 if (condition1
1723 && condition2)
1724 action();
1725 function(argument1
1726 && argument2);
1727
1728 if (c1 && (c2 ||
1729 c3))
1730 foo;
1731 if (c1 &&
1732 (c2 || c3))
1733 {
1734 }
1735
1736 if ( c1
1737 && ( c2
1738 || c3))
1739 foo;
1740 func( c1
1741 && ( c2
1742 || c3))
1743 foo;
1744}
1745
1746STARTTEST
1747:set cino=k2s,(s,U1
17482kdd3j=][
1749ENDTEST
1750
1751void func(void)
1752{
1753 if (condition1
1754 && condition2)
1755 action();
1756 function(argument1
1757 && argument2);
1758
1759 if (c1 && (c2 ||
1760 c3))
1761 foo;
1762 if (c1 &&
1763 (c2 || c3))
1764 {
1765 }
1766 if (c123456789
1767 && (c22345
1768 || c3))
1769 printf("foo\n");
1770
1771 c = c1 &&
1772 (
1773 c2 ||
1774 c3
1775 ) && c4;
1776}
1777
1778STARTTEST
1779:set cino=k2s,(0,W4
17802kdd3j=][
1781ENDTEST
1782
1783void func(void)
1784{
1785 if (condition1
1786 && condition2)
1787 action();
1788 function(argument1
1789 && argument2);
1790
1791 if (c1 && (c2 ||
1792 c3))
1793 foo;
1794 if (c1 &&
1795 (c2 || c3))
1796 {
1797 }
1798 if (c123456789
1799 && (c22345
1800 || c3))
1801 printf("foo\n");
1802
1803 if ( c1
1804 && ( c2
1805 || c3))
1806 foo;
1807
1808 a_long_line(
1809 argument,
1810 argument);
1811 a_short_line(argument,
1812 argument);
1813}
1814
1815STARTTEST
1816:set cino=k2s,u2
18172kdd3j=][
1818ENDTEST
1819
1820void func(void)
1821{
1822 if (condition1
1823 && condition2)
1824 action();
1825 function(argument1
1826 && argument2);
1827
1828 if (c1 && (c2 ||
1829 c3))
1830 foo;
1831 if (c1 &&
1832 (c2 || c3))
1833 {
1834 }
1835 if (c123456789
1836 && (c22345
1837 || c3))
1838 printf("foo\n");
1839}
1840
1841STARTTEST
1842:set cino=k2s,(0,w1
18432kdd3j=][
1844ENDTEST
1845
1846void func(void)
1847{
1848 if (condition1
1849 && condition2)
1850 action();
1851 function(argument1
1852 && argument2);
1853
1854 if (c1 && (c2 ||
1855 c3))
1856 foo;
1857 if (c1 &&
1858 (c2 || c3))
1859 {
1860 }
1861 if (c123456789
1862 && (c22345
1863 || c3))
1864 printf("foo\n");
1865
1866 if ( c1
1867 && ( c2
1868 || c3))
1869 foo;
1870 func( c1
1871 && ( c2
1872 || c3))
1873 foo;
1874}
1875
1876STARTTEST
1877:set cino=k2,(s
18782kdd3j=][
1879ENDTEST
1880
1881void func(void)
1882{
1883 if (condition1
1884 && condition2)
1885 action();
1886 function(argument1
1887 && argument2);
1888
1889 if (c1 && (c2 ||
1890 c3))
1891 foo;
1892 if (c1 &&
1893 (c2 || c3))
1894 {
1895 }
1896}
1897
1898STARTTEST
Bram Moolenaared38b0a2011-05-25 15:16:18 +02001899:set cino=N-s
Bram Moolenaar6ec154b2011-06-12 21:51:08 +02001900/^NAMESPACESTART
Bram Moolenaared38b0a2011-05-25 15:16:18 +02001901=/^NAMESPACEEND
1902ENDTEST
1903
Bram Moolenaar6ec154b2011-06-12 21:51:08 +02001904NAMESPACESTART
Bram Moolenaared38b0a2011-05-25 15:16:18 +02001905/* valid namespaces with normal indent */
1906namespace
1907{
1908 {
1909 111111111111;
1910}
1911}
1912namespace /* test */
1913{
1914 11111111111111111;
1915}
1916namespace // test
1917{
1918 111111111111111111;
1919}
1920namespace
1921{
1922 111111111111111111;
1923}
1924namespace test
1925{
1926 111111111111111111;
1927}
1928namespace{
1929 111111111111111111;
1930}
1931namespace test{
1932 111111111111111111;
1933}
1934namespace {
1935 111111111111111111;
1936}
1937namespace test {
1938 111111111111111111;
1939namespace test2 {
1940 22222222222222222;
1941}
1942}
1943
1944/* invalid namespaces use block indent */
1945namespace test test2 {
1946 111111111111111111111;
1947}
1948namespace11111111111 {
1949 111111111111;
1950}
1951namespace() {
1952 1111111111111;
1953}
1954namespace()
1955{
1956 111111111111111111;
1957}
1958namespace test test2
1959{
1960 1111111111111111111;
1961}
1962namespace111111111
1963{
1964 111111111111111111;
1965}
1966NAMESPACEEND
1967
1968
1969STARTTEST
Bram Moolenaar76f7fd32011-07-20 15:09:43 +02001970:set cino=j1,J1
Bram Moolenaar6ec154b2011-06-12 21:51:08 +02001971/^JSSTART
1972=/^JSEND
1973ENDTEST
1974
1975JSSTART
1976var bar = {
1977foo: {
1978that: this,
1979some: ok,
1980},
1981"bar":{
1982a : 2,
1983b: "123abc",
1984x: 4,
1985"y": 5
1986}
1987}
1988JSEND
1989
1990STARTTEST
Bram Moolenaar76f7fd32011-07-20 15:09:43 +02001991:set cino=j1,J1
1992/^JSSTART
1993=/^JSEND
1994ENDTEST
1995
1996JSSTART
1997var foo = [
Bram Moolenaar9f4fe7c2014-07-03 22:57:55 +020019981,
Bram Moolenaar76f7fd32011-07-20 15:09:43 +020019992,
20003
Bram Moolenaar9f4fe7c2014-07-03 22:57:55 +02002001];
Bram Moolenaar76f7fd32011-07-20 15:09:43 +02002002JSEND
2003
2004STARTTEST
2005:set cino=j1,J1
2006/^JSSTART
2007=/^JSEND
2008ENDTEST
2009
2010JSSTART
2011function bar() {
2012var foo = [
20131,
20142,
20153
Bram Moolenaar9f4fe7c2014-07-03 22:57:55 +02002016];
Bram Moolenaar76f7fd32011-07-20 15:09:43 +02002017}
2018JSEND
2019
2020STARTTEST
2021:set cino=j1,J1
2022/^JSSTART
2023=/^JSEND
2024ENDTEST
2025
2026JSSTART
2027(function($){
2028
Bram Moolenaar81439a62014-07-02 18:27:48 +02002029if (cond &&
2030cond) {
2031stmt;
2032}
Bram Moolenaar9f4fe7c2014-07-03 22:57:55 +02002033window.something.left =
2034(width - 50 + offset) + "px";
Bram Moolenaar76f7fd32011-07-20 15:09:43 +02002035var class_name='myclass';
2036
2037function private_method() {
2038}
2039
2040var public_method={
2041method: function(options,args){
2042private_method();
2043}
2044}
2045
2046function init(options) {
2047
2048$(this).data(class_name+'_public',$.extend({},{
2049foo: 'bar',
Bram Moolenaar9f4fe7c2014-07-03 22:57:55 +02002050bar: 2,
2051foobar: [
20521,
20532,
20543
Bram Moolenaar76f7fd32011-07-20 15:09:43 +02002055],
Bram Moolenaar9f4fe7c2014-07-03 22:57:55 +02002056callback: function(){
2057return true;
2058}
Bram Moolenaar76f7fd32011-07-20 15:09:43 +02002059}, options||{}));
2060}
2061
2062$.fn[class_name]=function() {
2063
2064var _arguments=arguments;
2065return this.each(function(){
2066
2067var options=$(this).data(class_name+'_public');
2068if (!options) {
2069init.apply(this,_arguments);
2070
2071} else {
2072var method=public_method[_arguments[0]];
2073
2074if (typeof(method)!='function') {
2075console.log(class_name+' has no method "'+_arguments[0]+'"');
2076return false;
2077}
2078_arguments[0]=options;
2079method.apply(this,_arguments);
2080}
2081});
2082}
2083
2084})(jQuery);
2085JSEND
2086
2087STARTTEST
2088:set cino=j1,J1
2089/^JSSTART
2090=/^JSEND
2091ENDTEST
2092
2093JSSTART
2094function init(options) {
2095$(this).data(class_name+'_public',$.extend({},{
2096foo: 'bar',
2097bar: 2,
2098foobar: [
Bram Moolenaar9f4fe7c2014-07-03 22:57:55 +020020991,
21002,
21013
Bram Moolenaar76f7fd32011-07-20 15:09:43 +02002102],
2103callback: function(){
2104return true;
2105}
2106}, options||{}));
2107}
2108JSEND
2109
2110STARTTEST
2111:set cino=j1,J1
2112/^JSSTART
2113=/^JSEND
2114ENDTEST
2115
2116JSSTART
2117(function($){
2118function init(options) {
2119$(this).data(class_name+'_public',$.extend({},{
2120foo: 'bar',
Bram Moolenaar9f4fe7c2014-07-03 22:57:55 +02002121bar: 2,
2122foobar: [
21231,
21242,
21253
Bram Moolenaar76f7fd32011-07-20 15:09:43 +02002126],
Bram Moolenaar9f4fe7c2014-07-03 22:57:55 +02002127callback: function(){
2128return true;
2129}
Bram Moolenaar76f7fd32011-07-20 15:09:43 +02002130}, options||{}));
2131}
2132})(jQuery);
2133JSEND
2134
2135STARTTEST
Bram Moolenaardcefba92015-03-20 19:06:06 +01002136:set cino=j1,J1,+2
2137/^JSSTART
2138=/^JSEND
2139ENDTEST
2140
2141JSSTART
2142// Results of JavaScript indent
2143// 1
2144(function(){
2145var a = [
2146'a',
2147'b',
2148'c',
2149'd',
2150'e',
2151'f',
2152'g',
2153'h',
2154'i'
2155];
2156}())
2157
2158// 2
2159(function(){
2160var a = [
21610 +
21625 *
21639 *
2164'a',
2165'b',
21660 +
21675 *
21689 *
2169'c',
2170'd',
2171'e',
2172'f',
2173'g',
2174'h',
2175'i'
2176];
2177}())
2178
2179// 3
2180(function(){
2181var a = [
21820 +
2183// comment 1
21845 *
2185/* comment 2 */
21869 *
2187'a',
2188'b',
21890 +
21905 *
21919 *
2192'c',
2193'd',
2194'e',
2195'f',
2196'g',
2197'h',
2198'i'
2199];
2200}())
2201
2202// 4
2203{
2204var a = [
22050,
22061
2207];
2208var b;
2209var c;
2210}
2211
2212// 5
2213{
2214var a = [
2215[
22160
2217],
22182,
22193
2220];
2221}
2222
2223// 6
2224{
2225var a = [
2226[
22270,
22281
2229],
22302,
22313
2232];
2233}
2234
2235// 7
2236{
2237var a = [
2238// [
22390,
2240// 1
2241// ],
22422,
22433
2244];
2245}
2246
2247// 8
2248var x = [
2249(function(){
2250var a,
2251b,
2252c,
2253d,
2254e,
2255f,
2256g,
2257h,
2258i;
2259})
2260];
2261
2262// 9
2263var a = [
22640 +
22655 *
22669 *
2267'a',
2268'b',
22690 +
22705 *
22719 *
2272'c',
2273'd',
2274'e',
2275'f',
2276'g',
2277'h',
2278'i'
2279];
2280
2281// 10
2282var a,
2283b,
2284c,
2285d,
2286e,
2287f,
2288g,
2289h,
2290i;
2291JSEND
2292
2293STARTTEST
Bram Moolenaar071d4272004-06-13 20:20:40 +00002294:g/^STARTTEST/.,/^ENDTEST/d
2295:1;/start of AUTO/,$wq! test.out
2296ENDTEST