From 0e4a206f723dc9704eeff7f9732d7ba731bbbf94 Mon Sep 17 00:00:00 2001 From: Octavia Togami Date: Tue, 25 Feb 2020 16:35:43 -0800 Subject: [PATCH] Cover many more ops (cherry picked from commit 3dbaae79cd4aa37724fb8969bbf595180e152f3e) --- .../expression/invoke/CompilingVisitor.java | 2 - .../internal/expression/ExpressionTest.java | 78 +++++++++++++++++++ 2 files changed, 78 insertions(+), 2 deletions(-) diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/expression/invoke/CompilingVisitor.java b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/expression/invoke/CompilingVisitor.java index 16b12d738..ac8a1308d 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/expression/invoke/CompilingVisitor.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/expression/invoke/CompilingVisitor.java @@ -462,8 +462,6 @@ class CompilingVisitor extends ExpressionBaseVisitor { return (l, r) -> ExpressionHandles.boolToDouble(l != r); case NEAR: return (l, r) -> ExpressionHandles.boolToDouble(almostEqual2sComplement(l, r)); - case GREATER_THAN_OR_EQUAL: - return (l, r) -> ExpressionHandles.boolToDouble(l >= r); } throw ExpressionHelper.evalException(ctx, "Invalid text for equality expr: " + ctx.op.getText()); }); diff --git a/worldedit-core/src/test/java/com/sk89q/worldedit/internal/expression/ExpressionTest.java b/worldedit-core/src/test/java/com/sk89q/worldedit/internal/expression/ExpressionTest.java index 9d915ebe7..f8089f029 100644 --- a/worldedit-core/src/test/java/com/sk89q/worldedit/internal/expression/ExpressionTest.java +++ b/worldedit-core/src/test/java/com/sk89q/worldedit/internal/expression/ExpressionTest.java @@ -101,6 +101,84 @@ class ExpressionTest extends BaseExpressionTest { checkTestCase("!-2", 0); } + @Test + void testComplement() { + checkTestCase("~0", ~0); + checkTestCase("~1", ~1); + checkTestCase("~-1", ~-1); + checkTestCase("~-2", ~-2); + // it drops the decimal! + checkTestCase("~0.1", ~0); + checkTestCase("~0.5", ~0); + checkTestCase("~1.9", ~1); + } + + @Test + void testShift() { + checkTestCase("1<<4", 1 << 4); + // drops both decimals + checkTestCase("1.1<<4.1", 1 << 4); + checkTestCase("16>>2", 16 >> 2); + checkTestCase("16.9>>2.1", 16 >> 2); + } + + @Test + void testComparisonOps() { + checkTestCase("1>=0", 1); + checkTestCase("1>0", 1); + + checkTestCase("0>=0", 1); + checkTestCase("0>0", 0); + + checkTestCase("0<=1", 1); + checkTestCase("0<1", 1); + + checkTestCase("0<=0", 1); + checkTestCase("0<0", 0); + + checkTestCase("1>=2", 0); + checkTestCase("1>2", 0); + + checkTestCase("0>=1", 0); + checkTestCase("0>1", 0); + + checkTestCase("2<=1", 0); + checkTestCase("2<1", 0); + + checkTestCase("1<=0", 0); + checkTestCase("1<0", 0); + } + + @Test + void testEqualityOps() { + checkTestCase("1==1", 1); + checkTestCase("0==1", 0); + checkTestCase("1==0", 0); + + checkTestCase("1!=1", 0); + checkTestCase("0!=1", 1); + checkTestCase("1!=0", 1); + + checkTestCase("1.1==1.1", 1); + // These aren't normally equal + checkTestCase("1!=0.999999999", 1); + // But they are _almost_ equal! + checkTestCase("1~=0.999999999", 1); + // On the other hand, these aren't + checkTestCase("1~=0.9", 0); + } + + @Test + void testPostfixOps() { + checkTestCase("(-1)!", 0); + checkTestCase("0!", 1); + checkTestCase("1!", 1); + checkTestCase("2!", 2); + checkTestCase("2000!", Double.POSITIVE_INFINITY); + // it truncates + checkTestCase("2.9!", 2); + } + @Test public void testErrors() { // test lexer errors