Module Name: src Committed By: rillig Date: Fri Jan 3 16:56:53 UTC 2025
Modified Files: src/tests/usr.bin/indent: psym_if_expr_stmt_else.c Log Message: tests/indent: demonstrate wrong indentation in multi-line else-if To generate a diff of this commit: cvs rdiff -u -r1.5 -r1.6 src/tests/usr.bin/indent/psym_if_expr_stmt_else.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_if_expr_stmt_else.c diff -u src/tests/usr.bin/indent/psym_if_expr_stmt_else.c:1.5 src/tests/usr.bin/indent/psym_if_expr_stmt_else.c:1.6 --- src/tests/usr.bin/indent/psym_if_expr_stmt_else.c:1.5 Thu May 11 09:28:53 2023 +++ src/tests/usr.bin/indent/psym_if_expr_stmt_else.c Fri Jan 3 16:56:53 2025 @@ -1,4 +1,4 @@ -/* $NetBSD: psym_if_expr_stmt_else.c,v 1.5 2023/05/11 09:28:53 rillig Exp $ */ +/* $NetBSD: psym_if_expr_stmt_else.c,v 1.6 2025/01/03 16:56:53 rillig Exp $ */ /* * Tests for the parser symbol psym_if_expr_stmt_else, which represents the @@ -82,3 +82,35 @@ example(_Bool cond) } } //indent end + + +/* + * In many cases, an else-if sequence is written in a single line. + * Occasionally, there are cases in which the code is clearer when the + * 'else' and 'if' are in separate lines. In such a case, the inner 'if' + * statement should be indented like any other statement. + */ +//indent input +void +example(void) +{ + if (cond) + stmt(); + else + if (cond) + stmt(); +} +//indent end + +//indent run +void +example(void) +{ + if (cond) + stmt(); + else + //$ FIXME: wrong indentation. + if (cond) + stmt(); +} +//indent end