OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2011, 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 the basic StreamController and StreamController.singleSubscription. |
| 6 import 'dart:async'; |
| 7 import 'dart:isolate'; |
| 8 import '../../../pkg/unittest/lib/unittest.dart'; |
| 9 import 'event_helper.dart'; |
| 10 |
| 11 main() { |
| 12 test("single", () { |
| 13 StreamController c = new StreamController(); |
| 14 Future f = c.single; |
| 15 f.then(expectAsync1((v) { Expect.equals(42, v);})); |
| 16 new Events.fromIterable([42]).replay(c); |
| 17 }); |
| 18 |
| 19 test("single empty", () { |
| 20 StreamController c = new StreamController(); |
| 21 Future f = c.single; |
| 22 f.catchError(expectAsync1((e) { Expect.isTrue(e.error is StateError); })); |
| 23 new Events.fromIterable([]).replay(c); |
| 24 }); |
| 25 |
| 26 test("single error", () { |
| 27 StreamController c = new StreamController(); |
| 28 Future f = c.single; |
| 29 f.catchError(expectAsync1((e) { Expect.equals("error", e.error); })); |
| 30 Events errorEvents = new Events()..error("error")..close(); |
| 31 errorEvents.replay(c); |
| 32 }); |
| 33 |
| 34 test("single error 2", () { |
| 35 StreamController c = new StreamController(); |
| 36 Future f = c.single; |
| 37 f.catchError(expectAsync1((e) { Expect.equals("error", e.error); })); |
| 38 Events errorEvents = new Events()..error("error")..error("error2")..close(); |
| 39 errorEvents.replay(c); |
| 40 }); |
| 41 |
| 42 test("single error 3", () { |
| 43 StreamController c = new StreamController(); |
| 44 Future f = c.single; |
| 45 f.catchError(expectAsync1((e) { Expect.equals("error", e.error); })); |
| 46 Events errorEvents = new Events()..add(499)..error("error")..close(); |
| 47 errorEvents.replay(c); |
| 48 }); |
| 49 } |
OLD | NEW |