Chromium Code Reviews| 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); |
| + }); |
| +} |