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

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

Issue 10537096: Revert changes to Future.chain() and Future.transform() from http://codereview.chromium.org/10517006 (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 6 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 | « corelib/src/implementation/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 371 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 Expect.isFalse(transformedFuture.isComplete); 382 Expect.isFalse(transformedFuture.isComplete);
383 completer.completeException(error); 383 completer.completeException(error);
384 Expect.equals(error, transformedFuture.exception); 384 Expect.equals(error, transformedFuture.exception);
385 } 385 }
386 386
387 testTransformTransformerFails() { 387 testTransformTransformerFails() {
388 final completer = new Completer<String>(); 388 final completer = new Completer<String>();
389 final error = new Exception("Oh no!"); 389 final error = new Exception("Oh no!");
390 final transformedFuture = completer.future.transform((x) { throw error; }); 390 final transformedFuture = completer.future.transform((x) { throw error; });
391 Expect.isFalse(transformedFuture.isComplete); 391 Expect.isFalse(transformedFuture.isComplete);
392 completer.complete("42"); 392 transformedFuture.then((v) => null);
393 Expect.throws(() => completer.complete("42"), check: (e) => e == error);
sammccall 2012/06/10 22:18:09 This covers bug 3489
393 Expect.equals(error, transformedFuture.exception); 394 Expect.equals(error, transformedFuture.exception);
394 } 395 }
395 396
396 // Tests [handleException] and [transform] on the same Future.
397 // An earlier implementation of [transform] didn't support this, and behavior
398 // depended on whether [handleException] or [transform] was called first.
399
400 testTransformAndHandleException() {
401 final completer = new Completer<String>();
402 final error = new Exception("Oh no!");
403 var futureError;
404 var transformedFutureError;
405
406 completer.future.transform((x) => "** $x **").handleException((e) {
407 Expect.isNotNull(futureError);
408 transformedFutureError = e;
409 return true;
410 });
411 completer.future.handleException((e) {
412 Expect.isNull(transformedFutureError);
413 futureError = e;
414 return true;
415 });
416 completer.completeException(error);
417
418 Expect.equals(error, futureError);
419 Expect.equals(error, transformedFutureError);
420 }
421
422 testHandleExceptionAndTransform() {
423 final completer = new Completer<String>();
424 final error = new Exception("Oh no!");
425 var futureError;
426 var transformedFutureError;
427
428 completer.future.handleException((e) {
429 Expect.isNull(transformedFutureError);
430 futureError = e;
431 return true;
432 });
433 completer.future.transform((x) => "** $x **").handleException((e) {
434 Expect.isNotNull(futureError);
435 transformedFutureError = e;
436 return true;
437 });
438 completer.completeException(error);
439
440 Expect.equals(error, futureError);
441 Expect.equals(error, transformedFutureError);
442 }
443
444 // Tests for Future.chain 397 // Tests for Future.chain
445 398
446 testChainSuccess() { 399 testChainSuccess() {
447 final completerA = new Completer<String>(); 400 final completerA = new Completer<String>();
448 final completerB = new Completer<String>(); 401 final completerB = new Completer<String>();
449 final chainedFuture = completerA.future.chain((x) { 402 final chainedFuture = completerA.future.chain((x) {
450 Expect.equals("42", x); 403 Expect.equals("42", x);
451 return completerB.future; 404 return completerB.future;
452 }); 405 });
453 Expect.isFalse(chainedFuture.isComplete); 406 Expect.isFalse(chainedFuture.isComplete);
(...skipping 14 matching lines...) Expand all
468 Expect.equals(error, chainedFuture.exception); 421 Expect.equals(error, chainedFuture.exception);
469 } 422 }
470 423
471 testChainTransformerFails() { 424 testChainTransformerFails() {
472 final completerA = new Completer<String>(); 425 final completerA = new Completer<String>();
473 final error = new Exception("Oh no!"); 426 final error = new Exception("Oh no!");
474 final chainedFuture = completerA.future.chain((x) { 427 final chainedFuture = completerA.future.chain((x) {
475 Expect.equals("42", x); 428 Expect.equals("42", x);
476 throw error; 429 throw error;
477 }); 430 });
431 chainedFuture.then((v) => null);
478 Expect.isFalse(chainedFuture.isComplete); 432 Expect.isFalse(chainedFuture.isComplete);
479 completerA.complete("42"); 433 Expect.throws(() => completerA.complete("42"), check: (e) => e == error);
480 Expect.equals(error, chainedFuture.exception); 434 Expect.equals(error, chainedFuture.exception);
481 } 435 }
482 436
483 testChainSecondFutureFails() { 437 testChainSecondFutureFails() {
484 final completerA = new Completer<String>(); 438 final completerA = new Completer<String>();
485 final completerB = new Completer<String>(); 439 final completerB = new Completer<String>();
486 final error = new Exception("Oh no!"); 440 final error = new Exception("Oh no!");
487 final chainedFuture = completerA.future.chain((x) { 441 final chainedFuture = completerA.future.chain((x) {
488 Expect.equals("42", x); 442 Expect.equals("42", x);
489 return completerB.future; 443 return completerB.future;
490 }); 444 });
491 Expect.isFalse(chainedFuture.isComplete); 445 Expect.isFalse(chainedFuture.isComplete);
492 completerA.complete("42"); 446 completerA.complete("42");
493 Expect.isFalse(chainedFuture.isComplete); 447 Expect.isFalse(chainedFuture.isComplete);
494 completerB.completeException(error); 448 completerB.completeException(error);
495 Expect.equals(error, chainedFuture.exception); 449 Expect.equals(error, chainedFuture.exception);
496 } 450 }
497 451
498 // Tests [handleException] and [chain] on the same Future.
499 // An earlier implementation of [chain] didn't support this, and behavior
500 // depended on whether [handleException] or [chain] was called first.
501
502 testChainAndHandleException() {
503 final completer = new Completer<String>();
504 final error = new Exception("Oh no!");
505 var futureError;
506 var chainedFutureError;
507
508 var chainedFuture = completer.future
509 .chain((_) => new Future<int>.immediate(43));
510 chainedFuture.handleException((e) {
511 Expect.isNotNull(futureError);
512 chainedFutureError = e;
513 return true;
514 });
515 completer.future.handleException((e) {
516 Expect.isNull(chainedFutureError);
517 futureError = e;
518 return true;
519 });
520 completer.completeException(error);
521
522 Expect.equals(error, futureError);
523 Expect.equals(error, chainedFutureError);
524 }
525
526 testHandleExceptionAndChain() {
527 final completer = new Completer<String>();
528 final error = new Exception("Oh no!");
529 var futureError;
530 var chainedFutureError;
531
532 completer.future.handleException((e) {
533 Expect.isNull(chainedFutureError);
534 futureError = e;
535 return true;
536 });
537 var chainedFuture = completer.future
538 .chain((_) => new Future<int>.immediate(43));
539 chainedFuture.handleException((e) {
540 Expect.isNotNull(futureError);
541 chainedFutureError = e;
542 return true;
543 });
544 completer.completeException(error);
545
546 Expect.equals(error, futureError);
547 Expect.equals(error, chainedFutureError);
548 }
549
550 main() { 452 main() {
551 testImmediate(); 453 testImmediate();
552 testNeverComplete(); 454 testNeverComplete();
553 testComplete(); 455 testComplete();
554 testCompleteWithCompleteHandlerBeforeComplete(); 456 testCompleteWithCompleteHandlerBeforeComplete();
555 testExceptionWithCompleteHandlerBeforeComplete(); 457 testExceptionWithCompleteHandlerBeforeComplete();
556 testCompleteWithCompleteHandlerAfterComplete(); 458 testCompleteWithCompleteHandlerAfterComplete();
557 testExceptionWithCompleteHandlerAfterComplete(); 459 testExceptionWithCompleteHandlerAfterComplete();
558 testCompleteWithManyCompleteHandlers(); 460 testCompleteWithManyCompleteHandlers();
559 testExceptionWithManyCompleteHandlers(); 461 testExceptionWithManyCompleteHandlers();
560 testCompleteWithSuccessHandlerBeforeComplete(); 462 testCompleteWithSuccessHandlerBeforeComplete();
561 testCompleteWithSuccessHandlerAfterComplete(); 463 testCompleteWithSuccessHandlerAfterComplete();
562 testCompleteManySuccessHandlers(); 464 testCompleteManySuccessHandlers();
563 testException(); 465 testException();
564 testExceptionHandler(); 466 testExceptionHandler();
565 testExceptionHandlerReturnsTrue(); 467 testExceptionHandlerReturnsTrue();
566 testExceptionHandlerReturnsTrue2(); 468 testExceptionHandlerReturnsTrue2();
567 testExceptionHandlerReturnsFalse(); 469 testExceptionHandlerReturnsFalse();
568 testExceptionHandlerReturnsFalse2(); 470 testExceptionHandlerReturnsFalse2();
569 testExceptionHandlerAfterCompleteThenNotCalled(); 471 testExceptionHandlerAfterCompleteThenNotCalled();
570 testExceptionHandlerAfterCompleteReturnsFalseThenThrows(); 472 testExceptionHandlerAfterCompleteReturnsFalseThenThrows();
571 testCompleteWithCompletionAndSuccessHandlers(); 473 testCompleteWithCompletionAndSuccessHandlers();
572 testExceptionWithCompletionAndSuccessHandlers(); 474 testExceptionWithCompletionAndSuccessHandlers();
573 testExceptionWithCompletionAndSuccessAndExceptionHandlers(); 475 testExceptionWithCompletionAndSuccessAndExceptionHandlers();
574 testTransformSuccess(); 476 testTransformSuccess();
575 testTransformFutureFails(); 477 testTransformFutureFails();
576 testTransformTransformerFails(); 478 testTransformTransformerFails();
577 testTransformAndHandleException();
578 testHandleExceptionAndTransform();
579 testChainSuccess(); 479 testChainSuccess();
580 testChainFirstFutureFails(); 480 testChainFirstFutureFails();
581 testChainTransformerFails(); 481 testChainTransformerFails();
582 testChainSecondFutureFails(); 482 testChainSecondFutureFails();
583 testChainAndHandleException();
584 testHandleExceptionAndChain();
585 } 483 }
OLDNEW
« no previous file with comments | « corelib/src/implementation/future_implementation.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698