diff --git a/src/commonMain/kotlin/com/charleskorn/kaml/YamlConfiguration.kt b/src/commonMain/kotlin/com/charleskorn/kaml/YamlConfiguration.kt index 84a46cff..aace5b80 100644 --- a/src/commonMain/kotlin/com/charleskorn/kaml/YamlConfiguration.kt +++ b/src/commonMain/kotlin/com/charleskorn/kaml/YamlConfiguration.kt @@ -18,6 +18,8 @@ package com.charleskorn.kaml +import kotlinx.serialization.ExperimentalSerializationApi + /** * Configuration options for parsing YAML to objects and serialising objects to YAML. * @@ -35,6 +37,7 @@ package com.charleskorn.kaml * * [sequenceBlockIndent]: number of spaces to use as indentation for sequences, if [sequenceStyle] set to [SequenceStyle.Block] * * [allowAnchorsAndAliases]: set to true to allow anchors and aliases when decoding YAML (defaults to `false`) * * [codePointLimit]: the maximum amount of code points allowed in the input YAML document (defaults to 3 MB) + * * [decodeEnumCaseInsensitive]: set to true to allow case-insensitive decoding of enums (defaults to `false`) */ public data class YamlConfiguration( internal val encodeDefaults: Boolean = true, @@ -52,6 +55,8 @@ public data class YamlConfiguration( internal val allowAnchorsAndAliases: Boolean = false, internal val yamlNamingStrategy: YamlNamingStrategy? = null, internal val codePointLimit: Int? = null, + @ExperimentalSerializationApi + internal val decodeEnumCaseInsensitive: Boolean = false, ) public enum class PolymorphismStyle { diff --git a/src/commonMain/kotlin/com/charleskorn/kaml/YamlScalarInput.kt b/src/commonMain/kotlin/com/charleskorn/kaml/YamlScalarInput.kt index 5db5fc9c..828abee4 100644 --- a/src/commonMain/kotlin/com/charleskorn/kaml/YamlScalarInput.kt +++ b/src/commonMain/kotlin/com/charleskorn/kaml/YamlScalarInput.kt @@ -42,13 +42,20 @@ internal class YamlScalarInput(val scalar: YamlScalar, yaml: Yaml, context: Seri return index } - val choices = (0..enumDescriptor.elementsCount - 1) + val choices = (0.. { Yaml.default.decodeFromString(TestEnum.serializer(), "value1") } + + exception.asClue { + it.message shouldBe "Value 'value1' is not a valid option, permitted choices are: Value1, Value2" + it.line shouldBe 1 + it.column shouldBe 1 + it.path shouldBe YamlPath.root + } + } + } } context("parsing null values") {