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

Unified Diff: tests/corelib/future_test.dart

Issue 10908040: Support transforming the exception in Future.transform(). (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Allow transformException to complete successfully. Created 8 years, 3 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
« no previous file with comments | « lib/coreimpl/future_implementation.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/corelib/future_test.dart
diff --git a/tests/corelib/future_test.dart b/tests/corelib/future_test.dart
index b26ed40b6955e208418b8e1756fe6ff45bf3726e..aefe3ff99abccba00e29aa4e9e19d0a774c426de 100644
--- a/tests/corelib/future_test.dart
+++ b/tests/corelib/future_test.dart
@@ -497,6 +497,53 @@ testChainSecondFutureFails() {
Expect.equals(error, chainedFuture.exception);
}
+// Tests for Future.transformException
+
+testTransformExceptionCompletesNormally() {
+ final completer = new Completer<String>();
+ var called = false;
+
+ final transformedFuture = completer.future.transformException((ex) {
+ Expect.fail("should not get here");
+ });
+
+ completer.complete("value");
+ Expect.isTrue(transformedFuture.isComplete);
+ Expect.equals("value", transformedFuture.value);
+}
+
+testTransformExceptionThrows() {
+ final completer = new Completer<String>();
+ var called = false;
+
+ final transformedFuture = completer.future.transformException((ex) {
+ Expect.equals("original error", ex);
+ called = true;
+ throw "transformed error";
+ });
+
+ completer.completeException("original error");
+ Expect.isTrue(called);
+ Expect.isTrue(transformedFuture.isComplete);
+ Expect.equals("transformed error", transformedFuture.exception);
+}
+
+testTransformExceptionReturns() {
+ final completer = new Completer<String>();
+ var called = false;
+
+ final transformedFuture = completer.future.transformException((ex) {
+ Expect.equals("original error", ex);
+ called = true;
+ return "transformed value";
+ });
+
+ completer.completeException("original error");
+ Expect.isTrue(called);
+ Expect.isTrue(transformedFuture.isComplete);
+ Expect.equals("transformed value", transformedFuture.value);
+}
+
main() {
testImmediate();
testNeverComplete();
@@ -533,4 +580,7 @@ main() {
testChainFirstFutureFails();
testChainTransformerFails();
testChainSecondFutureFails();
+ testTransformExceptionCompletesNormally();
+ testTransformExceptionThrows();
+ testTransformExceptionReturns();
}
« no previous file with comments | « lib/coreimpl/future_implementation.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698