| 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 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 225 ..add(1)..add(2)..add(3)..add(4) | 225 ..add(1)..add(2)..add(3)..add(4) |
| 226 ..close(); | 226 ..close(); |
| 227 actualEvents = new Events.capture(c.stream.expand((v) { | 227 actualEvents = new Events.capture(c.stream.expand((v) { |
| 228 var l = []; | 228 var l = []; |
| 229 for (int i = 0; i < v; i++) l.add(i + 1); | 229 for (int i = 0; i < v; i++) l.add(i + 1); |
| 230 return l; | 230 return l; |
| 231 })); | 231 })); |
| 232 sentEvents.replay(c); | 232 sentEvents.replay(c); |
| 233 Expect.listEquals(expectedEvents.events, actualEvents.events); | 233 Expect.listEquals(expectedEvents.events, actualEvents.events); |
| 234 | 234 |
| 235 // pipe is tested asynchronously and therefore not in this file. | |
| 236 c = new StreamController(); | |
| 237 var list = <int>[]; | |
| 238 c.stream.pipeInto(new CollectionSink<int>(list)) | |
| 239 .whenComplete(() { Expect.listEquals(<int>[1,2,9,3,9], list); }); | |
| 240 c.add(1); | |
| 241 c.add(2); | |
| 242 c.add(9); | |
| 243 c.add(3); | |
| 244 c.add(9); | |
| 245 c.close(); | |
| 246 | |
| 247 // test contains. | 235 // test contains. |
| 248 { | 236 { |
| 249 c = new StreamController(); | 237 c = new StreamController(); |
| 250 // Error after match is not important. | 238 // Error after match is not important. |
| 251 sentEvents = new Events()..add("a")..add("x")..error("FAIL")..close(); | 239 sentEvents = new Events()..add("a")..add("x")..error("FAIL")..close(); |
| 252 Future<bool> contains = c.stream.contains("x"); | 240 Future<bool> contains = c.stream.contains("x"); |
| 253 contains.then((var c) { | 241 contains.then((var c) { |
| 254 Expect.isTrue(c); | 242 Expect.isTrue(c); |
| 255 }); | 243 }); |
| 256 sentEvents.replay(c); | 244 sentEvents.replay(c); |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 410 Expect.isTrue(c.isClosed); | 398 Expect.isTrue(c.isClosed); |
| 411 } | 399 } |
| 412 } | 400 } |
| 413 | 401 |
| 414 main() { | 402 main() { |
| 415 testMultiController(); | 403 testMultiController(); |
| 416 testSingleController(); | 404 testSingleController(); |
| 417 testExtraMethods(); | 405 testExtraMethods(); |
| 418 testClosed(); | 406 testClosed(); |
| 419 } | 407 } |
| OLD | NEW |