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
+28
View File
@@ -22,6 +22,8 @@ abstract class SetJsTest {
val data: Set<String> = createTestMutableSet()
val empty: Set<String> = createEmptyMutableSet()
val SPECIAL_NAMES = array("__proto__", "constructor", "toString", "toLocaleString", "valueOf", "hasOwnProperty", "isPrototypeOf", "propertyIsEnumerable")
Test fun size() {
assertEquals(2, data.size())
assertEquals(0, empty.size())
@@ -122,6 +124,32 @@ abstract class SetJsTest {
assertTrue(data.isEmpty())
}
Test fun specialNamesNotContainsInEmptySet() {
for (element in SPECIAL_NAMES) {
assertFalse(empty.contains(element), "unexpected element: $element")
}
}
Test fun specialNamesNotContainsInNonEmptySet() {
for (element in SPECIAL_NAMES) {
assertFalse(data.contains(element), "unexpected element: $element")
}
}
Test fun putAndGetSpecialNamesToSet() {
val s = createTestMutableSet()
for (element in SPECIAL_NAMES) {
assertFalse(s.contains(element), "unexpected element: $element")
s.add(element)
assertTrue(s.contains(element), "element not found: $element")
s.remove(element)
assertFalse(s.contains(element), "unexpected element after remove: $element")
}
}
//Helpers
abstract fun createEmptyMutableSet(): MutableSet<String>