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: add tests for unary and b...



details:   https://anonhg.NetBSD.org/src/rev/7b7ea314d9b1
branches:  trunk
changeset: 365760:7b7ea314d9b1
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat Apr 23 17:25:58 2022 +0000

description:
tests/indent: add tests for unary and binary operators

diffstat:

 tests/usr.bin/indent/lsym_lparen_or_lbracket.c |  98 ++++++++++++++++++++++++-
 tests/usr.bin/indent/token_binary_op.c         |  18 +---
 2 files changed, 98 insertions(+), 18 deletions(-)

diffs (170 lines):

diff -r e4d0c1e4d935 -r 7b7ea314d9b1 tests/usr.bin/indent/lsym_lparen_or_lbracket.c
--- a/tests/usr.bin/indent/lsym_lparen_or_lbracket.c    Sat Apr 23 16:22:23 2022 +0000
+++ b/tests/usr.bin/indent/lsym_lparen_or_lbracket.c    Sat Apr 23 17:25:58 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lsym_lparen_or_lbracket.c,v 1.4 2022/04/22 21:21:20 rillig Exp $ */
+/* $NetBSD: lsym_lparen_or_lbracket.c,v 1.5 2022/04/23 17:25:58 rillig Exp $ */
 
 /*
  * Tests for the token lsym_lparen_or_lbracket, which represents a '(' or '['
@@ -15,12 +15,102 @@
  * In a 'sizeof' expression, '(' is required if the argument is a type name.
  *
  * After one of the keywords 'for', 'if', 'switch' or 'while', the controlling
- * expression must be enclosed in '(' and ')'.
+ * expression must be enclosed in '(' and ')'; see lsym_for.c, lsym_if.c,
+ * lsym_switch.c, lsym_while.c.
  *
- * In an expression, '(' followed by a type name starts a cast expression.
+ * In an expression, '(' followed by a type name starts a cast expression or
+ * a compound literal.
+ *
+ * In a declaration, '[' derives an array type.
+ *
+ * In an expression, '[' starts an array subscript.
  */
 
-// TODO: Add systematic tests for all cases.
+/* The '(' in a type name derives a function type. */
+#indent input
+typedef void signal_handler(int);
+void (*signal(void (*)(int)))(int);
+#indent end
+
+#indent run
+typedef void signal_handler(int);
+void           (*signal(void (*)(int)))(int);
+#indent end
+
+
+/*
+ * The '(' in an expression overrides operator precedence.  In multi-line
+ * expressions, the continuation lines are aligned on the parentheses.
+ */
+#indent input
+int nested = (
+       (
+               (
+                       (
+                               1 + 4
+                       )
+               )
+       )
+);
+#indent end
+
+#indent run
+int            nested = (
+                         (
+                          (
+                           (
+                            1 + 4
+                            )
+                           )
+                          )
+);
+#indent end
+
+
+/* The '(' in a function call expression starts the argument list. */
+#indent input
+int var = macro_call ( arg1,  arg2  ,arg3);
+#indent end
+
+#indent run
+int            var = macro_call(arg1, arg2, arg3);
+#indent end
+
+
+/*
+ * The '(' in a sizeof expression is required for type names and optional for
+ * expressions.
+ */
+#indent input
+size_t sizeof_typename = sizeof ( int );
+size_t sizeof_expr = sizeof ( 12345 ) ;
+#indent end
+
+#indent run
+size_t         sizeof_typename = sizeof(int);
+size_t         sizeof_expr = sizeof(12345);
+#indent end
+
+
+/* The '[' in a type name derives an array type. */
+#indent input
+int array_of_numbers[100];
+#indent end
+
+#indent run
+int            array_of_numbers[100];
+#indent end
+
+
+/* The '[' in an expression accesses an array element. */
+#indent input
+int second_prime = &primes[1];
+#indent end
+
+#indent run
+int            second_prime = &primes[1];
+#indent end
+
 
 #indent input
 void
diff -r e4d0c1e4d935 -r 7b7ea314d9b1 tests/usr.bin/indent/token_binary_op.c
--- a/tests/usr.bin/indent/token_binary_op.c    Sat Apr 23 16:22:23 2022 +0000
+++ b/tests/usr.bin/indent/token_binary_op.c    Sat Apr 23 17:25:58 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: token_binary_op.c,v 1.11 2022/04/23 09:35:26 rillig Exp $ */
+/* $NetBSD: token_binary_op.c,v 1.12 2022/04/23 17:25:58 rillig Exp $ */
 
 /*
  * Tests for binary operators like '+', '&&' and several others.
@@ -15,15 +15,10 @@
 void
 punctuators(void)
 {
-       int brackets = array[subscript];
-       int parentheses = function(argument);
        int braces = { initializer };
        int period = structure.member;
        int arrow = structure->member;
 
-       number = function(argument1, argument2);
-       number = function(argument), number;
-
        /* digraphs */
        number = array<:subscript:>;
        number = (int)<% initializer %>;
@@ -34,16 +29,11 @@
 void
 punctuators(void)
 {
-       int brackets = array[subscript];
-       int parentheses = function(argument);
 /* $ XXX: The spaces around the initializer are gone. */
        int braces = {initializer};
        int period = structure.member;
        int arrow = structure->member;
 
-       number = function(argument1, argument2);
-       number = function(argument), number;
-
        /* digraphs */
 /* $ XXX: indent is confused by the digraphs for '[' and ']'. */
 /* $ This probably doesn't matter since digraphs are not used in practice. */
@@ -83,9 +73,9 @@
 
 
 /*
- * For '+' and '-', this does not work since the lexer has to
- * distinguish between '++' and '+' early.  The following sequence is
- * thus tokenized as:
+ * Long chains of '+' and '-' must be split into several operators as the
+ * lexer has to distinguish between '++' and '+' early.  The following
+ * sequence is thus tokenized as:
  *
  *     word            "a"
  *     postfix_op      "++"



Home | Main Index | Thread Index | Old Index