mirror of
https://github.com/scratchfoundation/scratch-parser.git
synced 2025-08-28 22:18:45 -04:00
test: add new sprite2 test fixtures and integration tests
provide test coverage for sprite2 validation, and update sprite2_schema
This commit is contained in:
parent
b0d1e46cd8
commit
78ce54e69f
8 changed files with 274 additions and 46 deletions
|
@ -7,46 +7,15 @@
|
|||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"info": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"flashVersion": {
|
||||
"type": "string"
|
||||
},
|
||||
"swfVersion": {
|
||||
"type": "string"
|
||||
},
|
||||
"userAgent": {
|
||||
"type": "string"
|
||||
},
|
||||
"videoOn": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"savedExtensions": {
|
||||
"type": "array",
|
||||
"properties": {
|
||||
"extensionName": {
|
||||
"type": "string"
|
||||
},
|
||||
"blockSpecs": {
|
||||
"type": "array"
|
||||
},
|
||||
"menus": {
|
||||
"type": "object"
|
||||
},
|
||||
"javascriptURL": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"extensionName",
|
||||
"blockSpecs",
|
||||
"menus",
|
||||
"javascriptURL"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
"scratchX": {"type": "number"},
|
||||
"scratchY": {"type": "number"},
|
||||
"scale": {"type": "number"},
|
||||
"direction": {"type": "number"},
|
||||
"rotationStyle": {"type": "string"},
|
||||
"isDraggable": {"type": "boolean"},
|
||||
"indexInLibrary": {"type": "number"},
|
||||
"visible": {"type": "boolean"},
|
||||
"spriteInfo": {"type": "object"}
|
||||
}
|
||||
}
|
||||
]
|
||||
|
|
22
test/fixtures/data.js
vendored
22
test/fixtures/data.js
vendored
|
@ -5,14 +5,19 @@ var path = require('path');
|
|||
// Build file listings
|
||||
var sb = glob.sync(path.resolve(__dirname, './data/*.sb'));
|
||||
var sb2 = glob.sync(path.resolve(__dirname, './data/*.sb2'));
|
||||
var sprite2 = glob.sync(path.resolve(__dirname, './data/*.sprite2'));
|
||||
// Sprite2 and Sprite3 jsons have modified file extensions
|
||||
// so that they don't get caught here but can still be used by the
|
||||
// validate unit tests
|
||||
var json = glob.sync(path.resolve(__dirname, './data/*.json'));
|
||||
var gzipJson = glob.sync(path.resolve(__dirname, './data/*.json.gz'));
|
||||
|
||||
// Read files and convert to buffers
|
||||
for (var w in sb) sb[w] = fs.readFileSync(sb[w]);
|
||||
for (var x in sb2) sb2[x] = fs.readFileSync(sb2[x]);
|
||||
for (var y in json) json[y] = fs.readFileSync(json[y]);
|
||||
for (var z in gzipJson) gzipJson[z] = fs.readFileSync(gzipJson[z]);
|
||||
for (var a in sb) sb[a] = fs.readFileSync(sb[a]);
|
||||
for (var b in sb2) sb2[b] = fs.readFileSync(sb2[b]);
|
||||
for (var c in json) json[c] = fs.readFileSync(json[c]);
|
||||
for (var d in gzipJson) gzipJson[d] = fs.readFileSync(gzipJson[d]);
|
||||
for (var e in sprite2) sprite2[e] = fs.readFileSync(sprite2[e]);
|
||||
|
||||
// Return listings
|
||||
module.exports = {
|
||||
|
@ -28,8 +33,15 @@ module.exports = {
|
|||
json: fs.readFileSync(path.resolve(__dirname, './data/_example.json')),
|
||||
gzipJson: fs.readFileSync(path.resolve(__dirname, './data/_example.json.gz'))
|
||||
},
|
||||
sprites: {
|
||||
default_cat_sprite2: fs.readFileSync(path.resolve(__dirname, './data/_default_cat.sprite2')),
|
||||
default_cat_sprite2_json: fs.readFileSync(path.resolve(__dirname, './data/_default_cat.sprite2json')),
|
||||
example_sprite2: fs.readFileSync(path.resolve(__dirname, './data/_example_sprite.sprite2')),
|
||||
example_sprite2_json: fs.readFileSync(path.resolve(__dirname, './data/_example_sprite.sprite2json'))
|
||||
},
|
||||
sb: sb,
|
||||
sb2: sb2,
|
||||
json: json,
|
||||
gzipJson: gzipJson
|
||||
gzipJson: gzipJson,
|
||||
sprite2: sprite2
|
||||
};
|
||||
|
|
BIN
test/fixtures/data/_default_cat.sprite2
vendored
Normal file
BIN
test/fixtures/data/_default_cat.sprite2
vendored
Normal file
Binary file not shown.
38
test/fixtures/data/_default_cat.sprite2json
vendored
Executable file
38
test/fixtures/data/_default_cat.sprite2json
vendored
Executable file
|
@ -0,0 +1,38 @@
|
|||
{
|
||||
"objName": "Sprite1",
|
||||
"sounds": [{
|
||||
"soundName": "meow",
|
||||
"soundID": 0,
|
||||
"md5": "83c36d806dc92327b9e7049a565c6bff.wav",
|
||||
"sampleCount": 18688,
|
||||
"rate": 22050,
|
||||
"format": ""
|
||||
}],
|
||||
"costumes": [{
|
||||
"costumeName": "costume1",
|
||||
"baseLayerID": 0,
|
||||
"baseLayerMD5": "f9a1c175dbe2e5dee472858dd30d16bb.svg",
|
||||
"bitmapResolution": 1,
|
||||
"rotationCenterX": 47,
|
||||
"rotationCenterY": 55
|
||||
},
|
||||
{
|
||||
"costumeName": "costume2",
|
||||
"baseLayerID": 1,
|
||||
"baseLayerMD5": "6e8bd9ae68fdb02b7e1e3df656a75635.svg",
|
||||
"bitmapResolution": 1,
|
||||
"rotationCenterX": 47,
|
||||
"rotationCenterY": 55
|
||||
}],
|
||||
"currentCostumeIndex": 0,
|
||||
"scratchX": 0,
|
||||
"scratchY": 0,
|
||||
"scale": 1,
|
||||
"direction": 90,
|
||||
"rotationStyle": "normal",
|
||||
"isDraggable": false,
|
||||
"indexInLibrary": 100000,
|
||||
"visible": true,
|
||||
"spriteInfo": {
|
||||
}
|
||||
}
|
BIN
test/fixtures/data/_example_sprite.sprite2
vendored
Normal file
BIN
test/fixtures/data/_example_sprite.sprite2
vendored
Normal file
Binary file not shown.
131
test/fixtures/data/_example_sprite.sprite2json
vendored
Executable file
131
test/fixtures/data/_example_sprite.sprite2json
vendored
Executable file
|
@ -0,0 +1,131 @@
|
|||
{
|
||||
"objName": "1080 Hip-Hop",
|
||||
"scripts": [[27,
|
||||
26,
|
||||
[["whenKeyPressed", "space"],
|
||||
["doRepeat", 10, [["playSound:", "dance celebrate"]]],
|
||||
["doForever", [["changeGraphicEffect:by:", "color", 25]]]]]],
|
||||
"sounds": [{
|
||||
"soundName": "dance celebrate",
|
||||
"soundID": 0,
|
||||
"md5": "0edb8fb88af19e6e17d0f8cf64c1d136.wav",
|
||||
"sampleCount": 176401,
|
||||
"rate": 22050,
|
||||
"format": "adpcm"
|
||||
}],
|
||||
"costumes": [{
|
||||
"costumeName": "1080 stance",
|
||||
"baseLayerID": 0,
|
||||
"baseLayerMD5": "b50767d57a9979120db126ab0e78c967.png",
|
||||
"bitmapResolution": 2,
|
||||
"rotationCenterX": 70,
|
||||
"rotationCenterY": 278
|
||||
},
|
||||
{
|
||||
"costumeName": "1080 top stand",
|
||||
"baseLayerID": 1,
|
||||
"baseLayerMD5": "2beeccef2956cf00f3fe04a70941a304.png",
|
||||
"bitmapResolution": 2,
|
||||
"rotationCenterX": 74,
|
||||
"rotationCenterY": 274
|
||||
},
|
||||
{
|
||||
"costumeName": "1080 top R step",
|
||||
"baseLayerID": 2,
|
||||
"baseLayerMD5": "877253c7955364d01d3cdf6c00ad8f26.png",
|
||||
"bitmapResolution": 2,
|
||||
"rotationCenterX": 200,
|
||||
"rotationCenterY": 270
|
||||
},
|
||||
{
|
||||
"costumeName": "1080 top L step",
|
||||
"baseLayerID": 3,
|
||||
"baseLayerMD5": "0182ebabc5f0e2ba2f8c5a88543c841a.png",
|
||||
"bitmapResolution": 2,
|
||||
"rotationCenterX": 144,
|
||||
"rotationCenterY": 266
|
||||
},
|
||||
{
|
||||
"costumeName": "1080 top freeze",
|
||||
"baseLayerID": 4,
|
||||
"baseLayerMD5": "eeb7ec45ab14f11c59faa86d68aa6711.png",
|
||||
"bitmapResolution": 2,
|
||||
"rotationCenterX": 54,
|
||||
"rotationCenterY": 258
|
||||
},
|
||||
{
|
||||
"costumeName": "1080 top R cross",
|
||||
"baseLayerID": 5,
|
||||
"baseLayerMD5": "69eae69a7bb4951d2bf44031d709e9b7.png",
|
||||
"bitmapResolution": 2,
|
||||
"rotationCenterX": 206,
|
||||
"rotationCenterY": 252
|
||||
},
|
||||
{
|
||||
"costumeName": "1080 pop front",
|
||||
"baseLayerID": 6,
|
||||
"baseLayerMD5": "dd96cd3037b3e48814529bbf1d615bea.png",
|
||||
"bitmapResolution": 2,
|
||||
"rotationCenterX": 72,
|
||||
"rotationCenterY": 266
|
||||
},
|
||||
{
|
||||
"costumeName": "1080 pop down",
|
||||
"baseLayerID": 7,
|
||||
"baseLayerMD5": "0a4fe68e96f9194f3b5a039af8598c05.png",
|
||||
"bitmapResolution": 2,
|
||||
"rotationCenterX": 74,
|
||||
"rotationCenterY": 188
|
||||
},
|
||||
{
|
||||
"costumeName": "1080 pop left",
|
||||
"baseLayerID": 8,
|
||||
"baseLayerMD5": "097b4b61b323e4041315992f41196ec9.png",
|
||||
"bitmapResolution": 2,
|
||||
"rotationCenterX": 184,
|
||||
"rotationCenterY": 266
|
||||
},
|
||||
{
|
||||
"costumeName": "1080 pop right",
|
||||
"baseLayerID": 9,
|
||||
"baseLayerMD5": "9ab30ea9351f88b0bfcc7c1eff219ec4.png",
|
||||
"bitmapResolution": 2,
|
||||
"rotationCenterX": 78,
|
||||
"rotationCenterY": 276
|
||||
},
|
||||
{
|
||||
"costumeName": "1080 pop L arm",
|
||||
"baseLayerID": 10,
|
||||
"baseLayerMD5": "532ca24749bd0968b329c0970209805b.png",
|
||||
"bitmapResolution": 2,
|
||||
"rotationCenterX": 100,
|
||||
"rotationCenterY": 280
|
||||
},
|
||||
{
|
||||
"costumeName": "1080 pop stand",
|
||||
"baseLayerID": 11,
|
||||
"baseLayerMD5": "b140b94daf02503e0abfc1ec284c6ccd.png",
|
||||
"bitmapResolution": 2,
|
||||
"rotationCenterX": 92,
|
||||
"rotationCenterY": 280
|
||||
},
|
||||
{
|
||||
"costumeName": "1080 pop R arm",
|
||||
"baseLayerID": 12,
|
||||
"baseLayerMD5": "c69c7b764530b8a464f2ca4e5e85c303.png",
|
||||
"bitmapResolution": 2,
|
||||
"rotationCenterX": 74,
|
||||
"rotationCenterY": 278
|
||||
}],
|
||||
"currentCostumeIndex": 0,
|
||||
"scratchX": 0,
|
||||
"scratchY": 0,
|
||||
"scale": 1,
|
||||
"direction": 90,
|
||||
"rotationStyle": "normal",
|
||||
"isDraggable": false,
|
||||
"indexInLibrary": 100000,
|
||||
"visible": true,
|
||||
"spriteInfo": {
|
||||
}
|
||||
}
|
56
test/integration/sprites.js
Normal file
56
test/integration/sprites.js
Normal file
|
@ -0,0 +1,56 @@
|
|||
var test = require('tap').test;
|
||||
var JSZip = require('jszip');
|
||||
var data = require('../fixtures/data');
|
||||
var parser = require('../../index');
|
||||
|
||||
test('default cat sprite2', function (t) {
|
||||
parser(data.sprites.default_cat_sprite2, true, function (err, result) {
|
||||
t.equal(err, null);
|
||||
t.equal(Array.isArray(result), true);
|
||||
var res = result[0];
|
||||
var possibleZip = result[1];
|
||||
t.type(res, 'object');
|
||||
t.equal(res.projectVersion, 2);
|
||||
t.equal(possibleZip instanceof JSZip, true);
|
||||
t.end();
|
||||
});
|
||||
});
|
||||
|
||||
test('example sprite2', function (t) {
|
||||
parser(data.sprites.example_sprite2, true, function (err, result) {
|
||||
t.equal(err, null);
|
||||
t.equal(Array.isArray(result), true);
|
||||
var res = result[0];
|
||||
var possibleZip = result[1];
|
||||
t.type(res, 'object');
|
||||
t.equal(res.projectVersion, 2);
|
||||
t.equal(possibleZip instanceof JSZip, true);
|
||||
t.end();
|
||||
});
|
||||
});
|
||||
|
||||
test('default cat sprite2 json', function (t) {
|
||||
parser(data.sprites.default_cat_sprite2_json, true, function (err, result) {
|
||||
t.equal(err, null);
|
||||
t.equal(Array.isArray(result), true);
|
||||
var res = result[0];
|
||||
var possibleZip = result[1];
|
||||
t.type(res, 'object');
|
||||
t.equal(res.projectVersion, 2);
|
||||
t.equal(possibleZip, null);
|
||||
t.end();
|
||||
});
|
||||
});
|
||||
|
||||
test('default cat sprite2 json', function (t) {
|
||||
parser(data.sprites.example_sprite2_json, true, function (err, result) {
|
||||
t.equal(err, null);
|
||||
t.equal(Array.isArray(result), true);
|
||||
var res = result[0];
|
||||
var possibleZip = result[1];
|
||||
t.type(res, 'object');
|
||||
t.equal(res.projectVersion, 2);
|
||||
t.equal(possibleZip, null);
|
||||
t.end();
|
||||
});
|
||||
});
|
|
@ -7,7 +7,7 @@ test('spec', function (t) {
|
|||
t.end();
|
||||
});
|
||||
|
||||
test('valid', function (t) {
|
||||
test('valid sb2 project', function (t) {
|
||||
validate(false, JSON.parse(data.example.json), function (err, res) {
|
||||
t.equal(err, null);
|
||||
t.type(res, 'object');
|
||||
|
@ -15,6 +15,28 @@ test('valid', function (t) {
|
|||
});
|
||||
});
|
||||
|
||||
test('valid sprite2', function (t) {
|
||||
validate(true, JSON.parse(data.sprites.default_cat_sprite2_json), function (err, res) {
|
||||
t.equal(err, null);
|
||||
t.type(res, 'object');
|
||||
t.end();
|
||||
});
|
||||
});
|
||||
|
||||
// Note, the way the sb2/sprite2 validation is written, a valid sb2 project can actually
|
||||
// validate as a sprite2 file. The opposite should not be true.
|
||||
|
||||
test('valid sprite2 is not a valid project', function (t) {
|
||||
validate(false, JSON.parse(data.sprites.default_cat_sprite2_json), function (err, res) {
|
||||
t.type(err, 'object');
|
||||
t.type(err.validationError, 'string');
|
||||
var sb2Errs = err.sb2Errors;
|
||||
t.equal(Array.isArray(sb2Errs), true);
|
||||
t.type(res, 'undefined');
|
||||
t.end();
|
||||
});
|
||||
});
|
||||
|
||||
test('invalid, whole project', function (t) {
|
||||
validate(false, {foo: 1}, function (err, res) {
|
||||
t.type(err, 'object');
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue