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 basic StreamController and StreamController.singleSubscription. | 5 // Test the basic StreamController and StreamController.singleSubscription. |
6 library stream_controller_async_test; | 6 library stream_controller_async_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 'dart:isolate'; | 10 import 'dart:isolate'; |
11 import '../../../pkg/unittest/lib/unittest.dart'; | 11 import '../../../pkg/unittest/lib/unittest.dart'; |
12 import 'event_helper.dart'; | 12 import 'event_helper.dart'; |
13 | 13 |
14 testController() { | 14 testController() { |
15 // Test fold | 15 // Test fold |
16 test("StreamController.fold", () { | 16 test("StreamController.fold", () { |
17 StreamController c = new StreamController.broadcast(); | 17 StreamController c = new StreamController(); |
18 Stream stream = c.stream; | 18 Stream stream = c.stream.asBroadcastStream(); |
19 stream.fold(0, (a,b) => a + b) | 19 stream.fold(0, (a,b) => a + b) |
20 .then(expectAsync1((int v) { | 20 .then(expectAsync1((int v) { |
21 Expect.equals(42, v); | 21 Expect.equals(42, v); |
22 })); | 22 })); |
23 c.add(10); | 23 c.add(10); |
24 c.add(32); | 24 c.add(32); |
25 c.close(); | 25 c.close(); |
26 }); | 26 }); |
27 | 27 |
28 test("StreamController.fold throws", () { | 28 test("StreamController.fold throws", () { |
29 StreamController c = new StreamController.broadcast(); | 29 StreamController c = new StreamController(); |
30 Stream stream = c.stream; | 30 Stream stream = c.stream.asBroadcastStream(); |
31 stream.fold(0, (a,b) { throw "Fnyf!"; }) | 31 stream.fold(0, (a,b) { throw "Fnyf!"; }) |
32 .catchError(expectAsync1((e) { Expect.equals("Fnyf!", e.error); })); | 32 .catchError(expectAsync1((e) { Expect.equals("Fnyf!", e.error); })); |
33 c.add(42); | 33 c.add(42); |
34 }); | 34 }); |
35 } | 35 } |
36 | 36 |
37 testSingleController() { | 37 testSingleController() { |
38 test("Single-subscription StreamController.fold", () { | 38 test("Single-subscription StreamController.fold", () { |
39 StreamController c = new StreamController(); | 39 StreamController c = new StreamController(); |
40 Stream stream = c.stream; | 40 Stream stream = c.stream; |
(...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
419 testFuture("fold", (s, act) => s.fold(0, (a,b) => act(b))); | 419 testFuture("fold", (s, act) => s.fold(0, (a,b) => act(b))); |
420 } | 420 } |
421 | 421 |
422 main() { | 422 main() { |
423 testController(); | 423 testController(); |
424 testSingleController(); | 424 testSingleController(); |
425 testExtraMethods(); | 425 testExtraMethods(); |
426 testPause(); | 426 testPause(); |
427 testRethrow(); | 427 testRethrow(); |
428 } | 428 } |
OLD | NEW |