Fix #16
This commit is contained in:
parent
dce9199b78
commit
245b5ebc52
@ -105,8 +105,8 @@ open class Context(
|
||||
|
||||
override fun toMeta(): Meta = buildMeta {
|
||||
"parent" to parent?.name
|
||||
"properties" to properties.seal()
|
||||
"plugins" to plugins.map { it.toMeta() }
|
||||
"properties" put properties.seal()
|
||||
"plugins" put plugins.map { it.toMeta() }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -66,10 +66,10 @@ interface Plugin : Named, ContextAware, Provider, MetaRepr {
|
||||
fun detach()
|
||||
|
||||
override fun toMeta(): Meta = buildMeta {
|
||||
"context" to context.name
|
||||
"context" put context.name.toString()
|
||||
"type" to this::class.simpleName
|
||||
"tag" to tag
|
||||
"meta" to meta
|
||||
"tag" put tag
|
||||
"meta" put meta
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
@ -37,9 +37,9 @@ data class PluginTag(
|
||||
override fun toString(): String = listOf(group, name, version).joinToString(separator = ":")
|
||||
|
||||
override fun toMeta(): Meta = buildMeta {
|
||||
"name" to name
|
||||
"group" to group
|
||||
"version" to version
|
||||
"name" put name
|
||||
"group" put group
|
||||
"version" put version
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
@ -20,9 +20,9 @@ interface Data<out T : Any> : Goal<T>, MetaRepr{
|
||||
val meta: Meta
|
||||
|
||||
override fun toMeta(): Meta = buildMeta {
|
||||
"type" to (type.simpleName?:"undefined")
|
||||
"type" put (type.simpleName?:"undefined")
|
||||
if(!meta.isEmpty()) {
|
||||
"meta" to meta
|
||||
"meta" put meta
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -39,10 +39,10 @@ interface DataNode<out T : Any> : MetaRepr {
|
||||
val items: Map<NameToken, DataItem<T>>
|
||||
|
||||
override fun toMeta(): Meta = buildMeta {
|
||||
"type" to (type.simpleName ?: "undefined")
|
||||
"items" to {
|
||||
"type" put (type.simpleName ?: "undefined")
|
||||
"items" put {
|
||||
this@DataNode.items.forEach {
|
||||
it.key.toString() to it.value.toMeta()
|
||||
it.key.toString() put it.value.toMeta()
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -196,19 +196,19 @@ class DataTreeBuilder<T : Any>(val type: KClass<out T>) {
|
||||
/**
|
||||
* Append data to node
|
||||
*/
|
||||
infix fun String.to(data: Data<T>) = set(toName(), data)
|
||||
infix fun String.put(data: Data<T>) = set(toName(), data)
|
||||
|
||||
/**
|
||||
* Append node
|
||||
*/
|
||||
infix fun String.to(node: DataNode<T>) = set(toName(), node)
|
||||
infix fun String.put(node: DataNode<T>) = set(toName(), node)
|
||||
|
||||
infix fun String.to(item: DataItem<T>) = set(toName(), item)
|
||||
infix fun String.put(item: DataItem<T>) = set(toName(), item)
|
||||
|
||||
/**
|
||||
* Build and append node
|
||||
*/
|
||||
infix fun String.to(block: DataTreeBuilder<T>.() -> Unit) = set(toName(), DataTreeBuilder(type).apply(block))
|
||||
infix fun String.put(block: DataTreeBuilder<T>.() -> Unit) = set(toName(), DataTreeBuilder(type).apply(block))
|
||||
|
||||
|
||||
fun update(node: DataNode<T>) {
|
||||
|
@ -8,9 +8,9 @@ internal class DataTreeBuilderTest{
|
||||
@Test
|
||||
fun testDataUpdate(){
|
||||
val updateData = DataNode<Any>{
|
||||
"update" to {
|
||||
"a" to Data.static("a")
|
||||
"b" to Data.static("b")
|
||||
"update" put {
|
||||
"a" put Data.static("a")
|
||||
"b" put Data.static("b")
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -14,18 +14,18 @@ class YamlMetaFormatTest{
|
||||
@Test
|
||||
fun testYamlMetaFormat(){
|
||||
val meta = buildMeta {
|
||||
"a" to 22
|
||||
"node" to {
|
||||
"b" to "DDD"
|
||||
"c" to 11.1
|
||||
"d" to {
|
||||
"d1" to {
|
||||
"d11" to "aaa"
|
||||
"d12" to "bbb"
|
||||
"a" put 22
|
||||
"node" put {
|
||||
"b" put "DDD"
|
||||
"c" put 11.1
|
||||
"d" put {
|
||||
"d1" put {
|
||||
"d11" put "aaa"
|
||||
"d12" put "bbb"
|
||||
}
|
||||
"d2" to 2
|
||||
"d2" put 2
|
||||
}
|
||||
"array" to doubleArrayOf(1.0, 2.0, 3.0)
|
||||
"array" put doubleArrayOf(1.0, 2.0, 3.0)
|
||||
}
|
||||
}
|
||||
val string = meta.toString(YamlMetaFormat)
|
||||
|
@ -33,7 +33,7 @@ class RemoteFunctionClient(override val context: Context, val responder: Respond
|
||||
meta(meta)
|
||||
type = REQUEST_TYPE
|
||||
meta {
|
||||
SIZE_KEY to values.size
|
||||
SIZE_KEY put values.size
|
||||
}
|
||||
data {
|
||||
val inputFormat: IOFormat<T> = getInputFormat(meta, valueType)
|
||||
|
@ -8,7 +8,7 @@ class EnvelopeFormatTest {
|
||||
val envelope = Envelope.invoke {
|
||||
type = "test.format"
|
||||
meta{
|
||||
"d" to 22.2
|
||||
"d" put 22.2
|
||||
}
|
||||
data{
|
||||
writeDouble(22.2)
|
||||
|
@ -11,11 +11,11 @@ class MetaFormatTest {
|
||||
@Test
|
||||
fun testBinaryMetaFormat() {
|
||||
val meta = buildMeta {
|
||||
"a" to 22
|
||||
"node" to {
|
||||
"b" to "DDD"
|
||||
"c" to 11.1
|
||||
"array" to doubleArrayOf(1.0, 2.0, 3.0)
|
||||
"a" put 22
|
||||
"node" put {
|
||||
"b" put "DDD"
|
||||
"c" put 11.1
|
||||
"array" put doubleArrayOf(1.0, 2.0, 3.0)
|
||||
}
|
||||
}
|
||||
val bytes = meta.toBytes(BinaryMetaFormat)
|
||||
@ -26,11 +26,11 @@ class MetaFormatTest {
|
||||
@Test
|
||||
fun testJsonMetaFormat() {
|
||||
val meta = buildMeta {
|
||||
"a" to 22
|
||||
"node" to {
|
||||
"b" to "DDD"
|
||||
"c" to 11.1
|
||||
"array" to doubleArrayOf(1.0, 2.0, 3.0)
|
||||
"a" put 22
|
||||
"node" put {
|
||||
"b" put "DDD"
|
||||
"c" put 11.1
|
||||
"array" put doubleArrayOf(1.0, 2.0, 3.0)
|
||||
}
|
||||
}
|
||||
val string = meta.toString(JsonMetaFormat)
|
||||
|
@ -14,11 +14,11 @@ class MetaSerializerTest {
|
||||
@Test
|
||||
fun testMetaSerialization() {
|
||||
val meta = buildMeta {
|
||||
"a" to 22
|
||||
"node" to {
|
||||
"b" to "DDD"
|
||||
"c" to 11.1
|
||||
"array" to doubleArrayOf(1.0, 2.0, 3.0)
|
||||
"a" put 22
|
||||
"node" put {
|
||||
"b" put "DDD"
|
||||
"c" put 11.1
|
||||
"array" put doubleArrayOf(1.0, 2.0, 3.0)
|
||||
}
|
||||
}
|
||||
|
||||
@ -30,11 +30,11 @@ class MetaSerializerTest {
|
||||
@Test
|
||||
fun testCborSerialization() {
|
||||
val meta = buildMeta {
|
||||
"a" to 22
|
||||
"node" to {
|
||||
"b" to "DDD"
|
||||
"c" to 11.1
|
||||
"array" to doubleArrayOf(1.0, 2.0, 3.0)
|
||||
"a" put 22
|
||||
"node" put {
|
||||
"b" put "DDD"
|
||||
"c" put 11.1
|
||||
"array" put doubleArrayOf(1.0, 2.0, 3.0)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -26,9 +26,9 @@ fun IOPlugin.resolveIOFormatName(type: KClass<*>): Name {
|
||||
}
|
||||
|
||||
inline fun <reified T : Any, reified R : Any> IOPlugin.generateFunctionMeta(functionName: String): Meta = buildMeta {
|
||||
FUNCTION_NAME_KEY to functionName
|
||||
INPUT_FORMAT_KEY to resolveIOFormatName(T::class)
|
||||
OUTPUT_FORMAT_KEY to resolveIOFormatName(R::class)
|
||||
FUNCTION_NAME_KEY put functionName
|
||||
INPUT_FORMAT_KEY put resolveIOFormatName(T::class).toString()
|
||||
OUTPUT_FORMAT_KEY put resolveIOFormatName(R::class).toString()
|
||||
}
|
||||
|
||||
inline fun <reified T : Any, reified R : Any> FunctionServer.function(
|
||||
|
@ -9,8 +9,8 @@ import kotlin.test.assertTrue
|
||||
class FileEnvelopeTest {
|
||||
val envelope = Envelope {
|
||||
meta {
|
||||
"a" to "AAA"
|
||||
"b" to 22.2
|
||||
"a" put "AAA"
|
||||
"b" put 22.2
|
||||
}
|
||||
dataType = "hep.dataforge.test"
|
||||
dataID = "myData" // добавил только что
|
||||
|
@ -48,7 +48,7 @@ class EnvelopeServerTest {
|
||||
val request = Envelope.invoke {
|
||||
type = "test.echo"
|
||||
meta {
|
||||
"test.value" to 22
|
||||
"test.value" put 22
|
||||
}
|
||||
data {
|
||||
writeDouble(22.7)
|
||||
|
@ -72,7 +72,7 @@ class NodeDescriptor(config: Config) : ItemDescriptor(config) {
|
||||
* The list of value descriptors
|
||||
*/
|
||||
val values: Map<String, ValueDescriptor>
|
||||
get() = config.getAll(VALUE_KEY.toName()).entries.associate { (name, node) ->
|
||||
get() = config.getIndexed(VALUE_KEY.toName()).entries.associate { (name, node) ->
|
||||
name to ValueDescriptor.wrap(node.node ?: error("Value descriptor must be a node"))
|
||||
}
|
||||
|
||||
@ -93,7 +93,7 @@ class NodeDescriptor(config: Config) : ItemDescriptor(config) {
|
||||
* The map of children node descriptors
|
||||
*/
|
||||
val nodes: Map<String, NodeDescriptor>
|
||||
get() = config.getAll(NODE_KEY.toName()).entries.associate { (name, node) ->
|
||||
get() = config.getIndexed(NODE_KEY.toName()).entries.associate { (name, node) ->
|
||||
name to wrap(node.node ?: error("Node descriptor must be a node"))
|
||||
}
|
||||
|
||||
|
@ -61,7 +61,7 @@ class Laminate(layers: List<Meta>) : MetaBase() {
|
||||
}
|
||||
else -> map {
|
||||
when (it) {
|
||||
is MetaItem.ValueItem -> MetaItem.NodeItem(buildMeta { Meta.VALUE_KEY to it.value })
|
||||
is MetaItem.ValueItem -> MetaItem.NodeItem(buildMeta { Meta.VALUE_KEY put it.value })
|
||||
is MetaItem.NodeItem -> it
|
||||
}
|
||||
}.merge()
|
||||
|
@ -2,7 +2,10 @@ package hep.dataforge.meta
|
||||
|
||||
import hep.dataforge.names.Name
|
||||
import hep.dataforge.names.asName
|
||||
import hep.dataforge.values.EnumValue
|
||||
import hep.dataforge.values.Value
|
||||
import hep.dataforge.values.asValue
|
||||
import kotlin.jvm.JvmName
|
||||
|
||||
/**
|
||||
* DSL builder for meta. Is not intended to store mutable state
|
||||
@ -12,41 +15,105 @@ class MetaBuilder : AbstractMutableMeta<MetaBuilder>() {
|
||||
override fun wrapNode(meta: Meta): MetaBuilder = if (meta is MetaBuilder) meta else meta.builder()
|
||||
override fun empty(): MetaBuilder = MetaBuilder()
|
||||
|
||||
infix fun String.to(value: Any) {
|
||||
if (value is Meta) {
|
||||
this@MetaBuilder[this] = value
|
||||
}
|
||||
this@MetaBuilder[this] = Value.of(value)
|
||||
infix fun String.put(value: Value){
|
||||
set(this,value)
|
||||
}
|
||||
|
||||
infix fun String.to(meta: Meta) {
|
||||
infix fun String.put(string: String){
|
||||
set(this,string.asValue())
|
||||
}
|
||||
|
||||
infix fun String.put(number: Number){
|
||||
set(this,number.asValue())
|
||||
}
|
||||
|
||||
infix fun String.put(boolean: Boolean){
|
||||
set(this, boolean.asValue())
|
||||
}
|
||||
|
||||
infix fun String.put(enum: Enum<*>){
|
||||
set(this, EnumValue(enum))
|
||||
}
|
||||
|
||||
@JvmName("putValues")
|
||||
infix fun String.put(iterable: Iterable<Value>){
|
||||
set(this, iterable.asValue())
|
||||
}
|
||||
|
||||
@JvmName("putNumbers")
|
||||
infix fun String.put(iterable: Iterable<Number>){
|
||||
set(this, iterable.map { it.asValue() }.asValue())
|
||||
}
|
||||
|
||||
@JvmName("putStrings")
|
||||
infix fun String.put(iterable: Iterable<String>){
|
||||
set(this, iterable.map { it.asValue() }.asValue())
|
||||
}
|
||||
|
||||
infix fun String.put(array: DoubleArray){
|
||||
set(this, array.asValue())
|
||||
}
|
||||
|
||||
infix fun String.putValue(any: Any?){
|
||||
set(this, Value.of(any))
|
||||
}
|
||||
|
||||
infix fun String.put(meta: Meta) {
|
||||
this@MetaBuilder[this] = meta
|
||||
}
|
||||
|
||||
infix fun String.to(value: Iterable<Meta>) {
|
||||
infix fun String.put(repr: MetaRepr){
|
||||
set(this,repr.toMeta())
|
||||
}
|
||||
|
||||
@JvmName("putMetas")
|
||||
infix fun String.put(value: Iterable<Meta>) {
|
||||
this@MetaBuilder[this] = value.toList()
|
||||
}
|
||||
|
||||
infix fun String.to(metaBuilder: MetaBuilder.() -> Unit) {
|
||||
infix fun String.put(metaBuilder: MetaBuilder.() -> Unit) {
|
||||
this@MetaBuilder[this] = MetaBuilder().apply(metaBuilder)
|
||||
}
|
||||
|
||||
infix fun Name.to(value: Any) {
|
||||
if (value is Meta) {
|
||||
this@MetaBuilder[this] = value
|
||||
}
|
||||
this@MetaBuilder[this] = Value.of(value)
|
||||
infix fun Name.put(value: Value){
|
||||
set(this,value)
|
||||
}
|
||||
|
||||
infix fun Name.to(meta: Meta) {
|
||||
infix fun Name.put(string: String){
|
||||
set(this,string.asValue())
|
||||
}
|
||||
|
||||
infix fun Name.put(number: Number){
|
||||
set(this,number.asValue())
|
||||
}
|
||||
|
||||
infix fun Name.put(boolean: Boolean){
|
||||
set(this, boolean.asValue())
|
||||
}
|
||||
|
||||
infix fun Name.put(enum: Enum<*>){
|
||||
set(this, EnumValue(enum))
|
||||
}
|
||||
|
||||
@JvmName("putValues")
|
||||
infix fun Name.put(iterable: Iterable<Value>){
|
||||
set(this, iterable.asValue())
|
||||
}
|
||||
|
||||
infix fun Name.put(meta: Meta) {
|
||||
this@MetaBuilder[this] = meta
|
||||
}
|
||||
|
||||
infix fun Name.to(value: Iterable<Meta>) {
|
||||
infix fun Name.put(repr: MetaRepr){
|
||||
set(this,repr.toMeta())
|
||||
}
|
||||
|
||||
@JvmName("putMetas")
|
||||
infix fun Name.put(value: Iterable<Meta>) {
|
||||
this@MetaBuilder[this] = value.toList()
|
||||
}
|
||||
|
||||
infix fun Name.to(metaBuilder: MetaBuilder.() -> Unit) {
|
||||
infix fun Name.put(metaBuilder: MetaBuilder.() -> Unit) {
|
||||
this@MetaBuilder[this] = MetaBuilder().apply(metaBuilder)
|
||||
}
|
||||
}
|
||||
|
@ -164,7 +164,7 @@ fun MutableMeta<*>.append(name: Name, value: Any?) {
|
||||
if (newIndex.isNotEmpty()) {
|
||||
set(name, value)
|
||||
} else {
|
||||
val index = (getAll(name).keys.mapNotNull { it.toIntOrNull() }.max() ?: -1) + 1
|
||||
val index = (getIndexed(name).keys.mapNotNull { it.toIntOrNull() }.max() ?: -1) + 1
|
||||
set(name.withIndex(index.toString()), value)
|
||||
}
|
||||
}
|
||||
|
@ -7,7 +7,7 @@ import hep.dataforge.names.toName
|
||||
* Get all items matching given name.
|
||||
*/
|
||||
@DFExperimental
|
||||
fun Meta.getAll(name: Name): Map<String, MetaItem<*>> {
|
||||
fun Meta.getIndexed(name: Name): Map<String, MetaItem<*>> {
|
||||
val root = when (name.length) {
|
||||
0 -> error("Can't use empty name for that")
|
||||
1 -> this
|
||||
@ -24,14 +24,14 @@ fun Meta.getAll(name: Name): Map<String, MetaItem<*>> {
|
||||
}
|
||||
|
||||
@DFExperimental
|
||||
fun Meta.getAll(name: String): Map<String, MetaItem<*>> = getAll(name.toName())
|
||||
fun Meta.getIndexed(name: String): Map<String, MetaItem<*>> = this@getIndexed.getIndexed(name.toName())
|
||||
|
||||
|
||||
/**
|
||||
* Get all items matching given name.
|
||||
*/
|
||||
@DFExperimental
|
||||
fun <M : MetaNode<M>> M.getAll(name: Name): Map<String, MetaItem<M>> {
|
||||
fun <M : MetaNode<M>> M.getIndexed(name: Name): Map<String, MetaItem<M>> {
|
||||
val root: MetaNode<M>? = when (name.length) {
|
||||
0 -> error("Can't use empty name for that")
|
||||
1 -> this
|
||||
@ -48,4 +48,4 @@ fun <M : MetaNode<M>> M.getAll(name: Name): Map<String, MetaItem<M>> {
|
||||
}
|
||||
|
||||
@DFExperimental
|
||||
fun <M : MetaNode<M>> M.getAll(name: String): Map<String, MetaItem<M>> = getAll(name.toName())
|
||||
fun <M : MetaNode<M>> M.getIndexed(name: String): Map<String, MetaItem<M>> = getIndexed(name.toName())
|
@ -34,4 +34,4 @@ val Value.doubleArray: DoubleArray
|
||||
}
|
||||
|
||||
|
||||
fun Value.toMeta() = buildMeta { Meta.VALUE_KEY to this }
|
||||
fun Value.toMeta() = buildMeta { Meta.VALUE_KEY put this }
|
@ -9,13 +9,13 @@ class MetaBuilderTest {
|
||||
@Test
|
||||
fun testBuilder() {
|
||||
val meta = buildMeta {
|
||||
"a" to 22
|
||||
"b" to listOf(1, 2, 3)
|
||||
"a" put 22
|
||||
"b" put listOf(1, 2, 3)
|
||||
this["c"] = "myValue".asValue()
|
||||
"node" to {
|
||||
"e" to 12.2
|
||||
"childNode" to {
|
||||
"f" to true
|
||||
"node" put {
|
||||
"e" put 12.2
|
||||
"childNode" put {
|
||||
"f" put true
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -27,12 +27,12 @@ class MetaBuilderTest {
|
||||
fun testSNS(){
|
||||
val meta = buildMeta {
|
||||
repeat(10){
|
||||
"b.a[$it]" to it
|
||||
"b.a[$it]" put it
|
||||
}
|
||||
}.seal()
|
||||
assertEquals(10, meta.values().count())
|
||||
|
||||
val nodes = meta.getAll("b.a")
|
||||
val nodes = meta.getIndexed("b.a")
|
||||
|
||||
assertEquals(3, nodes["3"]?.int)
|
||||
}
|
||||
|
@ -11,12 +11,12 @@ class MetaExtensionTest {
|
||||
|
||||
@Test
|
||||
fun testEnum(){
|
||||
val meta = buildMeta{"enum" to TestEnum.test}
|
||||
val meta = buildMeta{"enum" put TestEnum.test}
|
||||
meta["enum"].enum<TestEnum>()
|
||||
}
|
||||
@Test
|
||||
fun testEnumByString(){
|
||||
val meta = buildMeta{"enum" to TestEnum.test.name}
|
||||
val meta = buildMeta{"enum" put TestEnum.test.name}
|
||||
println(meta["enum"].enum<TestEnum>())
|
||||
}
|
||||
|
||||
|
@ -17,16 +17,16 @@ class MetaTest {
|
||||
@Test
|
||||
fun metaEqualityTest() {
|
||||
val meta1 = buildMeta {
|
||||
"a" to 22
|
||||
"b" to {
|
||||
"c" to "ddd"
|
||||
"a" put 22
|
||||
"b" put {
|
||||
"c" put "ddd"
|
||||
}
|
||||
}
|
||||
val meta2 = buildMeta {
|
||||
"b" to {
|
||||
"c" to "ddd"
|
||||
"b" put {
|
||||
"c" put "ddd"
|
||||
}
|
||||
"a" to 22
|
||||
"a" put 22
|
||||
}.seal()
|
||||
assertEquals<Meta>(meta1, meta2)
|
||||
}
|
||||
@ -34,13 +34,13 @@ class MetaTest {
|
||||
@Test
|
||||
fun metaToMap(){
|
||||
val meta = buildMeta {
|
||||
"a" to 22
|
||||
"b" to {
|
||||
"c" to "ddd"
|
||||
"a" put 22
|
||||
"b" put {
|
||||
"c" put "ddd"
|
||||
}
|
||||
"list" to (0..4).map {
|
||||
"list" put (0..4).map {
|
||||
buildMeta {
|
||||
"value" to it
|
||||
"value" put it
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -7,12 +7,12 @@ class MutableMetaTest{
|
||||
@Test
|
||||
fun testRemove(){
|
||||
val meta = buildMeta {
|
||||
"aNode" to {
|
||||
"innerNode" to {
|
||||
"innerValue" to true
|
||||
"aNode" put {
|
||||
"innerNode" put {
|
||||
"innerValue" put true
|
||||
}
|
||||
"b" to 22
|
||||
"c" to "StringValue"
|
||||
"b" put 22
|
||||
"c" put "StringValue"
|
||||
}
|
||||
}.toConfig()
|
||||
|
||||
|
@ -9,8 +9,8 @@ class StyledTest{
|
||||
fun testSNS(){
|
||||
val meta = buildMeta {
|
||||
repeat(10){
|
||||
"b.a[$it]" to {
|
||||
"d" to it
|
||||
"b.a[$it]" put {
|
||||
"d" put it
|
||||
}
|
||||
}
|
||||
}.seal().withStyle()
|
||||
@ -18,9 +18,9 @@ class StyledTest{
|
||||
|
||||
val bNode = meta["b"].node
|
||||
|
||||
val aNodes = bNode?.getAll("a")
|
||||
val aNodes = bNode?.getIndexed("a")
|
||||
|
||||
val allNodes = meta.getAll("b.a")
|
||||
val allNodes = meta.getIndexed("b.a")
|
||||
|
||||
assertEquals(3, aNodes?.get("3").node["d"].int)
|
||||
assertEquals(3, allNodes["3"].node["d"].int)
|
||||
|
@ -27,12 +27,12 @@ class DynamicMetaTest {
|
||||
@Test
|
||||
fun testMetaToDynamic(){
|
||||
val meta = buildMeta {
|
||||
"a" to 22
|
||||
"array" to arrayOf(1, 2, 3)
|
||||
"b" to "myString"
|
||||
"ob" to {
|
||||
"childNode" to 18
|
||||
"booleanNode" to true
|
||||
"a" put 22
|
||||
"array" put listOf(1, 2, 3)
|
||||
"b" put "myString"
|
||||
"ob" put {
|
||||
"childNode" put 18
|
||||
"booleanNode" put true
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3,7 +3,9 @@ package hep.dataforge.scripting
|
||||
import hep.dataforge.context.Global
|
||||
import hep.dataforge.meta.get
|
||||
import hep.dataforge.meta.int
|
||||
import hep.dataforge.workspace.*
|
||||
import hep.dataforge.workspace.SimpleWorkspaceBuilder
|
||||
import hep.dataforge.workspace.context
|
||||
import hep.dataforge.workspace.target
|
||||
import org.junit.Test
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
@ -17,7 +19,7 @@ class BuildersKtTest {
|
||||
context("test")
|
||||
|
||||
target("testTarget"){
|
||||
"a" to 12
|
||||
"a" put 12
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -30,7 +32,7 @@ class BuildersKtTest {
|
||||
context("test")
|
||||
|
||||
target("testTarget"){
|
||||
"a" to 12
|
||||
"a" put 12
|
||||
}
|
||||
""".trimIndent()
|
||||
val workspace = Builders.buildWorkspace(script)
|
||||
|
@ -26,8 +26,8 @@ class DataDependency(val filter: DataFilter, val placement: Name = EmptyName) :
|
||||
}
|
||||
|
||||
override fun toMeta(): Meta = buildMeta {
|
||||
"data" to filter.config
|
||||
"to" to placement
|
||||
"data" put filter.config
|
||||
"to" put placement.toString()
|
||||
}
|
||||
}
|
||||
|
||||
@ -39,8 +39,8 @@ class AllDataDependency(val placement: Name = EmptyName) : Dependency() {
|
||||
}
|
||||
|
||||
override fun toMeta() = buildMeta {
|
||||
"data" to "@all"
|
||||
"to" to placement
|
||||
"data" put "@all"
|
||||
"to" put placement.toString()
|
||||
}
|
||||
}
|
||||
|
||||
@ -67,9 +67,9 @@ abstract class TaskDependency<out T : Any>(
|
||||
}
|
||||
|
||||
override fun toMeta(): Meta = buildMeta {
|
||||
"task" to name
|
||||
"meta" to meta
|
||||
"to" to placement
|
||||
"task" put name.toString()
|
||||
"meta" put meta
|
||||
"to" put placement.toString()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -31,9 +31,9 @@ data class TaskModel(
|
||||
//TODO add pre-run check of task result type?
|
||||
|
||||
override fun toMeta(): Meta = buildMeta {
|
||||
"name" to name
|
||||
"meta" to meta
|
||||
"dependsOn" to {
|
||||
"name" put name.toString()
|
||||
"meta" put meta
|
||||
"dependsOn" put {
|
||||
val dataDependencies = dependencies.filterIsInstance<DataDependency>()
|
||||
val taskDependencies = dependencies.filterIsInstance<TaskDependency<*>>()
|
||||
setIndexed("data".toName(), dataDependencies.map { it.toMeta() })
|
||||
|
@ -62,7 +62,7 @@ fun WorkspaceBuilder.target(name: String, block: MetaBuilder.() -> Unit) {
|
||||
fun WorkspaceBuilder.target(name: String, base: String, block: MetaBuilder.() -> Unit) {
|
||||
val parentTarget = targets[base] ?: error("Base target with name $base not found")
|
||||
targets[name] = parentTarget.builder()
|
||||
.apply { "@baseTarget" to base }
|
||||
.apply { "@baseTarget" put base }
|
||||
.apply(block)
|
||||
.seal()
|
||||
}
|
||||
|
@ -121,7 +121,7 @@ class SimpleWorkspaceTest {
|
||||
val customPipeTask = task<Int>("custom") {
|
||||
mapAction<Int> {
|
||||
meta = meta.builder().apply {
|
||||
"newValue" to 22
|
||||
"newValue" put 22
|
||||
}
|
||||
name += "new"
|
||||
result {
|
||||
@ -142,7 +142,7 @@ class SimpleWorkspaceTest {
|
||||
|
||||
@Test
|
||||
fun testMetaPropagation() {
|
||||
val node = workspace.run("sum") { "testFlag" to true }
|
||||
val node = workspace.run("sum") { "testFlag" put true }
|
||||
val res = node.first()?.get()
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user