| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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:collection" show Queue; | 5 import "dart:collection" show Queue; |
| 6 import "dart:typed_data" show Uint8List, Float32List; | 6 import "dart:typed_data" show Uint8List, Float32List; |
| 7 import "package:expect/expect.dart"; | 7 import "package:expect/expect.dart"; |
| 8 | 8 |
| 9 main() { | 9 main() { |
| 10 // testIterable takes an iterable and a list expected to be equal to | 10 // testIterable takes an iterable and a list expected to be equal to |
| 11 // the iterable's toList result, including the type parameter of the list. | 11 // the iterable's toList result, including the type parameter of the list. |
| 12 testIterable([], []); | 12 testIterable([], []); |
| 13 testIterable(<int>[], <int>[]); | 13 testIterable(<int>[], <int>[]); |
| 14 testIterable(<String>[], <String>[]); | 14 testIterable(<String>[], <String>[]); |
| 15 testIterable([1, 2, 3], [1, 2, 3]); | 15 testIterable([1, 2, 3], [1, 2, 3]); |
| 16 testIterable(<int>[1, 2, 3], <int>[1, 2, 3]); | 16 testIterable(<int>[1, 2, 3], <int>[1, 2, 3]); |
| 17 testIterable(const [1, 2], [1, 2]); | 17 testIterable(const [1, 2], [1, 2]); |
| 18 testIterable(const <int>[1, 2], <int>[1, 2]); | 18 testIterable(const <int>[1, 2], <int>[1, 2]); |
| 19 testIterable({"x": 1, "y": 1}.keys, ["x", "y"]); | 19 testIterable({"x": 1, "y": 1}.keys, ["x", "y"]); |
| 20 testIterable(<String, int>{"x": 1, "y": 1}.keys, <String>["x", "y"]); | 20 testIterable(<String, int>{"x": 1, "y": 1}.keys, <String>["x", "y"]); |
| 21 testIterable({"x": 2, "y": 3}.values, [2, 3]); | 21 testIterable({"x": 2, "y": 3}.values, [2, 3]); |
| 22 testIterable(<String, int>{"x": 2, "y": 3}.values, <int>[2, 3]); | 22 testIterable(<String, int>{"x": 2, "y": 3}.values, <int>[2, 3]); |
| 23 testIterable(new Iterable.generate(3), [0, 1, 2]); | 23 testIterable(new Iterable.generate(3), [0, 1, 2]); |
| 24 testIterable(new Iterable<int>.generate(3), <int>[0, 1, 2]); | 24 testIterable(new Iterable<int>.generate(3), <int>[0, 1, 2]); |
| 25 testIterable(new Iterable<String>.generate(3, (x)=>"$x"), | 25 testIterable( |
| 26 <String>["0", "1", "2"]); | 26 new Iterable<String>.generate(3, (x) => "$x"), <String>["0", "1", "2"]); |
| 27 testIterable(new Set.from([1, 2, 3]), [1, 2, 3]); | 27 testIterable(new Set.from([1, 2, 3]), [1, 2, 3]); |
| 28 testIterable(new Set<int>.from([1, 2, 3]), <int>[1, 2, 3]); | 28 testIterable(new Set<int>.from([1, 2, 3]), <int>[1, 2, 3]); |
| 29 testIterable(new Queue.from([1, 2, 3]), [1, 2, 3]); | 29 testIterable(new Queue.from([1, 2, 3]), [1, 2, 3]); |
| 30 testIterable(new Queue<int>.from(<int>[1, 2, 3]), <int>[1, 2, 3]); | 30 testIterable(new Queue<int>.from(<int>[1, 2, 3]), <int>[1, 2, 3]); |
| 31 testIterable(new Uint8List.fromList(<int>[1, 2, 3]), // //# 01: ok | 31 testIterable(new Uint8List.fromList(<int>[1, 2, 3]), // //# 01: ok |
| 32 <int>[1, 2, 3]); // //# 01: continued | 32 <int>[1, 2, 3]); // //# 01: continued |
| 33 testIterable(new Float32List.fromList([1.0, 2.0, 3.0]), // //# 01: continued | 33 testIterable(new Float32List.fromList([1.0, 2.0, 3.0]), // //# 01: continued |
| 34 <double>[1.0, 2.0, 3.0]); // //# 01: continued | 34 <double>[1.0, 2.0, 3.0]); // //# 01: continued |
| 35 testIterable("abc".codeUnits, <int>[97, 98, 99]); // //# 01: continued | 35 testIterable("abc".codeUnits, <int>[97, 98, 99]); // //# 01: continued |
| 36 testIterable("abc".runes, <int>[97, 98, 99]); | 36 testIterable("abc".runes, <int>[97, 98, 99]); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 48 testIterable(iterable.expand((x) => [x]), new List.from(expected), depth); | 48 testIterable(iterable.expand((x) => [x]), new List.from(expected), depth); |
| 49 testIterable(iterable.map((x) => x), new List.from(expected), depth); | 49 testIterable(iterable.map((x) => x), new List.from(expected), depth); |
| 50 testIterable(iterable.skipWhile((x) => false), expected, depth); | 50 testIterable(iterable.skipWhile((x) => false), expected, depth); |
| 51 testIterable(iterable.takeWhile((x) => true), expected, depth); | 51 testIterable(iterable.takeWhile((x) => true), expected, depth); |
| 52 testIterable(iterable.skip(0), expected, depth); | 52 testIterable(iterable.skip(0), expected, depth); |
| 53 testIterable(iterable.take(expected.length * 2), expected, depth); | 53 testIterable(iterable.take(expected.length * 2), expected, depth); |
| 54 testIterable(iterable.toSet(), expected, depth); | 54 testIterable(iterable.toSet(), expected, depth); |
| 55 } | 55 } |
| 56 } | 56 } |
| 57 | 57 |
| 58 test(Iterable iterable, List expected, { bool growable: true}) { | 58 test(Iterable iterable, List expected, {bool growable: true}) { |
| 59 var list = iterable.toList(growable: growable); | 59 var list = iterable.toList(growable: growable); |
| 60 Expect.listEquals(expected, list); | 60 Expect.listEquals(expected, list); |
| 61 Expect.equals(expected is List<int>, list is List<int>, "int"); | 61 Expect.equals(expected is List<int>, list is List<int>, "int"); |
| 62 Expect.equals(expected is List<double>, list is List<double>, "double"); | 62 Expect.equals(expected is List<double>, list is List<double>, "double"); |
| 63 Expect.equals(expected is List<String>, list is List<String>, "str"); | 63 Expect.equals(expected is List<String>, list is List<String>, "str"); |
| 64 if (growable) { | 64 if (growable) { |
| 65 int length = list.length; | 65 int length = list.length; |
| 66 list.add(null); | 66 list.add(null); |
| 67 Expect.equals(length + 1, list.length); | 67 Expect.equals(length + 1, list.length); |
| 68 } else { | 68 } else { |
| 69 Expect.throws(() { list.add(null); }); | 69 Expect.throws(() { |
| 70 list.add(null); |
| 71 }); |
| 70 } | 72 } |
| 71 } | 73 } |
| OLD | NEW |