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

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: Remove the null future "optimization". Fix some missing type parameters. 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
« no previous file with comments | « tests/lib/async/future_test.dart ('k') | tests/lib/lib.status » ('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) 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 flushMicrotasks();
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 flushMicrotasks();
36 // respects cancel.
37 sub2.cancel();
38 await flushMicrotasks();
39 Expect.equals(tick, 1);
40 // Still not complete.
41
42 StreamSubscription<int> sub3 =
43 s.listen(unreachable, onError: unreachable, onDone: ticker);
44 // respects pause.
45 sub3.pause();
46 Expect.equals(tick, 1);
47 await flushMicrotasks();
48 // Doesn't complete while paused.
49 Expect.equals(tick, 1);
50 sub3.resume();
51 await flushMicrotasks();
52 // Now completed.
53 Expect.equals(tick, 2);
54
55 asyncEnd();
56 }
57
58 Future flushMicrotasks() => new Future.delayed(Duration.ZERO);
OLDNEW
« no previous file with comments | « tests/lib/async/future_test.dart ('k') | tests/lib/lib.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698