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

Unified Diff: tests/corelib/futures_test.dart

Issue 11293132: Add a Futures.forEach function for asynchronously iterating over a collection. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Code review change Created 8 years, 1 month 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/core/future.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/corelib/futures_test.dart
diff --git a/tests/corelib/futures_test.dart b/tests/corelib/futures_test.dart
index e5daa1dabfbf49aef2df6cb8200a33dbc191c9a3..c3f48fb2743c5e67c148191ba7f07d9ff6007bc0 100644
--- a/tests/corelib/futures_test.dart
+++ b/tests/corelib/futures_test.dart
@@ -27,18 +27,43 @@ Future testCompleteBeforeWait() {
return Futures.wait(futures);
}
+Future testForEachEmpty() {
+ return Futures.forEach([], (_) => throw 'should not be called');
+}
+
+Future testForEach() {
+ var seen = <int>[];
+ return Futures.forEach([1, 2, 3, 4, 5], (n) {
+ seen.add(n);
+ return new Future.immediate(null);
+ }).transform((_) => Expect.listEquals([1, 2, 3, 4, 5], seen));
+}
+
+Future testForEachWithException() {
+ var seen = <int>[];
+ return Futures.forEach([1, 2, 3, 4, 5], (n) {
+ if (n == 4) throw 'correct exception';
+ seen.add(n);
+ return new Future.immediate(null);
+ }).transform((_) => throw 'incorrect exception').transformException((e) {
+ Expect.equals('correct exception', e);
+ });
+}
+
main() {
List<Future> futures = new List<Future>();
futures.add(testWaitEmpty());
futures.add(testCompleteAfterWait());
futures.add(testCompleteBeforeWait());
+ futures.add(testForEachEmpty());
+ futures.add(testForEach());
// Use a receive port for blocking the test.
// Note that if the test fails, the program will not end.
ReceivePort port = new ReceivePort();
Futures.wait(futures).then((List list) {
- Expect.equals(3, list.length);
+ Expect.equals(5, list.length);
port.close();
});
}
« no previous file with comments | « sdk/lib/core/future.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698