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