@@ -21,36 +21,36 @@ class UnsignedIntegersTest : JsonTestBase() {
2121 val double : Double
2222 )
2323
24- // TODO uncomment when Kotlin 1.8.0 is released
25- // @Serializable
26- // data class UnsignedArrays(
27- // val uByte: UByteArray,
28- // val uShort: UShortArray,
29- // val uInt: UIntArray,
30- // val uLong: ULongArray
31- // ) {
32- // override fun equals(other: Any?): Boolean {
33- // if (this === other) return true
34- // if (other == null || this::class != other::class) return false
35- //
36- // other as UnsignedArrays
37- //
38- // if (!uByte.contentEquals(other.uByte)) return false
39- // if (!uShort.contentEquals(other.uShort)) return false
40- // if (!uInt.contentEquals(other.uInt)) return false
41- // if (!uLong.contentEquals(other.uLong)) return false
42- //
43- // return true
44- // }
45- //
46- // override fun hashCode(): Int {
47- // var result = uByte.contentHashCode()
48- // result = 31 * result + uShort.contentHashCode()
49- // result = 31 * result + uInt.contentHashCode()
50- // result = 31 * result + uLong.contentHashCode()
51- // return result
52- // }
53- // }
24+ @ExperimentalUnsignedTypes
25+ @Serializable
26+ data class UnsignedArrays (
27+ val uByte : UByteArray ,
28+ val uShort : UShortArray ,
29+ val uInt : UIntArray ,
30+ val uLong : ULongArray
31+ ) {
32+ override fun equals (other : Any? ): Boolean {
33+ if (this == = other) return true
34+ if (other == null || this ::class != other::class ) return false
35+
36+ other as UnsignedArrays
37+
38+ if (! uByte.contentEquals(other.uByte)) return false
39+ if (! uShort.contentEquals(other.uShort)) return false
40+ if (! uInt.contentEquals(other.uInt)) return false
41+ if (! uLong.contentEquals(other.uLong)) return false
42+
43+ return true
44+ }
45+
46+ override fun hashCode (): Int {
47+ var result = uByte.contentHashCode()
48+ result = 31 * result + uShort.contentHashCode()
49+ result = 31 * result + uInt.contentHashCode()
50+ result = 31 * result + uLong.contentHashCode()
51+ return result
52+ }
53+ }
5454
5555 @Serializable
5656 data class UnsignedWithoutLong (val uInt : UInt , val uByte : UByte , val uShort : UShort )
@@ -123,18 +123,18 @@ class UnsignedIntegersTest : JsonTestBase() {
123123 ) { l, r -> l.contentEquals(r) }
124124 }
125125
126- // TODO uncomment when Kotlin 1.8.0 is released
127- // @OptIn(ExperimentalUnsignedTypes::class)
128- // fun testArrays() {
129- // val data = UnsignedArrays(
130- // ubyteArrayOf(1U, 220U),
131- // ushortArrayOf(1U, 65000U),
132- // uintArrayOf(1U, 2147483657U),
133- // ulongArrayOf(1U, 9223372036854775817U)
134- // )
135- // val json = """{"uByte":[1,220],uShort:[1,65000],uInt:[1,2147483657],uLong:[1,9223372036854775817]}"""
136- //
137- // assertJsonFormAndRestored(UnsignedArrays.serializer(), data, json)
138- // }
126+ @OptIn( ExperimentalUnsignedTypes :: class )
127+ @Test
128+ fun testArrays () {
129+ val data = UnsignedArrays (
130+ ubyteArrayOf(1U , 220U ),
131+ ushortArrayOf(1U , 65000U ),
132+ uintArrayOf(1U , 2147483657U ),
133+ ulongArrayOf(1U , 9223372036854775817U )
134+ )
135+ val json = """ {"uByte":[1,220]," uShort" :[1,65000]," uInt" :[1,2147483657]," uLong" :[1,9223372036854775817]}"""
136+
137+ assertJsonFormAndRestored(UnsignedArrays .serializer(), data, json)
138+ }
139139
140140}
0 commit comments