Support logic functions (#461)
* skip tests * Support logic functions #460 * Support logic functions #460
This commit is contained in:
@@ -62,6 +62,9 @@ public class CommonFunc implements IFunc {
|
||||
FuncExecutor.register(NAME_SPACE_PREFIX + "common.isNotBlank", this);
|
||||
FuncExecutor.register(NAME_SPACE_PREFIX + "common.isEmpty", this);
|
||||
FuncExecutor.register(NAME_SPACE_PREFIX + "common.isNotEmpty", this);
|
||||
FuncExecutor.register(NAME_SPACE_PREFIX + "common.and", this);
|
||||
FuncExecutor.register(NAME_SPACE_PREFIX + "common.or", this);
|
||||
FuncExecutor.register(NAME_SPACE_PREFIX + "common.not", this);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -132,4 +135,43 @@ public class CommonFunc implements IFunc {
|
||||
return !isEmpty(obj);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if all args are true<br/>
|
||||
*
|
||||
* @param objs
|
||||
* @return
|
||||
*/
|
||||
public boolean and(Boolean... objs) {
|
||||
if (objs != null && objs.length > 0) {
|
||||
for (int i = 0; i < objs.length; i++) {
|
||||
if (objs[i] == null || !objs[i]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if any arg is true<br/>
|
||||
*
|
||||
* @param objs
|
||||
* @return
|
||||
*/
|
||||
public boolean or(Boolean... objs) {
|
||||
if (objs != null && objs.length > 0) {
|
||||
for (int i = 0; i < objs.length; i++) {
|
||||
if (objs[i] != null && objs[i]) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean not(Boolean obj) {
|
||||
return !(obj == null ? false : obj);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -52,6 +52,18 @@ class CommonFuncTests {
|
||||
m.put("a", "1");
|
||||
m.put("b", "1");
|
||||
m.put("d", "");
|
||||
m.put("true", true);
|
||||
m.put("false", false);
|
||||
m.put("blank", "");
|
||||
m.put("null", null);
|
||||
m.put("stringtrue", "true");
|
||||
m.put("stringfalse", "false");
|
||||
m.put("string1", "1");
|
||||
m.put("string0", "0");
|
||||
m.put("stringabc", "abc");
|
||||
m.put("int1", "1");
|
||||
m.put("int0", "0");
|
||||
m.put("int2", "2");
|
||||
|
||||
List<Object> list = new ArrayList<>();
|
||||
list.add(createRecord("a", "a1"));
|
||||
@@ -238,4 +250,271 @@ class CommonFuncTests {
|
||||
assertEquals(false, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testAnd() {
|
||||
ONode ctx = getCtxNode();
|
||||
String funcExpression = "fn.common.and(true, true)";
|
||||
Boolean result = (Boolean)FuncExecutor.getInstance().exec(ctx, funcExpression);
|
||||
assertEquals(true, result);
|
||||
|
||||
funcExpression = "fn.common.and(true, true, true)";
|
||||
result = (Boolean)FuncExecutor.getInstance().exec(ctx, funcExpression);
|
||||
assertEquals(true, result);
|
||||
|
||||
funcExpression = "fn.common.and(true)";
|
||||
result = (Boolean)FuncExecutor.getInstance().exec(ctx, funcExpression);
|
||||
assertEquals(true, result);
|
||||
|
||||
funcExpression = "fn.common.and({data.m.true}, {data.m.true}, {data.m.true})";
|
||||
result = (Boolean)FuncExecutor.getInstance().exec(ctx, funcExpression);
|
||||
assertEquals(true, result);
|
||||
|
||||
funcExpression = "fn.common.and({data.m.true}, {data.m.true}, {data.m.true}, {data.m.notexist})";
|
||||
result = (Boolean)FuncExecutor.getInstance().exec(ctx, funcExpression);
|
||||
assertEquals(false, result);
|
||||
|
||||
funcExpression = "fn.common.and({data.m.true}, {data.m.true}, {data.m.true}, {data.m.null})";
|
||||
result = (Boolean)FuncExecutor.getInstance().exec(ctx, funcExpression);
|
||||
assertEquals(false, result);
|
||||
|
||||
funcExpression = "fn.common.and({data.m.true}, {data.m.true}, {data.m.true}, {data.m.blank})";
|
||||
result = (Boolean)FuncExecutor.getInstance().exec(ctx, funcExpression);
|
||||
assertEquals(false, result);
|
||||
|
||||
funcExpression = "fn.common.and({data.m.true}, {data.m.false}, {data.m.true})";
|
||||
result = (Boolean)FuncExecutor.getInstance().exec(ctx, funcExpression);
|
||||
assertEquals(false, result);
|
||||
|
||||
funcExpression = "fn.common.and({data.m.false}, {data.m.true})";
|
||||
result = (Boolean)FuncExecutor.getInstance().exec(ctx, funcExpression);
|
||||
assertEquals(false, result);
|
||||
|
||||
funcExpression = "fn.common.and({data.m.false})";
|
||||
result = (Boolean)FuncExecutor.getInstance().exec(ctx, funcExpression);
|
||||
assertEquals(false, result);
|
||||
|
||||
funcExpression = "fn.common.and({data.m.true}, {data.m.notexist})";
|
||||
result = (Boolean)FuncExecutor.getInstance().exec(ctx, funcExpression);
|
||||
assertEquals(false, result);
|
||||
|
||||
funcExpression = "fn.common.and({data.m.notexist})";
|
||||
result = (Boolean)FuncExecutor.getInstance().exec(ctx, funcExpression);
|
||||
assertEquals(false, result);
|
||||
|
||||
funcExpression = "fn.common.and()";
|
||||
result = (Boolean)FuncExecutor.getInstance().exec(ctx, funcExpression);
|
||||
assertEquals(false, result);
|
||||
|
||||
funcExpression = "fn.common.and({data.m.blank})";
|
||||
result = (Boolean)FuncExecutor.getInstance().exec(ctx, funcExpression);
|
||||
assertEquals(false, result);
|
||||
|
||||
funcExpression = "fn.common.and({data.m.null})";
|
||||
result = (Boolean)FuncExecutor.getInstance().exec(ctx, funcExpression);
|
||||
assertEquals(false, result);
|
||||
|
||||
funcExpression = "fn.common.and({data.m.int1})";
|
||||
result = (Boolean)FuncExecutor.getInstance().exec(ctx, funcExpression);
|
||||
assertEquals(true, result);
|
||||
|
||||
funcExpression = "fn.common.and({data.m.int0})";
|
||||
result = (Boolean)FuncExecutor.getInstance().exec(ctx, funcExpression);
|
||||
assertEquals(false, result);
|
||||
|
||||
funcExpression = "fn.common.and({data.m.string1})";
|
||||
result = (Boolean)FuncExecutor.getInstance().exec(ctx, funcExpression);
|
||||
assertEquals(true, result);
|
||||
|
||||
funcExpression = "fn.common.and({data.m.string0})";
|
||||
result = (Boolean)FuncExecutor.getInstance().exec(ctx, funcExpression);
|
||||
assertEquals(false, result);
|
||||
|
||||
funcExpression = "fn.common.and({data.m.stringabc})";
|
||||
result = (Boolean)FuncExecutor.getInstance().exec(ctx, funcExpression);
|
||||
assertEquals(false, result);
|
||||
|
||||
funcExpression = "fn.common.and({data.m.stringtrue})";
|
||||
result = (Boolean)FuncExecutor.getInstance().exec(ctx, funcExpression);
|
||||
assertEquals(true, result);
|
||||
|
||||
funcExpression = "fn.common.and({data.m.stringfalse})";
|
||||
result = (Boolean)FuncExecutor.getInstance().exec(ctx, funcExpression);
|
||||
assertEquals(false, result);
|
||||
|
||||
funcExpression = "fn.common.and({data.m.int2})";
|
||||
result = (Boolean)FuncExecutor.getInstance().exec(ctx, funcExpression);
|
||||
assertEquals(false, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testOr() {
|
||||
ONode ctx = getCtxNode();
|
||||
String funcExpression = "fn.common.or(true, true)";
|
||||
Boolean result = (Boolean)FuncExecutor.getInstance().exec(ctx, funcExpression);
|
||||
assertEquals(true, result);
|
||||
|
||||
funcExpression = "fn.common.or(true, true, true)";
|
||||
result = (Boolean)FuncExecutor.getInstance().exec(ctx, funcExpression);
|
||||
assertEquals(true, result);
|
||||
|
||||
funcExpression = "fn.common.or(false, true)";
|
||||
result = (Boolean)FuncExecutor.getInstance().exec(ctx, funcExpression);
|
||||
assertEquals(true, result);
|
||||
|
||||
funcExpression = "fn.common.or(true)";
|
||||
result = (Boolean)FuncExecutor.getInstance().exec(ctx, funcExpression);
|
||||
assertEquals(true, result);
|
||||
|
||||
funcExpression = "fn.common.or(false)";
|
||||
result = (Boolean)FuncExecutor.getInstance().exec(ctx, funcExpression);
|
||||
assertEquals(false, result);
|
||||
|
||||
funcExpression = "fn.common.or(true, false, true)";
|
||||
result = (Boolean)FuncExecutor.getInstance().exec(ctx, funcExpression);
|
||||
assertEquals(true, result);
|
||||
|
||||
funcExpression = "fn.common.or({data.m.true}, {data.m.true}, {data.m.true})";
|
||||
result = (Boolean)FuncExecutor.getInstance().exec(ctx, funcExpression);
|
||||
assertEquals(true, result);
|
||||
|
||||
funcExpression = "fn.common.or({data.m.true}, {data.m.true}, {data.m.false})";
|
||||
result = (Boolean)FuncExecutor.getInstance().exec(ctx, funcExpression);
|
||||
assertEquals(true, result);
|
||||
|
||||
funcExpression = "fn.common.or({data.m.false}, {data.m.true}, {data.m.true})";
|
||||
result = (Boolean)FuncExecutor.getInstance().exec(ctx, funcExpression);
|
||||
assertEquals(true, result);
|
||||
|
||||
funcExpression = "fn.common.or({data.m.false}, {data.m.notexist}, {data.m.true})";
|
||||
result = (Boolean)FuncExecutor.getInstance().exec(ctx, funcExpression);
|
||||
assertEquals(true, result);
|
||||
|
||||
funcExpression = "fn.common.or({data.m.false}, {data.m.null}, {data.m.true})";
|
||||
result = (Boolean)FuncExecutor.getInstance().exec(ctx, funcExpression);
|
||||
assertEquals(true, result);
|
||||
|
||||
funcExpression = "fn.common.or({data.m.false}, {data.m.blank}, {data.m.true})";
|
||||
result = (Boolean)FuncExecutor.getInstance().exec(ctx, funcExpression);
|
||||
assertEquals(true, result);
|
||||
|
||||
funcExpression = "fn.common.or({data.m.false}, {data.m.false}, {data.m.false})";
|
||||
result = (Boolean)FuncExecutor.getInstance().exec(ctx, funcExpression);
|
||||
assertEquals(false, result);
|
||||
|
||||
funcExpression = "fn.common.or({data.m.false}, {data.m.false})";
|
||||
result = (Boolean)FuncExecutor.getInstance().exec(ctx, funcExpression);
|
||||
assertEquals(false, result);
|
||||
|
||||
funcExpression = "fn.common.or({data.m.false})";
|
||||
result = (Boolean)FuncExecutor.getInstance().exec(ctx, funcExpression);
|
||||
assertEquals(false, result);
|
||||
|
||||
funcExpression = "fn.common.or({data.m.null})";
|
||||
result = (Boolean)FuncExecutor.getInstance().exec(ctx, funcExpression);
|
||||
assertEquals(false, result);
|
||||
|
||||
funcExpression = "fn.common.or({data.m.blank})";
|
||||
result = (Boolean)FuncExecutor.getInstance().exec(ctx, funcExpression);
|
||||
assertEquals(false, result);
|
||||
|
||||
funcExpression = "fn.common.or({data.m.notexist})";
|
||||
result = (Boolean)FuncExecutor.getInstance().exec(ctx, funcExpression);
|
||||
assertEquals(false, result);
|
||||
|
||||
funcExpression = "fn.common.or()";
|
||||
result = (Boolean)FuncExecutor.getInstance().exec(ctx, funcExpression);
|
||||
assertEquals(false, result);
|
||||
|
||||
funcExpression = "fn.common.or({data.m.true})";
|
||||
result = (Boolean)FuncExecutor.getInstance().exec(ctx, funcExpression);
|
||||
assertEquals(true, result);
|
||||
|
||||
funcExpression = "fn.common.or({data.m.int1})";
|
||||
result = (Boolean)FuncExecutor.getInstance().exec(ctx, funcExpression);
|
||||
assertEquals(true, result);
|
||||
|
||||
funcExpression = "fn.common.or({data.m.int0})";
|
||||
result = (Boolean)FuncExecutor.getInstance().exec(ctx, funcExpression);
|
||||
assertEquals(false, result);
|
||||
|
||||
funcExpression = "fn.common.or({data.m.string1})";
|
||||
result = (Boolean)FuncExecutor.getInstance().exec(ctx, funcExpression);
|
||||
assertEquals(true, result);
|
||||
|
||||
funcExpression = "fn.common.or({data.m.string0})";
|
||||
result = (Boolean)FuncExecutor.getInstance().exec(ctx, funcExpression);
|
||||
assertEquals(false, result);
|
||||
|
||||
funcExpression = "fn.common.or({data.m.stringabc})";
|
||||
result = (Boolean)FuncExecutor.getInstance().exec(ctx, funcExpression);
|
||||
assertEquals(false, result);
|
||||
|
||||
funcExpression = "fn.common.or({data.m.stringtrue})";
|
||||
result = (Boolean)FuncExecutor.getInstance().exec(ctx, funcExpression);
|
||||
assertEquals(true, result);
|
||||
|
||||
funcExpression = "fn.common.or({data.m.stringfalse})";
|
||||
result = (Boolean)FuncExecutor.getInstance().exec(ctx, funcExpression);
|
||||
assertEquals(false, result);
|
||||
|
||||
funcExpression = "fn.common.or({data.m.int2})";
|
||||
result = (Boolean)FuncExecutor.getInstance().exec(ctx, funcExpression);
|
||||
assertEquals(false, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testNot() {
|
||||
ONode ctx = getCtxNode();
|
||||
String funcExpression = "fn.common.not(true)";
|
||||
Boolean result = (Boolean)FuncExecutor.getInstance().exec(ctx, funcExpression);
|
||||
assertEquals(false, result);
|
||||
|
||||
funcExpression = "fn.common.not(false)";
|
||||
result = (Boolean)FuncExecutor.getInstance().exec(ctx, funcExpression);
|
||||
assertEquals(true, result);
|
||||
|
||||
funcExpression = "fn.common.not({data.m.blank})";
|
||||
result = (Boolean)FuncExecutor.getInstance().exec(ctx, funcExpression);
|
||||
assertEquals(true, result);
|
||||
|
||||
funcExpression = "fn.common.not({data.m.null})";
|
||||
result = (Boolean)FuncExecutor.getInstance().exec(ctx, funcExpression);
|
||||
assertEquals(true, result);
|
||||
|
||||
funcExpression = "fn.common.not({data.m.notexist})";
|
||||
result = (Boolean)FuncExecutor.getInstance().exec(ctx, funcExpression);
|
||||
assertEquals(true, result);
|
||||
|
||||
funcExpression = "fn.common.not({data.m.string1})";
|
||||
result = (Boolean)FuncExecutor.getInstance().exec(ctx, funcExpression);
|
||||
assertEquals(false, result);
|
||||
|
||||
funcExpression = "fn.common.not({data.m.string0})";
|
||||
result = (Boolean)FuncExecutor.getInstance().exec(ctx, funcExpression);
|
||||
assertEquals(true, result);
|
||||
|
||||
funcExpression = "fn.common.not({data.m.stringabc})";
|
||||
result = (Boolean)FuncExecutor.getInstance().exec(ctx, funcExpression);
|
||||
assertEquals(true, result);
|
||||
|
||||
funcExpression = "fn.common.not({data.m.stringtrue})";
|
||||
result = (Boolean)FuncExecutor.getInstance().exec(ctx, funcExpression);
|
||||
assertEquals(false, result);
|
||||
|
||||
funcExpression = "fn.common.not({data.m.stringfalse})";
|
||||
result = (Boolean)FuncExecutor.getInstance().exec(ctx, funcExpression);
|
||||
assertEquals(true, result);
|
||||
|
||||
funcExpression = "fn.common.not({data.m.int1})";
|
||||
result = (Boolean)FuncExecutor.getInstance().exec(ctx, funcExpression);
|
||||
assertEquals(false, result);
|
||||
|
||||
funcExpression = "fn.common.not({data.m.int0})";
|
||||
result = (Boolean)FuncExecutor.getInstance().exec(ctx, funcExpression);
|
||||
assertEquals(true, result);
|
||||
|
||||
funcExpression = "fn.common.not({data.m.int2})";
|
||||
result = (Boolean)FuncExecutor.getInstance().exec(ctx, funcExpression);
|
||||
assertEquals(true, result);
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,7 @@ baseline.jdk=jdk-1.8
|
||||
# 构建打包所用的maven版本
|
||||
build.tools.maven=maven3.2.5
|
||||
|
||||
build.command=mvn -B clean package install --file pom.xml && mvn -B clean package install --file fizz-bootstrap/pom.xml
|
||||
build.command=mvn -B clean package install -Dmaven.test.skip=true --file pom.xml && mvn -B clean package install -Dmaven.test.skip=true --file fizz-bootstrap/pom.xml
|
||||
|
||||
# 构建打包使用的打包文件
|
||||
build.output=fizz-bootstrap/target/*
|
||||
|
||||
Reference in New Issue
Block a user