2016-10-17 11:55:21 -04:00
|
|
|
var fs = require('fs');
|
|
|
|
var path = require('path');
|
|
|
|
var test = require('tap').test;
|
|
|
|
|
2016-10-26 11:19:43 -04:00
|
|
|
var renderedTarget = require('../../src/sprites/rendered-target');
|
2016-10-17 11:55:21 -04:00
|
|
|
var runtime = require('../../src/engine/runtime');
|
2016-12-30 10:19:58 -05:00
|
|
|
var sb2 = require('../../src/serialization/sb2');
|
2016-10-17 11:55:21 -04:00
|
|
|
|
|
|
|
test('spec', function (t) {
|
2016-12-30 10:19:58 -05:00
|
|
|
t.type(sb2, 'object');
|
|
|
|
t.type(sb2.deserialize, 'function');
|
2016-10-17 11:55:21 -04:00
|
|
|
t.end();
|
|
|
|
});
|
|
|
|
|
|
|
|
test('default', function (t) {
|
|
|
|
// Get SB2 JSON (string)
|
|
|
|
var uri = path.resolve(__dirname, '../fixtures/default.json');
|
|
|
|
var file = fs.readFileSync(uri, 'utf8');
|
|
|
|
|
|
|
|
// Create runtime instance & load SB2 into it
|
|
|
|
var rt = new runtime();
|
2016-12-30 10:19:58 -05:00
|
|
|
sb2.deserialize(file, rt);
|
2016-10-17 11:55:21 -04:00
|
|
|
|
|
|
|
// Test
|
|
|
|
t.type(file, 'string');
|
|
|
|
t.type(rt, 'object');
|
|
|
|
t.type(rt.targets, 'object');
|
|
|
|
|
2016-10-26 11:19:43 -04:00
|
|
|
t.ok(rt.targets[0] instanceof renderedTarget);
|
2016-10-17 11:55:21 -04:00
|
|
|
t.type(rt.targets[0].id, 'string');
|
|
|
|
t.type(rt.targets[0].blocks, 'object');
|
|
|
|
t.type(rt.targets[0].variables, 'object');
|
|
|
|
t.type(rt.targets[0].lists, 'object');
|
|
|
|
|
|
|
|
t.equal(rt.targets[0].isOriginal, true);
|
|
|
|
t.equal(rt.targets[0].currentCostume, 0);
|
|
|
|
t.equal(rt.targets[0].isOriginal, true);
|
|
|
|
t.equal(rt.targets[0].isStage, true);
|
|
|
|
|
2016-10-26 11:19:43 -04:00
|
|
|
t.ok(rt.targets[1] instanceof renderedTarget);
|
2016-10-17 11:55:21 -04:00
|
|
|
t.type(rt.targets[1].id, 'string');
|
|
|
|
t.type(rt.targets[1].blocks, 'object');
|
|
|
|
t.type(rt.targets[1].variables, 'object');
|
|
|
|
t.type(rt.targets[1].lists, 'object');
|
|
|
|
|
|
|
|
t.equal(rt.targets[1].isOriginal, true);
|
|
|
|
t.equal(rt.targets[1].currentCostume, 0);
|
|
|
|
t.equal(rt.targets[1].isOriginal, true);
|
|
|
|
t.equal(rt.targets[1].isStage, false);
|
|
|
|
t.end();
|
|
|
|
});
|
|
|
|
|
|
|
|
test('demo', function (t) {
|
|
|
|
// Get SB2 JSON (string)
|
|
|
|
var uri = path.resolve(__dirname, '../fixtures/demo.json');
|
|
|
|
var file = fs.readFileSync(uri, 'utf8');
|
|
|
|
|
|
|
|
// Create runtime instance & load SB2 into it
|
|
|
|
var rt = new runtime();
|
2016-12-30 10:19:58 -05:00
|
|
|
sb2.deserialize(file, rt);
|
2016-10-17 11:55:21 -04:00
|
|
|
|
|
|
|
// Test
|
|
|
|
t.type(file, 'string');
|
|
|
|
t.type(rt, 'object');
|
|
|
|
t.type(rt.targets, 'object');
|
|
|
|
|
2016-10-26 11:19:43 -04:00
|
|
|
t.ok(rt.targets[0] instanceof renderedTarget);
|
2016-10-17 11:55:21 -04:00
|
|
|
t.type(rt.targets[0].id, 'string');
|
|
|
|
t.type(rt.targets[0].blocks, 'object');
|
|
|
|
t.type(rt.targets[0].variables, 'object');
|
|
|
|
t.type(rt.targets[0].lists, 'object');
|
|
|
|
|
|
|
|
t.equal(rt.targets[0].isOriginal, true);
|
|
|
|
t.equal(rt.targets[0].currentCostume, 0);
|
|
|
|
t.equal(rt.targets[0].isOriginal, true);
|
|
|
|
t.equal(rt.targets[0].isStage, true);
|
|
|
|
|
2016-10-26 11:19:43 -04:00
|
|
|
t.ok(rt.targets[1] instanceof renderedTarget);
|
2016-10-17 11:55:21 -04:00
|
|
|
t.type(rt.targets[1].id, 'string');
|
|
|
|
t.type(rt.targets[1].blocks, 'object');
|
|
|
|
t.type(rt.targets[1].variables, 'object');
|
|
|
|
t.type(rt.targets[1].lists, 'object');
|
|
|
|
|
|
|
|
t.equal(rt.targets[1].isOriginal, true);
|
|
|
|
t.equal(rt.targets[1].currentCostume, 0);
|
|
|
|
t.equal(rt.targets[1].isOriginal, true);
|
|
|
|
t.equal(rt.targets[1].isStage, false);
|
|
|
|
t.end();
|
|
|
|
});
|