1/* $NetBSD: lsym_comment.c,v 1.24 2023/06/23 20:59:04 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 56typedef 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 */ 69void 70t(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 */ 98void 99t(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 201int decl;/*-fixed comment 202 fixed comment*/ 203//indent end 204 205//indent run -di0 206int 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 237int decl;/*-fixed comment 238123456789ab fixed comment*/ 239//indent end 240 241//indent run -di0 242int 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 254123456789ab 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 274int decl; /*-|fixed comment 275 | minus 12 | 276 | tabs inside | 277 |---| 278|-----------| 279tab1+++ tab2--- tab3+++ tab4--- tab5+++ tab6--- tab7+++fixed comment*/ 280//indent end 281 282//indent run -di0 283int decl; /*-|fixed comment 284 | minus 12 | 285| tabs inside | 286|---| 287|-----------| 288tab1+++ 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|-----------| 304tab1+++ 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|-----------| 316tab1+++ 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 499void 500function(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 524void 525function(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 552void 553function(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 586void 587function(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 626void 627function(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 671void 672function(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 732There 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 751void loop(void) 752{ 753while(cond)/*comment*/; 754 755 while(cond) 756 /*comment*/; 757} 758//indent end 759 760//indent run 761void 762loop(void) 763{ 764 while (cond) /* comment */; 765 766 while (cond) 767 /* comment */; 768} 769//indent end 770 771 772/* 773 * The following comment starts really far to the right. To avoid that each 774 * line only contains a single word, the maximum allowed line width is 775 * extended such that each comment line may contain 22 characters. 776 */ 777//indent input 778int global_variable_with_really_long_name_that_reaches_up_to_column_83; /* 1234567890123456789 1 1234567890123456789 12 1234567890123456789 123 1234567890123456789 1234 1234567890123456789 12345 1234567890123456789 123456 */ 779//indent end 780 781//indent run 782int global_variable_with_really_long_name_that_reaches_up_to_column_83; /* 1234567890123456789 1 783 * 1234567890123456789 12 784 * 1234567890123456789 785 * 123 786 * 1234567890123456789 787 * 1234 788 * 1234567890123456789 789 * 12345 790 * 1234567890123456789 791 * 123456 */ 792//indent end 793 794 795/* 796 * Demonstrates handling of line-end '//' comments. 797 * 798 * Even though this type of comments had been added in C99, indent didn't 799 * support these comments until 2021 and instead messed up the code in 800 * seemingly unpredictable ways. It treated any sequence of '/' as a binary 801 * operator, no matter whether it was '/' or '//' or '/////'. 802 */ 803//indent input 804int dummy // comment 805 = // eq 806 1 // one 807 + // plus 808 2;// two 809 810/////separator///// 811 812void function(void){} 813 814// Note: removing one of these line-end comments affected the formatting 815// of the main function below, before indent supported '//' comments. 816 817int 818main(void) 819{ 820} 821//indent end 822 823//indent run 824int dummy // comment 825= // eq 8261 // one 827+ // plus 8282; // two 829 830/////separator///// 831 832void 833function(void) 834{ 835} 836 837// Note: removing one of these line-end comments affected the formatting 838// of the main function below, before indent supported '//' comments. 839 840int 841main(void) 842{ 843} 844//indent end 845 846 847/* 848 * Between March 2021 and October 2021, indent supported C99 comments only 849 * very basically. It messed up the following code, repeating the identifier 850 * 'bar' twice in a row. 851 */ 852//indent input 853void c99_comment(void) 854{ 855foo(); // C99 comment 856bar(); 857} 858//indent end 859 860//indent run 861void 862c99_comment(void) 863{ 864 foo(); // C99 comment 865 bar(); 866} 867//indent end 868 869 870//indent input 871void 872comment_at_end_of_function(void) 873{ 874 if (cond) 875 statement(); 876 // comment 877} 878//indent end 879 880//indent run-equals-input 881 882 883//indent input 884int decl; 885// end-of-line comment at the end of the file 886//indent end 887 888//indent run-equals-input 889 890 891/* A form feed in the middle of a comment is an ordinary character. */ 892//indent input 893/* 894 * AE 895 */ 896/*-AE*/ 897//indent end 898 899//indent run-equals-input 900 901 902/* 903 * Form feeds are seldom used, especially in comments, so treat them as an 904 * ordinary character. 905 */ 906//indent input 907/* comment*/ 908/*text* comment*/ 909//indent end 910 911//indent run 912/* comment */ 913/* text* comment */ 914//indent end 915 916//indent run-equals-prev-output -nsc 917 918//indent run-equals-input -nfc1 919 920 921/* 922 * A completely empty line in a box comment must be copied unmodified to the 923 * output. This is done in process_comment by adding a space to the end of an 924 * otherwise empty comment. This space forces output_line to add some output, 925 * but the trailing space is discarded, resulting in an empty line. 926 */ 927//indent input 928/*- comment 929 930 931end */ 932//indent end 933 934//indent run-equals-input -nfc1 935 936 937//indent input 938/* comment comment comment comment ��ml��ute */ 939//indent end 940 941//indent run -l40 942/* 943 * comment comment comment comment 944 * ��ml��ute 945 */ 946//indent end 947 948 949//indent input 950int f(void) 951{ 952 if (0) 953 /* 12 1234 123 123456 1234 1234567 123 1234. */; 954} 955//indent end 956 957/* The comment is too long to fit in a single line. */ 958//indent run -l54 959int 960f(void) 961{ 962 if (0) 963 /* 964 * 12 1234 123 123456 1234 1234567 123 965 * 1234. 966 */; 967} 968//indent end 969 970/* The comment fits in a single line. */ 971//indent run 972int 973f(void) 974{ 975 if (0) 976 /* 12 1234 123 123456 1234 1234567 123 1234. */; 977} 978//indent end 979 980 981/* 982 * Test for an edge cases in comment handling, having a block comment inside 983 * a line comment. Before NetBSD pr_comment.c 1.96 from 2021-11-04, indent 984 * wrongly assumed that the comment would end at the '*' '/', tokenizing the 985 * second word 'still' as a type_outside_parentheses. 986 */ 987//indent input 988/* block comment */ 989// line comment /* still a line comment */ still a line comment 990//indent end 991 992//indent run-equals-input 993 994 995/* 996 * Tests for comments that are not wrapped. 997 */ 998//indent input 999/*- tab space tab space */ 1000/*- very-long-word-that-cannot-be-broken very-long-word-that-cannot-be-broken */ 1001/*- very-long-word-that-cannot-be-broken very-long-word-that-cannot-be-broken */ 1002//indent end 1003 1004//indent run-equals-input -l5 1005 1006//indent run-equals-input -l32 1007 1008 1009/* 1010 * Test for form feeds in nowrap comments. 1011 */ 1012//indent input 1013/*-*/ 1014/*-<>*/ 1015//indent end 1016 1017//indent run-equals-input 1018 1019 1020/* 1021 * In a comment that is wrapped, one or more empty lines separate paragraphs. 1022 * All of these empty lines are preserved. 1023 */ 1024//indent input 1025/* line 1 1026 1027 1028line 4 */ 1029//indent end 1030 1031//indent run 1032/* 1033 * line 1 1034 * 1035 * 1036 * line 4 1037 */ 1038//indent end 1039 1040//indent run-equals-input -nfc1 1041 1042//indent run-equals-input -nfc1 -nsc 1043 1044//indent run -nsc 1045/* 1046line 1 1047 1048 1049line 4 1050 */ 1051//indent end 1052 1053//indent run-equals-input -nsc -ncdb 1054 1055 1056/* 1057 * Since 2019-04-04 and before pr_comment.c 1.123 from 2021-11-25, the 1058 * function analyze_comment wrongly joined the two comments. 1059 */ 1060//indent input 1061/* 1062 *//* 1063join*/ 1064//indent end 1065 1066//indent run -nfc1 1067/* 1068 */ 1069 /* 1070 * join 1071 */ 1072//indent end 1073 1074 1075/* 1076 * Since 2019-04-04 and before pr_comment.c 1.123 from 2021-11-25, the 1077 * function analyze_comment generated malformed output by terminating the 1078 * first comment but omitting the start of the second comment. 1079 */ 1080//indent input 1081/* 1082*//* 1083error*/ 1084//indent end 1085 1086//indent run -nfc1 1087/* 1088*/ 1089 /* 1090 * error 1091 */ 1092//indent end 1093 1094 1095/* 1096 * Ensure that there is exactly one space between the comment and the 1097 * following binary operator. 1098 */ 1099//indent input 1100{ 1101a /* */ > b; 1102a>b; 1103} 1104//indent end 1105 1106//indent run 1107{ 1108 a /* */ > b; 1109 a > b; 1110} 1111//indent end 1112 1113 1114/* 1115 * Line comments are only related to a code snippet if they are on the same 1116 * line; they cannot be continued in the next lines. 1117 */ 1118//indent input 1119int line; // comment line 1 1120 // comment line 2 1121int block; /* comment line 1 1122 * comment line 2 1123 */ 1124//indent end 1125 1126//indent run -di0 1127int line; // comment line 1 1128// $ XXX: This comment was probably intended to continue 'comment line 1'. 1129// comment line 2 1130int block; /* comment line 1 comment line 2 */ 1131//indent end 1132 1133 1134// Ensure that '/*/' is not interpreted as a complete comment. 1135//indent input 1136/*/ comment? or:not; /* */ 1137//indent end 1138 1139//indent run 1140/* / comment? or:not; /* */ 1141//indent end 1142 1143//indent run-equals-input -nfc1 1144 1145 1146/* 1147 * The tokens '/' and '*' do not form a comment when they are separated by a 1148 * space. 1149 */ 1150//indent input 1151int a = b / *c; 1152// $ Indent can be tricked into treating '/' as a unary operator, thus turning 1153// $ some operators into the start of a comment. This only works in 1154// $ syntactically invalid text. 1155int a = b + / * c; 1156//indent end 1157 1158//indent run -di0 1159int a = b / *c; 1160// $ FIXME: Don't merge the two operators; there are enough situations where 1161// $ indent has to guess whether an operator is unary or binary, and these 1162// $ heuristics can go wrong. 1163int a = b + /*c; 1164//indent end 1165 1166 1167/* 1168 * Ensure that tab characters that are broken into separate lines are replaced 1169 * with spaces; other tabs are preserved. 1170 */ 1171//indent input 1172/* word word word word word word word word word */ 1173//indent end 1174 1175//indent run -l38 1176/* 1177 * word word word word word 1178 * word word word word 1179 */ 1180//indent end 1181 1182 1183/* In no-wrap comments, every single newline is preserved. */ 1184//indent input 1185/*- 1186paragraph 1 1187 1188 1189 1190paragraph 2 1191 */ 1192//indent end 1193 1194//indent run-equals-input 1195