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 miscellaneous test ca...



details:   https://anonhg.NetBSD.org/src/rev/d4fed12b795b
branches:  trunk
changeset: 376432:d4fed12b795b
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat Jun 17 22:09:24 2023 +0000

description:
tests/indent: add miscellaneous test cases found during clean up

diffstat:

 tests/usr.bin/indent/edge_cases.c              |  134 ++++++++++++++++++++++++-
 tests/usr.bin/indent/lsym_comment.c            |   53 +++++++++-
 tests/usr.bin/indent/lsym_funcname.c           |   31 +++++-
 tests/usr.bin/indent/lsym_lparen_or_lbracket.c |   23 ++++-
 tests/usr.bin/indent/lsym_tag.c                |   23 ++++-
 tests/usr.bin/indent/lsym_typedef.c            |   23 ++++-
 tests/usr.bin/indent/lsym_unary_op.c           |   26 ++++-
 tests/usr.bin/indent/lsym_word.c               |    6 +-
 tests/usr.bin/indent/opt_T.c                   |   19 +++-
 tests/usr.bin/indent/opt_bad.c                 |   23 ++++-
 tests/usr.bin/indent/opt_bbb.c                 |   24 ++++-
 tests/usr.bin/indent/opt_bc.c                  |   56 ++++++++++-
 tests/usr.bin/indent/opt_cd.c                  |   42 +++++++-
 tests/usr.bin/indent/opt_sc.c                  |   39 ++++++-
 14 files changed, 503 insertions(+), 19 deletions(-)

diffs (truncated from 695 to 300 lines):

diff -r cb705008843e -r d4fed12b795b tests/usr.bin/indent/edge_cases.c
--- a/tests/usr.bin/indent/edge_cases.c Sat Jun 17 15:47:31 2023 +0000
+++ b/tests/usr.bin/indent/edge_cases.c Sat Jun 17 22:09:24 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: edge_cases.c,v 1.3 2023/06/04 18:58:30 rillig Exp $ */
+/* $NetBSD: edge_cases.c,v 1.4 2023/06/17 22:09:24 rillig Exp $ */
 
 /*
  * Tests for edge cases in the C programming language that indent does not
@@ -44,3 +44,135 @@ number = array <:subscript: >;
 
 /* TODO: test trigraphs, which are as unusual as digraphs */
 /* TODO: test digraphs and trigraphs in string literals, just for fun */
+
+
+/*
+ * The keywords 'break', 'continue', 'goto' and 'restrict' are ordinary words,
+ * they do not force a line break before.
+ */
+//indent input
+{
+       Whether to break or not to break, that is the question;
+
+       The people goto the shopping mall;
+
+       Begin at the beginning, then continue until you come to the end;
+       then stop;
+
+       Try to restrict yourself;
+}
+//indent end
+
+//indent run-equals-input -di0
+
+
+/*
+ * Try a bit of Perl code, just for fun, taken from pkgsrc/pkgtools/pkglint4.
+ *
+ * It works surprisingly well.
+ */
+//indent input
+package PkgLint::Line;
+
+use strict;
+use warnings;
+
+BEGIN {
+       import PkgLint::Util qw(
+               false true
+               assert
+       );
+}
+
+use enum qw(FNAME LINES TEXT PHYSLINES CHANGED BEFORE AFTER EXTRA);
+
+sub new($$$$) {
+       my ($class, $fname, $lines, $text, $physlines) = @_;
+       my ($self) = ([$fname, $lines, $text, $physlines, false, [], [], {}]);
+       bless($self, $class);
+       return $self;
+}
+
+sub fname($)           { return shift()->[FNAME]; }
+
+# querying, getting and setting the extra values.
+sub has($$) {
+       my ($self, $name) = @_;
+       return exists($self->[EXTRA]->{$name});
+}
+//indent end
+
+//indent run -di0 -nfbs -npsl
+// $ Space after '::'.
+package PkgLint:: Line;
+
+use strict;
+use warnings;
+
+BEGIN {
+// $ Space after '::'.
+       import PkgLint:: Util qw(
+                                false true
+                                assert
+       );
+}
+
+// $ Space between 'qw' and '('.
+use enum qw (FNAME LINES TEXT PHYSLINES CHANGED BEFORE AFTER EXTRA);
+
+sub new($$$$) {
+// $ No space between 'my' and '('.
+       my($class, $fname, $lines, $text, $physlines) = @_;
+       my($self) = ([$fname, $lines, $text, $physlines, false, [], [], {
+// $ Line break between '{' and '}'.
+       }
+// $ Line break between '}' and ']'.
+       ]);
+       bless($self, $class);
+       return $self;
+}
+
+sub fname($) {
+       return shift()->[FNAME];
+}
+
+// $ Preprocessing lines are mostly preserved.
+# querying, getting and setting the extra values.
+sub has($$) {
+       my($self, $name) = @_;
+       return exists($self->[EXTRA]->{
+// $ Line breaks between '{', '$name', '}' and ');'.
+               $name
+       }
+       );
+}
+// exit 1
+// error: Standard Input:17: Unbalanced parentheses
+// warning: Standard Input:17: Extra ']'
+// warning: Standard Input:17: Extra ')'
+// error: Standard Input:27: Unbalanced parentheses
+// warning: Standard Input:27: Extra ')'
+//indent end
+
+
+/*
+ * Try a piece of old-style JavaScript, just for fun, using '==' instead of the
+ * now recommended '==='.
+ */
+//indent input
+function join(delim, values)
+{
+       if (values.length == 0)
+               return '';
+       if (values.length == 1)
+               return values[0];
+       var result = '';
+       for (var i in values) {
+               result += delim;
+               result += values[i];
+       }
+       return result.substr(delim.length);
+}
+//indent end
+
+//indent run-equals-input -di0 -npsl
diff -r cb705008843e -r d4fed12b795b tests/usr.bin/indent/lsym_comment.c
--- a/tests/usr.bin/indent/lsym_comment.c       Sat Jun 17 15:47:31 2023 +0000
+++ b/tests/usr.bin/indent/lsym_comment.c       Sat Jun 17 22:09:24 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lsym_comment.c,v 1.21 2023/06/14 09:31:05 rillig Exp $ */
+/* $NetBSD: lsym_comment.c,v 1.22 2023/06/17 22:09:24 rillig Exp $ */
 
 /*
  * Tests for the token lsym_comment, which starts a comment.
@@ -1144,3 +1144,54 @@ int block;                       /* comment line 1 comment l
 // $ FIXME: It's a comment, not code.
 /*/ comment ? or : not;                /* */
 //indent end
+
+
+/*
+ * The tokens '/' and '*' do not form a comment when they are separated by a
+ * space.
+ */
+//indent input
+int a = b / *c;
+// $ Indent can be tricked into treating '/' as a unary operator, thus turning
+// $ some operators into the start of a comment. This only works in
+// $ syntactically invalid text.
+int a = b + / * c;
+//indent end
+
+//indent run -di0
+int a = b / *c;
+// $ FIXME: Don't merge the two operators; there are enough situations where
+// $ indent has to guess whether an operator is unary or binary, and these
+// $ heuristics can go wrong.
+int a = b + /*c;
+//indent end
+
+
+/*
+ * Ensure that tab characters that are broken into separate lines are replaced
+ * with spaces; other tabs are preserved.
+ */
+//indent input
+/* word        word    word    word    word    word    word    word    word */
+//indent end
+
+//indent run -l38
+/*
+ * word        word    word    word    word
+ * word        word    word    word
+ */
+//indent end
+
+
+/* In no-wrap comments, every single newline is preserved. */
+//indent input
+/*-
+paragraph 1
+
+
+
+paragraph 2
+ */
+//indent end
+
+//indent run-equals-input
diff -r cb705008843e -r d4fed12b795b tests/usr.bin/indent/lsym_funcname.c
--- a/tests/usr.bin/indent/lsym_funcname.c      Sat Jun 17 15:47:31 2023 +0000
+++ b/tests/usr.bin/indent/lsym_funcname.c      Sat Jun 17 22:09:24 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lsym_funcname.c,v 1.6 2023/06/15 09:19:07 rillig Exp $ */
+/* $NetBSD: lsym_funcname.c,v 1.7 2023/06/17 22:09:24 rillig Exp $ */
 
 /*
  * Tests for the token lsym_funcname, which is the name of a function, but only
@@ -33,3 +33,32 @@ function_with_comment(void)
 //indent end
 
 //indent run-equals-input
+
+
+/*
+ * The heuristics for telling a function definition and a function declaration
+ * apart look at the remaining characters in a line but don't tokenize them.
+ * Due to that, a ');' in a comment influences the heuristics.
+ */
+//indent input
+// $ This ');' in the comment does not mark the end of the declaration.
+void heuristics_semicolon_comment(/* ); */) {}
+void heuristics_semicolon_no_comm(/* -- */) {}
+void heuristics_comma_comment(/* ), */) {}
+void heuristics_comma_no_comm(/* -- */) {}
+//indent end
+
+//indent run -di0
+void heuristics_semicolon_comment(/* ); */) {
+}
+void
+heuristics_semicolon_no_comm(/* -- */)
+{
+}
+void heuristics_comma_comment(/* ), */) {
+}
+void
+heuristics_comma_no_comm(/* -- */)
+{
+}
+//indent end
diff -r cb705008843e -r d4fed12b795b tests/usr.bin/indent/lsym_lparen_or_lbracket.c
--- a/tests/usr.bin/indent/lsym_lparen_or_lbracket.c    Sat Jun 17 15:47:31 2023 +0000
+++ b/tests/usr.bin/indent/lsym_lparen_or_lbracket.c    Sat Jun 17 22:09:24 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lsym_lparen_or_lbracket.c,v 1.18 2023/06/16 23:07:52 rillig Exp $ */
+/* $NetBSD: lsym_lparen_or_lbracket.c,v 1.19 2023/06/17 22:09:24 rillig Exp $ */
 
 /*
  * Tests for the token lsym_lparen_or_lbracket, which represents a '(' or '['
@@ -355,3 +355,24 @@ int arr[] = {
        ['1'] = 2,
 };
 //indent end
+
+
+/* In an initializer, a '(' does not start a function definition. */
+//indent input
+{
+type var = {
+.CONCAT(a, b)
+= init,
+};
+}
+
+//indent end
+
+//indent run
+{
+       type            var = {
+               .CONCAT(a, b)
+               = init,
+       };
+}
+//indent end
diff -r cb705008843e -r d4fed12b795b tests/usr.bin/indent/lsym_tag.c
--- a/tests/usr.bin/indent/lsym_tag.c   Sat Jun 17 15:47:31 2023 +0000
+++ b/tests/usr.bin/indent/lsym_tag.c   Sat Jun 17 22:09:24 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lsym_tag.c,v 1.9 2023/06/15 10:34:12 rillig Exp $ */
+/* $NetBSD: lsym_tag.c,v 1.10 2023/06/17 22:09:24 rillig Exp $ */
 
 /*
  * Tests for the token lsym_tag, which represents one of the keywords
@@ -156,3 +156,24 @@ enum multi_line {
 //indent run-equals-input -ci4
 
 //indent run-equals-input -ci4 -nlp
+
+



Home | Main Index | Thread Index | Old Index