From ad5cb0ddb6d4bd187cd4370711b1c9e34245fe07 Mon Sep 17 00:00:00 2001 From: Benoit Giannangeli Date: Wed, 8 Feb 2017 15:31:44 +0100 Subject: Upvalues --- tests/lvm.js | 121 +++++++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 92 insertions(+), 29 deletions(-) (limited to 'tests') diff --git a/tests/lvm.js b/tests/lvm.js index 199001f..df01167 100644 --- a/tests/lvm.js +++ b/tests/lvm.js @@ -491,6 +491,69 @@ test('FORPREP, FORLOOP (float)', function (t) { return total `, vm; + t.plan(2); + + t.comment("Running following code: \n" + luaCode); + + t.doesNotThrow(function () { + vm = getVM(luaCode); + vm.execute(); + }, "Program executed without errors"); + + t.strictEqual( + vm.L.stack[vm.L.top - 1].value, + 60.5, + "Program output is correct" + ); +}); + + +test('SETTABLE, GETTABLE', function (t) { + let luaCode = ` + local t = {} + + t[1] = "hello" + t["two"] = "world" + + return t + `, vm; + + t.plan(3); + + t.comment("Running following code: \n" + luaCode); + + t.doesNotThrow(function () { + vm = getVM(luaCode); + vm.execute(); + }, "Program executed without errors"); + + t.strictEqual( + vm.L.stack[vm.L.top - 1].value.array[1].value, + "hello", + "Program output is correct" + ); + + t.strictEqual( + vm.L.stack[vm.L.top - 1].value.hash.get("two").value, + "world", + "Program output is correct" + ); +}); + + +test('SETUPVAL, GETUPVAL', function (t) { + let luaCode = ` + local up = "hello" + + local f = function () + upup = "yo" + up = "world" + return up; + end + + return f() + `, vm; + t.plan(1); t.comment("Running following code: \n" + luaCode); @@ -502,40 +565,40 @@ test('FORPREP, FORLOOP (float)', function (t) { t.strictEqual( vm.L.stack[vm.L.top - 1].value, - 60.5, + "world", "Program output is correct" ); }); -// test('SETTABLE, GETTABLE', function (t) { -// let luaCode = ` -// local t = {} +test('SETTABUP, GETTABUP', function (t) { + let luaCode = ` + t = {} -// t[1] = "hello" -// t["two"] = "world" + t[1] = "hello" + t["two"] = "world" -// return t[1], t["two"] -// `, vm; + return t + `, vm; -// t.plan(2); - -// t.comment("Running following code: \n" + luaCode); - -// t.doesNotThrow(function () { -// vm = getVM(luaCode); -// vm.execute(); -// }, "Program executed without errors"); - -// t.stritEqual( -// vm.L.stack[vm.L.top - 1].value.array[1], -// "hello", -// "Program output is correct" -// ); - -// t.stritEqual( -// vm.L.stack[vm.L.top - 1].value.hash.get("two"), -// "world", -// "Program output is correct" -// ); -// }); \ No newline at end of file + t.plan(3); + + t.comment("Running following code: \n" + luaCode); + + t.doesNotThrow(function () { + vm = getVM(luaCode); + vm.execute(); + }, "Program executed without errors"); + + t.strictEqual( + vm.L.stack[vm.L.top - 1].value.array[1].value, + "hello", + "Program output is correct" + ); + + t.strictEqual( + vm.L.stack[vm.L.top - 1].value.hash.get("two").value, + "world", + "Program output is correct" + ); +}); \ No newline at end of file -- cgit v1.2.3-70-g09d2