blob: 477aacc1caa752f384f05a52747557d063319fa1 [file] [log] [blame]
Bram Moolenaar9e54a0e2006-04-14 20:42:25 +00001/* start of AUTO matically checked vim: set ts=4 : */
Bram Moolenaar071d4272004-06-13 20:20:40 +00002{
3 if (test)
4 cmd1;
5 cmd2;
6}
7
8{
9 if (test)
10 cmd1;
11 else
12 cmd2;
13}
14
15{
16 if (test)
17 {
18 cmd1;
19 cmd2;
20 }
21}
22
23{
24 if (test)
25 {
26 cmd1;
27 else
28 }
29}
30
31{
32 while (this)
33 if (test)
34 cmd1;
35 cmd2;
36}
37
38{
39 while (this)
40 if (test)
41 cmd1;
42 else
43 cmd2;
44}
45
46{
47 if (test)
48 {
49 cmd;
50 }
51
52 if (test)
53 cmd;
54}
55
56{
57 if (test) {
58 cmd;
59 }
60
61 if (test) cmd;
62}
63
64{
65 cmd1;
66 for (blah)
67 while (this)
68 if (test)
69 cmd2;
70 cmd3;
71}
72
73{
74 cmd1;
75 for (blah)
76 while (this)
77 if (test)
78 cmd2;
79 cmd3;
80
81 if (test)
82 {
83 cmd1;
84 cmd2;
85 cmd3;
86 }
87}
88
89
90/* Test for 'cindent' do/while mixed with if/else: */
91
92{
93 do
94 if (asdf)
95 asdfasd;
96 while (cond);
97
98 do
99 if (asdf)
100 while (asdf)
101 asdf;
102 while (asdf);
103}
104
105/* Test for 'cindent' with two ) on a continuation line */
106{
107 if (asdfasdf;asldkfj asdlkfj as;ldkfj sal;d
108 aal;sdkjf ( ;asldfkja;sldfk
109 al;sdjfka ;slkdf ) sa;ldkjfsa dlk;)
110 line up here;
111}
112
113
114/* C++ tests: */
115
116// foo() these three lines should remain in column 0
117// {
118// }
119
120/* Test for continuation and unterminated lines: */
121{
122 i = 99 + 14325 +
123 21345 +
124 21345 +
125 21345 + ( 21345 +
126 21345) +
127 2345 +
128 1234;
129 c = 1;
130}
131
132/*
133 testje for indent with empty line
134
135 here */
136
137{
138 if (testing &&
139 not a joke ||
140 line up here)
141 hay;
142 if (testing &&
143 (not a joke || testing
144 )line up here)
145 hay;
146 if (testing &&
147 (not a joke || testing
148 line up here))
149 hay;
150}
151
152
153{
154 switch (c)
155 {
156 case xx:
157 do
158 if (asdf)
159 do
160 asdfasdf;
161 while (asdf);
162 else
163 asdfasdf;
164 while (cond);
165 case yy:
166 case xx:
167 case zz:
168 testing;
169 }
170}
171
172{
173 if (cond) {
174 foo;
175 }
176 else
177 {
178 bar;
179 }
180}
181
182{
183 if (alskdfj ;alsdkfjal;skdjf (;sadlkfsa ;dlkf j;alksdfj ;alskdjf
184 alsdkfj (asldk;fj
185 awith cino=(0 ;lf this one goes to below the paren with ==
186 ;laksjfd ;lsakdjf ;alskdf asd)
187 asdfasdf;)))
188 asdfasdf;
189}
190
191 int
192func(a, b)
193 int a;
194 int c;
195{
196 if (c1 && (c2 ||
197 c3))
198 foo;
199 if (c1 &&
200 (c2 || c3)
201 )
202}
203
204{
205 while (asd)
206 {
207 if (asdf)
208 if (test)
209 if (that)
210 {
211 if (asdf)
212 do
213 cdasd;
214 while (as
215 df);
216 }
217 else
218 if (asdf)
219 asdf;
220 else
221 asdf;
222 asdf;
223 }
224}
225
226{
227 s = "/*"; b = ';'
228 s = "/*"; b = ';';
229 a = b;
230}
231
232{
233 switch (a)
234 {
235 case a:
236 switch (t)
237 {
238 case 1:
239 cmd;
240 break;
241 case 2:
242 cmd;
243 break;
244 }
245 cmd;
246 break;
247 case b:
248 {
249 int i;
250 cmd;
251 }
252 break;
253 case c: {
254 int i;
255 cmd;
256 }
257 case d: if (cond &&
258 test) { /* this line doesn't work right */
259 int i;
260 cmd;
261 }
262 break;
263 }
264}
265
266{
267 if (!(vim_strchr(p_cpo, CPO_BUFOPTGLOB) != NULL && entering) &&
268 (bp_to->b_p_initialized ||
269 (!entering && vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
270 return;
271label :
272 asdf = asdf ?
273 asdf : asdf;
274 asdf = asdf ?
275 asdf: asdf;
276}
277
278/* Special Comments : This function has the added complexity (compared */
279/* : to addtolist) of having to check for a detail */
280/* : texture and add that to the list first. */
281
282char *(array[100]) = {
283 "testje",
284 "foo",
285 "bar",
286}
287
288enum soppie
289{
290 yes = 0,
291 no,
292 maybe
293};
294
295typedef enum soppie
296{
297 yes = 0,
298 no,
299 maybe
300};
301
Bram Moolenaara5285652011-12-14 20:05:21 +0100302static enum
303{
304 yes = 0,
305 no,
306 maybe
307} soppie;
308
Bram Moolenaard999db22013-03-07 13:21:32 +0100309public static enum
310{
311 yes = 0,
312 no,
313 maybe
314} soppie;
315
316static private enum
317{
318 yes = 0,
319 no,
320 maybe
321} soppie;
322
Bram Moolenaar071d4272004-06-13 20:20:40 +0000323{
324 int a,
325 b;
326}
327
328{
329 struct Type
330 {
331 int i;
332 char *str;
333 } var[] =
334 {
335 0, "zero",
336 1, "one",
337 2, "two",
338 3, "three"
339 };
340
341 float matrix[3][3] =
342 {
343 {
344 0,
345 1,
346 2
347 },
348 {
349 3,
350 4,
351 5
352 },
353 {
354 6,
355 7,
356 8
357 }
358 };
359}
360
361{
362 /* blah ( blah */
363 /* where does this go? */
364
365 /* blah ( blah */
366 cmd;
367
368 func(arg1,
369 /* comment */
370 arg2);
371 a;
372 {
373 b;
374 {
375 c; /* Hey, NOW it indents?! */
376 }
377 }
378
379 {
380 func(arg1,
381 arg2,
382 arg3);
383 /* Hey, what am I doing here? Is this coz of the ","? */
384 }
385}
386
387main ()
388{
389 if (cond)
390 {
391 a = b;
392 }
393 if (cond) {
394 a = c;
395 }
396 if (cond)
397 a = d;
398 return;
399}
400
401{
402 case 2: if (asdf &&
403 asdfasdf)
404 aasdf;
405 a = 9;
406 case 3: if (asdf)
407 aasdf;
408 a = 9;
409 case 4: x = 1;
410 y = 2;
411
412label: if (asdf)
413 here;
414
415label: if (asdf &&
416 asdfasdf)
417 {
418 }
419
420label: if (asdf &&
421 asdfasdf) {
422 there;
423 }
424
425label: if (asdf &&
426 asdfasdf)
427 there;
428}
429
430{
431 /*
432 hello with ":set comments= cino=c5"
433 */
434
435 /*
436 hello with ":set comments= cino="
437 */
438}
439
440
441{
442 if (a < b) {
443 a = a + 1;
444 } else
445 a = a + 2;
446
447 if (a)
448 do {
449 testing;
450 } while (asdfasdf);
451 a = b + 1;
452 asdfasdf
453}
454
Bram Moolenaar04d17ae2014-08-06 17:44:14 +0200455{
456 for ( int i = 0;
457 i < 10; i++ )
458 {
459 }
460 i = 0;
461}
462
Bram Moolenaar071d4272004-06-13 20:20:40 +0000463class bob
464{
465 int foo() {return 1;}
466 int bar;
467}
468
469main()
470{
471 while(1)
472 if (foo)
473 {
474 bar;
475 }
476 else {
477 asdf;
478 }
479 misplacedline;
480}
481
482{
483 if (clipboard.state == SELECT_DONE
484 && ((row == clipboard.start.lnum
485 && col >= clipboard.start.col)
486 || row > clipboard.start.lnum))
487}
488
489{
490 if (1) {i += 4;}
491 where_am_i;
492 return 0;
493}
494
495{
496 {
497 } // sdf(asdf
498 if (asdf)
499 asd;
500}
501
502{
503label1:
504label2:
505}
506
507{
508 int fooRet = foo(pBar1, false /*fKB*/,
509 true /*fPTB*/, 3 /*nT*/, false /*fDF*/);
510 f() {
511 for ( i = 0;
512 i < m;
513 /* c */ i++ ) {
514 a = b;
515 }
516 }
517}
518
519{
520 f1(/*comment*/);
521 f2();
522}
523
524{
525 do {
526 if (foo) {
527 } else
528 ;
529 } while (foo);
530 foo(); // was wrong
531}
532
533int x; // no extra indent because of the ;
534void func()
535{
536}
537
538char *tab[] = {"aaa",
539 "};", /* }; */ NULL}
540 int indented;
541{}
542
543char *a[] = {"aaa", "bbb",
544 "ccc", NULL};
545// here
546
547char *tab[] = {"aaa",
548 "xx", /* xx */}; /* asdf */
549int not_indented;
550
551{
552 do {
553 switch (bla)
554 {
555 case 1: if (foo)
556 bar;
557 }
558 } while (boo);
559 wrong;
560}
561
562int foo,
563 bar;
564int foo;
565
566#if defined(foo) \
567 && defined(bar)
568char * xx = "asdf\
569 foo\
570 bor";
571int x;
572
573char *foo = "asdf\
574 asdf\
575 asdf",
576 *bar;
577
578void f()
579{
580#if defined(foo) \
581 && defined(bar)
582 char *foo = "asdf\
583 asdf\
584 asdf",
585 *bar;
586 {
587 int i;
588 char *foo = "asdf\
589 asdf\
590 asdf",
591 *bar;
592 }
593#endif
594}
595#endif
596
597int y; // comment
598// comment
599
600// comment
601
602{
603 Constructor(int a,
604 int b ) : BaseClass(a)
605 {
606 }
607}
608
609void foo()
610{
611 char one,
612 two;
613 struct bla piet,
614 jan;
615 enum foo kees,
616 jannie;
617 static unsigned sdf,
618 krap;
619 unsigned int piet,
620 jan;
621 int
622 kees,
623 jan;
624}
625
626{
627 t(int f,
628 int d); // )
629 d();
630}
631
632Constructor::Constructor(int a,
633 int b
634 ) :
635 BaseClass(a,
636 b,
637 c),
638 mMember(b),
639{
640}
641
642Constructor::Constructor(int a,
643 int b ) :
644 BaseClass(a)
645{
646}
647
648Constructor::Constructor(int a,
649 int b ) /*x*/ : /*x*/ BaseClass(a),
Bram Moolenaar7fc904b2006-04-13 20:37:35 +0000650 member(b)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000651{
652}
653
654class CAbc :
655 public BaseClass1,
656 protected BaseClass2
657{
658 int Test() { return FALSE; }
659 int Test1() { return TRUE; }
660
661 CAbc(int a, int b ) :
662 BaseClass(a)
663 {
664 switch(xxx)
665 {
666 case abc:
667 asdf();
668 break;
669
670 case 999:
671 baer();
672 break;
673 }
674 }
675
676 public: // <-- this was incoreectly indented before!!
677 void testfall();
678 protected:
679 void testfall();
680};
681
682class CAbc : public BaseClass1,
Bram Moolenaar7fc904b2006-04-13 20:37:35 +0000683 protected BaseClass2
Bram Moolenaar071d4272004-06-13 20:20:40 +0000684{
685};
686
687static struct
688{
689 int a;
690 int b;
691} variable[COUNT] =
692{
693 {
694 123,
695 456
696 },
697 {
698 123,
699 456
700 }
701};
702
703static struct
704{
705 int a;
706 int b;
707} variable[COUNT] =
708{
709 { 123, 456 },
710 { 123, 456 }
711};
712
713void asdf() /* ind_maxparen may cause trouble here */
714{
715 if ((0
716 && 1
717 && 1
718 && 1
719 && 1
720 && 1
721 && 1
722 && 1
723 && 1
724 && 1
725 && 1
726 && 1
727 && 1
728 && 1
729 && 1
730 && 1
731 && 1
732 && 1
733 && 1
734 && 1
735 && 1
736 && 1
737 && 1
738 && 1
739 && 1
740 && 1)) break;
741}
742
Bram Moolenaar18144c82006-04-12 21:52:12 +0000743foo()
744{
745 a = cond ? foo() : asdf
746 + asdf;
747
748 a = cond ?
749 foo() : asdf
750 + asdf;
751}
752
753int main(void)
754{
755 if (a)
756 if (b)
757 2;
758 else 3;
759 next_line_of_code();
760}
761
Bram Moolenaar7fc904b2006-04-13 20:37:35 +0000762barry()
763{
764 Foo::Foo (int one,
765 int two)
766 : something(4)
767 {}
768}
769
770barry()
771{
772 Foo::Foo (int one, int two)
773 : something(4)
774 {}
775}
776
777Constructor::Constructor(int a,
778 int b
779 ) :
780 BaseClass(a,
781 b,
782 c),
783 mMember(b)
784{
785}
Bram Moolenaar9e54a0e2006-04-14 20:42:25 +0000786int main ()
787{
788 if (lala)
789 do
790 ++(*lolo);
791 while (lili
792 && lele);
793 lulu;
794}
Bram Moolenaar7fc904b2006-04-13 20:37:35 +0000795
Bram Moolenaar9e54a0e2006-04-14 20:42:25 +0000796int main ()
797{
798 switch (c)
799 {
800 case 'c': if (cond)
801 {
802 }
803 }
804}
805
806main()
807{
808 (void) MyFancyFuasdfadsfnction(
809 argument);
810}
811
812main()
813{
814 char foo[] = "/*";
815 /* as
816 df */
817 hello
818}
Bram Moolenaared38b0a2011-05-25 15:16:18 +0200819
820/* valid namespaces with normal indent */
821namespace
822{
823 {
824 111111111111;
825 }
826}
827namespace /* test */
828{
829 11111111111111111;
830}
831namespace // test
832{
833 111111111111111111;
834}
835namespace
836{
837 111111111111111111;
838}
839namespace test
840{
841 111111111111111111;
842}
843namespace{
844 111111111111111111;
845}
846namespace test{
847 111111111111111111;
848}
849namespace {
850 111111111111111111;
851}
852namespace test {
853 111111111111111111;
854 namespace test2 {
855 22222222222222222;
856 }
857}
858
859/* invalid namespaces use block indent */
860namespace test test2 {
861 111111111111111111111;
862}
863namespace11111111111 {
864 111111111111;
865}
866namespace() {
867 1111111111111;
868}
869namespace()
870{
871 111111111111111111;
872}
873namespace test test2
874{
875 1111111111111111111;
876}
877namespace111111111
878{
879 111111111111111111;
880}
881
Bram Moolenaarf7bb86d2015-07-28 21:17:36 +0200882void getstring() {
883 /* Raw strings */
884 const char* s = R"(
885 test {
886 # comment
887 field: 123
888 }
889 )";
890}
891
892void getstring() {
893 const char* s = R"foo(
894 test {
895 # comment
896 field: 123
897 }
898 )foo";
899}
900
Bram Moolenaar089af182015-10-07 11:41:49 +0200901{
902 int a[4] = {
903 [0] = 0,
904 [1] = 1,
905 [2] = 2,
906 [3] = 3,
907 };
908}
909
910{
911 a = b[2]
912 + 3;
913}
914
915{
916 if (1)
917 /* aaaaa
918 * bbbbb
919 */
920 a = 1;
921}
922
Bram Moolenaard1b15de2015-10-13 16:13:39 +0200923void func()
924{
925 switch (foo)
926 {
927 case (bar):
928 if (baz())
929 quux();
930 break;
931 case (shmoo):
932 if (!bar)
933 {
934 }
935 case (foo1):
936 switch (bar)
937 {
938 case baz:
939 baz_f();
940 break;
941 }
942 break;
943 default:
944 baz();
945 baz();
946 break;
947 }
948}
949
Bram Moolenaar071d4272004-06-13 20:20:40 +0000950/* end of AUTO */
951
952
953{
954
955/* this is
956 * a real serious
957 * about life, the
958 * universe, and the
959 * rest important big
960 * comment
961 */
962 /* insert " about life, the universe, and the rest" after "serious" */
963}
964
965
966{
967 /*
968 * Testing for comments, without 'cin' set
969 */
970about life
971
972/*
973* what happens here?
974*/
975there
976
977 /*
978 the end of the comment, try inserting a line below */
979line
980
981 /* how about
982hello
983 this one */
984}
985
986
987{
988 var = this + that + vec[0] * vec[0]
989 + vec[1] * vec[1]
990 + vec2[2] * vec[2];
991}
992
993
994{
995 asdf asdflkajds f;
996 if (tes & ting) {
997 asdf asdf asdf ;
998 asdfa sdf asdf;
999 }
1000 testing1;
1001 if (tes & ting)
1002 {
1003 asdf asdf asdf ;
1004 asdfa sdf asdf;
1005 }
1006 testing2;
1007}
1008
1009
1010main ( int first_par, /*
1011 * Comment for
1012 * first par
1013 */
1014 int second_par /*
1015 * Comment for
1016 * second par
1017 */
1018 )
1019{
1020 func( first_par, /*
1021 * Comment for
1022 * first par
1023 */
1024 second_par /*
1025 * Comment for
1026 * second par
1027 */
1028 );
1029
1030}
1031
1032
Bram Moolenaar48d27922012-06-13 13:40:48 +02001033main(void)
1034{
1035 /* Make sure that cino=X0s is not parsed like cino=Xs. */
1036 if (cond)
1037 foo();
1038 else
1039 {
1040 bar();
1041 }
1042}
1043
1044
Bram Moolenaar071d4272004-06-13 20:20:40 +00001045{
1046 do
1047 {
1048 if ()
1049 {
1050 if ()
1051 asdf;
1052 else
1053 asdf;
1054 }
1055 } while ();
1056 cmd; /* this should go under the } */
1057}
1058
1059
1060void f()
1061{
1062 if ( k() ) {
1063 l();
1064
1065 } else { /* Start (two words) end */
1066 m();
1067 }
1068
1069 n();
1070}
1071
1072
1073void f()
1074 {
1075 if ( k() )
1076 {
1077 l();
1078 } else { /* Start (two words) end */
1079 m();
1080 }
1081 n(); /* should be under the if () */
1082}
1083
1084
1085void bar(void)
1086 {
1087 static array[2][2] =
1088 {
1089 { 1, 2 },
1090 { 3, 4 },
1091 }
1092
1093 while (a)
1094 {
1095 foo(&a);
1096 }
1097
1098 {
1099 int a;
1100 {
1101 a = a + 1;
1102 }
1103 }
1104 b = a;
1105 }
1106
1107void func(void)
1108 {
1109 a = 1;
1110 {
1111 b = 2;
1112 }
1113 c = 3;
1114 d = 4;
1115 }
1116/* foo */
1117
1118
1119a()
1120{
1121 do {
1122 a = a +
1123 a;
1124 } while ( a ); /* add text under this line */
1125 here
1126 if ( a )
1127 a;
1128}
1129
1130
1131a()
1132{
1133label1:
1134 /* hmm */
1135 // comment
1136label2: b();
1137label3 /* post */:
1138/* pre */ label4:
1139 f(/*com*/);
1140 if (/*com*/)
1141 cmd();
1142}
1143
1144
1145/*
1146 * A simple comment
1147 */
1148
1149/*
1150** A different comment
1151*/
1152
1153
1154void f()
1155{
1156
1157 /*********
1158 A comment.
1159 *********/
1160}
1161
1162
1163void f()
1164{
1165
1166 /*********
1167 A comment.
1168 *********/
1169}
1170
1171
1172void f()
1173{
1174 c = c1 &&
1175 (
1176 c2 ||
1177 c3
1178 ) && c4;
1179}
1180
1181
1182void f()
1183{
1184 c = c1 &&
1185 (
1186 c2 ||
1187 c3
1188 ) && c4;
1189}
1190
1191
1192void f()
1193{
1194 c = c1 &&
1195 (
1196 c2 ||
1197 c3
1198 ) && c4;
1199}
1200
1201
1202void f()
1203{
1204 if ( c1
1205 && ( c2
1206 || c3))
1207 foo;
1208}
1209
1210
1211void f()
1212{
1213 if ( c1
1214 && ( c2
1215 || c3))
1216 foo;
1217}
1218
1219
1220void f()
1221{
1222 c = c1 && (
1223 c2 ||
1224 c3
1225 ) && c4;
1226 if (
1227 c1 && c2
1228 )
1229 foo;
1230}
1231
1232
1233void f()
1234{
1235 c = c1 && (
1236 c2 ||
1237 c3
1238 ) && c4;
1239 if (
1240 c1 && c2
1241 )
1242 foo;
1243}
1244
1245
1246void f()
1247{
1248 switch (x)
1249 {
1250 case 1:
1251 a = b;
1252 break;
1253 default:
1254 a = 0;
1255 break;
1256 }
1257}
1258
1259
1260void f()
1261{
1262 invokeme(
1263 argu,
1264 ment);
1265 invokeme(
1266 argu,
1267 ment
1268 );
1269 invokeme(argu,
1270 ment
1271 );
1272}
1273
1274
1275void f()
1276{
1277 statement;
1278 // comment 1
1279 // comment 2
1280}
1281
1282
1283void f()
1284{
1285 statement;
1286 // comment 1
1287 // comment 2
1288}
1289
1290
1291class CAbc
1292{
1293 int Test() { return FALSE; }
1294
1295public: // comment
1296 void testfall();
1297protected:
1298 void testfall();
1299};
1300
1301
Bram Moolenaare79d1532011-10-04 18:03:47 +02001302class Foo : public Bar
1303{
1304 public:
1305 virtual void method1(void) = 0;
1306 virtual void method2(int arg1,
1307 int arg2,
1308 int arg3) = 0;
1309};
1310
1311
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00001312 void
1313foo()
1314{
1315 if (a)
1316 {
1317 } else
1318 asdf;
1319}
1320
1321
Bram Moolenaar071d4272004-06-13 20:20:40 +00001322{
1323 averylongfunctionnamelongfunctionnameaverylongfunctionname()->asd(
1324 asdasdf,
1325 func(asdf,
1326 asdfadsf),
1327 asdfasdf
1328 );
1329
1330 /* those are ugly, but consequent */
1331
1332 func()->asd(asdasdf,
1333 averylongfunctionname(
1334 abc,
1335 dec)->averylongfunctionname(
1336 asdfadsf,
1337 asdfasdf,
1338 asdfasdf,
1339 ),
1340 func(asdfadf,
1341 asdfasdf
1342 ),
1343 asdasdf
1344 );
1345
1346 averylongfunctionnameaverylongfunctionnameavery()->asd(fasdf(
1347 abc,
1348 dec)->asdfasdfasdf(
1349 asdfadsf,
1350 asdfasdf,
1351 asdfasdf,
1352 ),
1353 func(asdfadf,
1354 asdfasdf),
1355 asdasdf
1356 );
1357}
1358
Bram Moolenaar9e54a0e2006-04-14 20:42:25 +00001359
1360int main ()
1361{
1362 if (cond1 &&
1363 cond2
1364 )
1365 foo;
1366}
1367
Bram Moolenaar8d2d71d2011-04-28 13:02:09 +02001368
1369void func(int a
1370#if defined(FOO)
1371 , int b
1372 , int c
1373#endif
1374 )
1375{
1376}
1377
1378
1379 void
1380func(int a
1381#if defined(FOO)
1382 , int b
1383 , int c
1384#endif
1385 )
1386{
1387}
1388
Bram Moolenaar4ae06c12011-05-10 11:39:19 +02001389
1390void func(void)
1391{
1392 if(x==y)
1393 if(y==z)
1394 foo=1;
1395 else { bar=1;
1396 baz=2;
1397 }
1398 printf("Foo!\n");
1399}
1400
Bram Moolenaar496f9512011-05-19 16:35:09 +02001401void func1(void)
1402{
1403 char* tab[] = {"foo", "bar",
1404 "baz", "quux",
1405 "this line used", "to be indented incorrectly"};
1406 foo();
1407}
1408
1409void func2(void)
1410{
1411 int tab[] =
1412 {1, 2,
1413 3, 4,
1414 5, 6};
1415
1416 printf("This line used to be indented incorrectly.\n");
1417}
1418
Bram Moolenaar3388bb42011-11-30 17:20:23 +01001419int foo[]
1420#ifdef BAR
1421
1422= { 1, 2, 3,
1423 4, 5, 6 }
1424
1425#endif
1426 ;
1427int baz;
1428
Bram Moolenaar496f9512011-05-19 16:35:09 +02001429void func3(void)
1430{
1431 int tab[] = {
1432 1, 2,
1433 3, 4,
1434 5, 6};
1435
Bram Moolenaarc367faa2011-12-14 20:21:35 +01001436 printf("Don't you dare indent this line incorrectly!\n");
1437}
1438
1439 void
1440func4(a, b,
1441 c)
1442 int a;
1443 int b;
1444 int c;
1445{
1446}
1447
1448 void
1449func5(
1450 int a,
1451 int b)
1452{
1453}
1454
1455 void
1456func6(
1457 int a)
1458{
Bram Moolenaar496f9512011-05-19 16:35:09 +02001459}
1460
Bram Moolenaaraede6ce2011-05-10 11:56:30 +02001461
1462void func(void)
1463{
Bram Moolenaar50f42ca2011-07-15 14:12:30 +02001464 int tab[] =
1465 {
1466 1, 2, 3,
1467 4, 5, 6};
1468
1469 printf("Indent this line correctly!\n");
1470
1471 switch (foo)
1472 {
1473 case bar:
1474 printf("bar");
1475 break;
1476 case baz: {
1477 printf("baz");
1478 break;
1479 }
1480 case quux:
1481 printf("But don't break the indentation of this instruction\n");
1482 break;
1483 }
1484}
1485
1486
1487void func(void)
1488{
Bram Moolenaaraede6ce2011-05-10 11:56:30 +02001489 cout << "a"
1490 << "b"
1491 << ") :"
1492 << "c";
1493}
1494
Bram Moolenaara4271d52011-05-10 13:38:27 +02001495
1496void func(void)
1497{
1498 /*
1499 * This is a comment.
1500 */
1501 foo();
1502}
1503
Bram Moolenaar334adf02011-05-25 13:34:04 +02001504
1505void func(void)
1506{
1507 for (int i = 0; i < 10; ++i)
1508 if (i & 1) {
1509 foo(1);
1510 } else
1511 foo(0);
1512 baz();
1513}
1514
Bram Moolenaared38b0a2011-05-25 15:16:18 +02001515
Bram Moolenaar3675fa02012-04-05 17:17:42 +02001516void func(void)
1517{
1518 if (condition1
1519 && condition2)
1520 action();
1521 function(argument1
1522 && argument2);
1523
1524 if (c1 && (c2 ||
1525 c3))
1526 foo;
1527 if (c1 &&
1528 (c2 || c3))
1529 {
1530 }
1531
1532 if ( c1
1533 && ( c2
1534 || c3))
1535 foo;
1536 func( c1
1537 && ( c2
1538 || c3))
1539 foo;
1540}
1541
1542
1543void func(void)
1544{
1545 if (condition1
1546 && condition2)
1547 action();
1548 function(argument1
1549 && argument2);
1550
1551 if (c1 && (c2 ||
1552 c3))
1553 foo;
1554 if (c1 &&
1555 (c2 || c3))
1556 {
1557 }
1558
1559 if ( c1
1560 && ( c2
1561 || c3))
1562 foo;
1563 func( c1
1564 && ( c2
1565 || c3))
1566 foo;
1567}
1568
1569
1570void func(void)
1571{
1572 if (condition1
1573 && condition2)
1574 action();
1575 function(argument1
1576 && argument2);
1577
1578 if (c1 && (c2 ||
1579 c3))
1580 foo;
1581 if (c1 &&
1582 (c2 || c3))
1583 {
1584 }
1585 if (c123456789
1586 && (c22345
1587 || c3))
1588 printf("foo\n");
1589
1590 c = c1 &&
1591 (
1592 c2 ||
1593 c3
1594 ) && c4;
1595}
1596
1597
1598void func(void)
1599{
1600 if (condition1
1601 && condition2)
1602 action();
1603 function(argument1
1604 && argument2);
1605
1606 if (c1 && (c2 ||
1607 c3))
1608 foo;
1609 if (c1 &&
1610 (c2 || c3))
1611 {
1612 }
1613 if (c123456789
1614 && (c22345
1615 || c3))
1616 printf("foo\n");
1617
1618 if ( c1
1619 && ( c2
1620 || c3))
1621 foo;
1622
1623 a_long_line(
1624 argument,
1625 argument);
1626 a_short_line(argument,
1627 argument);
1628}
1629
1630
1631void func(void)
1632{
1633 if (condition1
1634 && condition2)
1635 action();
1636 function(argument1
1637 && argument2);
1638
1639 if (c1 && (c2 ||
1640 c3))
1641 foo;
1642 if (c1 &&
1643 (c2 || c3))
1644 {
1645 }
1646 if (c123456789
1647 && (c22345
1648 || c3))
1649 printf("foo\n");
1650}
1651
1652
1653void func(void)
1654{
1655 if (condition1
1656 && condition2)
1657 action();
1658 function(argument1
1659 && argument2);
1660
1661 if (c1 && (c2 ||
1662 c3))
1663 foo;
1664 if (c1 &&
1665 (c2 || c3))
1666 {
1667 }
1668 if (c123456789
1669 && (c22345
1670 || c3))
1671 printf("foo\n");
1672
1673 if ( c1
1674 && ( c2
1675 || c3))
1676 foo;
1677 func( c1
1678 && ( c2
1679 || c3))
1680 foo;
1681}
1682
1683
1684void func(void)
1685{
1686 if (condition1
1687 && condition2)
1688 action();
1689 function(argument1
1690 && argument2);
1691
1692 if (c1 && (c2 ||
1693 c3))
1694 foo;
1695 if (c1 &&
1696 (c2 || c3))
1697 {
1698 }
1699}
1700
1701
Bram Moolenaar6ec154b2011-06-12 21:51:08 +02001702NAMESPACESTART
Bram Moolenaared38b0a2011-05-25 15:16:18 +02001703/* valid namespaces with normal indent */
1704namespace
1705{
1706{
1707 111111111111;
1708}
1709}
1710namespace /* test */
1711{
171211111111111111111;
1713}
1714namespace // test
1715{
1716111111111111111111;
1717}
1718namespace
1719{
1720111111111111111111;
1721}
1722namespace test
1723{
1724111111111111111111;
1725}
1726namespace{
1727111111111111111111;
1728}
1729namespace test{
1730111111111111111111;
1731}
1732namespace {
1733111111111111111111;
1734}
1735namespace test {
1736111111111111111111;
1737namespace test2 {
173822222222222222222;
1739}
1740}
1741
1742/* invalid namespaces use block indent */
1743namespace test test2 {
1744 111111111111111111111;
1745}
1746namespace11111111111 {
1747 111111111111;
1748}
1749namespace() {
1750 1111111111111;
1751}
1752namespace()
1753{
1754 111111111111111111;
1755}
1756namespace test test2
1757{
1758 1111111111111111111;
1759}
1760namespace111111111
1761{
1762 111111111111111111;
1763}
1764NAMESPACEEND
1765
1766
Bram Moolenaar6ec154b2011-06-12 21:51:08 +02001767
1768JSSTART
1769var bar = {
1770 foo: {
1771 that: this,
1772 some: ok,
1773 },
1774 "bar":{
1775 a : 2,
1776 b: "123abc",
1777 x: 4,
1778 "y": 5
1779 }
1780}
1781JSEND
1782
Bram Moolenaar76f7fd32011-07-20 15:09:43 +02001783
1784JSSTART
1785var foo = [
Bram Moolenaar9f4fe7c2014-07-03 22:57:55 +02001786 1,
Bram Moolenaar76f7fd32011-07-20 15:09:43 +02001787 2,
1788 3
Bram Moolenaar9f4fe7c2014-07-03 22:57:55 +02001789];
Bram Moolenaar76f7fd32011-07-20 15:09:43 +02001790JSEND
1791
1792
1793JSSTART
1794function bar() {
1795 var foo = [
1796 1,
1797 2,
1798 3
Bram Moolenaar9f4fe7c2014-07-03 22:57:55 +02001799 ];
Bram Moolenaar76f7fd32011-07-20 15:09:43 +02001800}
1801JSEND
1802
1803
1804JSSTART
1805(function($){
1806
Bram Moolenaar81439a62014-07-02 18:27:48 +02001807 if (cond &&
1808 cond) {
1809 stmt;
1810 }
Bram Moolenaar9f4fe7c2014-07-03 22:57:55 +02001811 window.something.left =
1812 (width - 50 + offset) + "px";
Bram Moolenaar76f7fd32011-07-20 15:09:43 +02001813 var class_name='myclass';
1814
1815 function private_method() {
1816 }
1817
1818 var public_method={
1819 method: function(options,args){
1820 private_method();
1821 }
1822 }
1823
1824 function init(options) {
1825
1826 $(this).data(class_name+'_public',$.extend({},{
1827 foo: 'bar',
Bram Moolenaar9f4fe7c2014-07-03 22:57:55 +02001828 bar: 2,
1829 foobar: [
1830 1,
1831 2,
1832 3
Bram Moolenaar76f7fd32011-07-20 15:09:43 +02001833 ],
Bram Moolenaar9f4fe7c2014-07-03 22:57:55 +02001834 callback: function(){
1835 return true;
1836 }
Bram Moolenaar76f7fd32011-07-20 15:09:43 +02001837 }, options||{}));
1838 }
1839
1840 $.fn[class_name]=function() {
1841
1842 var _arguments=arguments;
1843 return this.each(function(){
1844
1845 var options=$(this).data(class_name+'_public');
1846 if (!options) {
1847 init.apply(this,_arguments);
1848
1849 } else {
1850 var method=public_method[_arguments[0]];
1851
1852 if (typeof(method)!='function') {
1853 console.log(class_name+' has no method "'+_arguments[0]+'"');
1854 return false;
1855 }
1856 _arguments[0]=options;
1857 method.apply(this,_arguments);
1858 }
1859 });
1860 }
1861
1862})(jQuery);
1863JSEND
1864
1865
1866JSSTART
1867function init(options) {
1868 $(this).data(class_name+'_public',$.extend({},{
1869 foo: 'bar',
1870 bar: 2,
1871 foobar: [
Bram Moolenaar9f4fe7c2014-07-03 22:57:55 +02001872 1,
1873 2,
1874 3
Bram Moolenaar76f7fd32011-07-20 15:09:43 +02001875 ],
1876 callback: function(){
1877 return true;
1878 }
1879 }, options||{}));
1880}
1881JSEND
1882
1883
1884JSSTART
1885(function($){
1886 function init(options) {
1887 $(this).data(class_name+'_public',$.extend({},{
1888 foo: 'bar',
Bram Moolenaar9f4fe7c2014-07-03 22:57:55 +02001889 bar: 2,
1890 foobar: [
1891 1,
1892 2,
1893 3
Bram Moolenaar76f7fd32011-07-20 15:09:43 +02001894 ],
Bram Moolenaar9f4fe7c2014-07-03 22:57:55 +02001895 callback: function(){
1896 return true;
1897 }
Bram Moolenaar76f7fd32011-07-20 15:09:43 +02001898 }, options||{}));
1899 }
1900})(jQuery);
1901JSEND
1902
Bram Moolenaardcefba92015-03-20 19:06:06 +01001903
1904JSSTART
1905// Results of JavaScript indent
1906// 1
1907(function(){
1908 var a = [
1909 'a',
1910 'b',
1911 'c',
1912 'd',
1913 'e',
1914 'f',
1915 'g',
1916 'h',
1917 'i'
1918 ];
1919}())
1920
1921// 2
1922(function(){
1923 var a = [
1924 0 +
1925 5 *
1926 9 *
1927 'a',
1928 'b',
1929 0 +
1930 5 *
1931 9 *
1932 'c',
1933 'd',
1934 'e',
1935 'f',
1936 'g',
1937 'h',
1938 'i'
1939 ];
1940}())
1941
1942// 3
1943(function(){
1944 var a = [
1945 0 +
1946 // comment 1
1947 5 *
1948 /* comment 2 */
1949 9 *
1950 'a',
1951 'b',
1952 0 +
1953 5 *
1954 9 *
1955 'c',
1956 'd',
1957 'e',
1958 'f',
1959 'g',
1960 'h',
1961 'i'
1962 ];
1963}())
1964
1965// 4
1966{
1967 var a = [
1968 0,
1969 1
1970 ];
1971 var b;
1972 var c;
1973}
1974
1975// 5
1976{
1977 var a = [
1978 [
1979 0
1980 ],
1981 2,
1982 3
1983 ];
1984}
1985
1986// 6
1987{
1988 var a = [
1989 [
1990 0,
1991 1
1992 ],
1993 2,
1994 3
1995 ];
1996}
1997
1998// 7
1999{
2000 var a = [
2001 // [
2002 0,
2003 // 1
2004 // ],
2005 2,
2006 3
2007 ];
2008}
2009
2010// 8
2011var x = [
2012 (function(){
2013 var a,
2014 b,
2015 c,
2016 d,
2017 e,
2018 f,
2019 g,
2020 h,
2021 i;
2022 })
2023];
2024
2025// 9
2026var a = [
2027 0 +
2028 5 *
2029 9 *
2030 'a',
2031 'b',
2032 0 +
2033 5 *
2034 9 *
2035 'c',
2036 'd',
2037 'e',
2038 'f',
2039 'g',
2040 'h',
2041 'i'
2042];
2043
2044// 10
2045var a,
2046 b,
2047 c,
2048 d,
2049 e,
2050 f,
2051 g,
2052 h,
2053 i;
2054JSEND
2055