Skip to content

Commit 6879ef6

Browse files
authored
Merge pull request #13 from flock-community/test/enum-label-property-mapping
test: add enum mapping tests for enums with extra properties
2 parents 0513fb4 + d565d6e commit 6879ef6

1 file changed

Lines changed: 62 additions & 0 deletions

File tree

test-integration/src/test/kotlin/community/flock/kmapper/EnumMappingTest.kt

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,68 @@ class EnumMappingTest {
7575
}
7676
}
7777

78+
@Test
79+
fun shouldCompile_enumWithLabelProperty() {
80+
IntegrationTest(options)
81+
.file("App.kt") {
82+
$$"""
83+
|package sample
84+
|
85+
|import community.flock.kmapper.mapper
86+
|
87+
|enum class FieldType { TEXT, NUMBER }
88+
|data class FormField(val name: String, val type: FieldType)
89+
|
90+
|enum class EvaluationFieldType(val label: String) { TEXT("Text"), NUMBER("Number") }
91+
|data class EvaluationFormField(val name: String, val type: EvaluationFieldType)
92+
|
93+
|fun main() {
94+
| val field = FormField(name="age", type=FieldType.NUMBER)
95+
| val dto: EvaluationFormField = field.mapper()
96+
| println(dto)
97+
|}
98+
|
99+
""".trimMargin()
100+
}
101+
.compileSuccess { output ->
102+
assertTrue(
103+
output.contains("EvaluationFormField(name=age, type=NUMBER)"),
104+
"Expected EvaluationFormField(name=age, type=NUMBER) in output"
105+
)
106+
}
107+
}
108+
109+
@Test
110+
fun shouldCompile_enumWithLabelPropertyReverse() {
111+
IntegrationTest(options)
112+
.file("App.kt") {
113+
$$"""
114+
|package sample
115+
|
116+
|import community.flock.kmapper.mapper
117+
|
118+
|enum class EvaluationFieldType(val label: String) { TEXT("Text"), NUMBER("Number") }
119+
|data class EvaluationFormField(val name: String, val type: EvaluationFieldType)
120+
|
121+
|enum class FieldType { TEXT, NUMBER }
122+
|data class FormField(val name: String, val type: FieldType)
123+
|
124+
|fun main() {
125+
| val field = EvaluationFormField(name="age", type=EvaluationFieldType.NUMBER)
126+
| val dto: FormField = field.mapper()
127+
| println(dto)
128+
|}
129+
|
130+
""".trimMargin()
131+
}
132+
.compileSuccess { output ->
133+
assertTrue(
134+
output.contains("FormField(name=age, type=NUMBER)"),
135+
"Expected FormField(name=age, type=NUMBER) in output"
136+
)
137+
}
138+
}
139+
78140
@Test
79141
fun shouldSuccess_nestedEnumMapping() {
80142
IntegrationTest(options)

0 commit comments

Comments
 (0)