Auto-fix formatting issues to address CI failure.

This commit is contained in:
Ben Henning
2024-08-21 21:02:07 +00:00
parent ca42a4b4fd
commit 0413021b7c
4 changed files with 1367 additions and 521 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -408,21 +408,21 @@ suite('WorkspaceSvg', function () {
});
suite('tidyUp', function () {
test('empty workspace does not change', function() {
test('empty workspace does not change', function () {
this.workspace.tidyUp();
const blocks = this.workspace.getTopBlocks(true);
assert.equal(blocks.length, 0, 'workspace is empty');
});
test('single block at (0, 0) does not change', function() {
test('single block at (0, 0) does not change', function () {
const blockJson = {
"type": "math_number",
"x": 0,
"y": 0,
"fields": {
"NUM": 123
}
'type': 'math_number',
'x': 0,
'y': 0,
'fields': {
'NUM': 123,
},
};
Blockly.serialization.blocks.append(blockJson, this.workspace);
@@ -431,17 +431,21 @@ suite('WorkspaceSvg', function () {
const blocks = this.workspace.getTopBlocks(true);
const origin = new Blockly.utils.Coordinate(0, 0);
assert.equal(blocks.length, 1, 'workspace has one top-level block');
assert.deepEqual(blocks[0].getRelativeToSurfaceXY(), origin, 'block is at origin');
assert.deepEqual(
blocks[0].getRelativeToSurfaceXY(),
origin,
'block is at origin',
);
});
test('single block at (10, 15) is moved to (0, 0)', function() {
test('single block at (10, 15) is moved to (0, 0)', function () {
const blockJson = {
"type": "math_number",
"x": 10,
"y": 15,
"fields": {
"NUM": 123
}
'type': 'math_number',
'x': 10,
'y': 15,
'fields': {
'NUM': 123,
},
};
Blockly.serialization.blocks.append(blockJson, this.workspace);
@@ -452,26 +456,30 @@ suite('WorkspaceSvg', function () {
const origin = new Blockly.utils.Coordinate(0, 0);
assert.equal(topBlocks.length, 1, 'workspace has one top-level block');
assert.equal(allBlocks.length, 1, 'workspace has one block overall');
assert.deepEqual(topBlocks[0].getRelativeToSurfaceXY(), origin, 'block is at origin');
assert.deepEqual(
topBlocks[0].getRelativeToSurfaceXY(),
origin,
'block is at origin',
);
});
test('single block at (10, 15) with child is moved as unit to (0, 0)', function() {
test('single block at (10, 15) with child is moved as unit to (0, 0)', function () {
const blockJson = {
"type": "logic_negate",
"id": "parent",
"x": 10,
"y": 15,
"inputs": {
"BOOL": {
"block": {
"type": "logic_boolean",
"id": "child",
"fields": {
"BOOL": "TRUE"
}
}
}
}
'type': 'logic_negate',
'id': 'parent',
'x': 10,
'y': 15,
'inputs': {
'BOOL': {
'block': {
'type': 'logic_boolean',
'id': 'child',
'fields': {
'BOOL': 'TRUE',
},
},
},
},
};
Blockly.serialization.blocks.append(blockJson, this.workspace);
@@ -482,21 +490,29 @@ suite('WorkspaceSvg', function () {
const origin = new Blockly.utils.Coordinate(0, 0);
assert.equal(topBlocks.length, 1, 'workspace has one top-level block');
assert.equal(allBlocks.length, 2, 'workspace has two blocks overall');
assert.deepEqual(topBlocks[0].getRelativeToSurfaceXY(), origin, 'block is at origin');
assert.notDeepEqual(allBlocks[1].getRelativeToSurfaceXY(), origin, 'child is not at origin');
assert.deepEqual(
topBlocks[0].getRelativeToSurfaceXY(),
origin,
'block is at origin',
);
assert.notDeepEqual(
allBlocks[1].getRelativeToSurfaceXY(),
origin,
'child is not at origin',
);
});
test('two blocks first at (10, 15) second at (0, 0) do not switch places', function() {
test('two blocks first at (10, 15) second at (0, 0) do not switch places', function () {
const blockJson1 = {
"type": "math_number",
"id": "block1",
"x": 10,
"y": 15,
"fields": {
"NUM": 123
}
'type': 'math_number',
'id': 'block1',
'x': 10,
'y': 15,
'fields': {
'NUM': 123,
},
};
const blockJson2 = {...blockJson1, "id": "block2", "x": 0, "y": 0};
const blockJson2 = {...blockJson1, 'id': 'block2', 'x': 0, 'y': 0};
Blockly.serialization.blocks.append(blockJson1, this.workspace);
Blockly.serialization.blocks.append(blockJson2, this.workspace);
@@ -510,21 +526,34 @@ suite('WorkspaceSvg', function () {
const origin = new Blockly.utils.Coordinate(0, 0);
const belowBlock2 = new Blockly.utils.Coordinate(0, 50);
assert.equal(topBlocks.length, 2, 'workspace has two top-level blocks');
assert.deepEqual(block2.getRelativeToSurfaceXY(), origin, 'block2 is at origin');
assert.deepEqual(block1.getRelativeToSurfaceXY(), belowBlock2, 'block1 is below block2');
assert.deepEqual(
block2.getRelativeToSurfaceXY(),
origin,
'block2 is at origin',
);
assert.deepEqual(
block1.getRelativeToSurfaceXY(),
belowBlock2,
'block1 is below block2',
);
});
test('two overlapping blocks are moved to origin and below', function() {
test('two overlapping blocks are moved to origin and below', function () {
const blockJson1 = {
"type": "math_number",
"id": "block1",
"x": 25,
"y": 15,
"fields": {
"NUM": 123
}
'type': 'math_number',
'id': 'block1',
'x': 25,
'y': 15,
'fields': {
'NUM': 123,
},
};
const blockJson2 = {
...blockJson1,
'id': 'block2',
'x': 15.25,
'y': 20.25,
};
const blockJson2 = {...blockJson1, "id": "block2", "x": 15.25, "y": 20.25};
Blockly.serialization.blocks.append(blockJson1, this.workspace);
Blockly.serialization.blocks.append(blockJson2, this.workspace);
@@ -536,21 +565,34 @@ suite('WorkspaceSvg', function () {
const origin = new Blockly.utils.Coordinate(0, 0);
const belowBlock1 = new Blockly.utils.Coordinate(0, 50);
assert.equal(topBlocks.length, 2, 'workspace has two top-level blocks');
assert.deepEqual(block1.getRelativeToSurfaceXY(), origin, 'block1 is at origin');
assert.deepEqual(block2.getRelativeToSurfaceXY(), belowBlock1, 'block2 is below block1');
assert.deepEqual(
block1.getRelativeToSurfaceXY(),
origin,
'block1 is at origin',
);
assert.deepEqual(
block2.getRelativeToSurfaceXY(),
belowBlock1,
'block2 is below block1',
);
});
test('two overlapping blocks with snapping are moved to grid-aligned positions', function() {
test('two overlapping blocks with snapping are moved to grid-aligned positions', function () {
const blockJson1 = {
"type": "math_number",
"id": "block1",
"x": 25,
"y": 15,
"fields": {
"NUM": 123
}
'type': 'math_number',
'id': 'block1',
'x': 25,
'y': 15,
'fields': {
'NUM': 123,
},
};
const blockJson2 = {
...blockJson1,
'id': 'block2',
'x': 15.25,
'y': 20.25,
};
const blockJson2 = {...blockJson1, "id": "block2", "x": 15.25, "y": 20.25};
Blockly.serialization.blocks.append(blockJson1, this.workspace);
Blockly.serialization.blocks.append(blockJson2, this.workspace);
this.workspace.getGrid().setSpacing(20);
@@ -564,28 +606,41 @@ suite('WorkspaceSvg', function () {
const snappedOffOrigin = new Blockly.utils.Coordinate(10, 10);
const belowBlock1 = new Blockly.utils.Coordinate(10, 70);
assert.equal(topBlocks.length, 2, 'workspace has two top-level blocks');
assert.deepEqual(block1.getRelativeToSurfaceXY(), snappedOffOrigin, 'block1 is near origin');
assert.deepEqual(block2.getRelativeToSurfaceXY(), belowBlock1, 'block2 is below block1');
assert.deepEqual(
block1.getRelativeToSurfaceXY(),
snappedOffOrigin,
'block1 is near origin',
);
assert.deepEqual(
block2.getRelativeToSurfaceXY(),
belowBlock1,
'block2 is below block1',
);
});
test('two overlapping blocks are moved to origin and below including children', function() {
test('two overlapping blocks are moved to origin and below including children', function () {
const blockJson1 = {
"type": "logic_negate",
"id": "block1",
"x": 10,
"y": 15,
"inputs": {
"BOOL": {
"block": {
"type": "logic_boolean",
"fields": {
"BOOL": "TRUE"
}
}
}
}
'type': 'logic_negate',
'id': 'block1',
'x': 10,
'y': 15,
'inputs': {
'BOOL': {
'block': {
'type': 'logic_boolean',
'fields': {
'BOOL': 'TRUE',
},
},
},
},
};
const blockJson2 = {
...blockJson1,
'id': 'block2',
'x': 15.25,
'y': 20.25,
};
const blockJson2 = {...blockJson1, "id": "block2", "x": 15.25, "y": 20.25};
Blockly.serialization.blocks.append(blockJson1, this.workspace);
Blockly.serialization.blocks.append(blockJson2, this.workspace);
@@ -605,60 +660,76 @@ suite('WorkspaceSvg', function () {
assert.equal(allBlocks.length, 4, 'workspace has four blocks overall');
assert.deepEqual(block1Pos, origin, 'block1 is at origin');
assert.deepEqual(block2Pos, belowBlock1, 'block2 is below block1');
assert.isAbove(block1ChildPos.x, block1Pos.x, 'block1\'s child is right of it');
assert.isBelow(block1ChildPos.y, block2Pos.y, 'block1\'s child is above block 2');
assert.isAbove(block2ChildPos.x, block2Pos.x, 'block2\'s child is right of it');
assert.isAbove(block2ChildPos.y, block1Pos.y, 'block2\'s child is below block 1');
assert.isAbove(
block1ChildPos.x,
block1Pos.x,
"block1's child is right of it",
);
assert.isBelow(
block1ChildPos.y,
block2Pos.y,
"block1's child is above block 2",
);
assert.isAbove(
block2ChildPos.x,
block2Pos.x,
"block2's child is right of it",
);
assert.isAbove(
block2ChildPos.y,
block1Pos.y,
"block2's child is below block 1",
);
});
test('two large overlapping blocks are moved to origin and below', function() {
test('two large overlapping blocks are moved to origin and below', function () {
const blockJson1 = {
"type": "controls_repeat_ext",
"id": "block1",
"x": 10,
"y": 20,
"inputs": {
"TIMES": {
"shadow": {
"type": "math_number",
"fields": {
"NUM": 10
}
}
'type': 'controls_repeat_ext',
'id': 'block1',
'x': 10,
'y': 20,
'inputs': {
'TIMES': {
'shadow': {
'type': 'math_number',
'fields': {
'NUM': 10,
},
},
},
"DO": {
"block": {
"type": "controls_if",
"inputs": {
"IF0": {
"block": {
"type": "logic_boolean",
"fields": {
"BOOL": "TRUE"
}
}
'DO': {
'block': {
'type': 'controls_if',
'inputs': {
'IF0': {
'block': {
'type': 'logic_boolean',
'fields': {
'BOOL': 'TRUE',
},
},
},
"DO0": {
"block": {
"type": "text_print",
"inputs": {
"TEXT": {
"shadow": {
"type": "text",
"fields": {
"TEXT": "abc"
}
}
}
}
}
}
}
}
}
}
'DO0': {
'block': {
'type': 'text_print',
'inputs': {
'TEXT': {
'shadow': {
'type': 'text',
'fields': {
'TEXT': 'abc',
},
},
},
},
},
},
},
},
},
},
};
const blockJson2 = {...blockJson1, "id": "block2", "x": 20, "y": 30};
const blockJson2 = {...blockJson1, 'id': 'block2', 'x': 20, 'y': 30};
Blockly.serialization.blocks.append(blockJson1, this.workspace);
Blockly.serialization.blocks.append(blockJson2, this.workspace);
@@ -670,24 +741,32 @@ suite('WorkspaceSvg', function () {
const origin = new Blockly.utils.Coordinate(0, 0);
const belowBlock1 = new Blockly.utils.Coordinate(0, 144);
assert.equal(topBlocks.length, 2, 'workspace has two top-level blocks');
assert.deepEqual(block1.getRelativeToSurfaceXY(), origin, 'block1 is at origin');
assert.deepEqual(block2.getRelativeToSurfaceXY(), belowBlock1, 'block2 is below block1');
assert.deepEqual(
block1.getRelativeToSurfaceXY(),
origin,
'block1 is at origin',
);
assert.deepEqual(
block2.getRelativeToSurfaceXY(),
belowBlock1,
'block2 is below block1',
);
});
test('five overlapping blocks are moved in-order as one column', function() {
test('five overlapping blocks are moved in-order as one column', function () {
const blockJson1 = {
"type": "math_number",
"id": "block1",
"x": 1,
"y": 2,
"fields": {
"NUM": 123
}
'type': 'math_number',
'id': 'block1',
'x': 1,
'y': 2,
'fields': {
'NUM': 123,
},
};
const blockJson2 = {...blockJson1, "id": "block2", "x": 3, "y": 4};
const blockJson3 = {...blockJson1, "id": "block3", "x": 5, "y": 6};
const blockJson4 = {...blockJson1, "id": "block4", "x": 7, "y": 8};
const blockJson5 = {...blockJson1, "id": "block5", "x": 9, "y": 10};
const blockJson2 = {...blockJson1, 'id': 'block2', 'x': 3, 'y': 4};
const blockJson3 = {...blockJson1, 'id': 'block3', 'x': 5, 'y': 6};
const blockJson4 = {...blockJson1, 'id': 'block4', 'x': 7, 'y': 8};
const blockJson5 = {...blockJson1, 'id': 'block5', 'x': 9, 'y': 10};
Blockly.serialization.blocks.append(blockJson1, this.workspace);
Blockly.serialization.blocks.append(blockJson2, this.workspace);
Blockly.serialization.blocks.append(blockJson3, this.workspace);
@@ -697,11 +776,21 @@ suite('WorkspaceSvg', function () {
this.workspace.tidyUp();
const topBlocks = this.workspace.getTopBlocks(true);
const block1Pos = this.workspace.getBlockById('block1').getRelativeToSurfaceXY();
const block2Pos = this.workspace.getBlockById('block2').getRelativeToSurfaceXY();
const block3Pos = this.workspace.getBlockById('block3').getRelativeToSurfaceXY();
const block4Pos = this.workspace.getBlockById('block4').getRelativeToSurfaceXY();
const block5Pos = this.workspace.getBlockById('block5').getRelativeToSurfaceXY();
const block1Pos = this.workspace
.getBlockById('block1')
.getRelativeToSurfaceXY();
const block2Pos = this.workspace
.getBlockById('block2')
.getRelativeToSurfaceXY();
const block3Pos = this.workspace
.getBlockById('block3')
.getRelativeToSurfaceXY();
const block4Pos = this.workspace
.getBlockById('block4')
.getRelativeToSurfaceXY();
const block5Pos = this.workspace
.getBlockById('block5')
.getRelativeToSurfaceXY();
const origin = new Blockly.utils.Coordinate(0, 0);
assert.equal(topBlocks.length, 5, 'workspace has five top-level blocks');
assert.deepEqual(block1Pos, origin, 'block1 is at origin');
@@ -715,15 +804,15 @@ suite('WorkspaceSvg', function () {
assert.isAbove(block5Pos.y, block4Pos.y, 'block5 is below block4');
});
test('single immovable block at (10, 15) is not moved', function() {
test('single immovable block at (10, 15) is not moved', function () {
const blockJson = {
"type": "math_number",
"x": 10,
"y": 15,
"movable": false,
"fields": {
"NUM": 123
}
'type': 'math_number',
'x': 10,
'y': 15,
'movable': false,
'fields': {
'NUM': 123,
},
};
Blockly.serialization.blocks.append(blockJson, this.workspace);
@@ -734,68 +823,84 @@ suite('WorkspaceSvg', function () {
const origPos = new Blockly.utils.Coordinate(10, 15);
assert.equal(topBlocks.length, 1, 'workspace has one top-level block');
assert.equal(allBlocks.length, 1, 'workspace has one block overall');
assert.deepEqual(topBlocks[0].getRelativeToSurfaceXY(), origPos, 'block is at (10, 15)');
assert.deepEqual(
topBlocks[0].getRelativeToSurfaceXY(),
origPos,
'block is at (10, 15)',
);
});
test('multiple block types immovable blocks are not moved', function() {
test('multiple block types immovable blocks are not moved', function () {
const smallBlockJson = {
"type": "math_number",
"fields": {
"NUM": 123
}
'type': 'math_number',
'fields': {
'NUM': 123,
},
};
const largeBlockJson = {
"type": "controls_repeat_ext",
"inputs": {
"TIMES": {
"shadow": {
"type": "math_number",
"fields": {
"NUM": 10
}
}
'type': 'controls_repeat_ext',
'inputs': {
'TIMES': {
'shadow': {
'type': 'math_number',
'fields': {
'NUM': 10,
},
},
},
"DO": {
"block": {
"type": "controls_if",
"inputs": {
"IF0": {
"block": {
"type": "logic_boolean",
"fields": {
"BOOL": "TRUE"
}
}
'DO': {
'block': {
'type': 'controls_if',
'inputs': {
'IF0': {
'block': {
'type': 'logic_boolean',
'fields': {
'BOOL': 'TRUE',
},
},
},
"DO0": {
"block": {
"type": "text_print",
"inputs": {
"TEXT": {
"shadow": {
"type": "text",
"fields": {
"TEXT": "abc"
}
}
}
}
}
}
}
}
}
}
'DO0': {
'block': {
'type': 'text_print',
'inputs': {
'TEXT': {
'shadow': {
'type': 'text',
'fields': {
'TEXT': 'abc',
},
},
},
},
},
},
},
},
},
},
};
// Block 1 overlaps block 2 (immovable) from above.
const blockJson1 = {...smallBlockJson, "id": "block1", "x": 1, "y": 2};
const blockJson2 = {...smallBlockJson, "id": "block2", "x": 10, "y": 20, "movable": false};
const blockJson1 = {...smallBlockJson, 'id': 'block1', 'x': 1, 'y': 2};
const blockJson2 = {
...smallBlockJson,
'id': 'block2',
'x': 10,
'y': 20,
'movable': false,
};
// Block 3 overlaps block 2 (immovable) from below.
const blockJson3 = {...smallBlockJson, "id": "block3", "x": 2, "y": 30};
const blockJson4 = {...largeBlockJson, "id": "block4", "x": 3, "y": 40};
const blockJson3 = {...smallBlockJson, 'id': 'block3', 'x': 2, 'y': 30};
const blockJson4 = {...largeBlockJson, 'id': 'block4', 'x': 3, 'y': 40};
// Block 5 (immovable) will end up overlapping with block 4 since it's large and will be
// moved.
const blockJson5 = {...smallBlockJson, "id": "block5", "x": 20, "y": 200, "movable": false};
const blockJson5 = {
...smallBlockJson,
'id': 'block5',
'x': 20,
'y': 200,
'movable': false,
};
Blockly.serialization.blocks.append(blockJson1, this.workspace);
Blockly.serialization.blocks.append(blockJson2, this.workspace);
Blockly.serialization.blocks.append(blockJson3, this.workspace);
@@ -805,11 +910,21 @@ suite('WorkspaceSvg', function () {
this.workspace.tidyUp();
const topBlocks = this.workspace.getTopBlocks(true);
const block1Rect = this.workspace.getBlockById('block1').getBoundingRectangle();
const block2Rect = this.workspace.getBlockById('block2').getBoundingRectangle();
const block3Rect = this.workspace.getBlockById('block3').getBoundingRectangle();
const block4Rect = this.workspace.getBlockById('block4').getBoundingRectangle();
const block5Rect = this.workspace.getBlockById('block5').getBoundingRectangle();
const block1Rect = this.workspace
.getBlockById('block1')
.getBoundingRectangle();
const block2Rect = this.workspace
.getBlockById('block2')
.getBoundingRectangle();
const block3Rect = this.workspace
.getBlockById('block3')
.getBoundingRectangle();
const block4Rect = this.workspace
.getBlockById('block4')
.getBoundingRectangle();
const block5Rect = this.workspace
.getBlockById('block5')
.getBoundingRectangle();
assert.equal(topBlocks.length, 5, 'workspace has five top-level blocks');
// Check that immovable blocks haven't moved.
assert.equal(block2Rect.left, 10, 'block2.x is at 10');
@@ -826,10 +941,22 @@ suite('WorkspaceSvg', function () {
assert.isAbove(block5Rect.top, block3Rect.top, 'block5 is below block3');
assert.isAbove(block4Rect.top, block5Rect.top, 'block4 is below block5');
// Ensure no blocks intersect (can check in order due to the position verification above).
assert.isFalse(block2Rect.intersects(block1Rect), "block2/block1 do not intersect");
assert.isFalse(block1Rect.intersects(block3Rect), "block1/block3 do not intersect");
assert.isFalse(block3Rect.intersects(block5Rect), "block3/block5 do not intersect");
assert.isFalse(block5Rect.intersects(block4Rect), "block5/block4 do not intersect");
assert.isFalse(
block2Rect.intersects(block1Rect),
'block2/block1 do not intersect',
);
assert.isFalse(
block1Rect.intersects(block3Rect),
'block1/block3 do not intersect',
);
assert.isFalse(
block3Rect.intersects(block5Rect),
'block3/block5 do not intersect',
);
assert.isFalse(
block5Rect.intersects(block4Rect),
'block5/block4 do not intersect',
);
});
});