summaryrefslogtreecommitdiff
path: root/tests/usr.bin/indent/fmt_else_comment.c
blob: a8895e1e75eab6dbdc3c842e39e2b5e783c874b7 (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
118
119
120
121
122
/*	$NetBSD: fmt_else_comment.c,v 1.6 2023/06/23 20:44:51 rillig Exp $	*/

/*
 * Tests for comments after 'if (expr)' and 'else'. Before 2023-05-11, if the
 * option '-br' was given (or rather, if '-bl' was not given), indent looked
 * ahead to the following significant token to see whether it was a '{', it
 * then moved the comments after the '{'. This token swapping was error-prone
 * and thus removed.
 *
 * See also:
 *	FreeBSD r303484
 *	FreeBSD r309342
 */

/*
 * Before 2023-05-11, the two 'if' statements below exercised 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". */
	// $ 'Old' means something before 2019.

	if (1) {
		int a;
	}


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

	if (1)
		;
	else /* Old indent would get very confused here */
	// $ 'Old' means something before 2019.
	/* 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