From d565d6ec4c535edc65e69b017e4fb981079bf2d2 Mon Sep 17 00:00:00 2001 From: Willem Veelenturf Date: Wed, 25 Mar 2026 18:38:40 +0100 Subject: [PATCH] test: add enum mapping tests for enums with extra properties (e.g. label) Covers mapping between simple enums and enums with constructor properties like wirespec-generated enums with a label field, in both directions. Co-Authored-By: Claude Opus 4.6 (1M context) --- .../flock/kmapper/EnumMappingTest.kt | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/test-integration/src/test/kotlin/community/flock/kmapper/EnumMappingTest.kt b/test-integration/src/test/kotlin/community/flock/kmapper/EnumMappingTest.kt index da50e33..a62ea92 100644 --- a/test-integration/src/test/kotlin/community/flock/kmapper/EnumMappingTest.kt +++ b/test-integration/src/test/kotlin/community/flock/kmapper/EnumMappingTest.kt @@ -75,6 +75,68 @@ class EnumMappingTest { } } + @Test + fun shouldCompile_enumWithLabelProperty() { + IntegrationTest(options) + .file("App.kt") { + $$""" + |package sample + | + |import community.flock.kmapper.mapper + | + |enum class FieldType { TEXT, NUMBER } + |data class FormField(val name: String, val type: FieldType) + | + |enum class EvaluationFieldType(val label: String) { TEXT("Text"), NUMBER("Number") } + |data class EvaluationFormField(val name: String, val type: EvaluationFieldType) + | + |fun main() { + | val field = FormField(name="age", type=FieldType.NUMBER) + | val dto: EvaluationFormField = field.mapper() + | println(dto) + |} + | + """.trimMargin() + } + .compileSuccess { output -> + assertTrue( + output.contains("EvaluationFormField(name=age, type=NUMBER)"), + "Expected EvaluationFormField(name=age, type=NUMBER) in output" + ) + } + } + + @Test + fun shouldCompile_enumWithLabelPropertyReverse() { + IntegrationTest(options) + .file("App.kt") { + $$""" + |package sample + | + |import community.flock.kmapper.mapper + | + |enum class EvaluationFieldType(val label: String) { TEXT("Text"), NUMBER("Number") } + |data class EvaluationFormField(val name: String, val type: EvaluationFieldType) + | + |enum class FieldType { TEXT, NUMBER } + |data class FormField(val name: String, val type: FieldType) + | + |fun main() { + | val field = EvaluationFormField(name="age", type=EvaluationFieldType.NUMBER) + | val dto: FormField = field.mapper() + | println(dto) + |} + | + """.trimMargin() + } + .compileSuccess { output -> + assertTrue( + output.contains("FormField(name=age, type=NUMBER)"), + "Expected FormField(name=age, type=NUMBER) in output" + ) + } + } + @Test fun shouldSuccess_nestedEnumMapping() { IntegrationTest(options)