Skip to content

Commit f565eb3

Browse files
authored
Format assert statements. (#1320)
* Format assert statements. * Fix test comments. * Inline if in list.
1 parent 120b752 commit f565eb3

File tree

2 files changed

+68
-1
lines changed

2 files changed

+68
-1
lines changed

lib/src/front_end/ast_node_visitor.dart

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,16 @@ class AstNodeVisitor extends ThrowingAstVisitor<void>
133133

134134
@override
135135
void visitAssertStatement(AssertStatement node) {
136-
throw UnimplementedError();
136+
token(node.assertKeyword);
137+
createList(
138+
[
139+
node.condition,
140+
if (node.message case var message?) message,
141+
],
142+
leftBracket: node.leftParenthesis,
143+
rightBracket: node.rightParenthesis,
144+
);
145+
token(node.semicolon);
137146
}
138147

139148
@override

test/statement/assert.stmt

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
40 columns |
2+
>>> Single-line assert.
3+
assert("some short string");
4+
<<<
5+
assert("some short string");
6+
>>> Split single-line assert.
7+
assert("some very long string that wraps");
8+
<<<
9+
assert(
10+
"some very long string that wraps",
11+
);
12+
>>> Single-line assert with message.
13+
assert(true, "blah");
14+
<<<
15+
assert(true, "blah");
16+
>>> Split assert with long message.
17+
assert(true, "looong string that wraps");
18+
<<<
19+
assert(
20+
true,
21+
"looong string that wraps",
22+
);
23+
>>> Split assert with message and long condition.
24+
assert(veryLongCondition, "long string that wraps");
25+
<<<
26+
assert(
27+
veryLongCondition,
28+
"long string that wraps",
29+
);
30+
>>> Split assert with a long message and a long condition.
31+
assert(veryVeryVeryVeryVeryLongCondition, "long string that wraps");
32+
<<<
33+
assert(
34+
veryVeryVeryVeryVeryLongCondition,
35+
"long string that wraps",
36+
);
37+
>>> Remove trailing comma if not split, with no message.
38+
assert(condition,);
39+
<<<
40+
assert(condition);
41+
>>> Remove trailing comma if not split, with a message.
42+
assert(condition, "some message",);
43+
<<<
44+
assert(condition, "some message");
45+
>>> Unsplit the argument list and remove trailing comma.
46+
assert(
47+
1,
48+
2,
49+
);
50+
<<<
51+
assert(1, 2);
52+
>>> Add trailing comma if argument list split.
53+
assert(longArgument1, veryLongArgument2);
54+
<<<
55+
assert(
56+
longArgument1,
57+
veryLongArgument2,
58+
);

0 commit comments

Comments
 (0)