Merged from the latest developing branch.
[MacVim.git] / src / testdir / test3.in
blob35582bd9c2379cf7d2e218d324e4fdb5bc5816fc
1 /* vim: set cin ts=4 sw=4 : */
3 Test for 'cindent'
5 STARTTEST
6 :so small.vim
7 :set nocompatible viminfo+=nviminfo modeline
8 :edit                " read modeline
9 /start of AUTO
10 =/end of AUTO
11 ENDTEST
13 /* start of AUTO matically checked vim: set ts=4 : */
15         if (test)
16                 cmd1;
17         cmd2;
21         if (test)
22                 cmd1;
23         else
24                 cmd2;
28         if (test)
29         {
30                 cmd1;
31                 cmd2;
32         }
36         if (test)
37         {
38                 cmd1;
39                 else
40         }
44         while (this)
45                 if (test)
46                         cmd1;
47         cmd2;
51         while (this)
52                 if (test)
53                         cmd1;
54                 else
55                         cmd2;
59         if (test)
60         {
61                 cmd;
62         }
64         if (test)
65                 cmd;
69         if (test) {
70                 cmd;
71         }
73         if (test) cmd;
77         cmd1;
78         for (blah)
79                 while (this)
80                         if (test)
81                                 cmd2;
82         cmd3;
86         cmd1;
87         for (blah)
88                 while (this)
89                         if (test)
90                                 cmd2;
91         cmd3;
93         if (test)
94         {
95                 cmd1;
96                 cmd2;
97                 cmd3;
98         }
102 /* Test for 'cindent' do/while mixed with if/else: */
105         do
106                 if (asdf)
107                         asdfasd;
108         while (cond);
110         do
111                 if (asdf)
112                         while (asdf)
113                                 asdf;
114         while (asdf);
117 /* Test for 'cindent' with two ) on a continuation line */
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;
126 /* C++ tests: */
128 // foo()                these three lines should remain in column 0
129 // {
130 // }
132 /* Test for continuation and unterminated lines: */
134         i = 99 + 14325 +
135                 21345 +
136                 21345 +
137                 21345 + ( 21345 +
138                                 21345) +
139                 2345 +
140                 1234;
141         c = 1;
145    testje for indent with empty line
147    here */
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;
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         }
185         if (cond) {
186                 foo;
187         }
188         else
189         {
190                 bar;
191         }
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;
203         int
204 func(a, b)
205         int a;
206         int c;
208         if (c1 && (c2 ||
209                         c3))
210                 foo;
211         if (c1 &&
212                         (c2 || c3)
213            )
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         }
239         s = "/*"; b = ';'
240                 s = "/*"; b = ';';
241         a = b;
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         }
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;
283 label :
284         asdf = asdf ?
285                 asdf : asdf;
286         asdf = asdf ?
287                 asdf: asdf;
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.                   */
294 char *(array[100]) = {
295         "testje",
296         "foo",
297         "bar",
300 enum soppie
302         yes = 0,
303         no,
304         maybe
307 typedef enum soppie
309         yes = 0,
310         no,
311         maybe
315         int a,
316                 b;
320         struct Type
321         {
322                 int i;
323                 char *str;
324         } var[] =
325         {
326                 0, "zero",
327                 1, "one",
328                 2, "two",
329                 3, "three"
330         };
332         float matrix[3][3] =
333         {
334                 {
335                         0,
336                         1,
337                         2
338                 },
339                 {
340                         3,
341                         4,
342                         5
343                 },
344                 {
345                         6,
346                         7,
347                         8
348                 }
349         };
353         /* blah ( blah */
354         /* where does this go? */
356         /* blah ( blah */
357         cmd;
359         func(arg1,
360                         /* comment */
361                         arg2);
362         a;
363         {
364                 b;
365                 {
366                         c; /* Hey, NOW it indents?! */
367                 }
368         }
370         {
371                 func(arg1,
372                                 arg2,
373                                 arg3);
374                 /* Hey, what am I doing here?  Is this coz of the ","? */
375         }
378 main ()
380         if (cond)
381         {
382                 a = b;
383         }
384         if (cond) {
385                 a = c;
386         }
387         if (cond)
388                 a = d;
389         return;
393         case 2: if (asdf &&
394                                         asdfasdf)
395                                 aasdf;
396                         a = 9;
397         case 3: if (asdf)
398                                 aasdf;
399                         a = 9;
400         case 4:    x = 1;
401                            y = 2;
403 label:  if (asdf)
404                         here;
406 label:  if (asdf &&
407                                 asdfasdf)
408                 {
409                 }
411 label:  if (asdf &&
412                                 asdfasdf) {
413                         there;
414                 }
416 label:  if (asdf &&
417                                 asdfasdf)
418                         there;
422         /*
423            hello with ":set comments= cino=c5"
424          */
426         /*
427            hello with ":set comments= cino="
428          */
433         if (a < b) {
434                 a = a + 1;
435         } else
436                 a = a + 2;
438         if (a)
439                 do {
440                         testing;
441                 } while (asdfasdf);
442         a = b + 1;
443         asdfasdf
446 class bob
448         int foo() {return 1;}
449                 int bar;
452 main()
454 while(1)
455 if (foo)
457 bar;
459 else {
460 asdf;
462 misplacedline;
466         if (clipboard.state == SELECT_DONE
467         && ((row == clipboard.start.lnum
468         && col >= clipboard.start.col)
469         || row > clipboard.start.lnum))
473 if (1) {i += 4;}
474 where_am_i;
475 return 0;
480 } // sdf(asdf
481 if (asdf)
482 asd;
486 label1:
487 label2:
491 int fooRet = foo(pBar1, false /*fKB*/,
492         true /*fPTB*/, 3 /*nT*/, false /*fDF*/);
493 f() {
494 for ( i = 0;
495         i < m;
496         /* c */ i++ ) {
497 a = b;
503         f1(/*comment*/);
504         f2();
508 do {
509 if (foo) {
510 } else
512 } while (foo);
513 foo();  // was wrong
516 int x;      // no extra indent because of the ;
517 void func()
521 char *tab[] = {"aaa",
522         "};", /* }; */ NULL}
523         int indented;
526 char *a[] = {"aaa", "bbb",
527         "ccc", NULL};
528 // here
530 char *tab[] = {"aaa",
531         "xx", /* xx */};    /* asdf */
532 int not_indented;
535         do {
536                 switch (bla)
537                 {
538                         case 1: if (foo)
539                                                 bar;
540                 }
541         } while (boo);
542                                         wrong;
545 int     foo,
546         bar;
547 int foo;
549 #if defined(foo) \
550         && defined(bar)
551 char * xx = "asdf\
552         foo\
553         bor";
554 int x;
556 char    *foo = "asdf\
557         asdf\
558         asdf",
559         *bar;
561 void f()
563 #if defined(foo) \
564         && defined(bar)
565 char    *foo = "asdf\
566         asdf\
567         asdf",
568         *bar;
569         {
570         int i;
571 char    *foo = "asdf\
572         asdf\
573         asdf",
574         *bar;
575         }
576 #endif
578 #endif
580 int y;          // comment
581                 // comment
583         // comment
586         Constructor(int a,
587                         int b )  : BaseClass(a)
588         {
589         }
592 void foo()
594         char one,
595         two;
596         struct bla piet,
597         jan;
598         enum foo kees,
599         jannie;
600         static unsigned sdf,
601         krap;
602         unsigned int piet,
603         jan;
604         int
605         kees,
606         jan;
610         t(int f,
611                         int d);         // )
612         d();
615 Constructor::Constructor(int a,
616                          int b 
617                         )  : 
618    BaseClass(a,
619              b,
620              c),
621    mMember(b),
625 Constructor::Constructor(int a,
626                          int b )  : 
627    BaseClass(a)
631 Constructor::Constructor(int a,
632                          int b ) /*x*/ : /*x*/ BaseClass(a),
633                                                member(b)
637 class CAbc :
638    public BaseClass1,
639    protected BaseClass2
641    int Test() { return FALSE; }
642    int Test1() { return TRUE; }
644    CAbc(int a, int b )  : 
645       BaseClass(a)
646    { 
647       switch(xxx)
648       {
649          case abc:
650             asdf();
651             break;
653          case 999:
654             baer();
655             break;
656       }
657    }
659 public: // <-- this was incoreectly indented before!!
660    void testfall();
661 protected:
662    void testfall();
665 class CAbc : public BaseClass1,
666              protected BaseClass2
670 static struct
672     int a;
673     int b;
674 } variable[COUNT] =
676     {
677         123,
678         456
679     },
680         {
681         123,
682         456
683     }
686 static struct
688     int a;
689     int b;
690 } variable[COUNT] =
692     { 123, 456 },
693         { 123, 456 }
696 void asdf()             /* ind_maxparen may cause trouble here */
698         if ((0
699                                 && 1
700                                 && 1
701                                 && 1
702                                 && 1
703                                 && 1
704                                 && 1
705                                 && 1
706                                 && 1
707                                 && 1
708                                 && 1
709                                 && 1
710                                 && 1
711                                 && 1
712                                 && 1
713                                 && 1
714                                 && 1
715                                 && 1
716                                 && 1
717                                 && 1
718                                 && 1
719                                 && 1
720                                 && 1
721                                 && 1
722                                 && 1
723                                 && 1)) break;
726 foo()
728         a = cond ? foo() : asdf
729                                            + asdf;
731         a = cond ?
732                 foo() : asdf
733                                 + asdf;
736 int  main(void)
738         if (a)
739                 if (b)
740                         2;
741                 else 3;
742         next_line_of_code();
745 barry()
747         Foo::Foo (int one,
748                         int two)
749                 : something(4)
750         {}
753 barry()
755         Foo::Foo (int one, int two)
756                 : something(4)
757         {}
760 Constructor::Constructor(int a,
761                 int b 
762                 )  : 
763         BaseClass(a,
764                         b,
765                         c),
766         mMember(b)
769        int main ()
770        {
771          if (lala)
772            do
773              ++(*lolo);
774            while (lili
775                   && lele);
776            lulu;
777        }
779 int main ()
781 switch (c)
783 case 'c': if (cond)
789 main()
791         (void) MyFancyFuasdfadsfnction(
792                         argument);
795 main()
797         char    foo[] = "/*";
798         /* as
799         df */
800                 hello
802 /* end of AUTO */
804 STARTTEST
805 :set tw=0 wm=60 columns=80 noai fo=croq
806 /serious/e
807 a about life, the universe, and the rest\e
808 ENDTEST
812 /* this is
813  * a real serious important big
814  * comment
815  */
816         /* insert " about life, the universe, and the rest" after "serious" */
819 STARTTEST
820 :set nocin
821 /comments
822 joabout life\e/happens
823 jothere\e/below
824 oline\e/this
825 Ohello\e
826 ENDTEST
829         /*
830          * Testing for comments, without 'cin' set
831          */
834 * what happens here?
837         /*
838            the end of the comment, try inserting a line below */
840                 /* how about
841                                 this one */
844 STARTTEST
845 :set cin
846 /vec2
848 ENDTEST
851     var = this + that + vec[0] * vec[0]
852                                       + vec[1] * vec[1]
853                                           + vec2[2] * vec[2];
856 STARTTEST
857 :set cin
858 :set cino=}4
859 /testing1
860 k2==/testing2
861 k2==
862 ENDTEST
865                 asdf asdflkajds f;
866         if (tes & ting) {
867                 asdf asdf asdf ;
868                 asdfa sdf asdf;
869                 }
870         testing1;
871         if (tes & ting)
872         {
873                 asdf asdf asdf ;
874                 asdfa sdf asdf;
875                 }
876         testing2;
879 STARTTEST
880 :set cin
881 :set cino=(0,)20
882 /main
884 ENDTEST
886 main ( int first_par, /*
887                        * Comment for
888                        * first par
889                        */
890           int second_par /*
891                        * Comment for
892                        * second par
893                        */
894      )
896         func( first_par, /*
897                       * Comment for
898                       * first par
899                       */
900     second_par /*
901                       * Comment for
902                       * second par
903                       */
904         );
908 STARTTEST
909 :set cin
910 :set cino=
911 ]]=][
912 ENDTEST
915         do
916         {
917                 if ()
918                 {
919                         if ()
920                                 asdf;
921                         else
922                                 asdf;
923                 }
924         } while ();
925                         cmd;            /* this should go under the } */
928 STARTTEST
929 ]]=][
930 ENDTEST
932 void f()
934     if ( k() ) {
935         l();
937     } else { /* Start (two words) end */
938         m();
939     }
941     n();
944 STARTTEST
945 :set cino={s,e-s
946 ]]=][
947 ENDTEST
949 void f()
951     if ( k() )
952         {
953         l();
954     } else { /* Start (two words) end */
955         m();
956     }
957                 n();    /* should be under the if () */
960 STARTTEST
961 :set cino={s,fs
962 ]]=/ foo
963 ENDTEST
965 void bar(void)
967         static array[2][2] =
968         {
969                 { 1, 2 },
970                 { 3, 4 },
971         }
973         while (a)
974         {
975                 foo(&a);
976         }
978         {
979                 int a;
980                 {
981                         a = a + 1;
982                 }
983         }
984         b = a;
985         }
987 void func(void)
988         {
989         a = 1;
990         {
991                 b = 2;
992         }
993         c = 3;
994         d = 4;
995         }
996 /* foo */
998 STARTTEST
999 :set cino=
1000 /while
1001 ohere\e
1002 ENDTEST
1006   do {
1007     a = a +
1008       a;
1009   } while ( a );                /* add text under this line */
1010     if ( a )
1011       a;
1014 STARTTEST
1015 :set cino= com=
1016 /comment
1017 olabel2: b();\rlabel3 /* post */:\r/* pre */ label4:\rf(/*com*/);\rif (/*com*/)\rcmd();\e
1018 ENDTEST
1022 label1:
1023             /* hmm */
1024             // comment
1027 STARTTEST
1028 :set comments& comments^=s:/*,m:**,ex:*/
1029 /simple
1031 ENDTEST
1034   * A simple comment
1035    */
1038   ** A different comment
1039    */
1041 STARTTEST
1042 :set cino=c0
1043 :set comments& comments-=s1:/* comments^=s0:/*
1044 2kdd]]=][
1045 ENDTEST
1047 void f()
1050         /*********
1051   A comment.
1052 *********/
1055 STARTTEST
1056 :set cino=c0,C1
1057 :set comments& comments-=s1:/* comments^=s0:/*
1058 2kdd]]=][
1059 ENDTEST
1061 void f()
1064         /*********
1065   A comment.
1066 *********/
1069 STARTTEST
1070 :set cino=
1071 ]]=][
1072 ENDTEST
1074 void f()
1076         c = c1 &&
1077         (
1078         c2 ||
1079         c3
1080         ) && c4;
1083 STARTTEST
1084 :set cino=(s
1085 2kdd]]=][
1086 ENDTEST
1088 void f()
1090         c = c1 &&
1091         (
1092         c2 ||
1093         c3
1094         ) && c4;
1097 STARTTEST
1098 :set cino=(s,U1  
1099 2kdd]]=][
1100 ENDTEST
1102 void f()
1104         c = c1 &&
1105         (
1106         c2 ||
1107         c3
1108         ) && c4;
1111 STARTTEST
1112 :set cino=(0
1113 2kdd]]=][
1114 ENDTEST
1116 void f()
1118         if (   c1
1119         && (   c2
1120         || c3))
1121         foo;
1124 STARTTEST
1125 :set cino=(0,w1  
1126 2kdd]]=][
1127 ENDTEST
1129 void f()
1131         if (   c1
1132         && (   c2
1133         || c3))
1134         foo;
1137 STARTTEST
1138 :set cino=(s
1139 2kdd]]=][
1140 ENDTEST
1142 void f()
1144         c = c1 && (
1145         c2 ||
1146         c3
1147         ) && c4;
1148         if (
1149         c1 && c2
1150         )
1151         foo;
1154 STARTTEST
1155 :set cino=(s,m1  
1156 2kdd]]=][
1157 ENDTEST
1159 void f()
1161         c = c1 && (
1162         c2 ||
1163         c3
1164         ) && c4;
1165         if (
1166         c1 && c2
1167         )
1168         foo;
1171 STARTTEST
1172 :set cino=b1
1173 2kdd]]=][
1174 ENDTEST
1176 void f()
1178         switch (x)
1179         {
1180                 case 1:
1181                         a = b;
1182                         break;
1183                 default:
1184                         a = 0;
1185                         break;
1186         }
1189 STARTTEST
1190 :set cino=(0,W5
1191 2kdd]]=][
1192 ENDTEST
1194 void f()
1196         invokeme(
1197         argu,
1198         ment);
1199         invokeme(
1200         argu,
1201         ment
1202         );
1203         invokeme(argu,
1204         ment
1205         );
1208 STARTTEST
1209 :set cino=/6
1210 2kdd]]=][
1211 ENDTEST
1213 void f()
1215         statement;
1216                 // comment 1
1217         // comment 2
1220 STARTTEST
1221 :set cino=
1222 2kdd]]/comment 1/+1
1224 ENDTEST
1226 void f()
1228         statement;
1229            // comment 1
1230         // comment 2
1233 STARTTEST
1234 :set cino=g0
1235 2kdd]]=][
1236 ENDTEST
1238 class CAbc
1240    int Test() { return FALSE; }
1242 public: // comment
1243    void testfall();
1244 protected:
1245    void testfall();
1248 STARTTEST
1249 :set cino=+20
1250 2kdd]]=][
1251 ENDTEST
1253         void
1254 foo()
1256         if (a)
1257         {
1258         } else
1259                 asdf;
1262 STARTTEST
1263 :set cino=(0,W2s
1264 2kdd]]=][
1265 ENDTEST
1268    averylongfunctionnamelongfunctionnameaverylongfunctionname()->asd(
1269          asdasdf,
1270          func(asdf,
1271               asdfadsf),
1272          asdfasdf
1273          );
1275    /* those are ugly, but consequent */
1277    func()->asd(asdasdf,
1278                averylongfunctionname(
1279                      abc,
1280                      dec)->averylongfunctionname(
1281                            asdfadsf,
1282                            asdfasdf,
1283                            asdfasdf,
1284                            ),
1285                func(asdfadf,
1286                     asdfasdf
1287                    ),
1288                asdasdf
1289               );
1291    averylongfunctionnameaverylongfunctionnameavery()->asd(fasdf(
1292                abc,
1293                dec)->asdfasdfasdf(
1294                      asdfadsf,
1295                      asdfasdf,
1296                      asdfasdf,
1297                      ),
1298          func(asdfadf,
1299               asdfasdf),
1300          asdasdf
1301          );
1304 STARTTEST
1305 :set cino=M1
1306 2kdd]]=][
1307 ENDTEST
1309 int main ()
1311         if (cond1 &&
1312                         cond2
1313                         )
1314                 foo;
1317 STARTTEST
1318 :g/^STARTTEST/.,/^ENDTEST/d
1319 :1;/start of AUTO/,$wq! test.out
1320 ENDTEST