Search in sources :

Example 21 with Context

use of org.nutz.lang.util.Context in project nutz by nutzam.

the class El2Test method test_el.

@Test
public void test_el() {
    El el = new El("'hi,'+name");
    Context ctx = Lang.context();
    ctx.set("name", "wendal");
    assertEquals("hi,wendal", el.eval(ctx));
}
Also used : Context(org.nutz.lang.util.Context) SimpleSpeedTest(org.nutz.el.speed.SimpleSpeedTest) Test(org.junit.Test)

Example 22 with Context

use of org.nutz.lang.util.Context in project nutz by nutzam.

the class El2Test method test_base64.

@Test
public void test_base64() {
    Context ctx = Lang.context();
    El el = new El("base64('中文,英文abc,火星文((%&(*')");
    assertEquals(Base64.encodeToString("中文,英文abc,火星文((%&(*".getBytes(Encoding.CHARSET_UTF8), false), el.eval(ctx));
    String str = Base64.encodeToString("EEE中文".getBytes(Encoding.CHARSET_UTF8), false);
    el = new El("base64('decode', \'" + str + "\')");
    assertEquals("EEE中文", el.eval(ctx));
}
Also used : Context(org.nutz.lang.util.Context) SimpleSpeedTest(org.nutz.el.speed.SimpleSpeedTest) Test(org.junit.Test)

Example 23 with Context

use of org.nutz.lang.util.Context in project nutz by nutzam.

the class El2Test method testIssue279.

@Test
public void testIssue279() throws InterruptedException {
    Context context = Lang.context();
    context.set("math", Maths.class);
    System.out.println(Maths.class.toString());
    assertEquals("class org.nutz.lang.Maths", El.eval(context, "math.toString()"));
    NutConf.load("org/nutz/el/issue279/279.js");
    assertEquals(El.eval("uuuid(false)"), "abc");
    assertEquals(El.eval("uuuid()"), "abc");
}
Also used : Context(org.nutz.lang.util.Context) Maths(org.nutz.lang.Maths) SimpleSpeedTest(org.nutz.el.speed.SimpleSpeedTest) Test(org.junit.Test)

Example 24 with Context

use of org.nutz.lang.util.Context in project nutz by nutzam.

the class Issue125Test method test2.

@Test
public void test2() {
    String[] a = new String[] { "a", "b" };
    String[] b = new String[] { "1", "2" };
    Map<String, Object> map = new HashMap<String, Object>();
    map.put("a", a);
    map.put("b", b);
    // 预编译结果为一个 El 对象
    El exp = new El("util.test(map['a'][0],map['b'][0])");
    Context context = Lang.context();
    context.set("util", new StringUtil());
    context.set("map", map);
    System.out.println(exp.eval(context));
}
Also used : Context(org.nutz.lang.util.Context) HashMap(java.util.HashMap) El(org.nutz.el.El) Test(org.junit.Test)

Example 25 with Context

use of org.nutz.lang.util.Context in project nutz by nutzam.

the class Issue125Test method test.

@Test
public void test() throws InstantiationException, IllegalAccessException {
    String[] a = new String[] { "a", "b" };
    Map<String, String[]> map = new HashMap<String, String[]>();
    map.put("a", a);
    El exp = new El("util.test(map['a'])");
    Context context = Lang.context();
    context.set("util", StringUtil.class.newInstance());
    context.set("map", map);
    assertEquals("ab", exp.eval(context));
}
Also used : Context(org.nutz.lang.util.Context) HashMap(java.util.HashMap) El(org.nutz.el.El) Test(org.junit.Test)

Aggregations

Context (org.nutz.lang.util.Context)40 Test (org.junit.Test)29 SimpleSpeedTest (org.nutz.el.speed.SimpleSpeedTest)24 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)3 ServletContext (javax.servlet.ServletContext)3 El (org.nutz.el.El)3 Map (java.util.Map)2 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 BigDecimal (java.math.BigDecimal)1 ServerSocket (java.net.ServerSocket)1 Socket (java.net.Socket)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 HttpSession (javax.servlet.http.HttpSession)1 Ignore (org.junit.Ignore)1 ElException (org.nutz.el.ElException)1 Issue293 (org.nutz.el.issue.Issue293)1 Issue303 (org.nutz.el.issue.Issue303)1