mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-12-23 00:57:13 +00:00
added tests for ParseMode
This commit is contained in:
parent
88208016d4
commit
91ab60d1f5
@ -29,8 +29,7 @@ typealias HTML = HTMLParseMode
|
||||
@Serializer(ParseMode::class)
|
||||
internal object ParseModeSerializerObject : KSerializer<ParseMode> {
|
||||
override fun deserialize(decoder: Decoder): ParseMode {
|
||||
val mode = decoder.decodeString()
|
||||
return when (mode) {
|
||||
return when (decoder.decodeString()) {
|
||||
MarkdownParseMode.parseModeName -> MarkdownParseMode
|
||||
HTMLParseMode.parseModeName -> HTMLParseMode
|
||||
else -> throw IllegalArgumentException("Unknown parse mode")
|
||||
|
@ -71,7 +71,7 @@ class ChatIdentifierTests {
|
||||
// username without starting @ symbol
|
||||
Example(testUsername.toUsername()).let { withUsername ->
|
||||
val stringified = Json.plain.stringify(Example.serializer(), withUsername).replace("@", "")
|
||||
assertEquals(stringified, "{\"identifier\":\"${testUsername.replace("@", "")}\"}")
|
||||
assertEquals("{\"identifier\":\"${testUsername.replace("@", "")}\"}", stringified)
|
||||
val deserialized = Json.plain.parse(Example.serializer(), stringified)
|
||||
assertEquals(withUsername, deserialized)
|
||||
}
|
||||
|
@ -0,0 +1,38 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.types
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.*
|
||||
import kotlinx.serialization.ImplicitReflectionSerializer
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlinx.serialization.json.Json
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
@ImplicitReflectionSerializer
|
||||
class ParseModeTests {
|
||||
@Serializable
|
||||
data class Example(
|
||||
val mode: ParseMode
|
||||
)
|
||||
|
||||
@Test
|
||||
fun `Markdown parse mode correctly serializing and deserializing`() {
|
||||
val example = Example(Markdown)
|
||||
|
||||
val stringified = Json.plain.stringify(Example.serializer(), example)
|
||||
assertEquals("{\"mode\":\"Markdown\"}", stringified)
|
||||
|
||||
val deserialized = Json.plain.parse(Example.serializer(), stringified)
|
||||
assertEquals(example, deserialized)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `HTML parse mode correctly serializing and deserializing`() {
|
||||
val example = Example(HTML)
|
||||
|
||||
val stringified = Json.plain.stringify(Example.serializer(), example)
|
||||
assertEquals("{\"mode\":\"HTML\"}", stringified)
|
||||
|
||||
val deserialized = Json.plain.parse(Example.serializer(), stringified)
|
||||
assertEquals(example, deserialized)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user