Home | History | Annotate | Line # | Download | only in indent
lsym_comment.c revision 1.5
      1 /* $NetBSD: lsym_comment.c,v 1.5 2023/05/11 09:28:53 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 /* The comment in the output has 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 					int decl;	/* indented declaration */
    588 				}
    589 			}
    590 		}
    591 	}
    592 }
    593 //indent end
    594 
    595 
    596 /*
    597  * Comments to the right of code.
    598  */
    599 //indent input
    600 void
    601 function(void)
    602 {
    603 	code();			/* code comment */
    604 	code();			/* code comment _________ to line length 78 */
    605 	code();			/* code comment __________ to line length 79 */
    606 	code();			/* code comment ___________ to line length 80 */
    607 	code();			/* code comment ____________ to line length 81 */
    608 	code();			/* code comment _____________ to line length 82 */
    609 
    610 /* $ In the following comments, the line length is measured after formatting. */
    611 	code();			/* code comment _________ to line length 78*/
    612 	code();			/* code comment __________ to line length 79*/
    613 	code();			/* code comment ___________ to line length 80*/
    614 	code();			/* code comment ____________ to line length 81*/
    615 	code();			/* code comment _____________ to line length 82*/
    616 
    617 	code();			/* short
    618 				 * multi-line
    619 				 * code
    620 				 * comment */
    621 
    622 	code();			/* long single-line code comment that is longer than the allowed line width */
    623 
    624 	code();			/* long multi-line code comment
    625  * that is longer than
    626  * the allowed line width */
    627 
    628 	code();			// C99 code comment
    629 	code();			// C99 code comment ________ to line length 78
    630 	code();			// C99 code comment _________ to line length 79
    631 	code();			// C99 code comment __________ to line length 80
    632 	code();			// C99 code comment ___________ to line length 81
    633 	code();			// C99 code comment ____________ to line length 82
    634 
    635 	if (cond) /* comment */
    636 		if (cond) /* comment */
    637 			if (cond) /* comment */
    638 				if (cond) /* comment */
    639 					if (cond) /* comment */
    640 						code(); /* comment */
    641 }
    642 //indent end
    643 
    644 //indent run
    645 void
    646 function(void)
    647 {
    648 	code();			/* code comment */
    649 	code();			/* code comment _________ to line length 78 */
    650 	code();			/* code comment __________ to line length 79 */
    651 	code();			/* code comment ___________ to line length 80 */
    652 	code();			/* code comment ____________ to line length 81 */
    653 	code();			/* code comment _____________ to line length
    654 				 * 82 */
    655 
    656 /* $ In the following comments, the line length is measured after formatting. */
    657 	code();			/* code comment _________ to line length 78 */
    658 	code();			/* code comment __________ to line length 79 */
    659 	code();			/* code comment ___________ to line length 80 */
    660 	code();			/* code comment ____________ to line length 81 */
    661 	code();			/* code comment _____________ to line length
    662 				 * 82 */
    663 
    664 	code();			/* short multi-line code comment */
    665 
    666 	code();			/* long single-line code comment that is
    667 				 * longer than the allowed line width */
    668 
    669 	code();			/* long multi-line code comment that is longer
    670 				 * than the allowed line width */
    671 
    672 /* $ Trailing C99 comments are not wrapped, as indent would not correctly */
    673 /* $ recognize the continuation lines as continued comments. For block */
    674 /* $ comments this works since the comment has not ended yet. */
    675 	code();			// C99 code comment
    676 	code();			// C99 code comment ________ to line length 78
    677 	code();			// C99 code comment _________ to line length 79
    678 	code();			// C99 code comment __________ to line length 80
    679 	code();			// C99 code comment ___________ to line length 81
    680 	code();			// C99 code comment ____________ to line length 82
    681 
    682 	if (cond)		/* comment */
    683 		if (cond)	/* comment */
    684 			if (cond)	/* comment */
    685 				if (cond)	/* comment */
    686 					if (cond)	/* comment */
    687 						code();	/* comment */
    688 }
    689 //indent end
    690 
    691 
    692 //indent input
    693 /*
    694 	 * this
    695 		 * is a boxed
    696 			 * staircase.
    697 *
    698 * Its paragraphs get wrapped.
    699 
    700 There may also be
    701 		lines without asterisks.
    702 
    703  */
    704 //indent end
    705 
    706 //indent run
    707 /*
    708  * this is a boxed staircase.
    709  *
    710  * Its paragraphs get wrapped.
    711  *
    712  * There may also be lines without asterisks.
    713  *
    714  */
    715 //indent end
    716 
    717 
    718 //indent input
    719 void loop(void)
    720 {
    721 while(cond)/*comment*/;
    722 
    723 	while(cond)
    724 	/*comment*/;
    725 }
    726 //indent end
    727 
    728 //indent run
    729 void
    730 loop(void)
    731 {
    732 	while (cond) /* comment */ ;
    733 
    734 	while (cond)
    735 /* $ XXX: The spaces around the comment look unintentional. */
    736 		 /* comment */ ;
    737 }
    738 //indent end
    739 
    740 
    741 /*
    742  * The following comment starts really far to the right. To avoid that each
    743  * line only contains a single word, the maximum allowed line width is
    744  * extended such that each comment line may contain 22 characters.
    745  */
    746 //indent input
    747 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 */
    748 //indent end
    749 
    750 //indent run
    751 int		global_variable_with_really_long_name_that_reaches_up_to_column_83;	/* 1234567890123456789 1
    752 											 * 1234567890123456789 12
    753 											 * 1234567890123456789
    754 											 * 123
    755 											 * 1234567890123456789
    756 											 * 1234
    757 											 * 1234567890123456789
    758 											 * 12345
    759 											 * 1234567890123456789
    760 											 * 123456 */
    761 //indent end
    762 
    763 
    764 /*
    765  * Demonstrates handling of line-end '//' comments.
    766  *
    767  * Even though this type of comments had been added in C99, indent didn't
    768  * support these comments until 2021 and instead messed up the code in
    769  * seemingly unpredictable ways. It treated any sequence of '/' as a binary
    770  * operator, no matter whether it was '/' or '//' or '/////'.
    771  */
    772 //indent input
    773 int dummy // comment
    774     = // eq
    775     1		// one
    776     + // plus
    777     2;// two
    778 
    779 /////separator/////
    780 
    781 void function(void){}
    782 
    783 // Note: removing one of these line-end comments affected the formatting
    784 // of the main function below, before indent supported '//' comments.
    785 
    786 int
    787 main(void)
    788 {
    789 }
    790 //indent end
    791 
    792 //indent run
    793 int		dummy		// comment
    794 =				// eq
    795 1				// one
    796 +				// plus
    797 2;				// two
    798 
    799 /////separator/////
    800 
    801 void
    802 function(void)
    803 {
    804 }
    805 
    806 // Note: removing one of these line-end comments affected the formatting
    807 // of the main function below, before indent supported '//' comments.
    808 
    809 int
    810 main(void)
    811 {
    812 }
    813 //indent end
    814 
    815 
    816 /*
    817  * Between March 2021 and October 2021, indent supported C99 comments only
    818  * very basically. It messed up the following code, repeating the identifier
    819  * 'bar' twice in a row.
    820  */
    821 //indent input
    822 void c99_comment(void)
    823 {
    824 foo(); // C99 comment
    825 bar();
    826 }
    827 //indent end
    828 
    829 //indent run
    830 void
    831 c99_comment(void)
    832 {
    833 	foo();			// C99 comment
    834 	bar();
    835 }
    836 //indent end
    837 
    838 
    839 //indent input
    840 void
    841 comment_at_end_of_function(void)
    842 {
    843 	if (cond)
    844 		statement();
    845 	// comment
    846 }
    847 //indent end
    848 
    849 //indent run-equals-input
    850 
    851 
    852 //indent input
    853 int		decl;
    854 // end-of-line comment at the end of the file
    855 //indent end
    856 
    857 //indent run-equals-input
    858 
    859 
    860 /* A form feed in the middle of a comment is an ordinary character. */
    861 //indent input
    862 /*
    863  * AE
    865  */
    866 /*-AE*/
    868 //indent end
    869 
    870 //indent run-equals-input
    871 
    872 
    873 /*
    874  * At the beginning of a block comment or after a '*', '\f' is special. This
    875  * is an implementation detail that should not be visible from the outside.
    876  * Form feeds in comments are seldom used though, so this is no problem.
    877  */
    878 //indent input
    879 /* comment*/
    881 /*text* comment*/
    883 //indent end
    884 
    885 //indent run
    886 /* * comment */
    888 /* text* * comment */
    890 //indent end
    891 
    892 /*
    893  * Without 'star_comment_cont', there is no separator between the form feed
    894  * and the surrounding text.
    895  */
    896 //indent run -nsc
    897 /*comment */
    899 /* text*comment */
    901 //indent end
    902 
    903 //indent run-equals-input -nfc1
    904 
    905 
    906 /*
    907  * A completely empty line in a box comment must be copied unmodified to the
    908  * output. This is done in process_comment by adding a space to the end of an
    909  * otherwise empty comment. This space forces output_complete_line to add some output,
    910  * but the trailing space is discarded, resulting in an empty line.
    911  */
    912 //indent input
    913 /*- comment
    914 
    915 
    916 end */
    917 //indent end
    918 
    919 //indent run-equals-input -nfc1
    920 
    921 
    922 //indent input
    923 /* comment comment comment comment mlute */
    924 //indent end
    925 
    926 //indent run -l40
    927 /*
    928  * comment comment comment comment
    929  * mlute
    930  */
    931 //indent end
    932 
    933 
    934 //indent input
    935 int f(void)
    936 {
    937 	if (0)
    938 		/* 12 1234 123 123456 1234 1234567 123 1234.  */;
    939 }
    940 //indent end
    941 
    942 /* The comment is too long to fit in a single line. */
    943 //indent run -l54
    944 int
    945 f(void)
    946 {
    947 	if (0)
    948 		/*
    949 		 * 12 1234 123 123456 1234 1234567 123
    950 		 * 1234.
    951 		  */ ;
    952 }
    953 //indent end
    954 
    955 /* The comment fits in a single line. */
    956 //indent run
    957 int
    958 f(void)
    959 {
    960 	if (0)
    961 		 /* 12 1234 123 123456 1234 1234567 123 1234.  */ ;
    962 }
    963 //indent end
    964 
    965 
    966 /*
    967  * Test for an edge cases in comment handling, having a block comment inside
    968  * a line comment. Before NetBSD pr_comment.c 1.96 from 2021-11-04, indent
    969  * wrongly assumed that the comment would end at the '*' '/', tokenizing the
    970  * second word 'still' as a type_outside_parentheses.
    971  */
    972 //indent input
    973 /* block comment */
    974 // line comment /* still a line comment */ still a line comment
    975 //indent end
    976 
    977 //indent run-equals-input
    978 
    979 
    980 /*
    981  * Tests for comments that are not wrapped.
    982  */
    983 //indent input
    984 /*-	tab space	tab space */
    985 /*-	very-long-word-that-cannot-be-broken very-long-word-that-cannot-be-broken */
    986 /*-	very-long-word-that-cannot-be-broken very-long-word-that-cannot-be-broken */
    987 //indent end
    988 
    989 //indent run-equals-input -l5
    990 
    991 //indent run-equals-input -l32
    992 
    993 
    994 /*
    995  * Test for form feeds in nowrap comments.
    996  */
    997 //indent input
    998 /*-*/
   1000 /*-<>*/
   1002 //indent end
   1003 
   1004 //indent run-equals-input
   1005 
   1006 
   1007 /*
   1008  * Test two completely empty lines in a wrap comment. The second empty line
   1009  * covers the condition ps.next_col_1 in copy_comment_wrap.
   1010  */
   1011 //indent input
   1012 /* line 1
   1013 
   1014 
   1015 line 4 */
   1016 //indent end
   1017 
   1018 //indent run
   1019 /*
   1020  * line 1
   1021  *
   1022  *
   1023  * line 4
   1024  */
   1025 //indent end
   1026 
   1027 //indent run-equals-input -nfc1
   1028 
   1029 //indent run-equals-input -nfc1 -nsc
   1030 
   1031 //indent run -nsc
   1032 /*
   1033 line 1
   1034 
   1035 
   1036 line 4
   1037  */
   1038 //indent end
   1039 
   1040 //indent run-equals-input -nsc -ncdb
   1041 
   1042 
   1043 /*
   1044  * Cover the code for expanding the comment buffer. As of 2021-11-07, the
   1045  * default buffer size is 200. To actually fill the comment buffer, there must
   1046  * be a single line of a comment that is longer than 200 bytes.
   1047  */
   1048 //indent input
   1049 /*-_____10________20________30________40________50________60________70________80________90_______100_______110_______120_______130_______140_______150_______160_______170_______180_______190_______200 */
   1050 //indent end
   1051 
   1052 //indent run-equals-input
   1053 
   1054 
   1055 /*
   1056  * Cover the code for expanding the comment buffer in com_terminate. As of
   1057  * 2021-11-07, the default buffer size is 200, with a safety margin of 1 at
   1058  * the beginning and another safety margin of 5 at the end. To force the
   1059  * comment buffer to expanded in com_terminate, the comment must be exactly
   1060  * 193 bytes long.
   1061  */
   1062 //indent input
   1063 /*-_____10________20________30________40________50________60________70________80________90_______100_______110_______120_______130_______140_______150_______160_______170_______180_______190 */
   1064 //indent end
   1065 
   1066 //indent run-equals-input
   1067 
   1068 
   1069 /*
   1070  * Since 2019-04-04 and before pr_comment.c 1.123 from 2021-11-25, the
   1071  * function analyze_comment wrongly joined the two comments.
   1072  */
   1073 //indent input
   1074 /*
   1075  *//*
   1076 join*/
   1077 //indent end
   1078 
   1079 /* FIXME: The last line of the first comment must not be modified. */
   1080 //indent run -nfc1
   1081 /*
   1082   *//*
   1083   * join
   1084   */
   1085 //indent end
   1086 
   1087 
   1088 /*
   1089  * Since 2019-04-04 and before pr_comment.c 1.123 from 2021-11-25, the
   1090  * function analyze_comment generated malformed output by terminating the
   1091  * first comment but omitting the start of the second comment.
   1092  */
   1093 //indent input
   1094 /*
   1095 *//*
   1096 error*/
   1097 //indent end
   1098 
   1099 //indent run -nfc1
   1100 /*
   1101  *//*
   1102   * error
   1103   */
   1104 //indent end
   1105