summaryrefslogtreecommitdiff
path: root/tests/lvm.js
diff options
context:
space:
mode:
Diffstat (limited to 'tests/lvm.js')
-rw-r--r--tests/lvm.js108
1 files changed, 108 insertions, 0 deletions
diff --git a/tests/lvm.js b/tests/lvm.js
index e2454eb..5f19455 100644
--- a/tests/lvm.js
+++ b/tests/lvm.js
@@ -342,4 +342,112 @@ test('EQ', function (t) {
true,
"Program output is correct"
);
+});
+
+
+test('TESTSET (and)', function (t) {
+ let luaCode = `
+ local a = true
+ local b = "hello"
+
+ return a and 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.strictEqual(
+ vm.L.stack[vm.L.top - 1].value,
+ "hello",
+ "Program output is correct"
+ );
+});
+
+
+test('TESTSET (or)', function (t) {
+ let luaCode = `
+ local a = false
+ local b = "hello"
+
+ return a or 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.strictEqual(
+ vm.L.stack[vm.L.top - 1].value,
+ "hello",
+ "Program output is correct"
+ );
+});
+
+
+test('TEST (true)', function (t) {
+ let luaCode = `
+ local a = true
+ local b = "hello"
+
+ if a then
+ return b
+ end
+
+ return "goodbye"
+ `, 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,
+ "hello",
+ "Program output is correct"
+ );
+});
+
+
+test('TEST (false)', function (t) {
+ let luaCode = `
+ local a = false
+ local b = "hello"
+
+ if a then
+ return b
+ end
+
+ return "goodbye"
+ `, 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,
+ "goodbye",
+ "Program output is correct"
+ );
}); \ No newline at end of file