From 156a43d4bf91ee070667b5df5785119f7b098373 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Mon, 7 Oct 2019 13:27:54 +0300 Subject: [PATCH] Fixed enum delegate --- .../src/commonMain/kotlin/hep/dataforge/meta/Meta.kt | 2 +- .../kotlin/hep/dataforge/meta/MetaExtensionTest.kt | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) rename dataforge-meta/src/{jvmTest => commonTest}/kotlin/hep/dataforge/meta/MetaExtensionTest.kt (78%) diff --git a/dataforge-meta/src/commonMain/kotlin/hep/dataforge/meta/Meta.kt b/dataforge-meta/src/commonMain/kotlin/hep/dataforge/meta/Meta.kt index 6b255a63..04c5f27b 100644 --- a/dataforge-meta/src/commonMain/kotlin/hep/dataforge/meta/Meta.kt +++ b/dataforge-meta/src/commonMain/kotlin/hep/dataforge/meta/Meta.kt @@ -242,7 +242,7 @@ val MetaItem<*>?.long get() = number?.toLong() val MetaItem<*>?.short get() = number?.toShort() inline fun > MetaItem<*>?.enum() = if (this is ValueItem && this.value is EnumValue<*>) { - this.value as E + this.value.value as E } else { string?.let { enumValueOf(it) } } diff --git a/dataforge-meta/src/jvmTest/kotlin/hep/dataforge/meta/MetaExtensionTest.kt b/dataforge-meta/src/commonTest/kotlin/hep/dataforge/meta/MetaExtensionTest.kt similarity index 78% rename from dataforge-meta/src/jvmTest/kotlin/hep/dataforge/meta/MetaExtensionTest.kt rename to dataforge-meta/src/commonTest/kotlin/hep/dataforge/meta/MetaExtensionTest.kt index 5f82df9a..30b6df18 100644 --- a/dataforge-meta/src/jvmTest/kotlin/hep/dataforge/meta/MetaExtensionTest.kt +++ b/dataforge-meta/src/commonTest/kotlin/hep/dataforge/meta/MetaExtensionTest.kt @@ -1,6 +1,7 @@ package hep.dataforge.meta -import org.junit.Test +import kotlin.test.Test + class MetaExtensionTest { @@ -15,7 +16,7 @@ class MetaExtensionTest { } @Test fun testEnumByString(){ - val meta = buildMeta{"enum" to TestEnum.test.toString()} + val meta = buildMeta{"enum" to TestEnum.test.name} println(meta["enum"].enum()) }