This is an automated email from the ASF dual-hosted git repository. henrib pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-jexl.git
The following commit(s) were added to refs/heads/master by this push: new aaaf842 JEXL-307: added another test Task #JEXL-307 - Variable redeclaration option aaaf842 is described below commit aaaf8424def2f4aff85fe80cc5a7efc7d5df12ff Author: henrib <hen...@apache.org> AuthorDate: Sat Feb 8 11:21:43 2020 +0100 JEXL-307: added another test Task #JEXL-307 - Variable redeclaration option --- .../org/apache/commons/jexl3/JexlTestCase.java | 1 - .../java/org/apache/commons/jexl3/LexicalTest.java | 28 +++++++++++++++++----- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/src/test/java/org/apache/commons/jexl3/JexlTestCase.java b/src/test/java/org/apache/commons/jexl3/JexlTestCase.java index 294ea4a..0edf01b 100644 --- a/src/test/java/org/apache/commons/jexl3/JexlTestCase.java +++ b/src/test/java/org/apache/commons/jexl3/JexlTestCase.java @@ -34,7 +34,6 @@ public class JexlTestCase { // The default options: all tests where engine must lexicality is // important can be identified by the builder calling lexical(...). static { - //JexlBuilder.setDefaultOptions("+safe", "-lexical"); JexlOptions.setDefaultFlags("-safe", "+lexical"); } /** No parameters signature for test run. */ diff --git a/src/test/java/org/apache/commons/jexl3/LexicalTest.java b/src/test/java/org/apache/commons/jexl3/LexicalTest.java index b525417..0e5ea2b 100644 --- a/src/test/java/org/apache/commons/jexl3/LexicalTest.java +++ b/src/test/java/org/apache/commons/jexl3/LexicalTest.java @@ -745,19 +745,35 @@ public class LexicalTest { JexlEngine jexl = new JexlBuilder().strict(true).features(f).create(); JexlScript script = jexl.createScript("var i = (x, y, z)->{return x + y + z}; i(22,18,2)"); JexlContext jc = new MapContext(); - Object result = script.execute(null); - Assert.assertEquals(result, 42); + Object result = script.execute(jc); + Assert.assertEquals(42, result); } @Test - public void testHoisted() throws Exception { + public void tesstCaptured0() throws Exception { JexlFeatures f = new JexlFeatures(); f.lexical(true); JexlEngine jexl = new JexlBuilder().strict(true).features(f).create(); - JexlScript script = jexl.createScript("var x = 10; var a = function(var b) {for (var q : 1 ..10) {return x + b}}; a(32)"); + JexlScript script = jexl.createScript( + "var x = 10;" + + "var a = function(var b) {for (var q : 1 ..10) {return x + b}}; a(32)"); JexlContext jc = new MapContext(); - Object result = script.execute(null); - Assert.assertEquals(result, 42); + Object result = script.execute(jc); + Assert.assertEquals(42, result); } + + @Test + public void testCaptured1() throws Exception { + JexlFeatures f = new JexlFeatures(); + f.lexical(true); + JexlEngine jexl = new JexlBuilder().strict(true).features(f).create(); + JexlScript script = jexl.createScript( + "{var x = 10; }" + + "var a = function(var b) {for (var q : 1 ..10) {return x + b}}; a(32)"); + JexlContext jc = new MapContext(); + jc.set("x", 11); + Object result = script.execute(jc); + Assert.assertEquals(43, result); + } }