• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2017-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
3  */
4 
5 package kotlinx.serialization
6 
7 import kotlinx.serialization.builtins.serializer
8 import kotlinx.serialization.internal.UnitSerializer
9 import kotlin.test.Test
10 
11 class SealedGenericClassesTest {
12     interface Output
13 
14     @Serializable
15     data class Something(val s: String) : Output
16 
17     @Serializable
18     sealed class Query<T : Output> {
19         @Serializable
20         data class SimpleQuery<T: Output>(val rawQuery: String) : Query<T>()
21     }
22 
23     @Serializable
24     sealed class Fetcher<T : Output> {
25         abstract val query: Query<T>
26 
27         @Serializable
28         data class SomethingFetcher(override val query: Query<Something>) : Fetcher<Something>()
29     }
30 
31     // Test that compilation and retrieval is successful
32     @Test
testQuerynull33     fun testQuery() {
34         Query.SimpleQuery.serializer(String.serializer())
35         Query.serializer(UnitSerializer)
36     }
37 
38     @Test
testFetchernull39     fun testFetcher() {
40         Fetcher.SomethingFetcher.serializer()
41         Fetcher.serializer(Something.serializer())
42     }
43 }
44