Index: tests/corelib/future_test.dart |
diff --git a/tests/corelib/future_test.dart b/tests/corelib/future_test.dart |
index 9ed1db54ed8a38e398b61fb2691a54d1067b8f12..31dbb8120c6ec400507973df27e798987bc814a6 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.listEquals([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.listEquals([2, 1], results); |
Siggi Cherem (dart-lang)
2012/11/21 01:08:57
it's weird to see these in opposite order, maybe u
nweiz
2012/11/21 20:39:09
Done.
|
+} |
+ |
+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.listEquals(["branch", "base"], results); |
+} |
+ |
+testExceptionIsHandledInBaseAndBranchAfterComplete() { |
+ var results = <String>[]; |
+ |
+ var completer = new Completer(); |
+ completer.completeException("error"); |
+ |
+ var branch = completer.future.transform((_) => null); |
Siggi Cherem (dart-lang)
2012/11/21 01:08:57
maybe add another test to check what happens if yo
nweiz
2012/11/21 20:39:09
That case isn't handled by this CL; it will actual
|
+ |
+ completer.future.handleException((e) { |
+ results.add("base"); |
+ return true; |
+ }); |
+ |
+ branch.handleException((e) { |
+ results.add("branch"); |
+ return true; |
+ }); |
+ |
+ Expect.listEquals(["base", "branch"], results); |
+} |
+ |
main() { |
testImmediate(); |
testNeverComplete(); |
@@ -605,4 +691,6 @@ main() { |
testTransformExceptionThrows(); |
testTransformExceptionReturns(); |
testTransformExceptionReturnsAFuture(); |
+ testExceptionTravelsAlongBothBranches(); |
+ testExceptionIsHandledInBaseAndBranch(); |
Siggi Cherem (dart-lang)
2012/11/21 01:08:57
add the other 2 tests? (...AfterComplete)
nweiz
2012/11/21 20:39:09
Done.
|
} |