summaryrefslogtreecommitdiff
path: root/tests/usr.bin/indent/psym_if_expr_stmt_else.c
blob: 333ff9a712cb368f3cbfe56c79d19ca7b967294b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/* $NetBSD: psym_if_expr_stmt_else.c,v 1.5 2023/05/11 09:28:53 rillig Exp $ */

/*
 * Tests for the parser symbol psym_if_expr_stmt_else, which represents the
 * parser state after reading the keyword 'if', the controlling expression,
 * the statement of the 'then' branch and the keyword 'else'.
 *
 * If the next token is an 'if', the formatting depends on the option '-ei' or
 * '-nei'.  Any other lookahead token completes the 'if' statement.
 */

//indent input
void
example(_Bool cond)
{
	if (cond) {}
	else if (cond) {}
	else if (cond) i++;
	else {}
}
//indent end

//indent run
void
example(_Bool cond)
{
	if (cond) {
	}
	else if (cond) {
	}
	else if (cond)
		i++;
	else {
	}
}
//indent end

/*
 * Combining the options '-bl' (place brace on the left margin) and '-ce'
 * (cuddle else) looks strange, but is technically correct.
 */
//indent run -bl
void
example(_Bool cond)
{
	if (cond)
	{
	}
	else if (cond)
	{
	}
	else if (cond)
		i++;
	else
	{
	}
}
//indent end

//indent run-equals-prev-output -bl -nce

/*
 * Adding the option '-nei' (do not join 'else if') expands the code even
 * more.
 */
//indent run -bl -nce -nei
void
example(_Bool cond)
{
	if (cond)
	{
	}
	else
		if (cond)
		{
		}
		else
			if (cond)
				i++;
			else
			{
			}
}
//indent end