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

Unified 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 side-by-side diff with in-line comments
Download patch
« sdk/lib/async/stream.dart ('K') | « sdk/lib/io/websocket_impl.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/lib/async/stream_sink_adapter_test.dart
diff --git a/tests/lib/async/stream_sink_adapter_test.dart b/tests/lib/async/stream_sink_adapter_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..95ebd8e2b05ffb9b242ce2c5a61814b6319a689b
--- /dev/null
+++ b/tests/lib/async/stream_sink_adapter_test.dart
@@ -0,0 +1,111 @@
+// Copyright (c) 2014, 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 "package:expect/expect.dart";
+import "package:async_helper/async_helper.dart";
+import 'dart:async';
+
+
+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.
+ final List expectedEvents;
+ final List events = [];
+
+ StreamConsumerImpl(this.expectedEvents);
+
+ Future addStream(Stream stream) {
+ 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.
+ events.add(event);
+ }).asFuture();
+ }
+
+ Future close() {
+ check();
+ return new Future.value();
+ }
+
+ void check() {
+ Expect.listEquals(expectedEvents, events);
+ }
+}
+
+
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.
+void testAddClose() {
+ asyncStart();
+ var sink = new StreamSinkAdapter(new StreamConsumerImpl([1, 2, 3]));
+ sink.add(1);
+ sink.add(2);
+ sink.add(3);
+ sink.close().then((_) {
+ asyncEnd();
+ });
+}
+
+
+void testAddFlush() {
+ asyncStart();
+ var consumer = new StreamConsumerImpl([1, 2, 3]);
+ var sink = new StreamSinkAdapter(consumer);
+ sink.add(1);
+ sink.add(2);
+ sink.add(3);
+ sink.flush().then((_) {
+ consumer.check();
+ asyncEnd();
+ });
+ // 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.
+ Expect.throws(() => sink.add(4));
+ Expect.throws(() => sink.addError("error"));
+ Expect.throws(() => sink.addStream(new Stream.fromIterable([])));
+ Expect.throws(() => sink.close());
+ sink.done; // No error.
+}
+
+
+void testAddStreamClose() {
+ asyncStart();
+ var list = [1, 2, 3];
+ var sink = new StreamSinkAdapter(new StreamConsumerImpl(list));
+ new Stream.fromIterable(list).pipe(sink).then((_) {
+ asyncEnd();
+ });
+ // Not valid while addStream.
+ Expect.throws(() => sink.add(4));
+ Expect.throws(() => sink.addError("error"));
+ Expect.throws(() => sink.addStream(new Stream.fromIterable([])));
+ Expect.throws(() => sink.close());
+ sink.done; // No error.
+}
+
+
+void testAddAddStreamClose() {
+ asyncStart();
+ var list = [1, 2, 3, 4, 5, 6];
+ var sink = new StreamSinkAdapter(new StreamConsumerImpl(list));
+ sink.add(1);
+ sink.add(2);
+ sink.add(3);
+ new Stream.fromIterable(list.skip(3)).pipe(sink).then((_) {
+ asyncEnd();
+ });
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.
+}
+
+
+void testAddError() {
+ asyncStart();
+ var sink = new StreamSinkAdapter(new StreamConsumerImpl([]));
+ new Future.error("error").asStream().pipe(sink).catchError((error) {
+ Expect.equals("error", error);
+ sink.close();
+ asyncEnd();
+ });
+}
+
+
+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.
+ testAddClose();
+ testAddFlush();
+ testAddStreamClose();
+ testAddAddStreamClose();
+ testAddError();
+}
« 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