xref: /netbsd-src/tests/usr.bin/indent/opt_ldi.c (revision 47306038c7d906b62edca1fd252c0e0d0772f5a0)
1 /* $NetBSD: opt_ldi.c,v 1.5 2022/04/24 09:04:12 rillig Exp $ */
2 
3 /*
4  * Tests for the option '-ldi', which specifies where the variable names of
5  * locally declared variables are placed.
6  *
7  * See also:
8  *	opt_di.c
9  */
10 
11 //indent input
12 int global;
13 
14 void
function(void)15 function(void)
16 {
17 	int local;
18 }
19 //indent end
20 
21 //indent run -ldi0
22 int		global;
23 
24 void
function(void)25 function(void)
26 {
27 	int local;
28 }
29 //indent end
30 
31 //indent run -ldi8
32 int		global;
33 
34 void
function(void)35 function(void)
36 {
37 	int	local;
38 }
39 //indent end
40 
41 //indent run -ldi24
42 int		global;
43 
44 void
function(void)45 function(void)
46 {
47 	int			local;
48 }
49 //indent end
50 
51 
52 /*
53  * A variable that has an ad-hoc struct/union/enum type does not need to be
54  * indented to the right of the keyword 'struct', it only needs a single space
55  * of indentation.
56  *
57  * Before NetBSD indent.c 1.151 from 2021-10-24, the indentation depended on
58  * the length of the keyword 'struct', 'union' or 'enum', together with type
59  * qualifiers like 'const' or the storage class like 'static'.
60  */
61 //indent input
62 {
63 	struct {
64 		int member;
65 	} var = {
66 		3,
67 	};
68 }
69 //indent end
70 
71 /*
72  * Struct members use '-di' for indentation, no matter whether they are
73  * declared globally or locally.
74  */
75 //indent run -ldi0
76 {
77 	struct {
78 		int		member;
79 	} var = {
80 		3,
81 	};
82 }
83 //indent end
84 
85 //indent run -ldi16
86 {
87 	struct {
88 		int		member;
89 	}		var = {
90 		3,
91 	};
92 }
93 //indent end
94