Chromium Code Reviews| OLD | NEW |
|---|---|
| (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)); | |
| OLD | NEW |