OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file |
| 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. |
| 4 |
| 5 import 'dart:async'; |
| 6 import 'dart:convert'; |
| 7 import 'dart:isolate'; |
| 8 |
| 9 import 'package:stream_channel/stream_channel.dart'; |
| 10 import 'package:test/test.dart'; |
| 11 |
| 12 import 'utils.dart'; |
| 13 |
| 14 void main() { |
| 15 var streamController; |
| 16 var sinkController; |
| 17 var channel; |
| 18 setUp(() { |
| 19 streamController = new StreamController(); |
| 20 sinkController = new StreamController(); |
| 21 channel = new StreamChannel( |
| 22 streamController.stream, sinkController.sink); |
| 23 }); |
| 24 |
| 25 test("pipe() pipes data from each channel's stream into the other's sink", |
| 26 () { |
| 27 var otherStreamController = new StreamController(); |
| 28 var otherSinkController = new StreamController(); |
| 29 var otherChannel = new StreamChannel( |
| 30 otherStreamController.stream, otherSinkController.sink); |
| 31 channel.pipe(otherChannel); |
| 32 |
| 33 streamController.add(1); |
| 34 streamController.add(2); |
| 35 streamController.add(3); |
| 36 streamController.close(); |
| 37 expect(otherSinkController.stream.toList(), completion(equals([1, 2, 3]))); |
| 38 |
| 39 otherStreamController.add(4); |
| 40 otherStreamController.add(5); |
| 41 otherStreamController.add(6); |
| 42 otherStreamController.close(); |
| 43 expect(sinkController.stream.toList(), completion(equals([4, 5, 6]))); |
| 44 }); |
| 45 |
| 46 test("transform() transforms the channel", () { |
| 47 var transformed = channel.transform(UTF8); |
| 48 |
| 49 streamController.add([102, 111, 111, 98, 97, 114]); |
| 50 streamController.close(); |
| 51 expect(transformed.stream.toList(), completion(equals(["foobar"]))); |
| 52 |
| 53 transformed.sink.add("fblthp"); |
| 54 transformed.sink.close(); |
| 55 expect(sinkController.stream.toList(), |
| 56 completion(equals([[102, 98, 108, 116, 104, 112]]))); |
| 57 }); |
| 58 } |
OLD | NEW |