summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorrillig <rillig@NetBSD.org>2021-11-28 16:20:13 +0000
committerrillig <rillig@NetBSD.org>2021-11-28 16:20:13 +0000
commit8da3fff4fe9be1c819becb54d1391c719b5dcfd3 (patch)
tree239416bdff34c382b4b6ab364a0382b1f06f1363 /tests
parent56952068922ca60f7a0c4b37d1a627f56abac665 (diff)
tests/indent: migrate token_question to lsym_question and extend it
Diffstat (limited to 'tests')
-rw-r--r--tests/usr.bin/indent/Makefile3
-rw-r--r--tests/usr.bin/indent/lsym_question.c59
-rw-r--r--tests/usr.bin/indent/token_question.c14
3 files changed, 58 insertions, 18 deletions
diff --git a/tests/usr.bin/indent/Makefile b/tests/usr.bin/indent/Makefile
index 04fb221b790..66cc9092fff 100644
--- a/tests/usr.bin/indent/Makefile
+++ b/tests/usr.bin/indent/Makefile
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.38 2021/11/28 16:05:59 rillig Exp $
+# $NetBSD: Makefile,v 1.39 2021/11/28 16:20:13 rillig Exp $
.include <bsd.own.mk>
@@ -133,7 +133,6 @@ FILES+= token_newline.c
FILES+= token_period.c
FILES+= token_postfix_op.c
FILES+= token_preprocessing.c
-FILES+= token_question.c
FILES+= token_rbrace.c
FILES+= token_rparen.c
FILES+= token_semicolon.c
diff --git a/tests/usr.bin/indent/lsym_question.c b/tests/usr.bin/indent/lsym_question.c
index fc71f18e48a..deebaa027c7 100644
--- a/tests/usr.bin/indent/lsym_question.c
+++ b/tests/usr.bin/indent/lsym_question.c
@@ -1,4 +1,4 @@
-/* $NetBSD: lsym_question.c,v 1.1 2021/11/18 21:19:19 rillig Exp $ */
+/* $NetBSD: lsym_question.c,v 1.2 2021/11/28 16:20:13 rillig Exp $ */
/* $FreeBSD$ */
/*
@@ -7,7 +7,62 @@
*/
#indent input
-// TODO: add input
+const char *result = cond ? "then" : "else";
+
+const char *multi = cond1 ? "cond1" : cond2 ? "cond2" : cond3 ? "cond3" : "";
+#indent end
+
+#indent run-equals-input -di0
+
+
+/*
+ * To make them easier to read, conditional expressions can be split into
+ * multiple lines.
+ */
+#indent input
+const char *separate_lines = cond
+ ? "then"
+ : "else";
+#indent end
+
+#indent run -di0
+const char *separate_lines = cond
+// $ XXX: Continuation lines in expressions should be indented, even in column 1.
+? "then"
+: "else";
+#indent end
+
+
+/*
+ * In functions, conditional expressions are indented as intended.
+ */
+#indent input
+void
+function(void)
+{
+ return cond
+ ? "then"
+ : "else";
+}
#indent end
#indent run-equals-input
+
+
+/*
+ * In functions, conditional expressions are indented as intended.
+ */
+#indent input
+void
+function(void)
+{
+ const char *branch = cond
+ // $ TODO: Indent these continuation lines as they are part of the
+ // $ TODO: initializer expression, not of the declarator part to the
+ // $ TODO: left of the '='.
+ ? "then"
+ : "else";
+}
+#indent end
+
+#indent run-equals-input -di0
diff --git a/tests/usr.bin/indent/token_question.c b/tests/usr.bin/indent/token_question.c
deleted file mode 100644
index 5e76f951d53..00000000000
--- a/tests/usr.bin/indent/token_question.c
+++ /dev/null
@@ -1,14 +0,0 @@
-/* $NetBSD: token_question.c,v 1.1 2021/10/18 22:30:34 rillig Exp $ */
-/* $FreeBSD$ */
-
-/*
- * Tests for the '?:' operator.
- */
-
-#indent input
-int var = cond ? 1 : 0;
-
-int multi = cond ? 1 : cond ? 2 : cond ? 3 : 4;
-#indent end
-
-#indent run-equals-input -di0