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

Unified Diff: test/stream_channel_test.dart

Issue 1639643002: Add StreamChannel.transform(). (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
« pubspec.yaml ('K') | « 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
new file mode 100644
index 0000000000000000000000000000000000000000..30a7db4fafb508dc9d92cd3637897e157f31147c
--- /dev/null
+++ b/test/stream_channel_test.dart
@@ -0,0 +1,58 @@
+// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+import 'dart:async';
+import 'dart:convert';
+import 'dart:isolate';
+
+import 'package:stream_channel/stream_channel.dart';
+import 'package:test/test.dart';
+
+import 'utils.dart';
+
+void main() {
+ var streamController;
+ var sinkController;
+ var channel;
+ setUp(() {
+ streamController = new StreamController();
+ sinkController = new StreamController();
+ channel = new StreamChannel(
+ streamController.stream, sinkController.sink);
+ });
+
+ test("pipe() pipes data from each channel's stream into the other's sink",
+ () {
+ var otherStreamController = new StreamController();
+ var otherSinkController = new StreamController();
+ var otherChannel = new StreamChannel(
+ otherStreamController.stream, otherSinkController.sink);
+ channel.pipe(otherChannel);
+
+ streamController.add(1);
+ streamController.add(2);
+ streamController.add(3);
+ streamController.close();
+ expect(otherSinkController.stream.toList(), completion(equals([1, 2, 3])));
+
+ otherStreamController.add(4);
+ otherStreamController.add(5);
+ otherStreamController.add(6);
+ otherStreamController.close();
+ expect(sinkController.stream.toList(), completion(equals([4, 5, 6])));
+ });
+
+ test("transform() transforms the channel", () {
+ var transformed = channel.transform(UTF8);
+
+ 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([[102, 98, 108, 116, 104, 112]])));
+ });
+}
« pubspec.yaml ('K') | « pubspec.yaml ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698