OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 async_star_pause_test; | 5 library async_star_pause_test; |
6 | 6 |
7 import "package:async_helper/async_helper.dart"; | 7 import "package:unittest/unittest.dart"; |
8 import "package:expect/expect.dart"; | |
9 import "dart:async"; | 8 import "dart:async"; |
10 | 9 |
11 main() { | 10 main() { |
12 // await for pauses stream during body. | 11 test("await for pauses stream during body", () async { |
13 asyncTest(() async { | |
14 // Assumes await-for uses streamIterator. | 12 // Assumes await-for uses streamIterator. |
15 var log = []; | 13 var log = []; |
16 var s = () async* { | 14 var s = () async* { |
17 for (int i = 0; i < 3; i++) { | 15 for (int i = 0; i < 3; i++) { |
18 log.add("$i-"); | 16 log.add("$i-"); |
19 yield i; | 17 yield i; |
20 // Should pause here until next iteration of await-for loop. | 18 // Should pause here until next iteration of await-for loop. |
21 log.add("$i+"); | 19 log.add("$i+"); |
22 } | 20 } |
23 }(); | 21 }(); |
24 await for (var i in s) { | 22 await for (var i in s) { |
25 log.add("$i?"); | 23 log.add("$i?"); |
26 await nextMicrotask(); | 24 await nextMicrotask(); |
27 log.add("$i!"); | 25 log.add("$i!"); |
28 } | 26 } |
29 Expect.listEquals(log, [ | 27 expect(log, [ |
30 "0-", | 28 "0-", |
31 "0?", | 29 "0?", |
32 "0!", | 30 "0!", |
33 "0+", | 31 "0+", |
34 "1-", | 32 "1-", |
35 "1?", | 33 "1?", |
36 "1!", | 34 "1!", |
37 "1+", | 35 "1+", |
38 "2-", | 36 "2-", |
39 "2?", | 37 "2?", |
40 "2!", | 38 "2!", |
41 "2+" | 39 "2+" |
42 ]); | 40 ]); |
43 }); | 41 }); |
44 } | 42 } |
45 | 43 |
46 Future nextMicrotask() => new Future.microtask(() {}); | 44 Future nextMicrotask() => new Future.microtask(() {}); |
OLD | NEW |