Home | History | Annotate | Line # | Download | only in indent
      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  * AE
    897  */
    898 /*-AE*/
    900 //indent end
    901 
    902 //indent run-equals-input
    903 
    904 
    905 /*
    906  * Form feeds are seldom used, especially in comments, so treat them as an
    907  * ordinary character.
    908  */
    909 //indent input
    910 /* comment*/
    912 /*text* comment*/
    914 //indent end
    915 
    916 //indent run
    917 /*  comment */
    919 /* text* comment */
    921 //indent end
    922 
    923 //indent run-equals-prev-output -nsc
    924 
    925 //indent run-equals-input -nfc1
    926 
    927 
    928 /*
    929  * A completely empty line in a box comment must be copied unmodified to the
    930  * output. This is done in process_comment by adding a space to the end of an
    931  * otherwise empty comment. This space forces output_line to add some output,
    932  * but the trailing space is discarded, resulting in an empty line.
    933  */
    934 //indent input
    935 /*- comment
    936 
    937 
    938 end */
    939 //indent end
    940 
    941 //indent run-equals-input -nfc1
    942 
    943 
    944 //indent input
    945 /* comment comment comment comment mlute */
    946 //indent end
    947 
    948 //indent run -l40
    949 /*
    950  * comment comment comment comment
    951  * mlute
    952  */
    953 //indent end
    954 
    955 
    956 //indent input
    957 int f(void)
    958 {
    959 	if (0)
    960 		/* 12 1234 123 123456 1234 1234567 123 1234.  */;
    961 }
    962 //indent end
    963 
    964 /* The comment is too long to fit in a single line. */
    965 //indent run -l54
    966 int
    967 f(void)
    968 {
    969 	if (0)
    970 		/*
    971 		 * 12 1234 123 123456 1234 1234567 123
    972 		 * 1234.
    973 		 */;
    974 }
    975 //indent end
    976 
    977 /* The comment fits in a single line. */
    978 //indent run
    979 int
    980 f(void)
    981 {
    982 	if (0)
    983 		/* 12 1234 123 123456 1234 1234567 123 1234. */;
    984 }
    985 //indent end
    986 
    987 
    988 /*
    989  * Test for an edge cases in comment handling, having a block comment inside
    990  * a line comment. Before NetBSD pr_comment.c 1.96 from 2021-11-04, indent
    991  * wrongly assumed that the comment would end at the '*' '/', tokenizing the
    992  * second word 'still' as a type_outside_parentheses.
    993  */
    994 //indent input
    995 /* block comment */
    996 // line comment /* still a line comment */ still a line comment
    997 //indent end
    998 
    999 //indent run-equals-input
   1000 
   1001 
   1002 /*
   1003  * Tests for comments that are not wrapped.
   1004  */
   1005 //indent input
   1006 /*-	tab space	tab space */
   1007 /*-	very-long-word-that-cannot-be-broken very-long-word-that-cannot-be-broken */
   1008 /*-	very-long-word-that-cannot-be-broken very-long-word-that-cannot-be-broken */
   1009 //indent end
   1010 
   1011 //indent run-equals-input -l5
   1012 
   1013 //indent run-equals-input -l32
   1014 
   1015 
   1016 /*
   1017  * Test for form feeds in nowrap comments.
   1018  */
   1019 //indent input
   1020 /*-*/
   1022 /*-<>*/
   1024 //indent end
   1025 
   1026 //indent run-equals-input
   1027 
   1028 
   1029 /*
   1030  * In a comment that is wrapped, one or more empty lines separate paragraphs.
   1031  * All of these empty lines are preserved.
   1032  */
   1033 //indent input
   1034 /* line 1
   1035 
   1036 
   1037 line 4 */
   1038 //indent end
   1039 
   1040 //indent run
   1041 /*
   1042  * line 1
   1043  *
   1044  *
   1045  * line 4
   1046  */
   1047 //indent end
   1048 
   1049 //indent run-equals-input -nfc1
   1050 
   1051 //indent run-equals-input -nfc1 -nsc
   1052 
   1053 //indent run -nsc
   1054 /*
   1055 line 1
   1056 
   1057 
   1058 line 4
   1059  */
   1060 //indent end
   1061 
   1062 //indent run-equals-input -nsc -ncdb
   1063 
   1064 
   1065 /*
   1066  * Since 2019-04-04 and before pr_comment.c 1.123 from 2021-11-25, the
   1067  * function analyze_comment wrongly joined the two comments.
   1068  */
   1069 //indent input
   1070 /*
   1071  *//*
   1072 join*/
   1073 //indent end
   1074 
   1075 //indent run -nfc1
   1076 /*
   1077  */
   1078  /*
   1079   * join
   1080   */
   1081 //indent end
   1082 
   1083 
   1084 /*
   1085  * Since 2019-04-04 and before pr_comment.c 1.123 from 2021-11-25, the
   1086  * function analyze_comment generated malformed output by terminating the
   1087  * first comment but omitting the start of the second comment.
   1088  */
   1089 //indent input
   1090 /*
   1091 *//*
   1092 error*/
   1093 //indent end
   1094 
   1095 //indent run -nfc1
   1096 /*
   1097 */
   1098  /*
   1099   * error
   1100   */
   1101 //indent end
   1102 
   1103 
   1104 /*
   1105  * Ensure that there is exactly one space between the comment and the
   1106  * following binary operator.
   1107  */
   1108 //indent input
   1109 {
   1110 a /* */ > b;
   1111 a>b;
   1112 }
   1113 //indent end
   1114 
   1115 //indent run
   1116 {
   1117 	a /* */ > b;
   1118 	a > b;
   1119 }
   1120 //indent end
   1121 
   1122 
   1123 /*
   1124  * Line comments are only related to a code snippet if they are on the same
   1125  * line; they cannot be continued in the next lines.
   1126  */
   1127 //indent input
   1128 int line;	// comment line 1
   1129 		// comment line 2
   1130 int block;	/* comment line 1
   1131 		 * comment line 2
   1132 		 */
   1133 //indent end
   1134 
   1135 //indent run -di0
   1136 int line;			// comment line 1
   1137 // $ XXX: This comment was probably intended to continue 'comment line 1'.
   1138 // comment line 2
   1139 int block;			/* comment line 1 comment line 2 */
   1140 //indent end
   1141 
   1142 
   1143 // Ensure that '/*/' is not interpreted as a complete comment.
   1144 //indent input
   1145 /*/ comment? or:not; /* */
   1146 //indent end
   1147 
   1148 //indent run
   1149 /* / comment? or:not; /* */
   1150 //indent end
   1151 
   1152 //indent run-equals-input -nfc1
   1153 
   1154 
   1155 /*
   1156  * The tokens '/' and '*' do not form a comment when they are separated by a
   1157  * space.
   1158  */
   1159 //indent input
   1160 int a = b / *c;
   1161 // $ Indent can be tricked into treating '/' as a unary operator, thus turning
   1162 // $ some operators into the start of a comment. This only works in
   1163 // $ syntactically invalid text.
   1164 int a = b + / * c;
   1165 //indent end
   1166 
   1167 //indent run -di0
   1168 int a = b / *c;
   1169 // $ FIXME: Don't merge the two operators; there are enough situations where
   1170 // $ indent has to guess whether an operator is unary or binary, and these
   1171 // $ heuristics can go wrong.
   1172 int a = b + /*c;
   1173 //indent end
   1174 
   1175 
   1176 /*
   1177  * Ensure that tab characters that are broken into separate lines are replaced
   1178  * with spaces; other tabs are preserved.
   1179  */
   1180 //indent input
   1181 /* word	word	word	word	word	word	word	word	word */
   1182 //indent end
   1183 
   1184 //indent run -l38
   1185 /*
   1186  * word	word	word	word	word
   1187  * word	word	word	word
   1188  */
   1189 //indent end
   1190 
   1191 
   1192 /* In no-wrap comments, every single newline is preserved. */
   1193 //indent input
   1194 /*-
   1195 paragraph 1
   1196 
   1197 
   1198 
   1199 paragraph 2
   1200  */
   1201 //indent end
   1202 
   1203 //indent run-equals-input
   1204