-
Notifications
You must be signed in to change notification settings - Fork 623
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tests for sealed generic serializers (#1767)
For commit JetBrains/kotlin@36484ab and issue #1646 and https://youtrack.jetbrains.com/issue/KT-49726
- Loading branch information
1 parent
53b46e9
commit 4c87a43
Showing
1 changed file
with
43 additions
and
0 deletions.
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
core/commonTest/src/kotlinx/serialization/SealedGenericClassesTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) | ||
} | ||
} |