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)"));
}
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'))"));
}
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) {
}
}
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\""));
}
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));
}
Aggregations