mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-11-26 03:58:44 +00:00
fixes
This commit is contained in:
parent
6b3f836096
commit
c85faa73c0
@ -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)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user