Module Name: src Committed By: rillig Date: Sat Apr 23 09:01:03 UTC 2022
Modified Files: src/distrib/sets/lists/tests: mi src/tests/usr.bin/indent: Makefile psym_if_expr.c psym_if_expr_stmt.c psym_if_expr_stmt_else.c Removed Files: src/tests/usr.bin/indent: token_if_expr.c token_if_expr_stmt.c token_if_expr_stmt_else.c Log Message: tests/indent: migrate a few token tests to psym tests To generate a diff of this commit: cvs rdiff -u -r1.1194 -r1.1195 src/distrib/sets/lists/tests/mi cvs rdiff -u -r1.40 -r1.41 src/tests/usr.bin/indent/Makefile cvs rdiff -u -r1.2 -r1.3 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 cvs rdiff -u -r1.2 -r0 src/tests/usr.bin/indent/token_if_expr.c \ src/tests/usr.bin/indent/token_if_expr_stmt.c \ src/tests/usr.bin/indent/token_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/distrib/sets/lists/tests/mi diff -u src/distrib/sets/lists/tests/mi:1.1194 src/distrib/sets/lists/tests/mi:1.1195 --- src/distrib/sets/lists/tests/mi:1.1194 Wed Apr 20 07:41:04 2022 +++ src/distrib/sets/lists/tests/mi Sat Apr 23 09:01:03 2022 @@ -1,4 +1,4 @@ -# $NetBSD: mi,v 1.1194 2022/04/20 07:41:04 blymn Exp $ +# $NetBSD: mi,v 1.1195 2022/04/23 09:01:03 rillig Exp $ # # Note: don't delete entries from here - mark them as "obsolete" instead. # @@ -5265,9 +5265,9 @@ ./usr/tests/usr.bin/indent/token_form_feed.c tests-usr.bin-tests compattestfile,atf ./usr/tests/usr.bin/indent/token_funcname.c tests-usr.bin-tests compattestfile,atf ./usr/tests/usr.bin/indent/token_ident.c tests-usr.bin-tests compattestfile,atf -./usr/tests/usr.bin/indent/token_if_expr.c tests-usr.bin-tests compattestfile,atf -./usr/tests/usr.bin/indent/token_if_expr_stmt.c tests-usr.bin-tests compattestfile,atf -./usr/tests/usr.bin/indent/token_if_expr_stmt_else.c tests-usr.bin-tests compattestfile,atf +./usr/tests/usr.bin/indent/token_if_expr.c tests-obsolete obsolete,atf +./usr/tests/usr.bin/indent/token_if_expr_stmt.c tests-obsolete obsolete,atf +./usr/tests/usr.bin/indent/token_if_expr_stmt_else.c tests-obsolete obsolete,atf ./usr/tests/usr.bin/indent/token_keyword_do.c tests-usr.bin-tests compattestfile,atf ./usr/tests/usr.bin/indent/token_keyword_do_else.c tests-usr.bin-tests compattestfile,atf ./usr/tests/usr.bin/indent/token_keyword_else.c tests-usr.bin-tests compattestfile,atf Index: src/tests/usr.bin/indent/Makefile diff -u src/tests/usr.bin/indent/Makefile:1.40 src/tests/usr.bin/indent/Makefile:1.41 --- src/tests/usr.bin/indent/Makefile:1.40 Fri Apr 22 21:21:20 2022 +++ src/tests/usr.bin/indent/Makefile Sat Apr 23 09:01:03 2022 @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.40 2022/04/22 21:21:20 rillig Exp $ +# $NetBSD: Makefile,v 1.41 2022/04/23 09:01:03 rillig Exp $ .include <bsd.own.mk> @@ -119,9 +119,6 @@ FILES+= token_for_exprs.c FILES+= token_form_feed.c FILES+= token_funcname.c FILES+= token_ident.c -FILES+= token_if_expr.c -FILES+= token_if_expr_stmt.c -FILES+= token_if_expr_stmt_else.c FILES+= token_keyword_do.c FILES+= token_keyword_do_else.c FILES+= token_keyword_else.c Index: src/tests/usr.bin/indent/psym_if_expr.c diff -u src/tests/usr.bin/indent/psym_if_expr.c:1.2 src/tests/usr.bin/indent/psym_if_expr.c:1.3 --- src/tests/usr.bin/indent/psym_if_expr.c:1.2 Fri Apr 22 21:21:20 2022 +++ src/tests/usr.bin/indent/psym_if_expr.c Sat Apr 23 09:01:03 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: psym_if_expr.c,v 1.2 2022/04/22 21:21:20 rillig Exp $ */ +/* $NetBSD: psym_if_expr.c,v 1.3 2022/04/23 09:01:03 rillig Exp $ */ /* * Tests for the parser symbol psym_if_expr, representing the parser state @@ -7,7 +7,16 @@ */ #indent input -// TODO: add input +void function(void) { + if(cond) stmt(); +} #indent end -#indent run-equals-input +#indent run +void +function(void) +{ + if (cond) + stmt(); +} +#indent end Index: src/tests/usr.bin/indent/psym_if_expr_stmt.c diff -u src/tests/usr.bin/indent/psym_if_expr_stmt.c:1.2 src/tests/usr.bin/indent/psym_if_expr_stmt.c:1.3 --- src/tests/usr.bin/indent/psym_if_expr_stmt.c:1.2 Fri Apr 22 21:21:20 2022 +++ src/tests/usr.bin/indent/psym_if_expr_stmt.c Sat Apr 23 09:01:03 2022 @@ -1,14 +1,27 @@ -/* $NetBSD: psym_if_expr_stmt.c,v 1.2 2022/04/22 21:21:20 rillig Exp $ */ +/* $NetBSD: psym_if_expr_stmt.c,v 1.3 2022/04/23 09:01:03 rillig Exp $ */ /* * Tests for the parser symbol psym_if_expr_stmt, which represents the state * after reading the keyword 'if', the controlling expression and the - * statement for the 'then' branch. If the next token is 'else', another - * statement will follow, otherwise the 'if' statement is finished already. + * statement for the 'then' branch. + * + * At this point, the 'if' statement is not necessarily complete, it can be + * completed with the keyword 'else' followed by a statement. + * + * Any token other than 'else' completes the 'if' statement. */ #indent input -// TODO: add input +void +function(void) +{ + if (cond) + stmt(); + if (cond) + stmt(); + else /* belongs to the second 'if' */ + stmt(); +} #indent end #indent run-equals-input 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.2 src/tests/usr.bin/indent/psym_if_expr_stmt_else.c:1.3 --- src/tests/usr.bin/indent/psym_if_expr_stmt_else.c:1.2 Fri Apr 22 21:21:20 2022 +++ src/tests/usr.bin/indent/psym_if_expr_stmt_else.c Sat Apr 23 09:01:03 2022 @@ -1,15 +1,96 @@ -/* $NetBSD: psym_if_expr_stmt_else.c,v 1.2 2022/04/22 21:21:20 rillig Exp $ */ +/* $NetBSD: psym_if_expr_stmt_else.c,v 1.3 2022/04/23 09:01:03 rillig Exp $ */ /* * Tests for the parser symbol psym_if_expr_stmt_else, which represents the * parser state after reading the keyword 'if', the controlling expression, - * the statement of the 'then' branch and the keyword 'else'. If the next - * token is an 'if', the formatting depends on the option '-ei' or '-nei'. In - * all other situations, the next statement will finish the 'if' statement. + * the statement of the 'then' branch and the keyword 'else'. + * + * If the next token is an 'if', the formatting depends on the option '-ei' or + * '-nei'. Any other lookahead token completes the 'if' statement. */ #indent input -// TODO: add input +void +example(_Bool cond) +{ + if (cond) {} + else if (cond) {} + else if (cond) i++; + else {} +} #indent end -#indent run-equals-input +#indent run +void +example(_Bool cond) +{ + if (cond) { + } else if (cond) { + } else if (cond) + i++; + else { + } +} +#indent end + +/* + * Combining the options '-bl' (place brace on the left margin) and '-ce' + * (cuddle else) looks strange, but is technically correct. + */ +#indent run -bl +void +example(_Bool cond) +{ + if (cond) + { + } else if (cond) + { + } else if (cond) + i++; + else + { + } +} +#indent end + +#indent run -bl -nce +void +example(_Bool cond) +{ + if (cond) + { + } + else if (cond) + { + } + else if (cond) + i++; + else + { + } +} +#indent end + +/* + * Adding the option '-nei' (do not join 'else if') expands the code even + * more. + */ +#indent run -bl -nce -nei +void +example(_Bool cond) +{ + if (cond) + { + } + else + if (cond) + { + } + else + if (cond) + i++; + else + { + } +} +#indent end