summaryrefslogtreecommitdiff
path: root/tests/usr.bin/indent/fmt_else_comment.c
blob: 840534375288ec8a006adf43ee1b8f15d3ccb102 (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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/*	$NetBSD: fmt_else_comment.c,v 1.2 2021/11/19 22:24:29 rillig Exp $	*/
/* $FreeBSD: head/usr.bin/indent/tests/elsecomment.0.pro 314613 2017-03-03 20:15:22Z ngie $ */

/*
 * Tests for comments after 'if (expr)' and 'else'. If the option '-br' is
 * given (or rather, if '-bl' is not given), indent looks ahead to the
 * following significant token to see whether it is a '{', it then moves the
 * comments after the '{'.
 *
 * See also:
 *	FreeBSD r303484
 *	FreeBSD r309342
 */

/*
 * The two 'if' statements below exercise two different code paths, even
 * though they look very similar.
 */
#indent input
void t(void) {
	if (1) /* a */ int a; else /* b */ int b;

	if (1) /* a */
		int a;
	else /* b */
		int b;
}
#indent end

#indent run
void
t(void)
{
	if (1)			/* a */
		int		a;
	else			/* b */
		int		b;

	if (1)			/* a */
		int		a;
	else			/* b */
		int		b;
}
#indent end


#indent input
void t(void) {
	if (1) {

	}



	/* Old indent would remove the 3 blank lines above, awaiting "else". */

	if (1) {
		int a;
	}


	else if (0) {
		int b;
	}
	/* test */
	else
		;

	if (1)
		;
	else /* Old indent would get very confused here */
	/* We also mustn't assume that there's only one comment */
	/* before the left brace. */
	{


	}
}
#indent end

#indent run -bl
void
t(void)
{
	if (1)
	{

	}



	/*
	 * Old indent would remove the 3 blank lines above, awaiting "else".
	 */

	if (1)
	{
		int		a;
	} else if (0)
	{
		int		b;
	}
	/* test */
	else
		;

	if (1)
		;
	else			/* Old indent would get very confused here */
		/* We also mustn't assume that there's only one comment */
		/* before the left brace. */
	{


	}
}
#indent end