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: cover code in lexi.c



details:   https://anonhg.NetBSD.org/src/rev/63c56118c7c5
branches:  trunk
changeset: 376215:63c56118c7c5
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Jun 04 22:20:04 2023 +0000

description:
tests/indent: cover code in lexi.c

diffstat:

 tests/usr.bin/indent/indent_off_on.c                 |  23 ++++++++++++++++-
 tests/usr.bin/indent/lsym_binary_op.c                |  23 ++++++++++++++++-
 tests/usr.bin/indent/lsym_type_outside_parentheses.c |  18 +++++++++++++-
 tests/usr.bin/indent/t_errors.sh                     |  26 +++++++++++++++++++-
 4 files changed, 86 insertions(+), 4 deletions(-)

diffs (145 lines):

diff -r cb3f228b3c34 -r 63c56118c7c5 tests/usr.bin/indent/indent_off_on.c
--- a/tests/usr.bin/indent/indent_off_on.c      Sun Jun 04 22:18:47 2023 +0000
+++ b/tests/usr.bin/indent/indent_off_on.c      Sun Jun 04 22:20:04 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: indent_off_on.c,v 1.14 2023/06/03 21:44:08 rillig Exp $ */
+/* $NetBSD: indent_off_on.c,v 1.15 2023/06/04 22:20:04 rillig Exp $ */
 
 /*
  * Tests for the comments 'INDENT OFF' and 'INDENT ON', which temporarily
@@ -252,3 +252,24 @@ int declaration;
 //indent end
 
 //indent run-equals-input -bacc
+
+
+/*
+ * If an 'INDENT OFF' comment directly follows a line continuation, the line
+ * continuation is dropped but the rest of the line is still formatted.
+ */
+//indent input
+int x ; \
+/* INDENT OFF */
+  int y ;
+/* INDENT ON */
+int z ;
+//indent end
+
+//indent run
+int            x;
+/* INDENT OFF */
+  int y ;
+/* INDENT ON */
+int            z;
+//indent end
diff -r cb3f228b3c34 -r 63c56118c7c5 tests/usr.bin/indent/lsym_binary_op.c
--- a/tests/usr.bin/indent/lsym_binary_op.c     Sun Jun 04 22:18:47 2023 +0000
+++ b/tests/usr.bin/indent/lsym_binary_op.c     Sun Jun 04 22:20:04 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lsym_binary_op.c,v 1.8 2023/06/04 19:28:54 rillig Exp $ */
+/* $NetBSD: lsym_binary_op.c,v 1.9 2023/06/04 22:20:04 rillig Exp $ */
 
 /*
  * Tests for the token lsym_binary_op, which represents a binary operator in
@@ -171,3 +171,24 @@ int conditional = condition ? number : n
 //indent end
 
 //indent run-equals-input -di0
+
+
+// After a ']', a '*' is a binary operator.
+//indent input
+int x = arr[3]*y;
+//indent end
+
+//indent run -di0
+int x = arr[3] * y;
+//indent end
+
+
+//indent input
+{
+       a = a;
+// $ FIXME: The first '*=' is categorized as 'unary_op token "*"'.
+       a *= b *= c;
+}
+//indent end
+
+//indent run-equals-input -di0
diff -r cb3f228b3c34 -r 63c56118c7c5 tests/usr.bin/indent/lsym_type_outside_parentheses.c
--- a/tests/usr.bin/indent/lsym_type_outside_parentheses.c      Sun Jun 04 22:18:47 2023 +0000
+++ b/tests/usr.bin/indent/lsym_type_outside_parentheses.c      Sun Jun 04 22:20:04 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lsym_type_outside_parentheses.c,v 1.5 2023/05/15 18:22:40 rillig Exp $ */
+/* $NetBSD: lsym_type_outside_parentheses.c,v 1.6 2023/06/04 22:20:04 rillig Exp $ */
 
 /*
  * Tests for the token lsym_type_outside_parentheses, which represents a type
@@ -29,3 +29,19 @@ const char          *const names[3];
 //indent end
 
 //indent run-equals-input -di24
+
+
+//indent input
+{
+{}
+size_t hello;
+}
+//indent end
+
+//indent run
+{
+       {
+       }
+       size_t          hello;
+}
+//indent end
diff -r cb3f228b3c34 -r 63c56118c7c5 tests/usr.bin/indent/t_errors.sh
--- a/tests/usr.bin/indent/t_errors.sh  Sun Jun 04 22:18:47 2023 +0000
+++ b/tests/usr.bin/indent/t_errors.sh  Sun Jun 04 22:20:04 2023 +0000
@@ -1,5 +1,5 @@
 #! /bin/sh
-# $NetBSD: t_errors.sh,v 1.31 2023/06/04 13:26:07 rillig Exp $
+# $NetBSD: t_errors.sh,v 1.32 2023/06/04 22:20:04 rillig Exp $
 #
 # Copyright (c) 2021 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -214,6 +214,28 @@ unterminated_comment_nowrap_body()
            "$indent" -st < comment.c
 }
 
+atf_test_case 'unterminated_char_constant'
+unterminated_char_constant_body()
+{
+       echo "char ch = 'x" > char.c
+
+       atf_check -s 'exit:1' \
+           -o "inline:char ch = 'x\n" \
+           -e 'inline:error: Standard Input:1: Unterminated literal\n' \
+           "$indent" -st -di0 < char.c
+}
+
+atf_test_case 'unterminated_string_literal'
+unterminated_string_literal_body()
+{
+       echo 'const char str[] = "x' > string.c
+
+       atf_check -s 'exit:1' \
+           -o 'inline:const char str[] = "x\n' \
+           -e 'inline:error: Standard Input:1: Unterminated literal\n' \
+           "$indent" -st -di0 < string.c
+}
+
 atf_test_case 'in_place_wrong_backup'
 in_place_wrong_backup_body()
 {
@@ -549,6 +571,8 @@ atf_init_test_cases()
        atf_add_test_case 'option_indent_size_zero'
        atf_add_test_case 'unterminated_comment_wrap'
        atf_add_test_case 'unterminated_comment_nowrap'
+       atf_add_test_case 'unterminated_char_constant'
+       atf_add_test_case 'unterminated_string_literal'
        atf_add_test_case 'in_place_wrong_backup'
        atf_add_test_case 'argument_input_enoent'
        atf_add_test_case 'argument_output_equals_input_name'



Home | Main Index | Thread Index | Old Index