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

Unified Diff: tests/corelib/splay_tree_from_iterable_test.dart

Issue 716513002: Fix type in generic type of parameters to SplayTreeMap.fromIterable. (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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sdk/lib/collection/splay_tree.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/corelib/splay_tree_from_iterable_test.dart
diff --git a/tests/corelib/splay_tree_from_iterable_test.dart b/tests/corelib/splay_tree_from_iterable_test.dart
index 18d0106930dc3d6f90f84ef8cab479e2ab3f6f76..778b0ff964e2916e9395959a8907a371e6b7d6c5 100644
--- a/tests/corelib/splay_tree_from_iterable_test.dart
+++ b/tests/corelib/splay_tree_from_iterable_test.dart
@@ -13,6 +13,7 @@ main() {
emptyIterableTest();
equalElementsTest();
genericTypeTest();
+ typedTest();
}
void defaultFunctionValuesTest() {
@@ -117,3 +118,51 @@ void genericTypeTest() {
Expect.isFalse(map is SplayTreeMap<dynamic, int>);
}
+// Test in checked mode with explicitly given types.
+void typedTest() {
+ bool isCheckedMode = false;
+ assert((isCheckedMode = true));
+ if (!isCheckedMode) return;
+
+ Expect.throws(() {
+ new SplayTreeMap<String,bool>.fromIterable(<int>[1, 2, 3],
+ key: (int v) => "$v"
+ // No "value" map, defaults to identity, which returns int, not bool.
+ );
+ });
+
+ Expect.throws(() {
+ new SplayTreeMap<String,bool>.fromIterable(<int>[1, 2, 3],
+ // No "key" map, defaults to identity, which returns int, not String.
+ value: (int v) => v.isOdd
+ );
+ });
+
+ Expect.throws(() {
+ new SplayTreeMap<String,bool>.fromIterable(<int>[1, 2, 3],
+ key: (int v) => v, // wrong type.
+ value: (int v) => v.isOdd
+ );
+ });
+
+ Expect.throws(() {
+ new SplayTreeMap<String,bool>.fromIterable(<int>[1, 2, 3],
+ key: (int v) => "$v",
+ value: (int v) => v // wrong type.
+ );
+ });
+
+ // But it works with explicit types when used correctly.
+ Map<String, bool> map =
+ new SplayTreeMap<String, bool>.fromIterable(<int>[1, 2, 3],
+ key: (int v) => "$v",
+ value: (int v) => v.isOdd);
+ Iterable<String> keys = map.keys;
+ Iterable<bool> values = map.values;
+ List<String> keyList = keys.toList();
+ List<bool> valueList = values.toList();
+ Expect.equals(3, keyList.length);
+ Expect.equals(3, valueList.length);
+ Expect.equals(keys.first, map.firstKey());
+ Expect.equals(keys.last, map.lastKey());
+}
« no previous file with comments | « sdk/lib/collection/splay_tree.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698