jvmTest.kotlinx.serialization.features.SerializerJvmSpecificTest.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of kotlinx-serialization-core-metadata Show documentation
Show all versions of kotlinx-serialization-core-metadata Show documentation
Kotlin multiplatform serialization runtime library
The newest version!
/*
* Copyright 2017-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
*/
package kotlinx.serialization.features
import kotlinx.serialization.*
import kotlinx.serialization.descriptors.*
import kotlinx.serialization.internal.*
import org.junit.Test
import kotlin.test.*
class SerializerJvmSpecificTest {
enum class Foo
@Serializable
abstract class ExplicitAbstract(public val i: Int = 42)
interface ImplicitInterface
@Serializable(with = PolymorphicSerializer::class)
interface ExplicitInterface
@Serializable
class Holder(
val iif: ImplicitInterface,
val eif: ExplicitInterface,
val ea: ExplicitAbstract
)
@Test
fun testNonSerializableEnum() {
val serializer = serializer()
assertTrue(serializer.descriptor.kind is SerialKind.ENUM)
}
@Test
fun testDefaultInterfaceSerializer() {
assertEquals(holderChildDescriptor(0), serializer().descriptor)
}
@Test
fun testExplicitInterfaceSerializer() {
assertEquals(holderChildDescriptor(1), serializer().descriptor)
}
@Test
fun testDefaultAbstractSerializer() {
// TODO discuss on serializers equality
assertEquals(holderChildDescriptor(2), serializer().descriptor)
}
private fun holderChildDescriptor(i: Int) = Holder.serializer().descriptor.getElementDescriptor(i)
}