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 import "dart:async"; |
5 import "package:expect/expect.dart"; | 6 import "package:expect/expect.dart"; |
6 import "package:async_helper/async_helper.dart"; | 7 import "package:async_helper/async_helper.dart"; |
7 | 8 |
8 range(start, end) async* { | 9 expectList(stream, list) { |
9 for (int i = start; i < end; i++) { | 10 return stream.toList().then((v) { |
10 yield i; | 11 Expect.listEquals(v, list); |
11 } | 12 }); |
12 } | 13 } |
13 | 14 |
14 concat(a, b) async* { | 15 mkStream(int n) async* { |
15 yield* a; | 16 for (int i = 0; i < n; i++) yield i; |
16 yield* b; | |
17 } | |
18 | |
19 test() async { | |
20 Expect.listEquals([1, 2, 3, 11, 12, 13], | |
21 await concat(range(1, 4), range(11, 14)).toList()); | |
22 } | 17 } |
23 | 18 |
24 main() { | 19 main() { |
| 20 f(s) async* { |
| 21 var r = 0; |
| 22 await for(var v in s.take(5)) yield r += v; |
| 23 } |
25 asyncStart(); | 24 asyncStart(); |
26 test().then((_) { | 25 expectList(f(mkStream(10)), [0, 1, 3, 6, 10]).then(asyncSuccess); |
27 asyncEnd(); | 26 } |
28 }); | |
29 } | |
OLD | NEW |