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

Side by Side 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 unified diff | Download patch
« pubspec.yaml ('K') | « pubspec.yaml ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 }
OLDNEW
« pubspec.yaml ('K') | « pubspec.yaml ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698