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 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 typedef String intToString(int v); | 122 typedef String intToString(int v); |
123 typedef bool intToBool(int v); | 123 typedef bool intToBool(int v); |
124 | 124 |
125 // Test in checked mode with explicitly given types. | 125 // Test in checked mode with explicitly given types. |
126 void typedTest() { | 126 void typedTest() { |
127 bool isCheckedMode = false; | |
128 assert((isCheckedMode = true)); | |
129 if (!isCheckedMode) return; | |
130 | |
131 // Assign functions to typed function variables. | 127 // Assign functions to typed function variables. |
132 intToString key = (int v) => "$v"; | 128 intToString key = (int v) => "$v"; |
133 intToBool value = (int v) => v.isOdd; | 129 intToBool value = (int v) => v.isOdd; |
134 Function id = (int i) => i; | 130 Function id = (int i) => i; |
135 | 131 |
136 Expect.throws(() { | 132 Expect.throws(() { |
137 new SplayTreeMap<String, bool>.fromIterable(<int>[1, 2, 3], key: key | 133 new SplayTreeMap<String, bool>.fromIterable(<int>[1, 2, 3], key: key |
138 // No "value" map, defaults to identity, which returns int, not bool. | 134 // No "value" map, defaults to identity, which returns int, not bool. |
139 ); | 135 ); |
140 }); | 136 }); |
(...skipping 22 matching lines...) Expand all Loading... |
163 key: key, value: value); | 159 key: key, value: value); |
164 Iterable<String> keys = map.keys; | 160 Iterable<String> keys = map.keys; |
165 Iterable<bool> values = map.values; | 161 Iterable<bool> values = map.values; |
166 List<String> keyList = keys.toList(); | 162 List<String> keyList = keys.toList(); |
167 List<bool> valueList = values.toList(); | 163 List<bool> valueList = values.toList(); |
168 Expect.equals(3, keyList.length); | 164 Expect.equals(3, keyList.length); |
169 Expect.equals(3, valueList.length); | 165 Expect.equals(3, valueList.length); |
170 Expect.equals(keys.first, map.firstKey()); | 166 Expect.equals(keys.first, map.firstKey()); |
171 Expect.equals(keys.last, map.lastKey()); | 167 Expect.equals(keys.last, map.lastKey()); |
172 } | 168 } |
OLD | NEW |