mirror of
https://github.com/scratchfoundation/scratch-analysis.git
synced 2024-11-24 08:38:27 -05:00
commit
04ed13106e
3 changed files with 181 additions and 0 deletions
23
test/fixtures/sb2/invalid-costumes.json
vendored
Normal file
23
test/fixtures/sb2/invalid-costumes.json
vendored
Normal file
|
@ -0,0 +1,23 @@
|
|||
{
|
||||
"objName": "Stage",
|
||||
"sounds": [{
|
||||
"soundName": "pop",
|
||||
"soundID": -1,
|
||||
"md5": "83a9787d4cb6f3b7632b4ddfebf74367.wav",
|
||||
"sampleCount": 258,
|
||||
"rate": 11025,
|
||||
"format": ""
|
||||
}],
|
||||
"costumes": {
|
||||
"invalid": "This should be an array but is an object instead"
|
||||
},
|
||||
"currentCostumeIndex": 0,
|
||||
"penLayerMD5": "5c81a336fab8be57adc039a8a2b33ca9.png",
|
||||
"penLayerID": -1,
|
||||
"children": [],
|
||||
"info": {
|
||||
"videoOn": false,
|
||||
"scriptCount": 0,
|
||||
"spriteCount": 0
|
||||
}
|
||||
}
|
136
test/fixtures/sb3/primitiveVariableAndListBlocks.json
vendored
Normal file
136
test/fixtures/sb3/primitiveVariableAndListBlocks.json
vendored
Normal file
|
@ -0,0 +1,136 @@
|
|||
{
|
||||
"targets": [
|
||||
{
|
||||
"isStage": true,
|
||||
"name": "Stage",
|
||||
"variables": {
|
||||
"T1[{JjfXy_y{K@EQkA?1": [
|
||||
"my_variable",
|
||||
"0"
|
||||
]
|
||||
},
|
||||
"lists": {
|
||||
"HewanSoehucCjFovU@^H": [
|
||||
"my_list",
|
||||
[]
|
||||
]
|
||||
},
|
||||
"broadcasts": {},
|
||||
"blocks": {},
|
||||
"comments": {},
|
||||
"currentCostume": 0,
|
||||
"costumes": [
|
||||
{
|
||||
"assetId": "cd21514d0531fdffb22204e0ec5ed84a",
|
||||
"name": "backdrop1",
|
||||
"md5ext": "cd21514d0531fdffb22204e0ec5ed84a.svg",
|
||||
"dataFormat": "svg",
|
||||
"rotationCenterX": 240,
|
||||
"rotationCenterY": 180
|
||||
}
|
||||
],
|
||||
"sounds": [
|
||||
{
|
||||
"assetId": "83a9787d4cb6f3b7632b4ddfebf74367",
|
||||
"name": "pop",
|
||||
"dataFormat": "wav",
|
||||
"format": "",
|
||||
"rate": 44100,
|
||||
"sampleCount": 1032,
|
||||
"md5ext": "83a9787d4cb6f3b7632b4ddfebf74367.wav"
|
||||
}
|
||||
],
|
||||
"volume": 100,
|
||||
"layerOrder": 0,
|
||||
"tempo": 60,
|
||||
"videoTransparency": 50,
|
||||
"videoState": "on",
|
||||
"textToSpeechLanguage": null
|
||||
},
|
||||
{
|
||||
"isStage": false,
|
||||
"name": "Sprite1",
|
||||
"variables": {},
|
||||
"lists": {},
|
||||
"broadcasts": {},
|
||||
"blocks": {
|
||||
"wS7V(|TE2G9v@AX8BYK~": [
|
||||
13,
|
||||
"my_list",
|
||||
"HewanSoehucCjFovU@^H",
|
||||
713,
|
||||
604
|
||||
],
|
||||
"|#CTw):^,.,NSY)[Tnb?": {
|
||||
"opcode": "motion_changexby",
|
||||
"next": null,
|
||||
"parent": "^m#)|6_G10cLNp(ZlZv(",
|
||||
"inputs": {
|
||||
"DX": [
|
||||
3,
|
||||
[
|
||||
12,
|
||||
"my_variable",
|
||||
"T1[{JjfXy_y{K@EQkA?1"
|
||||
],
|
||||
[
|
||||
4,
|
||||
"10"
|
||||
]
|
||||
]
|
||||
},
|
||||
"fields": {},
|
||||
"shadow": false,
|
||||
"topLevel": false
|
||||
},
|
||||
"2_SCXE]6;tCt$ZcG|GQ(": [
|
||||
12,
|
||||
"my_variable",
|
||||
"T1[{JjfXy_y{K@EQkA?1",
|
||||
322,
|
||||
449
|
||||
]
|
||||
},
|
||||
"comments": {},
|
||||
"currentCostume": 0,
|
||||
"costumes": [
|
||||
{
|
||||
"assetId": "b7853f557e4426412e64bb3da6531a99",
|
||||
"name": "costume1",
|
||||
"bitmapResolution": 1,
|
||||
"md5ext": "b7853f557e4426412e64bb3da6531a99.svg",
|
||||
"dataFormat": "svg",
|
||||
"rotationCenterX": 48,
|
||||
"rotationCenterY": 50
|
||||
}
|
||||
],
|
||||
"sounds": [
|
||||
{
|
||||
"assetId": "83c36d806dc92327b9e7049a565c6bff",
|
||||
"name": "Meow",
|
||||
"dataFormat": "wav",
|
||||
"format": "",
|
||||
"rate": 44100,
|
||||
"sampleCount": 37376,
|
||||
"md5ext": "83c36d806dc92327b9e7049a565c6bff.wav"
|
||||
}
|
||||
],
|
||||
"volume": 100,
|
||||
"layerOrder": 1,
|
||||
"visible": true,
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
"size": 100,
|
||||
"direction": 90,
|
||||
"draggable": false,
|
||||
"rotationStyle": "all around"
|
||||
}
|
||||
],
|
||||
"monitors": [],
|
||||
"meta": {
|
||||
"semver": "3.0.0",
|
||||
"vm": "0.2.0-prerelease.20181217191056",
|
||||
"agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36",
|
||||
"origin": "test.scratch.mit.edu"
|
||||
}
|
||||
}
|
|
@ -2,6 +2,9 @@ const fs = require('fs');
|
|||
const path = require('path');
|
||||
const test = require('tap').test;
|
||||
const analysis = require('../../lib/index');
|
||||
// using the sb2 directly to bypass scratch-parser and excersise
|
||||
// logic targeting broken project files
|
||||
const sb2 = require('../../lib/sb2');
|
||||
|
||||
const defaultObject = fs.readFileSync(
|
||||
path.resolve(__dirname, '../fixtures/sb2/default.json')
|
||||
|
@ -13,6 +16,10 @@ const complexBinary = fs.readFileSync(
|
|||
path.resolve(__dirname, '../fixtures/sb2/complex.sb2')
|
||||
);
|
||||
|
||||
const invalidCostumes = fs.readFileSync(
|
||||
path.resolve(__dirname, '../fixtures/sb2/invalid-costumes.json')
|
||||
);
|
||||
|
||||
test('default (object)', t => {
|
||||
analysis(defaultObject, (err, result) => {
|
||||
t.ok(typeof err === 'undefined' || err === null);
|
||||
|
@ -284,3 +291,18 @@ test('complex (binary)', t => {
|
|||
t.end();
|
||||
});
|
||||
});
|
||||
|
||||
test('stage with invalid costumes', t => {
|
||||
const project = JSON.parse(invalidCostumes);
|
||||
|
||||
sb2(project, (err, result) => {
|
||||
t.ok(typeof err === 'undefined' || err === null);
|
||||
t.type(result, 'object');
|
||||
t.type(result.backdrops, 'object');
|
||||
t.equal(result.backdrops.count, 0);
|
||||
t.same(result.backdrops.id, []);
|
||||
t.same(result.backdrops.hash, []);
|
||||
|
||||
t.end();
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue