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 "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'; |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 // Test transform. | 99 // Test transform. |
100 c = new StreamController(sync: true); | 100 c = new StreamController(sync: true); |
101 sentEvents = new Events()..add("a")..error(42)..add("b")..close(); | 101 sentEvents = new Events()..add("a")..error(42)..add("b")..close(); |
102 expectedEvents = | 102 expectedEvents = |
103 new Events()..error("a")..add(42)..error("b")..add("foo")..close(); | 103 new Events()..error("a")..add(42)..error("b")..add("foo")..close(); |
104 actualEvents = new Events.capture(c.stream.asBroadcastStream().transform( | 104 actualEvents = new Events.capture(c.stream.asBroadcastStream().transform( |
105 new StreamTransformer( | 105 new StreamTransformer( |
106 handleData: (v, s) { s.addError(v); }, | 106 handleData: (v, s) { s.addError(v); }, |
107 handleError: (e, s) { s.add(e); }, | 107 handleError: (e, s) { s.add(e); }, |
108 handleDone: (s) { | 108 handleDone: (s) { |
109 | |
110 s.add("foo"); | 109 s.add("foo"); |
111 | |
112 s.close(); | 110 s.close(); |
113 | |
114 }))); | 111 }))); |
115 sentEvents.replay(c); | 112 sentEvents.replay(c); |
116 Expect.listEquals(expectedEvents.events, actualEvents.events); | 113 Expect.listEquals(expectedEvents.events, actualEvents.events); |
117 | 114 |
118 // Test multiple filters. | 115 // Test multiple filters. |
119 c = new StreamController(sync: true); | 116 c = new StreamController(sync: true); |
120 sentEvents = new Events()..add(42) | 117 sentEvents = new Events()..add(42) |
121 ..add("snugglefluffy") | 118 ..add("snugglefluffy") |
122 ..add(7) | 119 ..add(7) |
123 ..add("42") | 120 ..add("42") |
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
418 c.close(); | 415 c.close(); |
419 Expect.isTrue(c.isClosed); | 416 Expect.isTrue(c.isClosed); |
420 } | 417 } |
421 | 418 |
422 main() { | 419 main() { |
423 testMultiController(); | 420 testMultiController(); |
424 testSingleController(); | 421 testSingleController(); |
425 testExtraMethods(); | 422 testExtraMethods(); |
426 testClosed(); | 423 testClosed(); |
427 } | 424 } |
OLD | NEW |