Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(802)

Unified Diff: test/stream_channel_test.dart

Issue 1657943002: Add support for stream- and sink-specific changes. (Closed) Base URL: git@github.com:dart-lang/stream_channel.git@master
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pubspec.yaml ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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();
+ });
}
« no previous file with comments | « pubspec.yaml ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698