xref: /netbsd-src/tests/usr.bin/indent/psym_if_expr_stmt_else.c (revision 3117ece4fc4a4ca4489ba793710b60b0d26bab6c)
1 /* $NetBSD: psym_if_expr_stmt_else.c,v 1.5 2023/05/11 09:28:53 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 	}
29 	else if (cond) {
30 	}
31 	else if (cond)
32 		i++;
33 	else {
34 	}
35 }
36 //indent end
37 
38 /*
39  * Combining the options '-bl' (place brace on the left margin) and '-ce'
40  * (cuddle else) looks strange, but is technically correct.
41  */
42 //indent run -bl
43 void
44 example(_Bool cond)
45 {
46 	if (cond)
47 	{
48 	}
49 	else if (cond)
50 	{
51 	}
52 	else if (cond)
53 		i++;
54 	else
55 	{
56 	}
57 }
58 //indent end
59 
60 //indent run-equals-prev-output -bl -nce
61 
62 /*
63  * Adding the option '-nei' (do not join 'else if') expands the code even
64  * more.
65  */
66 //indent run -bl -nce -nei
67 void
68 example(_Bool cond)
69 {
70 	if (cond)
71 	{
72 	}
73 	else
74 		if (cond)
75 		{
76 		}
77 		else
78 			if (cond)
79 				i++;
80 			else
81 			{
82 			}
83 }
84 //indent end
85