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 the same indentation. - */ -//indent run -eei -i4 -{ - if (a - && b) + stmt(); + while (a +/* $ FIXME: Needs extra indentation. */ + < b) + stmt(); + switch ( +/* $ FIXME: Needs extra indentation. */ + 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. - */ -//indent run -eei -i4 -nlp +/* With a continuation indentation of 2, there is no ambiguity at all. */ +//indent run -eei -i6 -ci2 -nlp { - if (a - && b) - stmt(); + if (a < + b) + stmt(); + if (a + < + b) + stmt(); + while (a + < b) + stmt(); + switch ( + a) + stmt(); } //indent end