aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorBenoit Giannangeli <benoit.giannangeli@boursorama.fr>2017-02-03 14:17:39 +0100
committerBenoit Giannangeli <benoit.giannangeli@boursorama.fr>2017-02-03 14:41:12 +0100
commit675b7642a9d624fa013416438ccca48ab6448ce6 (patch)
tree79797d22b6bddedaef9d5f5cff6b0bc25aec9268 /tests
parent29975e1ce839098e7e55b0cd25d788f0c96555ba (diff)
downloadfengari-675b7642a9d624fa013416438ccca48ab6448ce6.tar.gz
fengari-675b7642a9d624fa013416438ccca48ab6448ce6.tar.bz2
fengari-675b7642a9d624fa013416438ccca48ab6448ce6.zip
Binary/Unary operators
Diffstat (limited to 'tests')
-rw-r--r--tests/lvm.js53
1 files changed, 50 insertions, 3 deletions
diff --git a/tests/lvm.js b/tests/lvm.js
index ffd128d..d2c716a 100644
--- a/tests/lvm.js
+++ b/tests/lvm.js
@@ -73,18 +73,65 @@ test('MOV', function (t) {
return b
`, vm;
- t.plan(1);
+ 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[0].value,
"hello world",
"Program output is correct"
);
+});
+
+test('Binary op', function (t) {
+ let luaCode = `
+ local a = 5
+ local b = 10
+ return a + b, a - b, a * b, a / b, a % b, a^b, a // b, a & b, a | b, a ~ b, a << b, a >> b
+ `, vm;
+
+ t.plan(2);
+
+ t.comment("Running following code: \n" + luaCode);
+
+ t.doesNotThrow(function () {
+ vm = getVM(luaCode);
+ vm.execute();
+ }, "Program executed without errors");
+
+ t.deepEqual(
+ vm.L.stack.slice(0, 12).map(function (e) { return e.value; }),
+ [15, -5, 50, 0.5, 5, 9765625.0, 0, 0, 15, 15, 5120, 0],
+ "Program output is correct"
+ );
+});
+
+
+test('Unary op', function (t) {
+ let luaCode = `
+ local a = 5
+ local b = false
+ return -a, not b, ~a
+ `, vm;
+
+ t.plan(2);
+
+ t.comment("Running following code: \n" + luaCode);
+
+ t.doesNotThrow(function () {
+ vm = getVM(luaCode);
+ vm.execute();
+ }, "Program executed without errors");
+
+ t.deepEqual(
+ vm.L.stack.slice(0, 3).map(function (e) { return e.value; }),
+ [-5, true, -6],
+ "Program output is correct"
+ );
}); \ No newline at end of file