Move test

This commit is contained in:
Noel Németh 2022-08-16 13:16:20 +02:00
parent 8b74a7f1b8
commit f6596926f6
2 changed files with 21 additions and 20 deletions

View File

@ -2,9 +2,12 @@ package net.minestom.server.command;
import net.minestom.server.command.builder.Command;
import net.minestom.server.command.builder.CommandContext;
import net.minestom.server.command.builder.arguments.ArgumentType;
import net.minestom.server.command.builder.condition.CommandCondition;
import org.junit.jupiter.api.Test;
import java.util.concurrent.atomic.AtomicBoolean;
import static net.minestom.server.command.builder.arguments.ArgumentType.Literal;
import static org.junit.jupiter.api.Assertions.*;
@ -81,6 +84,24 @@ public class GraphConversionExecutorTest {
assertFalse(condition.canUse(null, null));
}
@Test
public void issue1326() {
final AtomicBoolean b = new AtomicBoolean(true);
var cmd = new Command("tp") {{
addConditionalSyntax((s, c) -> b.getAndSet(false), null, ArgumentType.Entity("target"),
ArgumentType.Double("x"), ArgumentType.Double("y"), ArgumentType.Double("z"));
}};
var graph = Graph.fromCommand(cmd);
final Graph.Node target = graph.root().next().get(0);
final Graph.Execution execution = target.execution();
assertNotNull(execution);
final CommandCondition condition = execution.condition();
assertNotNull(condition);
assertTrue(condition.canUse(null, null));
assertFalse(b.get(), "Condition wasn't executed.");
}
private static void dummyExecutor(CommandSender sender, CommandContext context) {
}
}

View File

@ -2,8 +2,6 @@ package net.minestom.server.command;
import net.minestom.server.command.builder.Command;
import net.minestom.server.command.builder.CommandContext;
import net.minestom.server.command.builder.arguments.ArgumentType;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import static net.minestom.server.command.builder.arguments.ArgumentType.Enum;
@ -117,24 +115,6 @@ public class GraphConversionTest {
assertEqualsGraph(graph, main);
}
@Test
//TODO See disable reason
@Disabled("Graphs' execution cannot be compared properly which makes this test pass when it shouldn't.")
public void issue1326() {
var cmd = new Command("tp") {{
addConditionalSyntax((s, c) -> s instanceof ConsoleSender, null, ArgumentType.Entity("target"),
ArgumentType.Double("x"), ArgumentType.Double("y"), ArgumentType.Double("z"));
}};
var graph = Graph.builder(ArgumentType.Literal("tp"))
.append(ArgumentType.Entity("target"),
new GraphImpl.ExecutionImpl(sender -> sender instanceof ConsoleSender,
null, null, null, null), b ->
b.append(ArgumentType.Double("x"), b1 ->
b1.append(ArgumentType.Double("y"), b2 ->
b2.append(ArgumentType.Double("z"))))).build();
assertEqualsGraph(graph, cmd);
}
private static void assertEqualsGraph(Graph expected, Command command) {
final Graph actual = Graph.fromCommand(command);
assertTrue(expected.compare(actual, Graph.Comparator.TREE), () -> {