I hate the fact that we started using ktfmt.

Whose decision was that anyway..?
This commit is contained in:
Alexander Söderberg 2021-07-10 11:42:40 +01:00 committed by Jason
parent 6871341291
commit e67d0d9310
2 changed files with 44 additions and 42 deletions

View file

@ -1,7 +1,7 @@
//
// 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
// of this software and associated documentation files (the "Software"), to deal
@ -40,26 +40,26 @@ class CommandBuildingDSLTest {
val manager = TestCommandManager()
manager.command(
manager.commandBuilder("kotlin", aliases = arrayOf("alias")) {
permission = "permission"
senderType<SpecificCommandSender>()
manager.commandBuilder("kotlin", aliases = arrayOf("alias")) {
permission = "permission"
senderType<SpecificCommandSender>()
literal("dsl")
argument(argumentDescription("An amazing command argument")) {
StringArgument.of("moment")
}
handler {
// ...
}
literal("dsl")
argument(argumentDescription("An amazing command argument")) {
StringArgument.of("moment")
}
handler {
// ...
}
manager.command(copy {
manager.command(
copy {
literal("bruh_moment")
handler {
// ...
}
})
}
)
})
manager.buildAndRegister("is") {
commandDescription("Command description")
@ -83,21 +83,22 @@ class CommandBuildingDSLTest {
manager.executeCommand(SpecificCommandSender(), "kotlin dsl time bruh_moment")
Assertions.assertEquals(
manager.commandHelpHandler.allCommands.map { it.syntaxString }.sorted(),
setOf(
"kotlin dsl <moment>",
"kotlin dsl <moment> bruh_moment",
"is",
"is this",
"is this going",
"is this going too_far",
).sorted()
)
manager.commandHelpHandler.allCommands.map { it.syntaxString }.sorted(),
setOf(
"kotlin dsl <moment>",
"kotlin dsl <moment> bruh_moment",
"is",
"is this",
"is this going",
"is this going too_far",
)
.sorted())
}
class TestCommandManager : CommandManager<TestCommandSender>(
CommandExecutionCoordinator.simpleCoordinator(), CommandRegistrationHandler.nullCommandRegistrationHandler()
) {
class TestCommandManager :
CommandManager<TestCommandSender>(
CommandExecutionCoordinator.simpleCoordinator(),
CommandRegistrationHandler.nullCommandRegistrationHandler()) {
override fun createDefaultCommandMeta(): SimpleCommandMeta {
return SimpleCommandMeta.empty()
}
@ -109,5 +110,4 @@ class CommandBuildingDSLTest {
open class TestCommandSender
class SpecificCommandSender : TestCommandSender()
}

View file

@ -7,14 +7,14 @@ import cloud.commandframework.execution.AsynchronousCommandExecutionCoordinator
import cloud.commandframework.internal.CommandRegistrationHandler
import cloud.commandframework.meta.CommandMeta
import cloud.commandframework.meta.SimpleCommandMeta
import java.util.concurrent.Executors
import java.util.concurrent.TimeUnit
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.future.await
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.withContext
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import java.util.concurrent.Executors
import java.util.concurrent.TimeUnit
class KotlinAnnotatedMethodsTest {
@ -37,32 +37,34 @@ class KotlinAnnotatedMethodsTest {
@Test
fun `test suspending command methods`(): Unit = runBlocking {
AnnotationParser(commandManager, TestCommandSender::class.java) {
SimpleCommandMeta.empty()
}.also { it.installCoroutineSupport() }.parse(CommandMethods())
SimpleCommandMeta.empty()
}
.also { it.installCoroutineSupport() }
.parse(CommandMethods())
commandManager.executeCommand(TestCommandSender(), "test").await()
}
private class TestCommandSender {}
private class TestCommandManager : CommandManager<TestCommandSender>(
AsynchronousCommandExecutionCoordinator.newBuilder<TestCommandSender>().withExecutor(executorService).build(),
CommandRegistrationHandler.nullCommandRegistrationHandler()
) {
private class TestCommandManager :
CommandManager<TestCommandSender>(
AsynchronousCommandExecutionCoordinator.newBuilder<TestCommandSender>()
.withExecutor(executorService)
.build(),
CommandRegistrationHandler.nullCommandRegistrationHandler()) {
override fun hasPermission(sender: TestCommandSender, permission: String): Boolean = true
override fun createDefaultCommandMeta(): CommandMeta = SimpleCommandMeta.empty()
}
public class CommandMethods {
@CommandMethod("test")
public suspend fun suspendingCommand(): Unit = withContext(Dispatchers.Default) {
println("called from thread: ${Thread.currentThread().name}")
}
public suspend fun suspendingCommand(): Unit =
withContext(Dispatchers.Default) {
println("called from thread: ${Thread.currentThread().name}")
}
}
}