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

Side by Side Diff: test/codegen/language/asyncstar_yield_test.dart

Issue 1243503007: fixes #221, initial sync*, async, async* implementation (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: Created 5 years, 4 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
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 import "dart:async";
6 import "package:expect/expect.dart";
7 import "package:async_helper/async_helper.dart";
8
9 Stream<int> foo1() async* {
10 yield 1;
11 var p = await new Future.value(10);
12 yield p + 10;
13 }
14
15 Stream<int> foo2() async* {
16 int i = 0;
17 while (true) {
18 await (new Future.delayed(new Duration(milliseconds: 0), () {}));
19 if (i > 10) return;
20 yield i;
21 i++;
22 }
23 }
24
25 Stream<int> foo3(p) async* {
26 int i = 0;
27 bool t = false;
28 yield null;
29 while (true) {
30 i++;
31 a: for (int i = 0; i < p; i++) {
32 if (!t) {
33 for (int j = 0; j < 3; j++) {
34 yield -1;
35 t = true;
36 break a;
37 }
38 }
39 await 4;
40 yield i;
41 }
42 }
43 }
44
45 Completer<bool> finalized = new Completer<bool>();
46
47 Stream<int> foo4() async* {
48 int i = 0;
49 try {
50 while (true) {
51 yield i;
52 i++;
53 }
54 } finally {
55 // Canceling the stream-subscription should run the finalizer.
56 finalized.complete(true);
57 }
58 }
59
60 test() async {
61 Expect.listEquals([1, 20], await (foo1().toList()));
62 Expect.listEquals([0, 1, 2, 3], await (foo2().take(4).toList()));
63 Expect.listEquals([null, -1, 0, 1, 2, 3, 0, 1, 2, 3],
64 await (foo3(4).take(10).toList()));
65 Expect.listEquals([0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
66 await (foo4().take(10).toList()));
67 Expect.isTrue(await (finalized.future));
68 }
69
70 main () {
71 asyncStart();
72 test().then((_) {
73 asyncEnd();
74 });
75 }
OLDNEW
« no previous file with comments | « test/codegen/language/asyncstar_throw_in_catch_test.dart ('k') | test/codegen/language/asyncstar_yieldstar_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698