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: explain, clean up and add...



details:   https://anonhg.NetBSD.org/src/rev/d59e0defa4ef
branches:  trunk
changeset: 374789:d59e0defa4ef
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat May 13 06:52:48 2023 +0000

description:
tests/indent: explain, clean up and add some tests

diffstat:

 tests/usr.bin/indent/fmt_block.c      |   6 +++-
 tests/usr.bin/indent/fmt_decl.c       |  48 +++++++++-------------------------
 tests/usr.bin/indent/lsym_binary_op.c |  13 ++++++++-
 tests/usr.bin/indent/lsym_comma.c     |   4 +--
 tests/usr.bin/indent/lsym_comment.c   |   4 +-
 tests/usr.bin/indent/lsym_do.c        |  39 +++++++++++++++++++++++++++-
 tests/usr.bin/indent/lsym_unary_op.c  |  25 +++++++++++++++++-
 tests/usr.bin/indent/lsym_while.c     |  25 +++++++++++++++++-
 tests/usr.bin/indent/t_misc.sh        |   4 +-
 9 files changed, 121 insertions(+), 47 deletions(-)

diffs (truncated from 311 to 300 lines):

diff -r 4ba086fe710e -r d59e0defa4ef tests/usr.bin/indent/fmt_block.c
--- a/tests/usr.bin/indent/fmt_block.c  Sat May 13 06:36:33 2023 +0000
+++ b/tests/usr.bin/indent/fmt_block.c  Sat May 13 06:52:48 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: fmt_block.c,v 1.5 2023/05/11 09:28:53 rillig Exp $ */
+/* $NetBSD: fmt_block.c,v 1.6 2023/05/13 06:52:48 rillig Exp $ */
 
 /*
  * Tests for formatting blocks of statements and declarations.
@@ -23,6 +23,10 @@ function(void)
 }
 //indent end
 
+/*
+ * Before 2023-05-11, indent incorrectly merged the '} {' into a single line,
+ * even though they are completely unrelated.
+ */
 //indent run-equals-input
 
 
diff -r 4ba086fe710e -r d59e0defa4ef tests/usr.bin/indent/fmt_decl.c
--- a/tests/usr.bin/indent/fmt_decl.c   Sat May 13 06:36:33 2023 +0000
+++ b/tests/usr.bin/indent/fmt_decl.c   Sat May 13 06:52:48 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: fmt_decl.c,v 1.37 2023/05/11 09:28:53 rillig Exp $     */
+/*     $NetBSD: fmt_decl.c,v 1.38 2023/05/13 06:52:48 rillig Exp $     */
 
 /*
  * Tests for declarations of global variables, external functions, and local
@@ -88,38 +88,8 @@ typedef struct Complex
 
 
 /*
- * As of 2021-11-07, indent parses the following function definition as these
- * tokens:
- *
- * line 1: type_outside_parentheses "void"
- * line 1: newline "\n"
- * line 2: funcname "t1"
- * line 2: newline "\n"                repeated, see search_stmt
- * line 3: funcname "t1"       XXX: wrong line_no
- * line 3: lparen_or_lbracket "("
- * line 3: type_in_parentheses "char"
- * line 3: unary_op "*"
- * line 3: word "a"
- * line 3: comma ","
- * line 3: type_in_parentheses "int"
- * line 3: word "b"
- * line 3: comma ","
- * line 3: newline "\n"
- * line 4: type_in_parentheses "void"
- * line 4: lparen_or_lbracket "("
- * line 4: unary_op "*"
- * line 4: word "fn"
- * line 4: rparen_or_rbracket ")"
- * line 4: lparen_or_lbracket "("
- * line 4: type_in_parentheses "void"
- * line 4: rparen_or_rbracket ")"
- * line 4: rparen_or_rbracket ")"
- * line 4: newline "\n"
- * line 5: lbrace "{"
- * line 5: lbrace "{"          repeated, see search_stmt
- * line 5: newline "\n"                FIXME: there is no newline in the source
- * line 6: rbrace "}"
- * line 6: eof "\n"
+ * Ensure that function definitions are reasonably indented.  Before
+ * 2023-05-11, tokens were repeatedly read, and the line numbers were wrong.
  */
 //indent input
 void
@@ -527,7 +497,10 @@ function_name_____20________30________40
 {}
 //indent end
 
-/* FIXME: The space between '){' is missing. */
+/*
+ * Before 2023-05-11, indent moved the '{' right after the '(void)', without
+ * any space in between.
+ */
 //indent run
 int           *function_name_____20________30________40________50
                (void)
@@ -547,6 +520,10 @@ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 {}
 //indent end
 
+/*
+ * Before 2023-05-11, indent moved the '{' right after the '(void)', without
+ * any space in between.
+ */
 //indent run
 int           *aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
                (void)
@@ -607,7 +584,8 @@ buffer_add(buffer *buf, char ch)
 
 
 /*
- * Indent gets easily confused by type names it does not know about.
+ * Before lexi.c 1.153 from 2021-11-25, indent did not recognize 'Token' as a
+ * type name and then messed up the positioning of the '{'.
  */
 //indent input
 static Token
diff -r 4ba086fe710e -r d59e0defa4ef tests/usr.bin/indent/lsym_binary_op.c
--- a/tests/usr.bin/indent/lsym_binary_op.c     Sat May 13 06:36:33 2023 +0000
+++ b/tests/usr.bin/indent/lsym_binary_op.c     Sat May 13 06:52:48 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lsym_binary_op.c,v 1.6 2022/04/24 10:36:37 rillig Exp $ */
+/* $NetBSD: lsym_binary_op.c,v 1.7 2023/05/13 06:52:48 rillig Exp $ */
 
 /*
  * Tests for the token lsym_binary_op, which represents a binary operator in
@@ -160,3 +160,14 @@ int                col_9           //
 =                              //
 9;
 //indent end
+
+
+/*
+ * The ternary conditional operator is not a binary operator, but both its
+ * components '?' and ':' follow the same spacing rules.
+ */
+//indent input
+int conditional = condition ? number : number;
+//indent end
+
+//indent run-equals-input -di0
diff -r 4ba086fe710e -r d59e0defa4ef tests/usr.bin/indent/lsym_comma.c
--- a/tests/usr.bin/indent/lsym_comma.c Sat May 13 06:36:33 2023 +0000
+++ b/tests/usr.bin/indent/lsym_comma.c Sat May 13 06:52:48 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lsym_comma.c,v 1.5 2022/04/24 09:04:12 rillig Exp $ */
+/* $NetBSD: lsym_comma.c,v 1.6 2023/05/13 06:52:48 rillig Exp $ */
 
 /*
  * Tests for the token lsym_comma, which represents a ',' in these contexts:
@@ -150,8 +150,6 @@ function(void)
 
 /*
  * In an initializer list, a ',' separates the initializer expressions.
- *
- * If a ',' starts a line, indent doesn't put a space before it.
  */
 //indent input
 int arr[] = {1, 2, 3};
diff -r 4ba086fe710e -r d59e0defa4ef tests/usr.bin/indent/lsym_comment.c
--- a/tests/usr.bin/indent/lsym_comment.c       Sat May 13 06:36:33 2023 +0000
+++ b/tests/usr.bin/indent/lsym_comment.c       Sat May 13 06:52:48 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lsym_comment.c,v 1.5 2023/05/11 09:28:53 rillig Exp $ */
+/* $NetBSD: lsym_comment.c,v 1.6 2023/05/13 06:52:48 rillig Exp $ */
 
 /*
  * Tests for the token lsym_comment, which starts a comment.
@@ -337,7 +337,7 @@ tab1+++     tab2--- tab3+++ tab4--- tab5+++ 
 }
 //indent end
 
-/* The comment in the output has moved to the right of the '{'. */
+/* Before 2023-05-11, the comment moved to the right of the '{'. */
 //indent run
 {
        if (0) /* comment */ {
diff -r 4ba086fe710e -r d59e0defa4ef tests/usr.bin/indent/lsym_do.c
--- a/tests/usr.bin/indent/lsym_do.c    Sat May 13 06:36:33 2023 +0000
+++ b/tests/usr.bin/indent/lsym_do.c    Sat May 13 06:52:48 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lsym_do.c,v 1.5 2023/05/11 10:39:26 rillig Exp $ */
+/* $NetBSD: lsym_do.c,v 1.6 2023/05/13 06:52:48 rillig Exp $ */
 
 /*
  * Tests for the token lsym_do, which represents the keyword 'do' that starts
@@ -49,3 +49,40 @@ else_do(int i)
                } while (0);
 }
 //indent end
+
+
+//indent input
+void
+variants(void)
+{
+       do stmt(); while (0);
+
+       do { stmt(); } while (0);
+
+       do /* comment */ stmt(); while (0);
+
+       while (0) do {} while (0);
+}
+//indent end
+
+//indent run
+void
+variants(void)
+{
+       do
+               stmt();
+       while (0);
+
+       do {
+               stmt();
+       } while (0);
+
+       do                      /* comment */
+               stmt();
+       while (0);
+
+       while (0)
+               do {
+               } while (0);
+}
+//indent end
diff -r 4ba086fe710e -r d59e0defa4ef tests/usr.bin/indent/lsym_unary_op.c
--- a/tests/usr.bin/indent/lsym_unary_op.c      Sat May 13 06:36:33 2023 +0000
+++ b/tests/usr.bin/indent/lsym_unary_op.c      Sat May 13 06:52:48 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lsym_unary_op.c,v 1.5 2022/04/24 10:36:37 rillig Exp $ */
+/* $NetBSD: lsym_unary_op.c,v 1.6 2023/05/13 06:52:48 rillig Exp $ */
 
 /*
  * Tests for the token lsym_unary_op, which represents a unary operator.
@@ -8,6 +8,12 @@
  *
  * In a type name, the "unary operator" '*' represents the derivation of a
  * pointer type.
+ *
+ * See also:
+ *     lsym_binary_op.c
+ *     lsym_postfix_op.c
+ *     C11 6.4.6 "Punctuators"
+ *     C11 6.5 "Expressions"
  */
 
 //indent input
@@ -54,3 +60,20 @@ int var = p -> member;
 //indent run -di0
 int var = p->member;
 //indent end
+
+
+//indent input
+void
+unary_operators(void)
+{
+       ++prefix_increment;
+       --prefix_decrement;
+       int *address = &lvalue;
+       int dereferenced = *address;
+       int positive = +number;
+       int negative = -number;
+       bool negated = !condition;
+}
+//indent end
+
+//indent run-equals-input -di0
diff -r 4ba086fe710e -r d59e0defa4ef tests/usr.bin/indent/lsym_while.c
--- a/tests/usr.bin/indent/lsym_while.c Sat May 13 06:36:33 2023 +0000
+++ b/tests/usr.bin/indent/lsym_while.c Sat May 13 06:52:48 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lsym_while.c,v 1.4 2022/04/24 10:36:37 rillig Exp $ */
+/* $NetBSD: lsym_while.c,v 1.5 2023/05/13 06:52:48 rillig Exp $ */
 
 /*
  * Tests for the token 'lsym_while', which represents the keyword 'while' that
@@ -25,3 +25,26 @@ function(void)
        while (cond);
 }
 //indent end
+
+
+/*
+ * The keyword 'while' must only be indented if it follows a psym_do_stmt,
+ * otherwise it starts a new statement and must start a new line.
+ */
+//indent input
+void
+function(void)
+{
+       {} while (0);
+}
+//indent end
+
+//indent run
+void
+function(void)
+{
+       {
+/* $ FIXME: The '} while' is misleading. */
+       } while (0);
+}
+//indent end
diff -r 4ba086fe710e -r d59e0defa4ef tests/usr.bin/indent/t_misc.sh
--- a/tests/usr.bin/indent/t_misc.sh    Sat May 13 06:36:33 2023 +0000
+++ b/tests/usr.bin/indent/t_misc.sh    Sat May 13 06:52:48 2023 +0000
@@ -1,5 +1,5 @@
 #! /bin/sh
-# $NetBSD: t_misc.sh,v 1.22 2023/05/12 10:53:33 rillig Exp $
+# $NetBSD: t_misc.sh,v 1.23 2023/05/13 06:52:48 rillig Exp $
 #



Home | Main Index | Thread Index | Old Index