OLD | NEW |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 import 'dart:async'; | 5 import 'dart:async'; |
6 | 6 |
7 import "package:async/src/typed/stream.dart"; | 7 import "package:async/src/typed/stream.dart"; |
8 import "package:test/test.dart"; | 8 import "package:test/test.dart"; |
9 | 9 |
10 import '../utils.dart'; | 10 import '../utils.dart'; |
11 | 11 |
12 void main() { | 12 void main() { |
13 group("with valid types, forwards", () { | 13 group("with valid types, forwards", () { |
14 var controller; | 14 var controller; |
15 var wrapper; | 15 var wrapper; |
16 var emptyWrapper; | 16 var emptyWrapper; |
17 var singleWrapper; | 17 var singleWrapper; |
18 var errorWrapper; | 18 var errorWrapper; |
19 setUp(() { | 19 setUp(() { |
20 controller = new StreamController<Object>() | 20 controller = new StreamController<int>() |
21 ..add(1) | 21 ..add(1) |
22 ..add(2) | 22 ..add(2) |
23 ..add(3) | 23 ..add(3) |
24 ..add(4) | 24 ..add(4) |
25 ..add(5) | 25 ..add(5) |
26 ..close(); | 26 ..close(); |
27 | 27 |
28 // TODO(nweiz): Use public methods when test#414 is fixed and we can run | 28 // TODO(nweiz): Use public methods when test#414 is fixed and we can run |
29 // this on DDC. | 29 // this on DDC. |
30 wrapper = new TypeSafeStream<int>(controller.stream); | 30 wrapper = new TypeSafeStream<int>(controller.stream); |
31 emptyWrapper = new TypeSafeStream<int>(new Stream<Object>.empty()); | 31 emptyWrapper = new TypeSafeStream<int>(new Stream<Object>.empty()); |
32 singleWrapper = | 32 singleWrapper = |
33 new TypeSafeStream<int>(new Stream<Object>.fromIterable([1])); | 33 new TypeSafeStream<int>(new Stream<Object>.fromIterable([1])); |
34 errorWrapper = new TypeSafeStream<int>( | 34 errorWrapper = new TypeSafeStream<int>( |
35 new Stream<Object>.fromFuture(new Future.error("oh no"))); | 35 new Stream<int>.fromFuture(new Future.error("oh no"))); |
36 }); | 36 }); |
37 | 37 |
38 test("first", () { | 38 test("first", () { |
39 expect(wrapper.first, completion(equals(1))); | 39 expect(wrapper.first, completion(equals(1))); |
40 expect(emptyWrapper.first, throwsStateError); | 40 expect(emptyWrapper.first, throwsStateError); |
41 }); | 41 }); |
42 | 42 |
43 test("last", () { | 43 test("last", () { |
44 expect(wrapper.last, completion(equals(5))); | 44 expect(wrapper.last, completion(equals(5))); |
45 expect(emptyWrapper.last, throwsStateError); | 45 expect(emptyWrapper.last, throwsStateError); |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 completion(equals([2, 4, 6, 8, 10]))); | 108 completion(equals([2, 4, 6, 8, 10]))); |
109 }); | 109 }); |
110 | 110 |
111 group("distinct()", () { | 111 group("distinct()", () { |
112 test("without equals", () { | 112 test("without equals", () { |
113 expect( | 113 expect( |
114 wrapper.distinct().toList(), completion(equals([1, 2, 3, 4, 5]))); | 114 wrapper.distinct().toList(), completion(equals([1, 2, 3, 4, 5]))); |
115 | 115 |
116 expect( | 116 expect( |
117 new TypeSafeStream<int>( | 117 new TypeSafeStream<int>( |
118 new Stream<Object>.fromIterable([1, 1, 2, 2, 3, 3])) | 118 new Stream<int>.fromIterable([1, 1, 2, 2, 3, 3])) |
119 .distinct() | 119 .distinct() |
120 .toList(), | 120 .toList(), |
121 completion(equals([1, 2, 3]))); | 121 completion(equals([1, 2, 3]))); |
122 }); | 122 }); |
123 | 123 |
124 test("with equals", () { | 124 test("with equals", () { |
125 expect(wrapper.distinct((i1, i2) => (i1 ~/ 2 == i2 ~/ 2)).toList(), | 125 expect(wrapper.distinct((i1, i2) => (i1 ~/ 2 == i2 ~/ 2)).toList(), |
126 completion(equals([1, 2, 4]))); | 126 completion(equals([1, 2, 4]))); |
127 }); | 127 }); |
128 }); | 128 }); |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
272 | 272 |
273 test("takeWhile()", () { | 273 test("takeWhile()", () { |
274 expect( | 274 expect( |
275 wrapper.takeWhile((i) => i < 3).toList(), completion(equals([1, 2]))); | 275 wrapper.takeWhile((i) => i < 3).toList(), completion(equals([1, 2]))); |
276 }); | 276 }); |
277 | 277 |
278 test("toSet()", () { | 278 test("toSet()", () { |
279 expect(wrapper.toSet(), completion(unorderedEquals([1, 2, 3, 4, 5]))); | 279 expect(wrapper.toSet(), completion(unorderedEquals([1, 2, 3, 4, 5]))); |
280 expect( | 280 expect( |
281 new TypeSafeStream<int>( | 281 new TypeSafeStream<int>( |
282 new Stream<Object>.fromIterable([1, 1, 2, 2, 3, 3])).toSet(), | 282 new Stream<int>.fromIterable([1, 1, 2, 2, 3, 3])).toSet(), |
283 completion(unorderedEquals([1, 2, 3]))); | 283 completion(unorderedEquals([1, 2, 3]))); |
284 }); | 284 }); |
285 | 285 |
286 test("transform()", () { | 286 test("transform()", () { |
287 var transformer = new StreamTransformer<int, String>.fromHandlers( | 287 var transformer = new StreamTransformer<int, String>.fromHandlers( |
288 handleData: (data, sink) { | 288 handleData: (data, sink) { |
289 sink.add(data.toString()); | 289 sink.add(data.toString()); |
290 }); | 290 }); |
291 | 291 |
292 expect(wrapper.transform(transformer).toList(), | 292 expect(wrapper.transform(transformer).toList(), |
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
599 expect(wrapper.join(" "), completion(equals("foo bar baz"))); | 599 expect(wrapper.join(" "), completion(equals("foo bar baz"))); |
600 }); | 600 }); |
601 }); | 601 }); |
602 | 602 |
603 test("toString()", () { | 603 test("toString()", () { |
604 expect(wrapper.toString(), contains("Stream")); | 604 expect(wrapper.toString(), contains("Stream")); |
605 }); | 605 }); |
606 }); | 606 }); |
607 }); | 607 }); |
608 } | 608 } |
OLD | NEW |