From f5536cd8aae574bd57f646e1e53e733f8b61a46a Mon Sep 17 00:00:00 2001 From: Benoit Giannangeli Date: Tue, 14 Feb 2017 08:39:42 +0100 Subject: TM tests --- tests/ltm.js | 44 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/tests/ltm.js b/tests/ltm.js index 290ef9c..cb0e38d 100644 --- a/tests/ltm.js +++ b/tests/ltm.js @@ -9,7 +9,7 @@ const VM = require("../src/lvm.js"); const getState = require("./tests.js").getState; -test('__index', function (t) { +test('__index, __newindex: with actual table', function (t) { let luaCode = ` local t = {yo=1} return t.yo, t.lo @@ -35,4 +35,46 @@ test('__index', function (t) { 1, "Program output is correct" ); +}); + + +test('__index: with non table', function (t) { + let luaCode = ` + local t = "a string" + return t.yo + `, L; + + t.plan(2); + + t.comment("Running following code: \n" + luaCode); + + t.doesNotThrow(function () { + L = getState(luaCode); + }, "Bytecode parsed without errors"); + + t.throws(function () { + VM.luaV_execute(L); + }, "Program executed with expected error"); + +}); + + +test('__newindex: with non table', function (t) { + let luaCode = ` + local t = "a string" + t.yo = "hello" + `, L; + + t.plan(2); + + t.comment("Running following code: \n" + luaCode); + + t.doesNotThrow(function () { + L = getState(luaCode); + }, "Bytecode parsed without errors"); + + t.throws(function () { + VM.luaV_execute(L); + }, "Program executed with expected error"); + }); \ No newline at end of file -- cgit v1.2.3-70-g09d2