ps_ind_level.c revision 1.3
1/* $NetBSD: ps_ind_level.c,v 1.3 2021/11/20 16:54:17 rillig Exp $ */
2/* $FreeBSD$ */
3
4/*
5 * The indentation of the very first line of a file determines the
6 * indentation of the remaining code. Even if later code has a smaller
7 * indentation, it is nevertheless indented to the level given by the first
8 * line of code.
9 *
10 * In this particular test, the indentation is set to 5 and the tabulator
11 * width is set to 8, to demonstrate an off-by-one error in
12 * main_prepare_parsing that has been fixed in indent.c 1.107 from 2021-10-05.
13 *
14 * The declaration in the first line is indented by 3 tabs, amounting to 24
15 * spaces. The initial indentation of the code is intended to be rounded down,
16 * to 4 levels of indentation, amounting to 20 spaces.
17 */
18#indent input
19			int indented_by_24;
20
21void function_in_column_1(void){}
22#indent end
23
24/* 5 spaces indentation, 8 spaces per tabulator */
25#indent run -i5 -ts8
26		    int		    indented_by_24;
27
28		    void	    function_in_column_1(void){
29		    }
30#indent end
31/*
32 * In the above function declaration, the space between '){' is missing. This
33 * is because the tokenizer only recognizes function definitions if they start
34 * at indentation level 0, but this declaration starts at indentation level 4,
35 * due to the indentation in line 1. It's an edge case and probably not worth
36 * fixing.
37 *
38 * See 'in_parameter_declaration = true'.
39 */
40
41
42/*
43 * Labels are always indented 2 levels left of the code. The first line starts
44 * at indentation level 3, the code in the function is therefore at level 4,
45 * and the label is at level 2, sticking out of the code.
46 */
47#indent input
48			int indent_by_24;
49
50void function(void) {
51label:;
52}
53#indent end
54
55#indent run -i8 -ts8 -di0
56			int indent_by_24;
57
58			void function(void){
59		label:		;
60			}
61#indent end
62
63
64/* Test the indentation computation in code_add_decl_indent. */
65#indent input
66int level_0;
67{
68int level_1;
69{
70int level_2;
71{
72int level_3;
73{
74int level_4;
75}
76}
77}
78}
79#indent end
80
81/*
82 * The variables are indented by 16, 21, 26, 31, 36.
83 * The variables end up in columns 17, 22, 27, 32, 37.
84 */
85#indent run -i5 -ts8 -di16 -ldi16
86int		level_0;
87{
88     int	     level_1;
89     {
90	  int		  level_2;
91	  {
92	       int	       level_3;
93	       {
94		    int		    level_4;
95	       }
96	  }
97     }
98}
99#indent end
100
101/*
102 * The variables are indented by 7, 12, 17, 22, 27.
103 * The variables end up in columns 8, 13, 18, 23, 28.
104 */
105#indent run -i5 -ts8 -di7 -ldi7
106int    level_0;
107{
108     int    level_1;
109     {
110	  int	 level_2;
111	  {
112	       int    level_3;
113	       {
114		    int	   level_4;
115	       }
116	  }
117     }
118}
119#indent end
120