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(); |
}); |
} |