lsym_question.c revision 1.4
1/* $NetBSD: lsym_question.c,v 1.4 2022/04/24 09:04:12 rillig Exp $ */
2
3/*
4 * Tests for the token lsym_question, which represents the '?' in a '?:'
5 * conditional expression.
6 */
7
8//indent input
9const char *result = cond ? "then" : "else";
10
11const char *multi = cond1 ? "cond1" : cond2 ? "cond2" : cond3 ? "cond3" : "";
12//indent end
13
14//indent run-equals-input -di0
15
16
17/*
18 * To make them easier to read, conditional expressions can be split into
19 * multiple lines.
20 */
21//indent input
22const char *separate_lines = cond
23	? "then"
24	: "else";
25//indent end
26
27//indent run -di0
28const char *separate_lines = cond
29// $ XXX: Continuation lines in expressions should be indented, even in column 1.
30? "then"
31: "else";
32//indent end
33
34
35/*
36 * In functions, conditional expressions are indented as intended.
37 */
38//indent input
39void
40function(void)
41{
42	return cond
43		? "then"
44		: "else";
45}
46//indent end
47
48//indent run-equals-input
49
50
51/*
52 * In functions, conditional expressions are indented as intended.
53 */
54//indent input
55void
56function(void)
57{
58	const char *branch = cond
59	// $ TODO: Indent these continuation lines as they are part of the
60	// $ TODO: initializer expression, not of the declarator part to the
61	// $ TODO: left of the '='.
62	? "then"
63	: "else";
64}
65//indent end
66
67//indent run-equals-input -di0
68