Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Format assert statements. #1320

Merged
merged 3 commits into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
);
kallentu marked this conversation as resolved.
Show resolved Hide resolved

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,
);