Skip to content

Commit db8cf09

Browse files
authored
Remove the Pair utility (#2271)
Use record types.
1 parent 032ef1d commit db8cf09

File tree

3 files changed

+11
-36
lines changed

3 files changed

+11
-36
lines changed

pkgs/test_core/lib/src/runner/load_suite.dart

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import 'package:test_api/src/backend/suite_platform.dart'; // ignore: implementa
1515
import 'package:test_api/src/backend/test.dart'; // ignore: implementation_imports
1616

1717
import '../util/io_stub.dart' if (dart.library.io) '../util/io.dart';
18-
import '../util/pair.dart';
1918
import 'load_exception.dart';
2019
import 'plugin/environment.dart';
2120
import 'runner_suite.dart';
@@ -61,13 +60,13 @@ class LoadSuite extends Suite implements RunnerSuite {
6160
///
6261
/// This will return `null` if the suite is unavailable for some reason (for
6362
/// example if an error occurred while loading it).
64-
Future<RunnerSuite?> get suite async => (await _suiteAndZone)?.first;
63+
Future<RunnerSuite?> get suite async => (await _suiteAndZone)?.suite;
6564

6665
/// A future that completes to a pair of [suite] and the load test's [Zone].
6766
///
6867
/// This will return `null` if the suite is unavailable for some reason (for
6968
/// example if an error occurred while loading it).
70-
final Future<Pair<RunnerSuite, Zone>?> _suiteAndZone;
69+
final Future<({RunnerSuite suite, Zone zone})?> _suiteAndZone;
7170

7271
/// Returns the test that loads the suite.
7372
///
@@ -86,7 +85,7 @@ class LoadSuite extends Suite implements RunnerSuite {
8685
factory LoadSuite(String name, SuiteConfiguration config,
8786
SuitePlatform platform, FutureOr<RunnerSuite?> Function() body,
8887
{String? path}) {
89-
var completer = Completer<Pair<RunnerSuite, Zone>?>.sync();
88+
var completer = Completer<({RunnerSuite suite, Zone zone})?>.sync();
9089
return LoadSuite._(name, config, platform, () {
9190
var invoker = Invoker.current;
9291
invoker!.addOutstandingCallback();
@@ -106,7 +105,8 @@ class LoadSuite extends Suite implements RunnerSuite {
106105
return;
107106
}
108107

109-
completer.complete(suite == null ? null : Pair(suite, Zone.current));
108+
completer.complete(
109+
suite == null ? null : (suite: suite, zone: Zone.current));
110110
invoker.removeOutstandingCallback();
111111
}());
112112

@@ -179,12 +179,12 @@ class LoadSuite extends Suite implements RunnerSuite {
179179
return LoadSuite._changeSuite(this, _suiteAndZone.then((pair) {
180180
if (pair == null) return null;
181181

182-
var zone = pair.last;
182+
var (:suite, :zone) = pair;
183183
RunnerSuite? newSuite;
184184
zone.runGuarded(() {
185-
newSuite = change(pair.first);
185+
newSuite = change(suite);
186186
});
187-
return newSuite == null ? null : Pair(newSuite!, zone);
187+
return newSuite == null ? null : (suite: newSuite!, zone: zone);
188188
}));
189189
}
190190

pkgs/test_core/lib/src/runner/parse_metadata.dart

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import 'package:test_api/src/backend/platform_selector.dart'; // ignore: impleme
1212
import 'package:test_api/src/backend/util/identifier_regex.dart'; // ignore: implementation_imports
1313

1414
import '../util/dart.dart';
15-
import '../util/pair.dart';
1615

1716
/// Parse the test metadata for the test file at [path] with [contents].
1817
///
@@ -80,8 +79,7 @@ class _Parser {
8079
for (var annotation in _annotations) {
8180
var pair =
8281
_resolveConstructor(annotation.name, annotation.constructorName);
83-
var name = pair.first;
84-
var constructorName = pair.last;
82+
var (name, constructorName) = pair;
8583

8684
if (name == 'TestOn') {
8785
_assertSingle(testOn, 'TestOn', annotation);
@@ -309,7 +307,7 @@ class _Parser {
309307
///
310308
/// Since the parsed file isn't fully resolved, this is necessary to
311309
/// disambiguate between prefixed names and named constructors.
312-
Pair<String, String?> _resolveConstructor(
310+
(String, String?) _resolveConstructor(
313311
Identifier identifier, SimpleIdentifier? constructorName) {
314312
// The syntax is ambiguous between named constructors and prefixed
315313
// annotations, so we need to resolve that ambiguity using the known
@@ -329,7 +327,7 @@ class _Parser {
329327
: identifier.name;
330328
if (constructorName != null) namedConstructor = constructorName.name;
331329
}
332-
return Pair(className, namedConstructor);
330+
return (className, namedConstructor);
333331
}
334332

335333
/// Parses a constructor invocation for [className].

pkgs/test_core/lib/src/util/pair.dart

Lines changed: 0 additions & 23 deletions
This file was deleted.

0 commit comments

Comments
 (0)