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 "package:expect/expect.dart"; | 5 import "package:expect/expect.dart"; |
6 | 6 |
| 7 dynamicCheck(input, {isInt, isString}) { |
| 8 var copy = input.toList(); |
| 9 Expect.isTrue(isInt == copy is List<int>); |
| 10 Expect.isTrue(isString == copy is List<String>); |
| 11 } |
| 12 |
7 main() { | 13 main() { |
8 List<int> list1 = <int>[1, 2, 3]; | 14 List<int> list1 = <int>[1, 2, 3]; |
9 List<int> list2 = const <int>[4, 5]; | 15 List<int> list2 = const <int>[4, 5]; |
10 List<String> list3 = <String>[]; | 16 List<String> list3 = <String>[]; |
11 Set<int> set1 = new Set<int>(); | 17 Set<int> set1 = new Set<int>(); |
12 set1..add(11) | 18 set1..add(11) |
13 ..add(12) | 19 ..add(12) |
14 ..add(13); | 20 ..add(13); |
15 Set<String> set2 = new Set<String>(); | 21 Set<String> set2 = new Set<String>(); |
16 set2..add("foo") | 22 set2..add("foo") |
17 ..add("bar") | 23 ..add("bar") |
18 ..add("toto"); | 24 ..add("toto"); |
19 Set set3 = new Set(); | 25 Set set3 = new Set(); |
20 | 26 |
21 var listCopy = list1.toList(); | 27 var listCopy = list1.toList(); |
22 Expect.listEquals(list1, listCopy); | 28 Expect.listEquals(list1, listCopy); |
23 Expect.isTrue(listCopy is List<int>); | 29 Expect.isTrue(listCopy is List<int>); |
24 Expect.isFalse(listCopy is List<String>); | 30 Expect.isFalse(listCopy is List<String>); |
25 Expect.isFalse(identical(list1, listCopy)); | 31 Expect.isFalse(identical(list1, listCopy)); |
| 32 dynamicCheck(list1, isInt: true, isString: false); |
26 | 33 |
27 listCopy = list2.toList(); | 34 listCopy = list2.toList(); |
28 Expect.listEquals(list2, listCopy); | 35 Expect.listEquals(list2, listCopy); |
29 Expect.isTrue(listCopy is List<int>); | 36 Expect.isTrue(listCopy is List<int>); |
30 Expect.isFalse(listCopy is List<String>); | 37 Expect.isFalse(listCopy is List<String>); |
31 Expect.isFalse(identical(list2, listCopy)); | 38 Expect.isFalse(identical(list2, listCopy)); |
| 39 dynamicCheck(list2, isInt: true, isString: false); |
32 | 40 |
33 listCopy = list3.toList(); | 41 listCopy = list3.toList(); |
34 Expect.listEquals(list3, listCopy); | 42 Expect.listEquals(list3, listCopy); |
35 Expect.isTrue(listCopy is List<String>); | 43 Expect.isTrue(listCopy is List<String>); |
36 Expect.isFalse(listCopy is List<int>); | 44 Expect.isFalse(listCopy is List<int>); |
37 Expect.isFalse(identical(list3, listCopy)); | 45 Expect.isFalse(identical(list3, listCopy)); |
| 46 dynamicCheck(list3, isInt: false, isString: true); |
38 | 47 |
39 listCopy = set1.toList(); | 48 listCopy = set1.toList(); |
40 Expect.equals(3, listCopy.length); | 49 Expect.equals(3, listCopy.length); |
41 Expect.isTrue(listCopy.contains(11)); | 50 Expect.isTrue(listCopy.contains(11)); |
42 Expect.isTrue(listCopy.contains(12)); | 51 Expect.isTrue(listCopy.contains(12)); |
43 Expect.isTrue(listCopy.contains(13)); | 52 Expect.isTrue(listCopy.contains(13)); |
44 Expect.isTrue(listCopy is List<int>); | 53 Expect.isTrue(listCopy is List<int>); |
45 Expect.isFalse(listCopy is List<String>); | 54 Expect.isFalse(listCopy is List<String>); |
| 55 dynamicCheck(set1, isInt: true, isString: false); |
46 | 56 |
47 listCopy = set2.toList(); | 57 listCopy = set2.toList(); |
48 Expect.equals(3, listCopy.length); | 58 Expect.equals(3, listCopy.length); |
49 Expect.isTrue(listCopy.contains("foo")); | 59 Expect.isTrue(listCopy.contains("foo")); |
50 Expect.isTrue(listCopy.contains("bar")); | 60 Expect.isTrue(listCopy.contains("bar")); |
51 Expect.isTrue(listCopy.contains("toto")); | 61 Expect.isTrue(listCopy.contains("toto")); |
52 Expect.isTrue(listCopy is List<String>); | 62 Expect.isTrue(listCopy is List<String>); |
53 Expect.isFalse(listCopy is List<int>); | 63 Expect.isFalse(listCopy is List<int>); |
| 64 dynamicCheck(set2, isInt: false, isString: true); |
54 | 65 |
55 listCopy = set3.toList(); | 66 listCopy = set3.toList(); |
56 Expect.isTrue(listCopy.isEmpty); | 67 Expect.isTrue(listCopy.isEmpty); |
57 Expect.isTrue(listCopy is List<int>); | 68 Expect.isTrue(listCopy is List<int>); |
58 Expect.isTrue(listCopy is List<String>); | 69 Expect.isTrue(listCopy is List<String>); |
| 70 dynamicCheck(set3, isInt: true, isString: true); |
59 } | 71 } |
OLD | NEW |