Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1 | /* vim: set cin ts=4 sw=4 : */ |
| 2 | |
| 3 | Test for 'cindent' |
| 4 | |
| 5 | STARTTEST |
| 6 | :so small.vim |
Bram Moolenaar | 8c8de83 | 2008-06-24 22:58:06 +0000 | [diff] [blame] | 7 | :set nocompatible viminfo+=nviminfo modeline |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8 | :edit " read modeline |
| 9 | /start of AUTO |
| 10 | =/end of AUTO |
| 11 | ENDTEST |
| 12 | |
Bram Moolenaar | 9e54a0e | 2006-04-14 20:42:25 +0000 | [diff] [blame] | 13 | /* start of AUTO matically checked vim: set ts=4 : */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 14 | { |
| 15 | if (test) |
| 16 | cmd1; |
| 17 | cmd2; |
| 18 | } |
| 19 | |
| 20 | { |
| 21 | if (test) |
| 22 | cmd1; |
| 23 | else |
| 24 | cmd2; |
| 25 | } |
| 26 | |
| 27 | { |
| 28 | if (test) |
| 29 | { |
| 30 | cmd1; |
| 31 | cmd2; |
| 32 | } |
| 33 | } |
| 34 | |
| 35 | { |
| 36 | if (test) |
| 37 | { |
| 38 | cmd1; |
| 39 | else |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | { |
| 44 | while (this) |
| 45 | if (test) |
| 46 | cmd1; |
| 47 | cmd2; |
| 48 | } |
| 49 | |
| 50 | { |
| 51 | while (this) |
| 52 | if (test) |
| 53 | cmd1; |
| 54 | else |
| 55 | cmd2; |
| 56 | } |
| 57 | |
| 58 | { |
| 59 | if (test) |
| 60 | { |
| 61 | cmd; |
| 62 | } |
| 63 | |
| 64 | if (test) |
| 65 | cmd; |
| 66 | } |
| 67 | |
| 68 | { |
| 69 | if (test) { |
| 70 | cmd; |
| 71 | } |
| 72 | |
| 73 | if (test) cmd; |
| 74 | } |
| 75 | |
| 76 | { |
| 77 | cmd1; |
| 78 | for (blah) |
| 79 | while (this) |
| 80 | if (test) |
| 81 | cmd2; |
| 82 | cmd3; |
| 83 | } |
| 84 | |
| 85 | { |
| 86 | cmd1; |
| 87 | for (blah) |
| 88 | while (this) |
| 89 | if (test) |
| 90 | cmd2; |
| 91 | cmd3; |
| 92 | |
| 93 | if (test) |
| 94 | { |
| 95 | cmd1; |
| 96 | cmd2; |
| 97 | cmd3; |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | |
| 102 | /* Test for 'cindent' do/while mixed with if/else: */ |
| 103 | |
| 104 | { |
| 105 | do |
| 106 | if (asdf) |
| 107 | asdfasd; |
| 108 | while (cond); |
| 109 | |
| 110 | do |
| 111 | if (asdf) |
| 112 | while (asdf) |
| 113 | asdf; |
| 114 | while (asdf); |
| 115 | } |
| 116 | |
| 117 | /* Test for 'cindent' with two ) on a continuation line */ |
| 118 | { |
| 119 | if (asdfasdf;asldkfj asdlkfj as;ldkfj sal;d |
| 120 | aal;sdkjf ( ;asldfkja;sldfk |
| 121 | al;sdjfka ;slkdf ) sa;ldkjfsa dlk;) |
| 122 | line up here; |
| 123 | } |
| 124 | |
| 125 | |
| 126 | /* C++ tests: */ |
| 127 | |
| 128 | // foo() these three lines should remain in column 0 |
| 129 | // { |
| 130 | // } |
| 131 | |
| 132 | /* Test for continuation and unterminated lines: */ |
| 133 | { |
| 134 | i = 99 + 14325 + |
| 135 | 21345 + |
| 136 | 21345 + |
| 137 | 21345 + ( 21345 + |
| 138 | 21345) + |
| 139 | 2345 + |
| 140 | 1234; |
| 141 | c = 1; |
| 142 | } |
| 143 | |
| 144 | /* |
| 145 | testje for indent with empty line |
| 146 | |
| 147 | here */ |
| 148 | |
| 149 | { |
| 150 | if (testing && |
| 151 | not a joke || |
| 152 | line up here) |
| 153 | hay; |
| 154 | if (testing && |
| 155 | (not a joke || testing |
| 156 | )line up here) |
| 157 | hay; |
| 158 | if (testing && |
| 159 | (not a joke || testing |
| 160 | line up here)) |
| 161 | hay; |
| 162 | } |
| 163 | |
| 164 | |
| 165 | { |
| 166 | switch (c) |
| 167 | { |
| 168 | case xx: |
| 169 | do |
| 170 | if (asdf) |
| 171 | do |
| 172 | asdfasdf; |
| 173 | while (asdf); |
| 174 | else |
| 175 | asdfasdf; |
| 176 | while (cond); |
| 177 | case yy: |
| 178 | case xx: |
| 179 | case zz: |
| 180 | testing; |
| 181 | } |
| 182 | } |
| 183 | |
| 184 | { |
| 185 | if (cond) { |
| 186 | foo; |
| 187 | } |
| 188 | else |
| 189 | { |
| 190 | bar; |
| 191 | } |
| 192 | } |
| 193 | |
| 194 | { |
| 195 | if (alskdfj ;alsdkfjal;skdjf (;sadlkfsa ;dlkf j;alksdfj ;alskdjf |
| 196 | alsdkfj (asldk;fj |
| 197 | awith cino=(0 ;lf this one goes to below the paren with == |
| 198 | ;laksjfd ;lsakdjf ;alskdf asd) |
| 199 | asdfasdf;))) |
| 200 | asdfasdf; |
| 201 | } |
| 202 | |
| 203 | int |
| 204 | func(a, b) |
| 205 | int a; |
| 206 | int c; |
| 207 | { |
| 208 | if (c1 && (c2 || |
| 209 | c3)) |
| 210 | foo; |
| 211 | if (c1 && |
| 212 | (c2 || c3) |
| 213 | ) |
| 214 | } |
| 215 | |
| 216 | { |
| 217 | while (asd) |
| 218 | { |
| 219 | if (asdf) |
| 220 | if (test) |
| 221 | if (that) |
| 222 | { |
| 223 | if (asdf) |
| 224 | do |
| 225 | cdasd; |
| 226 | while (as |
| 227 | df); |
| 228 | } |
| 229 | else |
| 230 | if (asdf) |
| 231 | asdf; |
| 232 | else |
| 233 | asdf; |
| 234 | asdf; |
| 235 | } |
| 236 | } |
| 237 | |
| 238 | { |
| 239 | s = "/*"; b = ';' |
| 240 | s = "/*"; b = ';'; |
| 241 | a = b; |
| 242 | } |
| 243 | |
| 244 | { |
| 245 | switch (a) |
| 246 | { |
| 247 | case a: |
| 248 | switch (t) |
| 249 | { |
| 250 | case 1: |
| 251 | cmd; |
| 252 | break; |
| 253 | case 2: |
| 254 | cmd; |
| 255 | break; |
| 256 | } |
| 257 | cmd; |
| 258 | break; |
| 259 | case b: |
| 260 | { |
| 261 | int i; |
| 262 | cmd; |
| 263 | } |
| 264 | break; |
| 265 | case c: { |
| 266 | int i; |
| 267 | cmd; |
| 268 | } |
| 269 | case d: if (cond && |
| 270 | test) { /* this line doesn't work right */ |
| 271 | int i; |
| 272 | cmd; |
| 273 | } |
| 274 | break; |
| 275 | } |
| 276 | } |
| 277 | |
| 278 | { |
| 279 | if (!(vim_strchr(p_cpo, CPO_BUFOPTGLOB) != NULL && entering) && |
| 280 | (bp_to->b_p_initialized || |
| 281 | (!entering && vim_strchr(p_cpo, CPO_BUFOPT) != NULL))) |
| 282 | return; |
| 283 | label : |
| 284 | asdf = asdf ? |
| 285 | asdf : asdf; |
| 286 | asdf = asdf ? |
| 287 | asdf: asdf; |
| 288 | } |
| 289 | |
| 290 | /* Special Comments : This function has the added complexity (compared */ |
| 291 | /* : to addtolist) of having to check for a detail */ |
| 292 | /* : texture and add that to the list first. */ |
| 293 | |
| 294 | char *(array[100]) = { |
| 295 | "testje", |
| 296 | "foo", |
| 297 | "bar", |
| 298 | } |
| 299 | |
| 300 | enum soppie |
| 301 | { |
| 302 | yes = 0, |
| 303 | no, |
| 304 | maybe |
| 305 | }; |
| 306 | |
| 307 | typedef enum soppie |
| 308 | { |
| 309 | yes = 0, |
| 310 | no, |
| 311 | maybe |
| 312 | }; |
| 313 | |
| 314 | { |
| 315 | int a, |
| 316 | b; |
| 317 | } |
| 318 | |
| 319 | { |
| 320 | struct Type |
| 321 | { |
| 322 | int i; |
| 323 | char *str; |
| 324 | } var[] = |
| 325 | { |
| 326 | 0, "zero", |
| 327 | 1, "one", |
| 328 | 2, "two", |
| 329 | 3, "three" |
| 330 | }; |
| 331 | |
| 332 | float matrix[3][3] = |
| 333 | { |
| 334 | { |
| 335 | 0, |
| 336 | 1, |
| 337 | 2 |
| 338 | }, |
| 339 | { |
| 340 | 3, |
| 341 | 4, |
| 342 | 5 |
| 343 | }, |
| 344 | { |
| 345 | 6, |
| 346 | 7, |
| 347 | 8 |
| 348 | } |
| 349 | }; |
| 350 | } |
| 351 | |
| 352 | { |
| 353 | /* blah ( blah */ |
| 354 | /* where does this go? */ |
| 355 | |
| 356 | /* blah ( blah */ |
| 357 | cmd; |
| 358 | |
| 359 | func(arg1, |
| 360 | /* comment */ |
| 361 | arg2); |
| 362 | a; |
| 363 | { |
| 364 | b; |
| 365 | { |
| 366 | c; /* Hey, NOW it indents?! */ |
| 367 | } |
| 368 | } |
| 369 | |
| 370 | { |
| 371 | func(arg1, |
| 372 | arg2, |
| 373 | arg3); |
| 374 | /* Hey, what am I doing here? Is this coz of the ","? */ |
| 375 | } |
| 376 | } |
| 377 | |
| 378 | main () |
| 379 | { |
| 380 | if (cond) |
| 381 | { |
| 382 | a = b; |
| 383 | } |
| 384 | if (cond) { |
| 385 | a = c; |
| 386 | } |
| 387 | if (cond) |
| 388 | a = d; |
| 389 | return; |
| 390 | } |
| 391 | |
| 392 | { |
| 393 | case 2: if (asdf && |
| 394 | asdfasdf) |
| 395 | aasdf; |
| 396 | a = 9; |
| 397 | case 3: if (asdf) |
| 398 | aasdf; |
| 399 | a = 9; |
| 400 | case 4: x = 1; |
| 401 | y = 2; |
| 402 | |
| 403 | label: if (asdf) |
| 404 | here; |
| 405 | |
| 406 | label: if (asdf && |
| 407 | asdfasdf) |
| 408 | { |
| 409 | } |
| 410 | |
| 411 | label: if (asdf && |
| 412 | asdfasdf) { |
| 413 | there; |
| 414 | } |
| 415 | |
| 416 | label: if (asdf && |
| 417 | asdfasdf) |
| 418 | there; |
| 419 | } |
| 420 | |
| 421 | { |
| 422 | /* |
| 423 | hello with ":set comments= cino=c5" |
| 424 | */ |
| 425 | |
| 426 | /* |
| 427 | hello with ":set comments= cino=" |
| 428 | */ |
| 429 | } |
| 430 | |
| 431 | |
| 432 | { |
| 433 | if (a < b) { |
| 434 | a = a + 1; |
| 435 | } else |
| 436 | a = a + 2; |
| 437 | |
| 438 | if (a) |
| 439 | do { |
| 440 | testing; |
| 441 | } while (asdfasdf); |
| 442 | a = b + 1; |
| 443 | asdfasdf |
| 444 | } |
| 445 | |
| 446 | class bob |
| 447 | { |
| 448 | int foo() {return 1;} |
| 449 | int bar; |
| 450 | } |
| 451 | |
| 452 | main() |
| 453 | { |
| 454 | while(1) |
| 455 | if (foo) |
| 456 | { |
| 457 | bar; |
| 458 | } |
| 459 | else { |
| 460 | asdf; |
| 461 | } |
| 462 | misplacedline; |
| 463 | } |
| 464 | |
| 465 | { |
| 466 | if (clipboard.state == SELECT_DONE |
| 467 | && ((row == clipboard.start.lnum |
| 468 | && col >= clipboard.start.col) |
| 469 | || row > clipboard.start.lnum)) |
| 470 | } |
| 471 | |
| 472 | { |
| 473 | if (1) {i += 4;} |
| 474 | where_am_i; |
| 475 | return 0; |
| 476 | } |
| 477 | |
| 478 | { |
| 479 | { |
| 480 | } // sdf(asdf |
| 481 | if (asdf) |
| 482 | asd; |
| 483 | } |
| 484 | |
| 485 | { |
| 486 | label1: |
| 487 | label2: |
| 488 | } |
| 489 | |
| 490 | { |
| 491 | int fooRet = foo(pBar1, false /*fKB*/, |
| 492 | true /*fPTB*/, 3 /*nT*/, false /*fDF*/); |
| 493 | f() { |
| 494 | for ( i = 0; |
| 495 | i < m; |
| 496 | /* c */ i++ ) { |
| 497 | a = b; |
| 498 | } |
| 499 | } |
| 500 | } |
| 501 | |
| 502 | { |
| 503 | f1(/*comment*/); |
| 504 | f2(); |
| 505 | } |
| 506 | |
| 507 | { |
| 508 | do { |
| 509 | if (foo) { |
| 510 | } else |
| 511 | ; |
| 512 | } while (foo); |
| 513 | foo(); // was wrong |
| 514 | } |
| 515 | |
| 516 | int x; // no extra indent because of the ; |
| 517 | void func() |
| 518 | { |
| 519 | } |
| 520 | |
| 521 | char *tab[] = {"aaa", |
| 522 | "};", /* }; */ NULL} |
| 523 | int indented; |
| 524 | {} |
| 525 | |
| 526 | char *a[] = {"aaa", "bbb", |
| 527 | "ccc", NULL}; |
| 528 | // here |
| 529 | |
| 530 | char *tab[] = {"aaa", |
| 531 | "xx", /* xx */}; /* asdf */ |
| 532 | int not_indented; |
| 533 | |
| 534 | { |
| 535 | do { |
| 536 | switch (bla) |
| 537 | { |
| 538 | case 1: if (foo) |
| 539 | bar; |
| 540 | } |
| 541 | } while (boo); |
| 542 | wrong; |
| 543 | } |
| 544 | |
| 545 | int foo, |
| 546 | bar; |
| 547 | int foo; |
| 548 | |
| 549 | #if defined(foo) \ |
| 550 | && defined(bar) |
| 551 | char * xx = "asdf\ |
| 552 | foo\ |
| 553 | bor"; |
| 554 | int x; |
| 555 | |
| 556 | char *foo = "asdf\ |
| 557 | asdf\ |
| 558 | asdf", |
| 559 | *bar; |
| 560 | |
| 561 | void f() |
| 562 | { |
| 563 | #if defined(foo) \ |
| 564 | && defined(bar) |
| 565 | char *foo = "asdf\ |
| 566 | asdf\ |
| 567 | asdf", |
| 568 | *bar; |
| 569 | { |
| 570 | int i; |
| 571 | char *foo = "asdf\ |
| 572 | asdf\ |
| 573 | asdf", |
| 574 | *bar; |
| 575 | } |
| 576 | #endif |
| 577 | } |
| 578 | #endif |
| 579 | |
| 580 | int y; // comment |
| 581 | // comment |
| 582 | |
| 583 | // comment |
| 584 | |
| 585 | { |
| 586 | Constructor(int a, |
| 587 | int b ) : BaseClass(a) |
| 588 | { |
| 589 | } |
| 590 | } |
| 591 | |
| 592 | void foo() |
| 593 | { |
| 594 | char one, |
| 595 | two; |
| 596 | struct bla piet, |
| 597 | jan; |
| 598 | enum foo kees, |
| 599 | jannie; |
| 600 | static unsigned sdf, |
| 601 | krap; |
| 602 | unsigned int piet, |
| 603 | jan; |
| 604 | int |
| 605 | kees, |
| 606 | jan; |
| 607 | } |
| 608 | |
| 609 | { |
| 610 | t(int f, |
| 611 | int d); // ) |
| 612 | d(); |
| 613 | } |
| 614 | |
| 615 | Constructor::Constructor(int a, |
| 616 | int b |
| 617 | ) : |
| 618 | BaseClass(a, |
| 619 | b, |
| 620 | c), |
| 621 | mMember(b), |
| 622 | { |
| 623 | } |
| 624 | |
| 625 | Constructor::Constructor(int a, |
| 626 | int b ) : |
| 627 | BaseClass(a) |
| 628 | { |
| 629 | } |
| 630 | |
| 631 | Constructor::Constructor(int a, |
| 632 | int b ) /*x*/ : /*x*/ BaseClass(a), |
| 633 | member(b) |
| 634 | { |
| 635 | } |
| 636 | |
| 637 | class CAbc : |
| 638 | public BaseClass1, |
| 639 | protected BaseClass2 |
| 640 | { |
| 641 | int Test() { return FALSE; } |
| 642 | int Test1() { return TRUE; } |
| 643 | |
| 644 | CAbc(int a, int b ) : |
| 645 | BaseClass(a) |
| 646 | { |
| 647 | switch(xxx) |
| 648 | { |
| 649 | case abc: |
| 650 | asdf(); |
| 651 | break; |
| 652 | |
| 653 | case 999: |
| 654 | baer(); |
| 655 | break; |
| 656 | } |
| 657 | } |
| 658 | |
| 659 | public: // <-- this was incoreectly indented before!! |
| 660 | void testfall(); |
| 661 | protected: |
| 662 | void testfall(); |
| 663 | }; |
| 664 | |
| 665 | class CAbc : public BaseClass1, |
| 666 | protected BaseClass2 |
| 667 | { |
| 668 | }; |
| 669 | |
| 670 | static struct |
| 671 | { |
| 672 | int a; |
| 673 | int b; |
| 674 | } variable[COUNT] = |
| 675 | { |
| 676 | { |
| 677 | 123, |
| 678 | 456 |
| 679 | }, |
| 680 | { |
| 681 | 123, |
| 682 | 456 |
| 683 | } |
| 684 | }; |
| 685 | |
| 686 | static struct |
| 687 | { |
| 688 | int a; |
| 689 | int b; |
| 690 | } variable[COUNT] = |
| 691 | { |
| 692 | { 123, 456 }, |
| 693 | { 123, 456 } |
| 694 | }; |
| 695 | |
| 696 | void asdf() /* ind_maxparen may cause trouble here */ |
| 697 | { |
| 698 | if ((0 |
| 699 | && 1 |
| 700 | && 1 |
| 701 | && 1 |
| 702 | && 1 |
| 703 | && 1 |
| 704 | && 1 |
| 705 | && 1 |
| 706 | && 1 |
| 707 | && 1 |
| 708 | && 1 |
| 709 | && 1 |
| 710 | && 1 |
| 711 | && 1 |
| 712 | && 1 |
| 713 | && 1 |
| 714 | && 1 |
| 715 | && 1 |
| 716 | && 1 |
| 717 | && 1 |
| 718 | && 1 |
| 719 | && 1 |
| 720 | && 1 |
| 721 | && 1 |
| 722 | && 1 |
| 723 | && 1)) break; |
| 724 | } |
| 725 | |
Bram Moolenaar | 18144c8 | 2006-04-12 21:52:12 +0000 | [diff] [blame] | 726 | foo() |
| 727 | { |
| 728 | a = cond ? foo() : asdf |
| 729 | + asdf; |
| 730 | |
| 731 | a = cond ? |
| 732 | foo() : asdf |
| 733 | + asdf; |
| 734 | } |
| 735 | |
| 736 | int main(void) |
| 737 | { |
| 738 | if (a) |
| 739 | if (b) |
| 740 | 2; |
| 741 | else 3; |
| 742 | next_line_of_code(); |
| 743 | } |
| 744 | |
Bram Moolenaar | 7fc904b | 2006-04-13 20:37:35 +0000 | [diff] [blame] | 745 | barry() |
| 746 | { |
| 747 | Foo::Foo (int one, |
| 748 | int two) |
| 749 | : something(4) |
| 750 | {} |
| 751 | } |
| 752 | |
| 753 | barry() |
| 754 | { |
| 755 | Foo::Foo (int one, int two) |
| 756 | : something(4) |
| 757 | {} |
| 758 | } |
| 759 | |
| 760 | Constructor::Constructor(int a, |
| 761 | int b |
| 762 | ) : |
| 763 | BaseClass(a, |
| 764 | b, |
| 765 | c), |
| 766 | mMember(b) |
| 767 | { |
| 768 | } |
Bram Moolenaar | 9e54a0e | 2006-04-14 20:42:25 +0000 | [diff] [blame] | 769 | int main () |
| 770 | { |
| 771 | if (lala) |
| 772 | do |
| 773 | ++(*lolo); |
| 774 | while (lili |
| 775 | && lele); |
| 776 | lulu; |
| 777 | } |
Bram Moolenaar | 7fc904b | 2006-04-13 20:37:35 +0000 | [diff] [blame] | 778 | |
Bram Moolenaar | 9e54a0e | 2006-04-14 20:42:25 +0000 | [diff] [blame] | 779 | int main () |
| 780 | { |
| 781 | switch (c) |
| 782 | { |
| 783 | case 'c': if (cond) |
| 784 | { |
| 785 | } |
| 786 | } |
| 787 | } |
| 788 | |
| 789 | main() |
| 790 | { |
| 791 | (void) MyFancyFuasdfadsfnction( |
| 792 | argument); |
| 793 | } |
| 794 | |
| 795 | main() |
| 796 | { |
| 797 | char foo[] = "/*"; |
| 798 | /* as |
| 799 | df */ |
| 800 | hello |
| 801 | } |
Bram Moolenaar | ed38b0a | 2011-05-25 15:16:18 +0200 | [diff] [blame^] | 802 | |
| 803 | /* valid namespaces with normal indent */ |
| 804 | namespace |
| 805 | { |
| 806 | { |
| 807 | 111111111111; |
| 808 | } |
| 809 | } |
| 810 | namespace /* test */ |
| 811 | { |
| 812 | 11111111111111111; |
| 813 | } |
| 814 | namespace // test |
| 815 | { |
| 816 | 111111111111111111; |
| 817 | } |
| 818 | namespace |
| 819 | { |
| 820 | 111111111111111111; |
| 821 | } |
| 822 | namespace test |
| 823 | { |
| 824 | 111111111111111111; |
| 825 | } |
| 826 | namespace{ |
| 827 | 111111111111111111; |
| 828 | } |
| 829 | namespace test{ |
| 830 | 111111111111111111; |
| 831 | } |
| 832 | namespace { |
| 833 | 111111111111111111; |
| 834 | } |
| 835 | namespace test { |
| 836 | 111111111111111111; |
| 837 | namespace test2 { |
| 838 | 22222222222222222; |
| 839 | } |
| 840 | } |
| 841 | |
| 842 | /* invalid namespaces use block indent */ |
| 843 | namespace test test2 { |
| 844 | 111111111111111111111; |
| 845 | } |
| 846 | namespace11111111111 { |
| 847 | 111111111111; |
| 848 | } |
| 849 | namespace() { |
| 850 | 1111111111111; |
| 851 | } |
| 852 | namespace() |
| 853 | { |
| 854 | 111111111111111111; |
| 855 | } |
| 856 | namespace test test2 |
| 857 | { |
| 858 | 1111111111111111111; |
| 859 | } |
| 860 | namespace111111111 |
| 861 | { |
| 862 | 111111111111111111; |
| 863 | } |
| 864 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 865 | /* end of AUTO */ |
| 866 | |
| 867 | STARTTEST |
| 868 | :set tw=0 wm=60 columns=80 noai fo=croq |
| 869 | /serious/e |
| 870 | a about life, the universe, and the rest |
| 871 | ENDTEST |
| 872 | |
| 873 | { |
| 874 | |
| 875 | /* this is |
| 876 | * a real serious important big |
| 877 | * comment |
| 878 | */ |
| 879 | /* insert " about life, the universe, and the rest" after "serious" */ |
| 880 | } |
| 881 | |
| 882 | STARTTEST |
| 883 | :set nocin |
| 884 | /comments |
| 885 | joabout life/happens |
| 886 | jothere/below |
| 887 | oline/this |
| 888 | Ohello |
| 889 | ENDTEST |
| 890 | |
| 891 | { |
| 892 | /* |
| 893 | * Testing for comments, without 'cin' set |
| 894 | */ |
| 895 | |
| 896 | /* |
| 897 | * what happens here? |
| 898 | */ |
| 899 | |
| 900 | /* |
| 901 | the end of the comment, try inserting a line below */ |
| 902 | |
| 903 | /* how about |
| 904 | this one */ |
| 905 | } |
| 906 | |
| 907 | STARTTEST |
| 908 | :set cin |
| 909 | /vec2 |
| 910 | == |
| 911 | ENDTEST |
| 912 | |
| 913 | { |
| 914 | var = this + that + vec[0] * vec[0] |
| 915 | + vec[1] * vec[1] |
| 916 | + vec2[2] * vec[2]; |
| 917 | } |
| 918 | |
| 919 | STARTTEST |
| 920 | :set cin |
| 921 | :set cino=}4 |
| 922 | /testing1 |
| 923 | k2==/testing2 |
| 924 | k2== |
| 925 | ENDTEST |
| 926 | |
| 927 | { |
| 928 | asdf asdflkajds f; |
| 929 | if (tes & ting) { |
| 930 | asdf asdf asdf ; |
| 931 | asdfa sdf asdf; |
| 932 | } |
| 933 | testing1; |
| 934 | if (tes & ting) |
| 935 | { |
| 936 | asdf asdf asdf ; |
| 937 | asdfa sdf asdf; |
| 938 | } |
| 939 | testing2; |
| 940 | } |
| 941 | |
| 942 | STARTTEST |
| 943 | :set cin |
| 944 | :set cino=(0,)20 |
| 945 | /main |
| 946 | =][ |
| 947 | ENDTEST |
| 948 | |
| 949 | main ( int first_par, /* |
| 950 | * Comment for |
| 951 | * first par |
| 952 | */ |
| 953 | int second_par /* |
| 954 | * Comment for |
| 955 | * second par |
| 956 | */ |
| 957 | ) |
| 958 | { |
| 959 | func( first_par, /* |
| 960 | * Comment for |
| 961 | * first par |
| 962 | */ |
| 963 | second_par /* |
| 964 | * Comment for |
| 965 | * second par |
| 966 | */ |
| 967 | ); |
| 968 | |
| 969 | } |
| 970 | |
| 971 | STARTTEST |
| 972 | :set cin |
| 973 | :set cino= |
| 974 | ]]=][ |
| 975 | ENDTEST |
| 976 | |
| 977 | { |
| 978 | do |
| 979 | { |
| 980 | if () |
| 981 | { |
| 982 | if () |
| 983 | asdf; |
| 984 | else |
| 985 | asdf; |
| 986 | } |
| 987 | } while (); |
| 988 | cmd; /* this should go under the } */ |
| 989 | } |
| 990 | |
| 991 | STARTTEST |
| 992 | ]]=][ |
| 993 | ENDTEST |
| 994 | |
| 995 | void f() |
| 996 | { |
| 997 | if ( k() ) { |
| 998 | l(); |
| 999 | |
| 1000 | } else { /* Start (two words) end */ |
| 1001 | m(); |
| 1002 | } |
| 1003 | |
| 1004 | n(); |
| 1005 | } |
| 1006 | |
| 1007 | STARTTEST |
| 1008 | :set cino={s,e-s |
| 1009 | ]]=][ |
| 1010 | ENDTEST |
| 1011 | |
| 1012 | void f() |
| 1013 | { |
| 1014 | if ( k() ) |
| 1015 | { |
| 1016 | l(); |
| 1017 | } else { /* Start (two words) end */ |
| 1018 | m(); |
| 1019 | } |
| 1020 | n(); /* should be under the if () */ |
| 1021 | } |
| 1022 | |
| 1023 | STARTTEST |
| 1024 | :set cino={s,fs |
| 1025 | ]]=/ foo |
| 1026 | ENDTEST |
| 1027 | |
| 1028 | void bar(void) |
| 1029 | { |
| 1030 | static array[2][2] = |
| 1031 | { |
| 1032 | { 1, 2 }, |
| 1033 | { 3, 4 }, |
| 1034 | } |
| 1035 | |
| 1036 | while (a) |
| 1037 | { |
| 1038 | foo(&a); |
| 1039 | } |
| 1040 | |
| 1041 | { |
| 1042 | int a; |
| 1043 | { |
| 1044 | a = a + 1; |
| 1045 | } |
| 1046 | } |
| 1047 | b = a; |
| 1048 | } |
| 1049 | |
| 1050 | void func(void) |
| 1051 | { |
| 1052 | a = 1; |
| 1053 | { |
| 1054 | b = 2; |
| 1055 | } |
| 1056 | c = 3; |
| 1057 | d = 4; |
| 1058 | } |
| 1059 | /* foo */ |
| 1060 | |
| 1061 | STARTTEST |
| 1062 | :set cino= |
| 1063 | /while |
| 1064 | ohere |
| 1065 | ENDTEST |
| 1066 | |
| 1067 | a() |
| 1068 | { |
| 1069 | do { |
| 1070 | a = a + |
| 1071 | a; |
| 1072 | } while ( a ); /* add text under this line */ |
| 1073 | if ( a ) |
| 1074 | a; |
| 1075 | } |
| 1076 | |
| 1077 | STARTTEST |
| 1078 | :set cino= com= |
| 1079 | /comment |
| 1080 | olabel2: b();
label3 /* post */:
/* pre */ label4:
f(/*com*/);
if (/*com*/)
cmd(); |
| 1081 | ENDTEST |
| 1082 | |
| 1083 | a() |
| 1084 | { |
| 1085 | label1: |
| 1086 | /* hmm */ |
| 1087 | // comment |
| 1088 | } |
| 1089 | |
| 1090 | STARTTEST |
| 1091 | :set comments& comments^=s:/*,m:**,ex:*/ |
| 1092 | /simple |
| 1093 | =5j |
| 1094 | ENDTEST |
| 1095 | |
| 1096 | /* |
| 1097 | * A simple comment |
| 1098 | */ |
| 1099 | |
| 1100 | /* |
| 1101 | ** A different comment |
| 1102 | */ |
| 1103 | |
| 1104 | STARTTEST |
| 1105 | :set cino=c0 |
| 1106 | :set comments& comments-=s1:/* comments^=s0:/* |
| 1107 | 2kdd]]=][ |
| 1108 | ENDTEST |
| 1109 | |
| 1110 | void f() |
| 1111 | { |
| 1112 | |
| 1113 | /********* |
| 1114 | A comment. |
| 1115 | *********/ |
| 1116 | } |
| 1117 | |
| 1118 | STARTTEST |
| 1119 | :set cino=c0,C1 |
| 1120 | :set comments& comments-=s1:/* comments^=s0:/* |
| 1121 | 2kdd]]=][ |
| 1122 | ENDTEST |
| 1123 | |
| 1124 | void f() |
| 1125 | { |
| 1126 | |
| 1127 | /********* |
| 1128 | A comment. |
| 1129 | *********/ |
| 1130 | } |
| 1131 | |
| 1132 | STARTTEST |
| 1133 | :set cino= |
| 1134 | ]]=][ |
| 1135 | ENDTEST |
| 1136 | |
| 1137 | void f() |
| 1138 | { |
| 1139 | c = c1 && |
| 1140 | ( |
| 1141 | c2 || |
| 1142 | c3 |
| 1143 | ) && c4; |
| 1144 | } |
| 1145 | |
| 1146 | STARTTEST |
| 1147 | :set cino=(s |
| 1148 | 2kdd]]=][ |
| 1149 | ENDTEST |
| 1150 | |
| 1151 | void f() |
| 1152 | { |
| 1153 | c = c1 && |
| 1154 | ( |
| 1155 | c2 || |
| 1156 | c3 |
| 1157 | ) && c4; |
| 1158 | } |
| 1159 | |
| 1160 | STARTTEST |
| 1161 | :set cino=(s,U1 |
| 1162 | 2kdd]]=][ |
| 1163 | ENDTEST |
| 1164 | |
| 1165 | void f() |
| 1166 | { |
| 1167 | c = c1 && |
| 1168 | ( |
| 1169 | c2 || |
| 1170 | c3 |
| 1171 | ) && c4; |
| 1172 | } |
| 1173 | |
| 1174 | STARTTEST |
| 1175 | :set cino=(0 |
| 1176 | 2kdd]]=][ |
| 1177 | ENDTEST |
| 1178 | |
| 1179 | void f() |
| 1180 | { |
| 1181 | if ( c1 |
| 1182 | && ( c2 |
| 1183 | || c3)) |
| 1184 | foo; |
| 1185 | } |
| 1186 | |
| 1187 | STARTTEST |
| 1188 | :set cino=(0,w1 |
| 1189 | 2kdd]]=][ |
| 1190 | ENDTEST |
| 1191 | |
| 1192 | void f() |
| 1193 | { |
| 1194 | if ( c1 |
| 1195 | && ( c2 |
| 1196 | || c3)) |
| 1197 | foo; |
| 1198 | } |
| 1199 | |
| 1200 | STARTTEST |
| 1201 | :set cino=(s |
| 1202 | 2kdd]]=][ |
| 1203 | ENDTEST |
| 1204 | |
| 1205 | void f() |
| 1206 | { |
| 1207 | c = c1 && ( |
| 1208 | c2 || |
| 1209 | c3 |
| 1210 | ) && c4; |
| 1211 | if ( |
| 1212 | c1 && c2 |
| 1213 | ) |
| 1214 | foo; |
| 1215 | } |
| 1216 | |
| 1217 | STARTTEST |
| 1218 | :set cino=(s,m1 |
| 1219 | 2kdd]]=][ |
| 1220 | ENDTEST |
| 1221 | |
| 1222 | void f() |
| 1223 | { |
| 1224 | c = c1 && ( |
| 1225 | c2 || |
| 1226 | c3 |
| 1227 | ) && c4; |
| 1228 | if ( |
| 1229 | c1 && c2 |
| 1230 | ) |
| 1231 | foo; |
| 1232 | } |
| 1233 | |
| 1234 | STARTTEST |
| 1235 | :set cino=b1 |
| 1236 | 2kdd]]=][ |
| 1237 | ENDTEST |
| 1238 | |
| 1239 | void f() |
| 1240 | { |
| 1241 | switch (x) |
| 1242 | { |
| 1243 | case 1: |
| 1244 | a = b; |
| 1245 | break; |
| 1246 | default: |
| 1247 | a = 0; |
| 1248 | break; |
| 1249 | } |
| 1250 | } |
| 1251 | |
| 1252 | STARTTEST |
| 1253 | :set cino=(0,W5 |
| 1254 | 2kdd]]=][ |
| 1255 | ENDTEST |
| 1256 | |
| 1257 | void f() |
| 1258 | { |
| 1259 | invokeme( |
| 1260 | argu, |
| 1261 | ment); |
| 1262 | invokeme( |
| 1263 | argu, |
| 1264 | ment |
| 1265 | ); |
| 1266 | invokeme(argu, |
| 1267 | ment |
| 1268 | ); |
| 1269 | } |
| 1270 | |
| 1271 | STARTTEST |
| 1272 | :set cino=/6 |
| 1273 | 2kdd]]=][ |
| 1274 | ENDTEST |
| 1275 | |
| 1276 | void f() |
| 1277 | { |
| 1278 | statement; |
| 1279 | // comment 1 |
| 1280 | // comment 2 |
| 1281 | } |
| 1282 | |
| 1283 | STARTTEST |
| 1284 | :set cino= |
| 1285 | 2kdd]]/comment 1/+1 |
| 1286 | == |
| 1287 | ENDTEST |
| 1288 | |
| 1289 | void f() |
| 1290 | { |
| 1291 | statement; |
| 1292 | // comment 1 |
| 1293 | // comment 2 |
| 1294 | } |
| 1295 | |
| 1296 | STARTTEST |
| 1297 | :set cino=g0 |
| 1298 | 2kdd]]=][ |
| 1299 | ENDTEST |
| 1300 | |
| 1301 | class CAbc |
| 1302 | { |
| 1303 | int Test() { return FALSE; } |
| 1304 | |
| 1305 | public: // comment |
| 1306 | void testfall(); |
| 1307 | protected: |
| 1308 | void testfall(); |
| 1309 | }; |
| 1310 | |
| 1311 | STARTTEST |
Bram Moolenaar | 7fc904b | 2006-04-13 20:37:35 +0000 | [diff] [blame] | 1312 | :set cino=+20 |
| 1313 | 2kdd]]=][ |
| 1314 | ENDTEST |
| 1315 | |
| 1316 | void |
| 1317 | foo() |
| 1318 | { |
| 1319 | if (a) |
| 1320 | { |
| 1321 | } else |
| 1322 | asdf; |
| 1323 | } |
| 1324 | |
| 1325 | STARTTEST |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1326 | :set cino=(0,W2s |
| 1327 | 2kdd]]=][ |
| 1328 | ENDTEST |
| 1329 | |
| 1330 | { |
| 1331 | averylongfunctionnamelongfunctionnameaverylongfunctionname()->asd( |
| 1332 | asdasdf, |
| 1333 | func(asdf, |
| 1334 | asdfadsf), |
| 1335 | asdfasdf |
| 1336 | ); |
| 1337 | |
| 1338 | /* those are ugly, but consequent */ |
| 1339 | |
| 1340 | func()->asd(asdasdf, |
| 1341 | averylongfunctionname( |
| 1342 | abc, |
| 1343 | dec)->averylongfunctionname( |
| 1344 | asdfadsf, |
| 1345 | asdfasdf, |
| 1346 | asdfasdf, |
| 1347 | ), |
| 1348 | func(asdfadf, |
| 1349 | asdfasdf |
| 1350 | ), |
| 1351 | asdasdf |
| 1352 | ); |
| 1353 | |
| 1354 | averylongfunctionnameaverylongfunctionnameavery()->asd(fasdf( |
| 1355 | abc, |
| 1356 | dec)->asdfasdfasdf( |
| 1357 | asdfadsf, |
| 1358 | asdfasdf, |
| 1359 | asdfasdf, |
| 1360 | ), |
| 1361 | func(asdfadf, |
| 1362 | asdfasdf), |
| 1363 | asdasdf |
| 1364 | ); |
| 1365 | } |
| 1366 | |
| 1367 | STARTTEST |
Bram Moolenaar | 9e54a0e | 2006-04-14 20:42:25 +0000 | [diff] [blame] | 1368 | :set cino=M1 |
| 1369 | 2kdd]]=][ |
| 1370 | ENDTEST |
| 1371 | |
| 1372 | int main () |
| 1373 | { |
| 1374 | if (cond1 && |
| 1375 | cond2 |
| 1376 | ) |
| 1377 | foo; |
| 1378 | } |
| 1379 | |
| 1380 | STARTTEST |
Bram Moolenaar | 8d2d71d | 2011-04-28 13:02:09 +0200 | [diff] [blame] | 1381 | :set cino=(0,ts |
| 1382 | 2kdd=][ |
| 1383 | ENDTEST |
| 1384 | |
| 1385 | void func(int a |
| 1386 | #if defined(FOO) |
| 1387 | , int b |
| 1388 | , int c |
| 1389 | #endif |
| 1390 | ) |
| 1391 | { |
| 1392 | } |
| 1393 | |
| 1394 | STARTTEST |
| 1395 | :set cino=(0 |
| 1396 | 2kdd=][ |
| 1397 | ENDTEST |
| 1398 | |
| 1399 | void |
| 1400 | func(int a |
| 1401 | #if defined(FOO) |
| 1402 | , int b |
| 1403 | , int c |
| 1404 | #endif |
| 1405 | ) |
| 1406 | { |
| 1407 | } |
| 1408 | |
| 1409 | STARTTEST |
Bram Moolenaar | 4ae06c1 | 2011-05-10 11:39:19 +0200 | [diff] [blame] | 1410 | :set cino& |
Bram Moolenaar | 496f951 | 2011-05-19 16:35:09 +0200 | [diff] [blame] | 1411 | 2kdd=4][ |
Bram Moolenaar | 4ae06c1 | 2011-05-10 11:39:19 +0200 | [diff] [blame] | 1412 | ENDTEST |
| 1413 | |
| 1414 | void func(void) |
| 1415 | { |
| 1416 | if(x==y) |
| 1417 | if(y==z) |
| 1418 | foo=1; |
| 1419 | else { bar=1; |
| 1420 | baz=2; |
| 1421 | } |
| 1422 | printf("Foo!\n"); |
| 1423 | } |
| 1424 | |
Bram Moolenaar | 496f951 | 2011-05-19 16:35:09 +0200 | [diff] [blame] | 1425 | void func1(void) |
| 1426 | { |
| 1427 | char* tab[] = {"foo", "bar", |
| 1428 | "baz", "quux", |
| 1429 | "this line used", "to be indented incorrectly"}; |
| 1430 | foo(); |
| 1431 | } |
| 1432 | |
| 1433 | void func2(void) |
| 1434 | { |
| 1435 | int tab[] = |
| 1436 | {1, 2, |
| 1437 | 3, 4, |
| 1438 | 5, 6}; |
| 1439 | |
| 1440 | printf("This line used to be indented incorrectly.\n"); |
| 1441 | } |
| 1442 | |
| 1443 | void func3(void) |
| 1444 | { |
| 1445 | int tab[] = { |
| 1446 | 1, 2, |
| 1447 | 3, 4, |
| 1448 | 5, 6}; |
| 1449 | |
| 1450 | printf("Don't you dare indent this line incorrectly!\n); |
| 1451 | } |
| 1452 | |
Bram Moolenaar | 4ae06c1 | 2011-05-10 11:39:19 +0200 | [diff] [blame] | 1453 | STARTTEST |
Bram Moolenaar | aede6ce | 2011-05-10 11:56:30 +0200 | [diff] [blame] | 1454 | :set cino& |
| 1455 | 2kdd=][ |
| 1456 | ENDTEST |
| 1457 | |
| 1458 | void func(void) |
| 1459 | { |
| 1460 | cout << "a" |
| 1461 | << "b" |
| 1462 | << ") :" |
| 1463 | << "c"; |
| 1464 | } |
| 1465 | |
| 1466 | STARTTEST |
Bram Moolenaar | a4271d5 | 2011-05-10 13:38:27 +0200 | [diff] [blame] | 1467 | :set com=s1:/*,m:*,ex:*/ |
| 1468 | ]]3jofoo(); |
| 1469 | ENDTEST |
| 1470 | |
| 1471 | void func(void) |
| 1472 | { |
| 1473 | /* |
| 1474 | * This is a comment. |
| 1475 | */ |
| 1476 | } |
| 1477 | |
| 1478 | STARTTEST |
Bram Moolenaar | 334adf0 | 2011-05-25 13:34:04 +0200 | [diff] [blame] | 1479 | :set cino& |
| 1480 | 2kdd=][ |
| 1481 | ENDTEST |
| 1482 | |
| 1483 | void func(void) |
| 1484 | { |
| 1485 | for (int i = 0; i < 10; ++i) |
| 1486 | if (i & 1) { |
| 1487 | foo(1); |
| 1488 | } else |
| 1489 | foo(0); |
| 1490 | baz(); |
| 1491 | } |
| 1492 | |
| 1493 | STARTTEST |
Bram Moolenaar | ed38b0a | 2011-05-25 15:16:18 +0200 | [diff] [blame^] | 1494 | :set cino=N-s |
| 1495 | /namespaces |
| 1496 | =/^NAMESPACEEND |
| 1497 | ENDTEST |
| 1498 | |
| 1499 | /* valid namespaces with normal indent */ |
| 1500 | namespace |
| 1501 | { |
| 1502 | { |
| 1503 | 111111111111; |
| 1504 | } |
| 1505 | } |
| 1506 | namespace /* test */ |
| 1507 | { |
| 1508 | 11111111111111111; |
| 1509 | } |
| 1510 | namespace // test |
| 1511 | { |
| 1512 | 111111111111111111; |
| 1513 | } |
| 1514 | namespace |
| 1515 | { |
| 1516 | 111111111111111111; |
| 1517 | } |
| 1518 | namespace test |
| 1519 | { |
| 1520 | 111111111111111111; |
| 1521 | } |
| 1522 | namespace{ |
| 1523 | 111111111111111111; |
| 1524 | } |
| 1525 | namespace test{ |
| 1526 | 111111111111111111; |
| 1527 | } |
| 1528 | namespace { |
| 1529 | 111111111111111111; |
| 1530 | } |
| 1531 | namespace test { |
| 1532 | 111111111111111111; |
| 1533 | namespace test2 { |
| 1534 | 22222222222222222; |
| 1535 | } |
| 1536 | } |
| 1537 | |
| 1538 | /* invalid namespaces use block indent */ |
| 1539 | namespace test test2 { |
| 1540 | 111111111111111111111; |
| 1541 | } |
| 1542 | namespace11111111111 { |
| 1543 | 111111111111; |
| 1544 | } |
| 1545 | namespace() { |
| 1546 | 1111111111111; |
| 1547 | } |
| 1548 | namespace() |
| 1549 | { |
| 1550 | 111111111111111111; |
| 1551 | } |
| 1552 | namespace test test2 |
| 1553 | { |
| 1554 | 1111111111111111111; |
| 1555 | } |
| 1556 | namespace111111111 |
| 1557 | { |
| 1558 | 111111111111111111; |
| 1559 | } |
| 1560 | NAMESPACEEND |
| 1561 | |
| 1562 | |
| 1563 | STARTTEST |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1564 | :g/^STARTTEST/.,/^ENDTEST/d |
| 1565 | :1;/start of AUTO/,$wq! test.out |
| 1566 | ENDTEST |