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