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