Fix scheme wrapping

This commit is contained in:
Alexander Nozik 2020-12-27 17:40:34 +03:00
parent f946777f40
commit 027d5ed923
4 changed files with 39 additions and 21 deletions

View File

@ -11,7 +11,7 @@ import hep.dataforge.names.asName
*/
public open class Scheme() : MutableItemProvider, Described, MetaRepr {
private var items: MutableItemProvider = MetaBuilder()
private var items: MutableItemProvider = Config()
private var default: ItemProvider? = null
@ -23,7 +23,7 @@ public open class Scheme() : MutableItemProvider, Described, MetaRepr {
descriptor: NodeDescriptor? = null,
) {
//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
this.items = items
this.descriptor = descriptor

View File

@ -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)
}
}

View File

@ -3,8 +3,7 @@ package hep.dataforge.meta
import kotlin.test.Test
import kotlin.test.assertEquals
class SpecificationTest {
class TestScheme : Scheme() {
internal class TestScheme : Scheme() {
var list by numberList(1, 2, 3)
var a by int()
@ -20,7 +19,9 @@ class SpecificationTest {
wrap(target, defaultProvider)
}
}
}
class SpecificationTest {
// @Test
// fun testMetaScheme(){
@ -70,7 +71,7 @@ class SpecificationTest {
fun testChildUpdate() {
val config = Config()
val child = config.getChild("child")
val scheme = child.update(TestScheme) {
child.update(TestScheme) {
a = 22
b = "test"
}

View File

@ -38,17 +38,11 @@ class DynamicMetaTest {
}
val dynamic = meta.toDynamic()
assertEquals(2,dynamic.array[1])
assertEquals(22, dynamic.a)
val keys = js("Object.keys(dynamic)") as Array<String>
assertTrue { keys.contains("ob") }
assertEquals(18, dynamic.ob.childNode)
assertEquals<Meta>(meta, DynamicMeta(dynamic))
}