xref: /netbsd-src/tests/usr.bin/indent/opt_fc1.c (revision 7d62b00eb9ad855ffcd7da46b41e23feb5476fac)
1 /* $NetBSD: opt_fc1.c,v 1.8 2022/04/24 09:04:12 rillig Exp $ */
2 
3 /*
4  * Tests for the options '-fc1' and '-nfc1'.
5  *
6  * The option '-fc1' formats comments in column 1.
7  *
8  * The option '-nfc1' preserves the original formatting of comments that start
9  * in column 1.
10  */
11 
12 //indent input
13 /*
14  * A comment
15  * in column 1.
16  *
17  *
18  *
19  */
20 //indent end
21 
22 //indent run -fc1
23 /*
24  * A comment in column 1.
25  *
26  *
27  *
28  */
29 //indent end
30 
31 //indent run-equals-input -nfc1
32 
33 
34 //indent input
35 /* $ Neither indentation nor surrounding spaces. */
36 /*narrow*/
37 
38 /* $ Indented by a single space, single spaces around the text. */
39  /* space */
40 
41 /* $ Indented by a single tab, single tabs around the text. */
42 	/*	indented tab	*/
43 
44 /* $ The space between these comments gets removed. */
45 /* block1 */ /* block2 */
46 
47 /* $ Both comment texts get surrounded by spaces. */
48 /*block1*//*block2*/
49 //indent end
50 
51 //indent run -fc1
52 /* $ The comment text got surrounded by spaces. */
53 /* narrow */
54 
55 /* $ The indentation got removed. */
56 /* space */
57 
58 /* $ The indentation got removed, only the leading tab got replaced by a space. */
59 /* indented tab	*/
60 
61 /* $ The space between these comments got removed. */
62 /* block1 *//* block2 */
63 
64 /* $ Both comment texts got surrounded by spaces. */
65 /* block1 *//* block2 */
66 //indent end
67 
68 //indent run -nfc1
69 /* $ No spaces got added around the comment text. */
70 /*narrow*/
71 
72 /* $ The indentation of a single space was preserved. */
73 /* $ If the comment were moved to column 1, it would change from the area */
74 /* $ of 'comments that may be formatted' to the area of 'comments that must */
75 /* $ not be formatted. The indentation of a single space prevents this. */
76  /* space */
77 
78 /* $ The indentation was changed from a single tab to a single space. */
79  /* indented tab	*/
80 
81 /* $ The space between these two comments got removed. */
82 /* $ XXX: The option '-nfc1' says that comments in column 1 do not get */
83 /* $ formatted, but the comment 'block1' was moved from column 1 to 2. */
84 /* $ This is probably because there is a second comment in the same line. */
85  /* block1 *//* block2 */
86 
87 /* $ It may seem strange at first that the left comment is not touched */
88 /* $ but the right comment gets spaces added. This difference is the */
89 /* $ exact purpose of the option '-nfc1', which says "do not touch comments */
90 /* $ that start in column 1. The first comment starts in column 1, the */
91 /* $ second comment doesn't. */
92 /* $ XXX: The option '-nfc1' says that comments in column 1 do not get */
93 /* $ formatted, but the comment 'block1' was moved from column 1 to 2. */
94 /* $ This is probably because there is a second comment in the same line. */
95  /*block1*//* block2 */
96 //indent end
97 
98 
99 /*
100  * Since 2019-04-04 and before pr_comment.c 1.123 from 2021-11-25, the
101  * function analyze_comment wrongly joined the two comments.
102  */
103 //indent input
104 /*
105  * A multi-line comment that starts
106  * in column 1.
107  *//* followed by another multi-line comment
108  * that starts in column 4.
109  */
110 //indent end
111 
112 //indent run -fc1
113 /*
114  * A multi-line comment that starts in column 1.
115  *//*
116  * followed by another multi-line comment that starts in column 4.
117  */
118 //indent end
119 
120 /* FIXME: The last line of the first comment must not be modified. */
121 //indent run -nfc1
122 /*
123  * A multi-line comment that starts
124  * in column 1.
125   *//*
126   * followed by another multi-line comment that starts in column 4.
127   */
128 //indent end
129 
130 
131 //indent input
132 /* comment */ int decl2; /* comment */
133 /* looooooooooooooooooooooooooooooooooooooooong first comment */ int decl2; /* second comment */
134 /* first comment */ int decl2; /* looooooooooooooooooooooooooooooooooooooooong second comment */
135 //indent end
136 
137 //indent run -fc1
138  /* comment */ int decl2;	/* comment */
139  /* looooooooooooooooooooooooooooooooooooooooong first comment */ int decl2;	/* second comment */
140  /* first comment */ int decl2;	/* looooooooooooooooooooooooooooooooooooooooong
141 				 * second comment */
142 //indent end
143 
144 //indent run-equals-prev-output -nfc1
145