I hate the fact that we started using ktfmt.
Whose decision was that anyway..?
This commit is contained in:
parent
6871341291
commit
e67d0d9310
2 changed files with 44 additions and 42 deletions
|
|
@ -1,7 +1,7 @@
|
||||||
//
|
//
|
||||||
// MIT License
|
// MIT License
|
||||||
//
|
//
|
||||||
// Copyright (c) 2021 Alexander Söderberg & Contributors
|
// Copyright (c) 2021 Alexander Söderberg & Contributors
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
// of this software and associated documentation files (the "Software"), to deal
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|
@ -40,26 +40,26 @@ class CommandBuildingDSLTest {
|
||||||
val manager = TestCommandManager()
|
val manager = TestCommandManager()
|
||||||
|
|
||||||
manager.command(
|
manager.command(
|
||||||
manager.commandBuilder("kotlin", aliases = arrayOf("alias")) {
|
manager.commandBuilder("kotlin", aliases = arrayOf("alias")) {
|
||||||
permission = "permission"
|
permission = "permission"
|
||||||
senderType<SpecificCommandSender>()
|
senderType<SpecificCommandSender>()
|
||||||
|
|
||||||
literal("dsl")
|
literal("dsl")
|
||||||
argument(argumentDescription("An amazing command argument")) {
|
argument(argumentDescription("An amazing command argument")) {
|
||||||
StringArgument.of("moment")
|
StringArgument.of("moment")
|
||||||
}
|
}
|
||||||
handler {
|
handler {
|
||||||
// ...
|
// ...
|
||||||
}
|
}
|
||||||
|
|
||||||
manager.command(copy {
|
manager.command(
|
||||||
|
copy {
|
||||||
literal("bruh_moment")
|
literal("bruh_moment")
|
||||||
handler {
|
handler {
|
||||||
// ...
|
// ...
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
})
|
||||||
)
|
|
||||||
|
|
||||||
manager.buildAndRegister("is") {
|
manager.buildAndRegister("is") {
|
||||||
commandDescription("Command description")
|
commandDescription("Command description")
|
||||||
|
|
@ -83,21 +83,22 @@ class CommandBuildingDSLTest {
|
||||||
manager.executeCommand(SpecificCommandSender(), "kotlin dsl time bruh_moment")
|
manager.executeCommand(SpecificCommandSender(), "kotlin dsl time bruh_moment")
|
||||||
|
|
||||||
Assertions.assertEquals(
|
Assertions.assertEquals(
|
||||||
manager.commandHelpHandler.allCommands.map { it.syntaxString }.sorted(),
|
manager.commandHelpHandler.allCommands.map { it.syntaxString }.sorted(),
|
||||||
setOf(
|
setOf(
|
||||||
"kotlin dsl <moment>",
|
"kotlin dsl <moment>",
|
||||||
"kotlin dsl <moment> bruh_moment",
|
"kotlin dsl <moment> bruh_moment",
|
||||||
"is",
|
"is",
|
||||||
"is this",
|
"is this",
|
||||||
"is this going",
|
"is this going",
|
||||||
"is this going too_far",
|
"is this going too_far",
|
||||||
).sorted()
|
)
|
||||||
)
|
.sorted())
|
||||||
}
|
}
|
||||||
|
|
||||||
class TestCommandManager : CommandManager<TestCommandSender>(
|
class TestCommandManager :
|
||||||
CommandExecutionCoordinator.simpleCoordinator(), CommandRegistrationHandler.nullCommandRegistrationHandler()
|
CommandManager<TestCommandSender>(
|
||||||
) {
|
CommandExecutionCoordinator.simpleCoordinator(),
|
||||||
|
CommandRegistrationHandler.nullCommandRegistrationHandler()) {
|
||||||
override fun createDefaultCommandMeta(): SimpleCommandMeta {
|
override fun createDefaultCommandMeta(): SimpleCommandMeta {
|
||||||
return SimpleCommandMeta.empty()
|
return SimpleCommandMeta.empty()
|
||||||
}
|
}
|
||||||
|
|
@ -109,5 +110,4 @@ class CommandBuildingDSLTest {
|
||||||
|
|
||||||
open class TestCommandSender
|
open class TestCommandSender
|
||||||
class SpecificCommandSender : TestCommandSender()
|
class SpecificCommandSender : TestCommandSender()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,14 +7,14 @@ import cloud.commandframework.execution.AsynchronousCommandExecutionCoordinator
|
||||||
import cloud.commandframework.internal.CommandRegistrationHandler
|
import cloud.commandframework.internal.CommandRegistrationHandler
|
||||||
import cloud.commandframework.meta.CommandMeta
|
import cloud.commandframework.meta.CommandMeta
|
||||||
import cloud.commandframework.meta.SimpleCommandMeta
|
import cloud.commandframework.meta.SimpleCommandMeta
|
||||||
|
import java.util.concurrent.Executors
|
||||||
|
import java.util.concurrent.TimeUnit
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.future.await
|
import kotlinx.coroutines.future.await
|
||||||
import kotlinx.coroutines.runBlocking
|
import kotlinx.coroutines.runBlocking
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
import org.junit.jupiter.api.BeforeEach
|
import org.junit.jupiter.api.BeforeEach
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
import java.util.concurrent.Executors
|
|
||||||
import java.util.concurrent.TimeUnit
|
|
||||||
|
|
||||||
class KotlinAnnotatedMethodsTest {
|
class KotlinAnnotatedMethodsTest {
|
||||||
|
|
||||||
|
|
@ -37,32 +37,34 @@ class KotlinAnnotatedMethodsTest {
|
||||||
@Test
|
@Test
|
||||||
fun `test suspending command methods`(): Unit = runBlocking {
|
fun `test suspending command methods`(): Unit = runBlocking {
|
||||||
AnnotationParser(commandManager, TestCommandSender::class.java) {
|
AnnotationParser(commandManager, TestCommandSender::class.java) {
|
||||||
SimpleCommandMeta.empty()
|
SimpleCommandMeta.empty()
|
||||||
}.also { it.installCoroutineSupport() }.parse(CommandMethods())
|
}
|
||||||
|
.also { it.installCoroutineSupport() }
|
||||||
|
.parse(CommandMethods())
|
||||||
|
|
||||||
commandManager.executeCommand(TestCommandSender(), "test").await()
|
commandManager.executeCommand(TestCommandSender(), "test").await()
|
||||||
}
|
}
|
||||||
|
|
||||||
private class TestCommandSender {}
|
private class TestCommandSender {}
|
||||||
|
|
||||||
private class TestCommandManager : CommandManager<TestCommandSender>(
|
private class TestCommandManager :
|
||||||
AsynchronousCommandExecutionCoordinator.newBuilder<TestCommandSender>().withExecutor(executorService).build(),
|
CommandManager<TestCommandSender>(
|
||||||
CommandRegistrationHandler.nullCommandRegistrationHandler()
|
AsynchronousCommandExecutionCoordinator.newBuilder<TestCommandSender>()
|
||||||
) {
|
.withExecutor(executorService)
|
||||||
|
.build(),
|
||||||
|
CommandRegistrationHandler.nullCommandRegistrationHandler()) {
|
||||||
|
|
||||||
override fun hasPermission(sender: TestCommandSender, permission: String): Boolean = true
|
override fun hasPermission(sender: TestCommandSender, permission: String): Boolean = true
|
||||||
|
|
||||||
override fun createDefaultCommandMeta(): CommandMeta = SimpleCommandMeta.empty()
|
override fun createDefaultCommandMeta(): CommandMeta = SimpleCommandMeta.empty()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public class CommandMethods {
|
public class CommandMethods {
|
||||||
|
|
||||||
@CommandMethod("test")
|
@CommandMethod("test")
|
||||||
public suspend fun suspendingCommand(): Unit = withContext(Dispatchers.Default) {
|
public suspend fun suspendingCommand(): Unit =
|
||||||
println("called from thread: ${Thread.currentThread().name}")
|
withContext(Dispatchers.Default) {
|
||||||
}
|
println("called from thread: ${Thread.currentThread().name}")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue