add test to descriptor default

This commit is contained in:
Alexander Nozik 2020-04-13 16:10:46 +03:00
parent 0434360d46
commit 7c68fc6e85
2 changed files with 12 additions and 1 deletions

View File

@ -1,5 +1,6 @@
package hep.dataforge.meta.descriptors
import hep.dataforge.meta.Laminate
import hep.dataforge.meta.MetaBase
import hep.dataforge.meta.MetaItem
import hep.dataforge.names.NameToken
@ -15,8 +16,10 @@ class DescriptorMeta(val descriptor: NodeDescriptor) : MetaBase() {
}
}
fun NodeDescriptor.buildDefaultMeta() = Laminate(default, DescriptorMeta(this))
fun NodeDescriptor.defaultItem(): MetaItem.NodeItem<*> =
MetaItem.NodeItem(default ?: DescriptorMeta(this))
MetaItem.NodeItem(buildDefaultMeta())
fun ValueDescriptor.defaultItem(): MetaItem.ValueItem = MetaItem.ValueItem(default ?: Null)

View File

@ -1,5 +1,7 @@
package hep.dataforge.meta.descriptors
import hep.dataforge.meta.boolean
import hep.dataforge.meta.get
import hep.dataforge.values.ValueType
import kotlin.test.Test
import kotlin.test.assertEquals
@ -31,4 +33,10 @@ class DescriptorTest {
val allowed = descriptor.nodes["aNode"]?.values?.get("b")?.allowedValues
assertEquals(emptyList(), allowed)
}
@Test
fun testDefaultMetaNode(){
val meta = descriptor.buildDefaultMeta()
assertEquals(false, meta["aNode.otherNode.otherValue"].boolean)
}
}