opt_bc.c revision 1.11 1 /* $NetBSD: opt_bc.c,v 1.11 2023/06/14 14:11:28 rillig Exp $ */
2
3 /*
4 * Tests for the options '-bc' and '-nbc'.
5 *
6 * The option '-bc' forces a newline after each comma in a declaration.
7 *
8 * The option '-nbc' removes line breaks between declarators. In most other
9 * places, indent preserves line breaks.
10 */
11
12 //indent input
13 int a,b,c;
14 void function_declaration(int a,int b,int c);
15 int m1,
16 m2,
17 m3;
18 char plain, *pointer;
19 //indent end
20
21 //indent run -bc
22 int a,
23 b,
24 c;
25 void function_declaration(int a, int b, int c);
26 int m1,
27 m2,
28 m3;
29 char plain,
30 *pointer;
31 //indent end
32
33 //indent run -nbc
34 int a, b, c;
35 void function_declaration(int a, int b, int c);
36 int m1, m2, m3;
37 char plain, *pointer;
38 //indent end
39
40
41 //indent input
42 old_style_definition(a, b, c)
43 double a,b,c;
44 {
45 return a+b+c;
46 }
47 //indent end
48
49 //indent run -bc
50 old_style_definition(a, b, c)
51 double a,
52 b,
53 c;
54 {
55 return a + b + c;
56 }
57 //indent end
58
59 //indent run -nbc
60 old_style_definition(a, b, c)
61 double a, b, c;
62 {
63 return a + b + c;
64 }
65 //indent end
66
67
68 /*
69 * Before indent.c 1.311 from 2023-06-02, indent formatted the two '#if'
70 * branches differently and merged the 'b, c' with the preceding preprocessing
71 * line.
72 */
73 //indent input
74 int a,
75 #if 0
76 b, c; int d;
77 #else
78 b, c; int d;
79 #endif
80 //indent end
81
82 //indent run -bc
83 int a,
84 #if 0
85 b,
86 c;
87 int d;
88 #else
89 b,
90 c;
91 int d;
92 #endif
93 //indent end
94
95 //indent run -nbc
96 int a,
97 #if 0
98 b, c;
99 int d;
100 #else
101 b, c;
102 int d;
103 #endif
104 //indent end
105
106
107 /*
108 * Before 2023-06-10, a '(' at the top level started a function definition,
109 * leaving variable declaration mode.
110 */
111 //indent input
112 int a = 1, b = 2;
113 int a = (1), b = 2;
114 //indent end
115
116 //indent run -bc
117 int a = 1,
118 b = 2;
119 int a = (1),
120 b = 2;
121 //indent end
122
123
124 /*
125 * When declarations are too long to fit in a single line, they should not be
126 * joined.
127 */
128 //indent input
129 {
130 const struct paren_level *prev = state.prev_ps.paren.item,
131 *curr = ps.paren.item;
132 }
133 //indent end
134
135 //indent run
136 // $ FIXME: The line becomes too long.
137 {
138 const struct paren_level *prev = state.prev_ps.paren.item, *curr = ps.paren.item;
139 }
140 //indent end
141