Skip to content

Commit

Permalink
Format assert statements. (#1320)
Browse files Browse the repository at this point in the history
* Format assert statements.

* Fix test comments.

* Inline if in list.
  • Loading branch information
kallentu authored Nov 13, 2023
1 parent 120b752 commit f565eb3
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 1 deletion.
11 changes: 10 additions & 1 deletion lib/src/front_end/ast_node_visitor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,16 @@ class AstNodeVisitor extends ThrowingAstVisitor<void>

@override
void visitAssertStatement(AssertStatement node) {
throw UnimplementedError();
token(node.assertKeyword);
createList(
[
node.condition,
if (node.message case var message?) message,
],
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");
>>> Split single-line 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 long message.
assert(true, "looong string that wraps");
<<<
assert(
true,
"looong string that wraps",
);
>>> Split assert with message and long condition.
assert(veryLongCondition, "long string that wraps");
<<<
assert(
veryLongCondition,
"long string that wraps",
);
>>> Split assert with a long message and a long condition.
assert(veryVeryVeryVeryVeryLongCondition, "long string that wraps");
<<<
assert(
veryVeryVeryVeryVeryLongCondition,
"long string that wraps",
);
>>> Remove trailing comma if not split, with no message.
assert(condition,);
<<<
assert(condition);
>>> Remove trailing comma if not split, with a message.
assert(condition, "some message",);
<<<
assert(condition, "some message");
>>> Unsplit the argument list and remove trailing comma.
assert(
1,
2,
);
<<<
assert(1, 2);
>>> Add trailing comma if argument list split.
assert(longArgument1, veryLongArgument2);
<<<
assert(
longArgument1,
veryLongArgument2,
);

0 comments on commit f565eb3

Please sign in to comment.