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: test extra indentation wi...



details:   https://anonhg.NetBSD.org/src/rev/36235c4ce87f
branches:  trunk
changeset: 375345:36235c4ce87f
user:      rillig <rillig%NetBSD.org@localhost>
date:      Mon May 15 12:11:07 2023 +0000

description:
tests/indent: test extra indentation with fixed continuation indentation

diffstat:

 tests/usr.bin/indent/opt_eei.c |  251 +++++++++++++++++++++-------------------
 1 files changed, 131 insertions(+), 120 deletions(-)

diffs (291 lines):

diff -r 7042d1c659f4 -r 36235c4ce87f tests/usr.bin/indent/opt_eei.c
--- a/tests/usr.bin/indent/opt_eei.c    Mon May 15 10:13:40 2023 +0000
+++ b/tests/usr.bin/indent/opt_eei.c    Mon May 15 12:11:07 2023 +0000
@@ -1,156 +1,167 @@
-/* $NetBSD: opt_eei.c,v 1.8 2022/04/24 09:04:12 rillig Exp $ */
+/* $NetBSD: opt_eei.c,v 1.9 2023/05/15 12:11:07 rillig Exp $ */
 
 /*
  * Tests for the options '-eei' and '-neei'.
  *
  * The option '-eei' enables extra indentation on continuation lines of the
  * expression part of 'if' and 'while' statements. These continuation lines
- * are indented one extra level.
+ * are indented one extra level to avoid being confused for the first
+ * statement of the body, even if the condition line starts with an operator
+ * such as '&&' or '<' that could not start a statement.
  *
  * The option '-neei' indents these conditions in the same way as all other
  * continued statements.
  */
 
 //indent input
-bool
-less(int a, int b)
-{
-       if (a <
-           b)
-               return true;
-       if (a
-           <
-           b)
-               return true;
-}
-//indent end
-
-//indent run -eei
-bool
-less(int a, int b)
 {
        if (a <
-                       b)
-               return true;
+b)
+               stmt();
        if (a
-                       <
-                       b)
-               return true;
-}
-//indent end
-
-//indent run-equals-input -neei
-
-/*
- * When a single indentation level is the same as the continuation
- * indentation, the code does not clearly show whether the 'b' belongs to the
- * condition or the body statement.
- */
-//indent run -neei -i4
-bool
-less(int a, int b)
-{
-    if (a <
-       b)
-       return true;
-    if (a
-       <
-       b)
-       return true;
-}
-//indent end
-
-/*
- * Adding the extra level of indentation is useful when the standard
- * indentation is the same as the indentation of statement continuations. In
- * such a case, the continued condition would have the same indentation as the
- * following statement, which would be confusing.
- */
-//indent run -eei -i4
-bool
-less(int a, int b)
-{
-    if (a <
-           b)
-       return true;
-    if (a
-           <
-           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)
+<
+b)
+               stmt();
+       while (a
+< b)
+               stmt();
+       switch (
+               a)
                stmt();
 }
 //indent end
 
 /*
- * The extra indentation is necessary here since otherwise the '&&' and the
- * 'stmt()' would start at the same indentation.
+ * By default, continuation lines are aligned on parentheses, and only a
+ * multi-line switch statement would have ambiguous indentation.
+ */
+//indent run
+{
+       if (a <
+           b)
+               stmt();
+       if (a
+           <
+           b)
+               stmt();
+       while (a
+              < b)
+               stmt();
+       switch (
+               a)
+               stmt();
+}
+//indent end
+
+//indent run-equals-prev-output -neei
+
+/*
+ * For indentation 8, the only expression that needs to be disambiguated is
+ * the one from the switch statement.
  */
+//indent run -eei
+{
+       if (a <
+/* $ XXX: No extra indentation necessary. */
+                       b)
+               stmt();
+       if (a
+/* $ XXX: No extra indentation necessary. */
+                       <
+/* $ XXX: No extra indentation necessary. */
+                       b)
+               stmt();
+       while (a
+/* $ XXX: No extra indentation necessary. */
+                       < b)
+               stmt();
+       switch (
+                       a)
+               stmt();
+}
+//indent end
+
+/* For indentation 4, the expressions from the 'if' are ambiguous. */
+//indent run -neei -i4
+{
+    if (a <
+       b)
+       stmt();
+    if (a
+       <
+       b)
+       stmt();
+    while (a
+          < b)
+       stmt();
+    switch (
+           a)
+       stmt();
+}
+//indent end
+
 //indent run -eei -i4
 {
+    if (a <
+           b)
+       stmt();
     if (a
-           && b)
+           <
+           b)
+       stmt();
+    while (a
+/* $ XXX: No extra indentation necessary. */
+           < b)
+       stmt();
+    switch (
+/* $ XXX: No extra indentation necessary. */
+           a)
        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.
+ * The -nlp option uses a fixed indentation for continuation lines. The if
+ * statements are disambiguated.
  */
 //indent run -eei -i4 -nlp
 {
+    if (a <
+/* $ FIXME: Needs extra indentation. */
+       b)
+       stmt();
     if (a
-       && b)
+/* $ FIXME: Needs extra indentation. */
+       <
+/* $ FIXME: Needs extra indentation. */
+       b)
+       stmt();
+    while (a
+/* $ FIXME: Needs extra indentation. */
+       < b)
+       stmt();
+    switch (
+/* $ FIXME: Needs extra indentation. */
+       a)
        stmt();
 }
 //indent end
+
+/* With a continuation indentation of 2, there is no ambiguity at all. */
+//indent run -eei -i6 -ci2 -nlp
+{
+      if (a <
+       b)
+           stmt();
+      if (a
+       <
+       b)
+           stmt();
+      while (a
+       < b)
+           stmt();
+      switch (
+       a)
+           stmt();
+}
+//indent end



Home | Main Index | Thread Index | Old Index