Add tests to ensure #KT-10786 Fixed and #KT-8724 Fixed
This commit is contained in:
@@ -329,6 +329,66 @@ abstract class MapJsTest {
|
||||
assertEquals(VALUES.toNormalizedList(), actualValues.toNormalizedList())
|
||||
}
|
||||
|
||||
@test fun mapMutableIterator() {
|
||||
val map = createTestMutableMap()
|
||||
map.keys.removeAll { it == KEYS[0] }
|
||||
map.entries.removeAll { it.key == KEYS[1] }
|
||||
map.values.removeAll { it == VALUES[3] }
|
||||
|
||||
assertEquals(1, map.size, "Expected 1 entry to remain in map, but got: $map")
|
||||
}
|
||||
|
||||
@test fun mapCollectionPropertiesAreViews() {
|
||||
val map = createTestMutableMap()
|
||||
assertTrue(map.size >= 3)
|
||||
val keys = map.keys
|
||||
val values = map.values
|
||||
val entries = map.entries
|
||||
|
||||
val (key, value) = map.entries.first()
|
||||
|
||||
map.remove(key)
|
||||
assertFalse(key in keys, "remove from map")
|
||||
assertFalse(value in values)
|
||||
assertFalse(entries.any { it.key == key })
|
||||
|
||||
map.put(key, value)
|
||||
assertTrue(key in keys, "put to map")
|
||||
assertTrue(value in values)
|
||||
assertTrue(entries.any { it.key == key })
|
||||
|
||||
keys -= key
|
||||
assertFalse(key in map, "remove from keys")
|
||||
assertFalse(value in values)
|
||||
assertFalse(entries.any { it.key == key })
|
||||
|
||||
val (key2, value2) = map.entries.first()
|
||||
values -= value2
|
||||
assertFalse(key2 in map, "remove from values")
|
||||
assertFalse(map.containsValue(value2))
|
||||
assertFalse(entries.any { it.value == value2 })
|
||||
|
||||
val entry = map.entries.first()
|
||||
entries -= entry
|
||||
assertFalse(entry.key in map, "remove from entries")
|
||||
assertFalse(entry.key in keys)
|
||||
assertFalse(entry.value in values)
|
||||
|
||||
val entry2 = map.entries.first()
|
||||
entry2.setValue(100)
|
||||
assertEquals(100, map[entry2.key], "set value via entry")
|
||||
}
|
||||
|
||||
@test fun mapCollectionPropertiesDoNotSupportAdd() {
|
||||
val map = createTestMutableMap()
|
||||
val entry = map.entries.first()
|
||||
val (key, value) = entry
|
||||
|
||||
assertFailsWith<UnsupportedOperationException> { map.entries += entry }
|
||||
assertFailsWith<UnsupportedOperationException> { map.keys += key }
|
||||
assertFailsWith<UnsupportedOperationException> { map.values += value }
|
||||
}
|
||||
|
||||
@test fun specialNamesNotContainsInEmptyMap() {
|
||||
val map = emptyMap()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user