2019-05-28 13:02:55 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const Mscript = require('../lib/mscript');
|
|
|
|
const mscript = new Mscript();
|
|
|
|
|
|
|
|
const assert = require('assert')
|
|
|
|
|
2019-05-28 21:40:59 +00:00
|
|
|
describe(`mscript module`, () => {
|
2019-05-28 13:02:55 +00:00
|
|
|
const script1 = 'CF\nPF\nCB\nPB\nBF\nBB';
|
|
|
|
const script2 = `CF 3\nPF 3`
|
|
|
|
const script3 = `CF\nPF`
|
|
|
|
|
2019-05-28 21:40:59 +00:00
|
|
|
it ('Should compile very short scripts as strings', () => {
|
2019-05-29 02:40:50 +00:00
|
|
|
const obj = mscript.interpret(script1)
|
2019-05-28 21:40:59 +00:00
|
|
|
assert.ok(obj.success, `Simple script1 compiles`);
|
2019-05-28 13:02:55 +00:00
|
|
|
assert.equal(obj.cam, 0, 'Camera gets equaled out');
|
|
|
|
assert.equal(obj.proj, 0, 'Projector gets cancelled out');
|
|
|
|
assert.equal(obj.arr.length, 6, 'Generate sequence of 6 steps');
|
|
|
|
});
|
|
|
|
|
2019-05-28 21:40:59 +00:00
|
|
|
it ('Should compile script with count values after command', () => {
|
2019-05-29 02:40:50 +00:00
|
|
|
const obj = mscript.interpret(script2)
|
2019-05-28 21:40:59 +00:00
|
|
|
assert.ok(obj.success, `Simple script2 compiles`);
|
|
|
|
assert.equal(obj.arr[0], 'CF', `First step is a camera_forward command`);
|
|
|
|
assert.equal(obj.cam, 3, `Camera finished on frame 3`);
|
|
|
|
assert.equal(obj.proj, 3, `Projector finished on frame 3`);
|
|
|
|
assert.equal(obj.arr.length, 6, `Generate sequence of 6 steps`);
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
it ('Should compile with implied counts of 1', () => {
|
2019-05-29 02:40:50 +00:00
|
|
|
const obj = mscript.interpret(script3);
|
2019-05-28 21:40:59 +00:00
|
|
|
assert.ok(obj.success, 'Simple script3 with implied counts compiles');
|
|
|
|
//console.log(obj);
|
2019-05-28 13:02:55 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2019-05-28 21:40:59 +00:00
|
|
|
describe(`mscript - Commands with integers`, () => {
|
|
|
|
const script = `
|
|
|
|
CF 5
|
|
|
|
PF 5
|
|
|
|
CB 5
|
|
|
|
PB 5
|
|
|
|
BF 3
|
|
|
|
BB 3`;
|
2019-05-28 13:02:55 +00:00
|
|
|
|
2019-05-28 21:40:59 +00:00
|
|
|
it ('Should compile script with integers as count values', () => {
|
2019-05-29 02:40:50 +00:00
|
|
|
const obj = mscript.interpret(script)
|
|
|
|
assert.ok(obj.success, `Script with integers cancels out count, but generates list of commands`)
|
|
|
|
assert.equal(obj.cam , 0, 'Steps cancel each other out on cam');
|
|
|
|
assert.equal(obj.proj, 0, 'Steps cancel each other out on proj');
|
|
|
|
assert.equal(obj.arr.length, 26, 'Total of 26 steps in sequence');
|
2019-05-28 13:02:55 +00:00
|
|
|
});
|
2019-05-28 21:40:59 +00:00
|
|
|
});
|
2019-05-28 13:02:55 +00:00
|
|
|
|
2019-05-29 02:40:50 +00:00
|
|
|
describe(`mscript - Device commands`, () => {
|
|
|
|
const script1 = `
|
2019-05-28 21:40:59 +00:00
|
|
|
CAM 50
|
|
|
|
PROJ 50`;
|
2019-05-28 13:02:55 +00:00
|
|
|
|
2019-05-28 21:40:59 +00:00
|
|
|
it ('Should compile script with device commands', () => {
|
2019-05-29 02:40:50 +00:00
|
|
|
const obj = mscript.interpret(script1);
|
|
|
|
assert.ok(obj.success, `Script generates 100 step sequence with 50 steps on each device`);
|
|
|
|
assert.equal(obj.cam, 50, `Camera gets to 50`);
|
|
|
|
assert.equal(obj.arr[0], 'BF', 'First step is black_forward');
|
|
|
|
assert.equal(obj.proj, 50, `Projector gets to 50`);
|
|
|
|
assert.equal(obj.arr[50], 'PF', '51st step is projector_forward');
|
|
|
|
assert.equal(obj.arr.length, 100, `Array is 100 steps long`);
|
|
|
|
});
|
|
|
|
|
|
|
|
const script2 = `
|
|
|
|
SET CAM 0
|
|
|
|
SET PROJ 50
|
|
|
|
|
|
|
|
CAM 50
|
|
|
|
PROJ 0`
|
|
|
|
|
|
|
|
it ('Should generate steps in correct direction', () => {
|
|
|
|
const obj = mscript.interpret(script2);
|
|
|
|
assert.ok(obj.success, `Script generates 100 step sequence with 50 steps on each device`);
|
|
|
|
assert.equal(obj.cam, 50, `Camera gets to 50`);
|
|
|
|
assert.equal(obj.arr[0], 'BF', 'First step is black_forward');
|
|
|
|
assert.equal(obj.proj, 0, `Projector gets to 0`);
|
|
|
|
assert.equal(obj.arr[50], 'PB', '51st step is projector_backward');
|
|
|
|
assert.equal(obj.arr.length, 100, `Array is 100 steps long`);
|
2019-05-28 13:02:55 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-05-28 21:40:59 +00:00
|
|
|
describe('mscript - State', () => {
|
|
|
|
const script = `
|
|
|
|
CF 1000
|
|
|
|
CB 1000
|
|
|
|
SET PROJ 200
|
|
|
|
PB 200`;
|
2019-05-28 13:02:55 +00:00
|
|
|
|
2019-05-28 21:40:59 +00:00
|
|
|
it ('Should manage state using SET commands', () => {
|
2019-05-29 02:40:50 +00:00
|
|
|
const obj = mscript.interpret(script)
|
|
|
|
let pass = false;
|
|
|
|
if (obj.success === true
|
|
|
|
&& obj.cam === 0
|
|
|
|
&& obj.proj === 0) {
|
|
|
|
pass = true;
|
|
|
|
}
|
|
|
|
assert.ok(pass, `Basic state test`);
|
2019-05-28 21:40:59 +00:00
|
|
|
});
|
|
|
|
});
|
2019-05-28 13:02:55 +00:00
|
|
|
|
2019-05-28 21:40:59 +00:00
|
|
|
describe('mscript - Loop', () => {
|
|
|
|
const script1 = `
|
|
|
|
LOOP 10
|
|
|
|
CF 3
|
|
|
|
PF 1
|
|
|
|
END LOOP`;
|
|
|
|
|
|
|
|
it ('Should generate a looped sequence between LOOP and END LOOP statements', () => {
|
2019-05-29 02:40:50 +00:00
|
|
|
const obj = mscript.interpret(script1)
|
|
|
|
let pass = false;
|
|
|
|
if (obj.success === true
|
|
|
|
&& obj.cam === 30
|
|
|
|
&& obj.proj === 10
|
|
|
|
&& obj.arr.length === 40) {
|
|
|
|
pass = true;
|
|
|
|
}
|
|
|
|
assert.ok(pass, 'Basic loop');
|
2019-05-28 13:02:55 +00:00
|
|
|
});
|
2019-05-28 21:40:59 +00:00
|
|
|
|
|
|
|
const script2 = `
|
|
|
|
LOOP 4
|
|
|
|
LOOP 4
|
|
|
|
PF
|
|
|
|
BF
|
|
|
|
END LOOP
|
|
|
|
END LOOP`;
|
|
|
|
|
|
|
|
it ('Should generate a sequence with nested loops', () => {
|
2019-05-29 02:40:50 +00:00
|
|
|
const obj = mscript.interpret(script2)
|
|
|
|
let pass = false;
|
|
|
|
if (obj.success === true
|
|
|
|
&& obj.cam === 16
|
|
|
|
&& obj.proj === 16
|
|
|
|
&& obj.arr.length === 32) {
|
|
|
|
pass = true;
|
|
|
|
}
|
|
|
|
assert.ok(pass, 'Nested loop works');
|
2019-05-28 13:02:55 +00:00
|
|
|
});
|
2019-05-28 21:40:59 +00:00
|
|
|
|
2019-05-28 13:02:55 +00:00
|
|
|
//LOOP W/ CAM and PROJ
|
2019-05-28 21:40:59 +00:00
|
|
|
const script3 = `
|
|
|
|
LOOP 2
|
|
|
|
CAM 4
|
|
|
|
PROJ 4
|
|
|
|
END`;
|
|
|
|
|
|
|
|
it ('Should generate a sequence with CAM and PROJ statements', () => {
|
2019-05-29 02:40:50 +00:00
|
|
|
const obj = mscript.interpret(script3)
|
|
|
|
let pass = false;
|
|
|
|
if (obj.success === true
|
|
|
|
&& obj.cam === 8
|
|
|
|
&& obj.proj === 8
|
|
|
|
&& obj.arr.length === 16
|
2019-07-26 23:54:22 +00:00
|
|
|
&& obj.meta.length === 16
|
|
|
|
&& obj.meta[0] === '0,0,0') {
|
2019-05-29 02:40:50 +00:00
|
|
|
pass = true;
|
|
|
|
}
|
|
|
|
assert.ok(pass, 'Basic cam/proj loop');
|
2019-05-28 13:02:55 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-05-28 21:40:59 +00:00
|
|
|
describe('mscript - Light', () => {
|
2019-05-28 13:02:55 +00:00
|
|
|
//Lighting tests
|
|
|
|
const script1 = 'L 255,255,255\nCF\nPF';
|
|
|
|
|
2019-05-29 02:40:50 +00:00
|
|
|
it ( `Should set a light value on camera steps`, () => {
|
|
|
|
const obj = mscript.interpret(script1)
|
2019-05-28 13:02:55 +00:00
|
|
|
let pass = false;
|
|
|
|
if (obj.success === true
|
|
|
|
&& obj.cam === 1
|
|
|
|
&& obj.proj === 1
|
|
|
|
&& obj.arr.length === 2
|
2019-07-26 23:54:22 +00:00
|
|
|
&& obj.meta.length === 2
|
|
|
|
&& obj.meta[0] === '255,255,255'
|
|
|
|
&& obj.meta[1] === '') {
|
2019-05-28 13:02:55 +00:00
|
|
|
pass = true;
|
|
|
|
}
|
|
|
|
assert.ok(pass, 'Basic light');
|
|
|
|
});
|
|
|
|
|
|
|
|
const script2 = 'L 255,255,255\nCF\nPF\nBF';
|
2019-05-29 02:40:50 +00:00
|
|
|
it ( `Should set light to black on black_forward`, () => {
|
|
|
|
const obj = mscript.interpret(script2)
|
2019-05-28 13:02:55 +00:00
|
|
|
let pass = false;
|
|
|
|
if (obj.success === true
|
|
|
|
&& obj.cam === 2
|
|
|
|
&& obj.proj === 1
|
|
|
|
&& obj.arr.length === 3
|
2019-07-26 23:54:22 +00:00
|
|
|
&& obj.meta.length === 3
|
|
|
|
&& obj.meta[0] === '255,255,255'
|
|
|
|
&& obj.meta[1] === ''
|
|
|
|
&& obj.meta[2] === '0,0,0') {
|
2019-05-28 13:02:55 +00:00
|
|
|
pass = true;
|
|
|
|
}
|
|
|
|
assert.ok(pass, 'Basic black');
|
|
|
|
});
|
|
|
|
const script3 = 'LOOP 2\nL 1,1,1\nCF\nL 2,2,2\nCF\nEND';
|
2019-05-29 02:40:50 +00:00
|
|
|
it ( `Should set light within a loop`, () => {
|
|
|
|
const obj = mscript.interpret(script3);
|
2019-05-28 13:02:55 +00:00
|
|
|
let pass = false;
|
|
|
|
if (obj.success === true
|
|
|
|
&& obj.cam === 4
|
|
|
|
&& obj.proj === 0
|
|
|
|
&& obj.arr.length === 4
|
2019-07-26 23:54:22 +00:00
|
|
|
&& obj.meta.length === 4
|
|
|
|
&& obj.meta[0] === '1,1,1'
|
|
|
|
&& obj.meta[3] === '2,2,2') {
|
2019-05-28 13:02:55 +00:00
|
|
|
pass = true;
|
|
|
|
}
|
|
|
|
assert.ok(pass, 'Basic light');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-05-28 21:40:59 +00:00
|
|
|
describe('mscript - Fade', () => {
|
2019-05-28 13:02:55 +00:00
|
|
|
|
|
|
|
const script1 =
|
|
|
|
`F 72 0,0,0 10,20,30
|
|
|
|
CF
|
|
|
|
END
|
|
|
|
PF 10`
|
2019-05-29 02:40:50 +00:00
|
|
|
it ('Should generate a fade', () => {
|
|
|
|
const obj = mscript.interpret(script1)
|
2019-05-28 13:02:55 +00:00
|
|
|
//console.dir(obj)
|
|
|
|
assert.ok(obj.success, 'Basic fade compiles');
|
|
|
|
assert.equal(obj.cam, 72, `Camera moves forward 72 frames`);
|
|
|
|
assert.equal(obj.proj, 10, 'Projector moves forward 10 frames');
|
|
|
|
assert.equal(obj.arr.length, 82, 'Generates 82 steps');
|
2019-07-26 23:54:22 +00:00
|
|
|
assert.equal(obj.meta[0], '0,0,0', 'Fade starts with starting color');
|
|
|
|
assert.equal(obj.meta[71], '10,20,30', 'Fade ends with ending color');
|
|
|
|
assert.equal(obj.meta[72], '', 'Frame after fade is default color');
|
2019-05-29 02:40:50 +00:00
|
|
|
})
|
2019-05-28 13:02:55 +00:00
|
|
|
|
|
|
|
const script2 =
|
|
|
|
`
|
|
|
|
F 24 25,255,125 225,125,10
|
|
|
|
CF
|
|
|
|
END
|
|
|
|
L 225,125,10
|
|
|
|
CF 10`
|
2019-05-29 02:40:50 +00:00
|
|
|
|
|
|
|
it ('Should generate a fade and immediately set a light value after', () => {
|
|
|
|
const obj = mscript.interpret(script2)
|
2019-05-28 13:02:55 +00:00
|
|
|
//console.dir(obj)
|
|
|
|
assert.ok(obj.success, 'Mscript labeled output success');
|
|
|
|
assert.equal(obj.cam, 34, 'There are 34 camera frames');
|
|
|
|
assert.equal(obj.arr.length, 34, 'There are 34 steps in the script');
|
2019-07-26 23:54:22 +00:00
|
|
|
assert.equal(obj.meta[0], '25,255,125', 'First frame is equal to start color');
|
|
|
|
assert.equal(obj.meta[23], '225,125,10', 'Last frame in fade is equal to end color');
|
|
|
|
assert.equal(obj.meta[24], '225,125,10', 'First frame after fade is set using Light command');
|
2019-05-29 02:40:50 +00:00
|
|
|
})
|
2019-05-28 13:02:55 +00:00
|
|
|
})
|
|
|
|
|
2022-08-08 02:18:58 +00:00
|
|
|
//secondary
|
|
|
|
|
2019-05-28 21:40:59 +00:00
|
|
|
/*describe('mscript - Variables', () => {
|
2019-05-28 13:02:55 +00:00
|
|
|
const script1 =
|
|
|
|
`@LIGHT=200,200,200
|
|
|
|
@COUNT=1
|
|
|
|
CF 20
|
|
|
|
PF
|
|
|
|
@COUNT++
|
|
|
|
`
|
|
|
|
mscript.interpret(script1, obj => {
|
|
|
|
//console.dir(obj)
|
|
|
|
assert.ok(true)
|
|
|
|
})
|
2019-05-28 21:40:59 +00:00
|
|
|
})*/
|