Module Name:    src
Committed By:   rillig
Date:           Sun Nov  7 08:03:15 UTC 2021

Modified Files:
        src/tests/usr.bin/indent: opt_eei.c

Log Message:
tests/indent: demonstrate buggy combination of '-eei' and '-nlp'

Seen in indent.c.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/tests/usr.bin/indent/opt_eei.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/usr.bin/indent/opt_eei.c
diff -u src/tests/usr.bin/indent/opt_eei.c:1.4 src/tests/usr.bin/indent/opt_eei.c:1.5
--- src/tests/usr.bin/indent/opt_eei.c:1.4	Mon Oct 18 07:11:31 2021
+++ src/tests/usr.bin/indent/opt_eei.c	Sun Nov  7 08:03:15 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: opt_eei.c,v 1.4 2021/10/18 07:11:31 rillig Exp $ */
+/* $NetBSD: opt_eei.c,v 1.5 2021/11/07 08:03:15 rillig Exp $ */
 /* $FreeBSD$ */
 
 /*
@@ -79,3 +79,78 @@ less(int a, int b)
 	return true;
 }
 #indent end
+
+/*
+ * With an indentation size of 4, the width of the code 'if (' is exactly one
+ * indentation level. With the option '-nlp', the option '-eei' has no effect.
+ *
+ * XXX: This is unexpected since this creates the exact ambiguity that the
+ * option '-eei' is supposed to prevent.
+ */
+#indent run -eei -i4 -nlp
+bool
+less(int a, int b)
+{
+    if (a <
+	b)
+	return true;
+    if (a
+	<
+	b)
+	return true;
+}
+#indent end
+
+
+/*
+ * The option '-eei' applies no matter whether the continued expression starts
+ * with a word or an operator like '&&'. The latter cannot start a statement,
+ * so there would be no ambiguity.
+ */
+#indent input
+{
+	if (a
+&& b)
+	    stmt();
+}
+#indent end
+
+/*
+ * XXX: The extra indentation is unnecessary since there is no possible
+ * confusion: the standard indentation is 8, the indentation of the continued
+ * condition could have stayed at 4.
+ */
+#indent run -eei
+{
+	if (a
+			&& b)
+		stmt();
+}
+#indent end
+
+/*
+ * The extra indentation is necessary here since otherwise the '&&' and the
+ * 'stmt()' would start at the same indentation.
+ */
+#indent run -eei -i4
+{
+    if (a
+	    && b)
+	stmt();
+}
+#indent end
+
+/*
+ * With an indentation size of 4, the width of the code 'if (' is exactly one
+ * indentation level. With the option '-nlp', the option '-eei' has no effect.
+ *
+ * XXX: This is unexpected since this creates the exact ambiguity that the
+ * option '-eei' is supposed to prevent.
+ */
+#indent run -eei -i4 -nlp
+{
+    if (a
+	&& b)
+	stmt();
+}
+#indent end

Reply via email to