Drop complicated MapAccessors. Deprecate simple cases of Delegates.mapVar and Delegates.mapVal in favor of direct delegation without wrappers.
This commit is contained in:
@@ -64,48 +64,3 @@ class VarByMapExtensionsTest {
|
||||
assertEquals(null, d)
|
||||
}
|
||||
}
|
||||
|
||||
class ValByMapAccessorExtensionsTest {
|
||||
val map: Map<String, String> = mapOf("a" to "all", "b" to "bar", "c" to "code")
|
||||
val genericMap = mapOf<String, Any?>("i" to 1, "x" to 1.0)
|
||||
|
||||
val mapAccessor = map.forProperties { it.name.take(1) }
|
||||
val genericMapAccessor = genericMap.forProperties { it.name.take(1) }
|
||||
|
||||
val cProperty by mapAccessor
|
||||
val xProperty by genericMapAccessor
|
||||
val zNoDefault by genericMapAccessor
|
||||
val zProperty by genericMapAccessor.withDefault { 1 }
|
||||
|
||||
test fun doTest() {
|
||||
assertEquals("code", cProperty)
|
||||
assertEquals(1.0, xProperty)
|
||||
assertEquals(1, zProperty)
|
||||
fails { zNoDefault }
|
||||
}
|
||||
}
|
||||
|
||||
class VarByMapAccessorExtensionsTest {
|
||||
val map = hashMapOf<String, Any?>("xProperty" to 1.0)
|
||||
|
||||
val mapAccessor = map.forProperties { it.name + "Property" }
|
||||
|
||||
var x: Double by mapAccessor.withDefault { 2.0 }
|
||||
var z: Int by mapAccessor
|
||||
var s: String by mapAccessor
|
||||
|
||||
test fun doTest() {
|
||||
assertEquals(1.0, x)
|
||||
|
||||
map.remove("xProperty")
|
||||
assertEquals(2.0, x)
|
||||
|
||||
z = 2
|
||||
assertEquals(2, z)
|
||||
assertEquals(2, map["zProperty"])
|
||||
|
||||
fails { s }
|
||||
map["sProperty"] = null
|
||||
s // fails { s } // does not fail due to KT-8135
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user