Index: tests/corelib/splay_tree_test.dart |
diff --git a/tests/corelib/splay_tree_test.dart b/tests/corelib/splay_tree_test.dart |
index 80a1742640783f9040cc528e72bc07dd117ed490..c6de49736b6fbb9b14bc581de80f801ad4a8f24c 100644 |
--- a/tests/corelib/splay_tree_test.dart |
+++ b/tests/corelib/splay_tree_test.dart |
@@ -53,6 +53,7 @@ main() { |
testSetFrom(); |
regressRemoveWhere(); |
regressRemoveWhere2(); |
+ regressFromCompare(); |
} |
void regressRemoveWhere() { |
@@ -93,3 +94,45 @@ void testSetFrom() { |
set2 = new SplayTreeSet<int>.from(set1.where((x) => x is int)); |
Expect.equals(3, set2.length); |
} |
+ |
+ |
+ |
+void regressFromCompare() { |
+ // Regression test for http://dartbug.com/23387. |
+ // The compare and isValidKey arguments to SplayTreeMap.from were ignored. |
+ |
+ int compare(a, b) { |
+ if (a is IncomparableKey && b is IncomparableKey) { |
+ return b.id - a.id; |
+ } |
+ throw "isValidKey failure"; |
+ } |
+ bool isValidKey(o) => o is IncomparableKey; |
+ IncomparableKey key(int n) => new IncomparableKey(n); |
+ |
+ var entries = {key(0): 0, key(1): 1, key(2): 2, key(0): 0}; |
+ Expect.equals(4, entries.length); |
+ var map = new SplayTreeMap<IncomparableKey, int>.from( |
+ entries, compare, isValidKey); |
+ Expect.equals(3, map.length); |
+ for (int i = 0; i < 3; i++) { |
+ Expect.isTrue(map.containsKey(key(i))); |
+ Expect.equals(i, map[key(i)]); |
+ } |
+ Expect.isFalse(map.containsKey(key(5))); |
+ Expect.isFalse(map.containsKey(1)); |
+ Expect.isFalse(map.containsKey("string")); |
+ Expect.equals(null, map[key(5)]); |
+ Expect.equals(null, map[1]); |
+ Expect.equals(null, map["string"]); |
+ Expect.throws(() { map[1] = 42; }); |
+ Expect.throws(() { map["string"] = 42; }); |
+ map[key(5)] = 42; |
+ Expect.equals(4, map.length); |
+ Expect.equals(42, map[key(5)]); |
+} |
+ |
+class IncomparableKey { |
+ final int id; |
+ IncomparableKey(this.id); |
+} |