Added command context and the ability to query arguments from it
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
package net.minecraft.commands.arguments;
|
||||
|
||||
import net.minecraft.commands.context.CommandContext;
|
||||
import net.minecraft.commands.context.CommandContextBuilder;
|
||||
import net.minecraft.commands.exceptions.ArgumentValidationException;
|
||||
import net.minecraft.commands.exceptions.IllegalArgumentSyntaxException;
|
||||
import org.junit.Before;
|
||||
@@ -55,4 +57,11 @@ public class IntegerArgumentTypeTest {
|
||||
assertThat(result.getRaw(), is("100"));
|
||||
assertThat(result.getResult(), is(100));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetInteger() throws Exception {
|
||||
CommandContext context = new CommandContextBuilder().withArgument("foo", type.parse("100")).build();
|
||||
|
||||
assertThat(IntegerArgumentType.getInteger(context, "foo"), is(100));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package net.minecraft.commands.context;
|
||||
|
||||
import net.minecraft.commands.arguments.IntegerArgumentType;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
public class CommandContextTest {
|
||||
CommandContext context;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
context = new CommandContextBuilder().build();
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testGetArgument_nonexistent() throws Exception {
|
||||
context.getArgument("foo", Object.class);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testGetArgument_wrongType() throws Exception {
|
||||
context = new CommandContextBuilder().withArgument("foo", IntegerArgumentType.integer().parse("123")).build();
|
||||
context.getArgument("foo", String.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetArgument() throws Exception {
|
||||
context = new CommandContextBuilder().withArgument("foo", IntegerArgumentType.integer().parse("123")).build();
|
||||
assertThat(context.getArgument("foo", int.class).getResult(), is(123));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user