| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 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 | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 // Test the Stream.single method. | 5 // Test the Stream.single method. |
| 6 library stream_single_test; | 6 library stream_single_test; |
| 7 | 7 |
| 8 import "package:expect/expect.dart"; | 8 import "package:expect/expect.dart"; |
| 9 import 'dart:async'; | 9 import 'dart:async'; |
| 10 import 'package:unittest/unittest.dart'; | 10 import 'package:unittest/unittest.dart'; |
| 11 import 'event_helper.dart'; | 11 import 'event_helper.dart'; |
| 12 | 12 |
| 13 main() { | 13 main() { |
| 14 test("single", () { | 14 test("single", () { |
| 15 StreamController c = new StreamController(sync: true); | 15 StreamController c = new StreamController(sync: true); |
| 16 Future f = c.stream.single; | 16 Future f = c.stream.single; |
| 17 f.then(expectAsync((v) { Expect.equals(42, v);})); | 17 f.then(expectAsync((v) { |
| 18 Expect.equals(42, v); |
| 19 })); |
| 18 new Events.fromIterable([42]).replay(c); | 20 new Events.fromIterable([42]).replay(c); |
| 19 }); | 21 }); |
| 20 | 22 |
| 21 test("single empty", () { | 23 test("single empty", () { |
| 22 StreamController c = new StreamController(sync: true); | 24 StreamController c = new StreamController(sync: true); |
| 23 Future f = c.stream.single; | 25 Future f = c.stream.single; |
| 24 f.catchError(expectAsync((error) { Expect.isTrue(error is StateError); })); | 26 f.catchError(expectAsync((error) { |
| 27 Expect.isTrue(error is StateError); |
| 28 })); |
| 25 new Events.fromIterable([]).replay(c); | 29 new Events.fromIterable([]).replay(c); |
| 26 }); | 30 }); |
| 27 | 31 |
| 28 test("single error", () { | 32 test("single error", () { |
| 29 StreamController c = new StreamController(sync: true); | 33 StreamController c = new StreamController(sync: true); |
| 30 Future f = c.stream.single; | 34 Future f = c.stream.single; |
| 31 f.catchError(expectAsync((error) { Expect.equals("error", error); })); | 35 f.catchError(expectAsync((error) { |
| 32 Events errorEvents = new Events()..error("error")..close(); | 36 Expect.equals("error", error); |
| 37 })); |
| 38 Events errorEvents = new Events() |
| 39 ..error("error") |
| 40 ..close(); |
| 33 errorEvents.replay(c); | 41 errorEvents.replay(c); |
| 34 }); | 42 }); |
| 35 | 43 |
| 36 test("single error 2", () { | 44 test("single error 2", () { |
| 37 StreamController c = new StreamController(sync: true); | 45 StreamController c = new StreamController(sync: true); |
| 38 Future f = c.stream.single; | 46 Future f = c.stream.single; |
| 39 f.catchError(expectAsync((error) { Expect.equals("error", error); })); | 47 f.catchError(expectAsync((error) { |
| 40 Events errorEvents = new Events()..error("error")..error("error2")..close(); | 48 Expect.equals("error", error); |
| 49 })); |
| 50 Events errorEvents = new Events() |
| 51 ..error("error") |
| 52 ..error("error2") |
| 53 ..close(); |
| 41 errorEvents.replay(c); | 54 errorEvents.replay(c); |
| 42 }); | 55 }); |
| 43 | 56 |
| 44 test("single error 3", () { | 57 test("single error 3", () { |
| 45 StreamController c = new StreamController(sync: true); | 58 StreamController c = new StreamController(sync: true); |
| 46 Future f = c.stream.single; | 59 Future f = c.stream.single; |
| 47 f.catchError(expectAsync((error) { Expect.equals("error", error); })); | 60 f.catchError(expectAsync((error) { |
| 48 Events errorEvents = new Events()..add(499)..error("error")..close(); | 61 Expect.equals("error", error); |
| 62 })); |
| 63 Events errorEvents = new Events() |
| 64 ..add(499) |
| 65 ..error("error") |
| 66 ..close(); |
| 49 errorEvents.replay(c); | 67 errorEvents.replay(c); |
| 50 }); | 68 }); |
| 51 } | 69 } |
| OLD | NEW |