From 027d5ed923a093e152576df4fe1257e68a67ccdd Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Sun, 27 Dec 2020 17:40:34 +0300 Subject: [PATCH] Fix scheme wrapping --- .../kotlin/hep/dataforge/meta/Scheme.kt | 4 +-- .../kotlin/hep/dataforge/meta/SchemeTest.kt | 23 ++++++++++++++++ .../hep/dataforge/meta/SpecificationTest.kt | 27 ++++++++++--------- .../hep/dataforge/meta/DynamicMetaTest.kt | 6 ----- 4 files changed, 39 insertions(+), 21 deletions(-) create mode 100644 dataforge-meta/src/commonTest/kotlin/hep/dataforge/meta/SchemeTest.kt diff --git a/dataforge-meta/src/commonMain/kotlin/hep/dataforge/meta/Scheme.kt b/dataforge-meta/src/commonMain/kotlin/hep/dataforge/meta/Scheme.kt index b2a82ca7..1f1b3b4d 100644 --- a/dataforge-meta/src/commonMain/kotlin/hep/dataforge/meta/Scheme.kt +++ b/dataforge-meta/src/commonMain/kotlin/hep/dataforge/meta/Scheme.kt @@ -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 diff --git a/dataforge-meta/src/commonTest/kotlin/hep/dataforge/meta/SchemeTest.kt b/dataforge-meta/src/commonTest/kotlin/hep/dataforge/meta/SchemeTest.kt new file mode 100644 index 00000000..2dfd746c --- /dev/null +++ b/dataforge-meta/src/commonTest/kotlin/hep/dataforge/meta/SchemeTest.kt @@ -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) + } +} \ No newline at end of file diff --git a/dataforge-meta/src/commonTest/kotlin/hep/dataforge/meta/SpecificationTest.kt b/dataforge-meta/src/commonTest/kotlin/hep/dataforge/meta/SpecificationTest.kt index ddf06c1b..cd8b2f82 100644 --- a/dataforge-meta/src/commonTest/kotlin/hep/dataforge/meta/SpecificationTest.kt +++ b/dataforge-meta/src/commonTest/kotlin/hep/dataforge/meta/SpecificationTest.kt @@ -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 { - override fun empty(): TestScheme = TestScheme() + companion object : Specification { + 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" } diff --git a/dataforge-meta/src/jsTest/kotlin/hep/dataforge/meta/DynamicMetaTest.kt b/dataforge-meta/src/jsTest/kotlin/hep/dataforge/meta/DynamicMetaTest.kt index a2dc2de9..1fabf061 100644 --- a/dataforge-meta/src/jsTest/kotlin/hep/dataforge/meta/DynamicMetaTest.kt +++ b/dataforge-meta/src/jsTest/kotlin/hep/dataforge/meta/DynamicMetaTest.kt @@ -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 - assertTrue { keys.contains("ob") } - assertEquals(18, dynamic.ob.childNode) - assertEquals(meta, DynamicMeta(dynamic)) }