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 424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
435 testTransformTransformerFails() { | 435 testTransformTransformerFails() { |
436 final completer = new Completer<String>(); | 436 final completer = new Completer<String>(); |
437 final error = new Exception("Oh no!"); | 437 final error = new Exception("Oh no!"); |
438 final transformedFuture = completer.future.transform((x) { throw error; }); | 438 final transformedFuture = completer.future.transform((x) { throw error; }); |
439 Expect.isFalse(transformedFuture.isComplete); | 439 Expect.isFalse(transformedFuture.isComplete); |
440 transformedFuture.then((v) => null); | 440 transformedFuture.then((v) => null); |
441 Expect.throws(() => completer.complete("42"), check: (e) => e == error); | 441 Expect.throws(() => completer.complete("42"), check: (e) => e == error); |
442 Expect.equals(error, transformedFuture.exception); | 442 Expect.equals(error, transformedFuture.exception); |
443 } | 443 } |
444 | 444 |
445 testTransformOnExceptionTransformerThrows() { | |
446 final completer = new Completer<String>(); | |
447 var called = false; | |
448 | |
449 final transformedFuture = completer.future.transform((x) { | |
450 throw "throw from transform"; | |
451 }, (ex) { | |
452 Expect.equals("throw from transform", ex); | |
453 called = true; | |
454 throw "transformed error"; | |
455 }); | |
456 | |
457 completer.complete("original error"); | |
Siggi Cherem (dart-lang)
2012/09/04 16:56:33
original error => normal value?
| |
458 Expect.isTrue(called); | |
459 Expect.isTrue(transformedFuture.isComplete); | |
460 Expect.equals("transformed error", transformedFuture.exception); | |
461 } | |
462 | |
463 testTransformOnExceptionThrows() { | |
464 final completer = new Completer<String>(); | |
465 var called = false; | |
466 | |
467 final transformedFuture = completer.future.transform((x) { | |
468 Expect.fail("should not get here"); | |
469 }, (ex) { | |
470 Expect.equals("original error", ex); | |
471 called = true; | |
472 throw "transformed error"; | |
473 }); | |
474 | |
475 completer.completeException("original error"); | |
476 Expect.isTrue(called); | |
477 Expect.isTrue(transformedFuture.isComplete); | |
478 Expect.equals("transformed error", transformedFuture.exception); | |
479 } | |
480 | |
481 testTransformOnExceptionReturnsTrue() { | |
482 final completer = new Completer<String>(); | |
483 var called = false; | |
484 | |
485 final transformedFuture = completer.future.transform((x) { | |
486 Expect.fail("should not get here"); | |
487 }, (ex) { | |
488 Expect.equals("original error", ex); | |
489 called = true; | |
490 return true; | |
491 }); | |
492 | |
493 completer.completeException("original error"); | |
494 Expect.isTrue(called); | |
495 Expect.isFalse(transformedFuture.isComplete); | |
496 } | |
497 | |
498 testTransformOnExceptionReturnsNontrue() { | |
499 final completer = new Completer<String>(); | |
500 var called = false; | |
501 | |
502 final transformedFuture = completer.future.transform((x) { | |
503 Expect.fail("should not get here"); | |
504 }, (ex) { | |
505 Expect.equals("original error", ex); | |
506 called = true; | |
507 return null; | |
508 }); | |
509 | |
510 completer.completeException("original error"); | |
511 Expect.isTrue(called); | |
512 Expect.isTrue(transformedFuture.isComplete); | |
513 Expect.equals("original error", transformedFuture.exception); | |
514 } | |
515 | |
516 | |
445 // Tests for Future.chain | 517 // Tests for Future.chain |
446 | 518 |
447 testChainSuccess() { | 519 testChainSuccess() { |
448 final completerA = new Completer<String>(); | 520 final completerA = new Completer<String>(); |
449 final completerB = new Completer<String>(); | 521 final completerB = new Completer<String>(); |
450 final chainedFuture = completerA.future.chain((x) { | 522 final chainedFuture = completerA.future.chain((x) { |
451 Expect.equals("42", x); | 523 Expect.equals("42", x); |
452 return completerB.future; | 524 return completerB.future; |
453 }); | 525 }); |
454 Expect.isFalse(chainedFuture.isComplete); | 526 Expect.isFalse(chainedFuture.isComplete); |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
522 testCallStackIsNullIfCompletedSuccessfully(); | 594 testCallStackIsNullIfCompletedSuccessfully(); |
523 testCallStackReturnsCallstackPassedToCompleteException(); | 595 testCallStackReturnsCallstackPassedToCompleteException(); |
524 testCallStackIsCapturedIfTransformCallbackThrows(); | 596 testCallStackIsCapturedIfTransformCallbackThrows(); |
525 testCallStackIsCapturedIfChainCallbackThrows(); | 597 testCallStackIsCapturedIfChainCallbackThrows(); |
526 testCompleteWithCompletionAndSuccessHandlers(); | 598 testCompleteWithCompletionAndSuccessHandlers(); |
527 testExceptionWithCompletionAndSuccessHandlers(); | 599 testExceptionWithCompletionAndSuccessHandlers(); |
528 testExceptionWithCompletionAndSuccessAndExceptionHandlers(); | 600 testExceptionWithCompletionAndSuccessAndExceptionHandlers(); |
529 testTransformSuccess(); | 601 testTransformSuccess(); |
530 testTransformFutureFails(); | 602 testTransformFutureFails(); |
531 testTransformTransformerFails(); | 603 testTransformTransformerFails(); |
604 testTransformOnExceptionTransformerThrows(); | |
605 testTransformOnExceptionThrows(); | |
606 testTransformOnExceptionReturnsTrue(); | |
607 testTransformOnExceptionReturnsNontrue(); | |
532 testChainSuccess(); | 608 testChainSuccess(); |
533 testChainFirstFutureFails(); | 609 testChainFirstFutureFails(); |
534 testChainTransformerFails(); | 610 testChainTransformerFails(); |
535 testChainSecondFutureFails(); | 611 testChainSecondFutureFails(); |
536 } | 612 } |
OLD | NEW |