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

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

Issue 16240008: Make StreamController be a StreamSink, not just an EventSink. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Complete rewrite. StreamController is now itself a StreamSink. Created 7 years, 5 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
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 "package:expect/expect.dart"; 8 import "package:expect/expect.dart";
9 import 'dart:async'; 9 import 'dart:async';
10 import 'event_helper.dart'; 10 import 'event_helper.dart';
11 11
12 testMultiController() { 12 void testMultiController() {
13 // Test normal flow. 13 // Test normal flow.
14 var c = new StreamController(sync: true); 14 var c = new StreamController(sync: true);
15 Events expectedEvents = new Events() 15 Events expectedEvents = new Events()
16 ..add(42) 16 ..add(42)
17 ..add("dibs") 17 ..add("dibs")
18 ..error("error!") 18 ..error("error!")
19 ..error("error too!") 19 ..error("error too!")
20 ..close(); 20 ..close();
21 Events actualEvents = new Events.capture(c.stream.asBroadcastStream()); 21 Events actualEvents = new Events.capture(c.stream.asBroadcastStream());
22 expectedEvents.replay(c); 22 expectedEvents.replay(c);
(...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after
401 sentEvents = new Events() 401 sentEvents = new Events()
402 ..add(5)..add(6)..add(4)..add(6)..add(8)..add(3)..add(4)..add(1)..close(); 402 ..add(5)..add(6)..add(4)..add(6)..add(8)..add(3)..add(4)..add(1)..close();
403 expectedEvents = new Events() 403 expectedEvents = new Events()
404 ..add(5)..add(4)..add(3)..add(1)..close(); 404 ..add(5)..add(4)..add(3)..add(1)..close();
405 // Use 'distinct' as a filter with access to the previously emitted event. 405 // Use 'distinct' as a filter with access to the previously emitted event.
406 actualEvents = new Events.capture(c.stream.distinct((a, b) => a < b)); 406 actualEvents = new Events.capture(c.stream.distinct((a, b) => a < b));
407 sentEvents.replay(c); 407 sentEvents.replay(c);
408 Expect.listEquals(expectedEvents.events, actualEvents.events); 408 Expect.listEquals(expectedEvents.events, actualEvents.events);
409 } 409 }
410 410
411 testClosed() { 411 void testClosed() {
412 StreamController c = new StreamController(sync: true); 412 StreamController c = new StreamController(sync: true);
413 Expect.isFalse(c.isClosed); 413 Expect.isFalse(c.isClosed);
414 c.add(42); 414 c.add(42);
415 Expect.isFalse(c.isClosed); 415 Expect.isFalse(c.isClosed);
416 c.addError("bad"); 416 c.addError("bad");
417 Expect.isFalse(c.isClosed); 417 Expect.isFalse(c.isClosed);
418 c.close(); 418 c.close();
419 Expect.isTrue(c.isClosed); 419 Expect.isTrue(c.isClosed);
420 } 420 }
421 421
422 main() { 422 main() {
423 testMultiController(); 423 testMultiController();
424 testSingleController(); 424 testSingleController();
425 testExtraMethods(); 425 testExtraMethods();
426 testClosed(); 426 testClosed();
427 } 427 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698