Fixed issue: #55
This commit is contained in:
@@ -26,6 +26,8 @@ import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
import java.io.StringReader;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.SQLException;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
@@ -438,6 +440,46 @@ public class FragmentsTest extends TestSuite {
|
||||
}
|
||||
}
|
||||
|
||||
public void testIoLinesClosesImplicitFileAtEnd() throws Exception {
|
||||
File file = writeTempFile("lines-close", "a\nb\n");
|
||||
try {
|
||||
Globals globals = JsePlatform.standardGlobals();
|
||||
Varargs iterTriplet = globals.get("io").get("lines").invoke(LuaValue.varargsOf(new LuaValue[] {
|
||||
LuaValue.valueOf(file.getAbsolutePath())
|
||||
}));
|
||||
LuaValue iter = iterTriplet.arg1();
|
||||
assertEquals(LuaValue.valueOf("a"), iter.call());
|
||||
assertEquals(LuaValue.valueOf("b"), iter.call());
|
||||
assertEquals(LuaValue.NIL, iter.call());
|
||||
|
||||
Field f = iter.getClass().getDeclaredField("f");
|
||||
f.setAccessible(true);
|
||||
Object fileHandle = f.get(iter);
|
||||
Method isclosed = fileHandle.getClass().getDeclaredMethod("isclosed");
|
||||
isclosed.setAccessible(true);
|
||||
assertEquals(Boolean.TRUE, isclosed.invoke(fileHandle));
|
||||
} finally {
|
||||
file.delete();
|
||||
}
|
||||
}
|
||||
|
||||
public void testIoLinesxCanBeClosedEarly() throws Exception {
|
||||
File file = writeTempFile("linesx-close", "a\nb\n");
|
||||
try {
|
||||
Globals globals = JsePlatform.standardGlobals();
|
||||
Varargs result = globals.load(
|
||||
"local it = io.linesx(" + quote(file.getAbsolutePath()) + ")\n" +
|
||||
"local first = it()\n" +
|
||||
"it:close()\n" +
|
||||
"return first, it()\n",
|
||||
"linesx.lua").invoke();
|
||||
assertEquals(LuaValue.valueOf("a"), result.arg1());
|
||||
assertEquals(LuaValue.NIL, result.arg(2));
|
||||
} finally {
|
||||
file.delete();
|
||||
}
|
||||
}
|
||||
|
||||
public void testTableMove() {
|
||||
runFragment(
|
||||
LuaValue.varargsOf(new LuaValue[] {
|
||||
|
||||
Reference in New Issue
Block a user