Module Name: src
Committed By: rillig
Date: Sun Nov 28 16:05:59 UTC 2021
Modified Files:
src/distrib/sets/lists/tests: mi
src/tests/usr.bin/indent: Makefile lsym_case_label.c lsym_colon.c
opt_cli.c
Removed Files:
src/tests/usr.bin/indent: token_case_label.c
Log Message:
tests/indent: migrate test token_case_label to lsym_case_label
To generate a diff of this commit:
cvs rdiff -u -r1.1171 -r1.1172 src/distrib/sets/lists/tests/mi
cvs rdiff -u -r1.37 -r1.38 src/tests/usr.bin/indent/Makefile
cvs rdiff -u -r1.3 -r1.4 src/tests/usr.bin/indent/lsym_case_label.c
cvs rdiff -u -r1.2 -r1.3 src/tests/usr.bin/indent/lsym_colon.c \
src/tests/usr.bin/indent/opt_cli.c
cvs rdiff -u -r1.1 -r0 src/tests/usr.bin/indent/token_case_label.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/distrib/sets/lists/tests/mi
diff -u src/distrib/sets/lists/tests/mi:1.1171 src/distrib/sets/lists/tests/mi:1.1172
--- src/distrib/sets/lists/tests/mi:1.1171 Sun Nov 28 15:26:22 2021
+++ src/distrib/sets/lists/tests/mi Sun Nov 28 16:05:59 2021
@@ -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
Index: src/tests/usr.bin/indent/Makefile
diff -u src/tests/usr.bin/indent/Makefile:1.37 src/tests/usr.bin/indent/Makefile:1.38
--- src/tests/usr.bin/indent/Makefile:1.37 Sun Nov 28 15:26:22 2021
+++ src/tests/usr.bin/indent/Makefile Sun Nov 28 16:05:59 2021
@@ -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_switch_expr.c
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
Index: src/tests/usr.bin/indent/lsym_case_label.c
diff -u src/tests/usr.bin/indent/lsym_case_label.c:1.3 src/tests/usr.bin/indent/lsym_case_label.c:1.4
--- src/tests/usr.bin/indent/lsym_case_label.c:1.3 Wed Nov 24 21:34:34 2021
+++ src/tests/usr.bin/indent/lsym_case_label.c Sun Nov 28 16:05:59 2021
@@ -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 @@ function(void)
}
}
#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
Index: src/tests/usr.bin/indent/lsym_colon.c
diff -u src/tests/usr.bin/indent/lsym_colon.c:1.2 src/tests/usr.bin/indent/lsym_colon.c:1.3
--- src/tests/usr.bin/indent/lsym_colon.c:1.2 Sun Nov 28 14:49:28 2021
+++ src/tests/usr.bin/indent/lsym_colon.c Sun Nov 28 16:05:59 2021
@@ -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
*/
Index: src/tests/usr.bin/indent/opt_cli.c
diff -u src/tests/usr.bin/indent/opt_cli.c:1.2 src/tests/usr.bin/indent/opt_cli.c:1.3
--- src/tests/usr.bin/indent/opt_cli.c:1.2 Sat Nov 20 16:54:17 2021
+++ src/tests/usr.bin/indent/opt_cli.c Sun Nov 28 16:05:59 2021
@@ -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 @@ classify(int n)
}
#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)