Search in sources :

Example 31 with Context

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

the class El2Test method test_issue314.

@Test
public void test_issue314() {
    Context context = Lang.context();
    context.set("String", String.class);
    Issue314 i314 = new Issue314();
    List<String> list = new ArrayList<String>();
    list.add("123");
    i314.setList(list);
    context.set("map", i314);
    assertEquals("123", El.eval(context, "String.valueOf(123)"));
    assertEquals("123", El.eval(context, "map.list.get(0)"));
}
Also used : Context(org.nutz.lang.util.Context) Issue314(org.nutz.el.issue.Issue314) ArrayList(java.util.ArrayList) SimpleSpeedTest(org.nutz.el.speed.SimpleSpeedTest) Test(org.junit.Test)

Example 32 with Context

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

the class El2Test method map.

/**
     * map测试
     */
@Test
public void map() {
    Context context = Lang.context();
    context.set("a", Lang.map("{x:10,y:50,txt:'Hello'}"));
    assertEquals(100, El.eval(context, "a.get('x')*10"));
    assertEquals(100, El.eval(context, "a.x*10"));
    assertEquals(100, El.eval(context, "a['x']*10"));
    assertEquals("Hello-40", El.eval(context, "a.get('txt')+(a.get('x')-a.get('y'))"));
}
Also used : Context(org.nutz.lang.util.Context) SimpleSpeedTest(org.nutz.el.speed.SimpleSpeedTest) Test(org.junit.Test)

Example 33 with Context

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

the class El2Test method context.

@Test
public void context() {
    Context context = Lang.context();
    List<String> list = new ArrayList<String>();
    list.add("jk");
    context.set("a", list);
    assertEquals("jk", El.eval(context, "a.get((1-1))"));
    assertEquals("jk", El.eval(context, "a.get(1-1)"));
    assertEquals("jk", El.eval(context, "a.get(0)"));
    assertTrue((Boolean) El.eval(Lang.context(), "a==null"));
    try {
        assertTrue((Boolean) El.eval(Lang.context(), "a.a"));
        fail();
    } catch (Exception e) {
    }
}
Also used : Context(org.nutz.lang.util.Context) ArrayList(java.util.ArrayList) UnsupportedEncodingException(java.io.UnsupportedEncodingException) SimpleSpeedTest(org.nutz.el.speed.SimpleSpeedTest) Test(org.junit.Test)

Example 34 with Context

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

the class El2Test method test_simple_condition.

/**
     * 参数
     */
@Test
public void test_simple_condition() {
    Context context = Lang.context();
    context.set("a", 10);
    assertEquals(10, El.eval(context, "a"));
    assertEquals(20, El.eval(context, "a + a"));
    context.set("b", "abc");
    assertEquals(25, El.eval(context, "a + 2 +a+ b.length()"));
    String s = "a>5?'GT 5':'LTE 5'";
    assertEquals("GT 5", El.eval(context, s));
    context.set("a", 5);
    assertEquals("LTE 5", El.eval(context, s));
    assertEquals("jk", El.eval("\"j\"+\"k\""));
}
Also used : Context(org.nutz.lang.util.Context) SimpleSpeedTest(org.nutz.el.speed.SimpleSpeedTest) Test(org.junit.Test)

Example 35 with Context

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

the class El2Test method test_issue411.

@Test
public void test_issue411() {
    El el = new El("a[0].b.isPass('')?'1':'2'");
    Context ctx = Lang.context();
    ctx.set("a", new Object[] { new org.nutz.el.issue411.Issue411.A() });
    assertEquals("1", el.eval(ctx));
}
Also used : Context(org.nutz.lang.util.Context) SimpleSpeedTest(org.nutz.el.speed.SimpleSpeedTest) 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