Home | History | Annotate | Line # | Download | only in indent
lsym_comment.c revision 1.18
      1 /* $NetBSD: lsym_comment.c,v 1.18 2023/06/06 07:51:35 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  * When determining whether the comment fits in a single line, only the first
    375  * trailing space or tab is kept, the others are removed.
    376  */
    377 //indent input
    378 /* tab: */
    379 /* 456789 123456789 123456789 12345		*/
    380 /* 456789 123456789 123456789 123456		*/
    381 /* space: */
    382 /* 456789 123456789 123456789 12345             */
    383 /* 456789 123456789 123456789 123456            */
    384 //indent end
    385 
    386 //indent run -l38
    387 /* tab: */
    388 /*
    389  * 456789 123456789 123456789 12345
    390  */
    391 /*
    392  * 456789 123456789 123456789 123456
    393  */
    394 /* space: */
    395 /* 456789 123456789 123456789 12345 */
    396 /*
    397  * 456789 123456789 123456789 123456
    398  */
    399 //indent end
    400 
    401 
    402 /*
    403  * The following comments test line breaking when the comment does not end
    404  * with a space. Since indent adds a trailing space to a single-line comment,
    405  * this space has to be taken into account when computing the line length.
    406  */
    407 //indent input
    408 /* x		. line length 35*/
    409 /* x		.. line length 36*/
    410 /* x		... line length 37*/
    411 /* x		.... line length 38*/
    412 /* x		..... line length 39*/
    413 /* x		...... line length 40*/
    414 /* x		....... line length 41*/
    415 /* x		........ line length 42*/
    416 //indent end
    417 
    418 //indent run -l38
    419 /* x		. line length 35 */
    420 /* x		.. line length 36 */
    421 /* x		... line length 37 */
    422 /* x		.... line length 38 */
    423 /*
    424  * x		..... line length 39
    425  */
    426 /*
    427  * x		...... line length 40
    428  */
    429 /*
    430  * x		....... line length 41
    431  */
    432 /*
    433  * x		........ line length 42
    434  */
    435 //indent end
    436 
    437 
    438 /*
    439  * The different types of comments that indent distinguishes, starting in
    440  * column 1 (see options '-fc1' and '-nfc1').
    441  */
    442 //indent input
    443 /* This is a traditional C block comment. */
    444 
    445 // This is a C99 line comment.
    446 
    447 /*
    448  * This is a box comment since its first line (the one above this line) is
    449  * empty.
    450  *
    451  *
    452  *
    453  * Its text gets wrapped.
    454  * Empty lines serve as paragraphs.
    455  */
    456 
    457 /**
    458  * This is a box comment
    459  * that is not re-wrapped.
    460  */
    461 
    462 /*-
    463  * This is a box comment
    464  * that is not re-wrapped.
    465  * It is often used for copyright declarations.
    466  */
    467 //indent end
    468 
    469 //indent run
    470 /* This is a traditional C block comment. */
    471 
    472 // This is a C99 line comment.
    473 
    474 /*
    475  * This is a box comment since its first line (the one above this line) is
    476  * empty.
    477  *
    478  *
    479  *
    480  * Its text gets wrapped. Empty lines serve as paragraphs.
    481  */
    482 
    483 /**
    484  * This is a box comment
    485  * that is not re-wrapped.
    486  */
    487 
    488 /*-
    489  * This is a box comment
    490  * that is not re-wrapped.
    491  * It is often used for copyright declarations.
    492  */
    493 //indent end
    494 
    495 
    496 /*
    497  * The different types of comments that indent distinguishes, starting in
    498  * column 9, so they are independent of the option '-fc1'.
    499  */
    500 //indent input
    501 void
    502 function(void)
    503 {
    504 	/* This is a traditional C block comment. */
    505 
    506 	/*
    507 	 * This is a box comment.
    508 	 *
    509 	 * It starts in column 9, not 1,
    510 	 * therefore it gets re-wrapped.
    511 	 */
    512 
    513 	/**
    514 	 * This is a box comment
    515 	 * that is not re-wrapped, even though it starts in column 9, not 1.
    516 	 */
    517 
    518 	/*-
    519 	 * This is a box comment
    520 	 * that is not re-wrapped.
    521 	 */
    522 }
    523 //indent end
    524 
    525 //indent run
    526 void
    527 function(void)
    528 {
    529 	/* This is a traditional C block comment. */
    530 
    531 	/*
    532 	 * This is a box comment.
    533 	 *
    534 	 * It starts in column 9, not 1, therefore it gets re-wrapped.
    535 	 */
    536 
    537 	/**
    538 	 * This is a box comment
    539 	 * that is not re-wrapped, even though it starts in column 9, not 1.
    540 	 */
    541 
    542 	/*-
    543 	 * This is a box comment
    544 	 * that is not re-wrapped.
    545 	 */
    546 }
    547 //indent end
    548 
    549 
    550 /*
    551  * Comments to the right of declarations.
    552  */
    553 //indent input
    554 void
    555 function(void)
    556 {
    557 	int decl;	/* declaration comment */
    558 
    559 	int decl;	/* short
    560 			 * multi-line
    561 			 * declaration
    562 			 * comment */
    563 
    564 	int decl;	/* long single-line declaration comment that is longer than the allowed line width */
    565 
    566 	int decl;	/* long multi-line declaration comment
    567  * that is longer than
    568  * the allowed line width */
    569 
    570 	int decl;	// C99 declaration comment
    571 
    572 	{
    573 		int decl;	/* indented declaration */
    574 		{
    575 			int decl;	/* indented declaration */
    576 			{
    577 				int decl;	/* indented declaration */
    578 				{
    579 					int decl;	/* indented declaration */
    580 				}
    581 			}
    582 		}
    583 	}
    584 }
    585 //indent end
    586 
    587 //indent run -ldi0
    588 void
    589 function(void)
    590 {
    591 	int decl;		/* declaration comment */
    592 
    593 	int decl;		/* short multi-line declaration comment */
    594 
    595 	int decl;		/* long single-line declaration comment that
    596 				 * is longer than the allowed line width */
    597 
    598 	int decl;		/* long multi-line declaration comment that is
    599 				 * longer than the allowed line width */
    600 
    601 	int decl;		// C99 declaration comment
    602 
    603 	{
    604 		int decl;	/* indented declaration */
    605 		{
    606 			int decl;	/* indented declaration */
    607 			{
    608 				int decl;	/* indented declaration */
    609 				{
    610 // $ This comment is indented so far to the right that it may overshoot the
    611 // $ right margin.  The allowed line length is increased to the starting
    612 // $ indentation of 56 plus a fixed amount of 25 columns, resulting in 81.
    613 // $ The trailing '*' would fit, but the trailing '/' is too much.
    614 					int decl;	/* indented declaration
    615 							 */
    616 				}
    617 			}
    618 		}
    619 	}
    620 }
    621 //indent end
    622 
    623 
    624 /*
    625  * Comments to the right of code.
    626  */
    627 //indent input
    628 void
    629 function(void)
    630 {
    631 	code();			/* code comment */
    632 	code();			/* code comment _________ to line length 78 */
    633 	code();			/* code comment __________ to line length 79 */
    634 	code();			/* code comment ___________ to line length 80 */
    635 	code();			/* code comment ____________ to line length 81 */
    636 	code();			/* code comment _____________ to line length 82 */
    637 
    638 /* $ In the following comments, the line length is measured after formatting. */
    639 	code();			/* code comment _________ to line length 78*/
    640 	code();			/* code comment __________ to line length 79*/
    641 	code();			/* code comment ___________ to line length 80*/
    642 	code();			/* code comment ____________ to line length 81*/
    643 	code();			/* code comment _____________ to line length 82*/
    644 
    645 	code();			/* short
    646 				 * multi-line
    647 				 * code
    648 				 * comment */
    649 
    650 	code();			/* long single-line code comment that is longer than the allowed line width */
    651 
    652 	code();			/* long multi-line code comment
    653  * that is longer than
    654  * the allowed line width */
    655 
    656 	code();			// C99 code comment
    657 	code();			// C99 code comment ________ to line length 78
    658 	code();			// C99 code comment _________ to line length 79
    659 	code();			// C99 code comment __________ to line length 80
    660 	code();			// C99 code comment ___________ to line length 81
    661 	code();			// C99 code comment ____________ to line length 82
    662 
    663 	if (cond) /* comment */
    664 		if (cond) /* comment */
    665 			if (cond) /* comment */
    666 				if (cond) /* comment */
    667 					if (cond) /* comment */
    668 						code(); /* comment */
    669 }
    670 //indent end
    671 
    672 //indent run -l78
    673 void
    674 function(void)
    675 {
    676 	code();			/* code comment */
    677 	code();			/* code comment _________ to line length 78 */
    678 	code();			/* code comment __________ to line length 79
    679 				 */
    680 	code();			/* code comment ___________ to line length 80
    681 				 */
    682 	code();			/* code comment ____________ to line length 81
    683 				 */
    684 	code();			/* code comment _____________ to line length
    685 				 * 82 */
    686 
    687 /* $ In the following comments, the line length is measured after formatting. */
    688 	code();			/* code comment _________ to line length 78 */
    689 	code();			/* code comment __________ to line length 79
    690 				 */
    691 	code();			/* code comment ___________ to line length 80
    692 				 */
    693 	code();			/* code comment ____________ to line length 81
    694 				 */
    695 	code();			/* code comment _____________ to line length
    696 				 * 82 */
    697 
    698 	code();			/* short multi-line code comment */
    699 
    700 	code();			/* long single-line code comment that is
    701 				 * longer than the allowed line width */
    702 
    703 	code();			/* long multi-line code comment that is longer
    704 				 * than the allowed line width */
    705 
    706 /* $ Trailing C99 comments are not wrapped, as indent would not correctly */
    707 /* $ recognize the continuation lines as continued comments. For block */
    708 /* $ comments this works since the comment has not ended yet. */
    709 	code();			// C99 code comment
    710 	code();			// C99 code comment ________ to line length 78
    711 	code();			// C99 code comment _________ to line length 79
    712 	code();			// C99 code comment __________ to line length 80
    713 	code();			// C99 code comment ___________ to line length 81
    714 	code();			// C99 code comment ____________ to line length 82
    715 
    716 	if (cond)		/* comment */
    717 		if (cond)	/* comment */
    718 			if (cond)	/* comment */
    719 				if (cond)	/* comment */
    720 					if (cond)	/* comment */
    721 						code();	/* comment */
    722 }
    723 //indent end
    724 
    725 
    726 //indent input
    727 /*
    728 	 * this
    729 		 * is a boxed
    730 			 * staircase.
    731 *
    732 * Its paragraphs get wrapped.
    733 
    734 There may also be
    735 		lines without asterisks.
    736 
    737  */
    738 //indent end
    739 
    740 //indent run
    741 /*
    742  * this is a boxed staircase.
    743  *
    744  * Its paragraphs get wrapped.
    745  *
    746  * There may also be lines without asterisks.
    747  *
    748  */
    749 //indent end
    750 
    751 
    752 //indent input
    753 void loop(void)
    754 {
    755 while(cond)/*comment*/;
    756 
    757 	while(cond)
    758 	/*comment*/;
    759 }
    760 //indent end
    761 
    762 //indent run
    763 void
    764 loop(void)
    765 {
    766 	while (cond) /* comment */;
    767 
    768 	while (cond)
    769 		/* comment */;
    770 }
    771 //indent end
    772 
    773 
    774 /*
    775  * The following comment starts really far to the right. To avoid that each
    776  * line only contains a single word, the maximum allowed line width is
    777  * extended such that each comment line may contain 22 characters.
    778  */
    779 //indent input
    780 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 */
    781 //indent end
    782 
    783 //indent run
    784 int		global_variable_with_really_long_name_that_reaches_up_to_column_83;	/* 1234567890123456789 1
    785 											 * 1234567890123456789 12
    786 											 * 1234567890123456789
    787 											 * 123
    788 											 * 1234567890123456789
    789 											 * 1234
    790 											 * 1234567890123456789
    791 											 * 12345
    792 											 * 1234567890123456789
    793 											 * 123456 */
    794 //indent end
    795 
    796 
    797 /*
    798  * Demonstrates handling of line-end '//' comments.
    799  *
    800  * Even though this type of comments had been added in C99, indent didn't
    801  * support these comments until 2021 and instead messed up the code in
    802  * seemingly unpredictable ways. It treated any sequence of '/' as a binary
    803  * operator, no matter whether it was '/' or '//' or '/////'.
    804  */
    805 //indent input
    806 int dummy // comment
    807     = // eq
    808     1		// one
    809     + // plus
    810     2;// two
    811 
    812 /////separator/////
    813 
    814 void function(void){}
    815 
    816 // Note: removing one of these line-end comments affected the formatting
    817 // of the main function below, before indent supported '//' comments.
    818 
    819 int
    820 main(void)
    821 {
    822 }
    823 //indent end
    824 
    825 //indent run
    826 int		dummy		// comment
    827 =				// eq
    828 1				// one
    829 +				// plus
    830 2;				// two
    831 
    832 /////separator/////
    833 
    834 void
    835 function(void)
    836 {
    837 }
    838 
    839 // Note: removing one of these line-end comments affected the formatting
    840 // of the main function below, before indent supported '//' comments.
    841 
    842 int
    843 main(void)
    844 {
    845 }
    846 //indent end
    847 
    848 
    849 /*
    850  * Between March 2021 and October 2021, indent supported C99 comments only
    851  * very basically. It messed up the following code, repeating the identifier
    852  * 'bar' twice in a row.
    853  */
    854 //indent input
    855 void c99_comment(void)
    856 {
    857 foo(); // C99 comment
    858 bar();
    859 }
    860 //indent end
    861 
    862 //indent run
    863 void
    864 c99_comment(void)
    865 {
    866 	foo();			// C99 comment
    867 	bar();
    868 }
    869 //indent end
    870 
    871 
    872 //indent input
    873 void
    874 comment_at_end_of_function(void)
    875 {
    876 	if (cond)
    877 		statement();
    878 	// comment
    879 }
    880 //indent end
    881 
    882 //indent run-equals-input
    883 
    884 
    885 //indent input
    886 int		decl;
    887 // end-of-line comment at the end of the file
    888 //indent end
    889 
    890 //indent run-equals-input
    891 
    892 
    893 /* A form feed in the middle of a comment is an ordinary character. */
    894 //indent input
    895 /*
    896  * AE
    898  */
    899 /*-AE*/
    901 //indent end
    902 
    903 //indent run-equals-input
    904 
    905 
    906 /*
    907  * Form feeds are seldom used, especially in comments, so treat them as an
    908  * ordinary character.
    909  */
    910 //indent input
    911 /* comment*/
    913 /*text* comment*/
    915 //indent end
    916 
    917 //indent run
    918 /*  comment */
    920 /* text* comment */
    922 //indent end
    923 
    924 //indent run-equals-prev-output -nsc
    925 
    926 //indent run-equals-input -nfc1
    927 
    928 
    929 /*
    930  * A completely empty line in a box comment must be copied unmodified to the
    931  * output. This is done in process_comment by adding a space to the end of an
    932  * otherwise empty comment. This space forces output_line to add some output,
    933  * but the trailing space is discarded, resulting in an empty line.
    934  */
    935 //indent input
    936 /*- comment
    937 
    938 
    939 end */
    940 //indent end
    941 
    942 //indent run-equals-input -nfc1
    943 
    944 
    945 //indent input
    946 /* comment comment comment comment mlute */
    947 //indent end
    948 
    949 //indent run -l40
    950 /*
    951  * comment comment comment comment
    952  * mlute
    953  */
    954 //indent end
    955 
    956 
    957 //indent input
    958 int f(void)
    959 {
    960 	if (0)
    961 		/* 12 1234 123 123456 1234 1234567 123 1234.  */;
    962 }
    963 //indent end
    964 
    965 /* The comment is too long to fit in a single line. */
    966 //indent run -l54
    967 int
    968 f(void)
    969 {
    970 	if (0)
    971 		/*
    972 		 * 12 1234 123 123456 1234 1234567 123
    973 		 * 1234.
    974 		 */;
    975 }
    976 //indent end
    977 
    978 /* The comment fits in a single line. */
    979 //indent run
    980 int
    981 f(void)
    982 {
    983 	if (0)
    984 		/* 12 1234 123 123456 1234 1234567 123 1234. */;
    985 }
    986 //indent end
    987 
    988 
    989 /*
    990  * Test for an edge cases in comment handling, having a block comment inside
    991  * a line comment. Before NetBSD pr_comment.c 1.96 from 2021-11-04, indent
    992  * wrongly assumed that the comment would end at the '*' '/', tokenizing the
    993  * second word 'still' as a type_outside_parentheses.
    994  */
    995 //indent input
    996 /* block comment */
    997 // line comment /* still a line comment */ still a line comment
    998 //indent end
    999 
   1000 //indent run-equals-input
   1001 
   1002 
   1003 /*
   1004  * Tests for comments that are not wrapped.
   1005  */
   1006 //indent input
   1007 /*-	tab space	tab space */
   1008 /*-	very-long-word-that-cannot-be-broken very-long-word-that-cannot-be-broken */
   1009 /*-	very-long-word-that-cannot-be-broken very-long-word-that-cannot-be-broken */
   1010 //indent end
   1011 
   1012 //indent run-equals-input -l5
   1013 
   1014 //indent run-equals-input -l32
   1015 
   1016 
   1017 /*
   1018  * Test for form feeds in nowrap comments.
   1019  */
   1020 //indent input
   1021 /*-*/
   1023 /*-<>*/
   1025 //indent end
   1026 
   1027 //indent run-equals-input
   1028 
   1029 
   1030 /*
   1031  * Test two completely empty lines in a wrap comment. The second empty line
   1032  * covers the condition ps.next_col_1 in copy_comment_wrap.
   1033  */
   1034 //indent input
   1035 /* line 1
   1036 
   1037 
   1038 line 4 */
   1039 //indent end
   1040 
   1041 //indent run
   1042 /*
   1043  * line 1
   1044  *
   1045  *
   1046  * line 4
   1047  */
   1048 //indent end
   1049 
   1050 //indent run-equals-input -nfc1
   1051 
   1052 //indent run-equals-input -nfc1 -nsc
   1053 
   1054 //indent run -nsc
   1055 /*
   1056 line 1
   1057 
   1058 
   1059 line 4
   1060  */
   1061 //indent end
   1062 
   1063 //indent run-equals-input -nsc -ncdb
   1064 
   1065 
   1066 /*
   1067  * Since 2019-04-04 and before pr_comment.c 1.123 from 2021-11-25, the
   1068  * function analyze_comment wrongly joined the two comments.
   1069  */
   1070 //indent input
   1071 /*
   1072  *//*
   1073 join*/
   1074 //indent end
   1075 
   1076 //indent run -nfc1
   1077 /*
   1078  */
   1079  /*
   1080   * join
   1081   */
   1082 //indent end
   1083 
   1084 
   1085 /*
   1086  * Since 2019-04-04 and before pr_comment.c 1.123 from 2021-11-25, the
   1087  * function analyze_comment generated malformed output by terminating the
   1088  * first comment but omitting the start of the second comment.
   1089  */
   1090 //indent input
   1091 /*
   1092 *//*
   1093 error*/
   1094 //indent end
   1095 
   1096 //indent run -nfc1
   1097 /*
   1098 */
   1099  /*
   1100   * error
   1101   */
   1102 //indent end
   1103 
   1104 
   1105 /*
   1106  * Ensure that there is exactly one space between the comment and the
   1107  * following binary operator.
   1108  */
   1109 //indent input
   1110 {
   1111 a /* */ > b;
   1112 a>b;
   1113 }
   1114 //indent end
   1115 
   1116 //indent run
   1117 {
   1118 	a /* */ > b;
   1119 	a > b;
   1120 }
   1121 //indent end
   1122