From b3e754520f2fafb087787604bdfb9b5a1569b28a Mon Sep 17 00:00:00 2001 From: Kallen Tu Date: Fri, 10 Nov 2023 23:53:33 +0000 Subject: [PATCH] Format assert statements. --- lib/src/front_end/ast_node_visitor.dart | 12 ++++- test/statement/assert.stmt | 58 +++++++++++++++++++++++++ 2 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 test/statement/assert.stmt diff --git a/lib/src/front_end/ast_node_visitor.dart b/lib/src/front_end/ast_node_visitor.dart index d942085c..837295cd 100644 --- a/lib/src/front_end/ast_node_visitor.dart +++ b/lib/src/front_end/ast_node_visitor.dart @@ -130,7 +130,17 @@ class AstNodeVisitor extends ThrowingAstVisitor @override void visitAssertStatement(AssertStatement node) { - throw UnimplementedError(); + token(node.assertKeyword); + + var arguments = [node.condition]; + if (node.message case var message?) arguments.add(message); + createList( + arguments, + leftBracket: node.leftParenthesis, + rightBracket: node.rightParenthesis, + ); + + token(node.semicolon); } @override diff --git a/test/statement/assert.stmt b/test/statement/assert.stmt new file mode 100644 index 00000000..d4854fe5 --- /dev/null +++ b/test/statement/assert.stmt @@ -0,0 +1,58 @@ +40 columns | +>>> single-line assert +assert("some short string"); +<<< +assert("some short string"); +>>> wrapped assert +assert("some very long string that wraps"); +<<< +assert( + "some very long string that wraps", +); +>>> single-line assert with message +assert(true, "blah"); +<<< +assert(true, "blah"); +>>> split assert with message before both +assert(true, "looong string that wraps"); +<<< +assert( + true, + "looong string that wraps", +); +>>> split assert with message after first +assert(veryLongCondition, "long string that wraps"); +<<< +assert( + veryLongCondition, + "long string that wraps", +); +>>> split assert with message at both +assert(veryVeryVeryVeryVeryLongCondition, "long string that wraps"); +<<< +assert( + veryVeryVeryVeryVeryLongCondition, + "long string that wraps", +); +>>> split assert with trailing comma +assert(condition,); +<<< +assert(condition); +>>> split assert with trailing comma and message +assert(condition, "some message",); +<<< +assert(condition, "some message"); +>>> remove from assert arg list if unsplit +assert( + 1, + 2, +); +<<< +assert(1, 2); +>>> add to assert arg list if split +assert(longArgument1, veryLongArgument2); +<<< +assert( + longArgument1, + veryLongArgument2, +);