From 63be1b456e4ac32d5f4d32f3aad486e8b4007279 Mon Sep 17 00:00:00 2001 From: Benoit Giannangeli Date: Sun, 28 May 2017 15:19:41 +0200 Subject: ltests.js: listcode --- tests/test-suite/inprogress/code.js | 52 +++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) (limited to 'tests/test-suite/inprogress') 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"); +}); -- cgit v1.2.3-54-g00ecf