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: migrate tests for parenth...



details:   https://anonhg.NetBSD.org/src/rev/68e37d89d585
branches:  trunk
changeset: 365768:68e37d89d585
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Apr 24 08:48:17 2022 +0000

description:
tests/indent: migrate tests for parentheses, brackets, braces

diffstat:

 distrib/sets/lists/tests/mi                    |    6 +-
 tests/usr.bin/indent/Makefile                  |    4 +-
 tests/usr.bin/indent/lsym_lparen_or_lbracket.c |  197 ++++++++++++++++++++++++-
 tests/usr.bin/indent/lsym_rbrace.c             |   70 ++++++++-
 tests/usr.bin/indent/token_lparen.c            |  196 ------------------------
 tests/usr.bin/indent/token_rbrace.c            |   16 --
 6 files changed, 261 insertions(+), 228 deletions(-)

diffs (truncated from 581 to 300 lines):

diff -r fd73518cc522 -r 68e37d89d585 distrib/sets/lists/tests/mi
--- a/distrib/sets/lists/tests/mi       Sun Apr 24 07:11:31 2022 +0000
+++ b/distrib/sets/lists/tests/mi       Sun Apr 24 08:48:17 2022 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.1196 2022/04/23 09:59:13 rillig Exp $
+# $NetBSD: mi,v 1.1197 2022/04/24 08:48:17 rillig Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -5274,13 +5274,13 @@
 ./usr/tests/usr.bin/indent/token_keyword_for_if_while.c                        tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/indent/token_keyword_struct_union_enum.c           tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/indent/token_lbrace.c                              tests-obsolete          obsolete,atf
-./usr/tests/usr.bin/indent/token_lparen.c                              tests-usr.bin-tests     compattestfile,atf
+./usr/tests/usr.bin/indent/token_lparen.c                              tests-obsolete          obsolete,atf
 ./usr/tests/usr.bin/indent/token_newline.c                             tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/indent/token_period.c                              tests-obsolete          obsolete,atf
 ./usr/tests/usr.bin/indent/token_postfix_op.c                          tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/indent/token_preprocessing.c                       tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/indent/token_question.c                            tests-obsolete          obsolete,atf
-./usr/tests/usr.bin/indent/token_rbrace.c                              tests-usr.bin-tests     compattestfile,atf
+./usr/tests/usr.bin/indent/token_rbrace.c                              tests-obsolete          obsolete,atf
 ./usr/tests/usr.bin/indent/token_rparen.c                              tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/indent/token_semicolon.c                           tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/indent/token_stmt.c                                        tests-usr.bin-tests     compattestfile,atf
diff -r fd73518cc522 -r 68e37d89d585 tests/usr.bin/indent/Makefile
--- a/tests/usr.bin/indent/Makefile     Sun Apr 24 07:11:31 2022 +0000
+++ b/tests/usr.bin/indent/Makefile     Sun Apr 24 08:48:17 2022 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: Makefile,v 1.42 2022/04/23 09:59:14 rillig Exp $
+#      $NetBSD: Makefile,v 1.43 2022/04/24 08:48:17 rillig Exp $
 
 .include <bsd.own.mk>
 
@@ -124,11 +124,9 @@
 FILES+=                token_keyword_else.c
 FILES+=                token_keyword_for_if_while.c
 FILES+=                token_keyword_struct_union_enum.c
-FILES+=                token_lparen.c
 FILES+=                token_newline.c
 FILES+=                token_postfix_op.c
 FILES+=                token_preprocessing.c
-FILES+=                token_rbrace.c
 FILES+=                token_rparen.c
 FILES+=                token_semicolon.c
 FILES+=                token_stmt.c
diff -r fd73518cc522 -r 68e37d89d585 tests/usr.bin/indent/lsym_lparen_or_lbracket.c
--- a/tests/usr.bin/indent/lsym_lparen_or_lbracket.c    Sun Apr 24 07:11:31 2022 +0000
+++ b/tests/usr.bin/indent/lsym_lparen_or_lbracket.c    Sun Apr 24 08:48:17 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lsym_lparen_or_lbracket.c,v 1.5 2022/04/23 17:25:58 rillig Exp $ */
+/* $NetBSD: lsym_lparen_or_lbracket.c,v 1.6 2022/04/24 08:48:17 rillig Exp $ */
 
 /*
  * Tests for the token lsym_lparen_or_lbracket, which represents a '(' or '['
@@ -9,18 +9,20 @@
  * In an expression, '(' starts an inner expression to override the usual
  * operator precedence.
  *
- * In an expression, an identifier followed by '(' starts a function call
- * expression.
+ * In a function call expression, '(' marks the beginning of the function
+ * arguments.
  *
  * In a 'sizeof' expression, '(' is required if the argument is a type name.
  *
+ * In an expression, '(' followed by a type name starts a cast expression or
+ * a compound literal.
+ *
+ * In a type declaration, '(' marks the beginning of the function parameters.
+ *
  * After one of the keywords 'for', 'if', 'switch' or 'while', the controlling
  * 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 or
- * a compound literal.
- *
  * In a declaration, '[' derives an array type.
  *
  * In an expression, '[' starts an array subscript.
@@ -38,6 +40,13 @@
 #indent end
 
 
+#indent input
+#define macro(arg) ((arg) + 1)
+#indent end
+
+#indent run-equals-input -di0
+
+
 /*
  * The '(' in an expression overrides operator precedence.  In multi-line
  * expressions, the continuation lines are aligned on the parentheses.
@@ -134,4 +143,180 @@
 
 #indent run-equals-input
 
+
+/* This is the maximum supported number of parentheses. */
+#indent input
+int zero = (((((((((((((((((((0)))))))))))))))))));
+#indent end
+
+#indent run-equals-input -di0
+
+
+#indent input
+void (*action)(void);
+#indent end
+
+#indent run-equals-input -di0
+
+
+#indent input
+void
+function(void)
+{
+    other_function();
+    other_function("first", 2, "last argument"[4]);
+
+    if (false)(void)x;
+    if (false)(func)(arg);
+    if (false)(cond)?123:456;
+
+    /* C99 compound literal */
+    origin = (struct point){0,0};
+
+    /* GCC statement expression */
+    /* expr = ({if(expr)debug();expr;}); */
+/* $ XXX: Generates 'error: Standard Input:36: Unbalanced parentheses'. */
+}
+#indent end
+
+#indent run
+void
+function(void)
+{
+       other_function();
+       other_function("first", 2, "last argument"[4]);
+
+       if (false)
+               (void)x;
+       if (false)
+               (func)(arg);
+       if (false)
+               (cond) ? 123 : 456;
+
+       /* C99 compound literal */
+       origin = (struct point){
+               0, 0
+       };
+
+       /* GCC statement expression */
+       /* expr = ({if(expr)debug();expr;}); */
+}
+#indent end
+
+
+/*
+ * C99 designator initializers are the rare situation where there is a space
+ * before a '['.
+ */
+#indent input
+int array[] = {
+       1, 2, [2] = 3, [3] = 4,
+};
+#indent end
+
+#indent run-equals-input -di0
+
+
+/*
+ * Test want_blank_before_lparen for all possible token types.
+ */
+#indent input
+void cover_want_blank_before_lparen(void)
+{
+       /* ps.prev_token can never be 'newline'. */
+       int newline =
+       (3);
+
+       int lparen_or_lbracket = a[(3)];
+       int rparen_or_rbracket = a[3](5);
+       +(unary_op);
+       3 + (binary_op);
+       a++(postfix_op);        /* unlikely to be seen in practice */
+       cond ? (question) : (5);
+       switch (expr) {
+       case (case_label):;
+       }
+       a ? 3 : (colon);
+       (semicolon) = 3;
+       int lbrace[] = {(3)};
+       int rbrace_in_decl = {{3}(4)};  /* syntax error */
+       {}
+       (rbrace_in_stmt)();
+       ident(3);
+       int(decl);
+       a++, (comma)();
+       int comment = /* comment */ (3);        /* comment is skipped */
+       switch (expr) {}
+#define preprocessing
+       (preprocessing)();
+       /* $ XXX: lsym_form_feed should be skipped, just as newline. */
+       (lsym_form_feed)();    /* XXX: should be skipped */
+       for(;;);
+       do(lsym_do)=3;while(0);
+       if(cond);else(lsym_else)();
+       do(lsym_do);while(0);
+       str.(member);           /* syntax error */
+       L("string_prefix");             /* impossible */
+       static (int)storage_class;      /* syntax error */
+       funcname(3);
+       typedef (type_def) new_type;
+       // $ TODO: is keyword_struct_union_enum possible?
+       struct (keyword_struct_union_enum);     /* syntax error */
+}
+#indent end
+
+#indent run -ldi0
+void
+cover_want_blank_before_lparen(void)
+{
+       /* ps.prev_token can never be 'newline'. */
+       int newline =
+       (3);
+
+       int lparen_or_lbracket = a[(3)];
+       int rparen_or_rbracket = a[3](5);
+       +(unary_op);
+       3 + (binary_op);
+       a++ (postfix_op);       /* unlikely to be seen in practice */
+       cond ? (question) : (5);
+       switch (expr) {
+       case (case_label):;
+       }
+       a ? 3 : (colon);
+       (semicolon) = 3;
+       int lbrace[] = {(3)};
+       int rbrace_in_decl = {{3} (4)}; /* syntax error */
+       {
+       }
+       (rbrace_in_stmt)();
+       ident(3);
+       int (decl);
+       a++, (comma)();
+       int comment = /* comment */ (3);        /* comment is skipped */
+       switch (expr) {
+       }
+#define preprocessing
+       (preprocessing)();
+
+/* $ XXX: Where has the '\f' gone? It should have been preserved. */
+       (lsym_form_feed)();     /* XXX: should be skipped */
+       for (;;);
+       do
+               (lsym_do) = 3;
+       while (0);
+       if (cond);
+       else
+               (lsym_else)();
+       do
+               (lsym_do);
+       while (0);
+       str.(member);           /* syntax error */
+       L("string_prefix");     /* impossible */
+       static (int)storage_class;      /* syntax error */
+       funcname(3);
+       typedef (type_def) new_type;
+       struct (keyword_struct_union_enum);     /* syntax error */
+}
+#indent end
+
 /* See t_errors.sh, test case 'compound_literal'. */
diff -r fd73518cc522 -r 68e37d89d585 tests/usr.bin/indent/lsym_rbrace.c
--- a/tests/usr.bin/indent/lsym_rbrace.c        Sun Apr 24 07:11:31 2022 +0000
+++ b/tests/usr.bin/indent/lsym_rbrace.c        Sun Apr 24 08:48:17 2022 +0000
@@ -1,15 +1,77 @@
-/* $NetBSD: lsym_rbrace.c,v 1.2 2022/04/22 21:21:20 rillig Exp $ */
+/* $NetBSD: lsym_rbrace.c,v 1.3 2022/04/24 08:48:17 rillig Exp $ */
 
 /*
- * Tests for the token lsym_rbrace, which represents '}', the counterpart to
- * '{'.
+ * Tests for the token lsym_rbrace, which represents a '}' in these contexts:
+ *
+ * In an initializer, '}' ends an inner group of initializers, usually to
+ * initialize a nested struct, union or array.
+ *
+ * In a function body, '}' ends a block.
+ *
+ * In an expression like '(type){...}', '}' ends a compound literal, which is
+ * typically used in an assignment to a struct or array.
+ *
+ * In macro arguments, a '}' is an ordinary character, it does not need to be
+ * balanced.  This is in contrast to '(' and ')', which must be balanced.
+ *
+ * TODO: try to split this token into lsym_rbrace_block and lsym_rbrace_init.



Home | Main Index | Thread Index | Old Index