Autoflush and encode written bytes in script contexts (fixes issue #20)
This commit is contained in:
@@ -51,6 +51,7 @@ public class ScriptEngineTests extends TestSuite {
|
||||
suite.addTest( new TestSuite( DefaultBindingsTest.class, "Default Bindings" ) );
|
||||
suite.addTest( new TestSuite( LuaJCBindingsTest.class, "LuaJC Bindings" ) );
|
||||
suite.addTest( new TestSuite( UserContextTest.class, "User Context" ) );
|
||||
suite.addTest( new TestSuite( WriterTest.class, "Writer" ) );
|
||||
return suite;
|
||||
}
|
||||
|
||||
@@ -282,4 +283,24 @@ public class ScriptEngineTests extends TestSuite {
|
||||
assertEquals(5, b.get("z"));
|
||||
}
|
||||
}
|
||||
|
||||
public static class WriterTest extends TestCase {
|
||||
protected ScriptEngine e;
|
||||
protected Bindings b;
|
||||
public void setUp() {
|
||||
this.e = new ScriptEngineManager().getEngineByName("luaj");
|
||||
this.b = e.getBindings(ScriptContext.ENGINE_SCOPE);
|
||||
}
|
||||
public void testWriter() throws ScriptException {
|
||||
CharArrayWriter output = new CharArrayWriter();
|
||||
CharArrayWriter errors = new CharArrayWriter();
|
||||
e.getContext().setWriter(output);
|
||||
e.getContext().setErrorWriter(errors);
|
||||
e.eval("io.write( [[line]] )");
|
||||
assertEquals("line", output.toString());
|
||||
e.eval("io.write( [[ one\nline two\n]] )");
|
||||
assertEquals("line one\nline two\n", output.toString());
|
||||
output.reset();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user