Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/indent indent: miscellaneous cleanups, more tests fo...



details:   https://anonhg.NetBSD.org/src/rev/1df7b88a48a8
branches:  trunk
changeset: 376390:1df7b88a48a8
user:      rillig <rillig%NetBSD.org@localhost>
date:      Thu Jun 15 09:19:06 2023 +0000

description:
indent: miscellaneous cleanups, more tests for edge cases

diffstat:

 tests/usr.bin/indent/fmt_decl.c                      |  19 ++++-
 tests/usr.bin/indent/lsym_case_label.c               |  22 +++++-
 tests/usr.bin/indent/lsym_funcname.c                 |  16 +++-
 tests/usr.bin/indent/lsym_lbrace.c                   |  84 +++++++++++++++++++-
 tests/usr.bin/indent/lsym_rparen_or_rbracket.c       |  38 ++++++++-
 tests/usr.bin/indent/lsym_semicolon.c                |  65 +++++++++++++++-
 tests/usr.bin/indent/lsym_tag.c                      |  19 ++++-
 tests/usr.bin/indent/lsym_type_outside_parentheses.c |  12 ++-
 tests/usr.bin/indent/opt_bacc.c                      |  32 +++++++-
 tests/usr.bin/indent/opt_eei.c                       |   5 +-
 tests/usr.bin/indent/ps_ind_level.c                  |  17 +++-
 usr.bin/indent/args.c                                |  10 +-
 usr.bin/indent/indent.c                              |  49 +++++------
 usr.bin/indent/io.c                                  |  14 +-
 14 files changed, 350 insertions(+), 52 deletions(-)

diffs (truncated from 703 to 300 lines):

diff -r 943789ff04ed -r 1df7b88a48a8 tests/usr.bin/indent/fmt_decl.c
--- a/tests/usr.bin/indent/fmt_decl.c   Thu Jun 15 09:15:54 2023 +0000
+++ b/tests/usr.bin/indent/fmt_decl.c   Thu Jun 15 09:19:06 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: fmt_decl.c,v 1.56 2023/06/15 08:40:20 rillig Exp $     */
+/*     $NetBSD: fmt_decl.c,v 1.57 2023/06/15 09:19:07 rillig Exp $     */
 
 /*
  * Tests for declarations of global variables, external functions, and local
@@ -1183,3 +1183,20 @@ multi_line = (int[]){
        };
 }
 //indent end
+
+
+/*
+ *
+ */
+//indent input
+int
+old_style(a)
+       struct {
+               int             member;
+       }               a;
+{
+       stmt;
+}
+//indent end
+
+//indent run-equals-input
diff -r 943789ff04ed -r 1df7b88a48a8 tests/usr.bin/indent/lsym_case_label.c
--- a/tests/usr.bin/indent/lsym_case_label.c    Thu Jun 15 09:15:54 2023 +0000
+++ b/tests/usr.bin/indent/lsym_case_label.c    Thu Jun 15 09:19:06 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lsym_case_label.c,v 1.10 2023/06/10 07:05:18 rillig Exp $ */
+/* $NetBSD: lsym_case_label.c,v 1.11 2023/06/15 09:19:07 rillig Exp $ */
 
 /*
  * Tests for the tokens lsym_case and lsym_default, which represent the
@@ -103,3 +103,23 @@ const char *type_name = _Generic(
 //indent end
 
 //indent run-equals-input -di0 -nlp
+
+
+/*
+ * Multi-line case expressions are rare but still should be processed in a
+ * sensible way.
+ */
+//indent input
+{
+       switch (expr) {
+// $ FIXME: The line containing the 'case' must be indented like a 'case'.
+               case 1
+                   + 2
+// $ FIXME: This continuation line must be indented by 4 columns.
+       + 3:
+               stmt;
+       }
+}
+//indent end
+
+//indent run-equals-input -ci4
diff -r 943789ff04ed -r 1df7b88a48a8 tests/usr.bin/indent/lsym_funcname.c
--- a/tests/usr.bin/indent/lsym_funcname.c      Thu Jun 15 09:15:54 2023 +0000
+++ b/tests/usr.bin/indent/lsym_funcname.c      Thu Jun 15 09:19:06 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lsym_funcname.c,v 1.5 2023/05/22 23:01:27 rillig Exp $ */
+/* $NetBSD: lsym_funcname.c,v 1.6 2023/06/15 09:19:07 rillig Exp $ */
 
 /*
  * Tests for the token lsym_funcname, which is the name of a function, but only
@@ -19,3 +19,17 @@ function(void)
 //indent end
 
 //indent run-equals-input
+
+
+/*
+ * The comment after the return type of a function definition is a code
+ * comment, not a declaration comment.
+ */
+//indent input
+void                           // comment
+function_with_comment(void)
+{
+}
+//indent end
+
+//indent run-equals-input
diff -r 943789ff04ed -r 1df7b88a48a8 tests/usr.bin/indent/lsym_lbrace.c
--- a/tests/usr.bin/indent/lsym_lbrace.c        Thu Jun 15 09:15:54 2023 +0000
+++ b/tests/usr.bin/indent/lsym_lbrace.c        Thu Jun 15 09:19:06 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lsym_lbrace.c,v 1.8 2023/06/04 13:49:00 rillig Exp $ */
+/* $NetBSD: lsym_lbrace.c,v 1.9 2023/06/15 09:19:07 rillig Exp $ */
 
 /*
  * Tests for the token lsym_lbrace, which represents a '{' in these contexts:
@@ -58,8 +58,88 @@ origin(void)
        return (struct point){
                .x = 0,
                .y = 0,
+       }, actual_return_value;
+}
+//indent end
+
+//indent run-equals-input
+
+/* Ensure that the comma is not interpreted as separator for declarators. */
+//indent run-equals-input -bc
+
+
+//indent input
+{
+       const char *hello = (const char[]){
+               'h', 'e', 'l', 'l', 'o',
+       }, *world = (const char[]){
+               'w', 'o', 'r', 'l', 'd',
        };
 }
 //indent end
 
-//indent run-equals-input
+//indent run-equals-input -ldi0
+
+//indent run-equals-input -ldi0 -bc
+
+
+//indent input
+{
+       if (cond rparen {
+       }
+       switch (expr rparen {
+       }
+}
+//indent end
+
+//indent run
+{
+               if (cond rparen {
+               }
+               switch (expr rparen {
+               }
+}
+exit 1
+error: Standard Input:2: Unbalanced parentheses
+error: Standard Input:4: Unbalanced parentheses
+//indent end
+
+
+/*
+ * The -bl option does not force initializer braces on separate lines.
+ */
+//indent input
+struct {int member;} var = {1};
+//indent end
+
+//indent run -bl
+struct
+{
+       int             member;
+}              var = {1};
+//indent end
+
+
+/*
+ * A comment in a single-line function definition is not a declaration comment
+ * and thus not in column 25.
+ */
+//indent input
+void function(void); /* comment */
+void function(void) { /* comment */ }
+//indent end
+
+//indent run -di0
+void function(void);           /* comment */
+void
+function(void)
+{                              /* comment */
+}
+//indent end
+
+//indent run -di0 -nfbs
+void function(void);           /* comment */
+void
+function(void) {               /* comment */
+}
+//indent end
diff -r 943789ff04ed -r 1df7b88a48a8 tests/usr.bin/indent/lsym_rparen_or_rbracket.c
--- a/tests/usr.bin/indent/lsym_rparen_or_rbracket.c    Thu Jun 15 09:15:54 2023 +0000
+++ b/tests/usr.bin/indent/lsym_rparen_or_rbracket.c    Thu Jun 15 09:19:06 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lsym_rparen_or_rbracket.c,v 1.4 2022/04/24 10:36:37 rillig Exp $ */
+/* $NetBSD: lsym_rparen_or_rbracket.c,v 1.5 2023/06/15 09:19:07 rillig Exp $ */
 
 /*
  * Tests for the token lsym_rparen_or_lbracket, which represents ')' or ']',
@@ -18,3 +18,39 @@ int array[3] = {[2] = 3};
 //indent end
 
 //indent run-equals-input -di0
+
+
+//indent input
+int a = array[
+3
+];
+{
+int a = array[
+3
+];
+}
+//indent end
+
+//indent run -di0
+int a = array[
+             3
+];
+{
+       int a = array[
+                     3
+// $ FIXME: Should be one level to the left since it is the outermost bracket.
+               ];
+}
+//indent end
+
+//indent run -di0 -nlp
+int a = array[
+       3
+];
+{
+       int a = array[
+               3
+// $ FIXME: Should be one level to the left since it is the outermost bracket.
+               ];
+}
+//indent end
diff -r 943789ff04ed -r 1df7b88a48a8 tests/usr.bin/indent/lsym_semicolon.c
--- a/tests/usr.bin/indent/lsym_semicolon.c     Thu Jun 15 09:15:54 2023 +0000
+++ b/tests/usr.bin/indent/lsym_semicolon.c     Thu Jun 15 09:19:06 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lsym_semicolon.c,v 1.4 2022/04/24 10:36:37 rillig Exp $ */
+/* $NetBSD: lsym_semicolon.c,v 1.5 2023/06/15 09:19:07 rillig Exp $ */
 
 /*
  * Tests for the token lsym_semicolon, which represents ';' in these contexts:
@@ -41,3 +41,66 @@ function(void)
                stmt();
 }
 //indent end
+
+
+//indent input
+{
+       switch (expr) {
+// $ FIXME: Indent the 'case' at the 'switch'.
+               case;
+               stmt;
+       case 2:
+               stmt;
+       }
+}
+//indent end
+
+//indent run-equals-input
+
+
+/*
+ * A semicolon closes all possibly open '?:' expressions, so that the next ':'
+ * is interpreted as a bit-field.
+ */
+//indent input
+struct s {
+       int a[len ? ? ? 1];
+       int bit_field:1;
+};
+//indent end
+
+//indent run-equals-input -di0
+
+
+/*
+ * A semicolon does not magically close any initializer braces that may still
+ * be open.
+ */
+//indent input
+int a = {{;
+int b = 3;
+//indent end
+
+//indent run -di0
+int a = {{;
+               int b = 3;
+exit 1
+error: Standard Input:2: Stuff missing from end of file
+//indent end
+
+
+//indent input



Home | Main Index | Thread Index | Old Index