Source-Changes-HG archive

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

[src/trunk]: src/tests/usr.bin/indent tests/indent: clean up and extend tests



details:   https://anonhg.NetBSD.org/src/rev/0c5d0068d1ed
branches:  trunk
changeset: 1026375:0c5d0068d1ed
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat Nov 20 16:54:17 2021 +0000

description:
tests/indent: clean up and extend tests

diffstat:

 tests/usr.bin/indent/lsym_case_label.c    |    3 +-
 tests/usr.bin/indent/lsym_comma.c         |    4 +-
 tests/usr.bin/indent/lsym_lbrace.c        |    4 +-
 tests/usr.bin/indent/lsym_postfix_op.c    |   22 ++++-
 tests/usr.bin/indent/lsym_preprocessing.c |   24 +++++-
 tests/usr.bin/indent/opt_ce.c             |    8 +-
 tests/usr.bin/indent/opt_ci.c             |   42 ++++++++++-
 tests/usr.bin/indent/opt_cli.c            |   11 ++-
 tests/usr.bin/indent/opt_d.c              |    9 +-
 tests/usr.bin/indent/opt_di.c             |    6 +-
 tests/usr.bin/indent/opt_dj.c             |   26 +++++-
 tests/usr.bin/indent/opt_eei.c            |    7 +-
 tests/usr.bin/indent/opt_ei.c             |   22 +++++-
 tests/usr.bin/indent/opt_fc1.c            |   15 +-
 tests/usr.bin/indent/opt_fcb.c            |  121 ++++++++++++++++++++++-------
 tests/usr.bin/indent/opt_i.c              |    7 +-
 tests/usr.bin/indent/opt_ip.c             |   63 +++++++++++----
 tests/usr.bin/indent/opt_l.c              |   16 +++-
 tests/usr.bin/indent/opt_lc.c             |   29 ++++--
 tests/usr.bin/indent/opt_ldi.c            |   17 +++-
 tests/usr.bin/indent/opt_lp.c             |   36 ++++++++-
 tests/usr.bin/indent/opt_lpl.c            |    6 +-
 tests/usr.bin/indent/opt_psl.c            |   10 +-
 tests/usr.bin/indent/opt_ta.c             |   14 ++-
 tests/usr.bin/indent/opt_ut.c             |    6 +-
 tests/usr.bin/indent/opt_v.c              |   10 +-
 tests/usr.bin/indent/ps_ind_level.c       |    6 +-
 tests/usr.bin/indent/psym_for_exprs.c     |   18 ++++-
 tests/usr.bin/indent/psym_switch_expr.c   |   34 ++++++++-
 tests/usr.bin/indent/psym_while_expr.c    |   37 ++++++++-
 tests/usr.bin/indent/token_binary_op.c    |  105 ++++++++++---------------
 tests/usr.bin/indent/token_comment.c      |   94 ++++++++++------------
 tests/usr.bin/indent/token_newline.c      |    4 +-
 tests/usr.bin/indent/token_period.c       |   11 +--
 tests/usr.bin/indent/token_while_expr.c   |    4 +-
 35 files changed, 606 insertions(+), 245 deletions(-)

diffs (truncated from 1589 to 300 lines):

diff -r 549c6eadb0cd -r 0c5d0068d1ed tests/usr.bin/indent/lsym_case_label.c
--- a/tests/usr.bin/indent/lsym_case_label.c    Sat Nov 20 16:18:18 2021 +0000
+++ b/tests/usr.bin/indent/lsym_case_label.c    Sat Nov 20 16:54:17 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lsym_case_label.c,v 1.1 2021/11/18 21:19:19 rillig Exp $ */
+/* $NetBSD: lsym_case_label.c,v 1.2 2021/11/20 16:54:17 rillig Exp $ */
 /* $FreeBSD$ */
 
 /*
@@ -9,6 +9,7 @@
  * Since C11, the keyword 'default' is used in _Generic selections as well.
  *
  * See also:
+ *     opt_cli.c
  *     psym_switch_expr.c
  *     C11 6.5.1.1             "Generic selection"
  */
diff -r 549c6eadb0cd -r 0c5d0068d1ed tests/usr.bin/indent/lsym_comma.c
--- a/tests/usr.bin/indent/lsym_comma.c Sat Nov 20 16:18:18 2021 +0000
+++ b/tests/usr.bin/indent/lsym_comma.c Sat Nov 20 16:54:17 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lsym_comma.c,v 1.1 2021/11/18 21:19:19 rillig Exp $ */
+/* $NetBSD: lsym_comma.c,v 1.2 2021/11/20 16:54:17 rillig Exp $ */
 /* $FreeBSD$ */
 
 /*
@@ -7,6 +7,8 @@
  * In an expression, the binary operator ',' evaluates its left operand before
  * its right operand, inserting a sequence point.
  *
+ * In a declaration, a ',' separates the declarators.
+ *
  * In a parameter list of a function type, a ',' separates the parameter
  * declarations.
  *
diff -r 549c6eadb0cd -r 0c5d0068d1ed tests/usr.bin/indent/lsym_lbrace.c
--- a/tests/usr.bin/indent/lsym_lbrace.c        Sat Nov 20 16:18:18 2021 +0000
+++ b/tests/usr.bin/indent/lsym_lbrace.c        Sat Nov 20 16:54:17 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lsym_lbrace.c,v 1.1 2021/11/18 21:19:19 rillig Exp $ */
+/* $NetBSD: lsym_lbrace.c,v 1.2 2021/11/20 16:54:17 rillig Exp $ */
 /* $FreeBSD$ */
 
 /*
@@ -11,6 +11,8 @@
  *
  * In an expression, '(type){' starts a compound expression that is typically
  * used in an assignment to a struct or array.
+ *
+ * TODO: try to split this token into lsym_lbrace_block and lsym_lbrace_init.
  */
 
 #indent input
diff -r 549c6eadb0cd -r 0c5d0068d1ed tests/usr.bin/indent/lsym_postfix_op.c
--- a/tests/usr.bin/indent/lsym_postfix_op.c    Sat Nov 20 16:18:18 2021 +0000
+++ b/tests/usr.bin/indent/lsym_postfix_op.c    Sat Nov 20 16:54:17 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lsym_postfix_op.c,v 1.1 2021/11/18 21:19:19 rillig Exp $ */
+/* $NetBSD: lsym_postfix_op.c,v 1.2 2021/11/20 16:54:17 rillig Exp $ */
 /* $FreeBSD$ */
 
 /*
@@ -10,7 +10,23 @@
  */
 
 #indent input
-// TODO: add input
+int decl = lvalue ++;
+int decl = lvalue --;
+#indent end
+
+#indent run -di0
+int decl = lvalue++;
+int decl = lvalue--;
 #indent end
 
-#indent run-equals-input
+
+/*
+ * There is no operator '**', so try that just for fun.
+ */
+#indent input
+int decl = lvalue **;
+#indent end
+
+#indent run -di0
+int decl = lvalue * *;
+#indent end
diff -r 549c6eadb0cd -r 0c5d0068d1ed tests/usr.bin/indent/lsym_preprocessing.c
--- a/tests/usr.bin/indent/lsym_preprocessing.c Sat Nov 20 16:18:18 2021 +0000
+++ b/tests/usr.bin/indent/lsym_preprocessing.c Sat Nov 20 16:54:17 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lsym_preprocessing.c,v 1.1 2021/11/18 21:19:19 rillig Exp $ */
+/* $NetBSD: lsym_preprocessing.c,v 1.2 2021/11/20 16:54:17 rillig Exp $ */
 /* $FreeBSD$ */
 
 /*
@@ -18,3 +18,25 @@
 #indent end
 
 #indent run-equals-input
+
+
+/*
+ * Whitespace in the following preprocessing directives is preserved.
+ */
+#indent input
+#define space ' '              /* the 'define' is followed by a space */
+#define        tab '\t'                /* the 'define' is followed by a tab */
+#if   0                                /* 3 spaces */
+#elif          0               /* 2 tabs */
+#elif  0       >       1       /* tabs between the tokens */
+#endif
+#indent end
+
+#indent run-equals-input
+
+// TODO: #define unfinished_string "...
+// TODO: #define unfinished_char '...
+// TODO: # 123 "file.h"
+// TODO: backslash-newline
+// TODO: block comment
+// TODO: line comment
diff -r 549c6eadb0cd -r 0c5d0068d1ed tests/usr.bin/indent/opt_ce.c
--- a/tests/usr.bin/indent/opt_ce.c     Sat Nov 20 16:18:18 2021 +0000
+++ b/tests/usr.bin/indent/opt_ce.c     Sat Nov 20 16:54:17 2021 +0000
@@ -1,13 +1,15 @@
-/* $NetBSD: opt_ce.c,v 1.3 2021/10/16 21:32:10 rillig Exp $ */
+/* $NetBSD: opt_ce.c,v 1.4 2021/11/20 16:54:17 rillig Exp $ */
 /* $FreeBSD$ */
 
 /*
  * Tests for the options '-ce' and '-nce'.
  *
- * The option '-ce' places the 'else if' in a single line, as if it were only
- * a single keyword.
+ * The option '-ce' places the 'else' on the same line as the preceding '}'.
  *
  * The option '-nce' places the 'else' on the next line.
+ *
+ * See also:
+ *     opt_ei.c
  */
 
 #indent input
diff -r 549c6eadb0cd -r 0c5d0068d1ed tests/usr.bin/indent/opt_ci.c
--- a/tests/usr.bin/indent/opt_ci.c     Sat Nov 20 16:18:18 2021 +0000
+++ b/tests/usr.bin/indent/opt_ci.c     Sat Nov 20 16:54:17 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: opt_ci.c,v 1.4 2021/11/20 11:13:18 rillig Exp $ */
+/* $NetBSD: opt_ci.c,v 1.5 2021/11/20 16:54:17 rillig Exp $ */
 /* $FreeBSD$ */
 
 /*
@@ -189,3 +189,43 @@
                        third));
 }
 #indent end
+
+
+/*
+ * In the default configuration, the indentation level from '-i' is the same
+ * as the continuation indentation from '-ci'.  The difference between these
+ * becomes visible for structural macros like 'forever' or 'foreach'.
+ */
+#indent input
+#define forever for (;;)
+void
+function(void)
+{
+       forever
+               stmt();
+
+       forever {
+               stmt();
+       }
+}
+#indent end
+
+#indent run-equals-input
+
+/*
+ * The difference between the block indentation and the continuation
+ * indentation only becomes visible when these two differ.
+ */
+#indent run -i8 -ci4
+#define forever for (;;)
+void
+function(void)
+{
+       forever
+           stmt();
+
+       forever {
+               stmt();
+       }
+}
+#indent end
diff -r 549c6eadb0cd -r 0c5d0068d1ed tests/usr.bin/indent/opt_cli.c
--- a/tests/usr.bin/indent/opt_cli.c    Sat Nov 20 16:18:18 2021 +0000
+++ b/tests/usr.bin/indent/opt_cli.c    Sat Nov 20 16:54:17 2021 +0000
@@ -1,6 +1,15 @@
-/* $NetBSD: opt_cli.c,v 1.1 2021/10/22 20:54:36 rillig Exp $ */
+/* $NetBSD: opt_cli.c,v 1.2 2021/11/20 16:54:17 rillig Exp $ */
 /* $FreeBSD$ */
 
+/*
+ * Tests for the option '-cli' ("case label indentation"), which sets the
+ * amount of indentation of a 'case' relative to the surrounding 'switch',
+ * measured in indentation levels.
+ *
+ * See also:
+ *     lsym_case_label.c
+ */
+
 #indent input
 void
 classify(int n)
diff -r 549c6eadb0cd -r 0c5d0068d1ed tests/usr.bin/indent/opt_d.c
--- a/tests/usr.bin/indent/opt_d.c      Sat Nov 20 16:18:18 2021 +0000
+++ b/tests/usr.bin/indent/opt_d.c      Sat Nov 20 16:54:17 2021 +0000
@@ -1,7 +1,11 @@
-/* $NetBSD: opt_d.c,v 1.1 2021/10/22 20:54:36 rillig Exp $ */
+/* $NetBSD: opt_d.c,v 1.2 2021/11/20 16:54:17 rillig Exp $ */
 /* $FreeBSD$ */
 
-/* XXX: oops, the comments at level 0 move below the '{' */
+/*
+ * Tests for the option '-d', which moves comments to the left of the
+ * current code indentation level.
+ */
+
 #indent input
 void
 example(void)
@@ -20,6 +24,7 @@
 }
 #indent end
 
+/* The comments at level 0 move below the '{', due to the option '-br'. */
 #indent run -d1
 void
 example(void)
diff -r 549c6eadb0cd -r 0c5d0068d1ed tests/usr.bin/indent/opt_di.c
--- a/tests/usr.bin/indent/opt_di.c     Sat Nov 20 16:18:18 2021 +0000
+++ b/tests/usr.bin/indent/opt_di.c     Sat Nov 20 16:54:17 2021 +0000
@@ -1,9 +1,9 @@
-/* $NetBSD: opt_di.c,v 1.5 2021/11/20 11:13:18 rillig Exp $ */
+/* $NetBSD: opt_di.c,v 1.6 2021/11/20 16:54:17 rillig Exp $ */
 /* $FreeBSD$ */
 
 /*
- * Test the option '-di', which specifies the indentation of the variable
- * declarator.
+ * Test the option '-di', which specifies the indentation of the first
+ * variable name in a declaration.
  */
 
 #indent input
diff -r 549c6eadb0cd -r 0c5d0068d1ed tests/usr.bin/indent/opt_dj.c
--- a/tests/usr.bin/indent/opt_dj.c     Sat Nov 20 16:18:18 2021 +0000
+++ b/tests/usr.bin/indent/opt_dj.c     Sat Nov 20 16:54:17 2021 +0000
@@ -1,10 +1,10 @@
-/* $NetBSD: opt_dj.c,v 1.4 2021/11/20 11:13:18 rillig Exp $ */
+/* $NetBSD: opt_dj.c,v 1.5 2021/11/20 16:54:17 rillig Exp $ */
 /* $FreeBSD$ */
 
 /*
  * Tests for the options '-dj' and '-ndj'.
  *
- * The option '-dj' left-justifies declarations.
+ * The option '-dj' left-justifies declarations of local variables.
  *
  * The option '-ndj' indents declarations the same as code.
  */
@@ -55,3 +55,25 @@
        code();
 }
 #indent end
+
+
+/*
+ * The option '-dj' does not influence traditional function definitions.
+ */
+#indent input
+double
+dbl_plus3(a, b, c)
+double a, b, c;
+{
+       return a + b + c;
+}
+#indent end
+
+#indent run -dj
+double
+dbl_plus3(a, b, c)
+       double          a, b, c;
+{
+       return a + b + c;
+}



Home | Main Index | Thread Index | Old Index