summaryrefslogtreecommitdiff
path: root/tests/usr.bin/indent/indent_off_on.c
blob: 5d55c01ffdc2c176b84ec1d1a6a618c6c01eafaf (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
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
/* $NetBSD: indent_off_on.c,v 1.15 2023/06/04 22:20:04 rillig Exp $ */

/*
 * Tests for the comments 'INDENT OFF' and 'INDENT ON', which temporarily
 * disable formatting, copying the input directly to the output.  Internally,
 * indent still keeps track of the number of braces and other indentation.
 */

//indent input
{}

/*INDENT OFF*/
/*INDENT ON*/

{}
//indent end

//indent run
{
}

/*INDENT OFF*/
/*INDENT ON*/

{
}
//indent end


//indent input
{}


/*INDENT OFF*/
/*INDENT ON*/
//indent end

//indent run
{
}


/*INDENT OFF*/
/*INDENT ON*/
//indent end


//indent input
{}
 /* INDENT OFF */
 /* INDENT ON */
{}
//indent end

//indent run
{
}
 /* INDENT OFF */
 /* INDENT ON */
{
}
//indent end


//indent input
{}
	/* INDENT OFF */
	/* INDENT ON */
{}
//indent end

//indent run
{
}
	/* INDENT OFF */
	/* INDENT ON */
{
}
//indent end


/*
 * The INDENT comments can be written without space between the words, but
 * nobody does this.
 */
//indent input
int   decl   ;
/*INDENTOFF*/
int   decl   ;
/*INDENTON*/
int   decl   ;
//indent end

//indent run -di0
int decl;
/*INDENTOFF*/
int   decl   ;
/*INDENTON*/
int decl;
//indent end


/*
 * Any whitespace around the 'INDENT ON/OFF' is ignored, as is any whitespace
 * between the two words.
 */
//indent input
int   decl   ;
/*		INDENT		OFF		*/
int   decl   ;
/*		INDENT		ON		*/
int   decl   ;
//indent end

//indent run -di0
int decl;
/*		INDENT		OFF		*/
int   decl   ;
/*		INDENT		ON		*/
int decl;
//indent end


//indent input
/*INDENT OFF*/
/* No formatting takes place here. */
int format( void ) {{{
/*INDENT ON*/
}}}
//indent end

//indent run
/*INDENT OFF*/
/* No formatting takes place here. */
int format( void ) {{{
/*INDENT ON*/
		}
	}
}
//indent end


//indent input
/* INDENT OFF */
void indent_off ( void ) ;
/*  INDENT */
void indent_on ( void ) ;
/* INDENT OFF */
void indent_off ( void ) ;
	/* INDENT ON */
void indent_on ( void ) ;	/* the comment may be indented */
/* INDENT		OFF					*/
void indent_off ( void ) ;
/* INDENTATION ON */
void indent_still_off ( void ) ;	/* due to the word 'INDENTATION' */
/* INDENT ON * */
void indent_still_off ( void ) ;	/* due to the extra '*' at the end */
/* INDENT ON */
void indent_on ( void ) ;
/* INDENT: OFF */
void indent_still_on ( void ) ;	/* due to the colon in the middle */
/* INDENT OFF */		/* extra comment */
void indent_still_on ( void ) ;	/* due to the extra comment to the right */
//indent end

//indent run
/* INDENT OFF */
void indent_off ( void ) ;
/*  INDENT */
void		indent_on(void);
/* INDENT OFF */
void indent_off ( void ) ;
	/* INDENT ON */
void		indent_on(void);	/* the comment may be indented */
/* INDENT		OFF					*/
void indent_off ( void ) ;
/* INDENTATION ON */
void indent_still_off ( void ) ;	/* due to the word 'INDENTATION' */
/* INDENT ON * */
void indent_still_off ( void ) ;	/* due to the extra '*' at the end */
/* INDENT ON */
void		indent_on(void);
/* INDENT: OFF */
void		indent_still_on(void);	/* due to the colon in the middle */
/* $ The extra comment got moved to a separate line, but indenting is still */
/* $ on because the 'INDENT OFF' comment was not in a line of its own. */
/* INDENT OFF */
/* extra comment */
void		indent_still_on(void);	/* due to the extra comment to the
					 * right */
//indent end


/*
 * Try to confuse indent by having a string literal that has an embedded
 * INDENT comment.  Indent doesn't get confused though because it requires the
 * INDENT comment to go from the very beginning of the line to the very end of
 * the line.
 */
//indent input
const char *str = "\
/* INDENT OFF */\
"   ,   ch;
//indent end

//indent run
const char     *str = "\
/* INDENT OFF */\
", ch;
//indent end


/*
 * The keywords in the INDENT comments must all be uppercase.
 */
//indent input
int   on   ;
/* indent off */
int   still_on   ;
/* INDENT off */
int   still_on   ;
/* indent OFF */
int   still_on   ;
/* INDENT OFF */
int   finally_off   ;
//indent end

//indent run -di0
int on;
/* indent off */
int still_on;
/* INDENT off */
int still_on;
/* indent OFF */
int still_on;
/* INDENT OFF */
int   finally_off   ;
//indent end


/*
 * Ensure that in 'INDENT OFF' mode, no blank line is added between lines, even
 * when requested via the -bacc option.
 */
//indent input
/* INDENT OFF */
int declaration;
#if 0
#endif
int declaration;
/* INDENT ON */
//indent end

//indent run-equals-input -bacc


/*
 * If an 'INDENT OFF' comment directly follows a line continuation, the line
 * continuation is dropped but the rest of the line is still formatted.
 */
//indent input
int x ; \
/* INDENT OFF */
  int y ;
/* INDENT ON */
int z ;
//indent end

//indent run
int		x;
/* INDENT OFF */
  int y ;
/* INDENT ON */
int		z;
//indent end