Add grammer for lua 5.2 syntax and add unit test for LuaParser
This commit is contained in:
@@ -29,6 +29,7 @@ import org.luaj.vm2.WeakTableTest.WeakKeyValueTableTest;
|
||||
import org.luaj.vm2.WeakTableTest.WeakValueTableTest;
|
||||
import org.luaj.vm2.compiler.CompilerUnitTests;
|
||||
import org.luaj.vm2.compiler.DumpLoadEndianIntTest;
|
||||
import org.luaj.vm2.compiler.LuaParserTests;
|
||||
import org.luaj.vm2.compiler.RegressionTests;
|
||||
import org.luaj.vm2.compiler.SimpleTests;
|
||||
import org.luaj.vm2.lib.jse.LuaJavaCoercionTest;
|
||||
@@ -69,6 +70,7 @@ public class AllTests {
|
||||
TestSuite compiler = new TestSuite("Lua Compiler Tests");
|
||||
compiler.addTestSuite(CompilerUnitTests.class);
|
||||
compiler.addTestSuite(DumpLoadEndianIntTest.class);
|
||||
compiler.addTestSuite(LuaParserTests.class);
|
||||
compiler.addTestSuite(RegressionTests.class);
|
||||
compiler.addTestSuite(SimpleTests.class);
|
||||
suite.addTest(compiler);
|
||||
|
||||
@@ -46,10 +46,23 @@ abstract public class AbstractUnitTests extends TestCase {
|
||||
_G = JsePlatform.standardGlobals();
|
||||
}
|
||||
|
||||
protected String pathOfFile(String file) {
|
||||
return jar + dir + "/" + file;
|
||||
}
|
||||
|
||||
protected InputStream inputStreamOfPath(String path) throws IOException {
|
||||
URL url = new URL(path);
|
||||
return url.openStream();
|
||||
}
|
||||
|
||||
protected InputStream inputStreamOfFile(String file) throws IOException {
|
||||
return inputStreamOfPath(pathOfFile(file));
|
||||
}
|
||||
|
||||
protected void doTest(String file) {
|
||||
try {
|
||||
// load source from jar
|
||||
String path = jar + dir + "/" + file;
|
||||
String path = pathOfFile(file);
|
||||
byte[] lua = bytesFromJar(path);
|
||||
|
||||
// compile in memory
|
||||
@@ -83,8 +96,7 @@ abstract public class AbstractUnitTests extends TestCase {
|
||||
}
|
||||
|
||||
protected byte[] bytesFromJar(String path) throws IOException {
|
||||
URL url = new URL(path);
|
||||
InputStream is = url.openStream();
|
||||
InputStream is = inputStreamOfPath(path);
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
byte[] buffer = new byte[2048];
|
||||
int n;
|
||||
|
||||
28
test/junit/org/luaj/vm2/compiler/LuaParserTests.java
Normal file
28
test/junit/org/luaj/vm2/compiler/LuaParserTests.java
Normal file
@@ -0,0 +1,28 @@
|
||||
package org.luaj.vm2.compiler;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.Reader;
|
||||
|
||||
import org.luaj.vm2.LuaValue;
|
||||
import org.luaj.vm2.parser.LuaParser;
|
||||
|
||||
public class LuaParserTests extends CompilerUnitTests {
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
LuaValue.valueOf(true);
|
||||
}
|
||||
|
||||
protected void doTest(String file) {
|
||||
try {
|
||||
InputStream is = inputStreamOfFile(file);
|
||||
Reader r = new InputStreamReader(is, "ISO-8859-1");
|
||||
LuaParser parser = new LuaParser(r);
|
||||
parser.Chunk();
|
||||
} catch (Exception e) {
|
||||
fail(e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user