Map.getOrImplicitDefault is exposed public as Map.getValue
#KT-11851
This commit is contained in:
@@ -28,14 +28,15 @@ class MapTest {
|
||||
assertEquals("x", d)
|
||||
}
|
||||
|
||||
@Suppress("INVISIBLE_MEMBER")
|
||||
@Test fun getOrImplicitDefault() {
|
||||
@Test fun getValue() {
|
||||
val data: MutableMap<String, Int> = hashMapOf("bar" to 1)
|
||||
assertFailsWith<NoSuchElementException> { data.getOrImplicitDefault("foo") }
|
||||
assertEquals(1, data.getOrImplicitDefault("bar"))
|
||||
assertFailsWith<NoSuchElementException> { data.getValue("foo") }.let { e ->
|
||||
assertTrue("foo" in e.message!!)
|
||||
}
|
||||
assertEquals(1, data.getValue("bar"))
|
||||
|
||||
val mutableWithDefault = data.withDefault { 42 }
|
||||
assertEquals(42, mutableWithDefault.getOrImplicitDefault("foo"))
|
||||
assertEquals(42, mutableWithDefault.getValue("foo"))
|
||||
|
||||
// verify that it is wrapper
|
||||
mutableWithDefault["bar"] = 2
|
||||
@@ -44,10 +45,10 @@ class MapTest {
|
||||
assertEquals(3, mutableWithDefault["bar"])
|
||||
|
||||
val readonlyWithDefault = (data as Map<String, Int>).withDefault { it.length }
|
||||
assertEquals(4, readonlyWithDefault.getOrImplicitDefault("loop"))
|
||||
assertEquals(4, readonlyWithDefault.getValue("loop"))
|
||||
|
||||
val withReplacedDefault = readonlyWithDefault.withDefault { 42 }
|
||||
assertEquals(42, withReplacedDefault.getOrImplicitDefault("loop"))
|
||||
assertEquals(42, withReplacedDefault.getValue("loop"))
|
||||
}
|
||||
|
||||
@Test fun getOrPut() {
|
||||
|
||||
Reference in New Issue
Block a user