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

Side by Side Diff: tests/lib/async/stream_controller_test.dart

Issue 11953103: Add public-facing method and class that allows intercepting stream events. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address review comments Created 7 years, 10 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 | Annotate | Revision Log
« no previous file with comments | « sdk/lib/async/stream_pipe.dart ('k') | tests/lib/async/stream_event_transform_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 var list = <int>[]; 233 var list = <int>[];
234 c.stream.pipeInto(new CollectionSink<int>(list)) 234 c.stream.pipeInto(new CollectionSink<int>(list))
235 .whenComplete(() { Expect.listEquals(<int>[1,2,9,3,9], list); }); 235 .whenComplete(() { Expect.listEquals(<int>[1,2,9,3,9], list); });
236 c.add(1); 236 c.add(1);
237 c.add(2); 237 c.add(2);
238 c.add(9); 238 c.add(9);
239 c.add(3); 239 c.add(3);
240 c.add(9); 240 c.add(9);
241 c.close(); 241 c.close();
242 242
243 // test contains.
244 {
245 c = new StreamController();
246 // Error after match is not important.
247 sentEvents = new Events()..add("a")..add("x")..error("FAIL")..close();
248 Future<bool> contains = c.stream.contains("x");
249 contains.then((var c) {
250 Expect.isTrue(c);
251 });
252 sentEvents.replay(c);
253 }
254
255 {
256 c = new StreamController();
257 // Not matching is ok.
258 sentEvents = new Events()..add("a")..add("x")..add("b")..close();
259 Future<bool> contains = c.stream.contains("y");
260 contains.then((var c) {
261 Expect.isFalse(c);
262 });
263 sentEvents.replay(c);
264 }
265
266 {
267 c = new StreamController();
268 // Error before match makes future err.
269 sentEvents = new Events()..add("a")..error("FAIL")..add("b")..close();
270 Future<bool> contains = c.stream.contains("b");
271 contains.then((var c) {
272 Expect.fail("no value expected");
273 }).catchError((AsyncError e) {
274 Expect.equals("FAIL", e.error);
275 });
276 sentEvents.replay(c);
277 }
278
243 // Test transform. 279 // Test transform.
244 c = new StreamController(); 280 c = new StreamController();
245 sentEvents = new Events()..add("a")..error(42)..add("b")..close(); 281 sentEvents = new Events()..add("a")..error(42)..add("b")..close();
246 expectedEvents = 282 expectedEvents =
247 new Events()..error("a")..add(42)..error("b")..add("foo")..close(); 283 new Events()..error("a")..add(42)..error("b")..add("foo")..close();
248 actualEvents = new Events.capture(c.stream.transform( 284 actualEvents = new Events.capture(c.stream.transform(
249 new StreamTransformer.from( 285 new StreamTransformer.from(
250 onData: (v, s) { s.signalError(new AsyncError(v)); }, 286 onData: (v, s) { s.signalError(new AsyncError(v)); },
251 onError: (e, s) { s.add(e.error); }, 287 onError: (e, s) { s.add(e.error); },
252 onDone: (s) { 288 onDone: (s) {
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 actualEvents = new Events.capture(c.stream.distinct((a, b) => a < b)); 390 actualEvents = new Events.capture(c.stream.distinct((a, b) => a < b));
355 sentEvents.replay(c); 391 sentEvents.replay(c);
356 Expect.listEquals(expectedEvents.events, actualEvents.events); 392 Expect.listEquals(expectedEvents.events, actualEvents.events);
357 } 393 }
358 394
359 main() { 395 main() {
360 testMultiController(); 396 testMultiController();
361 testSingleController(); 397 testSingleController();
362 testExtraMethods(); 398 testExtraMethods();
363 } 399 }
OLDNEW
« no previous file with comments | « sdk/lib/async/stream_pipe.dart ('k') | tests/lib/async/stream_event_transform_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698