Home | History | Annotate | Line # | Download | only in indent
indent_off_on.c revision 1.10
      1 /* $NetBSD: indent_off_on.c,v 1.10 2023/05/14 17:53:38 rillig Exp $ */
      2 
      3 /*
      4  * Tests for the comments 'INDENT OFF' and 'INDENT ON', which temporarily
      5  * disable formatting, copying the input directly to the output.  Internally,
      6  * indent still keeps track of the number of braces and other indentation.
      7  */
      8 
      9 //indent input
     10 {}
     11 
     12 /*INDENT OFF*/
     13 /*INDENT ON*/
     14 
     15 {}
     16 //indent end
     17 
     18 /*
     19  * XXX: It is asymmetric that 'INDENT OFF' is kept as is, while 'INDENT ON'
     20  * gets enclosed with spaces.
     21  */
     22 //indent run
     23 {
     24 }
     25 /* $ FIXME: This empty line must stay. */
     26 /*INDENT OFF*/
     27 /* $ FIXME: The empty line below must be above the 'OFF' comment. */
     28 
     29 /* INDENT ON */
     30 
     31 {
     32 }
     33 //indent end
     34 
     35 
     36 //indent input
     37 {}
     38 
     39 
     40 /*INDENT OFF*/
     41 /*INDENT ON*/
     42 //indent end
     43 
     44 //indent run
     45 {
     46 }
     47 
     48 /*INDENT OFF*/
     49 /* $ FIXME: The empty line below must be above the 'OFF' comment. */
     50 
     51 /* INDENT ON */
     52 //indent end
     53 
     54 
     55 //indent input
     56 {}
     57  /* INDENT OFF */
     58  /* INDENT ON */
     59 {}
     60 //indent end
     61 
     62 /*
     63  * XXX: It is asymmetric that 'INDENT OFF' is indented, while 'INDENT ON'
     64  * is aligned.
     65  */
     66 //indent run
     67 {
     68 }
     69  /* INDENT OFF */
     70 /* $ FIXME: The empty line below must be removed. */
     71 
     72 /* INDENT ON */
     73 {
     74 }
     75 //indent end
     76 
     77 
     78 //indent input
     79 {}
     80 	/* INDENT OFF */
     81 	/* INDENT ON */
     82 {}
     83 //indent end
     84 
     85 /*
     86  * XXX: It is asymmetric that 'INDENT OFF' is indented, while 'INDENT ON'
     87  * is aligned.
     88  */
     89 //indent run
     90 {
     91 }
     92 	/* INDENT OFF */
     93 /* $ FIXME: The empty line below must be removed. */
     94 
     95 /* INDENT ON */
     96 {
     97 }
     98 //indent end
     99 
    100 
    101 /*
    102  * The INDENT comments can be written without space between the words, but
    103  * nobody does this.
    104  */
    105 //indent input
    106 int   decl   ;
    107 /*INDENTOFF*/
    108 int   decl   ;
    109 /*INDENTON*/
    110 int   decl   ;
    111 //indent end
    112 
    113 //indent run -di0
    114 int decl;
    115 /*INDENTOFF*/
    116 int   decl   ;
    117 /* $ FIXME: The empty line below must be removed. */
    118 
    119 /* INDENTON */
    120 int decl;
    121 //indent end
    122 
    123 
    124 /*
    125  * Any whitespace around the 'INDENT ON/OFF' is ignored, as is any whitespace
    126  * between the two words.
    127  */
    128 //indent input
    129 int   decl   ;
    130 /*		INDENT		OFF		*/
    131 int   decl   ;
    132 /*		INDENT		ON		*/
    133 int   decl   ;
    134 //indent end
    135 
    136 /*
    137  * XXX: It is asymmetric that 'INDENT OFF' is indented, while 'INDENT ON'
    138  * is pushed to the start of the line.
    139  */
    140 //indent run -di0
    141 int decl;
    142 /*		INDENT		OFF		*/
    143 int   decl   ;
    144 /* $ FIXME: The empty line below must be removed. */
    145 
    146 /* INDENT		ON		*/
    147 int decl;
    148 //indent end
    149 
    150 
    151 //indent input
    152 /*INDENT OFF*/
    153 /* No formatting takes place here. */
    154 int format( void ) {{{
    155 /*INDENT ON*/
    156 }}}
    157 //indent end
    158 
    159 //indent run
    160 /*INDENT OFF*/
    161 /* No formatting takes place here. */
    162 int format( void ) {{{
    163 /* $ XXX: Why is the INDENT ON comment indented? */
    164 /* $ XXX: Why does the INDENT ON comment get spaces, but not the OFF comment? */
    165 /* $ FIXME: The empty line below must be removed. */
    166 
    167 			/* INDENT ON */
    168 }
    169 }
    170 }
    171 //indent end
    172 
    173 
    174 //indent input
    175 /* INDENT OFF */
    176 void indent_off ( void ) ;
    177 /*  INDENT */
    178 void indent_on ( void ) ;
    179 /* INDENT OFF */
    180 void indent_off ( void ) ;
    181 	/* INDENT ON */
    182 void indent_on ( void ) ;	/* the comment may be indented */
    183 /* INDENT		OFF					*/
    184 void indent_off ( void ) ;
    185 /* INDENTATION ON */
    186 void indent_still_off ( void ) ;	/* due to the word 'INDENTATION' */
    187 /* INDENT ON * */
    188 void indent_still_off ( void ) ;	/* due to the extra '*' at the end */
    189 /* INDENT ON */
    190 void indent_on ( void ) ;
    191 /* INDENT: OFF */
    192 void indent_still_on ( void ) ;	/* due to the colon in the middle */
    193 /* INDENT OFF */		/* extra comment */
    194 void indent_still_on ( void ) ;	/* due to the extra comment to the right */
    195 //indent end
    196 
    197 //indent run
    198 /* INDENT OFF */
    199 void indent_off ( void ) ;
    200 /* $ FIXME: The empty line below must be removed. */
    201 
    202 /* $ XXX: The double space from the below comment got merged to a single */
    203 /* $ XXX: space even though the comment might be regarded to be still in */
    204 /* $ XXX: the OFF section. */
    205 /* INDENT */
    206 void		indent_on(void);
    207 /* INDENT OFF */
    208 void indent_off ( void ) ;
    209 /* $ FIXME: The empty line below must be removed. */
    210 
    211 /* $ XXX: The below comment got moved from column 9 to column 1. */
    212 /* INDENT ON */
    213 void		indent_on(void);	/* the comment may be indented */
    214 /* INDENT		OFF					*/
    215 void indent_off ( void ) ;
    216 /* INDENTATION ON */
    217 void indent_still_off ( void ) ;	/* due to the word 'INDENTATION' */
    218 /* INDENT ON * */
    219 void indent_still_off ( void ) ;	/* due to the extra '*' at the end */
    220 /* $ FIXME: The empty line below must be removed. */
    221 
    222 /* INDENT ON */
    223 void		indent_on(void);
    224 /* INDENT: OFF */
    225 void		indent_still_on(void);	/* due to the colon in the middle */
    226 /* $ The extra comment got moved to a separate line, but indenting is still */
    227 /* $ off because the 'INDENT OFF' comment was not in a line of its own. */
    228 /* INDENT OFF */
    229 /* extra comment */
    230 void		indent_still_on(void);	/* due to the extra comment to the
    231 					 * right */
    232 //indent end
    233 
    234 
    235 /*
    236  * Try to confuse indent by having a string literal that has an embedded
    237  * INDENT comment.  Indent doesn't get confused though because it requires the
    238  * INDENT comment to go from the very beginning of the line to the very end of
    239  * the line.
    240  */
    241 //indent input
    242 const char *str = "\
    243 /* INDENT OFF */\
    244 "   ,   ch;
    245 //indent end
    246 
    247 //indent run
    248 const char     *str = "\
    249 /* INDENT OFF */\
    250 ", ch;
    251 //indent end
    252 
    253 
    254 /*
    255  * The keywords in the INDENT comments must all be uppercase.
    256  */
    257 //indent input
    258 int   on   ;
    259 /* indent off */
    260 int   still_on   ;
    261 /* INDENT off */
    262 int   still_on   ;
    263 /* indent OFF */
    264 int   still_on   ;
    265 /* INDENT OFF */
    266 int   finally_off   ;
    267 //indent end
    268 
    269 //indent run -di0
    270 int on;
    271 /* indent off */
    272 int still_on;
    273 /* INDENT off */
    274 int still_on;
    275 /* indent OFF */
    276 int still_on;
    277 /* INDENT OFF */
    278 int   finally_off   ;
    279 //indent end
    280