diff options
author | Benoit Giannangeli <benoit.giannangeli@boursorama.fr> | 2017-02-03 14:17:39 +0100 |
---|---|---|
committer | Benoit Giannangeli <benoit.giannangeli@boursorama.fr> | 2017-02-03 14:41:12 +0100 |
commit | 675b7642a9d624fa013416438ccca48ab6448ce6 (patch) | |
tree | 79797d22b6bddedaef9d5f5cff6b0bc25aec9268 /tests/lvm.js | |
parent | 29975e1ce839098e7e55b0cd25d788f0c96555ba (diff) | |
download | fengari-675b7642a9d624fa013416438ccca48ab6448ce6.tar.gz fengari-675b7642a9d624fa013416438ccca48ab6448ce6.tar.bz2 fengari-675b7642a9d624fa013416438ccca48ab6448ce6.zip |
Binary/Unary operators
Diffstat (limited to 'tests/lvm.js')
-rw-r--r-- | tests/lvm.js | 53 |
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 |