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 option '-ci'



details:   https://anonhg.NetBSD.org/src/rev/01c96e3ea690
branches:  trunk
changeset: 1024746:01c96e3ea690
user:      rillig <rillig%NetBSD.org@localhost>
date:      Mon Nov 01 22:48:56 2021 +0000

description:
tests/indent: test option '-ci'

There are quite a few tricky special cases, but as they are all listed
in the manual page, they are not surprising.

diffstat:

 tests/usr.bin/indent/opt_ci.c |  174 +++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 172 insertions(+), 2 deletions(-)

diffs (194 lines):

diff -r 882d56e6750d -r 01c96e3ea690 tests/usr.bin/indent/opt_ci.c
--- a/tests/usr.bin/indent/opt_ci.c     Mon Nov 01 21:37:32 2021 +0000
+++ b/tests/usr.bin/indent/opt_ci.c     Mon Nov 01 22:48:56 2021 +0000
@@ -1,12 +1,85 @@
-/* $NetBSD: opt_ci.c,v 1.1 2021/10/22 20:54:36 rillig Exp $ */
+/* $NetBSD: opt_ci.c,v 1.2 2021/11/01 22:48:56 rillig Exp $ */
 /* $FreeBSD$ */
 
+/*
+ * Tests for the option '-ci', which controls the indentation of continuation
+ * lines in statements and declarations, but only inside a function.
+ */
+
+/*
+ * Top level expressions with and without parentheses.
+ */
+#indent input
+int top_level = 1 +
+ 2;
+int top_level = (1 +
+ 2 + (
+  3));
+#indent end
+
+#indent run -ci0
+int            top_level = 1 +
+2;
+int            top_level = (1 +
+                            2 + (
+                                 3));
+#indent end
+#indent run-equals-prev-output -ci2
+#indent run-equals-prev-output -ci4
+#indent run-equals-prev-output -ci8
+
+#indent run -ci0 -nlp
+int            top_level = 1 +
+2;
+int            top_level = (1 +
+       2 + (
+               3));
+#indent end
+
+#indent run -ci2 -nlp
+int            top_level = 1 +
+2;
+int            top_level = (1 +
+  2 + (
+    3));
+#indent end
+
+/*
+ * Since '-ci4' is half an indentation level, indent all continuations using
+ * the same level, no matter how many parentheses there are. The rationale for
+ * this may have been to prevent that the continuation line has the same
+ * indentation as a follow-up statement, such as in 'if' statements.
+ */
+#indent run -ci4 -nlp
+int            top_level = 1 +
+2;
+int            top_level = (1 +
+    2 + (
+    3));
+#indent end
+
+/*
+ * Declarations in functions without parentheses.
+ */
 #indent input
 int
 sum(int a, int b)
 {
        return a +
-                       b;
+        b;
+       return first +
+        second;
+}
+#indent end
+
+#indent run -ci0
+int
+sum(int a, int b)
+{
+       return a +
+               b;
+       return first +
+               second;
 }
 #indent end
 
@@ -16,5 +89,102 @@
 {
        return a +
          b;
+       return first +
+         second;
+}
+#indent end
+
+#indent run -ci4
+int
+sum(int a, int b)
+{
+       return a +
+           b;
+       return first +
+           second;
+}
+#indent end
+
+#indent run -ci8
+int
+sum(int a, int b)
+{
+       return a +
+               b;
+       return first +
+               second;
+}
+#indent end
+
+
+/*
+ * Continued statements with expressions in parentheses.
+ */
+#indent input
+int
+sum(int a, int b)
+{
+       return (a +
+       b);
+       return (first +
+       second + (
+       third));
 }
 #indent end
+
+#indent run -ci0
+int
+sum(int a, int b)
+{
+       return(a +
+              b);
+       return(first +
+              second + (
+                        third));
+}
+#indent end
+#indent run-equals-prev-output -ci2
+#indent run-equals-prev-output -ci4
+#indent run-equals-prev-output -ci8
+
+#indent run -ci2 -nlp
+int
+sum(int a, int b)
+{
+       return(a +
+         b);
+       return(first +
+         second + (
+           third));
+}
+#indent end
+
+/*
+ * Since '-ci4' is half an indentation level, indent all continuations using
+ * the same level, no matter how many parentheses there are. The rationale for
+ * this may have been to prevent that the continuation line has the same
+ * indentation as a follow-up statement, such as in 'if' statements.
+ */
+#indent run -ci4 -nlp
+int
+sum(int a, int b)
+{
+       return(a +
+           b);
+       return(first +
+           second + (
+           third));
+}
+#indent end
+
+#indent run -ci8 -nlp
+int
+sum(int a, int b)
+{
+       return(a +
+               b);
+       return(first +
+               second + (
+                       third));
+}
+#indent end



Home | Main Index | Thread Index | Old Index