| 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 526 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 537 called = true; | 537 called = true; |
| 538 return "transformed value"; | 538 return "transformed value"; |
| 539 }); | 539 }); |
| 540 | 540 |
| 541 completer.completeException("original error"); | 541 completer.completeException("original error"); |
| 542 Expect.isTrue(called); | 542 Expect.isTrue(called); |
| 543 Expect.isTrue(transformedFuture.isComplete); | 543 Expect.isTrue(transformedFuture.isComplete); |
| 544 Expect.equals("transformed value", transformedFuture.value); | 544 Expect.equals("transformed value", transformedFuture.value); |
| 545 } | 545 } |
| 546 | 546 |
| 547 testTransformExceptionReturnsAFuture() { |
| 548 final completer = new Completer<String>(); |
| 549 var called = false; |
| 550 |
| 551 final returnedCompleter = new Completer<String>(); |
| 552 |
| 553 final transformedFuture = completer.future.transformException((ex) { |
| 554 Expect.equals("original error", ex); |
| 555 called = true; |
| 556 return returnedCompleter.future; |
| 557 }); |
| 558 |
| 559 completer.completeException("original error"); |
| 560 Expect.isTrue(called); |
| 561 Expect.isFalse(transformedFuture.isComplete); |
| 562 |
| 563 returnedCompleter.complete("transformed value"); |
| 564 Expect.isTrue(transformedFuture.isComplete); |
| 565 Expect.equals("transformed value", transformedFuture.value); |
| 566 } |
| 567 |
| 547 main() { | 568 main() { |
| 548 testImmediate(); | 569 testImmediate(); |
| 549 testNeverComplete(); | 570 testNeverComplete(); |
| 550 testComplete(); | 571 testComplete(); |
| 551 testCompleteWithCompleteHandlerBeforeComplete(); | 572 testCompleteWithCompleteHandlerBeforeComplete(); |
| 552 testExceptionWithCompleteHandlerBeforeComplete(); | 573 testExceptionWithCompleteHandlerBeforeComplete(); |
| 553 testCompleteWithCompleteHandlerAfterComplete(); | 574 testCompleteWithCompleteHandlerAfterComplete(); |
| 554 testExceptionWithCompleteHandlerAfterComplete(); | 575 testExceptionWithCompleteHandlerAfterComplete(); |
| 555 testCompleteWithManyCompleteHandlers(); | 576 testCompleteWithManyCompleteHandlers(); |
| 556 testExceptionWithManyCompleteHandlers(); | 577 testExceptionWithManyCompleteHandlers(); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 576 testTransformSuccess(); | 597 testTransformSuccess(); |
| 577 testTransformFutureFails(); | 598 testTransformFutureFails(); |
| 578 testTransformTransformerFails(); | 599 testTransformTransformerFails(); |
| 579 testChainSuccess(); | 600 testChainSuccess(); |
| 580 testChainFirstFutureFails(); | 601 testChainFirstFutureFails(); |
| 581 testChainTransformerFails(); | 602 testChainTransformerFails(); |
| 582 testChainSecondFutureFails(); | 603 testChainSecondFutureFails(); |
| 583 testTransformExceptionCompletesNormally(); | 604 testTransformExceptionCompletesNormally(); |
| 584 testTransformExceptionThrows(); | 605 testTransformExceptionThrows(); |
| 585 testTransformExceptionReturns(); | 606 testTransformExceptionReturns(); |
| 607 testTransformExceptionReturnsAFuture(); |
| 586 } | 608 } |
| OLD | NEW |