Skip to content

Commit

Permalink
Add tests to ensure #KT-10786 Fixed and #KT-8724 Fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
ilya-g committed Sep 24, 2016
1 parent 26cbad8 commit 1ea0219
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions libraries/stdlib/test/js/MapJsTest.kt
Expand Up @@ -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()

Expand Down

0 comments on commit 1ea0219

Please sign in to comment.