mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-06-28 10:06:40 +00:00
Fixed the query functions not comparing data values at all for their return values.
Also made them accept RValue as well and added some test cases for them and for the overloader bug i fixed last time.
This commit is contained in:
@ -3,6 +3,7 @@ package com.sk89q.worldedit.expression;
|
||||
import static org.junit.Assert.*;
|
||||
import static java.lang.Math.*;
|
||||
|
||||
import com.sk89q.worldedit.expression.runtime.ExpressionEnvironment;
|
||||
import org.junit.*;
|
||||
|
||||
import com.sk89q.worldedit.expression.lexer.LexerException;
|
||||
@ -59,6 +60,26 @@ public class ExpressionTest {
|
||||
compile("x(");
|
||||
fail("Error expected");
|
||||
} catch (ParserException e) {}
|
||||
|
||||
// test overloader errors
|
||||
try {
|
||||
compile("atan2(1)");
|
||||
fail("Error expected");
|
||||
} catch (ParserException e) {
|
||||
assertEquals("Error position", 0, e.getPosition());
|
||||
}
|
||||
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
|
||||
@ -110,8 +131,52 @@ public class ExpressionTest {
|
||||
assertEquals(127, simpleEval("x=1;y=2;z=3;switch (3) { case 1: x=5; case 2: y=6; default: z=7 } x*100+y*10+z"), 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testQuery() throws Exception {
|
||||
assertEquals(1, simpleEval("a=1;b=2;query(3,4,5,a,b); a==3 && b==4"), 0);
|
||||
assertEquals(1, simpleEval("a=1;b=2;queryAbs(3,4,5,a*1,b*1); a==1 && b==2"), 0);
|
||||
assertEquals(1, simpleEval("a=1;b=2;queryRel(3,4,5,(a),(b)); a==300 && b==400"), 0);
|
||||
assertEquals(1, simpleEval("query(3,4,5,3,4)"), 0);
|
||||
assertEquals(1, simpleEval("!query(3,4,5,3,2)"), 0);
|
||||
assertEquals(1, simpleEval("!queryAbs(3,4,5,10,40)"), 0);
|
||||
assertEquals(1, simpleEval("!queryRel(3,4,5,100,200)"), 0);
|
||||
}
|
||||
|
||||
private double simpleEval(String expressionString) throws ExpressionException {
|
||||
final Expression expression = compile(expressionString);
|
||||
|
||||
expression.setEnvironment(new ExpressionEnvironment() {
|
||||
@Override
|
||||
public int getBlockType(double x, double y, double z) {
|
||||
return (int) x;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBlockData(double x, double y, double z) {
|
||||
return (int) y;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBlockTypeAbs(double x, double y, double z) {
|
||||
return (int) x*10;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBlockDataAbs(double x, double y, double z) {
|
||||
return (int) y*10;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBlockTypeRel(double x, double y, double z) {
|
||||
return (int) x*100;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBlockDataRel(double x, double y, double z) {
|
||||
return (int) y*100;
|
||||
}
|
||||
});
|
||||
|
||||
return expression.evaluate();
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user