OLD | NEW |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 import 'dart:collection'; | 6 import 'dart:collection'; |
7 | 7 |
8 main() { | 8 main() { |
9 defaultFunctionValuesTest(); | 9 defaultFunctionValuesTest(); |
10 defaultKeyFunctionTest(); | 10 defaultKeyFunctionTest(); |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 var map = | 112 var map = |
113 new SplayTreeMap<int, String>.fromIterable([1, 2, 3], value: (x) => '$x'); | 113 new SplayTreeMap<int, String>.fromIterable([1, 2, 3], value: (x) => '$x'); |
114 Expect.isTrue(map is Map<int, String>); | 114 Expect.isTrue(map is Map<int, String>); |
115 Expect.isTrue(map is SplayTreeMap<int, String>); | 115 Expect.isTrue(map is SplayTreeMap<int, String>); |
116 | 116 |
117 // Make sure it is not just SplayTreeMap<dynamic, dynamic>. | 117 // Make sure it is not just SplayTreeMap<dynamic, dynamic>. |
118 Expect.isFalse(map is SplayTreeMap<String, dynamic>); | 118 Expect.isFalse(map is SplayTreeMap<String, dynamic>); |
119 Expect.isFalse(map is SplayTreeMap<dynamic, int>); | 119 Expect.isFalse(map is SplayTreeMap<dynamic, int>); |
120 } | 120 } |
121 | 121 |
| 122 final bool isCheckedMode = (() { |
| 123 try { |
| 124 var i = 42; |
| 125 String s = i; |
| 126 } on TypeError catch (e) { |
| 127 return true; |
| 128 } |
| 129 return false; |
| 130 })(); |
| 131 |
122 // Test in checked mode with explicitly given types. | 132 // Test in checked mode with explicitly given types. |
123 void typedTest() { | 133 void typedTest() { |
124 bool isCheckedMode = false; | |
125 assert((isCheckedMode = true)); | |
126 if (!isCheckedMode) return; | 134 if (!isCheckedMode) return; |
127 | 135 |
128 // Assign functions to untyped function variables. | 136 // Assign functions to untyped function variables. |
129 Function key = (int v) => "$v"; | 137 Function key = (int v) => "$v"; |
130 Function value = (int v) => v.isOdd; | 138 Function value = (int v) => v.isOdd; |
131 Function id = (int i) => i; | 139 Function id = (int i) => i; |
132 | 140 |
133 Expect.throws(() { | 141 Expect.throws(() { |
134 new SplayTreeMap<String, bool>.fromIterable(<int>[1, 2, 3], key: key | 142 new SplayTreeMap<String, bool>.fromIterable(<int>[1, 2, 3], key: key |
135 // No "value" map, defaults to identity, which returns int, not bool. | 143 // No "value" map, defaults to identity, which returns int, not bool. |
(...skipping 24 matching lines...) Expand all Loading... |
160 key: key, value: value); | 168 key: key, value: value); |
161 Iterable<String> keys = map.keys; | 169 Iterable<String> keys = map.keys; |
162 Iterable<bool> values = map.values; | 170 Iterable<bool> values = map.values; |
163 List<String> keyList = keys.toList(); | 171 List<String> keyList = keys.toList(); |
164 List<bool> valueList = values.toList(); | 172 List<bool> valueList = values.toList(); |
165 Expect.equals(3, keyList.length); | 173 Expect.equals(3, keyList.length); |
166 Expect.equals(3, valueList.length); | 174 Expect.equals(3, valueList.length); |
167 Expect.equals(keys.first, map.firstKey()); | 175 Expect.equals(keys.first, map.firstKey()); |
168 Expect.equals(keys.last, map.lastKey()); | 176 Expect.equals(keys.last, map.lastKey()); |
169 } | 177 } |
OLD | NEW |