Add equality checking to each command node

This commit is contained in:
Nathan Adams
2014-09-25 16:34:44 +02:00
parent f91bc15e19
commit 5760f94009
6 changed files with 128 additions and 0 deletions
@@ -1,5 +1,6 @@
package net.minecraft.commands.tree;
import com.google.common.testing.EqualsTester;
import net.minecraft.commands.context.CommandContextBuilder;
import net.minecraft.commands.exceptions.IllegalArgumentSyntaxException;
import org.junit.Before;
@@ -40,4 +41,30 @@ public class ArgumentCommandNodeTest {
public void testParseInvalid() throws Exception {
node.parse("foo", contextBuilder);
}
@Test
public void testEquals() throws Exception {
new EqualsTester()
.addEqualityGroup(
argument("foo", integer()).build(),
argument("foo", integer()).build()
)
.addEqualityGroup(
argument("bar", integer(-100, 100)).build(),
argument("bar", integer(-100, 100)).build()
)
.addEqualityGroup(
argument("foo", integer(-100, 100)).build(),
argument("foo", integer(-100, 100)).build()
)
.addEqualityGroup(
argument("foo", integer()).then(
argument("bar", integer())
).build(),
argument("foo", integer()).then(
argument("bar", integer())
).build()
)
.testEquals();
}
}
@@ -1,5 +1,6 @@
package net.minecraft.commands.tree;
import com.google.common.testing.EqualsTester;
import net.minecraft.commands.context.CommandContextBuilder;
import net.minecraft.commands.exceptions.IllegalArgumentSyntaxException;
import org.junit.Before;
@@ -38,4 +39,26 @@ public class LiteralCommandNodeTest {
public void testParseInvalid() throws Exception {
node.parse("bar", contextBuilder);
}
@Test
public void testEquals() throws Exception {
new EqualsTester()
.addEqualityGroup(
literal("foo").build(),
literal("foo").build()
)
.addEqualityGroup(
literal("bar").build(),
literal("bar").build()
)
.addEqualityGroup(
literal("foo").then(
literal("bar")
).build(),
literal("foo").then(
literal("bar")
).build()
)
.testEquals();
}
}
@@ -1,9 +1,11 @@
package net.minecraft.commands.tree;
import com.google.common.testing.EqualsTester;
import net.minecraft.commands.context.CommandContextBuilder;
import org.junit.Before;
import org.junit.Test;
import static net.minecraft.commands.builder.LiteralArgumentBuilder.literal;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;
@@ -18,6 +20,23 @@ public class RootCommandNodeTest {
@Test
public void testParse() throws Exception {
assertThat(node.parse("foo bar baz", new CommandContextBuilder()), is("foo bar baz"));
}
@Test
public void testEquals() throws Exception {
new EqualsTester()
.addEqualityGroup(
new RootCommandNode(),
new RootCommandNode()
)
.addEqualityGroup(
new RootCommandNode() {{
addChild(literal("foo").build());
}},
new RootCommandNode() {{
addChild(literal("foo").build());
}}
)
.testEquals();
}
}