mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-25 15:40:28 +08:00
Add test raw command
This commit is contained in:
parent
ba7822cf88
commit
f51003ad58
@ -240,9 +240,9 @@ public suspend inline fun CommandSender.executeCommand(
|
||||
@JvmSynthetic
|
||||
public suspend inline fun Command.execute(
|
||||
sender: CommandSender,
|
||||
arguments: Message = EmptyMessageChain,
|
||||
vararg arguments: Message = emptyArray(),
|
||||
checkPermission: Boolean = true,
|
||||
): CommandExecuteResult = CommandManager.executeCommand(sender, this, arguments, checkPermission)
|
||||
): CommandExecuteResult = CommandManager.executeCommand(sender, this, arguments.asMessageChain(), checkPermission)
|
||||
|
||||
/**
|
||||
* 执行一个确切的指令
|
||||
@ -255,4 +255,4 @@ public suspend inline fun Command.execute(
|
||||
sender: CommandSender,
|
||||
arguments: String = "",
|
||||
checkPermission: Boolean = true,
|
||||
): CommandExecuteResult = execute(sender, PlainText(arguments), checkPermission)
|
||||
): CommandExecuteResult = execute(sender, PlainText(arguments), checkPermission = checkPermission)
|
||||
|
@ -48,6 +48,15 @@ object TestCompositeCommand : CompositeCommand(
|
||||
}
|
||||
}
|
||||
|
||||
object TestRawCommand : RawCommand(
|
||||
ConsoleCommandOwner,
|
||||
"testRaw"
|
||||
) {
|
||||
override suspend fun CommandSender.onCommand(args: MessageChain) {
|
||||
Testing.ok(args)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
object TestSimpleCommand : RawCommand(owner, "testSimple", "tsS") {
|
||||
override suspend fun CommandSender.onCommand(args: MessageChain) {
|
||||
@ -104,6 +113,17 @@ internal class TestCommand {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `test raw command`() = runBlocking {
|
||||
TestRawCommand.withRegistration {
|
||||
val result = withTesting<MessageChain> {
|
||||
assertSuccess(TestRawCommand.execute(sender, PlainText("a1"), PlainText("a2"), PlainText("a3")))
|
||||
}
|
||||
assertEquals(3, result.size)
|
||||
assertEquals("a1, a2, a3", result.joinToString())
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `test flattenCommandArgs`() {
|
||||
val result = arrayOf("test", image).flattenCommandComponents().toTypedArray()
|
||||
|
Loading…
Reference in New Issue
Block a user