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