Mirror von
https://github.com/IntellectualSites/FastAsyncWorldEdit.git
synchronisiert 2024-12-25 02:20:07 +01:00
Register a platform for expression tests
Dieser Commit ist enthalten in:
Ursprung
bb923aeb59
Commit
21db86f26b
@ -127,34 +127,34 @@ public class Expression {
|
|||||||
((Variable) invokable).value = values[i];
|
((Variable) invokable).value = values[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
pushInstance();
|
Future<Double> result = evalThread.submit(new Callable<Double>() {
|
||||||
try {
|
@Override
|
||||||
Future<Double> result = evalThread.submit(new Callable<Double>() {
|
public Double call() throws Exception {
|
||||||
@Override
|
pushInstance();
|
||||||
public Double call() throws Exception {
|
try {
|
||||||
return root.getValue();
|
return root.getValue();
|
||||||
|
} finally {
|
||||||
|
popInstance();
|
||||||
}
|
}
|
||||||
});
|
|
||||||
try {
|
|
||||||
return result.get(WorldEdit.getInstance().getConfiguration().calculationTimeout, TimeUnit.MILLISECONDS);
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
Thread.currentThread().interrupt();
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
} catch (ExecutionException e) {
|
|
||||||
Throwable cause = e.getCause();
|
|
||||||
if (cause instanceof ReturnException) {
|
|
||||||
return ((ReturnException) cause).getValue();
|
|
||||||
}
|
|
||||||
if (cause instanceof RuntimeException) {
|
|
||||||
throw (RuntimeException) cause;
|
|
||||||
}
|
|
||||||
throw new RuntimeException(cause);
|
|
||||||
} catch (TimeoutException e) {
|
|
||||||
result.cancel(true);
|
|
||||||
throw new EvaluationException(-1, "Calculations exceeded time limit.");
|
|
||||||
}
|
}
|
||||||
} finally {
|
});
|
||||||
popInstance();
|
try {
|
||||||
|
return result.get(WorldEdit.getInstance().getConfiguration().calculationTimeout, TimeUnit.MILLISECONDS);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
Thread.currentThread().interrupt();
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
} catch (ExecutionException e) {
|
||||||
|
Throwable cause = e.getCause();
|
||||||
|
if (cause instanceof ReturnException) {
|
||||||
|
return ((ReturnException) cause).getValue();
|
||||||
|
}
|
||||||
|
if (cause instanceof RuntimeException) {
|
||||||
|
throw (RuntimeException) cause;
|
||||||
|
}
|
||||||
|
throw new RuntimeException(cause);
|
||||||
|
} catch (TimeoutException e) {
|
||||||
|
result.cancel(true);
|
||||||
|
throw new EvaluationException(-1, "Calculations exceeded time limit.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,13 +24,23 @@ import static java.lang.Math.sin;
|
|||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import com.sk89q.worldedit.WorldEdit;
|
||||||
|
import com.sk89q.worldedit.event.platform.PlatformReadyEvent;
|
||||||
import com.sk89q.worldedit.internal.expression.lexer.LexerException;
|
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 org.junit.Test;
|
|
||||||
|
|
||||||
public class ExpressionTest {
|
public class ExpressionTest {
|
||||||
|
@Before
|
||||||
|
public void setup() {
|
||||||
|
WorldEdit.getInstance().getPlatformManager().register(new ExpressionPlatform());
|
||||||
|
WorldEdit.getInstance().getPlatformManager().handlePlatformReady(new PlatformReadyEvent());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEvaluate() throws ExpressionException {
|
public void testEvaluate() throws ExpressionException {
|
||||||
// check
|
// check
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren