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

Side by Side 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, 10 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
« no previous file with comments | « 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
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file 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 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. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 import 'dart:async'; 5 import 'dart:async';
6 import 'dart:convert'; 6 import 'dart:convert';
7 import 'dart:isolate'; 7 import 'dart:isolate';
8 8
9 import 'package:async/async.dart';
9 import 'package:stream_channel/stream_channel.dart'; 10 import 'package:stream_channel/stream_channel.dart';
10 import 'package:test/test.dart'; 11 import 'package:test/test.dart';
11 12
12 import 'utils.dart'; 13 import 'utils.dart';
13 14
14 void main() { 15 void main() {
15 var streamController; 16 var streamController;
16 var sinkController; 17 var sinkController;
17 var channel; 18 var channel;
18 setUp(() { 19 setUp(() {
(...skipping 30 matching lines...) Expand all
49 50
50 streamController.add([102, 111, 111, 98, 97, 114]); 51 streamController.add([102, 111, 111, 98, 97, 114]);
51 streamController.close(); 52 streamController.close();
52 expect(transformed.stream.toList(), completion(equals(["foobar"]))); 53 expect(transformed.stream.toList(), completion(equals(["foobar"])));
53 54
54 transformed.sink.add("fblthp"); 55 transformed.sink.add("fblthp");
55 transformed.sink.close(); 56 transformed.sink.close();
56 expect(sinkController.stream.toList(), 57 expect(sinkController.stream.toList(),
57 completion(equals([[102, 98, 108, 116, 104, 112]]))); 58 completion(equals([[102, 98, 108, 116, 104, 112]])));
58 }); 59 });
60
61 test("transformStream() transforms only the stream", () {
62 var transformed = channel.transformStream(UTF8.decoder);
63
64 streamController.add([102, 111, 111, 98, 97, 114]);
65 streamController.close();
66 expect(transformed.stream.toList(), completion(equals(["foobar"])));
67
68 transformed.sink.add("fblthp");
69 transformed.sink.close();
70 expect(sinkController.stream.toList(),
71 completion(equals(["fblthp"])));
72 });
73
74 test("transformSink() transforms only the sink", () {
75 var transformed = channel.transformSink(
76 new StreamSinkTransformer.fromStreamTransformer(UTF8.encoder));
77
78 streamController.add([102, 111, 111, 98, 97, 114]);
79 streamController.close();
80 expect(transformed.stream.toList(),
81 completion(equals([[102, 111, 111, 98, 97, 114]])));
82
83 transformed.sink.add("fblthp");
84 transformed.sink.close();
85 expect(sinkController.stream.toList(),
86 completion(equals([[102, 98, 108, 116, 104, 112]])));
87 });
88
89 test("changeStream() changes the stream", () {
90 var newController = new StreamController();
91 var changed = channel.changeStream((stream) {
92 expect(stream, equals(channel.stream));
93 return newController.stream;
94 });
95
96 newController.add(10);
97 newController.close();
98
99 streamController.add(20);
100 streamController.close();
101
102 expect(changed.stream.toList(), completion(equals([10])));
103 });
104
105 test("changeSink() changes the sink", () {
106 var newController = new StreamController();
107 var changed = channel.changeSink((sink) {
108 expect(sink, equals(channel.sink));
109 return newController.sink;
110 });
111
112 expect(newController.stream.toList(), completion(equals([10])));
113 streamController.stream.listen(expectAsync((_) {}, count: 0));
114
115 changed.sink.add(10);
116 changed.sink.close();
117 });
59 } 118 }
OLDNEW
« 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