xref: /netbsd-src/tests/usr.bin/indent/psym_switch_expr.c (revision f7b95e49e6e60b33d007495fadfcfffda49d129f)
1 /* $NetBSD: psym_switch_expr.c,v 1.6 2023/06/23 20:44:51 rillig Exp $ */
2 
3 /*
4  * Tests for the parser symbol psym_switch_expr, which represents the keyword
5  * 'switch' followed by the controlling expression, now waiting for a
6  * statement (usually a block) containing the 'case' labels.
7  */
8 
9 //indent run-equals-input
10 
11 
12 /*
13  * In all practical cases, a 'switch (expr)' is followed by a block, but the
14  * C syntax allows an arbitrary statement.  Unless such a statement has a
15  * label or is a loop, its beginning is unreachable.
16  */
17 //indent input
18 void
function(void)19 function(void)
20 {
21 	switch (expr)
22 	if (cond) {
23 	case 1: return;
24 	case 2: break;
25 	}
26 }
27 //indent end
28 
29 //indent run
30 void
function(void)31 function(void)
32 {
33 	switch (expr)
34 		if (cond) {
35 	case 1:
36 			return;
37 	case 2:
38 			break;
39 		}
40 }
41 //indent end
42 
43 //indent run -cli-0.375
44 void
function(void)45 function(void)
46 {
47 	switch (expr)
48 		if (cond) {
49      case 1:
50 			return;
51      case 2:
52 			break;
53 		}
54 }
55 //indent end
56