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

Unified 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 side-by-side diff with in-line comments
Download patch
« lib/src/lazy_stream.dart ('K') | « pubspec.yaml ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/lazy_stream_test.dart
diff --git a/test/lazy_stream_test.dart b/test/lazy_stream_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..ca7e99587438523c824da8e8cb55cddadc14bb37
--- /dev/null
+++ b/test/lazy_stream_test.dart
@@ -0,0 +1,86 @@
+// Copyright (c) 2015, 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:async/async.dart";
+import "package:test/test.dart";
+
+import "utils.dart";
+
+main() {
+ test("calls the callback when the stream is listened", () async {
+ var callbackCalled = false;
+ var stream = new LazyStream(expectAsync(() {
+ callbackCalled = true;
+ return new Stream.empty();
+ }));
+
+ await flushMicrotasks();
+ expect(callbackCalled, isFalse);
+
+ stream.listen(null);
+ expect(callbackCalled, isTrue);
+ });
+
+ test("forwards to a synchronously-provided stream", () async {
+ var controller = new StreamController<int>();
+ var stream = new LazyStream(expectAsync(() => controller.stream));
+
+ var events = [];
+ stream.listen(events.add);
+
+ controller.add(1);
+ await flushMicrotasks();
+ expect(events, equals([1]));
+
+ controller.add(2);
+ await flushMicrotasks();
+ expect(events, equals([1, 2]));
+
+ controller.add(3);
+ await flushMicrotasks();
+ expect(events, equals([1, 2, 3]));
+
+ controller.close();
+ });
+
+ test("forwards to an asynchronously-provided stream", () async {
+ var controller = new StreamController<int>();
+ var stream = new LazyStream(expectAsync(() async => controller.stream));
+
+ var events = [];
+ stream.listen(events.add);
+
+ controller.add(1);
+ await flushMicrotasks();
+ expect(events, equals([1]));
+
+ controller.add(2);
+ await flushMicrotasks();
+ expect(events, equals([1, 2]));
+
+ controller.add(3);
+ await flushMicrotasks();
+ expect(events, equals([1, 2, 3]));
+
+ controller.close();
+ });
+
+ 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.
+ var stream = new LazyStream(expectAsync(() => new Stream.empty()));
+ stream.listen(null);
+ expect(() => stream.listen(null), throwsStateError);
+ expect(() => stream.listen(null), throwsStateError);
+ });
+
+ test("a lazy stream can't be listened to from within its callback", () {
+ var stream;
+ stream = new LazyStream(expectAsync(() {
+ expect(() => stream.listen(null), throwsStateError);
+ return new Stream.empty();
+ }));
+ stream.listen(null);
+ });
+}
« 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