Skip to content

Commit 430ff6d

Browse files
stereotype441commit-bot@chromium.org
authored andcommitted
Migration: fix "matching" functionality of edge testing infrastructure.
Change-Id: I6318f89ba962329a1d3f4b0af2b0352981d6c9fb Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/117840 Reviewed-by: Konstantin Shcheglov <[email protected]> Commit-Queue: Paul Berry <[email protected]>
1 parent f1bff1b commit 430ff6d

File tree

1 file changed

+32
-7
lines changed

1 file changed

+32
-7
lines changed

pkg/nnbd_migration/test/migration_visitor_test_base.dart

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,12 @@ class AnyNodeMatcher implements NodeMatcher {
2929
NullabilityNode get matchingNode => _matchingNodes.single;
3030

3131
@override
32-
bool matches(NullabilityNode node) {
32+
void matched(NullabilityNode node) {
3333
_matchingNodes.add(node);
34+
}
35+
36+
@override
37+
bool matches(NullabilityNode node) {
3438
return true;
3539
}
3640
}
@@ -208,12 +212,16 @@ mixin EdgeTester {
208212
List<NullabilityEdge> getEdges(Object source, Object destination) {
209213
var sourceMatcher = NodeMatcher(source);
210214
var destinationMatcher = NodeMatcher(destination);
211-
return graph
212-
.getAllEdges()
213-
.where((e) =>
214-
sourceMatcher.matches(e.sourceNode) &&
215-
destinationMatcher.matches(e.destinationNode))
216-
.toList();
215+
var result = <NullabilityEdge>[];
216+
for (var edge in graph.getAllEdges()) {
217+
if (sourceMatcher.matches(edge.sourceNode) &&
218+
destinationMatcher.matches(edge.destinationNode)) {
219+
sourceMatcher.matched(edge.sourceNode);
220+
destinationMatcher.matched(edge.destinationNode);
221+
result.add(edge);
222+
}
223+
}
224+
return result;
217225
}
218226

219227
/// Creates a [NodeMatcher] matching a substitution node whose inner and outer
@@ -365,6 +373,8 @@ abstract class NodeMatcher {
365373
'Unclear how to match node expectation of type ${expectation.runtimeType}');
366374
}
367375

376+
void matched(NullabilityNode node);
377+
368378
bool matches(NullabilityNode node);
369379
}
370380

@@ -374,6 +384,9 @@ class _ExactNodeMatcher implements NodeMatcher {
374384

375385
_ExactNodeMatcher(this._expectation);
376386

387+
@override
388+
void matched(NullabilityNode node) {}
389+
377390
@override
378391
bool matches(NullabilityNode node) => node == _expectation;
379392
}
@@ -386,6 +399,18 @@ class _SubstitutionNodeMatcher implements NodeMatcher {
386399

387400
_SubstitutionNodeMatcher(this.inner, this.outer);
388401

402+
@override
403+
void matched(NullabilityNode node) {
404+
if (node is NullabilityNodeForSubstitution) {
405+
inner.matched(node.innerNode);
406+
outer.matched(node.outerNode);
407+
} else {
408+
throw StateError(
409+
'matched should only be called on nodes for which matches returned '
410+
'true');
411+
}
412+
}
413+
389414
@override
390415
bool matches(NullabilityNode node) {
391416
return node is NullabilityNodeForSubstitution &&

0 commit comments

Comments
 (0)