aboutsummaryrefslogtreecommitdiff
path: root/tests/lvm.js
diff options
context:
space:
mode:
authorBenoit Giannangeli <benoit.giannangeli@boursorama.fr>2017-02-08 14:22:54 +0100
committerBenoit Giannangeli <benoit.giannangeli@boursorama.fr>2017-02-08 15:12:34 +0100
commitbd6367e8f3162ff76628fa42948e66ba9e6ae281 (patch)
tree70c2d91779de9fd522bea781ff6af79d73159d98 /tests/lvm.js
parent7d63489f2615609e21befc9d21a0e9f8fe2bf61a (diff)
downloadfengari-bd6367e8f3162ff76628fa42948e66ba9e6ae281.tar.gz
fengari-bd6367e8f3162ff76628fa42948e66ba9e6ae281.tar.bz2
fengari-bd6367e8f3162ff76628fa42948e66ba9e6ae281.zip
FORPREP, FORLOOP
Diffstat (limited to 'tests/lvm.js')
-rw-r--r--tests/lvm.js79
1 files changed, 67 insertions, 12 deletions
diff --git a/tests/lvm.js b/tests/lvm.js
index 4c10521..199001f 100644
--- a/tests/lvm.js
+++ b/tests/lvm.js
@@ -453,14 +453,15 @@ test('TEST (false)', function (t) {
});
-test('SETTABLE, GETTABLE', function (t) {
+test('FORPREP, FORLOOP (int)', function (t) {
let luaCode = `
- local t = {}
+ local total = 0
- t[1] = "hello"
- t["two"] = "world"
+ for i = 0, 10 do
+ total = total + i
+ end
- return t[1], t["two"]
+ return total
`, vm;
t.plan(2);
@@ -472,15 +473,69 @@ test('SETTABLE, GETTABLE', function (t) {
vm.execute();
}, "Program executed without errors");
- t.stritEqual(
- vm.L.stack[vm.L.top - 1].value.array[1],
- "hello",
+ t.strictEqual(
+ vm.L.stack[vm.L.top - 1].value,
+ 55,
"Program output is correct"
);
+});
+
+test('FORPREP, FORLOOP (float)', function (t) {
+ let luaCode = `
+ local total = 0
- t.stritEqual(
- vm.L.stack[vm.L.top - 1].value.hash.get("two"),
- "world",
+ for i = 0.5, 10.5 do
+ total = total + i
+ end
+
+ return total
+ `, vm;
+
+ t.plan(1);
+
+ 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"
);
-}); \ No newline at end of file
+});
+
+
+// test('SETTABLE, GETTABLE', function (t) {
+// let luaCode = `
+// local t = {}
+
+// t[1] = "hello"
+// t["two"] = "world"
+
+// return t[1], t["two"]
+// `, 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