Module Name: src
Committed By: rillig
Date: Sat Apr 23 09:59:14 UTC 2022
Modified Files:
src/distrib/sets/lists/tests: mi
src/tests/usr.bin/indent: Makefile lsym_lbrace.c lsym_period.c
Removed Files:
src/tests/usr.bin/indent: token_lbrace.c token_period.c
Log Message:
tests/indent: migrate tests for the tokens '{' and '.'
To generate a diff of this commit:
cvs rdiff -u -r1.1195 -r1.1196 src/distrib/sets/lists/tests/mi
cvs rdiff -u -r1.41 -r1.42 src/tests/usr.bin/indent/Makefile
cvs rdiff -u -r1.4 -r1.5 src/tests/usr.bin/indent/lsym_lbrace.c
cvs rdiff -u -r1.2 -r1.3 src/tests/usr.bin/indent/lsym_period.c
cvs rdiff -u -r1.2 -r0 src/tests/usr.bin/indent/token_lbrace.c
cvs rdiff -u -r1.3 -r0 src/tests/usr.bin/indent/token_period.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.1195 src/distrib/sets/lists/tests/mi:1.1196
--- src/distrib/sets/lists/tests/mi:1.1195 Sat Apr 23 09:01:03 2022
+++ src/distrib/sets/lists/tests/mi Sat Apr 23 09:59:13 2022
@@ -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
Index: src/tests/usr.bin/indent/Makefile
diff -u src/tests/usr.bin/indent/Makefile:1.41 src/tests/usr.bin/indent/Makefile:1.42
--- src/tests/usr.bin/indent/Makefile:1.41 Sat Apr 23 09:01:03 2022
+++ src/tests/usr.bin/indent/Makefile Sat Apr 23 09:59:14 2022
@@ -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_do_else.c
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
Index: src/tests/usr.bin/indent/lsym_lbrace.c
diff -u src/tests/usr.bin/indent/lsym_lbrace.c:1.4 src/tests/usr.bin/indent/lsym_lbrace.c:1.5
--- src/tests/usr.bin/indent/lsym_lbrace.c:1.4 Fri Apr 22 21:21:20 2022
+++ src/tests/usr.bin/indent/lsym_lbrace.c Sat Apr 23 09:59:14 2022
@@ -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
Index: src/tests/usr.bin/indent/lsym_period.c
diff -u src/tests/usr.bin/indent/lsym_period.c:1.2 src/tests/usr.bin/indent/lsym_period.c:1.3
--- src/tests/usr.bin/indent/lsym_period.c:1.2 Fri Apr 22 21:21:20 2022
+++ src/tests/usr.bin/indent/lsym_period.c Sat Apr 23 09:59:14 2022
@@ -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
+#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
+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