Added ScriptUtils

This commit is contained in:
Auxilor
2022-04-25 11:32:47 +01:00
parent a993acae72
commit cb9b59ae01
4 changed files with 162 additions and 2 deletions

View File

@@ -0,0 +1,40 @@
import com.willfp.eco.util.ScriptUtils;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
public class ScriptUtilsTest {
@Test
public void testScriptUtils() {
Assertions.assertEquals(
"Test",
ScriptUtils.eval("\"Test\"")
);
Assertions.assertNull(ScriptUtils.eval("empasd___a !&&b1923"));
Assertions.assertEquals(
10,
ScriptUtils.eval("8 + 2")
);
Assertions.assertEquals(
"XVIII",
ScriptUtils.eval("com.willfp.eco.util.NumberUtils.toNumeral(18)")
);
}
@Test
public void testBindings() {
Assertions.assertEquals(
10,
ScriptUtils.eval("x + y", (bindings) -> {
bindings.put("x", 2);
bindings.put("y", 8);
})
);
Assertions.assertEquals(
12,
ScriptUtils.eval("x + y", (bindings) -> {
bindings.put("x", 3);
bindings.put("y", 9);
})
);
}
}