OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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_join_test; | 6 library stream_join_test; |
7 | 7 |
8 import 'dart:async'; | 8 import 'dart:async'; |
9 import 'event_helper.dart'; | 9 import 'event_helper.dart'; |
10 import 'package:unittest/unittest.dart'; | 10 import 'package:unittest/unittest.dart'; |
11 import "package:expect/expect.dart"; | 11 import "package:expect/expect.dart"; |
12 | 12 |
13 main() { | 13 main() { |
14 test("join-empty", () { | 14 test("join-empty", () { |
15 StreamController c = new StreamController(); | 15 StreamController c = new StreamController(); |
16 c.stream.join("X").then(expectAsync( | 16 c.stream.join("X").then(expectAsync((String s) => expect(s, equals("")))); |
17 (String s) => expect(s, equals("")) | |
18 )); | |
19 c.close(); | 17 c.close(); |
20 }); | 18 }); |
21 | 19 |
22 test("join-single", () { | 20 test("join-single", () { |
23 StreamController c = new StreamController(); | 21 StreamController c = new StreamController(); |
24 c.stream.join("X").then(expectAsync( | 22 c.stream |
25 (String s) => expect(s, equals("foo")) | 23 .join("X") |
26 )); | 24 .then(expectAsync((String s) => expect(s, equals("foo")))); |
27 c.add("foo"); | 25 c.add("foo"); |
28 c.close(); | 26 c.close(); |
29 }); | 27 }); |
30 | 28 |
31 test("join-three", () { | 29 test("join-three", () { |
32 StreamController c = new StreamController(); | 30 StreamController c = new StreamController(); |
33 c.stream.join("X").then(expectAsync( | 31 c.stream |
34 (String s) => expect(s, equals("fooXbarXbaz")) | 32 .join("X") |
35 )); | 33 .then(expectAsync((String s) => expect(s, equals("fooXbarXbaz")))); |
36 c.add("foo"); | 34 c.add("foo"); |
37 c.add("bar"); | 35 c.add("bar"); |
38 c.add("baz"); | 36 c.add("baz"); |
39 c.close(); | 37 c.close(); |
40 }); | 38 }); |
41 | 39 |
42 test("join-three-non-string", () { | 40 test("join-three-non-string", () { |
43 StreamController c = new StreamController(); | 41 StreamController c = new StreamController(); |
44 c.stream.join("X").then(expectAsync( | 42 c.stream |
45 (String s) => expect(s, equals("fooXbarXbaz")) | 43 .join("X") |
46 )); | 44 .then(expectAsync((String s) => expect(s, equals("fooXbarXbaz")))); |
47 c.add(new Foo("foo")); | 45 c.add(new Foo("foo")); |
48 c.add(new Foo("bar")); | 46 c.add(new Foo("bar")); |
49 c.add(new Foo("baz")); | 47 c.add(new Foo("baz")); |
50 c.close(); | 48 c.close(); |
51 }); | 49 }); |
52 | 50 |
53 test("join-error", () { | 51 test("join-error", () { |
54 StreamController c = new StreamController(); | 52 StreamController c = new StreamController(); |
55 c.stream.join("X").catchError(expectAsync( | 53 c.stream |
56 (String s) => expect(s, equals("BAD!")) | 54 .join("X") |
57 )); | 55 .catchError(expectAsync((String s) => expect(s, equals("BAD!")))); |
58 c.add(new Foo("foo")); | 56 c.add(new Foo("foo")); |
59 c.add(new Foo("bar")); | 57 c.add(new Foo("bar")); |
60 c.add(new Bad()); | 58 c.add(new Bad()); |
61 c.add(new Foo("baz")); | 59 c.add(new Foo("baz")); |
62 c.close(); | 60 c.close(); |
63 }); | 61 }); |
64 } | 62 } |
65 | 63 |
66 class Foo { | 64 class Foo { |
67 String value; | 65 String value; |
68 Foo(this.value); | 66 Foo(this.value); |
69 String toString() => value; | 67 String toString() => value; |
70 } | 68 } |
71 | 69 |
72 class Bad { | 70 class Bad { |
73 Bad(); | 71 Bad(); |
74 String toString() => throw "BAD!"; | 72 String toString() => throw "BAD!"; |
75 } | 73 } |
OLD | NEW |