Module Name:    src
Committed By:   rillig
Date:           Tue Oct 19 20:41:42 UTC 2021

Modified Files:
        src/tests/usr.bin/indent: indent_off_on.c token_comment.c

Log Message:
tests/indent: move tests for indent comments

The special INDENT ON and INDENT OFF comments look like ordinary
comments but are handled in inbuf_read_line. Implementing this feature
in the input function has several unintended side effects regarding
indentation of these comments, as demonstrated by the tests.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/tests/usr.bin/indent/indent_off_on.c
cvs rdiff -u -r1.4 -r1.5 src/tests/usr.bin/indent/token_comment.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/usr.bin/indent/indent_off_on.c
diff -u src/tests/usr.bin/indent/indent_off_on.c:1.1 src/tests/usr.bin/indent/indent_off_on.c:1.2
--- src/tests/usr.bin/indent/indent_off_on.c:1.1	Tue Oct 19 20:20:25 2021
+++ src/tests/usr.bin/indent/indent_off_on.c	Tue Oct 19 20:41:42 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: indent_off_on.c,v 1.1 2021/10/19 20:20:25 rillig Exp $ */
+/* $NetBSD: indent_off_on.c,v 1.2 2021/10/19 20:41:42 rillig Exp $ */
 /* $FreeBSD$ */
 
 /*
@@ -116,3 +116,82 @@ int   decl   ;
 /* INDENT		ON		*/
 int decl;
 #indent end
+
+
+#indent input
+/*INDENT OFF*/
+/* No formatting takes place here. */
+int format( void ) {{{
+/*INDENT ON*/
+}}}
+#indent end
+
+#indent run
+/*INDENT OFF*/
+/* No formatting takes place here. */
+int format( void ) {{{
+/* $ XXX: Why is the INDENT ON comment indented? */
+/* $ XXX: Why does the INDENT ON comment get spaces, but not the OFF comment? */
+			/* INDENT ON */
+}
+}
+}
+#indent end
+
+
+#indent input
+/* INDENT OFF */
+void indent_off ( void ) ;
+/*  INDENT */
+void indent_on ( void ) ;
+/* INDENT OFF */
+void indent_off ( void ) ;
+	/* INDENT ON */
+void indent_on ( void ) ;	/* the comment may be indented */
+/* INDENT		OFF					*/
+void indent_off ( void ) ;
+/* INDENTATION ON */
+void indent_still_off ( void ) ;	/* due to the word 'INDENTATION' */
+/* INDENT ON * */
+void indent_still_off ( void ) ;	/* due to the extra '*' at the end */
+/* INDENT ON */
+void indent_on ( void ) ;
+/* INDENT: OFF */
+void indent_still_on ( void ) ;	/* due to the colon in the middle */
+/* INDENT OFF */		/* extra comment */
+void indent_still_on ( void ) ;	/* due to the extra comment to the right */
+#indent end
+
+#indent run
+/* INDENT OFF */
+void indent_off ( void ) ;
+/* $ XXX: The double space from the below comment got merged to a single */
+/* $ XXX: space even though the comment might be regarded to be still in */
+/* $ XXX: the OFF section. */
+/* INDENT */
+void
+indent_on(void);
+/* INDENT OFF */
+void indent_off ( void ) ;
+/* $ XXX: The below comment got moved from column 9 to column 1. */
+/* INDENT ON */
+void
+indent_on(void);		/* the comment may be indented */
+/* INDENT		OFF					*/
+void indent_off ( void ) ;
+/* INDENTATION ON */
+void indent_still_off ( void ) ;	/* due to the word 'INDENTATION' */
+/* INDENT ON * */
+void indent_still_off ( void ) ;	/* due to the extra '*' at the end */
+/* INDENT ON */
+void
+indent_on(void);
+/* INDENT: OFF */
+void
+indent_still_on(void);		/* due to the colon in the middle */
+/* $ The extra comment got moved to the left since there is no code in */
+/* $ that line. */
+/* INDENT OFF *//* extra comment */
+void
+indent_still_on(void);		/* due to the extra comment to the right */
+#indent end

Index: src/tests/usr.bin/indent/token_comment.c
diff -u src/tests/usr.bin/indent/token_comment.c:1.4 src/tests/usr.bin/indent/token_comment.c:1.5
--- src/tests/usr.bin/indent/token_comment.c:1.4	Tue Oct 19 18:29:59 2021
+++ src/tests/usr.bin/indent/token_comment.c	Tue Oct 19 20:41:42 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: token_comment.c,v 1.4 2021/10/19 18:29:59 rillig Exp $ */
+/* $NetBSD: token_comment.c,v 1.5 2021/10/19 20:41:42 rillig Exp $ */
 /* $FreeBSD$ */
 
 /*
@@ -508,102 +508,6 @@ function(void)
 }
 #indent end
 
-#indent input
-void
-function(void)
-{
-	code();
-}
-
-/*INDENT OFF*/
-#indent end
-
-#indent run
-void
-function(void)
-{
-	code();
-}
-/* $ FIXME: Missing empty line. */
-/*INDENT OFF*/
-#indent end
-
-/*
- * The special comments 'INDENT OFF' and 'INDENT ON' toggle whether the code
- * is formatted or kept as is.
- */
-#indent input
-/*INDENT OFF*/
-/* No formatting takes place here. */
-int format( void ) {{{
-/*INDENT ON*/
-}}}
-
-/* INDENT OFF */
-void indent_off ( void ) ;
-/*  INDENT */
-void indent_on ( void ) ;
-/* INDENT OFF */
-void indent_off ( void ) ;
-	/* INDENT ON */
-void indent_on ( void ) ;	/* the comment may be indented */
-/* INDENT		OFF					*/
-void indent_off ( void ) ;
-/* INDENTATION ON */
-void indent_still_off ( void ) ;	/* due to the word 'INDENTATION' */
-/* INDENT ON * */
-void indent_still_off ( void ) ;	/* due to the extra '*' at the end */
-/* INDENT ON */
-void indent_on ( void ) ;
-/* INDENT: OFF */
-void indent_still_on ( void ) ;	/* due to the colon in the middle */
-/* INDENT OFF */		/* extra comment */
-void indent_still_on ( void ) ;	/* due to the extra comment to the right */
-#indent end
-
-#indent run
-/*INDENT OFF*/
-/* No formatting takes place here. */
-int format( void ) {{{
-/* $ XXX: Why is the INDENT ON comment indented? */
-/* $ XXX: Why does the INDENT ON comment get spaces, but not the OFF comment? */
-			/* INDENT ON */
-}
-}
-}
-/* $ FIXME: The empty line disappeared but shouldn't. */
-/* INDENT OFF */
-void indent_off ( void ) ;
-/* $ XXX: The double space from the below comment got merged to a single */
-/* $ XXX: space even though the comment might be regarded to be still in */
-/* $ XXX: the OFF section. */
-/* INDENT */
-void
-indent_on(void);
-/* INDENT OFF */
-void indent_off ( void ) ;
-/* $ XXX: The below comment got moved from column 9 to column 1. */
-/* INDENT ON */
-void
-indent_on(void);		/* the comment may be indented */
-/* INDENT		OFF					*/
-void indent_off ( void ) ;
-/* INDENTATION ON */
-void indent_still_off ( void ) ;	/* due to the word 'INDENTATION' */
-/* INDENT ON * */
-void indent_still_off ( void ) ;	/* due to the extra '*' at the end */
-/* INDENT ON */
-void
-indent_on(void);
-/* INDENT: OFF */
-void
-indent_still_on(void);		/* due to the colon in the middle */
-/* $ The extra comment got moved to the left since there is no code in */
-/* $ that line. */
-/* INDENT OFF *//* extra comment */
-void
-indent_still_on(void);		/* due to the extra comment to the right */
-#indent end
 
 #indent input
 /*

Reply via email to