Fix scheme wrapping
This commit is contained in:
parent
f946777f40
commit
027d5ed923
@ -11,7 +11,7 @@ import hep.dataforge.names.asName
|
|||||||
*/
|
*/
|
||||||
public open class Scheme() : MutableItemProvider, Described, MetaRepr {
|
public open class Scheme() : MutableItemProvider, Described, MetaRepr {
|
||||||
|
|
||||||
private var items: MutableItemProvider = MetaBuilder()
|
private var items: MutableItemProvider = Config()
|
||||||
|
|
||||||
private var default: ItemProvider? = null
|
private var default: ItemProvider? = null
|
||||||
|
|
||||||
@ -23,7 +23,7 @@ public open class Scheme() : MutableItemProvider, Described, MetaRepr {
|
|||||||
descriptor: NodeDescriptor? = null,
|
descriptor: NodeDescriptor? = null,
|
||||||
) {
|
) {
|
||||||
//use properties in the init block as default
|
//use properties in the init block as default
|
||||||
this.default = items.withDefault(default)
|
this.default = this.items.withDefault(default)
|
||||||
//reset values, defaults are already saved
|
//reset values, defaults are already saved
|
||||||
this.items = items
|
this.items = items
|
||||||
this.descriptor = descriptor
|
this.descriptor = descriptor
|
||||||
|
@ -0,0 +1,23 @@
|
|||||||
|
package hep.dataforge.meta
|
||||||
|
|
||||||
|
import kotlin.test.Test
|
||||||
|
import kotlin.test.assertEquals
|
||||||
|
|
||||||
|
class SchemeTest {
|
||||||
|
@Test
|
||||||
|
fun testSchemeWrappingBeforeEdit(){
|
||||||
|
val config = Config()
|
||||||
|
val scheme = TestScheme.wrap(config)
|
||||||
|
scheme.a = 29
|
||||||
|
assertEquals(29, config["a"].int)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testSchemeWrappingAfterEdit(){
|
||||||
|
val scheme = TestScheme.empty()
|
||||||
|
scheme.a = 29
|
||||||
|
val config = Config()
|
||||||
|
scheme.retarget(config)
|
||||||
|
assertEquals(29, scheme.a)
|
||||||
|
}
|
||||||
|
}
|
@ -3,24 +3,25 @@ package hep.dataforge.meta
|
|||||||
import kotlin.test.Test
|
import kotlin.test.Test
|
||||||
import kotlin.test.assertEquals
|
import kotlin.test.assertEquals
|
||||||
|
|
||||||
class SpecificationTest {
|
internal class TestScheme : Scheme() {
|
||||||
class TestScheme : Scheme() {
|
var list by numberList(1, 2, 3)
|
||||||
var list by numberList(1, 2, 3)
|
|
||||||
|
|
||||||
var a by int()
|
var a by int()
|
||||||
var b by string()
|
var b by string()
|
||||||
|
|
||||||
companion object : Specification<TestScheme> {
|
companion object : Specification<TestScheme> {
|
||||||
override fun empty(): TestScheme = TestScheme()
|
override fun empty(): TestScheme = TestScheme()
|
||||||
|
|
||||||
override fun read(items: ItemProvider): TestScheme =
|
override fun read(items: ItemProvider): TestScheme =
|
||||||
wrap(Config(), items)
|
wrap(Config(), items)
|
||||||
|
|
||||||
override fun write(target: MutableItemProvider, defaultProvider: ItemProvider): TestScheme =
|
override fun write(target: MutableItemProvider, defaultProvider: ItemProvider): TestScheme =
|
||||||
wrap(target, defaultProvider)
|
wrap(target, defaultProvider)
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class SpecificationTest {
|
||||||
|
|
||||||
// @Test
|
// @Test
|
||||||
// fun testMetaScheme(){
|
// fun testMetaScheme(){
|
||||||
@ -70,7 +71,7 @@ class SpecificationTest {
|
|||||||
fun testChildUpdate() {
|
fun testChildUpdate() {
|
||||||
val config = Config()
|
val config = Config()
|
||||||
val child = config.getChild("child")
|
val child = config.getChild("child")
|
||||||
val scheme = child.update(TestScheme) {
|
child.update(TestScheme) {
|
||||||
a = 22
|
a = 22
|
||||||
b = "test"
|
b = "test"
|
||||||
}
|
}
|
||||||
|
@ -38,17 +38,11 @@ class DynamicMetaTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
val dynamic = meta.toDynamic()
|
val dynamic = meta.toDynamic()
|
||||||
|
|
||||||
assertEquals(2,dynamic.array[1])
|
assertEquals(2,dynamic.array[1])
|
||||||
|
|
||||||
assertEquals(22, dynamic.a)
|
assertEquals(22, dynamic.a)
|
||||||
|
|
||||||
val keys = js("Object.keys(dynamic)") as Array<String>
|
val keys = js("Object.keys(dynamic)") as Array<String>
|
||||||
|
|
||||||
assertTrue { keys.contains("ob") }
|
assertTrue { keys.contains("ob") }
|
||||||
|
|
||||||
assertEquals(18, dynamic.ob.childNode)
|
assertEquals(18, dynamic.ob.childNode)
|
||||||
|
|
||||||
assertEquals<Meta>(meta, DynamicMeta(dynamic))
|
assertEquals<Meta>(meta, DynamicMeta(dynamic))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user