File tree Expand file tree Collapse file tree 2 files changed +36
-0
lines changed
commonMain/src/kotlinx/serialization/internal
commonTest/src/kotlinx/serialization Expand file tree Collapse file tree 2 files changed +36
-0
lines changed Original file line number Diff line number Diff line change @@ -58,6 +58,13 @@ internal class PrimitiveSerialDescriptor(
58
58
override fun getElementDescriptor (index : Int ): SerialDescriptor = error()
59
59
override fun getElementAnnotations (index : Int ): List <Annotation > = error()
60
60
override fun toString (): String = " PrimitiveDescriptor($serialName )"
61
+ override fun equals (other : Any? ): Boolean {
62
+ if (this == = other) return true
63
+ if (other !is PrimitiveSerialDescriptor ) return false
64
+ if (serialName == other.serialName && kind == other.kind) return true
65
+ return false
66
+ }
67
+ override fun hashCode () = serialName.hashCode() + 31 * kind.hashCode()
61
68
private fun error (): Nothing = throw IllegalStateException (" Primitive descriptor does not have elements" )
62
69
}
63
70
Original file line number Diff line number Diff line change
1
+ package kotlinx.serialization
2
+
3
+ import kotlinx.serialization.descriptors.PrimitiveKind
4
+ import kotlinx.serialization.internal.PrimitiveSerialDescriptor
5
+ import kotlin.test.Test
6
+ import kotlin.test.assertEquals
7
+ import kotlin.test.assertNotSame
8
+
9
+ class PrimitiveSerialDescriptorTest {
10
+
11
+ @Test
12
+ fun testEqualsImplemented () {
13
+ val first = PrimitiveSerialDescriptor (" test_name" , PrimitiveKind .LONG )
14
+ val second = PrimitiveSerialDescriptor (" test_name" , PrimitiveKind .LONG )
15
+
16
+ assertNotSame(first, second)
17
+ assertEquals(first, second)
18
+ }
19
+
20
+ @Test
21
+ fun testHashCodeStability () {
22
+ val first = PrimitiveSerialDescriptor (" test_name" , PrimitiveKind .LONG )
23
+ val second = PrimitiveSerialDescriptor (" test_name" , PrimitiveKind .LONG )
24
+
25
+ assertNotSame(first, second)
26
+ assertEquals(first.hashCode(), second.hashCode())
27
+ }
28
+
29
+ }
You can’t perform that action at this time.
0 commit comments