summaryrefslogtreecommitdiff
path: root/tests/usr.bin/indent/opt_ci.c
blob: 63752a824bc5819e9e1a8941529700fb1d43a7f2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
/* $NetBSD: opt_ci.c,v 1.11 2023/06/10 08:17:04 rillig Exp $ */

/*
 * Tests for the option '-ci', which controls the indentation of continuation
 * lines in statements and declarations, but only inside a function.
 */

/*
 * Top level expressions with and without parentheses.
 */
//indent input
int top_level = 1 +
 2;
int top_level = (1 +
 2 + (
  3));
//indent end

//indent run -ci0
int		top_level = 1 +
2;
int		top_level = (1 +
			     2 + (
				  3));
//indent end

//indent run-equals-prev-output -ci2

//indent run-equals-prev-output -ci4

//indent run-equals-prev-output -ci8

//indent run -ci0 -nlp
int		top_level = 1 +
2;
int		top_level = (1 +
	2 + (
		3));
//indent end

//indent run -ci2 -nlp
int		top_level = 1 +
2;
int		top_level = (1 +
  2 + (
    3));
//indent end

/*
 * Between 2019-04-04 and 2023-06-09, there was a special rule that prevented
 * indentation based on the number of open parentheses, in the case that the
 * continuation indentation is half an indentation level, maybe to prevent that
 * the continuation line has the same indentation as a follow-up statement,
 * such as in 'if' statements. To prevent such ambiguities, see '-eei'.
 */
//indent run -ci4 -nlp
int		top_level = 1 +
2;
int		top_level = (1 +
    2 + (
	3));
//indent end


/*
 * Declarations in functions without parentheses.
 */
//indent input
int
sum(int a, int b)
{
	return a +
	 b;
	return first +
	 second;
}
//indent end

//indent run -ci0
int
sum(int a, int b)
{
	return a +
		b;
	return first +
		second;
}
//indent end

//indent run -ci2
int
sum(int a, int b)
{
	return a +
	  b;
	return first +
	  second;
}
//indent end

//indent run -ci4
int
sum(int a, int b)
{
	return a +
	    b;
	return first +
	    second;
}
//indent end

//indent run -ci8
int
sum(int a, int b)
{
	return a +
		b;
	return first +
		second;
}
//indent end


/*
 * Continued statements with expressions in parentheses.
 */
//indent input
int
sum(int a, int b)
{
	return (a +
	b);
	return (first +
	second + (
	third));
}
//indent end

//indent run -ci0
int
sum(int a, int b)
{
	return (a +
		b);
	return (first +
		second + (
			  third));
}
//indent end

//indent run-equals-prev-output -ci2

//indent run-equals-prev-output -ci4

//indent run-equals-prev-output -ci8

//indent run -ci2 -nlp
int
sum(int a, int b)
{
	return (a +
	  b);
	return (first +
	  second + (
	    third));
}
//indent end

//indent run -ci4 -nlp
int
sum(int a, int b)
{
	return (a +
	    b);
	return (first +
	    second + (
		third));
}
//indent end

//indent run -ci8 -nlp
int
sum(int a, int b)
{
	return (a +
		b);
	return (first +
		second + (
			third));
}
//indent end


/*
 * In the default configuration, the indentation level from '-i' is the same
 * as the continuation indentation from '-ci'.  The difference between these
 * becomes visible for structural macros like 'forever' or 'foreach'.
 */
//indent input
#define forever for (;;)
void
function(void)
{
	forever
		stmt();

	forever {
		stmt();
	}
}
//indent end

//indent run-equals-input

/*
 * The difference between the block indentation and the continuation
 * indentation only becomes visible when these two differ.
 */
//indent run -i8 -ci4
#define forever for (;;)
void
function(void)
{
	forever
	    stmt();

	forever {
		stmt();
	}
}
//indent end


//indent input
{
	size_t last_word_len = com.len
	    - (size_t)(last_blank + 1);
}
//indent end

//indent run-equals-input -ldi0 -ci4