diff --git a/api/src/commonMain/kotlin/Parameters.kt b/api/src/commonMain/kotlin/Parameters.kt index b9b0969..b8755fc 100644 --- a/api/src/commonMain/kotlin/Parameters.kt +++ b/api/src/commonMain/kotlin/Parameters.kt @@ -2,6 +2,7 @@ package opensavvy.spine.api import kotlin.jvm.JvmInline import kotlin.reflect.KProperty +import kotlin.uuid.Uuid /** * Underlying storage for [Parameters]: a mutable map of parameter names to their raw string values. @@ -309,6 +310,7 @@ internal inline fun stringToValue(value: String) = when (T::class) { ULong::class -> value.toULong() as T Float::class -> value.toFloat() as T Double::class -> value.toDouble() as T + Uuid::class -> Uuid.parse(value) as T else -> throw UnsupportedOperationException("The type ${T::class.simpleName ?: T::class.toString()} is not currently supported in parameters.") } @@ -351,6 +353,7 @@ internal inline fun valueToString(value: T) = when (value) { is ULong -> value.toString() is Float -> value.toString() is Double -> value.toString() + is Uuid -> value.toString() else -> throw UnsupportedOperationException("The type ${T::class.simpleName ?: T::class.toString()} is not currently supported in parameters.") } diff --git a/api/src/commonTest/kotlin/ParametersTest.kt b/api/src/commonTest/kotlin/ParametersTest.kt index 4fb24aa..d806291 100644 --- a/api/src/commonTest/kotlin/ParametersTest.kt +++ b/api/src/commonTest/kotlin/ParametersTest.kt @@ -1,5 +1,6 @@ package opensavvy.spine.api +import kotlin.uuid.Uuid import opensavvy.prepared.suite.SuiteDsl import opensavvy.prepared.suite.assertions.checkThrows @@ -118,8 +119,10 @@ fun SuiteDsl.parameters() = suite("Endpoint parameters") { var float: Float by parameter() var double: Double by parameter() + var uuid: Uuid by parameter() } + val expectedUuid = Uuid.parse("123e4567-e89b-12d3-a456-426614174000") val params = buildParameters(::Types) { string = "thing" bool = true @@ -135,6 +138,7 @@ fun SuiteDsl.parameters() = suite("Endpoint parameters") { float = 9f double = 10.0 + uuid = expectedUuid } check(params.string == "thing") @@ -152,6 +156,7 @@ fun SuiteDsl.parameters() = suite("Endpoint parameters") { check(params.float == 9f) check(params.double == 10.0) + check(params.uuid == expectedUuid) check(params.data == mapOf( "string" to listOf("thing"), @@ -169,6 +174,7 @@ fun SuiteDsl.parameters() = suite("Endpoint parameters") { "float" to listOf("${9.0}"), // JVM: "9.0" — JS: "9" "double" to listOf("${10.0}"), + "uuid" to listOf("123e4567-e89b-12d3-a456-426614174000"), )) } }