Module Name: src Committed By: rillig Date: Sat Oct 16 21:32:10 UTC 2021
Modified Files: src/tests/usr.bin/indent: opt_bap.c opt_bbb.c opt_bc.c opt_bs.c opt_cdb.c opt_ce.c opt_cs.c opt_dj.c opt_eei.c opt_ei.c opt_fbs.c opt_fc1.c opt_fcb.c opt_ip.c opt_lp.c opt_lpl.c opt_pcs.c opt_psl.c opt_sc.c opt_sob.c opt_ut.c opt_v.c Log Message: tests/lint: document and extend the tests for options To generate a diff of this commit: cvs rdiff -u -r1.1 -r1.2 src/tests/usr.bin/indent/opt_bap.c \ src/tests/usr.bin/indent/opt_dj.c src/tests/usr.bin/indent/opt_ut.c \ src/tests/usr.bin/indent/opt_v.c cvs rdiff -u -r1.2 -r1.3 src/tests/usr.bin/indent/opt_bbb.c \ src/tests/usr.bin/indent/opt_bc.c src/tests/usr.bin/indent/opt_bs.c \ src/tests/usr.bin/indent/opt_cdb.c src/tests/usr.bin/indent/opt_ce.c \ src/tests/usr.bin/indent/opt_cs.c src/tests/usr.bin/indent/opt_eei.c \ src/tests/usr.bin/indent/opt_ei.c src/tests/usr.bin/indent/opt_fbs.c \ src/tests/usr.bin/indent/opt_fc1.c src/tests/usr.bin/indent/opt_fcb.c \ src/tests/usr.bin/indent/opt_ip.c src/tests/usr.bin/indent/opt_lp.c \ src/tests/usr.bin/indent/opt_lpl.c src/tests/usr.bin/indent/opt_pcs.c \ src/tests/usr.bin/indent/opt_psl.c src/tests/usr.bin/indent/opt_sc.c \ 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/opt_bap.c diff -u src/tests/usr.bin/indent/opt_bap.c:1.1 src/tests/usr.bin/indent/opt_bap.c:1.2 --- src/tests/usr.bin/indent/opt_bap.c:1.1 Sat Oct 16 03:20:13 2021 +++ src/tests/usr.bin/indent/opt_bap.c Sat Oct 16 21:32:10 2021 @@ -1,13 +1,21 @@ -/* $NetBSD: opt_bap.c,v 1.1 2021/10/16 03:20:13 rillig Exp $ */ +/* $NetBSD: opt_bap.c,v 1.2 2021/10/16 21:32:10 rillig Exp $ */ /* $FreeBSD$ */ +/* + * Tests for the options '-bap' and '-nbap'. + * + * The option '-bap' forces a blank line after every function body. + * + * The option '-nbap' keeps everything as is. + */ + #indent input -static void one_liner(void) { /* FIXME: needs empty line below */ } -static void several_lines(void) { +static void one_liner(void){} +static void several_lines(void) +{ action(); - /* FIXME: needs empty line below */ } -int main(void){/* FIXME: needs empty line below */} +int main(void){} int global_variable; void already_has_blank_line_below(void) @@ -26,18 +34,20 @@ int the_end; #indent run -bap static void one_liner(void) -{ /* FIXME: needs empty line below */ +{ } +/* $ FIXME: needs a blank line here */ static void several_lines(void) { action(); - /* FIXME: needs empty line below */ } +/* $ FIXME: needs a blank line here */ int main(void) -{ /* FIXME: needs empty line below */ +{ } +/* $ FIXME: needs a blank line here */ int global_variable; void @@ -55,27 +65,6 @@ has_several_blank_lines_below(void) int the_end; #indent end -#indent input -static void one_liner(void) {} -static void several_lines(void) { - action(); -} -int main(void){} -int global_variable; - -void already_has_blank_line_below(void) -{ -} - -void has_several_blank_lines_below(void) -{ -} - - - -int the_end; -#indent end - #indent run -nbap static void one_liner(void) Index: src/tests/usr.bin/indent/opt_dj.c diff -u src/tests/usr.bin/indent/opt_dj.c:1.1 src/tests/usr.bin/indent/opt_dj.c:1.2 --- src/tests/usr.bin/indent/opt_dj.c:1.1 Sat Oct 16 03:20:13 2021 +++ src/tests/usr.bin/indent/opt_dj.c Sat Oct 16 21:32:10 2021 @@ -1,6 +1,15 @@ -/* $NetBSD: opt_dj.c,v 1.1 2021/10/16 03:20:13 rillig Exp $ */ +/* $NetBSD: opt_dj.c,v 1.2 2021/10/16 21:32:10 rillig Exp $ */ /* $FreeBSD$ */ +/* + * Tests for the options '-dj' and '-ndj'. + * + * The option '-dj' left-justifies declarations. + * + * The option '-ndj' indents declarations the same as code. + */ + +/* For top-level declarations, '-dj' and '-ndj' produce the same output. */ #indent input int i; int *ip; @@ -19,20 +28,7 @@ const void ******vpppppp; const void ********vpppppppp; #indent end -#indent input -/* FIXME: The options -dj and -ndj produce the same output. */ - -int i; -int *ip; -const char *ccp; -const void *****vppppp; -const void ******vpppppp; -const void ********vpppppppp; -#indent end - #indent run -ndj -/* FIXME: The options -dj and -ndj produce the same output. */ - int i; int *ip; const char *ccp; @@ -40,3 +36,28 @@ const void *****vppppp; const void ******vpppppp; const void ********vpppppppp; #indent end + +#indent input +void example(void) { + int decl; + code(); +} +#indent end + +#indent run -dj +void +example(void) +{ +int decl; + code(); +} +#indent end + +#indent run -ndj +void +example(void) +{ + int decl; + code(); +} +#indent end Index: src/tests/usr.bin/indent/opt_ut.c diff -u src/tests/usr.bin/indent/opt_ut.c:1.1 src/tests/usr.bin/indent/opt_ut.c:1.2 --- src/tests/usr.bin/indent/opt_ut.c:1.1 Sat Oct 16 03:20:13 2021 +++ src/tests/usr.bin/indent/opt_ut.c Sat Oct 16 21:32:10 2021 @@ -1,6 +1,14 @@ -/* $NetBSD: opt_ut.c,v 1.1 2021/10/16 03:20:13 rillig Exp $ */ +/* $NetBSD: opt_ut.c,v 1.2 2021/10/16 21:32:10 rillig Exp $ */ /* $FreeBSD$ */ +/* + * Tests for the options '-ut' and '-nut'. + * + * The option '-ut' uses tabs for indentation. + * + * The option '-nut' uses only spaces for indentation. + */ + #indent input int variable; @@ -9,7 +17,12 @@ void function_declaration(void); void function_definition(void) { - int local_variable; +int local_variable; + +if (arg > 0) +function( +arg - 1 +); } #indent end @@ -22,28 +35,24 @@ void function_definition(void) { int local_variable; -} -#indent end - -#indent input -int var; -void -function(int arg) -{ if (arg > 0) function( - arg - 1 + arg - 1 ); } #indent end #indent run -nut -int var; +int variable; + +void function_declaration(void); void -function(int arg) +function_definition(void) { + int local_variable; + if (arg > 0) function( arg - 1 Index: src/tests/usr.bin/indent/opt_v.c diff -u src/tests/usr.bin/indent/opt_v.c:1.1 src/tests/usr.bin/indent/opt_v.c:1.2 --- src/tests/usr.bin/indent/opt_v.c:1.1 Sat Oct 16 03:20:13 2021 +++ src/tests/usr.bin/indent/opt_v.c Sat Oct 16 21:32:10 2021 @@ -1,6 +1,17 @@ -/* $NetBSD: opt_v.c,v 1.1 2021/10/16 03:20:13 rillig Exp $ */ +/* $NetBSD: opt_v.c,v 1.2 2021/10/16 21:32:10 rillig Exp $ */ /* $FreeBSD$ */ +/* + * Tests for the options '-v' and '-nv'. + * + * The option '-v' enables verbose mode. It outputs some information about + * what's going on under the hood, especially when lines are broken. It also + * outputs a few statistics about line counts and comments at the end. + * + * The option '-nv' disables verbose mode. Only errors and warnings are output + * in this mode, but no progress messages. + */ + #indent input /* * A long comment. Index: src/tests/usr.bin/indent/opt_bbb.c diff -u src/tests/usr.bin/indent/opt_bbb.c:1.2 src/tests/usr.bin/indent/opt_bbb.c:1.3 --- src/tests/usr.bin/indent/opt_bbb.c:1.2 Sat Oct 16 05:40:17 2021 +++ src/tests/usr.bin/indent/opt_bbb.c Sat Oct 16 21:32:10 2021 @@ -1,6 +1,14 @@ -/* $NetBSD: opt_bbb.c,v 1.2 2021/10/16 05:40:17 rillig Exp $ */ +/* $NetBSD: opt_bbb.c,v 1.3 2021/10/16 21:32:10 rillig Exp $ */ /* $FreeBSD$ */ +/* + * Tests for the options '-bbb' and '-nbbb'. + * + * The option '-bbb' forces a blank line before every block comment. + * + * The option '-nbbb' keeps everything as is. + */ + #indent input /* * This is a block comment. Index: src/tests/usr.bin/indent/opt_bc.c diff -u src/tests/usr.bin/indent/opt_bc.c:1.2 src/tests/usr.bin/indent/opt_bc.c:1.3 --- src/tests/usr.bin/indent/opt_bc.c:1.2 Sat Oct 16 05:40:17 2021 +++ src/tests/usr.bin/indent/opt_bc.c Sat Oct 16 21:32:10 2021 @@ -1,6 +1,14 @@ -/* $NetBSD: opt_bc.c,v 1.2 2021/10/16 05:40:17 rillig Exp $ */ +/* $NetBSD: opt_bc.c,v 1.3 2021/10/16 21:32:10 rillig Exp $ */ /* $FreeBSD$ */ +/* + * Tests for the options '-bc' and '-nbc'. + * + * The option '-bc' forces a newline after each comma in a declaration. + * + * The option '-nbc' keeps everything as is. + */ + #indent input int a,b,c; void function_declaration(int a,int b,int c); Index: src/tests/usr.bin/indent/opt_bs.c diff -u src/tests/usr.bin/indent/opt_bs.c:1.2 src/tests/usr.bin/indent/opt_bs.c:1.3 --- src/tests/usr.bin/indent/opt_bs.c:1.2 Sat Oct 16 05:40:17 2021 +++ src/tests/usr.bin/indent/opt_bs.c Sat Oct 16 21:32:10 2021 @@ -1,6 +1,15 @@ -/* $NetBSD: opt_bs.c,v 1.2 2021/10/16 05:40:17 rillig Exp $ */ +/* $NetBSD: opt_bs.c,v 1.3 2021/10/16 21:32:10 rillig Exp $ */ /* $FreeBSD$ */ +/* + * Tests for the options '-bs' and '-nbs'. + * + * The option '-bs' forces a space after the keyword 'sizeof'. + * + * The option '-nbs' removes all whitespace after the keyword 'sizeof', unless + * the next token is a word as well. + */ + #indent input void example(int i) Index: src/tests/usr.bin/indent/opt_cdb.c diff -u src/tests/usr.bin/indent/opt_cdb.c:1.2 src/tests/usr.bin/indent/opt_cdb.c:1.3 --- src/tests/usr.bin/indent/opt_cdb.c:1.2 Sat Oct 16 05:40:17 2021 +++ src/tests/usr.bin/indent/opt_cdb.c Sat Oct 16 21:32:10 2021 @@ -1,6 +1,17 @@ -/* $NetBSD: opt_cdb.c,v 1.2 2021/10/16 05:40:17 rillig Exp $ */ +/* $NetBSD: opt_cdb.c,v 1.3 2021/10/16 21:32:10 rillig Exp $ */ /* $FreeBSD$ */ +/* + * Tests for the options '-cdb' and '-ncdb'. + * + * The option '-cdb' forces the comment delimiter '/' '*' and '*' '/' to be on + * a separate line. This only affects block comments, not comments to the + * right of the code. + * + * The option '-ncdb' compresses multi-line comments to single-line comments, + * as far as possible. + */ + #indent input /* A single-line comment. */ @@ -13,7 +24,33 @@ * multi-line * comment. */ +#indent end + +#indent run -cdb +/* A single-line comment. */ + +/* + * A multi-line comment. + */ + +/* + * A multi-line comment. + */ +#indent end + +#indent run -ncdb +/* A single-line comment. */ +/* A multi-line comment. */ + +/* A multi-line comment. */ +#indent end + + +/* + * Code comments on global declarations. + */ +#indent input int ga; /* A single-line comment. */ int gb; /* A @@ -25,7 +62,28 @@ int gc; /* * multi-line * comment. */ +#indent end + +#indent run -cdb +int ga; /* A single-line comment. */ + +int gb; /* A multi-line comment. */ + +int gc; /* A multi-line comment. */ +#indent end + +#indent run -ncdb +int ga; /* A single-line comment. */ + +int gb; /* A multi-line comment. */ + +int gc; /* A multi-line comment. */ +#indent end +/* + * Block comments that are inside a function. + */ +#indent input void example(void) { @@ -47,22 +105,6 @@ example(void) #indent end #indent run -cdb -/* A single-line comment. */ - -/* - * A multi-line comment. - */ - -/* - * A multi-line comment. - */ - -int ga; /* A single-line comment. */ - -int gb; /* A multi-line comment. */ - -int gc; /* A multi-line comment. */ - void example(void) { @@ -82,18 +124,6 @@ example(void) #indent end #indent run -ncdb -/* A single-line comment. */ - -/* A multi-line comment. */ - -/* A multi-line comment. */ - -int ga; /* A single-line comment. */ - -int gb; /* A multi-line comment. */ - -int gc; /* A multi-line comment. */ - void example(void) { Index: src/tests/usr.bin/indent/opt_ce.c diff -u src/tests/usr.bin/indent/opt_ce.c:1.2 src/tests/usr.bin/indent/opt_ce.c:1.3 --- src/tests/usr.bin/indent/opt_ce.c:1.2 Sat Oct 16 05:40:17 2021 +++ src/tests/usr.bin/indent/opt_ce.c Sat Oct 16 21:32:10 2021 @@ -1,6 +1,15 @@ -/* $NetBSD: opt_ce.c,v 1.2 2021/10/16 05:40:17 rillig Exp $ */ +/* $NetBSD: opt_ce.c,v 1.3 2021/10/16 21:32:10 rillig Exp $ */ /* $FreeBSD$ */ +/* + * Tests for the options '-ce' and '-nce'. + * + * The option '-ce' places the 'else if' in a single line, as if it were only + * a single keyword. + * + * The option '-nce' places the 'else' on the next line. + */ + #indent input void example(int n) Index: src/tests/usr.bin/indent/opt_cs.c diff -u src/tests/usr.bin/indent/opt_cs.c:1.2 src/tests/usr.bin/indent/opt_cs.c:1.3 --- src/tests/usr.bin/indent/opt_cs.c:1.2 Sat Oct 16 05:40:17 2021 +++ src/tests/usr.bin/indent/opt_cs.c Sat Oct 16 21:32:10 2021 @@ -1,6 +1,14 @@ -/* $NetBSD: opt_cs.c,v 1.2 2021/10/16 05:40:17 rillig Exp $ */ +/* $NetBSD: opt_cs.c,v 1.3 2021/10/16 21:32:10 rillig Exp $ */ /* $FreeBSD$ */ +/* + * Tests for the options '-cs' and '-ncs'. + * + * The option '-cs' forces a space after the parentheses of a cast. + * + * The option '-ncs' removes all whitespace after the parentheses of a cast. + */ + #indent input int i0 = (int)3.0; int i1 = (int) 3.0; Index: src/tests/usr.bin/indent/opt_eei.c diff -u src/tests/usr.bin/indent/opt_eei.c:1.2 src/tests/usr.bin/indent/opt_eei.c:1.3 --- src/tests/usr.bin/indent/opt_eei.c:1.2 Sat Oct 16 05:40:17 2021 +++ src/tests/usr.bin/indent/opt_eei.c Sat Oct 16 21:32:10 2021 @@ -1,6 +1,17 @@ -/* $NetBSD: opt_eei.c,v 1.2 2021/10/16 05:40:17 rillig Exp $ */ +/* $NetBSD: opt_eei.c,v 1.3 2021/10/16 21:32:10 rillig Exp $ */ /* $FreeBSD$ */ +/* + * 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. + * + * The option '-neei' indents these conditions in the same way as all other + * continued statements. + */ + #indent input bool less(int a, int b) @@ -42,3 +53,41 @@ less(int a, int b) return true; } #indent end + +/* + * When the indentation level is the same as the continuation indentation, the + * indentation does not show the structure of the code. + */ +#indent run -neei -i4 +bool +less(int a, int b) +{ + if (a < + b) + return true; + if (a + < + b) + return true; +} +#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; + if (a + < + b) + return true; +} +#indent end Index: src/tests/usr.bin/indent/opt_ei.c diff -u src/tests/usr.bin/indent/opt_ei.c:1.2 src/tests/usr.bin/indent/opt_ei.c:1.3 --- src/tests/usr.bin/indent/opt_ei.c:1.2 Sat Oct 16 05:40:17 2021 +++ src/tests/usr.bin/indent/opt_ei.c Sat Oct 16 21:32:10 2021 @@ -1,6 +1,16 @@ -/* $NetBSD: opt_ei.c,v 1.2 2021/10/16 05:40:17 rillig Exp $ */ +/* $NetBSD: opt_ei.c,v 1.3 2021/10/16 21:32:10 rillig Exp $ */ /* $FreeBSD$ */ +/* + * Tests for the options '-ei' and '-nei'. + * + * The option '-ei' indents the 'if' in 'else if' as part of the outer 'if' + * statement. + * + * The option '-nei' treats the 'if' in 'else if' as a separate, independent + * statement that is indented one level deeper than the outer 'if'. + */ + #indent input void example(int n) Index: src/tests/usr.bin/indent/opt_fbs.c diff -u src/tests/usr.bin/indent/opt_fbs.c:1.2 src/tests/usr.bin/indent/opt_fbs.c:1.3 --- src/tests/usr.bin/indent/opt_fbs.c:1.2 Sat Oct 16 05:40:17 2021 +++ src/tests/usr.bin/indent/opt_fbs.c Sat Oct 16 21:32:10 2021 @@ -1,6 +1,18 @@ -/* $NetBSD: opt_fbs.c,v 1.2 2021/10/16 05:40:17 rillig Exp $ */ +/* $NetBSD: opt_fbs.c,v 1.3 2021/10/16 21:32:10 rillig Exp $ */ /* $FreeBSD$ */ +/* + * Tests for the options '-fbs' and '-nfbs'. + * + * The option '-fbs' splits the function declaration and the opening brace + * across two lines. + * + * The option '-nfbs' places the opening brace of a function definition in the + * same line as the function declaration. + * + * See '-bl', '-br'. + */ + #indent input void example(int n) {} #indent end Index: src/tests/usr.bin/indent/opt_fc1.c diff -u src/tests/usr.bin/indent/opt_fc1.c:1.2 src/tests/usr.bin/indent/opt_fc1.c:1.3 --- src/tests/usr.bin/indent/opt_fc1.c:1.2 Sat Oct 16 05:40:17 2021 +++ src/tests/usr.bin/indent/opt_fc1.c Sat Oct 16 21:32:10 2021 @@ -1,6 +1,14 @@ -/* $NetBSD: opt_fc1.c,v 1.2 2021/10/16 05:40:17 rillig Exp $ */ +/* $NetBSD: opt_fc1.c,v 1.3 2021/10/16 21:32:10 rillig Exp $ */ /* $FreeBSD$ */ +/* + * Tests for the options '-fc1' and '-nfc1'. + * + * The option '-fc1' formats comments in column 1. + * + * The option '-nfc1' prevents comments in column 1 as is. + */ + #indent input /* * A comment @@ -9,7 +17,29 @@ * * */ +#indent end + +#indent run -fc1 +/* + * A comment in column 1. + * + * + * + */ +#indent end + +#indent run -nfc1 +/* + * A comment + * in column 1. + * + * + * + */ +#indent end + +#indent input /* $ Neither indentation nor surrounding spaces. */ /*narrow*/ @@ -24,27 +54,9 @@ /* $ Both comment texts get surrounded by spaces. */ /*block1*//*block2*/ - -/* - * A multi-line comment that starts - * in column 1. - *//* followed by another multi-line comment - * that starts in column 4. - */ - -/* comment */ int decl2; /* comment */ -/* looooooooooooooooooooooooooooooooooooooooong first comment */ int decl2; /* second comment */ -/* first comment */ int decl2; /* looooooooooooooooooooooooooooooooooooooooong second comment */ #indent end #indent run -fc1 -/* - * A comment in column 1. - * - * - * - */ - /* $ The comment text got surrounded by spaces. */ /* narrow */ @@ -59,29 +71,9 @@ /* $ Both comment texts got surrounded by spaces. */ /* block1 *//* block2 */ - -/* - * A multi-line comment that starts in column 1. - * - * followed by another multi-line comment that starts in column 4. - */ -/* $ XXX: The two comments have been merged into a single comment. */ - - /* comment */ int decl2; /* comment */ - /* looooooooooooooooooooooooooooooooooooooooong first comment */ int decl2; /* second comment */ - /* first comment */ int decl2; /* looooooooooooooooooooooooooooooooooooooooong - * second comment */ #indent end #indent run -nfc1 -/* - * A comment - * in column 1. - * - * - * - */ - /* $ No spaces got added around the comment text. */ /*narrow*/ @@ -109,7 +101,28 @@ /* $ formatted, but the comment 'block1' was moved from column 1 to 2. */ /* $ This is probably because there is a second comment in the same line. */ /*block1*//* block2 */ +#indent end + +#indent input +/* + * A multi-line comment that starts + * in column 1. + *//* followed by another multi-line comment + * that starts in column 4. + */ +#indent end + +#indent run -fc1 +/* + * A multi-line comment that starts in column 1. + * + * followed by another multi-line comment that starts in column 4. + */ +/* $ XXX: The two comments have been merged into a single comment. */ +#indent end + +#indent run -nfc1 /* * A multi-line comment that starts * in column 1. @@ -117,7 +130,23 @@ * followed by another multi-line comment that starts in column 4. */ /* $ XXX: The two comments have been merged into a single comment. */ +#indent end + +#indent input +/* comment */ int decl2; /* comment */ +/* looooooooooooooooooooooooooooooooooooooooong first comment */ int decl2; /* second comment */ +/* first comment */ int decl2; /* looooooooooooooooooooooooooooooooooooooooong second comment */ +#indent end + +#indent run -fc1 + /* comment */ int decl2; /* comment */ + /* looooooooooooooooooooooooooooooooooooooooong first comment */ int decl2; /* second comment */ + /* first comment */ int decl2; /* looooooooooooooooooooooooooooooooooooooooong + * second comment */ +#indent end + +#indent run -nfc1 /* comment */ int decl2; /* comment */ /* looooooooooooooooooooooooooooooooooooooooong first comment */ int decl2; /* second comment */ /* first comment */ int decl2; /* looooooooooooooooooooooooooooooooooooooooong Index: src/tests/usr.bin/indent/opt_fcb.c diff -u src/tests/usr.bin/indent/opt_fcb.c:1.2 src/tests/usr.bin/indent/opt_fcb.c:1.3 --- src/tests/usr.bin/indent/opt_fcb.c:1.2 Sat Oct 16 05:40:17 2021 +++ src/tests/usr.bin/indent/opt_fcb.c Sat Oct 16 21:32:10 2021 @@ -1,9 +1,18 @@ -/* $NetBSD: opt_fcb.c,v 1.2 2021/10/16 05:40:17 rillig Exp $ */ +/* $NetBSD: opt_fcb.c,v 1.3 2021/10/16 21:32:10 rillig Exp $ */ /* $FreeBSD$ */ -#indent input +/* + * Tests for the options '-fcb' and '-nfcb'. + * + * The option '-fcb' formats block comments (ones that begin with '/' '*' + * '\n'). + * + * The option '-nfcb' formats block comments like other box comments. + */ + /* FIXME: The options -fcb and -nfcb result in exactly the same output. */ +#indent input /* Not * * so carefully @@ -15,7 +24,38 @@ * efu for ted com t * lly box . */ +#indent end + +#indent run -fcb +/* + * Not + * + * so carefully formatted comment + */ + +/*- + * car mat men + * efu for ted com t + * lly box . + */ +#indent end + +#indent run -nfcb +/* + * Not + * + * so carefully formatted comment + */ + +/*- + * car mat men + * efu for ted com t + * lly box . + */ +#indent end + +#indent input void example(void) { @@ -34,20 +74,6 @@ example(void) #indent end #indent run -fcb -/* FIXME: The options -fcb and -nfcb result in exactly the same output. */ - -/* - * Not - * - * so carefully formatted comment - */ - -/*- - * car mat men - * efu for ted com t - * lly box . - */ - void example(void) { @@ -66,20 +92,6 @@ example(void) #indent end #indent run -nfcb -/* FIXME: The options -fcb and -nfcb result in exactly the same output. */ - -/* - * Not - * - * so carefully formatted comment - */ - -/*- - * car mat men - * efu for ted com t - * lly box . - */ - void example(void) { Index: src/tests/usr.bin/indent/opt_ip.c diff -u src/tests/usr.bin/indent/opt_ip.c:1.2 src/tests/usr.bin/indent/opt_ip.c:1.3 --- src/tests/usr.bin/indent/opt_ip.c:1.2 Sat Oct 16 05:40:17 2021 +++ src/tests/usr.bin/indent/opt_ip.c Sat Oct 16 21:32:10 2021 @@ -1,9 +1,17 @@ -/* $NetBSD: opt_ip.c,v 1.2 2021/10/16 05:40:17 rillig Exp $ */ +/* $NetBSD: opt_ip.c,v 1.3 2021/10/16 21:32:10 rillig Exp $ */ /* $FreeBSD$ */ -#indent input +/* + * Tests for the options '-ip' and '-nip'. + * + * The option '-ip' indents parameter declarations from the left margin. + * + * The option '-nip' TODO. + */ + /* FIXME: The options -ip and -nip produce the same output. */ +#indent input int several_parameters_1(int a, int b, @@ -23,8 +31,6 @@ const char *cp); #indent end #indent run -ip -/* FIXME: The options -ip and -nip produce the same output. */ - int several_parameters_1(int a, int b, @@ -44,8 +50,6 @@ several_parameters_3( #indent end #indent run -nip -/* FIXME: The options -ip and -nip produce the same output. */ - int several_parameters_1(int a, int b, Index: src/tests/usr.bin/indent/opt_lp.c diff -u src/tests/usr.bin/indent/opt_lp.c:1.2 src/tests/usr.bin/indent/opt_lp.c:1.3 --- src/tests/usr.bin/indent/opt_lp.c:1.2 Sat Oct 16 05:40:17 2021 +++ src/tests/usr.bin/indent/opt_lp.c Sat Oct 16 21:32:10 2021 @@ -1,6 +1,18 @@ -/* $NetBSD: opt_lp.c,v 1.2 2021/10/16 05:40:17 rillig Exp $ */ +/* $NetBSD: opt_lp.c,v 1.3 2021/10/16 21:32:10 rillig Exp $ */ /* $FreeBSD$ */ +/* + * Tests for the options '-lp' and '-nlp'. + * + * The option '-lp' lines up code surrounded by parentheses in continuation + * lines. With '-lp', if a line has a left parenthesis that is not closed on + * that line, continuation lines are lined up to start at the character + * position just after the left parenthesis. + * + * The option '-nlp' indents continuation lines with the continuation + * indentation; see '-ci'. + */ + #indent input void example(void) Index: src/tests/usr.bin/indent/opt_lpl.c diff -u src/tests/usr.bin/indent/opt_lpl.c:1.2 src/tests/usr.bin/indent/opt_lpl.c:1.3 --- src/tests/usr.bin/indent/opt_lpl.c:1.2 Sat Oct 16 05:40:17 2021 +++ src/tests/usr.bin/indent/opt_lpl.c Sat Oct 16 21:32:10 2021 @@ -1,6 +1,21 @@ -/* $NetBSD: opt_lpl.c,v 1.2 2021/10/16 05:40:17 rillig Exp $ */ +/* $NetBSD: opt_lpl.c,v 1.3 2021/10/16 21:32:10 rillig Exp $ */ /* $FreeBSD$ */ +/* + * Tests for the options '-lpl' and '-nlpl'. + * + * The option '-lpl' lines up code surrounded by parentheses in continuation + * lines, even if it would extend past the right margin. + * + * The option '-nlpl' moves continuation lines that would stick over the right + * margin to the left, to keep it within the margin, if that does not require + * placing it to the left of the prevailing indentation level. + * + * These switches have no effect if '-nlp' is selected. + */ + +/* $ TODO: Add code that differs between -lpl and -nlpl. */ + #indent input void example(void) @@ -26,7 +41,6 @@ example(void) #indent end #indent run -lpl -/* $ TODO: Add code that differs between -lpl and -nlpl. */ void example(void) { @@ -53,7 +67,6 @@ example(void) #indent end #indent run -nlpl -/* $ TODO: Add code that differs between -lpl and -nlpl. */ void example(void) { Index: src/tests/usr.bin/indent/opt_pcs.c diff -u src/tests/usr.bin/indent/opt_pcs.c:1.2 src/tests/usr.bin/indent/opt_pcs.c:1.3 --- src/tests/usr.bin/indent/opt_pcs.c:1.2 Sat Oct 16 05:40:17 2021 +++ src/tests/usr.bin/indent/opt_pcs.c Sat Oct 16 21:32:10 2021 @@ -1,13 +1,23 @@ -/* $NetBSD: opt_pcs.c,v 1.2 2021/10/16 05:40:17 rillig Exp $ */ +/* $NetBSD: opt_pcs.c,v 1.3 2021/10/16 21:32:10 rillig Exp $ */ /* $FreeBSD$ */ +/* + * Tests for the options '-pcs' and '-npcs'. + * + * The option '-pcs' adds a space in a function call expression, between the + * function name and the opening parenthesis. + * + * The option '-npcs' removes any whitespace from a function call expression, + * between the function name and the opening parenthesis. + */ + #indent input void example(void) { function_call(); - function_call(1); - function_call(1,2,3); + function_call (1); + function_call (1,2,3); } #indent end Index: src/tests/usr.bin/indent/opt_psl.c diff -u src/tests/usr.bin/indent/opt_psl.c:1.2 src/tests/usr.bin/indent/opt_psl.c:1.3 --- src/tests/usr.bin/indent/opt_psl.c:1.2 Sat Oct 16 05:40:17 2021 +++ src/tests/usr.bin/indent/opt_psl.c Sat Oct 16 21:32:10 2021 @@ -1,15 +1,63 @@ -/* $NetBSD: opt_psl.c,v 1.2 2021/10/16 05:40:17 rillig Exp $ */ +/* $NetBSD: opt_psl.c,v 1.3 2021/10/16 21:32:10 rillig Exp $ */ /* $FreeBSD$ */ +/* + * Tests for the options '-psl' and '-npsl'. + * + * The option '-psl' starts a new line for the function name in a function + * definition. + * + * The option '-npsl' puts the function name in the same line as its return + * type. + */ + +/* Single-line function declarations are not affected by these options. */ #indent input void function_declaration(void); - -void function_definition(void) {} #indent end #indent run -psl void function_declaration(void); +#indent end +#indent run -npsl +void function_declaration(void); +#indent end + +/* + * Multi-line function declarations are affected by these options since indent + * wrongly assumes they were function definitions, not declarations. + */ +#indent input +void function_declaration( +void); +#indent end + +#indent run -psl +void +function_declaration( + void); +#indent end + +/* + * In a function definition (which indent wrongly assumes here), in contrast + * to a declaration, the function name is not indented to column 17. + */ +#indent run -npsl +void function_declaration( + void); +#indent end + +/* + * In a function definition, in contrast to a declaration, the function name + * is not indented to column 17 since the other function definitions are too + * far away. + */ +#indent input +void function_definition(void) {} +#indent end + +#indent run -psl void function_definition(void) { @@ -17,8 +65,6 @@ function_definition(void) #indent end #indent run -npsl -void function_declaration(void); - void function_definition(void) { } Index: src/tests/usr.bin/indent/opt_sc.c diff -u src/tests/usr.bin/indent/opt_sc.c:1.2 src/tests/usr.bin/indent/opt_sc.c:1.3 --- src/tests/usr.bin/indent/opt_sc.c:1.2 Sat Oct 16 05:40:17 2021 +++ src/tests/usr.bin/indent/opt_sc.c Sat Oct 16 21:32:10 2021 @@ -1,46 +1,71 @@ -/* $NetBSD: opt_sc.c,v 1.2 2021/10/16 05:40:17 rillig Exp $ */ +/* $NetBSD: opt_sc.c,v 1.3 2021/10/16 21:32:10 rillig Exp $ */ /* $FreeBSD$ */ +/* + * Tests for the options '-sc' and '-nsc'. + * + * The option '-sc' starts continuation lines of block comments with " * ". + * + * The option '-nsc' does not use asterisks for aligning the continuation + * lines of comments. + */ + #indent input /* comment without asterisks */ - -/* -** This comment style is used by Lua. -*/ - -/** - * Javadoc, adopted by several other programming languages. - */ #indent end #indent run -sc /* * comment without asterisks */ +#indent end -/* $ XXX: The additional '*' is debatable. */ +#indent run -nsc /* - * * This comment style is used by Lua. +comment without asterisks */ +#indent end -/** - * Javadoc, adopted by several other programming languages. + +#indent input +/* +** This comment style is used by Lua. +*/ +#indent end + +/* XXX: The additional '*' is debatable. */ +#indent run -sc +/* + * * This comment style is used by Lua. */ #indent end +/* This comment, as rewritten by indent, is not actually used by Lua. */ #indent run -nsc /* -comment without asterisks + * This comment style is used by Lua. */ +#indent end -/* $ This comment, as rewritten by indent, is not actually used by Lua. */ /* - * This comment style is used by Lua. + * Comments that start with '*' or '-' do not get modified at all. + */ +#indent input +/** + * Javadoc, adopted by several other programming languages. */ +#indent end +#indent run -sc +/** + * Javadoc, adopted by several other programming languages. + */ +#indent end + +#indent run -nsc /** * Javadoc, adopted by several other programming languages. */ Index: src/tests/usr.bin/indent/opt_sob.c diff -u src/tests/usr.bin/indent/opt_sob.c:1.2 src/tests/usr.bin/indent/opt_sob.c:1.3 --- src/tests/usr.bin/indent/opt_sob.c:1.2 Sat Oct 16 05:40:17 2021 +++ src/tests/usr.bin/indent/opt_sob.c Sat Oct 16 21:32:10 2021 @@ -1,9 +1,22 @@ -/* $NetBSD: opt_sob.c,v 1.2 2021/10/16 05:40:17 rillig Exp $ */ +/* $NetBSD: opt_sob.c,v 1.3 2021/10/16 21:32:10 rillig Exp $ */ /* $FreeBSD$ */ +/* + * Tests for the options '-sob' and '-nsob'. + * + * The option '-sob' swallows optional blank lines. + * + * XXX: The manual page says: "You can use this to get rid of blank lines + * after declarations."; double check this. + * + * The option '-nsob' keeps optional blank lines as is. + */ + +/* + * FIXME: There are lots of 'optional blank lines' here that should be + * swallowed. + */ #indent input -/* $ FIXME: There are lots of 'optional blank lines' here that should */ -/* $ FIXME: be swallowed. */ void function_declaration(void);