Index: test/stream_channel_test.dart |
diff --git a/test/stream_channel_test.dart b/test/stream_channel_test.dart |
index 5f006c39c64a4ecf400a6bd7af4c4b34b9da48fb..f5251778d70865b6cdbeb45d121e293b0ecaf245 100644 |
--- a/test/stream_channel_test.dart |
+++ b/test/stream_channel_test.dart |
@@ -6,6 +6,7 @@ import 'dart:async'; |
import 'dart:convert'; |
import 'dart:isolate'; |
+import 'package:async/async.dart'; |
import 'package:stream_channel/stream_channel.dart'; |
import 'package:test/test.dart'; |
@@ -56,4 +57,62 @@ void main() { |
expect(sinkController.stream.toList(), |
completion(equals([[102, 98, 108, 116, 104, 112]]))); |
}); |
+ |
+ test("transformStream() transforms only the stream", () { |
+ var transformed = channel.transformStream(UTF8.decoder); |
+ |
+ streamController.add([102, 111, 111, 98, 97, 114]); |
+ streamController.close(); |
+ expect(transformed.stream.toList(), completion(equals(["foobar"]))); |
+ |
+ transformed.sink.add("fblthp"); |
+ transformed.sink.close(); |
+ expect(sinkController.stream.toList(), |
+ completion(equals(["fblthp"]))); |
+ }); |
+ |
+ test("transformSink() transforms only the sink", () { |
+ var transformed = channel.transformSink( |
+ new StreamSinkTransformer.fromStreamTransformer(UTF8.encoder)); |
+ |
+ streamController.add([102, 111, 111, 98, 97, 114]); |
+ streamController.close(); |
+ expect(transformed.stream.toList(), |
+ completion(equals([[102, 111, 111, 98, 97, 114]]))); |
+ |
+ transformed.sink.add("fblthp"); |
+ transformed.sink.close(); |
+ expect(sinkController.stream.toList(), |
+ completion(equals([[102, 98, 108, 116, 104, 112]]))); |
+ }); |
+ |
+ test("changeStream() changes the stream", () { |
+ var newController = new StreamController(); |
+ var changed = channel.changeStream((stream) { |
+ expect(stream, equals(channel.stream)); |
+ return newController.stream; |
+ }); |
+ |
+ newController.add(10); |
+ newController.close(); |
+ |
+ streamController.add(20); |
+ streamController.close(); |
+ |
+ expect(changed.stream.toList(), completion(equals([10]))); |
+ }); |
+ |
+ test("changeSink() changes the sink", () { |
+ var newController = new StreamController(); |
+ var changed = channel.changeSink((sink) { |
+ expect(sink, equals(channel.sink)); |
+ return newController.sink; |
+ }); |
+ |
+ expect(newController.stream.toList(), completion(equals([10]))); |
+ streamController.stream.listen(expectAsync((_) {}, count: 0)); |
+ |
+ changed.sink.add(10); |
+ changed.sink.close(); |
+ }); |
} |