提交 6146d838 编写于 作者: Y yumin.pym

format test code

上级 f5201db0
......@@ -42,6 +42,7 @@ public class ExpressRunner {
private static final Log log = LogFactory.getLog(ExpressRunner.class);
private static final String GLOBAL_DEFINE_NAME = "全局定义";
/**
* 是否输出所有的跟踪信息,同时还需要log级别是DEBUG级别
*/
......@@ -192,10 +193,11 @@ public class ExpressRunner {
}
/**
* 添加宏定义 例如: macro 玄难 { abc(userinfo.userId);}
* 添加宏定义
* 例如: macro 宏名称 { abc(userInfo.userId);}
*
* @param macroName:玄难
* @param express :abc(userinfo.userId);
* @param macroName 宏名称
* @param express 表达式,示例:abc(userInfo.userId);
* @throws Exception
*/
public void addMacro(String macroName, String express) throws Exception {
......
......@@ -87,10 +87,8 @@ public class InstructionSetContext implements IExpressContext<String, Object> {
public Object findAliasOrDefSymbol(String varName) {
Object result = this.symbolTable.get(varName);
if (result == null) {
if (this.parent instanceof InstructionSetContext) {
result = ((InstructionSetContext)this.parent).findAliasOrDefSymbol(varName);
}
if (result == null && this.parent instanceof InstructionSetContext) {
result = ((InstructionSetContext)this.parent).findAliasOrDefSymbol(varName);
}
return result;
}
......@@ -103,8 +101,7 @@ public class InstructionSetContext implements IExpressContext<String, Object> {
if (result == null) {
if (this.isExpandToParent && this.parent != null
&& this.parent instanceof InstructionSetContext) {
result = ((InstructionSetContext)this.parent)
.getSymbol(varName);
result = ((InstructionSetContext)this.parent).getSymbol(varName);
} else {
result = OperateDataCacheManager.fetchOperateDataAttr(varName, null);
this.addSymbol(varName, result);
......
......@@ -36,12 +36,12 @@ public class FunctionTest {
@Test
public void testFunction3() throws Exception {
ExpressRunner runner = new ExpressRunner();
String funExp =
"function FAILFUN(Integer errorCode,String message){\n" +
"System.out.println(errorCode+\" \"+message);\n" +
"return NewMap(\"message\":message,\"errorCode\":errorCode,\"success\":false);\n" +
"}\n";
runner.loadMultiExpress("", funExp);
String funExpress = ""
+ "function FAILFUN(Integer errorCode,String message){\n"
+ " System.out.println(errorCode+\" \"+message);\n"
+ " return NewMap(\"message\":message,\"errorCode\":errorCode,\"success\":false);\n"
+ "}";
runner.loadMultiExpress("", funExpress);
String exp = "FAILFUN(-1,'error')";
IExpressContext<String, Object> context = new DefaultContext<>();
......@@ -51,6 +51,6 @@ public class FunctionTest {
String exp2 = "FAILFUN(-12,'error')";
IExpressContext<String, Object> context2 = new DefaultContext<>();
Object result2 = runner.execute(exp2, context2, null, false, false);
System.out.println(result);
System.out.println(result2);
}
}
......@@ -14,8 +14,8 @@ public class AClassDefineSingleTest {
String express = ""
+ "ABC example = new ABC(new com.ql.util.express.test.BeanExample(), 'xuannan');"
+ " example.整数值 =100 + 100;"
+ " print(example.整数值);";
+ "example.整数值 =100 + 100;"
+ "print(example.整数值);";
ExpressRunner expressRunner = new ExpressRunner(false, true);
DefaultContext<String, Object> context = new DefaultContext<>();
......
......@@ -8,56 +8,57 @@ import org.junit.Test;
public class AClassDefineTest {
@Test
public void testNewVClass() throws Exception {
String express = "" +
"int a = 100;" +
"class ABC(){" +
" int a = 200;" +
" println a;" +
"}" +
"ABC abc = new ABC();" +
"println a + abc.a;" +
"return a + abc.a;";
String express = ""
+ "int a = 100;"
+ "class ABC() {"
+ " int a = 200;"
+ " println a;"
+ "}"
+ "ABC abc = new ABC();"
+ "println a + abc.a;"
+ "return a + abc.a;";
ExpressRunner runner = new ExpressRunner(false, false);
DefaultContext<String, Object> context = new DefaultContext<>();
runner.loadMultiExpress("ClassTest", express);
Object r = runner.executeByExpressName("ClassTest", context, null, false, false, null);
Assert.assertTrue("VClass的作用域错误", r.toString().equalsIgnoreCase("300"));
Object result = runner.executeByExpressName("ClassTest", context, null, false, false, null);
Assert.assertTrue("VClass的作用域错误", result.toString().equalsIgnoreCase("300"));
}
@Test
public void testABC() throws Exception {
String expressDefine =
"class ABC(com.ql.util.express.test.BeanExample bean,String name){"
+ "姓名= name;"
+ "计数器 = new InnerClass();"
+ "整数值:bean.intValue;"
+ "浮点值:bean.doubleValue;"
+ "哈希值:{bean.hashCode();};"
+ "function add(int a,int b){return a + b + 整数值 + 计数器.计数;};"
+ "class InnerClass(){" +
"int 计数 =200;" +
"};"
+ "};";
String express =
"ABC example = new ABC(new com.ql.util.express.test.BeanExample(),'xuannan');"
+ "ABC example2 = new ABC(new com.ql.util.express.test.BeanExample(),'xuanyu');"
+ " example.整数值 =100;"
+ " example2.整数值 =200;"
+ " example.浮点值= 99.99;"
+ " example2.浮点值= 11.11;"
+ " example.浮点值 = example.浮点值 + example.整数值;"
+ " result = example.add(10,20) +'--'+ example2.add(10,20) +'--'+ example.姓名 +'--'+ example2.姓名 "
+ "+'--'+ example.浮点值 +'--' + example2.浮点值 ;"
+ " println result;"
+ " return result ;"
+ "";
String expressDefine = ""
+ "class ABC(com.ql.util.express.test.BeanExample bean, String name) {"
+ " 姓名 = name;"
+ " 计数器 = new InnerClass();"
+ " 整数值:bean.intValue;"
+ " 浮点值:bean.doubleValue;"
+ " 哈希值:{bean.hashCode();};"
+ " function add(int a, int b) {"
+ " return a + b + 整数值 + 计数器.计数;"
+ " };"
+ " class InnerClass() {"
+ " int 计数 = 200;"
+ " };"
+ "};";
String express = ""
+ "ABC example = new ABC(new com.ql.util.express.test.BeanExample(),'xuannan');"
+ "ABC example2 = new ABC(new com.ql.util.express.test.BeanExample(),'xuanyu');"
+ "example.整数值 = 100;"
+ "example2.整数值 = 200;"
+ "example.浮点值 = 99.99;"
+ "example2.浮点值 = 11.11;"
+ "example.浮点值 = example.浮点值 + example.整数值;"
+ "result = example.add(10, 20) + '--' + example2.add(10, 20) + '--' + example.姓名 + '--' + example2.姓名 + "
+ "'--' + example.浮点值 + '--' + example2.浮点值;"
+ "println result;"
+ "return result;";
ExpressRunner runner = new ExpressRunner(false, true);
DefaultContext<String, Object> context = new DefaultContext<>();
runner.loadMultiExpress("", expressDefine);
runner.loadMultiExpress("ClassTest", express);
Object r = runner.executeByExpressName("ClassTest", context,
null, false, false, null);
Object r = runner.executeByExpressName("ClassTest", context, null, false, false, null);
Assert.assertTrue("VClass的作用域错误", r.toString().equalsIgnoreCase("330--430--xuannan--xuanyu--199.99--11.11"));
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册