From 01d7a43f5ef8e7a74bad9b39916d553d61b29fc3 Mon Sep 17 00:00:00 2001 From: Benoit Giannangeli Date: Wed, 8 Feb 2017 10:29:20 +0100 Subject: TEST, TESTSET --- tests/lvm.js | 108 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 108 insertions(+) (limited to 'tests') diff --git a/tests/lvm.js b/tests/lvm.js index e2454eb..5f19455 100644 --- a/tests/lvm.js +++ b/tests/lvm.js @@ -342,4 +342,112 @@ test('EQ', function (t) { true, "Program output is correct" ); +}); + + +test('TESTSET (and)', function (t) { + let luaCode = ` + local a = true + local b = "hello" + + return a and 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.strictEqual( + vm.L.stack[vm.L.top - 1].value, + "hello", + "Program output is correct" + ); +}); + + +test('TESTSET (or)', function (t) { + let luaCode = ` + local a = false + local b = "hello" + + return a or 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.strictEqual( + vm.L.stack[vm.L.top - 1].value, + "hello", + "Program output is correct" + ); +}); + + +test('TEST (true)', function (t) { + let luaCode = ` + local a = true + local b = "hello" + + if a then + return b + end + + return "goodbye" + `, 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, + "hello", + "Program output is correct" + ); +}); + + +test('TEST (false)', function (t) { + let luaCode = ` + local a = false + local b = "hello" + + if a then + return b + end + + return "goodbye" + `, 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, + "goodbye", + "Program output is correct" + ); }); \ No newline at end of file -- cgit v1.2.3-54-g00ecf