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

Unified Diff: test/stream_channel_controller_test.dart

Issue 1662773003: Add StreamChannel.withGuarantees and StreamChannelController. (Closed) Base URL: git@github.com:dart-lang/stream_channel.git@master
Patch Set: Code review changes 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
« no previous file with comments | « pubspec.yaml ('k') | test/with_guarantees_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/stream_channel_controller_test.dart
diff --git a/test/stream_channel_controller_test.dart b/test/stream_channel_controller_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..e45f09062484a7fc37256d9a9bbfb1ace4a2fd86
--- /dev/null
+++ b/test/stream_channel_controller_test.dart
@@ -0,0 +1,86 @@
+// 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 'package:stream_channel/stream_channel.dart';
+import 'package:test/test.dart';
+
+import 'utils.dart';
+
+void main() {
+ group("asynchronously", () {
+ var controller;
+ setUp(() {
+ controller = new StreamChannelController();
+ });
+
+ test("forwards events from the local sink to the foreign stream", () {
+ controller.local.sink..add(1)..add(2)..add(3)..close();
+ expect(controller.foreign.stream.toList(), completion(equals([1, 2, 3])));
+ });
+
+ test("forwards events from the foreign sink to the local stream", () {
+ controller.foreign.sink..add(1)..add(2)..add(3)..close();
+ expect(controller.local.stream.toList(), completion(equals([1, 2, 3])));
+ });
+ });
+
+ group("synchronously", () {
+ var controller;
+ setUp(() {
+ controller = new StreamChannelController(sync: true);
+ });
+
+ test("synchronously forwards events from the local sink to the foreign "
+ "stream", () {
+ var receivedEvent = false;
+ var receivedError = false;
+ var receivedDone = false;
+ controller.foreign.stream.listen(expectAsync((event) {
+ expect(event, equals(1));
+ receivedEvent = true;
+ }), onError: expectAsync((error) {
+ expect(error, equals("oh no"));
+ receivedError = true;
+ }), onDone: expectAsync(() {
+ receivedDone = true;
+ }));
+
+ controller.local.sink.add(1);
+ expect(receivedEvent, isTrue);
+
+ controller.local.sink.addError("oh no");
+ expect(receivedError, isTrue);
+
+ controller.local.sink.close();
+ expect(receivedDone, isTrue);
+ });
+
+ test("synchronously forwards events from the foreign sink to the local "
+ "stream", () {
+ var receivedEvent = false;
+ var receivedError = false;
+ var receivedDone = false;
+ controller.local.stream.listen(expectAsync((event) {
+ expect(event, equals(1));
+ receivedEvent = true;
+ }), onError: expectAsync((error) {
+ expect(error, equals("oh no"));
+ receivedError = true;
+ }), onDone: expectAsync(() {
+ receivedDone = true;
+ }));
+
+ controller.foreign.sink.add(1);
+ expect(receivedEvent, isTrue);
+
+ controller.foreign.sink.addError("oh no");
+ expect(receivedError, isTrue);
+
+ controller.foreign.sink.close();
+ expect(receivedDone, isTrue);
+ });
+ });
+}
« no previous file with comments | « pubspec.yaml ('k') | test/with_guarantees_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698