aboutsummaryrefslogtreecommitdiff
path: root/tests/test-suite/inprogress
diff options
context:
space:
mode:
authorBenoit Giannangeli <giann008@gmail.com>2017-05-28 15:19:41 +0200
committerBenoit Giannangeli <giann008@gmail.com>2017-05-28 15:39:20 +0200
commit63be1b456e4ac32d5f4d32f3aad486e8b4007279 (patch)
treef225c8819f3deb1b3d3123ea26187a182c4425ac /tests/test-suite/inprogress
parent42404e2251ce2390b08ef920018a0029e914c69d (diff)
downloadfengari-63be1b456e4ac32d5f4d32f3aad486e8b4007279.tar.gz
fengari-63be1b456e4ac32d5f4d32f3aad486e8b4007279.tar.bz2
fengari-63be1b456e4ac32d5f4d32f3aad486e8b4007279.zip
ltests.js: listcode
Diffstat (limited to 'tests/test-suite/inprogress')
-rw-r--r--tests/test-suite/inprogress/code.js52
1 files changed, 52 insertions, 0 deletions
diff --git a/tests/test-suite/inprogress/code.js b/tests/test-suite/inprogress/code.js
index cc4b131..00ca53b 100644
--- a/tests/test-suite/inprogress/code.js
+++ b/tests/test-suite/inprogress/code.js
@@ -54,3 +54,55 @@ test("[test-suite] api: testing reuse in constant table", function (t) {
}, "Lua program ran without error");
});
+
+
+const prefix = `
+ function check (f, ...)
+ local arg = {...}
+ local c = T.listcode(f)
+ for i=1, #arg do
+ print(arg[i], c[i])
+ assert(string.find(c[i], '- '..arg[i]..' *%d'))
+ end
+ assert(c[#arg+2] == nil)
+ end
+
+
+ function checkequal (a, b)
+ a = T.listcode(a)
+ b = T.listcode(b)
+ for i = 1, #a do
+ a[i] = string.gsub(a[i], '%b()', '') -- remove line number
+ b[i] = string.gsub(b[i], '%b()', '') -- remove line number
+ assert(a[i] == b[i])
+ end
+ end
+`;
+
+test("[test-suite] api: some basic instructions", function (t) {
+ let luaCode = `
+ check(function ()
+ (function () end){f()}
+ end, 'CLOSURE', 'NEWTABLE', 'GETTABUP', 'CALL', 'SETLIST', 'CALL', 'RETURN')
+ `, L;
+
+ t.plan(2);
+
+ t.doesNotThrow(function () {
+
+ L = lauxlib.luaL_newstate();
+
+ lualib.luaL_openlibs(L);
+
+ ltests.luaopen_tests(L);
+
+ lauxlib.luaL_loadstring(L, lua.to_luastring(prefix + luaCode));
+
+ }, "Lua program loaded without error");
+
+ t.doesNotThrow(function () {
+
+ lua.lua_call(L, 0, -1);
+
+ }, "Lua program ran without error");
+});