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,24 +3,25 @@ package hep.dataforge.meta
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
class SpecificationTest {
|
||||
class TestScheme : Scheme() {
|
||||
var list by numberList(1, 2, 3)
|
||||
internal class TestScheme : Scheme() {
|
||||
var list by numberList(1, 2, 3)
|
||||
|
||||
var a by int()
|
||||
var b by string()
|
||||
var a by int()
|
||||
var b by string()
|
||||
|
||||
companion object : Specification<TestScheme> {
|
||||
override fun empty(): TestScheme = TestScheme()
|
||||
companion object : Specification<TestScheme> {
|
||||
override fun empty(): TestScheme = TestScheme()
|
||||
|
||||
override fun read(items: ItemProvider): TestScheme =
|
||||
wrap(Config(), items)
|
||||
override fun read(items: ItemProvider): TestScheme =
|
||||
wrap(Config(), items)
|
||||
|
||||
override fun write(target: MutableItemProvider, defaultProvider: ItemProvider): TestScheme =
|
||||
wrap(target, defaultProvider)
|
||||
override fun write(target: MutableItemProvider, defaultProvider: ItemProvider): TestScheme =
|
||||
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"
|
||||
}
|
||||
|
@ -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