xref: /netbsd-src/tests/usr.bin/indent/fmt_else_comment.c (revision 8c1e5e0299e96ca2aeb2e79be074046198f4efa0)
1 /*	$NetBSD: fmt_else_comment.c,v 1.1 2021/10/22 19:27:53 rillig Exp $	*/
2 /* $FreeBSD: head/usr.bin/indent/tests/elsecomment.0.pro 314613 2017-03-03 20:15:22Z ngie $ */
3 
4 /* See r303484 and r309342 */
5 
6 #indent input
7 void t(void) {
8 	/* The two if statements below excercise two different code paths. */
9 
10 	if (1) /* a */ int a; else /* b */ int b;
11 
12 	if (1) /* a */
13 		int a;
14 	else /* b */
15 		int b;
16 
17 	if (1) {
18 
19 	}
20 
21 
22 
23 	/* Old indent would remove the 3 blank lines above, awaiting "else". */
24 
25 	if (1) {
26 		int a;
27 	}
28 
29 
30 	else if (0) {
31 		int b;
32 	}
33 	/* test */
34 	else
35 		;
36 
37 	if (1)
38 		;
39 	else /* Old indent would get very confused here */
40 	/* We also mustn't assume that there's only one comment */
41 	/* before the left brace. */
42 	{
43 
44 
45 	}
46 }
47 #indent end
48 
49 #indent run -bl
50 void
51 t(void)
52 {
53 	/* The two if statements below excercise two different code paths. */
54 
55 	if (1)			/* a */
56 		int		a;
57 	else			/* b */
58 		int		b;
59 
60 	if (1)			/* a */
61 		int		a;
62 	else			/* b */
63 		int		b;
64 
65 	if (1)
66 	{
67 
68 	}
69 
70 
71 
72 	/*
73 	 * Old indent would remove the 3 blank lines above, awaiting "else".
74 	 */
75 
76 	if (1)
77 	{
78 		int		a;
79 	} else if (0)
80 	{
81 		int		b;
82 	}
83 	/* test */
84 	else
85 		;
86 
87 	if (1)
88 		;
89 	else			/* Old indent would get very confused here */
90 		/* We also mustn't assume that there's only one comment */
91 		/* before the left brace. */
92 	{
93 
94 
95 	}
96 }
97 #indent end
98