mirror of
https://gitee.com/dromara/hutool.git
synced 2025-09-21 02:58:11 +08:00
fix bug
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
package cn.hutool.script.test;
|
||||
|
||||
|
||||
import cn.hutool.core.io.resource.ResourceUtil;
|
||||
import org.junit.Assert;
|
||||
|
||||
import javax.script.Invocable;
|
||||
import javax.script.ScriptEngine;
|
||||
import javax.script.ScriptEngineManager;
|
||||
import javax.script.ScriptException;
|
||||
|
||||
public class NashornDeepTest {
|
||||
|
||||
public static void main(String[] args) throws ScriptException, NoSuchMethodException {
|
||||
ScriptEngine engine = new ScriptEngineManager().getEngineByName("js");
|
||||
|
||||
engine.eval(ResourceUtil.readUtf8Str("filter1.js"));
|
||||
|
||||
final Object filter1 = ((Invocable) engine).invokeFunction("filter1", 1, 2);
|
||||
Assert.assertFalse((Boolean) filter1);
|
||||
}
|
||||
}
|
@@ -1,7 +1,9 @@
|
||||
package cn.hutool.script.test;
|
||||
|
||||
import cn.hutool.core.io.resource.ResourceUtil;
|
||||
import cn.hutool.script.ScriptRuntimeException;
|
||||
import cn.hutool.script.ScriptUtil;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import javax.script.CompiledScript;
|
||||
@@ -31,6 +33,12 @@ public class ScriptUtilTest {
|
||||
ScriptUtil.eval("print('Script test!');");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void invokeTest() {
|
||||
final Object result = ScriptUtil.invoke(ResourceUtil.readUtf8Str("filter1.js"), "filter1", 2, 1);
|
||||
Assert.assertTrue((Boolean) result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void pythonTest() throws ScriptException {
|
||||
final ScriptEngine pythonEngine = ScriptUtil.getPythonEngine();
|
||||
|
6
hutool-script/src/test/resources/filter1.js
Normal file
6
hutool-script/src/test/resources/filter1.js
Normal file
@@ -0,0 +1,6 @@
|
||||
function filter1(a, b) {
|
||||
if (a > b) {
|
||||
return a > b;
|
||||
}
|
||||
return false;
|
||||
}
|
Reference in New Issue
Block a user