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

Unified Diff: tests/lib/async/future_test.dart

Issue 1563223002: Add Future.any and Stream.fromFutures. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Address comment Created 4 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/stream.dart ('k') | tests/lib/async/stream_from_futures_test.dart » ('j') | 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 030340d6468ed9686aee59e2df9a672c5f35a050..e8387bfd19e1a159fbda3c9c6f5e508b44d668ce 100644
--- a/tests/lib/async/future_test.dart
+++ b/tests/lib/async/future_test.dart
@@ -926,6 +926,74 @@ void testTypes() {
testType("Future.error", new Future<int>.error("ERR")..catchError((_){}));
}
+void testAnyValue() {
+ asyncStart();
+ var cs = new List.generate(3, (_) => new Completer());
+ var result = Future.any(cs.map((x) => x.future));
+
+ result.then((v) {
+ Expect.equals(42, v);
+ asyncEnd();
+ }, onError: (e, s) {
+ Expect.fail("Unexpected error: $e");
+ });
+
+ cs[1].complete(42);
+ cs[2].complete(10);
+ cs[0].complete(20);
+}
+
+void testAnyError() {
+ asyncStart();
+ var cs = new List.generate(3, (_) => new Completer());
+ var result = Future.any(cs.map((x) => x.future));
+
+ result.then((v) {
+ Expect.fail("Unexpected value: $v");
+ }, onError: (e, s) {
+ Expect.equals(42, e);
+ asyncEnd();
+ });
+
+ cs[1].completeError(42);
+ cs[2].complete(10);
+ cs[0].complete(20);
+}
+
+void testAnyIgnoreIncomplete() {
+ asyncStart();
+ var cs = new List.generate(3, (_) => new Completer());
+ var result = Future.any(cs.map((x) => x.future));
+
+ result.then((v) {
+ Expect.equals(42, v);
+ asyncEnd();
+ }, onError: (e, s) {
+ Expect.fail("Unexpected error: $e");
+ });
+
+ cs[1].complete(42);
+ // The other two futures never complete.
+}
+
+void testAnyIgnoreError() {
+ asyncStart();
+ var cs = new List.generate(3, (_) => new Completer());
+ var result = Future.any(cs.map((x) => x.future));
+
+ result.then((v) {
+ Expect.equals(42, v);
+ asyncEnd();
+ }, onError: (e, s) {
+ Expect.fail("Unexpected error: $e");
+ });
+
+ cs[1].complete(42);
+ // The errors are ignored, not uncaught.
+ cs[2].completeError("BAD");
+ cs[0].completeError("BAD");
+}
+
main() {
asyncStart();
@@ -989,6 +1057,11 @@ main() {
testTypes();
+ testAnyValue();
+ testAnyError();
+ testAnyIgnoreIncomplete();
+ testAnyIgnoreError();
+
asyncEnd();
}
« no previous file with comments | « sdk/lib/async/stream.dart ('k') | tests/lib/async/stream_from_futures_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698