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: demonstrate buggy combina...



details:   https://anonhg.NetBSD.org/src/rev/8a9a165efe3a
branches:  trunk
changeset: 1024823:8a9a165efe3a
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Nov 07 08:03:15 2021 +0000

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

Seen in indent.c.

diffstat:

 tests/usr.bin/indent/opt_eei.c |  77 +++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 76 insertions(+), 1 deletions(-)

diffs (88 lines):

diff -r 4b81240c086e -r 8a9a165efe3a tests/usr.bin/indent/opt_eei.c
--- a/tests/usr.bin/indent/opt_eei.c    Sun Nov 07 07:44:59 2021 +0000
+++ b/tests/usr.bin/indent/opt_eei.c    Sun Nov 07 08:03:15 2021 +0000
@@ -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 @@
        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



Home | Main Index | Thread Index | Old Index