xref: /netbsd-src/tests/usr.bin/indent/lsym_comment.c (revision 7d62b00eb9ad855ffcd7da46b41e23feb5476fac)
1 /* $NetBSD: lsym_comment.c,v 1.4 2022/04/24 10:36:37 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 
735 	while (cond)
736 /* $ XXX: The spaces around the comment look unintentional. */
737 		 /* comment */ ;
738 }
739 //indent end
740 
741 
742 /*
743  * The following comment starts really far to the right. To avoid that each
744  * line only contains a single word, the maximum allowed line width is
745  * extended such that each comment line may contain 22 characters.
746  */
747 //indent input
748 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 */
749 //indent end
750 
751 //indent run
752 int		global_variable_with_really_long_name_that_reaches_up_to_column_83;	/* 1234567890123456789 1
753 											 * 1234567890123456789 12
754 											 * 1234567890123456789
755 											 * 123
756 											 * 1234567890123456789
757 											 * 1234
758 											 * 1234567890123456789
759 											 * 12345
760 											 * 1234567890123456789
761 											 * 123456 */
762 //indent end
763 
764 
765 /*
766  * Demonstrates handling of line-end '//' comments.
767  *
768  * Even though this type of comments had been added in C99, indent didn't
769  * support these comments until 2021 and instead messed up the code in
770  * seemingly unpredictable ways. It treated any sequence of '/' as a binary
771  * operator, no matter whether it was '/' or '//' or '/////'.
772  */
773 //indent input
774 int dummy // comment
775     = // eq
776     1		// one
777     + // plus
778     2;// two
779 
780 /////separator/////
781 
782 void function(void){}
783 
784 // Note: removing one of these line-end comments affected the formatting
785 // of the main function below, before indent supported '//' comments.
786 
787 int
788 main(void)
789 {
790 }
791 //indent end
792 
793 //indent run
794 int		dummy		// comment
795 =				// eq
796 1				// one
797 +				// plus
798 2;				// two
799 
800 /////separator/////
801 
802 void
803 function(void)
804 {
805 }
806 
807 // Note: removing one of these line-end comments affected the formatting
808 // of the main function below, before indent supported '//' comments.
809 
810 int
811 main(void)
812 {
813 }
814 //indent end
815 
816 
817 /*
818  * Between March 2021 and October 2021, indent supported C99 comments only
819  * very basically. It messed up the following code, repeating the identifier
820  * 'bar' twice in a row.
821  */
822 //indent input
823 void c99_comment(void)
824 {
825 foo(); // C99 comment
826 bar();
827 }
828 //indent end
829 
830 //indent run
831 void
832 c99_comment(void)
833 {
834 	foo();			// C99 comment
835 	bar();
836 }
837 //indent end
838 
839 
840 //indent input
841 void
842 comment_at_end_of_function(void)
843 {
844 	if (cond)
845 		statement();
846 	// comment
847 }
848 //indent end
849 
850 //indent run-equals-input
851 
852 
853 //indent input
854 int		decl;
855 // end-of-line comment at the end of the file
856 //indent end
857 
858 //indent run-equals-input
859 
860 
861 /* A form feed in the middle of a comment is an ordinary character. */
862 //indent input
863 /*
864  * AE
865  */
866 /*-AE*/
867 //indent end
868 
869 //indent run-equals-input
870 
871 
872 /*
873  * At the beginning of a block comment or after a '*', '\f' is special. This
874  * is an implementation detail that should not be visible from the outside.
875  * Form feeds in comments are seldom used though, so this is no problem.
876  */
877 //indent input
878 /* comment*/
879 /*text* comment*/
880 //indent end
881 
882 //indent run
883 /* * comment */
884 /* text* * comment */
885 //indent end
886 
887 /*
888  * Without 'star_comment_cont', there is no separator between the form feed
889  * and the surrounding text.
890  */
891 //indent run -nsc
892 /*comment */
893 /* text*comment */
894 //indent end
895 
896 //indent run-equals-input -nfc1
897 
898 
899 /*
900  * A completely empty line in a box comment must be copied unmodified to the
901  * output. This is done in process_comment by adding a space to the end of an
902  * otherwise empty comment. This space forces output_complete_line to add some output,
903  * but the trailing space is discarded, resulting in an empty line.
904  */
905 //indent input
906 /*- comment
907 
908 
909 end */
910 //indent end
911 
912 //indent run-equals-input -nfc1
913 
914 
915 //indent input
916 /* comment comment comment comment Ümläute */
917 //indent end
918 
919 //indent run -l40
920 /*
921  * comment comment comment comment
922  * Ümläute
923  */
924 //indent end
925 
926 
927 //indent input
928 int f(void)
929 {
930 	if (0)
931 		/* 12 1234 123 123456 1234 1234567 123 1234.  */;
932 }
933 //indent end
934 
935 /* The comment is too long to fit in a single line. */
936 //indent run -l54
937 int
938 f(void)
939 {
940 	if (0)
941 		/*
942 		 * 12 1234 123 123456 1234 1234567 123
943 		 * 1234.
944 		  */ ;
945 }
946 //indent end
947 
948 /* The comment fits in a single line. */
949 //indent run
950 int
951 f(void)
952 {
953 	if (0)
954 		 /* 12 1234 123 123456 1234 1234567 123 1234.  */ ;
955 }
956 //indent end
957 
958 
959 /*
960  * Test for an edge cases in comment handling, having a block comment inside
961  * a line comment. Before NetBSD pr_comment.c 1.96 from 2021-11-04, indent
962  * wrongly assumed that the comment would end at the '*' '/', tokenizing the
963  * second word 'still' as a type_outside_parentheses.
964  */
965 //indent input
966 /* block comment */
967 // line comment /* still a line comment */ still a line comment
968 //indent end
969 
970 //indent run-equals-input
971 
972 
973 /*
974  * Tests for comments that are not wrapped.
975  */
976 //indent input
977 /*-	tab space	tab space */
978 /*-	very-long-word-that-cannot-be-broken very-long-word-that-cannot-be-broken */
979 /*-	very-long-word-that-cannot-be-broken very-long-word-that-cannot-be-broken */
980 //indent end
981 
982 //indent run-equals-input -l5
983 
984 //indent run-equals-input -l32
985 
986 
987 /*
988  * Test for form feeds in nowrap comments.
989  */
990 //indent input
991 /*-*/
992 /*-<>*/
993 //indent end
994 
995 //indent run-equals-input
996 
997 
998 /*
999  * Test two completely empty lines in a wrap comment. The second empty line
1000  * covers the condition ps.next_col_1 in copy_comment_wrap.
1001  */
1002 //indent input
1003 /* line 1
1004 
1005 
1006 line 4 */
1007 //indent end
1008 
1009 //indent run
1010 /*
1011  * line 1
1012  *
1013  *
1014  * line 4
1015  */
1016 //indent end
1017 
1018 //indent run-equals-input -nfc1
1019 
1020 //indent run-equals-input -nfc1 -nsc
1021 
1022 //indent run -nsc
1023 /*
1024 line 1
1025 
1026 
1027 line 4
1028  */
1029 //indent end
1030 
1031 //indent run-equals-input -nsc -ncdb
1032 
1033 
1034 /*
1035  * Cover the code for expanding the comment buffer. As of 2021-11-07, the
1036  * default buffer size is 200. To actually fill the comment buffer, there must
1037  * be a single line of a comment that is longer than 200 bytes.
1038  */
1039 //indent input
1040 /*-_____10________20________30________40________50________60________70________80________90_______100_______110_______120_______130_______140_______150_______160_______170_______180_______190_______200 */
1041 //indent end
1042 
1043 //indent run-equals-input
1044 
1045 
1046 /*
1047  * Cover the code for expanding the comment buffer in com_terminate. As of
1048  * 2021-11-07, the default buffer size is 200, with a safety margin of 1 at
1049  * the beginning and another safety margin of 5 at the end. To force the
1050  * comment buffer to expanded in com_terminate, the comment must be exactly
1051  * 193 bytes long.
1052  */
1053 //indent input
1054 /*-_____10________20________30________40________50________60________70________80________90_______100_______110_______120_______130_______140_______150_______160_______170_______180_______190 */
1055 //indent end
1056 
1057 //indent run-equals-input
1058 
1059 
1060 /*
1061  * Since 2019-04-04 and before pr_comment.c 1.123 from 2021-11-25, the
1062  * function analyze_comment wrongly joined the two comments.
1063  */
1064 //indent input
1065 /*
1066  *//*
1067 join*/
1068 //indent end
1069 
1070 /* FIXME: The last line of the first comment must not be modified. */
1071 //indent run -nfc1
1072 /*
1073   *//*
1074   * join
1075   */
1076 //indent end
1077 
1078 
1079 /*
1080  * Since 2019-04-04 and before pr_comment.c 1.123 from 2021-11-25, the
1081  * function analyze_comment generated malformed output by terminating the
1082  * first comment but omitting the start of the second comment.
1083  */
1084 //indent input
1085 /*
1086 *//*
1087 error*/
1088 //indent end
1089 
1090 //indent run -nfc1
1091 /*
1092  *//*
1093   * error
1094   */
1095 //indent end
1096