Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(12)

Side by Side Diff: tests/corelib/splay_tree_from_iterable_test.dart

Issue 710063002: Change SplayTreeMap test to not cause static type warnings, only runtime errors. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
117 Expect.isFalse(map is SplayTreeMap<String, dynamic>); 117 Expect.isFalse(map is SplayTreeMap<String, dynamic>);
118 Expect.isFalse(map is SplayTreeMap<dynamic, int>); 118 Expect.isFalse(map is SplayTreeMap<dynamic, int>);
119 } 119 }
120 120
121 // Test in checked mode with explicitly given types. 121 // Test in checked mode with explicitly given types.
122 void typedTest() { 122 void typedTest() {
123 bool isCheckedMode = false; 123 bool isCheckedMode = false;
124 assert((isCheckedMode = true)); 124 assert((isCheckedMode = true));
125 if (!isCheckedMode) return; 125 if (!isCheckedMode) return;
126 126
127 // Assign functions to untyped function variables.
128 Function key = (int v) => "$v";
129 Function value = (int v) => v.isOdd;
130 Function id = (int i) => i;
131
127 Expect.throws(() { 132 Expect.throws(() {
128 new SplayTreeMap<String,bool>.fromIterable(<int>[1, 2, 3], 133 new SplayTreeMap<String,bool>.fromIterable(<int>[1, 2, 3],
129 key: (int v) => "$v" 134 key: key
130 // No "value" map, defaults to identity, which returns int, not bool. 135 // No "value" map, defaults to identity, which returns int, not bool.
131 ); 136 );
132 }); 137 });
133 138
134 Expect.throws(() { 139 Expect.throws(() {
135 new SplayTreeMap<String,bool>.fromIterable(<int>[1, 2, 3], 140 new SplayTreeMap<String,bool>.fromIterable(<int>[1, 2, 3],
136 // No "key" map, defaults to identity, which returns int, not String. 141 // No "key" map, defaults to identity, which returns int, not String.
137 value: (int v) => v.isOdd 142 value: value
138 ); 143 );
139 }); 144 });
140 145
141 Expect.throws(() { 146 Expect.throws(() {
142 new SplayTreeMap<String,bool>.fromIterable(<int>[1, 2, 3], 147 new SplayTreeMap<String,bool>.fromIterable(<int>[1, 2, 3],
143 key: (int v) => v, // wrong type. 148 key: id, // wrong type.
144 value: (int v) => v.isOdd 149 value: value
145 ); 150 );
146 }); 151 });
147 152
148 Expect.throws(() { 153 Expect.throws(() {
149 new SplayTreeMap<String,bool>.fromIterable(<int>[1, 2, 3], 154 new SplayTreeMap<String,bool>.fromIterable(<int>[1, 2, 3],
150 key: (int v) => "$v", 155 key: key,
151 value: (int v) => v // wrong type. 156 value: id // wrong type.
152 ); 157 );
153 }); 158 });
154 159
155 // But it works with explicit types when used correctly. 160 // But it works with explicit types when used correctly.
156 Map<String, bool> map = 161 SplayTreeMap<String, bool> map =
157 new SplayTreeMap<String, bool>.fromIterable(<int>[1, 2, 3], 162 new SplayTreeMap<String, bool>.fromIterable(<int>[1, 2, 3],
158 key: (int v) => "$v", 163 key: key,
159 value: (int v) => v.isOdd); 164 value: value);
160 Iterable<String> keys = map.keys; 165 Iterable<String> keys = map.keys;
161 Iterable<bool> values = map.values; 166 Iterable<bool> values = map.values;
162 List<String> keyList = keys.toList(); 167 List<String> keyList = keys.toList();
163 List<bool> valueList = values.toList(); 168 List<bool> valueList = values.toList();
164 Expect.equals(3, keyList.length); 169 Expect.equals(3, keyList.length);
165 Expect.equals(3, valueList.length); 170 Expect.equals(3, valueList.length);
166 Expect.equals(keys.first, map.firstKey()); 171 Expect.equals(keys.first, map.firstKey());
167 Expect.equals(keys.last, map.lastKey()); 172 Expect.equals(keys.last, map.lastKey());
168 } 173 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698