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