mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2024-12-23 06:23:37 -05:00
Additional tests for invalid adapter
inputs
This commit is contained in:
parent
e9accca107
commit
2339c5e710
3 changed files with 49 additions and 0 deletions
|
@ -32,6 +32,9 @@ function domToBlocks (blocksDOM) {
|
|||
var blocks = {};
|
||||
for (var i = 0; i < blocksDOM.length; i++) {
|
||||
var block = blocksDOM[i];
|
||||
if (!block.name || !block.attribs) {
|
||||
continue;
|
||||
}
|
||||
var tagName = block.name.toLowerCase();
|
||||
if (tagName == 'block' || tagName == 'shadow') {
|
||||
domToBlock(block, blocks, true);
|
||||
|
@ -114,6 +117,10 @@ function domToBlock (blockDOM, blocks, isTopBlock) {
|
|||
};
|
||||
break;
|
||||
case 'next':
|
||||
if (!childBlockNode || !childBlockNode.attribs) {
|
||||
// Invalid child block.
|
||||
continue;
|
||||
}
|
||||
// Recursively generate block structure for next block.
|
||||
domToBlock(childBlockNode, blocks, false);
|
||||
// Link next block to this block.
|
||||
|
|
18
test/fixtures/events.json
vendored
18
test/fixtures/events.json
vendored
|
@ -35,5 +35,23 @@
|
|||
"xml": {
|
||||
"outerHTML": "<block type=\"wedo_setcolor\" id=\"*CT)7+UKjQIEtUw.OGT6\" x=\"89\" y=\"48\"><next><block type=\"wedo_motorspeed\" id=\"Er*:^o7yYL#dX+5)R^xq\"></block></next></block>"
|
||||
}
|
||||
},
|
||||
"createinvalid": {
|
||||
"name": "whatever",
|
||||
"xml": {
|
||||
"outerHTML": "<xml></xml>"
|
||||
}
|
||||
},
|
||||
"createinvalidgrandchild": {
|
||||
"name": "block",
|
||||
"xml": {
|
||||
"outerHTML": "<block type=\"control_forever\" id=\"r9`RpL74T6*SXPKv7}Dq\" x=\"61\" y=\"90\"><next><invalidgrandchild>xxx</invalidgrandchild></next></block>"
|
||||
}
|
||||
},
|
||||
"createbadxml": {
|
||||
"name": "whatever",
|
||||
"xml": {
|
||||
"outerHTML": "></xml>"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -141,3 +141,27 @@ test('create with next connection', function (t) {
|
|||
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('create with invalid block xml', function (t) {
|
||||
// Entirely invalid block XML
|
||||
var result = adapter(events.createinvalid);
|
||||
t.ok(Array.isArray(result));
|
||||
t.equal(result.length, 0);
|
||||
|
||||
// Invalid grandchild tag
|
||||
var result2 = adapter(events.createinvalidgrandchild);
|
||||
t.ok(Array.isArray(result2));
|
||||
t.equal(result2.length, 1);
|
||||
t.type(result2[0].id, 'string');
|
||||
t.equal(Object.keys(result2[0].inputs).length, 0);
|
||||
t.equal(Object.keys(result2[0].fields).length, 0);
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('create with invalid xml', function (t) {
|
||||
var result = adapter(events.createbadxml);
|
||||
t.ok(Array.isArray(result));
|
||||
t.equal(result.length, 0);
|
||||
t.end();
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue