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