1239 assertEquals(sw.toString().replaceAll("\r", ""), "hello\n"); 1240 } 1241 1242 @Test 1243 // check that print prints all arguments (more than one) 1244 public void printManyTest() { 1245 final ScriptEngineManager m = new ScriptEngineManager(); 1246 final ScriptEngine e = m.getEngineByName("nashorn"); 1247 final StringWriter sw = new StringWriter(); 1248 e.getContext().setWriter(sw); 1249 try { 1250 e.eval("print(34, true, 'hello')"); 1251 } catch (final Throwable t) { 1252 t.printStackTrace(); 1253 fail(t.getMessage()); 1254 } 1255 1256 // dos2unix - fix line endings if running on windows 1257 assertEquals(sw.toString().replaceAll("\r", ""), "34 true hello\n"); 1258 } 1259 } | 1239 assertEquals(sw.toString().replaceAll("\r", ""), "hello\n"); 1240 } 1241 1242 @Test 1243 // check that print prints all arguments (more than one) 1244 public void printManyTest() { 1245 final ScriptEngineManager m = new ScriptEngineManager(); 1246 final ScriptEngine e = m.getEngineByName("nashorn"); 1247 final StringWriter sw = new StringWriter(); 1248 e.getContext().setWriter(sw); 1249 try { 1250 e.eval("print(34, true, 'hello')"); 1251 } catch (final Throwable t) { 1252 t.printStackTrace(); 1253 fail(t.getMessage()); 1254 } 1255 1256 // dos2unix - fix line endings if running on windows 1257 assertEquals(sw.toString().replaceAll("\r", ""), "34 true hello\n"); 1258 } 1259 1260 @Test 1261 public void mirrorNewObjectGlobalFunctionTest() throws ScriptException { 1262 final ScriptEngineManager m = new ScriptEngineManager(); 1263 final ScriptEngine e = m.getEngineByName("nashorn"); 1264 final ScriptEngine e2 = m.getEngineByName("nashorn"); 1265 1266 e.eval("function func() {}"); 1267 e2.put("foo", e.get("func")); 1268 final Object e2global = e2.eval("this"); 1269 final Object newObj = ((ScriptObjectMirror)e2global).newObject("foo"); 1270 assertTrue(newObj instanceof ScriptObjectMirror); 1271 } 1272 1273 @Test 1274 public void mirrorNewObjectInstanceFunctionTest() throws ScriptException { 1275 final ScriptEngineManager m = new ScriptEngineManager(); 1276 final ScriptEngine e = m.getEngineByName("nashorn"); 1277 final ScriptEngine e2 = m.getEngineByName("nashorn"); 1278 1279 e.eval("function func() {}"); 1280 e2.put("func", e.get("func")); 1281 final Object e2obj = e2.eval("({ foo: func })"); 1282 final Object newObj = ((ScriptObjectMirror)e2obj).newObject("foo"); 1283 assertTrue(newObj instanceof ScriptObjectMirror); 1284 } 1285 } |