mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2025-05-14 23:40:32 -04:00
Additional adapter tests for new cases
This commit is contained in:
parent
4eb63cf33e
commit
06eaee9108
2 changed files with 102 additions and 6 deletions
test
25
test/fixtures/events.json
vendored
25
test/fixtures/events.json
vendored
|
@ -16,11 +16,24 @@
|
|||
"name": "block",
|
||||
"xml": {
|
||||
"outerHTML": "<block type=\"control_forever\" id=\"r9`RpL74T6*SXPKv7}Dq\" x=\"61\" y=\"90\"><statement name=\"SUBSTACK\"><block type=\"control_wait\" id=\"{Rwt[LFtD1-JPAi-qf:.\"><value name=\"DURATION\"><shadow type=\"math_number\" id=\"VMDxt_9SYe5{*eNRe5dZ\"><field name=\"NUM\">1</field></shadow></value></block></statement></block>"
|
||||
},
|
||||
"ids": [
|
||||
"r9`RpL74T6*SXPKv7}Dq",
|
||||
"{Rwt[LFtD1-JPAi-qf:.",
|
||||
"VMDxt_9SYe5{*eNRe5dZ"
|
||||
]
|
||||
}
|
||||
},
|
||||
"createtwosubstacks": {
|
||||
"name": "block",
|
||||
"xml": {
|
||||
"outerHTML": "<block type=\"control_if_else\" id=\"8W?lmIY!Tgnh)~0!G#9-\" x=\"87\" y=\"159\"><statement name=\"SUBSTACK\"><block type=\"event_broadcast\" id=\"lgU2GGtwlREuasCB02Vr\"></block></statement><statement name=\"SUBSTACK2\"><block type=\"event_broadcast\" id=\"Gb]N,2P;|J%F?pxSwz(2\"></block></statement></block>"
|
||||
}
|
||||
},
|
||||
"createtoplevelshadow": {
|
||||
"name": "shadow",
|
||||
"xml": {
|
||||
"outerHTML": "<shadow type=\"math_number\" id=\"z9d57=IUI5se;DBbyug)\"><field name=\"NUM\">4</field></shadow>"
|
||||
}
|
||||
},
|
||||
"createwithnext": {
|
||||
"name": "block",
|
||||
"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>"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,6 +7,14 @@ test('spec', function (t) {
|
|||
t.end();
|
||||
});
|
||||
|
||||
test('invalid inputs', function(t) {
|
||||
var nothing = adapter('not an object');
|
||||
t.type(nothing, 'undefined');
|
||||
nothing = adapter({noxmlproperty:true});
|
||||
t.type(nothing, 'undefined');
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('create event', function (t) {
|
||||
var result = adapter(events.create);
|
||||
|
||||
|
@ -58,3 +66,78 @@ test('create with substack', function (t) {
|
|||
t.type(substackBlock, 'object');
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('create with two substacks', function (t) {
|
||||
var result = adapter(events.createtwosubstacks);
|
||||
// Outer block
|
||||
t.type(result[0].id, 'string');
|
||||
t.type(result[0].opcode, 'string');
|
||||
t.type(result[0].fields, 'object');
|
||||
t.type(result[0].inputs, 'object');
|
||||
t.type(result[0].inputs['SUBSTACK'], 'object');
|
||||
t.type(result[0].inputs['SUBSTACK2'], 'object');
|
||||
t.type(result[0].topLevel, 'boolean');
|
||||
t.equal(result[0].topLevel, true);
|
||||
// In substacks
|
||||
var firstSubstackBlockId = result[0].inputs['SUBSTACK']['block'];
|
||||
var secondSubstackBlockId = result[0].inputs['SUBSTACK2']['block'];
|
||||
t.type(firstSubstackBlockId, 'string');
|
||||
t.type(secondSubstackBlockId, 'string');
|
||||
// Find actual substack blocks
|
||||
var firstSubstackBlock = null;
|
||||
var secondSubstackBlock = null;
|
||||
for (var i = 0; i < result.length; i++) {
|
||||
if (result[i].id == firstSubstackBlockId) {
|
||||
firstSubstackBlock = result[i];
|
||||
}
|
||||
if (result[i].id == secondSubstackBlockId) {
|
||||
secondSubstackBlock = result[i];
|
||||
}
|
||||
}
|
||||
t.type(firstSubstackBlock, 'object');
|
||||
t.type(secondSubstackBlock, 'object');
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('create with top-level shadow', function (t) {
|
||||
var result = adapter(events.createtoplevelshadow);
|
||||
t.ok(Array.isArray(result));
|
||||
t.equal(result.length, 1);
|
||||
|
||||
// Outer block
|
||||
t.type(result[0].id, 'string');
|
||||
t.type(result[0].opcode, 'string');
|
||||
t.type(result[0].fields, 'object');
|
||||
t.type(result[0].inputs, 'object');
|
||||
t.type(result[0].topLevel, 'boolean');
|
||||
t.equal(result[0].topLevel, true);
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('create with next connection', function (t) {
|
||||
var result = adapter(events.createwithnext);
|
||||
|
||||
t.ok(Array.isArray(result));
|
||||
t.equal(result.length, 2);
|
||||
|
||||
// First block
|
||||
t.type(result[0].id, 'string');
|
||||
t.type(result[0].opcode, 'string');
|
||||
t.type(result[0].fields, 'object');
|
||||
t.type(result[0].inputs, 'object');
|
||||
t.type(result[0].topLevel, 'boolean');
|
||||
t.equal(result[0].topLevel, true);
|
||||
t.type(result[0].next, 'string');
|
||||
t.equal(result[0].next, result[1].id);
|
||||
|
||||
// Second block
|
||||
t.type(result[1].id, 'string');
|
||||
t.type(result[1].opcode, 'string');
|
||||
t.type(result[1].fields, 'object');
|
||||
t.type(result[1].inputs, 'object');
|
||||
t.type(result[1].topLevel, 'boolean');
|
||||
t.equal(result[1].topLevel, false);
|
||||
t.equal(result[1].next, null);
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue