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

Remove the Pair utility #2271

Merged
merged 3 commits into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
16 changes: 8 additions & 8 deletions pkgs/test_core/lib/src/runner/load_suite.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import 'package:test_api/src/backend/suite_platform.dart'; // ignore: implementa
import 'package:test_api/src/backend/test.dart'; // ignore: implementation_imports

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

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

/// Returns the test that loads the suite.
///
Expand All @@ -86,7 +85,7 @@ class LoadSuite extends Suite implements RunnerSuite {
factory LoadSuite(String name, SuiteConfiguration config,
SuitePlatform platform, FutureOr<RunnerSuite?> Function() body,
{String? path}) {
var completer = Completer<Pair<RunnerSuite, Zone>?>.sync();
var completer = Completer<({RunnerSuite suite, Zone zone})?>.sync();
return LoadSuite._(name, config, platform, () {
var invoker = Invoker.current;
invoker!.addOutstandingCallback();
Expand All @@ -106,7 +105,8 @@ class LoadSuite extends Suite implements RunnerSuite {
return;
}

completer.complete(suite == null ? null : Pair(suite, Zone.current));
completer.complete(
suite == null ? null : (suite: suite, zone: Zone.current));
invoker.removeOutstandingCallback();
}());

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

var zone = pair.last;
var (:suite, :zone) = pair;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice!

RunnerSuite? newSuite;
zone.runGuarded(() {
newSuite = change(pair.first);
newSuite = change(suite);
});
return newSuite == null ? null : Pair(newSuite!, zone);
return newSuite == null ? null : (suite: newSuite!, zone: zone);
}));
}

Expand Down
8 changes: 3 additions & 5 deletions pkgs/test_core/lib/src/runner/parse_metadata.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import 'package:test_api/src/backend/platform_selector.dart'; // ignore: impleme
import 'package:test_api/src/backend/util/identifier_regex.dart'; // ignore: implementation_imports

import '../util/dart.dart';
import '../util/pair.dart';

/// Parse the test metadata for the test file at [path] with [contents].
///
Expand Down Expand Up @@ -80,8 +79,7 @@ class _Parser {
for (var annotation in _annotations) {
var pair =
_resolveConstructor(annotation.name, annotation.constructorName);
var name = pair.first;
var constructorName = pair.last;
var (name, constructorName) = pair;

if (name == 'TestOn') {
_assertSingle(testOn, 'TestOn', annotation);
Expand Down Expand Up @@ -309,7 +307,7 @@ class _Parser {
///
/// Since the parsed file isn't fully resolved, this is necessary to
/// disambiguate between prefixed names and named constructors.
Pair<String, String?> _resolveConstructor(
(String, String?) _resolveConstructor(
Identifier identifier, SimpleIdentifier? constructorName) {
// The syntax is ambiguous between named constructors and prefixed
// annotations, so we need to resolve that ambiguity using the known
Expand All @@ -329,7 +327,7 @@ class _Parser {
: identifier.name;
if (constructorName != null) namedConstructor = constructorName.name;
}
return Pair(className, namedConstructor);
return (className, namedConstructor);
}

/// Parses a constructor invocation for [className].
Expand Down
23 changes: 0 additions & 23 deletions pkgs/test_core/lib/src/util/pair.dart

This file was deleted.

Loading