Copilot commented on code in PR #397:
URL: https://github.com/apache/commons-jexl/pull/397#discussion_r2766348721


##########
src/main/java/org/apache/commons/jexl3/internal/TemplateInterpreter.java:
##########
@@ -299,14 +297,25 @@ protected Interpreter createInterpreter(final JexlContext 
context, final Frame l
             };
         }
         // otherwise...
-        final int numChildren = script.jjtGetNumChildren();
-        Object result = null;
-        for (int i = 0; i < numChildren; i++) {
-            final JexlNode child = script.jjtGetChild(i);
-            result = child.jjtAccept(this, data);
-            cancelCheck(child);
+        final Object[] stack = saveStack();
+        try {
+            return runScript(script, data);
+        } finally {
+            restoreStack(stack);
+        }
+    }
+
+    private Object[] saveStack() {
+        if (frame != null && frame.stack != null) {
+            return frame.stack.clone();
+        }
+        return  null;

Review Comment:
   Extra space before 'null'. The codebase consistently uses a single space in 
'return null;' statements.
   ```suggestion
           return null;
   ```



##########
src/test/java/org/apache/commons/jexl3/Issues400Test.java:
##########
@@ -980,5 +981,91 @@ void test451() {
         assertThrows(JexlException.Property.class,
             () -> jexl451.createScript("o.class.classLoader", 
"o").execute(null, new Object()));
     }
+
+    @Test
+    void testIssue455a() {
+        final JexlEngine jexl = new JexlBuilder().create();
+        String code = "name -> `${name +\n\t\f\r name}`";
+        JexlScript script = jexl.createScript(code);
+        Object o = script.execute(null, "Hello");
+        String ctl = "HelloHello";
+        Assertions.assertEquals(ctl, o);
+    }
+
+    @Test
+    void testIssue455b() {
+        final JexlEngine jexl = new JexlBuilder().create();
+        String code = "name -> `${name}\n${name}`;";
+        JexlScript script = jexl.createScript(code);
+        Object o = script.execute(null, "Hello");
+        String ctl = "Hello\nHello";
+        Assertions.assertEquals(ctl, o);
+    }
+
+    @Test
+    void testIssue455c() {
+        final JexlEngine jexl = new JexlBuilder().create();
+        final JexlContext context = new MapContext();
+        context.set("name", "Hello");
+        final JxltEngine jxlt = jexl.createJxltEngine();
+        final JxltEngine.Template template = 
jxlt.createTemplate("<b>\n\t${name\n\t+\r\f name}\n</b>");
+        final StringWriter writer = new StringWriter();
+        template.evaluate(context, writer);
+        assertEquals("<b>\n\tHelloHello\n</b>", writer.toString());
+    }
+
+    @Test
+    void testIssue455d() {
+        final JexlEngine jexl = new JexlBuilder().create();
+        // 'ref' contains 'greeting' which is the name of the variable to 
expand
+        String code = "`#{${\nref\t}}\n#{${\rref\f}}`;";
+        JexlScript script = jexl.createScript(code, "ref", "greeting");
+        Object o = script.execute(null, "greeting", "Hello");
+        String ctl = "Hello\nHello";
+        Assertions.assertEquals(ctl, o);
+    }
+
+    @Test
+    public void testIssue455e() {
+        final JexlEngine jexl = new JexlBuilder().create();
+        // Evaluate nested immediate inside deferred at runtime using a 
parameterized script
+        final String src = "(name, suffix) -> `#{name} Hello ${name} ! 
#{suffix}`";
+        final JexlScript script = jexl.createScript(src);
+        final Object result = script.execute(null, "World", "~");
+        Assertions.assertEquals("World Hello World ! ~", result);
+    }
+
+    @Test
+    public void testIssue455f() {

Review Comment:
   Test methods should use package-private (default) visibility to be 
consistent with the rest of the test class. Only 2 out of 46 test methods in 
this file are marked as public, and those are the ones added in this PR.



##########
src/test/java/org/apache/commons/jexl3/Issues400Test.java:
##########
@@ -980,5 +981,91 @@ void test451() {
         assertThrows(JexlException.Property.class,
             () -> jexl451.createScript("o.class.classLoader", 
"o").execute(null, new Object()));
     }
+
+    @Test
+    void testIssue455a() {
+        final JexlEngine jexl = new JexlBuilder().create();
+        String code = "name -> `${name +\n\t\f\r name}`";
+        JexlScript script = jexl.createScript(code);
+        Object o = script.execute(null, "Hello");
+        String ctl = "HelloHello";
+        Assertions.assertEquals(ctl, o);
+    }
+
+    @Test
+    void testIssue455b() {
+        final JexlEngine jexl = new JexlBuilder().create();
+        String code = "name -> `${name}\n${name}`;";
+        JexlScript script = jexl.createScript(code);
+        Object o = script.execute(null, "Hello");
+        String ctl = "Hello\nHello";
+        Assertions.assertEquals(ctl, o);
+    }
+
+    @Test
+    void testIssue455c() {
+        final JexlEngine jexl = new JexlBuilder().create();
+        final JexlContext context = new MapContext();
+        context.set("name", "Hello");
+        final JxltEngine jxlt = jexl.createJxltEngine();
+        final JxltEngine.Template template = 
jxlt.createTemplate("<b>\n\t${name\n\t+\r\f name}\n</b>");
+        final StringWriter writer = new StringWriter();
+        template.evaluate(context, writer);
+        assertEquals("<b>\n\tHelloHello\n</b>", writer.toString());
+    }
+
+    @Test
+    void testIssue455d() {
+        final JexlEngine jexl = new JexlBuilder().create();
+        // 'ref' contains 'greeting' which is the name of the variable to 
expand
+        String code = "`#{${\nref\t}}\n#{${\rref\f}}`;";
+        JexlScript script = jexl.createScript(code, "ref", "greeting");
+        Object o = script.execute(null, "greeting", "Hello");
+        String ctl = "Hello\nHello";
+        Assertions.assertEquals(ctl, o);
+    }
+
+    @Test
+    public void testIssue455e() {

Review Comment:
   Test methods should use package-private (default) visibility to be 
consistent with the rest of the test class. Only 2 out of 46 test methods in 
this file are marked as public, and those are the ones added in this PR.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to