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

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: Allow transformException to complete successfully. 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
« no previous file with comments | « lib/coreimpl/future_implementation.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 testTransformExceptionReturns() {
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 "transformed value";
539 });
540
541 completer.completeException("original error");
542 Expect.isTrue(called);
543 Expect.isTrue(transformedFuture.isComplete);
544 Expect.equals("transformed value", transformedFuture.value);
545 }
546
500 main() { 547 main() {
501 testImmediate(); 548 testImmediate();
502 testNeverComplete(); 549 testNeverComplete();
503 testComplete(); 550 testComplete();
504 testCompleteWithCompleteHandlerBeforeComplete(); 551 testCompleteWithCompleteHandlerBeforeComplete();
505 testExceptionWithCompleteHandlerBeforeComplete(); 552 testExceptionWithCompleteHandlerBeforeComplete();
506 testCompleteWithCompleteHandlerAfterComplete(); 553 testCompleteWithCompleteHandlerAfterComplete();
507 testExceptionWithCompleteHandlerAfterComplete(); 554 testExceptionWithCompleteHandlerAfterComplete();
508 testCompleteWithManyCompleteHandlers(); 555 testCompleteWithManyCompleteHandlers();
509 testExceptionWithManyCompleteHandlers(); 556 testExceptionWithManyCompleteHandlers();
(...skipping 16 matching lines...) Expand all
526 testCompleteWithCompletionAndSuccessHandlers(); 573 testCompleteWithCompletionAndSuccessHandlers();
527 testExceptionWithCompletionAndSuccessHandlers(); 574 testExceptionWithCompletionAndSuccessHandlers();
528 testExceptionWithCompletionAndSuccessAndExceptionHandlers(); 575 testExceptionWithCompletionAndSuccessAndExceptionHandlers();
529 testTransformSuccess(); 576 testTransformSuccess();
530 testTransformFutureFails(); 577 testTransformFutureFails();
531 testTransformTransformerFails(); 578 testTransformTransformerFails();
532 testChainSuccess(); 579 testChainSuccess();
533 testChainFirstFutureFails(); 580 testChainFirstFutureFails();
534 testChainTransformerFails(); 581 testChainTransformerFails();
535 testChainSecondFutureFails(); 582 testChainSecondFutureFails();
583 testTransformExceptionCompletesNormally();
584 testTransformExceptionThrows();
585 testTransformExceptionReturns();
536 } 586 }
OLDNEW
« no previous file with comments | « lib/coreimpl/future_implementation.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698