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 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 final future = completer.future; | 159 final future = completer.future; |
160 final ex = new Exception(); | 160 final ex = new Exception(); |
161 | 161 |
162 bool reached = false; | 162 bool reached = false; |
163 future.handleException((e) { return false; }); | 163 future.handleException((e) { return false; }); |
164 future.handleException((e) { reached = true; return false; }); // overshadowed | 164 future.handleException((e) { reached = true; return false; }); // overshadowed |
165 completer.completeException(ex); // future.then is not called, so no exception | 165 completer.completeException(ex); // future.then is not called, so no exception |
166 Expect.isTrue(reached); | 166 Expect.isTrue(reached); |
167 } | 167 } |
168 | 168 |
| 169 testExceptionHandlerAfterCompleteThenNotCalled() { |
| 170 final completer = new Completer<int>(); |
| 171 final future = completer.future; |
| 172 final ex = new Exception(); |
| 173 |
| 174 var ex2; |
| 175 completer.completeException(ex); |
| 176 future.handleException((e) { ex2 = e; return true; }); |
| 177 future.then((e) { }); |
| 178 Expect.equals(ex, ex2); |
| 179 } |
| 180 |
| 181 testExceptionHandlerAfterCompleteReturnsFalseThenThrows() { |
| 182 final completer = new Completer<int>(); |
| 183 final future = completer.future; |
| 184 final ex = new Exception(); |
| 185 |
| 186 var ex2; |
| 187 completer.completeException(ex); |
| 188 future.handleException((e) { ex2 = e; return false; }); |
| 189 Expect.throws(() { future.then((e) { }); }); |
| 190 Expect.equals(ex, ex2); |
| 191 } |
| 192 |
169 // Tests for Future.transform | 193 // Tests for Future.transform |
170 | 194 |
171 testTransformSuccess() { | 195 testTransformSuccess() { |
172 final completer = new Completer<String>(); | 196 final completer = new Completer<String>(); |
173 final transformedFuture = completer.future.transform((x) => "** $x **"); | 197 final transformedFuture = completer.future.transform((x) => "** $x **"); |
174 Expect.isFalse(transformedFuture.isComplete); | 198 Expect.isFalse(transformedFuture.isComplete); |
175 completer.complete("42"); | 199 completer.complete("42"); |
176 Expect.equals("** 42 **", transformedFuture.value); | 200 Expect.equals("** 42 **", transformedFuture.value); |
177 } | 201 } |
178 | 202 |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
256 testComplete(); | 280 testComplete(); |
257 testCompleteWithHandlerBeforeComplete(); | 281 testCompleteWithHandlerBeforeComplete(); |
258 testCompleteWithHandlerAfterComplete(); | 282 testCompleteWithHandlerAfterComplete(); |
259 testCompleteManyHandlers(); | 283 testCompleteManyHandlers(); |
260 testException(); | 284 testException(); |
261 testExceptionHandler(); | 285 testExceptionHandler(); |
262 testExceptionHandlerReturnsTrue(); | 286 testExceptionHandlerReturnsTrue(); |
263 testExceptionHandlerReturnsTrue2(); | 287 testExceptionHandlerReturnsTrue2(); |
264 testExceptionHandlerReturnsFalse(); | 288 testExceptionHandlerReturnsFalse(); |
265 testExceptionHandlerReturnsFalse2(); | 289 testExceptionHandlerReturnsFalse2(); |
| 290 testExceptionHandlerAfterCompleteThenNotCalled(); |
| 291 testExceptionHandlerAfterCompleteReturnsFalseThenThrows(); |
266 testTransformSuccess(); | 292 testTransformSuccess(); |
267 testTransformFutureFails(); | 293 testTransformFutureFails(); |
268 testTransformTransformerFails(); | 294 testTransformTransformerFails(); |
269 testChainSuccess(); | 295 testChainSuccess(); |
270 testChainFirstFutureFails(); | 296 testChainFirstFutureFails(); |
271 testChainTransformerFails(); | 297 testChainTransformerFails(); |
272 testChainSecondFutureFails(); | 298 testChainSecondFutureFails(); |
273 } | 299 } |
OLD | NEW |