indent_off_on.c revision 1.9 1 /* $NetBSD: indent_off_on.c,v 1.9 2023/05/11 18:13:55 rillig Exp $ */
2
3 /*
4 * Tests for the comments 'INDENT OFF' and 'INDENT ON', which temporarily
5 * disable formatting, copying the input directly to the output. Internally,
6 * indent still keeps track of the number of braces and other indentation.
7 */
8
9 //indent input
10 {}
11
12 /*INDENT OFF*/
13 /*INDENT ON*/
14
15 {}
16 //indent end
17
18 /*
19 * XXX: It is asymmetric that 'INDENT OFF' is kept as is, while 'INDENT ON'
20 * gets enclosed with spaces.
21 */
22 //indent run
23 {
24 }
25 /* $ FIXME: This empty line must stay. */
26 /*INDENT OFF*/
27 /* $ FIXME: The empty line below must be above the 'OFF' comment. */
28
29 /* INDENT ON */
30
31 {
32 }
33 //indent end
34
35
36 //indent input
37 {}
38
39
40 /*INDENT OFF*/
41 /*INDENT ON*/
42 //indent end
43
44 //indent run
45 {
46 }
47
48 /*INDENT OFF*/
49 /* $ FIXME: The empty line below must be above the 'OFF' comment. */
50
51 /* INDENT ON */
52 //indent end
53
54
55 //indent input
56 {}
57 /* INDENT OFF */
58 /* INDENT ON */
59 {}
60 //indent end
61
62 /*
63 * XXX: It is asymmetric that 'INDENT OFF' is indented, while 'INDENT ON'
64 * is aligned.
65 */
66 //indent run
67 {
68 }
69 /* INDENT OFF */
70 /* $ FIXME: The empty line below must be removed. */
71
72 /* INDENT ON */
73 {
74 }
75 //indent end
76
77
78 //indent input
79 {}
80 /* INDENT OFF */
81 /* INDENT ON */
82 {}
83 //indent end
84
85 /*
86 * XXX: It is asymmetric that 'INDENT OFF' is indented, while 'INDENT ON'
87 * is aligned.
88 */
89 //indent run
90 {
91 }
92 /* INDENT OFF */
93 /* $ FIXME: The empty line below must be removed. */
94
95 /* INDENT ON */
96 {
97 }
98 //indent end
99
100
101 /*
102 * The INDENT comments can be written without space between the words, but
103 * nobody does this.
104 */
105 //indent input
106 int decl ;
107 /*INDENTOFF*/
108 int decl ;
109 /*INDENTON*/
110 int decl ;
111 //indent end
112
113 //indent run -di0
114 int decl;
115 /*INDENTOFF*/
116 int decl ;
117 /* $ FIXME: The empty line below must be removed. */
118
119 /* INDENTON */
120 int decl;
121 //indent end
122
123
124 /*
125 * Any whitespace around the 'INDENT ON/OFF' is ignored, as is any whitespace
126 * between the two words.
127 */
128 //indent input
129 int decl ;
130 /* INDENT OFF */
131 int decl ;
132 /* INDENT ON */
133 int decl ;
134 //indent end
135
136 /*
137 * XXX: It is asymmetric that 'INDENT OFF' is indented, while 'INDENT ON'
138 * is pushed to the start of the line.
139 */
140 //indent run -di0
141 int decl;
142 /* INDENT OFF */
143 int decl ;
144 /* $ FIXME: The empty line below must be removed. */
145
146 /* INDENT ON */
147 int decl;
148 //indent end
149
150
151 //indent input
152 /*INDENT OFF*/
153 /* No formatting takes place here. */
154 int format( void ) {{{
155 /*INDENT ON*/
156 }}}
157 //indent end
158
159 //indent run
160 /*INDENT OFF*/
161 /* No formatting takes place here. */
162 int format( void ) {{{
163 /* $ XXX: Why is the INDENT ON comment indented? */
164 /* $ XXX: Why does the INDENT ON comment get spaces, but not the OFF comment? */
165 /* $ FIXME: The empty line below must be removed. */
166
167 /* INDENT ON */
168 }
169 }
170 }
171 //indent end
172
173
174 //indent input
175 /* INDENT OFF */
176 void indent_off ( void ) ;
177 /* INDENT */
178 void indent_on ( void ) ;
179 /* INDENT OFF */
180 void indent_off ( void ) ;
181 /* INDENT ON */
182 void indent_on ( void ) ; /* the comment may be indented */
183 /* INDENT OFF */
184 void indent_off ( void ) ;
185 /* INDENTATION ON */
186 void indent_still_off ( void ) ; /* due to the word 'INDENTATION' */
187 /* INDENT ON * */
188 void indent_still_off ( void ) ; /* due to the extra '*' at the end */
189 /* INDENT ON */
190 void indent_on ( void ) ;
191 /* INDENT: OFF */
192 void indent_still_on ( void ) ; /* due to the colon in the middle */
193 /* INDENT OFF */ /* extra comment */
194 void indent_still_on ( void ) ; /* due to the extra comment to the right */
195 //indent end
196
197 //indent run
198 /* INDENT OFF */
199 void indent_off ( void ) ;
200 /* $ FIXME: The empty line below must be removed. */
201
202 /* $ XXX: The double space from the below comment got merged to a single */
203 /* $ XXX: space even though the comment might be regarded to be still in */
204 /* $ XXX: the OFF section. */
205 /* INDENT */
206 void indent_on(void);
207 /* INDENT OFF */
208 void indent_off ( void ) ;
209 /* $ FIXME: The empty line below must be removed. */
210
211 /* $ XXX: The below comment got moved from column 9 to column 1. */
212 /* INDENT ON */
213 void indent_on(void); /* the comment may be indented */
214 /* INDENT OFF */
215 void indent_off ( void ) ;
216 /* INDENTATION ON */
217 void indent_still_off ( void ) ; /* due to the word 'INDENTATION' */
218 /* INDENT ON * */
219 void indent_still_off ( void ) ; /* due to the extra '*' at the end */
220 /* $ FIXME: The empty line below must be removed. */
221
222 /* INDENT ON */
223 void indent_on(void);
224 /* INDENT: OFF */
225 void indent_still_on(void); /* due to the colon in the middle */
226 /* $ The extra comment got moved to the left since there is no code in */
227 /* $ that line. */
228 /* INDENT OFF *//* extra comment */
229 void indent_still_on(void); /* due to the extra comment to the
230 * right */
231 //indent end
232
233
234 /*
235 * Try to confuse indent by having a string literal that has an embedded
236 * INDENT comment. Indent doesn't get confused though because it requires the
237 * INDENT comment to go from the very beginning of the line to the very end of
238 * the line.
239 */
240 //indent input
241 const char *str = "\
242 /* INDENT OFF */\
243 " , ch;
244 //indent end
245
246 //indent run
247 const char *str = "\
248 /* INDENT OFF */\
249 ", ch;
250 //indent end
251
252
253 /*
254 * The keywords in the INDENT comments must all be uppercase.
255 */
256 //indent input
257 int on ;
258 /* indent off */
259 int still_on ;
260 /* INDENT off */
261 int still_on ;
262 /* indent OFF */
263 int still_on ;
264 /* INDENT OFF */
265 int finally_off ;
266 //indent end
267
268 //indent run -di0
269 int on;
270 /* indent off */
271 int still_on;
272 /* INDENT off */
273 int still_on;
274 /* indent OFF */
275 int still_on;
276 /* INDENT OFF */
277 int finally_off ;
278 //indent end
279