OLD | NEW |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 // Test the basic StreamController and StreamController.singleSubscription. | 5 // Test the basic StreamController and StreamController.singleSubscription. |
6 library stream_controller_test; | 6 library stream_controller_test; |
7 | 7 |
8 import 'dart:async'; | 8 import 'dart:async'; |
9 import 'event_helper.dart'; | 9 import 'event_helper.dart'; |
10 | 10 |
11 testMultiController() { | 11 testMultiController() { |
12 // Test normal flow. | 12 // Test normal flow. |
13 var c = new StreamController.multiSubscription(); | 13 var c = new StreamController.broadcast(); |
14 Events expectedEvents = new Events() | 14 Events expectedEvents = new Events() |
15 ..add(42) | 15 ..add(42) |
16 ..add("dibs") | 16 ..add("dibs") |
17 ..error("error!") | 17 ..error("error!") |
18 ..error("error too!") | 18 ..error("error too!") |
19 ..close(); | 19 ..close(); |
20 Events actualEvents = new Events.capture(c); | 20 Events actualEvents = new Events.capture(c.stream); |
21 expectedEvents.replay(c); | 21 expectedEvents.replay(c); |
22 Expect.listEquals(expectedEvents.events, actualEvents.events); | 22 Expect.listEquals(expectedEvents.events, actualEvents.events); |
23 | 23 |
24 // Test automatic unsubscription on error. | 24 // Test automatic unsubscription on error. |
25 c = new StreamController.multiSubscription(); | 25 c = new StreamController.broadcast(); |
26 expectedEvents = new Events()..add(42)..error("error"); | 26 expectedEvents = new Events()..add(42)..error("error"); |
27 actualEvents = new Events.capture(c, unsubscribeOnError: true); | 27 actualEvents = new Events.capture(c.stream, unsubscribeOnError: true); |
28 Events sentEvents = | 28 Events sentEvents = |
29 new Events()..add(42)..error("error")..add("Are you there?"); | 29 new Events()..add(42)..error("error")..add("Are you there?"); |
30 sentEvents.replay(c); | 30 sentEvents.replay(c); |
31 Expect.listEquals(expectedEvents.events, actualEvents.events); | 31 Expect.listEquals(expectedEvents.events, actualEvents.events); |
32 | 32 |
33 // Test manual unsubscription. | 33 // Test manual unsubscription. |
34 c = new StreamController.multiSubscription(); | 34 c = new StreamController.broadcast(); |
35 expectedEvents = new Events()..add(42)..error("error")..add(37); | 35 expectedEvents = new Events()..add(42)..error("error")..add(37); |
36 actualEvents = new Events.capture(c, unsubscribeOnError: false); | 36 actualEvents = new Events.capture(c.stream, unsubscribeOnError: false); |
37 expectedEvents.replay(c); | 37 expectedEvents.replay(c); |
38 actualEvents.subscription.cancel(); | 38 actualEvents.subscription.cancel(); |
39 c.add("Are you there"); // Not sent to actualEvents. | 39 c.add("Are you there"); // Not sent to actualEvents. |
40 Expect.listEquals(expectedEvents.events, actualEvents.events); | 40 Expect.listEquals(expectedEvents.events, actualEvents.events); |
41 | 41 |
42 // Test filter. | 42 // Test filter. |
43 c = new StreamController.multiSubscription(); | 43 c = new StreamController.broadcast(); |
44 expectedEvents = new Events() | 44 expectedEvents = new Events() |
45 ..add("a string")..add("another string")..close(); | 45 ..add("a string")..add("another string")..close(); |
46 sentEvents = new Events() | 46 sentEvents = new Events() |
47 ..add("a string")..add(42)..add("another string")..close(); | 47 ..add("a string")..add(42)..add("another string")..close(); |
48 actualEvents = new Events.capture(c.where((v) => v is String)); | 48 actualEvents = new Events.capture(c.stream.where((v) => v is String)); |
49 sentEvents.replay(c); | 49 sentEvents.replay(c); |
50 Expect.listEquals(expectedEvents.events, actualEvents.events); | 50 Expect.listEquals(expectedEvents.events, actualEvents.events); |
51 | 51 |
52 // Test map. | 52 // Test map. |
53 c = new StreamController.multiSubscription(); | 53 c = new StreamController.broadcast(); |
54 expectedEvents = new Events()..add("abab")..error("error")..close(); | 54 expectedEvents = new Events()..add("abab")..error("error")..close(); |
55 sentEvents = new Events()..add("ab")..error("error")..close(); | 55 sentEvents = new Events()..add("ab")..error("error")..close(); |
56 actualEvents = new Events.capture(c.mappedBy((v) => "$v$v")); | 56 actualEvents = new Events.capture(c.stream.mappedBy((v) => "$v$v")); |
57 sentEvents.replay(c); | 57 sentEvents.replay(c); |
58 Expect.listEquals(expectedEvents.events, actualEvents.events); | 58 Expect.listEquals(expectedEvents.events, actualEvents.events); |
59 | 59 |
60 // Test handleError. | 60 // Test handleError. |
61 c = new StreamController.multiSubscription(); | 61 c = new StreamController.broadcast(); |
62 expectedEvents = new Events()..add("ab")..error("[foo]"); | 62 expectedEvents = new Events()..add("ab")..error("[foo]"); |
63 sentEvents = new Events()..add("ab")..error("foo")..add("ab")..close(); | 63 sentEvents = new Events()..add("ab")..error("foo")..add("ab")..close(); |
64 actualEvents = new Events.capture(c.handleError((v) { | 64 actualEvents = new Events.capture(c.stream.handleError((v) { |
65 if (v.error is String) { | 65 if (v.error is String) { |
66 throw new AsyncError("[${v.error}]", | 66 throw new AsyncError("[${v.error}]", |
67 "other stack"); | 67 "other stack"); |
68 } | 68 } |
69 }), unsubscribeOnError: true); | 69 }), unsubscribeOnError: true); |
70 sentEvents.replay(c); | 70 sentEvents.replay(c); |
71 Expect.listEquals(expectedEvents.events, actualEvents.events); | 71 Expect.listEquals(expectedEvents.events, actualEvents.events); |
72 | 72 |
73 // reduce is tested asynchronously and therefore not in this file. | 73 // reduce is tested asynchronously and therefore not in this file. |
74 | 74 |
75 // Test expand | 75 // Test expand |
76 c = new StreamController.multiSubscription(); | 76 c = new StreamController.broadcast(); |
77 sentEvents = new Events()..add(3)..add(2)..add(4)..close(); | 77 sentEvents = new Events()..add(3)..add(2)..add(4)..close(); |
78 expectedEvents = new Events()..add(1)..add(2)..add(3) | 78 expectedEvents = new Events()..add(1)..add(2)..add(3) |
79 ..add(1)..add(2) | 79 ..add(1)..add(2) |
80 ..add(1)..add(2)..add(3)..add(4) | 80 ..add(1)..add(2)..add(3)..add(4) |
81 ..close(); | 81 ..close(); |
82 actualEvents = new Events.capture(c.expand((v) { | 82 actualEvents = new Events.capture(c.stream.expand((v) { |
83 var l = []; | 83 var l = []; |
84 for (int i = 0; i < v; i++) l.add(i + 1); | 84 for (int i = 0; i < v; i++) l.add(i + 1); |
85 return l; | 85 return l; |
86 })); | 86 })); |
87 sentEvents.replay(c); | 87 sentEvents.replay(c); |
88 Expect.listEquals(expectedEvents.events, actualEvents.events); | 88 Expect.listEquals(expectedEvents.events, actualEvents.events); |
89 | 89 |
90 // Test transform. | 90 // Test transform. |
91 c = new StreamController.multiSubscription(); | 91 c = new StreamController.broadcast(); |
92 sentEvents = new Events()..add("a")..error(42)..add("b")..close(); | 92 sentEvents = new Events()..add("a")..error(42)..add("b")..close(); |
93 expectedEvents = | 93 expectedEvents = |
94 new Events()..error("a")..add(42)..error("b")..add("foo")..close(); | 94 new Events()..error("a")..add(42)..error("b")..add("foo")..close(); |
95 actualEvents = new Events.capture(c.transform(new StreamTransformer.from( | 95 actualEvents = new Events.capture(c.stream.transform( |
96 onData: (v, s) { s.signalError(new AsyncError(v)); }, | 96 new StreamTransformer.from( |
97 onError: (e, s) { s.add(e.error); }, | 97 onData: (v, s) { s.signalError(new AsyncError(v)); }, |
98 onDone: (s) { | 98 onError: (e, s) { s.add(e.error); }, |
99 s.add("foo"); | 99 onDone: (s) { |
100 s.close(); | 100 s.add("foo"); |
101 }))); | 101 s.close(); |
| 102 }))); |
102 sentEvents.replay(c); | 103 sentEvents.replay(c); |
103 Expect.listEquals(expectedEvents.events, actualEvents.events); | 104 Expect.listEquals(expectedEvents.events, actualEvents.events); |
104 | 105 |
105 // Test multiple filters. | 106 // Test multiple filters. |
106 c = new StreamController.multiSubscription(); | 107 c = new StreamController.broadcast(); |
107 sentEvents = new Events()..add(42) | 108 sentEvents = new Events()..add(42) |
108 ..add("snugglefluffy") | 109 ..add("snugglefluffy") |
109 ..add(7) | 110 ..add(7) |
110 ..add("42") | 111 ..add("42") |
111 ..error("not FormatException") // Unsubscribes. | 112 ..error("not FormatException") // Unsubscribes. |
112 ..close(); | 113 ..close(); |
113 expectedEvents = new Events()..add(42)..error("not FormatException"); | 114 expectedEvents = new Events()..add(42)..error("not FormatException"); |
114 actualEvents = new Events.capture( | 115 actualEvents = new Events.capture( |
115 c.where((v) => v is String) | 116 c.stream.where((v) => v is String) |
116 .mappedBy((v) => int.parse(v)) | 117 .mappedBy((v) => int.parse(v)) |
117 .handleError((v) { | 118 .handleError((v) { |
118 if (v.error is! FormatException) throw v; | 119 if (v.error is! FormatException) throw v; |
119 }) | 120 }) |
120 .where((v) => v > 10), | 121 .where((v) => v > 10), |
121 unsubscribeOnError: true); | 122 unsubscribeOnError: true); |
122 sentEvents.replay(c); | 123 sentEvents.replay(c); |
123 Expect.listEquals(expectedEvents.events, actualEvents.events); | 124 Expect.listEquals(expectedEvents.events, actualEvents.events); |
124 | 125 |
125 // Test subscription changes while firing. | 126 // Test subscription changes while firing. |
126 c = new StreamController.multiSubscription(); | 127 c = new StreamController.broadcast(); |
127 var sink = c.sink; | 128 var sink = c.sink; |
128 var stream = c.stream; | 129 var stream = c.stream; |
129 var counter = 0; | 130 var counter = 0; |
130 var subscription = stream.listen(null); | 131 var subscription = stream.listen(null); |
131 subscription.onData((data) { | 132 subscription.onData((data) { |
132 counter += data; | 133 counter += data; |
133 subscription.cancel(); | 134 subscription.cancel(); |
134 stream.listen((data) { | 135 stream.listen((data) { |
135 counter += 10 * data; | 136 counter += 10 * data; |
136 }); | 137 }); |
(...skipping 13 matching lines...) Expand all Loading... |
150 | 151 |
151 testSingleController() { | 152 testSingleController() { |
152 // Test normal flow. | 153 // Test normal flow. |
153 var c = new StreamController(); | 154 var c = new StreamController(); |
154 Events expectedEvents = new Events() | 155 Events expectedEvents = new Events() |
155 ..add(42) | 156 ..add(42) |
156 ..add("dibs") | 157 ..add("dibs") |
157 ..error("error!") | 158 ..error("error!") |
158 ..error("error too!") | 159 ..error("error too!") |
159 ..close(); | 160 ..close(); |
160 Events actualEvents = new Events.capture(c); | 161 Events actualEvents = new Events.capture(c.stream); |
161 expectedEvents.replay(c); | 162 expectedEvents.replay(c); |
162 Expect.listEquals(expectedEvents.events, actualEvents.events); | 163 Expect.listEquals(expectedEvents.events, actualEvents.events); |
163 | 164 |
164 // Test automatic unsubscription on error. | 165 // Test automatic unsubscription on error. |
165 c = new StreamController(); | 166 c = new StreamController(); |
166 expectedEvents = new Events()..add(42)..error("error"); | 167 expectedEvents = new Events()..add(42)..error("error"); |
167 actualEvents = new Events.capture(c, unsubscribeOnError: true); | 168 actualEvents = new Events.capture(c.stream, unsubscribeOnError: true); |
168 Events sentEvents = | 169 Events sentEvents = |
169 new Events()..add(42)..error("error")..add("Are you there?"); | 170 new Events()..add(42)..error("error")..add("Are you there?"); |
170 sentEvents.replay(c); | 171 sentEvents.replay(c); |
171 Expect.listEquals(expectedEvents.events, actualEvents.events); | 172 Expect.listEquals(expectedEvents.events, actualEvents.events); |
172 | 173 |
173 // Test manual unsubscription. | 174 // Test manual unsubscription. |
174 c = new StreamController(); | 175 c = new StreamController(); |
175 expectedEvents = new Events()..add(42)..error("error")..add(37); | 176 expectedEvents = new Events()..add(42)..error("error")..add(37); |
176 actualEvents = new Events.capture(c, unsubscribeOnError: false); | 177 actualEvents = new Events.capture(c.stream, unsubscribeOnError: false); |
177 expectedEvents.replay(c); | 178 expectedEvents.replay(c); |
178 actualEvents.subscription.cancel(); | 179 actualEvents.subscription.cancel(); |
179 c.add("Are you there"); // Not sent to actualEvents. | 180 c.add("Are you there"); // Not sent to actualEvents. |
180 Expect.listEquals(expectedEvents.events, actualEvents.events); | 181 Expect.listEquals(expectedEvents.events, actualEvents.events); |
181 | 182 |
182 // Test filter. | 183 // Test filter. |
183 c = new StreamController(); | 184 c = new StreamController(); |
184 expectedEvents = new Events() | 185 expectedEvents = new Events() |
185 ..add("a string")..add("another string")..close(); | 186 ..add("a string")..add("another string")..close(); |
186 sentEvents = new Events() | 187 sentEvents = new Events() |
187 ..add("a string")..add(42)..add("another string")..close(); | 188 ..add("a string")..add(42)..add("another string")..close(); |
188 actualEvents = new Events.capture(c.where((v) => v is String)); | 189 actualEvents = new Events.capture(c.stream.where((v) => v is String)); |
189 sentEvents.replay(c); | 190 sentEvents.replay(c); |
190 Expect.listEquals(expectedEvents.events, actualEvents.events); | 191 Expect.listEquals(expectedEvents.events, actualEvents.events); |
191 | 192 |
192 // Test map. | 193 // Test map. |
193 c = new StreamController(); | 194 c = new StreamController(); |
194 expectedEvents = new Events()..add("abab")..error("error")..close(); | 195 expectedEvents = new Events()..add("abab")..error("error")..close(); |
195 sentEvents = new Events()..add("ab")..error("error")..close(); | 196 sentEvents = new Events()..add("ab")..error("error")..close(); |
196 actualEvents = new Events.capture(c.mappedBy((v) => "$v$v")); | 197 actualEvents = new Events.capture(c.stream.mappedBy((v) => "$v$v")); |
197 sentEvents.replay(c); | 198 sentEvents.replay(c); |
198 Expect.listEquals(expectedEvents.events, actualEvents.events); | 199 Expect.listEquals(expectedEvents.events, actualEvents.events); |
199 | 200 |
200 // Test handleError. | 201 // Test handleError. |
201 c = new StreamController(); | 202 c = new StreamController(); |
202 expectedEvents = new Events()..add("ab")..error("[foo]"); | 203 expectedEvents = new Events()..add("ab")..error("[foo]"); |
203 sentEvents = new Events()..add("ab")..error("foo")..add("ab")..close(); | 204 sentEvents = new Events()..add("ab")..error("foo")..add("ab")..close(); |
204 actualEvents = new Events.capture(c.handleError((v) { | 205 actualEvents = new Events.capture(c.stream.handleError((v) { |
205 if (v.error is String) { | 206 if (v.error is String) { |
206 throw new AsyncError("[${v.error}]", | 207 throw new AsyncError("[${v.error}]", |
207 "other stack"); | 208 "other stack"); |
208 } | 209 } |
209 }), unsubscribeOnError: true); | 210 }), unsubscribeOnError: true); |
210 sentEvents.replay(c); | 211 sentEvents.replay(c); |
211 Expect.listEquals(expectedEvents.events, actualEvents.events); | 212 Expect.listEquals(expectedEvents.events, actualEvents.events); |
212 | 213 |
213 // reduce is tested asynchronously and therefore not in this file. | 214 // reduce is tested asynchronously and therefore not in this file. |
214 | 215 |
215 // Test expand | 216 // Test expand |
216 c = new StreamController(); | 217 c = new StreamController(); |
217 sentEvents = new Events()..add(3)..add(2)..add(4)..close(); | 218 sentEvents = new Events()..add(3)..add(2)..add(4)..close(); |
218 expectedEvents = new Events()..add(1)..add(2)..add(3) | 219 expectedEvents = new Events()..add(1)..add(2)..add(3) |
219 ..add(1)..add(2) | 220 ..add(1)..add(2) |
220 ..add(1)..add(2)..add(3)..add(4) | 221 ..add(1)..add(2)..add(3)..add(4) |
221 ..close(); | 222 ..close(); |
222 actualEvents = new Events.capture(c.expand((v) { | 223 actualEvents = new Events.capture(c.stream.expand((v) { |
223 var l = []; | 224 var l = []; |
224 for (int i = 0; i < v; i++) l.add(i + 1); | 225 for (int i = 0; i < v; i++) l.add(i + 1); |
225 return l; | 226 return l; |
226 })); | 227 })); |
227 sentEvents.replay(c); | 228 sentEvents.replay(c); |
228 Expect.listEquals(expectedEvents.events, actualEvents.events); | 229 Expect.listEquals(expectedEvents.events, actualEvents.events); |
229 | 230 |
230 // pipe is tested asynchronously and therefore not in this file. | 231 // pipe is tested asynchronously and therefore not in this file. |
231 c = new StreamController(); | 232 c = new StreamController(); |
232 var list = <int>[]; | 233 var list = <int>[]; |
233 c.pipeInto(new CollectionSink<int>(list)) | 234 c.stream.pipeInto(new CollectionSink<int>(list)) |
234 .whenComplete(() { Expect.listEquals(<int>[1,2,9,3,9], list); }); | 235 .whenComplete(() { Expect.listEquals(<int>[1,2,9,3,9], list); }); |
235 c.add(1); | 236 c.add(1); |
236 c.add(2); | 237 c.add(2); |
237 c.add(9); | 238 c.add(9); |
238 c.add(3); | 239 c.add(3); |
239 c.add(9); | 240 c.add(9); |
240 c.close(); | 241 c.close(); |
241 | 242 |
242 // Test transform. | 243 // Test transform. |
243 c = new StreamController(); | 244 c = new StreamController(); |
244 sentEvents = new Events()..add("a")..error(42)..add("b")..close(); | 245 sentEvents = new Events()..add("a")..error(42)..add("b")..close(); |
245 expectedEvents = | 246 expectedEvents = |
246 new Events()..error("a")..add(42)..error("b")..add("foo")..close(); | 247 new Events()..error("a")..add(42)..error("b")..add("foo")..close(); |
247 actualEvents = new Events.capture(c.transform(new StreamTransformer.from( | 248 actualEvents = new Events.capture(c.stream.transform( |
248 onData: (v, s) { s.signalError(new AsyncError(v)); }, | 249 new StreamTransformer.from( |
249 onError: (e, s) { s.add(e.error); }, | 250 onData: (v, s) { s.signalError(new AsyncError(v)); }, |
250 onDone: (s) { | 251 onError: (e, s) { s.add(e.error); }, |
251 s.add("foo"); | 252 onDone: (s) { |
252 s.close(); | 253 s.add("foo"); |
253 }))); | 254 s.close(); |
| 255 }))); |
254 sentEvents.replay(c); | 256 sentEvents.replay(c); |
255 Expect.listEquals(expectedEvents.events, actualEvents.events); | 257 Expect.listEquals(expectedEvents.events, actualEvents.events); |
256 | 258 |
257 // Test multiple filters. | 259 // Test multiple filters. |
258 c = new StreamController(); | 260 c = new StreamController(); |
259 sentEvents = new Events()..add(42) | 261 sentEvents = new Events()..add(42) |
260 ..add("snugglefluffy") | 262 ..add("snugglefluffy") |
261 ..add(7) | 263 ..add(7) |
262 ..add("42") | 264 ..add("42") |
263 ..error("not FormatException") // Unsubscribes. | 265 ..error("not FormatException") // Unsubscribes. |
264 ..close(); | 266 ..close(); |
265 expectedEvents = new Events()..add(42)..error("not FormatException"); | 267 expectedEvents = new Events()..add(42)..error("not FormatException"); |
266 actualEvents = new Events.capture( | 268 actualEvents = new Events.capture( |
267 c.where((v) => v is String) | 269 c.stream.where((v) => v is String) |
268 .mappedBy((v) => int.parse(v)) | 270 .mappedBy((v) => int.parse(v)) |
269 .handleError((v) { | 271 .handleError((v) { |
270 if (v.error is! FormatException) throw v; | 272 if (v.error is! FormatException) throw v; |
271 }) | 273 }) |
272 .where((v) => v > 10), | 274 .where((v) => v > 10), |
273 unsubscribeOnError: true); | 275 unsubscribeOnError: true); |
274 sentEvents.replay(c); | 276 sentEvents.replay(c); |
275 Expect.listEquals(expectedEvents.events, actualEvents.events); | 277 Expect.listEquals(expectedEvents.events, actualEvents.events); |
276 | 278 |
277 // Test that only one subscription is allowed. | 279 // Test that only one subscription is allowed. |
278 c = new StreamController(); | 280 c = new StreamController(); |
279 var sink = c.sink; | 281 var sink = c.sink; |
280 var stream = c.stream; | 282 var stream = c.stream; |
281 var counter = 0; | 283 var counter = 0; |
282 var subscription = stream.listen((data) { counter += data; }); | 284 var subscription = stream.listen((data) { counter += data; }); |
283 Expect.throws(() => stream.listen(null), (e) => e is StateError); | 285 Expect.throws(() => stream.listen(null), (e) => e is StateError); |
284 sink.add(1); | 286 sink.add(1); |
285 Expect.equals(1, counter); | 287 Expect.equals(1, counter); |
286 c.close(); | 288 c.close(); |
287 } | 289 } |
288 | 290 |
289 testExtraMethods() { | 291 testExtraMethods() { |
290 Events sentEvents = new Events()..add(1)..add(2)..add(3)..close(); | 292 Events sentEvents = new Events()..add(1)..add(2)..add(3)..close(); |
291 | 293 |
292 var c = new StreamController(); | 294 var c = new StreamController(); |
293 Events expectedEvents = new Events()..add(3)..close(); | 295 Events expectedEvents = new Events()..add(3)..close(); |
294 Events actualEvents = new Events.capture(c.skip(2)); | 296 Events actualEvents = new Events.capture(c.stream.skip(2)); |
295 sentEvents.replay(c); | 297 sentEvents.replay(c); |
296 Expect.listEquals(expectedEvents.events, actualEvents.events); | 298 Expect.listEquals(expectedEvents.events, actualEvents.events); |
297 | 299 |
298 c = new StreamController(); | 300 c = new StreamController(); |
299 expectedEvents = new Events()..close(); | 301 expectedEvents = new Events()..close(); |
300 actualEvents = new Events.capture(c.skip(3)); | 302 actualEvents = new Events.capture(c.stream.skip(3)); |
301 sentEvents.replay(c); | 303 sentEvents.replay(c); |
302 Expect.listEquals(expectedEvents.events, actualEvents.events); | 304 Expect.listEquals(expectedEvents.events, actualEvents.events); |
303 | 305 |
304 c = new StreamController(); | 306 c = new StreamController(); |
305 expectedEvents = new Events()..close(); | 307 expectedEvents = new Events()..close(); |
306 actualEvents = new Events.capture(c.skip(7)); | 308 actualEvents = new Events.capture(c.stream.skip(7)); |
307 sentEvents.replay(c); | 309 sentEvents.replay(c); |
308 Expect.listEquals(expectedEvents.events, actualEvents.events); | 310 Expect.listEquals(expectedEvents.events, actualEvents.events); |
309 | 311 |
310 c = new StreamController(); | 312 c = new StreamController(); |
311 expectedEvents = sentEvents; | 313 expectedEvents = sentEvents; |
312 actualEvents = new Events.capture(c.skip(0)); | 314 actualEvents = new Events.capture(c.stream.skip(0)); |
313 sentEvents.replay(c); | 315 sentEvents.replay(c); |
314 Expect.listEquals(expectedEvents.events, actualEvents.events); | 316 Expect.listEquals(expectedEvents.events, actualEvents.events); |
315 | 317 |
316 | 318 |
317 c = new StreamController(); | 319 c = new StreamController(); |
318 expectedEvents = new Events()..add(3)..close(); | 320 expectedEvents = new Events()..add(3)..close(); |
319 actualEvents = new Events.capture(c.skipWhile((x) => x <= 2)); | 321 actualEvents = new Events.capture(c.stream.skipWhile((x) => x <= 2)); |
320 sentEvents.replay(c); | 322 sentEvents.replay(c); |
321 Expect.listEquals(expectedEvents.events, actualEvents.events); | 323 Expect.listEquals(expectedEvents.events, actualEvents.events); |
322 | 324 |
323 | 325 |
324 c = new StreamController(); | 326 c = new StreamController(); |
325 expectedEvents = new Events()..add(1)..add(2)..close(); | 327 expectedEvents = new Events()..add(1)..add(2)..close(); |
326 actualEvents = new Events.capture(c.take(2)); | 328 actualEvents = new Events.capture(c.stream.take(2)); |
327 sentEvents.replay(c); | 329 sentEvents.replay(c); |
328 Expect.listEquals(expectedEvents.events, actualEvents.events); | 330 Expect.listEquals(expectedEvents.events, actualEvents.events); |
329 | 331 |
330 | 332 |
331 c = new StreamController(); | 333 c = new StreamController(); |
332 expectedEvents = new Events()..add(1)..add(2)..close(); | 334 expectedEvents = new Events()..add(1)..add(2)..close(); |
333 actualEvents = new Events.capture(c.takeWhile((x) => x <= 2)); | 335 actualEvents = new Events.capture(c.stream.takeWhile((x) => x <= 2)); |
334 sentEvents.replay(c); | 336 sentEvents.replay(c); |
335 Expect.listEquals(expectedEvents.events, actualEvents.events); | 337 Expect.listEquals(expectedEvents.events, actualEvents.events); |
336 | 338 |
337 c = new StreamController(); | 339 c = new StreamController(); |
338 sentEvents = new Events() | 340 sentEvents = new Events() |
339 ..add(1)..add(1)..add(2)..add(1)..add(2)..add(2)..add(2)..close(); | 341 ..add(1)..add(1)..add(2)..add(1)..add(2)..add(2)..add(2)..close(); |
340 expectedEvents = new Events() | 342 expectedEvents = new Events() |
341 ..add(1)..add(2)..add(1)..add(2)..close(); | 343 ..add(1)..add(2)..add(1)..add(2)..close(); |
342 actualEvents = new Events.capture(c.distinct()); | 344 actualEvents = new Events.capture(c.stream.distinct()); |
343 sentEvents.replay(c); | 345 sentEvents.replay(c); |
344 Expect.listEquals(expectedEvents.events, actualEvents.events); | 346 Expect.listEquals(expectedEvents.events, actualEvents.events); |
345 | 347 |
346 c = new StreamController(); | 348 c = new StreamController(); |
347 sentEvents = new Events() | 349 sentEvents = new Events() |
348 ..add(5)..add(6)..add(4)..add(6)..add(8)..add(3)..add(4)..add(1)..close(); | 350 ..add(5)..add(6)..add(4)..add(6)..add(8)..add(3)..add(4)..add(1)..close(); |
349 expectedEvents = new Events() | 351 expectedEvents = new Events() |
350 ..add(5)..add(4)..add(3)..add(1)..close(); | 352 ..add(5)..add(4)..add(3)..add(1)..close(); |
351 // Use 'distinct' as a filter with access to the previously emitted event. | 353 // Use 'distinct' as a filter with access to the previously emitted event. |
352 actualEvents = new Events.capture(c.distinct((a, b) => a < b)); | 354 actualEvents = new Events.capture(c.stream.distinct((a, b) => a < b)); |
353 sentEvents.replay(c); | 355 sentEvents.replay(c); |
354 Expect.listEquals(expectedEvents.events, actualEvents.events); | 356 Expect.listEquals(expectedEvents.events, actualEvents.events); |
355 } | 357 } |
356 | 358 |
357 main() { | 359 main() { |
358 testMultiController(); | 360 testMultiController(); |
359 testSingleController(); | 361 testSingleController(); |
360 testExtraMethods(); | 362 testExtraMethods(); |
361 } | 363 } |
OLD | NEW |