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