Skip to content

Commit 91ec0fd

Browse files
committed
Add some simple tests for eval
With the custom SciJava Jython ScriptEngine implementation, the eval support was rather broken. For example, the expression "v=1" would say: SyntaxError: ("mismatched input '=' expecting EOF", ('<string>', 1, 1, 'v=1\n')) Fortunately, the stock Jython 2.7.0 ScriptEngine works.
1 parent 6cd8345 commit 91ec0fd

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/test/java/org/scijava/plugins/scripting/jython/JythonTest.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import static org.junit.Assert.assertSame;
3737

3838
import java.io.IOException;
39+
import java.math.BigInteger;
3940
import java.util.concurrent.ExecutionException;
4041

4142
import javax.script.Bindings;
@@ -148,4 +149,22 @@ public void testLongType() throws InterruptedException, ExecutionException,
148149
final String expected = "<type 'long'>";
149150
assertEquals(expected, actual);
150151
}
152+
153+
@Test
154+
public void testEval() throws ScriptException {
155+
final ScriptLanguage language = scriptService.getLanguageByExtension("py");
156+
final ScriptEngine engine = language.getScriptEngine();
157+
assertEquals(PyScriptEngine.class, engine.getClass());
158+
159+
final Object sum = engine.eval("2 + 3");
160+
assertEquals(5, sum);
161+
162+
final String n1 = "112233445566778899";
163+
final String n2 = "998877665544332211";
164+
final Object bigNum = engine.eval(n1 + "*" + n2);
165+
assertEquals(new BigInteger(n1).multiply(new BigInteger(n2)), bigNum);
166+
167+
final Object varAssign = engine.eval("a = 4 + 5");
168+
assertNull(varAssign);
169+
}
151170
}

0 commit comments

Comments
 (0)