remove expression

This commit is contained in:
Looly
2023-04-21 01:15:25 +08:00
parent 32e8caccdd
commit f60e426e34
36 changed files with 0 additions and 1433 deletions

View File

@@ -1,62 +0,0 @@
package org.dromara.hutool.extra.expression;
import org.dromara.hutool.core.date.DateUtil;
import org.dromara.hutool.core.lang.Console;
import org.dromara.hutool.core.map.Dict;
import org.dromara.hutool.extra.expression.engine.aviator.AviatorEngine;
import lombok.Data;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.util.Date;
/**
* Aviator引擎单元测试来自https://github.com/looly/hutool/pull/1203
*/
public class AviatorTest {
@Test
public void simpleTest(){
final Foo foo = new Foo(100, 3.14f, DateUtil.parse("2020-11-12"));
final ExpressionEngine engine = new AviatorEngine();
String exp =
"\"[foo i=\"+ foo.i + \", f=\" + foo.f + \", date.year=\" + (foo.date.year+1900) + \", date.month=\" + foo.date.month + \", bars[0].name=\" + #foo.bars[0].name + \"]\"";
String result = (String) engine.eval(exp, Dict.of().set("foo", foo));
Assertions.assertEquals("[foo i=100, f=3.14, date.year=2020, date.month=10, bars[0].name=bar]", result);
// Assignment.
exp = "#foo.bars[0].name='hello aviator' ; #foo.bars[0].name";
result = (String) engine.eval(exp, Dict.of().set("foo", foo));
Assertions.assertEquals("hello aviator", result);
Assertions.assertEquals("hello aviator", foo.bars[0].getName());
exp = "foo.bars[0] = nil ; foo.bars[0]";
result = (String) engine.eval(exp, Dict.of().set("foo", foo));
Console.log("Execute expression: " + exp);
Assertions.assertNull(result);
Assertions.assertNull(foo.bars[0]);
}
@Data
public static class Bar {
public Bar() {
this.name = "bar";
}
private String name;
}
@Data
public static class Foo {
int i;
float f;
Date date;
Bar[] bars = new Bar[1];
public Foo(final int i, final float f, final Date date) {
this.i = i;
this.f = f;
this.date = date;
this.bars[0] = new Bar();
}
}
}

View File

@@ -1,111 +0,0 @@
package org.dromara.hutool.extra.expression;
import org.dromara.hutool.core.map.Dict;
import org.dromara.hutool.extra.expression.engine.jexl.JexlEngine;
import org.dromara.hutool.extra.expression.engine.jfireel.JfireELEngine;
import org.dromara.hutool.extra.expression.engine.mvel.MvelEngine;
import org.dromara.hutool.extra.expression.engine.qlexpress.QLExpressEngine;
import org.dromara.hutool.extra.expression.engine.rhino.RhinoEngine;
import org.dromara.hutool.extra.expression.engine.spel.SpELEngine;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.util.HashMap;
import java.util.Map;
public class ExpressionUtilTest {
@Test
public void evalTest(){
final Dict dict = Dict.of()
.set("a", 100.3)
.set("b", 45)
.set("c", -199.100);
final Object eval = ExpressionUtil.eval("a-(b-c)", dict);
Assertions.assertEquals(-143.8, (double)eval, 0);
}
@Test
public void jexlTest(){
final ExpressionEngine engine = new JexlEngine();
final Dict dict = Dict.of()
.set("a", 100.3)
.set("b", 45)
.set("c", -199.100);
final Object eval = engine.eval("a-(b-c)", dict);
Assertions.assertEquals(-143.8, (double)eval, 0);
}
@Test
public void jexlScriptTest(){
final ExpressionEngine engine = new JexlEngine();
final String exps2="if(a>0){return 100;}";
final Map<String,Object> map2=new HashMap<>();
map2.put("a", 1);
final Object eval1 = engine.eval(exps2, map2);
Assertions.assertEquals(100, eval1);
}
@Test
public void mvelTest(){
final ExpressionEngine engine = new MvelEngine();
final Dict dict = Dict.of()
.set("a", 100.3)
.set("b", 45)
.set("c", -199.100);
final Object eval = engine.eval("a-(b-c)", dict);
Assertions.assertEquals(-143.8, (double)eval, 0);
}
@Test
public void jfireELTest(){
final ExpressionEngine engine = new JfireELEngine();
final Dict dict = Dict.of()
.set("a", 100.3)
.set("b", 45)
.set("c", -199.100);
final Object eval = engine.eval("a-(b-c)", dict);
Assertions.assertEquals(-143.8, (double)eval, 0);
}
@Test
public void spELTest(){
final ExpressionEngine engine = new SpELEngine();
final Dict dict = Dict.of()
.set("a", 100.3)
.set("b", 45)
.set("c", -199.100);
final Object eval = engine.eval("#a-(#b-#c)", dict);
Assertions.assertEquals(-143.8, (double)eval, 0);
}
@Test
public void rhinoTest(){
final ExpressionEngine engine = new RhinoEngine();
final Dict dict = Dict.of()
.set("a", 100.3)
.set("b", 45)
.set("c", -199.100);
final Object eval = engine.eval("a-(b-c)", dict);
Assertions.assertEquals(-143.8, (double)eval, 0);
}
@Test
public void qlExpressTest(){
final ExpressionEngine engine = new QLExpressEngine();
final Dict dict = Dict.of()
.set("a", 100.3)
.set("b", 45)
.set("c", -199.100);
final Object eval = engine.eval("a-(b-c)", dict);
Assertions.assertEquals(-143.8, (double)eval, 0);
}
}

View File

@@ -1,32 +0,0 @@
/*
* Copyright (c) 2023 looly(loolly@aliyun.com)
* Hutool is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
*/
package org.dromara.hutool.extra.expression;
import org.dromara.hutool.core.map.Dict;
import org.dromara.hutool.extra.expression.engine.ognl.OgnlEngine;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
public class OgnlTest {
@Test
void evalTest() {
final ExpressionEngine engine = new OgnlEngine();
final Dict dict = Dict.of()
.set("a", 100.3)
.set("b", 45)
.set("c", -199.100);
final Object eval = engine.eval("#a-(#b-#c)", dict);
Assertions.assertEquals(-143.8, (double)eval, 0);
}
}