aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenoit Giannangeli <benoit.giannangeli@boursorama.fr>2017-02-14 08:39:42 +0100
committerBenoit Giannangeli <benoit.giannangeli@boursorama.fr>2017-02-14 08:39:42 +0100
commitf5536cd8aae574bd57f646e1e53e733f8b61a46a (patch)
tree5f827b9c58320a429b3545c748fa36804819d307
parent97cd23961c8a5b69c4845528a1a494f40127089f (diff)
downloadfengari-f5536cd8aae574bd57f646e1e53e733f8b61a46a.tar.gz
fengari-f5536cd8aae574bd57f646e1e53e733f8b61a46a.tar.bz2
fengari-f5536cd8aae574bd57f646e1e53e733f8b61a46a.zip
TM tests
-rw-r--r--tests/ltm.js44
1 files changed, 43 insertions, 1 deletions
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