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 tokenization of punc...



details:   https://anonhg.NetBSD.org/src/rev/68eb5188447a
branches:  trunk
changeset: 953548:68eb5188447a
user:      rillig <rillig%NetBSD.org@localhost>
date:      Fri Mar 12 17:41:10 2021 +0000

description:
tests/indent: test tokenization of punctuation, mainly operators

diffstat:

 tests/usr.bin/indent/token-binary_op.0        |  102 ++++++++++++++++++++++++-
 tests/usr.bin/indent/token-binary_op.0.pro    |    8 +-
 tests/usr.bin/indent/token-binary_op.0.stdout |  105 +++++++++++++++++++++++++-
 3 files changed, 205 insertions(+), 10 deletions(-)

diffs (243 lines):

diff -r 6fe5e22a063e -r 68eb5188447a tests/usr.bin/indent/token-binary_op.0
--- a/tests/usr.bin/indent/token-binary_op.0    Fri Mar 12 17:03:06 2021 +0000
+++ b/tests/usr.bin/indent/token-binary_op.0    Fri Mar 12 17:41:10 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: token-binary_op.0,v 1.1 2021/03/12 00:13:06 rillig Exp $ */
+/* $NetBSD: token-binary_op.0,v 1.2 2021/03/12 17:41:10 rillig Exp $ */
 /* $FreeBSD$ */
 
 /*
@@ -9,4 +9,102 @@
  * multiplication, or pointer dereference, or pointer type declaration.
  */
 
-/* TODO: Add some code to be formatted. */
+/* See C99 6.4.6 */
+void
+punctuators(void)
+{
+       int brackets = array[subscript];
+       int parentheses = function(argument);
+       int braces = { initializer };
+       int period = structure.member;
+       int arrow = structure->member;
+
+       ++prefix_increment;
+       postfix_increment++;
+       --prefix_decrement;
+       postfix_decrement--;
+       int *address = &lvalue;
+       int bitwise_and = value & mask;
+       int product = factor * factor;
+       int dereferenced = *address;
+       int positive = +number;
+       int sum = number + number;
+       int negative = -number;
+       int difference = number - number;
+       bool negated = !condition;
+
+       int quotient = number / number;
+       int modulo = number % number;
+       int shifted_left = number << number;
+       int shifted_right = number >> number;
+       bool less_than = number < number;
+       bool greater_than = number > number;
+       bool less_equal = number <= number;
+       bool greater_equal = number >= number;
+       bool equal = number == number;
+       bool unequal = number != number;
+       int bitwise_exclusive_or = number ^ number;
+       int bitwise_or = number | number;
+       bool logical_and = condition && condition;
+       bool logical_or = condition || condition;
+
+       int conditional = condition ? number : number;
+
+       /* combined assignment operators */
+       number = (expression);
+       number *= number;
+       number /= number;
+       number %= number;
+       number += number;
+       number -= number;
+       number <<= number;
+       number >>= number;
+       number &= number;
+       number ^= number;
+       number |= number;
+
+       number = function(argument1, argument2);
+       number = function(argument), number;
+
+       /* digraphs */
+       number = array<:subscript:>;
+       number = (int)<% initializer %>;
+}
+
+void
+peculiarities(void)
+{
+       /*
+        * When indent tokenizes some of the operators, it allows for
+        * arbitrary repetitions of the operator character, followed by an
+        * arbitrary amount of '='.  This is used for operators like '&&' or
+        * '|||==='.
+        *
+        * Before 2021-03-07 22:11:01, the comment '//' was treated as an
+        * operator as well, and so was the comment '/////', leading to
+        * unexpected results; see comment-line-end.0 for more details.
+        *
+        * See lexi.c, lexi, "default:".
+        */
+       if (a &&&&&&& b)
+               return;
+       if (a |||=== b)
+               return;
+
+       /*-
+        * For '+' and '-', this does not work since the lexer has to
+        * distinguish between '++' and '+' early.  The following sequence is
+        * thus tokenized as:
+        *
+        *      ident           'a'
+        *      postfix         '++'
+        *      binary_op       '++'
+        *      unary_op        '++'
+        *      unary_op        '+'
+        *      ident           'b'
+        *
+        * See lexi.c, lexi, "case '+':".
+        */
+       if (a +++++++ b)
+               return;
+}
diff -r 6fe5e22a063e -r 68eb5188447a tests/usr.bin/indent/token-binary_op.0.pro
--- a/tests/usr.bin/indent/token-binary_op.0.pro        Fri Mar 12 17:03:06 2021 +0000
+++ b/tests/usr.bin/indent/token-binary_op.0.pro        Fri Mar 12 17:41:10 2021 +0000
@@ -1,8 +1,4 @@
-/* $NetBSD: token-binary_op.0.pro,v 1.1 2021/03/12 00:13:06 rillig Exp $ */
+/* $NetBSD: token-binary_op.0.pro,v 1.2 2021/03/12 17:41:10 rillig Exp $ */
 /* $FreeBSD$ */
 
-/*
- * TODO: Explain the command line options of the test.
- */
-
-/* TODO: Add some command line options */
+-ldi0          /* do not align local variables in declarations */
diff -r 6fe5e22a063e -r 68eb5188447a tests/usr.bin/indent/token-binary_op.0.stdout
--- a/tests/usr.bin/indent/token-binary_op.0.stdout     Fri Mar 12 17:03:06 2021 +0000
+++ b/tests/usr.bin/indent/token-binary_op.0.stdout     Fri Mar 12 17:41:10 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: token-binary_op.0.stdout,v 1.1 2021/03/12 00:13:06 rillig Exp $ */
+/* $NetBSD: token-binary_op.0.stdout,v 1.2 2021/03/12 17:41:10 rillig Exp $ */
 /* $FreeBSD$ */
 
 /*
@@ -9,4 +9,105 @@
  * multiplication, or pointer dereference, or pointer type declaration.
  */
 
-/* TODO: Add some code to be formatted. */
+/* See C99 6.4.6 */
+void
+punctuators(void)
+{
+       int brackets = array[subscript];
+       int parentheses = function(argument);
+/* $ XXX: The spaces around the initializer are gone. */
+       int braces = {initializer};
+       int period = structure.member;
+       int arrow = structure->member;
+
+       ++prefix_increment;
+       postfix_increment++;
+       --prefix_decrement;
+       postfix_decrement--;
+       int *address = &lvalue;
+       int bitwise_and = value & mask;
+       int product = factor * factor;
+       int dereferenced = *address;
+       int positive = +number;
+       int sum = number + number;
+       int negative = -number;
+       int difference = number - number;
+       bool negated = !condition;
+
+       int quotient = number / number;
+       int modulo = number % number;
+       int shifted_left = number << number;
+       int shifted_right = number >> number;
+       bool less_than = number < number;
+       bool greater_than = number > number;
+       bool less_equal = number <= number;
+       bool greater_equal = number >= number;
+       bool equal = number == number;
+       bool unequal = number != number;
+       int bitwise_exclusive_or = number ^ number;
+       int bitwise_or = number | number;
+       bool logical_and = condition && condition;
+       bool logical_or = condition || condition;
+
+       int conditional = condition ? number : number;
+
+       /* combined assignment operators */
+       number = (expression);
+       number *= number;
+       number /= number;
+       number %= number;
+       number += number;
+       number -= number;
+       number <<= number;
+       number >>= number;
+       number &= number;
+       number ^= number;
+       number |= number;
+
+       number = function(argument1, argument2);
+       number = function(argument), number;
+
+       /* digraphs */
+/* $ XXX: indent is confused by the digraphs for '[' and ']'. */
+/* $ This probably doesn't matter since digraphs are not used in practice. */
+number = array <:subscript:>;
+       number = (int)<%initializer % >;
+}
+
+void
+peculiarities(void)
+{
+       /*
+        * When indent tokenizes some of the operators, it allows for
+        * arbitrary repetitions of the operator character, followed by an
+        * arbitrary amount of '='.  This is used for operators like '&&' or
+        * '|||==='.
+        *
+        * Before 2021-03-07 22:11:01, the comment '//' was treated as an
+        * operator as well, and so was the comment '/////', leading to
+        * unexpected results; see comment-line-end.0 for more details.
+        *
+        * See lexi.c, lexi, "default:".
+        */
+       if (a &&&&&&& b)
+               return;
+       if (a |||=== b)
+               return;
+
+       /*-
+        * For '+' and '-', this does not work since the lexer has to
+        * distinguish between '++' and '+' early.  The following sequence is
+        * thus tokenized as:
+        *
+        *      ident           'a'
+        *      postfix         '++'
+        *      binary_op       '++'
+        *      unary_op        '++'
+        *      unary_op        '+'
+        *      ident           'b'
+        *
+        * See lexi.c, lexi, "case '+':".
+        */
+       if (a++ ++ +++b)
+               return;
+}



Home | Main Index | Thread Index | Old Index