blob: c65a0dab33844a95f271a4ac855710b15f0f9ee1 [file] [log] [blame]
Bram Moolenaar6b643942017-03-05 19:44:06 +01001" Test for cinoptions and cindent
Bram Moolenaar6b643942017-03-05 19:44:06 +01002
3func Test_cino_hash()
4 " Test that curbuf->b_ind_hash_comment is correctly reset
5 new
6 setlocal cindent cinoptions=#1
7 setlocal cinoptions=
8 call setline(1, ["#include <iostream>"])
9 call cursor(1, 1)
10 norm! o#include
11 "call feedkeys("o#include\<esc>", 't')
12 call assert_equal(["#include <iostream>", "#include"], getline(1,2))
13 bwipe!
14endfunc
Bram Moolenaar7720ba82017-03-08 22:19:26 +010015
16func Test_cino_extern_c()
17 " Test for cino-E
18
Bram Moolenaarc79745a2019-05-20 22:12:34 +020019 let without_ind =<< trim [CODE]
Bram Moolenaare7eb9272019-06-24 00:58:07 +020020 #ifdef __cplusplus
21 extern "C" {
22 #endif
23 int func_a(void);
24 #ifdef __cplusplus
25 }
26 #endif
Bram Moolenaarc79745a2019-05-20 22:12:34 +020027 [CODE]
Bram Moolenaar7720ba82017-03-08 22:19:26 +010028
Bram Moolenaarc79745a2019-05-20 22:12:34 +020029 let with_ind =<< trim [CODE]
Bram Moolenaare7eb9272019-06-24 00:58:07 +020030 #ifdef __cplusplus
31 extern "C" {
32 #endif
33 int func_a(void);
34 #ifdef __cplusplus
35 }
36 #endif
Bram Moolenaarc79745a2019-05-20 22:12:34 +020037 [CODE]
Bram Moolenaar7720ba82017-03-08 22:19:26 +010038 new
39 setlocal cindent cinoptions=E0
40 call setline(1, without_ind)
41 call feedkeys("gg=G", 'tx')
42 call assert_equal(with_ind, getline(1, '$'))
43
44 setlocal cinoptions=E-s
45 call setline(1, with_ind)
46 call feedkeys("gg=G", 'tx')
47 call assert_equal(without_ind, getline(1, '$'))
48
49 setlocal cinoptions=Es
50 let tests = [
51 \ ['recognized', ['extern "C" {'], "\t\t;"],
52 \ ['recognized', ['extern "C++" {'], "\t\t;"],
53 \ ['recognized', ['extern /* com */ "C"{'], "\t\t;"],
54 \ ['recognized', ['extern"C"{'], "\t\t;"],
55 \ ['recognized', ['extern "C"', '{'], "\t\t;"],
56 \ ['not recognized', ['extern {'], "\t;"],
57 \ ['not recognized', ['extern /*"C"*/{'], "\t;"],
58 \ ['not recognized', ['extern "C" //{'], ";"],
59 \ ['not recognized', ['extern "C" /*{*/'], ";"],
60 \ ]
61
62 for pair in tests
63 let lines = pair[1]
64 call setline(1, lines)
65 call feedkeys(len(lines) . "Go;", 'tx')
66 call assert_equal(pair[2], getline(len(lines) + 1), 'Failed for "' . string(lines) . '"')
67 endfor
68
Bram Moolenaar7720ba82017-03-08 22:19:26 +010069 bwipe!
70endfunc
71
Bram Moolenaare2e69e42017-09-02 20:30:35 +020072func Test_cindent_rawstring()
Bram Moolenaardde81312017-08-26 17:49:01 +020073 new
74 setl cindent
75 call feedkeys("i" .
76 \ "int main() {\<CR>" .
77 \ "R\"(\<CR>" .
78 \ ")\";\<CR>" .
79 \ "statement;\<Esc>", "x")
80 call assert_equal("\tstatement;", getline(line('.')))
81 bw!
Bram Moolenaare2e69e42017-09-02 20:30:35 +020082endfunc
83
84func Test_cindent_expr()
85 new
86 func! MyIndentFunction()
87 return v:lnum == 1 ? shiftwidth() : 0
88 endfunc
89 setl expandtab sw=8 indentkeys+=; indentexpr=MyIndentFunction()
Bram Moolenaarc79745a2019-05-20 22:12:34 +020090 let testinput =<< trim [CODE]
Bram Moolenaare7eb9272019-06-24 00:58:07 +020091 var_a = something()
92 b = something()
Bram Moolenaarc79745a2019-05-20 22:12:34 +020093 [CODE]
94 call setline(1, testinput)
Bram Moolenaare2e69e42017-09-02 20:30:35 +020095 call cursor(1, 1)
96 call feedkeys("^\<c-v>j$A;\<esc>", 'tnix')
Bram Moolenaare7eb9272019-06-24 00:58:07 +020097 let expected =<< [CODE]
98 var_a = something();
99b = something();
100[CODE]
Bram Moolenaarc79745a2019-05-20 22:12:34 +0200101 call assert_equal(expected, getline(1, '$'))
Bram Moolenaare2e69e42017-09-02 20:30:35 +0200102
103 %d
Bram Moolenaare7eb9272019-06-24 00:58:07 +0200104 let testinput =<< [CODE]
105 var_a = something()
106 b = something()
107[CODE]
Bram Moolenaarc79745a2019-05-20 22:12:34 +0200108 call setline(1, testinput)
Bram Moolenaare2e69e42017-09-02 20:30:35 +0200109 call cursor(1, 1)
110 call feedkeys("^\<c-v>j$A;\<esc>", 'tnix')
Bram Moolenaare7eb9272019-06-24 00:58:07 +0200111 let expected =<< [CODE]
112 var_a = something();
113 b = something()
114[CODE]
Bram Moolenaarc79745a2019-05-20 22:12:34 +0200115 call assert_equal(expected, getline(1, '$'))
Bram Moolenaare2e69e42017-09-02 20:30:35 +0200116 bw!
117endfunc
118
Bram Moolenaar17aca702019-05-16 22:24:55 +0200119func Test_cindent_func()
120 new
121 setlocal cindent
122 call setline(1, ['int main(void)', '{', 'return 0;', '}'])
Bram Moolenaar1a3a8912019-08-23 22:31:37 +0200123 call assert_equal(-1, cindent(0))
124 call assert_equal(&sw, 3->cindent())
125 call assert_equal(-1, cindent(line('$')+1))
Bram Moolenaar17aca702019-05-16 22:24:55 +0200126 bwipe!
127endfunc
128
Bram Moolenaar1ab74a52019-05-31 20:02:53 +0200129func Test_cindent_1()
130 new
131 setl cindent ts=4 sw=4
132 setl cino& sts&
133
134 let code =<< trim [CODE]
135 /* start of AUTO matically checked vim: set ts=4 : */
136 {
137 if (test)
138 cmd1;
139 cmd2;
140 }
141
142 {
143 if (test)
144 cmd1;
145 else
146 cmd2;
147 }
148
149 {
150 if (test)
151 {
152 cmd1;
153 cmd2;
154 }
155 }
156
157 {
158 if (test)
159 {
160 cmd1;
161 else
162 }
163 }
164
165 {
166 while (this)
167 if (test)
168 cmd1;
169 cmd2;
170 }
171
172 {
173 while (this)
174 if (test)
175 cmd1;
176 else
177 cmd2;
178 }
179
180 {
181 if (test)
182 {
183 cmd;
184 }
185
186 if (test)
187 cmd;
188 }
189
190 {
191 if (test) {
192 cmd;
193 }
194
195 if (test) cmd;
196 }
197
198 {
199 cmd1;
200 for (blah)
201 while (this)
202 if (test)
203 cmd2;
204 cmd3;
205 }
206
207 {
208 cmd1;
209 for (blah)
210 while (this)
211 if (test)
212 cmd2;
213 cmd3;
214
215 if (test)
216 {
217 cmd1;
218 cmd2;
219 cmd3;
220 }
221 }
222
223
224 /* Test for 'cindent' do/while mixed with if/else: */
225
226 {
227 do
228 if (asdf)
229 asdfasd;
230 while (cond);
231
232 do
233 if (asdf)
234 while (asdf)
235 asdf;
236 while (asdf);
237 }
238
239 /* Test for 'cindent' with two ) on a continuation line */
240 {
241 if (asdfasdf;asldkfj asdlkfj as;ldkfj sal;d
242 aal;sdkjf ( ;asldfkja;sldfk
243 al;sdjfka ;slkdf ) sa;ldkjfsa dlk;)
244 line up here;
245 }
246
247
248 /* C++ tests: */
249
250 // foo() these three lines should remain in column 0
251 // {
252 // }
253
254 /* Test for continuation and unterminated lines: */
255 {
256 i = 99 + 14325 +
257 21345 +
258 21345 +
259 21345 + ( 21345 +
260 21345) +
261 2345 +
262 1234;
263 c = 1;
264 }
265
266 /*
267 testje for indent with empty line
268
269 here */
270
271 {
272 if (testing &&
273 not a joke ||
274 line up here)
275 hay;
276 if (testing &&
277 (not a joke || testing
278 )line up here)
279 hay;
280 if (testing &&
281 (not a joke || testing
282 line up here))
283 hay;
284 }
285
286
287 {
288 switch (c)
289 {
290 case xx:
291 do
292 if (asdf)
293 do
294 asdfasdf;
295 while (asdf);
296 else
297 asdfasdf;
298 while (cond);
299 case yy:
300 case xx:
301 case zz:
302 testing;
303 }
304 }
305
306 {
307 if (cond) {
308 foo;
309 }
310 else
311 {
312 bar;
313 }
314 }
315
316 {
317 if (alskdfj ;alsdkfjal;skdjf (;sadlkfsa ;dlkf j;alksdfj ;alskdjf
318 alsdkfj (asldk;fj
319 awith cino=(0 ;lf this one goes to below the paren with ==
320 ;laksjfd ;lsakdjf ;alskdf asd)
321 asdfasdf;)))
322 asdfasdf;
323 }
324
325 int
326 func(a, b)
327 int a;
328 int c;
329 {
330 if (c1 && (c2 ||
331 c3))
332 foo;
333 if (c1 &&
334 (c2 || c3)
335 )
336 }
337
338 {
339 while (asd)
340 {
341 if (asdf)
342 if (test)
343 if (that)
344 {
345 if (asdf)
346 do
347 cdasd;
348 while (as
349 df);
350 }
351 else
352 if (asdf)
353 asdf;
354 else
355 asdf;
356 asdf;
357 }
358 }
359
360 {
361 s = "/*"; b = ';'
362 s = "/*"; b = ';';
363 a = b;
364 }
365
366 {
367 switch (a)
368 {
369 case a:
370 switch (t)
371 {
372 case 1:
373 cmd;
374 break;
375 case 2:
376 cmd;
377 break;
378 }
379 cmd;
380 break;
381 case b:
382 {
383 int i;
384 cmd;
385 }
386 break;
387 case c: {
388 int i;
389 cmd;
390 }
391 case d: if (cond &&
392 test) { /* this line doesn't work right */
393 int i;
394 cmd;
395 }
396 break;
397 }
398 }
399
400 {
401 if (!(vim_strchr(p_cpo, CPO_BUFOPTGLOB) != NULL && entering) &&
402 (bp_to->b_p_initialized ||
403 (!entering && vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
404 return;
405 label :
406 asdf = asdf ?
407 asdf : asdf;
408 asdf = asdf ?
409 asdf: asdf;
410 }
411
412 /* Special Comments : This function has the added complexity (compared */
413 /* : to addtolist) of having to check for a detail */
414 /* : texture and add that to the list first. */
415
416 char *(array[100]) = {
417 "testje",
418 "foo",
419 "bar",
420 }
421
422 enum soppie
423 {
424 yes = 0,
425 no,
426 maybe
427 };
428
429 typedef enum soppie
430 {
431 yes = 0,
432 no,
433 maybe
434 };
435
436 static enum
437 {
438 yes = 0,
439 no,
440 maybe
441 } soppie;
442
443 public static enum
444 {
445 yes = 0,
446 no,
447 maybe
448 } soppie;
449
450 static private enum
451 {
452 yes = 0,
453 no,
454 maybe
455 } soppie;
456
457 {
458 int a,
459 b;
460 }
461
462 {
463 struct Type
464 {
465 int i;
466 char *str;
467 } var[] =
468 {
469 0, "zero",
470 1, "one",
471 2, "two",
472 3, "three"
473 };
474
475 float matrix[3][3] =
476 {
477 {
478 0,
479 1,
480 2
481 },
482 {
483 3,
484 4,
485 5
486 },
487 {
488 6,
489 7,
490 8
491 }
492 };
493 }
494
495 {
496 /* blah ( blah */
497 /* where does this go? */
498
499 /* blah ( blah */
500 cmd;
501
502 func(arg1,
503 /* comment */
504 arg2);
505 a;
506 {
507 b;
508 {
509 c; /* Hey, NOW it indents?! */
510 }
511 }
512
513 {
514 func(arg1,
515 arg2,
516 arg3);
517 /* Hey, what am I doing here? Is this coz of the ","? */
518 }
519 }
520
521 main ()
522 {
523 if (cond)
524 {
525 a = b;
526 }
527 if (cond) {
528 a = c;
529 }
530 if (cond)
531 a = d;
532 return;
533 }
534
535 {
536 case 2: if (asdf &&
537 asdfasdf)
538 aasdf;
539 a = 9;
540 case 3: if (asdf)
541 aasdf;
542 a = 9;
543 case 4: x = 1;
544 y = 2;
545
546 label: if (asdf)
547 here;
548
549 label: if (asdf &&
550 asdfasdf)
551 {
552 }
553
554 label: if (asdf &&
555 asdfasdf) {
556 there;
557 }
558
559 label: if (asdf &&
560 asdfasdf)
561 there;
562 }
563
564 {
565 /*
566 hello with ":set comments= cino=c5"
567 */
568
569 /*
570 hello with ":set comments= cino="
571 */
572 }
573
574
575 {
576 if (a < b) {
577 a = a + 1;
578 } else
579 a = a + 2;
580
581 if (a)
582 do {
583 testing;
584 } while (asdfasdf);
585 a = b + 1;
586 asdfasdf
587 }
588
589 {
590 for ( int i = 0;
591 i < 10; i++ )
592 {
593 }
594 i = 0;
595 }
596
597 class bob
598 {
599 int foo() {return 1;}
600 int bar;
601 }
602
603 main()
604 {
605 while(1)
606 if (foo)
607 {
608 bar;
609 }
610 else {
611 asdf;
612 }
613 misplacedline;
614 }
615
616 {
617 if (clipboard.state == SELECT_DONE
618 && ((row == clipboard.start.lnum
619 && col >= clipboard.start.col)
620 || row > clipboard.start.lnum))
621 }
622
623 {
624 if (1) {i += 4;}
625 where_am_i;
626 return 0;
627 }
628
629 {
630 {
631 } // sdf(asdf
632 if (asdf)
633 asd;
634 }
635
636 {
637 label1:
638 label2:
639 }
640
641 {
642 int fooRet = foo(pBar1, false /*fKB*/,
643 true /*fPTB*/, 3 /*nT*/, false /*fDF*/);
644 f() {
645 for ( i = 0;
646 i < m;
647 /* c */ i++ ) {
648 a = b;
649 }
650 }
651 }
652
653 {
654 f1(/*comment*/);
655 f2();
656 }
657
658 {
659 do {
660 if (foo) {
661 } else
662 ;
663 } while (foo);
664 foo(); // was wrong
665 }
666
667 int x; // no extra indent because of the ;
668 void func()
669 {
670 }
671
672 char *tab[] = {"aaa",
673 "};", /* }; */ NULL}
674 int indented;
675 {}
676
677 char *a[] = {"aaa", "bbb",
678 "ccc", NULL};
679 // here
680
681 char *tab[] = {"aaa",
682 "xx", /* xx */}; /* asdf */
683 int not_indented;
684
685 {
686 do {
687 switch (bla)
688 {
689 case 1: if (foo)
690 bar;
691 }
692 } while (boo);
693 wrong;
694 }
695
696 int foo,
697 bar;
698 int foo;
699
700 #if defined(foo) \
701 && defined(bar)
702 char * xx = "asdf\
703 foo\
704 bor";
705 int x;
706
707 char *foo = "asdf\
708 asdf\
709 asdf",
710 *bar;
711
712 void f()
713 {
714 #if defined(foo) \
715 && defined(bar)
716 char *foo = "asdf\
717 asdf\
718 asdf",
719 *bar;
720 {
721 int i;
722 char *foo = "asdf\
723 asdf\
724 asdf",
725 *bar;
726 }
727 #endif
728 }
729 #endif
730
731 int y; // comment
732 // comment
733
734 // comment
735
736 {
737 Constructor(int a,
738 int b ) : BaseClass(a)
739 {
740 }
741 }
742
743 void foo()
744 {
745 char one,
746 two;
747 struct bla piet,
748 jan;
749 enum foo kees,
750 jannie;
751 static unsigned sdf,
752 krap;
753 unsigned int piet,
754 jan;
755 int
756 kees,
757 jan;
758 }
759
760 {
761 t(int f,
762 int d); // )
763 d();
764 }
765
766 Constructor::Constructor(int a,
767 int b
768 ) :
769 BaseClass(a,
770 b,
771 c),
772 mMember(b),
773 {
774 }
775
776 Constructor::Constructor(int a,
777 int b ) :
778 BaseClass(a)
779 {
780 }
781
782 Constructor::Constructor(int a,
783 int b ) /*x*/ : /*x*/ BaseClass(a),
784 member(b)
785 {
786 }
787
788 A::A(int a, int b)
789 : aa(a),
790 bb(b),
791 cc(c)
792 {
793 }
794
795 class CAbc :
796 public BaseClass1,
797 protected BaseClass2
798 {
799 int Test() { return FALSE; }
800 int Test1() { return TRUE; }
801
802 CAbc(int a, int b ) :
803 BaseClass(a)
804 {
805 switch(xxx)
806 {
807 case abc:
808 asdf();
809 break;
810
811 case 999:
812 baer();
813 break;
814 }
815 }
816
Bram Moolenaar4b96df52020-01-26 22:00:26 +0100817 public: // <-- this was incorrectly indented before!!
Bram Moolenaar1ab74a52019-05-31 20:02:53 +0200818 void testfall();
819 protected:
820 void testfall();
821 };
822
823 class CAbc : public BaseClass1,
824 protected BaseClass2
825 {
826 };
827
828 static struct
829 {
830 int a;
831 int b;
832 } variable[COUNT] =
833 {
834 {
835 123,
836 456
837 },
838 {
839 123,
840 456
841 }
842 };
843
844 static struct
845 {
846 int a;
847 int b;
848 } variable[COUNT] =
849 {
850 { 123, 456 },
851 { 123, 456 }
852 };
853
854 void asdf() /* ind_maxparen may cause trouble here */
855 {
856 if ((0
857 && 1
858 && 1
859 && 1
860 && 1
861 && 1
862 && 1
863 && 1
864 && 1
865 && 1
866 && 1
867 && 1
868 && 1
869 && 1
870 && 1
871 && 1
872 && 1
873 && 1
874 && 1
875 && 1
876 && 1
877 && 1
878 && 1
879 && 1
880 && 1
881 && 1)) break;
882 }
883
884 foo()
885 {
886 a = cond ? foo() : asdf
887 + asdf;
888
889 a = cond ?
890 foo() : asdf
891 + asdf;
892 }
893
894 int main(void)
895 {
896 if (a)
897 if (b)
898 2;
899 else 3;
900 next_line_of_code();
901 }
902
903 barry()
904 {
905 Foo::Foo (int one,
906 int two)
907 : something(4)
908 {}
909 }
910
911 barry()
912 {
913 Foo::Foo (int one, int two)
914 : something(4)
915 {}
916 }
917
918 Constructor::Constructor(int a,
919 int b
920 ) :
921 BaseClass(a,
922 b,
923 c),
924 mMember(b)
925 {
926 }
927 int main ()
928 {
929 if (lala)
930 do
931 ++(*lolo);
932 while (lili
933 && lele);
934 lulu;
935 }
936
937 int main ()
938 {
939 switch (c)
940 {
941 case 'c': if (cond)
942 {
943 }
944 }
945 }
946
947 main()
948 {
949 (void) MyFancyFuasdfadsfnction(
950 argument);
951 }
952
953 main()
954 {
955 char foo[] = "/*";
956 /* as
957 df */
958 hello
959 }
960
961 /* valid namespaces with normal indent */
962 namespace
963 {
964 {
965 111111111111;
966 }
967 }
968 namespace /* test */
969 {
970 11111111111111111;
971 }
972 namespace // test
973 {
974 111111111111111111;
975 }
976 namespace
977 {
978 111111111111111111;
979 }
980 namespace test
981 {
982 111111111111111111;
983 }
984 namespace{
985 111111111111111111;
986 }
987 namespace test{
988 111111111111111111;
989 }
990 namespace {
991 111111111111111111;
992 }
993 namespace test {
994 111111111111111111;
995 namespace test2 {
996 22222222222222222;
997 }
998 }
zeertzjqf2f0bdd2021-12-22 20:55:30 +0000999 inline namespace {
1000 111111111111111111;
1001 }
1002 inline /* test */ namespace {
1003 111111111111111111;
1004 }
1005 inline/* test */namespace {
1006 111111111111111111;
1007 }
Bram Moolenaar1ab74a52019-05-31 20:02:53 +02001008
1009 /* invalid namespaces use block indent */
1010 namespace test test2 {
1011 111111111111111111111;
1012 }
1013 namespace11111111111 {
1014 111111111111;
1015 }
1016 namespace() {
1017 1111111111111;
1018 }
1019 namespace()
1020 {
1021 111111111111111111;
1022 }
1023 namespace test test2
1024 {
1025 1111111111111111111;
1026 }
1027 namespace111111111
1028 {
1029 111111111111111111;
1030 }
zeertzjqf2f0bdd2021-12-22 20:55:30 +00001031 inlinenamespace {
1032 111111111111111111;
1033 }
Bram Moolenaar1ab74a52019-05-31 20:02:53 +02001034
1035 void getstring() {
1036 /* Raw strings */
1037 const char* s = R"(
1038 test {
1039 # comment
1040 field: 123
1041 }
1042 )";
1043 }
1044
1045 void getstring() {
1046 const char* s = R"foo(
1047 test {
1048 # comment
1049 field: 123
1050 }
1051 )foo";
1052 }
1053
1054 {
1055 int a[4] = {
1056 [0] = 0,
1057 [1] = 1,
1058 [2] = 2,
1059 [3] = 3,
1060 };
1061 }
1062
1063 {
1064 a = b[2]
1065 + 3;
1066 }
1067
1068 {
1069 if (1)
1070 /* aaaaa
1071 * bbbbb
1072 */
1073 a = 1;
1074 }
1075
1076 void func()
1077 {
1078 switch (foo)
1079 {
1080 case (bar):
1081 if (baz())
1082 quux();
1083 break;
1084 case (shmoo):
1085 if (!bar)
1086 {
1087 }
1088 case (foo1):
1089 switch (bar)
1090 {
1091 case baz:
1092 baz_f();
1093 break;
1094 }
1095 break;
1096 default:
1097 baz();
1098 baz();
1099 break;
1100 }
1101 }
1102
1103 /* end of AUTO */
1104 [CODE]
1105
1106 call append(0, code)
1107 normal gg
1108 call search('start of AUTO')
1109 exe "normal =/end of AUTO\<CR>"
1110
1111 let expected =<< trim [CODE]
1112 /* start of AUTO matically checked vim: set ts=4 : */
1113 {
1114 if (test)
1115 cmd1;
1116 cmd2;
1117 }
1118
1119 {
1120 if (test)
1121 cmd1;
1122 else
1123 cmd2;
1124 }
1125
1126 {
1127 if (test)
1128 {
1129 cmd1;
1130 cmd2;
1131 }
1132 }
1133
1134 {
1135 if (test)
1136 {
1137 cmd1;
1138 else
1139 }
1140 }
1141
1142 {
1143 while (this)
1144 if (test)
1145 cmd1;
1146 cmd2;
1147 }
1148
1149 {
1150 while (this)
1151 if (test)
1152 cmd1;
1153 else
1154 cmd2;
1155 }
1156
1157 {
1158 if (test)
1159 {
1160 cmd;
1161 }
1162
1163 if (test)
1164 cmd;
1165 }
1166
1167 {
1168 if (test) {
1169 cmd;
1170 }
1171
1172 if (test) cmd;
1173 }
1174
1175 {
1176 cmd1;
1177 for (blah)
1178 while (this)
1179 if (test)
1180 cmd2;
1181 cmd3;
1182 }
1183
1184 {
1185 cmd1;
1186 for (blah)
1187 while (this)
1188 if (test)
1189 cmd2;
1190 cmd3;
1191
1192 if (test)
1193 {
1194 cmd1;
1195 cmd2;
1196 cmd3;
1197 }
1198 }
1199
1200
1201 /* Test for 'cindent' do/while mixed with if/else: */
1202
1203 {
1204 do
1205 if (asdf)
1206 asdfasd;
1207 while (cond);
1208
1209 do
1210 if (asdf)
1211 while (asdf)
1212 asdf;
1213 while (asdf);
1214 }
1215
1216 /* Test for 'cindent' with two ) on a continuation line */
1217 {
1218 if (asdfasdf;asldkfj asdlkfj as;ldkfj sal;d
1219 aal;sdkjf ( ;asldfkja;sldfk
1220 al;sdjfka ;slkdf ) sa;ldkjfsa dlk;)
1221 line up here;
1222 }
1223
1224
1225 /* C++ tests: */
1226
1227 // foo() these three lines should remain in column 0
1228 // {
1229 // }
1230
1231 /* Test for continuation and unterminated lines: */
1232 {
1233 i = 99 + 14325 +
1234 21345 +
1235 21345 +
1236 21345 + ( 21345 +
1237 21345) +
1238 2345 +
1239 1234;
1240 c = 1;
1241 }
1242
1243 /*
1244 testje for indent with empty line
1245
1246 here */
1247
1248 {
1249 if (testing &&
1250 not a joke ||
1251 line up here)
1252 hay;
1253 if (testing &&
1254 (not a joke || testing
1255 )line up here)
1256 hay;
1257 if (testing &&
1258 (not a joke || testing
1259 line up here))
1260 hay;
1261 }
1262
1263
1264 {
1265 switch (c)
1266 {
1267 case xx:
1268 do
1269 if (asdf)
1270 do
1271 asdfasdf;
1272 while (asdf);
1273 else
1274 asdfasdf;
1275 while (cond);
1276 case yy:
1277 case xx:
1278 case zz:
1279 testing;
1280 }
1281 }
1282
1283 {
1284 if (cond) {
1285 foo;
1286 }
1287 else
1288 {
1289 bar;
1290 }
1291 }
1292
1293 {
1294 if (alskdfj ;alsdkfjal;skdjf (;sadlkfsa ;dlkf j;alksdfj ;alskdjf
1295 alsdkfj (asldk;fj
1296 awith cino=(0 ;lf this one goes to below the paren with ==
1297 ;laksjfd ;lsakdjf ;alskdf asd)
1298 asdfasdf;)))
1299 asdfasdf;
1300 }
1301
1302 int
1303 func(a, b)
1304 int a;
1305 int c;
1306 {
1307 if (c1 && (c2 ||
1308 c3))
1309 foo;
1310 if (c1 &&
1311 (c2 || c3)
1312 )
1313 }
1314
1315 {
1316 while (asd)
1317 {
1318 if (asdf)
1319 if (test)
1320 if (that)
1321 {
1322 if (asdf)
1323 do
1324 cdasd;
1325 while (as
1326 df);
1327 }
1328 else
1329 if (asdf)
1330 asdf;
1331 else
1332 asdf;
1333 asdf;
1334 }
1335 }
1336
1337 {
1338 s = "/*"; b = ';'
1339 s = "/*"; b = ';';
1340 a = b;
1341 }
1342
1343 {
1344 switch (a)
1345 {
1346 case a:
1347 switch (t)
1348 {
1349 case 1:
1350 cmd;
1351 break;
1352 case 2:
1353 cmd;
1354 break;
1355 }
1356 cmd;
1357 break;
1358 case b:
1359 {
1360 int i;
1361 cmd;
1362 }
1363 break;
1364 case c: {
1365 int i;
1366 cmd;
1367 }
1368 case d: if (cond &&
1369 test) { /* this line doesn't work right */
1370 int i;
1371 cmd;
1372 }
1373 break;
1374 }
1375 }
1376
1377 {
1378 if (!(vim_strchr(p_cpo, CPO_BUFOPTGLOB) != NULL && entering) &&
1379 (bp_to->b_p_initialized ||
1380 (!entering && vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
1381 return;
1382 label :
1383 asdf = asdf ?
1384 asdf : asdf;
1385 asdf = asdf ?
1386 asdf: asdf;
1387 }
1388
1389 /* Special Comments : This function has the added complexity (compared */
1390 /* : to addtolist) of having to check for a detail */
1391 /* : texture and add that to the list first. */
1392
1393 char *(array[100]) = {
1394 "testje",
1395 "foo",
1396 "bar",
1397 }
1398
1399 enum soppie
1400 {
1401 yes = 0,
1402 no,
1403 maybe
1404 };
1405
1406 typedef enum soppie
1407 {
1408 yes = 0,
1409 no,
1410 maybe
1411 };
1412
1413 static enum
1414 {
1415 yes = 0,
1416 no,
1417 maybe
1418 } soppie;
1419
1420 public static enum
1421 {
1422 yes = 0,
1423 no,
1424 maybe
1425 } soppie;
1426
1427 static private enum
1428 {
1429 yes = 0,
1430 no,
1431 maybe
1432 } soppie;
1433
1434 {
1435 int a,
1436 b;
1437 }
1438
1439 {
1440 struct Type
1441 {
1442 int i;
1443 char *str;
1444 } var[] =
1445 {
1446 0, "zero",
1447 1, "one",
1448 2, "two",
1449 3, "three"
1450 };
1451
1452 float matrix[3][3] =
1453 {
1454 {
1455 0,
1456 1,
1457 2
1458 },
1459 {
1460 3,
1461 4,
1462 5
1463 },
1464 {
1465 6,
1466 7,
1467 8
1468 }
1469 };
1470 }
1471
1472 {
1473 /* blah ( blah */
1474 /* where does this go? */
1475
1476 /* blah ( blah */
1477 cmd;
1478
1479 func(arg1,
1480 /* comment */
1481 arg2);
1482 a;
1483 {
1484 b;
1485 {
1486 c; /* Hey, NOW it indents?! */
1487 }
1488 }
1489
1490 {
1491 func(arg1,
1492 arg2,
1493 arg3);
1494 /* Hey, what am I doing here? Is this coz of the ","? */
1495 }
1496 }
1497
1498 main ()
1499 {
1500 if (cond)
1501 {
1502 a = b;
1503 }
1504 if (cond) {
1505 a = c;
1506 }
1507 if (cond)
1508 a = d;
1509 return;
1510 }
1511
1512 {
1513 case 2: if (asdf &&
1514 asdfasdf)
1515 aasdf;
1516 a = 9;
1517 case 3: if (asdf)
1518 aasdf;
1519 a = 9;
1520 case 4: x = 1;
1521 y = 2;
1522
1523 label: if (asdf)
1524 here;
1525
1526 label: if (asdf &&
1527 asdfasdf)
1528 {
1529 }
1530
1531 label: if (asdf &&
1532 asdfasdf) {
1533 there;
1534 }
1535
1536 label: if (asdf &&
1537 asdfasdf)
1538 there;
1539 }
1540
1541 {
1542 /*
1543 hello with ":set comments= cino=c5"
1544 */
1545
1546 /*
1547 hello with ":set comments= cino="
1548 */
1549 }
1550
1551
1552 {
1553 if (a < b) {
1554 a = a + 1;
1555 } else
1556 a = a + 2;
1557
1558 if (a)
1559 do {
1560 testing;
1561 } while (asdfasdf);
1562 a = b + 1;
1563 asdfasdf
1564 }
1565
1566 {
1567 for ( int i = 0;
1568 i < 10; i++ )
1569 {
1570 }
1571 i = 0;
1572 }
1573
1574 class bob
1575 {
1576 int foo() {return 1;}
1577 int bar;
1578 }
1579
1580 main()
1581 {
1582 while(1)
1583 if (foo)
1584 {
1585 bar;
1586 }
1587 else {
1588 asdf;
1589 }
1590 misplacedline;
1591 }
1592
1593 {
1594 if (clipboard.state == SELECT_DONE
1595 && ((row == clipboard.start.lnum
1596 && col >= clipboard.start.col)
1597 || row > clipboard.start.lnum))
1598 }
1599
1600 {
1601 if (1) {i += 4;}
1602 where_am_i;
1603 return 0;
1604 }
1605
1606 {
1607 {
1608 } // sdf(asdf
1609 if (asdf)
1610 asd;
1611 }
1612
1613 {
1614 label1:
1615 label2:
1616 }
1617
1618 {
1619 int fooRet = foo(pBar1, false /*fKB*/,
1620 true /*fPTB*/, 3 /*nT*/, false /*fDF*/);
1621 f() {
1622 for ( i = 0;
1623 i < m;
1624 /* c */ i++ ) {
1625 a = b;
1626 }
1627 }
1628 }
1629
1630 {
1631 f1(/*comment*/);
1632 f2();
1633 }
1634
1635 {
1636 do {
1637 if (foo) {
1638 } else
1639 ;
1640 } while (foo);
1641 foo(); // was wrong
1642 }
1643
1644 int x; // no extra indent because of the ;
1645 void func()
1646 {
1647 }
1648
1649 char *tab[] = {"aaa",
1650 "};", /* }; */ NULL}
1651 int indented;
1652 {}
1653
1654 char *a[] = {"aaa", "bbb",
1655 "ccc", NULL};
1656 // here
1657
1658 char *tab[] = {"aaa",
1659 "xx", /* xx */}; /* asdf */
1660 int not_indented;
1661
1662 {
1663 do {
1664 switch (bla)
1665 {
1666 case 1: if (foo)
1667 bar;
1668 }
1669 } while (boo);
1670 wrong;
1671 }
1672
1673 int foo,
1674 bar;
1675 int foo;
1676
1677 #if defined(foo) \
1678 && defined(bar)
1679 char * xx = "asdf\
1680 foo\
1681 bor";
1682 int x;
1683
1684 char *foo = "asdf\
1685 asdf\
1686 asdf",
1687 *bar;
1688
1689 void f()
1690 {
1691 #if defined(foo) \
1692 && defined(bar)
1693 char *foo = "asdf\
1694 asdf\
1695 asdf",
1696 *bar;
1697 {
1698 int i;
1699 char *foo = "asdf\
1700 asdf\
1701 asdf",
1702 *bar;
1703 }
1704 #endif
1705 }
1706 #endif
1707
1708 int y; // comment
Bram Moolenaar6e371ec2021-12-12 14:16:39 +00001709 // comment
Bram Moolenaar1ab74a52019-05-31 20:02:53 +02001710
Bram Moolenaar6e371ec2021-12-12 14:16:39 +00001711 // comment
Bram Moolenaar1ab74a52019-05-31 20:02:53 +02001712
1713 {
1714 Constructor(int a,
1715 int b ) : BaseClass(a)
1716 {
1717 }
1718 }
1719
1720 void foo()
1721 {
1722 char one,
1723 two;
1724 struct bla piet,
1725 jan;
1726 enum foo kees,
1727 jannie;
1728 static unsigned sdf,
1729 krap;
1730 unsigned int piet,
1731 jan;
1732 int
1733 kees,
1734 jan;
1735 }
1736
1737 {
1738 t(int f,
1739 int d); // )
1740 d();
1741 }
1742
1743 Constructor::Constructor(int a,
1744 int b
1745 ) :
1746 BaseClass(a,
1747 b,
1748 c),
1749 mMember(b),
1750 {
1751 }
1752
1753 Constructor::Constructor(int a,
1754 int b ) :
1755 BaseClass(a)
1756 {
1757 }
1758
1759 Constructor::Constructor(int a,
1760 int b ) /*x*/ : /*x*/ BaseClass(a),
1761 member(b)
1762 {
1763 }
1764
1765 A::A(int a, int b)
1766 : aa(a),
1767 bb(b),
1768 cc(c)
1769 {
1770 }
1771
1772 class CAbc :
1773 public BaseClass1,
1774 protected BaseClass2
1775 {
1776 int Test() { return FALSE; }
1777 int Test1() { return TRUE; }
1778
1779 CAbc(int a, int b ) :
1780 BaseClass(a)
1781 {
1782 switch(xxx)
1783 {
1784 case abc:
1785 asdf();
1786 break;
1787
1788 case 999:
1789 baer();
1790 break;
1791 }
1792 }
1793
Bram Moolenaar4b96df52020-01-26 22:00:26 +01001794 public: // <-- this was incorrectly indented before!!
Bram Moolenaar1ab74a52019-05-31 20:02:53 +02001795 void testfall();
1796 protected:
1797 void testfall();
1798 };
1799
1800 class CAbc : public BaseClass1,
1801 protected BaseClass2
1802 {
1803 };
1804
1805 static struct
1806 {
1807 int a;
1808 int b;
1809 } variable[COUNT] =
1810 {
1811 {
1812 123,
1813 456
1814 },
1815 {
1816 123,
1817 456
1818 }
1819 };
1820
1821 static struct
1822 {
1823 int a;
1824 int b;
1825 } variable[COUNT] =
1826 {
1827 { 123, 456 },
1828 { 123, 456 }
1829 };
1830
1831 void asdf() /* ind_maxparen may cause trouble here */
1832 {
1833 if ((0
1834 && 1
1835 && 1
1836 && 1
1837 && 1
1838 && 1
1839 && 1
1840 && 1
1841 && 1
1842 && 1
1843 && 1
1844 && 1
1845 && 1
1846 && 1
1847 && 1
1848 && 1
1849 && 1
1850 && 1
1851 && 1
1852 && 1
1853 && 1
1854 && 1
1855 && 1
1856 && 1
1857 && 1
1858 && 1)) break;
1859 }
1860
1861 foo()
1862 {
1863 a = cond ? foo() : asdf
1864 + asdf;
1865
1866 a = cond ?
1867 foo() : asdf
1868 + asdf;
1869 }
1870
1871 int main(void)
1872 {
1873 if (a)
1874 if (b)
1875 2;
1876 else 3;
1877 next_line_of_code();
1878 }
1879
1880 barry()
1881 {
1882 Foo::Foo (int one,
1883 int two)
1884 : something(4)
1885 {}
1886 }
1887
1888 barry()
1889 {
1890 Foo::Foo (int one, int two)
1891 : something(4)
1892 {}
1893 }
1894
1895 Constructor::Constructor(int a,
1896 int b
1897 ) :
1898 BaseClass(a,
1899 b,
1900 c),
1901 mMember(b)
1902 {
1903 }
1904 int main ()
1905 {
1906 if (lala)
1907 do
1908 ++(*lolo);
1909 while (lili
1910 && lele);
1911 lulu;
1912 }
1913
1914 int main ()
1915 {
1916 switch (c)
1917 {
1918 case 'c': if (cond)
1919 {
1920 }
1921 }
1922 }
1923
1924 main()
1925 {
1926 (void) MyFancyFuasdfadsfnction(
1927 argument);
1928 }
1929
1930 main()
1931 {
1932 char foo[] = "/*";
1933 /* as
1934 df */
1935 hello
1936 }
1937
1938 /* valid namespaces with normal indent */
1939 namespace
1940 {
1941 {
1942 111111111111;
1943 }
1944 }
1945 namespace /* test */
1946 {
1947 11111111111111111;
1948 }
1949 namespace // test
1950 {
1951 111111111111111111;
1952 }
1953 namespace
1954 {
1955 111111111111111111;
1956 }
1957 namespace test
1958 {
1959 111111111111111111;
1960 }
1961 namespace{
1962 111111111111111111;
1963 }
1964 namespace test{
1965 111111111111111111;
1966 }
1967 namespace {
1968 111111111111111111;
1969 }
1970 namespace test {
1971 111111111111111111;
1972 namespace test2 {
1973 22222222222222222;
1974 }
1975 }
zeertzjqf2f0bdd2021-12-22 20:55:30 +00001976 inline namespace {
1977 111111111111111111;
1978 }
1979 inline /* test */ namespace {
1980 111111111111111111;
1981 }
1982 inline/* test */namespace {
1983 111111111111111111;
1984 }
Bram Moolenaar1ab74a52019-05-31 20:02:53 +02001985
1986 /* invalid namespaces use block indent */
1987 namespace test test2 {
1988 111111111111111111111;
1989 }
1990 namespace11111111111 {
1991 111111111111;
1992 }
1993 namespace() {
1994 1111111111111;
1995 }
1996 namespace()
1997 {
1998 111111111111111111;
1999 }
2000 namespace test test2
2001 {
2002 1111111111111111111;
2003 }
2004 namespace111111111
2005 {
2006 111111111111111111;
2007 }
zeertzjqf2f0bdd2021-12-22 20:55:30 +00002008 inlinenamespace {
2009 111111111111111111;
2010 }
Bram Moolenaar1ab74a52019-05-31 20:02:53 +02002011
2012 void getstring() {
2013 /* Raw strings */
2014 const char* s = R"(
2015 test {
2016 # comment
2017 field: 123
2018 }
2019 )";
2020 }
2021
2022 void getstring() {
2023 const char* s = R"foo(
2024 test {
2025 # comment
2026 field: 123
2027 }
2028 )foo";
2029 }
2030
2031 {
2032 int a[4] = {
2033 [0] = 0,
2034 [1] = 1,
2035 [2] = 2,
2036 [3] = 3,
2037 };
2038 }
2039
2040 {
2041 a = b[2]
2042 + 3;
2043 }
2044
2045 {
2046 if (1)
2047 /* aaaaa
2048 * bbbbb
2049 */
2050 a = 1;
2051 }
2052
2053 void func()
2054 {
2055 switch (foo)
2056 {
2057 case (bar):
2058 if (baz())
2059 quux();
2060 break;
2061 case (shmoo):
2062 if (!bar)
2063 {
2064 }
2065 case (foo1):
2066 switch (bar)
2067 {
2068 case baz:
2069 baz_f();
2070 break;
2071 }
2072 break;
2073 default:
2074 baz();
2075 baz();
2076 break;
2077 }
2078 }
2079
2080 /* end of AUTO */
2081
2082 [CODE]
2083
2084 call assert_equal(expected, getline(1, '$'))
2085 enew! | close
2086endfunc
2087
2088func Test_cindent_2()
2089 new
2090 setl cindent ts=4 sw=4
2091 setl tw=0 noai fo=croq
2092 let &wm = &columns - 20
2093
2094 let code =<< trim [CODE]
Bram Moolenaare7eb9272019-06-24 00:58:07 +02002095 {
2096
2097 /* this is
2098 * a real serious important big
2099 * comment
2100 */
2101 /* insert " about life, the universe, and the rest" after "serious" */
2102 }
Bram Moolenaar1ab74a52019-05-31 20:02:53 +02002103 [CODE]
2104
2105 call append(0, code)
2106 normal gg
2107 call search('serious', 'e')
2108 normal a about life, the universe, and the rest
2109
2110 let expected =<< trim [CODE]
2111 {
2112
2113 /* this is
2114 * a real serious
2115 * about life, the
2116 * universe, and the
2117 * rest important big
2118 * comment
2119 */
2120 /* insert " about life, the universe, and the rest" after "serious" */
2121 }
2122
2123 [CODE]
2124
2125 call assert_equal(expected, getline(1, '$'))
2126 set wm&
2127 enew! | close
2128endfunc
2129
2130func Test_cindent_3()
2131 new
2132 setl nocindent ts=4 sw=4
2133
2134 let code =<< trim [CODE]
2135 {
2136 /*
2137 * Testing for comments, without 'cin' set
2138 */
2139
2140 /*
2141 * what happens here?
2142 */
2143
2144 /*
2145 the end of the comment, try inserting a line below */
2146
2147 /* how about
2148 this one */
2149 }
2150 [CODE]
2151
2152 call append(0, code)
2153 normal gg
2154 call search('comments')
2155 normal joabout life
2156 call search('happens')
2157 normal jothere
2158 call search('below')
2159 normal oline
2160 call search('this')
2161 normal Ohello
2162
2163 let expected =<< trim [CODE]
2164 {
2165 /*
2166 * Testing for comments, without 'cin' set
2167 */
2168 about life
2169
2170 /*
2171 * what happens here?
2172 */
2173 there
2174
2175 /*
2176 the end of the comment, try inserting a line below */
2177 line
2178
2179 /* how about
2180 hello
2181 this one */
2182 }
2183
2184 [CODE]
2185
2186 call assert_equal(expected, getline(1, '$'))
2187 enew! | close
2188endfunc
2189
2190func Test_cindent_4()
2191 new
2192 setl cindent ts=4 sw=4
2193
2194 let code =<< trim [CODE]
2195 {
2196 var = this + that + vec[0] * vec[0]
2197 + vec[1] * vec[1]
2198 + vec2[2] * vec[2];
2199 }
2200 [CODE]
2201
2202 call append(0, code)
2203 normal gg
2204 call search('vec2')
2205 normal ==
2206
2207 let expected =<< trim [CODE]
2208 {
2209 var = this + that + vec[0] * vec[0]
2210 + vec[1] * vec[1]
2211 + vec2[2] * vec[2];
2212 }
2213
2214 [CODE]
2215
2216 call assert_equal(expected, getline(1, '$'))
2217 enew! | close
2218endfunc
2219
2220func Test_cindent_5()
2221 new
2222 setl cindent ts=4 sw=4
2223 setl cino=}4
2224
2225 let code =<< trim [CODE]
2226 {
2227 asdf asdflkajds f;
2228 if (tes & ting) {
2229 asdf asdf asdf ;
2230 asdfa sdf asdf;
2231 }
2232 testing1;
2233 if (tes & ting)
2234 {
2235 asdf asdf asdf ;
2236 asdfa sdf asdf;
2237 }
2238 testing2;
2239 }
2240 [CODE]
2241
2242 call append(0, code)
2243 normal gg
2244 call search('testing1')
2245 exe "normal k2==/testing2\<CR>"
2246 normal k2==
2247
2248 let expected =<< trim [CODE]
2249 {
2250 asdf asdflkajds f;
2251 if (tes & ting) {
2252 asdf asdf asdf ;
2253 asdfa sdf asdf;
2254 }
2255 testing1;
2256 if (tes & ting)
2257 {
2258 asdf asdf asdf ;
2259 asdfa sdf asdf;
2260 }
2261 testing2;
2262 }
2263
2264 [CODE]
2265
2266 call assert_equal(expected, getline(1, '$'))
2267 enew! | close
2268endfunc
2269
2270func Test_cindent_6()
2271 new
2272 setl cindent ts=4 sw=4
2273 setl cino=(0,)20
2274
2275 let code =<< trim [CODE]
2276 main ( int first_par, /*
2277 * Comment for
2278 * first par
2279 */
2280 int second_par /*
2281 * Comment for
2282 * second par
2283 */
2284 )
2285 {
2286 func( first_par, /*
2287 * Comment for
2288 * first par
2289 */
2290 second_par /*
2291 * Comment for
2292 * second par
2293 */
2294 );
2295
2296 }
2297 [CODE]
2298
2299 call append(0, code)
2300 normal gg
2301 call search('main')
2302 normal =][
2303
2304 let expected =<< trim [CODE]
2305 main ( int first_par, /*
2306 * Comment for
2307 * first par
2308 */
2309 int second_par /*
2310 * Comment for
2311 * second par
2312 */
2313 )
2314 {
2315 func( first_par, /*
2316 * Comment for
2317 * first par
2318 */
2319 second_par /*
2320 * Comment for
2321 * second par
2322 */
2323 );
2324
2325 }
2326
2327 [CODE]
2328
2329 call assert_equal(expected, getline(1, '$'))
2330 enew! | close
2331endfunc
2332
2333func Test_cindent_7()
2334 new
2335 setl cindent ts=4 sw=4
2336 setl cino=es,n0s
2337
2338 let code =<< trim [CODE]
2339 main(void)
2340 {
2341 /* Make sure that cino=X0s is not parsed like cino=Xs. */
2342 if (cond)
2343 foo();
2344 else
2345 {
2346 bar();
2347 }
2348 }
2349 [CODE]
2350
2351 call append(0, code)
2352 normal gg
2353 call search('main')
2354 normal =][
2355
2356 let expected =<< trim [CODE]
2357 main(void)
2358 {
2359 /* Make sure that cino=X0s is not parsed like cino=Xs. */
2360 if (cond)
2361 foo();
2362 else
2363 {
2364 bar();
2365 }
2366 }
2367
2368 [CODE]
2369
2370 call assert_equal(expected, getline(1, '$'))
2371 enew! | close
2372endfunc
2373
2374func Test_cindent_8()
2375 new
2376 setl cindent ts=4 sw=4
2377 setl cino=
2378
2379 let code =<< trim [CODE]
2380
2381 {
2382 do
2383 {
2384 if ()
2385 {
2386 if ()
2387 asdf;
2388 else
2389 asdf;
2390 }
2391 } while ();
2392 cmd; /* this should go under the } */
2393 }
2394 [CODE]
2395
2396 call append(0, code)
2397 normal gg
2398 normal ]]=][
2399
2400 let expected =<< trim [CODE]
2401
2402 {
2403 do
2404 {
2405 if ()
2406 {
2407 if ()
2408 asdf;
2409 else
2410 asdf;
2411 }
2412 } while ();
2413 cmd; /* this should go under the } */
2414 }
2415
2416 [CODE]
2417
2418 call assert_equal(expected, getline(1, '$'))
2419 enew! | close
2420endfunc
2421
2422func Test_cindent_9()
2423 new
2424 setl cindent ts=4 sw=4
2425
2426 let code =<< trim [CODE]
2427
2428 void f()
2429 {
2430 if ( k() ) {
2431 l();
2432
2433 } else { /* Start (two words) end */
2434 m();
2435 }
2436
2437 n();
2438 }
2439 [CODE]
2440
2441 call append(0, code)
2442 normal gg
2443 normal ]]=][
2444
2445 let expected =<< trim [CODE]
2446
2447 void f()
2448 {
2449 if ( k() ) {
2450 l();
2451
2452 } else { /* Start (two words) end */
2453 m();
2454 }
2455
2456 n();
2457 }
2458
2459 [CODE]
2460
2461 call assert_equal(expected, getline(1, '$'))
2462 enew! | close
2463endfunc
2464
2465func Test_cindent_10()
2466 new
2467 setl cindent ts=4 sw=4
2468 setl cino={s,e-s
2469
2470 let code =<< trim [CODE]
2471
2472 void f()
2473 {
2474 if ( k() )
2475 {
2476 l();
2477 } else { /* Start (two words) end */
2478 m();
2479 }
2480 n(); /* should be under the if () */
2481 }
2482 [CODE]
2483
2484 call append(0, code)
2485 normal gg
2486 normal ]]=][
2487
2488 let expected =<< trim [CODE]
2489
2490 void f()
2491 {
2492 if ( k() )
2493 {
2494 l();
2495 } else { /* Start (two words) end */
2496 m();
2497 }
2498 n(); /* should be under the if () */
2499 }
2500
2501 [CODE]
2502
2503 call assert_equal(expected, getline(1, '$'))
2504 enew! | close
2505endfunc
2506
2507func Test_cindent_11()
2508 new
2509 setl cindent ts=4 sw=4
2510 setl cino={s,fs
2511
2512 let code =<< trim [CODE]
2513 void bar(void)
2514 {
2515 static array[2][2] =
2516 {
2517 { 1, 2 },
2518 { 3, 4 },
2519 }
2520
2521 while (a)
2522 {
2523 foo(&a);
2524 }
2525
2526 {
2527 int a;
2528 {
2529 a = a + 1;
2530 }
2531 }
2532 b = a;
2533 }
2534
2535 void func(void)
2536 {
2537 a = 1;
2538 {
2539 b = 2;
2540 }
2541 c = 3;
2542 d = 4;
2543 }
2544 /* foo */
2545 [CODE]
2546
2547 call append(0, code)
2548 normal gg
2549 exe "normal ]]=/ foo\<CR>"
2550
2551 let expected =<< trim [CODE]
2552 void bar(void)
2553 {
2554 static array[2][2] =
2555 {
2556 { 1, 2 },
2557 { 3, 4 },
2558 }
2559
2560 while (a)
2561 {
2562 foo(&a);
2563 }
2564
2565 {
2566 int a;
2567 {
2568 a = a + 1;
2569 }
2570 }
2571 b = a;
2572 }
2573
2574 void func(void)
2575 {
2576 a = 1;
2577 {
2578 b = 2;
2579 }
2580 c = 3;
2581 d = 4;
2582 }
2583 /* foo */
2584
2585 [CODE]
2586
2587 call assert_equal(expected, getline(1, '$'))
2588 enew! | close
2589endfunc
2590
2591func Test_cindent_12()
2592 new
2593 setl cindent ts=4 sw=4
2594 setl cino=
2595
2596 let code =<< trim [CODE]
2597 a()
2598 {
2599 do {
2600 a = a +
2601 a;
2602 } while ( a ); /* add text under this line */
2603 if ( a )
2604 a;
2605 }
2606 [CODE]
2607
2608 call append(0, code)
2609 normal gg
2610 call search('while')
2611 normal ohere
2612
2613 let expected =<< trim [CODE]
2614 a()
2615 {
2616 do {
2617 a = a +
2618 a;
2619 } while ( a ); /* add text under this line */
2620 here
2621 if ( a )
2622 a;
2623 }
2624
2625 [CODE]
2626
2627 call assert_equal(expected, getline(1, '$'))
2628 enew! | close
2629endfunc
2630
2631func Test_cindent_13()
2632 new
2633 setl cindent ts=4 sw=4
2634 setl cino= com=
2635
2636 let code =<< trim [CODE]
2637 a()
2638 {
2639 label1:
2640 /* hmm */
2641 // comment
2642 }
2643 [CODE]
2644
2645 call append(0, code)
2646 normal gg
2647 call search('comment')
2648 exe "normal olabel2: b();\rlabel3 /* post */:\r/* pre */ label4:\r" .
2649 \ "f(/*com*/);\rif (/*com*/)\rcmd();"
2650
2651 let expected =<< trim [CODE]
2652 a()
2653 {
2654 label1:
2655 /* hmm */
2656 // comment
2657 label2: b();
2658 label3 /* post */:
2659 /* pre */ label4:
2660 f(/*com*/);
2661 if (/*com*/)
2662 cmd();
2663 }
2664
2665 [CODE]
2666
2667 call assert_equal(expected, getline(1, '$'))
2668 enew! | close
2669endfunc
2670
2671func Test_cindent_14()
2672 new
2673 setl cindent ts=4 sw=4
2674 setl comments& comments^=s:/*,m:**,ex:*/
2675
2676 let code =<< trim [CODE]
2677 /*
2678 * A simple comment
2679 */
2680
2681 /*
2682 ** A different comment
2683 */
2684 [CODE]
2685
2686 call append(0, code)
2687 normal gg
2688 call search('simple')
2689 normal =5j
2690
2691 let expected =<< trim [CODE]
2692 /*
2693 * A simple comment
2694 */
2695
2696 /*
2697 ** A different comment
2698 */
2699
2700 [CODE]
2701
2702 call assert_equal(expected, getline(1, '$'))
2703 enew! | close
2704endfunc
2705
2706func Test_cindent_15()
2707 new
2708 setl cindent ts=4 sw=4
2709 setl cino=c0
2710 setl comments& comments-=s1:/* comments^=s0:/*
2711
2712 let code =<< trim [CODE]
2713 void f()
2714 {
2715
2716 /*********
2717 A comment.
2718 *********/
2719 }
2720 [CODE]
2721
2722 call append(0, code)
2723 normal gg
2724 normal ]]=][
2725
2726 let expected =<< trim [CODE]
2727 void f()
2728 {
2729
2730 /*********
2731 A comment.
2732 *********/
2733 }
2734
2735 [CODE]
2736
2737 call assert_equal(expected, getline(1, '$'))
2738 enew! | close
2739endfunc
2740
2741func Test_cindent_16()
2742 new
2743 setl cindent ts=4 sw=4
2744 setl cino=c0,C1
2745 setl comments& comments-=s1:/* comments^=s0:/*
2746
2747 let code =<< trim [CODE]
2748 void f()
2749 {
2750
2751 /*********
2752 A comment.
2753 *********/
2754 }
2755 [CODE]
2756
2757 call append(0, code)
2758 normal gg
2759 normal ]]=][
2760
2761 let expected =<< trim [CODE]
2762 void f()
2763 {
2764
2765 /*********
2766 A comment.
2767 *********/
2768 }
2769
2770 [CODE]
2771
2772 call assert_equal(expected, getline(1, '$'))
2773 enew! | close
2774endfunc
2775
2776func Test_cindent_17()
2777 new
2778 setl cindent ts=4 sw=4
2779 setl cino=
2780
2781 let code =<< trim [CODE]
2782 void f()
2783 {
2784 c = c1 &&
2785 (
2786 c2 ||
2787 c3
2788 ) && c4;
2789 }
2790 [CODE]
2791
2792 call append(0, code)
2793 normal gg
2794 normal ]]=][
2795
2796 let expected =<< trim [CODE]
2797 void f()
2798 {
2799 c = c1 &&
2800 (
2801 c2 ||
2802 c3
2803 ) && c4;
2804 }
2805
2806 [CODE]
2807
2808 call assert_equal(expected, getline(1, '$'))
2809 enew! | close
2810endfunc
2811
2812func Test_cindent_18()
2813 new
2814 setl cindent ts=4 sw=4
2815 setl cino=(s
2816
2817 let code =<< trim [CODE]
2818 void f()
2819 {
2820 c = c1 &&
2821 (
2822 c2 ||
2823 c3
2824 ) && c4;
2825 }
2826 [CODE]
2827
2828 call append(0, code)
2829 normal gg
2830 normal ]]=][
2831
2832 let expected =<< trim [CODE]
2833 void f()
2834 {
2835 c = c1 &&
2836 (
2837 c2 ||
2838 c3
2839 ) && c4;
2840 }
2841
2842 [CODE]
2843
2844 call assert_equal(expected, getline(1, '$'))
2845 enew! | close
2846endfunc
2847
2848func Test_cindent_19()
2849 new
2850 setl cindent ts=4 sw=4
2851 set cino=(s,U1
2852
2853 let code =<< trim [CODE]
2854 void f()
2855 {
2856 c = c1 &&
2857 (
2858 c2 ||
2859 c3
2860 ) && c4;
2861 }
2862 [CODE]
2863
2864 call append(0, code)
2865 normal gg
2866 normal ]]=][
2867
2868 let expected =<< trim [CODE]
2869 void f()
2870 {
2871 c = c1 &&
2872 (
2873 c2 ||
2874 c3
2875 ) && c4;
2876 }
2877
2878 [CODE]
2879
2880 call assert_equal(expected, getline(1, '$'))
2881 enew! | close
2882endfunc
2883
2884func Test_cindent_20()
2885 new
2886 setl cindent ts=4 sw=4
2887 setl cino=(0
2888
2889 let code =<< trim [CODE]
2890 void f()
2891 {
2892 if ( c1
2893 && ( c2
2894 || c3))
2895 foo;
2896 }
2897 [CODE]
2898
2899 call append(0, code)
2900 normal gg
2901 normal ]]=][
2902
2903 let expected =<< trim [CODE]
2904 void f()
2905 {
2906 if ( c1
2907 && ( c2
2908 || c3))
2909 foo;
2910 }
2911
2912 [CODE]
2913
2914 call assert_equal(expected, getline(1, '$'))
2915 enew! | close
2916endfunc
2917
2918func Test_cindent_21()
2919 new
2920 setl cindent ts=4 sw=4
2921 setl cino=(0,w1
2922
2923 let code =<< trim [CODE]
2924 void f()
2925 {
2926 if ( c1
2927 && ( c2
2928 || c3))
2929 foo;
2930 }
2931 [CODE]
2932
2933 call append(0, code)
2934 normal gg
2935 normal ]]=][
2936
2937 let expected =<< trim [CODE]
2938 void f()
2939 {
2940 if ( c1
2941 && ( c2
2942 || c3))
2943 foo;
2944 }
2945
2946 [CODE]
2947
2948 call assert_equal(expected, getline(1, '$'))
2949 enew! | close
2950endfunc
2951
2952func Test_cindent_22()
2953 new
2954 setl cindent ts=4 sw=4
2955 setl cino=(s
2956
2957 let code =<< trim [CODE]
2958 void f()
2959 {
2960 c = c1 && (
2961 c2 ||
2962 c3
2963 ) && c4;
2964 if (
2965 c1 && c2
2966 )
2967 foo;
2968 }
2969 [CODE]
2970
2971 call append(0, code)
2972 normal gg
2973 normal ]]=][
2974
2975 let expected =<< trim [CODE]
2976 void f()
2977 {
2978 c = c1 && (
2979 c2 ||
2980 c3
2981 ) && c4;
2982 if (
2983 c1 && c2
2984 )
2985 foo;
2986 }
2987
2988 [CODE]
2989
2990 call assert_equal(expected, getline(1, '$'))
2991 enew! | close
2992endfunc
2993
2994func Test_cindent_23()
2995 new
2996 setl cindent ts=4 sw=4
2997 setl cino=(s,m1
2998
2999 let code =<< trim [CODE]
3000 void f()
3001 {
3002 c = c1 && (
3003 c2 ||
3004 c3
3005 ) && c4;
3006 if (
3007 c1 && c2
3008 )
3009 foo;
3010 }
3011 [CODE]
3012
3013 call append(0, code)
3014 normal gg
3015 normal ]]=][
3016
3017 let expected =<< trim [CODE]
3018 void f()
3019 {
3020 c = c1 && (
3021 c2 ||
3022 c3
3023 ) && c4;
3024 if (
3025 c1 && c2
3026 )
3027 foo;
3028 }
3029
3030 [CODE]
3031
3032 call assert_equal(expected, getline(1, '$'))
3033 enew! | close
3034endfunc
3035
3036func Test_cindent_24()
3037 new
3038 setl cindent ts=4 sw=4
3039 setl cino=b1
3040
3041 let code =<< trim [CODE]
3042 void f()
3043 {
3044 switch (x)
3045 {
3046 case 1:
3047 a = b;
3048 break;
3049 default:
3050 a = 0;
3051 break;
3052 }
3053 }
3054 [CODE]
3055
3056 call append(0, code)
3057 normal gg
3058 normal ]]=][
3059
3060 let expected =<< trim [CODE]
3061 void f()
3062 {
3063 switch (x)
3064 {
3065 case 1:
3066 a = b;
3067 break;
3068 default:
3069 a = 0;
3070 break;
3071 }
3072 }
3073
3074 [CODE]
3075
3076 call assert_equal(expected, getline(1, '$'))
3077 enew! | close
3078endfunc
3079
3080func Test_cindent_25()
3081 new
3082 setl cindent ts=4 sw=4
3083 setl cino=(0,W5
3084
3085 let code =<< trim [CODE]
3086 void f()
3087 {
3088 invokeme(
3089 argu,
3090 ment);
3091 invokeme(
3092 argu,
3093 ment
3094 );
3095 invokeme(argu,
3096 ment
3097 );
3098 }
3099 [CODE]
3100
3101 call append(0, code)
3102 normal gg
3103 normal ]]=][
3104
3105 let expected =<< trim [CODE]
3106 void f()
3107 {
3108 invokeme(
3109 argu,
3110 ment);
3111 invokeme(
3112 argu,
3113 ment
3114 );
3115 invokeme(argu,
3116 ment
3117 );
3118 }
3119
3120 [CODE]
3121
3122 call assert_equal(expected, getline(1, '$'))
3123 enew! | close
3124endfunc
3125
3126func Test_cindent_26()
3127 new
3128 setl cindent ts=4 sw=4
3129 setl cino=/6
3130
3131 let code =<< trim [CODE]
3132 void f()
3133 {
3134 statement;
3135 // comment 1
3136 // comment 2
3137 }
3138 [CODE]
3139
3140 call append(0, code)
3141 normal gg
3142 normal ]]=][
3143
3144 let expected =<< trim [CODE]
3145 void f()
3146 {
3147 statement;
3148 // comment 1
3149 // comment 2
3150 }
3151
3152 [CODE]
3153
3154 call assert_equal(expected, getline(1, '$'))
3155 enew! | close
3156endfunc
3157
3158func Test_cindent_27()
3159 new
3160 setl cindent ts=4 sw=4
3161 setl cino=
3162
3163 let code =<< trim [CODE]
3164 void f()
3165 {
3166 statement;
3167 // comment 1
3168 // comment 2
3169 }
3170 [CODE]
3171
3172 call append(0, code)
3173 normal gg
3174 exe "normal ]]/comment 1/+1\<CR>=="
3175
3176 let expected =<< trim [CODE]
3177 void f()
3178 {
3179 statement;
3180 // comment 1
3181 // comment 2
3182 }
3183
3184 [CODE]
3185
3186 call assert_equal(expected, getline(1, '$'))
3187 enew! | close
3188endfunc
3189
3190func Test_cindent_28()
3191 new
3192 setl cindent ts=4 sw=4
3193 setl cino=g0
3194
3195 let code =<< trim [CODE]
3196 class CAbc
3197 {
3198 int Test() { return FALSE; }
3199
3200 public: // comment
3201 void testfall();
3202 protected:
3203 void testfall();
3204 };
3205 [CODE]
3206
3207 call append(0, code)
3208 normal gg
3209 normal ]]=][
3210
3211 let expected =<< trim [CODE]
3212 class CAbc
3213 {
3214 int Test() { return FALSE; }
3215
3216 public: // comment
3217 void testfall();
3218 protected:
3219 void testfall();
3220 };
3221
3222 [CODE]
3223
3224 call assert_equal(expected, getline(1, '$'))
3225 enew! | close
3226endfunc
3227
3228func Test_cindent_29()
3229 new
3230 setl cindent ts=4 sw=4
3231 setl cino=(0,gs,hs
3232
3233 let code =<< trim [CODE]
3234 class Foo : public Bar
3235 {
3236 public:
3237 virtual void method1(void) = 0;
3238 virtual void method2(int arg1,
3239 int arg2,
3240 int arg3) = 0;
3241 };
3242 [CODE]
3243
3244 call append(0, code)
3245 normal gg
3246 normal ]]=][
3247
3248 let expected =<< trim [CODE]
3249 class Foo : public Bar
3250 {
3251 public:
3252 virtual void method1(void) = 0;
3253 virtual void method2(int arg1,
3254 int arg2,
3255 int arg3) = 0;
3256 };
3257
3258 [CODE]
3259
3260 call assert_equal(expected, getline(1, '$'))
3261 enew! | close
3262endfunc
3263
3264func Test_cindent_30()
3265 new
3266 setl cindent ts=4 sw=4
3267 setl cino=+20
3268
Bram Moolenaare7eb9272019-06-24 00:58:07 +02003269 let code =<< [CODE]
3270 void
3271foo()
3272{
3273 if (a)
3274 {
3275 } else
3276 asdf;
3277}
3278[CODE]
Bram Moolenaar1ab74a52019-05-31 20:02:53 +02003279
3280 call append(0, code)
3281 normal gg
3282 normal ]]=][
3283
Bram Moolenaare7eb9272019-06-24 00:58:07 +02003284 let expected =<< [CODE]
3285 void
3286foo()
3287{
3288 if (a)
3289 {
3290 } else
3291 asdf;
3292}
Bram Moolenaar1ab74a52019-05-31 20:02:53 +02003293
Bram Moolenaare7eb9272019-06-24 00:58:07 +02003294[CODE]
Bram Moolenaar1ab74a52019-05-31 20:02:53 +02003295
3296 call assert_equal(expected, getline(1, '$'))
3297 enew! | close
3298endfunc
3299
3300func Test_cindent_31()
3301 new
3302 setl cindent ts=4 sw=4
3303 setl cino=(0,W2s
3304
3305 let code =<< trim [CODE]
3306
3307 {
3308 averylongfunctionnamelongfunctionnameaverylongfunctionname()->asd(
3309 asdasdf,
3310 func(asdf,
3311 asdfadsf),
3312 asdfasdf
3313 );
3314
3315 /* those are ugly, but consequent */
3316
3317 func()->asd(asdasdf,
3318 averylongfunctionname(
3319 abc,
3320 dec)->averylongfunctionname(
3321 asdfadsf,
3322 asdfasdf,
3323 asdfasdf,
3324 ),
3325 func(asdfadf,
3326 asdfasdf
3327 ),
3328 asdasdf
3329 );
3330
3331 averylongfunctionnameaverylongfunctionnameavery()->asd(fasdf(
3332 abc,
3333 dec)->asdfasdfasdf(
3334 asdfadsf,
3335 asdfasdf,
3336 asdfasdf,
3337 ),
3338 func(asdfadf,
3339 asdfasdf),
3340 asdasdf
3341 );
3342 }
3343 [CODE]
3344
3345 call append(0, code)
3346 normal gg
3347 normal ]]=][
3348
3349 let expected =<< trim [CODE]
3350
3351 {
3352 averylongfunctionnamelongfunctionnameaverylongfunctionname()->asd(
3353 asdasdf,
3354 func(asdf,
3355 asdfadsf),
3356 asdfasdf
3357 );
3358
3359 /* those are ugly, but consequent */
3360
3361 func()->asd(asdasdf,
3362 averylongfunctionname(
3363 abc,
3364 dec)->averylongfunctionname(
3365 asdfadsf,
3366 asdfasdf,
3367 asdfasdf,
3368 ),
3369 func(asdfadf,
3370 asdfasdf
3371 ),
3372 asdasdf
3373 );
3374
3375 averylongfunctionnameaverylongfunctionnameavery()->asd(fasdf(
3376 abc,
3377 dec)->asdfasdfasdf(
3378 asdfadsf,
3379 asdfasdf,
3380 asdfasdf,
3381 ),
3382 func(asdfadf,
3383 asdfasdf),
3384 asdasdf
3385 );
3386 }
3387
3388 [CODE]
3389
3390 call assert_equal(expected, getline(1, '$'))
3391 enew! | close
3392endfunc
3393
3394func Test_cindent_32()
3395 new
3396 setl cindent ts=4 sw=4
3397 setl cino=M1
3398
3399 let code =<< trim [CODE]
3400 int main ()
3401 {
3402 if (cond1 &&
3403 cond2
3404 )
3405 foo;
3406 }
3407 [CODE]
3408
3409 call append(0, code)
3410 normal gg
3411 normal ]]=][
3412
3413 let expected =<< trim [CODE]
3414 int main ()
3415 {
3416 if (cond1 &&
3417 cond2
3418 )
3419 foo;
3420 }
3421
3422 [CODE]
3423
3424 call assert_equal(expected, getline(1, '$'))
3425 enew! | close
3426endfunc
3427
3428func Test_cindent_33()
3429 new
3430 setl cindent ts=4 sw=4
3431 setl cino=(0,ts
3432
3433 let code =<< trim [CODE]
3434 void func(int a
3435 #if defined(FOO)
3436 , int b
3437 , int c
3438 #endif
3439 )
3440 {
3441 }
3442 [CODE]
3443
3444 call append(0, code)
3445 normal gg
3446 normal 2j=][
3447
3448 let expected =<< trim [CODE]
3449 void func(int a
3450 #if defined(FOO)
3451 , int b
3452 , int c
3453 #endif
3454 )
3455 {
3456 }
3457
3458 [CODE]
3459
3460 call assert_equal(expected, getline(1, '$'))
3461 enew! | close
3462endfunc
3463
3464func Test_cindent_34()
3465 new
3466 setl cindent ts=4 sw=4
3467 setl cino=(0
3468
3469 let code =<< trim [CODE]
3470
3471 void
3472 func(int a
3473 #if defined(FOO)
3474 , int b
3475 , int c
3476 #endif
3477 )
3478 {
3479 }
3480 [CODE]
3481
3482 call append(0, code)
3483 normal gg
3484 normal =][
3485
3486 let expected =<< trim [CODE]
Bram Moolenaare7eb9272019-06-24 00:58:07 +02003487
Bram Moolenaar1ab74a52019-05-31 20:02:53 +02003488 void
3489 func(int a
3490 #if defined(FOO)
3491 , int b
3492 , int c
3493 #endif
3494 )
3495 {
3496 }
3497
3498 [CODE]
3499
3500 call assert_equal(expected, getline(1, '$'))
3501 enew! | close
3502endfunc
3503
3504func Test_cindent_35()
3505 new
3506 setl cindent ts=4 sw=4
3507 setl cino&
3508
3509 let code =<< trim [CODE]
3510 void func(void)
3511 {
3512 if(x==y)
3513 if(y==z)
3514 foo=1;
3515 else { bar=1;
3516 baz=2;
3517 }
3518 printf("Foo!\n");
3519 }
3520
3521 void func1(void)
3522 {
3523 char* tab[] = {"foo", "bar",
3524 "baz", "quux",
3525 "this line used", "to be indented incorrectly"};
3526 foo();
3527 }
3528
3529 void func2(void)
3530 {
3531 int tab[] =
3532 {1, 2,
3533 3, 4,
3534 5, 6};
3535
3536 printf("This line used to be indented incorrectly.\n");
3537 }
3538
3539 int foo[]
3540 #ifdef BAR
3541
3542 = { 1, 2, 3,
3543 4, 5, 6 }
3544
3545 #endif
3546 ;
3547 int baz;
3548
3549 void func3(void)
3550 {
3551 int tab[] = {
3552 1, 2,
3553 3, 4,
3554 5, 6};
3555
3556 printf("Don't you dare indent this line incorrectly!\n");
3557 }
3558
3559 void
3560 func4(a, b,
3561 c)
3562 int a;
3563 int b;
3564 int c;
3565 {
3566 }
3567
3568 void
3569 func5(
3570 int a,
3571 int b)
3572 {
3573 }
3574
3575 void
3576 func6(
3577 int a)
3578 {
3579 }
3580 [CODE]
3581
3582 call append(0, code)
3583 normal gg
3584 normal ]]=7][
3585
3586 let expected =<< trim [CODE]
3587 void func(void)
3588 {
3589 if(x==y)
3590 if(y==z)
3591 foo=1;
3592 else { bar=1;
3593 baz=2;
3594 }
3595 printf("Foo!\n");
3596 }
3597
3598 void func1(void)
3599 {
3600 char* tab[] = {"foo", "bar",
3601 "baz", "quux",
3602 "this line used", "to be indented incorrectly"};
3603 foo();
3604 }
3605
3606 void func2(void)
3607 {
3608 int tab[] =
3609 {1, 2,
3610 3, 4,
3611 5, 6};
3612
3613 printf("This line used to be indented incorrectly.\n");
3614 }
3615
3616 int foo[]
3617 #ifdef BAR
3618
3619 = { 1, 2, 3,
3620 4, 5, 6 }
3621
3622 #endif
3623 ;
3624 int baz;
3625
3626 void func3(void)
3627 {
3628 int tab[] = {
3629 1, 2,
3630 3, 4,
3631 5, 6};
3632
3633 printf("Don't you dare indent this line incorrectly!\n");
3634 }
3635
3636 void
3637 func4(a, b,
3638 c)
3639 int a;
3640 int b;
3641 int c;
3642 {
3643 }
3644
3645 void
3646 func5(
3647 int a,
3648 int b)
3649 {
3650 }
3651
3652 void
3653 func6(
3654 int a)
3655 {
3656 }
3657
3658 [CODE]
3659
3660 call assert_equal(expected, getline(1, '$'))
3661 enew! | close
3662endfunc
3663
3664func Test_cindent_36()
3665 new
3666 setl cindent ts=4 sw=4
3667 setl cino&
3668 setl cino+=l1
3669
3670 let code =<< trim [CODE]
3671 void func(void)
3672 {
3673 int tab[] =
3674 {
3675 1, 2, 3,
3676 4, 5, 6};
3677
3678 printf("Indent this line correctly!\n");
3679
3680 switch (foo)
3681 {
3682 case bar:
3683 printf("bar");
3684 break;
3685 case baz: {
3686 printf("baz");
3687 break;
3688 }
3689 case quux:
3690 printf("But don't break the indentation of this instruction\n");
3691 break;
3692 }
3693 }
3694 [CODE]
3695
3696 call append(0, code)
3697 normal gg
3698 normal ]]=][
3699
3700 let expected =<< trim [CODE]
3701 void func(void)
3702 {
3703 int tab[] =
3704 {
3705 1, 2, 3,
3706 4, 5, 6};
3707
3708 printf("Indent this line correctly!\n");
3709
3710 switch (foo)
3711 {
3712 case bar:
3713 printf("bar");
3714 break;
3715 case baz: {
3716 printf("baz");
3717 break;
3718 }
3719 case quux:
3720 printf("But don't break the indentation of this instruction\n");
3721 break;
3722 }
3723 }
3724
3725 [CODE]
3726
3727 call assert_equal(expected, getline(1, '$'))
3728 enew! | close
3729endfunc
3730
3731func Test_cindent_37()
3732 new
3733 setl cindent ts=4 sw=4
3734 setl cino&
3735
3736 let code =<< trim [CODE]
3737 void func(void)
3738 {
3739 cout << "a"
3740 << "b"
3741 << ") :"
3742 << "c";
3743 }
3744 [CODE]
3745
3746 call append(0, code)
3747 normal gg
3748 normal ]]=][
3749
3750 let expected =<< trim [CODE]
3751 void func(void)
3752 {
3753 cout << "a"
3754 << "b"
3755 << ") :"
3756 << "c";
3757 }
3758
3759 [CODE]
3760
3761 call assert_equal(expected, getline(1, '$'))
3762 enew! | close
3763endfunc
3764
3765func Test_cindent_38()
3766 new
3767 setl cindent ts=4 sw=4
3768 setl com=s1:/*,m:*,ex:*/
3769
3770 let code =<< trim [CODE]
3771 void func(void)
3772 {
3773 /*
3774 * This is a comment.
3775 */
3776 }
3777 [CODE]
3778
3779 call append(0, code)
3780 normal gg
3781 normal ]]3jofoo();
3782
3783 let expected =<< trim [CODE]
3784 void func(void)
3785 {
3786 /*
3787 * This is a comment.
3788 */
3789 foo();
3790 }
3791
3792 [CODE]
3793
3794 call assert_equal(expected, getline(1, '$'))
3795 enew! | close
3796endfunc
3797
3798func Test_cindent_39()
3799 new
3800 setl cindent ts=4 sw=4
3801 setl cino&
3802
3803 let code =<< trim [CODE]
3804 void func(void)
3805 {
3806 for (int i = 0; i < 10; ++i)
3807 if (i & 1) {
3808 foo(1);
3809 } else
3810 foo(0);
3811 baz();
3812 }
3813 [CODE]
3814
3815 call append(0, code)
3816 normal gg
3817 normal ]]=][
3818
3819 let expected =<< trim [CODE]
3820 void func(void)
3821 {
3822 for (int i = 0; i < 10; ++i)
3823 if (i & 1) {
3824 foo(1);
3825 } else
3826 foo(0);
3827 baz();
3828 }
3829
3830 [CODE]
3831
3832 call assert_equal(expected, getline(1, '$'))
3833 enew! | close
3834endfunc
3835
3836func Test_cindent_40()
3837 new
3838 setl cindent ts=4 sw=4
3839 setl cino=k2s,(0
3840
3841 let code =<< trim [CODE]
3842 void func(void)
3843 {
3844 if (condition1
3845 && condition2)
3846 action();
3847 function(argument1
3848 && argument2);
3849
3850 if (c1 && (c2 ||
3851 c3))
3852 foo;
3853 if (c1 &&
3854 (c2 || c3))
3855 {
3856 }
3857
3858 if ( c1
3859 && ( c2
3860 || c3))
3861 foo;
3862 func( c1
3863 && ( c2
3864 || c3))
3865 foo;
3866 }
3867 [CODE]
3868
3869 call append(0, code)
3870 normal gg
3871 normal ]]=][
3872
3873 let expected =<< trim [CODE]
3874 void func(void)
3875 {
3876 if (condition1
3877 && condition2)
3878 action();
3879 function(argument1
3880 && argument2);
3881
3882 if (c1 && (c2 ||
3883 c3))
3884 foo;
3885 if (c1 &&
3886 (c2 || c3))
3887 {
3888 }
3889
3890 if ( c1
3891 && ( c2
3892 || c3))
3893 foo;
3894 func( c1
3895 && ( c2
3896 || c3))
3897 foo;
3898 }
3899
3900 [CODE]
3901
3902 call assert_equal(expected, getline(1, '$'))
3903 enew! | close
3904endfunc
3905
3906func Test_cindent_41()
3907 new
3908 setl cindent ts=4 sw=4
3909 setl cino=k2s,(s
3910
3911 let code =<< trim [CODE]
3912 void func(void)
3913 {
3914 if (condition1
3915 && condition2)
3916 action();
3917 function(argument1
3918 && argument2);
3919
3920 if (c1 && (c2 ||
3921 c3))
3922 foo;
3923 if (c1 &&
3924 (c2 || c3))
3925 {
3926 }
3927
3928 if ( c1
3929 && ( c2
3930 || c3))
3931 foo;
3932 func( c1
3933 && ( c2
3934 || c3))
3935 foo;
3936 }
3937 [CODE]
3938
3939 call append(0, code)
3940 normal gg
3941 normal ]]=][
3942
3943 let expected =<< trim [CODE]
3944 void func(void)
3945 {
3946 if (condition1
3947 && condition2)
3948 action();
3949 function(argument1
3950 && argument2);
3951
3952 if (c1 && (c2 ||
3953 c3))
3954 foo;
3955 if (c1 &&
3956 (c2 || c3))
3957 {
3958 }
3959
3960 if ( c1
3961 && ( c2
3962 || c3))
3963 foo;
3964 func( c1
3965 && ( c2
3966 || c3))
3967 foo;
3968 }
3969
3970 [CODE]
3971
3972 call assert_equal(expected, getline(1, '$'))
3973 enew! | close
3974endfunc
3975
3976func Test_cindent_42()
3977 new
3978 setl cindent ts=4 sw=4
3979 setl cino=k2s,(s,U1
3980
3981 let code =<< trim [CODE]
3982 void func(void)
3983 {
3984 if (condition1
3985 && condition2)
3986 action();
3987 function(argument1
3988 && argument2);
3989
3990 if (c1 && (c2 ||
3991 c3))
3992 foo;
3993 if (c1 &&
3994 (c2 || c3))
3995 {
3996 }
3997 if (c123456789
3998 && (c22345
3999 || c3))
4000 printf("foo\n");
4001
4002 c = c1 &&
4003 (
4004 c2 ||
4005 c3
4006 ) && c4;
4007 }
4008 [CODE]
4009
4010 call append(0, code)
4011 normal gg
4012 normal ]]=][
4013
4014 let expected =<< trim [CODE]
4015 void func(void)
4016 {
4017 if (condition1
4018 && condition2)
4019 action();
4020 function(argument1
4021 && argument2);
4022
4023 if (c1 && (c2 ||
4024 c3))
4025 foo;
4026 if (c1 &&
4027 (c2 || c3))
4028 {
4029 }
4030 if (c123456789
4031 && (c22345
4032 || c3))
4033 printf("foo\n");
4034
4035 c = c1 &&
4036 (
4037 c2 ||
4038 c3
4039 ) && c4;
4040 }
4041
4042 [CODE]
4043
4044 call assert_equal(expected, getline(1, '$'))
4045 enew! | close
4046endfunc
4047
4048func Test_cindent_43()
4049 new
4050 setl cindent ts=4 sw=4
4051 setl cino=k2s,(0,W4
4052
4053 let code =<< trim [CODE]
4054 void func(void)
4055 {
4056 if (condition1
4057 && condition2)
4058 action();
4059 function(argument1
4060 && argument2);
4061
4062 if (c1 && (c2 ||
4063 c3))
4064 foo;
4065 if (c1 &&
4066 (c2 || c3))
4067 {
4068 }
4069 if (c123456789
4070 && (c22345
4071 || c3))
4072 printf("foo\n");
4073
4074 if ( c1
4075 && ( c2
4076 || c3))
4077 foo;
4078
4079 a_long_line(
4080 argument,
4081 argument);
4082 a_short_line(argument,
4083 argument);
4084 }
4085 [CODE]
4086
4087 call append(0, code)
4088 normal gg
4089 normal ]]=][
4090
4091 let expected =<< trim [CODE]
4092 void func(void)
4093 {
4094 if (condition1
4095 && condition2)
4096 action();
4097 function(argument1
4098 && argument2);
4099
4100 if (c1 && (c2 ||
4101 c3))
4102 foo;
4103 if (c1 &&
4104 (c2 || c3))
4105 {
4106 }
4107 if (c123456789
4108 && (c22345
4109 || c3))
4110 printf("foo\n");
4111
4112 if ( c1
4113 && ( c2
4114 || c3))
4115 foo;
4116
4117 a_long_line(
4118 argument,
4119 argument);
4120 a_short_line(argument,
4121 argument);
4122 }
4123
4124 [CODE]
4125
4126 call assert_equal(expected, getline(1, '$'))
4127 enew! | close
4128endfunc
4129
4130func Test_cindent_44()
4131 new
4132 setl cindent ts=4 sw=4
4133 setl cino=k2s,u2
4134
4135 let code =<< trim [CODE]
4136 void func(void)
4137 {
4138 if (condition1
4139 && condition2)
4140 action();
4141 function(argument1
4142 && argument2);
4143
4144 if (c1 && (c2 ||
4145 c3))
4146 foo;
4147 if (c1 &&
4148 (c2 || c3))
4149 {
4150 }
4151 if (c123456789
4152 && (c22345
4153 || c3))
4154 printf("foo\n");
4155 }
4156 [CODE]
4157
4158 call append(0, code)
4159 normal gg
4160 normal ]]=][
4161
4162 let expected =<< trim [CODE]
4163 void func(void)
4164 {
4165 if (condition1
4166 && condition2)
4167 action();
4168 function(argument1
4169 && argument2);
4170
4171 if (c1 && (c2 ||
4172 c3))
4173 foo;
4174 if (c1 &&
4175 (c2 || c3))
4176 {
4177 }
4178 if (c123456789
4179 && (c22345
4180 || c3))
4181 printf("foo\n");
4182 }
4183
4184 [CODE]
4185
4186 call assert_equal(expected, getline(1, '$'))
4187 enew! | close
4188endfunc
4189
4190func Test_cindent_45()
4191 new
4192 setl cindent ts=4 sw=4
4193 setl cino=k2s,(0,w1
4194
4195 let code =<< trim [CODE]
4196 void func(void)
4197 {
4198 if (condition1
4199 && condition2)
4200 action();
4201 function(argument1
4202 && argument2);
4203
4204 if (c1 && (c2 ||
4205 c3))
4206 foo;
4207 if (c1 &&
4208 (c2 || c3))
4209 {
4210 }
4211 if (c123456789
4212 && (c22345
4213 || c3))
4214 printf("foo\n");
4215
4216 if ( c1
4217 && ( c2
4218 || c3))
4219 foo;
4220 func( c1
4221 && ( c2
4222 || c3))
4223 foo;
4224 }
4225 [CODE]
4226
4227 call append(0, code)
4228 normal gg
4229 normal ]]=][
4230
4231 let expected =<< trim [CODE]
4232 void func(void)
4233 {
4234 if (condition1
4235 && condition2)
4236 action();
4237 function(argument1
4238 && argument2);
4239
4240 if (c1 && (c2 ||
4241 c3))
4242 foo;
4243 if (c1 &&
4244 (c2 || c3))
4245 {
4246 }
4247 if (c123456789
4248 && (c22345
4249 || c3))
4250 printf("foo\n");
4251
4252 if ( c1
4253 && ( c2
4254 || c3))
4255 foo;
4256 func( c1
4257 && ( c2
4258 || c3))
4259 foo;
4260 }
4261
4262 [CODE]
4263
4264 call assert_equal(expected, getline(1, '$'))
4265 enew! | close
4266endfunc
4267
4268func Test_cindent_46()
4269 new
4270 setl cindent ts=4 sw=4
4271 setl cino=k2,(s
4272
4273 let code =<< trim [CODE]
4274 void func(void)
4275 {
4276 if (condition1
4277 && condition2)
4278 action();
4279 function(argument1
4280 && argument2);
4281
4282 if (c1 && (c2 ||
4283 c3))
4284 foo;
4285 if (c1 &&
4286 (c2 || c3))
4287 {
4288 }
4289 }
4290 [CODE]
4291
4292 call append(0, code)
4293 normal gg
4294 normal ]]=][
4295
4296 let expected =<< trim [CODE]
4297 void func(void)
4298 {
4299 if (condition1
4300 && condition2)
4301 action();
4302 function(argument1
4303 && argument2);
4304
4305 if (c1 && (c2 ||
4306 c3))
4307 foo;
4308 if (c1 &&
4309 (c2 || c3))
4310 {
4311 }
4312 }
4313
4314 [CODE]
4315
4316 call assert_equal(expected, getline(1, '$'))
4317 enew! | close
4318endfunc
4319
4320func Test_cindent_47()
4321 new
4322 setl cindent ts=4 sw=4
4323 setl cino=N-s
4324
4325 let code =<< trim [CODE]
4326 NAMESPACESTART
4327 /* valid namespaces with normal indent */
4328 namespace
4329 {
4330 {
4331 111111111111;
4332 }
4333 }
4334 namespace /* test */
4335 {
4336 11111111111111111;
4337 }
4338 namespace // test
4339 {
4340 111111111111111111;
4341 }
4342 namespace
4343 {
4344 111111111111111111;
4345 }
4346 namespace test
4347 {
4348 111111111111111111;
4349 }
4350 namespace test::cpp17
4351 {
4352 111111111111111111;
4353 }
4354 namespace ::incorrectcpp17
4355 {
4356 111111111111111111;
4357 }
4358 namespace test::incorrectcpp17::
4359 {
4360 111111111111111111;
4361 }
4362 namespace test:incorrectcpp17
4363 {
4364 111111111111111111;
4365 }
4366 namespace test:::incorrectcpp17
4367 {
4368 111111111111111111;
4369 }
4370 namespace{
4371 111111111111111111;
4372 }
4373 namespace test{
4374 111111111111111111;
4375 }
4376 namespace {
4377 111111111111111111;
4378 }
4379 namespace test {
4380 111111111111111111;
4381 namespace test2 {
4382 22222222222222222;
4383 }
4384 }
zeertzjqf2f0bdd2021-12-22 20:55:30 +00004385 inline namespace {
4386 111111111111111111;
4387 }
4388 inline /* test */ namespace {
4389 111111111111111111;
4390 }
4391 inline/* test */namespace {
4392 111111111111111111;
4393 }
Bram Moolenaar1ab74a52019-05-31 20:02:53 +02004394
4395 /* invalid namespaces use block indent */
4396 namespace test test2 {
4397 111111111111111111111;
4398 }
4399 namespace11111111111 {
4400 111111111111;
4401 }
4402 namespace() {
4403 1111111111111;
4404 }
4405 namespace()
4406 {
4407 111111111111111111;
4408 }
4409 namespace test test2
4410 {
4411 1111111111111111111;
4412 }
4413 namespace111111111
4414 {
4415 111111111111111111;
4416 }
zeertzjqf2f0bdd2021-12-22 20:55:30 +00004417 inlinenamespace {
4418 111111111111111111;
4419 }
Bram Moolenaar1ab74a52019-05-31 20:02:53 +02004420 NAMESPACEEND
4421 [CODE]
4422
4423 call append(0, code)
4424 normal gg
4425 call search('^NAMESPACESTART')
4426 exe "normal =/^NAMESPACEEND\n"
4427
4428 let expected =<< trim [CODE]
4429 NAMESPACESTART
4430 /* valid namespaces with normal indent */
4431 namespace
4432 {
4433 {
4434 111111111111;
4435 }
4436 }
4437 namespace /* test */
4438 {
4439 11111111111111111;
4440 }
4441 namespace // test
4442 {
4443 111111111111111111;
4444 }
4445 namespace
4446 {
4447 111111111111111111;
4448 }
4449 namespace test
4450 {
4451 111111111111111111;
4452 }
4453 namespace test::cpp17
4454 {
4455 111111111111111111;
4456 }
4457 namespace ::incorrectcpp17
4458 {
4459 111111111111111111;
4460 }
4461 namespace test::incorrectcpp17::
4462 {
4463 111111111111111111;
4464 }
4465 namespace test:incorrectcpp17
4466 {
4467 111111111111111111;
4468 }
4469 namespace test:::incorrectcpp17
4470 {
4471 111111111111111111;
4472 }
4473 namespace{
4474 111111111111111111;
4475 }
4476 namespace test{
4477 111111111111111111;
4478 }
4479 namespace {
4480 111111111111111111;
4481 }
4482 namespace test {
4483 111111111111111111;
4484 namespace test2 {
4485 22222222222222222;
4486 }
4487 }
zeertzjqf2f0bdd2021-12-22 20:55:30 +00004488 inline namespace {
4489 111111111111111111;
4490 }
4491 inline /* test */ namespace {
4492 111111111111111111;
4493 }
4494 inline/* test */namespace {
4495 111111111111111111;
4496 }
Bram Moolenaar1ab74a52019-05-31 20:02:53 +02004497
4498 /* invalid namespaces use block indent */
4499 namespace test test2 {
4500 111111111111111111111;
4501 }
4502 namespace11111111111 {
4503 111111111111;
4504 }
4505 namespace() {
4506 1111111111111;
4507 }
4508 namespace()
4509 {
4510 111111111111111111;
4511 }
4512 namespace test test2
4513 {
4514 1111111111111111111;
4515 }
4516 namespace111111111
4517 {
4518 111111111111111111;
4519 }
zeertzjqf2f0bdd2021-12-22 20:55:30 +00004520 inlinenamespace {
4521 111111111111111111;
4522 }
Bram Moolenaar1ab74a52019-05-31 20:02:53 +02004523 NAMESPACEEND
4524
4525 [CODE]
4526
4527 call assert_equal(expected, getline(1, '$'))
4528 enew! | close
4529endfunc
4530
4531func Test_cindent_48()
4532 new
4533 setl cindent ts=4 sw=4
4534 setl cino=j1,J1
4535
4536 let code =<< trim [CODE]
4537 JSSTART
4538 var bar = {
4539 foo: {
4540 that: this,
4541 some: ok,
4542 },
4543 "bar":{
4544 a : 2,
4545 b: "123abc",
4546 x: 4,
4547 "y": 5
4548 }
4549 }
4550 JSEND
4551 [CODE]
4552
4553 call append(0, code)
4554 normal gg
4555 call search('^JSSTART')
4556 exe "normal =/^JSEND\n"
4557
4558 let expected =<< trim [CODE]
4559 JSSTART
4560 var bar = {
4561 foo: {
4562 that: this,
4563 some: ok,
4564 },
4565 "bar":{
4566 a : 2,
4567 b: "123abc",
4568 x: 4,
4569 "y": 5
4570 }
4571 }
4572 JSEND
4573
4574 [CODE]
4575
4576 call assert_equal(expected, getline(1, '$'))
4577 enew! | close
4578endfunc
4579
4580func Test_cindent_49()
4581 new
4582 setl cindent ts=4 sw=4
4583 setl cino=j1,J1
4584
4585 let code =<< trim [CODE]
4586 JSSTART
4587 var foo = [
4588 1,
4589 2,
4590 3
4591 ];
4592 JSEND
4593 [CODE]
4594
4595 call append(0, code)
4596 normal gg
4597 call search('^JSSTART')
4598 exe "normal =/^JSEND\n"
4599
4600 let expected =<< trim [CODE]
4601 JSSTART
4602 var foo = [
4603 1,
4604 2,
4605 3
4606 ];
4607 JSEND
4608
4609 [CODE]
4610
4611 call assert_equal(expected, getline(1, '$'))
4612 enew! | close
4613endfunc
4614
4615func Test_cindent_50()
4616 new
4617 setl cindent ts=4 sw=4
4618 setl cino=j1,J1
4619
4620 let code =<< trim [CODE]
4621 JSSTART
4622 function bar() {
4623 var foo = [
4624 1,
4625 2,
4626 3
4627 ];
4628 }
4629 JSEND
4630 [CODE]
4631
4632 call append(0, code)
4633 normal gg
4634 call search('^JSSTART')
4635 exe "normal =/^JSEND\n"
4636
4637 let expected =<< trim [CODE]
4638 JSSTART
4639 function bar() {
4640 var foo = [
4641 1,
4642 2,
4643 3
4644 ];
4645 }
4646 JSEND
4647
4648 [CODE]
4649
4650 call assert_equal(expected, getline(1, '$'))
4651 enew! | close
4652endfunc
4653
4654func Test_cindent_51()
4655 new
4656 setl cindent ts=4 sw=4
4657 setl cino=j1,J1
4658
4659 let code =<< trim [CODE]
4660 JSSTART
4661 (function($){
4662
4663 if (cond &&
4664 cond) {
4665 stmt;
4666 }
4667 window.something.left =
4668 (width - 50 + offset) + "px";
4669 var class_name='myclass';
4670
4671 function private_method() {
4672 }
4673
4674 var public_method={
4675 method: function(options,args){
4676 private_method();
4677 }
4678 }
4679
4680 function init(options) {
4681
4682 $(this).data(class_name+'_public',$.extend({},{
4683 foo: 'bar',
4684 bar: 2,
4685 foobar: [
4686 1,
4687 2,
4688 3
4689 ],
4690 callback: function(){
4691 return true;
4692 }
4693 }, options||{}));
4694 }
4695
4696 $.fn[class_name]=function() {
4697
4698 var _arguments=arguments;
4699 return this.each(function(){
4700
4701 var options=$(this).data(class_name+'_public');
4702 if (!options) {
4703 init.apply(this,_arguments);
4704
4705 } else {
4706 var method=public_method[_arguments[0]];
4707
4708 if (typeof(method)!='function') {
4709 console.log(class_name+' has no method "'+_arguments[0]+'"');
4710 return false;
4711 }
4712 _arguments[0]=options;
4713 method.apply(this,_arguments);
4714 }
4715 });
4716 }
4717
4718 })(jQuery);
4719 JSEND
4720 [CODE]
4721
4722 call append(0, code)
4723 normal gg
4724 call search('^JSSTART')
4725 exe "normal =/^JSEND\n"
4726
4727 let expected =<< trim [CODE]
4728 JSSTART
4729 (function($){
4730
4731 if (cond &&
4732 cond) {
4733 stmt;
4734 }
4735 window.something.left =
4736 (width - 50 + offset) + "px";
4737 var class_name='myclass';
4738
4739 function private_method() {
4740 }
4741
4742 var public_method={
4743 method: function(options,args){
4744 private_method();
4745 }
4746 }
4747
4748 function init(options) {
4749
4750 $(this).data(class_name+'_public',$.extend({},{
4751 foo: 'bar',
4752 bar: 2,
4753 foobar: [
4754 1,
4755 2,
4756 3
4757 ],
4758 callback: function(){
4759 return true;
4760 }
4761 }, options||{}));
4762 }
4763
4764 $.fn[class_name]=function() {
4765
4766 var _arguments=arguments;
4767 return this.each(function(){
4768
4769 var options=$(this).data(class_name+'_public');
4770 if (!options) {
4771 init.apply(this,_arguments);
4772
4773 } else {
4774 var method=public_method[_arguments[0]];
4775
4776 if (typeof(method)!='function') {
4777 console.log(class_name+' has no method "'+_arguments[0]+'"');
4778 return false;
4779 }
4780 _arguments[0]=options;
4781 method.apply(this,_arguments);
4782 }
4783 });
4784 }
4785
4786 })(jQuery);
4787 JSEND
4788
4789 [CODE]
4790
4791 call assert_equal(expected, getline(1, '$'))
4792 enew! | close
4793endfunc
4794
4795func Test_cindent_52()
4796 new
4797 setl cindent ts=4 sw=4
4798 setl cino=j1,J1
4799
4800 let code =<< trim [CODE]
4801 JSSTART
4802 function init(options) {
4803 $(this).data(class_name+'_public',$.extend({},{
4804 foo: 'bar',
4805 bar: 2,
4806 foobar: [
4807 1,
4808 2,
4809 3
4810 ],
4811 callback: function(){
4812 return true;
4813 }
4814 }, options||{}));
4815 }
4816 JSEND
4817 [CODE]
4818
4819 call append(0, code)
4820 normal gg
4821 call search('^JSSTART')
4822 exe "normal =/^JSEND\n"
4823
4824 let expected =<< trim [CODE]
4825 JSSTART
4826 function init(options) {
4827 $(this).data(class_name+'_public',$.extend({},{
4828 foo: 'bar',
4829 bar: 2,
4830 foobar: [
4831 1,
4832 2,
4833 3
4834 ],
4835 callback: function(){
4836 return true;
4837 }
4838 }, options||{}));
4839 }
4840 JSEND
4841
4842 [CODE]
4843
4844 call assert_equal(expected, getline(1, '$'))
4845 enew! | close
4846endfunc
4847
4848func Test_cindent_53()
4849 new
4850 setl cindent ts=4 sw=4
4851 setl cino=j1,J1
4852
4853 let code =<< trim [CODE]
4854 JSSTART
4855 (function($){
4856 function init(options) {
4857 $(this).data(class_name+'_public',$.extend({},{
4858 foo: 'bar',
4859 bar: 2,
4860 foobar: [
4861 1,
4862 2,
4863 3
4864 ],
4865 callback: function(){
4866 return true;
4867 }
4868 }, options||{}));
4869 }
4870 })(jQuery);
4871 JSEND
4872 [CODE]
4873
4874 call append(0, code)
4875 normal gg
4876 call search('^JSSTART')
4877 exe "normal =/^JSEND\n"
4878
4879 let expected =<< trim [CODE]
4880 JSSTART
4881 (function($){
4882 function init(options) {
4883 $(this).data(class_name+'_public',$.extend({},{
4884 foo: 'bar',
4885 bar: 2,
4886 foobar: [
4887 1,
4888 2,
4889 3
4890 ],
4891 callback: function(){
4892 return true;
4893 }
4894 }, options||{}));
4895 }
4896 })(jQuery);
4897 JSEND
4898
4899 [CODE]
4900
4901 call assert_equal(expected, getline(1, '$'))
4902 enew! | close
4903endfunc
4904
4905func Test_cindent_54()
4906 new
4907 setl cindent ts=4 sw=4
4908 setl cino=j1,J1,+2
4909
4910 let code =<< trim [CODE]
4911 JSSTART
4912 // Results of JavaScript indent
4913 // 1
4914 (function(){
4915 var a = [
4916 'a',
4917 'b',
4918 'c',
4919 'd',
4920 'e',
4921 'f',
4922 'g',
4923 'h',
4924 'i'
4925 ];
4926 }())
4927
4928 // 2
4929 (function(){
4930 var a = [
4931 0 +
4932 5 *
4933 9 *
4934 'a',
4935 'b',
4936 0 +
4937 5 *
4938 9 *
4939 'c',
4940 'd',
4941 'e',
4942 'f',
4943 'g',
4944 'h',
4945 'i'
4946 ];
4947 }())
4948
4949 // 3
4950 (function(){
4951 var a = [
4952 0 +
4953 // comment 1
4954 5 *
4955 /* comment 2 */
4956 9 *
4957 'a',
4958 'b',
4959 0 +
4960 5 *
4961 9 *
4962 'c',
4963 'd',
4964 'e',
4965 'f',
4966 'g',
4967 'h',
4968 'i'
4969 ];
4970 }())
4971
4972 // 4
4973 {
4974 var a = [
4975 0,
4976 1
4977 ];
4978 var b;
4979 var c;
4980 }
4981
4982 // 5
4983 {
4984 var a = [
4985 [
4986 0
4987 ],
4988 2,
4989 3
4990 ];
4991 }
4992
4993 // 6
4994 {
4995 var a = [
4996 [
4997 0,
4998 1
4999 ],
5000 2,
5001 3
5002 ];
5003 }
5004
5005 // 7
5006 {
5007 var a = [
5008 // [
5009 0,
5010 // 1
5011 // ],
5012 2,
5013 3
5014 ];
5015 }
5016
5017 // 8
5018 var x = [
5019 (function(){
5020 var a,
5021 b,
5022 c,
5023 d,
5024 e,
5025 f,
5026 g,
5027 h,
5028 i;
5029 })
5030 ];
5031
5032 // 9
5033 var a = [
5034 0 +
5035 5 *
5036 9 *
5037 'a',
5038 'b',
5039 0 +
5040 5 *
5041 9 *
5042 'c',
5043 'd',
5044 'e',
5045 'f',
5046 'g',
5047 'h',
5048 'i'
5049 ];
5050
5051 // 10
5052 var a,
5053 b,
5054 c,
5055 d,
5056 e,
5057 f,
5058 g,
5059 h,
5060 i;
5061 JSEND
5062 [CODE]
5063
5064 call append(0, code)
5065 normal gg
5066 call search('^JSSTART')
5067 exe "normal =/^JSEND\n"
5068
5069 let expected =<< trim [CODE]
5070 JSSTART
5071 // Results of JavaScript indent
5072 // 1
5073 (function(){
5074 var a = [
5075 'a',
5076 'b',
5077 'c',
5078 'd',
5079 'e',
5080 'f',
5081 'g',
5082 'h',
5083 'i'
5084 ];
5085 }())
5086
5087 // 2
5088 (function(){
5089 var a = [
5090 0 +
5091 5 *
5092 9 *
5093 'a',
5094 'b',
5095 0 +
5096 5 *
5097 9 *
5098 'c',
5099 'd',
5100 'e',
5101 'f',
5102 'g',
5103 'h',
5104 'i'
5105 ];
5106 }())
5107
5108 // 3
5109 (function(){
5110 var a = [
5111 0 +
5112 // comment 1
5113 5 *
5114 /* comment 2 */
5115 9 *
5116 'a',
5117 'b',
5118 0 +
5119 5 *
5120 9 *
5121 'c',
5122 'd',
5123 'e',
5124 'f',
5125 'g',
5126 'h',
5127 'i'
5128 ];
5129 }())
5130
5131 // 4
5132 {
5133 var a = [
5134 0,
5135 1
5136 ];
5137 var b;
5138 var c;
5139 }
5140
5141 // 5
5142 {
5143 var a = [
5144 [
5145 0
5146 ],
5147 2,
5148 3
5149 ];
5150 }
5151
5152 // 6
5153 {
5154 var a = [
5155 [
5156 0,
5157 1
5158 ],
5159 2,
5160 3
5161 ];
5162 }
5163
5164 // 7
5165 {
5166 var a = [
5167 // [
5168 0,
5169 // 1
5170 // ],
5171 2,
5172 3
5173 ];
5174 }
5175
5176 // 8
5177 var x = [
5178 (function(){
5179 var a,
5180 b,
5181 c,
5182 d,
5183 e,
5184 f,
5185 g,
5186 h,
5187 i;
5188 })
5189 ];
5190
5191 // 9
5192 var a = [
5193 0 +
5194 5 *
5195 9 *
5196 'a',
5197 'b',
5198 0 +
5199 5 *
5200 9 *
5201 'c',
5202 'd',
5203 'e',
5204 'f',
5205 'g',
5206 'h',
5207 'i'
5208 ];
5209
5210 // 10
5211 var a,
5212 b,
5213 c,
5214 d,
5215 e,
5216 f,
5217 g,
5218 h,
5219 i;
5220 JSEND
5221
5222 [CODE]
5223
5224 call assert_equal(expected, getline(1, '$'))
5225 enew! | close
5226endfunc
5227
5228func Test_cindent_55()
5229 new
5230 setl cindent ts=4 sw=4
5231 setl cino&
5232
5233 let code =<< trim [CODE]
5234 /* start of define */
5235 {
5236 }
5237 #define AAA \
5238 BBB\
5239 CCC
5240
5241 #define CNT \
5242 1 + \
5243 2 + \
5244 4
5245 /* end of define */
5246 [CODE]
5247
5248 call append(0, code)
5249 normal gg
5250 call search('start of define')
5251 exe "normal =/end of define\n"
5252
5253 let expected =<< trim [CODE]
5254 /* start of define */
5255 {
5256 }
5257 #define AAA \
5258 BBB\
5259 CCC
5260
5261 #define CNT \
5262 1 + \
5263 2 + \
5264 4
5265 /* end of define */
5266
5267 [CODE]
5268
5269 call assert_equal(expected, getline(1, '$'))
5270 enew! | close
5271endfunc
5272
5273func Test_cindent_56()
5274 new
5275 setl cindent ts=4 sw=4
5276 setl cino&
5277
5278 let code =<< trim [CODE]
5279 {
5280 a = second/*bug*/*line;
5281 }
5282 [CODE]
5283
5284 call append(0, code)
5285 normal gg
5286 call search('a = second')
5287 normal ox
5288
5289 let expected =<< trim [CODE]
5290 {
5291 a = second/*bug*/*line;
5292 x
5293 }
5294
5295 [CODE]
5296
5297 call assert_equal(expected, getline(1, '$'))
5298 enew! | close
5299endfunc
5300
Bram Moolenaar02ad4632020-01-12 13:48:18 +01005301" this was going beyond the end of the line.
5302func Test_cindent_case()
5303 new
Bram Moolenaar4b96df52020-01-26 22:00:26 +01005304 call setline(1, 'case x: // x')
Bram Moolenaar02ad4632020-01-12 13:48:18 +01005305 set cindent
5306 norm! f:a:
Bram Moolenaar4b96df52020-01-26 22:00:26 +01005307 call assert_equal('case x:: // x', getline(1))
Bram Moolenaar4b96df52020-01-26 22:00:26 +01005308 set cindent&
Bram Moolenaar02ad4632020-01-12 13:48:18 +01005309 bwipe!
5310endfunc
5311
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01005312" Test for changing multiple lines (using c) with cindent
5313func Test_cindent_change_multline()
5314 new
5315 setlocal cindent
5316 call setline(1, ['if (a)', '{', ' i = 1;', '}'])
5317 normal! jc3jm = 2;
5318 call assert_equal("\tm = 2;", getline(2))
5319 close!
5320endfunc
5321
Bram Moolenaar60ae0e72022-05-16 18:06:15 +01005322" This was reading past the end of the line
5323func Test_cindent_check_funcdecl()
5324 new
5325 sil norm o0('\0=L
5326 bwipe!
5327endfunc
5328
Tom Praschan3506cf32022-04-07 12:39:08 +01005329func Test_cindent_scopedecls()
5330 new
5331 setl cindent ts=4 sw=4
5332 setl cino=g0
5333 setl cinsd+=public\ slots,signals
5334
5335 let code =<< trim [CODE]
5336 class Foo
5337 {
5338 public:
5339 virtual void foo() = 0;
5340 public slots:
5341 void onBar();
5342 signals:
5343 void baz();
5344 private:
5345 int x;
5346 };
5347 [CODE]
5348
5349 call append(0, code)
5350 normal gg
5351 normal ]]=][
5352
5353 let expected =<< trim [CODE]
5354 class Foo
5355 {
5356 public:
5357 virtual void foo() = 0;
5358 public slots:
5359 void onBar();
5360 signals:
5361 void baz();
5362 private:
5363 int x;
5364 };
5365
5366 [CODE]
5367
5368 call assert_equal(expected, getline(1, '$'))
5369 enew! | close
5370endfunc
5371
Bram Moolenaard881b512020-05-31 17:49:30 +02005372func Test_cindent_pragma()
5373 new
5374 setl cindent ts=4 sw=4
5375 setl cino=Ps
5376
5377 let code =<< trim [CODE]
5378 {
5379 #pragma omp parallel
5380 {
5381 #pragma omp task
5382 foo();
5383 # pragma omp taskwait
5384 }
5385 }
5386 [CODE]
5387
5388 call append(0, code)
5389 normal gg
5390 normal =G
5391
5392 let expected =<< trim [CODE]
5393 {
5394 #pragma omp parallel
5395 {
5396 #pragma omp task
5397 foo();
5398 # pragma omp taskwait
5399 }
5400 }
5401
5402 [CODE]
5403
5404 call assert_equal(expected, getline(1, '$'))
5405 enew! | close
5406endfunc
5407
Bram Moolenaar78e0fa42021-10-05 21:58:53 +01005408func Test_backslash_at_end_of_line()
5409 new
5410 exe "norm v>O'\\\<C-m>-"
5411 exe "norm \<C-q>="
5412 bwipe!
5413endfunc
5414
Bram Moolenaar2de9b7c2021-11-19 19:41:13 +00005415func Test_find_brace_backwards()
5416 " this was looking beyond the end of the line
5417 new
5418 norm R/*
5419 norm o0{
5420 norm o//
5421 norm V{=
5422 call assert_equal(['/*', ' 0{', '//'], getline(1, 3))
5423 bwipe!
5424endfunc
5425
5426
Bram Moolenaar7720ba82017-03-08 22:19:26 +01005427" vim: shiftwidth=2 sts=2 expandtab