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

Side by Side 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: code review 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « sdk/lib/async/future.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library futures_test; 5 library futures_test;
6 import 'package:async_helper/async_helper.dart'; 6 import 'package:async_helper/async_helper.dart';
7 import "package:expect/expect.dart"; 7 import "package:expect/expect.dart";
8 import 'dart:async'; 8 import 'dart:async';
9 9
10 Future testWaitEmpty() { 10 Future testWaitEmpty() {
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 } 177 }
178 178
179 Future testForEach() { 179 Future testForEach() {
180 var seen = <int>[]; 180 var seen = <int>[];
181 return Future.forEach([1, 2, 3, 4, 5], (n) { 181 return Future.forEach([1, 2, 3, 4, 5], (n) {
182 seen.add(n); 182 seen.add(n);
183 return new Future.value(); 183 return new Future.value();
184 }).then((_) => Expect.listEquals([1, 2, 3, 4, 5], seen)); 184 }).then((_) => Expect.listEquals([1, 2, 3, 4, 5], seen));
185 } 185 }
186 186
187 Future testForEachSync() {
188 var seen = <int>[];
189 return Future.forEach([1, 2, 3, 4, 5], seen.add)
190 .then((_) => Expect.listEquals([1, 2, 3, 4, 5], seen));
191 }
192
187 Future testForEachWithException() { 193 Future testForEachWithException() {
188 var seen = <int>[]; 194 var seen = <int>[];
189 return Future.forEach([1, 2, 3, 4, 5], (n) { 195 return Future.forEach([1, 2, 3, 4, 5], (n) {
190 if (n == 4) throw 'correct exception'; 196 if (n == 4) throw 'correct exception';
191 seen.add(n); 197 seen.add(n);
192 return new Future.value(); 198 return new Future.value();
193 }).then((_) { 199 }).then((_) {
194 throw 'incorrect exception'; 200 throw 'incorrect exception';
195 }).catchError((error) { 201 }).catchError((error) {
196 Expect.equals('correct exception', error); 202 Expect.equals('correct exception', error);
197 }); 203 });
198 } 204 }
199 205
206 Future testDoWhile() {
207 var count = 0;
208 return Future.doWhile(() {
209 count++;
210 return new Future(() => count < 10);
211 }).then((_) => Expect.equals(10, count));
212 }
213
214 Future testDoWhileSync() {
215 var count = 0;
216 return Future.doWhile(() {
217 count++;
218 return count < 10;
219 }).then((_) => Expect.equals(10, count));
220 }
221
222 Future testDoWhileWithException() {
223 var count = 0;
224 return Future.doWhile(() {
225 count++;
226 if (count == 4) throw 'correct exception';
227 return new Future(() => true);
228 }).then((_) {
229 throw 'incorrect exception';
230 }).catchError((error) {
231 Expect.equals('correct exception', error);
232 });
233 }
234
200 main() { 235 main() {
201 List<Future> futures = new List<Future>(); 236 List<Future> futures = new List<Future>();
202 237
203 futures.add(testWaitEmpty()); 238 futures.add(testWaitEmpty());
204 futures.add(testCompleteAfterWait()); 239 futures.add(testCompleteAfterWait());
205 futures.add(testCompleteBeforeWait()); 240 futures.add(testCompleteBeforeWait());
206 futures.add(testWaitWithMultipleValues()); 241 futures.add(testWaitWithMultipleValues());
207 futures.add(testWaitWithSingleError()); 242 futures.add(testWaitWithSingleError());
208 futures.add(testWaitWithMultipleErrors()); 243 futures.add(testWaitWithMultipleErrors());
209 futures.add(testWaitWithMultipleErrorsEager()); 244 futures.add(testWaitWithMultipleErrorsEager());
210 futures.add(testWaitWithSingleErrorWithStackTrace()); 245 futures.add(testWaitWithSingleErrorWithStackTrace());
211 futures.add(testWaitWithMultipleErrorsWithStackTrace()); 246 futures.add(testWaitWithMultipleErrorsWithStackTrace());
212 futures.add(testWaitWithMultipleErrorsWithStackTraceEager()); 247 futures.add(testWaitWithMultipleErrorsWithStackTraceEager());
213 futures.add(testEagerWait()); 248 futures.add(testEagerWait());
214 futures.add(testForEachEmpty()); 249 futures.add(testForEachEmpty());
215 futures.add(testForEach()); 250 futures.add(testForEach());
251 futures.add(testForEachSync());
216 futures.add(testForEachWithException()); 252 futures.add(testForEachWithException());
253 futures.add(testDoWhile());
254 futures.add(testDoWhileSync());
255 futures.add(testDoWhileWithException());
217 256
218 asyncStart(); 257 asyncStart();
219 Future.wait(futures).then((List list) { 258 Future.wait(futures).then((List list) {
220 Expect.equals(14, list.length); 259 Expect.equals(18, list.length);
221 asyncEnd(); 260 asyncEnd();
222 }); 261 });
223 } 262 }
OLDNEW
« no previous file with comments | « sdk/lib/async/future.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698