mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-27 00:30:17 +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
|
@JvmSynthetic
|
||||||
public suspend inline fun Command.execute(
|
public suspend inline fun Command.execute(
|
||||||
sender: CommandSender,
|
sender: CommandSender,
|
||||||
arguments: Message = EmptyMessageChain,
|
vararg arguments: Message = emptyArray(),
|
||||||
checkPermission: Boolean = true,
|
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,
|
sender: CommandSender,
|
||||||
arguments: String = "",
|
arguments: String = "",
|
||||||
checkPermission: Boolean = true,
|
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") {
|
object TestSimpleCommand : RawCommand(owner, "testSimple", "tsS") {
|
||||||
override suspend fun CommandSender.onCommand(args: MessageChain) {
|
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
|
@Test
|
||||||
fun `test flattenCommandArgs`() {
|
fun `test flattenCommandArgs`() {
|
||||||
val result = arrayOf("test", image).flattenCommandComponents().toTypedArray()
|
val result = arrayOf("test", image).flattenCommandComponents().toTypedArray()
|
||||||
|
Loading…
Reference in New Issue
Block a user