Module Name: src Committed By: rillig Date: Mon Nov 1 22:48:56 UTC 2021
Modified Files: src/tests/usr.bin/indent: opt_ci.c Log Message: tests/indent: test option '-ci' There are quite a few tricky special cases, but as they are all listed in the manual page, they are not surprising. To generate a diff of this commit: cvs rdiff -u -r1.1 -r1.2 src/tests/usr.bin/indent/opt_ci.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_ci.c diff -u src/tests/usr.bin/indent/opt_ci.c:1.1 src/tests/usr.bin/indent/opt_ci.c:1.2 --- src/tests/usr.bin/indent/opt_ci.c:1.1 Fri Oct 22 20:54:36 2021 +++ src/tests/usr.bin/indent/opt_ci.c Mon Nov 1 22:48:56 2021 @@ -1,12 +1,85 @@ -/* $NetBSD: opt_ci.c,v 1.1 2021/10/22 20:54:36 rillig Exp $ */ +/* $NetBSD: opt_ci.c,v 1.2 2021/11/01 22:48:56 rillig Exp $ */ /* $FreeBSD$ */ +/* + * Tests for the option '-ci', which controls the indentation of continuation + * lines in statements and declarations, but only inside a function. + */ + +/* + * Top level expressions with and without parentheses. + */ +#indent input +int top_level = 1 + + 2; +int top_level = (1 + + 2 + ( + 3)); +#indent end + +#indent run -ci0 +int top_level = 1 + +2; +int top_level = (1 + + 2 + ( + 3)); +#indent end +#indent run-equals-prev-output -ci2 +#indent run-equals-prev-output -ci4 +#indent run-equals-prev-output -ci8 + +#indent run -ci0 -nlp +int top_level = 1 + +2; +int top_level = (1 + + 2 + ( + 3)); +#indent end + +#indent run -ci2 -nlp +int top_level = 1 + +2; +int top_level = (1 + + 2 + ( + 3)); +#indent end + +/* + * Since '-ci4' is half an indentation level, indent all continuations using + * the same level, no matter how many parentheses there are. The rationale for + * this may have been to prevent that the continuation line has the same + * indentation as a follow-up statement, such as in 'if' statements. + */ +#indent run -ci4 -nlp +int top_level = 1 + +2; +int top_level = (1 + + 2 + ( + 3)); +#indent end + +/* + * Declarations in functions without parentheses. + */ #indent input int sum(int a, int b) { return a + - b; + b; + return first + + second; +} +#indent end + +#indent run -ci0 +int +sum(int a, int b) +{ + return a + + b; + return first + + second; } #indent end @@ -16,5 +89,102 @@ sum(int a, int b) { return a + b; + return first + + second; +} +#indent end + +#indent run -ci4 +int +sum(int a, int b) +{ + return a + + b; + return first + + second; +} +#indent end + +#indent run -ci8 +int +sum(int a, int b) +{ + return a + + b; + return first + + second; +} +#indent end + + +/* + * Continued statements with expressions in parentheses. + */ +#indent input +int +sum(int a, int b) +{ + return (a + + b); + return (first + + second + ( + third)); +} +#indent end + +#indent run -ci0 +int +sum(int a, int b) +{ + return(a + + b); + return(first + + second + ( + third)); +} +#indent end +#indent run-equals-prev-output -ci2 +#indent run-equals-prev-output -ci4 +#indent run-equals-prev-output -ci8 + +#indent run -ci2 -nlp +int +sum(int a, int b) +{ + return(a + + b); + return(first + + second + ( + third)); +} +#indent end + +/* + * Since '-ci4' is half an indentation level, indent all continuations using + * the same level, no matter how many parentheses there are. The rationale for + * this may have been to prevent that the continuation line has the same + * indentation as a follow-up statement, such as in 'if' statements. + */ +#indent run -ci4 -nlp +int +sum(int a, int b) +{ + return(a + + b); + return(first + + second + ( + third)); +} +#indent end + +#indent run -ci8 -nlp +int +sum(int a, int b) +{ + return(a + + b); + return(first + + second + ( + third)); } #indent end