From f51003ad580ce56c1c5792c60cde62ed8d77ad5f Mon Sep 17 00:00:00 2001 From: Him188 Date: Tue, 10 Nov 2020 08:55:54 +0800 Subject: [PATCH] Add test raw command --- .../src/command/CommandManager.kt | 6 +++--- .../mirai-console/test/command/TestCommand.kt | 20 +++++++++++++++++++ 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/backend/mirai-console/src/command/CommandManager.kt b/backend/mirai-console/src/command/CommandManager.kt index ee2871993..f265483b6 100644 --- a/backend/mirai-console/src/command/CommandManager.kt +++ b/backend/mirai-console/src/command/CommandManager.kt @@ -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) diff --git a/backend/mirai-console/test/command/TestCommand.kt b/backend/mirai-console/test/command/TestCommand.kt index 3a89ca769..82d7e524a 100644 --- a/backend/mirai-console/test/command/TestCommand.kt +++ b/backend/mirai-console/test/command/TestCommand.kt @@ -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 { + 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()