summaryrefslogtreecommitdiff
path: root/tests/usr.bin/indent/lsym_question.c
blob: 7dd2f37f5167611a340856c05d9a35f45ad47c18 (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
/* $NetBSD: lsym_question.c,v 1.5 2023/05/15 10:13:40 rillig Exp $ */

/*
 * Tests for the token lsym_question, which represents the '?' in a '?:'
 * conditional expression.
 */

//indent input
const char *result = cond ? "then" : "else";

const char *multi = cond1 ? "cond1" : cond2 ? "cond2" : cond3 ? "cond3" : "";
//indent end

//indent run-equals-input -di0


/*
 * To make them easier to read, conditional expressions can be split into
 * multiple lines.
 */
//indent input
const char *separate_lines = cond
	? "then"
	: "else";
//indent end

//indent run -di0
const char *separate_lines = cond
// $ XXX: Continuation lines in expressions should be indented, even in column 1.
? "then"
: "else";
//indent end


/*
 * In functions, conditional expressions are indented as intended.
 */
//indent input
void
function(void)
{
	return cond
		? "then"
		: "else";
}
//indent end

//indent run-equals-input


/*
 * In functions, conditional expressions are indented as intended.
 */
//indent input
void
function(void)
{
	const char *branch = cond
		? "then"
		: "else";

	const char *multiple_branches = cond1
		? "then 1"
		: cond2
		? "then 2"
		: "else";

	const char *condensed = cond1 ? "condensed 1"
		: cond2 ? "condensed 2"
		: "condensed else";
}
//indent end

//indent run-equals-input -di0