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

Side by Side 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, 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') | test/with_guarantees_test.dart » ('j') | 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
7 import 'package:stream_channel/stream_channel.dart';
8 import 'package:test/test.dart';
9
10 import 'utils.dart';
11
12 void main() {
13 group("asynchronously", () {
14 var controller;
15 setUp(() {
16 controller = new StreamChannelController();
17 });
18
19 test("forwards events from the local sink to the foreign stream", () {
20 controller.local.sink..add(1)..add(2)..add(3)..close();
21 expect(controller.foreign.stream.toList(), completion(equals([1, 2, 3])));
22 });
23
24 test("forwards events from the foreign sink to the local stream", () {
25 controller.foreign.sink..add(1)..add(2)..add(3)..close();
26 expect(controller.local.stream.toList(), completion(equals([1, 2, 3])));
27 });
28 });
29
30 group("synchronously", () {
31 var controller;
32 setUp(() {
33 controller = new StreamChannelController(sync: true);
34 });
35
36 test("synchronously forwards events from the local sink to the foreign "
37 "stream", () {
38 var receivedEvent = false;
39 var receivedError = false;
40 var receivedDone = false;
41 controller.foreign.stream.listen(expectAsync((event) {
42 expect(event, equals(1));
43 receivedEvent = true;
44 }), onError: expectAsync((error) {
45 expect(error, equals("oh no"));
46 receivedError = true;
47 }), onDone: expectAsync(() {
48 receivedDone = true;
49 }));
50
51 controller.local.sink.add(1);
52 expect(receivedEvent, isTrue);
53
54 controller.local.sink.addError("oh no");
55 expect(receivedError, isTrue);
56
57 controller.local.sink.close();
58 expect(receivedDone, isTrue);
59 });
60
61 test("synchronously forwards events from the foreign sink to the local "
62 "stream", () {
63 var receivedEvent = false;
64 var receivedError = false;
65 var receivedDone = false;
66 controller.local.stream.listen(expectAsync((event) {
67 expect(event, equals(1));
68 receivedEvent = true;
69 }), onError: expectAsync((error) {
70 expect(error, equals("oh no"));
71 receivedError = true;
72 }), onDone: expectAsync(() {
73 receivedDone = true;
74 }));
75
76 controller.foreign.sink.add(1);
77 expect(receivedEvent, isTrue);
78
79 controller.foreign.sink.addError("oh no");
80 expect(receivedError, isTrue);
81
82 controller.foreign.sink.close();
83 expect(receivedDone, isTrue);
84 });
85 });
86 }
OLDNEW
« 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