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