xref: /netbsd-src/tests/usr.bin/indent/fmt_else_comment.c (revision 53b02e147d4ed531c0d2a5ca9b3e8026ba3e99b5)
1 /*	$NetBSD: fmt_else_comment.c,v 1.2 2021/11/19 22:24:29 rillig Exp $	*/
2 /* $FreeBSD: head/usr.bin/indent/tests/elsecomment.0.pro 314613 2017-03-03 20:15:22Z ngie $ */
3 
4 /*
5  * Tests for comments after 'if (expr)' and 'else'. If the option '-br' is
6  * given (or rather, if '-bl' is not given), indent looks ahead to the
7  * following significant token to see whether it is a '{', it then moves the
8  * comments after the '{'.
9  *
10  * See also:
11  *	FreeBSD r303484
12  *	FreeBSD r309342
13  */
14 
15 /*
16  * The two 'if' statements below exercise two different code paths, even
17  * though they look very similar.
18  */
19 #indent input
20 void t(void) {
21 	if (1) /* a */ int a; else /* b */ int b;
22 
23 	if (1) /* a */
24 		int a;
25 	else /* b */
26 		int b;
27 }
28 #indent end
29 
30 #indent run
31 void
32 t(void)
33 {
34 	if (1)			/* a */
35 		int		a;
36 	else			/* b */
37 		int		b;
38 
39 	if (1)			/* a */
40 		int		a;
41 	else			/* b */
42 		int		b;
43 }
44 #indent end
45 
46 
47 #indent input
48 void t(void) {
49 	if (1) {
50 
51 	}
52 
53 
54 
55 	/* Old indent would remove the 3 blank lines above, awaiting "else". */
56 
57 	if (1) {
58 		int a;
59 	}
60 
61 
62 	else if (0) {
63 		int b;
64 	}
65 	/* test */
66 	else
67 		;
68 
69 	if (1)
70 		;
71 	else /* Old indent would get very confused here */
72 	/* We also mustn't assume that there's only one comment */
73 	/* before the left brace. */
74 	{
75 
76 
77 	}
78 }
79 #indent end
80 
81 #indent run -bl
82 void
83 t(void)
84 {
85 	if (1)
86 	{
87 
88 	}
89 
90 
91 
92 	/*
93 	 * Old indent would remove the 3 blank lines above, awaiting "else".
94 	 */
95 
96 	if (1)
97 	{
98 		int		a;
99 	} else if (0)
100 	{
101 		int		b;
102 	}
103 	/* test */
104 	else
105 		;
106 
107 	if (1)
108 		;
109 	else			/* Old indent would get very confused here */
110 		/* We also mustn't assume that there's only one comment */
111 		/* before the left brace. */
112 	{
113 
114 
115 	}
116 }
117 #indent end
118