JS stdlib: added test for using special names(i.e. Object.prototype members) in Maps and Sets. Fixed the support special names in PrimitiveHashMap.

This commit is contained in:
Zalim Bashorov
2014-06-19 20:15:06 +04:00
parent 6f5c88c21f
commit 79b7b1c447
3 changed files with 77 additions and 12 deletions
+38
View File
@@ -26,6 +26,8 @@ abstract class MapJsTest {
val KEYS = array("zero", "one", "two", "three").toList()
val VALUES = array(0, 1, 2, 3).toList()
val SPECIAL_NAMES = array("__proto__", "constructor", "toString", "toLocaleString", "valueOf", "hasOwnProperty", "isPrototypeOf", "propertyIsEnumerable")
test fun getOrElse() {
val data = emptyMap()
val a = data.getOrElse("foo"){2}
@@ -246,6 +248,42 @@ abstract class MapJsTest {
assertEquals(VALUES.toNormalizedList(), actualValues.toNormalizedList())
}
test fun specialNamesNotContainsInEmptyMap() {
val map = emptyMap()
for (key in SPECIAL_NAMES) {
assertFalse(map.containsKey(key), "unexpected key: $key")
}
}
test fun specialNamesNotContainsInNonEmptyMap() {
val map = createTestMap()
for (key in SPECIAL_NAMES) {
assertFalse(map.containsKey(key), "unexpected key: $key")
}
}
test fun putAndGetSpecialNamesToMap() {
val map = createTestMutableMap()
var value = 0
for (key in SPECIAL_NAMES) {
assertFalse(map.containsKey(key), "unexpected key: $key")
map.put(key, value)
assertTrue(map.containsKey(key), "key not found: $key")
val actualValue = map.get(key)
assertEquals(value, actualValue, "wrong value fo key: $key")
map.remove(key)
assertFalse(map.containsKey(key), "unexpected key after remove: $key")
value += 3
}
}
/*
test fun createLinkedMap() {
val map = linkedMapOf("c" to 3, "b" to 2, "a" to 1)