summaryrefslogtreecommitdiff
path: root/tests/usr.bin/indent/opt_di.c
blob: 1935c7df86eef6ef58fa70db402825ea3172840c (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
123
124
125
126
127
/* $NetBSD: opt_di.c,v 1.8 2022/04/24 09:04:12 rillig Exp $ */

/*
 * Test the option '-di', which specifies the indentation of the first
 * variable name in a declaration.
 */

//indent input
int space;
int	tab;
int		tab16;

struct long_name long_name;
//indent end

//indent run -di8
int	space;
int	tab;
int	tab16;

struct long_name long_name;
//indent end


/*
 * The declarator can be a simple variable name. It can also be prefixed by
 * asterisks, for pointer variables. These asterisks are placed to the left of
 * the indentation line, so that the variable names are aligned.
 *
 * There can be multiple declarators in a single declaration, separated by
 * commas. Only the first of them is aligned to the indentation given by
 * '-di', the others are separated with a single space.
 */
//indent input
int var;
int *ptr, *****ptr;
//indent end

//indent run -di12
int	    var;
int	   *ptr, *****ptr;
//indent end


/*
 * Test the various values for indenting.
 */
//indent input
int decl ;
//indent end

/*
 * An indentation of 0 columns uses a single space between the declaration
 * specifiers (in this case 'int') and the declarator.
 */
//indent run -di0
int decl;
//indent end

/*
 * An indentation of 7 columns uses spaces for indentation since in the
 * default configuration, the next tab stop would be at indentation 8.
 */
//indent run -di7
int    decl;
//indent end

/* The indentation consists of a single tab. */
//indent run -di8
int	decl;
//indent end

/* The indentation consists of a tab and a space. */
//indent run -di9
int	 decl;
//indent end

//indent run -di16
int		decl;
//indent end


/*
 * Ensure that all whitespace is normalized to be indented by 8 columns,
 * which in the default configuration amounts to a single tab.
 */
//indent input
int space;
int	tab;
int		tab16;
struct long_name long_name;
//indent end

//indent run -di8
int	space;
int	tab;
int	tab16;
struct long_name long_name;
//indent end


/*
 * A variable that has an ad-hoc struct/union/enum type does not need to be
 * indented to the right of the keyword 'struct', it only needs a single space
 * of indentation.
 *
 * Before NetBSD indent.c 1.151 from 2021-10-24, the indentation depended on
 * the length of the keyword 'struct', 'union' or 'enum', together with type
 * qualifiers like 'const' or the storage class like 'static'.
 */
//indent input
struct {
	int member;
} var = {
	3,
};
//indent end

//indent run-equals-input -di0

//indent run
struct {
	int		member;
}		var = {
	3,
};
//indent end