• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
<lambda>null2  * Copyright 2017-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
3  */
4 
5 package kotlinx.serialization.json
6 
7 import kotlinx.serialization.*
8 import kotlin.test.Test
9 import kotlin.test.assertEquals
10 
11 class JsonUnionEnumTest : JsonTestBase() {
12 
13     enum class SomeEnum { ALPHA, BETA, GAMMA }
14 
15     @Serializable
16     data class WithUnions(val s: String,
17                           val e: SomeEnum = SomeEnum.ALPHA,
18                           val i: Int = 42)
19 
20     @Test
21     fun testEnum() = parametrizedTest { jsonTestingMode ->
22         val data = WithUnions("foo", SomeEnum.BETA)
23         val json = default.encodeToString(WithUnions.serializer(), data, jsonTestingMode)
24         val restored = default.decodeFromString(WithUnions.serializer(), json, jsonTestingMode)
25         assertEquals(data, restored)
26     }
27 }
28