Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(204)

Unified Diff: pkg/barback/test/transformer/mock.dart

Issue 23543005: Make Transform a little more pleasant to use: (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Revise test code for handling primaryInput. Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: pkg/barback/test/transformer/mock.dart
diff --git a/pkg/barback/test/transformer/mock.dart b/pkg/barback/test/transformer/mock.dart
index 088700277a7a0ad8d03ad34b7fbe17b3e60f31ea..bd909543840517ca388f1ed99f35ab0252c9af2b 100644
--- a/pkg/barback/test/transformer/mock.dart
+++ b/pkg/barback/test/transformer/mock.dart
@@ -30,17 +30,20 @@ abstract class MockTransformer extends Transformer {
/// The number of currently running transforms.
int _runningTransforms = 0;
- // A completer for pausing the transformer before it finishes running [apply].
+ /// A completer for pausing the transformer before it finishes running [apply].
Completer _apply;
- // Completers for pausing the transformer before it finishes running
- // [isPrimary].
+ /// Completers for pausing the transformer before it finishes running
+ /// [isPrimary].
final _isPrimary = new Map<AssetId, Completer>();
- // Completers for pausing the transformer before it finishes getting inputs
- // the [Transform].
+ /// Completers for pausing the transformer before it finishes getting inputs
+ /// the [Transform].
final _getInput = new Map<AssetId, Completer>();
+ /// Completer for pausing the transformer before it accesses [primaryInput].
+ Completer _getPrimary;
+
/// A completer that completes once this transformer begins running.
///
/// Once this transformer finishes running, this is reset to a new completer,
@@ -99,8 +102,8 @@ abstract class MockTransformer extends Transformer {
}, "resume isPrimary($name) for $this");
}
- /// Causes the transformer to pause while loading the input with the given
- /// [name]. This can be the primary input or a secondary input.
+ /// Causes the transformer to pause while loading the secondary input with
+ /// the given [name].
///
/// This can be resumed by calling [resumeGetInput]. This operation is
/// scheduled.
@@ -120,6 +123,27 @@ abstract class MockTransformer extends Transformer {
}, "resume getInput($name) for $this");
}
+ /// Causes the transformer to pause before accessing [primaryInput].
+ ///
+ /// This can be resumed by calling [resumeGetPrimary]. This operation is
+ /// scheduled.
+ void pauseGetPrimary() {
nweiz 2013/08/28 21:15:00 I don't like making these separate from [pauseGetI
Bob Nystrom 2013/08/28 22:38:24 I think it's important to split this out. This met
+ schedule(() {
+ _getPrimary = new Completer();
+ }, "pause primaryInput for $this");
+ }
+
+ /// Resumes the transformer's invocation of [primaryInput] after
+ /// [pauseGetPrimary] was called.
+ ///
+ /// This operation is scheduled.
+ void resumeGetPrimary() {
+ schedule(() {
+ _getPrimary.complete();
+ _getPrimary = null;
+ }, "resume getPrimary() for $this");
+ }
+
/// Like [Transform.getInput], but respects [pauseGetInput].
///
/// This is intended for use by subclasses of [MockTransformer].
@@ -129,11 +153,14 @@ abstract class MockTransformer extends Transformer {
}).then((_) => transform.getInput(id));
}
- /// Like [Transform.primaryInput], but respects [pauseGetInput].
+ /// Like [Transform.primaryInput], but respects [pauseGetPrimary].
///
/// This is intended for use by subclasses of [MockTransformer].
- Future<Asset> getPrimary(Transform transform) =>
- getInput(transform, transform.primaryId);
+ Future<Asset> getPrimary(Transform transform) {
+ return newFuture(() {
+ if (_getPrimary != null) return _getPrimary.future;
+ }).then((_) => transform.primaryInput);
+ }
Future<bool> isPrimary(Asset asset) {
return newFuture(() => doIsPrimary(asset)).then((result) {

Powered by Google App Engine
This is Rietveld 408576698