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:
@@ -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>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user