xref: /netbsd-src/tests/usr.bin/indent/lsym_rbrace.c (revision 98ca6839b8f4162102369f36715e69ce1fdcfe88)
1 /* $NetBSD: lsym_rbrace.c,v 1.8 2025/01/04 21:54:26 rillig Exp $ */
2 
3 /*
4  * Tests for the token lsym_rbrace, which represents a '}' in these contexts:
5  *
6  * In an initializer, '}' ends an inner group of initializers, usually to
7  * initialize a nested struct, union or array.
8  *
9  * In a function body, '}' ends a block.
10  *
11  * In an expression like '(type){...}', '}' ends a compound literal, which is
12  * typically used in an assignment to a struct or array.
13  *
14  * In macro arguments, a '}' is an ordinary character, it does not need to be
15  * balanced.  This is in contrast to '(' and ')', which must be balanced.
16  *
17  * TODO: try to split this token into lsym_rbrace_block and lsym_rbrace_init.
18  *
19  * See also:
20  *	lsym_lbrace.c
21  */
22 
23 /* Brace level in an initializer */
24 //indent input
25 void
26 function(void)
27 {
28 	struct person	p = {
29 		.name = "Name",
30 		.age = {{{35}}},	/* C11 6.7.9 allows this. */
31 	};
32 }
33 //indent end
34 
35 //indent run-equals-input
36 
37 
38 /* Begin of a block of statements */
39 //indent input
40 void function(void) {{{ body(); }}}
41 //indent end
42 
43 //indent run
44 void
45 function(void)
46 {
47 	{
48 		{
49 			body();
50 		}
51 	}
52 }
53 //indent end
54 
55 
56 /* Compound literal */
57 //indent input
58 struct point
59 origin(void)
60 {
61 	return (struct point){
62 		.x = 0,
63 		.y = 0,
64 	};
65 }
66 //indent end
67 
68 //indent run-equals-input
69 
70 
71 //indent input
72 {
73 int numbers[][] = {
74 {11},
75 {21},
76 {31},
77 };
78 int numbers[][] = {{11},
79 {21},
80 {31},
81 };
82 }
83 //indent end
84 
85 //indent run -di0
86 {
87 	int numbers[][] = {
88 		{11},
89 		{21},
90 		{31},
91 	};
92 	int numbers[][] = {{11},
93 		{21},
94 		{31},
95 	};
96 }
97 //indent end
98