mirror of
https://github.com/scratchfoundation/scratch-analysis.git
synced 2025-08-28 22:09:00 -04:00
Fix handling of primitive blocks: list and variable.
Previously these blocks have been reported as 'undefined'. Right now they are reported as 'data_list' and 'data_variable'. I came up with these names myslef and will consult it during the code review.
This commit is contained in:
parent
0f4220d101
commit
15a9463dd2
2 changed files with 51 additions and 1 deletions
14
lib/sb3.js
14
lib/sb3.js
|
@ -92,10 +92,22 @@ const blocks = function (targets) {
|
|||
for (let t in targets) {
|
||||
for (let a in targets[t].blocks) {
|
||||
const block = targets[t].blocks[a];
|
||||
let opcode = block.opcode;
|
||||
|
||||
// Check for primitive blocks which don't have the opcode field
|
||||
if (typeof opcode === 'undefined') {
|
||||
switch (block[0]) {
|
||||
case (12):
|
||||
opcode = 'data_variable';
|
||||
break;
|
||||
case (13):
|
||||
opcode = 'data_list';
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Get opcode and check variable manipulation for the presence of
|
||||
// cloud variables
|
||||
let opcode = block.opcode;
|
||||
if (opcode === 'data_setvariableto' || opcode === 'data_changevariableby') {
|
||||
if (isArgCloudVar(block.fields.VARIABLE[1])) {
|
||||
opcode += '_cloud';
|
||||
|
|
|
@ -21,6 +21,10 @@ const badExtensions = fs.readFileSync(
|
|||
path.resolve(__dirname, '../fixtures/sb3/badExtensions.json')
|
||||
);
|
||||
|
||||
const primitiveVariableAndListBlocks = fs.readFileSync(
|
||||
path.resolve(__dirname, '../fixtures/sb3/primitiveVariableAndListBlocks.json')
|
||||
);
|
||||
|
||||
test('default (object)', t => {
|
||||
analysis(defaultObject, (err, result) => {
|
||||
t.ok(typeof err === 'undefined' || err === null);
|
||||
|
@ -351,3 +355,37 @@ test('regression test IBE-198, a bad list does not break library', t => {
|
|||
t.end();
|
||||
});
|
||||
});
|
||||
|
||||
test('correctly handling primitve reporter blocks: list and variable', t => {
|
||||
analysis(primitiveVariableAndListBlocks, (err, result) => {
|
||||
t.ok(typeof err === 'undefined' || err === null);
|
||||
t.type(result, 'object');
|
||||
|
||||
t.type(result.variables, 'object');
|
||||
t.equal(result.variables.count, 1);
|
||||
t.same(result.variables.id, [
|
||||
'my_variable'
|
||||
]);
|
||||
|
||||
t.type(result.lists, 'object');
|
||||
t.equal(result.lists.count, 1);
|
||||
t.same(result.lists.id, [
|
||||
'my_list'
|
||||
]);
|
||||
|
||||
t.type(result.blocks, 'object');
|
||||
t.equal(result.blocks.count, 3);
|
||||
t.equal(result.blocks.unique, 3);
|
||||
t.same(result.blocks.id, [
|
||||
'data_list',
|
||||
'motion_changexby',
|
||||
'data_variable'
|
||||
]);
|
||||
t.same(result.blocks.frequency, {
|
||||
data_list: 1,
|
||||
motion_changexby: 1,
|
||||
data_variable: 1
|
||||
});
|
||||
t.end();
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue