-
Notifications
You must be signed in to change notification settings - Fork 612
/
CachedSerializersTest.kt
57 lines (46 loc) · 1.48 KB
/
CachedSerializersTest.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/*
* Copyright 2017-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
*/
package kotlinx.serialization
import kotlinx.serialization.modules.*
import kotlinx.serialization.test.noJsLegacy
import kotlin.test.*
import kotlin.time.*
class CachedSerializersTest {
@Serializable
object Object
@Serializable
sealed class SealedParent {
@Serializable
data class Child(val i: Int) : SealedParent()
}
@Serializable
abstract class Abstract
@Test
fun testObjectSerializersAreSame() = noJsLegacy {
assertSame(Object.serializer(), Object.serializer())
}
@Test
fun testSealedSerializersAreSame() = noJsLegacy {
assertSame(SealedParent.serializer(), SealedParent.serializer())
}
@Test
fun testAbstractSerializersAreSame() = noJsLegacy {
assertSame(Abstract.serializer(), Abstract.serializer())
}
@OptIn(ExperimentalTime::class)
@Test
@Ignore // TODO: Unignore after 1.8.0 update
fun testSerializersAreIntrinsified() {
val m = SerializersModule { }
val direct = measureTime {
Object.serializer()
}
val directMs = direct.inWholeMicroseconds
val indirect = measureTime {
m.serializer<Object>()
}
val indirectMs = indirect.inWholeMicroseconds
if (indirectMs > directMs + (directMs / 4)) error("Direct ($directMs) and indirect ($indirectMs) times are too far apart")
}
}