summaryrefslogtreecommitdiff
path: root/platform-paper/src
diff options
context:
space:
mode:
authorSho Sakuma <me@m1sk9.dev>2026-04-07 18:10:51 +0900
committerSho Sakuma <me@m1sk9.dev>2026-04-07 18:10:51 +0900
commite634887202e97be0b2dd8b850cc1dc7ab164309c (patch)
tree1e577e1993491d8239ce46be45f760abe741a393 /platform-paper/src
parent5d01be7d6d12848ed594bfa260034db8fec7882c (diff)
downloadLunaticChat-e634887202e97be0b2dd8b850cc1dc7ab164309c.tar.gz
LunaticChat-e634887202e97be0b2dd8b850cc1dc7ab164309c.tar.bz2
LunaticChat-e634887202e97be0b2dd8b850cc1dc7ab164309c.zip
test(command): add unit tests for withAliases method
Cover the new withAliases helper in LunaticCommand to satisfy codecov/patch coverage threshold (80%). Co-Authored-By: Claude <noreply@anthropic.com>
Diffstat (limited to 'platform-paper/src')
-rw-r--r--platform-paper/src/test/kotlin/dev/m1sk9/lunaticChat/paper/command/core/WithAliasesTest.kt116
1 files changed, 116 insertions, 0 deletions
diff --git a/platform-paper/src/test/kotlin/dev/m1sk9/lunaticChat/paper/command/core/WithAliasesTest.kt b/platform-paper/src/test/kotlin/dev/m1sk9/lunaticChat/paper/command/core/WithAliasesTest.kt
new file mode 100644
index 0000000..f6dff91
--- /dev/null
+++ b/platform-paper/src/test/kotlin/dev/m1sk9/lunaticChat/paper/command/core/WithAliasesTest.kt
@@ -0,0 +1,116 @@
+package dev.m1sk9.lunaticChat.paper.command.core
+
+import com.mojang.brigadier.builder.LiteralArgumentBuilder
+import dev.m1sk9.lunaticChat.paper.LunaticChat
+import io.mockk.mockk
+import io.papermc.paper.command.brigadier.CommandSourceStack
+import io.papermc.paper.command.brigadier.Commands
+import kotlin.test.Test
+import kotlin.test.assertEquals
+import kotlin.test.assertSame
+import kotlin.test.assertTrue
+
+@Suppress("UnstableApiUsage")
+class WithAliasesTest {
+ /**
+ * Test helper that exposes the protected [LunaticCommand.withAliases] method.
+ */
+ private class TestableCommand(
+ plugin: LunaticChat,
+ ) : LunaticCommand(plugin) {
+ override fun buildCommand(): LiteralArgumentBuilder<CommandSourceStack> = Commands.literal("test")
+
+ /** Expose the protected withAliases for testing. */
+ fun testWithAliases(
+ primary: LiteralArgumentBuilder<CommandSourceStack>,
+ aliases: List<String>,
+ ): List<LiteralArgumentBuilder<CommandSourceStack>> = withAliases(primary, aliases)
+ }
+
+ private val plugin = mockk<LunaticChat>(relaxed = true)
+ private val command = TestableCommand(plugin)
+
+ @Test
+ fun `withAliases with empty list returns only primary`() {
+ val primary = Commands.literal("status")
+ val result = command.testWithAliases(primary, emptyList())
+
+ assertEquals(1, result.size)
+ assertSame(primary, result[0])
+ }
+
+ @Test
+ fun `withAliases with single alias returns primary and alias`() {
+ val primary = Commands.literal("status")
+ val result = command.testWithAliases(primary, listOf("st"))
+
+ assertEquals(2, result.size)
+ assertSame(primary, result[0])
+ assertEquals("st", result[1].literal)
+ }
+
+ @Test
+ fun `withAliases with multiple aliases returns primary and all aliases`() {
+ val primary = Commands.literal("channel")
+ val result = command.testWithAliases(primary, listOf("ch", "c"))
+
+ assertEquals(3, result.size)
+ assertSame(primary, result[0])
+ assertEquals("ch", result[1].literal)
+ assertEquals("c", result[2].literal)
+ }
+
+ @Test
+ fun `withAliases copies children to alias nodes`() {
+ val primary = Commands.literal("status")
+ val child = Commands.literal("verbose")
+ primary.then(child)
+
+ val result = command.testWithAliases(primary, listOf("st"))
+
+ assertEquals(2, result.size)
+ // The alias node should have the same children as the primary
+ assertTrue(result[1].arguments.toList().isNotEmpty())
+ assertEquals(
+ primary.arguments.toList().size,
+ result[1].arguments.toList().size,
+ )
+ }
+
+ @Test
+ fun `withAliases copies executor to alias nodes`() {
+ val primary = Commands.literal("status")
+ primary.executes { 1 }
+
+ val result = command.testWithAliases(primary, listOf("st"))
+
+ assertEquals(2, result.size)
+ // The alias node should have an executor (command) set
+ assertEquals(primary.command, result[1].command)
+ }
+
+ @Test
+ fun `withAliases copies requirement to alias nodes`() {
+ val primary = Commands.literal("status")
+ val requirement: java.util.function.Predicate<CommandSourceStack> =
+ java.util.function.Predicate { false }
+ primary.requires(requirement)
+
+ val result = command.testWithAliases(primary, listOf("st"))
+
+ assertEquals(2, result.size)
+ // The alias node should have the same requirement
+ assertEquals(primary.requirement, result[1].requirement)
+ }
+
+ @Test
+ fun `withAliases without executor does not set executor on alias`() {
+ val primary = Commands.literal("status")
+ // Do not set an executor
+
+ val result = command.testWithAliases(primary, listOf("st"))
+
+ assertEquals(2, result.size)
+ assertEquals(null, result[1].command)
+ }
+}