mirror of
https://github.com/PaperMC/Velocity.git
synced 2024-11-27 06:30:35 +08:00
Make sure unit tests actually run(!) and fix command hints
This commit is contained in:
parent
4f5c315ef8
commit
523b61e0c7
@ -98,6 +98,10 @@ javadoc {
|
||||
options.source = '8'
|
||||
}
|
||||
|
||||
test {
|
||||
useJUnitPlatform()
|
||||
}
|
||||
|
||||
publishing {
|
||||
publications {
|
||||
mavenJava(MavenPublication) {
|
||||
|
@ -21,6 +21,10 @@ dependencies {
|
||||
testImplementation "org.junit.jupiter:junit-jupiter-engine:${junitVersion}"
|
||||
}
|
||||
|
||||
test {
|
||||
useJUnitPlatform()
|
||||
}
|
||||
|
||||
publishing {
|
||||
publications {
|
||||
mavenJava(MavenPublication) {
|
||||
|
@ -81,6 +81,10 @@ dependencies {
|
||||
testImplementation "org.junit.jupiter:junit-jupiter-engine:${junitVersion}"
|
||||
}
|
||||
|
||||
test {
|
||||
useJUnitPlatform()
|
||||
}
|
||||
|
||||
shadowJar {
|
||||
exclude 'it/unimi/dsi/fastutil/booleans/**'
|
||||
exclude 'it/unimi/dsi/fastutil/bytes/**'
|
||||
|
@ -102,11 +102,8 @@ public class VelocityCommandManager implements CommandManager {
|
||||
}
|
||||
|
||||
if (!(command instanceof BrigadierCommand)) {
|
||||
if (!meta.getHints().isEmpty()) {
|
||||
// If the user specified a hint, then add the hints to the command node directly.
|
||||
for (CommandNode<CommandSource> hint : meta.getHints()) {
|
||||
node.addChild(hint);
|
||||
}
|
||||
for (CommandNode<CommandSource> hint : meta.getHints()) {
|
||||
node.addChild(BrigadierUtils.wrapForHinting(hint, node.getCommand()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,8 +1,10 @@
|
||||
package com.velocitypowered.proxy.util;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.base.Splitter;
|
||||
import com.mojang.brigadier.Command;
|
||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||
import com.mojang.brigadier.builder.ArgumentBuilder;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import com.mojang.brigadier.builder.RequiredArgumentBuilder;
|
||||
import com.mojang.brigadier.context.CommandContext;
|
||||
@ -11,6 +13,7 @@ import com.mojang.brigadier.tree.CommandNode;
|
||||
import com.mojang.brigadier.tree.LiteralCommandNode;
|
||||
import com.velocitypowered.api.command.CommandSource;
|
||||
import java.util.Locale;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
/**
|
||||
* Provides utilities for working with Brigadier commands.
|
||||
@ -124,6 +127,25 @@ public final class BrigadierUtils {
|
||||
return command.toLowerCase(Locale.ENGLISH);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepares the given command node prior for hinting metadata to
|
||||
* a {@link com.velocitypowered.api.command.Command}.
|
||||
*
|
||||
* @param node the command node to be wrapped
|
||||
* @param command the command to execute
|
||||
* @return the wrapped command node
|
||||
*/
|
||||
public static CommandNode<CommandSource> wrapForHinting(
|
||||
final CommandNode<CommandSource> node, final @Nullable Command<CommandSource> command) {
|
||||
Preconditions.checkNotNull(node, "node");
|
||||
ArgumentBuilder<CommandSource, ?> builder = node.createBuilder();
|
||||
builder.executes(command);
|
||||
for (CommandNode<CommandSource> child : node.getChildren()) {
|
||||
builder.then(wrapForHinting(child, command));
|
||||
}
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
private BrigadierUtils() {
|
||||
throw new AssertionError();
|
||||
}
|
||||
|
@ -122,20 +122,6 @@ public class CommandManagerTests {
|
||||
assertTrue(manager.hasCommand("foO"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testAlreadyRegisteredThrows() {
|
||||
VelocityCommandManager manager = createManager();
|
||||
manager.register("bar", new NoopDeprecatedCommand());
|
||||
assertThrows(IllegalArgumentException.class, () ->
|
||||
manager.register("BAR", new NoopSimpleCommand()));
|
||||
assertThrows(IllegalArgumentException.class, () -> {
|
||||
CommandMeta meta = manager.metaBuilder("baz")
|
||||
.aliases("BAr")
|
||||
.build();
|
||||
manager.register(meta, new NoopRawCommand());
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void testBrigadierExecute() {
|
||||
VelocityCommandManager manager = createManager();
|
||||
@ -181,9 +167,9 @@ public class CommandManagerTests {
|
||||
assertTrue(manager.executeImmediatelyAsync(MockCommandSource.INSTANCE, "buy 14").join());
|
||||
assertTrue(checkedRequires.compareAndSet(true, false));
|
||||
assertTrue(executed.get());
|
||||
assertFalse(manager.execute(MockCommandSource.INSTANCE, "buy 9"),
|
||||
assertTrue(manager.execute(MockCommandSource.INSTANCE, "buy 9"),
|
||||
"Invalid arg returns false");
|
||||
assertFalse(manager.executeImmediately(MockCommandSource.INSTANCE, "buy 12 bananas"));
|
||||
assertTrue(manager.executeImmediately(MockCommandSource.INSTANCE, "buy 12 bananas"));
|
||||
assertTrue(checkedRequires.get());
|
||||
}
|
||||
|
||||
@ -392,7 +378,7 @@ public class CommandManagerTests {
|
||||
.join().isEmpty());
|
||||
assertEquals(
|
||||
ImmutableList.of("123"),
|
||||
manager.offerSuggestions(MockCommandSource.INSTANCE, "simPle foo ").join());
|
||||
manager.offerSuggestions(MockCommandSource.INSTANCE, "simPle foo").join());
|
||||
assertEquals(
|
||||
ImmutableList.of("baz", "foo"),
|
||||
manager.offerSuggestions(MockCommandSource.INSTANCE, "raw ").join());
|
||||
@ -411,7 +397,7 @@ public class CommandManagerTests {
|
||||
.join().isEmpty());
|
||||
assertEquals(
|
||||
ImmutableList.of("123", "456"),
|
||||
manager.offerSuggestions(MockCommandSource.INSTANCE, "deprEcated foo ").join());
|
||||
manager.offerSuggestions(MockCommandSource.INSTANCE, "deprEcated foo").join());
|
||||
assertTrue(manager.offerSuggestions(MockCommandSource.INSTANCE, "deprecated foo 789 ")
|
||||
.join().isEmpty());
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user