Module Name:    src
Committed By:   rillig
Date:           Sun Jun  4 22:20:04 UTC 2023

Modified Files:
        src/tests/usr.bin/indent: indent_off_on.c lsym_binary_op.c
            lsym_type_outside_parentheses.c t_errors.sh

Log Message:
tests/indent: cover code in lexi.c


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/tests/usr.bin/indent/indent_off_on.c
cvs rdiff -u -r1.8 -r1.9 src/tests/usr.bin/indent/lsym_binary_op.c
cvs rdiff -u -r1.5 -r1.6 \
    src/tests/usr.bin/indent/lsym_type_outside_parentheses.c
cvs rdiff -u -r1.31 -r1.32 src/tests/usr.bin/indent/t_errors.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/usr.bin/indent/indent_off_on.c
diff -u src/tests/usr.bin/indent/indent_off_on.c:1.14 src/tests/usr.bin/indent/indent_off_on.c:1.15
--- src/tests/usr.bin/indent/indent_off_on.c:1.14	Sat Jun  3 21:44:08 2023
+++ src/tests/usr.bin/indent/indent_off_on.c	Sun Jun  4 22:20:04 2023
@@ -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

Index: src/tests/usr.bin/indent/lsym_binary_op.c
diff -u src/tests/usr.bin/indent/lsym_binary_op.c:1.8 src/tests/usr.bin/indent/lsym_binary_op.c:1.9
--- src/tests/usr.bin/indent/lsym_binary_op.c:1.8	Sun Jun  4 19:28:54 2023
+++ src/tests/usr.bin/indent/lsym_binary_op.c	Sun Jun  4 22:20:04 2023
@@ -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

Index: src/tests/usr.bin/indent/lsym_type_outside_parentheses.c
diff -u src/tests/usr.bin/indent/lsym_type_outside_parentheses.c:1.5 src/tests/usr.bin/indent/lsym_type_outside_parentheses.c:1.6
--- src/tests/usr.bin/indent/lsym_type_outside_parentheses.c:1.5	Mon May 15 18:22:40 2023
+++ src/tests/usr.bin/indent/lsym_type_outside_parentheses.c	Sun Jun  4 22:20:04 2023
@@ -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

Index: src/tests/usr.bin/indent/t_errors.sh
diff -u src/tests/usr.bin/indent/t_errors.sh:1.31 src/tests/usr.bin/indent/t_errors.sh:1.32
--- src/tests/usr.bin/indent/t_errors.sh:1.31	Sun Jun  4 13:26:07 2023
+++ src/tests/usr.bin/indent/t_errors.sh	Sun Jun  4 22:20:04 2023
@@ -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'

Reply via email to