From 675b7642a9d624fa013416438ccca48ab6448ce6 Mon Sep 17 00:00:00 2001 From: Benoit Giannangeli Date: Fri, 3 Feb 2017 14:17:39 +0100 Subject: Binary/Unary operators --- tests/lvm.js | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 50 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/lvm.js b/tests/lvm.js index ffd128d..d2c716a 100644 --- a/tests/lvm.js +++ b/tests/lvm.js @@ -73,18 +73,65 @@ test('MOV', function (t) { return b `, vm; - t.plan(1); + t.plan(2); t.comment("Running following code: \n" + luaCode); - // t.doesNotThrow(function () { + t.doesNotThrow(function () { vm = getVM(luaCode); vm.execute(); - // }, "Program executed without errors"); + }, "Program executed without errors"); t.strictEqual( vm.L.stack[0].value, "hello world", "Program output is correct" ); +}); + +test('Binary op', function (t) { + let luaCode = ` + local a = 5 + local b = 10 + return a + b, a - b, a * b, a / b, a % b, a^b, a // b, a & b, a | b, a ~ b, a << b, a >> b + `, vm; + + t.plan(2); + + t.comment("Running following code: \n" + luaCode); + + t.doesNotThrow(function () { + vm = getVM(luaCode); + vm.execute(); + }, "Program executed without errors"); + + t.deepEqual( + vm.L.stack.slice(0, 12).map(function (e) { return e.value; }), + [15, -5, 50, 0.5, 5, 9765625.0, 0, 0, 15, 15, 5120, 0], + "Program output is correct" + ); +}); + + +test('Unary op', function (t) { + let luaCode = ` + local a = 5 + local b = false + return -a, not b, ~a + `, vm; + + t.plan(2); + + t.comment("Running following code: \n" + luaCode); + + t.doesNotThrow(function () { + vm = getVM(luaCode); + vm.execute(); + }, "Program executed without errors"); + + t.deepEqual( + vm.L.stack.slice(0, 3).map(function (e) { return e.value; }), + [-5, true, -6], + "Program output is correct" + ); }); \ No newline at end of file -- cgit v1.2.3-54-g00ecf