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