blob: 2f9572cc1323f913fea79f4ebc82c2f0fad5cc76 [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
Bram Moolenaare01f4f82015-11-10 14:06:53 +0100654A::A(int a, int b)
655 : aa(a),
656 bb(b),
657 cc(c)
658{
659}
660
Bram Moolenaar071d4272004-06-13 20:20:40 +0000661class CAbc :
662 public BaseClass1,
663 protected BaseClass2
664{
665 int Test() { return FALSE; }
666 int Test1() { return TRUE; }
667
668 CAbc(int a, int b ) :
669 BaseClass(a)
670 {
671 switch(xxx)
672 {
673 case abc:
674 asdf();
675 break;
676
677 case 999:
678 baer();
679 break;
680 }
681 }
682
683 public: // <-- this was incoreectly indented before!!
684 void testfall();
685 protected:
686 void testfall();
687};
688
689class CAbc : public BaseClass1,
Bram Moolenaar7fc904b2006-04-13 20:37:35 +0000690 protected BaseClass2
Bram Moolenaar071d4272004-06-13 20:20:40 +0000691{
692};
693
694static struct
695{
696 int a;
697 int b;
698} variable[COUNT] =
699{
700 {
701 123,
702 456
703 },
704 {
705 123,
706 456
707 }
708};
709
710static struct
711{
712 int a;
713 int b;
714} variable[COUNT] =
715{
716 { 123, 456 },
717 { 123, 456 }
718};
719
720void asdf() /* ind_maxparen may cause trouble here */
721{
722 if ((0
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
741 && 1
742 && 1
743 && 1
744 && 1
745 && 1
746 && 1
747 && 1)) break;
748}
749
Bram Moolenaar18144c82006-04-12 21:52:12 +0000750foo()
751{
752 a = cond ? foo() : asdf
753 + asdf;
754
755 a = cond ?
756 foo() : asdf
757 + asdf;
758}
759
760int main(void)
761{
762 if (a)
763 if (b)
764 2;
765 else 3;
766 next_line_of_code();
767}
768
Bram Moolenaar7fc904b2006-04-13 20:37:35 +0000769barry()
770{
771 Foo::Foo (int one,
772 int two)
773 : something(4)
774 {}
775}
776
777barry()
778{
779 Foo::Foo (int one, int two)
780 : something(4)
781 {}
782}
783
784Constructor::Constructor(int a,
785 int b
786 ) :
787 BaseClass(a,
788 b,
789 c),
790 mMember(b)
791{
792}
Bram Moolenaar9e54a0e2006-04-14 20:42:25 +0000793int main ()
794{
795 if (lala)
796 do
797 ++(*lolo);
798 while (lili
799 && lele);
800 lulu;
801}
Bram Moolenaar7fc904b2006-04-13 20:37:35 +0000802
Bram Moolenaar9e54a0e2006-04-14 20:42:25 +0000803int main ()
804{
805 switch (c)
806 {
807 case 'c': if (cond)
808 {
809 }
810 }
811}
812
813main()
814{
815 (void) MyFancyFuasdfadsfnction(
816 argument);
817}
818
819main()
820{
821 char foo[] = "/*";
822 /* as
823 df */
824 hello
825}
Bram Moolenaared38b0a2011-05-25 15:16:18 +0200826
827/* valid namespaces with normal indent */
828namespace
829{
830 {
831 111111111111;
832 }
833}
834namespace /* test */
835{
836 11111111111111111;
837}
838namespace // test
839{
840 111111111111111111;
841}
842namespace
843{
844 111111111111111111;
845}
846namespace test
847{
848 111111111111111111;
849}
850namespace{
851 111111111111111111;
852}
853namespace test{
854 111111111111111111;
855}
856namespace {
857 111111111111111111;
858}
859namespace test {
860 111111111111111111;
861 namespace test2 {
862 22222222222222222;
863 }
864}
865
866/* invalid namespaces use block indent */
867namespace test test2 {
868 111111111111111111111;
869}
870namespace11111111111 {
871 111111111111;
872}
873namespace() {
874 1111111111111;
875}
876namespace()
877{
878 111111111111111111;
879}
880namespace test test2
881{
882 1111111111111111111;
883}
884namespace111111111
885{
886 111111111111111111;
887}
888
Bram Moolenaarf7bb86d2015-07-28 21:17:36 +0200889void getstring() {
890 /* Raw strings */
891 const char* s = R"(
892 test {
893 # comment
894 field: 123
895 }
896 )";
897}
898
899void getstring() {
900 const char* s = R"foo(
901 test {
902 # comment
903 field: 123
904 }
905 )foo";
906}
907
Bram Moolenaar089af182015-10-07 11:41:49 +0200908{
909 int a[4] = {
910 [0] = 0,
911 [1] = 1,
912 [2] = 2,
913 [3] = 3,
914 };
915}
916
917{
918 a = b[2]
919 + 3;
920}
921
922{
923 if (1)
924 /* aaaaa
925 * bbbbb
926 */
927 a = 1;
928}
929
Bram Moolenaard1b15de2015-10-13 16:13:39 +0200930void func()
931{
932 switch (foo)
933 {
934 case (bar):
935 if (baz())
936 quux();
937 break;
938 case (shmoo):
939 if (!bar)
940 {
941 }
942 case (foo1):
943 switch (bar)
944 {
945 case baz:
946 baz_f();
947 break;
948 }
949 break;
950 default:
951 baz();
952 baz();
953 break;
954 }
955}
956
Bram Moolenaar071d4272004-06-13 20:20:40 +0000957/* end of AUTO */
958
959
960{
961
962/* this is
963 * a real serious
964 * about life, the
965 * universe, and the
966 * rest important big
967 * comment
968 */
969 /* insert " about life, the universe, and the rest" after "serious" */
970}
971
972
973{
974 /*
975 * Testing for comments, without 'cin' set
976 */
977about life
978
979/*
980* what happens here?
981*/
982there
983
984 /*
985 the end of the comment, try inserting a line below */
986line
987
988 /* how about
989hello
990 this one */
991}
992
993
994{
995 var = this + that + vec[0] * vec[0]
996 + vec[1] * vec[1]
997 + vec2[2] * vec[2];
998}
999
1000
1001{
1002 asdf asdflkajds f;
1003 if (tes & ting) {
1004 asdf asdf asdf ;
1005 asdfa sdf asdf;
1006 }
1007 testing1;
1008 if (tes & ting)
1009 {
1010 asdf asdf asdf ;
1011 asdfa sdf asdf;
1012 }
1013 testing2;
1014}
1015
1016
1017main ( int first_par, /*
1018 * Comment for
1019 * first par
1020 */
1021 int second_par /*
1022 * Comment for
1023 * second par
1024 */
1025 )
1026{
1027 func( first_par, /*
1028 * Comment for
1029 * first par
1030 */
1031 second_par /*
1032 * Comment for
1033 * second par
1034 */
1035 );
1036
1037}
1038
1039
Bram Moolenaar48d27922012-06-13 13:40:48 +02001040main(void)
1041{
1042 /* Make sure that cino=X0s is not parsed like cino=Xs. */
1043 if (cond)
1044 foo();
1045 else
1046 {
1047 bar();
1048 }
1049}
1050
1051
Bram Moolenaar071d4272004-06-13 20:20:40 +00001052{
1053 do
1054 {
1055 if ()
1056 {
1057 if ()
1058 asdf;
1059 else
1060 asdf;
1061 }
1062 } while ();
1063 cmd; /* this should go under the } */
1064}
1065
1066
1067void f()
1068{
1069 if ( k() ) {
1070 l();
1071
1072 } else { /* Start (two words) end */
1073 m();
1074 }
1075
1076 n();
1077}
1078
1079
1080void f()
1081 {
1082 if ( k() )
1083 {
1084 l();
1085 } else { /* Start (two words) end */
1086 m();
1087 }
1088 n(); /* should be under the if () */
1089}
1090
1091
1092void bar(void)
1093 {
1094 static array[2][2] =
1095 {
1096 { 1, 2 },
1097 { 3, 4 },
1098 }
1099
1100 while (a)
1101 {
1102 foo(&a);
1103 }
1104
1105 {
1106 int a;
1107 {
1108 a = a + 1;
1109 }
1110 }
1111 b = a;
1112 }
1113
1114void func(void)
1115 {
1116 a = 1;
1117 {
1118 b = 2;
1119 }
1120 c = 3;
1121 d = 4;
1122 }
1123/* foo */
1124
1125
1126a()
1127{
1128 do {
1129 a = a +
1130 a;
1131 } while ( a ); /* add text under this line */
1132 here
1133 if ( a )
1134 a;
1135}
1136
1137
1138a()
1139{
1140label1:
1141 /* hmm */
1142 // comment
1143label2: b();
1144label3 /* post */:
1145/* pre */ label4:
1146 f(/*com*/);
1147 if (/*com*/)
1148 cmd();
1149}
1150
1151
1152/*
1153 * A simple comment
1154 */
1155
1156/*
1157** A different comment
1158*/
1159
1160
1161void f()
1162{
1163
1164 /*********
1165 A comment.
1166 *********/
1167}
1168
1169
1170void f()
1171{
1172
1173 /*********
1174 A comment.
1175 *********/
1176}
1177
1178
1179void f()
1180{
1181 c = c1 &&
1182 (
1183 c2 ||
1184 c3
1185 ) && c4;
1186}
1187
1188
1189void f()
1190{
1191 c = c1 &&
1192 (
1193 c2 ||
1194 c3
1195 ) && c4;
1196}
1197
1198
1199void f()
1200{
1201 c = c1 &&
1202 (
1203 c2 ||
1204 c3
1205 ) && c4;
1206}
1207
1208
1209void f()
1210{
1211 if ( c1
1212 && ( c2
1213 || c3))
1214 foo;
1215}
1216
1217
1218void f()
1219{
1220 if ( c1
1221 && ( c2
1222 || c3))
1223 foo;
1224}
1225
1226
1227void f()
1228{
1229 c = c1 && (
1230 c2 ||
1231 c3
1232 ) && c4;
1233 if (
1234 c1 && c2
1235 )
1236 foo;
1237}
1238
1239
1240void f()
1241{
1242 c = c1 && (
1243 c2 ||
1244 c3
1245 ) && c4;
1246 if (
1247 c1 && c2
1248 )
1249 foo;
1250}
1251
1252
1253void f()
1254{
1255 switch (x)
1256 {
1257 case 1:
1258 a = b;
1259 break;
1260 default:
1261 a = 0;
1262 break;
1263 }
1264}
1265
1266
1267void f()
1268{
1269 invokeme(
1270 argu,
1271 ment);
1272 invokeme(
1273 argu,
1274 ment
1275 );
1276 invokeme(argu,
1277 ment
1278 );
1279}
1280
1281
1282void f()
1283{
1284 statement;
1285 // comment 1
1286 // comment 2
1287}
1288
1289
1290void f()
1291{
1292 statement;
1293 // comment 1
1294 // comment 2
1295}
1296
1297
1298class CAbc
1299{
1300 int Test() { return FALSE; }
1301
1302public: // comment
1303 void testfall();
1304protected:
1305 void testfall();
1306};
1307
1308
Bram Moolenaare79d1532011-10-04 18:03:47 +02001309class Foo : public Bar
1310{
1311 public:
1312 virtual void method1(void) = 0;
1313 virtual void method2(int arg1,
1314 int arg2,
1315 int arg3) = 0;
1316};
1317
1318
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00001319 void
1320foo()
1321{
1322 if (a)
1323 {
1324 } else
1325 asdf;
1326}
1327
1328
Bram Moolenaar071d4272004-06-13 20:20:40 +00001329{
1330 averylongfunctionnamelongfunctionnameaverylongfunctionname()->asd(
1331 asdasdf,
1332 func(asdf,
1333 asdfadsf),
1334 asdfasdf
1335 );
1336
1337 /* those are ugly, but consequent */
1338
1339 func()->asd(asdasdf,
1340 averylongfunctionname(
1341 abc,
1342 dec)->averylongfunctionname(
1343 asdfadsf,
1344 asdfasdf,
1345 asdfasdf,
1346 ),
1347 func(asdfadf,
1348 asdfasdf
1349 ),
1350 asdasdf
1351 );
1352
1353 averylongfunctionnameaverylongfunctionnameavery()->asd(fasdf(
1354 abc,
1355 dec)->asdfasdfasdf(
1356 asdfadsf,
1357 asdfasdf,
1358 asdfasdf,
1359 ),
1360 func(asdfadf,
1361 asdfasdf),
1362 asdasdf
1363 );
1364}
1365
Bram Moolenaar9e54a0e2006-04-14 20:42:25 +00001366
1367int main ()
1368{
1369 if (cond1 &&
1370 cond2
1371 )
1372 foo;
1373}
1374
Bram Moolenaar8d2d71d2011-04-28 13:02:09 +02001375
1376void func(int a
1377#if defined(FOO)
1378 , int b
1379 , int c
1380#endif
1381 )
1382{
1383}
1384
1385
1386 void
1387func(int a
1388#if defined(FOO)
1389 , int b
1390 , int c
1391#endif
1392 )
1393{
1394}
1395
Bram Moolenaar4ae06c12011-05-10 11:39:19 +02001396
1397void func(void)
1398{
1399 if(x==y)
1400 if(y==z)
1401 foo=1;
1402 else { bar=1;
1403 baz=2;
1404 }
1405 printf("Foo!\n");
1406}
1407
Bram Moolenaar496f9512011-05-19 16:35:09 +02001408void func1(void)
1409{
1410 char* tab[] = {"foo", "bar",
1411 "baz", "quux",
1412 "this line used", "to be indented incorrectly"};
1413 foo();
1414}
1415
1416void func2(void)
1417{
1418 int tab[] =
1419 {1, 2,
1420 3, 4,
1421 5, 6};
1422
1423 printf("This line used to be indented incorrectly.\n");
1424}
1425
Bram Moolenaar3388bb42011-11-30 17:20:23 +01001426int foo[]
1427#ifdef BAR
1428
1429= { 1, 2, 3,
1430 4, 5, 6 }
1431
1432#endif
1433 ;
1434int baz;
1435
Bram Moolenaar496f9512011-05-19 16:35:09 +02001436void func3(void)
1437{
1438 int tab[] = {
1439 1, 2,
1440 3, 4,
1441 5, 6};
1442
Bram Moolenaarc367faa2011-12-14 20:21:35 +01001443 printf("Don't you dare indent this line incorrectly!\n");
1444}
1445
1446 void
1447func4(a, b,
1448 c)
1449 int a;
1450 int b;
1451 int c;
1452{
1453}
1454
1455 void
1456func5(
1457 int a,
1458 int b)
1459{
1460}
1461
1462 void
1463func6(
1464 int a)
1465{
Bram Moolenaar496f9512011-05-19 16:35:09 +02001466}
1467
Bram Moolenaaraede6ce2011-05-10 11:56:30 +02001468
1469void func(void)
1470{
Bram Moolenaar50f42ca2011-07-15 14:12:30 +02001471 int tab[] =
1472 {
1473 1, 2, 3,
1474 4, 5, 6};
1475
1476 printf("Indent this line correctly!\n");
1477
1478 switch (foo)
1479 {
1480 case bar:
1481 printf("bar");
1482 break;
1483 case baz: {
1484 printf("baz");
1485 break;
1486 }
1487 case quux:
1488 printf("But don't break the indentation of this instruction\n");
1489 break;
1490 }
1491}
1492
1493
1494void func(void)
1495{
Bram Moolenaaraede6ce2011-05-10 11:56:30 +02001496 cout << "a"
1497 << "b"
1498 << ") :"
1499 << "c";
1500}
1501
Bram Moolenaara4271d52011-05-10 13:38:27 +02001502
1503void func(void)
1504{
1505 /*
1506 * This is a comment.
1507 */
1508 foo();
1509}
1510
Bram Moolenaar334adf02011-05-25 13:34:04 +02001511
1512void func(void)
1513{
1514 for (int i = 0; i < 10; ++i)
1515 if (i & 1) {
1516 foo(1);
1517 } else
1518 foo(0);
1519 baz();
1520}
1521
Bram Moolenaared38b0a2011-05-25 15:16:18 +02001522
Bram Moolenaar3675fa02012-04-05 17:17:42 +02001523void func(void)
1524{
1525 if (condition1
1526 && condition2)
1527 action();
1528 function(argument1
1529 && argument2);
1530
1531 if (c1 && (c2 ||
1532 c3))
1533 foo;
1534 if (c1 &&
1535 (c2 || c3))
1536 {
1537 }
1538
1539 if ( c1
1540 && ( c2
1541 || c3))
1542 foo;
1543 func( c1
1544 && ( c2
1545 || c3))
1546 foo;
1547}
1548
1549
1550void func(void)
1551{
1552 if (condition1
1553 && condition2)
1554 action();
1555 function(argument1
1556 && argument2);
1557
1558 if (c1 && (c2 ||
1559 c3))
1560 foo;
1561 if (c1 &&
1562 (c2 || c3))
1563 {
1564 }
1565
1566 if ( c1
1567 && ( c2
1568 || c3))
1569 foo;
1570 func( c1
1571 && ( c2
1572 || c3))
1573 foo;
1574}
1575
1576
1577void func(void)
1578{
1579 if (condition1
1580 && condition2)
1581 action();
1582 function(argument1
1583 && argument2);
1584
1585 if (c1 && (c2 ||
1586 c3))
1587 foo;
1588 if (c1 &&
1589 (c2 || c3))
1590 {
1591 }
1592 if (c123456789
1593 && (c22345
1594 || c3))
1595 printf("foo\n");
1596
1597 c = c1 &&
1598 (
1599 c2 ||
1600 c3
1601 ) && c4;
1602}
1603
1604
1605void func(void)
1606{
1607 if (condition1
1608 && condition2)
1609 action();
1610 function(argument1
1611 && argument2);
1612
1613 if (c1 && (c2 ||
1614 c3))
1615 foo;
1616 if (c1 &&
1617 (c2 || c3))
1618 {
1619 }
1620 if (c123456789
1621 && (c22345
1622 || c3))
1623 printf("foo\n");
1624
1625 if ( c1
1626 && ( c2
1627 || c3))
1628 foo;
1629
1630 a_long_line(
1631 argument,
1632 argument);
1633 a_short_line(argument,
1634 argument);
1635}
1636
1637
1638void func(void)
1639{
1640 if (condition1
1641 && condition2)
1642 action();
1643 function(argument1
1644 && argument2);
1645
1646 if (c1 && (c2 ||
1647 c3))
1648 foo;
1649 if (c1 &&
1650 (c2 || c3))
1651 {
1652 }
1653 if (c123456789
1654 && (c22345
1655 || c3))
1656 printf("foo\n");
1657}
1658
1659
1660void func(void)
1661{
1662 if (condition1
1663 && condition2)
1664 action();
1665 function(argument1
1666 && argument2);
1667
1668 if (c1 && (c2 ||
1669 c3))
1670 foo;
1671 if (c1 &&
1672 (c2 || c3))
1673 {
1674 }
1675 if (c123456789
1676 && (c22345
1677 || c3))
1678 printf("foo\n");
1679
1680 if ( c1
1681 && ( c2
1682 || c3))
1683 foo;
1684 func( c1
1685 && ( c2
1686 || c3))
1687 foo;
1688}
1689
1690
1691void func(void)
1692{
1693 if (condition1
1694 && condition2)
1695 action();
1696 function(argument1
1697 && argument2);
1698
1699 if (c1 && (c2 ||
1700 c3))
1701 foo;
1702 if (c1 &&
1703 (c2 || c3))
1704 {
1705 }
1706}
1707
1708
Bram Moolenaar6ec154b2011-06-12 21:51:08 +02001709NAMESPACESTART
Bram Moolenaared38b0a2011-05-25 15:16:18 +02001710/* valid namespaces with normal indent */
1711namespace
1712{
1713{
1714 111111111111;
1715}
1716}
1717namespace /* test */
1718{
171911111111111111111;
1720}
1721namespace // test
1722{
1723111111111111111111;
1724}
1725namespace
1726{
1727111111111111111111;
1728}
1729namespace test
1730{
1731111111111111111111;
1732}
Bram Moolenaarca8b8d62016-11-17 21:30:27 +01001733namespace test::cpp17
1734{
1735111111111111111111;
1736}
1737namespace ::incorrectcpp17
1738{
1739 111111111111111111;
1740}
1741namespace test::incorrectcpp17::
1742{
1743 111111111111111111;
1744}
1745namespace test:incorrectcpp17
1746{
1747 111111111111111111;
1748}
1749namespace test:::incorrectcpp17
1750{
1751 111111111111111111;
1752}
Bram Moolenaared38b0a2011-05-25 15:16:18 +02001753namespace{
1754111111111111111111;
1755}
1756namespace test{
1757111111111111111111;
1758}
1759namespace {
1760111111111111111111;
1761}
1762namespace test {
1763111111111111111111;
1764namespace test2 {
176522222222222222222;
1766}
1767}
1768
1769/* invalid namespaces use block indent */
1770namespace test test2 {
1771 111111111111111111111;
1772}
1773namespace11111111111 {
1774 111111111111;
1775}
1776namespace() {
1777 1111111111111;
1778}
1779namespace()
1780{
1781 111111111111111111;
1782}
1783namespace test test2
1784{
1785 1111111111111111111;
1786}
1787namespace111111111
1788{
1789 111111111111111111;
1790}
1791NAMESPACEEND
1792
1793
Bram Moolenaar6ec154b2011-06-12 21:51:08 +02001794
1795JSSTART
1796var bar = {
1797 foo: {
1798 that: this,
1799 some: ok,
1800 },
1801 "bar":{
1802 a : 2,
1803 b: "123abc",
1804 x: 4,
1805 "y": 5
1806 }
1807}
1808JSEND
1809
Bram Moolenaar76f7fd32011-07-20 15:09:43 +02001810
1811JSSTART
1812var foo = [
Bram Moolenaar9f4fe7c2014-07-03 22:57:55 +02001813 1,
Bram Moolenaar76f7fd32011-07-20 15:09:43 +02001814 2,
1815 3
Bram Moolenaar9f4fe7c2014-07-03 22:57:55 +02001816];
Bram Moolenaar76f7fd32011-07-20 15:09:43 +02001817JSEND
1818
1819
1820JSSTART
1821function bar() {
1822 var foo = [
1823 1,
1824 2,
1825 3
Bram Moolenaar9f4fe7c2014-07-03 22:57:55 +02001826 ];
Bram Moolenaar76f7fd32011-07-20 15:09:43 +02001827}
1828JSEND
1829
1830
1831JSSTART
1832(function($){
1833
Bram Moolenaar81439a62014-07-02 18:27:48 +02001834 if (cond &&
1835 cond) {
1836 stmt;
1837 }
Bram Moolenaar9f4fe7c2014-07-03 22:57:55 +02001838 window.something.left =
1839 (width - 50 + offset) + "px";
Bram Moolenaar76f7fd32011-07-20 15:09:43 +02001840 var class_name='myclass';
1841
1842 function private_method() {
1843 }
1844
1845 var public_method={
1846 method: function(options,args){
1847 private_method();
1848 }
1849 }
1850
1851 function init(options) {
1852
1853 $(this).data(class_name+'_public',$.extend({},{
1854 foo: 'bar',
Bram Moolenaar9f4fe7c2014-07-03 22:57:55 +02001855 bar: 2,
1856 foobar: [
1857 1,
1858 2,
1859 3
Bram Moolenaar76f7fd32011-07-20 15:09:43 +02001860 ],
Bram Moolenaar9f4fe7c2014-07-03 22:57:55 +02001861 callback: function(){
1862 return true;
1863 }
Bram Moolenaar76f7fd32011-07-20 15:09:43 +02001864 }, options||{}));
1865 }
1866
1867 $.fn[class_name]=function() {
1868
1869 var _arguments=arguments;
1870 return this.each(function(){
1871
1872 var options=$(this).data(class_name+'_public');
1873 if (!options) {
1874 init.apply(this,_arguments);
1875
1876 } else {
1877 var method=public_method[_arguments[0]];
1878
1879 if (typeof(method)!='function') {
1880 console.log(class_name+' has no method "'+_arguments[0]+'"');
1881 return false;
1882 }
1883 _arguments[0]=options;
1884 method.apply(this,_arguments);
1885 }
1886 });
1887 }
1888
1889})(jQuery);
1890JSEND
1891
1892
1893JSSTART
1894function init(options) {
1895 $(this).data(class_name+'_public',$.extend({},{
1896 foo: 'bar',
1897 bar: 2,
1898 foobar: [
Bram Moolenaar9f4fe7c2014-07-03 22:57:55 +02001899 1,
1900 2,
1901 3
Bram Moolenaar76f7fd32011-07-20 15:09:43 +02001902 ],
1903 callback: function(){
1904 return true;
1905 }
1906 }, options||{}));
1907}
1908JSEND
1909
1910
1911JSSTART
1912(function($){
1913 function init(options) {
1914 $(this).data(class_name+'_public',$.extend({},{
1915 foo: 'bar',
Bram Moolenaar9f4fe7c2014-07-03 22:57:55 +02001916 bar: 2,
1917 foobar: [
1918 1,
1919 2,
1920 3
Bram Moolenaar76f7fd32011-07-20 15:09:43 +02001921 ],
Bram Moolenaar9f4fe7c2014-07-03 22:57:55 +02001922 callback: function(){
1923 return true;
1924 }
Bram Moolenaar76f7fd32011-07-20 15:09:43 +02001925 }, options||{}));
1926 }
1927})(jQuery);
1928JSEND
1929
Bram Moolenaardcefba92015-03-20 19:06:06 +01001930
1931JSSTART
1932// Results of JavaScript indent
1933// 1
1934(function(){
1935 var a = [
1936 'a',
1937 'b',
1938 'c',
1939 'd',
1940 'e',
1941 'f',
1942 'g',
1943 'h',
1944 'i'
1945 ];
1946}())
1947
1948// 2
1949(function(){
1950 var a = [
1951 0 +
1952 5 *
1953 9 *
1954 'a',
1955 'b',
1956 0 +
1957 5 *
1958 9 *
1959 'c',
1960 'd',
1961 'e',
1962 'f',
1963 'g',
1964 'h',
1965 'i'
1966 ];
1967}())
1968
1969// 3
1970(function(){
1971 var a = [
1972 0 +
1973 // comment 1
1974 5 *
1975 /* comment 2 */
1976 9 *
1977 'a',
1978 'b',
1979 0 +
1980 5 *
1981 9 *
1982 'c',
1983 'd',
1984 'e',
1985 'f',
1986 'g',
1987 'h',
1988 'i'
1989 ];
1990}())
1991
1992// 4
1993{
1994 var a = [
1995 0,
1996 1
1997 ];
1998 var b;
1999 var c;
2000}
2001
2002// 5
2003{
2004 var a = [
2005 [
2006 0
2007 ],
2008 2,
2009 3
2010 ];
2011}
2012
2013// 6
2014{
2015 var a = [
2016 [
2017 0,
2018 1
2019 ],
2020 2,
2021 3
2022 ];
2023}
2024
2025// 7
2026{
2027 var a = [
2028 // [
2029 0,
2030 // 1
2031 // ],
2032 2,
2033 3
2034 ];
2035}
2036
2037// 8
2038var x = [
2039 (function(){
2040 var a,
2041 b,
2042 c,
2043 d,
2044 e,
2045 f,
2046 g,
2047 h,
2048 i;
2049 })
2050];
2051
2052// 9
2053var a = [
2054 0 +
2055 5 *
2056 9 *
2057 'a',
2058 'b',
2059 0 +
2060 5 *
2061 9 *
2062 'c',
2063 'd',
2064 'e',
2065 'f',
2066 'g',
2067 'h',
2068 'i'
2069];
2070
2071// 10
2072var a,
2073 b,
2074 c,
2075 d,
2076 e,
2077 f,
2078 g,
2079 h,
2080 i;
2081JSEND
2082