Skip to content

Commit

Permalink
Add tests for UuidSerializer that were supposed to work in Kotlin 2.1 (
Browse files Browse the repository at this point in the history
  • Loading branch information
sandwwraith authored Dec 18, 2024
1 parent d62f3b8 commit fa797bc
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,7 @@ class SerializersLookupTest : JsonTestBase() {
@OptIn(ExperimentalUuidApi::class)
fun testLookupUuid() {
assertSame<KSerializer<*>?>(Uuid.serializer(), serializerOrNull(typeOf<Uuid>()))
// TODO: uncomment in 2.1 release
// assertSame<KSerializer<*>?>(Uuid.serializer(), serializer<Uuid>())
assertSame<KSerializer<*>?>(Uuid.serializer(), serializer<Uuid>())
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,32 @@ class UuidTest : JsonTestBase() {
assertJsonFormAndRestored(Uuid.serializer(), uuid, "\"$uuid\"")
}

// TODO: write a test without @Contextual after 2.1.0 release
@Serializable
data class Holder(@Contextual val uuid: Uuid)
data class Holder(val uuid: Uuid)

@Serializable
data class HolderContextual(@Contextual val uuid: Uuid)

val json = Json { serializersModule = serializersModuleOf(Uuid.serializer()) }

@Test
fun testNested() {
fun testCompiled() {
val fixed = Uuid.parse("bc501c76-d806-4578-b45e-97a264e280f1")
assertJsonFormAndRestored(
Holder.serializer(),
Holder(fixed),
"""{"uuid":"bc501c76-d806-4578-b45e-97a264e280f1"}""",
Json
)
}

@Test
fun testContextual() {
val fixed = Uuid.parse("bc501c76-d806-4578-b45e-97a264e280f1")
assertJsonFormAndRestored(
HolderContextual.serializer(),
HolderContextual(fixed),
"""{"uuid":"bc501c76-d806-4578-b45e-97a264e280f1"}""",
json
)
}
Expand Down

0 comments on commit fa797bc

Please sign in to comment.