提交 024bc97b 编写于 作者: Y yumin.pym

format test code

上级 a69d104a
......@@ -42,8 +42,8 @@ public class QLPattern {
arrayListCache);
QLMatchResult result = findMatchStatementWithAddRootOptimizeStack(staticParams, pattern, point, 1);
if (printStackDepth) {
log.warn("递归堆栈深度:" + maxDeep.longValue() + " 重用QLMatchResult次数:" + resultCache.fetchCount
+ " 新建QLMatchResult次数:" + resultCache.newCount + " 新建ArrayList数量:" + arrayListCache.newCount);
log.warn("递归堆栈深度:" + maxDeep.longValue() + " 重用QLMatchResult次数:" + resultCache.fetchCount
+ " 新建QLMatchResult次数:" + resultCache.newCount + " 新建ArrayList数量:" + arrayListCache.newCount);
}
if (result == null || result.getMatchSize() == 0) {
throw new QLCompileException("程序错误,不满足语法规范,没有匹配到合适的语法,最大匹配致[0:" + (maxMatchPoint.longValue() - 1) + "]");
......
......@@ -129,10 +129,10 @@ public class KeyWordDefine4Java {
"STAT_IFELSE:TYPE=STATEMENT,DEFINE=(if|when->if)^$EXPRESS$then$(STAT_BLOCK|STATEMENT|EXPRESS)$else$"
+ "(STAT_BLOCK|STATEMENT)",
"STAT_IF:TYPE=STATEMENT, DEFINE=(if|when->if)^$EXPRESS$then$(STAT_BLOCK|STATEMENT)",
"STAT_IF:TYPE=STATEMENT,DEFINE=(if|when->if)^$EXPRESS$then$(STAT_BLOCK|STATEMENT)",
"STAT_IFELSE_JAVA:TYPE=STATEMENT,DEFINE=(if|when->if)^$CHILD_EXPRESS$(STAT_BLOCK|STATEMENT|EXPRESS)$else$"
+ "(STAT_BLOCK|STATEMENT)",
"STAT_IF_JAVA:TYPE=STATEMENT, DEFINE=(if|when->if)^$CHILD_EXPRESS$(STAT_BLOCK|STATEMENT)",
"STAT_IF_JAVA:TYPE=STATEMENT,DEFINE=(if|when->if)^$CHILD_EXPRESS$(STAT_BLOCK|STATEMENT)",
"PARAMETER_DEFINE:TYPE=STATEMENT,DEFINE=LEFT_BRACKET->CHILD_EXPRESS^$(RIGHT_BRACKET~|(VAR_DEFINE$(,"
+ "~$VAR_DEFINE)*$RIGHT_BRACKET~))",
......
......@@ -26,39 +26,44 @@ public class WorkflowTest {
*/
@Test
public void testApprove1() throws Exception {
//定义表达式
String exp = "如果 (审批通过(经理,金额)){" +
" 如果 (金额 大于 5000){ " +
" 如果 (审批通过(总监,金额)){" +
" 如果 (审批通过(财务,金额)){" +
" 报销入账(金额)" +
" }否则 {" +
" 打回修改(申请人)" +
" }" +
" }否则 {" +
" 打回修改(申请人)" +
" }" +
" }否则 {" +
" 如果 (审批通过(财务,金额)){" +
" 报销入账(金额)" +
" }否则 {" +
" 打回修改(申请人)" +
" }" +
" }" +
"}否则 {" +
" 打回修改(申请人)" +
"}" +
"打印(\"完成\")";
// 此脚本内容与example/approve.ql及example/approve1.ql中的一段脚本内容完全相同
String express = ""
+ "如果 (审批通过(经理, 金额)) {\n"
+ " 如果 (金额 大于 5000) {\n"
+ " 如果 (审批通过(总监, 金额)) {\n"
+ " 如果 (审批通过(财务, 金额)) {\n"
+ " 报销入账(金额)\n"
+ " } 否则 {\n"
+ " 打回修改(申请人)\n"
+ " }\n"
+ " } 否则 {\n"
+ " 打回修改(申请人)\n"
+ " }\n"
+ " } 否则 {\n"
+ " 如果 (审批通过(财务, 金额)) {\n"
+ " 报销入账(金额)\n"
+ " } 否则 {\n"
+ " 打回修改(申请人)\n"
+ " }\n"
+ " }\n"
+ "} 否则 {\n"
+ " 打回修改(申请人)\n"
+ "}\n"
+ "打印(\"完成\")\n";
System.out.println("express = " + express);
ExpressRunner runner = new ExpressRunner();
//定义操作符别名
runner.addOperatorWithAlias("如果", "if", null);
runner.addOperatorWithAlias("否则", "else", null);
runner.addOperatorWithAlias("大于", ">", null);
runner.addFunctionOfServiceMethod("打印", new WorkflowTest(), "println", new String[] {"String"}, null);
//定义方法
runner.addFunction("审批通过", new ApproveOperator(1));
runner.addFunction("报销入账", new ApproveOperator(2));
runner.addFunction("打回修改", new ApproveOperator(3));
//设置上下文变量
IExpressContext<String, Object> expressContext = new DefaultContext<>();
expressContext.put("经理", "王经理");
......@@ -66,8 +71,8 @@ public class WorkflowTest {
expressContext.put("财务", "张财务");
expressContext.put("申请人", "小强");
expressContext.put("金额", 4000);
//执行表达式
runner.execute(exp, expressContext, null, false, false);
runner.execute(express, expressContext, null, false, false);
}
/**
......@@ -78,18 +83,20 @@ public class WorkflowTest {
@Test
public void testApprove2() throws Exception {
ExpressRunner runner = new ExpressRunner();
//定义操作符别名
runner.addOperatorWithAlias("如果", "if", null);
runner.addOperatorWithAlias("否则", "else", null);
runner.addOperatorWithAlias("大于", ">", null);
runner.addFunctionOfServiceMethod("打印", new WorkflowTest(), "println", new String[] {"String"}, null);
//定义方法
runner.addFunction("审批通过", new ApproveOperator(1));
runner.addFunction("报销入账", new ApproveOperator(2));
runner.addFunction("打回修改", new ApproveOperator(3));
//加载文件
//加载文件,从指定文件中获取表示式构造指令集
runner.loadExpress("example/approve1");
//从指定文件中获取表示式构造指令集
//设置上下文变量
IExpressContext<String, Object> expressContext = new DefaultContext<>();
......@@ -110,13 +117,16 @@ public class WorkflowTest {
@Test
public void testApprove3() throws Exception {
ExpressRunner runner = new ExpressRunner();
//定义操作符别名
runner.addOperatorWithAlias("如果", "if", null);
runner.addOperatorWithAlias("否则", "else", null);
runner.addOperatorWithAlias("大于", ">", null);
runner.addFunctionOfServiceMethod("打印", new WorkflowTest(), "println", new String[] {"String"}, null);
//加载文件
runner.loadExpress("example/approve");
//设置上下文变量
IExpressContext<String, Object> expressContext = new DefaultContext<>();
expressContext.put("经理", "王经理");
......@@ -136,6 +146,7 @@ public class WorkflowTest {
@Test
public void testApprove4() throws Exception {
ExpressRunner runner = new ExpressRunner();
//定义操作符别名
runner.addOperatorWithAlias("如果", "if", null);
runner.addOperatorWithAlias("否则", "else", null);
......@@ -145,6 +156,7 @@ public class WorkflowTest {
//加载文件
runner.loadExpress("example/approve1");
runner.loadExpress("example/approve2");
//设置上下文变量
IExpressContext<String, Object> expressContext = new DefaultContext<>();
expressContext.put("经理", "王经理");
......
......@@ -35,7 +35,7 @@ public class ArrayTest {
{"Object[] abc = [];return abc.length", "0"},
{"Map abc = NewMap(1:1,2:2); return abc.get(1) + abc.get(2)", "3"},
{"Map abc = NewMap(\"a\":1,\"b\":2); return abc.a + abc.b", "3"},
{"int o1 =10; int o2=20;String k1 =\"a\";String k2 =\"b\"; Map abc = NewMap(k1:o1,k2:o2); return abc.a +"
{"int o1 =10; int o2=20;String k1 =\"a\";String k2 =\"b\"; Map abc = NewMap(k1:o1,k2:o2); return abc.a +"
+ " abc.b", "30"},
{"Map abc = NewMap(1:\"xuannan\",2:\"qianghui\"); return abc.get(1) +\"-\"+ abc.get(2)",
"xuannan-qianghui"},
......
......@@ -50,12 +50,12 @@ public class ExpressTest {
null);
String[][] expressTest = new String[][] {
{"isVIP(\"qh\") ; isVIP(\"xuannan\"); return isVIP(\"qh\") ;", "false"},
{"如果 三星卖家 则 'a' love 'b' 否则 'b' love 'd' ", "b{a}b"},
{"when 三星卖家 then 'a' love 'b' 否则 'b' love 'd' ", "b{a}b"},
{"如果 三星卖家 则 'a' love 'b' 否则 'b' love 'd'", "b{a}b"},
{"when 三星卖家 then 'a' love 'b' 否则 'b' love 'd'", "b{a}b"},
{"int defVar = 100; defVar = defVar + 100;", "200"},
{"int a=0; if false then a = 5 else a=10+1 ; return a ", "11"},
{" 3+ (1==2?4:3) +8", "14"},
{" 如果 (true) 则 {2+2;} 否则 {20 + 20;} ", "4"},
{"int a = 0; if false then a = 5; else a = 10 + 1; return a;", "11"},
{"3+ (1==2?4:3) +8", "14"},
{"如果 (true) 则 {2 + 2;} 否则 {20 + 20;}", "4"},
{"'AAAAAAA' +'-' + \"\" +'' + \"B\"", "AAAAAAA-B"},
{"System.out.println(\"ss\")", "null"},
{"unionName = new com.ql.util.express.test.BeanExample(\"张三\").unionName(\"李四\")",
......@@ -72,7 +72,7 @@ public class ExpressTest {
{"new String(\"12345\").length()", "5"},
{"'a' love 'b' love 'c' love 'd'", "d{c{b{a}b}c}d"},
{"10 * (10 + 1) + 2 * (3 + 5) * 2", "142"},
{"( 2 属于 (4,3,5)) or isVIP(\"qhlhl2010@gmail.com\") or isVIP(\"qhlhl2010@gmail.com\")", "false"},
{"(2 属于 (4,3,5)) or isVIP(\"qhlhl2010@gmail.com\") or isVIP(\"qhlhl2010@gmail.com\")", "false"},
{" 1!=1 and isVIP(\"qhlhl2010@gmail.com\")", "false"},
{" 1==1 or isVIP(\"qhlhl2010@gmail.com\") ", "true"},
{"abc == 1", "true"},
......@@ -113,7 +113,7 @@ public class ExpressTest {
throw new Exception(
"处理错误,计算结果与预期的不匹配," + expressStr + " = " + result + ",但是期望值是:" + expressTest[point][1]);
}
System.out.println("Example " + point + " : " + expressStr + " = " + result);
System.out.println("Example " + point + " : " + expressStr + " = " + result);
}
System.out.println(expressContext);
}
......
......@@ -10,21 +10,21 @@ public class IfTest {
@Test
public void testIf() throws Exception {
String[][] expresses = new String[][] {
{"if 1==1 then return 100 else return 10;", "100"},
{"if 1==2 then return 100 else return 10;", "10"},
{"if 1==1 then return 100; else return 10;", "100"},
{"if 1==2 then return 100; else return 10;", "10"},
{"if 1==1 then {return 100} else {return 10;}", "100"},
{"if 1==2 then {return 100} else {return 10;}", "10"},
{"if 1==1 then return 100 ; return 10000;", "100"},
{"if 1==1 then return 100; else return 10;", "100"},
{"if 1==2 then return 100; else return 10;", "10"},
{"if 1==1 then return 100; else return 10;", "100"},
{"if 1==2 then return 100; else return 10;", "10"},
{"if 1==1 then {return 100;} else {return 10;}", "100"},
{"if 1==2 then {return 100;} else {return 10;}", "10"},
{"if 1==1 then return 100;; return 10000;", "100"},
{"if 1==2 then return 100; return 10000;", "10000"},
{"if (1==1) return 100 else return 10;", "100"},
{"if (1==2) return 100 else return 10;", "10"},
{"if (1==1) return 100; else return 10;", "100"},
{"if (1==2) return 100; else return 10;", "10"},
{"if (1==1) {return 100} else {return 10;}", "100"},
{"if (1==2) {return 100} else {return 10;}", "10"},
{"if (1==1) return 100 ; return 10000;", "100"},
{"if (1==1) return 100; else return 10;", "100"},
{"if (1==2) return 100; else return 10;", "10"},
{"if (1==1) return 100; else return 10;", "100"},
{"if (1==2) return 100; else return 10;", "10"},
{"if (1==1) {return 100;} else {return 10;}", "100"},
{"if (1==2) {return 100;} else {return 10;}", "10"},
{"if (1==1) return 100; return 10000;", "100"},
{"if (1==2) return 100; return 10000;", "10000"},
};
for (int i = 0; i < expresses.length; i++) {
......
......@@ -40,19 +40,19 @@ public class NewExpressTest {
{"if(1==2) { return 100;}", "null"},
{"int i = 2", "2"},
{"i=2;i<10;", "true"},
{"a =0 ; for(int i=0;i<10;i=i+1){a = a + 1;} return a;", "10"},
{"a =0; for(int i = 0; i < 10; i = i + 1) {a = a + 1;} return a;", "10"},
{"new String(\"ss\")", "ss"},
{"(new String[1][1])[0][0]", "null"},
{"a = new String[1][9]; a[0][1+1] = \"qianghui\"; b = a[0][2]; ", "qianghui"},
{"a = new String[1][9]; a[0][1+1] = \"qianghui\"; b = a[0][2];", "qianghui"},
{"(new String[3][5])[1].length", "5"},
{"\"abc\".length()", "3"},
{"\"abc\".substring(1,3).substring(1,2)", "c"},
{"Integer.SIZE", "32"},
{"new com.ql.util.express.test.BeanExample(\"qianghui\").name", "qianghui"},
{"System.out.println(1)", "null"},
{"int a = 0;for(int i= 0;i<10;i++){ System.out.println(i); a= a+ i} return a;", "45"},
{"int a = 0;for(int i= 0;i<10;i++){ if(i > 5) then{break;} a= a+ i;} return a;", "15"},
{"int a = 0;for(int i= 0;i<10;i++){ if(i <=5) then{continue;} a= a+ i;} return a;", "30"},
{"int a = 0;for(int i = 0; i < 10; i++){System.out.println(i); a = a + i;} return a;", "45"},
{"int a = 0;for(int i = 0; i < 10; i++){if(i > 5) then{break;} a = a + i;} return a;", "15"},
{"int a = 0;for(int i = 0; i < 10; i++){if(i <= 5) then{continue;} a = a + i;} return a;", "30"},
{"int a =0; alias pa a; pa++ ;return a", "1"},
{"int[][] a = new int[10][10]; alias pa a[0]; pa[0] =100 ;return a[0][0]", "100"},
{"int[][] a = new int[10][10]; {exportAlias pa a[0]; pa[0] =100} ;pa[1] =200; return a[0][0] + a[0][1];",
......@@ -62,7 +62,7 @@ public class NewExpressTest {
{"return ((float)9)/2", "4.5"},
{"int a =9; return ((float)a)/2", "4.5"},
{"float a =9; return a/2", "4.5"},
{"macro 惩罚 {100 + 100} 惩罚;", "200"},
{"macro 惩罚 {100 + 100} 惩罚;", "200"},
{"function union(String a,String b){return a +'-'+ b;}; union(\"qiang\",\"hui\")", "qiang-hui"},
{" 3+4 in (8+3,7,9)", "true"},
{"\"ab\" like \"a%\"", "true"},
......
......@@ -37,7 +37,7 @@ public class OpCallTest {
throw new Exception(
"处理错误,计算结果与预期的不匹配," + expressStr + " = " + result + ",但是期望值是:" + expressTest[point][1]);
}
System.out.println("Example " + point + " : " + expressStr + " = " + result);
System.out.println("Example " + point + " : " + expressStr + " = " + result);
if (errorList.size() > 0) {
System.out.println("系统输出的错误提示信息:" + errorList);
}
......
......@@ -32,7 +32,7 @@ public class VarAreaTest {
public void testVarArea2() throws Exception {
String express = ""
+ "qh = 1;"
+ "如果 ( false) 则 {"
+ "如果 ( false) 则 {"
+ " 3 + (3) + (4 + 1);"
+ "} 否则 {"
+ " int qh = 3;"
......
......@@ -17,6 +17,6 @@
}
}
} 否则 {
打回修改(申请人)
打回修改(申请人)
}
打印("完成")
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册