Add grammer for lua 5.2 syntax and add unit test for LuaParser

This commit is contained in:
James Roseborough
2012-08-31 14:13:43 +00:00
parent 4dcb672b72
commit 79f31955a4
4 changed files with 409 additions and 3 deletions

View File

@@ -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);

View File

@@ -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;

View 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();
}
}
}