-
Notifications
You must be signed in to change notification settings - Fork 624
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support Serializer for Nothing on the JS target (#2330)
Workaround for KT-51333: serialization of `Nothing` on the JS target and related tests See also #932 Co-authored-by: Leonid Startsev <[email protected]>
- Loading branch information
1 parent
782b9f3
commit b8de86f
Showing
3 changed files
with
59 additions
and
2 deletions.
There are no files selected for viewing
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
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
30 changes: 30 additions & 0 deletions
30
formats/protobuf/commonTest/src/kotlinx/serialization/protobuf/ProtobufNothingTest.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,30 @@ | ||
/* | ||
* Copyright 2017-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. | ||
*/ | ||
|
||
package kotlinx.serialization.protobuf | ||
|
||
import kotlinx.serialization.* | ||
import kotlinx.serialization.test.* | ||
import kotlin.test.* | ||
|
||
class ProtobufNothingTest { | ||
@Serializable | ||
/*private*/ data class NullableNothingBox(val value: Nothing?) // `private` doesn't work on the JS legacy target | ||
|
||
@Serializable | ||
private data class ParameterizedBox<T : Any>(val value: T?) | ||
|
||
private inline fun <reified T> testConversion(data: T, expectedHexString: String) { | ||
val string = ProtoBuf.encodeToHexString(data).uppercase() | ||
assertEquals(expectedHexString, string) | ||
assertEquals(data, ProtoBuf.decodeFromHexString(string)) | ||
} | ||
|
||
@Test | ||
fun testNothing() { | ||
testConversion(NullableNothingBox(null), "") | ||
if (isJsLegacy()) return | ||
testConversion(ParameterizedBox(null), "") | ||
} | ||
} |