1 /* $NetBSD: lsym_comment.c,v 1.25 2025/01/03 23:37:18 rillig Exp $ */ 2 3 /* 4 * Tests for the token lsym_comment, which starts a comment. 5 * 6 * C11 distinguishes block comments and end-of-line comments. Indent further 7 * distinguishes box comments that are a special kind of block comments. 8 * 9 * See also: 10 * opt_fc1.c 11 * lsym_comment.c 12 */ 13 14 /*- 15 * TODO: systematically test comments 16 * 17 * - starting in column 1, with opt.format_col1_comments (-fc1) 18 * - starting in column 1, without opt.format_col1_comments (-fc1) 19 * - starting in column 9, independent of opt.format_col1_comments (-fc1) 20 * - starting in column 33, the default 21 * - starting in column 65, which is already close to the default right margin 22 * - starting in column 81, spilling into the right margin 23 * 24 * - block comment starting with '/' '*' '-' 25 * - block comment starting with '/' '*' '*' 26 * - block comment starting with '/' '*' '\n' 27 * - end-of-line comment starting with '//' 28 * - end-of-line comment starting with '//x', so without leading space 29 * - block comment starting with '/' '*' 'x', so without leading space 30 * 31 * - block/end-of-line comment to the right of a label 32 * - block/end-of-line comment to the right of code 33 * - block/end-of-line comment to the right of label with code 34 * 35 * - with/without opt.comment_delimiter_on_blank_line (-cdb) 36 * - with/without opt.star_comment_cont (-sc) 37 * - with/without opt.format_block_comments (-fbc) 38 * - with varying opt.max_line_length (32, 64, 80, 140) 39 * - with varying opt.unindent_displace (-d0, -d2, -d-5) 40 * - with varying opt.indent_size (3, 4, 8) 41 * - with varying opt.tabsize (3, 4, 8, 16) 42 * - with varying opt.block_comment_max_line_length (-lc60, -lc78, -lc90) 43 * - with varying opt.comment_column (-c0, -c1, -c33, -c80) 44 * - with varying opt.decl_comment_column (-cd0, -cd1, -cd20, -cd33, -cd80) 45 * - with/without ps.line_has_decl 46 * 47 * - very long comments that overflow the buffer 'com' 48 * - comments that come from save_com 49 * - very long word that already spills over the right margin 50 * - wrap/nowrap comment containing '\n' 51 * - wrap/nowrap comment containing '\f' 52 * - wrap/nowrap comment containing '\t' 53 */ 54 55 //indent input 56 typedef enum x { 57 aaaaaaaaaaaaaaaaaaaaaa = 1 << 0, /* test a */ 58 bbbbbbbbbbbbbbbbb = 1 << 1, /* test b */ 59 cccccccccccccc = 1 << 1, /* test c */ 60 dddddddddddddddddddddddddddddd = 1 << 2 /* test d */ 61 } x; 62 //indent end 63 64 //indent run-equals-input -bbb 65 66 67 //indent input 68 /* See FreeBSD r303597, r303598, r309219, and r309343 */ 69 void 70 t(void) { 71 /* 72 * Old indent wrapped the URL near where this sentence ends. 73 * 74 * https://www.freebsd.org/cgi/man.cgi?query=indent&apropos=0&sektion=0&manpath=FreeBSD+12-current&arch=default&format=html 75 */ 76 77 /* 78 * The default maximum line length for comments is 78, and the 'kk' at 79 * the end makes the line exactly 78 bytes long. 80 * 81 * aaaaaa bbbbbb cccccc dddddd eeeeee ffffff ggggg hhhhh iiiii jjjj kk 82 */ 83 84 /* 85 * Old indent unnecessarily removed the star comment continuation on the next line. 86 * 87 * *test* 88 */ 89 90 /* r309219 Go through linked list, freeing from the malloced (t[-1]) address. */ 91 92 /* r309343 */ 93 } 94 //indent end 95 96 //indent run -bbb 97 /* See FreeBSD r303597, r303598, r309219, and r309343 */ 98 void 99 t(void) 100 { 101 102 /* 103 * Old indent wrapped the URL near where this sentence ends. 104 * 105 * https://www.freebsd.org/cgi/man.cgi?query=indent&apropos=0&sektion=0&manpath=FreeBSD+12-current&arch=default&format=html 106 */ 107 108 /* 109 * The default maximum line length for comments is 78, and the 'kk' at 110 * the end makes the line exactly 78 bytes long. 111 * 112 * aaaaaa bbbbbb cccccc dddddd eeeeee ffffff ggggg hhhhh iiiii jjjj kk 113 */ 114 115 /* 116 * Old indent unnecessarily removed the star comment continuation on 117 * the next line. 118 * 119 * *test* 120 */ 121 122 /* 123 * r309219 Go through linked list, freeing from the malloced (t[-1]) 124 * address. 125 */ 126 127 /* r309343 */ 128 } 129 //indent end 130 131 132 /* 133 * The first Christmas tree is to the right of the code, therefore the comment 134 * is moved to the code comment column; the follow-up lines of that comment 135 * are moved by the same distance, to preserve the internal layout. 136 * 137 * The other Christmas tree is a standalone block comment, therefore the 138 * comment starts in the code column. 139 */ 140 //indent input 141 { 142 if (1) /*- a Christmas tree * 143 *** 144 ***** */ 145 /*- another one * 146 *** 147 ***** */ 148 1; 149 } 150 //indent end 151 152 //indent run -bbb 153 { 154 if (1) /*- a Christmas tree * 155 *** 156 ***** */ 157 /*- another one * 158 *** 159 ***** */ 160 1; 161 } 162 //indent end 163 164 165 /* 166 * The first Christmas tree is to the right of the code, therefore the comment 167 * is moved to the code comment column; the follow-up lines of that comment 168 * are moved by the same distance, to preserve the internal layout. 169 * 170 * The other Christmas tree is a standalone block comment, therefore the 171 * comment starts in the code column. 172 */ 173 //indent input 174 { 175 if (7) { /*- a Christmas tree * 176 *** 177 ***** */ 178 /*- another one * 179 *** 180 ***** */ 181 stmt(); 182 } 183 } 184 //indent end 185 186 //indent run -bbb 187 { 188 if (7) { /*- a Christmas tree * 189 *** 190 ***** */ 191 /*- another one * 192 *** 193 ***** */ 194 stmt(); 195 } 196 } 197 //indent end 198 199 200 //indent input 201 int decl;/*-fixed comment 202 fixed comment*/ 203 //indent end 204 205 //indent run -di0 206 int decl; /*-fixed comment 207 fixed comment*/ 208 //indent end 209 /* 210 * XXX: The second line of the above comment contains 11 spaces in a row, 211 * instead of using as many tabs as possible. 212 */ 213 214 215 //indent input 216 { 217 if (0)/*-first line | 218 second line |*/ 219 ; 220 } 221 //indent end 222 223 //indent run -di0 224 { 225 if (0) /*-first line | 226 second line |*/ 227 ; 228 } 229 //indent end 230 231 232 /* 233 * Ensure that all text of the comment is preserved when the comment is moved 234 * to the right. 235 */ 236 //indent input 237 int decl;/*-fixed comment 238 123456789ab fixed comment*/ 239 //indent end 240 241 //indent run -di0 242 int decl; /*-fixed comment 243 123456789ab fixed comment*/ 244 //indent end 245 246 247 /* 248 * Ensure that all text of the comment is preserved when the comment is moved 249 * to the right. 250 */ 251 //indent input 252 { 253 if(0)/*-first line 254 123456789ab second line |*/ 255 ; 256 } 257 //indent end 258 259 //indent run -di0 260 { 261 if (0) /*-first line 262 123456789ab second line |*/ 263 ; 264 } 265 //indent end 266 267 268 /* 269 * Ensure that all text of the comment is preserved when the comment is moved 270 * to the left. In this case, the internal layout of the comment cannot be 271 * preserved since the second line already starts in column 1. 272 */ 273 //indent input 274 int decl; /*-|fixed comment 275 | minus 12 | 276 | tabs inside | 277 |---| 278 |-----------| 279 tab1+++ tab2--- tab3+++ tab4--- tab5+++ tab6--- tab7+++fixed comment*/ 280 //indent end 281 282 //indent run -di0 283 int decl; /*-|fixed comment 284 | minus 12 | 285 | tabs inside | 286 |---| 287 |-----------| 288 tab1+++ tab2--- tab3+++ tab4--- tab5+++ tab6--- tab7+++fixed comment*/ 289 //indent end 290 291 292 /* 293 * Ensure that all text of the comment is preserved when the comment is moved 294 * to the left. In this case, the internal layout of the comment cannot be 295 * preserved since the second line already starts in column 1. 296 */ 297 //indent input 298 { 299 if(0) /*-|first line 300 | minus 12 | 301 | tabs inside | 302 |---| 303 |-----------| 304 tab1+++ tab2--- tab3+++ tab4--- tab5+++ tab6--- tab7+++fixed comment*/ 305 ; 306 } 307 //indent end 308 309 //indent run -di0 310 { 311 if (0) /*-|first line 312 | minus 12 | 313 | tabs inside | 314 |---| 315 |-----------| 316 tab1+++ tab2--- tab3+++ tab4--- tab5+++ tab6--- tab7+++fixed comment*/ 317 ; 318 } 319 //indent end 320 321 322 /* 323 * Ensure that '{' after a comment is preserved. 324 */ 325 //indent input 326 { 327 if(0)/*comment*/{ 328 } 329 } 330 //indent end 331 332 /* Before 2023-05-11, the comment and the '{' swapped places. */ 333 //indent run 334 { 335 if (0) /* comment */ { 336 } 337 } 338 //indent end 339 340 341 /* 342 * The following comments test line breaking when the comment ends with a 343 * space. 344 */ 345 //indent input 346 /* 456789 123456789 123456789 12345 */ 347 /* 456789 123456789 123456789 123456 */ 348 /* 456789 123456789 123456789 1234567 */ 349 /* 456789 123456789 123456789 12345678 */ 350 /* 456789 123456789 123456789 123456789 */ 351 //indent end 352 353 //indent run -l38 354 /* 456789 123456789 123456789 12345 */ 355 /* 356 * 456789 123456789 123456789 123456 357 */ 358 /* 359 * 456789 123456789 123456789 1234567 360 */ 361 /* 362 * 456789 123456789 123456789 12345678 363 */ 364 /* 365 * 456789 123456789 123456789 366 * 123456789 367 */ 368 //indent end 369 370 371 /* 372 * When determining whether the comment fits in a single line, only the first 373 * trailing space or tab is kept, the others are removed. 374 */ 375 //indent input 376 /* tab: */ 377 /* 456789 123456789 123456789 12345 */ 378 /* 456789 123456789 123456789 123456 */ 379 /* space: */ 380 /* 456789 123456789 123456789 12345 */ 381 /* 456789 123456789 123456789 123456 */ 382 //indent end 383 384 //indent run -l38 385 /* tab: */ 386 /* 387 * 456789 123456789 123456789 12345 388 */ 389 /* 390 * 456789 123456789 123456789 123456 391 */ 392 /* space: */ 393 /* 456789 123456789 123456789 12345 */ 394 /* 395 * 456789 123456789 123456789 123456 396 */ 397 //indent end 398 399 400 /* 401 * The following comments test line breaking when the comment does not end 402 * with a space. Since indent adds a trailing space to a single-line comment, 403 * this space has to be taken into account when computing the line length. 404 */ 405 //indent input 406 /* x . line length 35*/ 407 /* x .. line length 36*/ 408 /* x ... line length 37*/ 409 /* x .... line length 38*/ 410 /* x ..... line length 39*/ 411 /* x ...... line length 40*/ 412 /* x ....... line length 41*/ 413 /* x ........ line length 42*/ 414 //indent end 415 416 //indent run -l38 417 /* x . line length 35 */ 418 /* x .. line length 36 */ 419 /* x ... line length 37 */ 420 /* x .... line length 38 */ 421 /* 422 * x ..... line length 39 423 */ 424 /* 425 * x ...... line length 40 426 */ 427 /* 428 * x ....... line length 41 429 */ 430 /* 431 * x ........ line length 42 432 */ 433 //indent end 434 435 436 /* 437 * The different types of comments that indent distinguishes, starting in 438 * column 1 (see options '-fc1' and '-nfc1'). 439 */ 440 //indent input 441 /* This is a traditional C block comment. */ 442 443 // This is a C99 line comment. 444 445 /* 446 * This is a box comment since its first line (the one above this line) is 447 * empty. 448 * 449 * 450 * 451 * Its text gets wrapped. 452 * Empty lines serve as paragraphs. 453 */ 454 455 /** 456 * This is a box comment 457 * that is not re-wrapped. 458 */ 459 460 /*- 461 * This is a box comment 462 * that is not re-wrapped. 463 * It is often used for copyright declarations. 464 */ 465 //indent end 466 467 //indent run 468 /* This is a traditional C block comment. */ 469 470 // This is a C99 line comment. 471 472 /* 473 * This is a box comment since its first line (the one above this line) is 474 * empty. 475 * 476 * 477 * 478 * Its text gets wrapped. Empty lines serve as paragraphs. 479 */ 480 481 /** 482 * This is a box comment 483 * that is not re-wrapped. 484 */ 485 486 /*- 487 * This is a box comment 488 * that is not re-wrapped. 489 * It is often used for copyright declarations. 490 */ 491 //indent end 492 493 494 /* 495 * The different types of comments that indent distinguishes, starting in 496 * column 9, so they are independent of the option '-fc1'. 497 */ 498 //indent input 499 void 500 function(void) 501 { 502 /* This is a traditional C block comment. */ 503 504 /* 505 * This is a box comment. 506 * 507 * It starts in column 9, not 1, 508 * therefore it gets re-wrapped. 509 */ 510 511 /** 512 * This is a box comment 513 * that is not re-wrapped, even though it starts in column 9, not 1. 514 */ 515 516 /*- 517 * This is a box comment 518 * that is not re-wrapped. 519 */ 520 } 521 //indent end 522 523 //indent run 524 void 525 function(void) 526 { 527 /* This is a traditional C block comment. */ 528 529 /* 530 * This is a box comment. 531 * 532 * It starts in column 9, not 1, therefore it gets re-wrapped. 533 */ 534 535 /** 536 * This is a box comment 537 * that is not re-wrapped, even though it starts in column 9, not 1. 538 */ 539 540 /*- 541 * This is a box comment 542 * that is not re-wrapped. 543 */ 544 } 545 //indent end 546 547 548 /* 549 * Comments to the right of declarations. 550 */ 551 //indent input 552 void 553 function(void) 554 { 555 int decl; /* declaration comment */ 556 557 int decl; /* short 558 * multi-line 559 * declaration 560 * comment */ 561 562 int decl; /* long single-line declaration comment that is longer than the allowed line width */ 563 564 int decl; /* long multi-line declaration comment 565 * that is longer than 566 * the allowed line width */ 567 568 int decl; // C99 declaration comment 569 570 { 571 int decl; /* indented declaration */ 572 { 573 int decl; /* indented declaration */ 574 { 575 int decl; /* indented declaration */ 576 { 577 int decl; /* indented declaration */ 578 } 579 } 580 } 581 } 582 } 583 //indent end 584 585 //indent run -ldi0 586 void 587 function(void) 588 { 589 int decl; /* declaration comment */ 590 591 int decl; /* short multi-line declaration comment */ 592 593 int decl; /* long single-line declaration comment that 594 * is longer than the allowed line width */ 595 596 int decl; /* long multi-line declaration comment that is 597 * longer than the allowed line width */ 598 599 int decl; // C99 declaration comment 600 601 { 602 int decl; /* indented declaration */ 603 { 604 int decl; /* indented declaration */ 605 { 606 int decl; /* indented declaration */ 607 { 608 // $ This comment is indented so far to the right that it may overshoot the 609 // $ right margin. The allowed line length is increased to the starting 610 // $ indentation of 56 plus a fixed amount of 25 columns, resulting in 81. 611 // $ The trailing '*' would fit, but the trailing '/' is too much. 612 int decl; /* indented declaration 613 */ 614 } 615 } 616 } 617 } 618 } 619 //indent end 620 621 622 /* 623 * Comments to the right of code. 624 */ 625 //indent input 626 void 627 function(void) 628 { 629 code(); /* code comment */ 630 code(); /* code comment _________ to line length 78 */ 631 code(); /* code comment __________ to line length 79 */ 632 code(); /* code comment ___________ to line length 80 */ 633 code(); /* code comment ____________ to line length 81 */ 634 code(); /* code comment _____________ to line length 82 */ 635 636 /* $ In the following comments, the line length is measured after formatting. */ 637 code(); /* code comment _________ to line length 78*/ 638 code(); /* code comment __________ to line length 79*/ 639 code(); /* code comment ___________ to line length 80*/ 640 code(); /* code comment ____________ to line length 81*/ 641 code(); /* code comment _____________ to line length 82*/ 642 643 code(); /* short 644 * multi-line 645 * code 646 * comment */ 647 648 code(); /* long single-line code comment that is longer than the allowed line width */ 649 650 code(); /* long multi-line code comment 651 * that is longer than 652 * the allowed line width */ 653 654 code(); // C99 code comment 655 code(); // C99 code comment ________ to line length 78 656 code(); // C99 code comment _________ to line length 79 657 code(); // C99 code comment __________ to line length 80 658 code(); // C99 code comment ___________ to line length 81 659 code(); // C99 code comment ____________ to line length 82 660 661 if (cond) /* comment */ 662 if (cond) /* comment */ 663 if (cond) /* comment */ 664 if (cond) /* comment */ 665 if (cond) /* comment */ 666 code(); /* comment */ 667 } 668 //indent end 669 670 //indent run -l78 671 void 672 function(void) 673 { 674 code(); /* code comment */ 675 code(); /* code comment _________ to line length 78 */ 676 code(); /* code comment __________ to line length 79 677 */ 678 code(); /* code comment ___________ to line length 80 679 */ 680 code(); /* code comment ____________ to line length 81 681 */ 682 code(); /* code comment _____________ to line length 683 * 82 */ 684 685 /* $ In the following comments, the line length is measured after formatting. */ 686 code(); /* code comment _________ to line length 78 */ 687 code(); /* code comment __________ to line length 79 688 */ 689 code(); /* code comment ___________ to line length 80 690 */ 691 code(); /* code comment ____________ to line length 81 692 */ 693 code(); /* code comment _____________ to line length 694 * 82 */ 695 696 code(); /* short multi-line code comment */ 697 698 code(); /* long single-line code comment that is 699 * longer than the allowed line width */ 700 701 code(); /* long multi-line code comment that is longer 702 * than the allowed line width */ 703 704 /* $ Trailing C99 comments are not wrapped, as indent would not correctly */ 705 /* $ recognize the continuation lines as continued comments. For block */ 706 /* $ comments this works since the comment has not ended yet. */ 707 code(); // C99 code comment 708 code(); // C99 code comment ________ to line length 78 709 code(); // C99 code comment _________ to line length 79 710 code(); // C99 code comment __________ to line length 80 711 code(); // C99 code comment ___________ to line length 81 712 code(); // C99 code comment ____________ to line length 82 713 714 if (cond) /* comment */ 715 if (cond) /* comment */ 716 if (cond) /* comment */ 717 if (cond) /* comment */ 718 if (cond) /* comment */ 719 code(); /* comment */ 720 } 721 //indent end 722 723 724 //indent input 725 /* 726 * this 727 * is a boxed 728 * staircase. 729 * 730 * Its paragraphs get wrapped. 731 732 There may also be 733 lines without asterisks. 734 735 */ 736 //indent end 737 738 //indent run 739 /* 740 * this is a boxed staircase. 741 * 742 * Its paragraphs get wrapped. 743 * 744 * There may also be lines without asterisks. 745 * 746 */ 747 //indent end 748 749 750 //indent input 751 void loop(void) 752 { 753 while(cond)/*comment*/; 754 755 while(cond) 756 /*comment*/; 757 } 758 //indent end 759 760 //indent run 761 void 762 loop(void) 763 { 764 while (cond) /* comment */ 765 ; 766 767 while (cond) 768 /* comment */; 769 } 770 //indent end 771 772 773 /* 774 * The following comment starts really far to the right. To avoid that each 775 * line only contains a single word, the maximum allowed line width is 776 * extended such that each comment line may contain 22 characters. 777 */ 778 //indent input 779 int global_variable_with_really_long_name_that_reaches_up_to_column_83; /* 1234567890123456789 1 1234567890123456789 12 1234567890123456789 123 1234567890123456789 1234 1234567890123456789 12345 1234567890123456789 123456 */ 780 //indent end 781 782 //indent run 783 int global_variable_with_really_long_name_that_reaches_up_to_column_83; /* 1234567890123456789 1 784 * 1234567890123456789 12 785 * 1234567890123456789 786 * 123 787 * 1234567890123456789 788 * 1234 789 * 1234567890123456789 790 * 12345 791 * 1234567890123456789 792 * 123456 */ 793 //indent end 794 795 796 /* 797 * Demonstrates handling of line-end '//' comments. 798 * 799 * Even though this type of comments had been added in C99, indent didn't 800 * support these comments until 2021 and instead messed up the code in 801 * seemingly unpredictable ways. It treated any sequence of '/' as a binary 802 * operator, no matter whether it was '/' or '//' or '/////'. 803 */ 804 //indent input 805 int dummy // comment 806 = // eq 807 1 // one 808 + // plus 809 2;// two 810 811 /////separator///// 812 813 void function(void){} 814 815 // Note: removing one of these line-end comments affected the formatting 816 // of the main function below, before indent supported '//' comments. 817 818 int 819 main(void) 820 { 821 } 822 //indent end 823 824 //indent run 825 int dummy // comment 826 = // eq 827 1 // one 828 + // plus 829 2; // two 830 831 /////separator///// 832 833 void 834 function(void) 835 { 836 } 837 838 // Note: removing one of these line-end comments affected the formatting 839 // of the main function below, before indent supported '//' comments. 840 841 int 842 main(void) 843 { 844 } 845 //indent end 846 847 848 /* 849 * Between March 2021 and October 2021, indent supported C99 comments only 850 * very basically. It messed up the following code, repeating the identifier 851 * 'bar' twice in a row. 852 */ 853 //indent input 854 void c99_comment(void) 855 { 856 foo(); // C99 comment 857 bar(); 858 } 859 //indent end 860 861 //indent run 862 void 863 c99_comment(void) 864 { 865 foo(); // C99 comment 866 bar(); 867 } 868 //indent end 869 870 871 //indent input 872 void 873 comment_at_end_of_function(void) 874 { 875 if (cond) 876 statement(); 877 // comment 878 } 879 //indent end 880 881 //indent run-equals-input 882 883 884 //indent input 885 int decl; 886 // end-of-line comment at the end of the file 887 //indent end 888 889 //indent run-equals-input 890 891 892 /* A form feed in the middle of a comment is an ordinary character. */ 893 //indent input 894 /* 895 * AE 896 */ 897 /*-AE*/ 898 //indent end 899 900 //indent run-equals-input 901 902 903 /* 904 * Form feeds are seldom used, especially in comments, so treat them as an 905 * ordinary character. 906 */ 907 //indent input 908 /* comment*/ 909 /*text* comment*/ 910 //indent end 911 912 //indent run 913 /* comment */ 914 /* text* comment */ 915 //indent end 916 917 //indent run-equals-prev-output -nsc 918 919 //indent run-equals-input -nfc1 920 921 922 /* 923 * A completely empty line in a box comment must be copied unmodified to the 924 * output. This is done in process_comment by adding a space to the end of an 925 * otherwise empty comment. This space forces output_line to add some output, 926 * but the trailing space is discarded, resulting in an empty line. 927 */ 928 //indent input 929 /*- comment 930 931 932 end */ 933 //indent end 934 935 //indent run-equals-input -nfc1 936 937 938 //indent input 939 /* comment comment comment comment Ümläute */ 940 //indent end 941 942 //indent run -l40 943 /* 944 * comment comment comment comment 945 * Ümläute 946 */ 947 //indent end 948 949 950 //indent input 951 int f(void) 952 { 953 if (0) 954 /* 12 1234 123 123456 1234 1234567 123 1234. */; 955 } 956 //indent end 957 958 /* The comment is too long to fit in a single line. */ 959 //indent run -l54 960 int 961 f(void) 962 { 963 if (0) 964 /* 965 * 12 1234 123 123456 1234 1234567 123 966 * 1234. 967 */; 968 } 969 //indent end 970 971 /* The comment fits in a single line. */ 972 //indent run 973 int 974 f(void) 975 { 976 if (0) 977 /* 12 1234 123 123456 1234 1234567 123 1234. */; 978 } 979 //indent end 980 981 982 /* 983 * Test for an edge cases in comment handling, having a block comment inside 984 * a line comment. Before NetBSD pr_comment.c 1.96 from 2021-11-04, indent 985 * wrongly assumed that the comment would end at the '*' '/', tokenizing the 986 * second word 'still' as a type_outside_parentheses. 987 */ 988 //indent input 989 /* block comment */ 990 // line comment /* still a line comment */ still a line comment 991 //indent end 992 993 //indent run-equals-input 994 995 996 /* 997 * Tests for comments that are not wrapped. 998 */ 999 //indent input 1000 /*- tab space tab space */ 1001 /*- very-long-word-that-cannot-be-broken very-long-word-that-cannot-be-broken */ 1002 /*- very-long-word-that-cannot-be-broken very-long-word-that-cannot-be-broken */ 1003 //indent end 1004 1005 //indent run-equals-input -l5 1006 1007 //indent run-equals-input -l32 1008 1009 1010 /* 1011 * Test for form feeds in nowrap comments. 1012 */ 1013 //indent input 1014 /*-*/ 1015 /*-<>*/ 1016 //indent end 1017 1018 //indent run-equals-input 1019 1020 1021 /* 1022 * In a comment that is wrapped, one or more empty lines separate paragraphs. 1023 * All of these empty lines are preserved. 1024 */ 1025 //indent input 1026 /* line 1 1027 1028 1029 line 4 */ 1030 //indent end 1031 1032 //indent run 1033 /* 1034 * line 1 1035 * 1036 * 1037 * line 4 1038 */ 1039 //indent end 1040 1041 //indent run-equals-input -nfc1 1042 1043 //indent run-equals-input -nfc1 -nsc 1044 1045 //indent run -nsc 1046 /* 1047 line 1 1048 1049 1050 line 4 1051 */ 1052 //indent end 1053 1054 //indent run-equals-input -nsc -ncdb 1055 1056 1057 /* 1058 * Since 2019-04-04 and before pr_comment.c 1.123 from 2021-11-25, the 1059 * function analyze_comment wrongly joined the two comments. 1060 */ 1061 //indent input 1062 /* 1063 *//* 1064 join*/ 1065 //indent end 1066 1067 //indent run -nfc1 1068 /* 1069 */ 1070 /* 1071 * join 1072 */ 1073 //indent end 1074 1075 1076 /* 1077 * Since 2019-04-04 and before pr_comment.c 1.123 from 2021-11-25, the 1078 * function analyze_comment generated malformed output by terminating the 1079 * first comment but omitting the start of the second comment. 1080 */ 1081 //indent input 1082 /* 1083 *//* 1084 error*/ 1085 //indent end 1086 1087 //indent run -nfc1 1088 /* 1089 */ 1090 /* 1091 * error 1092 */ 1093 //indent end 1094 1095 1096 /* 1097 * Ensure that there is exactly one space between the comment and the 1098 * following binary operator. 1099 */ 1100 //indent input 1101 { 1102 a /* */ > b; 1103 a>b; 1104 } 1105 //indent end 1106 1107 //indent run 1108 { 1109 a /* */ > b; 1110 a > b; 1111 } 1112 //indent end 1113 1114 1115 /* 1116 * Line comments are only related to a code snippet if they are on the same 1117 * line; they cannot be continued in the next lines. 1118 */ 1119 //indent input 1120 int line; // comment line 1 1121 // comment line 2 1122 int block; /* comment line 1 1123 * comment line 2 1124 */ 1125 //indent end 1126 1127 //indent run -di0 1128 int line; // comment line 1 1129 // $ XXX: This comment was probably intended to continue 'comment line 1'. 1130 // comment line 2 1131 int block; /* comment line 1 comment line 2 */ 1132 //indent end 1133 1134 1135 // Ensure that '/*/' is not interpreted as a complete comment. 1136 //indent input 1137 /*/ comment? or:not; /* */ 1138 //indent end 1139 1140 //indent run 1141 /* / comment? or:not; /* */ 1142 //indent end 1143 1144 //indent run-equals-input -nfc1 1145 1146 1147 /* 1148 * The tokens '/' and '*' do not form a comment when they are separated by a 1149 * space. 1150 */ 1151 //indent input 1152 int a = b / *c; 1153 // $ Indent can be tricked into treating '/' as a unary operator, thus turning 1154 // $ some operators into the start of a comment. This only works in 1155 // $ syntactically invalid text. 1156 int a = b + / * c; 1157 //indent end 1158 1159 //indent run -di0 1160 int a = b / *c; 1161 // $ FIXME: Don't merge the two operators; there are enough situations where 1162 // $ indent has to guess whether an operator is unary or binary, and these 1163 // $ heuristics can go wrong. 1164 int a = b + /*c; 1165 //indent end 1166 1167 1168 /* 1169 * Ensure that tab characters that are broken into separate lines are replaced 1170 * with spaces; other tabs are preserved. 1171 */ 1172 //indent input 1173 /* word word word word word word word word word */ 1174 //indent end 1175 1176 //indent run -l38 1177 /* 1178 * word word word word word 1179 * word word word word 1180 */ 1181 //indent end 1182 1183 1184 /* In no-wrap comments, every single newline is preserved. */ 1185 //indent input 1186 /*- 1187 paragraph 1 1188 1189 1190 1191 paragraph 2 1192 */ 1193 //indent end 1194 1195 //indent run-equals-input 1196