Commands can be parsed, in a very limited way.
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
package net.minecraft.commands.arguments;
|
||||
|
||||
import net.minecraft.commands.exceptions.IllegalCommandArgumentException;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static net.minecraft.commands.arguments.IntegerArgumentType.integer;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
public class IntegerArgumentTypeTest {
|
||||
IntegerArgumentType type;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
type = integer(-100, 100);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParse() throws Exception {
|
||||
assertThat(type.parse("50"), is(50));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalCommandArgumentException.class)
|
||||
public void testParseInvalid() throws Exception {
|
||||
type.parse("fifty");
|
||||
}
|
||||
|
||||
@Test(expected = IllegalCommandArgumentException.class)
|
||||
public void testParseTooLow() throws Exception {
|
||||
type.parse("-101");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseLowerLimit() throws Exception {
|
||||
assertThat(type.parse("-100"), is(-100));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalCommandArgumentException.class)
|
||||
public void testParseTooHigh() throws Exception {
|
||||
type.parse("101");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseHigherLimit() throws Exception {
|
||||
assertThat(type.parse("100"), is(100));
|
||||
}
|
||||
}
|
||||
@@ -13,8 +13,8 @@ import static org.hamcrest.Matchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
public class RequiredArgumentBuilderTest {
|
||||
@Mock CommandArgumentType type;
|
||||
RequiredArgumentBuilder builder;
|
||||
@Mock CommandArgumentType<Integer> type;
|
||||
RequiredArgumentBuilder<Integer> builder;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
@@ -23,7 +23,7 @@ public class RequiredArgumentBuilderTest {
|
||||
|
||||
@Test
|
||||
public void testBuild() throws Exception {
|
||||
ArgumentCommandNode node = builder.build();
|
||||
ArgumentCommandNode<Integer> node = builder.build();
|
||||
|
||||
assertThat(node.getName(), is("foo"));
|
||||
assertThat(node.getType(), is(type));
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
package net.minecraft.commands.tree;
|
||||
|
||||
import net.minecraft.commands.exceptions.IllegalCommandArgumentException;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static net.minecraft.commands.arguments.IntegerArgumentType.integer;
|
||||
import static net.minecraft.commands.builder.RequiredArgumentBuilder.argument;
|
||||
|
||||
public class ArgumentCommandNodeTest {
|
||||
ArgumentCommandNode node;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
node = argument("foo", integer()).build();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParse() throws Exception {
|
||||
node.parse("123");
|
||||
}
|
||||
|
||||
@Test(expected = IllegalCommandArgumentException.class)
|
||||
public void testParseInvalid() throws Exception {
|
||||
node.parse("bar");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package net.minecraft.commands.tree;
|
||||
|
||||
import net.minecraft.commands.exceptions.IllegalCommandArgumentException;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static net.minecraft.commands.builder.CommandBuilder.command;
|
||||
|
||||
public class LiteralCommandNodeTest {
|
||||
LiteralCommandNode node;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
node = command("foo").build();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParse() throws Exception {
|
||||
node.parse("foo");
|
||||
}
|
||||
|
||||
@Test(expected = IllegalCommandArgumentException.class)
|
||||
public void testParseInvalid() throws Exception {
|
||||
node.parse("bar");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user