| 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 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 858 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 869 }); | 869 }); |
| 870 | 870 |
| 871 }, onError: (int index, s) { | 871 }, onError: (int index, s) { |
| 872 Expect.isTrue(index == 0 || index == 2, "$index"); | 872 Expect.isTrue(index == 0 || index == 2, "$index"); |
| 873 Expect.isFalse(uncaughts[index]); | 873 Expect.isFalse(uncaughts[index]); |
| 874 uncaughts[index] = true; | 874 uncaughts[index] = true; |
| 875 asyncEnd(); | 875 asyncEnd(); |
| 876 }); | 876 }); |
| 877 } | 877 } |
| 878 | 878 |
| 879 void testBadFuture() { |
| 880 var bad = new BadFuture(); |
| 881 // Completing with bad future (then call throws) puts error in result. |
| 882 asyncStart(); |
| 883 Completer completer = new Completer(); |
| 884 completer.complete(bad); |
| 885 completer.future.then((_) { fail("unreachable"); }, |
| 886 onError: (e, s) { |
| 887 Expect.isTrue(completer.isCompleted); |
| 888 asyncEnd(); |
| 889 }); |
| 890 |
| 891 asyncStart(); |
| 892 var f = new Future.value().then((_) => bad); |
| 893 f.then((_) { fail("unreachable"); }, |
| 894 onError: (e, s) { |
| 895 asyncEnd(); |
| 896 }); |
| 897 } |
| 898 |
| 879 main() { | 899 main() { |
| 880 asyncStart(); | 900 asyncStart(); |
| 881 | 901 |
| 882 testValue(); | 902 testValue(); |
| 883 testSync(); | 903 testSync(); |
| 884 testNeverComplete(); | 904 testNeverComplete(); |
| 885 | 905 |
| 886 testComplete(); | 906 testComplete(); |
| 887 testCompleteWithSuccessHandlerBeforeComplete(); | 907 testCompleteWithSuccessHandlerBeforeComplete(); |
| 888 testCompleteWithSuccessHandlerAfterComplete(); | 908 testCompleteWithSuccessHandlerAfterComplete(); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 928 | 948 |
| 929 testChainedFutureValue(); | 949 testChainedFutureValue(); |
| 930 testChainedFutureValueDelay(); | 950 testChainedFutureValueDelay(); |
| 931 testChainedFutureError(); | 951 testChainedFutureError(); |
| 932 | 952 |
| 933 testSyncFuture_i13368(); | 953 testSyncFuture_i13368(); |
| 934 | 954 |
| 935 testWaitCleanUp(); | 955 testWaitCleanUp(); |
| 936 testWaitCleanUpError(); | 956 testWaitCleanUpError(); |
| 937 | 957 |
| 958 testBadFuture(); |
| 959 |
| 938 asyncEnd(); | 960 asyncEnd(); |
| 939 } | 961 } |
| 940 | 962 |
| 941 /// A Future that isn't recognizable as a _Future. | 963 /// A Future that isn't recognizable as a _Future. |
| 942 class CustomFuture<T> implements Future<T> { | 964 class CustomFuture<T> implements Future<T> { |
| 943 Future _realFuture; | 965 Future _realFuture; |
| 944 CustomFuture(this._realFuture); | 966 CustomFuture(this._realFuture); |
| 945 Future then(action(result), {Function onError}) => | 967 Future then(action(result), {Function onError}) => |
| 946 _realFuture.then(action, onError: onError); | 968 _realFuture.then(action, onError: onError); |
| 947 Future catchError(Function onError, {bool test(e)}) => | 969 Future catchError(Function onError, {bool test(e)}) => |
| 948 _realFuture.catchError(onError, test: test); | 970 _realFuture.catchError(onError, test: test); |
| 949 Future whenComplete(action()) => _realFuture.whenComplete(action); | 971 Future whenComplete(action()) => _realFuture.whenComplete(action); |
| 950 Future timeout(Duration timeLimit, {void onTimeout()}) => | 972 Future timeout(Duration timeLimit, {void onTimeout()}) => |
| 951 _realFuture.timeout(timeLimit, onTimeout: onTimeout); | 973 _realFuture.timeout(timeLimit, onTimeout: onTimeout); |
| 952 Stream asStream() => _realFuture.asStream(); | 974 Stream asStream() => _realFuture.asStream(); |
| 953 String toString() => "CustomFuture@${_realFuture.hashCode}"; | 975 String toString() => "CustomFuture@${_realFuture.hashCode}"; |
| 954 int get hashCode => _realFuture.hashCode; | 976 int get hashCode => _realFuture.hashCode; |
| 955 } | 977 } |
| 978 |
| 979 class BadFuture<T> implements Future<T> { |
| 980 Future then(action(result)) { |
| 981 throw "then GOTCHA!"; |
| 982 } |
| 983 Future catchError(Function onError) { |
| 984 throw "catch GOTCHA!"; |
| 985 } |
| 986 Future whenComplete(action()) { |
| 987 throw "finally GOTCHA!"; |
| 988 } |
| 989 } |
| OLD | NEW |