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 import "dart:async"; | 5 import "dart:async"; |
6 import "package:expect/expect.dart"; | 6 import "package:expect/expect.dart"; |
7 | 7 |
8 class TypeTest<T, NT> { | 8 class TypeTest<T, NT> { |
9 void call(object, name) { | 9 void call(object, name) { |
10 Expect.isTrue(object is T, "$name is $T"); | 10 Expect.isTrue(object is T, "$name is $T"); |
11 Expect.isFalse(object is NT, "$name is! $NT"); | 11 Expect.isFalse(object is NT, "$name is! $NT"); |
12 } | 12 } |
13 } | 13 } |
14 | 14 |
15 main() { | 15 main() { |
16 var checkIntStream = new TypeTest<Stream<int>, Stream<String>>(); | 16 var checkIntStream = new TypeTest<Stream<int>, Stream<String>>(); |
17 var checkIntFuture = new TypeTest<Future<int>, Future<String>>(); | 17 var checkIntFuture = new TypeTest<Future<int>, Future<String>>(); |
18 var checkBoolFuture = new TypeTest<Future<bool>, Future<String>>(); | 18 var checkBoolFuture = new TypeTest<Future<bool>, Future<String>>(); |
19 var checkStringFuture = new TypeTest<Future<String>, Future<int>>(); | 19 var checkStringFuture = new TypeTest<Future<String>, Future<int>>(); |
20 var checkIntSetFuture = new TypeTest<Future<Set<int>>, Future<Set<String>>>(); | 20 var checkIntSetFuture = new TypeTest<Future<Set<int>>, Future<Set<String>>>(); |
21 var checkIntListFuture = new TypeTest<Future<List<int>>, | 21 var checkIntListFuture = |
22 Future<List<String>>>(); | 22 new TypeTest<Future<List<int>>, Future<List<String>>>(); |
23 var checkIntSubscription = new TypeTest<StreamSubscription<int>, | 23 var checkIntSubscription = |
24 StreamSubscription<String>>(); | 24 new TypeTest<StreamSubscription<int>, StreamSubscription<String>>(); |
25 | 25 |
26 // Generic function used as parameter for, e.g., `skipWhile` and `reduce`. | 26 // Generic function used as parameter for, e.g., `skipWhile` and `reduce`. |
27 f([_1, _2]) => throw "unreachable"; | 27 f([_1, _2]) => throw "unreachable"; |
28 | 28 |
29 bool testIntStream(stream(), name, int recursionDepth) { | 29 bool testIntStream(stream(), name, int recursionDepth) { |
30 checkIntStream(stream(), name); | 30 checkIntStream(stream(), name); |
31 if (recursionDepth > 0) { | 31 if (recursionDepth > 0) { |
32 checkIntSubscription(stream().listen(null), "$name.listen"); | 32 checkIntSubscription(stream().listen(null), "$name.listen"); |
33 | 33 |
34 checkIntFuture(stream().first, "$name.first"); | 34 checkIntFuture(stream().first, "$name.first"); |
35 checkIntFuture(stream().last, "$name.last"); | 35 checkIntFuture(stream().last, "$name.last"); |
36 checkIntFuture(stream().single, "$name.single"); | 36 checkIntFuture(stream().single, "$name.single"); |
37 checkIntFuture(stream().singleWhere(f), "$name.singleWhere"); | 37 checkIntFuture(stream().singleWhere(f), "$name.singleWhere"); |
38 checkIntFuture(stream().elementAt(2), "$name.elementAt"); | 38 checkIntFuture(stream().elementAt(2), "$name.elementAt"); |
39 checkIntFuture(stream().reduce(f), "$name.reduce"); | 39 checkIntFuture(stream().reduce(f), "$name.reduce"); |
40 checkIntListFuture(stream().toList(), "$name.toList"); | 40 checkIntListFuture(stream().toList(), "$name.toList"); |
41 checkIntSetFuture(stream().toSet(), "$name.toSert"); | 41 checkIntSetFuture(stream().toSet(), "$name.toSert"); |
42 | 42 |
43 checkIntFuture(stream().length, "$name.length"); | 43 checkIntFuture(stream().length, "$name.length"); |
44 checkBoolFuture(stream().isEmpty, "$name.is"); | 44 checkBoolFuture(stream().isEmpty, "$name.is"); |
45 checkBoolFuture(stream().any(f) , "$name.any"); | 45 checkBoolFuture(stream().any(f), "$name.any"); |
46 checkBoolFuture(stream().every(f), "$name.every"); | 46 checkBoolFuture(stream().every(f), "$name.every"); |
47 checkBoolFuture(stream().contains(null), "$name.contains"); | 47 checkBoolFuture(stream().contains(null), "$name.contains"); |
48 checkStringFuture(stream().join(), "$name.join"); | 48 checkStringFuture(stream().join(), "$name.join"); |
49 | 49 |
50 var n = recursionDepth - 1; | 50 var n = recursionDepth - 1; |
51 testIntStream(() => stream().where(f), "$name.where", n); | 51 testIntStream(() => stream().where(f), "$name.where", n); |
52 testIntStream(() => stream().take(2), "$name.take", n); | 52 testIntStream(() => stream().take(2), "$name.take", n); |
53 testIntStream(() => stream().takeWhile(f), "$name.takeWhile", n); | 53 testIntStream(() => stream().takeWhile(f), "$name.takeWhile", n); |
54 testIntStream(() => stream().skip(2), "$name.skip", n); | 54 testIntStream(() => stream().skip(2), "$name.skip", n); |
55 testIntStream(() => stream().skipWhile(f), "$name.skipWhile", n); | 55 testIntStream(() => stream().skipWhile(f), "$name.skipWhile", n); |
56 testIntStream(() => stream().distinct(f), "$name.distinct", n); | 56 testIntStream(() => stream().distinct(f), "$name.distinct", n); |
57 testIntStream(() => stream().handleError(f), "$name.handleError", n); | 57 testIntStream(() => stream().handleError(f), "$name.handleError", n); |
58 testIntStream(() => stream().asBroadcastStream(), | 58 testIntStream( |
59 "$name.asBroadcastStream", n); | 59 () => stream().asBroadcastStream(), "$name.asBroadcastStream", n); |
60 } | 60 } |
61 } | 61 } |
62 | 62 |
63 testIntStream(() => new StreamController<int>().stream, "Stream<int>", 3); | 63 testIntStream(() => new StreamController<int>().stream, "Stream<int>", 3); |
64 testIntStream(() => new StreamController<int>.broadcast().stream, | 64 testIntStream(() => new StreamController<int>.broadcast().stream, |
65 "BroadcastStream<int>", 3); | 65 "BroadcastStream<int>", 3); |
66 } | 66 } |
OLD | NEW |