2018-03-16 15:30:54 +00:00
|
|
|
'use strict';
|
|
|
|
|
2018-06-16 22:49:48 +00:00
|
|
|
const Mscript = require('../lib/mscript');
|
|
|
|
const mscript = new Mscript();
|
2018-03-16 15:30:54 +00:00
|
|
|
|
|
|
|
QUnit.test(`Basic functions`, (assert) => {
|
2018-03-16 16:22:34 +00:00
|
|
|
const script1 = 'CF\nPF\nCB\nPB\nBF\nBB';
|
|
|
|
const script2 = `CF 3\nPF 3`
|
|
|
|
assert.expect( 2 );
|
|
|
|
|
|
|
|
mscript.interpret(script1, (obj) => {
|
|
|
|
let pass = false;
|
2018-03-16 15:30:54 +00:00
|
|
|
if (obj.success === true
|
|
|
|
&& obj.cam === 0
|
|
|
|
&& obj.proj === 0
|
|
|
|
&& obj.arr.length === 6) {
|
|
|
|
pass = true;
|
|
|
|
}
|
2018-03-16 16:22:34 +00:00
|
|
|
assert.ok(pass, `Simple script1 compiles`)
|
2018-03-16 15:30:54 +00:00
|
|
|
});
|
2018-03-16 16:22:34 +00:00
|
|
|
mscript.interpret(script2, (obj) => {
|
|
|
|
let pass = false;
|
2018-03-16 15:30:54 +00:00
|
|
|
if (obj.success === true
|
2018-03-16 16:22:34 +00:00
|
|
|
&& obj.cam === 3
|
|
|
|
&& obj.proj === 3
|
2018-03-16 15:30:54 +00:00
|
|
|
&& obj.arr.length === 6) {
|
2018-03-16 16:22:34 +00:00
|
|
|
pass = true;
|
2018-03-16 15:30:54 +00:00
|
|
|
}
|
2018-03-16 16:22:34 +00:00
|
|
|
assert.ok(pass, `Simple script2 compiles`)
|
2018-03-16 15:30:54 +00:00
|
|
|
});
|
2018-03-16 16:22:34 +00:00
|
|
|
});
|
2018-03-16 15:30:54 +00:00
|
|
|
|
2018-03-16 16:22:34 +00:00
|
|
|
QUnit.test(`Commands with integers`, (assert) => {
|
|
|
|
const script = 'CF 5\nPF 5\nCB 5\nPB 5\nBF 3\nBB 3';
|
|
|
|
assert.expect( 1 );
|
|
|
|
mscript.interpret(script, (obj) => {
|
|
|
|
let pass = false;
|
2018-03-16 15:30:54 +00:00
|
|
|
if (obj.success === true
|
|
|
|
&& obj.cam === 0
|
|
|
|
&& obj.proj === 0
|
2018-03-16 16:22:34 +00:00
|
|
|
&& obj.arr.length === 26) {
|
|
|
|
pass = true;
|
2018-03-16 15:30:54 +00:00
|
|
|
}
|
2018-03-16 16:22:34 +00:00
|
|
|
assert.ok(pass, `Script with integers cancels out count, but generates list of commands`)
|
2018-03-16 15:30:54 +00:00
|
|
|
});
|
2018-03-16 16:22:34 +00:00
|
|
|
})
|
2018-03-16 15:30:54 +00:00
|
|
|
|
2018-03-16 16:22:34 +00:00
|
|
|
|
|
|
|
QUnit.test('State', (assert) => {
|
|
|
|
const script = 'CF 1000\nCB 1000\nSET PROJ 200\nPB 200';
|
|
|
|
assert.expect(1);
|
|
|
|
mscript.interpret(script, (obj) => {
|
|
|
|
let pass = false;
|
2018-03-16 15:30:54 +00:00
|
|
|
if (obj.success === true
|
|
|
|
&& obj.cam === 0
|
|
|
|
&& obj.proj === 0) {
|
2018-03-16 16:22:34 +00:00
|
|
|
pass = true;
|
2018-03-16 15:30:54 +00:00
|
|
|
}
|
2018-03-16 16:22:34 +00:00
|
|
|
assert.ok(pass, `Basic state test`);
|
2018-03-16 15:30:54 +00:00
|
|
|
});
|
2018-03-16 16:22:34 +00:00
|
|
|
});
|
2018-03-16 15:30:54 +00:00
|
|
|
|
2018-03-16 16:22:34 +00:00
|
|
|
QUnit.test('Loop', (assert) => {
|
|
|
|
const script1 = 'LOOP 10\nCF 3\nPF 1\nEND LOOP';
|
|
|
|
assert.expect(3);
|
|
|
|
mscript.interpret(script1, (obj) => {
|
|
|
|
let pass = false;
|
2018-03-16 15:30:54 +00:00
|
|
|
if (obj.success === true
|
|
|
|
&& obj.cam === 30
|
|
|
|
&& obj.proj === 10
|
|
|
|
&& obj.arr.length === 40) {
|
2018-03-16 16:22:34 +00:00
|
|
|
pass = true;
|
2018-03-16 15:30:54 +00:00
|
|
|
}
|
2018-03-16 16:22:34 +00:00
|
|
|
assert.ok(pass, 'Basic loop');
|
2018-03-16 15:30:54 +00:00
|
|
|
|
2018-03-16 16:22:34 +00:00
|
|
|
});
|
|
|
|
const script2 = 'LOOP 4\nLOOP 4\nPF\nBF\nEND LOOP\nEND LOOP';
|
|
|
|
mscript.interpret(script2, (obj) => {
|
|
|
|
let pass = false;
|
2018-03-16 15:30:54 +00:00
|
|
|
if (obj.success === true
|
|
|
|
&& obj.cam === 16
|
|
|
|
&& obj.proj === 16
|
|
|
|
&& obj.arr.length === 32) {
|
2018-03-16 16:22:34 +00:00
|
|
|
pass = true;
|
|
|
|
}
|
|
|
|
assert.ok(pass, 'Recursive loop');
|
|
|
|
});
|
|
|
|
//LOOP W/ CAM and PROJ
|
|
|
|
const script3 = 'LOOP 2\nCAM 4\nPROJ 4\nEND';
|
|
|
|
mscript.interpret(script3, (obj) => {
|
|
|
|
let pass = false;
|
|
|
|
if (obj.success === true
|
|
|
|
&& obj.cam === 8
|
|
|
|
&& obj.proj === 8
|
|
|
|
&& obj.arr.length === 16
|
|
|
|
&& obj.light.length === 16
|
2018-06-16 22:49:48 +00:00
|
|
|
&& obj.light[0] === '0,0,0') {
|
2018-03-16 16:22:34 +00:00
|
|
|
pass = true;
|
2018-03-16 15:30:54 +00:00
|
|
|
}
|
2018-03-16 16:22:34 +00:00
|
|
|
assert.ok(pass, 'Basic cam/proj loop');
|
2018-03-16 15:30:54 +00:00
|
|
|
});
|
2018-03-16 16:22:34 +00:00
|
|
|
});
|
2018-03-16 15:30:54 +00:00
|
|
|
|
2018-03-16 16:22:34 +00:00
|
|
|
QUnit.test('Light', (assert) => {
|
2018-03-16 15:30:54 +00:00
|
|
|
//Lighting tests
|
2018-03-16 16:22:34 +00:00
|
|
|
const script1 = 'L 255,255,255\nCF\nPF';
|
|
|
|
assert.expect(3);
|
|
|
|
mscript.interpret(script1, (obj) => {
|
|
|
|
let pass = false;
|
2018-03-16 15:30:54 +00:00
|
|
|
if (obj.success === true
|
|
|
|
&& obj.cam === 1
|
|
|
|
&& obj.proj === 1
|
|
|
|
&& obj.arr.length === 2
|
|
|
|
&& obj.light.length === 2
|
|
|
|
&& obj.light[0] === '255,255,255'
|
|
|
|
&& obj.light[1] === '') {
|
2018-03-16 16:22:34 +00:00
|
|
|
pass = true;
|
2018-03-16 15:30:54 +00:00
|
|
|
}
|
2018-03-16 16:22:34 +00:00
|
|
|
assert.ok(pass, 'Basic light');
|
2018-03-16 15:30:54 +00:00
|
|
|
});
|
2018-03-16 16:22:34 +00:00
|
|
|
|
|
|
|
const script2 = 'L 255,255,255\nCF\nPF\nBF';
|
|
|
|
mscript.interpret(script2, (obj) => {
|
|
|
|
let pass = false;
|
2018-03-16 15:30:54 +00:00
|
|
|
if (obj.success === true
|
|
|
|
&& obj.cam === 2
|
|
|
|
&& obj.proj === 1
|
|
|
|
&& obj.arr.length === 3
|
|
|
|
&& obj.light.length === 3
|
|
|
|
&& obj.light[0] === '255,255,255'
|
|
|
|
&& obj.light[1] === ''
|
2018-06-16 22:49:48 +00:00
|
|
|
&& obj.light[2] === '0,0,0') {
|
2018-03-16 16:22:34 +00:00
|
|
|
pass = true;
|
2018-03-16 15:30:54 +00:00
|
|
|
}
|
2018-03-16 16:22:34 +00:00
|
|
|
assert.ok(pass, 'Basic black');
|
2018-03-16 15:30:54 +00:00
|
|
|
});
|
2018-03-16 16:22:34 +00:00
|
|
|
const script3 = 'LOOP 2\nL 1,1,1\nCF\nL 2,2,2\nCF\nEND';
|
|
|
|
mscript.interpret(script3, (obj) => {
|
|
|
|
let pass = false;
|
2018-03-16 15:30:54 +00:00
|
|
|
if (obj.success === true
|
|
|
|
&& obj.cam === 4
|
|
|
|
&& obj.proj === 0
|
|
|
|
&& obj.arr.length === 4
|
|
|
|
&& obj.light.length === 4
|
|
|
|
&& obj.light[0] === '1,1,1'
|
|
|
|
&& obj.light[3] === '2,2,2') {
|
2018-03-16 16:22:34 +00:00
|
|
|
pass = true;
|
2018-03-16 15:30:54 +00:00
|
|
|
}
|
2018-03-16 16:22:34 +00:00
|
|
|
assert.ok(pass, 'Basic light');
|
2018-03-16 15:30:54 +00:00
|
|
|
});
|
2018-03-16 16:22:34 +00:00
|
|
|
});
|