Files
JChatGPT/src/test/kotlin/profile/ProfileMessageRendererTest.kt
T
jie65535 23299b2ae7 profile: add progressive user profiles
Add cache-expiry profile maintenance and contextual injection, reorganize runtime code by responsibility, remove automatic favorability decay, and prepare version 1.15.0.
2026-08-02 21:45:34 +08:00

47 lines
1.5 KiB
Kotlin

package top.jie65535.mirai.profile
import net.mamoe.mirai.message.data.MessageSourceKind
import top.jie65535.mirai.data.ChatMessageRecord
import kotlin.test.Test
import kotlin.test.assertEquals
class ProfileMessageRendererTest {
@Test
fun rendersStoredJsonWithoutMiraiRuntime() {
val record = record(
"""
[
{"type":"QuoteReply","source":{"fromId":200,"originalMessage":[{"type":"PlainText","content":"我在公明工作"}]}},
{"type":"At","target":200},
{"type":"PlainText","content":" 这说的是你,不是我"},
{"type":"Image","isEmoji":false}
]
""".trimIndent()
)
assertEquals(
"[引用 U1: 我在公明工作]@U1 这说的是你,不是我[图片]",
ProfileMessageRenderer.render(record, mapOf(100L to "TARGET", 200L to "U1"), 500),
)
assertEquals(setOf(200L), ProfileMessageRenderer.referencedUserIds(record))
}
@Test
fun truncatesLongMessagesAfterRendering() {
val record = record("""[{"type":"PlainText","content":"1234567890"}]""")
assertEquals("12345678...[截断]", ProfileMessageRenderer.render(record, emptyMap(), 8))
}
private fun record(code: String) = ChatMessageRecord(
botId = 1,
fromId = 100,
targetId = 10,
ids = null,
internalIds = null,
time = 100,
kind = MessageSourceKind.GROUP,
code = code,
)
}