mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-06-14 13:13:53 +00:00
Merge remote-tracking branch 'upstream/master' into breaking
This commit is contained in:
@ -21,17 +21,23 @@ package com.sk89q.minecraft.util.commands;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class CommandContextTest {
|
||||
|
||||
private static final Logger log = Logger.getLogger(CommandContextTest.class.getCanonicalName());
|
||||
private static final Logger log = LoggerFactory.getLogger(CommandContextTest.class);
|
||||
private static final String firstCmdString = "herpderp -opw testers \"mani world\" 'another thing' because something";
|
||||
CommandContext firstCommand;
|
||||
|
||||
@ -40,7 +46,7 @@ public class CommandContextTest {
|
||||
try {
|
||||
firstCommand = new CommandContext(firstCmdString, new HashSet<>(Arrays.asList('o', 'w')));
|
||||
} catch (CommandException e) {
|
||||
log.log(Level.WARNING, "Error", e);
|
||||
log.warn("Error", e);
|
||||
fail("Unexpected exception when creating CommandContext");
|
||||
}
|
||||
}
|
||||
@ -79,7 +85,7 @@ public class CommandContextTest {
|
||||
new CommandContext(cmd);
|
||||
new CommandContext(cmd2);
|
||||
} catch (CommandException e) {
|
||||
log.log(Level.WARNING, "Error", e);
|
||||
log.warn("Error", e);
|
||||
fail("Error creating CommandContext");
|
||||
}
|
||||
}
|
||||
@ -90,7 +96,7 @@ public class CommandContextTest {
|
||||
try {
|
||||
new CommandContext(cmd);
|
||||
} catch (CommandException e) {
|
||||
log.log(Level.WARNING, "Error", e);
|
||||
log.warn("Error", e);
|
||||
fail("Error creating CommandContext");
|
||||
}
|
||||
}
|
||||
@ -101,7 +107,7 @@ public class CommandContextTest {
|
||||
try {
|
||||
new CommandContext(cmd);
|
||||
} catch (CommandException e) {
|
||||
log.log(Level.WARNING, "Error", e);
|
||||
log.warn("Error", e);
|
||||
fail("Error creating CommandContext");
|
||||
}
|
||||
}
|
||||
@ -115,7 +121,7 @@ public class CommandContextTest {
|
||||
CommandContext context2 = new CommandContext("r hello -f world");
|
||||
assertTrue(context2.hasFlag('f'));
|
||||
} catch (CommandException e) {
|
||||
log.log(Level.WARNING, "Error", e);
|
||||
log.warn("Error", e);
|
||||
fail("Error creating CommandContext");
|
||||
}
|
||||
}
|
||||
@ -131,7 +137,7 @@ public class CommandContextTest {
|
||||
CommandContext context2 = new CommandContext("pm name \"hello world\" foo bar");
|
||||
assertEquals("\"hello world\" foo bar", context2.getJoinedStrings(1));
|
||||
} catch (CommandException e) {
|
||||
log.log(Level.WARNING, "Error", e);
|
||||
log.warn("Error", e);
|
||||
fail("Error creating CommandContext");
|
||||
}
|
||||
}
|
||||
@ -143,7 +149,7 @@ public class CommandContextTest {
|
||||
assertArrayEquals(new String[] { "foo", "bar", "baz" }, context.getSlice(0));
|
||||
|
||||
} catch (CommandException e) {
|
||||
log.log(Level.WARNING, "Error", e);
|
||||
log.warn("Error", e);
|
||||
fail("Error creating CommandContext");
|
||||
}
|
||||
}
|
||||
@ -154,7 +160,7 @@ public class CommandContextTest {
|
||||
CommandContext context = new CommandContext("region flag xmas blocked-cmds \"\"");
|
||||
assertEquals(context.argsLength(), 3);
|
||||
} catch (CommandException e) {
|
||||
log.log(Level.WARNING, "Error", e);
|
||||
log.warn("Error", e);
|
||||
fail("Error creating CommandContext");
|
||||
}
|
||||
}
|
||||
|
@ -42,7 +42,7 @@ public class BlockTransformExtentTest {
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
BlockTypes.register(new BlockType("worldedit:test"));
|
||||
BlockType.REGISTRY.register("worldedit:test", new BlockType("worldedit:test"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -19,11 +19,23 @@
|
||||
|
||||
package com.sk89q.worldedit.internal.expression;
|
||||
|
||||
import static java.lang.Math.atan2;
|
||||
import static java.lang.Math.sin;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import com.sk89q.worldedit.LocalConfiguration;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.extension.platform.Platform;
|
||||
import com.sk89q.worldedit.internal.expression.lexer.LexerException;
|
||||
import com.sk89q.worldedit.internal.expression.parser.ParserException;
|
||||
import com.sk89q.worldedit.internal.expression.runtime.EvaluationException;
|
||||
import com.sk89q.worldedit.internal.expression.runtime.ExpressionEnvironment;
|
||||
import org.junit.Test;
|
||||
|
||||
import static java.lang.Math.atan2;
|
||||
import static java.lang.Math.sin;
|
||||
@ -31,6 +43,17 @@ import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
public class ExpressionTest {
|
||||
@Before
|
||||
public void setup() {
|
||||
Platform mockPlat = Mockito.mock(Platform.class);
|
||||
Mockito.when(mockPlat.getConfiguration()).thenReturn(new LocalConfiguration() {
|
||||
@Override
|
||||
public void load() {
|
||||
}
|
||||
});
|
||||
WorldEdit.getInstance().getPlatformManager().register(mockPlat);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEvaluate() throws ExpressionException {
|
||||
// check
|
||||
@ -46,7 +69,7 @@ public class ExpressionTest {
|
||||
assertEquals(atan2(3, 4), simpleEval("atan2(3, 4)"), 0);
|
||||
|
||||
// check variables
|
||||
assertEquals(8, compile("foo+bar", "foo", "bar").evaluate(5, 3), 0);
|
||||
assertEquals(8, compile("foo+bar", "foo", "bar").evaluate(5D, 3D), 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -105,7 +128,7 @@ public class ExpressionTest {
|
||||
@Test
|
||||
public void testAssign() throws ExpressionException {
|
||||
Expression foo = compile("{a=x} b=y; c=z", "x", "y", "z", "a", "b", "c");
|
||||
foo.evaluate(2, 3, 5);
|
||||
foo.evaluate(2D, 3D, 5D);
|
||||
assertEquals(2, foo.getVariable("a", false).getValue(), 0);
|
||||
assertEquals(3, foo.getVariable("b", false).getValue(), 0);
|
||||
assertEquals(5, foo.getVariable("c", false).getValue(), 0);
|
||||
@ -118,13 +141,13 @@ public class ExpressionTest {
|
||||
|
||||
// test 'dangling else'
|
||||
final Expression expression1 = compile("if (1) if (0) x=4; else y=5;", "x", "y");
|
||||
expression1.evaluate(1, 2);
|
||||
expression1.evaluate(1D, 2D);
|
||||
assertEquals(1, expression1.getVariable("x", false).getValue(), 0);
|
||||
assertEquals(5, expression1.getVariable("y", false).getValue(), 0);
|
||||
|
||||
// test if the if construct is correctly recognized as a statement
|
||||
final Expression expression2 = compile("if (0) if (1) x=5; y=4;", "x", "y");
|
||||
expression2.evaluate(1, 2);
|
||||
expression2.evaluate(1D, 2D);
|
||||
assertEquals(4, expression2.getVariable("y", false).getValue(), 0);
|
||||
}
|
||||
|
||||
@ -162,6 +185,16 @@ public class ExpressionTest {
|
||||
assertEquals(1, simpleEval("!queryRel(3,4,5,100,200)"), 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTimeout() throws Exception {
|
||||
try {
|
||||
simpleEval("for(i=0;i<256;i++){for(j=0;j<256;j++){for(k=0;k<256;k++){for(l=0;l<256;l++){ln(pi)}}}}");
|
||||
fail("Loop was not stopped.");
|
||||
} catch (EvaluationException e) {
|
||||
assertTrue(e.getMessage().contains("Calculations exceeded time limit"));
|
||||
}
|
||||
}
|
||||
|
||||
private double simpleEval(String expressionString) throws ExpressionException {
|
||||
final Expression expression = compile(expressionString);
|
||||
|
||||
|
Reference in New Issue
Block a user