summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorBenoit Giannangeli <benoit.giannangeli@boursorama.fr>2017-02-08 15:31:44 +0100
committerBenoit Giannangeli <giann008@gmail.com>2017-02-10 08:53:03 +0100
commitad5cb0ddb6d4bd187cd4370711b1c9e34245fe07 (patch)
tree3e8bccded1cd4625661fe9b06f66e11202c1dec2 /tests
parentbd6367e8f3162ff76628fa42948e66ba9e6ae281 (diff)
downloadfengari-ad5cb0ddb6d4bd187cd4370711b1c9e34245fe07.tar.gz
fengari-ad5cb0ddb6d4bd187cd4370711b1c9e34245fe07.tar.bz2
fengari-ad5cb0ddb6d4bd187cd4370711b1c9e34245fe07.zip
Upvalues
Diffstat (limited to 'tests')
-rw-r--r--tests/lvm.js121
1 files changed, 92 insertions, 29 deletions
diff --git a/tests/lvm.js b/tests/lvm.js
index 199001f..df01167 100644
--- a/tests/lvm.js
+++ b/tests/lvm.js
@@ -491,6 +491,69 @@ test('FORPREP, FORLOOP (float)', function (t) {
return total
`, 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,
+ 60.5,
+ "Program output is correct"
+ );
+});
+
+
+test('SETTABLE, GETTABLE', function (t) {
+ let luaCode = `
+ local t = {}
+
+ t[1] = "hello"
+ t["two"] = "world"
+
+ return t
+ `, vm;
+
+ t.plan(3);
+
+ 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.array[1].value,
+ "hello",
+ "Program output is correct"
+ );
+
+ t.strictEqual(
+ vm.L.stack[vm.L.top - 1].value.hash.get("two").value,
+ "world",
+ "Program output is correct"
+ );
+});
+
+
+test('SETUPVAL, GETUPVAL', function (t) {
+ let luaCode = `
+ local up = "hello"
+
+ local f = function ()
+ upup = "yo"
+ up = "world"
+ return up;
+ end
+
+ return f()
+ `, vm;
+
t.plan(1);
t.comment("Running following code: \n" + luaCode);
@@ -502,40 +565,40 @@ test('FORPREP, FORLOOP (float)', function (t) {
t.strictEqual(
vm.L.stack[vm.L.top - 1].value,
- 60.5,
+ "world",
"Program output is correct"
);
});
-// test('SETTABLE, GETTABLE', function (t) {
-// let luaCode = `
-// local t = {}
+test('SETTABUP, GETTABUP', function (t) {
+ let luaCode = `
+ t = {}
-// t[1] = "hello"
-// t["two"] = "world"
+ t[1] = "hello"
+ t["two"] = "world"
-// return t[1], t["two"]
-// `, vm;
+ return t
+ `, vm;
-// t.plan(2);
-
-// t.comment("Running following code: \n" + luaCode);
-
-// t.doesNotThrow(function () {
-// vm = getVM(luaCode);
-// vm.execute();
-// }, "Program executed without errors");
-
-// t.stritEqual(
-// vm.L.stack[vm.L.top - 1].value.array[1],
-// "hello",
-// "Program output is correct"
-// );
-
-// t.stritEqual(
-// vm.L.stack[vm.L.top - 1].value.hash.get("two"),
-// "world",
-// "Program output is correct"
-// );
-// }); \ No newline at end of file
+ t.plan(3);
+
+ 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.array[1].value,
+ "hello",
+ "Program output is correct"
+ );
+
+ t.strictEqual(
+ vm.L.stack[vm.L.top - 1].value.hash.get("two").value,
+ "world",
+ "Program output is correct"
+ );
+}); \ No newline at end of file