Skip to content

Commit 3fcc65f

Browse files
authored
Migrate more tests over to the new style. (#1411)
In the process, I discovered a bug where the formatter would allow any list-like construct (collection literal, etc.) to support block formatting, which is definitely not intended. Only argument lists should allow that. Fixed that bug.
1 parent a5533c3 commit 3fcc65f

File tree

16 files changed

+331
-10
lines changed

16 files changed

+331
-10
lines changed

lib/src/front_end/ast_node_visitor.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,13 +141,13 @@ class AstNodeVisitor extends ThrowingAstVisitor<Piece> with PieceFactory {
141141
Piece visitAssertInitializer(AssertInitializer node) {
142142
return buildPiece((b) {
143143
b.token(node.assertKeyword);
144-
b.add(createList(
145-
leftBracket: node.leftParenthesis,
144+
b.add(createArgumentList(
145+
node.leftParenthesis,
146146
[
147147
node.condition,
148148
if (node.message case var message?) message,
149149
],
150-
rightBracket: node.rightParenthesis,
150+
node.rightParenthesis,
151151
));
152152
});
153153
}

lib/src/front_end/delimited_list_builder.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class DelimitedListBuilder {
6262
});
6363
}
6464

65-
_setBlockElementFormatting();
65+
if (_style.allowBlockElement) _setBlockElementFormatting();
6666

6767
var piece =
6868
ListPiece(_leftBracket, _elements, _blanksAfter, _rightBracket, _style);

test/declaration/constructor_assert.unit

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,20 @@ class Foo {
7979
anotherLongCondition,
8080
'a message',
8181
);
82+
}
83+
>>> Allow block-formatting the assert arguments.
84+
class Foo {
85+
Foo()
86+
: assert(
87+
() {
88+
slowComputation();
89+
}(),
90+
);
91+
}
92+
<<<
93+
class Foo {
94+
Foo()
95+
: assert(() {
96+
slowComputation();
97+
}());
8298
}

test/expression/collection_if.stmt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,23 @@ var list = [
133133
if (condition)
134134
if (another) longThingHereThatsLong,
135135
];
136+
>>> Split outer if when subelement is for.
137+
var list = [
138+
if (a) for (var b in c) thing
139+
];
140+
<<<
141+
var list = [
142+
if (a)
143+
for (var b in c) thing,
144+
];
145+
>>> Don't force split outer when subelement is nested inside collection.
146+
var list = [
147+
if (a) [for (var b in c) d]
148+
];
149+
<<<
150+
var list = [
151+
if (a) [for (var b in c) d],
152+
];
136153
>>> Nested if inside list doesn't force outer if to split.
137154
var list = [if (a) [if (b) c]];
138155
<<<

test/expression/collection_spread.stmt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,14 @@ var list = [
5252
yield thing;
5353
}(),
5454
4,
55+
];
56+
>>> Spread cascade.
57+
var list = [1, ...thing..cascade()..another(), 4];
58+
<<<
59+
var list = [
60+
1,
61+
...thing
62+
..cascade()
63+
..another(),
64+
4,
5565
];

test/expression/list.stmt

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,4 +116,15 @@ thirdElement];
116116
AnotherLongTypeName
117117
>
118118
>
119-
>[1, 2, 3];
119+
>[1, 2, 3];
120+
>>> Force split because of contained block.
121+
[first, () {"fn";},third,fourth];
122+
<<<
123+
[
124+
first,
125+
() {
126+
"fn";
127+
},
128+
third,
129+
fourth,
130+
];

test/expression/map.stmt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,4 +138,14 @@ const {first: 1, second: 2};
138138
VeryLongTypeName,
139139
AnotherLongTypeName
140140
>
141-
>{1: 'one', 2: 'two'};
141+
>{1: 'one', 2: 'two'};
142+
>>> Force split because of contained block.
143+
var m = {first: 1, fn: () {"fn";},third:fourth};
144+
<<<
145+
var m = {
146+
first: 1,
147+
fn: () {
148+
"fn";
149+
},
150+
third: fourth,
151+
};

test/expression/map_comment.stmt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,17 @@ var map = {
99
var map = {
1010
// comment
1111
};
12-
>>> Inline block comment.
12+
>>> Inline block comment in empty map.
1313
var map = { /* comment */ };
1414
<<<
1515
var map = {/* comment */};
16+
>>> Inline block comment after entry.
17+
var map = {first: one /* bang */, second: two};
18+
<<<
19+
var map = {
20+
first: one /* bang */,
21+
second: two,
22+
};
1623
>>> After entry.
1724
({key: value // comment
1825
});

test/expression/record.stmt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,3 +117,14 @@ var record = (
117117
veryLongElement__________,
118118
),
119119
);
120+
>>> Force split because of contained block.
121+
(first, () {"fn";},third,fourth);
122+
<<<
123+
(
124+
first,
125+
() {
126+
"fn";
127+
},
128+
third,
129+
fourth,
130+
);

test/expression/set.stmt

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,17 @@ var set =
3333
Fifth,
3434
Sixth
3535
>
36-
>{};
36+
>{};
37+
>>> Force split because of contained block.
38+
var s = {first, 1, fn, () {"fn";},third,fourth};
39+
<<<
40+
var s = {
41+
first,
42+
1,
43+
fn,
44+
() {
45+
"fn";
46+
},
47+
third,
48+
fourth,
49+
};

0 commit comments

Comments
 (0)