opt_ci.c revision 1.2 1 /* $NetBSD: opt_ci.c,v 1.2 2021/11/01 22:48:56 rillig Exp $ */
2 /* $FreeBSD$ */
3
4 /*
5 * Tests for the option '-ci', which controls the indentation of continuation
6 * lines in statements and declarations, but only inside a function.
7 */
8
9 /*
10 * Top level expressions with and without parentheses.
11 */
12 #indent input
13 int top_level = 1 +
14 2;
15 int top_level = (1 +
16 2 + (
17 3));
18 #indent end
19
20 #indent run -ci0
21 int top_level = 1 +
22 2;
23 int top_level = (1 +
24 2 + (
25 3));
26 #indent end
27 #indent run-equals-prev-output -ci2
28 #indent run-equals-prev-output -ci4
29 #indent run-equals-prev-output -ci8
30
31 #indent run -ci0 -nlp
32 int top_level = 1 +
33 2;
34 int top_level = (1 +
35 2 + (
36 3));
37 #indent end
38
39 #indent run -ci2 -nlp
40 int top_level = 1 +
41 2;
42 int top_level = (1 +
43 2 + (
44 3));
45 #indent end
46
47 /*
48 * Since '-ci4' is half an indentation level, indent all continuations using
49 * the same level, no matter how many parentheses there are. The rationale for
50 * this may have been to prevent that the continuation line has the same
51 * indentation as a follow-up statement, such as in 'if' statements.
52 */
53 #indent run -ci4 -nlp
54 int top_level = 1 +
55 2;
56 int top_level = (1 +
57 2 + (
58 3));
59 #indent end
60
61 /*
62 * Declarations in functions without parentheses.
63 */
64 #indent input
65 int
66 sum(int a, int b)
67 {
68 return a +
69 b;
70 return first +
71 second;
72 }
73 #indent end
74
75 #indent run -ci0
76 int
77 sum(int a, int b)
78 {
79 return a +
80 b;
81 return first +
82 second;
83 }
84 #indent end
85
86 #indent run -ci2
87 int
88 sum(int a, int b)
89 {
90 return a +
91 b;
92 return first +
93 second;
94 }
95 #indent end
96
97 #indent run -ci4
98 int
99 sum(int a, int b)
100 {
101 return a +
102 b;
103 return first +
104 second;
105 }
106 #indent end
107
108 #indent run -ci8
109 int
110 sum(int a, int b)
111 {
112 return a +
113 b;
114 return first +
115 second;
116 }
117 #indent end
118
119
120 /*
121 * Continued statements with expressions in parentheses.
122 */
123 #indent input
124 int
125 sum(int a, int b)
126 {
127 return (a +
128 b);
129 return (first +
130 second + (
131 third));
132 }
133 #indent end
134
135 #indent run -ci0
136 int
137 sum(int a, int b)
138 {
139 return(a +
140 b);
141 return(first +
142 second + (
143 third));
144 }
145 #indent end
146 #indent run-equals-prev-output -ci2
147 #indent run-equals-prev-output -ci4
148 #indent run-equals-prev-output -ci8
149
150 #indent run -ci2 -nlp
151 int
152 sum(int a, int b)
153 {
154 return(a +
155 b);
156 return(first +
157 second + (
158 third));
159 }
160 #indent end
161
162 /*
163 * Since '-ci4' is half an indentation level, indent all continuations using
164 * the same level, no matter how many parentheses there are. The rationale for
165 * this may have been to prevent that the continuation line has the same
166 * indentation as a follow-up statement, such as in 'if' statements.
167 */
168 #indent run -ci4 -nlp
169 int
170 sum(int a, int b)
171 {
172 return(a +
173 b);
174 return(first +
175 second + (
176 third));
177 }
178 #indent end
179
180 #indent run -ci8 -nlp
181 int
182 sum(int a, int b)
183 {
184 return(a +
185 b);
186 return(first +
187 second + (
188 third));
189 }
190 #indent end
191