@@ -5,6 +5,7 @@ import io.kotest.core.spec.style.FunSpec
5
5
import io.kotest.matchers.collections.shouldContainExactlyInAnyOrder
6
6
import kotlinx.serialization.Serializable
7
7
import kotlinx.serialization.builtins.serializer
8
+ import kotlinx.serialization.descriptors.SerialDescriptor
8
9
9
10
class SerializerDescriptorsExtractorTest : FunSpec ({
10
11
@@ -18,14 +19,7 @@ class SerializerDescriptorsExtractorTest : FunSpec({
18
19
19
20
val actual = SerializerDescriptorsExtractor .Default (Example1 .Parent .serializer())
20
21
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
29
23
}
30
24
31
25
test("Example2 : given parent class, expect subclass property descriptor extracted") {
@@ -38,17 +32,36 @@ class SerializerDescriptorsExtractorTest : FunSpec({
38
32
39
33
val actual = SerializerDescriptorsExtractor .Default (Example2 .Parent .serializer())
40
34
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
49
36
}
50
37
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
+ }
52
65
53
66
54
67
@Suppress(" unused" )
@@ -78,3 +91,17 @@ private object Example2 {
78
91
@Serializable
79
92
class SubClass1 (val n : Nested ) : SealedSub()
80
93
}
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