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

format test code

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