|
6 | 6 | * %% |
7 | 7 | * Redistribution and use in source and binary forms, with or without |
8 | 8 | * modification, are permitted provided that the following conditions are met: |
9 | | - * |
| 9 | + * |
10 | 10 | * 1. Redistributions of source code must retain the above copyright notice, |
11 | 11 | * this list of conditions and the following disclaimer. |
12 | 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
13 | 13 | * this list of conditions and the following disclaimer in the documentation |
14 | 14 | * and/or other materials provided with the distribution. |
15 | | - * |
| 15 | + * |
16 | 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
17 | 17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
18 | 18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
|
35 | 35 | import org.scijava.script.ScriptModule; |
36 | 36 | import org.scijava.script.ScriptService; |
37 | 37 |
|
| 38 | +import javax.script.ScriptContext; |
38 | 39 | import javax.script.ScriptEngine; |
39 | 40 | import javax.script.SimpleScriptContext; |
40 | 41 | import java.io.StringWriter; |
41 | 42 |
|
42 | | -import static org.junit.Assert.assertEquals; |
43 | | -import static org.junit.Assert.assertTrue; |
| 43 | +import static org.junit.Assert.*; |
44 | 44 |
|
45 | 45 | /** |
46 | 46 | * Scala unit tests. |
@@ -210,7 +210,7 @@ public void testLocals() throws Exception { |
210 | 210 | assertEquals("17", engine.eval("hello").toString()); |
211 | 211 | assertEquals("17", engine.get("hello").toString()); |
212 | 212 |
|
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 |
214 | 214 | // final Bindings bindings = engine.getBindings(ScriptContext.ENGINE_SCOPE); |
215 | 215 | // bindings.clear(); |
216 | 216 | // assertNull(engine.get("hello")); |
@@ -266,4 +266,24 @@ public void testImportsRetained() throws Exception { |
266 | 266 | assertEquals(result, result2); |
267 | 267 | } |
268 | 268 | } |
| 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 | + } |
269 | 289 | } |
0 commit comments