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

Side by Side Diff: tests/language_strong/await_for_cancel_test.dart

Issue 2771453003: Format all tests. (Closed)
Patch Set: Format files Created 3 years, 8 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
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 "dart:async";
6 import "package:expect/expect.dart"; 6 import "package:expect/expect.dart";
7 import "package:async_helper/async_helper.dart"; 7 import "package:async_helper/async_helper.dart";
8 8
9 bool canceled; 9 bool canceled;
10 10
11 test1() async { 11 test1() async {
12 canceled = false; 12 canceled = false;
13 try { 13 try {
14 StreamController controller = infiniteStreamController(); 14 StreamController controller = infiniteStreamController();
15 outer: while(true) { 15 outer:
16 while (true) {
16 await for (var x in controller.stream) { 17 await for (var x in controller.stream) {
17 for (int j = 0; j < 10; j++) { 18 for (int j = 0; j < 10; j++) {
18 if (j == 5) break outer; 19 if (j == 5) break outer;
19 } 20 }
20 } 21 }
21 } 22 }
22 } finally { 23 } finally {
23 Expect.isTrue(canceled); 24 Expect.isTrue(canceled);
24 } 25 }
25 } 26 }
26 27
27 test2() async { 28 test2() async {
28 canceled = false; 29 canceled = false;
29 try { 30 try {
30 StreamController controller = infiniteStreamController(); 31 StreamController controller = infiniteStreamController();
31 bool first = true; 32 bool first = true;
32 outer: while(true) { 33 outer:
34 while (true) {
33 if (first) { 35 if (first) {
34 first = false; 36 first = false;
35 } else { 37 } else {
36 break; 38 break;
37 } 39 }
38 await for (var x in controller.stream) { 40 await for (var x in controller.stream) {
39 for (int j = 0; j < 10; j++) { 41 for (int j = 0; j < 10; j++) {
40 if (j == 5) continue outer; 42 if (j == 5) continue outer;
41 } 43 }
42 } 44 }
43 } 45 }
44 } finally { 46 } finally {
45 Expect.isTrue(canceled); 47 Expect.isTrue(canceled);
46 } 48 }
47 } 49 }
48 50
49 test() async { 51 test() async {
50 await test1(); 52 await test1();
51 await test2(); 53 await test2();
52 } 54 }
53 55
54 main() { 56 main() {
55 asyncStart(); 57 asyncStart();
56 test().then((_) { 58 test().then((_) {
57 asyncEnd(); 59 asyncEnd();
58 }); 60 });
59 } 61 }
60 62
61
62 // Create a stream that produces numbers [1, 2, ... ] 63 // Create a stream that produces numbers [1, 2, ... ]
63 StreamController infiniteStreamController() { 64 StreamController infiniteStreamController() {
64 StreamController controller; 65 StreamController controller;
65 Timer timer; 66 Timer timer;
66 int counter = 0; 67 int counter = 0;
67 68
68 void tick() { 69 void tick() {
69 if (controller.isPaused) { 70 if (controller.isPaused) {
70 return; 71 return;
71 } 72 }
(...skipping 11 matching lines...) Expand all
83 84
84 controller = new StreamController( 85 controller = new StreamController(
85 onListen: startTimer, 86 onListen: startTimer,
86 onResume: startTimer, 87 onResume: startTimer,
87 onCancel: () { 88 onCancel: () {
88 canceled = true; 89 canceled = true;
89 }); 90 });
90 91
91 return controller; 92 return controller;
92 } 93 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698