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

Side by Side Diff: tests/corelib/future_test.dart

Issue 10908040: Support transforming the exception in Future.transform(). (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Split transformException() out into separate method. Created 8 years, 3 months 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 // 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 479 matching lines...) Expand 10 before | Expand all | Expand 10 after
490 Expect.equals("42", x); 490 Expect.equals("42", x);
491 return completerB.future; 491 return completerB.future;
492 }); 492 });
493 Expect.isFalse(chainedFuture.isComplete); 493 Expect.isFalse(chainedFuture.isComplete);
494 completerA.complete("42"); 494 completerA.complete("42");
495 Expect.isFalse(chainedFuture.isComplete); 495 Expect.isFalse(chainedFuture.isComplete);
496 completerB.completeException(error); 496 completerB.completeException(error);
497 Expect.equals(error, chainedFuture.exception); 497 Expect.equals(error, chainedFuture.exception);
498 } 498 }
499 499
500 // Tests for Future.transformException
501
502 testTransformExceptionCompletesNormally() {
503 final completer = new Completer<String>();
504 var called = false;
505
506 final transformedFuture = completer.future.transformException((ex) {
507 Expect.fail("should not get here");
508 });
509
510 completer.complete("value");
511 Expect.isTrue(transformedFuture.isComplete);
512 Expect.equals("value", transformedFuture.value);
513 }
514
515 testTransformExceptionThrows() {
516 final completer = new Completer<String>();
517 var called = false;
518
519 final transformedFuture = completer.future.transformException((ex) {
520 Expect.equals("original error", ex);
521 called = true;
522 throw "transformed error";
523 });
524
525 completer.completeException("original error");
526 Expect.isTrue(called);
527 Expect.isTrue(transformedFuture.isComplete);
528 Expect.equals("transformed error", transformedFuture.exception);
529 }
530
531 testTransformExceptionReturnsTrue() {
532 final completer = new Completer<String>();
533 var called = false;
534
535 final transformedFuture = completer.future.transformException((ex) {
536 Expect.equals("original error", ex);
537 called = true;
538 return true;
539 });
540
541 completer.completeException("original error");
542 Expect.isTrue(called);
543 Expect.isFalse(transformedFuture.isComplete);
544 }
545
546 testTransformExceptionReturnsNontrue() {
547 final completer = new Completer<String>();
548 var called = false;
549
550 final transformedFuture = completer.future.transformException((ex) {
551 Expect.equals("original error", ex);
552 called = true;
553 return null;
554 });
555
556 completer.completeException("original error");
557 Expect.isTrue(called);
558 Expect.isTrue(transformedFuture.isComplete);
559 Expect.equals("original error", transformedFuture.exception);
560 }
561
500 main() { 562 main() {
501 testImmediate(); 563 testImmediate();
502 testNeverComplete(); 564 testNeverComplete();
503 testComplete(); 565 testComplete();
504 testCompleteWithCompleteHandlerBeforeComplete(); 566 testCompleteWithCompleteHandlerBeforeComplete();
505 testExceptionWithCompleteHandlerBeforeComplete(); 567 testExceptionWithCompleteHandlerBeforeComplete();
506 testCompleteWithCompleteHandlerAfterComplete(); 568 testCompleteWithCompleteHandlerAfterComplete();
507 testExceptionWithCompleteHandlerAfterComplete(); 569 testExceptionWithCompleteHandlerAfterComplete();
508 testCompleteWithManyCompleteHandlers(); 570 testCompleteWithManyCompleteHandlers();
509 testExceptionWithManyCompleteHandlers(); 571 testExceptionWithManyCompleteHandlers();
(...skipping 16 matching lines...) Expand all
526 testCompleteWithCompletionAndSuccessHandlers(); 588 testCompleteWithCompletionAndSuccessHandlers();
527 testExceptionWithCompletionAndSuccessHandlers(); 589 testExceptionWithCompletionAndSuccessHandlers();
528 testExceptionWithCompletionAndSuccessAndExceptionHandlers(); 590 testExceptionWithCompletionAndSuccessAndExceptionHandlers();
529 testTransformSuccess(); 591 testTransformSuccess();
530 testTransformFutureFails(); 592 testTransformFutureFails();
531 testTransformTransformerFails(); 593 testTransformTransformerFails();
532 testChainSuccess(); 594 testChainSuccess();
533 testChainFirstFutureFails(); 595 testChainFirstFutureFails();
534 testChainTransformerFails(); 596 testChainTransformerFails();
535 testChainSecondFutureFails(); 597 testChainSecondFutureFails();
598 testTransformExceptionCompletesNormally();
599 testTransformExceptionThrows();
600 testTransformExceptionReturnsTrue();
601 testTransformExceptionReturnsNontrue();
536 } 602 }
OLDNEW
« lib/coreimpl/future_implementation.dart ('K') | « lib/coreimpl/future_implementation.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698