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

Side by Side Diff: tests/lib/async/stream_sink_adapter_test.dart

Issue 196423021: Move _StreamSinkImpl from dart:io to dart:async as StreamSinkAdapter. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fix doc and add test.dart Created 6 years, 9 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 | Annotate | Revision Log
« sdk/lib/async/stream.dart ('K') | « sdk/lib/io/websocket_impl.dart ('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) 2014, 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 "package:expect/expect.dart";
6 import "package:async_helper/async_helper.dart";
7 import 'dart:async';
8
9
10 class StreamConsumerImpl implements StreamConsumer {
Lasse Reichstein Nielsen 2014/03/19 13:27:20 Impl isn't saying anything. How about ExpectingStr
Anders Johnsen 2014/03/19 13:56:39 Done.
11 final List expectedEvents;
12 final List events = [];
13
14 StreamConsumerImpl(this.expectedEvents);
15
16 Future addStream(Stream stream) {
17 return stream.listen((event) {
Lasse Reichstein Nielsen 2014/03/19 13:27:20 return stream.listen(events.add).asFuture();
Anders Johnsen 2014/03/19 13:56:39 Done.
18 events.add(event);
19 }).asFuture();
20 }
21
22 Future close() {
23 check();
24 return new Future.value();
25 }
26
27 void check() {
28 Expect.listEquals(expectedEvents, events);
29 }
30 }
31
32
Lasse Reichstein Nielsen 2014/03/19 13:27:20 Add documentation for tests: What is it testing, h
Anders Johnsen 2014/03/19 13:56:39 Done.
33 void testAddClose() {
34 asyncStart();
35 var sink = new StreamSinkAdapter(new StreamConsumerImpl([1, 2, 3]));
36 sink.add(1);
37 sink.add(2);
38 sink.add(3);
39 sink.close().then((_) {
40 asyncEnd();
41 });
42 }
43
44
45 void testAddFlush() {
46 asyncStart();
47 var consumer = new StreamConsumerImpl([1, 2, 3]);
48 var sink = new StreamSinkAdapter(consumer);
49 sink.add(1);
50 sink.add(2);
51 sink.add(3);
52 sink.flush().then((_) {
53 consumer.check();
54 asyncEnd();
55 });
56 // Not valid while flush.
Lasse Reichstein Nielsen 2014/03/19 13:27:20 while flush -> during flush. (or "while flushing",
Anders Johnsen 2014/03/19 13:56:39 Done.
57 Expect.throws(() => sink.add(4));
58 Expect.throws(() => sink.addError("error"));
59 Expect.throws(() => sink.addStream(new Stream.fromIterable([])));
60 Expect.throws(() => sink.close());
61 sink.done; // No error.
62 }
63
64
65 void testAddStreamClose() {
66 asyncStart();
67 var list = [1, 2, 3];
68 var sink = new StreamSinkAdapter(new StreamConsumerImpl(list));
69 new Stream.fromIterable(list).pipe(sink).then((_) {
70 asyncEnd();
71 });
72 // Not valid while addStream.
73 Expect.throws(() => sink.add(4));
74 Expect.throws(() => sink.addError("error"));
75 Expect.throws(() => sink.addStream(new Stream.fromIterable([])));
76 Expect.throws(() => sink.close());
77 sink.done; // No error.
78 }
79
80
81 void testAddAddStreamClose() {
82 asyncStart();
83 var list = [1, 2, 3, 4, 5, 6];
84 var sink = new StreamSinkAdapter(new StreamConsumerImpl(list));
85 sink.add(1);
86 sink.add(2);
87 sink.add(3);
88 new Stream.fromIterable(list.skip(3)).pipe(sink).then((_) {
89 asyncEnd();
90 });
Lasse Reichstein Nielsen 2014/03/19 13:27:20 What happens if you do "sink.add(0);" here? Does i
Anders Johnsen 2014/03/19 13:56:39 Done.
91 }
92
93
94 void testAddError() {
95 asyncStart();
96 var sink = new StreamSinkAdapter(new StreamConsumerImpl([]));
97 new Future.error("error").asStream().pipe(sink).catchError((error) {
98 Expect.equals("error", error);
99 sink.close();
100 asyncEnd();
101 });
102 }
103
104
105 void main() {
Lasse Reichstein Nielsen 2014/03/19 13:27:20 Add "asyncStart()" before calling the tests, and "
Anders Johnsen 2014/03/19 13:56:39 Done.
106 testAddClose();
107 testAddFlush();
108 testAddStreamClose();
109 testAddAddStreamClose();
110 testAddError();
111 }
OLDNEW
« sdk/lib/async/stream.dart ('K') | « sdk/lib/io/websocket_impl.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698