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

Unified Diff: tests/corelib/map_test.dart

Issue 12827018: Add a new implementation of HashMap that uses JS objects for its (multiple) hash tables. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Prefer local variable. Created 7 years, 9 months 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
Index: tests/corelib/map_test.dart
diff --git a/tests/corelib/map_test.dart b/tests/corelib/map_test.dart
index d405471b2459ba1e58989ca9ab52ac49d5e4f5dd..cca54cfdcfda42360a8e9c483dbd920bb98360b5 100644
--- a/tests/corelib/map_test.dart
+++ b/tests/corelib/map_test.dart
@@ -14,8 +14,25 @@ void main() {
testMapLiteral();
testNullValue();
testTypes();
+
+ testWeirdKeys(new Map());
+ testWeirdKeys(new Map<String, String>());
+ testWeirdKeys(new HashMap());
+ testWeirdKeys(new HashMap<String, String>());
+ testWeirdKeys(new LinkedHashMap());
+ testWeirdKeys(new LinkedHashMap<String, String>());
+ testWeirdKeys(new SplayTreeMap());
+ testWeirdKeys(new SplayTreeMap<String, String>());
+
+ // BUG(9368): Enable these tests.
+ if (false) {
+ Expect.isFalse(new Map<int, num>() is Map<String, num>);
+ Expect.isFalse(new HashMap<int, num>() is Map<String, num>);
+ Expect.isFalse(new LinkedHashMap<int, num>() is Map<String, num>);
+ }
}
+
void test(Map map) {
testDeletedElement(map);
testMap(map, 1, 2, 3, 4, 5, 6, 7, 8);
@@ -134,52 +151,52 @@ void testMap(Map map, key1, key2, key3, key4, key5, key6, key7, key8) {
Expect.equals(true, map.containsValue(value1));
// Test Map.forEach.
- Map other_map = new Map();
+ Map otherMap = new Map();
void testForEachMap(key, value) {
- other_map[key] = value;
+ otherMap[key] = value;
}
map.forEach(testForEachMap);
- Expect.equals(true, other_map.containsKey(key1));
- Expect.equals(true, other_map.containsKey(key2));
- Expect.equals(true, other_map.containsValue(value1));
- Expect.equals(true, other_map.containsValue(value2));
- Expect.equals(2, other_map.length);
+ Expect.equals(true, otherMap.containsKey(key1));
+ Expect.equals(true, otherMap.containsKey(key2));
+ Expect.equals(true, otherMap.containsValue(value1));
+ Expect.equals(true, otherMap.containsValue(value2));
+ Expect.equals(2, otherMap.length);
- other_map.clear();
- Expect.equals(0, other_map.length);
+ otherMap.clear();
+ Expect.equals(0, otherMap.length);
// Test Collection.keys.
void testForEachCollection(value) {
- other_map[value] = value;
+ otherMap[value] = value;
}
Iterable keys = map.keys;
keys.forEach(testForEachCollection);
- Expect.equals(true, other_map.containsKey(key1));
- Expect.equals(true, other_map.containsKey(key2));
- Expect.equals(true, other_map.containsValue(key1));
- Expect.equals(true, other_map.containsValue(key2));
- Expect.equals(true, !other_map.containsKey(value1));
- Expect.equals(true, !other_map.containsKey(value2));
- Expect.equals(true, !other_map.containsValue(value1));
- Expect.equals(true, !other_map.containsValue(value2));
- Expect.equals(2, other_map.length);
- other_map.clear();
- Expect.equals(0, other_map.length);
+ Expect.equals(true, otherMap.containsKey(key1));
+ Expect.equals(true, otherMap.containsKey(key2));
+ Expect.equals(true, otherMap.containsValue(key1));
+ Expect.equals(true, otherMap.containsValue(key2));
+ Expect.equals(true, !otherMap.containsKey(value1));
+ Expect.equals(true, !otherMap.containsKey(value2));
+ Expect.equals(true, !otherMap.containsValue(value1));
+ Expect.equals(true, !otherMap.containsValue(value2));
+ Expect.equals(2, otherMap.length);
+ otherMap.clear();
+ Expect.equals(0, otherMap.length);
// Test Collection.values.
Iterable values = map.values;
values.forEach(testForEachCollection);
- Expect.equals(true, !other_map.containsKey(key1));
- Expect.equals(true, !other_map.containsKey(key2));
- Expect.equals(true, !other_map.containsValue(key1));
- Expect.equals(true, !other_map.containsValue(key2));
- Expect.equals(true, other_map.containsKey(value1));
- Expect.equals(true, other_map.containsKey(value2));
- Expect.equals(true, other_map.containsValue(value1));
- Expect.equals(true, other_map.containsValue(value2));
- Expect.equals(2, other_map.length);
- other_map.clear();
- Expect.equals(0, other_map.length);
+ Expect.equals(true, !otherMap.containsKey(key1));
+ Expect.equals(true, !otherMap.containsKey(key2));
+ Expect.equals(true, !otherMap.containsValue(key1));
+ Expect.equals(true, !otherMap.containsValue(key2));
+ Expect.equals(true, otherMap.containsKey(value1));
+ Expect.equals(true, otherMap.containsKey(value2));
+ Expect.equals(true, otherMap.containsValue(value1));
+ Expect.equals(true, otherMap.containsValue(value2));
+ Expect.equals(2, otherMap.length);
+ otherMap.clear();
+ Expect.equals(0, otherMap.length);
// Test Map.putIfAbsent.
map.clear();
@@ -245,7 +262,7 @@ void testNullValue() {
}
void testTypes() {
- Map<int> map;
+ Map<int, dynamic> map;
testMap(Map map) {
map[42] = "text";
map[43] = "text";
@@ -264,3 +281,32 @@ void testTypes() {
testMap(new SplayTreeMap<num, String>(Comparable.compare));
testMap(new SplayTreeMap<num, String>((num a, num b) => a.compareTo(b)));
}
+
+void testWeirdKeys(Map map) {
+ // Test weird keys.
+ var weirdKeys = const [
+ 'hasOwnProperty',
+ 'constructor',
erikcorry 2013/03/22 12:59:24 Please add __proto__, __count__, __parent__, NaN a
+ 'toLocaleString',
+ 'propertyIsEnumerable',
+ '__defineGetter__',
+ '__defineSetter__',
+ '__lookupGetter__',
+ '__lookupSetter__',
+ 'isPrototypeOf',
+ 'toString',
+ 'valueOf' ];
+ Expect.isTrue(map.isEmpty);
+ for (var key in weirdKeys) {
+ Expect.isFalse(map.containsKey(key));
+ Expect.equals(null, map[key]);
+ var value = 'value:$key';
+ map[key] = value;
+ Expect.isTrue(map.containsKey(key));
+ Expect.equals(value, map[key]);
+ Expect.equals(value, map.remove(key));
+ Expect.isFalse(map.containsKey(key));
+ Expect.equals(null, map[key]);
+ }
+ Expect.isTrue(map.isEmpty);
+}

Powered by Google App Engine
This is Rietveld 408576698