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 the tok...



details:   https://anonhg.NetBSD.org/src/rev/a099c6958e6c
branches:  trunk
changeset: 365754:a099c6958e6c
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat Apr 23 09:59:13 2022 +0000

description:
tests/indent: migrate tests for the tokens '{' and '.'

diffstat:

 distrib/sets/lists/tests/mi         |   6 +-
 tests/usr.bin/indent/Makefile       |   4 +-
 tests/usr.bin/indent/lsym_lbrace.c  |  57 +++++++++++++++++++++++++++++++++++-
 tests/usr.bin/indent/lsym_period.c  |  51 ++++++++++++++++++++++++++++++--
 tests/usr.bin/indent/token_lbrace.c |  25 ----------------
 tests/usr.bin/indent/token_period.c |  23 --------------
 6 files changed, 106 insertions(+), 60 deletions(-)

diffs (243 lines):

diff -r 86b3d30bbdb1 -r a099c6958e6c distrib/sets/lists/tests/mi
--- a/distrib/sets/lists/tests/mi       Sat Apr 23 09:35:26 2022 +0000
+++ b/distrib/sets/lists/tests/mi       Sat Apr 23 09:59:13 2022 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.1195 2022/04/23 09:01:03 rillig Exp $
+# $NetBSD: mi,v 1.1196 2022/04/23 09:59:13 rillig Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -5273,10 +5273,10 @@
 ./usr/tests/usr.bin/indent/token_keyword_else.c                                tests-usr.bin-tests     compattestfile,atf
 ./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-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_newline.c                             tests-usr.bin-tests     compattestfile,atf
-./usr/tests/usr.bin/indent/token_period.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
diff -r 86b3d30bbdb1 -r a099c6958e6c tests/usr.bin/indent/Makefile
--- a/tests/usr.bin/indent/Makefile     Sat Apr 23 09:35:26 2022 +0000
+++ b/tests/usr.bin/indent/Makefile     Sat Apr 23 09:59:13 2022 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: Makefile,v 1.41 2022/04/23 09:01:03 rillig Exp $
+#      $NetBSD: Makefile,v 1.42 2022/04/23 09:59:14 rillig Exp $
 
 .include <bsd.own.mk>
 
@@ -124,10 +124,8 @@
 FILES+=                token_keyword_else.c
 FILES+=                token_keyword_for_if_while.c
 FILES+=                token_keyword_struct_union_enum.c
-FILES+=                token_lbrace.c
 FILES+=                token_lparen.c
 FILES+=                token_newline.c
-FILES+=                token_period.c
 FILES+=                token_postfix_op.c
 FILES+=                token_preprocessing.c
 FILES+=                token_rbrace.c
diff -r 86b3d30bbdb1 -r a099c6958e6c tests/usr.bin/indent/lsym_lbrace.c
--- a/tests/usr.bin/indent/lsym_lbrace.c        Sat Apr 23 09:35:26 2022 +0000
+++ b/tests/usr.bin/indent/lsym_lbrace.c        Sat Apr 23 09:59:13 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lsym_lbrace.c,v 1.4 2022/04/22 21:21:20 rillig Exp $ */
+/* $NetBSD: lsym_lbrace.c,v 1.5 2022/04/23 09:59:14 rillig Exp $ */
 
 /*
  * Tests for the token lsym_lbrace, which represents a '{' in these contexts:
@@ -11,11 +11,64 @@
  * In an expression, '(type){' starts a compound literal that 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 '(', which must be balanced with ')'.
+ *
  * TODO: try to split this token into lsym_lbrace_block and lsym_lbrace_init.
  */
 
+/* Brace level in an initializer */
 #indent input
-// TODO: add input
+void
+function(void)
+{
+       struct person   p = {
+               .name = "Name",
+               .age = {{{35}}},        /* C11 6.7.9 allows this. */
+       };
+}
 #indent end
 
 #indent run-equals-input
+
+
+/* Begin of a block of statements */
+#indent input
+void function(void) {{{ body(); }}}
+#indent end
+
+#indent run
+void
+function(void)
+/* $ FIXME: Each '{' must be properly indented. */
+{{{
+                       body();
+}
+}
+}
+#indent end
+
+
+/* Compound literal */
+#indent input
+struct point
+origin(void)
+{
+       return (struct point){
+               .x = 0,
+               .y = 0,
+       };
+}
+#indent end
+
+#indent run
+struct point
+origin(void)
+{
+       return (struct point){
+               .x = 0,
+/* $ FIXME: All initializers must be indented to the same level. */
+                       .y = 0,
+       };
+}
+#indent end
diff -r 86b3d30bbdb1 -r a099c6958e6c tests/usr.bin/indent/lsym_period.c
--- a/tests/usr.bin/indent/lsym_period.c        Sat Apr 23 09:35:26 2022 +0000
+++ b/tests/usr.bin/indent/lsym_period.c        Sat Apr 23 09:59:13 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lsym_period.c,v 1.2 2022/04/22 21:21:20 rillig Exp $ */
+/* $NetBSD: lsym_period.c,v 1.3 2022/04/23 09:59:14 rillig Exp $ */
 
 /*
  * Tests for the token lsym_period, which represents '.' in these contexts:
@@ -9,14 +9,57 @@
  * or union 'sou'.
  *
  * In a function prototype declaration, the sequence '.' '.' '.' marks the
- * start of a variable number of arguments.
+ * start of a variable number of arguments.  It would have been more intuitive
+ * to model them as a single token, but it doesn't make any difference for
+ * formatting the code.
  *
  * See also:
  *     lsym_word.c             for '.' inside numeric constants
  */
 
+/* Designators in an initialization */
 #indent input
-// TODO: add input
+struct point {
+       int x;
+       int y;
+} p = {
+       .x = 3,
+       .y = 4,
+};
+#indent end
+
+#indent run-equals-input -di0
+
+
+/* Accessing struct members */
+#indent input
+time_t
+get_time(struct stat st)
+{
+       return st.st_mtime > 0 ? st . st_atime : st.st_ctime;
+}
 #indent end
 
-#indent run-equals-input
+#indent run
+time_t
+/* $ FIXME: The '{' must be in the next line. */
+get_time(struct stat st){
+       return st.st_mtime > 0 ? st.st_atime : st.st_ctime;
+}
+#indent end
+
+#indent run -Ttime_t
+time_t
+get_time(struct stat st)
+{
+       return st.st_mtime > 0 ? st.st_atime : st.st_ctime;
+}
+#indent end
+
+
+/* Varargs in a function declaration */
+#indent input
+void my_printf(const char *, ...);
+#indent end
+
+#indent run-equals-input -di0
diff -r 86b3d30bbdb1 -r a099c6958e6c tests/usr.bin/indent/token_lbrace.c
--- a/tests/usr.bin/indent/token_lbrace.c       Sat Apr 23 09:35:26 2022 +0000
+++ /dev/null   Thu Jan 01 00:00:00 1970 +0000
@@ -1,25 +0,0 @@
-/* $NetBSD: token_lbrace.c,v 1.2 2022/04/22 21:21:20 rillig Exp $ */
-
-/*
- * Tests for the token '{'.
- *
- * It is used as the start marker of a block of statements.
- *
- * It is used in initializers.
- *
- * In macro arguments, a '{' is an ordinary character, it does not need to be
- * balanced.  This is in contrast to '(', which must be balanced with ')'.
- */
-
-#indent input
-void
-function(void)
-{
-       struct person   p = {
-               .name = "Name",
-               .age = {{{35}}},        /* C11 6.7.9 allows this. */
-       };
-}
-#indent end
-
-#indent run-equals-input
diff -r 86b3d30bbdb1 -r a099c6958e6c tests/usr.bin/indent/token_period.c
--- a/tests/usr.bin/indent/token_period.c       Sat Apr 23 09:35:26 2022 +0000
+++ /dev/null   Thu Jan 01 00:00:00 1970 +0000
@@ -1,23 +0,0 @@
-/* $NetBSD: token_period.c,v 1.3 2022/04/22 21:21:20 rillig Exp $ */
-
-/*
- * The ellipsis for the function parameter is a sequence of three '.' tokens.
- * It would have been more intuitive to model them as a single token, but it
- * doesn't make any difference for formatting the code.
- */
-#indent input
-void my_printf(const char *, ...);
-#indent end
-
-#indent run-equals-input -di0
-
-
-#indent input
-int var = str.member;
-int var = str . member;
-#indent end
-
-#indent run -di0
-int var = str.member;
-int var = str.member;
-#indent end



Home | Main Index | Thread Index | Old Index