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 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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; | 127 bool isCheckedMode = false; |
128 assert((isCheckedMode = true)); | 128 assert((isCheckedMode = true)); |
129 if (!isCheckedMode) return; | 129 if (!isCheckedMode) return; |
Bob Nystrom
2017/07/24 22:27:43
Dart 2.0 doesn't have checked mode anymore (or, pe
| |
130 | 130 |
131 // Assign functions to typed function variables. | 131 // Assign functions to typed function variables. |
132 intToString key = (int v) => "$v"; | 132 intToString key = (int v) => "$v"; |
133 intToBool value = (int v) => v.isOdd; | 133 intToBool value = (int v) => v.isOdd; |
134 Function id = (int i) => i; | 134 Function id = (int i) => i; |
135 | 135 |
136 Expect.throws(() { | 136 Expect.throws(() { |
137 new SplayTreeMap<String, bool>.fromIterable(<int>[1, 2, 3], key: key | 137 new SplayTreeMap<String, bool>.fromIterable(<int>[1, 2, 3], key: key |
138 // No "value" map, defaults to identity, which returns int, not bool. | 138 // No "value" map, defaults to identity, which returns int, not bool. |
139 ); | 139 ); |
(...skipping 23 matching lines...) Expand all Loading... | |
163 key: key, value: value); | 163 key: key, value: value); |
164 Iterable<String> keys = map.keys; | 164 Iterable<String> keys = map.keys; |
165 Iterable<bool> values = map.values; | 165 Iterable<bool> values = map.values; |
166 List<String> keyList = keys.toList(); | 166 List<String> keyList = keys.toList(); |
167 List<bool> valueList = values.toList(); | 167 List<bool> valueList = values.toList(); |
168 Expect.equals(3, keyList.length); | 168 Expect.equals(3, keyList.length); |
169 Expect.equals(3, valueList.length); | 169 Expect.equals(3, valueList.length); |
170 Expect.equals(keys.first, map.firstKey()); | 170 Expect.equals(keys.first, map.firstKey()); |
171 Expect.equals(keys.last, map.lastKey()); | 171 Expect.equals(keys.last, map.lastKey()); |
172 } | 172 } |
OLD | NEW |