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 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 // Test transform. | 91 // Test transform. |
92 c = new StreamController.broadcast(); | 92 c = new StreamController.broadcast(); |
93 sentEvents = new Events()..add("a")..error(42)..add("b")..close(); | 93 sentEvents = new Events()..add("a")..error(42)..add("b")..close(); |
94 expectedEvents = | 94 expectedEvents = |
95 new Events()..error("a")..add(42)..error("b")..add("foo")..close(); | 95 new Events()..error("a")..add(42)..error("b")..add("foo")..close(); |
96 actualEvents = new Events.capture(c.stream.transform( | 96 actualEvents = new Events.capture(c.stream.transform( |
97 new StreamTransformer( | 97 new StreamTransformer( |
98 handleData: (v, s) { s.addError(new AsyncError(v)); }, | 98 handleData: (v, s) { s.addError(new AsyncError(v)); }, |
99 handleError: (e, s) { s.add(e.error); }, | 99 handleError: (e, s) { s.add(e.error); }, |
100 handleDone: (s) { | 100 handleDone: (s) { |
| 101 |
101 s.add("foo"); | 102 s.add("foo"); |
| 103 |
102 s.close(); | 104 s.close(); |
| 105 |
103 }))); | 106 }))); |
104 sentEvents.replay(c); | 107 sentEvents.replay(c); |
105 Expect.listEquals(expectedEvents.events, actualEvents.events); | 108 Expect.listEquals(expectedEvents.events, actualEvents.events); |
106 | 109 |
107 // Test multiple filters. | 110 // Test multiple filters. |
108 c = new StreamController.broadcast(); | 111 c = new StreamController.broadcast(); |
109 sentEvents = new Events()..add(42) | 112 sentEvents = new Events()..add(42) |
110 ..add("snugglefluffy") | 113 ..add("snugglefluffy") |
111 ..add(7) | 114 ..add(7) |
112 ..add("42") | 115 ..add("42") |
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
366 sentEvents.replay(c); | 369 sentEvents.replay(c); |
367 Expect.listEquals(expectedEvents.events, actualEvents.events); | 370 Expect.listEquals(expectedEvents.events, actualEvents.events); |
368 | 371 |
369 | 372 |
370 c = new StreamController(); | 373 c = new StreamController(); |
371 expectedEvents = new Events()..add(1)..add(2)..close(); | 374 expectedEvents = new Events()..add(1)..add(2)..close(); |
372 actualEvents = new Events.capture(c.stream.takeWhile((x) => x <= 2)); | 375 actualEvents = new Events.capture(c.stream.takeWhile((x) => x <= 2)); |
373 sentEvents.replay(c); | 376 sentEvents.replay(c); |
374 Expect.listEquals(expectedEvents.events, actualEvents.events); | 377 Expect.listEquals(expectedEvents.events, actualEvents.events); |
375 | 378 |
| 379 |
376 c = new StreamController(); | 380 c = new StreamController(); |
377 sentEvents = new Events() | 381 sentEvents = new Events() |
378 ..add(1)..add(1)..add(2)..add(1)..add(2)..add(2)..add(2)..close(); | 382 ..add(1)..add(1)..add(2)..add(1)..add(2)..add(2)..add(2)..close(); |
379 expectedEvents = new Events() | 383 expectedEvents = new Events() |
380 ..add(1)..add(2)..add(1)..add(2)..close(); | 384 ..add(1)..add(2)..add(1)..add(2)..close(); |
381 actualEvents = new Events.capture(c.stream.distinct()); | 385 actualEvents = new Events.capture(c.stream.distinct()); |
382 sentEvents.replay(c); | 386 sentEvents.replay(c); |
383 Expect.listEquals(expectedEvents.events, actualEvents.events); | 387 Expect.listEquals(expectedEvents.events, actualEvents.events); |
384 | 388 |
| 389 |
385 c = new StreamController(); | 390 c = new StreamController(); |
386 sentEvents = new Events() | 391 sentEvents = new Events() |
387 ..add(5)..add(6)..add(4)..add(6)..add(8)..add(3)..add(4)..add(1)..close(); | 392 ..add(5)..add(6)..add(4)..add(6)..add(8)..add(3)..add(4)..add(1)..close(); |
388 expectedEvents = new Events() | 393 expectedEvents = new Events() |
389 ..add(5)..add(4)..add(3)..add(1)..close(); | 394 ..add(5)..add(4)..add(3)..add(1)..close(); |
390 // Use 'distinct' as a filter with access to the previously emitted event. | 395 // Use 'distinct' as a filter with access to the previously emitted event. |
391 actualEvents = new Events.capture(c.stream.distinct((a, b) => a < b)); | 396 actualEvents = new Events.capture(c.stream.distinct((a, b) => a < b)); |
392 sentEvents.replay(c); | 397 sentEvents.replay(c); |
393 Expect.listEquals(expectedEvents.events, actualEvents.events); | 398 Expect.listEquals(expectedEvents.events, actualEvents.events); |
394 } | 399 } |
(...skipping 10 matching lines...) Expand all Loading... |
405 Expect.isTrue(c.isClosed); | 410 Expect.isTrue(c.isClosed); |
406 } | 411 } |
407 } | 412 } |
408 | 413 |
409 main() { | 414 main() { |
410 testMultiController(); | 415 testMultiController(); |
411 testSingleController(); | 416 testSingleController(); |
412 testExtraMethods(); | 417 testExtraMethods(); |
413 testClosed(); | 418 testClosed(); |
414 } | 419 } |
OLD | NEW |