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

Unified 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, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sdk/lib/async/future_impl.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/lib/async/future_test.dart
diff --git a/tests/lib/async/future_test.dart b/tests/lib/async/future_test.dart
index 373a131bf1c5f5647a84cd3897619d200139416c..19c09f83ec5c276ba361c838bff56c31ec758737 100644
--- a/tests/lib/async/future_test.dart
+++ b/tests/lib/async/future_test.dart
@@ -16,6 +16,31 @@ testImmediate() {
});
}
+testOf() {
+ compare(func) {
+ // Compare the results of the following two futures.
+ Future f1 = new Future.of(func);
+ Future f2 = new Future.immediate(null).then((_) => func());
+ f2.catchError((_){}); // I'll get the error later.
+ f1.then((v1) { f2.then((v2) { Expect.equals(v1, v2); }); },
+ onError: (e1) {
+ f2.then((_) { Expect.fail("Expected error"); },
+ onError: (e2) {
+ Expect.equals(e1.error, e2.error);
+ });
+ });
+ }
+ Future val = new Future.immediate(42);
+ Future err1 = new Future.immediateError("Error")..catchError((_){});
+ Future err2 = new Future.immediateError(new AsyncError("AsyncError"))..catchError((_){});
+ compare(() => 42);
+ compare(() => val);
+ compare(() { throw "Flif"; });
+ compare(() { throw new AsyncError("AsyncFlif"); });
+ compare(() => err1);
+ compare(() => err2);
+}
+
testNeverComplete() {
final completer = new Completer<int>();
final future = completer.future;
@@ -559,6 +584,7 @@ testChainedFutureError() {
main() {
testImmediate();
+ testOf();
testNeverComplete();
testComplete();
@@ -599,3 +625,4 @@ main() {
testChainedFutureError();
}
+
« 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