blob: 4fc73a978a05ed98a8e4bdb384ef9f16114a8ead [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 Moolenaar071d4272004-06-13 20:20:40 +0000935/* end of AUTO */
936
937STARTTEST
938:set tw=0 wm=60 columns=80 noai fo=croq
939/serious/e
940a about life, the universe, and the rest
941ENDTEST
942
943{
944
945/* this is
946 * a real serious important big
947 * comment
948 */
949 /* insert " about life, the universe, and the rest" after "serious" */
950}
951
952STARTTEST
953:set nocin
954/comments
955joabout life/happens
956jothere/below
957oline/this
958Ohello
959ENDTEST
960
961{
962 /*
963 * Testing for comments, without 'cin' set
964 */
965
966/*
967* what happens here?
968*/
969
970 /*
971 the end of the comment, try inserting a line below */
972
973 /* how about
974 this one */
975}
976
977STARTTEST
978:set cin
979/vec2
980==
981ENDTEST
982
983{
984 var = this + that + vec[0] * vec[0]
985 + vec[1] * vec[1]
986 + vec2[2] * vec[2];
987}
988
989STARTTEST
990:set cin
991:set cino=}4
992/testing1
993k2==/testing2
994k2==
995ENDTEST
996
997{
998 asdf asdflkajds f;
999 if (tes & ting) {
1000 asdf asdf asdf ;
1001 asdfa sdf asdf;
1002 }
1003 testing1;
1004 if (tes & ting)
1005 {
1006 asdf asdf asdf ;
1007 asdfa sdf asdf;
1008 }
1009 testing2;
1010}
1011
1012STARTTEST
1013:set cin
1014:set cino=(0,)20
1015/main
1016=][
1017ENDTEST
1018
1019main ( int first_par, /*
1020 * Comment for
1021 * first par
1022 */
1023 int second_par /*
1024 * Comment for
1025 * second par
1026 */
1027 )
1028{
1029 func( first_par, /*
1030 * Comment for
1031 * first par
1032 */
1033 second_par /*
1034 * Comment for
1035 * second par
1036 */
1037 );
1038
1039}
1040
1041STARTTEST
1042:set cin
Bram Moolenaar48d27922012-06-13 13:40:48 +02001043:set cino=es,n0s
1044/main
1045=][
1046ENDTEST
1047
1048main(void)
1049{
1050 /* Make sure that cino=X0s is not parsed like cino=Xs. */
1051 if (cond)
1052 foo();
1053 else
1054 {
1055 bar();
1056 }
1057}
1058
1059STARTTEST
1060:set cin
Bram Moolenaar071d4272004-06-13 20:20:40 +00001061:set cino=
1062]]=][
1063ENDTEST
1064
1065{
1066 do
1067 {
1068 if ()
1069 {
1070 if ()
1071 asdf;
1072 else
1073 asdf;
1074 }
1075 } while ();
1076 cmd; /* this should go under the } */
1077}
1078
1079STARTTEST
1080]]=][
1081ENDTEST
1082
1083void f()
1084{
1085 if ( k() ) {
1086 l();
1087
1088 } else { /* Start (two words) end */
1089 m();
1090 }
1091
1092 n();
1093}
1094
1095STARTTEST
1096:set cino={s,e-s
1097]]=][
1098ENDTEST
1099
1100void f()
1101{
1102 if ( k() )
1103 {
1104 l();
1105 } else { /* Start (two words) end */
1106 m();
1107 }
1108 n(); /* should be under the if () */
1109}
1110
1111STARTTEST
1112:set cino={s,fs
1113]]=/ foo
1114ENDTEST
1115
1116void bar(void)
1117{
1118 static array[2][2] =
1119 {
1120 { 1, 2 },
1121 { 3, 4 },
1122 }
1123
1124 while (a)
1125 {
1126 foo(&a);
1127 }
1128
1129 {
1130 int a;
1131 {
1132 a = a + 1;
1133 }
1134 }
1135 b = a;
1136 }
1137
1138void func(void)
1139 {
1140 a = 1;
1141 {
1142 b = 2;
1143 }
1144 c = 3;
1145 d = 4;
1146 }
1147/* foo */
1148
1149STARTTEST
1150:set cino=
1151/while
1152ohere
1153ENDTEST
1154
1155a()
1156{
1157 do {
1158 a = a +
1159 a;
1160 } while ( a ); /* add text under this line */
1161 if ( a )
1162 a;
1163}
1164
1165STARTTEST
1166:set cino= com=
1167/comment
1168olabel2: b(); label3 /* post */: /* pre */ label4: f(/*com*/); if (/*com*/) cmd();
1169ENDTEST
1170
1171a()
1172{
1173label1:
1174 /* hmm */
1175 // comment
1176}
1177
1178STARTTEST
1179:set comments& comments^=s:/*,m:**,ex:*/
1180/simple
1181=5j
1182ENDTEST
1183
1184/*
1185 * A simple comment
1186 */
1187
1188/*
1189 ** A different comment
1190 */
1191
1192STARTTEST
1193:set cino=c0
1194:set comments& comments-=s1:/* comments^=s0:/*
11952kdd]]=][
1196ENDTEST
1197
1198void f()
1199{
1200
1201 /*********
1202 A comment.
1203*********/
1204}
1205
1206STARTTEST
1207:set cino=c0,C1
1208:set comments& comments-=s1:/* comments^=s0:/*
12092kdd]]=][
1210ENDTEST
1211
1212void f()
1213{
1214
1215 /*********
1216 A comment.
1217*********/
1218}
1219
1220STARTTEST
1221:set cino=
1222]]=][
1223ENDTEST
1224
1225void f()
1226{
1227 c = c1 &&
1228 (
1229 c2 ||
1230 c3
1231 ) && c4;
1232}
1233
1234STARTTEST
1235:set cino=(s
12362kdd]]=][
1237ENDTEST
1238
1239void f()
1240{
1241 c = c1 &&
1242 (
1243 c2 ||
1244 c3
1245 ) && c4;
1246}
1247
1248STARTTEST
1249:set cino=(s,U1
12502kdd]]=][
1251ENDTEST
1252
1253void f()
1254{
1255 c = c1 &&
1256 (
1257 c2 ||
1258 c3
1259 ) && c4;
1260}
1261
1262STARTTEST
1263:set cino=(0
12642kdd]]=][
1265ENDTEST
1266
1267void f()
1268{
1269 if ( c1
1270 && ( c2
1271 || c3))
1272 foo;
1273}
1274
1275STARTTEST
1276:set cino=(0,w1
12772kdd]]=][
1278ENDTEST
1279
1280void f()
1281{
1282 if ( c1
1283 && ( c2
1284 || c3))
1285 foo;
1286}
1287
1288STARTTEST
1289:set cino=(s
12902kdd]]=][
1291ENDTEST
1292
1293void f()
1294{
1295 c = c1 && (
1296 c2 ||
1297 c3
1298 ) && c4;
1299 if (
1300 c1 && c2
1301 )
1302 foo;
1303}
1304
1305STARTTEST
1306:set cino=(s,m1
13072kdd]]=][
1308ENDTEST
1309
1310void f()
1311{
1312 c = c1 && (
1313 c2 ||
1314 c3
1315 ) && c4;
1316 if (
1317 c1 && c2
1318 )
1319 foo;
1320}
1321
1322STARTTEST
1323:set cino=b1
13242kdd]]=][
1325ENDTEST
1326
1327void f()
1328{
1329 switch (x)
1330 {
1331 case 1:
1332 a = b;
1333 break;
1334 default:
1335 a = 0;
1336 break;
1337 }
1338}
1339
1340STARTTEST
1341:set cino=(0,W5
13422kdd]]=][
1343ENDTEST
1344
1345void f()
1346{
1347 invokeme(
1348 argu,
1349 ment);
1350 invokeme(
1351 argu,
1352 ment
1353 );
1354 invokeme(argu,
1355 ment
1356 );
1357}
1358
1359STARTTEST
1360:set cino=/6
13612kdd]]=][
1362ENDTEST
1363
1364void f()
1365{
1366 statement;
1367 // comment 1
1368 // comment 2
1369}
1370
1371STARTTEST
1372:set cino=
13732kdd]]/comment 1/+1
1374==
1375ENDTEST
1376
1377void f()
1378{
1379 statement;
1380 // comment 1
1381 // comment 2
1382}
1383
1384STARTTEST
1385:set cino=g0
13862kdd]]=][
1387ENDTEST
1388
1389class CAbc
1390{
1391 int Test() { return FALSE; }
1392
1393public: // comment
1394 void testfall();
1395protected:
1396 void testfall();
1397};
1398
1399STARTTEST
Bram Moolenaare79d1532011-10-04 18:03:47 +02001400:set cino=(0,gs,hs
14012kdd]]=][
1402ENDTEST
1403
1404class Foo : public Bar
1405{
1406public:
1407virtual void method1(void) = 0;
1408virtual void method2(int arg1,
1409int arg2,
1410int arg3) = 0;
1411};
1412
1413STARTTEST
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00001414:set cino=+20
14152kdd]]=][
1416ENDTEST
1417
1418 void
1419foo()
1420{
1421 if (a)
1422 {
1423 } else
1424 asdf;
1425}
1426
1427STARTTEST
Bram Moolenaar071d4272004-06-13 20:20:40 +00001428:set cino=(0,W2s
14292kdd]]=][
1430ENDTEST
1431
1432{
1433 averylongfunctionnamelongfunctionnameaverylongfunctionname()->asd(
1434 asdasdf,
1435 func(asdf,
1436 asdfadsf),
1437 asdfasdf
1438 );
1439
1440 /* those are ugly, but consequent */
1441
1442 func()->asd(asdasdf,
1443 averylongfunctionname(
1444 abc,
1445 dec)->averylongfunctionname(
1446 asdfadsf,
1447 asdfasdf,
1448 asdfasdf,
1449 ),
1450 func(asdfadf,
1451 asdfasdf
1452 ),
1453 asdasdf
1454 );
1455
1456 averylongfunctionnameaverylongfunctionnameavery()->asd(fasdf(
1457 abc,
1458 dec)->asdfasdfasdf(
1459 asdfadsf,
1460 asdfasdf,
1461 asdfasdf,
1462 ),
1463 func(asdfadf,
1464 asdfasdf),
1465 asdasdf
1466 );
1467}
1468
1469STARTTEST
Bram Moolenaar9e54a0e2006-04-14 20:42:25 +00001470:set cino=M1
14712kdd]]=][
1472ENDTEST
1473
1474int main ()
1475{
1476 if (cond1 &&
1477 cond2
1478 )
1479 foo;
1480}
1481
1482STARTTEST
Bram Moolenaar8d2d71d2011-04-28 13:02:09 +02001483:set cino=(0,ts
Bram Moolenaar9f4fe7c2014-07-03 22:57:55 +020014842kdd2j=][
Bram Moolenaar8d2d71d2011-04-28 13:02:09 +02001485ENDTEST
1486
1487void func(int a
1488#if defined(FOO)
1489 , int b
1490 , int c
1491#endif
1492 )
1493{
1494}
1495
1496STARTTEST
1497:set cino=(0
Bram Moolenaar9f4fe7c2014-07-03 22:57:55 +020014982kdd2j=][
Bram Moolenaar8d2d71d2011-04-28 13:02:09 +02001499ENDTEST
1500
1501void
1502func(int a
1503#if defined(FOO)
1504 , int b
1505 , int c
1506#endif
1507 )
1508{
1509}
1510
1511STARTTEST
Bram Moolenaar4ae06c12011-05-10 11:39:19 +02001512:set cino&
Bram Moolenaar9f4fe7c2014-07-03 22:57:55 +020015132kdd2j=7][
Bram Moolenaar4ae06c12011-05-10 11:39:19 +02001514ENDTEST
1515
1516void func(void)
1517{
1518 if(x==y)
1519 if(y==z)
1520 foo=1;
1521 else { bar=1;
1522 baz=2;
1523 }
1524 printf("Foo!\n");
1525}
1526
Bram Moolenaar496f9512011-05-19 16:35:09 +02001527void func1(void)
1528{
1529 char* tab[] = {"foo", "bar",
1530 "baz", "quux",
1531 "this line used", "to be indented incorrectly"};
1532 foo();
1533}
1534
1535void func2(void)
1536{
1537 int tab[] =
1538 {1, 2,
1539 3, 4,
1540 5, 6};
1541
1542 printf("This line used to be indented incorrectly.\n");
1543}
1544
Bram Moolenaar3388bb42011-11-30 17:20:23 +01001545int foo[]
1546#ifdef BAR
1547
1548= { 1, 2, 3,
1549 4, 5, 6 }
1550
1551#endif
1552;
1553 int baz;
1554
Bram Moolenaar496f9512011-05-19 16:35:09 +02001555void func3(void)
1556{
1557 int tab[] = {
1558 1, 2,
1559 3, 4,
1560 5, 6};
1561
Bram Moolenaarc367faa2011-12-14 20:21:35 +01001562printf("Don't you dare indent this line incorrectly!\n");
1563}
1564
1565void
1566func4(a, b,
1567 c)
1568int a;
1569int b;
1570int c;
1571{
1572}
1573
1574void
1575func5(
1576 int a,
1577 int b)
1578{
1579}
1580
1581void
1582func6(
1583 int a)
1584{
Bram Moolenaar496f9512011-05-19 16:35:09 +02001585}
1586
Bram Moolenaar4ae06c12011-05-10 11:39:19 +02001587STARTTEST
Bram Moolenaaraede6ce2011-05-10 11:56:30 +02001588:set cino&
Bram Moolenaar50f42ca2011-07-15 14:12:30 +02001589:set cino+=l1
Bram Moolenaar9f4fe7c2014-07-03 22:57:55 +020015902kdd2j=][
Bram Moolenaar50f42ca2011-07-15 14:12:30 +02001591ENDTEST
1592
1593void func(void)
1594{
1595 int tab[] =
1596 {
1597 1, 2, 3,
1598 4, 5, 6};
1599
1600 printf("Indent this line correctly!\n");
1601
1602 switch (foo)
1603 {
1604 case bar:
1605 printf("bar");
1606 break;
1607 case baz: {
1608 printf("baz");
1609 break;
1610 }
1611 case quux:
1612printf("But don't break the indentation of this instruction\n");
1613break;
1614 }
1615}
1616
1617STARTTEST
1618:set cino&
Bram Moolenaar9f4fe7c2014-07-03 22:57:55 +020016192kdd2j=][
Bram Moolenaaraede6ce2011-05-10 11:56:30 +02001620ENDTEST
1621
1622void func(void)
1623{
1624 cout << "a"
1625 << "b"
1626 << ") :"
1627 << "c";
1628}
1629
1630STARTTEST
Bram Moolenaara4271d52011-05-10 13:38:27 +02001631:set com=s1:/*,m:*,ex:*/
1632]]3jofoo();
1633ENDTEST
1634
1635void func(void)
1636{
1637 /*
1638 * This is a comment.
1639 */
1640}
1641
1642STARTTEST
Bram Moolenaar334adf02011-05-25 13:34:04 +02001643:set cino&
Bram Moolenaar9f4fe7c2014-07-03 22:57:55 +020016442kdd2j=][
Bram Moolenaar334adf02011-05-25 13:34:04 +02001645ENDTEST
1646
1647void func(void)
1648{
1649 for (int i = 0; i < 10; ++i)
1650 if (i & 1) {
1651 foo(1);
1652 } else
1653 foo(0);
1654baz();
1655}
1656
1657STARTTEST
Bram Moolenaar3675fa02012-04-05 17:17:42 +02001658:set cino=k2s,(0
16592kdd3j=][
1660ENDTEST
1661
1662void func(void)
1663{
1664 if (condition1
1665 && condition2)
1666 action();
1667 function(argument1
1668 && argument2);
1669
1670 if (c1 && (c2 ||
1671 c3))
1672 foo;
1673 if (c1 &&
1674 (c2 || c3))
1675 {
1676 }
1677
1678 if ( c1
1679 && ( c2
1680 || c3))
1681 foo;
1682 func( c1
1683 && ( c2
1684 || c3))
1685 foo;
1686}
1687
1688STARTTEST
1689:set cino=k2s,(s
16902kdd3j=][
1691ENDTEST
1692
1693void func(void)
1694{
1695 if (condition1
1696 && condition2)
1697 action();
1698 function(argument1
1699 && argument2);
1700
1701 if (c1 && (c2 ||
1702 c3))
1703 foo;
1704 if (c1 &&
1705 (c2 || c3))
1706 {
1707 }
1708
1709 if ( c1
1710 && ( c2
1711 || c3))
1712 foo;
1713 func( c1
1714 && ( c2
1715 || c3))
1716 foo;
1717}
1718
1719STARTTEST
1720:set cino=k2s,(s,U1
17212kdd3j=][
1722ENDTEST
1723
1724void func(void)
1725{
1726 if (condition1
1727 && condition2)
1728 action();
1729 function(argument1
1730 && argument2);
1731
1732 if (c1 && (c2 ||
1733 c3))
1734 foo;
1735 if (c1 &&
1736 (c2 || c3))
1737 {
1738 }
1739 if (c123456789
1740 && (c22345
1741 || c3))
1742 printf("foo\n");
1743
1744 c = c1 &&
1745 (
1746 c2 ||
1747 c3
1748 ) && c4;
1749}
1750
1751STARTTEST
1752:set cino=k2s,(0,W4
17532kdd3j=][
1754ENDTEST
1755
1756void func(void)
1757{
1758 if (condition1
1759 && condition2)
1760 action();
1761 function(argument1
1762 && argument2);
1763
1764 if (c1 && (c2 ||
1765 c3))
1766 foo;
1767 if (c1 &&
1768 (c2 || c3))
1769 {
1770 }
1771 if (c123456789
1772 && (c22345
1773 || c3))
1774 printf("foo\n");
1775
1776 if ( c1
1777 && ( c2
1778 || c3))
1779 foo;
1780
1781 a_long_line(
1782 argument,
1783 argument);
1784 a_short_line(argument,
1785 argument);
1786}
1787
1788STARTTEST
1789:set cino=k2s,u2
17902kdd3j=][
1791ENDTEST
1792
1793void func(void)
1794{
1795 if (condition1
1796 && condition2)
1797 action();
1798 function(argument1
1799 && argument2);
1800
1801 if (c1 && (c2 ||
1802 c3))
1803 foo;
1804 if (c1 &&
1805 (c2 || c3))
1806 {
1807 }
1808 if (c123456789
1809 && (c22345
1810 || c3))
1811 printf("foo\n");
1812}
1813
1814STARTTEST
1815:set cino=k2s,(0,w1
18162kdd3j=][
1817ENDTEST
1818
1819void func(void)
1820{
1821 if (condition1
1822 && condition2)
1823 action();
1824 function(argument1
1825 && argument2);
1826
1827 if (c1 && (c2 ||
1828 c3))
1829 foo;
1830 if (c1 &&
1831 (c2 || c3))
1832 {
1833 }
1834 if (c123456789
1835 && (c22345
1836 || c3))
1837 printf("foo\n");
1838
1839 if ( c1
1840 && ( c2
1841 || c3))
1842 foo;
1843 func( c1
1844 && ( c2
1845 || c3))
1846 foo;
1847}
1848
1849STARTTEST
1850:set cino=k2,(s
18512kdd3j=][
1852ENDTEST
1853
1854void func(void)
1855{
1856 if (condition1
1857 && condition2)
1858 action();
1859 function(argument1
1860 && argument2);
1861
1862 if (c1 && (c2 ||
1863 c3))
1864 foo;
1865 if (c1 &&
1866 (c2 || c3))
1867 {
1868 }
1869}
1870
1871STARTTEST
Bram Moolenaared38b0a2011-05-25 15:16:18 +02001872:set cino=N-s
Bram Moolenaar6ec154b2011-06-12 21:51:08 +02001873/^NAMESPACESTART
Bram Moolenaared38b0a2011-05-25 15:16:18 +02001874=/^NAMESPACEEND
1875ENDTEST
1876
Bram Moolenaar6ec154b2011-06-12 21:51:08 +02001877NAMESPACESTART
Bram Moolenaared38b0a2011-05-25 15:16:18 +02001878/* valid namespaces with normal indent */
1879namespace
1880{
1881 {
1882 111111111111;
1883}
1884}
1885namespace /* test */
1886{
1887 11111111111111111;
1888}
1889namespace // test
1890{
1891 111111111111111111;
1892}
1893namespace
1894{
1895 111111111111111111;
1896}
1897namespace test
1898{
1899 111111111111111111;
1900}
1901namespace{
1902 111111111111111111;
1903}
1904namespace test{
1905 111111111111111111;
1906}
1907namespace {
1908 111111111111111111;
1909}
1910namespace test {
1911 111111111111111111;
1912namespace test2 {
1913 22222222222222222;
1914}
1915}
1916
1917/* invalid namespaces use block indent */
1918namespace test test2 {
1919 111111111111111111111;
1920}
1921namespace11111111111 {
1922 111111111111;
1923}
1924namespace() {
1925 1111111111111;
1926}
1927namespace()
1928{
1929 111111111111111111;
1930}
1931namespace test test2
1932{
1933 1111111111111111111;
1934}
1935namespace111111111
1936{
1937 111111111111111111;
1938}
1939NAMESPACEEND
1940
1941
1942STARTTEST
Bram Moolenaar76f7fd32011-07-20 15:09:43 +02001943:set cino=j1,J1
Bram Moolenaar6ec154b2011-06-12 21:51:08 +02001944/^JSSTART
1945=/^JSEND
1946ENDTEST
1947
1948JSSTART
1949var bar = {
1950foo: {
1951that: this,
1952some: ok,
1953},
1954"bar":{
1955a : 2,
1956b: "123abc",
1957x: 4,
1958"y": 5
1959}
1960}
1961JSEND
1962
1963STARTTEST
Bram Moolenaar76f7fd32011-07-20 15:09:43 +02001964:set cino=j1,J1
1965/^JSSTART
1966=/^JSEND
1967ENDTEST
1968
1969JSSTART
1970var foo = [
Bram Moolenaar9f4fe7c2014-07-03 22:57:55 +020019711,
Bram Moolenaar76f7fd32011-07-20 15:09:43 +020019722,
19733
Bram Moolenaar9f4fe7c2014-07-03 22:57:55 +02001974];
Bram Moolenaar76f7fd32011-07-20 15:09:43 +02001975JSEND
1976
1977STARTTEST
1978:set cino=j1,J1
1979/^JSSTART
1980=/^JSEND
1981ENDTEST
1982
1983JSSTART
1984function bar() {
1985var foo = [
19861,
19872,
19883
Bram Moolenaar9f4fe7c2014-07-03 22:57:55 +02001989];
Bram Moolenaar76f7fd32011-07-20 15:09:43 +02001990}
1991JSEND
1992
1993STARTTEST
1994:set cino=j1,J1
1995/^JSSTART
1996=/^JSEND
1997ENDTEST
1998
1999JSSTART
2000(function($){
2001
Bram Moolenaar81439a62014-07-02 18:27:48 +02002002if (cond &&
2003cond) {
2004stmt;
2005}
Bram Moolenaar9f4fe7c2014-07-03 22:57:55 +02002006window.something.left =
2007(width - 50 + offset) + "px";
Bram Moolenaar76f7fd32011-07-20 15:09:43 +02002008var class_name='myclass';
2009
2010function private_method() {
2011}
2012
2013var public_method={
2014method: function(options,args){
2015private_method();
2016}
2017}
2018
2019function init(options) {
2020
2021$(this).data(class_name+'_public',$.extend({},{
2022foo: 'bar',
Bram Moolenaar9f4fe7c2014-07-03 22:57:55 +02002023bar: 2,
2024foobar: [
20251,
20262,
20273
Bram Moolenaar76f7fd32011-07-20 15:09:43 +02002028],
Bram Moolenaar9f4fe7c2014-07-03 22:57:55 +02002029callback: function(){
2030return true;
2031}
Bram Moolenaar76f7fd32011-07-20 15:09:43 +02002032}, options||{}));
2033}
2034
2035$.fn[class_name]=function() {
2036
2037var _arguments=arguments;
2038return this.each(function(){
2039
2040var options=$(this).data(class_name+'_public');
2041if (!options) {
2042init.apply(this,_arguments);
2043
2044} else {
2045var method=public_method[_arguments[0]];
2046
2047if (typeof(method)!='function') {
2048console.log(class_name+' has no method "'+_arguments[0]+'"');
2049return false;
2050}
2051_arguments[0]=options;
2052method.apply(this,_arguments);
2053}
2054});
2055}
2056
2057})(jQuery);
2058JSEND
2059
2060STARTTEST
2061:set cino=j1,J1
2062/^JSSTART
2063=/^JSEND
2064ENDTEST
2065
2066JSSTART
2067function init(options) {
2068$(this).data(class_name+'_public',$.extend({},{
2069foo: 'bar',
2070bar: 2,
2071foobar: [
Bram Moolenaar9f4fe7c2014-07-03 22:57:55 +020020721,
20732,
20743
Bram Moolenaar76f7fd32011-07-20 15:09:43 +02002075],
2076callback: function(){
2077return true;
2078}
2079}, options||{}));
2080}
2081JSEND
2082
2083STARTTEST
2084:set cino=j1,J1
2085/^JSSTART
2086=/^JSEND
2087ENDTEST
2088
2089JSSTART
2090(function($){
2091function init(options) {
2092$(this).data(class_name+'_public',$.extend({},{
2093foo: 'bar',
Bram Moolenaar9f4fe7c2014-07-03 22:57:55 +02002094bar: 2,
2095foobar: [
20961,
20972,
20983
Bram Moolenaar76f7fd32011-07-20 15:09:43 +02002099],
Bram Moolenaar9f4fe7c2014-07-03 22:57:55 +02002100callback: function(){
2101return true;
2102}
Bram Moolenaar76f7fd32011-07-20 15:09:43 +02002103}, options||{}));
2104}
2105})(jQuery);
2106JSEND
2107
2108STARTTEST
Bram Moolenaardcefba92015-03-20 19:06:06 +01002109:set cino=j1,J1,+2
2110/^JSSTART
2111=/^JSEND
2112ENDTEST
2113
2114JSSTART
2115// Results of JavaScript indent
2116// 1
2117(function(){
2118var a = [
2119'a',
2120'b',
2121'c',
2122'd',
2123'e',
2124'f',
2125'g',
2126'h',
2127'i'
2128];
2129}())
2130
2131// 2
2132(function(){
2133var a = [
21340 +
21355 *
21369 *
2137'a',
2138'b',
21390 +
21405 *
21419 *
2142'c',
2143'd',
2144'e',
2145'f',
2146'g',
2147'h',
2148'i'
2149];
2150}())
2151
2152// 3
2153(function(){
2154var a = [
21550 +
2156// comment 1
21575 *
2158/* comment 2 */
21599 *
2160'a',
2161'b',
21620 +
21635 *
21649 *
2165'c',
2166'd',
2167'e',
2168'f',
2169'g',
2170'h',
2171'i'
2172];
2173}())
2174
2175// 4
2176{
2177var a = [
21780,
21791
2180];
2181var b;
2182var c;
2183}
2184
2185// 5
2186{
2187var a = [
2188[
21890
2190],
21912,
21923
2193];
2194}
2195
2196// 6
2197{
2198var a = [
2199[
22000,
22011
2202],
22032,
22043
2205];
2206}
2207
2208// 7
2209{
2210var a = [
2211// [
22120,
2213// 1
2214// ],
22152,
22163
2217];
2218}
2219
2220// 8
2221var x = [
2222(function(){
2223var a,
2224b,
2225c,
2226d,
2227e,
2228f,
2229g,
2230h,
2231i;
2232})
2233];
2234
2235// 9
2236var a = [
22370 +
22385 *
22399 *
2240'a',
2241'b',
22420 +
22435 *
22449 *
2245'c',
2246'd',
2247'e',
2248'f',
2249'g',
2250'h',
2251'i'
2252];
2253
2254// 10
2255var a,
2256b,
2257c,
2258d,
2259e,
2260f,
2261g,
2262h,
2263i;
2264JSEND
2265
2266STARTTEST
Bram Moolenaar071d4272004-06-13 20:20:40 +00002267:g/^STARTTEST/.,/^ENDTEST/d
2268:1;/start of AUTO/,$wq! test.out
2269ENDTEST