Skip to content

Commit 30f09ad

Browse files
committed
cleanup, add test cases
1 parent f3186c8 commit 30f09ad

File tree

4 files changed

+41
-4
lines changed

4 files changed

+41
-4
lines changed

src/engine/runtime.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1429,12 +1429,11 @@ class Runtime extends EventEmitter {
14291429
break;
14301430
}
14311431

1432-
// Check if "blockShape" is specified
1432+
// Allow extensiosn to override outputShape
14331433
if (blockInfo.blockShape) {
1434-
blockJSON.outputShape = blockInfo.outputShape || ScratchBlocksConstants.OUTPUT_SHAPE_ROUND;
1434+
blockJSON.outputShape = blockInfo.blockShape;
14351435
}
14361436

1437-
14381437
const blockText = Array.isArray(blockInfo.text) ? blockInfo.text : [blockInfo.text];
14391438
let inTextNum = 0; // text for the next block "arm" is blockText[inTextNum]
14401439
let inBranchNum = 0; // how many branches have we placed into the JSON so far?

src/extension-support/tw-extension-api-common.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const ArgumentType = require('./argument-type');
22
const BlockType = require('./block-type');
3-
const BlockShape = require('./block-shape');
3+
const BlockShape = require('./tw-block-shape');
44
const TargetType = require('./target-type');
55
const Cast = require('../util/cast');
66

test/unit/tw_block_shape.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
const {test} = require('tap');
2+
const Runtime = require('../../src/engine/runtime');
3+
const Scratch = require('../../src/extension-support/tw-extension-api-common');
4+
5+
test('blockShape', t => {
6+
const rt = new Runtime();
7+
rt._registerExtensionPrimitives({
8+
id: 'shapetest',
9+
name: 'shapetest',
10+
blocks: [
11+
{
12+
blockType: Scratch.BlockType.REPORTER,
13+
blockShape: Scratch.BlockShape.HEXAGONAL,
14+
opcode: 'hexagonal',
15+
text: 'hexagonal'
16+
},
17+
{
18+
blockType: Scratch.BlockType.BOOLEAN,
19+
blockShape: Scratch.BlockShape.ROUND,
20+
opcode: 'round',
21+
text: 'round'
22+
},
23+
{
24+
blockType: Scratch.BlockType.REPORTER,
25+
blockShape: Scratch.BlockShape.SQUARE,
26+
opcode: 'square',
27+
text: 'square'
28+
}
29+
]
30+
});
31+
32+
const json = rt.getBlocksJSON();
33+
t.equal(json.length, 3);
34+
t.equal(json[0].outputShape, 1);
35+
t.equal(json[1].outputShape, 2);
36+
t.equal(json[2].outputShape, 3);
37+
t.end();
38+
});

0 commit comments

Comments
 (0)