OLD | NEW |
---|---|
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 // Tests for Future.immediate | 5 // Tests for Future.immediate |
6 | 6 |
7 testImmediate() { | 7 testImmediate() { |
8 final future = new Future<String>.immediate("42"); | 8 final future = new Future<String>.immediate("42"); |
9 Expect.isTrue(future.isComplete); | 9 Expect.isTrue(future.isComplete); |
10 Expect.isTrue(future.hasValue); | 10 Expect.isTrue(future.hasValue); |
(...skipping 547 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
558 | 558 |
559 completer.completeException("original error"); | 559 completer.completeException("original error"); |
560 Expect.isTrue(called); | 560 Expect.isTrue(called); |
561 Expect.isFalse(transformedFuture.isComplete); | 561 Expect.isFalse(transformedFuture.isComplete); |
562 | 562 |
563 returnedCompleter.complete("transformed value"); | 563 returnedCompleter.complete("transformed value"); |
564 Expect.isTrue(transformedFuture.isComplete); | 564 Expect.isTrue(transformedFuture.isComplete); |
565 Expect.equals("transformed value", transformedFuture.value); | 565 Expect.equals("transformed value", transformedFuture.value); |
566 } | 566 } |
567 | 567 |
568 // Tests for branching exceptions | |
569 | |
570 testExceptionTravelsAlongBothBranches() { | |
571 var results = <int>[]; | |
572 | |
573 var completer = new Completer(); | |
574 var branch1 = completer.future.transform((_) => null); | |
575 var branch2 = completer.future.transform((_) => null); | |
576 | |
577 branch1.handleException((e) { | |
578 results.add(1); | |
579 return true; | |
580 }); | |
581 | |
582 branch2.handleException((e) { | |
583 results.add(2); | |
584 return true; | |
585 }); | |
586 | |
587 completer.completeException("error"); | |
588 Expect.listEquals([1, 2], results); | |
589 } | |
590 | |
591 testExceptionTravelsAlongBothBranchesAfterComplete() { | |
592 var results = <int>[]; | |
593 | |
594 var completer = new Completer(); | |
595 completer.completeException("error"); | |
596 | |
597 var branch1 = completer.future.transform((_) => null); | |
598 var branch2 = completer.future.transform((_) => null); | |
599 | |
600 branch1.handleException((e) { | |
601 results.add(1); | |
602 return true; | |
603 }); | |
604 | |
605 branch2.handleException((e) { | |
606 results.add(2); | |
607 return true; | |
608 }); | |
609 | |
610 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.
| |
611 } | |
612 | |
613 testExceptionIsHandledInBaseAndBranch() { | |
614 var results = <String>[]; | |
615 | |
616 var completer = new Completer(); | |
617 var branch = completer.future.transform((_) => null); | |
618 | |
619 completer.future.handleException((e) { | |
620 results.add("base"); | |
621 return true; | |
622 }); | |
623 | |
624 branch.handleException((e) { | |
625 results.add("branch"); | |
626 return true; | |
627 }); | |
628 | |
629 completer.completeException("error"); | |
630 Expect.listEquals(["branch", "base"], results); | |
631 } | |
632 | |
633 testExceptionIsHandledInBaseAndBranchAfterComplete() { | |
634 var results = <String>[]; | |
635 | |
636 var completer = new Completer(); | |
637 completer.completeException("error"); | |
638 | |
639 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
| |
640 | |
641 completer.future.handleException((e) { | |
642 results.add("base"); | |
643 return true; | |
644 }); | |
645 | |
646 branch.handleException((e) { | |
647 results.add("branch"); | |
648 return true; | |
649 }); | |
650 | |
651 Expect.listEquals(["base", "branch"], results); | |
652 } | |
653 | |
568 main() { | 654 main() { |
569 testImmediate(); | 655 testImmediate(); |
570 testNeverComplete(); | 656 testNeverComplete(); |
571 testComplete(); | 657 testComplete(); |
572 testCompleteWithCompleteHandlerBeforeComplete(); | 658 testCompleteWithCompleteHandlerBeforeComplete(); |
573 testExceptionWithCompleteHandlerBeforeComplete(); | 659 testExceptionWithCompleteHandlerBeforeComplete(); |
574 testCompleteWithCompleteHandlerAfterComplete(); | 660 testCompleteWithCompleteHandlerAfterComplete(); |
575 testExceptionWithCompleteHandlerAfterComplete(); | 661 testExceptionWithCompleteHandlerAfterComplete(); |
576 testCompleteWithManyCompleteHandlers(); | 662 testCompleteWithManyCompleteHandlers(); |
577 testExceptionWithManyCompleteHandlers(); | 663 testExceptionWithManyCompleteHandlers(); |
(...skipping 20 matching lines...) Expand all Loading... | |
598 testTransformFutureFails(); | 684 testTransformFutureFails(); |
599 testTransformTransformerFails(); | 685 testTransformTransformerFails(); |
600 testChainSuccess(); | 686 testChainSuccess(); |
601 testChainFirstFutureFails(); | 687 testChainFirstFutureFails(); |
602 testChainTransformerFails(); | 688 testChainTransformerFails(); |
603 testChainSecondFutureFails(); | 689 testChainSecondFutureFails(); |
604 testTransformExceptionCompletesNormally(); | 690 testTransformExceptionCompletesNormally(); |
605 testTransformExceptionThrows(); | 691 testTransformExceptionThrows(); |
606 testTransformExceptionReturns(); | 692 testTransformExceptionReturns(); |
607 testTransformExceptionReturnsAFuture(); | 693 testTransformExceptionReturnsAFuture(); |
694 testExceptionTravelsAlongBothBranches(); | |
695 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.
| |
608 } | 696 } |
OLD | NEW |