From eb950bd75ef44a9924b8e142aeed63f72f198caa Mon Sep 17 00:00:00 2001 From: Octavia Togami Date: Mon, 24 Feb 2020 03:33:49 -0500 Subject: [PATCH] Add more expression test cases, fix bugs Also added a few more comments + reorganized exceptions that are invoke-internal. (cherry picked from commit cbd686548fd62248fabbaab551a6875a14170957) --- .../internal/expression/invoke/CompilingVisitor.java | 5 +---- .../internal/expression/ExpressionTest.java | 12 +++++++++++- 2 files changed, 12 insertions(+), 5 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 72e5f6f64..ae2b153ba 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 @@ -678,13 +678,10 @@ class CompilingVisitor extends ExpressionBaseVisitor { // MH:oldResult,result = (ExecutionData)Double // Execute `oldResult` but ignore its return value, then execute result and return that. - // If either result is `defaultResult`, it's bogus, so just skip it + // If `oldResult` (the old value) is `defaultResult`, it's bogus, so just skip it if (oldResult == DEFAULT_RESULT) { return result; } - if (result == DEFAULT_RESULT) { - return oldResult; - } // Add a dummy Double parameter to the end // MH:dummyDouble = (ExecutionData, Double)Double MethodHandle dummyDouble = MethodHandles.dropArguments( 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 7bb616be8..3d870a9fc 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 @@ -55,7 +55,17 @@ class ExpressionTest extends BaseExpressionTest { testCase("0 || 5", 5), testCase("2 || 5", 2), testCase("2 && 5", 5), - testCase("5 && 0", 0) + testCase("5 && 0", 0), + // check ternaries + testCase("false ? 1 : 2", 2), + testCase("true ? 1 : 2", 1), + // - ternary binds inside + testCase("true ? true ? 1 : 2 : 3", 1), + testCase("true ? false ? 1 : 2 : 3", 2), + testCase("false ? true ? 1 : 2 : 3", 3), + testCase("false ? false ? 1 : 2 : 3", 3), + // check return + testCase("return 1; 0", 1) ); return testCases.stream() .map(testCase -> DynamicTest.dynamicTest(