opt_eei.c revision 1.5 1 1.5 rillig /* $NetBSD: opt_eei.c,v 1.5 2021/11/07 08:03:15 rillig Exp $ */
2 1.1 rillig /* $FreeBSD$ */
3 1.1 rillig
4 1.3 rillig /*
5 1.3 rillig * Tests for the options '-eei' and '-neei'.
6 1.3 rillig *
7 1.3 rillig * The option '-eei' enables extra indentation on continuation lines of the
8 1.3 rillig * expression part of 'if' and 'while' statements. These continuation lines
9 1.3 rillig * are indented one extra level.
10 1.3 rillig *
11 1.3 rillig * The option '-neei' indents these conditions in the same way as all other
12 1.3 rillig * continued statements.
13 1.3 rillig */
14 1.3 rillig
15 1.1 rillig #indent input
16 1.1 rillig bool
17 1.1 rillig less(int a, int b)
18 1.1 rillig {
19 1.1 rillig if (a <
20 1.1 rillig b)
21 1.1 rillig return true;
22 1.1 rillig if (a
23 1.1 rillig <
24 1.1 rillig b)
25 1.1 rillig return true;
26 1.1 rillig }
27 1.1 rillig #indent end
28 1.1 rillig
29 1.1 rillig #indent run -eei
30 1.1 rillig bool
31 1.1 rillig less(int a, int b)
32 1.1 rillig {
33 1.1 rillig if (a <
34 1.1 rillig b)
35 1.1 rillig return true;
36 1.1 rillig if (a
37 1.1 rillig <
38 1.1 rillig b)
39 1.1 rillig return true;
40 1.1 rillig }
41 1.1 rillig #indent end
42 1.1 rillig
43 1.4 rillig #indent run-equals-input -neei
44 1.3 rillig
45 1.3 rillig /*
46 1.3 rillig * When the indentation level is the same as the continuation indentation, the
47 1.3 rillig * indentation does not show the structure of the code.
48 1.3 rillig */
49 1.3 rillig #indent run -neei -i4
50 1.3 rillig bool
51 1.3 rillig less(int a, int b)
52 1.3 rillig {
53 1.3 rillig if (a <
54 1.3 rillig b)
55 1.3 rillig return true;
56 1.3 rillig if (a
57 1.3 rillig <
58 1.3 rillig b)
59 1.3 rillig return true;
60 1.3 rillig }
61 1.3 rillig #indent end
62 1.3 rillig
63 1.3 rillig /*
64 1.3 rillig * Adding the extra level of indentation is useful when the standard
65 1.3 rillig * indentation is the same as the indentation of statement continuations. In
66 1.3 rillig * such a case, the continued condition would have the same indentation as the
67 1.3 rillig * following statement, which would be confusing.
68 1.3 rillig */
69 1.3 rillig #indent run -eei -i4
70 1.3 rillig bool
71 1.3 rillig less(int a, int b)
72 1.3 rillig {
73 1.3 rillig if (a <
74 1.3 rillig b)
75 1.3 rillig return true;
76 1.3 rillig if (a
77 1.3 rillig <
78 1.3 rillig b)
79 1.3 rillig return true;
80 1.3 rillig }
81 1.3 rillig #indent end
82 1.5 rillig
83 1.5 rillig /*
84 1.5 rillig * With an indentation size of 4, the width of the code 'if (' is exactly one
85 1.5 rillig * indentation level. With the option '-nlp', the option '-eei' has no effect.
86 1.5 rillig *
87 1.5 rillig * XXX: This is unexpected since this creates the exact ambiguity that the
88 1.5 rillig * option '-eei' is supposed to prevent.
89 1.5 rillig */
90 1.5 rillig #indent run -eei -i4 -nlp
91 1.5 rillig bool
92 1.5 rillig less(int a, int b)
93 1.5 rillig {
94 1.5 rillig if (a <
95 1.5 rillig b)
96 1.5 rillig return true;
97 1.5 rillig if (a
98 1.5 rillig <
99 1.5 rillig b)
100 1.5 rillig return true;
101 1.5 rillig }
102 1.5 rillig #indent end
103 1.5 rillig
104 1.5 rillig
105 1.5 rillig /*
106 1.5 rillig * The option '-eei' applies no matter whether the continued expression starts
107 1.5 rillig * with a word or an operator like '&&'. The latter cannot start a statement,
108 1.5 rillig * so there would be no ambiguity.
109 1.5 rillig */
110 1.5 rillig #indent input
111 1.5 rillig {
112 1.5 rillig if (a
113 1.5 rillig && b)
114 1.5 rillig stmt();
115 1.5 rillig }
116 1.5 rillig #indent end
117 1.5 rillig
118 1.5 rillig /*
119 1.5 rillig * XXX: The extra indentation is unnecessary since there is no possible
120 1.5 rillig * confusion: the standard indentation is 8, the indentation of the continued
121 1.5 rillig * condition could have stayed at 4.
122 1.5 rillig */
123 1.5 rillig #indent run -eei
124 1.5 rillig {
125 1.5 rillig if (a
126 1.5 rillig && b)
127 1.5 rillig stmt();
128 1.5 rillig }
129 1.5 rillig #indent end
130 1.5 rillig
131 1.5 rillig /*
132 1.5 rillig * The extra indentation is necessary here since otherwise the '&&' and the
133 1.5 rillig * 'stmt()' would start at the same indentation.
134 1.5 rillig */
135 1.5 rillig #indent run -eei -i4
136 1.5 rillig {
137 1.5 rillig if (a
138 1.5 rillig && b)
139 1.5 rillig stmt();
140 1.5 rillig }
141 1.5 rillig #indent end
142 1.5 rillig
143 1.5 rillig /*
144 1.5 rillig * With an indentation size of 4, the width of the code 'if (' is exactly one
145 1.5 rillig * indentation level. With the option '-nlp', the option '-eei' has no effect.
146 1.5 rillig *
147 1.5 rillig * XXX: This is unexpected since this creates the exact ambiguity that the
148 1.5 rillig * option '-eei' is supposed to prevent.
149 1.5 rillig */
150 1.5 rillig #indent run -eei -i4 -nlp
151 1.5 rillig {
152 1.5 rillig if (a
153 1.5 rillig && b)
154 1.5 rillig stmt();
155 1.5 rillig }
156 1.5 rillig #indent end
157