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

Unified Diff: tests/corelib/future_test.dart

Issue 11412139: Make exceptions propagate through multiple Future branches. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 1 month 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 | « tests/co19/co19-runtime.status ('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 9ed1db54ed8a38e398b61fb2691a54d1067b8f12..1916dddfeddb9e0b68c331cf44b5835a13689713 100644
--- a/tests/corelib/future_test.dart
+++ b/tests/corelib/future_test.dart
@@ -565,6 +565,92 @@ testTransformExceptionReturnsAFuture() {
Expect.equals("transformed value", transformedFuture.value);
}
+// Tests for branching exceptions
+
+testExceptionTravelsAlongBothBranches() {
+ var results = <int>[];
+
+ var completer = new Completer();
+ var branch1 = completer.future.transform((_) => null);
+ var branch2 = completer.future.transform((_) => null);
+
+ branch1.handleException((e) {
+ results.add(1);
+ return true;
+ });
+
+ branch2.handleException((e) {
+ results.add(2);
+ return true;
+ });
+
+ completer.completeException("error");
+ Expect.setEquals([1, 2], results);
+}
+
+testExceptionTravelsAlongBothBranchesAfterComplete() {
+ var results = <int>[];
+
+ var completer = new Completer();
+ completer.completeException("error");
+
+ var branch1 = completer.future.transform((_) => null);
+ var branch2 = completer.future.transform((_) => null);
+
+ branch1.handleException((e) {
+ results.add(1);
+ return true;
+ });
+
+ branch2.handleException((e) {
+ results.add(2);
+ return true;
+ });
+
+ Expect.setEquals([1, 2], results);
+}
+
+testExceptionIsHandledInBaseAndBranch() {
+ var results = <String>[];
+
+ var completer = new Completer();
+ var branch = completer.future.transform((_) => null);
+
+ completer.future.handleException((e) {
+ results.add("base");
+ return true;
+ });
+
+ branch.handleException((e) {
+ results.add("branch");
+ return true;
+ });
+
+ completer.completeException("error");
+ Expect.setEquals(["base", "branch"], results);
+}
+
+testExceptionIsHandledInBaseAndBranchAfterComplete() {
+ var results = <String>[];
+
+ var completer = new Completer();
+ completer.completeException("error");
+
+ var branch = completer.future.transform((_) => null);
+
+ completer.future.handleException((e) {
+ results.add("base");
+ return true;
+ });
+
+ branch.handleException((e) {
+ results.add("branch");
+ return true;
+ });
+
+ Expect.setEquals(["base", "branch"], results);
+}
+
main() {
testImmediate();
testNeverComplete();
@@ -605,4 +691,8 @@ main() {
testTransformExceptionThrows();
testTransformExceptionReturns();
testTransformExceptionReturnsAFuture();
+ testExceptionTravelsAlongBothBranches();
+ testExceptionTravelsAlongBothBranchesAfterComplete();
+ testExceptionIsHandledInBaseAndBranch();
+ testExceptionIsHandledInBaseAndBranchAfterComplete();
}
« no previous file with comments | « tests/co19/co19-runtime.status ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698