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

Side by Side Diff: tests/lib/async/future_test.dart

Issue 12091105: Add Future.of that calls a function and captures the result (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Better comment. Created 7 years, 10 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 | « sdk/lib/async/future_impl.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 library future_test; 5 library future_test;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:isolate'; 8 import 'dart:isolate';
9 9
10 testImmediate() { 10 testImmediate() {
11 final future = new Future<String>.immediate("42"); 11 final future = new Future<String>.immediate("42");
12 var port = new ReceivePort(); 12 var port = new ReceivePort();
13 future.then((x) { 13 future.then((x) {
14 Expect.equals("42", x); 14 Expect.equals("42", x);
15 port.close(); 15 port.close();
16 }); 16 });
17 } 17 }
18 18
19 testOf() {
20 compare(func) {
21 // Compare the results of the following two futures.
22 Future f1 = new Future.of(func);
23 Future f2 = new Future.immediate(null).then((_) => func());
24 f2.catchError((_){}); // I'll get the error later.
25 f1.then((v1) { f2.then((v2) { Expect.equals(v1, v2); }); },
26 onError: (e1) {
27 f2.then((_) { Expect.fail("Expected error"); },
28 onError: (e2) {
29 Expect.equals(e1.error, e2.error);
30 });
31 });
32 }
33 Future val = new Future.immediate(42);
34 Future err1 = new Future.immediateError("Error")..catchError((_){});
35 Future err2 = new Future.immediateError(new AsyncError("AsyncError"))..catchEr ror((_){});
36 compare(() => 42);
37 compare(() => val);
38 compare(() { throw "Flif"; });
39 compare(() { throw new AsyncError("AsyncFlif"); });
40 compare(() => err1);
41 compare(() => err2);
42 }
43
19 testNeverComplete() { 44 testNeverComplete() {
20 final completer = new Completer<int>(); 45 final completer = new Completer<int>();
21 final future = completer.future; 46 final future = completer.future;
22 future.then((v) => Expect.fails("Value not expected")); 47 future.then((v) => Expect.fails("Value not expected"));
23 future.catchError((e) => Expect.fails("Value not expected")); 48 future.catchError((e) => Expect.fails("Value not expected"));
24 } 49 }
25 50
26 testComplete() { 51 testComplete() {
27 final completer = new Completer<int>(); 52 final completer = new Completer<int>();
28 final future = completer.future; 53 final future = completer.future;
(...skipping 523 matching lines...) Expand 10 before | Expand all | Expand 10 after
552 future.then((v) => new Future.immediateError("Fehler")) 577 future.then((v) => new Future.immediateError("Fehler"))
553 .then((v) { Expect.fail("unreachable!"); }, onError: (e) { 578 .then((v) { Expect.fail("unreachable!"); }, onError: (e) {
554 Expect.equals("Fehler", e.error); 579 Expect.equals("Fehler", e.error);
555 port.close(); 580 port.close();
556 }); 581 });
557 completer.complete(21); 582 completer.complete(21);
558 } 583 }
559 584
560 main() { 585 main() {
561 testImmediate(); 586 testImmediate();
587 testOf();
562 testNeverComplete(); 588 testNeverComplete();
563 589
564 testComplete(); 590 testComplete();
565 testCompleteWithSuccessHandlerBeforeComplete(); 591 testCompleteWithSuccessHandlerBeforeComplete();
566 testCompleteWithSuccessHandlerAfterComplete(); 592 testCompleteWithSuccessHandlerAfterComplete();
567 testCompleteManySuccessHandlers(); 593 testCompleteManySuccessHandlers();
568 testCompleteWithAsyncError(); 594 testCompleteWithAsyncError();
569 595
570 testException(); 596 testException();
571 testExceptionHandler(); 597 testExceptionHandler();
(...skipping 20 matching lines...) Expand all
592 testFutureThenThrowsAsync(); 618 testFutureThenThrowsAsync();
593 testFutureCatchThrowsAsync(); 619 testFutureCatchThrowsAsync();
594 testFutureWhenThrowsAsync(); 620 testFutureWhenThrowsAsync();
595 testFutureCatchRethrowsAsync(); 621 testFutureCatchRethrowsAsync();
596 622
597 testChainedFutureValue(); 623 testChainedFutureValue();
598 testChainedFutureValueDelay(); 624 testChainedFutureValueDelay();
599 testChainedFutureError(); 625 testChainedFutureError();
600 } 626 }
601 627
628
OLDNEW
« no previous file with comments | « sdk/lib/async/future_impl.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698