mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-06-03 00:15:27 +00:00
143 lines
3.9 KiB
Kotlin
143 lines
3.9 KiB
Kotlin
package com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity
|
|
|
|
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity.textsources.*
|
|
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.MarkdownV2
|
|
import com.github.insanusmokrassar.TelegramBotAPI.utils.*
|
|
import kotlin.test.*
|
|
|
|
class TextPartsCreatingTests {
|
|
@Test
|
|
fun testThatTextWithMultilevelPartsCorrectlyCreating() {
|
|
val text = "It is simple hello world"
|
|
val formattedV2Text = "It *_is_ ~__simple__~* hello world"
|
|
val entities = listOf(
|
|
RawMessageEntity(
|
|
"bold",
|
|
3,
|
|
9
|
|
),
|
|
RawMessageEntity(
|
|
"italic",
|
|
3,
|
|
2
|
|
),
|
|
RawMessageEntity(
|
|
"strikethrough",
|
|
6,
|
|
6
|
|
),
|
|
RawMessageEntity(
|
|
"underline",
|
|
6,
|
|
6
|
|
)
|
|
)
|
|
|
|
val textParts = createTextPart(text, entities)
|
|
|
|
|
|
assertTrue (
|
|
textParts.first().source is BoldTextSource
|
|
)
|
|
|
|
val boldSource = textParts.first().source as BoldTextSource
|
|
assertTrue (
|
|
boldSource.textParts.first().source is ItalicTextSource
|
|
)
|
|
assertTrue (
|
|
boldSource.textParts[1].source is RegularTextSource
|
|
)
|
|
assertTrue (
|
|
boldSource.textParts[2].source is StrikethroughTextSource
|
|
)
|
|
assertTrue (
|
|
(boldSource.textParts[2].source as StrikethroughTextSource).textParts.first().source is UnderlineTextSource
|
|
)
|
|
|
|
|
|
val fullTextParts = text.fullListOfSubSource(textParts)
|
|
|
|
assertTrue(
|
|
fullTextParts.first().source is RegularTextSource
|
|
)
|
|
assertTrue(
|
|
fullTextParts[1].source is BoldTextSource
|
|
)
|
|
assertTrue(
|
|
fullTextParts[2].source is RegularTextSource
|
|
)
|
|
|
|
assertEquals(
|
|
formattedV2Text,
|
|
createMarkdownV2Text(fullTextParts.map { it.source }).first()
|
|
)
|
|
}
|
|
|
|
@Test
|
|
fun testThatTextWithMultilevelPartsCorrectlyCreatingInHtml() {
|
|
val text = "It is simple hello world"
|
|
val formattedHtmlText = "It <b><i>is</i> <s><u>simple</u></s></b> hello world"
|
|
val entities = listOf(
|
|
RawMessageEntity(
|
|
"bold",
|
|
3,
|
|
9
|
|
),
|
|
RawMessageEntity(
|
|
"italic",
|
|
3,
|
|
2
|
|
),
|
|
RawMessageEntity(
|
|
"strikethrough",
|
|
6,
|
|
6
|
|
),
|
|
RawMessageEntity(
|
|
"underline",
|
|
6,
|
|
6
|
|
)
|
|
)
|
|
|
|
val textParts = createTextPart(text, entities)
|
|
|
|
|
|
assertTrue (
|
|
textParts.first().source is BoldTextSource
|
|
)
|
|
|
|
val boldSource = textParts.first().source as BoldTextSource
|
|
assertTrue (
|
|
boldSource.textParts.first().source is ItalicTextSource
|
|
)
|
|
assertTrue (
|
|
boldSource.textParts[1].source is RegularTextSource
|
|
)
|
|
assertTrue (
|
|
boldSource.textParts[2].source is StrikethroughTextSource
|
|
)
|
|
assertTrue (
|
|
(boldSource.textParts[2].source as StrikethroughTextSource).textParts.first().source is UnderlineTextSource
|
|
)
|
|
|
|
|
|
val fullTextParts = text.fullListOfSubSource(textParts)
|
|
|
|
assertTrue(
|
|
fullTextParts.first().source is RegularTextSource
|
|
)
|
|
assertTrue(
|
|
fullTextParts[1].source is BoldTextSource
|
|
)
|
|
assertTrue(
|
|
fullTextParts[2].source is RegularTextSource
|
|
)
|
|
|
|
assertEquals(
|
|
formattedHtmlText,
|
|
createHtmlText(fullTextParts.map { it.source }).first()
|
|
)
|
|
}
|
|
}
|