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

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

Issue 356773005: Add Future.doWhile to dart:async. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 6 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
« sdk/lib/async/future.dart ('K') | « sdk/lib/async/future.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/futures_test.dart
diff --git a/tests/lib/async/futures_test.dart b/tests/lib/async/futures_test.dart
index 21121206d4469e4297f68fd4d81b19d554f89b2f..c703780ebfcc35311bf89c10993af126e26786ff 100644
--- a/tests/lib/async/futures_test.dart
+++ b/tests/lib/async/futures_test.dart
@@ -184,6 +184,14 @@ Future testForEach() {
}).then((_) => Expect.listEquals([1, 2, 3, 4, 5], seen));
}
+Future testForEachSync() {
+ var seen = <int>[];
+ return Future.forEach([1, 2, 3, 4, 5], (n) {
+ seen.add(n);
+ return;
+ }).then((_) => Expect.listEquals([1, 2, 3, 4, 5], seen));
Lasse Reichstein Nielsen 2014/06/26 06:26:49 The entire "(n) { seen.add(n); return; }" function
nweiz 2014/06/26 19:48:11 Done.
+}
+
Future testForEachWithException() {
var seen = <int>[];
return Future.forEach([1, 2, 3, 4, 5], (n) {
@@ -197,6 +205,35 @@ Future testForEachWithException() {
});
}
+Future testDoWhile() {
+ var count = 0;
+ return Future.doWhile(() {
+ count++;
+ return new Future(() => count < 10);
+ }).then((_) => Expect.equals(10, count));
+}
+
+Future testDoWhileSync() {
+ var count = 0;
+ return Future.doWhile(() {
+ count++;
+ return count < 10;
+ }).then((_) => Expect.equals(10, count));
+}
+
+Future testDoWhileWithException() {
+ var count = 0;
+ return Future.doWhile(() {
+ count++;
+ if (count == 4) throw 'correct exception'
+ return new Future(() => true);
+ }).then((_) {
+ throw 'incorrect exception';
+ }).catchError((error) {
+ Expect.equals('correct exception', error);
+ });
+}
+
main() {
List<Future> futures = new List<Future>();
@@ -213,7 +250,11 @@ main() {
futures.add(testEagerWait());
futures.add(testForEachEmpty());
futures.add(testForEach());
+ futures.add(testForEachSync());
futures.add(testForEachWithException());
+ futures.add(testDoWhile());
+ futures.add(testDoWhileSync());
+ futures.add(testDoWhileWithException());
asyncStart();
Future.wait(futures).then((List list) {
« sdk/lib/async/future.dart ('K') | « sdk/lib/async/future.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698