xref: /netbsd-src/tests/usr.bin/indent/psym_if_expr_stmt_else.c (revision 7d62b00eb9ad855ffcd7da46b41e23feb5476fac)
1 /* $NetBSD: psym_if_expr_stmt_else.c,v 1.4 2022/04/24 09:04:12 rillig Exp $ */
2 
3 /*
4  * Tests for the parser symbol psym_if_expr_stmt_else, which represents the
5  * parser state after reading the keyword 'if', the controlling expression,
6  * the statement of the 'then' branch and the keyword 'else'.
7  *
8  * If the next token is an 'if', the formatting depends on the option '-ei' or
9  * '-nei'.  Any other lookahead token completes the 'if' statement.
10  */
11 
12 //indent input
13 void
14 example(_Bool cond)
15 {
16 	if (cond) {}
17 	else if (cond) {}
18 	else if (cond) i++;
19 	else {}
20 }
21 //indent end
22 
23 //indent run
24 void
25 example(_Bool cond)
26 {
27 	if (cond) {
28 	} else if (cond) {
29 	} else if (cond)
30 		i++;
31 	else {
32 	}
33 }
34 //indent end
35 
36 /*
37  * Combining the options '-bl' (place brace on the left margin) and '-ce'
38  * (cuddle else) looks strange, but is technically correct.
39  */
40 //indent run -bl
41 void
42 example(_Bool cond)
43 {
44 	if (cond)
45 	{
46 	} else if (cond)
47 	{
48 	} else if (cond)
49 		i++;
50 	else
51 	{
52 	}
53 }
54 //indent end
55 
56 //indent run -bl -nce
57 void
58 example(_Bool cond)
59 {
60 	if (cond)
61 	{
62 	}
63 	else if (cond)
64 	{
65 	}
66 	else if (cond)
67 		i++;
68 	else
69 	{
70 	}
71 }
72 //indent end
73 
74 /*
75  * Adding the option '-nei' (do not join 'else if') expands the code even
76  * more.
77  */
78 //indent run -bl -nce -nei
79 void
80 example(_Bool cond)
81 {
82 	if (cond)
83 	{
84 	}
85 	else
86 		if (cond)
87 		{
88 		}
89 		else
90 			if (cond)
91 				i++;
92 			else
93 			{
94 			}
95 }
96 //indent end
97