Add test raw command

This commit is contained in:
Him188 2020-11-10 08:55:54 +08:00
parent ba7822cf88
commit f51003ad58
2 changed files with 23 additions and 3 deletions

View File

@ -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)

View File

@ -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()