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: add code snippets found i...



details:   https://anonhg.NetBSD.org/src/rev/a81a0fa6624e
branches:  trunk
changeset: 375958:a81a0fa6624e
user:      rillig <rillig%NetBSD.org@localhost>
date:      Tue May 23 06:18:00 2023 +0000

description:
tests/indent: add code snippets found in make and lint1

diffstat:

 tests/usr.bin/indent/fmt_decl.c      |  52 +++++++++++++++++++++++++++++++++++-
 tests/usr.bin/indent/lsym_for.c      |  18 +++++++++++-
 tests/usr.bin/indent/lsym_unary_op.c |  17 +++++++++++-
 tests/usr.bin/indent/opt_bap.c       |  28 ++++++++++++++++++-
 tests/usr.bin/indent/opt_lp.c        |  24 +++++++++++++++-
 tests/usr.bin/indent/opt_sob.c       |  36 ++++++++++++++++++++++++-
 6 files changed, 169 insertions(+), 6 deletions(-)

diffs (279 lines):

diff -r 628120d783ac -r a81a0fa6624e tests/usr.bin/indent/fmt_decl.c
--- a/tests/usr.bin/indent/fmt_decl.c   Tue May 23 00:31:42 2023 +0000
+++ b/tests/usr.bin/indent/fmt_decl.c   Tue May 23 06:18:00 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: fmt_decl.c,v 1.43 2023/05/16 08:22:11 rillig Exp $     */
+/*     $NetBSD: fmt_decl.c,v 1.44 2023/05/23 06:18:00 rillig Exp $     */
 
 /*
  * Tests for declarations of global variables, external functions, and local
@@ -960,3 +960,53 @@ ch_isalpha(char ch)
 //indent end
 
 //indent run-equals-input -i4 -di0
+
+
+//indent input
+struct {
+       void *list;
+       Table /* comment */ table;
+} var;
+//indent end
+
+//indent run -di0
+struct {
+       void *list;
+// $ FIXME: Wrong indentation, as 'Table' starts a new declaration.
+            Table /* comment */ table;
+} var;
+//indent end
+
+
+//indent input
+void __printflike(1, 2)
+debug_printf(const char *fmt, ...)
+{
+}
+//indent end
+
+//indent run
+void
+// $ FIXME: No line break here.
+__printflike(1, 2)
+debug_printf(const char *fmt, ...)
+{
+}
+//indent end
+
+
+//indent input
+void
+(error_at)(int msgid, const pos_t *pos, ...)
+{
+}
+//indent end
+
+//indent run -ci4 -di0 -ndj -nlp
+void
+// $ FIXME: Wrong indentation, should be 0 instead.
+// $ FIXME: Wrong spacing around '*'.
+     (error_at)(int msgid, const pos_t * pos, ...)
+{
+}
+//indent end
diff -r 628120d783ac -r a81a0fa6624e tests/usr.bin/indent/lsym_for.c
--- a/tests/usr.bin/indent/lsym_for.c   Tue May 23 00:31:42 2023 +0000
+++ b/tests/usr.bin/indent/lsym_for.c   Tue May 23 06:18:00 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lsym_for.c,v 1.4 2022/04/24 10:36:37 rillig Exp $ */
+/* $NetBSD: lsym_for.c,v 1.5 2023/05/23 06:18:00 rillig Exp $ */
 
 /*
  * Tests for the token lsym_for, which represents the keyword 'for' that
@@ -87,3 +87,19 @@ function(void)
 //indent end
 
 //indent run-equals-input
+
+
+//indent input
+{
+       for (const list_item *i = first; i != NULL; i = i->next) {
+       }
+}
+//indent end
+
+//indent run
+{
+// $ FIXME: Wrong spacing after '*'.
+       for (const list_item * i = first; i != NULL; i = i->next) {
+       }
+}
+//indent end
diff -r 628120d783ac -r a81a0fa6624e tests/usr.bin/indent/lsym_unary_op.c
--- a/tests/usr.bin/indent/lsym_unary_op.c      Tue May 23 00:31:42 2023 +0000
+++ b/tests/usr.bin/indent/lsym_unary_op.c      Tue May 23 06:18:00 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lsym_unary_op.c,v 1.6 2023/05/13 06:52:48 rillig Exp $ */
+/* $NetBSD: lsym_unary_op.c,v 1.7 2023/05/23 06:18:00 rillig Exp $ */
 
 /*
  * Tests for the token lsym_unary_op, which represents a unary operator.
@@ -77,3 +77,18 @@ unary_operators(void)
 //indent end
 
 //indent run-equals-input -di0
+
+
+//indent input
+{
+sbuf_t *sb = *(sbuf_t **)sp;
+}
+//indent end
+
+//indent run -di0
+{
+// $ FIXME: Wrong spacing between the '*'.
+// $ FIXME: Wrong spacing after the cast.
+       sbuf_t *sb = *(sbuf_t * *) sp;
+}
+//indent end
diff -r 628120d783ac -r a81a0fa6624e tests/usr.bin/indent/opt_bap.c
--- a/tests/usr.bin/indent/opt_bap.c    Tue May 23 00:31:42 2023 +0000
+++ b/tests/usr.bin/indent/opt_bap.c    Tue May 23 06:18:00 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: opt_bap.c,v 1.8 2023/05/20 12:05:01 rillig Exp $ */
+/* $NetBSD: opt_bap.c,v 1.9 2023/05/23 06:18:00 rillig Exp $ */
 
 /*
  * Tests for the options '-bap' and '-nbap' ("blank line after procedure
@@ -111,3 +111,29 @@ example(void)
 //indent end
 
 //indent run-equals-input -bap
+
+
+//indent input
+#if 0
+void
+f(void)
+{
+}
+#else
+#endif
+//indent end
+
+//indent run -bacc -bap
+#if 0
+void
+f(void)
+{
+}
+// $ The following blank line may be considered optional, as it precedes a
+// $ preprocessing line.  In that case, the -bap option would only apply to
+// $ elements on the same syntactic level, such as function definitions and
+// $ other declarations.
+
+#else
+#endif
+//indent end
diff -r 628120d783ac -r a81a0fa6624e tests/usr.bin/indent/opt_lp.c
--- a/tests/usr.bin/indent/opt_lp.c     Tue May 23 00:31:42 2023 +0000
+++ b/tests/usr.bin/indent/opt_lp.c     Tue May 23 06:18:00 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: opt_lp.c,v 1.6 2022/04/24 09:04:12 rillig Exp $ */
+/* $NetBSD: opt_lp.c,v 1.7 2023/05/23 06:18:00 rillig Exp $ */
 
 /*
  * Tests for the options '-lp' and '-nlp'.
@@ -87,3 +87,25 @@ example(void)
            third_procedure(p4, p5));
 }
 //indent end
+
+
+//indent input
+{
+if (cond) {
+} else if (cond &&
+cond &&
+cond) {
+}
+}
+//indent end
+
+//indent run -ci4 -nlp
+{
+       if (cond) {
+       } else if (cond &&
+// $ FIXME: Wrong indentation, should be 4 spaces only.
+                   cond &&
+           cond) {
+       }
+}
+//indent end
diff -r 628120d783ac -r a81a0fa6624e tests/usr.bin/indent/opt_sob.c
--- a/tests/usr.bin/indent/opt_sob.c    Tue May 23 00:31:42 2023 +0000
+++ b/tests/usr.bin/indent/opt_sob.c    Tue May 23 06:18:00 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: opt_sob.c,v 1.7 2023/05/22 10:28:59 rillig Exp $ */
+/* $NetBSD: opt_sob.c,v 1.8 2023/05/23 06:18:00 rillig Exp $ */
 
 /*
  * Tests for the options '-sob' and '-nsob'.
@@ -26,6 +26,9 @@ function_with_0_blank_lines(void)
        var = value;
        if (var > 0)
                var--;
+       if (var > 0) {
+               var--;
+       }
        return var;
 }
 
@@ -42,6 +45,13 @@ function_with_1_blank_line(void)
 
                var--;
 
+       if (var > 0) {
+/* $ The following line is "optional" and is removed due to '-sob'. */
+
+               var--;
+
+       }
+
        return var;
 
 }
@@ -65,6 +75,15 @@ function_with_2_blank_lines(void)
                var--;
 
 
+       if (var > 0) {
+
+
+               var--;
+
+
+       }
+
+
        return var;
 
 
@@ -82,6 +101,9 @@ function_with_0_blank_lines(void)
        var = value;
        if (var > 0)
                var--;
+       if (var > 0) {
+               var--;
+       }
        return var;
 }
 
@@ -96,6 +118,12 @@ function_with_1_blank_line(void)
        if (var > 0)
                var--;
 
+       if (var > 0) {
+               var--;
+// $ XXX: The following blank line may be considered optional.
+
+       }
+
        return var;
 
 }
@@ -112,6 +140,12 @@ function_with_2_blank_lines(void)
        if (var > 0)
                var--;
 
+       if (var > 0) {
+               var--;
+// $ XXX: The following blank line may be considered optional.
+
+       }
+
        return var;
 
 }



Home | Main Index | Thread Index | Old Index