@@ -5,6 +5,7 @@ import io.kotest.core.spec.style.FunSpec
55import io.kotest.matchers.collections.shouldContainExactlyInAnyOrder
66import kotlinx.serialization.Serializable
77import kotlinx.serialization.builtins.serializer
8+ import kotlinx.serialization.descriptors.SerialDescriptor
89
910class SerializerDescriptorsExtractorTest : FunSpec ({
1011
@@ -18,14 +19,7 @@ class SerializerDescriptorsExtractorTest : FunSpec({
1819
1920 val actual = SerializerDescriptorsExtractor .Default (Example1 .Parent .serializer())
2021
21- withClue(
22- """
23- expected: ${expected.map { it.serialName }.sorted().joinToString()}
24- actual: ${actual.map { it.serialName }.sorted().joinToString()}
25- """.trimIndent()
26- ) {
27- actual shouldContainExactlyInAnyOrder expected
28- }
22+ actual shouldContainDescriptors expected
2923 }
3024
3125 test("Example2 : given parent class, expect subclass property descriptor extracted") {
@@ -38,17 +32,36 @@ class SerializerDescriptorsExtractorTest : FunSpec({
3832
3933 val actual = SerializerDescriptorsExtractor .Default (Example2 .Parent .serializer())
4034
41- withClue(
42- """
43- expected: ${expected.map { it.serialName }.sorted().joinToString()}
44- actual: ${actual.map { it.serialName }.sorted().joinToString()}
45- """.trimIndent()
46- ) {
47- actual shouldContainExactlyInAnyOrder expected
48- }
35+ actual shouldContainDescriptors expected
4936 }
5037
51- })
38+ test("Example3 : expect nullable/non-nullable SerialDescriptors be de-duplicated") {
39+
40+ val expected = listOf(
41+ Example3 .SomeType .serializer().descriptor,
42+ Example3 .TypeHolder .serializer().descriptor,
43+ String .serializer().descriptor,
44+ )
45+
46+ val actual = SerializerDescriptorsExtractor .Default (Example3 .TypeHolder .serializer())
47+
48+ actual shouldContainDescriptors expected
49+ }
50+ }) {
51+ companion object {
52+ private infix fun Collection<SerialDescriptor>.shouldContainDescriptors (expected : Collection <SerialDescriptor >) {
53+ val actual = this
54+ withClue(
55+ """
56+ expected: ${expected.map { it.serialName }.sorted().joinToString()}
57+ actual: ${actual.map { it.serialName }.sorted().joinToString()}
58+ """ .trimIndent()
59+ ) {
60+ actual shouldContainExactlyInAnyOrder expected
61+ }
62+ }
63+ }
64+ }
5265
5366
5467@Suppress(" unused" )
@@ -78,3 +91,17 @@ private object Example2 {
7891 @Serializable
7992 class SubClass1 (val n : Nested ) : SealedSub()
8093}
94+
95+
96+ @Suppress(" unused" )
97+ private object Example3 {
98+
99+ @Serializable
100+ class SomeType (val a : String )
101+
102+ @Serializable
103+ class TypeHolder (
104+ val required : SomeType ,
105+ val optional : SomeType ? ,
106+ )
107+ }
0 commit comments