xref: /netbsd-src/tests/usr.bin/indent/opt_bs.c (revision 47306038c7d906b62edca1fd252c0e0d0772f5a0)
1 /* $NetBSD: opt_bs.c,v 1.10 2022/04/24 09:04:12 rillig Exp $ */
2 
3 /*
4  * Tests for the options '-bs' and '-nbs' ("blank after sizeof").
5  *
6  * The option '-bs' forces a space after the keyword 'sizeof'.
7  *
8  * The option '-nbs' removes horizontal whitespace after the keyword 'sizeof',
9  * unless the next token is a word as well.
10  */
11 
12 //indent input
13 void
example(int i)14 example(int i)
15 {
16 	print(sizeof(i));
17 	print(sizeof(int));
18 
19 	print(sizeof i);
20 	print(sizeof (i));
21 	print(sizeof (int));
22 
23 	print(sizeof   i);
24 	print(sizeof   (i));
25 	print(sizeof   (int));
26 }
27 //indent end
28 
29 //indent run -bs
30 void
example(int i)31 example(int i)
32 {
33 	print(sizeof (i));
34 	print(sizeof (int));
35 
36 	print(sizeof i);
37 	print(sizeof (i));
38 	print(sizeof (int));
39 
40 	print(sizeof i);
41 	print(sizeof (i));
42 	print(sizeof (int));
43 }
44 //indent end
45 
46 //indent run -nbs
47 void
example(int i)48 example(int i)
49 {
50 	print(sizeof(i));
51 	print(sizeof(int));
52 
53 	print(sizeof i);
54 	print(sizeof(i));
55 	print(sizeof(int));
56 
57 	print(sizeof i);
58 	print(sizeof(i));
59 	print(sizeof(int));
60 }
61 //indent end
62 
63 
64 /*
65  * The option '-bs' only affects 'sizeof', not 'offsetof', even though these
66  * two keywords are syntactically similar.
67  */
68 //indent input
69 int sizeof_type = sizeof   (int);
70 int sizeof_type = sizeof(int);
71 int sizeof_expr = sizeof   (0);
72 int sizeof_expr = sizeof(0);
73 int sizeof_expr = sizeof   0;
74 
75 int offset = offsetof(struct s, member);
76 int offset = offsetof   (struct s, member);
77 //indent end
78 
79 //indent run -pcs -di0
80 int sizeof_type = sizeof (int);
81 int sizeof_type = sizeof (int);
82 int sizeof_expr = sizeof (0);
83 int sizeof_expr = sizeof (0);
84 int sizeof_expr = sizeof 0;
85 
86 int offset = offsetof (struct s, member);
87 int offset = offsetof (struct s, member);
88 //indent end
89 
90 //indent run -npcs -di0
91 int sizeof_type = sizeof(int);
92 int sizeof_type = sizeof(int);
93 int sizeof_expr = sizeof(0);
94 int sizeof_expr = sizeof(0);
95 int sizeof_expr = sizeof 0;
96 
97 int offset = offsetof(struct s, member);
98 int offset = offsetof(struct s, member);
99 //indent end
100 
101 
102 /* Ensure that there is no blank before 'sizeof(' if there is a '\n' between. */
103 //indent input
104 int sizeof_newline = sizeof
105 (0);
106 //indent end
107 
108 //indent run-equals-input -di0 -bs
109 
110 //indent run-equals-input -di0 -nbs
111 
112 
113 /* Ensure that only the first '(' after 'sizeof' gets a blank. */
114 //indent input
115 int sizeof_parenthesized = sizeof((0));
116 //indent end
117 
118 //indent run -di0 -bs
119 int sizeof_parenthesized = sizeof ((0));
120 //indent end
121 
122 //indent run-equals-input -di0 -nbs
123