gradle updates

This commit is contained in:
MattBDev 2019-08-15 15:35:45 -04:00
parent cbbe8b5dfa
commit f8758994c3
2 changed files with 71 additions and 73 deletions

View File

@ -50,6 +50,11 @@ dependencies {
compile 'com.mojang:datafixerupper:1.0.20' compile 'com.mojang:datafixerupper:1.0.20'
compile 'com.github.luben:zstd-jni:1.1.1' compile 'com.github.luben:zstd-jni:1.1.1'
compile 'co.aikar:fastutil-lite:1.0' compile 'co.aikar:fastutil-lite:1.0'
testImplementation ("org.junit.jupiter:junit-jupiter-api:5.5.0")
testImplementation ("org.junit.jupiter:junit-jupiter-params:5.5.0")
testImplementation ("org.mockito:mockito-core:3.0.0")
testImplementation ("org.mockito:mockito-junit-jupiter:3.0.0")
testRuntime ("org.junit.jupiter:junit-jupiter-engine:5.5.0")
} }
tasks.withType(JavaCompile).configureEach { tasks.withType(JavaCompile).configureEach {

View File

@ -19,16 +19,6 @@
package com.sk89q.worldedit.internal.expression; 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.LocalConfiguration;
import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.extension.platform.Platform; import com.sk89q.worldedit.extension.platform.Platform;
@ -36,17 +26,27 @@ import com.sk89q.worldedit.internal.expression.lexer.LexerException;
import com.sk89q.worldedit.internal.expression.parser.ParserException; import com.sk89q.worldedit.internal.expression.parser.ParserException;
import com.sk89q.worldedit.internal.expression.runtime.EvaluationException; import com.sk89q.worldedit.internal.expression.runtime.EvaluationException;
import com.sk89q.worldedit.internal.expression.runtime.ExpressionEnvironment; import com.sk89q.worldedit.internal.expression.runtime.ExpressionEnvironment;
import com.sk89q.worldedit.internal.expression.runtime.ExpressionTimeoutException;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static java.lang.Math.atan2; import static java.lang.Math.atan2;
import static java.lang.Math.sin; import static java.lang.Math.sin;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertAll;
import static org.junit.Assert.fail; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
public class ExpressionTest { public class ExpressionTest {
@Before
private Platform mockPlat = mock(Platform.class);
@BeforeEach
public void setup() { public void setup() {
Platform mockPlat = Mockito.mock(Platform.class); when(mockPlat.getConfiguration()).thenReturn(new LocalConfiguration() {
Mockito.when(mockPlat.getConfiguration()).thenReturn(new LocalConfiguration() {
@Override @Override
public void load() { public void load() {
} }
@ -54,6 +54,11 @@ public class ExpressionTest {
WorldEdit.getInstance().getPlatformManager().register(mockPlat); WorldEdit.getInstance().getPlatformManager().register(mockPlat);
} }
@AfterEach
public void tearDown() {
WorldEdit.getInstance().getPlatformManager().unregister(mockPlat);
}
@Test @Test
public void testEvaluate() throws ExpressionException { public void testEvaluate() throws ExpressionException {
// check // check
@ -73,56 +78,46 @@ public class ExpressionTest {
} }
@Test @Test
public void testErrors() throws ExpressionException { public void testErrors() {
// test lexer errors assertAll(
try { // test lexer errors
compile("#"); () -> {
fail("Error expected"); LexerException e = assertThrows(LexerException.class,
} catch (LexerException e) { () -> compile("#"));
assertEquals("Error position", 0, e.getPosition()); assertEquals(0, e.getPosition(), "Error position");
} },
// test parser errors
// test parser errors () -> {
try { ParserException e = assertThrows(ParserException.class,
compile("x"); () -> compile("x"));
fail("Error expected"); assertEquals(0, e.getPosition(), "Error position");
} catch (ParserException e) { },
assertEquals("Error position", 0, e.getPosition()); () -> {
} ParserException e = assertThrows(ParserException.class,
try { () -> compile("x()"));
compile("x()"); assertEquals(0, e.getPosition(), "Error position");
fail("Error expected"); },
} catch (ParserException e) { () -> assertThrows(ParserException.class,
assertEquals("Error position", 0, e.getPosition()); () -> compile("(")),
} () -> assertThrows(ParserException.class,
try { () -> compile("x(")),
compile("("); // test overloader errors
fail("Error expected"); () -> {
} catch (ParserException ignored) {} ParserException e = assertThrows(ParserException.class,
try { () -> compile("atan2(1)"));
compile("x("); assertEquals(0, e.getPosition(), "Error position");
fail("Error expected"); },
} catch (ParserException ignored) {} () -> {
ParserException e = assertThrows(ParserException.class,
// test overloader errors () -> compile("atan2(1, 2, 3)"));
try { assertEquals(0, e.getPosition(), "Error position");
compile("atan2(1)"); },
fail("Error expected"); () -> {
} catch (ParserException e) { ParserException e = assertThrows(ParserException.class,
assertEquals("Error position", 0, e.getPosition()); () -> compile("rotate(1, 2, 3)"));
} assertEquals(0, e.getPosition(), "Error position");
try { }
compile("atan2(1, 2, 3)"); );
fail("Error expected");
} catch (ParserException e) {
assertEquals("Error position", 0, e.getPosition());
}
try {
compile("rotate(1, 2, 3)");
fail("Error expected");
} catch (ParserException e) {
assertEquals("Error position", 0, e.getPosition());
}
} }
@Test @Test
@ -186,13 +181,11 @@ public class ExpressionTest {
} }
@Test @Test
public void testTimeout() throws Exception { public void testTimeout() {
try { ExpressionTimeoutException e = assertThrows(ExpressionTimeoutException.class,
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)}}}}"); () -> 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."); "Loop was not stopped.");
} catch (EvaluationException e) { assertTrue(e.getMessage().contains("Calculations exceeded time limit"));
assertTrue(e.getMessage().contains("Calculations exceeded time limit"));
}
} }
private double simpleEval(String expressionString) throws ExpressionException { private double simpleEval(String expressionString) throws ExpressionException {