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