From 86a09b63a6a316ee0855ce1d5307ea89f0b6f1ec Mon Sep 17 00:00:00 2001 From: Benoit Giannangeli Date: Sun, 5 Feb 2017 09:12:54 +0100 Subject: Fixed bad use of L.top --- tests/lvm.js | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) (limited to 'tests') diff --git a/tests/lvm.js b/tests/lvm.js index 1b4d8c3..54c40ae 100644 --- a/tests/lvm.js +++ b/tests/lvm.js @@ -1,3 +1,4 @@ +/*jshint esversion: 6 */ "use strict"; const test = require('tape'); @@ -60,7 +61,7 @@ test('LOADK, RETURN', function (t) { }, "Program executed without errors"); t.strictEqual( - vm.L.stack[0].value, + vm.L.stack[vm.L.top - 1].value, "hello world", "Program output is correct" ); @@ -84,7 +85,7 @@ test('MOV', function (t) { }, "Program executed without errors"); t.strictEqual( - vm.L.stack[0].value, + vm.L.stack[vm.L.top - 1].value, "hello world", "Program output is correct" ); @@ -107,7 +108,7 @@ test('Binary op', function (t) { }, "Program executed without errors"); t.deepEqual( - vm.L.stack.slice(0, 12).map(function (e) { return e.value; }), + vm.L.stack.slice(vm.L.top - 12 - 1, vm.L.top - 1).map(function (e) { return e.value; }), [15, -5, 50, 0.5, 5, 9765625.0, 0, 0, 15, 15, 5120, 0], "Program output is correct" ); @@ -131,7 +132,7 @@ test('Unary op, LOADBOOL', function (t) { }, "Program executed without errors"); t.deepEqual( - vm.L.stack.slice(0, 3).map(function (e) { return e.value; }), + vm.L.stack.slice(vm.L.top - 3 - 1, vm.L.top - 1).map(function (e) { return e.value; }), [-5, true, -6], "Program output is correct" ); @@ -154,7 +155,7 @@ test('NEWTABLE', function (t) { }, "Program executed without errors"); t.ok( - vm.L.stack[0] instanceof Table, + vm.L.stack[vm.L.top - 1] instanceof Table, "Program output is correct" ); }); @@ -171,12 +172,18 @@ test('CALL', function (t) { return c `, vm; - t.plan(0); + 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[vm.L.top - 1].value, + 3, + "Program output is correct" + ); }); \ No newline at end of file -- cgit v1.2.3-70-g09d2