Skip to content

Commit 33f3b1b

Browse files
committed
Add test for issue #5: "eval should sometimes make an entry in the ENGINE_SCOPE bindings"
1 parent 32d4c5f commit 33f3b1b

File tree

1 file changed

+25
-5
lines changed

1 file changed

+25
-5
lines changed

src/test/java/org/scijava/plugins/scripting/scala/ScalaTest.java

+25-5
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
* %%
77
* Redistribution and use in source and binary forms, with or without
88
* modification, are permitted provided that the following conditions are met:
9-
*
9+
*
1010
* 1. Redistributions of source code must retain the above copyright notice,
1111
* this list of conditions and the following disclaimer.
1212
* 2. Redistributions in binary form must reproduce the above copyright notice,
1313
* this list of conditions and the following disclaimer in the documentation
1414
* and/or other materials provided with the distribution.
15-
*
15+
*
1616
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
1717
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1818
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -35,12 +35,12 @@
3535
import org.scijava.script.ScriptModule;
3636
import org.scijava.script.ScriptService;
3737

38+
import javax.script.ScriptContext;
3839
import javax.script.ScriptEngine;
3940
import javax.script.SimpleScriptContext;
4041
import java.io.StringWriter;
4142

42-
import static org.junit.Assert.assertEquals;
43-
import static org.junit.Assert.assertTrue;
43+
import static org.junit.Assert.*;
4444

4545
/**
4646
* Scala unit tests.
@@ -210,7 +210,7 @@ public void testLocals() throws Exception {
210210
assertEquals("17", engine.eval("hello").toString());
211211
assertEquals("17", engine.get("hello").toString());
212212

213-
// With Scala 3.2.2 cannot reset bindings correctly, will skip the ret of the test
213+
// With Scala 3.2.2 cannot reset bindings correctly, will skip the rest of the test
214214
// final Bindings bindings = engine.getBindings(ScriptContext.ENGINE_SCOPE);
215215
// bindings.clear();
216216
// assertNull(engine.get("hello"));
@@ -266,4 +266,24 @@ public void testImportsRetained() throws Exception {
266266
assertEquals(result, result2);
267267
}
268268
}
269+
270+
/**
271+
* Test for issue #5: "eval should sometimes make an entry in the ENGINE_SCOPE bindings"
272+
*/
273+
@Test
274+
public void issue5() {
275+
try (final Context context = new Context(ScriptService.class)) {
276+
277+
final ScriptService scriptService = context.getService(ScriptService.class);
278+
final ScriptEngine engine = scriptService.getLanguageByName("scala").getScriptEngine();
279+
280+
assertFalse(engine.getBindings(ScriptContext.ENGINE_SCOPE).containsKey("ten"));
281+
engine.put("ten", 10);
282+
assertEquals(10, engine.get("ten"));
283+
assertTrue(engine.getBindings(ScriptContext.ENGINE_SCOPE).containsKey("ten"));
284+
285+
engine.put("twenty", 20);
286+
assertEquals(20, engine.get("twenty"));
287+
}
288+
}
269289
}

0 commit comments

Comments
 (0)