CVS commit: src/tests/usr.bin/indent
Module Name:src Committed By: rillig Date: Sun Dec 17 10:02:10 UTC 2023 Modified Files: src/tests/usr.bin/indent: t_misc.sh Log Message: tests/indent: don't create an unneeded file To generate a diff of this commit: cvs rdiff -u -r1.28 -r1.29 src/tests/usr.bin/indent/t_misc.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/t_misc.sh diff -u src/tests/usr.bin/indent/t_misc.sh:1.28 src/tests/usr.bin/indent/t_misc.sh:1.29 --- src/tests/usr.bin/indent/t_misc.sh:1.28 Sun Dec 10 17:45:35 2023 +++ src/tests/usr.bin/indent/t_misc.sh Sun Dec 17 10:02:09 2023 @@ -1,5 +1,5 @@ #! /bin/sh -# $NetBSD: t_misc.sh,v 1.28 2023/12/10 17:45:35 rillig Exp $ +# $NetBSD: t_misc.sh,v 1.29 2023/12/17 10:02:09 rillig Exp $ # # Copyright (c) 2021 The NetBSD Foundation, Inc. # All rights reserved. @@ -211,7 +211,6 @@ option_without_hyphen_body() printf ' -i3 xi5 +di0\n' > .indent.pro printf '%s\n' 'int var[] = {' '1,' '}' > code.c - printf '%s\n' 'int var[] = {' ' 1,' '}' > code.exp atf_check \ -s 'exit:1' \
CVS commit: src/tests/usr.bin/indent
Module Name:src Committed By: rillig Date: Sun Dec 17 10:02:10 UTC 2023 Modified Files: src/tests/usr.bin/indent: t_misc.sh Log Message: tests/indent: don't create an unneeded file To generate a diff of this commit: cvs rdiff -u -r1.28 -r1.29 src/tests/usr.bin/indent/t_misc.sh Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/tests/usr.bin/indent
Module Name:src Committed By: rillig Date: Sun Dec 10 15:39:25 UTC 2023 Modified Files: src/tests/usr.bin/indent: t_errors.sh Log Message: tests/indent: fix name of test case To generate a diff of this commit: cvs rdiff -u -r1.37 -r1.38 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/t_errors.sh diff -u src/tests/usr.bin/indent/t_errors.sh:1.37 src/tests/usr.bin/indent/t_errors.sh:1.38 --- src/tests/usr.bin/indent/t_errors.sh:1.37 Wed Jun 14 19:05:40 2023 +++ src/tests/usr.bin/indent/t_errors.sh Sun Dec 10 15:39:25 2023 @@ -1,5 +1,5 @@ #! /bin/sh -# $NetBSD: t_errors.sh,v 1.37 2023/06/14 19:05:40 rillig Exp $ +# $NetBSD: t_errors.sh,v 1.38 2023/12/10 15:39:25 rillig Exp $ # # Copyright (c) 2021 The NetBSD Foundation, Inc. # All rights reserved. @@ -57,8 +57,8 @@ option_bool_trailing_garbage_body() -bacchus } -atf_test_case 'option_int_missing_argument' -option_int_missing_argument_body() +atf_test_case 'option_int_wrong_argument' +option_int_wrong_argument_body() { expect_error \ 'indent: Command line: argument "x" to option "-ts" must be an integer' \ @@ -468,7 +468,7 @@ atf_init_test_cases() { atf_add_test_case 'option_unknown' atf_add_test_case 'option_bool_trailing_garbage' - atf_add_test_case 'option_int_missing_argument' + atf_add_test_case 'option_int_wrong_argument' atf_add_test_case 'option_profile_not_found' atf_add_test_case 'option_buffer_overflow' atf_add_test_case 'option_typedefs_not_found'
CVS commit: src/tests/usr.bin/indent
Module Name:src Committed By: rillig Date: Sun Dec 10 15:39:25 UTC 2023 Modified Files: src/tests/usr.bin/indent: t_errors.sh Log Message: tests/indent: fix name of test case To generate a diff of this commit: cvs rdiff -u -r1.37 -r1.38 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.
CVS commit: src/tests/usr.bin/indent
Module Name:src Committed By: rillig Date: Sun Dec 3 14:26:10 UTC 2023 Modified Files: src/tests/usr.bin/indent: fmt_expr.c Log Message: tests/indent: test compound expressions To generate a diff of this commit: cvs rdiff -u -r1.10 -r1.11 src/tests/usr.bin/indent/fmt_expr.c 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/fmt_expr.c diff -u src/tests/usr.bin/indent/fmt_expr.c:1.10 src/tests/usr.bin/indent/fmt_expr.c:1.11 --- src/tests/usr.bin/indent/fmt_expr.c:1.10 Fri Jun 16 23:19:01 2023 +++ src/tests/usr.bin/indent/fmt_expr.c Sun Dec 3 14:26:10 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: fmt_expr.c,v 1.10 2023/06/16 23:19:01 rillig Exp $ */ +/* $NetBSD: fmt_expr.c,v 1.11 2023/12/03 14:26:10 rillig Exp $ */ /* * Tests for all kinds of expressions that are not directly related to unary @@ -57,3 +57,28 @@ // error: Standard Input:7: Unbalanced parentheses // warning: Standard Input:9: Extra ')' //indent end + + +// A compound expression with an unknown type is indented other than one with +// a known type. Ideally, both cases should be treated the same. +//indent input +{ + var = (type) { .member = value }; + var = (type) { value, value, value }; + var = (struct s) { .member = value }; + var = (struct s) { value, value, value }; +} +//indent end + +//indent run +{ + var = (type) { + .member = value + }; + var = (type) { + value, value, value + }; + var = (struct s){.member = value}; + var = (struct s){value, value, value}; +} +//indent end
CVS commit: src/tests/usr.bin/indent
Module Name:src Committed By: rillig Date: Sun Dec 3 14:26:10 UTC 2023 Modified Files: src/tests/usr.bin/indent: fmt_expr.c Log Message: tests/indent: test compound expressions To generate a diff of this commit: cvs rdiff -u -r1.10 -r1.11 src/tests/usr.bin/indent/fmt_expr.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/tests/usr.bin/indent
Module Name:src Committed By: rillig Date: Sun Oct 22 21:03:08 UTC 2023 Modified Files: src/tests/usr.bin/indent: lsym_unary_op.c opt_bad.c Log Message: tests/indent: clean up comments To generate a diff of this commit: cvs rdiff -u -r1.12 -r1.13 src/tests/usr.bin/indent/lsym_unary_op.c \ src/tests/usr.bin/indent/opt_bad.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/tests/usr.bin/indent
Module Name:src Committed By: rillig Date: Sun Oct 22 21:03:08 UTC 2023 Modified Files: src/tests/usr.bin/indent: lsym_unary_op.c opt_bad.c Log Message: tests/indent: clean up comments To generate a diff of this commit: cvs rdiff -u -r1.12 -r1.13 src/tests/usr.bin/indent/lsym_unary_op.c \ src/tests/usr.bin/indent/opt_bad.c 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/lsym_unary_op.c diff -u src/tests/usr.bin/indent/lsym_unary_op.c:1.12 src/tests/usr.bin/indent/lsym_unary_op.c:1.13 --- src/tests/usr.bin/indent/lsym_unary_op.c:1.12 Sat Jun 17 22:09:24 2023 +++ src/tests/usr.bin/indent/lsym_unary_op.c Sun Oct 22 21:03:08 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: lsym_unary_op.c,v 1.12 2023/06/17 22:09:24 rillig Exp $ */ +/* $NetBSD: lsym_unary_op.c,v 1.13 2023/10/22 21:03:08 rillig Exp $ */ /* * Tests for the token lsym_unary_op, which represents a unary operator. @@ -50,8 +50,8 @@ int same = + + + + +- - - - -3; /* - * A special kind of unary operator is '->', which additionally suppresses the - * next space. + * The operator '->' is special as it additionally suppresses the space between + * the operator and its right operand. */ //indent input int var = p -> member; Index: src/tests/usr.bin/indent/opt_bad.c diff -u src/tests/usr.bin/indent/opt_bad.c:1.12 src/tests/usr.bin/indent/opt_bad.c:1.13 --- src/tests/usr.bin/indent/opt_bad.c:1.12 Mon Jun 26 14:54:40 2023 +++ src/tests/usr.bin/indent/opt_bad.c Sun Oct 22 21:03:08 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: opt_bad.c,v 1.12 2023/06/26 14:54:40 rillig Exp $ */ +/* $NetBSD: opt_bad.c,v 1.13 2023/10/22 21:03:08 rillig Exp $ */ /* * Tests for the options '-bad' and '-nbad'. @@ -174,7 +174,7 @@ initializer_with_blank(void) /* comment */ int decl2; // $ If the declaration is followed by a '}' that terminates the block - // $ statement, * there is no need for a blank line before the '}'. + // $ statement, there is no need for a blank line before the '}'. } //indent end
CVS commit: src/tests/usr.bin/indent
Module Name:src Committed By: rillig Date: Tue Jun 27 04:28:16 UTC 2023 Modified Files: src/tests/usr.bin/indent: opt_badp.c Log Message: tests/indent: test the -badp option To generate a diff of this commit: cvs rdiff -u -r1.14 -r1.15 src/tests/usr.bin/indent/opt_badp.c 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/opt_badp.c diff -u src/tests/usr.bin/indent/opt_badp.c:1.14 src/tests/usr.bin/indent/opt_badp.c:1.15 --- src/tests/usr.bin/indent/opt_badp.c:1.14 Mon Jun 26 20:03:09 2023 +++ src/tests/usr.bin/indent/opt_badp.c Tue Jun 27 04:28:16 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: opt_badp.c,v 1.14 2023/06/26 20:03:09 rillig Exp $ */ +/* $NetBSD: opt_badp.c,v 1.15 2023/06/27 04:28:16 rillig Exp $ */ /* * Tests for the options '-badp' and '-nbadp'. @@ -210,3 +210,79 @@ f(void) { stmt; } //indent end + + +/* The '}' of an initializer does not end a block. */ +//indent input +void +f(void) +{ + int decl1[2][2] = { + {1, 2}, + {3, 4}, + }; + int decl2 = 5; + stmt; +} +//indent end + +//indent run -di0 +void +f(void) +{ + int decl1[2][2] = { + {1, 2}, + {3, 4}, + }; + int decl2 = 5; +// $ FIXME: Add blank line here. + stmt; +} +//indent end + + +/* + * Due to its limited lookahead, indent cannot know whether the comment is + * followed by a declaration or a statement. + */ +//indent input +void f(void) { + int decl1; + /* comment */ + int decl2; + stmt; +} +//indent end + +//indent run -badp +void +f(void) +{ + int decl1; +// $ FIXME: No blank line here. + + /* comment */ + int decl2; +// $ FIXME: Add blank line here. + stmt; +} +//indent end + + +/* Combining -bad and -badp only adds a single blank line. */ +//indent input +void f(void) { int decl; stmt1; stmt2; } +//indent end + +//indent run -bad -badp +void +f(void) +{ + int decl; + + stmt1; +// $ FIXME: Remove this blank line. + + stmt2; +} +//indent end
CVS commit: src/tests/usr.bin/indent
Module Name:src Committed By: rillig Date: Tue Jun 27 04:28:16 UTC 2023 Modified Files: src/tests/usr.bin/indent: opt_badp.c Log Message: tests/indent: test the -badp option To generate a diff of this commit: cvs rdiff -u -r1.14 -r1.15 src/tests/usr.bin/indent/opt_badp.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/tests/usr.bin/indent
Module Name:src Committed By: rillig Date: Mon Jun 26 12:21:18 UTC 2023 Modified Files: src/tests/usr.bin/indent: opt_dj.c t_options.lua Log Message: tests/indent: strengthen requirements for test input files Previously, 'indent run-equals-prev-output' was allowed even when there was no 'indent run' section above. This created an ambiguity, since 'previous output' could mean either the 'indent run' section or the 'indent run-equals-input' section. To generate a diff of this commit: cvs rdiff -u -r1.8 -r1.9 src/tests/usr.bin/indent/opt_dj.c cvs rdiff -u -r1.6 -r1.7 src/tests/usr.bin/indent/t_options.lua 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/opt_dj.c diff -u src/tests/usr.bin/indent/opt_dj.c:1.8 src/tests/usr.bin/indent/opt_dj.c:1.9 --- src/tests/usr.bin/indent/opt_dj.c:1.8 Mon Jun 5 15:02:54 2023 +++ src/tests/usr.bin/indent/opt_dj.c Mon Jun 26 12:21:18 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: opt_dj.c,v 1.8 2023/06/05 15:02:54 rillig Exp $ */ +/* $NetBSD: opt_dj.c,v 1.9 2023/06/26 12:21:18 rillig Exp $ */ /* * Tests for the options '-dj' and '-ndj'. @@ -108,10 +108,10 @@ struct a { }; //indent end -//indent run-equals-input -di0 - //indent run-equals-prev-output -dj +//indent run-equals-input -di0 + //indent input { Index: src/tests/usr.bin/indent/t_options.lua diff -u src/tests/usr.bin/indent/t_options.lua:1.6 src/tests/usr.bin/indent/t_options.lua:1.7 --- src/tests/usr.bin/indent/t_options.lua:1.6 Fri Jun 16 23:19:01 2023 +++ src/tests/usr.bin/indent/t_options.lua Mon Jun 26 12:21:18 2023 @@ -1,4 +1,4 @@ --- $NetBSD: t_options.lua,v 1.6 2023/06/16 23:19:01 rillig Exp $ +-- $NetBSD: t_options.lua,v 1.7 2023/06/26 12:21:18 rillig Exp $ -- -- Copyright (c) 2023 The NetBSD Foundation, Inc. -- All rights reserved. @@ -199,9 +199,15 @@ local function handle_indent_run_equals_ expected_out:write(input_excl_comm) unused_input_lineno = 0 max_empty_lines = 0 + output_incl_comm = "" + output_excl_comm = "" end local function handle_indent_run_equals_prev_output(args) + if output_incl_comm == "" then + warn(lineno, + "no previous output; use run-equals-input instead") + end check_empty_lines_block(1) run_indent(input_excl_comm, args) expected_out:write(output_excl_comm)
CVS commit: src/tests/usr.bin/indent
Module Name:src Committed By: rillig Date: Mon Jun 26 12:21:18 UTC 2023 Modified Files: src/tests/usr.bin/indent: opt_dj.c t_options.lua Log Message: tests/indent: strengthen requirements for test input files Previously, 'indent run-equals-prev-output' was allowed even when there was no 'indent run' section above. This created an ambiguity, since 'previous output' could mean either the 'indent run' section or the 'indent run-equals-input' section. To generate a diff of this commit: cvs rdiff -u -r1.8 -r1.9 src/tests/usr.bin/indent/opt_dj.c cvs rdiff -u -r1.6 -r1.7 src/tests/usr.bin/indent/t_options.lua Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/tests/usr.bin/indent
Module Name:src Committed By: rillig Date: Mon Jun 26 11:01:08 UTC 2023 Modified Files: src/tests/usr.bin/indent: opt_badp.c Log Message: tests/indent: extend test for -badp option To generate a diff of this commit: cvs rdiff -u -r1.12 -r1.13 src/tests/usr.bin/indent/opt_badp.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/tests/usr.bin/indent
Module Name:src Committed By: rillig Date: Mon Jun 26 11:01:08 UTC 2023 Modified Files: src/tests/usr.bin/indent: opt_badp.c Log Message: tests/indent: extend test for -badp option To generate a diff of this commit: cvs rdiff -u -r1.12 -r1.13 src/tests/usr.bin/indent/opt_badp.c 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/opt_badp.c diff -u src/tests/usr.bin/indent/opt_badp.c:1.12 src/tests/usr.bin/indent/opt_badp.c:1.13 --- src/tests/usr.bin/indent/opt_badp.c:1.12 Sun Jun 4 19:28:54 2023 +++ src/tests/usr.bin/indent/opt_badp.c Mon Jun 26 11:01:08 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: opt_badp.c,v 1.12 2023/06/04 19:28:54 rillig Exp $ */ +/* $NetBSD: opt_badp.c,v 1.13 2023/06/26 11:01:08 rillig Exp $ */ /* * Tests for the options '-badp' and '-nbadp'. @@ -8,6 +8,8 @@ * even if there are no declarations. */ + +/* An empty function body does not need a blank line. */ //indent input void empty(void) @@ -20,6 +22,7 @@ empty(void) //indent run-equals-input -nbadp +/* If an empty function body already has a blank line, it is kept. */ //indent input void blank(void) @@ -33,6 +36,10 @@ blank(void) //indent run-equals-input -nbadp +/* + * If a function body has only declarations (doesn't occur in practice), it + * does not need an empty line. + */ //indent input void declaration(void) @@ -46,6 +53,10 @@ declaration(void) //indent run-equals-input -nbadp +/* + * A function body without declarations gets an empty line above the first + * statement. + */ //indent input void statement(void) @@ -60,6 +71,10 @@ statement(void) //indent run-equals-input -nbadp +/* + * A function body with a declaration and a statement gets a blank line between + * those. + */ //indent input void declaration_statement(void) @@ -82,6 +97,7 @@ declaration_statement(void) //indent run-equals-input -nbadp +/* If there already is a blank line in the right place, it is kept. */ //indent input static void declaration_blank_statement(void) @@ -97,6 +113,7 @@ declaration_blank_statement(void) //indent run-equals-input -nbadp +/* Additional blank lines are kept. To remove them, see the '-sob' option. */ //indent input static void declaration_blank_blank_statement(void) @@ -115,6 +132,26 @@ declaration_blank_blank_statement(void) /* + * The blank line is only inserted at the top of a function body, not in nested + * block statements. + */ +//indent input +static void +nested(void) +{ + { + int decl; + stmt(); + } +} +//indent end + +//indent run-equals-input -badp + +//indent run-equals-input -nbadp + + +/* * A struct declaration or an initializer are not function bodies, so don't * add a blank line after them. */
CVS commit: src/tests/usr.bin/indent
Module Name:src Committed By: rillig Date: Fri Jun 23 20:44:51 UTC 2023 Modified Files: src/tests/usr.bin/indent: fmt_else_comment.c opt_bap.c psym_switch_expr.c Log Message: tests/indent: fix comments To generate a diff of this commit: cvs rdiff -u -r1.5 -r1.6 src/tests/usr.bin/indent/fmt_else_comment.c \ src/tests/usr.bin/indent/psym_switch_expr.c cvs rdiff -u -r1.10 -r1.11 src/tests/usr.bin/indent/opt_bap.c 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/fmt_else_comment.c diff -u src/tests/usr.bin/indent/fmt_else_comment.c:1.5 src/tests/usr.bin/indent/fmt_else_comment.c:1.6 --- src/tests/usr.bin/indent/fmt_else_comment.c:1.5 Thu May 11 09:28:53 2023 +++ src/tests/usr.bin/indent/fmt_else_comment.c Fri Jun 23 20:44:51 2023 @@ -1,10 +1,11 @@ -/* $NetBSD: fmt_else_comment.c,v 1.5 2023/05/11 09:28:53 rillig Exp $ */ +/* $NetBSD: fmt_else_comment.c,v 1.6 2023/06/23 20:44:51 rillig Exp $ */ /* - * Tests for comments after 'if (expr)' and 'else'. If the option '-br' is - * given (or rather, if '-bl' is not given), indent looks ahead to the - * following significant token to see whether it is a '{', it then moves the - * comments after the '{'. + * Tests for comments after 'if (expr)' and 'else'. Before 2023-05-11, if the + * option '-br' was given (or rather, if '-bl' was not given), indent looked + * ahead to the following significant token to see whether it was a '{', it + * then moved the comments after the '{'. This token swapping was error-prone + * and thus removed. * * See also: * FreeBSD r303484 @@ -12,8 +13,8 @@ */ /* - * The two 'if' statements below exercise two different code paths, even - * though they look very similar. + * Before 2023-05-11, the two 'if' statements below exercised two different + * code paths, even though they look very similar. */ //indent input void t(void) { @@ -52,6 +53,7 @@ void t(void) { /* Old indent would remove the 3 blank lines above, awaiting "else". */ + // $ 'Old' means something before 2019. if (1) { int a; @@ -68,6 +70,7 @@ void t(void) { if (1) ; else /* Old indent would get very confused here */ + // $ 'Old' means something before 2019. /* We also mustn't assume that there's only one comment */ /* before the left brace. */ { Index: src/tests/usr.bin/indent/psym_switch_expr.c diff -u src/tests/usr.bin/indent/psym_switch_expr.c:1.5 src/tests/usr.bin/indent/psym_switch_expr.c:1.6 --- src/tests/usr.bin/indent/psym_switch_expr.c:1.5 Tue Jun 6 04:37:27 2023 +++ src/tests/usr.bin/indent/psym_switch_expr.c Fri Jun 23 20:44:51 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: psym_switch_expr.c,v 1.5 2023/06/06 04:37:27 rillig Exp $ */ +/* $NetBSD: psym_switch_expr.c,v 1.6 2023/06/23 20:44:51 rillig Exp $ */ /* * Tests for the parser symbol psym_switch_expr, which represents the keyword @@ -12,7 +12,7 @@ /* * In all practical cases, a 'switch (expr)' is followed by a block, but the * C syntax allows an arbitrary statement. Unless such a statement has a - * label, it is unreachable. + * label or is a loop, its beginning is unreachable. */ //indent input void Index: src/tests/usr.bin/indent/opt_bap.c diff -u src/tests/usr.bin/indent/opt_bap.c:1.10 src/tests/usr.bin/indent/opt_bap.c:1.11 --- src/tests/usr.bin/indent/opt_bap.c:1.10 Fri Jun 16 11:48:32 2023 +++ src/tests/usr.bin/indent/opt_bap.c Fri Jun 23 20:44:51 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: opt_bap.c,v 1.10 2023/06/16 11:48:32 rillig Exp $ */ +/* $NetBSD: opt_bap.c,v 1.11 2023/06/23 20:44:51 rillig Exp $ */ /* * Tests for the options '-bap' and '-nbap' ("blank line after procedure @@ -115,7 +115,7 @@ example(void) /* * A preprocessing line after the end of a function body does not force a blank - * line, as these lines are not a different syntactic layer. + * line, as these lines are from a different syntactic layer. */ //indent input #if 0
CVS commit: src/tests/usr.bin/indent
Module Name:src Committed By: rillig Date: Fri Jun 23 20:44:51 UTC 2023 Modified Files: src/tests/usr.bin/indent: fmt_else_comment.c opt_bap.c psym_switch_expr.c Log Message: tests/indent: fix comments To generate a diff of this commit: cvs rdiff -u -r1.5 -r1.6 src/tests/usr.bin/indent/fmt_else_comment.c \ src/tests/usr.bin/indent/psym_switch_expr.c cvs rdiff -u -r1.10 -r1.11 src/tests/usr.bin/indent/opt_bap.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/tests/usr.bin/indent
Module Name:src Committed By: rillig Date: Sun Jun 18 07:29:37 UTC 2023 Modified Files: src/tests/usr.bin/indent: opt_bbb.c Log Message: indent: test block comments and the -bbb option To generate a diff of this commit: cvs rdiff -u -r1.9 -r1.10 src/tests/usr.bin/indent/opt_bbb.c 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/opt_bbb.c diff -u src/tests/usr.bin/indent/opt_bbb.c:1.9 src/tests/usr.bin/indent/opt_bbb.c:1.10 --- src/tests/usr.bin/indent/opt_bbb.c:1.9 Sat Jun 17 22:09:24 2023 +++ src/tests/usr.bin/indent/opt_bbb.c Sun Jun 18 07:29:36 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: opt_bbb.c,v 1.9 2023/06/17 22:09:24 rillig Exp $ */ +/* $NetBSD: opt_bbb.c,v 1.10 2023/06/18 07:29:36 rillig Exp $ */ /* * Tests for the options '-bbb' and '-nbbb'. @@ -71,8 +71,15 @@ function_definition(void) { label:/* not a block comment */ stmt; /* not a block comment */ +label: /* + * This is not a block comment, as it goes to the right. + */ + stmt; /* + * This is not a block comment, as it goes to + * the right. + */ /** - * block comment + * This is a block comment. */ } //indent end @@ -82,8 +89,16 @@ label:/* not a block comment */ label:/* not a block comment */ stmt; /* not a block comment */ +// $ TODO: No blank line before this comment. +label:/* This is not a block comment, as it goes to + * the right. */ + +// $ TODO: No blank line before this comment. + stmt; /* This is not a block comment, as it goes to + * the right. */ + /** - * block comment + * This is a block comment. */ } //indent end
CVS commit: src/tests/usr.bin/indent
Module Name:src Committed By: rillig Date: Sun Jun 18 07:29:37 UTC 2023 Modified Files: src/tests/usr.bin/indent: opt_bbb.c Log Message: indent: test block comments and the -bbb option To generate a diff of this commit: cvs rdiff -u -r1.9 -r1.10 src/tests/usr.bin/indent/opt_bbb.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/tests/usr.bin/indent
Module Name:src Committed By: rillig Date: Sat Jun 17 22:09:25 UTC 2023 Modified Files: src/tests/usr.bin/indent: edge_cases.c lsym_comment.c lsym_funcname.c lsym_lparen_or_lbracket.c lsym_tag.c lsym_typedef.c lsym_unary_op.c lsym_word.c opt_T.c opt_bad.c opt_bbb.c opt_bc.c opt_cd.c opt_sc.c Log Message: tests/indent: add miscellaneous test cases found during clean up To generate a diff of this commit: cvs rdiff -u -r1.3 -r1.4 src/tests/usr.bin/indent/edge_cases.c cvs rdiff -u -r1.21 -r1.22 src/tests/usr.bin/indent/lsym_comment.c cvs rdiff -u -r1.6 -r1.7 src/tests/usr.bin/indent/lsym_funcname.c \ src/tests/usr.bin/indent/lsym_word.c cvs rdiff -u -r1.18 -r1.19 src/tests/usr.bin/indent/lsym_lparen_or_lbracket.c cvs rdiff -u -r1.9 -r1.10 src/tests/usr.bin/indent/lsym_tag.c cvs rdiff -u -r1.8 -r1.9 src/tests/usr.bin/indent/lsym_typedef.c \ src/tests/usr.bin/indent/opt_bbb.c cvs rdiff -u -r1.11 -r1.12 src/tests/usr.bin/indent/lsym_unary_op.c cvs rdiff -u -r1.4 -r1.5 src/tests/usr.bin/indent/opt_T.c \ src/tests/usr.bin/indent/opt_cd.c cvs rdiff -u -r1.10 -r1.11 src/tests/usr.bin/indent/opt_bad.c cvs rdiff -u -r1.12 -r1.13 src/tests/usr.bin/indent/opt_bc.c cvs rdiff -u -r1.7 -r1.8 src/tests/usr.bin/indent/opt_sc.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/tests/usr.bin/indent
Module Name:src Committed By: rillig Date: Sat Jun 17 22:09:25 UTC 2023 Modified Files: src/tests/usr.bin/indent: edge_cases.c lsym_comment.c lsym_funcname.c lsym_lparen_or_lbracket.c lsym_tag.c lsym_typedef.c lsym_unary_op.c lsym_word.c opt_T.c opt_bad.c opt_bbb.c opt_bc.c opt_cd.c opt_sc.c Log Message: tests/indent: add miscellaneous test cases found during clean up To generate a diff of this commit: cvs rdiff -u -r1.3 -r1.4 src/tests/usr.bin/indent/edge_cases.c cvs rdiff -u -r1.21 -r1.22 src/tests/usr.bin/indent/lsym_comment.c cvs rdiff -u -r1.6 -r1.7 src/tests/usr.bin/indent/lsym_funcname.c \ src/tests/usr.bin/indent/lsym_word.c cvs rdiff -u -r1.18 -r1.19 src/tests/usr.bin/indent/lsym_lparen_or_lbracket.c cvs rdiff -u -r1.9 -r1.10 src/tests/usr.bin/indent/lsym_tag.c cvs rdiff -u -r1.8 -r1.9 src/tests/usr.bin/indent/lsym_typedef.c \ src/tests/usr.bin/indent/opt_bbb.c cvs rdiff -u -r1.11 -r1.12 src/tests/usr.bin/indent/lsym_unary_op.c cvs rdiff -u -r1.4 -r1.5 src/tests/usr.bin/indent/opt_T.c \ src/tests/usr.bin/indent/opt_cd.c cvs rdiff -u -r1.10 -r1.11 src/tests/usr.bin/indent/opt_bad.c cvs rdiff -u -r1.12 -r1.13 src/tests/usr.bin/indent/opt_bc.c cvs rdiff -u -r1.7 -r1.8 src/tests/usr.bin/indent/opt_sc.c 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/edge_cases.c diff -u src/tests/usr.bin/indent/edge_cases.c:1.3 src/tests/usr.bin/indent/edge_cases.c:1.4 --- src/tests/usr.bin/indent/edge_cases.c:1.3 Sun Jun 4 18:58:30 2023 +++ src/tests/usr.bin/indent/edge_cases.c Sat Jun 17 22:09:24 2023 @@ -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 Index: src/tests/usr.bin/indent/lsym_comment.c diff -u src/tests/usr.bin/indent/lsym_comment.c:1.21
CVS commit: src/tests/usr.bin/indent
Module Name:src Committed By: rillig Date: Fri Jun 16 23:19:01 UTC 2023 Modified Files: src/tests/usr.bin/indent: fmt_expr.c lsym_lbrace.c lsym_preprocessing.c lsym_semicolon.c psym_else.c psym_rbrace.c t_options.lua Log Message: tests/indent: format stderr output as end-of-line comments This generates fewer error markers in syntax-aware editors. To generate a diff of this commit: cvs rdiff -u -r1.9 -r1.10 src/tests/usr.bin/indent/fmt_expr.c \ src/tests/usr.bin/indent/lsym_lbrace.c cvs rdiff -u -r1.14 -r1.15 src/tests/usr.bin/indent/lsym_preprocessing.c cvs rdiff -u -r1.5 -r1.6 src/tests/usr.bin/indent/lsym_semicolon.c \ src/tests/usr.bin/indent/t_options.lua cvs rdiff -u -r1.6 -r1.7 src/tests/usr.bin/indent/psym_else.c cvs rdiff -u -r1.4 -r1.5 src/tests/usr.bin/indent/psym_rbrace.c 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/fmt_expr.c diff -u src/tests/usr.bin/indent/fmt_expr.c:1.9 src/tests/usr.bin/indent/fmt_expr.c:1.10 --- src/tests/usr.bin/indent/fmt_expr.c:1.9 Fri Jun 16 12:55:57 2023 +++ src/tests/usr.bin/indent/fmt_expr.c Fri Jun 16 23:19:01 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: fmt_expr.c,v 1.9 2023/06/16 12:55:57 rillig Exp $ */ +/* $NetBSD: fmt_expr.c,v 1.10 2023/06/16 23:19:01 rillig Exp $ */ /* * Tests for all kinds of expressions that are not directly related to unary @@ -53,7 +53,7 @@ stmt; }); } -exit 1 -error: Standard Input:7: Unbalanced parentheses -warning: Standard Input:9: Extra ')' +// exit 1 +// error: Standard Input:7: Unbalanced parentheses +// warning: Standard Input:9: Extra ')' //indent end Index: src/tests/usr.bin/indent/lsym_lbrace.c diff -u src/tests/usr.bin/indent/lsym_lbrace.c:1.9 src/tests/usr.bin/indent/lsym_lbrace.c:1.10 --- src/tests/usr.bin/indent/lsym_lbrace.c:1.9 Thu Jun 15 09:19:07 2023 +++ src/tests/usr.bin/indent/lsym_lbrace.c Fri Jun 16 23:19:01 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: lsym_lbrace.c,v 1.9 2023/06/15 09:19:07 rillig Exp $ */ +/* $NetBSD: lsym_lbrace.c,v 1.10 2023/06/16 23:19:01 rillig Exp $ */ /* * Tests for the token lsym_lbrace, which represents a '{' in these contexts: @@ -99,9 +99,9 @@ origin(void) switch (expr rparen { } } -exit 1 -error: Standard Input:2: Unbalanced parentheses -error: Standard Input:4: Unbalanced parentheses +// exit 1 +// error: Standard Input:2: Unbalanced parentheses +// error: Standard Input:4: Unbalanced parentheses //indent end Index: src/tests/usr.bin/indent/lsym_preprocessing.c diff -u src/tests/usr.bin/indent/lsym_preprocessing.c:1.14 src/tests/usr.bin/indent/lsym_preprocessing.c:1.15 --- src/tests/usr.bin/indent/lsym_preprocessing.c:1.14 Wed Jun 14 20:46:08 2023 +++ src/tests/usr.bin/indent/lsym_preprocessing.c Fri Jun 16 23:19:01 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: lsym_preprocessing.c,v 1.14 2023/06/14 20:46:08 rillig Exp $ */ +/* $NetBSD: lsym_preprocessing.c,v 1.15 2023/06/16 23:19:01 rillig Exp $ */ /* * Tests for the token lsym_preprocessing, which represents a '#' that starts @@ -301,11 +301,11 @@ int before; #unknown # 3 "file.c" -exit 1 -error: Standard Input:1: Unmatched #else -error: Standard Input:2: Unmatched #elif -error: Standard Input:3: Unmatched #elifdef -error: Standard Input:4: Unmatched #endif +// exit 1 +// error: Standard Input:1: Unmatched #else +// error: Standard Input:2: Unmatched #elif +// error: Standard Input:3: Unmatched #elifdef +// error: Standard Input:4: Unmatched #endif //indent end Index: src/tests/usr.bin/indent/lsym_semicolon.c diff -u src/tests/usr.bin/indent/lsym_semicolon.c:1.5 src/tests/usr.bin/indent/lsym_semicolon.c:1.6 --- src/tests/usr.bin/indent/lsym_semicolon.c:1.5 Thu Jun 15 09:19:07 2023 +++ src/tests/usr.bin/indent/lsym_semicolon.c Fri Jun 16 23:19:01 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: lsym_semicolon.c,v 1.5 2023/06/15 09:19:07 rillig Exp $ */ +/* $NetBSD: lsym_semicolon.c,v 1.6 2023/06/16 23:19:01 rillig Exp $ */ /* * Tests for the token lsym_semicolon, which represents ';' in these contexts: @@ -84,8 +84,8 @@ int b = 3; //indent run -di0 int a = {{; int b = 3; -exit 1 -error: Standard Input:2: Stuff missing from end of file +// exit 1 +// error: Standard Input:2: Stuff missing from end of file //indent end @@ -101,6 +101,6 @@ error: Standard Input:2: Stuff missing f int a = {{; int b = 3; } -exit 1 -error: Standard Input:4: Stuff missing from end of file +// exit 1 +// error: Standard Input:4: Stuff missing from end of file //indent end Index: src/tests/usr.bin/indent/t_options.lua diff -u src/tests/usr.bin/indent/t_options.lua:1.5 src/tests/usr.bin/indent/t_options.lua:1.6 --- src/tests/usr.bin/indent/t_options.lua:1.5 Wed Jun 14 17:07:32 2023 +++ src/tests/usr.bin/indent/t_options.lua Fri Jun 16 23:19:01 2023 @@ -1,4 +1,4 @@ --- $NetBSD: t_options.lua,v 1.5 2023/06/14 17:07:32 rillig Exp $ +-- $NetBSD: t_options.lua,v 1.6 2023/06/16
CVS commit: src/tests/usr.bin/indent
Module Name:src Committed By: rillig Date: Fri Jun 16 23:19:01 UTC 2023 Modified Files: src/tests/usr.bin/indent: fmt_expr.c lsym_lbrace.c lsym_preprocessing.c lsym_semicolon.c psym_else.c psym_rbrace.c t_options.lua Log Message: tests/indent: format stderr output as end-of-line comments This generates fewer error markers in syntax-aware editors. To generate a diff of this commit: cvs rdiff -u -r1.9 -r1.10 src/tests/usr.bin/indent/fmt_expr.c \ src/tests/usr.bin/indent/lsym_lbrace.c cvs rdiff -u -r1.14 -r1.15 src/tests/usr.bin/indent/lsym_preprocessing.c cvs rdiff -u -r1.5 -r1.6 src/tests/usr.bin/indent/lsym_semicolon.c \ src/tests/usr.bin/indent/t_options.lua cvs rdiff -u -r1.6 -r1.7 src/tests/usr.bin/indent/psym_else.c cvs rdiff -u -r1.4 -r1.5 src/tests/usr.bin/indent/psym_rbrace.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/tests/usr.bin/indent
Module Name:src Committed By: rillig Date: Fri Jun 16 13:43:30 UTC 2023 Modified Files: src/tests/usr.bin/indent: lsym_rparen_or_rbracket.c Log Message: tests/indent: add a few code snippets from usr.bin/xlint To generate a diff of this commit: cvs rdiff -u -r1.5 -r1.6 src/tests/usr.bin/indent/lsym_rparen_or_rbracket.c 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/lsym_rparen_or_rbracket.c diff -u src/tests/usr.bin/indent/lsym_rparen_or_rbracket.c:1.5 src/tests/usr.bin/indent/lsym_rparen_or_rbracket.c:1.6 --- src/tests/usr.bin/indent/lsym_rparen_or_rbracket.c:1.5 Thu Jun 15 09:19:07 2023 +++ src/tests/usr.bin/indent/lsym_rparen_or_rbracket.c Fri Jun 16 13:43:30 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: lsym_rparen_or_rbracket.c,v 1.5 2023/06/15 09:19:07 rillig Exp $ */ +/* $NetBSD: lsym_rparen_or_rbracket.c,v 1.6 2023/06/16 13:43:30 rillig Exp $ */ /* * Tests for the token lsym_rparen_or_lbracket, which represents ')' or ']', @@ -54,3 +54,24 @@ int a = array[ ]; } //indent end + + +//indent input +{ + dcs_align((u_int)dcs); + mpools.pools[i] = (memory_pool){NULL, 0, 0}; + list_add(l, (const char[3]){'-', (char)c, '\0'}); +} +//indent end + +//indent run -ci4 -di0 -nlp +{ +// $ FIXME: No space after cast. + dcs_align((u_int) dcs); +// $ FIXME: Don't add newlines. + mpools.pools[i] = (memory_pool) { + NULL, 0, 0 + }; + list_add(l, (const char[3]){'-', (char)c, '\0'}); +} +//indent end
CVS commit: src/tests/usr.bin/indent
Module Name:src Committed By: rillig Date: Fri Jun 16 13:43:30 UTC 2023 Modified Files: src/tests/usr.bin/indent: lsym_rparen_or_rbracket.c Log Message: tests/indent: add a few code snippets from usr.bin/xlint To generate a diff of this commit: cvs rdiff -u -r1.5 -r1.6 src/tests/usr.bin/indent/lsym_rparen_or_rbracket.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/tests/usr.bin/indent
Module Name:src Committed By: rillig Date: Fri Jun 16 11:58:33 UTC 2023 Modified Files: src/tests/usr.bin/indent: lsym_typedef.c Log Message: tests/indent: demonstrate wrong tokenization after typedef Since 2023-06-10 06:52, which fixed the indentation of C11 _Generic expressions. To generate a diff of this commit: cvs rdiff -u -r1.6 -r1.7 src/tests/usr.bin/indent/lsym_typedef.c 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/lsym_typedef.c diff -u src/tests/usr.bin/indent/lsym_typedef.c:1.6 src/tests/usr.bin/indent/lsym_typedef.c:1.7 --- src/tests/usr.bin/indent/lsym_typedef.c:1.6 Sun Apr 24 10:36:37 2022 +++ src/tests/usr.bin/indent/lsym_typedef.c Fri Jun 16 11:58:33 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: lsym_typedef.c,v 1.6 2022/04/24 10:36:37 rillig Exp $ */ +/* $NetBSD: lsym_typedef.c,v 1.7 2023/06/16 11:58:33 rillig Exp $ */ /* * Tests for the token lsym_typedef, which represents the keyword 'typedef' @@ -59,3 +59,25 @@ typedef int number; //indent end //indent run-equals-input + + +/* + * Ensure that a typedef declaration does not introduce an unnecessary line + * break after the '}'. + */ +//indent input +typedef struct { + int member; + bool bit:1; +} typedef_name; +//indent end + +//indent run -di0 +typedef struct { + int member; +// $ FIXME: No space after the ':' here. + bool bit: 1; +} +// $ FIXME: No linebreak here. +typedef_name; +//indent end
CVS commit: src/tests/usr.bin/indent
Module Name:src Committed By: rillig Date: Fri Jun 16 11:58:33 UTC 2023 Modified Files: src/tests/usr.bin/indent: lsym_typedef.c Log Message: tests/indent: demonstrate wrong tokenization after typedef Since 2023-06-10 06:52, which fixed the indentation of C11 _Generic expressions. To generate a diff of this commit: cvs rdiff -u -r1.6 -r1.7 src/tests/usr.bin/indent/lsym_typedef.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/tests/usr.bin/indent
Module Name:src Committed By: rillig Date: Wed Jun 14 17:07:33 UTC 2023 Modified Files: src/tests/usr.bin/indent: fmt_expr.c lsym_preprocessing.c psym_else.c t_options.lua Log Message: tests/indent: separate stdout from stderr Due to buffering, there was no guarantee that the output would be exactly in the same order as written in the tests. To generate a diff of this commit: cvs rdiff -u -r1.7 -r1.8 src/tests/usr.bin/indent/fmt_expr.c cvs rdiff -u -r1.12 -r1.13 src/tests/usr.bin/indent/lsym_preprocessing.c cvs rdiff -u -r1.5 -r1.6 src/tests/usr.bin/indent/psym_else.c cvs rdiff -u -r1.4 -r1.5 src/tests/usr.bin/indent/t_options.lua 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/fmt_expr.c diff -u src/tests/usr.bin/indent/fmt_expr.c:1.7 src/tests/usr.bin/indent/fmt_expr.c:1.8 --- src/tests/usr.bin/indent/fmt_expr.c:1.7 Sat Jun 10 08:17:04 2023 +++ src/tests/usr.bin/indent/fmt_expr.c Wed Jun 14 17:07:32 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: fmt_expr.c,v 1.7 2023/06/10 08:17:04 rillig Exp $ */ +/* $NetBSD: fmt_expr.c,v 1.8 2023/06/14 17:07:32 rillig Exp $ */ /* * Tests for all kinds of expressions that are not directly related to unary @@ -44,8 +44,6 @@ //indent end //indent run -di0 -error: Standard Input:7: Unbalanced parentheses -warning: Standard Input:9: Extra ')' { int var = ({1}); int var = ({ @@ -57,4 +55,6 @@ warning: Standard Input:9: Extra ')' }); } exit 1 +error: Standard Input:7: Unbalanced parentheses +warning: Standard Input:9: Extra ')' //indent end Index: src/tests/usr.bin/indent/lsym_preprocessing.c diff -u src/tests/usr.bin/indent/lsym_preprocessing.c:1.12 src/tests/usr.bin/indent/lsym_preprocessing.c:1.13 --- src/tests/usr.bin/indent/lsym_preprocessing.c:1.12 Wed Jun 14 10:29:52 2023 +++ src/tests/usr.bin/indent/lsym_preprocessing.c Wed Jun 14 17:07:32 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: lsym_preprocessing.c,v 1.12 2023/06/14 10:29:52 rillig Exp $ */ +/* $NetBSD: lsym_preprocessing.c,v 1.13 2023/06/14 17:07:32 rillig Exp $ */ /* * Tests for the token lsym_preprocessing, which represents a '#' that starts @@ -294,10 +294,6 @@ int before; //indent end //indent run -error: Standard Input:1: Unmatched #else -error: Standard Input:2: Unmatched #elif -error: Standard Input:3: Unmatched #elifdef -error: Standard Input:4: Unmatched #endif #else #elif 0 #elifdef var @@ -306,4 +302,8 @@ error: Standard Input:4: Unmatched #endi #unknown # 3 "file.c" exit 1 +error: Standard Input:1: Unmatched #else +error: Standard Input:2: Unmatched #elif +error: Standard Input:3: Unmatched #elifdef +error: Standard Input:4: Unmatched #endif //indent end Index: src/tests/usr.bin/indent/psym_else.c diff -u src/tests/usr.bin/indent/psym_else.c:1.5 src/tests/usr.bin/indent/psym_else.c:1.6 --- src/tests/usr.bin/indent/psym_else.c:1.5 Sat Jun 10 17:35:41 2023 +++ src/tests/usr.bin/indent/psym_else.c Wed Jun 14 17:07:32 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: psym_else.c,v 1.5 2023/06/10 17:35:41 rillig Exp $ */ +/* $NetBSD: psym_else.c,v 1.6 2023/06/14 17:07:32 rillig Exp $ */ /* * Tests for the parser symbol psym_else, which represents the keyword 'else' @@ -80,9 +80,9 @@ function(void) //indent end //indent run -error: Standard Input:2: Unmatched 'else' { else } exit 1 +error: Standard Input:2: Unmatched 'else' //indent end Index: src/tests/usr.bin/indent/t_options.lua diff -u src/tests/usr.bin/indent/t_options.lua:1.4 src/tests/usr.bin/indent/t_options.lua:1.5 --- src/tests/usr.bin/indent/t_options.lua:1.4 Mon May 22 06:35:56 2023 +++ src/tests/usr.bin/indent/t_options.lua Wed Jun 14 17:07:32 2023 @@ -1,4 +1,4 @@ --- $NetBSD: t_options.lua,v 1.4 2023/05/22 06:35:56 rillig Exp $ +-- $NetBSD: t_options.lua,v 1.5 2023/06/14 17:07:32 rillig Exp $ -- -- Copyright (c) 2023 The NetBSD Foundation, Inc. -- All rights reserved. @@ -126,7 +126,7 @@ end local function run_indent(inp, args) local indent = os.getenv("INDENT") or "indent" - local cmd = indent .. " " .. args .. " 2>&1" + local cmd = indent .. " " .. args .. " 2>t_options.err" local indent_in = assert(io.popen(cmd, "w")) indent_in:write(inp) @@ -134,6 +134,9 @@ local function run_indent(inp, args) if not ok then print(kind .. " " .. info) end + for line in io.lines("t_options.err") do + print(line) + end end local function handle_empty_section(line)
CVS commit: src/tests/usr.bin/indent
Module Name:src Committed By: rillig Date: Wed Jun 14 17:07:33 UTC 2023 Modified Files: src/tests/usr.bin/indent: fmt_expr.c lsym_preprocessing.c psym_else.c t_options.lua Log Message: tests/indent: separate stdout from stderr Due to buffering, there was no guarantee that the output would be exactly in the same order as written in the tests. To generate a diff of this commit: cvs rdiff -u -r1.7 -r1.8 src/tests/usr.bin/indent/fmt_expr.c cvs rdiff -u -r1.12 -r1.13 src/tests/usr.bin/indent/lsym_preprocessing.c cvs rdiff -u -r1.5 -r1.6 src/tests/usr.bin/indent/psym_else.c cvs rdiff -u -r1.4 -r1.5 src/tests/usr.bin/indent/t_options.lua Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/tests/usr.bin/indent
Module Name:src Committed By: rillig Date: Sat Jun 10 17:56:29 UTC 2023 Modified Files: src/tests/usr.bin/indent: fmt_decl.c psym_if_expr.c Log Message: tests/indent: add move coverage tests To generate a diff of this commit: cvs rdiff -u -r1.53 -r1.54 src/tests/usr.bin/indent/fmt_decl.c cvs rdiff -u -r1.4 -r1.5 src/tests/usr.bin/indent/psym_if_expr.c 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/fmt_decl.c diff -u src/tests/usr.bin/indent/fmt_decl.c:1.53 src/tests/usr.bin/indent/fmt_decl.c:1.54 --- src/tests/usr.bin/indent/fmt_decl.c:1.53 Sat Jun 10 06:38:21 2023 +++ src/tests/usr.bin/indent/fmt_decl.c Sat Jun 10 17:56:29 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: fmt_decl.c,v 1.53 2023/06/10 06:38:21 rillig Exp $ */ +/* $NetBSD: fmt_decl.c,v 1.54 2023/06/10 17:56:29 rillig Exp $ */ /* * Tests for declarations of global variables, external functions, and local @@ -1069,3 +1069,19 @@ b[] = {1, 2}; b[] = {1, 2}; } //indent end + + +/* + * When a type occurs at the top level, it forces a line break before. + */ +//indent input +__attribute__((__dead__)) void die(void) {} +//indent end + +//indent run +__attribute__((__dead__)) +void +die(void) +{ +} +//indent end Index: src/tests/usr.bin/indent/psym_if_expr.c diff -u src/tests/usr.bin/indent/psym_if_expr.c:1.4 src/tests/usr.bin/indent/psym_if_expr.c:1.5 --- src/tests/usr.bin/indent/psym_if_expr.c:1.4 Sun Apr 24 09:04:12 2022 +++ src/tests/usr.bin/indent/psym_if_expr.c Sat Jun 10 17:56:29 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: psym_if_expr.c,v 1.4 2022/04/24 09:04:12 rillig Exp $ */ +/* $NetBSD: psym_if_expr.c,v 1.5 2023/06/10 17:56:29 rillig Exp $ */ /* * Tests for the parser symbol psym_if_expr, representing the parser state @@ -20,3 +20,27 @@ function(void) stmt(); } //indent end + + +/* + * Indent is forgiving about syntax errors such as an 'if' statement in which + * the condition is not parenthesized. + */ +//indent input +{ + if cond { + } + if cond && cond { + } +} +//indent end + +//indent run +{ + if cond { + } + if cond + && cond { + } +} +//indent end
CVS commit: src/tests/usr.bin/indent
Module Name:src Committed By: rillig Date: Sat Jun 10 17:56:29 UTC 2023 Modified Files: src/tests/usr.bin/indent: fmt_decl.c psym_if_expr.c Log Message: tests/indent: add move coverage tests To generate a diff of this commit: cvs rdiff -u -r1.53 -r1.54 src/tests/usr.bin/indent/fmt_decl.c cvs rdiff -u -r1.4 -r1.5 src/tests/usr.bin/indent/psym_if_expr.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/tests/usr.bin/indent
Module Name:src Committed By: rillig Date: Fri Jun 9 09:45:55 UTC 2023 Modified Files: src/tests/usr.bin/indent: fmt_decl.c fmt_expr.c psym_stmt.c Log Message: tests/indent: add real-life test cases from make(1) and lint(1) To generate a diff of this commit: cvs rdiff -u -r1.50 -r1.51 src/tests/usr.bin/indent/fmt_decl.c cvs rdiff -u -r1.4 -r1.5 src/tests/usr.bin/indent/fmt_expr.c \ src/tests/usr.bin/indent/psym_stmt.c 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/fmt_decl.c diff -u src/tests/usr.bin/indent/fmt_decl.c:1.50 src/tests/usr.bin/indent/fmt_decl.c:1.51 --- src/tests/usr.bin/indent/fmt_decl.c:1.50 Thu Jun 8 21:18:54 2023 +++ src/tests/usr.bin/indent/fmt_decl.c Fri Jun 9 09:45:55 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: fmt_decl.c,v 1.50 2023/06/08 21:18:54 rillig Exp $ */ +/* $NetBSD: fmt_decl.c,v 1.51 2023/06/09 09:45:55 rillig Exp $ */ /* * Tests for declarations of global variables, external functions, and local @@ -153,6 +153,7 @@ t2(char *x, int y) //indent input const int int_minimum_size = +// $ FIXME: Missing indentation. MAXALIGN(offsetof(int, test)) + MAXIMUM_ALIGNOF; //indent end @@ -1002,3 +1003,49 @@ struct a { //indent end //indent run-equals-input -di0 + + +//indent input +static FILE *ArchFindMember(const char *, const char *, + struct ar_hdr *, const char *); + +bool +Job_CheckCommands(GNode *gn, void (*abortProc)(const char *, ...)) +{ +} + +static void MAKE_ATTR_PRINTFLIKE(5, 0) +ParseVErrorInternal(FILE *f, bool useVars, const GNode *gn, + ParseErrorLevel level, const char *fmt, va_list ap) +{ +} + +typedef struct { + const char *m_name; +} mod_t; +//indent end + +//indent run -fbs -di0 -psl +// $ FIXME: Must be detected as a function declaration, not a definition. +static FILE * +ArchFindMember(const char *, const char *, + struct ar_hdr *, const char *); + +bool +Job_CheckCommands(GNode *gn, void (*abortProc)(const char *, ...)) +{ +} + +static void +MAKE_ATTR_PRINTFLIKE(5, 0) +ParseVErrorInternal(FILE *f, bool useVars, const GNode *gn, + ParseErrorLevel level, const char *fmt, va_list ap) +{ +} + +typedef struct { + const char *m_name; +} +// $ FIXME: Remove this line break. +mod_t; +//indent end Index: src/tests/usr.bin/indent/fmt_expr.c diff -u src/tests/usr.bin/indent/fmt_expr.c:1.4 src/tests/usr.bin/indent/fmt_expr.c:1.5 --- src/tests/usr.bin/indent/fmt_expr.c:1.4 Sun Apr 24 09:04:12 2022 +++ src/tests/usr.bin/indent/fmt_expr.c Fri Jun 9 09:45:55 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: fmt_expr.c,v 1.4 2022/04/24 09:04:12 rillig Exp $ */ +/* $NetBSD: fmt_expr.c,v 1.5 2023/06/09 09:45:55 rillig Exp $ */ /* * Tests for all kinds of expressions that are not directly related to unary @@ -23,3 +23,14 @@ t(void) int n = malloc(offsetof(struct s, f) + 1); } //indent end + + +//indent input +{ + for (ln = gnodes->first; ln != NULL; ln = ln->next) +// $ FIXME: No space after the cast. + *(GNode **) Vector_Push() = ln->datum; +} +//indent end + +//indent run-equals-input Index: src/tests/usr.bin/indent/psym_stmt.c diff -u src/tests/usr.bin/indent/psym_stmt.c:1.4 src/tests/usr.bin/indent/psym_stmt.c:1.5 --- src/tests/usr.bin/indent/psym_stmt.c:1.4 Sun Apr 24 10:36:37 2022 +++ src/tests/usr.bin/indent/psym_stmt.c Fri Jun 9 09:45:55 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: psym_stmt.c,v 1.4 2022/04/24 10:36:37 rillig Exp $ */ +/* $NetBSD: psym_stmt.c,v 1.5 2023/06/09 09:45:55 rillig Exp $ */ /* * Tests for the parser symbol psym_stmt, which represents a statement on the @@ -26,3 +26,18 @@ function(void) * syntactic macro, especially not when its definition is in a header file. */ //indent run-equals-input + + +//indent input +{ + TAILQ_FOREACH(a, b, c) { + a = +// $ FIXME: The 'b' must be indented as a continuation. +// $ The '{' in line 2 sets ps.block_init though, even though it does not +// $ follow a '='. + b; + } +} +//indent end + +//indent run-equals-input -di0 -nlp -ci4
CVS commit: src/tests/usr.bin/indent
Module Name:src Committed By: rillig Date: Fri Jun 9 09:45:55 UTC 2023 Modified Files: src/tests/usr.bin/indent: fmt_decl.c fmt_expr.c psym_stmt.c Log Message: tests/indent: add real-life test cases from make(1) and lint(1) To generate a diff of this commit: cvs rdiff -u -r1.50 -r1.51 src/tests/usr.bin/indent/fmt_decl.c cvs rdiff -u -r1.4 -r1.5 src/tests/usr.bin/indent/fmt_expr.c \ src/tests/usr.bin/indent/psym_stmt.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/tests/usr.bin/indent
Module Name:src Committed By: rillig Date: Fri Jun 9 07:54:05 UTC 2023 Modified Files: src/tests/usr.bin/indent: opt_eei.c Log Message: tests/indent: test extra indentation in expressions To generate a diff of this commit: cvs rdiff -u -r1.12 -r1.13 src/tests/usr.bin/indent/opt_eei.c 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/opt_eei.c diff -u src/tests/usr.bin/indent/opt_eei.c:1.12 src/tests/usr.bin/indent/opt_eei.c:1.13 --- src/tests/usr.bin/indent/opt_eei.c:1.12 Mon May 15 13:33:19 2023 +++ src/tests/usr.bin/indent/opt_eei.c Fri Jun 9 07:54:05 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: opt_eei.c,v 1.12 2023/05/15 13:33:19 rillig Exp $ */ +/* $NetBSD: opt_eei.c,v 1.13 2023/06/09 07:54:05 rillig Exp $ */ /* * Tests for the options '-eei' and '-neei'. @@ -187,3 +187,62 @@ b) ); } //indent end + + +/* + * When multi-line expressions are aligned on the parentheses, they may have an + * ambiguous indentation as well. + */ +//indent input +{ + if (fun( + 1, + 2, + 3)) + stmt; +} +//indent end + +//indent run-equals-input + +//indent run -eei +{ + if (fun( +// $ TODO: Indent one level further. + 1, + 2, + 3)) + stmt; +} +//indent end + + +/* + * + */ +//indent input +{ + if ((( + 3 + ))) + stmt; + if + 4 + + stmt; +} +//indent end + +//indent run -ci2 -nlp -eei +{ + if ((( + 3 + ))) + stmt; +// $ XXX: The indentation of '4' may be considered ambiguous. + if + 4 + + stmt; +} +//indent end
CVS commit: src/tests/usr.bin/indent
Module Name:src Committed By: rillig Date: Fri Jun 9 07:54:05 UTC 2023 Modified Files: src/tests/usr.bin/indent: opt_eei.c Log Message: tests/indent: test extra indentation in expressions To generate a diff of this commit: cvs rdiff -u -r1.12 -r1.13 src/tests/usr.bin/indent/opt_eei.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/tests/usr.bin/indent
Module Name:src Committed By: rillig Date: Thu Jun 8 20:49:04 UTC 2023 Modified Files: src/tests/usr.bin/indent: lsym_lparen_or_lbracket.c lsym_unary_op.c Log Message: tests/indent: add more tests, from indent's own code To generate a diff of this commit: cvs rdiff -u -r1.13 -r1.14 src/tests/usr.bin/indent/lsym_lparen_or_lbracket.c cvs rdiff -u -r1.8 -r1.9 src/tests/usr.bin/indent/lsym_unary_op.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/tests/usr.bin/indent
Module Name:src Committed By: rillig Date: Thu Jun 8 20:49:04 UTC 2023 Modified Files: src/tests/usr.bin/indent: lsym_lparen_or_lbracket.c lsym_unary_op.c Log Message: tests/indent: add more tests, from indent's own code To generate a diff of this commit: cvs rdiff -u -r1.13 -r1.14 src/tests/usr.bin/indent/lsym_lparen_or_lbracket.c cvs rdiff -u -r1.8 -r1.9 src/tests/usr.bin/indent/lsym_unary_op.c 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/lsym_lparen_or_lbracket.c diff -u src/tests/usr.bin/indent/lsym_lparen_or_lbracket.c:1.13 src/tests/usr.bin/indent/lsym_lparen_or_lbracket.c:1.14 --- src/tests/usr.bin/indent/lsym_lparen_or_lbracket.c:1.13 Sun Jun 4 18:58:30 2023 +++ src/tests/usr.bin/indent/lsym_lparen_or_lbracket.c Thu Jun 8 20:49:04 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: lsym_lparen_or_lbracket.c,v 1.13 2023/06/04 18:58:30 rillig Exp $ */ +/* $NetBSD: lsym_lparen_or_lbracket.c,v 1.14 2023/06/08 20:49:04 rillig Exp $ */ /* * Tests for the token lsym_lparen_or_lbracket, which represents a '(' or '[' @@ -336,3 +336,19 @@ cover_want_blank_before_lparen(void) //indent end /* See t_errors.sh, test case 'compound_literal'. */ + + +//indent input +int arr[] = { +['0'] = 1, +['1'] = 2, +}; +//indent end + +//indent run -di0 +int arr[] = { + ['0'] = 1, +// $ FIXME: 1 space extra indentation. + ['1'] = 2, +}; +//indent end Index: src/tests/usr.bin/indent/lsym_unary_op.c diff -u src/tests/usr.bin/indent/lsym_unary_op.c:1.8 src/tests/usr.bin/indent/lsym_unary_op.c:1.9 --- src/tests/usr.bin/indent/lsym_unary_op.c:1.8 Fri Jun 2 14:21:55 2023 +++ src/tests/usr.bin/indent/lsym_unary_op.c Thu Jun 8 20:49:04 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: lsym_unary_op.c,v 1.8 2023/06/02 14:21:55 rillig Exp $ */ +/* $NetBSD: lsym_unary_op.c,v 1.9 2023/06/08 20:49:04 rillig Exp $ */ /* * Tests for the token lsym_unary_op, which represents a unary operator. @@ -82,6 +82,8 @@ unary_operators(void) //indent input { sbuf_t *sb = *(sbuf_t **)sp; +return (int)(a * (float)b); +a = (2 * b == c); } //indent end @@ -89,5 +91,9 @@ sbuf_t *sb = *(sbuf_t **)sp; { // $ FIXME: Wrong spacing after the cast. sbuf_t *sb = *(sbuf_t **) sp; +// $ FIXME: Wrong spacing after the '*'. + return (int)(a *(float)b); +// $ FIXME: Wrong spacing after the '*'. + a = (2 *b == c); } //indent end
CVS commit: src/tests/usr.bin/indent
Module Name:src Committed By: rillig Date: Thu Jun 8 20:28:50 UTC 2023 Modified Files: src/tests/usr.bin/indent: opt_lp.c Log Message: tests/indent: extend test for wrong indentation in 'else if' To generate a diff of this commit: cvs rdiff -u -r1.7 -r1.8 src/tests/usr.bin/indent/opt_lp.c 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/opt_lp.c diff -u src/tests/usr.bin/indent/opt_lp.c:1.7 src/tests/usr.bin/indent/opt_lp.c:1.8 --- src/tests/usr.bin/indent/opt_lp.c:1.7 Tue May 23 06:18:00 2023 +++ src/tests/usr.bin/indent/opt_lp.c Thu Jun 8 20:28:50 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: opt_lp.c,v 1.7 2023/05/23 06:18:00 rillig Exp $ */ +/* $NetBSD: opt_lp.c,v 1.8 2023/06/08 20:28:50 rillig Exp $ */ /* * Tests for the options '-lp' and '-nlp'. @@ -91,21 +91,52 @@ example(void) //indent input { -if (cond) { -} else if (cond && -cond && -cond) { +if (cond11a +&& cond11b +&& cond11c) { +stmt11; +} else if (cond12a +&& cond12b +&& cond12c) { +stmt12; } } + +{ +if (cond21a +&& cond21b +&& cond21c) +stmt21; +else if (cond22a +&& cond22b +&& cond22c) +stmt22; +} //indent end //indent run -ci4 -nlp { - if (cond) { - } else if (cond && + if (cond11a + && cond11b + && cond11c) { + stmt11; + } else if (cond12a // $ FIXME: Wrong indentation, should be 4 spaces only. - cond && - cond) { + && cond12b + && cond12c) { + stmt12; } } + +{ + if (cond21a + && cond21b + && cond21c) + stmt21; + else if (cond22a +// $ FIXME: Wrong indentation, should be 4 spaces only. + && cond22b + && cond22c) + stmt22; +} //indent end
CVS commit: src/tests/usr.bin/indent
Module Name:src Committed By: rillig Date: Thu Jun 8 20:28:50 UTC 2023 Modified Files: src/tests/usr.bin/indent: opt_lp.c Log Message: tests/indent: extend test for wrong indentation in 'else if' To generate a diff of this commit: cvs rdiff -u -r1.7 -r1.8 src/tests/usr.bin/indent/opt_lp.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/tests/usr.bin/indent
Module Name:src Committed By: rillig Date: Tue Jun 6 05:39:49 UTC 2023 Modified Files: src/tests/usr.bin/indent: lsym_comment.c Log Message: tests/indent: comments with trailing whitespace may fit in a single line To generate a diff of this commit: cvs rdiff -u -r1.16 -r1.17 src/tests/usr.bin/indent/lsym_comment.c 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/lsym_comment.c diff -u src/tests/usr.bin/indent/lsym_comment.c:1.16 src/tests/usr.bin/indent/lsym_comment.c:1.17 --- src/tests/usr.bin/indent/lsym_comment.c:1.16 Mon Jun 5 08:22:00 2023 +++ src/tests/usr.bin/indent/lsym_comment.c Tue Jun 6 05:39:49 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: lsym_comment.c,v 1.16 2023/06/05 08:22:00 rillig Exp $ */ +/* $NetBSD: lsym_comment.c,v 1.17 2023/06/06 05:39:49 rillig Exp $ */ /* * Tests for the token lsym_comment, which starts a comment. @@ -371,6 +371,25 @@ tab1+++ tab2--- tab3+++ tab4--- tab5+++ /* + * TODO: Trailing whitespace in a comment is ignored when determining whether the + * comment fits in a single line. + */ +//indent input +/* 456789 123456789 123456789 12345 */ +/* 456789 123456789 123456789 123456 */ +//indent end + +//indent run -l38 +/* + * 456789 123456789 123456789 12345 + */ +/* + * 456789 123456789 123456789 123456 + */ +//indent end + + +/* * The following comments test line breaking when the comment does not end * with a space. Since indent adds a trailing space to a single-line comment, * this space has to be taken into account when computing the line length.
CVS commit: src/tests/usr.bin/indent
Module Name:src Committed By: rillig Date: Tue Jun 6 05:39:49 UTC 2023 Modified Files: src/tests/usr.bin/indent: lsym_comment.c Log Message: tests/indent: comments with trailing whitespace may fit in a single line To generate a diff of this commit: cvs rdiff -u -r1.16 -r1.17 src/tests/usr.bin/indent/lsym_comment.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/tests/usr.bin/indent
Module Name:src Committed By: rillig Date: Mon Jun 5 15:02:54 UTC 2023 Modified Files: src/tests/usr.bin/indent: fmt_decl.c opt_dj.c Log Message: tests/indent: add test for left-justifying declarations To generate a diff of this commit: cvs rdiff -u -r1.48 -r1.49 src/tests/usr.bin/indent/fmt_decl.c cvs rdiff -u -r1.7 -r1.8 src/tests/usr.bin/indent/opt_dj.c 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/fmt_decl.c diff -u src/tests/usr.bin/indent/fmt_decl.c:1.48 src/tests/usr.bin/indent/fmt_decl.c:1.49 --- src/tests/usr.bin/indent/fmt_decl.c:1.48 Fri Jun 2 14:34:14 2023 +++ src/tests/usr.bin/indent/fmt_decl.c Mon Jun 5 15:02:54 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: fmt_decl.c,v 1.48 2023/06/02 14:34:14 rillig Exp $ */ +/* $NetBSD: fmt_decl.c,v 1.49 2023/06/05 15:02:54 rillig Exp $ */ /* * Tests for declarations of global variables, external functions, and local @@ -974,3 +974,21 @@ void { } //indent end + + +//indent input +struct a { + struct b { + struct c { + struct d1 { +int e; + } d1; + struct d2 { +int e; + } d2; + } c; + } b; +}; +//indent end + +//indent run-equals-input -di0 Index: src/tests/usr.bin/indent/opt_dj.c diff -u src/tests/usr.bin/indent/opt_dj.c:1.7 src/tests/usr.bin/indent/opt_dj.c:1.8 --- src/tests/usr.bin/indent/opt_dj.c:1.7 Sun Apr 24 09:04:12 2022 +++ src/tests/usr.bin/indent/opt_dj.c Mon Jun 5 15:02:54 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: opt_dj.c,v 1.7 2022/04/24 09:04:12 rillig Exp $ */ +/* $NetBSD: opt_dj.c,v 1.8 2023/06/05 15:02:54 rillig Exp $ */ /* * Tests for the options '-dj' and '-ndj'. @@ -76,3 +76,77 @@ dbl_plus3(a, b, c) return a + b + c; } //indent end + + +//indent input +struct a { + struct b { + struct c { + struct d1 { +int e; + } d1; + struct d2 { +int e; + } d2; + } c; + } b; +}; +//indent end + +//indent run -d0 +struct a { + struct b { + struct c { + struct d1 { +int e; + } d1; + struct d2 { +int e; + } d2; + } c; + } b; +}; +//indent end + +//indent run-equals-input -di0 + +//indent run-equals-prev-output -dj + + +//indent input +{ + { + struct a { + struct b { +struct c { + struct d1 { + int e; + } d1; + struct d2 { + int e; + } d2; +} c; + } b; + }; + } +} +//indent end + +//indent run -dj +{ + { +struct a { + struct b { + struct c { + struct d1 { +int e; + } d1; + struct d2 { +int e; + } d2; + } c; + } b; +}; + } +} +//indent end
CVS commit: src/tests/usr.bin/indent
Module Name:src Committed By: rillig Date: Mon Jun 5 15:02:54 UTC 2023 Modified Files: src/tests/usr.bin/indent: fmt_decl.c opt_dj.c Log Message: tests/indent: add test for left-justifying declarations To generate a diff of this commit: cvs rdiff -u -r1.48 -r1.49 src/tests/usr.bin/indent/fmt_decl.c cvs rdiff -u -r1.7 -r1.8 src/tests/usr.bin/indent/opt_dj.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/tests/usr.bin/indent
Module Name:src Committed By: rillig Date: Mon Jun 5 08:10:25 UTC 2023 Modified Files: src/tests/usr.bin/indent: lsym_do.c psym_do.c Log Message: tests/indent: add tests for 'do-while' loops To generate a diff of this commit: cvs rdiff -u -r1.7 -r1.8 src/tests/usr.bin/indent/lsym_do.c cvs rdiff -u -r1.4 -r1.5 src/tests/usr.bin/indent/psym_do.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/tests/usr.bin/indent
Module Name:src Committed By: rillig Date: Mon Jun 5 08:10:25 UTC 2023 Modified Files: src/tests/usr.bin/indent: lsym_do.c psym_do.c Log Message: tests/indent: add tests for 'do-while' loops To generate a diff of this commit: cvs rdiff -u -r1.7 -r1.8 src/tests/usr.bin/indent/lsym_do.c cvs rdiff -u -r1.4 -r1.5 src/tests/usr.bin/indent/psym_do.c 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/lsym_do.c diff -u src/tests/usr.bin/indent/lsym_do.c:1.7 src/tests/usr.bin/indent/lsym_do.c:1.8 --- src/tests/usr.bin/indent/lsym_do.c:1.7 Mon May 22 23:01:27 2023 +++ src/tests/usr.bin/indent/lsym_do.c Mon Jun 5 08:10:25 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: lsym_do.c,v 1.7 2023/05/22 23:01:27 rillig Exp $ */ +/* $NetBSD: lsym_do.c,v 1.8 2023/06/05 08:10:25 rillig Exp $ */ /* * Tests for the token lsym_do, which represents the keyword 'do' that starts @@ -110,3 +110,48 @@ variants(void) } while (0); } //indent end + + +/* Ensure that the 'do' starts a line. */ +//indent input +{ + /* */ do {} while (false); + + word do {} while (false); + + label: do {} while (false); +} +//indent end + +//indent run +{ +// $ FIXME: Trailing whitespace. + /* */ + do { + } while (false); + + word + do { + } while (false); + +label: do { + } while (false); +} +//indent end + +//indent run -sob +{ +// $ FIXME: Trailing whitespace. + /* */ + do { + } while (false); +// $ FIXME: This blank line is not optional and must be preserved. + word + do { +// $ FIXME: The expression is indented too far to the right. + } while (false); +// $ FIXME: This blank line is not optional and must be preserved. +label: do { + } while (false); +} +//indent end Index: src/tests/usr.bin/indent/psym_do.c diff -u src/tests/usr.bin/indent/psym_do.c:1.4 src/tests/usr.bin/indent/psym_do.c:1.5 --- src/tests/usr.bin/indent/psym_do.c:1.4 Sun Apr 24 10:36:37 2022 +++ src/tests/usr.bin/indent/psym_do.c Mon Jun 5 08:10:25 2023 @@ -1,8 +1,12 @@ -/* $NetBSD: psym_do.c,v 1.4 2022/04/24 10:36:37 rillig Exp $ */ +/* $NetBSD: psym_do.c,v 1.5 2023/06/05 08:10:25 rillig Exp $ */ /* * Tests for the parser symbol psym_do, which represents the state after * reading the token 'do', now waiting for the statement of the loop body. + * + * See also: + * lsym_do.c + * psym_do_stmt.c */ //indent input
CVS commit: src/tests/usr.bin/indent
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' +
CVS commit: src/tests/usr.bin/indent
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.
CVS commit: src/tests/usr.bin/indent
Module Name:src Committed By: rillig Date: Sun Jun 4 19:28:54 UTC 2023 Modified Files: src/tests/usr.bin/indent: lex_ident.c lsym_binary_op.c opt_badp.c Log Message: tests/indent: clean up comments To generate a diff of this commit: cvs rdiff -u -r1.6 -r1.7 src/tests/usr.bin/indent/lex_ident.c cvs rdiff -u -r1.7 -r1.8 src/tests/usr.bin/indent/lsym_binary_op.c cvs rdiff -u -r1.11 -r1.12 src/tests/usr.bin/indent/opt_badp.c 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/lex_ident.c diff -u src/tests/usr.bin/indent/lex_ident.c:1.6 src/tests/usr.bin/indent/lex_ident.c:1.7 --- src/tests/usr.bin/indent/lex_ident.c:1.6 Mon May 15 17:28:14 2023 +++ src/tests/usr.bin/indent/lex_ident.c Sun Jun 4 19:28:54 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: lex_ident.c,v 1.6 2023/05/15 17:28:14 rillig Exp $ */ +/* $NetBSD: lex_ident.c,v 1.7 2023/06/04 19:28:54 rillig Exp $ */ /* * Test lexing of word-like tokens, such as keywords, identifiers, numeric @@ -19,15 +19,13 @@ iable; int no_backslash; -/* $ See check_size_token. */ -/* $ The default buffer size is 200, the limit is 195. */ +// $ Test long identifiers, to cover the code that expands a buffer first to +// $ more than 400 bytes and then to more than 1400 bytes. struct long_tag_name_to_overflow_the_token_buffer_4567890\ 12345678901234567890123456789012345678901234567890\ 12345678901234567890123456789012345678901234567890\ 12345678901234567890123456789012345678901234567890; -/* $ See check_size_token. */ -/* $ The difference between limit and start got incremented to 595. */ struct long_tag_name_to_overflow_the_token_buffer_4567890\ 12345678901234567890123456789012345678901234567890\ 12345678901234567890123456789012345678901234567890\ Index: src/tests/usr.bin/indent/lsym_binary_op.c diff -u src/tests/usr.bin/indent/lsym_binary_op.c:1.7 src/tests/usr.bin/indent/lsym_binary_op.c:1.8 --- src/tests/usr.bin/indent/lsym_binary_op.c:1.7 Sat May 13 06:52:48 2023 +++ src/tests/usr.bin/indent/lsym_binary_op.c Sun Jun 4 19:28:54 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: lsym_binary_op.c,v 1.7 2023/05/13 06:52:48 rillig Exp $ */ +/* $NetBSD: lsym_binary_op.c,v 1.8 2023/06/04 19:28:54 rillig Exp $ */ /* * Tests for the token lsym_binary_op, which represents a binary operator in @@ -82,9 +82,9 @@ int var = expr * *ptr; * 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. + * Before 2021-03-07 22:11:01, the comment '//' was treated as a binary + * operator as well, and so was the comment '/', leading to unexpected + * spacing. * * See lexi.c, lexi, "default:". */ Index: src/tests/usr.bin/indent/opt_badp.c diff -u src/tests/usr.bin/indent/opt_badp.c:1.11 src/tests/usr.bin/indent/opt_badp.c:1.12 --- src/tests/usr.bin/indent/opt_badp.c:1.11 Mon May 15 09:05:08 2023 +++ src/tests/usr.bin/indent/opt_badp.c Sun Jun 4 19:28:54 2023 @@ -1,10 +1,11 @@ -/* $NetBSD: opt_badp.c,v 1.11 2023/05/15 09:05:08 rillig Exp $ */ +/* $NetBSD: opt_badp.c,v 1.12 2023/06/04 19:28:54 rillig Exp $ */ /* * Tests for the options '-badp' and '-nbadp'. * - * The option '-badp' forces a blank line after the first set of declarations - * in a function. It produces a blank line even if there are no declarations. + * The option '-badp' forces a blank line between the first set of declarations + * in a function and the next comment or statement. It produces a blank line + * even if there are no declarations. */ //indent input
CVS commit: src/tests/usr.bin/indent
Module Name:src Committed By: rillig Date: Sun Jun 4 19:28:54 UTC 2023 Modified Files: src/tests/usr.bin/indent: lex_ident.c lsym_binary_op.c opt_badp.c Log Message: tests/indent: clean up comments To generate a diff of this commit: cvs rdiff -u -r1.6 -r1.7 src/tests/usr.bin/indent/lex_ident.c cvs rdiff -u -r1.7 -r1.8 src/tests/usr.bin/indent/lsym_binary_op.c cvs rdiff -u -r1.11 -r1.12 src/tests/usr.bin/indent/opt_badp.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/tests/usr.bin/indent
Module Name:src Committed By: rillig Date: Fri Jun 2 11:26:21 UTC 2023 Modified Files: src/tests/usr.bin/indent: opt_bc.c Log Message: tests/indent: demonstrate bugs when formatting preprocessing lines To generate a diff of this commit: cvs rdiff -u -r1.6 -r1.7 src/tests/usr.bin/indent/opt_bc.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/tests/usr.bin/indent
Module Name:src Committed By: rillig Date: Fri Jun 2 11:26:21 UTC 2023 Modified Files: src/tests/usr.bin/indent: opt_bc.c Log Message: tests/indent: demonstrate bugs when formatting preprocessing lines To generate a diff of this commit: cvs rdiff -u -r1.6 -r1.7 src/tests/usr.bin/indent/opt_bc.c 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/opt_bc.c diff -u src/tests/usr.bin/indent/opt_bc.c:1.6 src/tests/usr.bin/indent/opt_bc.c:1.7 --- src/tests/usr.bin/indent/opt_bc.c:1.6 Sun Apr 24 09:04:12 2022 +++ src/tests/usr.bin/indent/opt_bc.c Fri Jun 2 11:26:21 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: opt_bc.c,v 1.6 2022/04/24 09:04:12 rillig Exp $ */ +/* $NetBSD: opt_bc.c,v 1.7 2023/06/02 11:26:21 rillig Exp $ */ /* * Tests for the options '-bc' and '-nbc'. @@ -63,3 +63,37 @@ double a, b, c; return a + b + c; } //indent end + + +//indent input +int a, +#if 0 +b, c; int d; +#else +b, c; int d; +#endif +//indent end + +//indent run -bc +int a, +#if 0 + b, + c; +int d; +#else +// $ FIXME: The '#else' branch must be indented like the '#if' branch. + b, c; +int d; +#endif +//indent end + +//indent run -nbc +int a, +// $ FIXME: 'b, c' must not be merged into the preprocessing line. +#if 0 b, c; +int d; +#else + b, c; +int d; +#endif +//indent end
CVS commit: src/tests/usr.bin/indent
Module Name:src Committed By: rillig Date: Tue May 23 06:18:00 UTC 2023 Modified Files: src/tests/usr.bin/indent: fmt_decl.c lsym_for.c lsym_unary_op.c opt_bap.c opt_lp.c opt_sob.c Log Message: tests/indent: add code snippets found in make and lint1 To generate a diff of this commit: cvs rdiff -u -r1.43 -r1.44 src/tests/usr.bin/indent/fmt_decl.c cvs rdiff -u -r1.4 -r1.5 src/tests/usr.bin/indent/lsym_for.c cvs rdiff -u -r1.6 -r1.7 src/tests/usr.bin/indent/lsym_unary_op.c \ src/tests/usr.bin/indent/opt_lp.c cvs rdiff -u -r1.8 -r1.9 src/tests/usr.bin/indent/opt_bap.c cvs rdiff -u -r1.7 -r1.8 src/tests/usr.bin/indent/opt_sob.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/tests/usr.bin/indent
Module Name:src Committed By: rillig Date: Tue May 23 06:18:00 UTC 2023 Modified Files: src/tests/usr.bin/indent: fmt_decl.c lsym_for.c lsym_unary_op.c opt_bap.c opt_lp.c opt_sob.c Log Message: tests/indent: add code snippets found in make and lint1 To generate a diff of this commit: cvs rdiff -u -r1.43 -r1.44 src/tests/usr.bin/indent/fmt_decl.c cvs rdiff -u -r1.4 -r1.5 src/tests/usr.bin/indent/lsym_for.c cvs rdiff -u -r1.6 -r1.7 src/tests/usr.bin/indent/lsym_unary_op.c \ src/tests/usr.bin/indent/opt_lp.c cvs rdiff -u -r1.8 -r1.9 src/tests/usr.bin/indent/opt_bap.c cvs rdiff -u -r1.7 -r1.8 src/tests/usr.bin/indent/opt_sob.c 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/fmt_decl.c diff -u src/tests/usr.bin/indent/fmt_decl.c:1.43 src/tests/usr.bin/indent/fmt_decl.c:1.44 --- src/tests/usr.bin/indent/fmt_decl.c:1.43 Tue May 16 08:22:11 2023 +++ src/tests/usr.bin/indent/fmt_decl.c Tue May 23 06:18:00 2023 @@ -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 Index: src/tests/usr.bin/indent/lsym_for.c diff -u src/tests/usr.bin/indent/lsym_for.c:1.4 src/tests/usr.bin/indent/lsym_for.c:1.5 --- src/tests/usr.bin/indent/lsym_for.c:1.4 Sun Apr 24 10:36:37 2022 +++ src/tests/usr.bin/indent/lsym_for.c Tue May 23 06:18:00 2023 @@ -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 Index: src/tests/usr.bin/indent/lsym_unary_op.c diff -u src/tests/usr.bin/indent/lsym_unary_op.c:1.6 src/tests/usr.bin/indent/lsym_unary_op.c:1.7 --- src/tests/usr.bin/indent/lsym_unary_op.c:1.6 Sat May 13 06:52:48 2023 +++ src/tests/usr.bin/indent/lsym_unary_op.c Tue May 23 06:18:00 2023 @@ -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 Index: src/tests/usr.bin/indent/opt_lp.c diff -u src/tests/usr.bin/indent/opt_lp.c:1.6 src/tests/usr.bin/indent/opt_lp.c:1.7 --- src/tests/usr.bin/indent/opt_lp.c:1.6 Sun Apr 24 09:04:12 2022 +++ src/tests/usr.bin/indent/opt_lp.c Tue May 23 06:18:00 2023 @@ -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 Index: src/tests/usr.bin/indent/opt_bap.c diff -u src/tests/usr.bin/indent/opt_bap.c:1.8 src/tests/usr.bin/indent/opt_bap.c:1.9 --- src/tests/usr.bin/indent/opt_bap.c:1.8 Sat May 20 12:05:01 2023 +++ src/tests/usr.bin/indent/opt_bap.c Tue May 23 06:18:00 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: opt_bap.c,v 1.8 2023/05/20 12:05:01 rillig Exp $ */
CVS commit: src/tests/usr.bin/indent
Module Name:src Committed By: rillig Date: Mon May 22 23:01:27 UTC 2023 Modified Files: src/tests/usr.bin/indent: edge_cases.c lsym_do.c lsym_funcname.c Log Message: tests/indent: refine a few tests To generate a diff of this commit: cvs rdiff -u -r1.1 -r1.2 src/tests/usr.bin/indent/edge_cases.c cvs rdiff -u -r1.6 -r1.7 src/tests/usr.bin/indent/lsym_do.c cvs rdiff -u -r1.4 -r1.5 src/tests/usr.bin/indent/lsym_funcname.c 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/edge_cases.c diff -u src/tests/usr.bin/indent/edge_cases.c:1.1 src/tests/usr.bin/indent/edge_cases.c:1.2 --- src/tests/usr.bin/indent/edge_cases.c:1.1 Sun Apr 24 10:36:37 2022 +++ src/tests/usr.bin/indent/edge_cases.c Mon May 22 23:01:27 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: edge_cases.c,v 1.1 2022/04/24 10:36:37 rillig Exp $ */ +/* $NetBSD: edge_cases.c,v 1.2 2023/05/22 23:01:27 rillig Exp $ */ /* * Tests for edge cases in the C programming language that indent does not @@ -7,7 +7,8 @@ /* * Digraphs are replacements for the characters '[', '{' and '#', which are - * missing in some exotic restricted source character sets. + * missing in some exotic restricted source character sets. They are not used + * in practice, therefore indent doesn't need to support them. * * See C99 6.4.6 */ @@ -28,12 +29,15 @@ void digraphs(void) { /* same as 'array[subscript]' */ -// $ XXX: The indentation is completely wrong. -// $ XXX: The space between 'array' and '<' doesn't belong there. +// $ Indent interprets everything before the second ':' as a label name, +// $ therefore the statement is indented that far to the left. +// $ +// $ The space between 'array' and '<' comes from the binary operator '<'. number = array <:subscript:>; /* same as '(int){ initializer }' */ -// $ XXX: The space between '%' and '>' doesn't belong there. +// $ The opening '<' and '%' are interpreted as unary operators. +// $ The closing '%' and '>' are interpreted as a binary and unary operator. number = (int)<%initializer % >; } //indent end Index: src/tests/usr.bin/indent/lsym_do.c diff -u src/tests/usr.bin/indent/lsym_do.c:1.6 src/tests/usr.bin/indent/lsym_do.c:1.7 --- src/tests/usr.bin/indent/lsym_do.c:1.6 Sat May 13 06:52:48 2023 +++ src/tests/usr.bin/indent/lsym_do.c Mon May 22 23:01:27 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: lsym_do.c,v 1.6 2023/05/13 06:52:48 rillig Exp $ */ +/* $NetBSD: lsym_do.c,v 1.7 2023/05/22 23:01:27 rillig Exp $ */ /* * Tests for the token lsym_do, which represents the keyword 'do' that starts @@ -86,3 +86,27 @@ variants(void) } while (0); } //indent end + +//indent run -bl +void +variants(void) +{ + do + stmt(); + while (0); + + do + { + stmt(); + } while (0); + + do /* comment */ + stmt(); + while (0); + + while (0) + do + { + } while (0); +} +//indent end Index: src/tests/usr.bin/indent/lsym_funcname.c diff -u src/tests/usr.bin/indent/lsym_funcname.c:1.4 src/tests/usr.bin/indent/lsym_funcname.c:1.5 --- src/tests/usr.bin/indent/lsym_funcname.c:1.4 Sun Apr 24 10:36:37 2022 +++ src/tests/usr.bin/indent/lsym_funcname.c Mon May 22 23:01:27 2023 @@ -1,10 +1,8 @@ -/* $NetBSD: lsym_funcname.c,v 1.4 2022/04/24 10:36:37 rillig Exp $ */ +/* $NetBSD: lsym_funcname.c,v 1.5 2023/05/22 23:01:27 rillig Exp $ */ /* - * Tests for the token lsym_funcname, which is an identifier that is followed - * by an opening parenthesis. - * - * TODO: Document how lsym_funcname is handled differently from lsym_word. + * Tests for the token lsym_funcname, which is the name of a function, but only + * in a function definition, not in a declaration or a call expression. * * See also: * lsym_word.c
CVS commit: src/tests/usr.bin/indent
Module Name:src Committed By: rillig Date: Mon May 22 23:01:27 UTC 2023 Modified Files: src/tests/usr.bin/indent: edge_cases.c lsym_do.c lsym_funcname.c Log Message: tests/indent: refine a few tests To generate a diff of this commit: cvs rdiff -u -r1.1 -r1.2 src/tests/usr.bin/indent/edge_cases.c cvs rdiff -u -r1.6 -r1.7 src/tests/usr.bin/indent/lsym_do.c cvs rdiff -u -r1.4 -r1.5 src/tests/usr.bin/indent/lsym_funcname.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/tests/usr.bin/indent
Module Name:src Committed By: rillig Date: Mon May 22 06:35:56 UTC 2023 Modified Files: src/tests/usr.bin/indent: t_options.lua Log Message: tests/indent: skip creating an intermediate file in tests To generate a diff of this commit: cvs rdiff -u -r1.3 -r1.4 src/tests/usr.bin/indent/t_options.lua 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/t_options.lua diff -u src/tests/usr.bin/indent/t_options.lua:1.3 src/tests/usr.bin/indent/t_options.lua:1.4 --- src/tests/usr.bin/indent/t_options.lua:1.3 Sun May 21 10:18:44 2023 +++ src/tests/usr.bin/indent/t_options.lua Mon May 22 06:35:56 2023 @@ -1,4 +1,4 @@ --- $NetBSD: t_options.lua,v 1.3 2023/05/21 10:18:44 rillig Exp $ +-- $NetBSD: t_options.lua,v 1.4 2023/05/22 06:35:56 rillig Exp $ -- -- Copyright (c) 2023 The NetBSD Foundation, Inc. -- All rights reserved. @@ -24,6 +24,8 @@ -- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -- POSSIBILITY OF SUCH DAMAGE. +-- usage: [INDENT=...] lua t_options.lua ... +-- -- Test driver for indent that runs indent on several inputs, checks the -- output and can run indent with different command line options on the same -- input. @@ -32,11 +34,11 @@ -- and the output, all as close together as possible. The test files use the -- following directives: -- --- //indent input [description] +-- //indent input -- Specifies the input to be formatted. -- //indent run [options] -- Runs indent on the input, using the given options. --- //indent end [description] +-- //indent end -- Finishes an '//indent input' or '//indent run' section. -- //indent run-equals-input [options] -- Runs indent on the input, expecting unmodified output. @@ -124,16 +126,14 @@ end local function run_indent(inp, args) local indent = os.getenv("INDENT") or "indent" - local cmd = indent .. " " .. args .. " indent.in -st" + local cmd = indent .. " " .. args .. " 2>&1" - local indent_in = assert(io.open("indent.in", "w")) + local indent_in = assert(io.popen(cmd, "w")) indent_in:write(inp) - indent_in:close() - local ok, kind, info = os.execute(cmd) + local ok, kind, info = indent_in:close() if not ok then print(kind .. " " .. info) end - os.remove("indent.in") end local function handle_empty_section(line) @@ -236,7 +236,9 @@ local function handle_indent_directive(l print(line) expected_out:write(line .. "\n") - if command == "input" and args == "" then + if command == "input" and args ~= "" then + warn(lineno, "'//indent input' does not take arguments") + elseif command == "input" then handle_indent_input() elseif command == "run" then handle_indent_run(args)
CVS commit: src/tests/usr.bin/indent
Module Name:src Committed By: rillig Date: Mon May 22 06:35:56 UTC 2023 Modified Files: src/tests/usr.bin/indent: t_options.lua Log Message: tests/indent: skip creating an intermediate file in tests To generate a diff of this commit: cvs rdiff -u -r1.3 -r1.4 src/tests/usr.bin/indent/t_options.lua Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/tests/usr.bin/indent
Module Name:src Committed By: rillig Date: Sat May 20 22:08:07 UTC 2023 Modified Files: src/tests/usr.bin/indent: t_options.lua Log Message: tests/indent: prevent 'indent end' with arguments To generate a diff of this commit: cvs rdiff -u -r1.1 -r1.2 src/tests/usr.bin/indent/t_options.lua 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/t_options.lua diff -u src/tests/usr.bin/indent/t_options.lua:1.1 src/tests/usr.bin/indent/t_options.lua:1.2 --- src/tests/usr.bin/indent/t_options.lua:1.1 Sat May 20 21:32:05 2023 +++ src/tests/usr.bin/indent/t_options.lua Sat May 20 22:08:07 2023 @@ -1,4 +1,4 @@ --- $NetBSD: t_options.lua,v 1.1 2023/05/20 21:32:05 rillig Exp $ +-- $NetBSD: t_options.lua,v 1.2 2023/05/20 22:08:07 rillig Exp $ -- -- Copyright (c) 2023 The NetBSD Foundation, Inc. -- All rights reserved. @@ -129,7 +129,7 @@ local function run_indent(inp, args) local indent_in = assert(io.open("indent.in", "w")) indent_in:write(inp) indent_in:close() - ok, kind, info = os.execute(cmd) + local ok, kind, info = os.execute(cmd) if not ok then print(kind .. " " .. info) end @@ -155,84 +155,103 @@ local function handle_empty_section(line end end -local function handle_indent_directive(line, command, args) - print(line) - expected_out:write(line .. "\n") +local function handle_indent_input() + if prev_empty_lines ~= 2 and seen_input_section then + warn(lineno, "input section needs 2 empty lines " + .. "above, not " .. prev_empty_lines) + end + check_empty_lines_block(2) + check_unused_input() + section = "input" + section_excl_comm = "" + section_incl_comm = "" + unused_input_lineno = lineno + seen_input_section = true + output_excl_comm = "" + output_incl_comm = "" + output_lineno = 0 +end - if command == "input" then - if prev_empty_lines ~= 2 and seen_input_section then - warn(lineno, "input section needs 2 empty lines " - .. "above, not " .. prev_empty_lines) - end - check_empty_lines_block(2) - check_unused_input() - section = "input" - section_excl_comm = "" - section_incl_comm = "" - unused_input_lineno = lineno - seen_input_section = true - output_excl_comm = "" - output_incl_comm = "" - output_lineno = 0 +local function handle_indent_run(args) + if section ~= "" then + warn(lineno, "unfinished section '" .. section .. "'") + end + check_empty_lines_block(1) + if prev_empty_lines ~= 1 then + warn(lineno, "run section needs 1 empty line above, " + .. "not " .. prev_empty_lines) + end + section = "run" + output_lineno = lineno + section_excl_comm = "" + section_incl_comm = "" - elseif command == "run" then - if section ~= "" then - warn(lineno, "unfinished section '" .. section .. "'") - end - check_empty_lines_block(1) - if prev_empty_lines ~= 1 then - warn(lineno, "run section needs 1 empty line above, " - .. "not " .. prev_empty_lines) - end - section = "run" - output_lineno = lineno - section_excl_comm = "" - section_incl_comm = "" + run_indent(input_excl_comm, args) + unused_input_lineno = 0 +end - run_indent(input_excl_comm, args) - unused_input_lineno = 0 +local function handle_indent_run_equals_input(args) + check_empty_lines_block(1) + run_indent(input_excl_comm, args) + expected_out:write(input_excl_comm) + unused_input_lineno = 0 + max_empty_lines = 0 +end - elseif command == "run-equals-input" then - check_empty_lines_block(1) - run_indent(input_excl_comm, args) - expected_out:write(input_excl_comm) - unused_input_lineno = 0 - max_empty_lines = 0 +local function handle_indent_run_equals_prev_output(args) + check_empty_lines_block(1) + run_indent(input_excl_comm, args) + expected_out:write(output_excl_comm) + max_empty_lines = 0 +end - elseif command == "run-equals-prev-output" then - check_empty_lines_block(1) - run_indent(input_excl_comm, args) - expected_out:write(output_excl_comm) - max_empty_lines = 0 +local function handle_indent_end_input() + if section_incl_comm == input_incl_comm then + warn(lineno, "duplicate input; remove this section") + end - elseif command == "end" and section == "input" then - if section_incl_comm == input_incl_comm then - warn(lineno, "duplicate input; remove this section") - end + input_excl_comm = section_excl_comm + input_incl_comm = section_incl_comm + section = "" + max_empty_lines = 0 +end - input_excl_comm = section_excl_comm - input_incl_comm = section_incl_comm - section = "" - max_empty_lines = 0 +local function handle_indent_end_run() + if section_incl_comm == input_incl_comm then + warn(output_lineno, + "output == input; use run-equals-input") + end + if section_incl_comm == output_incl_comm then + warn(output_lineno, + "duplicate output; use run-equals-prev-output") + end - elseif command == "end" and section == "run" then - if section_incl_comm == input_incl_comm then - warn(output_lineno, -
CVS commit: src/tests/usr.bin/indent
Module Name:src Committed By: rillig Date: Sat May 20 22:08:07 UTC 2023 Modified Files: src/tests/usr.bin/indent: t_options.lua Log Message: tests/indent: prevent 'indent end' with arguments To generate a diff of this commit: cvs rdiff -u -r1.1 -r1.2 src/tests/usr.bin/indent/t_options.lua Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/tests/usr.bin/indent
Module Name:src Committed By: rillig Date: Sat May 20 17:31:53 UTC 2023 Modified Files: src/tests/usr.bin/indent: t_options.awk Log Message: tests/indent: clean up test driver No functional change. To generate a diff of this commit: cvs rdiff -u -r1.12 -r1.13 src/tests/usr.bin/indent/t_options.awk Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/tests/usr.bin/indent
Module Name:src Committed By: rillig Date: Sat May 20 17:31:53 UTC 2023 Modified Files: src/tests/usr.bin/indent: t_options.awk Log Message: tests/indent: clean up test driver No functional change. To generate a diff of this commit: cvs rdiff -u -r1.12 -r1.13 src/tests/usr.bin/indent/t_options.awk 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/t_options.awk diff -u src/tests/usr.bin/indent/t_options.awk:1.12 src/tests/usr.bin/indent/t_options.awk:1.13 --- src/tests/usr.bin/indent/t_options.awk:1.12 Mon May 15 17:38:56 2023 +++ src/tests/usr.bin/indent/t_options.awk Sat May 20 17:31:53 2023 @@ -1,4 +1,4 @@ -# $NetBSD: t_options.awk,v 1.12 2023/05/15 17:38:56 rillig Exp $ +# $NetBSD: t_options.awk,v 1.13 2023/05/20 17:31:53 rillig Exp $ # # Copyright (c) 2021 The NetBSD Foundation, Inc. # All rights reserved. @@ -85,11 +85,6 @@ function warn(lineno, msg) warned = 1 } -function quote(s) -{ - return "'" s "'" -} - function check_empty_lines_block(n) { if (max_empty_lines != n && seen_input_section) @@ -160,7 +155,7 @@ section == "" { } else if ($2 == "run") { if (section != "") - warn(NR, "unfinished section " quote(section)) + warn(NR, "unfinished section '" section "'") check_empty_lines_block(1) if (prev_empty_lines != 1) warn(NR, "run section needs 1 empty line above, " \ @@ -209,10 +204,10 @@ section == "" { max_empty_lines = 0 } else if ($2 == "end") { - warn(NR, "misplaced " quote("//indent end")) + warn(NR, "misplaced '//indent end'") } else { - die(NR, "invalid line " quote($0)) + die(NR, "invalid line '" $0 "'") } prev_empty_lines = 0 @@ -235,7 +230,7 @@ section == "" && !/^$/ && !/^#/ && !/^\/ END { if (section != "") - die(NR, "still in section " quote(section)) + die(NR, "still in section '" section "'") check_unused_input() if (warned) exit(1)
CVS commit: src/tests/usr.bin/indent
Module Name:src Committed By: rillig Date: Fri May 19 07:05:26 UTC 2023 Modified Files: src/tests/usr.bin/indent: opt_cdb.c Log Message: tests/indent: test multi-line comments with -ncdb To generate a diff of this commit: cvs rdiff -u -r1.8 -r1.9 src/tests/usr.bin/indent/opt_cdb.c 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/opt_cdb.c diff -u src/tests/usr.bin/indent/opt_cdb.c:1.8 src/tests/usr.bin/indent/opt_cdb.c:1.9 --- src/tests/usr.bin/indent/opt_cdb.c:1.8 Sun Apr 24 09:04:12 2022 +++ src/tests/usr.bin/indent/opt_cdb.c Fri May 19 07:05:26 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: opt_cdb.c,v 1.8 2022/04/24 09:04:12 rillig Exp $ */ +/* $NetBSD: opt_cdb.c,v 1.9 2023/05/19 07:05:26 rillig Exp $ */ /* * Tests for the options '-cdb' and '-ncdb'. @@ -198,3 +198,30 @@ example(void) /* * */ //indent end + + +/* + * Since 2019-04-04, the -ncdb option condenses multi-line comments as well, + * not only single-line comments. + * + * XXX: Is this intended? + */ +//indent input +{ + /* + * This is the first paragraph. + * + * This is the second paragraph. + */ +} +//indent end + +//indent run-equals-input -cdb + +//indent run -ncdb +{ + /* This is the first paragraph. + * + * This is the second paragraph. */ +} +//indent end
CVS commit: src/tests/usr.bin/indent
Module Name:src Committed By: rillig Date: Fri May 19 07:05:26 UTC 2023 Modified Files: src/tests/usr.bin/indent: opt_cdb.c Log Message: tests/indent: test multi-line comments with -ncdb To generate a diff of this commit: cvs rdiff -u -r1.8 -r1.9 src/tests/usr.bin/indent/opt_cdb.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/tests/usr.bin/indent
Module Name:src Committed By: rillig Date: Mon May 15 17:51:49 UTC 2023 Modified Files: src/tests/usr.bin/indent: lsym_type_outside_parentheses.c Log Message: tests/indent: test type detection To generate a diff of this commit: cvs rdiff -u -r1.3 -r1.4 \ src/tests/usr.bin/indent/lsym_type_outside_parentheses.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/tests/usr.bin/indent
Module Name:src Committed By: rillig Date: Mon May 15 17:51:49 UTC 2023 Modified Files: src/tests/usr.bin/indent: lsym_type_outside_parentheses.c Log Message: tests/indent: test type detection To generate a diff of this commit: cvs rdiff -u -r1.3 -r1.4 \ src/tests/usr.bin/indent/lsym_type_outside_parentheses.c 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/lsym_type_outside_parentheses.c diff -u src/tests/usr.bin/indent/lsym_type_outside_parentheses.c:1.3 src/tests/usr.bin/indent/lsym_type_outside_parentheses.c:1.4 --- src/tests/usr.bin/indent/lsym_type_outside_parentheses.c:1.3 Sun Apr 24 09:04:12 2022 +++ src/tests/usr.bin/indent/lsym_type_outside_parentheses.c Mon May 15 17:51:49 2023 @@ -1,13 +1,29 @@ -/* $NetBSD: lsym_type_outside_parentheses.c,v 1.3 2022/04/24 09:04:12 rillig Exp $ */ +/* $NetBSD: lsym_type_outside_parentheses.c,v 1.4 2023/05/15 17:51:49 rillig Exp $ */ /* * Tests for the token lsym_type_outside_parentheses, which represents a type * name outside parentheses, such as in a declaration that is not for a * function. + * + * See also: + * lex_ident + * lsym_type_in_parentheses + * lsym_word + * opt_ta + * opt_T */ +/* + * Indent has to guess which identifiers are types and which are variables. + */ //indent input -// TODO: add input +t1 *no_init_ptr; +t2 *init_ptr = 0; +/* $ FIXME: Assume that an identifier after 'const' is a type name. */ +const t3 * const_no_init_ptr; +static t4 *static_no_init_ptr; +/* $ FIXME: Assume that an identifier after 'typedef' is a type name. */ +typedef t5 * typedef_no_init_ptr; //indent end -//indent run-equals-input +//indent run-equals-input -di24
CVS commit: src/tests/usr.bin/indent
Module Name:src Committed By: rillig Date: Mon May 15 17:38:56 UTC 2023 Modified Files: src/tests/usr.bin/indent: t_misc.sh t_options.awk Log Message: indent: remove accidental space before tab To generate a diff of this commit: cvs rdiff -u -r1.24 -r1.25 src/tests/usr.bin/indent/t_misc.sh cvs rdiff -u -r1.11 -r1.12 src/tests/usr.bin/indent/t_options.awk 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/t_misc.sh diff -u src/tests/usr.bin/indent/t_misc.sh:1.24 src/tests/usr.bin/indent/t_misc.sh:1.25 --- src/tests/usr.bin/indent/t_misc.sh:1.24 Sat May 13 08:33:39 2023 +++ src/tests/usr.bin/indent/t_misc.sh Mon May 15 17:38:56 2023 @@ -1,5 +1,5 @@ #! /bin/sh -# $NetBSD: t_misc.sh,v 1.24 2023/05/13 08:33:39 rillig Exp $ +# $NetBSD: t_misc.sh,v 1.25 2023/05/15 17:38:56 rillig Exp $ # # Copyright (c) 2021 The NetBSD Foundation, Inc. # All rights reserved. @@ -311,7 +311,7 @@ opt_U_body() size_t from stddef.h off_t for file offsets - ignored_t is ignored since it is indented + ignored_t is ignored since it is indented EOF cat <<-\EOF > code.c Index: src/tests/usr.bin/indent/t_options.awk diff -u src/tests/usr.bin/indent/t_options.awk:1.11 src/tests/usr.bin/indent/t_options.awk:1.12 --- src/tests/usr.bin/indent/t_options.awk:1.11 Thu May 11 09:28:53 2023 +++ src/tests/usr.bin/indent/t_options.awk Mon May 15 17:38:56 2023 @@ -1,4 +1,4 @@ -# $NetBSD: t_options.awk,v 1.11 2023/05/11 09:28:53 rillig Exp $ +# $NetBSD: t_options.awk,v 1.12 2023/05/15 17:38:56 rillig Exp $ # # Copyright (c) 2021 The NetBSD Foundation, Inc. # All rights reserved. @@ -93,7 +93,7 @@ function quote(s) function check_empty_lines_block(n) { if (max_empty_lines != n && seen_input_section) - warn(NR, "expecting " n " empty " (n != 1 ? "lines" : "line") ", got " max_empty_lines) + warn(NR, "expecting " n " empty " (n != 1 ? "lines" : "line") ", got " max_empty_lines) } function check_unused_input()
CVS commit: src/tests/usr.bin/indent
Module Name:src Committed By: rillig Date: Mon May 15 17:38:56 UTC 2023 Modified Files: src/tests/usr.bin/indent: t_misc.sh t_options.awk Log Message: indent: remove accidental space before tab To generate a diff of this commit: cvs rdiff -u -r1.24 -r1.25 src/tests/usr.bin/indent/t_misc.sh cvs rdiff -u -r1.11 -r1.12 src/tests/usr.bin/indent/t_options.awk Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/tests/usr.bin/indent
Module Name:src Committed By: rillig Date: Mon May 15 15:04:48 UTC 2023 Modified Files: src/tests/usr.bin/indent: fmt_decl.c Log Message: tests/indent: demonstrate wrong spacing after function prototype To generate a diff of this commit: cvs rdiff -u -r1.39 -r1.40 src/tests/usr.bin/indent/fmt_decl.c 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/fmt_decl.c diff -u src/tests/usr.bin/indent/fmt_decl.c:1.39 src/tests/usr.bin/indent/fmt_decl.c:1.40 --- src/tests/usr.bin/indent/fmt_decl.c:1.39 Mon May 15 14:55:47 2023 +++ src/tests/usr.bin/indent/fmt_decl.c Mon May 15 15:04:48 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: fmt_decl.c,v 1.39 2023/05/15 14:55:47 rillig Exp $ */ +/* $NetBSD: fmt_decl.c,v 1.40 2023/05/15 15:04:48 rillig Exp $ */ /* * Tests for declarations of global variables, external functions, and local @@ -887,3 +887,35 @@ char *(*fn)(int, int) = NULL; /* XXX: The parameter '(int)' is wrongly interpreted as a type cast. */ /* XXX: The parameter '(int, int)' is wrongly interpreted as a type cast. */ //indent run-equals-input -di0 + + +/* + * Depending on the line break in the function header, the spaces around the + * '||' operator were removed. + */ +//indent input +bool is_identifier_start(char ch) +{ + return ch_isalpha(ch) || ch == '_'; +} + +bool +is_identifier_start(char ch) +{ + return ch_isalpha(ch) || ch == '_'; +} +//indent end + +//indent run +bool +is_identifier_start(char ch) +{ + return ch_isalpha(ch) || ch == '_'; +} + +bool +is_identifier_start(char ch) +{ + return ch_isalpha(ch)||ch == '_'; +} +//indent end
CVS commit: src/tests/usr.bin/indent
Module Name:src Committed By: rillig Date: Mon May 15 15:04:48 UTC 2023 Modified Files: src/tests/usr.bin/indent: fmt_decl.c Log Message: tests/indent: demonstrate wrong spacing after function prototype To generate a diff of this commit: cvs rdiff -u -r1.39 -r1.40 src/tests/usr.bin/indent/fmt_decl.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/tests/usr.bin/indent
Module Name:src Committed By: rillig Date: Mon May 15 13:53:32 UTC 2023 Modified Files: src/tests/usr.bin/indent: lsym_tag.c Log Message: tests/indent: demonstrate wrong indentation of struct members To generate a diff of this commit: cvs rdiff -u -r1.5 -r1.6 src/tests/usr.bin/indent/lsym_tag.c 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/lsym_tag.c diff -u src/tests/usr.bin/indent/lsym_tag.c:1.5 src/tests/usr.bin/indent/lsym_tag.c:1.6 --- src/tests/usr.bin/indent/lsym_tag.c:1.5 Sun Apr 24 10:36:37 2022 +++ src/tests/usr.bin/indent/lsym_tag.c Mon May 15 13:53:32 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: lsym_tag.c,v 1.5 2022/04/24 10:36:37 rillig Exp $ */ +/* $NetBSD: lsym_tag.c,v 1.6 2023/05/15 13:53:32 rillig Exp $ */ /* * Tests for the token lsym_tag, which represents one of the keywords @@ -114,3 +114,32 @@ struct /* comment */ tag var; //indent run -di0 struct /* comment */ tag var; //indent end + + +/* + * Ensure that the names of struct members are all indented the same. + * Before -XX-XX, the indentation depended on their type name. + */ +//indent input +struct { + enum { + untagged_constant, + } untagged_member; + enum tag_name { + tagged_constant, + } tagged_member; +}; +//indent end + +//indent run -di0 +struct { + enum { + untagged_constant, + }untagged_member; + /* $ FIXME: 4 spaces above, should be 1. */ + enum tag_name { + tagged_constant, + }tagged_member; + /* $ FIXME: 8 spaces above, should be 1. */ +}; +//indent end
CVS commit: src/tests/usr.bin/indent
Module Name:src Committed By: rillig Date: Mon May 15 13:53:32 UTC 2023 Modified Files: src/tests/usr.bin/indent: lsym_tag.c Log Message: tests/indent: demonstrate wrong indentation of struct members To generate a diff of this commit: cvs rdiff -u -r1.5 -r1.6 src/tests/usr.bin/indent/lsym_tag.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/tests/usr.bin/indent
Module Name:src Committed By: rillig Date: Mon May 15 13:28:05 UTC 2023 Modified Files: src/tests/usr.bin/indent: opt_eei.c Log Message: tests/indent: add another test for -eei -nlp To generate a diff of this commit: cvs rdiff -u -r1.10 -r1.11 src/tests/usr.bin/indent/opt_eei.c 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/opt_eei.c diff -u src/tests/usr.bin/indent/opt_eei.c:1.10 src/tests/usr.bin/indent/opt_eei.c:1.11 --- src/tests/usr.bin/indent/opt_eei.c:1.10 Mon May 15 12:59:43 2023 +++ src/tests/usr.bin/indent/opt_eei.c Mon May 15 13:28:05 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: opt_eei.c,v 1.10 2023/05/15 12:59:43 rillig Exp $ */ +/* $NetBSD: opt_eei.c,v 1.11 2023/05/15 13:28:05 rillig Exp $ */ /* * Tests for the options '-eei' and '-neei'. @@ -160,3 +160,30 @@ b) stmt(); } //indent end + + +/* + * Ensure that after a condition with extra indentation, the following + * statements are not affected. + */ +//indent input +{ + if ( + cond + ) + stmt( + arg + ); +} +//indent end + +//indent run -eei -nlp -i4 +{ +if ( + cond + ) + stmt( + arg + ); +} +//indent end
CVS commit: src/tests/usr.bin/indent
Module Name:src Committed By: rillig Date: Mon May 15 13:28:05 UTC 2023 Modified Files: src/tests/usr.bin/indent: opt_eei.c Log Message: tests/indent: add another test for -eei -nlp To generate a diff of this commit: cvs rdiff -u -r1.10 -r1.11 src/tests/usr.bin/indent/opt_eei.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/tests/usr.bin/indent
Module Name:src Committed By: rillig Date: Mon May 15 12:11:07 UTC 2023 Modified Files: src/tests/usr.bin/indent: opt_eei.c Log Message: tests/indent: test extra indentation with fixed continuation indentation To generate a diff of this commit: cvs rdiff -u -r1.8 -r1.9 src/tests/usr.bin/indent/opt_eei.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/tests/usr.bin/indent
Module Name:src Committed By: rillig Date: Mon May 15 12:11:07 UTC 2023 Modified Files: src/tests/usr.bin/indent: opt_eei.c Log Message: tests/indent: test extra indentation with fixed continuation indentation To generate a diff of this commit: cvs rdiff -u -r1.8 -r1.9 src/tests/usr.bin/indent/opt_eei.c 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/opt_eei.c diff -u src/tests/usr.bin/indent/opt_eei.c:1.8 src/tests/usr.bin/indent/opt_eei.c:1.9 --- src/tests/usr.bin/indent/opt_eei.c:1.8 Sun Apr 24 09:04:12 2022 +++ src/tests/usr.bin/indent/opt_eei.c Mon May 15 12:11:07 2023 @@ -1,156 +1,167 @@ -/* $NetBSD: opt_eei.c,v 1.8 2022/04/24 09:04:12 rillig Exp $ */ +/* $NetBSD: opt_eei.c,v 1.9 2023/05/15 12:11:07 rillig Exp $ */ /* * Tests for the options '-eei' and '-neei'. * * The option '-eei' enables extra indentation on continuation lines of the * expression part of 'if' and 'while' statements. These continuation lines - * are indented one extra level. + * are indented one extra level to avoid being confused for the first + * statement of the body, even if the condition line starts with an operator + * such as '&&' or '<' that could not start a statement. * * The option '-neei' indents these conditions in the same way as all other * continued statements. */ //indent input -bool -less(int a, int b) +{ + if (a < +b) + stmt(); + if (a +< +b) + stmt(); + while (a +< b) + stmt(); + switch ( + a) + stmt(); +} +//indent end + +/* + * By default, continuation lines are aligned on parentheses, and only a + * multi-line switch statement would have ambiguous indentation. + */ +//indent run { if (a < b) - return true; + stmt(); if (a < b) - return true; + stmt(); + while (a + < b) + stmt(); + switch ( + a) + stmt(); } //indent end +//indent run-equals-prev-output -neei + +/* + * For indentation 8, the only expression that needs to be disambiguated is + * the one from the switch statement. + */ //indent run -eei -bool -less(int a, int b) { if (a < +/* $ XXX: No extra indentation necessary. */ b) - return true; + stmt(); if (a +/* $ XXX: No extra indentation necessary. */ < +/* $ XXX: No extra indentation necessary. */ b) - return true; + stmt(); + while (a +/* $ XXX: No extra indentation necessary. */ + < b) + stmt(); + switch ( + a) + stmt(); } //indent end -//indent run-equals-input -neei - -/* - * When a single indentation level is the same as the continuation - * indentation, the code does not clearly show whether the 'b' belongs to the - * condition or the body statement. - */ +/* For indentation 4, the expressions from the 'if' are ambiguous. */ //indent run -neei -i4 -bool -less(int a, int b) { if (a < b) - return true; + stmt(); if (a < b) - return true; + stmt(); +while (a + < b) + stmt(); +switch ( + a) + stmt(); } //indent end -/* - * Adding the extra level of indentation is useful when the standard - * indentation is the same as the indentation of statement continuations. In - * such a case, the continued condition would have the same indentation as the - * following statement, which would be confusing. - */ //indent run -eei -i4 -bool -less(int a, int b) { if (a < b) - return true; + stmt(); if (a < b) - return true; + stmt(); +while (a +/* $ XXX: No extra indentation necessary. */ + < b) + stmt(); +switch ( +/* $ XXX: No extra indentation necessary. */ + a) + stmt(); } //indent end /* - * With an indentation size of 4, the width of the code 'if (' is exactly one - * indentation level. With the option '-nlp', the option '-eei' has no effect. - * - * XXX: This is unexpected since this creates the exact ambiguity that the - * option '-eei' is supposed to prevent. + * The -nlp option uses a fixed indentation for continuation lines. The if + * statements are disambiguated. */ //indent run -eei -i4 -nlp -bool -less(int a, int b) { if (a < +/* $ FIXME: Needs extra indentation. */ b) - return true; + stmt(); if (a +/* $ FIXME: Needs extra indentation. */ < +/* $ FIXME: Needs extra indentation. */ b) - return true; -} -//indent end - - -/* - * The option '-eei' applies no matter whether the continued expression starts - * with a word or an operator like '&&'. The latter cannot start a statement, - * so there would be no ambiguity. - */ -//indent input -{ - if (a -&& b) - stmt(); -} -//indent end - -/* - * XXX: The extra indentation is unnecessary since there is no possible - * confusion: the standard indentation is 8, the indentation of the continued - * condition could have stayed at 4. - */ -//indent run -eei -{ - if (a - && b) - stmt(); -} -//indent end - -/* - * The extra indentation is necessary here since otherwise the '&&' and the - * 'stmt()' would start at
CVS commit: src/tests/usr.bin/indent
Module Name:src Committed By: rillig Date: Mon May 15 09:05:08 UTC 2023 Modified Files: src/tests/usr.bin/indent: opt_badp.c Log Message: tests/indent: -badp should not add blank lines in initializers To generate a diff of this commit: cvs rdiff -u -r1.10 -r1.11 src/tests/usr.bin/indent/opt_badp.c 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/opt_badp.c diff -u src/tests/usr.bin/indent/opt_badp.c:1.10 src/tests/usr.bin/indent/opt_badp.c:1.11 --- src/tests/usr.bin/indent/opt_badp.c:1.10 Thu May 11 18:13:55 2023 +++ src/tests/usr.bin/indent/opt_badp.c Mon May 15 09:05:08 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: opt_badp.c,v 1.10 2023/05/11 18:13:55 rillig Exp $ */ +/* $NetBSD: opt_badp.c,v 1.11 2023/05/15 09:05:08 rillig Exp $ */ /* * Tests for the options '-badp' and '-nbadp'. @@ -111,3 +111,23 @@ declaration_blank_blank_statement(void) //indent run-equals-input -badp //indent run-equals-input -nbadp + + +/* + * A struct declaration or an initializer are not function bodies, so don't + * add a blank line after them. + */ +//indent input +struct { + int member[2]; +} s = { + { + 0, + 0, + } +}; +//indent end + +//indent run-equals-input -di0 -badp + +//indent run-equals-input -di0 -nbadp
CVS commit: src/tests/usr.bin/indent
Module Name:src Committed By: rillig Date: Mon May 15 09:05:08 UTC 2023 Modified Files: src/tests/usr.bin/indent: opt_badp.c Log Message: tests/indent: -badp should not add blank lines in initializers To generate a diff of this commit: cvs rdiff -u -r1.10 -r1.11 src/tests/usr.bin/indent/opt_badp.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/tests/usr.bin/indent
Module Name:src Committed By: rillig Date: Mon May 15 08:22:23 UTC 2023 Modified Files: src/tests/usr.bin/indent: psym_for_exprs.c Log Message: tests/indent: demonstrate wrong spacing in for loops To generate a diff of this commit: cvs rdiff -u -r1.4 -r1.5 src/tests/usr.bin/indent/psym_for_exprs.c 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/psym_for_exprs.c diff -u src/tests/usr.bin/indent/psym_for_exprs.c:1.4 src/tests/usr.bin/indent/psym_for_exprs.c:1.5 --- src/tests/usr.bin/indent/psym_for_exprs.c:1.4 Sun Apr 24 09:04:12 2022 +++ src/tests/usr.bin/indent/psym_for_exprs.c Mon May 15 08:22:23 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: psym_for_exprs.c,v 1.4 2022/04/24 09:04:12 rillig Exp $ */ +/* $NetBSD: psym_for_exprs.c,v 1.5 2023/05/15 08:22:23 rillig Exp $ */ /* * Tests for the parser state psym_for_exprs, which represents the state after @@ -7,10 +7,31 @@ */ //indent input -// TODO: add input +void +for_loops(void) +{ + for (int i = 0; i < 10; i++) + printf("%d * %d = %d\n", i, 7, i * 7); + + for (int i = 0; i < 10; i++) { + printf("%d * %d = %d\n", i, 7, i * 7); + } +} //indent end -//indent run-equals-input +//indent run +void +for_loops(void) +{ + for (int i = 0; i < 10; i++) + printf("%d * %d = %d\n", i, 7, i * 7); + + /* $ FIXME: Add space between ')' and '{'. */ + for (int i = 0; i < 10; i++){ + printf("%d * %d = %d\n", i, 7, i * 7); + } +} +//indent end /* @@ -19,7 +40,7 @@ */ //indent input void -function(void) +small_scope(void) { for (int i = 0; i < 3; i++) stmt();
CVS commit: src/tests/usr.bin/indent
Module Name:src Committed By: rillig Date: Mon May 15 08:22:23 UTC 2023 Modified Files: src/tests/usr.bin/indent: psym_for_exprs.c Log Message: tests/indent: demonstrate wrong spacing in for loops To generate a diff of this commit: cvs rdiff -u -r1.4 -r1.5 src/tests/usr.bin/indent/psym_for_exprs.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/tests/usr.bin/indent
Module Name:src Committed By: rillig Date: Sat May 13 14:19:14 UTC 2023 Modified Files: src/tests/usr.bin/indent: opt_bad.c Log Message: tests/indent: extend test for blank line after declaration To generate a diff of this commit: cvs rdiff -u -r1.7 -r1.8 src/tests/usr.bin/indent/opt_bad.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/tests/usr.bin/indent
Module Name:src Committed By: rillig Date: Sat May 13 14:19:14 UTC 2023 Modified Files: src/tests/usr.bin/indent: opt_bad.c Log Message: tests/indent: extend test for blank line after declaration To generate a diff of this commit: cvs rdiff -u -r1.7 -r1.8 src/tests/usr.bin/indent/opt_bad.c 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/opt_bad.c diff -u src/tests/usr.bin/indent/opt_bad.c:1.7 src/tests/usr.bin/indent/opt_bad.c:1.8 --- src/tests/usr.bin/indent/opt_bad.c:1.7 Thu May 11 18:13:55 2023 +++ src/tests/usr.bin/indent/opt_bad.c Sat May 13 14:19:14 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: opt_bad.c,v 1.7 2023/05/11 18:13:55 rillig Exp $ */ +/* $NetBSD: opt_bad.c,v 1.8 2023/05/13 14:19:14 rillig Exp $ */ /* * Tests for the options '-bad' and '-nbad'. @@ -87,3 +87,69 @@ function_definition(void) function_call(); } //indent end + + +/* + * A comment after a declaration does not change whether there should be a + * blank line below the declaration. + */ +//indent input +void +comments(void) +{ + int local_var_1; /* comment */ + int local_var_2; /* comment */ + /* comment line */ + function_call(); +} +//indent end + +//indent run -ldi0 -bad +void +comments(void) +{ + int local_var_1; /* comment */ + int local_var_2; /* comment */ + /* comment line */ + /* $ TODO: Add blank line here. */ + function_call(); +} +//indent end + +//indent run-equals-input -ldi0 -nbad + + +/* + * A declaration that has a braced initializer is still a declaration and + * therefore needs a blank line below. + */ +//indent input +void +initializer(void) +{ + int local_var_init_1[] = { + 1 + }; + int local_var_init_2[] = { + 1 + }; + function_call(); +} +//indent end + +//indent run -ldi0 -bad +void +initializer(void) +{ + int local_var_init_1[] = { + 1 + }; + int local_var_init_2[] = { + 1 + }; + /* $ TODO: Add blank line here. */ + function_call(); +} +//indent end + +//indent run-equals-input -ldi0 -nbad
CVS commit: src/tests/usr.bin/indent
Module Name:src Committed By: rillig Date: Sat May 13 06:52:48 UTC 2023 Modified Files: src/tests/usr.bin/indent: fmt_block.c fmt_decl.c lsym_binary_op.c lsym_comma.c lsym_comment.c lsym_do.c lsym_unary_op.c lsym_while.c t_misc.sh Log Message: tests/indent: explain, clean up and add some tests To generate a diff of this commit: cvs rdiff -u -r1.5 -r1.6 src/tests/usr.bin/indent/fmt_block.c \ src/tests/usr.bin/indent/lsym_comma.c \ src/tests/usr.bin/indent/lsym_comment.c \ src/tests/usr.bin/indent/lsym_do.c \ src/tests/usr.bin/indent/lsym_unary_op.c cvs rdiff -u -r1.37 -r1.38 src/tests/usr.bin/indent/fmt_decl.c cvs rdiff -u -r1.6 -r1.7 src/tests/usr.bin/indent/lsym_binary_op.c cvs rdiff -u -r1.4 -r1.5 src/tests/usr.bin/indent/lsym_while.c cvs rdiff -u -r1.22 -r1.23 src/tests/usr.bin/indent/t_misc.sh Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/tests/usr.bin/indent
Module Name:src Committed By: rillig Date: Sat May 13 06:52:48 UTC 2023 Modified Files: src/tests/usr.bin/indent: fmt_block.c fmt_decl.c lsym_binary_op.c lsym_comma.c lsym_comment.c lsym_do.c lsym_unary_op.c lsym_while.c t_misc.sh Log Message: tests/indent: explain, clean up and add some tests To generate a diff of this commit: cvs rdiff -u -r1.5 -r1.6 src/tests/usr.bin/indent/fmt_block.c \ src/tests/usr.bin/indent/lsym_comma.c \ src/tests/usr.bin/indent/lsym_comment.c \ src/tests/usr.bin/indent/lsym_do.c \ src/tests/usr.bin/indent/lsym_unary_op.c cvs rdiff -u -r1.37 -r1.38 src/tests/usr.bin/indent/fmt_decl.c cvs rdiff -u -r1.6 -r1.7 src/tests/usr.bin/indent/lsym_binary_op.c cvs rdiff -u -r1.4 -r1.5 src/tests/usr.bin/indent/lsym_while.c cvs rdiff -u -r1.22 -r1.23 src/tests/usr.bin/indent/t_misc.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/fmt_block.c diff -u src/tests/usr.bin/indent/fmt_block.c:1.5 src/tests/usr.bin/indent/fmt_block.c:1.6 --- src/tests/usr.bin/indent/fmt_block.c:1.5 Thu May 11 09:28:53 2023 +++ src/tests/usr.bin/indent/fmt_block.c Sat May 13 06:52:48 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: fmt_block.c,v 1.5 2023/05/11 09:28:53 rillig Exp $ */ +/* $NetBSD: fmt_block.c,v 1.6 2023/05/13 06:52:48 rillig Exp $ */ /* * Tests for formatting blocks of statements and declarations. @@ -23,6 +23,10 @@ function(void) } //indent end +/* + * Before 2023-05-11, indent incorrectly merged the '} {' into a single line, + * even though they are completely unrelated. + */ //indent run-equals-input Index: src/tests/usr.bin/indent/lsym_comma.c diff -u src/tests/usr.bin/indent/lsym_comma.c:1.5 src/tests/usr.bin/indent/lsym_comma.c:1.6 --- src/tests/usr.bin/indent/lsym_comma.c:1.5 Sun Apr 24 09:04:12 2022 +++ src/tests/usr.bin/indent/lsym_comma.c Sat May 13 06:52:48 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: lsym_comma.c,v 1.5 2022/04/24 09:04:12 rillig Exp $ */ +/* $NetBSD: lsym_comma.c,v 1.6 2023/05/13 06:52:48 rillig Exp $ */ /* * Tests for the token lsym_comma, which represents a ',' in these contexts: @@ -150,8 +150,6 @@ function(void) /* * In an initializer list, a ',' separates the initializer expressions. - * - * If a ',' starts a line, indent doesn't put a space before it. */ //indent input int arr[] = {1, 2, 3}; Index: src/tests/usr.bin/indent/lsym_comment.c diff -u src/tests/usr.bin/indent/lsym_comment.c:1.5 src/tests/usr.bin/indent/lsym_comment.c:1.6 --- src/tests/usr.bin/indent/lsym_comment.c:1.5 Thu May 11 09:28:53 2023 +++ src/tests/usr.bin/indent/lsym_comment.c Sat May 13 06:52:48 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: lsym_comment.c,v 1.5 2023/05/11 09:28:53 rillig Exp $ */ +/* $NetBSD: lsym_comment.c,v 1.6 2023/05/13 06:52:48 rillig Exp $ */ /* * Tests for the token lsym_comment, which starts a comment. @@ -337,7 +337,7 @@ tab1+++ tab2--- tab3+++ tab4--- tab5+++ } //indent end -/* The comment in the output has moved to the right of the '{'. */ +/* Before 2023-05-11, the comment moved to the right of the '{'. */ //indent run { if (0) /* comment */ { Index: src/tests/usr.bin/indent/lsym_do.c diff -u src/tests/usr.bin/indent/lsym_do.c:1.5 src/tests/usr.bin/indent/lsym_do.c:1.6 --- src/tests/usr.bin/indent/lsym_do.c:1.5 Thu May 11 10:39:26 2023 +++ src/tests/usr.bin/indent/lsym_do.c Sat May 13 06:52:48 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: lsym_do.c,v 1.5 2023/05/11 10:39:26 rillig Exp $ */ +/* $NetBSD: lsym_do.c,v 1.6 2023/05/13 06:52:48 rillig Exp $ */ /* * Tests for the token lsym_do, which represents the keyword 'do' that starts @@ -49,3 +49,40 @@ else_do(int i) } while (0); } //indent end + + +//indent input +void +variants(void) +{ + do stmt(); while (0); + + do { stmt(); } while (0); + + do /* comment */ stmt(); while (0); + + while (0) do {} while (0); +} +//indent end + +//indent run +void +variants(void) +{ + do + stmt(); + while (0); + + do { + stmt(); + } while (0); + + do /* comment */ + stmt(); + while (0); + + while (0) + do { + } while (0); +} +//indent end Index: src/tests/usr.bin/indent/lsym_unary_op.c diff -u src/tests/usr.bin/indent/lsym_unary_op.c:1.5 src/tests/usr.bin/indent/lsym_unary_op.c:1.6 --- src/tests/usr.bin/indent/lsym_unary_op.c:1.5 Sun Apr 24 10:36:37 2022 +++ src/tests/usr.bin/indent/lsym_unary_op.c Sat May 13 06:52:48 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: lsym_unary_op.c,v 1.5 2022/04/24 10:36:37 rillig Exp $ */ +/* $NetBSD: lsym_unary_op.c,v 1.6 2023/05/13 06:52:48 rillig Exp $ */ /* * Tests for the token lsym_unary_op, which represents a unary operator. @@ -8,6 +8,12 @@ * * In a type name, the "unary operator" '*' represents the derivation of a * pointer type. + * + * See also: + * lsym_binary_op.c + * lsym_postfix_op.c + * C11 6.4.6 "Punctuators" + * C11 6.5 "Expressions" */ //indent input @@ -54,3 +60,20 @@ int var = p -> member;
CVS commit: src/tests/usr.bin/indent
Module Name:src Committed By: rillig Date: Thu May 11 21:36:31 UTC 2023 Modified Files: src/tests/usr.bin/indent: lsym_preprocessing.c Log Message: tests/indent: test interaction between preprocessing and comments To generate a diff of this commit: cvs rdiff -u -r1.8 -r1.9 src/tests/usr.bin/indent/lsym_preprocessing.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/tests/usr.bin/indent
Module Name:src Committed By: rillig Date: Thu May 11 21:36:31 UTC 2023 Modified Files: src/tests/usr.bin/indent: lsym_preprocessing.c Log Message: tests/indent: test interaction between preprocessing and comments To generate a diff of this commit: cvs rdiff -u -r1.8 -r1.9 src/tests/usr.bin/indent/lsym_preprocessing.c 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/lsym_preprocessing.c diff -u src/tests/usr.bin/indent/lsym_preprocessing.c:1.8 src/tests/usr.bin/indent/lsym_preprocessing.c:1.9 --- src/tests/usr.bin/indent/lsym_preprocessing.c:1.8 Thu May 11 19:01:35 2023 +++ src/tests/usr.bin/indent/lsym_preprocessing.c Thu May 11 21:36:31 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: lsym_preprocessing.c,v 1.8 2023/05/11 19:01:35 rillig Exp $ */ +/* $NetBSD: lsym_preprocessing.c,v 1.9 2023/05/11 21:36:31 rillig Exp $ */ /* * Tests for the token lsym_preprocessing, which represents a '#' that starts @@ -241,3 +241,33 @@ do {\ //indent end //indent run-equals-input + + +/* + * The 'INDENT OFF' state is global, it does not depend on the preprocessing + * directives, otherwise the declarations for 'on' and 'after' would be moved + * to column 1. + */ +//indent input +int first_line; + int before; +#if 0 +/*INDENT OFF*/ + int off; +#else + int on; +#endif + int after; +//indent end + +//indent run -di0 +int first_line; +int before; +#if 0 +/*INDENT OFF*/ + int off; +#else + int on; +#endif + int after; +//indent end
CVS commit: src/tests/usr.bin/indent
Module Name:src Committed By: rillig Date: Thu May 11 18:36:36 UTC 2023 Modified Files: src/tests/usr.bin/indent: lsym_preprocessing.c Log Message: tests/indent: test multi-line comments in preprocessing lines To generate a diff of this commit: cvs rdiff -u -r1.5 -r1.6 src/tests/usr.bin/indent/lsym_preprocessing.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/tests/usr.bin/indent
Module Name:src Committed By: rillig Date: Thu May 11 18:36:36 UTC 2023 Modified Files: src/tests/usr.bin/indent: lsym_preprocessing.c Log Message: tests/indent: test multi-line comments in preprocessing lines To generate a diff of this commit: cvs rdiff -u -r1.5 -r1.6 src/tests/usr.bin/indent/lsym_preprocessing.c 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/lsym_preprocessing.c diff -u src/tests/usr.bin/indent/lsym_preprocessing.c:1.5 src/tests/usr.bin/indent/lsym_preprocessing.c:1.6 --- src/tests/usr.bin/indent/lsym_preprocessing.c:1.5 Sun Apr 24 10:36:37 2022 +++ src/tests/usr.bin/indent/lsym_preprocessing.c Thu May 11 18:36:36 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: lsym_preprocessing.c,v 1.5 2022/04/24 10:36:37 rillig Exp $ */ +/* $NetBSD: lsym_preprocessing.c,v 1.6 2023/05/11 18:36:36 rillig Exp $ */ /* * Tests for the token lsym_preprocessing, which represents a '#' that starts @@ -213,3 +213,33 @@ int unary_plus = #else/* comment */ #endif/* comment */ //indent end + + +/* + * Multi-line comments in preprocessing lines. + */ +//indent input +#define eol_comment // EOL + +#define wrap_comment /* line 1 + * line 2 + * line 3 + */ + +#define fixed_comment /*- line 1 + * line 2 + * line 3 + */ +//indent end + +//indent run +#define eol_comment // EOL + +#define wrap_comment /* line 1 line 2 line 3 */ + +/* $ FIXME: Keep the original indentation of the follow-up lines. */ +#define fixed_comment /*- line 1 + * line 2 + * line 3 + */ +//indent end
CVS commit: src/tests/usr.bin/indent
Module Name:src Committed By: rillig Date: Sun Apr 24 09:04:12 UTC 2022 Modified Files: src/tests/usr.bin/indent: Makefile fmt_block.c fmt_decl.c fmt_else_comment.c fmt_expr.c indent_off_on.c label.c lex_char.c lex_ident.c lex_string.c lsym_binary_op.c lsym_case_label.c lsym_colon.c lsym_comma.c lsym_comment.c lsym_do.c lsym_else.c lsym_eof.c lsym_for.c lsym_form_feed.c lsym_funcname.c lsym_if.c lsym_lbrace.c lsym_lparen_or_lbracket.c lsym_newline.c lsym_offsetof.c lsym_period.c lsym_postfix_op.c lsym_preprocessing.c lsym_question.c lsym_rbrace.c lsym_return.c lsym_rparen_or_rbracket.c lsym_semicolon.c lsym_sizeof.c lsym_storage_class.c lsym_switch.c lsym_tag.c lsym_type_in_parentheses.c lsym_type_outside_parentheses.c lsym_typedef.c lsym_unary_op.c lsym_while.c lsym_word.c opt_P.c opt_T.c opt_bacc.c opt_bad.c opt_badp.c opt_bap.c opt_bap_sob.c opt_bbb.c opt_bc.c opt_bl_br.c opt_bs.c opt_c.c opt_cd.c opt_cdb.c opt_ce.c opt_ci.c opt_cli.c opt_cs.c opt_d.c opt_di.c opt_dj.c opt_eei.c opt_ei.c opt_fbs.c opt_fc1.c opt_fcb.c opt_i.c opt_ip.c opt_l.c opt_lc.c opt_ldi.c opt_lp.c opt_lpl.c opt_pcs.c opt_psl.c opt_sc.c opt_sob.c opt_ta.c opt_ts.c opt_ut.c opt_v.c opt_version.c ps_ind_level.c psym_decl.c psym_do.c psym_do_stmt.c psym_else.c psym_for_exprs.c psym_if_expr.c psym_if_expr_stmt.c psym_if_expr_stmt_else.c psym_lbrace.c psym_rbrace.c psym_semicolon.c psym_stmt.c psym_stmt_list.c psym_switch_expr.c psym_while_expr.c t_options.awk t_options.sh token_binary_op.c token_comment.c token_decl.c token_do_stmt.c token_end_of_file.c token_for_exprs.c token_form_feed.c token_funcname.c token_ident.c token_keyword_do.c token_keyword_do_else.c token_keyword_else.c token_keyword_for_if_while.c token_keyword_struct_union_enum.c token_newline.c token_postfix_op.c token_preprocessing.c token_rparen.c token_semicolon.c token_stmt.c token_stmt_list.c token_storage_class.c token_string_prefix.c token_switch_expr.c token_type_def.c token_unary_op.c token_while_expr.c Log Message: tests/indent: change directive from '#' to '//' Using a '//' instead of '#' turns the directives into well-formed C code, resulting in fewer error markers in the editor. To generate a diff of this commit: cvs rdiff -u -r1.43 -r1.44 src/tests/usr.bin/indent/Makefile cvs rdiff -u -r1.3 -r1.4 src/tests/usr.bin/indent/fmt_block.c \ src/tests/usr.bin/indent/fmt_else_comment.c \ src/tests/usr.bin/indent/fmt_expr.c src/tests/usr.bin/indent/label.c \ src/tests/usr.bin/indent/lex_char.c src/tests/usr.bin/indent/lex_string.c \ src/tests/usr.bin/indent/lsym_period.c \ src/tests/usr.bin/indent/lsym_postfix_op.c \ src/tests/usr.bin/indent/lsym_preprocessing.c \ src/tests/usr.bin/indent/lsym_question.c \ src/tests/usr.bin/indent/lsym_rbrace.c \ src/tests/usr.bin/indent/lsym_return.c \ src/tests/usr.bin/indent/lsym_tag.c \ src/tests/usr.bin/indent/lsym_unary_op.c src/tests/usr.bin/indent/opt_T.c \ src/tests/usr.bin/indent/opt_bap_sob.c src/tests/usr.bin/indent/opt_c.c \ src/tests/usr.bin/indent/opt_cd.c src/tests/usr.bin/indent/opt_d.c \ src/tests/usr.bin/indent/opt_i.c src/tests/usr.bin/indent/opt_lc.c \ src/tests/usr.bin/indent/opt_ta.c src/tests/usr.bin/indent/opt_version.c \ src/tests/usr.bin/indent/psym_for_exprs.c \ src/tests/usr.bin/indent/psym_if_expr.c \ src/tests/usr.bin/indent/psym_if_expr_stmt.c \ src/tests/usr.bin/indent/psym_if_expr_stmt_else.c \ src/tests/usr.bin/indent/psym_switch_expr.c \ src/tests/usr.bin/indent/psym_while_expr.c \ src/tests/usr.bin/indent/token_for_exprs.c \ src/tests/usr.bin/indent/token_newline.c \ src/tests/usr.bin/indent/token_preprocessing.c \ src/tests/usr.bin/indent/token_semicolon.c \ src/tests/usr.bin/indent/token_unary_op.c \ src/tests/usr.bin/indent/token_while_expr.c cvs rdiff -u -r1.34 -r1.35 src/tests/usr.bin/indent/fmt_decl.c cvs rdiff -u -r1.7 -r1.8 src/tests/usr.bin/indent/indent_off_on.c \ src/tests/usr.bin/indent/opt_cdb.c src/tests/usr.bin/indent/opt_ci.c \ src/tests/usr.bin/indent/opt_di.c src/tests/usr.bin/indent/opt_eei.c \ src/tests/usr.bin/indent/opt_fc1.c src/tests/usr.bin/indent/opt_fcb.c \ src/tests/usr.bin/indent/opt_psl.c src/tests/usr.bin/indent/opt_v.c cvs rdiff -u -r1.4 -r1.5 src/tests/usr.bin/indent/lex_ident.c \ src/tests/usr.bin/indent/lsym_binary_op.c \ src/tests/usr.bin/indent/lsym_colon.c \ src/tests/usr.bin/indent/lsym_comma.c \ src/tests/usr.bin/indent/lsym_offsetof.c \ src/tests/usr.bin/indent/lsym_sizeof.c \ src/tests/usr.bin/indent/lsym_typedef.c \
CVS commit: src/tests/usr.bin/indent
Module Name:src Committed By: rillig Date: Sun Apr 24 08:52:44 UTC 2022 Modified Files: src/tests/usr.bin/indent: fmt_decl.c lsym_offsetof.c opt_bacc.c opt_badp.c opt_bs.c opt_ci.c opt_fcb.c opt_l.c t_options.awk token_comment.c token_string_prefix.c Log Message: tests/indent: normalize amount of empty lines between test cases To generate a diff of this commit: cvs rdiff -u -r1.33 -r1.34 src/tests/usr.bin/indent/fmt_decl.c cvs rdiff -u -r1.3 -r1.4 src/tests/usr.bin/indent/lsym_offsetof.c \ src/tests/usr.bin/indent/opt_l.c \ src/tests/usr.bin/indent/token_string_prefix.c cvs rdiff -u -r1.8 -r1.9 src/tests/usr.bin/indent/opt_bacc.c \ src/tests/usr.bin/indent/opt_bs.c src/tests/usr.bin/indent/t_options.awk cvs rdiff -u -r1.7 -r1.8 src/tests/usr.bin/indent/opt_badp.c cvs rdiff -u -r1.6 -r1.7 src/tests/usr.bin/indent/opt_ci.c \ src/tests/usr.bin/indent/opt_fcb.c cvs rdiff -u -r1.28 -r1.29 src/tests/usr.bin/indent/token_comment.c 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/fmt_decl.c diff -u src/tests/usr.bin/indent/fmt_decl.c:1.33 src/tests/usr.bin/indent/fmt_decl.c:1.34 --- src/tests/usr.bin/indent/fmt_decl.c:1.33 Fri Apr 22 21:21:20 2022 +++ src/tests/usr.bin/indent/fmt_decl.c Sun Apr 24 08:52:44 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: fmt_decl.c,v 1.33 2022/04/22 21:21:20 rillig Exp $ */ +/* $NetBSD: fmt_decl.c,v 1.34 2022/04/24 08:52:44 rillig Exp $ */ /* * Tests for declarations of global variables, external functions, and local @@ -613,6 +613,7 @@ ToToken(bool cond) #indent end #indent run-equals-input -TToken + /* Since lexi.c 1.153 from 2021-11-25. */ #indent run-equals-input @@ -647,6 +648,7 @@ static CachedDir *dot = NULL; #indent end #indent run-equals-input -TCachedDir + /* Since lexi.c 1.153 from 2021-11-25. */ #indent run-equals-input @@ -713,6 +715,7 @@ CachedDir_Assign(CachedDir **var, Cached #indent end #indent run-equals-input + #indent run-equals-input -TCachedDir Index: src/tests/usr.bin/indent/lsym_offsetof.c diff -u src/tests/usr.bin/indent/lsym_offsetof.c:1.3 src/tests/usr.bin/indent/lsym_offsetof.c:1.4 --- src/tests/usr.bin/indent/lsym_offsetof.c:1.3 Fri Apr 22 21:21:20 2022 +++ src/tests/usr.bin/indent/lsym_offsetof.c Sun Apr 24 08:52:44 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: lsym_offsetof.c,v 1.3 2022/04/22 21:21:20 rillig Exp $ */ +/* $NetBSD: lsym_offsetof.c,v 1.4 2022/04/24 08:52:44 rillig Exp $ */ /* * Tests for the token lsym_offsetof, which represents the keyword 'offsetof' @@ -10,6 +10,7 @@ size_t offset = offsetof(struct s, memb #indent end #indent run-equals-input + #indent run-equals-input -bs /* Index: src/tests/usr.bin/indent/opt_l.c diff -u src/tests/usr.bin/indent/opt_l.c:1.3 src/tests/usr.bin/indent/opt_l.c:1.4 --- src/tests/usr.bin/indent/opt_l.c:1.3 Fri Apr 22 21:21:20 2022 +++ src/tests/usr.bin/indent/opt_l.c Sun Apr 24 08:52:44 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: opt_l.c,v 1.3 2022/04/22 21:21:20 rillig Exp $ */ +/* $NetBSD: opt_l.c,v 1.4 2022/04/24 08:52:44 rillig Exp $ */ /* * Tests for the option '-l', which specifies the maximum length of a line. @@ -27,9 +27,11 @@ * same output. */ #indent end + #indent run-equals-prev-output -lc38 #indent run-equals-input -l78 + #indent run-equals-input -lc78 Index: src/tests/usr.bin/indent/token_string_prefix.c diff -u src/tests/usr.bin/indent/token_string_prefix.c:1.3 src/tests/usr.bin/indent/token_string_prefix.c:1.4 --- src/tests/usr.bin/indent/token_string_prefix.c:1.3 Fri Apr 22 21:21:20 2022 +++ src/tests/usr.bin/indent/token_string_prefix.c Sun Apr 24 08:52:44 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: token_string_prefix.c,v 1.3 2022/04/22 21:21:20 rillig Exp $ */ +/* $NetBSD: token_string_prefix.c,v 1.4 2022/04/24 08:52:44 rillig Exp $ */ /* * Tests for strings of wide characters, which are prefixed with 'L'. @@ -15,7 +15,9 @@ wchar_t wide_string[] = L"wide string"; * string literal. */ #indent run-equals-input -di0 + #indent run-equals-input -di0 -l25 + #indent run-equals-input -di0 -l1 Index: src/tests/usr.bin/indent/opt_bacc.c diff -u src/tests/usr.bin/indent/opt_bacc.c:1.8 src/tests/usr.bin/indent/opt_bacc.c:1.9 --- src/tests/usr.bin/indent/opt_bacc.c:1.8 Sat Apr 23 06:43:23 2022 +++ src/tests/usr.bin/indent/opt_bacc.c Sun Apr 24 08:52:44 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: opt_bacc.c,v 1.8 2022/04/23 06:43:23 rillig Exp $ */ +/* $NetBSD: opt_bacc.c,v 1.9 2022/04/24 08:52:44 rillig Exp $ */ /* * Tests for the options '-bacc' and '-nbacc' ("blank line around conditional @@ -145,4 +145,5 @@ int outer_below; #indent end #indent run-equals-input -di0 -bacc + #indent run-equals-input -di0 -nbacc Index: src/tests/usr.bin/indent/opt_bs.c diff -u src/tests/usr.bin/indent/opt_bs.c:1.8 src/tests/usr.bin/indent/opt_bs.c:1.9 --- src/tests/usr.bin/indent/opt_bs.c:1.8 Fri Apr 22
CVS commit: src/tests/usr.bin/indent
Module Name:src Committed By: rillig Date: Sun Apr 24 08:52:44 UTC 2022 Modified Files: src/tests/usr.bin/indent: fmt_decl.c lsym_offsetof.c opt_bacc.c opt_badp.c opt_bs.c opt_ci.c opt_fcb.c opt_l.c t_options.awk token_comment.c token_string_prefix.c Log Message: tests/indent: normalize amount of empty lines between test cases To generate a diff of this commit: cvs rdiff -u -r1.33 -r1.34 src/tests/usr.bin/indent/fmt_decl.c cvs rdiff -u -r1.3 -r1.4 src/tests/usr.bin/indent/lsym_offsetof.c \ src/tests/usr.bin/indent/opt_l.c \ src/tests/usr.bin/indent/token_string_prefix.c cvs rdiff -u -r1.8 -r1.9 src/tests/usr.bin/indent/opt_bacc.c \ src/tests/usr.bin/indent/opt_bs.c src/tests/usr.bin/indent/t_options.awk cvs rdiff -u -r1.7 -r1.8 src/tests/usr.bin/indent/opt_badp.c cvs rdiff -u -r1.6 -r1.7 src/tests/usr.bin/indent/opt_ci.c \ src/tests/usr.bin/indent/opt_fcb.c cvs rdiff -u -r1.28 -r1.29 src/tests/usr.bin/indent/token_comment.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/tests/usr.bin/indent
Module Name:src Committed By: rillig Date: Sat Apr 23 17:25:58 UTC 2022 Modified Files: src/tests/usr.bin/indent: lsym_lparen_or_lbracket.c token_binary_op.c Log Message: tests/indent: add tests for unary and binary operators To generate a diff of this commit: cvs rdiff -u -r1.4 -r1.5 src/tests/usr.bin/indent/lsym_lparen_or_lbracket.c cvs rdiff -u -r1.11 -r1.12 src/tests/usr.bin/indent/token_binary_op.c 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/lsym_lparen_or_lbracket.c diff -u src/tests/usr.bin/indent/lsym_lparen_or_lbracket.c:1.4 src/tests/usr.bin/indent/lsym_lparen_or_lbracket.c:1.5 --- src/tests/usr.bin/indent/lsym_lparen_or_lbracket.c:1.4 Fri Apr 22 21:21:20 2022 +++ src/tests/usr.bin/indent/lsym_lparen_or_lbracket.c Sat Apr 23 17:25:58 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: lsym_lparen_or_lbracket.c,v 1.4 2022/04/22 21:21:20 rillig Exp $ */ +/* $NetBSD: lsym_lparen_or_lbracket.c,v 1.5 2022/04/23 17:25:58 rillig Exp $ */ /* * Tests for the token lsym_lparen_or_lbracket, which represents a '(' or '[' @@ -15,12 +15,102 @@ * In a 'sizeof' expression, '(' is required if the argument is a type name. * * After one of the keywords 'for', 'if', 'switch' or 'while', the controlling - * expression must be enclosed in '(' and ')'. + * expression must be enclosed in '(' and ')'; see lsym_for.c, lsym_if.c, + * lsym_switch.c, lsym_while.c. * - * In an expression, '(' followed by a type name starts a cast expression. + * In an expression, '(' followed by a type name starts a cast expression or + * a compound literal. + * + * In a declaration, '[' derives an array type. + * + * In an expression, '[' starts an array subscript. + */ + +/* The '(' in a type name derives a function type. */ +#indent input +typedef void signal_handler(int); +void (*signal(void (*)(int)))(int); +#indent end + +#indent run +typedef void signal_handler(int); +void (*signal(void (*)(int)))(int); +#indent end + + +/* + * The '(' in an expression overrides operator precedence. In multi-line + * expressions, the continuation lines are aligned on the parentheses. */ +#indent input +int nested = ( + ( + ( + ( +1 + 4 + ) + ) + ) +); +#indent end + +#indent run +int nested = ( + ( + ( + ( + 1 + 4 + ) + ) + ) +); +#indent end + + +/* The '(' in a function call expression starts the argument list. */ +#indent input +int var = macro_call ( arg1, arg2 ,arg3); +#indent end + +#indent run +int var = macro_call(arg1, arg2, arg3); +#indent end + + +/* + * The '(' in a sizeof expression is required for type names and optional for + * expressions. + */ +#indent input +size_t sizeof_typename = sizeof ( int ); +size_t sizeof_expr = sizeof ( 12345 ) ; +#indent end + +#indent run +size_t sizeof_typename = sizeof(int); +size_t sizeof_expr = sizeof(12345); +#indent end + + +/* The '[' in a type name derives an array type. */ +#indent input +int array_of_numbers[100]; +#indent end + +#indent run +int array_of_numbers[100]; +#indent end + + +/* The '[' in an expression accesses an array element. */ +#indent input +int second_prime = [1]; +#indent end + +#indent run +int second_prime = [1]; +#indent end -// TODO: Add systematic tests for all cases. #indent input void Index: src/tests/usr.bin/indent/token_binary_op.c diff -u src/tests/usr.bin/indent/token_binary_op.c:1.11 src/tests/usr.bin/indent/token_binary_op.c:1.12 --- src/tests/usr.bin/indent/token_binary_op.c:1.11 Sat Apr 23 09:35:26 2022 +++ src/tests/usr.bin/indent/token_binary_op.c Sat Apr 23 17:25:58 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: token_binary_op.c,v 1.11 2022/04/23 09:35:26 rillig Exp $ */ +/* $NetBSD: token_binary_op.c,v 1.12 2022/04/23 17:25:58 rillig Exp $ */ /* * Tests for binary operators like '+', '&&' and several others. @@ -15,15 +15,10 @@ void punctuators(void) { - int brackets = array[subscript]; - int parentheses = function(argument); int braces = { initializer }; int period = structure.member; int arrow = structure->member; - number = function(argument1, argument2); - number = function(argument), number; - /* digraphs */ number = array<:subscript:>; number = (int)<% initializer %>; @@ -34,16 +29,11 @@ punctuators(void) 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; - 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. */ @@ -83,9 +73,9 @@ long_run_of_operators(void) /* - * For '+' and '-', this does not work since the lexer has to - * distinguish
CVS commit: src/tests/usr.bin/indent
Module Name:src Committed By: rillig Date: Sat Apr 23 17:25:58 UTC 2022 Modified Files: src/tests/usr.bin/indent: lsym_lparen_or_lbracket.c token_binary_op.c Log Message: tests/indent: add tests for unary and binary operators To generate a diff of this commit: cvs rdiff -u -r1.4 -r1.5 src/tests/usr.bin/indent/lsym_lparen_or_lbracket.c cvs rdiff -u -r1.11 -r1.12 src/tests/usr.bin/indent/token_binary_op.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/tests/usr.bin/indent
Module Name:src Committed By: rillig Date: Sat Apr 23 09:35:26 UTC 2022 Modified Files: src/tests/usr.bin/indent: lsym_binary_op.c lsym_unary_op.c token_binary_op.c Log Message: tests/indent: migrate tests for unary and binary operators To generate a diff of this commit: cvs rdiff -u -r1.3 -r1.4 src/tests/usr.bin/indent/lsym_binary_op.c cvs rdiff -u -r1.2 -r1.3 src/tests/usr.bin/indent/lsym_unary_op.c cvs rdiff -u -r1.10 -r1.11 src/tests/usr.bin/indent/token_binary_op.c 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/lsym_binary_op.c diff -u src/tests/usr.bin/indent/lsym_binary_op.c:1.3 src/tests/usr.bin/indent/lsym_binary_op.c:1.4 --- src/tests/usr.bin/indent/lsym_binary_op.c:1.3 Fri Apr 22 21:21:20 2022 +++ src/tests/usr.bin/indent/lsym_binary_op.c Sat Apr 23 09:35:26 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: lsym_binary_op.c,v 1.3 2022/04/22 21:21:20 rillig Exp $ */ +/* $NetBSD: lsym_binary_op.c,v 1.4 2022/04/23 09:35:26 rillig Exp $ */ /* * Tests for the token lsym_binary_op, which represents a binary operator in @@ -22,7 +22,42 @@ */ #indent input -// TODO: add input +void +binary_operators(void) +{ + /* In the order of appearance in C11 6.5. */ + a = a * a; + a = a / a; + a = a % a; + a = a + a; + a = a - a; + a = a << a; + a = a >> a; + a = a < a; + a = a > a; + a = a <= a; + a = a >= a; + a = a == a; + a = a != a; + a = a & a; + a = a ^ a; + a = a | a; + a = a && a; + a = a || a; + a = a ? a : a; + a = a; + a *= a; + a /= a; + a %= a; + a += a; + a -= a; + a <<= a; + a >>= a; + a &= a; + a ^= a; + a |= a; + a = a, a; +} #indent end #indent run-equals-input Index: src/tests/usr.bin/indent/lsym_unary_op.c diff -u src/tests/usr.bin/indent/lsym_unary_op.c:1.2 src/tests/usr.bin/indent/lsym_unary_op.c:1.3 --- src/tests/usr.bin/indent/lsym_unary_op.c:1.2 Fri Apr 22 21:21:20 2022 +++ src/tests/usr.bin/indent/lsym_unary_op.c Sat Apr 23 09:35:26 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: lsym_unary_op.c,v 1.2 2022/04/22 21:21:20 rillig Exp $ */ +/* $NetBSD: lsym_unary_op.c,v 1.3 2022/04/23 09:35:26 rillig Exp $ */ /* * Tests for the token lsym_unary_op, which represents a unary operator. @@ -11,7 +11,12 @@ */ #indent input -// TODO: add input +void +unary_operators(void) +{ + /* In the order of appearance in C11 6.5. */ + function(a++, a--, ++a, --a, , *a, +a, -a, ~a, !a); +} #indent end #indent run-equals-input Index: src/tests/usr.bin/indent/token_binary_op.c diff -u src/tests/usr.bin/indent/token_binary_op.c:1.10 src/tests/usr.bin/indent/token_binary_op.c:1.11 --- src/tests/usr.bin/indent/token_binary_op.c:1.10 Fri Apr 22 21:21:20 2022 +++ src/tests/usr.bin/indent/token_binary_op.c Sat Apr 23 09:35:26 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: token_binary_op.c,v 1.10 2022/04/22 21:21:20 rillig Exp $ */ +/* $NetBSD: token_binary_op.c,v 1.11 2022/04/23 09:35:26 rillig Exp $ */ /* * Tests for binary operators like '+', '&&' and several others. @@ -21,50 +21,6 @@ punctuators(void) int period = structure.member; int arrow = structure->member; - ++prefix_increment; - postfix_increment++; - --prefix_decrement; - postfix_decrement--; - int *address = - 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; @@ -85,50 +41,6 @@ punctuators(void) int period = structure.member; int arrow = structure->member; - ++prefix_increment; - postfix_increment++; - --prefix_decrement; - postfix_decrement--; - int *address = - 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
CVS commit: src/tests/usr.bin/indent
Module Name:src Committed By: rillig Date: Sat Apr 23 09:35:26 UTC 2022 Modified Files: src/tests/usr.bin/indent: lsym_binary_op.c lsym_unary_op.c token_binary_op.c Log Message: tests/indent: migrate tests for unary and binary operators To generate a diff of this commit: cvs rdiff -u -r1.3 -r1.4 src/tests/usr.bin/indent/lsym_binary_op.c cvs rdiff -u -r1.2 -r1.3 src/tests/usr.bin/indent/lsym_unary_op.c cvs rdiff -u -r1.10 -r1.11 src/tests/usr.bin/indent/token_binary_op.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/tests/usr.bin/indent
Module Name:src Committed By: rillig Date: Sun Feb 13 12:04:37 UTC 2022 Modified Files: src/tests/usr.bin/indent: lsym_lparen_or_lbracket.c Log Message: tests/indent: test token '(' There are already some tests in token_lparen.c that need to be merged. To generate a diff of this commit: cvs rdiff -u -r1.2 -r1.3 src/tests/usr.bin/indent/lsym_lparen_or_lbracket.c 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/lsym_lparen_or_lbracket.c diff -u src/tests/usr.bin/indent/lsym_lparen_or_lbracket.c:1.2 src/tests/usr.bin/indent/lsym_lparen_or_lbracket.c:1.3 --- src/tests/usr.bin/indent/lsym_lparen_or_lbracket.c:1.2 Sun Feb 13 11:07:48 2022 +++ src/tests/usr.bin/indent/lsym_lparen_or_lbracket.c Sun Feb 13 12:04:37 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: lsym_lparen_or_lbracket.c,v 1.2 2022/02/13 11:07:48 rillig Exp $ */ +/* $NetBSD: lsym_lparen_or_lbracket.c,v 1.3 2022/02/13 12:04:37 rillig Exp $ */ /* $FreeBSD$ */ /* @@ -21,8 +21,26 @@ * In an expression, '(' followed by a type name starts a cast expression. */ +// TODO: Add systematic tests for all cases. + #indent input -// TODO: add input +void +function(void) +{ + /* Type casts */ + a = (int)b; + a = (struct tag)b; + /* TODO: The '(int)' is not a type cast, it is a prototype list. */ + a = (int (*)(int))fn; + + /* Not type casts */ + a = sizeof(int) * 2; + a = sizeof(5) * 2; + a = offsetof(struct stat, st_mtime); + + /* Grouping subexpressions */ + a = b + c * d; +} #indent end #indent run-equals-input
CVS commit: src/tests/usr.bin/indent
Module Name:src Committed By: rillig Date: Sun Feb 13 12:04:37 UTC 2022 Modified Files: src/tests/usr.bin/indent: lsym_lparen_or_lbracket.c Log Message: tests/indent: test token '(' There are already some tests in token_lparen.c that need to be merged. To generate a diff of this commit: cvs rdiff -u -r1.2 -r1.3 src/tests/usr.bin/indent/lsym_lparen_or_lbracket.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/tests/usr.bin/indent
Module Name:src Committed By: rillig Date: Sun Feb 13 11:07:48 UTC 2022 Modified Files: src/tests/usr.bin/indent: lsym_lbrace.c lsym_lparen_or_lbracket.c t_errors.sh Log Message: tests/indent: demonstrate the poor handling of compound literals To generate a diff of this commit: cvs rdiff -u -r1.2 -r1.3 src/tests/usr.bin/indent/lsym_lbrace.c cvs rdiff -u -r1.1 -r1.2 src/tests/usr.bin/indent/lsym_lparen_or_lbracket.c cvs rdiff -u -r1.22 -r1.23 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.
CVS commit: src/tests/usr.bin/indent
Module Name:src Committed By: rillig Date: Sun Feb 13 11:07:48 UTC 2022 Modified Files: src/tests/usr.bin/indent: lsym_lbrace.c lsym_lparen_or_lbracket.c t_errors.sh Log Message: tests/indent: demonstrate the poor handling of compound literals To generate a diff of this commit: cvs rdiff -u -r1.2 -r1.3 src/tests/usr.bin/indent/lsym_lbrace.c cvs rdiff -u -r1.1 -r1.2 src/tests/usr.bin/indent/lsym_lparen_or_lbracket.c cvs rdiff -u -r1.22 -r1.23 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/lsym_lbrace.c diff -u src/tests/usr.bin/indent/lsym_lbrace.c:1.2 src/tests/usr.bin/indent/lsym_lbrace.c:1.3 --- src/tests/usr.bin/indent/lsym_lbrace.c:1.2 Sat Nov 20 16:54:17 2021 +++ src/tests/usr.bin/indent/lsym_lbrace.c Sun Feb 13 11:07:48 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: lsym_lbrace.c,v 1.2 2021/11/20 16:54:17 rillig Exp $ */ +/* $NetBSD: lsym_lbrace.c,v 1.3 2022/02/13 11:07:48 rillig Exp $ */ /* $FreeBSD$ */ /* @@ -9,7 +9,7 @@ * * In a function body, '{' starts a block. * - * In an expression, '(type){' starts a compound expression that is typically + * In an expression, '(type){' starts a compound literal that is typically * used in an assignment to a struct or array. * * TODO: try to split this token into lsym_lbrace_block and lsym_lbrace_init. Index: src/tests/usr.bin/indent/lsym_lparen_or_lbracket.c diff -u src/tests/usr.bin/indent/lsym_lparen_or_lbracket.c:1.1 src/tests/usr.bin/indent/lsym_lparen_or_lbracket.c:1.2 --- src/tests/usr.bin/indent/lsym_lparen_or_lbracket.c:1.1 Thu Nov 18 21:19:19 2021 +++ src/tests/usr.bin/indent/lsym_lparen_or_lbracket.c Sun Feb 13 11:07:48 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: lsym_lparen_or_lbracket.c,v 1.1 2021/11/18 21:19:19 rillig Exp $ */ +/* $NetBSD: lsym_lparen_or_lbracket.c,v 1.2 2022/02/13 11:07:48 rillig Exp $ */ /* $FreeBSD$ */ /* @@ -26,3 +26,5 @@ #indent end #indent run-equals-input + +/* See t_errors.sh, test case 'compound_literal'. */ Index: src/tests/usr.bin/indent/t_errors.sh diff -u src/tests/usr.bin/indent/t_errors.sh:1.22 src/tests/usr.bin/indent/t_errors.sh:1.23 --- src/tests/usr.bin/indent/t_errors.sh:1.22 Thu Nov 25 21:48:23 2021 +++ src/tests/usr.bin/indent/t_errors.sh Sun Feb 13 11:07:48 2022 @@ -1,5 +1,5 @@ #! /bin/sh -# $NetBSD: t_errors.sh,v 1.22 2021/11/25 21:48:23 rillig Exp $ +# $NetBSD: t_errors.sh,v 1.23 2022/02/13 11:07:48 rillig Exp $ # # Copyright (c) 2021 The NetBSD Foundation, Inc. # All rights reserved. @@ -495,6 +495,53 @@ EOF } +atf_test_case 'compound_literal' +compound_literal_body() +{ + # Test handling of compound literals (C99 6.5.2.5), as well as casts. + + cat < code.c +void +function(void) +{ + origin = + ((int) + ((-1)* + (struct point){0,0} + ) + ); +} +EOF + + sed '/^#/d' < expected.out +void +function(void) +{ + origin = + ((int) + ((-1) * + (struct point){ +# FIXME: the '{' is part of the expression, not a separate block. + 0, 0 +# FIXME: the '}' is part of the expression, not a separate block. + } +# FIXME: the ')' must be aligned with the corresponding '('. + ) + ); +} +EOF + sed '/^#/d' < expected.err +# FIXME: The parentheses _are_ balanced, the '}' does not end the block. +error: code.c:9: Unbalanced parentheses +warning: code.c:10: Extra ')' +# FIXME: There is no line 12 in the input file. +warning: code.c:12: Extra ')' +EOF + + atf_check -s 'exit:1' -o 'file:expected.out' -e 'file:expected.err' \ + "$indent" -nfc1 -ci12 code.c -st +} + atf_init_test_cases() { atf_add_test_case 'option_unknown' @@ -532,4 +579,5 @@ atf_init_test_cases() atf_add_test_case 'unbalanced_parentheses_3' atf_add_test_case 'search_stmt_comment_segv' atf_add_test_case 'search_stmt_fits_in_one_line' + atf_add_test_case 'compound_literal' }
CVS commit: src/tests/usr.bin/indent
Module Name:src Committed By: rillig Date: Sat Feb 12 19:46:56 UTC 2022 Modified Files: src/tests/usr.bin/indent: lsym_tag.c Log Message: tests/indent: add another test for indentation of enum constants To prevent an overzealous quick hack for indenting enum constants in a typedef, as part of fixing PR#55453. To generate a diff of this commit: cvs rdiff -u -r1.1 -r1.2 src/tests/usr.bin/indent/lsym_tag.c 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/lsym_tag.c diff -u src/tests/usr.bin/indent/lsym_tag.c:1.1 src/tests/usr.bin/indent/lsym_tag.c:1.2 --- src/tests/usr.bin/indent/lsym_tag.c:1.1 Thu Nov 18 21:19:19 2021 +++ src/tests/usr.bin/indent/lsym_tag.c Sat Feb 12 19:46:56 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: lsym_tag.c,v 1.1 2021/11/18 21:19:19 rillig Exp $ */ +/* $NetBSD: lsym_tag.c,v 1.2 2022/02/12 19:46:56 rillig Exp $ */ /* $FreeBSD$ */ /* @@ -6,8 +6,38 @@ * 'struct', 'union' or 'enum' that declare, define or use a tagged type. */ +/* TODO: Add systematic tests for 'struct'. */ +/* TODO: Add systematic tests for 'union'. */ +/* TODO: Add systematic tests for 'enum'. */ + + #indent input -// TODO: add input +int +indent_enum_constants(void) +{ + enum color { + red, + green + }; + enum color colors[] = { + red, + red, + red, + }; + /* + * Ensure that the token sequence 'enum type {' only matches if there + * are no other tokens in between, to prevent statement continuations + * from being indented like enum constant declarations. + * + * See https://gnats.netbsd.org/55453. + */ + if (colors[0] == (enum color)1) { + return 1 + + 2 + + 3; + } + return 0; +} #indent end -#indent run-equals-input +#indent run-equals-input -ci2
CVS commit: src/tests/usr.bin/indent
Module Name:src Committed By: rillig Date: Sat Feb 12 19:46:56 UTC 2022 Modified Files: src/tests/usr.bin/indent: lsym_tag.c Log Message: tests/indent: add another test for indentation of enum constants To prevent an overzealous quick hack for indenting enum constants in a typedef, as part of fixing PR#55453. To generate a diff of this commit: cvs rdiff -u -r1.1 -r1.2 src/tests/usr.bin/indent/lsym_tag.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
CVS commit: src/tests/usr.bin/indent
Module Name:src Committed By: rillig Date: Sat Feb 12 13:38:29 UTC 2022 Modified Files: src/tests/usr.bin/indent: lsym_typedef.c Log Message: tests/indent: demonstrate wrong formatting of enum (since 2019-04-04) Reported by me in PR#55453. To generate a diff of this commit: cvs rdiff -u -r1.1 -r1.2 src/tests/usr.bin/indent/lsym_typedef.c 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/lsym_typedef.c diff -u src/tests/usr.bin/indent/lsym_typedef.c:1.1 src/tests/usr.bin/indent/lsym_typedef.c:1.2 --- src/tests/usr.bin/indent/lsym_typedef.c:1.1 Thu Nov 18 21:19:19 2021 +++ src/tests/usr.bin/indent/lsym_typedef.c Sat Feb 12 13:38:29 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: lsym_typedef.c,v 1.1 2021/11/18 21:19:19 rillig Exp $ */ +/* $NetBSD: lsym_typedef.c,v 1.2 2022/02/12 13:38:29 rillig Exp $ */ /* $FreeBSD$ */ /* @@ -6,8 +6,46 @@ * for giving a type an additional name. */ +/* + * Since 2019-04-04, indent places all enum constants except the first in the + * wrong column, but only if the enum declaration follows a 'typedef'. + * + * https://gnats.netbsd.org/55453 + */ #indent input -// TODO: add input +typedef enum { +TC1, +TC2 +} T; + +enum { +EC1, +EC2 +} E; +#indent end + +/* FIXME: TC2 is indented too far. */ +#indent run -ci4 -i4 +typedef enum { +TC1, + TC2 +} T; + +enum { +EC1, +EC2 +} E; #indent end -#indent run-equals-input +/* FIXME: TC2 is indented too far. */ +#indent run -ci2 +typedef enum { + TC1, + TC2 +} T; + +enum { + EC1, + EC2 +} E; +#indent end