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

Side by Side Diff: tests/lib/async/future_test.dart

Issue 50373002: Change and documentat how completer handles futures. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Change signature everywhere. Created 7 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 library future_test; 5 library future_test;
6 6
7 import 'package:async_helper/async_helper.dart'; 7 import 'package:async_helper/async_helper.dart';
8 import "package:expect/expect.dart"; 8 import "package:expect/expect.dart";
9 import 'dart:async'; 9 import 'dart:async';
10 10
(...skipping 549 matching lines...) Expand 10 before | Expand all | Expand 10 after
560 560
561 asyncStart(); 561 asyncStart();
562 future.catchError((e) { 562 future.catchError((e) {
563 Expect.identical(error, e); 563 Expect.identical(error, e);
564 asyncEnd(); 564 asyncEnd();
565 }); 565 });
566 566
567 completer.completeError(error); 567 completer.completeError(error);
568 } 568 }
569 569
570 void testCompleteWithFutureSuccess() {
571 asyncStart();
572 final completer = new Completer<int>();
573 final completer2 = new Completer<int>();
574 completer.complete(completer2.future);
575 completer.future.then((v) {
576 Expect.equals(42, v);
577 asyncEnd();
578 });
579 completer2.complete(42);
580 }
581
582 void testCompleteWithFutureSuccess2() {
583 asyncStart();
584 final completer = new Completer<int>();
585 Future result = new Future.value(42);
586 completer.complete(result);
587 completer.future.then((v) {
588 Expect.equals(42, v);
589 asyncEnd();
590 });
591 }
592
593 void testCompleteWithFutureError() {
594 asyncStart();
595 final completer = new Completer<int>();
596 final completer2 = new Completer<int>();
597 completer.complete(completer2.future);
598 completer.future.then((v) {
599 Expect.fail("Should not happen");
600 asyncEnd();
601 }, onError: (e) {
602 Expect.equals("ERROR-tcwfe", e);
603 asyncEnd();
604 });
605 completer2.completeError("ERROR-tcwfe");
606 }
607
608 void testCompleteWithFutureError2() {
609 asyncStart();
610 final completer = new Completer<int>();
611 Future result = new Future.error("ERROR-tcwfe2");
612 completer.complete(result);
613 completer.future.then((v) {
614 Expect.fail("Should not happen");
615 asyncEnd();
616 }, onError: (e) {
617 Expect.equals("ERROR-tcwfe2", e);
618 asyncEnd();
619 });
620 }
621
622 void testCompleteErrorWithFuture() {
623 final completer = new Completer<int>();
624 Expect.throws(() => completer.completeError(new Future.value(42)));
625 }
626
627 void testCompleteWithCustomFutureSuccess() {
628 asyncStart();
629 final completer = new Completer<int>();
630 final completer2 = new Completer<int>();
631 completer.complete(new CustomFuture(completer2.future));
632 completer.future.then((v) {
633 Expect.equals(42, v);
634 asyncEnd();
635 });
636 completer2.complete(42);
637 }
638
639 void testCompleteWithCustomFutureError() {
640 asyncStart();
641 final completer = new Completer<int>();
642 final completer2 = new Completer<int>();
643 completer.complete(new CustomFuture(completer2.future));
644 completer.future.then((v) {
645 Expect.fail("Should not happen");
646 asyncEnd();
647 }, onError: (e) {
648 Expect.equals("ERROR-tcwcfe", e);
649 asyncEnd();
650 });
651 completer2.completeError("ERROR-tcwcfe");
652 }
653
654 void testCompleteErrorWithCustomFuture() {
655 final completer = new Completer<int>();
656 var future = new CustomFuture(new Future.value(42));
657 Expect.throws(() => completer.completeError(future));
658 }
659
660 void testCompleteErrorWithNull() {
661 final completer = new Completer<int>();
662 Expect.throws(() => completer.completeError(null));
663 }
664
570 void testChainedFutureValue() { 665 void testChainedFutureValue() {
571 final completer = new Completer(); 666 final completer = new Completer();
572 final future = completer.future; 667 final future = completer.future;
573 asyncStart(); 668 asyncStart();
574 669
575 future.then((v) => new Future.value(v * 2)) 670 future.then((v) => new Future.value(v * 2))
576 .then((v) { 671 .then((v) {
577 Expect.equals(42, v); 672 Expect.equals(42, v);
578 asyncEnd(); 673 asyncEnd();
579 }); 674 });
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
634 testValue(); 729 testValue();
635 testSync(); 730 testSync();
636 testNeverComplete(); 731 testNeverComplete();
637 732
638 testComplete(); 733 testComplete();
639 testCompleteWithSuccessHandlerBeforeComplete(); 734 testCompleteWithSuccessHandlerBeforeComplete();
640 testCompleteWithSuccessHandlerAfterComplete(); 735 testCompleteWithSuccessHandlerAfterComplete();
641 testCompleteManySuccessHandlers(); 736 testCompleteManySuccessHandlers();
642 testCompleteWithError(); 737 testCompleteWithError();
643 738
739 testCompleteWithFutureSuccess();
740 testCompleteWithFutureSuccess2();
741 testCompleteWithFutureError();
742 testCompleteWithFutureError2();
743 testCompleteErrorWithFuture();
744 testCompleteWithCustomFutureSuccess();
745 testCompleteWithCustomFutureError();
746 testCompleteErrorWithCustomFuture();
747 testCompleteErrorWithNull();
748
644 testException(); 749 testException();
645 testExceptionHandler(); 750 testExceptionHandler();
646 testExceptionHandlerReturnsTrue(); 751 testExceptionHandlerReturnsTrue();
647 testExceptionHandlerReturnsTrue2(); 752 testExceptionHandlerReturnsTrue2();
648 testExceptionHandlerReturnsFalse(); 753 testExceptionHandlerReturnsFalse();
649 754
650 testFutureAsStreamCompleteAfter(); 755 testFutureAsStreamCompleteAfter();
651 testFutureAsStreamCompleteBefore(); 756 testFutureAsStreamCompleteBefore();
652 testFutureAsStreamCompleteImmediate(); 757 testFutureAsStreamCompleteImmediate();
653 testFutureAsStreamCompleteErrorAfter(); 758 testFutureAsStreamCompleteErrorAfter();
(...skipping 13 matching lines...) Expand all
667 testFutureCatchThrowsAsync(); 772 testFutureCatchThrowsAsync();
668 testFutureWhenThrowsAsync(); 773 testFutureWhenThrowsAsync();
669 testFutureCatchRethrowsAsync(); 774 testFutureCatchRethrowsAsync();
670 775
671 testChainedFutureValue(); 776 testChainedFutureValue();
672 testChainedFutureValueDelay(); 777 testChainedFutureValueDelay();
673 testChainedFutureError(); 778 testChainedFutureError();
674 779
675 testSyncFuture_i13368(); 780 testSyncFuture_i13368();
676 } 781 }
782
783 /// A Future that isn't recognizable as a _Future.
784 class CustomFuture<T> implements Future<T> {
785 Future _realFuture;
786 CustomFuture(this._realFuture);
787 Future then(action(result), {Function onError}) =>
788 _realFuture.then(action, onError: onError);
789 Future catchError(Function onError, {bool test(e)}) =>
790 _realFuture.catchError(onError, test: test);
791 Future whenComplete(action()) => _realFuture.whenComplete(action);
792 Stream asStream() => _realFuture.asStream();
793 String toString() => "CustomFuture@${_realFuture.hashCode}";
794 int get hashCode => _realFuture.hashCode;
795 }
OLDNEW
« sdk/lib/async/future_impl.dart ('K') | « sdk/lib/async/future_impl.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698