ps_ind_level.c revision 1.6
11.6Srillig/* $NetBSD: ps_ind_level.c,v 1.6 2022/04/24 09:04:12 rillig Exp $ */
21.1Srillig
31.1Srillig/*
41.1Srillig * The indentation of the very first line of a file determines the
51.1Srillig * indentation of the remaining code. Even if later code has a smaller
61.1Srillig * indentation, it is nevertheless indented to the level given by the first
71.1Srillig * line of code.
81.1Srillig *
91.1Srillig * In this particular test, the indentation is set to 5 and the tabulator
101.1Srillig * width is set to 8, to demonstrate an off-by-one error in
111.1Srillig * main_prepare_parsing that has been fixed in indent.c 1.107 from 2021-10-05.
121.1Srillig *
131.1Srillig * The declaration in the first line is indented by 3 tabs, amounting to 24
141.1Srillig * spaces. The initial indentation of the code is intended to be rounded down,
151.1Srillig * to 4 levels of indentation, amounting to 20 spaces.
161.1Srillig */
171.6Srillig//indent input
181.3Srillig			int indented_by_24;
191.1Srillig
201.1Srilligvoid function_in_column_1(void){}
211.6Srillig//indent end
221.1Srillig
231.1Srillig/* 5 spaces indentation, 8 spaces per tabulator */
241.6Srillig//indent run -i5 -ts8
251.3Srillig		    int		    indented_by_24;
261.1Srillig
271.1Srillig		    void	    function_in_column_1(void){
281.1Srillig		    }
291.6Srillig//indent end
301.1Srillig/*
311.1Srillig * In the above function declaration, the space between '){' is missing. This
321.1Srillig * is because the tokenizer only recognizes function definitions if they start
331.1Srillig * at indentation level 0, but this declaration starts at indentation level 4,
341.4Srillig * due to the indentation in line 1. It's an edge case that is probably not
351.4Srillig * worth fixing.
361.1Srillig *
371.4Srillig * See 'in_func_def_params = true'.
381.1Srillig */
391.1Srillig
401.1Srillig
411.1Srillig/*
421.1Srillig * Labels are always indented 2 levels left of the code. The first line starts
431.1Srillig * at indentation level 3, the code in the function is therefore at level 4,
441.1Srillig * and the label is at level 2, sticking out of the code.
451.1Srillig */
461.6Srillig//indent input
471.1Srillig			int indent_by_24;
481.1Srillig
491.1Srilligvoid function(void) {
501.1Srilliglabel:;
511.1Srillig}
521.6Srillig//indent end
531.1Srillig
541.6Srillig//indent run -i8 -ts8 -di0
551.1Srillig			int indent_by_24;
561.1Srillig
571.1Srillig			void function(void){
581.1Srillig		label:		;
591.1Srillig			}
601.6Srillig//indent end
611.2Srillig
621.2Srillig
631.2Srillig/* Test the indentation computation in code_add_decl_indent. */
641.6Srillig//indent input
651.2Srilligint level_0;
661.2Srillig{
671.2Srilligint level_1;
681.2Srillig{
691.2Srilligint level_2;
701.2Srillig{
711.2Srilligint level_3;
721.2Srillig{
731.2Srilligint level_4;
741.2Srillig}
751.2Srillig}
761.2Srillig}
771.2Srillig}
781.6Srillig//indent end
791.2Srillig
801.2Srillig/*
811.2Srillig * The variables are indented by 16, 21, 26, 31, 36.
821.2Srillig * The variables end up in columns 17, 22, 27, 32, 37.
831.2Srillig */
841.6Srillig//indent run -i5 -ts8 -di16 -ldi16
851.2Srilligint		level_0;
861.2Srillig{
871.2Srillig     int	     level_1;
881.2Srillig     {
891.2Srillig	  int		  level_2;
901.2Srillig	  {
911.2Srillig	       int	       level_3;
921.2Srillig	       {
931.2Srillig		    int		    level_4;
941.2Srillig	       }
951.2Srillig	  }
961.2Srillig     }
971.2Srillig}
981.6Srillig//indent end
991.2Srillig
1001.2Srillig/*
1011.2Srillig * The variables are indented by 7, 12, 17, 22, 27.
1021.2Srillig * The variables end up in columns 8, 13, 18, 23, 28.
1031.2Srillig */
1041.6Srillig//indent run -i5 -ts8 -di7 -ldi7
1051.2Srilligint    level_0;
1061.2Srillig{
1071.2Srillig     int    level_1;
1081.2Srillig     {
1091.2Srillig	  int	 level_2;
1101.2Srillig	  {
1111.2Srillig	       int    level_3;
1121.2Srillig	       {
1131.2Srillig		    int	   level_4;
1141.2Srillig	       }
1151.2Srillig	  }
1161.2Srillig     }
1171.2Srillig}
1181.6Srillig//indent end
119