summaryrefslogtreecommitdiff
path: root/formats/protobuf/commonTest/src/kotlinx/serialization/protobuf/ProtobufNothingTest.kt
diff options
context:
space:
mode:
Diffstat (limited to 'formats/protobuf/commonTest/src/kotlinx/serialization/protobuf/ProtobufNothingTest.kt')
-rw-r--r--formats/protobuf/commonTest/src/kotlinx/serialization/protobuf/ProtobufNothingTest.kt29
1 files changed, 29 insertions, 0 deletions
diff --git a/formats/protobuf/commonTest/src/kotlinx/serialization/protobuf/ProtobufNothingTest.kt b/formats/protobuf/commonTest/src/kotlinx/serialization/protobuf/ProtobufNothingTest.kt
new file mode 100644
index 00000000..e90ff2be
--- /dev/null
+++ b/formats/protobuf/commonTest/src/kotlinx/serialization/protobuf/ProtobufNothingTest.kt
@@ -0,0 +1,29 @@
+/*
+ * 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), "")
+ testConversion(ParameterizedBox(null), "")
+ }
+}