opt_badp.c revision 1.13 1 /* $NetBSD: opt_badp.c,v 1.13 2023/06/26 11:01:08 rillig Exp $ */
2
3 /*
4 * Tests for the options '-badp' and '-nbadp'.
5 *
6 * The option '-badp' forces a blank line between the first set of declarations
7 * in a function and the next comment or statement. It produces a blank line
8 * even if there are no declarations.
9 */
10
11
12 /* An empty function body does not need a blank line. */
13 //indent input
14 void
15 empty(void)
16 {
17 }
18 //indent end
19
20 //indent run-equals-input -badp
21
22 //indent run-equals-input -nbadp
23
24
25 /* If an empty function body already has a blank line, it is kept. */
26 //indent input
27 void
28 blank(void)
29 {
30
31 }
32 //indent end
33
34 //indent run-equals-input -badp
35
36 //indent run-equals-input -nbadp
37
38
39 /*
40 * If a function body has only declarations (doesn't occur in practice), it
41 * does not need an empty line.
42 */
43 //indent input
44 void
45 declaration(void)
46 {
47 int decl;
48 }
49 //indent end
50
51 //indent run-equals-input -badp
52
53 //indent run-equals-input -nbadp
54
55
56 /*
57 * A function body without declarations gets an empty line above the first
58 * statement.
59 */
60 //indent input
61 void
62 statement(void)
63 {
64 stmt();
65 }
66 //indent end
67
68 /* TODO: add blank line */
69 //indent run-equals-input -badp
70
71 //indent run-equals-input -nbadp
72
73
74 /*
75 * A function body with a declaration and a statement gets a blank line between
76 * those.
77 */
78 //indent input
79 void
80 declaration_statement(void)
81 {
82 int decl;
83 stmt();
84 }
85 //indent end
86
87 //indent run -badp
88 void
89 declaration_statement(void)
90 {
91 int decl;
92 /* $ FIXME: missing empty line */
93 stmt();
94 }
95 //indent end
96
97 //indent run-equals-input -nbadp
98
99
100 /* If there already is a blank line in the right place, it is kept. */
101 //indent input
102 static void
103 declaration_blank_statement(void)
104 {
105 int decl;
106
107 stmt();
108 }
109 //indent end
110
111 //indent run-equals-input -badp
112
113 //indent run-equals-input -nbadp
114
115
116 /* Additional blank lines are kept. To remove them, see the '-sob' option. */
117 //indent input
118 static void
119 declaration_blank_blank_statement(void)
120 {
121 int decl;
122
123
124
125 stmt();
126 }
127 //indent end
128
129 //indent run-equals-input -badp
130
131 //indent run-equals-input -nbadp
132
133
134 /*
135 * The blank line is only inserted at the top of a function body, not in nested
136 * block statements.
137 */
138 //indent input
139 static void
140 nested(void)
141 {
142 {
143 int decl;
144 stmt();
145 }
146 }
147 //indent end
148
149 //indent run-equals-input -badp
150
151 //indent run-equals-input -nbadp
152
153
154 /*
155 * A struct declaration or an initializer are not function bodies, so don't
156 * add a blank line after them.
157 */
158 //indent input
159 struct {
160 int member[2];
161 } s = {
162 {
163 0,
164 0,
165 }
166 };
167 //indent end
168
169 //indent run-equals-input -di0 -badp
170
171 //indent run-equals-input -di0 -nbadp
172