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 test token_case_l...



details:   https://anonhg.NetBSD.org/src/rev/d468a4f14507
branches:  trunk
changeset: 1026551:d468a4f14507
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Nov 28 16:05:59 2021 +0000

description:
tests/indent: migrate test token_case_label to lsym_case_label

diffstat:

 distrib/sets/lists/tests/mi             |   4 +-
 tests/usr.bin/indent/Makefile           |   3 +-
 tests/usr.bin/indent/lsym_case_label.c  |  65 ++++++++++++++++++++++++++++++--
 tests/usr.bin/indent/lsym_colon.c       |   6 ++-
 tests/usr.bin/indent/opt_cli.c          |  27 +++++++++++++-
 tests/usr.bin/indent/token_case_label.c |  47 -----------------------
 6 files changed, 94 insertions(+), 58 deletions(-)

diffs (235 lines):

diff -r fd22b39a978c -r d468a4f14507 distrib/sets/lists/tests/mi
--- a/distrib/sets/lists/tests/mi       Sun Nov 28 15:49:36 2021 +0000
+++ b/distrib/sets/lists/tests/mi       Sun Nov 28 16:05:59 2021 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.1171 2021/11/28 15:26:22 rillig Exp $
+# $NetBSD: mi,v 1.1172 2021/11/28 16:05:59 rillig Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -5243,7 +5243,7 @@
 ./usr/tests/usr.bin/indent/token-while_expr.0.pro                      tests-obsolete          obsolete,atf
 ./usr/tests/usr.bin/indent/token-while_expr.0.stdout                   tests-obsolete          obsolete,atf
 ./usr/tests/usr.bin/indent/token_binary_op.c                           tests-usr.bin-tests     compattestfile,atf
-./usr/tests/usr.bin/indent/token_case_label.c                          tests-usr.bin-tests     compattestfile,atf
+./usr/tests/usr.bin/indent/token_case_label.c                          tests-obsolete          obsolete,atf
 ./usr/tests/usr.bin/indent/token_colon.c                               tests-obsolete          obsolete,atf
 ./usr/tests/usr.bin/indent/token_comma.c                               tests-obsolete          obsolete,atf
 ./usr/tests/usr.bin/indent/token_comment.c                             tests-usr.bin-tests     compattestfile,atf
diff -r fd22b39a978c -r d468a4f14507 tests/usr.bin/indent/Makefile
--- a/tests/usr.bin/indent/Makefile     Sun Nov 28 15:49:36 2021 +0000
+++ b/tests/usr.bin/indent/Makefile     Sun Nov 28 16:05:59 2021 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: Makefile,v 1.37 2021/11/28 15:26:22 rillig Exp $
+#      $NetBSD: Makefile,v 1.38 2021/11/28 16:05:59 rillig Exp $
 
 .include <bsd.own.mk>
 
@@ -111,7 +111,6 @@
 FILES+=                psym_while_expr.c
 FILES+=                t_options.awk
 FILES+=                token_binary_op.c
-FILES+=                token_case_label.c
 FILES+=                token_comment.c
 FILES+=                token_decl.c
 FILES+=                token_do_stmt.c
diff -r fd22b39a978c -r d468a4f14507 tests/usr.bin/indent/lsym_case_label.c
--- a/tests/usr.bin/indent/lsym_case_label.c    Sun Nov 28 15:49:36 2021 +0000
+++ b/tests/usr.bin/indent/lsym_case_label.c    Sun Nov 28 16:05:59 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lsym_case_label.c,v 1.3 2021/11/24 21:34:34 rillig Exp $ */
+/* $NetBSD: lsym_case_label.c,v 1.4 2021/11/28 16:05:59 rillig Exp $ */
 /* $FreeBSD$ */
 
 /*
@@ -14,13 +14,29 @@
  *     C11 6.5.1.1             "Generic selection"
  */
 
-// TODO: test C11 _Generic
-
+/*
+ * A case label can be used in a 'switch' statement.
+ */
 #indent input
-// TODO: add input
+void function(void){switch(expr){case 1:;case 2:break;default:switch(inner){case 4:break;}}}
 #indent end
 
-#indent run-equals-input
+#indent run
+void
+function(void)
+{
+       switch (expr) {
+       case 1: ;
+       case 2:
+               break;
+       default:
+               switch (inner) {
+               case 4:
+                       break;
+               }
+       }
+}
+#indent end
 
 
 /*
@@ -59,3 +75,42 @@
        }
 }
 #indent end
+
+
+/*
+ * Since C11, the _Generic selection expression allows a switch on the data
+ * type of an expression.
+ */
+#indent input
+const char *type_name = _Generic(
+       ' ',
+       int: "character constants have type 'int'",
+       char: "character constants have type 'char'",
+       default: "character constants have some other type"
+);
+#indent end
+
+#indent run -di0
+const char *type_name = _Generic(
+// $ XXX: It's strange to align the arguments at the parenthesis even though
+// $ XXX: the first argument is already on a separate line.
+                                ' ',
+// $ TODO: indent the type names
+int:                            "character constants have type 'int'",
+char:                           "character constants have type 'char'",
+default:
+// $ TODO: remove the newline after 'default:'
+                                "character constants have some other type"
+);
+#indent end
+
+#indent run -di0 -nlp
+const char *type_name = _Generic(
+       ' ',
+// $ TODO: indent the type names
+int:   "character constants have type 'int'",
+char:  "character constants have type 'char'",
+default:
+       "character constants have some other type"
+);
+#indent end
diff -r fd22b39a978c -r d468a4f14507 tests/usr.bin/indent/lsym_colon.c
--- a/tests/usr.bin/indent/lsym_colon.c Sun Nov 28 15:49:36 2021 +0000
+++ b/tests/usr.bin/indent/lsym_colon.c Sun Nov 28 16:05:59 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lsym_colon.c,v 1.2 2021/11/28 14:49:28 rillig Exp $ */
+/* $NetBSD: lsym_colon.c,v 1.3 2021/11/28 16:05:59 rillig Exp $ */
 /* $FreeBSD$ */
 
 /*
@@ -12,8 +12,12 @@
  *
  * In the declaration of a struct member that is a bit-field.
  *
+ * Since C11, in the _Generic selection to separate the type from its
+ * corresponding expression.
+ *
  * See also:
  *     label.c
+ *     lsym_case_label.c       for the C11 _Generic expression
  *     lsym_question.c
  */
 
diff -r fd22b39a978c -r d468a4f14507 tests/usr.bin/indent/opt_cli.c
--- a/tests/usr.bin/indent/opt_cli.c    Sun Nov 28 15:49:36 2021 +0000
+++ b/tests/usr.bin/indent/opt_cli.c    Sun Nov 28 16:05:59 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: opt_cli.c,v 1.2 2021/11/20 16:54:17 rillig Exp $ */
+/* $NetBSD: opt_cli.c,v 1.3 2021/11/28 16:05:59 rillig Exp $ */
 /* $FreeBSD$ */
 
 /*
@@ -24,6 +24,31 @@
 }
 #indent end
 
+#indent run -cli0.5
+void
+classify(int n)
+{
+       switch (n) {
+           case 0:
+               print("zero");
+               break;
+           case 1:
+               print("one");
+               break;
+           case 2:
+           case 3:
+               print("prime");
+               break;
+           case 4:
+               print("square");
+               break;
+           default:
+               print("large");
+               break;
+       }
+}
+#indent end
+
 #indent run -cli1.5
 void
 classify(int n)
diff -r fd22b39a978c -r d468a4f14507 tests/usr.bin/indent/token_case_label.c
--- a/tests/usr.bin/indent/token_case_label.c   Sun Nov 28 15:49:36 2021 +0000
+++ /dev/null   Thu Jan 01 00:00:00 1970 +0000
@@ -1,47 +0,0 @@
-/* $NetBSD: token_case_label.c,v 1.1 2021/10/18 22:30:34 rillig Exp $ */
-/* $FreeBSD$ */
-
-/*
- * Tests for formatting of case labels in switch statements.
- */
-
-#indent input
-void function(void){switch(expr){case 1:;case 2:break;case 3:switch(
-inner){case 4:break;}}}
-#indent end
-
-#indent run
-void
-function(void)
-{
-       switch (expr) {
-       case 1: ;
-       case 2:
-               break;
-       case 3:
-               switch (
-                       inner) {
-               case 4:
-                       break;
-               }
-       }
-}
-#indent end
-
-#indent run -cli0.5
-void
-function(void)
-{
-       switch (expr) {
-           case 1:;
-           case 2:
-               break;
-           case 3:
-               switch (
-                       inner) {
-                   case 4:
-                       break;
-               }
-       }
-}
-#indent end



Home | Main Index | Thread Index | Old Index