1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-11-22 08:13:47 +00:00
This commit is contained in:
InsanusMokrassar 2020-03-22 13:53:42 +06:00
parent 6b3f836096
commit c85faa73c0

View File

@ -1,5 +1,6 @@
package com.github.insanusmokrassar.TelegramBotAPI.types
import com.github.insanusmokrassar.TelegramBotAPI.utils.nonstrictJsonFormat
import kotlinx.serialization.ImplicitReflectionSerializer
import kotlinx.serialization.Serializable
import kotlinx.serialization.json.Json
@ -54,25 +55,25 @@ class ChatIdentifierTests {
)
Example(chatIdentifierChatId.toChatId()).let { withChatId ->
val stringified = Json.plain.stringify(Example.serializer(), withChatId)
val stringified = nonstrictJsonFormat.stringify(Example.serializer(), withChatId)
assertEquals(stringified, "{\"identifier\":$chatIdentifierChatId}")
val deserialized = Json.plain.parse(Example.serializer(), stringified)
val deserialized = nonstrictJsonFormat.parse(Example.serializer(), stringified)
assertEquals(withChatId, deserialized)
}
Example(testUsername.toUsername()).let { withUsername ->
val stringified = Json.plain.stringify(Example.serializer(), withUsername)
val stringified = nonstrictJsonFormat.stringify(Example.serializer(), withUsername)
assertEquals(stringified, "{\"identifier\":\"$testUsername\"}")
val deserialized = Json.plain.parse(Example.serializer(), stringified)
val deserialized = nonstrictJsonFormat.parse(Example.serializer(), stringified)
assertEquals(withUsername, deserialized)
}
// Replace @ by empty string, because from time to time we can retrieve from Telegram system
// username without starting @ symbol
Example(testUsername.toUsername()).let { withUsername ->
val stringified = Json.plain.stringify(Example.serializer(), withUsername).replace("@", "")
val stringified = nonstrictJsonFormat.stringify(Example.serializer(), withUsername).replace("@", "")
assertEquals("{\"identifier\":\"${testUsername.replace("@", "")}\"}", stringified)
val deserialized = Json.plain.parse(Example.serializer(), stringified)
val deserialized = nonstrictJsonFormat.parse(Example.serializer(), stringified)
assertEquals(withUsername, deserialized)
}
}