Skip to content

Commit

Permalink
Tests for sealed generic serializers (#1767)
Browse files Browse the repository at this point in the history
  • Loading branch information
sandwwraith authored Nov 22, 2021
1 parent 53b46e9 commit 4c87a43
Showing 1 changed file with 43 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* 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.builtins.serializer
import kotlinx.serialization.internal.UnitSerializer
import kotlin.test.Test

class SealedGenericClassesTest {
interface Output

@Serializable
data class Something(val s: String) : Output

@Serializable
sealed class Query<T : Output> {
@Serializable
data class SimpleQuery<T: Output>(val rawQuery: String) : Query<T>()
}

@Serializable
sealed class Fetcher<T : Output> {
abstract val query: Query<T>

@Serializable
data class SomethingFetcher(override val query: Query<Something>) : Fetcher<Something>()
}

// Test that compilation and retrieval is successful
@Test
fun testQuery() {
val serial1 = Query.SimpleQuery.serializer(String.serializer())
val serial2 = Query.serializer(UnitSerializer)
}

@Test
fun testFetcher() {
val serial1 = Fetcher.SomethingFetcher.serializer()
val serial2 = Fetcher.serializer(Something.serializer())
}
}

0 comments on commit 4c87a43

Please sign in to comment.