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

Side by Side Diff: tests/lib/async/stream_listen_zone_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) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 stream_listen_zeno_test; 5 library stream_listen_zeno_test;
6 6
7 import "dart:async"; 7 import "dart:async";
8 import "package:expect/expect.dart"; 8 import "package:expect/expect.dart";
9 import "package:async_helper/async_helper.dart"; 9 import "package:async_helper/async_helper.dart";
10 10
11 main() { 11 main() {
12 asyncStart(); 12 asyncStart();
13 var controller; 13 var controller;
14 for (bool overrideDone in [false, true]) { 14 for (bool overrideDone in [false, true]) {
15 for (bool sync in [false, true]) { 15 for (bool sync in [false, true]) {
16 var mode = "${sync ? "-sync" : ""}${overrideDone ? "-od": ""}"; 16 var mode = "${sync ? "-sync" : ""}${overrideDone ? "-od": ""}";
17 controller = new StreamController(sync: sync); 17 controller = new StreamController(sync: sync);
18 testStream("SC$mode", controller, controller.stream, overrideDone); 18 testStream("SC$mode", controller, controller.stream, overrideDone);
19 controller = new StreamController.broadcast(sync: sync); 19 controller = new StreamController.broadcast(sync: sync);
20 testStream("BSC$mode", controller, controller.stream, overrideDone); 20 testStream("BSC$mode", controller, controller.stream, overrideDone);
21 controller = new StreamController(sync: sync); 21 controller = new StreamController(sync: sync);
22 testStream("SCAB$mode", controller, controller.stream.asBroadcastStream(), 22 testStream("SCAB$mode", controller, controller.stream.asBroadcastStream(),
23 overrideDone, 3); 23 overrideDone, 3);
24 controller = new StreamController(sync: sync); 24 controller = new StreamController(sync: sync);
25 testStream("SCMap$mode", controller, controller.stream.map((x) => x), 25 testStream("SCMap$mode", controller, controller.stream.map((x) => x),
26 overrideDone, 3); 26 overrideDone, 3);
27 } 27 }
28 } 28 }
29 asyncEnd(); 29 asyncEnd();
30 } 30 }
31 31
32 void testStream(String name, StreamController controller, Stream stream, 32 void testStream(
33 bool overrideDone, [int registerExpect = 0]) { 33 String name, StreamController controller, Stream stream, bool overrideDone,
34 [int registerExpect = 0]) {
34 asyncStart(); 35 asyncStart();
35 StreamSubscription sub; 36 StreamSubscription sub;
36 Zone zone; 37 Zone zone;
37 int registerCount = 0; 38 int registerCount = 0;
38 int callbackBits = 0; 39 int callbackBits = 0;
39 int stepCount = 0; 40 int stepCount = 0;
40 Function step; 41 Function step;
41 void nextStep() { Zone.ROOT.scheduleMicrotask(step); } 42 void nextStep() {
43 Zone.ROOT.scheduleMicrotask(step);
44 }
45
42 runZoned(() { 46 runZoned(() {
43 zone = Zone.current; 47 zone = Zone.current;
44 sub = stream.listen((v) { 48 sub = stream.listen((v) {
45 Expect.identical(zone, Zone.current, name); 49 Expect.identical(zone, Zone.current, name);
46 Expect.equals(42, v, name); 50 Expect.equals(42, v, name);
47 callbackBits |= 1; 51 callbackBits |= 1;
48 nextStep(); 52 nextStep();
49 }, onError: (e, s) { 53 }, onError: (e, s) {
50 Expect.identical(zone, Zone.current, name); 54 Expect.identical(zone, Zone.current, name);
51 Expect.equals("ERROR", e, name); 55 Expect.equals("ERROR", e, name);
52 callbackBits |= 2; 56 callbackBits |= 2;
53 nextStep(); 57 nextStep();
54 }, onDone: () { 58 }, onDone: () {
55 Expect.identical(zone, Zone.current, name); 59 Expect.identical(zone, Zone.current, name);
56 if (overrideDone) throw "RUNNING WRONG ONDONE"; 60 if (overrideDone) throw "RUNNING WRONG ONDONE";
57 callbackBits |= 4; 61 callbackBits |= 4;
58 nextStep(); 62 nextStep();
59 }); 63 });
60 registerExpect += 3; 64 registerExpect += 3;
61 Expect.equals(registerExpect, registerCount, name); 65 Expect.equals(registerExpect, registerCount, name);
62 }, zoneSpecification: new ZoneSpecification( 66 },
63 registerCallback: (self, p, z, callback()) { 67 zoneSpecification:
64 Expect.identical(zone, self, name); 68 new ZoneSpecification(registerCallback: (self, p, z, callback()) {
65 registerCount++; 69 Expect.identical(zone, self, name);
66 return () { 70 registerCount++;
67 Expect.identical(zone, Zone.current, name); 71 return () {
68 callback(); 72 Expect.identical(zone, Zone.current, name);
69 }; 73 callback();
70 }, 74 };
71 registerUnaryCallback: (self, p, z, callback(a)) { 75 }, registerUnaryCallback: (self, p, z, callback(a)) {
72 Expect.identical(zone, self, name); 76 Expect.identical(zone, self, name);
73 registerCount++; 77 registerCount++;
74 return (a) { 78 return (a) {
75 Expect.identical(zone, Zone.current, name); 79 Expect.identical(zone, Zone.current, name);
76 callback(a); 80 callback(a);
77 }; 81 };
78 }, 82 }, registerBinaryCallback: (self, package, z, callback(a, b)) {
79 registerBinaryCallback: (self, package, z, callback(a, b)) { 83 Expect.identical(zone, self, name);
80 Expect.identical(zone, self, name); 84 registerCount++;
81 registerCount++; 85 return (a, b) {
82 return (a, b) { 86 Expect.identical(zone, Zone.current, name);
83 Expect.identical(zone, Zone.current, name); 87 callback(a, b);
84 callback(a, b); 88 };
85 }; 89 }));
86 }
87 ));
88 90
89 int expectedBits = 0; 91 int expectedBits = 0;
90 step = () { 92 step = () {
91 var stepName = "$name-$stepCount"; 93 var stepName = "$name-$stepCount";
92 Expect.identical(Zone.ROOT, Zone.current, stepName); 94 Expect.identical(Zone.ROOT, Zone.current, stepName);
93 Expect.equals(expectedBits, callbackBits, stepName); 95 Expect.equals(expectedBits, callbackBits, stepName);
94 switch (stepCount++) { 96 switch (stepCount++) {
95 case 0: 97 case 0:
96 expectedBits |= 1; 98 expectedBits |= 1;
97 controller.add(42); 99 controller.add(42);
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 } 141 }
140 Expect.equals(registerExpect, registerCount, stepName); 142 Expect.equals(registerExpect, registerCount, stepName);
141 controller.close(); 143 controller.close();
142 break; 144 break;
143 case 5: 145 case 5:
144 asyncEnd(); 146 asyncEnd();
145 } 147 }
146 }; 148 };
147 step(); 149 step();
148 } 150 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698