Parcelize: Add support for unsigned types on the IR backend
This commit is contained in:
committed by
Alexander Udalov
parent
34a200bf09
commit
9fd777cb7d
@@ -0,0 +1,46 @@
|
||||
// WITH_RUNTIME
|
||||
// IGNORE_BACKEND: JVM
|
||||
|
||||
@file:JvmName("TestKt")
|
||||
package test
|
||||
|
||||
import kotlinx.parcelize.*
|
||||
import android.os.Parcel
|
||||
import android.os.Parcelable
|
||||
|
||||
@Parcelize
|
||||
data class UnsignedTypes(
|
||||
val ub: UByte, val us: UShort, val ui: UInt, val ul: ULong,
|
||||
val nub: UByte?, val nus: UShort?, val nui: UInt?, val nul: ULong?
|
||||
) : Parcelable
|
||||
|
||||
fun box() = parcelTest { parcel ->
|
||||
val first = UnsignedTypes(
|
||||
3.toUByte(), 10.toUShort(), 300.toUInt(), 3000UL,
|
||||
3.toUByte(), 10.toUShort(), 300.toUInt(), 3000UL,
|
||||
)
|
||||
val second = UnsignedTypes(
|
||||
UByte.MAX_VALUE, UShort.MAX_VALUE, UInt.MAX_VALUE, ULong.MAX_VALUE,
|
||||
UByte.MAX_VALUE, UShort.MAX_VALUE, UInt.MAX_VALUE, ULong.MAX_VALUE,
|
||||
)
|
||||
val third = UnsignedTypes(
|
||||
UByte.MIN_VALUE, UShort.MIN_VALUE, UInt.MIN_VALUE, ULong.MIN_VALUE,
|
||||
null, null, null, null,
|
||||
)
|
||||
|
||||
first.writeToParcel(parcel, 0)
|
||||
second.writeToParcel(parcel, 0)
|
||||
third.writeToParcel(parcel, 0)
|
||||
|
||||
val bytes = parcel.marshall()
|
||||
parcel.unmarshall(bytes, 0, bytes.size)
|
||||
parcel.setDataPosition(0)
|
||||
|
||||
val first2 = readFromParcel<UnsignedTypes>(parcel)
|
||||
val second2 = readFromParcel<UnsignedTypes>(parcel)
|
||||
val third2 = readFromParcel<UnsignedTypes>(parcel)
|
||||
|
||||
assert(first == first2)
|
||||
assert(second == second2)
|
||||
assert(third == third2)
|
||||
}
|
||||
Reference in New Issue
Block a user