summaryrefslogtreecommitdiff
path: root/tests/usr.bin/indent/ps_ind_level.c
blob: 92c42d21f6e3632de567fdce0c207d128f2ac84c (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
128
129
130
131
132
133
/* $NetBSD: ps_ind_level.c,v 1.9 2023/06/15 09:19:07 rillig Exp $ */

/*
 * The indentation of the very first line of a file determines the
 * indentation of the remaining code. This mode is meant for code snippets from
 * function bodies. At this level, function definitions are not recognized
 * properly.
 *
 * Even if later code has a smaller indentation, it is nevertheless indented to
 * the level given by the first line of code.
 *
 * In this particular test, the indentation is set to 5 and the tabulator
 * width is set to 8, to demonstrate an off-by-one error in
 * main_prepare_parsing that has been fixed in indent.c 1.107 from 2021-10-05.
 *
 * The declaration in the first line is indented by 3 tabs, amounting to 24
 * spaces. The initial indentation of the code is intended to be rounded down,
 * to 4 levels of indentation, amounting to 20 spaces.
 */
//indent input
			int indented_by_24;

void function_in_column_1(void){}

			#if indented
#endif
//indent end

/* 5 spaces indentation, 8 spaces per tabulator */
//indent run -i5 -ts8
		    int		    indented_by_24;

		    void	    function_in_column_1(void) {
		    }

#if indented
#endif
//indent end


/*
 * Labels are always indented 2 levels left of the code. The first line starts
 * at indentation level 3, the code in the function is therefore at level 4,
 * and the label is at level 2, sticking out of the code.
 */
//indent input
			int indent_by_24;

void function(void) {
label:;
}
//indent end

//indent run -i8 -ts8 -di0
			int indent_by_24;

			void function(void) {
		label:		;
			}
//indent end


/* Test the indentation computation in code_add_decl_indent. */
//indent input
int level_0;
{
int level_1;
{
int level_2;
{
int level_3;
{
int level_4;
}
}
}
}
//indent end

/*
 * The variables are indented by 16, 21, 26, 31, 36.
 * The variables end up in columns 17, 22, 27, 32, 37.
 */
//indent run -i5 -ts8 -di16 -ldi16
int		level_0;
{
     int	     level_1;
     {
	  int		  level_2;
	  {
	       int	       level_3;
	       {
		    int		    level_4;
	       }
	  }
     }
}
//indent end

/*
 * The variables are indented by 7, 12, 17, 22, 27.
 * The variables end up in columns 8, 13, 18, 23, 28.
 */
//indent run -i5 -ts8 -di7 -ldi7
int    level_0;
{
     int    level_1;
     {
	  int	 level_2;
	  {
	       int    level_3;
	       {
		    int	   level_4;
	       }
	  }
     }
}
//indent end


/*
 * Having function definitions indented to the right is not supported. In that
 * case, indent does not recognize it as a function definition, and it doesn't
 * indent the old-style parameter declarations one level further to the right.
 */
//indent input
			int		old_style(a)
			int		a;
			{
			}
//indent end

//indent run-equals-input