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

Side by Side Diff: tests/lib/async/stream_empty_test.dart

Issue 1177343004: Add Stream.empty. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Add test, fix impl. Created 5 years, 6 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
« sdk/lib/async/stream.dart ('K') | « sdk/lib/async/stream_impl.dart ('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 // Test empty stream.
6 import "package:expect/expect.dart";
7 import "dart:async";
8 import 'package:async_helper/async_helper.dart';
9
10 main() async {
11 unreachable([a,b]) { throw "UNREACHABLE"; }
12 int tick = 0;
13 ticker() { tick++; }
14
15 asyncStart();
16
17 Stream<int> s = const Stream<int>.empty(); // Is const constructor.
18 Expect.isFalse(s is Stream<String>); // Respects type parameter.
19 StreamSubscription<int> sub =
20 s.listen(unreachable, onError: unreachable, onDone: ticker);
21 Expect.isFalse(sub is StreamSubscription<String>); // Type parameter in sub.
22
23 // Doesn't do callback in response to listen.
24 Expect.equals(tick, 0);
25 await sleep(50);
26 // Completes eventually.
27 Expect.equals(tick, 1);
28
29 // It's a broadcast stream - can listen twice.
30 Expect.isTrue(s.isBroadcast);
31 StreamSubscription<int> sub2 =
32 s.listen(unreachable, onError: unreachable, onDone: unreachable);
33 // respects pause.
34 sub2.pause();
35 await sleep(50);
36 // respects cancel.
37 sub2.cancel();
38 await sleep(50);
39 // Still not complete.
Søren Gjesse 2015/06/15 12:57:42 Add Expect.equals(tick, 1); here as well.
Lasse Reichstein Nielsen 2015/06/16 09:25:12 Done.
40
41 StreamSubscription<int> sub3 =
42 s.listen(unreachable, onError: unreachable, onDone: ticker);
43 // respects pause.
44 sub3.pause();
45 Expect.equals(tick, 1);
46 await sleep(50);
47 // Doesn't complete while paused.
48 Expect.equals(tick, 1);
49 sub3.resume();
50 await sleep(50);
51 // Doesn't complete while paused.
Søren Gjesse 2015/06/15 12:57:42 Wrong comment.
Lasse Reichstein Nielsen 2015/06/16 09:25:12 Fixed.
52 Expect.equals(tick, 2);
53
54 asyncEnd();
55 }
56
57 Future sleep(int ms) => new Future.delayed(new Duration(milliseconds: ms));
OLDNEW
« sdk/lib/async/stream.dart ('K') | « sdk/lib/async/stream_impl.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698