commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hen...@apache.org
Subject svn commit: r1698222 - in /commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3: IssuesTest.java JXLTTest.java
Date Thu, 27 Aug 2015 19:58:15 GMT
Author: henrib
Date: Thu Aug 27 19:58:15 2015
New Revision: 1698222

URL: http://svn.apache.org/r1698222
Log:
JEXL:
Implemented JEXL-177; multiline formats use backquote (`) as delimiter and interpolate ${...}
expressions;

Modified:
    commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/IssuesTest.java
    commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/JXLTTest.java

Modified: commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/IssuesTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/IssuesTest.java?rev=1698222&r1=1698221&r2=1698222&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/IssuesTest.java (original)
+++ commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/IssuesTest.java Thu Aug
27 19:58:15 2015
@@ -22,7 +22,9 @@ import java.math.MathContext;
 import java.util.HashMap;
 import java.util.Map;
 import org.apache.commons.jexl3.internal.introspection.Uberspect;
+import org.apache.commons.jexl3.introspection.JexlMethod;
 import java.io.File;
+import java.io.StringWriter;
 import java.net.URL;
 import java.util.ArrayList;
 import java.util.Arrays;

Modified: commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/JXLTTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/JXLTTest.java?rev=1698222&r1=1698221&r2=1698222&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/JXLTTest.java (original)
+++ commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/JXLTTest.java Thu Aug
27 19:58:15 2015
@@ -16,6 +16,9 @@
  */
 package org.apache.commons.jexl3;
 
+import org.apache.commons.jexl3.internal.TemplateDebugger;
+import org.apache.commons.jexl3.internal.TemplateEngine;
+import org.apache.commons.jexl3.internal.TemplateScript;
 import org.apache.log4j.Logger;
 import org.apache.log4j.LogManager;
 
@@ -58,6 +61,15 @@ public class JXLTTest extends JexlTestCa
         super.tearDown();
     }
 
+    private static String refactor(TemplateDebugger td, JxltEngine.Template ts) {
+        boolean dbg = td.debug((TemplateScript)ts);
+        if (dbg) {
+            return td.toString();
+        } else {
+            return "";
+        }
+    }
+
     /** Extract the source from a toString-ed expression. */
     private String getSource(String tostring) {
         int len = tostring.length();
@@ -531,6 +543,11 @@ public class JXLTTest extends JexlTestCa
 
         String dstr = t.asString();
         Assert.assertNotNull(dstr);
+
+        TemplateDebugger td = new TemplateDebugger();
+        String refactored = refactor(td, (TemplateScript) t);
+        Assert.assertNotNull(refactored);
+        Assert.assertEquals(test42, refactored);
     }
 
     public static class FrobozWriter extends PrintWriter {
@@ -564,9 +581,10 @@ public class JXLTTest extends JexlTestCa
         String rpt
                 = "<report>\n"
                 + "\n"
+                + "\n$$ var a = 1;"
                 + "\n$$ var x = 2;"
                 + "\n"
-                + "\n     $$ var y = 9;"
+                + "\n$$ var y = 9;"
                 + "\n"
                 + "\n        ${x + y}"
                 + "\n</report>\n";
@@ -574,8 +592,13 @@ public class JXLTTest extends JexlTestCa
         StringWriter strw = new StringWriter();
         t.evaluate(context, strw);
         String output = strw.toString();
-        String ctl = "<report>\n\n\n        11\n</report>\n";
+        String ctl = "<report>\n\n\n\n\n        11\n</report>\n";
         Assert.assertEquals(ctl, output);
+
+        TemplateDebugger td = new TemplateDebugger();
+        String refactored = refactor(td, (TemplateScript) t);
+        Assert.assertNotNull(refactored);
+        Assert.assertEquals(rpt, refactored);
     }
 
     @Test
@@ -631,6 +654,11 @@ public class JXLTTest extends JexlTestCa
         Assert.assertTrue(output.indexOf("43") > 0);
         Assert.assertTrue(output.indexOf("44") > 0);
         Assert.assertTrue(output.indexOf("45") > 0);
+
+        TemplateDebugger td = new TemplateDebugger();
+        String xxx = refactor(td, (TemplateScript) t);
+        Assert.assertNotNull(xxx);
+        Assert.assertEquals(rpt, xxx);
     }
     @Test
     public void testOneLiner() throws Exception {
@@ -650,6 +678,49 @@ public class JXLTTest extends JexlTestCa
         String output = strw.toString();
         Assert.assertEquals("fourty-two", output);
     }
+
+    @Test
+    public void testInterpolation() throws Exception {
+        context.set("user", "Dimitri");
+        String expr =  "`Hello \n${user}`";
+        Object value = JEXL.createScript(expr).execute(context);
+        Assert.assertEquals(expr, "Hello \nDimitri", value);
+    }
+
+    @Test
+    public void testInterpolationGlobal() throws Exception {
+        String expr =  "user='Dimitri'; `Hello \n${user}`";
+        Object value = JEXL.createScript(expr).execute(context);
+        Assert.assertEquals(expr, "Hello \nDimitri", value);
+    }
+
+    @Test
+    public void testInterpolationLocal() throws Exception {
+        String expr =  "var user='Henrib'; `Hello \n${user}`";
+        Object value = JEXL.createScript(expr).execute(context);
+        Assert.assertEquals(expr, "Hello \nHenrib", value);
+    }
+
+    @Test
+    public void testInterpolationLvsG() throws Exception {
+        String expr =  "user='Dimitri'; var user='Henrib'; `H\\\"ello \n${user}`";
+        Object value = JEXL.createScript(expr).execute(context);
+        Assert.assertEquals(expr, "H\"ello \nHenrib", value);
+    }
+        @Test
+    public void testInterpolationLvsG2() throws Exception {
+        String expr =  "user='Dimitri'; var user='Henrib'; `H\\`ello \n${user}`";
+        Object value = JEXL.createScript(expr).execute(context);
+        Assert.assertEquals(expr, "H`ello \nHenrib", value);
+    }
+
+    @Test
+    public void testInterpolationParameter() throws Exception {
+        String expr =  "(user)->{`Hello \n${user}`}";
+        Object value = JEXL.createScript(expr).execute(context, "Henrib");
+        Assert.assertEquals(expr, "Hello \nHenrib", value);
+    }
+//
 //
 //    @Test public void testDeferredTemplate() throws Exception {
 //        JxltEngine.Template t = JXLT.createTemplate("$$", new StringReader(



Mime
View raw message