Skip to content

Commit

Permalink
Format assert statements.
Browse files Browse the repository at this point in the history
  • Loading branch information
kallentu committed Nov 10, 2023
1 parent 565e8bf commit b3e7545
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 1 deletion.
12 changes: 11 additions & 1 deletion lib/src/front_end/ast_node_visitor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,17 @@ class AstNodeVisitor extends ThrowingAstVisitor<void>

@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
Expand Down
58 changes: 58 additions & 0 deletions test/statement/assert.stmt
Original file line number Diff line number Diff line change
@@ -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,
);

0 comments on commit b3e7545

Please sign in to comment.