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

Side by Side Diff: test/lazy_stream_test.dart

Issue 1491923005: Add a LazyStream class. (Closed) Base URL: git@github.com:dart-lang/async.git@master
Patch Set: Created 5 years 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
« lib/src/lazy_stream.dart ('K') | « 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
(Empty)
1 // Copyright (c) 2015, 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:async/async.dart";
8 import "package:test/test.dart";
9
10 import "utils.dart";
11
12 main() {
13 test("calls the callback when the stream is listened", () async {
14 var callbackCalled = false;
15 var stream = new LazyStream(expectAsync(() {
16 callbackCalled = true;
17 return new Stream.empty();
18 }));
19
20 await flushMicrotasks();
21 expect(callbackCalled, isFalse);
22
23 stream.listen(null);
24 expect(callbackCalled, isTrue);
25 });
26
27 test("forwards to a synchronously-provided stream", () async {
28 var controller = new StreamController<int>();
29 var stream = new LazyStream(expectAsync(() => controller.stream));
30
31 var events = [];
32 stream.listen(events.add);
33
34 controller.add(1);
35 await flushMicrotasks();
36 expect(events, equals([1]));
37
38 controller.add(2);
39 await flushMicrotasks();
40 expect(events, equals([1, 2]));
41
42 controller.add(3);
43 await flushMicrotasks();
44 expect(events, equals([1, 2, 3]));
45
46 controller.close();
47 });
48
49 test("forwards to an asynchronously-provided stream", () async {
50 var controller = new StreamController<int>();
51 var stream = new LazyStream(expectAsync(() async => controller.stream));
52
53 var events = [];
54 stream.listen(events.add);
55
56 controller.add(1);
57 await flushMicrotasks();
58 expect(events, equals([1]));
59
60 controller.add(2);
61 await flushMicrotasks();
62 expect(events, equals([1, 2]));
63
64 controller.add(3);
65 await flushMicrotasks();
66 expect(events, equals([1, 2, 3]));
67
68 controller.close();
69 });
70
71 test("a lazy stream can't be listened to multiple times", () {
Lasse Reichstein Nielsen 2015/12/03 11:44:20 Check that stream.isBroadcast is false.
nweiz 2015/12/11 00:06:57 Done.
72 var stream = new LazyStream(expectAsync(() => new Stream.empty()));
73 stream.listen(null);
74 expect(() => stream.listen(null), throwsStateError);
75 expect(() => stream.listen(null), throwsStateError);
76 });
77
78 test("a lazy stream can't be listened to from within its callback", () {
79 var stream;
80 stream = new LazyStream(expectAsync(() {
81 expect(() => stream.listen(null), throwsStateError);
82 return new Stream.empty();
83 }));
84 stream.listen(null);
85 });
86 }
OLDNEW
« lib/src/lazy_stream.dart ('K') | « pubspec.yaml ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698