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 {
|
||||
|
||||
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
|
||||
|
@ -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,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()
|
||||
@ -22,6 +21,8 @@ class SpecificationTest {
|
||||
}
|
||||
}
|
||||
|
||||
class SpecificationTest {
|
||||
|
||||
// @Test
|
||||
// fun testMetaScheme(){
|
||||
// val styled = Meta {
|
||||
@ -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"
|
||||
}
|
||||
|
@ -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))
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user