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 a few token tests...
details: https://anonhg.NetBSD.org/src/rev/b577ff125428
branches: trunk
changeset: 365752:b577ff125428
user: rillig <rillig%NetBSD.org@localhost>
date: Sat Apr 23 09:01:03 2022 +0000
description:
tests/indent: migrate a few token tests to psym tests
diffstat:
distrib/sets/lists/tests/mi | 8 +-
tests/usr.bin/indent/Makefile | 5 +-
tests/usr.bin/indent/psym_if_expr.c | 15 +++-
tests/usr.bin/indent/psym_if_expr_stmt.c | 21 ++++-
tests/usr.bin/indent/psym_if_expr_stmt_else.c | 93 ++++++++++++++++++++++++-
tests/usr.bin/indent/token_if_expr.c | 20 -----
tests/usr.bin/indent/token_if_expr_stmt.c | 25 ------
tests/usr.bin/indent/token_if_expr_stmt_else.c | 21 -----
8 files changed, 121 insertions(+), 87 deletions(-)
diffs (288 lines):
diff -r dfc013303734 -r b577ff125428 distrib/sets/lists/tests/mi
--- a/distrib/sets/lists/tests/mi Sat Apr 23 07:55:07 2022 +0000
+++ b/distrib/sets/lists/tests/mi Sat Apr 23 09:01:03 2022 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.1194 2022/04/20 07:41:04 blymn Exp $
+# $NetBSD: mi,v 1.1195 2022/04/23 09:01:03 rillig Exp $
#
# Note: don't delete entries from here - mark them as "obsolete" instead.
#
@@ -5265,9 +5265,9 @@
./usr/tests/usr.bin/indent/token_form_feed.c tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/indent/token_funcname.c tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/indent/token_ident.c tests-usr.bin-tests compattestfile,atf
-./usr/tests/usr.bin/indent/token_if_expr.c tests-usr.bin-tests compattestfile,atf
-./usr/tests/usr.bin/indent/token_if_expr_stmt.c tests-usr.bin-tests compattestfile,atf
-./usr/tests/usr.bin/indent/token_if_expr_stmt_else.c tests-usr.bin-tests compattestfile,atf
+./usr/tests/usr.bin/indent/token_if_expr.c tests-obsolete obsolete,atf
+./usr/tests/usr.bin/indent/token_if_expr_stmt.c tests-obsolete obsolete,atf
+./usr/tests/usr.bin/indent/token_if_expr_stmt_else.c tests-obsolete obsolete,atf
./usr/tests/usr.bin/indent/token_keyword_do.c tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/indent/token_keyword_do_else.c tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/indent/token_keyword_else.c tests-usr.bin-tests compattestfile,atf
diff -r dfc013303734 -r b577ff125428 tests/usr.bin/indent/Makefile
--- a/tests/usr.bin/indent/Makefile Sat Apr 23 07:55:07 2022 +0000
+++ b/tests/usr.bin/indent/Makefile Sat Apr 23 09:01:03 2022 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.40 2022/04/22 21:21:20 rillig Exp $
+# $NetBSD: Makefile,v 1.41 2022/04/23 09:01:03 rillig Exp $
.include <bsd.own.mk>
@@ -119,9 +119,6 @@
FILES+= token_form_feed.c
FILES+= token_funcname.c
FILES+= token_ident.c
-FILES+= token_if_expr.c
-FILES+= token_if_expr_stmt.c
-FILES+= token_if_expr_stmt_else.c
FILES+= token_keyword_do.c
FILES+= token_keyword_do_else.c
FILES+= token_keyword_else.c
diff -r dfc013303734 -r b577ff125428 tests/usr.bin/indent/psym_if_expr.c
--- a/tests/usr.bin/indent/psym_if_expr.c Sat Apr 23 07:55:07 2022 +0000
+++ b/tests/usr.bin/indent/psym_if_expr.c Sat Apr 23 09:01:03 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: psym_if_expr.c,v 1.2 2022/04/22 21:21:20 rillig Exp $ */
+/* $NetBSD: psym_if_expr.c,v 1.3 2022/04/23 09:01:03 rillig Exp $ */
/*
* Tests for the parser symbol psym_if_expr, representing the parser state
@@ -7,7 +7,16 @@
*/
#indent input
-// TODO: add input
+void function(void) {
+ if(cond) stmt();
+}
#indent end
-#indent run-equals-input
+#indent run
+void
+function(void)
+{
+ if (cond)
+ stmt();
+}
+#indent end
diff -r dfc013303734 -r b577ff125428 tests/usr.bin/indent/psym_if_expr_stmt.c
--- a/tests/usr.bin/indent/psym_if_expr_stmt.c Sat Apr 23 07:55:07 2022 +0000
+++ b/tests/usr.bin/indent/psym_if_expr_stmt.c Sat Apr 23 09:01:03 2022 +0000
@@ -1,14 +1,27 @@
-/* $NetBSD: psym_if_expr_stmt.c,v 1.2 2022/04/22 21:21:20 rillig Exp $ */
+/* $NetBSD: psym_if_expr_stmt.c,v 1.3 2022/04/23 09:01:03 rillig Exp $ */
/*
* Tests for the parser symbol psym_if_expr_stmt, which represents the state
* after reading the keyword 'if', the controlling expression and the
- * statement for the 'then' branch. If the next token is 'else', another
- * statement will follow, otherwise the 'if' statement is finished already.
+ * statement for the 'then' branch.
+ *
+ * At this point, the 'if' statement is not necessarily complete, it can be
+ * completed with the keyword 'else' followed by a statement.
+ *
+ * Any token other than 'else' completes the 'if' statement.
*/
#indent input
-// TODO: add input
+void
+function(void)
+{
+ if (cond)
+ stmt();
+ if (cond)
+ stmt();
+ else /* belongs to the second 'if' */
+ stmt();
+}
#indent end
#indent run-equals-input
diff -r dfc013303734 -r b577ff125428 tests/usr.bin/indent/psym_if_expr_stmt_else.c
--- a/tests/usr.bin/indent/psym_if_expr_stmt_else.c Sat Apr 23 07:55:07 2022 +0000
+++ b/tests/usr.bin/indent/psym_if_expr_stmt_else.c Sat Apr 23 09:01:03 2022 +0000
@@ -1,15 +1,96 @@
-/* $NetBSD: psym_if_expr_stmt_else.c,v 1.2 2022/04/22 21:21:20 rillig Exp $ */
+/* $NetBSD: psym_if_expr_stmt_else.c,v 1.3 2022/04/23 09:01:03 rillig Exp $ */
/*
* Tests for the parser symbol psym_if_expr_stmt_else, which represents the
* parser state after reading the keyword 'if', the controlling expression,
- * the statement of the 'then' branch and the keyword 'else'. If the next
- * token is an 'if', the formatting depends on the option '-ei' or '-nei'. In
- * all other situations, the next statement will finish the 'if' statement.
+ * the statement of the 'then' branch and the keyword 'else'.
+ *
+ * If the next token is an 'if', the formatting depends on the option '-ei' or
+ * '-nei'. Any other lookahead token completes the 'if' statement.
*/
#indent input
-// TODO: add input
+void
+example(_Bool cond)
+{
+ if (cond) {}
+ else if (cond) {}
+ else if (cond) i++;
+ else {}
+}
+#indent end
+
+#indent run
+void
+example(_Bool cond)
+{
+ if (cond) {
+ } else if (cond) {
+ } else if (cond)
+ i++;
+ else {
+ }
+}
#indent end
-#indent run-equals-input
+/*
+ * Combining the options '-bl' (place brace on the left margin) and '-ce'
+ * (cuddle else) looks strange, but is technically correct.
+ */
+#indent run -bl
+void
+example(_Bool cond)
+{
+ if (cond)
+ {
+ } else if (cond)
+ {
+ } else if (cond)
+ i++;
+ else
+ {
+ }
+}
+#indent end
+
+#indent run -bl -nce
+void
+example(_Bool cond)
+{
+ if (cond)
+ {
+ }
+ else if (cond)
+ {
+ }
+ else if (cond)
+ i++;
+ else
+ {
+ }
+}
+#indent end
+
+/*
+ * Adding the option '-nei' (do not join 'else if') expands the code even
+ * more.
+ */
+#indent run -bl -nce -nei
+void
+example(_Bool cond)
+{
+ if (cond)
+ {
+ }
+ else
+ if (cond)
+ {
+ }
+ else
+ if (cond)
+ i++;
+ else
+ {
+ }
+}
+#indent end
diff -r dfc013303734 -r b577ff125428 tests/usr.bin/indent/token_if_expr.c
--- a/tests/usr.bin/indent/token_if_expr.c Sat Apr 23 07:55:07 2022 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,20 +0,0 @@
-/* $NetBSD: token_if_expr.c,v 1.2 2022/04/22 21:21:20 rillig Exp $ */
-
-/*
- * Tests for 'if' followed by a parenthesized expression.
- */
-
-#indent input
-void function(void) {
- if(cond) stmt();
-}
-#indent end
-
-#indent run
-void
-function(void)
-{
- if (cond)
- stmt();
-}
-#indent end
diff -r dfc013303734 -r b577ff125428 tests/usr.bin/indent/token_if_expr_stmt.c
--- a/tests/usr.bin/indent/token_if_expr_stmt.c Sat Apr 23 07:55:07 2022 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,25 +0,0 @@
-/* $NetBSD: token_if_expr_stmt.c,v 1.2 2022/04/22 21:21:20 rillig Exp $ */
-
-/*
- * Tests for 'if' followed by a parenthesized expression and a statement.
- *
- * At this point, the 'if' statement is not necessarily complete, it can be
- * completed with the keyword 'else' followed by a statement.
- *
- * Any token other than 'else' completes the 'if' statement.
- */
-
-#indent input
-void
-function(void)
-{
- if (cond)
- stmt();
- if (cond)
- stmt();
- else /* belongs to the second 'if' */
- stmt();
-}
-#indent end
-
-#indent run-equals-input
diff -r dfc013303734 -r b577ff125428 tests/usr.bin/indent/token_if_expr_stmt_else.c
--- a/tests/usr.bin/indent/token_if_expr_stmt_else.c Sat Apr 23 07:55:07 2022 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,21 +0,0 @@
-/* $NetBSD: token_if_expr_stmt_else.c,v 1.2 2022/04/22 21:21:20 rillig Exp $ */
-
-/*
- * Tests for 'if' followed by a parenthesized expression, a statement and the
- * keyword 'else'.
- *
- * At this point, the statement needs to be completed with another statement.
- */
-
-#indent input
-void
-function(void)
-{
- if (cond)
- stmt();
- else
- stmt();
-}
-#indent end
-
-#indent run-equals-input
Home |
Main Index |
Thread Index |
Old Index