From bd6367e8f3162ff76628fa42948e66ba9e6ae281 Mon Sep 17 00:00:00 2001 From: Benoit Giannangeli Date: Wed, 8 Feb 2017 14:22:54 +0100 Subject: FORPREP, FORLOOP --- tests/lvm.js | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 67 insertions(+), 12 deletions(-) (limited to 'tests/lvm.js') diff --git a/tests/lvm.js b/tests/lvm.js index 4c10521..199001f 100644 --- a/tests/lvm.js +++ b/tests/lvm.js @@ -453,14 +453,15 @@ test('TEST (false)', function (t) { }); -test('SETTABLE, GETTABLE', function (t) { +test('FORPREP, FORLOOP (int)', function (t) { let luaCode = ` - local t = {} + local total = 0 - t[1] = "hello" - t["two"] = "world" + for i = 0, 10 do + total = total + i + end - return t[1], t["two"] + return total `, vm; t.plan(2); @@ -472,15 +473,69 @@ test('SETTABLE, GETTABLE', function (t) { vm.execute(); }, "Program executed without errors"); - t.stritEqual( - vm.L.stack[vm.L.top - 1].value.array[1], - "hello", + t.strictEqual( + vm.L.stack[vm.L.top - 1].value, + 55, "Program output is correct" ); +}); + +test('FORPREP, FORLOOP (float)', function (t) { + let luaCode = ` + local total = 0 - t.stritEqual( - vm.L.stack[vm.L.top - 1].value.hash.get("two"), - "world", + for i = 0.5, 10.5 do + total = total + i + end + + return total + `, vm; + + t.plan(1); + + 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" ); -}); \ No newline at end of file +}); + + +// test('SETTABLE, GETTABLE', function (t) { +// let luaCode = ` +// local t = {} + +// t[1] = "hello" +// t["two"] = "world" + +// return t[1], t["two"] +// `, 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 -- cgit v1.2.3-70-g09d2