Skip to content

Commit 7e227ed

Browse files
committed
chore: Added test for map containers
1 parent 7a42db9 commit 7e227ed

File tree

1 file changed

+27
-3
lines changed

1 file changed

+27
-3
lines changed

formats/hocon/src/test/kotlin/kotlinx/serialization/hocon/HoconPolymorphismTest.kt

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@ class HoconPolymorphismTest {
2424
}
2525

2626
@Serializable
27-
data class SealedContainer(val sealed: Collection<Sealed>)
27+
data class SealedCollectionContainer(val sealed: Collection<Sealed>)
28+
29+
@Serializable
30+
data class SealedMapContainer(val sealed: Map<String, Sealed>)
2831

2932
@Serializable
3033
data class CompositeClass(var sealed: Sealed)
@@ -116,14 +119,35 @@ class HoconPolymorphismTest {
116119
{ type = data_class, name = testDataClass, intField = 1 }
117120
]
118121
""".trimIndent(),
119-
original = SealedContainer(
122+
original = SealedCollectionContainer(
120123
listOf(
121124
Sealed.AnnotatedTypeChild(type = "override"),
122125
Sealed.ObjectChild,
123126
Sealed.DataClassChild(name = "testDataClass"),
124127
)
125128
),
126-
serializer = SealedContainer.serializer(),
129+
serializer = SealedCollectionContainer.serializer(),
130+
)
131+
}
132+
133+
@Test
134+
fun testMapContainer() {
135+
objectHocon.assertStringFormAndRestored(
136+
expected = """
137+
sealed = {
138+
"annotated_type_child" = { type = annotated_type_child, my_type = override, intField = 3 }
139+
"object" = { type = object }
140+
"data_class" = { type = data_class, name = testDataClass, intField = 1 }
141+
}
142+
""".trimIndent(),
143+
original = SealedMapContainer(
144+
mapOf(
145+
"annotated_type_child" to Sealed.AnnotatedTypeChild(type = "override"),
146+
"object" to Sealed.ObjectChild,
147+
"data_class" to Sealed.DataClassChild(name = "testDataClass"),
148+
)
149+
),
150+
serializer = SealedMapContainer.serializer(),
127151
)
128152
}
129153
}

0 commit comments

Comments
 (0)